Skip to content

Commit

Permalink
Redraw old canvas contents when resizing
Browse files Browse the repository at this point in the history
As drawing can now be asynchronous with Workers, backup and redraw the
old canvas contents when resizing to avoid briefly showing a blank
canvas.

Signed-off-by: Chris Lord <chris.lord@collabora.com>
Change-Id: Ida261fa0d9c65d0d65ba5b7b9f31f8bcc792ac18
  • Loading branch information
Chris Lord authored and caolanm committed Nov 22, 2024
1 parent 6dda17b commit db3ca27
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions browser/src/canvas/CanvasSectionContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,12 @@ class CanvasSectionContainer {
if (this.right === newWidth && this.bottom === newHeight)
return;

// Drawing may happen asynchronously so backup the old contents to avoid
// showing a blank canvas.
var oldImageData: ImageData = null;
if (this.paintedEver)
oldImageData = this.context.getImageData(0, 0, this.canvas.width, this.canvas.height);

this.canvas.width = newWidth;
this.canvas.height = newHeight;

Expand All @@ -1348,9 +1354,10 @@ class CanvasSectionContainer {
app.canvasSize.pX = newWidth;
app.canvasSize.pY = newHeight;

// Avoid black default background if canvas was never painted
// since construction.
if (!this.paintedEver)
// Avoid black default background.
if (oldImageData)
this.context.putImageData(oldImageData, 0, 0);
else
this.clearCanvas();

this.clearMousePositions();
Expand Down

0 comments on commit db3ca27

Please sign in to comment.