mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-13 00:03:10 +00:00
Increase cache canvas in steps, do not increase every mouse move (#4037)
* first try * step increase size of canvas * removed console.log git push
This commit is contained in:
parent
6185b07408
commit
ede5d8476c
1 changed files with 22 additions and 6 deletions
|
|
@ -922,23 +922,39 @@
|
|||
}
|
||||
}
|
||||
var dims = this._limitCacheSize(this._getCacheCanvasDimensions()),
|
||||
minCacheSize = fabric.minCacheSideLimit,
|
||||
width = dims.width, height = dims.height,
|
||||
zoomX = dims.zoomX, zoomY = dims.zoomY,
|
||||
dimensionsChanged = width !== this.cacheWidth || height !== this.cacheHeight,
|
||||
zoomChanged = this.zoomX !== zoomX || this.zoomY !== zoomY,
|
||||
shouldRedraw = dimensionsChanged || zoomChanged;
|
||||
shouldRedraw = dimensionsChanged || zoomChanged,
|
||||
additionalWidth = 0, additionalHeight = 0, shouldResizeCanvas = false;
|
||||
if (dimensionsChanged) {
|
||||
var canvasWidth = this._cacheCanvas.width,
|
||||
canvasHeight = this._cacheCanvas.height,
|
||||
sizeGrowing = width > canvasWidth || height > canvasHeight,
|
||||
sizeShrinking = (width < canvasWidth * 0.9 || height < canvasHeight * 0.9) &&
|
||||
canvasWidth > minCacheSize && canvasHeight > minCacheSize;
|
||||
shouldResizeCanvas = sizeGrowing || sizeShrinking;
|
||||
if (sizeGrowing) {
|
||||
additionalWidth = (width * 0.1) & ~1;
|
||||
additionalHeight = (height * 0.1) & ~1;
|
||||
}
|
||||
}
|
||||
if (shouldRedraw) {
|
||||
if (dimensionsChanged) {
|
||||
this._cacheCanvas.width = Math.ceil(width);
|
||||
this._cacheCanvas.height = Math.ceil(height);
|
||||
if (shouldResizeCanvas) {
|
||||
this._cacheCanvas.width = Math.max(Math.ceil(width) + additionalWidth, minCacheSize);
|
||||
this._cacheCanvas.height = Math.max(Math.ceil(height) + additionalHeight, minCacheSize);
|
||||
this.cacheWidth = width;
|
||||
this.cacheHeight = height;
|
||||
this.cacheTranslationX = (width + additionalWidth) / 2;
|
||||
this.cacheTranslationY = (height + additionalHeight) / 2;
|
||||
}
|
||||
else {
|
||||
this._cacheContext.setTransform(1, 0, 0, 1, 0, 0);
|
||||
this._cacheContext.clearRect(0, 0, this._cacheCanvas.width, this._cacheCanvas.height);
|
||||
}
|
||||
this._cacheContext.translate(width / 2, height / 2);
|
||||
this._cacheContext.translate(this.cacheTranslationX, this.cacheTranslationY);
|
||||
this._cacheContext.scale(zoomX, zoomY);
|
||||
this.zoomX = zoomX;
|
||||
this.zoomY = zoomY;
|
||||
|
|
@ -1272,7 +1288,7 @@
|
|||
*/
|
||||
drawCacheOnCanvas: function(ctx) {
|
||||
ctx.scale(1 / this.zoomX, 1 / this.zoomY);
|
||||
ctx.drawImage(this._cacheCanvas, -this.cacheWidth / 2, -this.cacheHeight / 2);
|
||||
ctx.drawImage(this._cacheCanvas, -this.cacheTranslationX, -this.cacheTranslationY);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue