Only resize canvas when necessary
This commit is contained in:
parent
6d28f42d57
commit
41e21ed129
@ -220,11 +220,20 @@ class RenderWebGL extends EventEmitter {
|
||||
* @param {int} pixelsTall The desired height in device-independent pixels.
|
||||
*/
|
||||
resize (pixelsWide, pixelsTall) {
|
||||
const {canvas} = this._gl;
|
||||
const pixelRatio = window.devicePixelRatio || 1;
|
||||
this._gl.canvas.width = pixelsWide * pixelRatio;
|
||||
this._gl.canvas.height = pixelsTall * pixelRatio;
|
||||
// Resizing the canvas can cause it to be cleared, so redraw it.
|
||||
this.draw();
|
||||
const newWidth = pixelsWide * pixelRatio;
|
||||
const newHeight = pixelsTall * pixelRatio;
|
||||
|
||||
// Certain operations, such as moving the color picker, call `resize` once per frame, even though the canvas
|
||||
// size doesn't change. To avoid unnecessary canvas updates, check that we *really* need to resize the canvas.
|
||||
if (canvas.width !== newWidth || canvas.height !== newHeight) {
|
||||
canvas.width = newWidth;
|
||||
canvas.height = newHeight;
|
||||
// Resizing the canvas causes it to be cleared, so redraw it.
|
||||
this.draw();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user