Skip to content

Commit

Permalink
Merge pull request #265 from excalidraw/master
Browse files Browse the repository at this point in the history
fix: image render perf (excalidraw#8697)
  • Loading branch information
zsviczian authored Oct 23, 2024
2 parents 2964c24 + 958e03f commit 653a32e
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions packages/excalidraw/renderer/renderElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export interface ExcalidrawElementWithCanvas {
canvasOffsetX: number;
canvasOffsetY: number;
boundTextElementVersion: number | null;
imageCrop: ExcalidrawImageElement["crop"] | null;
containingFrameOpacity: number;
boundTextCanvas: HTMLCanvasElement;
}
Expand Down Expand Up @@ -336,6 +337,7 @@ const generateElementCanvas = (
getContainingFrame(element, elementsMap)?.opacity || 100,
boundTextCanvas,
angle: element.angle,
imageCrop: isImageElement(element) ? element.crop : null,
};
};

Expand Down Expand Up @@ -547,6 +549,7 @@ const generateElementWithCanvas = (
!appState?.shouldCacheIgnoreZoom;
const boundTextElement = getBoundTextElement(element, elementsMap);
const boundTextElementVersion = boundTextElement?.version || null;
const imageCrop = isImageElement(element) ? element.crop : null;

const containingFrameOpacity =
getContainingFrame(element, elementsMap)?.opacity || 100;
Expand All @@ -556,6 +559,7 @@ const generateElementWithCanvas = (
shouldRegenerateBecauseZoom ||
prevElementWithCanvas.theme !== appState.theme ||
prevElementWithCanvas.boundTextElementVersion !== boundTextElementVersion ||
prevElementWithCanvas.imageCrop !== imageCrop ||
prevElementWithCanvas.containingFrameOpacity !== containingFrameOpacity ||
// since we rotate the canvas when copying from cached canvas, we don't
// regenerate the cached canvas. But we need to in case of labels which are
Expand Down Expand Up @@ -985,24 +989,14 @@ export const renderElement = (
context.restore();
}

const _elementWithCanvas = generateElementCanvas(
elementWithCanvas.element,
allElementsMap,
appState.zoom,
drawElementFromCanvas(
elementWithCanvas,
context,
renderConfig,
appState,
allElementsMap,
);

if (_elementWithCanvas) {
drawElementFromCanvas(
_elementWithCanvas,
context,
renderConfig,
appState,
allElementsMap,
);
}

// reset
context.imageSmoothingEnabled = currentImageSmoothingStatus;
}
Expand Down

0 comments on commit 653a32e

Please sign in to comment.