Skip to content

Commit

Permalink
Update Offscreen.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon authored Apr 18, 2024
1 parent ab9ce3c commit 3e9297e
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions package/src/renderer/Offscreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,13 @@ export const drawAsImage = (element: ReactElement, size: SkSize) => {
return drawAsImageFromPicture(drawAsPicture(element), size);
};

// Offscreen there is no notion of pixel density
// However, some users might be confused when using useTexture, using dimensions in points not pixels
// If we were to do the scaling here, APIs that textures as input (e.g Atlas)
// would need to adapt to the pixel density
// We are not sure yet if the APIs could be more ergonomic there
// We could also in the case of Atlas set the default matrix to scale by the pixel density
// Other some other texture sources like Images have only pixel dimensions
const pd = 1;
export const drawAsImageFromPicture = (picture: SkPicture, size: SkSize) => {
"worklet";
const surface = Skia.Surface.MakeOffscreen(

Check failure on line 37 in package/src/renderer/Offscreen.tsx

View workflow job for this annotation

GitHub Actions / build (example)

Replace `⏎····size.width,⏎····size.height⏎··` with `size.width,·size.height`

Check failure on line 37 in package/src/renderer/Offscreen.tsx

View workflow job for this annotation

GitHub Actions / build (fabricexample)

Replace `⏎····size.width,⏎····size.height⏎··` with `size.width,·size.height`
size.width * pd,
size.height * pd
size.width,
size.height
)!;
const canvas = surface.getCanvas();
canvas.scale(pd, pd);
canvas.drawPicture(picture);
surface.flush();
const image = surface.makeImageSnapshot();
Expand Down

0 comments on commit 3e9297e

Please sign in to comment.