Skip to content

Commit

Permalink
Cherry-pick 26aaa25. rdar://122309325
Browse files Browse the repository at this point in the history
    REGRESSION(267824@main): Changing HTMLCanvasElement width, height causes intermediate buffer allocations
    https://bugs.webkit.org/show_bug.cgi?id=268745
    rdar://122309325

    Reviewed by Simon Fraser.

    Resizing is intended to leave the buffer unallocated, so that
    sequential width, height assignments will not allocate multiple times.

    This intention was nullified by CanvasRenderingContext2DBase::reset().
    Calling resetTransform redundantly would recreate the buffer
    immediately from width, height attribute setters.

    The transform reset is redundant, the context transform is reset when
    the context state saver is restored and re-saved.

    Clearing the canvas doesn't need to use public
    CanvasRenderingContext2DBase::clearCanvas() that will mutate the context
    state. The state is in known state with initial transform, and thus it
    doesn't need transform mutation.

    * Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:
    (WebCore::CanvasRenderingContext2DBase::reset):

    Canonical link: https://commits.webkit.org/274135@main

Identifier: 272448.530@safari-7618.1.15.10-branch
  • Loading branch information
kkinnunen-apple authored and rjepstein committed Feb 8, 2024
1 parent 8415dd0 commit 8155dd1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
CONSOLE MESSAGE: Canvas area exceeds the maximum limit (width * height > 268435456).
CONSOLE MESSAGE: Canvas area exceeds the maximum limit (width * height > 268435456).

Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
CONSOLE MESSAGE: Canvas area exceeds the maximum limit (width * height > 16777216).
CONSOLE MESSAGE: Canvas area exceeds the maximum limit (width * height > 16777216).

8 changes: 4 additions & 4 deletions Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@ void CanvasRenderingContext2DBase::reset()
m_cachedContents.emplace<CachedContentsTransparent>();

clearAccumulatedDirtyRect();
resetTransform();

canvasBase().resetGraphicsContextState();
clearCanvas();
if (auto* c = canvasBase().existingDrawingContext()) {
canvasBase().resetGraphicsContextState();
c->clearRect(FloatRect { { }, canvasBase().size() });
}
}

CanvasRenderingContext2DBase::State::State()
Expand Down

0 comments on commit 8155dd1

Please sign in to comment.