Skip to content

Cherry-pick 307450@main (39eb51251d8f). https://bugs.webkit.org/show_bug.cgi?id=275100#68429

Merged
webkit-commit-queue merged 6 commits into
WebKit:webkitglib/2.52from
csaavedra:eng/CanvasBase-owns-a-ImageBuffer-that-belongs-to-the-CanvasRenderingContext
Jul 1, 2026
Merged

Cherry-pick 307450@main (39eb51251d8f). https://bugs.webkit.org/show_bug.cgi?id=275100#68429
webkit-commit-queue merged 6 commits into
WebKit:webkitglib/2.52from
csaavedra:eng/CanvasBase-owns-a-ImageBuffer-that-belongs-to-the-CanvasRenderingContext

Conversation

@csaavedra

@csaavedra csaavedra commented Jul 1, 2026

Copy link
Copy Markdown
Member

5c9a25e

Cherry-pick 307450@main (39eb51251d8f). https://bugs.webkit.org/show_bug.cgi?id=275100

    CanvasBase owns a ImageBuffer that belongs to the CanvasRenderingContext
    https://bugs.webkit.org/show_bug.cgi?id=275100
    rdar://129208981

    Reviewed by Simon Fraser.

    Before, CanvasBase would own a ImageBuffer that was historically the
    2d context drawing backing store. This ImageBuffer was then repurposed for
    bitmaprenderer, webgl, webgpu backing store to paint all these contexts
    to page (i.e layer) contents. This coden organization is not good,
    because this dictates that the content will exist in an ImageBuffer.
    This needs an extra draw to bitmap to be used. This in turn results
    in loss of performance and memory for all context types, and loss
    of correctness for bitmaprenderer.

    Fix by moving the ImageBuffer backing store to
    CanvasRenderingContext2DBase. Fix by introducing the paint buffer
    backing store specific to each rendering context. In subsequent commits,
    each of the context type may hold and assign the paint buffer backing
    store in efficient manner suitable for each context type.  Also in
    subsequent commits, the paint storage will be held in NativeImages,
    avoiding the need to use ImageBuffer for context types that do not
    originate their images from ImageBuffer.

    * LayoutTests/platform/ios/fast/canvas/offscreen-giant-transfer-to-imagebitmap-expected.txt:
    * LayoutTests/platform/mac-wk2/fast/canvas/offscreen-giant-transfer-to-imagebitmap-expected.txt:
    * Source/WebCore/dom/Document.cpp:
    (WebCore::Document::getCSSCanvasContext):
    * Source/WebCore/html/CanvasBase.cpp:
    (WebCore::CanvasBase::~CanvasBase):
    (WebCore::CanvasBase::makeRenderingResultsAvailable):
    (WebCore::CanvasBase::setSize):
    (WebCore::CanvasBase::shouldAccelerate const):
    (WebCore::CanvasBase::validateArea const):
    (WebCore::CanvasBase::buffer const): Deleted.
    (WebCore::CanvasBase::setImageBuffer const): Deleted.
    (WebCore::CanvasBase::allocateImageBuffer const): Deleted.
    * Source/WebCore/html/CanvasBase.h:
    (WebCore::CanvasBase::setImageBufferAndMarkDirty): Deleted.
    (WebCore::CanvasBase::setHasCreatedImageBuffer): Deleted.
    (WebCore::CanvasBase::hasCreatedImageBuffer const): Deleted.
    (WebCore::CanvasBase::createImageBuffer const): Deleted.
    * Source/WebCore/html/CustomPaintCanvas.cpp:
    (WebCore::CustomPaintCanvas::~CustomPaintCanvas):
    * Source/WebCore/html/CustomPaintCanvas.h:
    * Source/WebCore/html/HTMLCanvasElement.cpp:
    (WebCore::HTMLCanvasElement::~HTMLCanvasElement):
    (WebCore::HTMLCanvasElement::attributeChanged):
    (WebCore::HTMLCanvasElement::setSizeForControllingContext):
    (WebCore::HTMLCanvasElement::didUpdateSizeProperties):
    (WebCore::HTMLCanvasElement::setCSSCanvasContextSize): Deleted.
    (WebCore::HTMLCanvasElement::createImageBuffer const): Deleted.
    (WebCore::HTMLCanvasElement::setImageBufferAndMarkDirty): Deleted.
    * Source/WebCore/html/HTMLCanvasElement.h:
    * Source/WebCore/html/OffscreenCanvas.cpp:
    (WebCore::OffscreenCanvas::~OffscreenCanvas):
    (WebCore::OffscreenCanvas::setWidth):
    (WebCore::OffscreenCanvas::setHeight):
    (WebCore::OffscreenCanvas::setSizeForControllingContext):
    (WebCore::OffscreenCanvas::didUpdateSizeProperties):
    (WebCore::OffscreenCanvas::transferToImageBitmap):
    (WebCore::OffscreenCanvas::createImageBuffer const): Deleted.
    (WebCore::OffscreenCanvas::setImageBufferAndMarkDirty): Deleted.
    * Source/WebCore/html/OffscreenCanvas.h:
    * Source/WebCore/html/canvas/CanvasRenderingContext.cpp:
    (WebCore::CanvasRenderingContext::updateMemoryCost const):
    (WebCore::CanvasRenderingContext::surfaceBufferToImageBuffer): Deleted.
    (WebCore::CanvasRenderingContext::isSurfaceBufferTransparentBlack const): Deleted.
    (WebCore::CanvasRenderingContext::updateMemoryCostOnAllocation): Deleted.
    * Source/WebCore/html/canvas/CanvasRenderingContext.h:
    * Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:
    (WebCore::CanvasRenderingContext2DBase::~CanvasRenderingContext2DBase):
    (WebCore::CanvasRenderingContext2DBase::surfaceBufferToImageBuffer):
    (WebCore::CanvasRenderingContext2DBase::isSurfaceBufferTransparentBlack const):
    (WebCore::CanvasRenderingContext2DBase::layerContentsDisplayDelegate):
    (WebCore::CanvasRenderingContext2DBase::flushDeferredOperations):
    (WebCore::CanvasRenderingContext2DBase::reset):
    (WebCore::CanvasRenderingContext2DBase::didUpdateCanvasSizeProperties):
    (WebCore::CanvasRenderingContext2DBase::drawingContext const):
    (WebCore::CanvasRenderingContext2DBase::existingDrawingContext const):
    (WebCore::CanvasRenderingContext2DBase::baseTransform const):
    (WebCore::CanvasRenderingContext2DBase::prepareForDisplay):
    (WebCore::CanvasRenderingContext2DBase::putImageData):
    (WebCore::CanvasRenderingContext2DBase::getEffectiveRenderingModeForTesting):
    (WebCore::CanvasRenderingContext2DBase::buffer const):
    (WebCore::CanvasRenderingContext2DBase::allocateImageBuffer const):
    * Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h:
    (WebCore::CanvasRenderingContext2DBase::hasCreatedImageBuffer const):
    * Source/WebCore/html/canvas/GPUBasedCanvasRenderingContext.h:
    * Source/WebCore/html/canvas/GPUCanvasContextCocoa.h:
    * Source/WebCore/html/canvas/GPUCanvasContextCocoa.mm:
    (WebCore::GPUCanvasContextCocoa::didUpdateCanvasSizeProperties):
    (WebCore::GPUCanvasContextCocoa::surfaceBufferToImageBuffer):
    (WebCore::GPUCanvasContextCocoa::unconfigure):
    (WebCore::GPUCanvasContextCocoa::prepareForDisplay):
    (WebCore::GPUCanvasContextCocoa::markContextChangedAndNotifyCanvasObservers):
    (WebCore::GPUCanvasContextCocoa::updateMemoryCost const):
    (WebCore::GPUCanvasContextCocoa::reshape): Deleted.
    * Source/WebCore/html/canvas/ImageBitmapRenderingContext.cpp:
    (WebCore::ImageBitmapRenderingContext::transferFromImageBitmap):
    (WebCore::ImageBitmapRenderingContext::transferToImageBuffer):
    (WebCore::ImageBitmapRenderingContext::surfaceBufferToImageBuffer):
    (WebCore::ImageBitmapRenderingContext::setBlank): Deleted.
    * Source/WebCore/html/canvas/ImageBitmapRenderingContext.h:
    * Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.cpp:
    (WebCore::OffscreenCanvasRenderingContext2D::transferToImageBuffer):
    * Source/WebCore/html/canvas/PlaceholderRenderingContext.cpp:
    (WebCore::PlaceholderRenderingContext::setContentsToLayer):
    (WebCore::PlaceholderRenderingContext::setPlaceholderBuffer):
    (WebCore::PlaceholderRenderingContext::pixelFormat const):
    (WebCore::PlaceholderRenderingContext::surfaceBufferToImageBuffer):
    (WebCore::PlaceholderRenderingContext::isSurfaceBufferTransparentBlack const):
    (WebCore::PlaceholderRenderingContext::didUpdateCanvasSizeProperties):
    * Source/WebCore/html/canvas/PlaceholderRenderingContext.h:
    * Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp:
    (WebCore::WebGLRenderingContextBase::initializeNewContext):
    (WebCore::WebGLRenderingContextBase::initializeContextState):
    (WebCore::WebGLRenderingContextBase::markContextChangedAndNotifyCanvasObserver):
    (WebCore::createImageBufferForWebGLContextReads):
    (WebCore::WebGLRenderingContextBase::surfaceBufferToImageBuffer):
    (WebCore::WebGLRenderingContextBase::transferToImageBuffer):
    (WebCore::WebGLRenderingContextBase::didUpdateCanvasSizeProperties):
    (WebCore::WebGLRenderingContextBase::prepareForDisplay):
    (WebCore::WebGLRenderingContextBase::updateMemoryCost const):
    (WebCore::WebGLRenderingContextBase::reshape): Deleted.
    * Source/WebCore/html/canvas/WebGLRenderingContextBase.h:
    * Source/WebCore/inspector/InspectorInstrumentation.cpp:
    (WebCore::InspectorInstrumentation::didChangeCanvasMemoryImpl):
    * Source/WebCore/inspector/InspectorInstrumentation.h:
    (WebCore::InspectorInstrumentation::didChangeCanvasMemory):
    * Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp:
    (WebCore::InspectorCanvasAgent::didChangeCanvasMemory):
    (WebCore::InspectorCanvasAgent::findInspectorCanvas):
    * Source/WebCore/inspector/agents/InspectorCanvasAgent.h:
    * Source/WebCore/rendering/RenderLayerBacking.cpp:
    (WebCore::RenderLayerBacking::createPrimaryGraphicsLayer):

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

    # Conflicts:
    #   Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
    #   Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.cpp
    #   Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
    #   Source/WebCore/rendering/RenderLayerBacking.cpp

Canonical link: https://commits.webkit.org/305877.809@webkitglib/2.52

e3ccffb

Cherry-pick 306772@main (163003d0cfa2). https://bugs.webkit.org/show_bug.cgi?id=306617

    Avoid using CanvasBase::allocateImageBuffer() in WebGL, WebGPU transferToImageBuffer()
    https://bugs.webkit.org/show_bug.cgi?id=306617
    rdar://169276497

    Reviewed by Mike Wyrzykowski.

    The allocation function is related to how 2D context backing store is
    allocated. transferToImageBuffer needs a general purpose ImageBuffer,
    where the WebGL, WebGPU backing store is transferred to.

    This makes it simpler to move 2D context related ImageBuffer code to
    2D rendering context classes.

    * LayoutTests/platform/mac-wk2/fast/canvas/offscreen-giant-transfer-to-imagebitmap-expected.txt:
    Example of failure being fixed here:
    Previously transferToImageBitmap of a giant WebGL context failed due to
    canvas area limitations.

    * Source/WebCore/html/canvas/GPUCanvasContextCocoa.mm:
    (WebCore::GPUCanvasContextCocoa::transferToImageBuffer):
    * Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp:
    (WebCore::WebGLRenderingContextBase::transferToImageBuffer):

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

Canonical link: https://commits.webkit.org/305877.808@webkitglib/2.52

ecfaa2e

Cherry-pick 306625@main (3c05c29f69e0). https://bugs.webkit.org/show_bug.cgi?id=306608

    Move memory cost reporting to canvas rendering contexts
    https://bugs.webkit.org/show_bug.cgi?id=306608
    rdar://169256162

    Reviewed by Simon Fraser.

    Before, the canvas element or offscreen canvas object would report the
    memory cost The rendering context holds the resources and the cost is
    per rendering context type.

    This simplifies moving the ImageBuffer to CanvasRenderingContext2DBase.
    The current memory cost is bound to the image buffer size, and this is
    wildly inaccurate for WebGL and WebGPU. This will be fixed later.

    * Source/WebCore/html/CanvasBase.cpp:
    (WebCore::CanvasBase::setImageBuffer const):
    (WebCore::CanvasBase::memoryCost const): Deleted.
    (WebCore::CanvasBase::externalMemoryCost const): Deleted.
    * Source/WebCore/html/CanvasBase.h:
    * Source/WebCore/html/HTMLCanvasElement.idl:
    * Source/WebCore/html/OffscreenCanvas.idl:
    * Source/WebCore/html/canvas/CanvasRenderingContext.cpp:
    (WebCore::CanvasRenderingContext::updateMemoryCostOnAllocation):
    (WebCore::CanvasRenderingContext::memoryCost const):
    (WebCore::CanvasRenderingContext::externalMemoryCost const):
    * Source/WebCore/html/canvas/CanvasRenderingContext.h:
    * Source/WebCore/html/canvas/CanvasRenderingContext2D.idl:
    * Source/WebCore/html/canvas/GPUCanvasContext.idl:
    * Source/WebCore/html/canvas/ImageBitmapRenderingContext.idl:
    * Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.idl:
    * Source/WebCore/html/canvas/WebGL2RenderingContext.idl:
    * Source/WebCore/html/canvas/WebGLRenderingContext.idl:
    * Source/WebCore/inspector/InspectorCanvas.cpp:
    (WebCore::InspectorCanvas::buildObjectForCanvas):
    * Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp:
    (WebCore::InspectorCanvasAgent::didChangeCanvasMemory):

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

Canonical link: https://commits.webkit.org/305877.807@webkitglib/2.52

212940b

Cherry-pick 306511@main (8d32ab8d183e). https://bugs.webkit.org/show_bug.cgi?id=306603

    Remove CanvasBase::m_contextStateSaver, it is not useful
    https://bugs.webkit.org/show_bug.cgi?id=306603
    rdar://169252451

    Reviewed by Simon Fraser.

    GraphicsContextStateSaver is a RAII class, it's not more useful than
    explicit save/restore useful when managed explicitly. Having the state
    saver in CanvasBase makes it harder to move the ImageBuffer from
    CanvasBase to 2DCanvasRenderingContextBase.

    * Source/WebCore/html/CanvasBase.cpp:
    (WebCore::CanvasBase::setImageBuffer const):
    (WebCore::CanvasBase::resetGraphicsContextState const): Deleted.
    * Source/WebCore/html/CanvasBase.h:
    * Source/WebCore/html/HTMLCanvasElement.cpp:
    (WebCore::HTMLCanvasElement::didUpdateSizeProperties):
    * Source/WebCore/html/OffscreenCanvas.cpp:
    (WebCore::OffscreenCanvas::didUpdateSizeProperties):
    * Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:
    (WebCore::CanvasRenderingContext2DBase::unwindStateStack):
    (WebCore::CanvasRenderingContext2DBase::reset):

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

Canonical link: https://commits.webkit.org/305877.806@webkitglib/2.52

f7982e4

Cherry-pick 306510@main (104d3149f3b3). https://bugs.webkit.org/show_bug.cgi?id=306606

    Remove HTMLCanvasElement::clearImageBuffer, it is redundant
    https://bugs.webkit.org/show_bug.cgi?id=306606
    rdar://169253510

    Reviewed by Simon Fraser.

    2D context canvas is cleared in 2DCanvasRenderingContext::reset() already.
    The function makes it harder to move the ImageBuffer to
    2DCanvasRenderingContext.

    * Source/WebCore/html/HTMLCanvasElement.cpp:
    (WebCore::HTMLCanvasElement::didUpdateSizeProperties):
    (WebCore::HTMLCanvasElement::createImageBuffer const):
    (WebCore::HTMLCanvasElement::clearCopiedImage const):
    (WebCore::HTMLCanvasElement::clearImageBuffer const): Deleted.
    * Source/WebCore/html/HTMLCanvasElement.h:

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

Canonical link: https://commits.webkit.org/305877.805@webkitglib/2.52

c7f74f6

Cherry-pick 306490@main (dc5403ca9f85). https://bugs.webkit.org/show_bug.cgi?id=306613

    Remove unused code from ImageBitmapRenderingContext
    https://bugs.webkit.org/show_bug.cgi?id=306613
    rdar://169267153

    Reviewed by Anne van Kesteren.

    Remove unused code and merge trivial functions that are used only once.
    Remove stale comments. The spec text has changed, and the comments
    make the trivial code more complex.

    Makes future changes moving ImageBuffer out of CanvasBase more
    reviewable.

    * Source/WebCore/html/canvas/ImageBitmapRenderingContext.cpp:
    (WebCore::ImageBitmapRenderingContext::transferFromImageBitmap):
    (WebCore::ImageBitmapRenderingContext::setBlank):
    (WebCore::ImageBitmapRenderingContext::setOutputBitmap): Deleted.
    * Source/WebCore/html/canvas/ImageBitmapRenderingContext.h:

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

Canonical link: https://commits.webkit.org/305877.804@webkitglib/2.52

7578e98

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style 🛠 ios 🛠 mac ✅ 🛠 wpe 🛠 win
✅ 🧪 bindings 🛠 ios-sim 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 🧪 win-tests
✅ 🧪 webkitperl 🧪 ios-wk2 🧪 api-mac ✅ 🧪 api-wpe
🧪 ios-wk2-wpt 🧪 api-mac-debug ✅ 🛠 gtk3-libwebrtc
🧪 jsc-x86-64 🧪 api-ios 🧪 mac-wk2 ✅ 🛠 gtk
🛠 ios-safer-cpp 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
🛠 vision 🧪 mac-wk2-stress ✅ 🧪 api-gtk
🛠 vision-sim 🧪 mac-intel-wk2 🛠 playstation
✅ 🛠 🧪 unsafe-merge 🧪 vision-wk2 🛠 mac-safer-cpp
🛠 tv 🧪 mac-site-isolation
🛠 tv-sim
🛠 watch
🛠 watch-sim

@csaavedra csaavedra self-assigned this Jul 1, 2026
@csaavedra csaavedra added the Canvas Bugs related to the canvas element. label Jul 1, 2026
@csaavedra csaavedra requested review from nikolaszimmermann and removed request for cdumez, dcrousso, patrickangle and rniwa July 1, 2026 11:02
@csaavedra csaavedra added the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jul 1, 2026
…gi?id=306613

    Remove unused code from ImageBitmapRenderingContext
    https://bugs.webkit.org/show_bug.cgi?id=306613
    rdar://169267153

    Reviewed by Anne van Kesteren.

    Remove unused code and merge trivial functions that are used only once.
    Remove stale comments. The spec text has changed, and the comments
    make the trivial code more complex.

    Makes future changes moving ImageBuffer out of CanvasBase more
    reviewable.

    * Source/WebCore/html/canvas/ImageBitmapRenderingContext.cpp:
    (WebCore::ImageBitmapRenderingContext::transferFromImageBitmap):
    (WebCore::ImageBitmapRenderingContext::setBlank):
    (WebCore::ImageBitmapRenderingContext::setOutputBitmap): Deleted.
    * Source/WebCore/html/canvas/ImageBitmapRenderingContext.h:

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

Canonical link: https://commits.webkit.org/305877.804@webkitglib/2.52
…gi?id=306606

    Remove HTMLCanvasElement::clearImageBuffer, it is redundant
    https://bugs.webkit.org/show_bug.cgi?id=306606
    rdar://169253510

    Reviewed by Simon Fraser.

    2D context canvas is cleared in 2DCanvasRenderingContext::reset() already.
    The function makes it harder to move the ImageBuffer to
    2DCanvasRenderingContext.

    * Source/WebCore/html/HTMLCanvasElement.cpp:
    (WebCore::HTMLCanvasElement::didUpdateSizeProperties):
    (WebCore::HTMLCanvasElement::createImageBuffer const):
    (WebCore::HTMLCanvasElement::clearCopiedImage const):
    (WebCore::HTMLCanvasElement::clearImageBuffer const): Deleted.
    * Source/WebCore/html/HTMLCanvasElement.h:

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

Canonical link: https://commits.webkit.org/305877.805@webkitglib/2.52
…gi?id=306603

    Remove CanvasBase::m_contextStateSaver, it is not useful
    https://bugs.webkit.org/show_bug.cgi?id=306603
    rdar://169252451

    Reviewed by Simon Fraser.

    GraphicsContextStateSaver is a RAII class, it's not more useful than
    explicit save/restore useful when managed explicitly. Having the state
    saver in CanvasBase makes it harder to move the ImageBuffer from
    CanvasBase to 2DCanvasRenderingContextBase.

    * Source/WebCore/html/CanvasBase.cpp:
    (WebCore::CanvasBase::setImageBuffer const):
    (WebCore::CanvasBase::resetGraphicsContextState const): Deleted.
    * Source/WebCore/html/CanvasBase.h:
    * Source/WebCore/html/HTMLCanvasElement.cpp:
    (WebCore::HTMLCanvasElement::didUpdateSizeProperties):
    * Source/WebCore/html/OffscreenCanvas.cpp:
    (WebCore::OffscreenCanvas::didUpdateSizeProperties):
    * Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:
    (WebCore::CanvasRenderingContext2DBase::unwindStateStack):
    (WebCore::CanvasRenderingContext2DBase::reset):

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

Canonical link: https://commits.webkit.org/305877.806@webkitglib/2.52
…gi?id=306608

    Move memory cost reporting to canvas rendering contexts
    https://bugs.webkit.org/show_bug.cgi?id=306608
    rdar://169256162

    Reviewed by Simon Fraser.

    Before, the canvas element or offscreen canvas object would report the
    memory cost The rendering context holds the resources and the cost is
    per rendering context type.

    This simplifies moving the ImageBuffer to CanvasRenderingContext2DBase.
    The current memory cost is bound to the image buffer size, and this is
    wildly inaccurate for WebGL and WebGPU. This will be fixed later.

    * Source/WebCore/html/CanvasBase.cpp:
    (WebCore::CanvasBase::setImageBuffer const):
    (WebCore::CanvasBase::memoryCost const): Deleted.
    (WebCore::CanvasBase::externalMemoryCost const): Deleted.
    * Source/WebCore/html/CanvasBase.h:
    * Source/WebCore/html/HTMLCanvasElement.idl:
    * Source/WebCore/html/OffscreenCanvas.idl:
    * Source/WebCore/html/canvas/CanvasRenderingContext.cpp:
    (WebCore::CanvasRenderingContext::updateMemoryCostOnAllocation):
    (WebCore::CanvasRenderingContext::memoryCost const):
    (WebCore::CanvasRenderingContext::externalMemoryCost const):
    * Source/WebCore/html/canvas/CanvasRenderingContext.h:
    * Source/WebCore/html/canvas/CanvasRenderingContext2D.idl:
    * Source/WebCore/html/canvas/GPUCanvasContext.idl:
    * Source/WebCore/html/canvas/ImageBitmapRenderingContext.idl:
    * Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.idl:
    * Source/WebCore/html/canvas/WebGL2RenderingContext.idl:
    * Source/WebCore/html/canvas/WebGLRenderingContext.idl:
    * Source/WebCore/inspector/InspectorCanvas.cpp:
    (WebCore::InspectorCanvas::buildObjectForCanvas):
    * Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp:
    (WebCore::InspectorCanvasAgent::didChangeCanvasMemory):

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

Canonical link: https://commits.webkit.org/305877.807@webkitglib/2.52
…gi?id=306617

    Avoid using CanvasBase::allocateImageBuffer() in WebGL, WebGPU transferToImageBuffer()
    https://bugs.webkit.org/show_bug.cgi?id=306617
    rdar://169276497

    Reviewed by Mike Wyrzykowski.

    The allocation function is related to how 2D context backing store is
    allocated. transferToImageBuffer needs a general purpose ImageBuffer,
    where the WebGL, WebGPU backing store is transferred to.

    This makes it simpler to move 2D context related ImageBuffer code to
    2D rendering context classes.

    * LayoutTests/platform/mac-wk2/fast/canvas/offscreen-giant-transfer-to-imagebitmap-expected.txt:
    Example of failure being fixed here:
    Previously transferToImageBitmap of a giant WebGL context failed due to
    canvas area limitations.

    * Source/WebCore/html/canvas/GPUCanvasContextCocoa.mm:
    (WebCore::GPUCanvasContextCocoa::transferToImageBuffer):
    * Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp:
    (WebCore::WebGLRenderingContextBase::transferToImageBuffer):

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

Canonical link: https://commits.webkit.org/305877.808@webkitglib/2.52
…gi?id=275100

    CanvasBase owns a ImageBuffer that belongs to the CanvasRenderingContext
    https://bugs.webkit.org/show_bug.cgi?id=275100
    rdar://129208981

    Reviewed by Simon Fraser.

    Before, CanvasBase would own a ImageBuffer that was historically the
    2d context drawing backing store. This ImageBuffer was then repurposed for
    bitmaprenderer, webgl, webgpu backing store to paint all these contexts
    to page (i.e layer) contents. This coden organization is not good,
    because this dictates that the content will exist in an ImageBuffer.
    This needs an extra draw to bitmap to be used. This in turn results
    in loss of performance and memory for all context types, and loss
    of correctness for bitmaprenderer.

    Fix by moving the ImageBuffer backing store to
    CanvasRenderingContext2DBase. Fix by introducing the paint buffer
    backing store specific to each rendering context. In subsequent commits,
    each of the context type may hold and assign the paint buffer backing
    store in efficient manner suitable for each context type.  Also in
    subsequent commits, the paint storage will be held in NativeImages,
    avoiding the need to use ImageBuffer for context types that do not
    originate their images from ImageBuffer.

    * LayoutTests/platform/ios/fast/canvas/offscreen-giant-transfer-to-imagebitmap-expected.txt:
    * LayoutTests/platform/mac-wk2/fast/canvas/offscreen-giant-transfer-to-imagebitmap-expected.txt:
    * Source/WebCore/dom/Document.cpp:
    (WebCore::Document::getCSSCanvasContext):
    * Source/WebCore/html/CanvasBase.cpp:
    (WebCore::CanvasBase::~CanvasBase):
    (WebCore::CanvasBase::makeRenderingResultsAvailable):
    (WebCore::CanvasBase::setSize):
    (WebCore::CanvasBase::shouldAccelerate const):
    (WebCore::CanvasBase::validateArea const):
    (WebCore::CanvasBase::buffer const): Deleted.
    (WebCore::CanvasBase::setImageBuffer const): Deleted.
    (WebCore::CanvasBase::allocateImageBuffer const): Deleted.
    * Source/WebCore/html/CanvasBase.h:
    (WebCore::CanvasBase::setImageBufferAndMarkDirty): Deleted.
    (WebCore::CanvasBase::setHasCreatedImageBuffer): Deleted.
    (WebCore::CanvasBase::hasCreatedImageBuffer const): Deleted.
    (WebCore::CanvasBase::createImageBuffer const): Deleted.
    * Source/WebCore/html/CustomPaintCanvas.cpp:
    (WebCore::CustomPaintCanvas::~CustomPaintCanvas):
    * Source/WebCore/html/CustomPaintCanvas.h:
    * Source/WebCore/html/HTMLCanvasElement.cpp:
    (WebCore::HTMLCanvasElement::~HTMLCanvasElement):
    (WebCore::HTMLCanvasElement::attributeChanged):
    (WebCore::HTMLCanvasElement::setSizeForControllingContext):
    (WebCore::HTMLCanvasElement::didUpdateSizeProperties):
    (WebCore::HTMLCanvasElement::setCSSCanvasContextSize): Deleted.
    (WebCore::HTMLCanvasElement::createImageBuffer const): Deleted.
    (WebCore::HTMLCanvasElement::setImageBufferAndMarkDirty): Deleted.
    * Source/WebCore/html/HTMLCanvasElement.h:
    * Source/WebCore/html/OffscreenCanvas.cpp:
    (WebCore::OffscreenCanvas::~OffscreenCanvas):
    (WebCore::OffscreenCanvas::setWidth):
    (WebCore::OffscreenCanvas::setHeight):
    (WebCore::OffscreenCanvas::setSizeForControllingContext):
    (WebCore::OffscreenCanvas::didUpdateSizeProperties):
    (WebCore::OffscreenCanvas::transferToImageBitmap):
    (WebCore::OffscreenCanvas::createImageBuffer const): Deleted.
    (WebCore::OffscreenCanvas::setImageBufferAndMarkDirty): Deleted.
    * Source/WebCore/html/OffscreenCanvas.h:
    * Source/WebCore/html/canvas/CanvasRenderingContext.cpp:
    (WebCore::CanvasRenderingContext::updateMemoryCost const):
    (WebCore::CanvasRenderingContext::surfaceBufferToImageBuffer): Deleted.
    (WebCore::CanvasRenderingContext::isSurfaceBufferTransparentBlack const): Deleted.
    (WebCore::CanvasRenderingContext::updateMemoryCostOnAllocation): Deleted.
    * Source/WebCore/html/canvas/CanvasRenderingContext.h:
    * Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:
    (WebCore::CanvasRenderingContext2DBase::~CanvasRenderingContext2DBase):
    (WebCore::CanvasRenderingContext2DBase::surfaceBufferToImageBuffer):
    (WebCore::CanvasRenderingContext2DBase::isSurfaceBufferTransparentBlack const):
    (WebCore::CanvasRenderingContext2DBase::layerContentsDisplayDelegate):
    (WebCore::CanvasRenderingContext2DBase::flushDeferredOperations):
    (WebCore::CanvasRenderingContext2DBase::reset):
    (WebCore::CanvasRenderingContext2DBase::didUpdateCanvasSizeProperties):
    (WebCore::CanvasRenderingContext2DBase::drawingContext const):
    (WebCore::CanvasRenderingContext2DBase::existingDrawingContext const):
    (WebCore::CanvasRenderingContext2DBase::baseTransform const):
    (WebCore::CanvasRenderingContext2DBase::prepareForDisplay):
    (WebCore::CanvasRenderingContext2DBase::putImageData):
    (WebCore::CanvasRenderingContext2DBase::getEffectiveRenderingModeForTesting):
    (WebCore::CanvasRenderingContext2DBase::buffer const):
    (WebCore::CanvasRenderingContext2DBase::allocateImageBuffer const):
    * Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h:
    (WebCore::CanvasRenderingContext2DBase::hasCreatedImageBuffer const):
    * Source/WebCore/html/canvas/GPUBasedCanvasRenderingContext.h:
    * Source/WebCore/html/canvas/GPUCanvasContextCocoa.h:
    * Source/WebCore/html/canvas/GPUCanvasContextCocoa.mm:
    (WebCore::GPUCanvasContextCocoa::didUpdateCanvasSizeProperties):
    (WebCore::GPUCanvasContextCocoa::surfaceBufferToImageBuffer):
    (WebCore::GPUCanvasContextCocoa::unconfigure):
    (WebCore::GPUCanvasContextCocoa::prepareForDisplay):
    (WebCore::GPUCanvasContextCocoa::markContextChangedAndNotifyCanvasObservers):
    (WebCore::GPUCanvasContextCocoa::updateMemoryCost const):
    (WebCore::GPUCanvasContextCocoa::reshape): Deleted.
    * Source/WebCore/html/canvas/ImageBitmapRenderingContext.cpp:
    (WebCore::ImageBitmapRenderingContext::transferFromImageBitmap):
    (WebCore::ImageBitmapRenderingContext::transferToImageBuffer):
    (WebCore::ImageBitmapRenderingContext::surfaceBufferToImageBuffer):
    (WebCore::ImageBitmapRenderingContext::setBlank): Deleted.
    * Source/WebCore/html/canvas/ImageBitmapRenderingContext.h:
    * Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.cpp:
    (WebCore::OffscreenCanvasRenderingContext2D::transferToImageBuffer):
    * Source/WebCore/html/canvas/PlaceholderRenderingContext.cpp:
    (WebCore::PlaceholderRenderingContext::setContentsToLayer):
    (WebCore::PlaceholderRenderingContext::setPlaceholderBuffer):
    (WebCore::PlaceholderRenderingContext::pixelFormat const):
    (WebCore::PlaceholderRenderingContext::surfaceBufferToImageBuffer):
    (WebCore::PlaceholderRenderingContext::isSurfaceBufferTransparentBlack const):
    (WebCore::PlaceholderRenderingContext::didUpdateCanvasSizeProperties):
    * Source/WebCore/html/canvas/PlaceholderRenderingContext.h:
    * Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp:
    (WebCore::WebGLRenderingContextBase::initializeNewContext):
    (WebCore::WebGLRenderingContextBase::initializeContextState):
    (WebCore::WebGLRenderingContextBase::markContextChangedAndNotifyCanvasObserver):
    (WebCore::createImageBufferForWebGLContextReads):
    (WebCore::WebGLRenderingContextBase::surfaceBufferToImageBuffer):
    (WebCore::WebGLRenderingContextBase::transferToImageBuffer):
    (WebCore::WebGLRenderingContextBase::didUpdateCanvasSizeProperties):
    (WebCore::WebGLRenderingContextBase::prepareForDisplay):
    (WebCore::WebGLRenderingContextBase::updateMemoryCost const):
    (WebCore::WebGLRenderingContextBase::reshape): Deleted.
    * Source/WebCore/html/canvas/WebGLRenderingContextBase.h:
    * Source/WebCore/inspector/InspectorInstrumentation.cpp:
    (WebCore::InspectorInstrumentation::didChangeCanvasMemoryImpl):
    * Source/WebCore/inspector/InspectorInstrumentation.h:
    (WebCore::InspectorInstrumentation::didChangeCanvasMemory):
    * Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp:
    (WebCore::InspectorCanvasAgent::didChangeCanvasMemory):
    (WebCore::InspectorCanvasAgent::findInspectorCanvas):
    * Source/WebCore/inspector/agents/InspectorCanvasAgent.h:
    * Source/WebCore/rendering/RenderLayerBacking.cpp:
    (WebCore::RenderLayerBacking::createPrimaryGraphicsLayer):

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

    # Conflicts:
    #	Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
    #	Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.cpp
    #	Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
    #	Source/WebCore/rendering/RenderLayerBacking.cpp

Canonical link: https://commits.webkit.org/305877.809@webkitglib/2.52
@webkit-commit-queue webkit-commit-queue changed the title Cherry-pick 30 Cherry-pick 307450@main (39eb51251d8f). https://bugs.webkit.org/show_bug.cgi?id=275100 Jul 1, 2026
@webkit-commit-queue webkit-commit-queue force-pushed the eng/CanvasBase-owns-a-ImageBuffer-that-belongs-to-the-CanvasRenderingContext branch from 7578e98 to 5c9a25e Compare July 1, 2026 14:17
@webkit-commit-queue

Copy link
Copy Markdown
Collaborator

Committed 305877.809@webkitglib/2.52 (5c9a25e): https://commits.webkit.org/305877.809@webkitglib/2.52

Reviewed commits have been landed. Closing PR #68429 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 5c9a25e into WebKit:webkitglib/2.52 Jul 1, 2026
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Canvas Bugs related to the canvas element.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants