Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: aec414a86945fd065b52d3697e1036012e6a6b30
https://github.com/WebKit/WebKit/commit/aec414a86945fd065b52d3697e1036012e6a6b30
Author: Kimmo Kinnunen <[email protected]>
Date: 2026-10-10 (Sat, 10 Oct 2026)
Changed paths:
M
LayoutTests/platform/glib/webgl/default-framebuffer-size-limits-1-expected.txt
M
LayoutTests/platform/glib/webgl/default-framebuffer-size-limits-2-expected.txt
M
LayoutTests/platform/glib/webgl/default-framebuffer-size-limits-3-expected.txt
M
LayoutTests/platform/glib/webgl/default-framebuffer-size-limits-4-expected.txt
M LayoutTests/platform/gtk/TestExpectations
A LayoutTests/webgl/default-framebuffer-resize-applied-at-use-expected.txt
A LayoutTests/webgl/default-framebuffer-resize-applied-at-use.html
M
LayoutTests/webgl/default-framebuffer-resize-clears-despite-state-expected.txt
M LayoutTests/webgl/default-framebuffer-resize-clears-despite-state.html
M LayoutTests/webgl/default-framebuffer-size-limits-1-expected.txt
M LayoutTests/webgl/default-framebuffer-size-limits-2-expected.txt
M LayoutTests/webgl/default-framebuffer-size-limits-3-expected.txt
M LayoutTests/webgl/default-framebuffer-size-limits-4-expected.txt
M LayoutTests/webgl/default-framebuffer-size-limits-worker-1-expected.txt
M LayoutTests/webgl/default-framebuffer-size-limits-worker-2-expected.txt
M LayoutTests/webgl/default-framebuffer-size-limits-worker-3-expected.txt
M LayoutTests/webgl/default-framebuffer-size-limits-worker-4-expected.txt
M
LayoutTests/webgl/lose-context-on-default-framebuffer-allocation-failure-expected.txt
M
LayoutTests/webgl/lose-context-on-default-framebuffer-allocation-failure.html
M LayoutTests/webgl/resources/default-framebuffer-size-limits.js
M Source/WebCore/html/canvas/WebGL2RenderingContext.cpp
M Source/WebCore/html/canvas/WebGLDefaultFramebuffer.cpp
M Source/WebCore/html/canvas/WebGLDefaultFramebuffer.h
M Source/WebCore/html/canvas/WebGLDrawInstancedBaseVertexBaseInstance.cpp
M Source/WebCore/html/canvas/WebGLMultiDraw.cpp
M
Source/WebCore/html/canvas/WebGLMultiDrawInstancedBaseVertexBaseInstance.cpp
M Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
M Source/WebCore/html/canvas/WebGLRenderingContextBase.h
Log Message:
-----------
WebGL: Resizing the canvas with separate width and height assignments can
lose the context
https://bugs.webkit.org/show_bug.cgi?id=325943
rdar://188900757
Reviewed by Mike Wyrzykowski.
Each canvas width or height assignment reallocated the default
framebuffer storage. Resizing a canvas with separate width and height
assignments thus allocated the storage for the intermediate size. For
example, resizing from 2x16384 to 16384x2 allocated a 16384x16384
drawing buffer. With antialias, that did not fit in memory and the
context was lost.
Set only the size when the canvas is resized, and reallocate the
storage when the default framebuffer is next used. The drawing buffer
size is reported right away. WebGLDefaultFramebuffer::setSize() sets
the size, and ensureSize() reallocates and clears the storage if the
size was set since the last reallocation. The context calls
ensureSize() through ensureDefaultFramebufferSize() before every use of
the default framebuffer, before clearIfComposited() and in the reads of
the display buffer. Draws, clears and reads of framebuffer objects do not
use the default framebuffer, so they do not reallocate it. If the
reallocation fails, the context is lost and the call returns without
using the default framebuffer.
A resize that shrinks the storage reallocates it right away, so that a
page that shrinks the canvas to release memory does not keep the old
storage until the canvas is next used. The shrink does not allocate more
than is already allocated.
Mark the context as active in willUpdateDrawingBufferContents(), since
draws to framebuffer objects no longer call clearIfComposited().
blitFramebuffer() did not call clearIfComposited(), so a blit could read
or write the default framebuffer at its old size, or read stale
contents from a default framebuffer that should read as cleared. Call it
when the default framebuffer is bound for reading or drawing.
Resizing the canvas and resizing it back without using the default
framebuffer reallocates the storage to the size it already has. Then
the storage may keep its contents, and only the clear in reshape()
clears it. Disable the rasterizer discard and enable the draw buffer 0
for the clear, as clearIfComposited() does, so that the state the
application set does not prevent it.
The resize marks the display buffer to be replaced with the cleared
drawing buffer of the new size. The reallocation to the size the storage
already has does not replace it, so for example the placeholder canvas
of an OffscreenCanvas would keep showing the old contents.
A failure to allocate the storage after a resize now loses the context
at the first use after the resize. The reallocation stays pending after
the failure.
Disable the WebGL errors to console in the allocation failure test and
in the new test. The errors that the GPU process reports are printed
asynchronously, which made the output depend on timing.
*
LayoutTests/platform/glib/webgl/default-framebuffer-size-limits-1-expected.txt:
*
LayoutTests/platform/glib/webgl/default-framebuffer-size-limits-2-expected.txt:
*
LayoutTests/platform/glib/webgl/default-framebuffer-size-limits-3-expected.txt:
*
LayoutTests/platform/glib/webgl/default-framebuffer-size-limits-4-expected.txt:
* LayoutTests/platform/gtk/TestExpectations:
* LayoutTests/webgl/default-framebuffer-resize-applied-at-use-expected.txt:
Added.
* LayoutTests/webgl/default-framebuffer-resize-applied-at-use.html: Added.
*
LayoutTests/webgl/default-framebuffer-resize-clears-despite-state-expected.txt:
* LayoutTests/webgl/default-framebuffer-resize-clears-despite-state.html:
* LayoutTests/webgl/default-framebuffer-size-limits-1-expected.txt:
* LayoutTests/webgl/default-framebuffer-size-limits-2-expected.txt:
* LayoutTests/webgl/default-framebuffer-size-limits-3-expected.txt:
* LayoutTests/webgl/default-framebuffer-size-limits-4-expected.txt:
* LayoutTests/webgl/default-framebuffer-size-limits-worker-1-expected.txt:
* LayoutTests/webgl/default-framebuffer-size-limits-worker-2-expected.txt:
* LayoutTests/webgl/default-framebuffer-size-limits-worker-3-expected.txt:
* LayoutTests/webgl/default-framebuffer-size-limits-worker-4-expected.txt:
*
LayoutTests/webgl/lose-context-on-default-framebuffer-allocation-failure-expected.txt:
* LayoutTests/webgl/lose-context-on-default-framebuffer-allocation-failure.html:
* LayoutTests/webgl/resources/default-framebuffer-size-limits.js:
* Source/WebCore/html/canvas/WebGL2RenderingContext.cpp:
(WebCore::WebGL2RenderingContext::blitFramebuffer):
(WebCore::WebGL2RenderingContext::copyTexSubImage3D):
(WebCore::WebGL2RenderingContext::drawRangeElements):
(WebCore::WebGL2RenderingContext::clearBufferiv):
(WebCore::WebGL2RenderingContext::clearBufferfv):
(WebCore::WebGL2RenderingContext::clearBufferfi):
(WebCore::WebGL2RenderingContext::readPixels):
* Source/WebCore/html/canvas/WebGLDefaultFramebuffer.cpp:
(WebCore::WebGLDefaultFramebuffer::setSize):
(WebCore::WebGLDefaultFramebuffer::ensureSize):
(WebCore::WebGLDefaultFramebuffer::reshape):
* Source/WebCore/html/canvas/WebGLDefaultFramebuffer.h:
(WebCore::WebGLDefaultFramebuffer::pendingSizeShrinksStorage const):
* Source/WebCore/html/canvas/WebGLDrawInstancedBaseVertexBaseInstance.cpp:
(WebCore::WebGLDrawInstancedBaseVertexBaseInstance::drawArraysInstancedBaseInstanceWEBGL):
(WebCore::WebGLDrawInstancedBaseVertexBaseInstance::drawElementsInstancedBaseVertexBaseInstanceWEBGL):
* Source/WebCore/html/canvas/WebGLMultiDraw.cpp:
(WebCore::WebGLMultiDraw::multiDrawArraysWEBGL):
(WebCore::WebGLMultiDraw::multiDrawArraysInstancedWEBGL):
(WebCore::WebGLMultiDraw::multiDrawElementsWEBGL):
(WebCore::WebGLMultiDraw::multiDrawElementsInstancedWEBGL):
* Source/WebCore/html/canvas/WebGLMultiDrawInstancedBaseVertexBaseInstance.cpp:
(WebCore::WebGLMultiDrawInstancedBaseVertexBaseInstance::multiDrawArraysInstancedBaseInstanceWEBGL):
(WebCore::WebGLMultiDrawInstancedBaseVertexBaseInstance::multiDrawElementsInstancedBaseVertexBaseInstanceWEBGL):
* Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::initializeNewContext):
(WebCore::WebGLRenderingContextBase::willUpdateDrawingBufferContents):
(WebCore::WebGLRenderingContextBase::ensureDefaultFramebufferSize):
(WebCore::WebGLRenderingContextBase::clearIfComposited):
(WebCore::WebGLRenderingContextBase::surfaceBufferToNativeImage):
(WebCore::WebGLRenderingContextBase::drawingBufferToPixelBuffer):
(WebCore::WebGLRenderingContextBase::surfaceBufferToVideoFrame):
(WebCore::WebGLRenderingContextBase::transferToImageBuffer):
(WebCore::WebGLRenderingContextBase::didUpdateCanvasSizeProperties):
(WebCore::WebGLRenderingContextBase::clear):
(WebCore::WebGLRenderingContextBase::copyTexSubImage2D):
(WebCore::WebGLRenderingContextBase::drawArrays):
(WebCore::WebGLRenderingContextBase::drawElements):
(WebCore::WebGLRenderingContextBase::readPixels):
(WebCore::WebGLRenderingContextBase::copyTexImage2D):
(WebCore::WebGLRenderingContextBase::drawArraysInstanced):
(WebCore::WebGLRenderingContextBase::drawElementsInstanced):
(WebCore::WebGLRenderingContextBase::prepareForDisplay):
* Source/WebCore/html/canvas/WebGLRenderingContextBase.h:
Canonical link: https://commits.webkit.org/323298@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications