MCPcopy Create free account
hub / github.com/Snapchat/Valdi / doRasterize

Method doRasterize

apps/managed_context_example/ManagedContextExample.tsx:141–180  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

139 }
140
141 private async doRasterize(): Promise<Asset> {
142 const [componentWidth, componentHeight] = this.getComponentSize();
143 const context = createManagedContext({
144 embeddedPlatformViewRasterMethod: this.state.rasterMethod,
145 deltaRasterization: true,
146 });
147 context.render(() => {
148 <InnerComponent />;
149 });
150
151 await context.onAllAssetsLoaded();
152
153 await context.layout(componentWidth, componentHeight, false);
154
155 const { frame } = await context.draw();
156
157 const scale = Device.getDisplayScale() / DOWNSCALE_RATIO[this.state.downscaleRatioIndex];
158 const rasterWidth = Math.floor(scale * componentWidth);
159 const rasterHeight = Math.floor(scale * componentHeight);
160
161 const bytesPerPixel = 4;
162
163 const bitmap = createBitmap({
164 width: rasterWidth,
165 height: rasterHeight,
166 colorType: BitmapColorType.RGBA8888,
167 alphaType: BitmapAlphaType.OPAQUE,
168 rowBytes: rasterWidth * bytesPerPixel,
169 });
170
171 frame.rasterInto(bitmap, true);
172
173 const buffer = bitmap.encode(ImageEncoding.PNG, 1.0);
174
175 frame.dispose();
176 bitmap.dispose();
177 context.dispose();
178
179 return makeAssetFromBytes(buffer);
180 }
181}
182
183const styles = {};

Callers 1

AppClass · 0.95

Calls 12

getComponentSizeMethod · 0.95
createManagedContextFunction · 0.90
createBitmapFunction · 0.90
makeAssetFromBytesFunction · 0.90
renderMethod · 0.65
onAllAssetsLoadedMethod · 0.65
layoutMethod · 0.65
drawMethod · 0.65
rasterIntoMethod · 0.65
encodeMethod · 0.65
disposeMethod · 0.65
getDisplayScaleMethod · 0.45

Tested by

no test coverage detected