Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 05c4585aef2819a1881b7d910e70ae55492e0282
https://github.com/WebKit/WebKit/commit/05c4585aef2819a1881b7d910e70ae55492e0282
Author: Nikolas Zimmermann <[email protected]>
Date: 2026-01-08 (Thu, 08 Jan 2026)
Changed paths:
M Source/WebCore/platform/graphics/skia/GraphicsContextSkia.h
M
Source/WebCore/platform/graphics/skia/ImageBufferSkiaAcceleratedBackend.cpp
M Source/WebCore/platform/graphics/skia/ImageBufferSkiaAcceleratedBackend.h
M Source/WebCore/platform/graphics/skia/ImageBufferSkiaSurfaceBackend.h
M Source/WebCore/platform/graphics/skia/SkiaRecordingResult.cpp
M Source/WebCore/platform/graphics/skia/SkiaRecordingResult.h
M Source/WebCore/platform/graphics/skia/SkiaReplayCanvas.cpp
M Source/WebCore/platform/graphics/skia/SkiaReplayCanvas.h
Log Message:
-----------
[GTK][WPE][Skia] Add canvas 2D operation recording for batched replay
https://bugs.webkit.org/show_bug.cgi?id=303575
Reviewed by Carlos Garcia Campos.
Introduce canvas 2D operation recording for GPU-accelerated canvas rendering.
Instead of executing drawing commands immediately, operations are recorded into
an SkPicture and replayed in batch when the canvas contents are actually needed.
This reduces GPU state change overhead for workloads with many small drawing
operations.
When a canvas ImageBuffer is first accessed, we create a recording context
backed
by an SkPictureRecorder. All subsequent drawing operations are captured into
this
recording rather than being executed on the GPU surface. This continues until a
"materialization point" is reached - a point where the actual pixel contents are
needed. The optimal case is prepareForDisplay(), where the recording is replayed
just before compositing. Other materialization points include
createNativeImageReference()
for snapshots, getPixelBuffer()/putPixelBuffer() for CPU access, and
flushContext()
for explicit synchronization.
At the materialization point, the recording is finalized and replayed to the GPU
surface. The drawing state (fill/stroke colors, composite modes, transforms,
etc.)
is preserved across this transition. After flushing, the canvas switches to
direct
rendering mode for all subsequent operations - we don't restart recording, as
the
batching benefit has already been realized for the initial burst of drawing
commands.
A SkiaSwitchableCanvas (derived from SkNWayCanvas) serves as the stable canvas
reference held by GraphicsContextSkia, allowing us to transparently redirect
drawing operations from the recording canvas to the surface canvas after
flushing.
Cross-thread transfer (e.g., for OffscreenCanvas) is handled by flushing any
pending recording on the source thread before transfer, since Skia surfaces are
not thread-safe. The destination thread simply waits for the GPU fence rather
than recreating the surface. Additionally, when drawing GPU-backed images whose
textures were created in a different GL context, we rewrap them using
SkImages::BorrowTextureFrom() to make them valid for the current context.
Covered by existing tests.
* Source/WebCore/platform/graphics/skia/GraphicsContextSkia.h:
* Source/WebCore/platform/graphics/skia/ImageBufferSkiaAcceleratedBackend.cpp:
(WebCore::ImageBufferSkiaAcceleratedBackend::~ImageBufferSkiaAcceleratedBackend):
(WebCore::ImageBufferSkiaAcceleratedBackend::context):
(WebCore::ImageBufferSkiaAcceleratedBackend::ensureCanvasRecordingContext):
(WebCore::ImageBufferSkiaAcceleratedBackend::copyGraphicsState):
(WebCore::ImageBufferSkiaAcceleratedBackend::flushCanvasRecordingContextIfNeeded):
(WebCore::ImageBufferSkiaAcceleratedBackend::flushContext):
(WebCore::ImageBufferSkiaAcceleratedBackend::prepareForDisplay):
(WebCore::ImageBufferSkiaAcceleratedBackend::createNativeImageReference):
(WebCore::ImageBufferSkiaAcceleratedBackend::getPixelBuffer):
(WebCore::ImageBufferSkiaAcceleratedBackend::putPixelBuffer):
* Source/WebCore/platform/graphics/skia/ImageBufferSkiaAcceleratedBackend.h:
* Source/WebCore/platform/graphics/skia/ImageBufferSkiaSurfaceBackend.h:
* Source/WebCore/platform/graphics/skia/SkiaRecordingResult.cpp:
* Source/WebCore/platform/graphics/skia/SkiaRecordingResult.h:
* Source/WebCore/platform/graphics/skia/SkiaReplayCanvas.cpp:
* Source/WebCore/platform/graphics/skia/SkiaReplayCanvas.h:
Canonical link: https://commits.webkit.org/305273@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications