[webkit-changes] [WebKit/WebKit] 50ae4e: [WebGL] Avoid using glReadPixels to paint WebGL ca...

Dan Glastonbury noreply at github.com
Mon Apr 3 11:13:57 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 50ae4e81ccce7b0c1ebd530b24a88ed25ba82caf
      https://github.com/WebKit/WebKit/commit/50ae4e81ccce7b0c1ebd530b24a88ed25ba82caf
  Author: Dan Glastonbury <djg at apple.com>
  Date:   2023-04-03 (Mon, 03 Apr 2023)

  Changed paths:
    M Source/WebCore/platform/graphics/GraphicsContextGL.cpp
    M Source/WebCore/platform/graphics/GraphicsContextGL.h
    M Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp
    M Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h
    M Source/WebCore/platform/graphics/cairo/GraphicsContextGLCairo.cpp
    M Source/WebCore/platform/graphics/cg/GraphicsContextGLCG.cpp
    M Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.h
    M Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm
    M Source/WebCore/platform/graphics/cocoa/GraphicsContextGLIOSurfaceSwapChain.h
    M Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp
    M Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h

  Log Message:
  -----------
  [WebGL] Avoid using glReadPixels to paint WebGL canvas into 2D canvas
https://bugs.webkit.org/show_bug.cgi?id=252795
rdar://87173127

Reviewed by Kimmo Kinnunen.

Instead of reading pixels from the current drawing buffer using glReadPixels,
the IOSurface backing the drawing buffer is wrapped in a CGImage for the
duration of the synchronous call to paintRenderingResultsToCanvas.

To ensure that the WebGL rendering is present in the drawing buffer, any pending
GL operations are executed to update rendering before creating a CGImageRef
wrapper around WebGL's IOSurface.

* Source/WebCore/platform/graphics/GraphicsContextGL.cpp:
(WebCore::GraphicsContextGL::paintToCanvas):

Platform dependent code has been extracted into
createNativeImageFromPixelBuffer, allowing paintToCanvas implementations to be
unified.

* Source/WebCore/platform/graphics/GraphicsContextGL.h:

Split paintToCanvas(..., Ref<PixelBuffer>&&, ...) into
createNativeImageFromPixelBuffer(Ref<PixelBufer>&&, ...) and
paintToCanvas(NativeImage&, ...). This allows the painting of any NativeImage to
canvas, not just PixelBuffer sources and provides a convenience function to
obtain a NativeImage from a PixelBuffer.

* Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp:
(WebCore::GraphicsContextGLANGLE::prepareTexture):

Since we're now calling prepareTexture() in a difference context remove ASSERT
that layer isn't composited.

* Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h:
* Source/WebCore/platform/graphics/cairo/GraphicsContextGLCairo.cpp:
(WebCore::GraphicsContextGL::createNativeImageFromPixelBuffer):

Helper function to create NativeImage from PixelBuffer.

(WebCore::GraphicsContextGL::paintToCanvas): Deleted.
* Source/WebCore/platform/graphics/cg/GraphicsContextGLCG.cpp:
(WebCore::GraphicsContextGL::createNativeImageFromPixelBuffer):

Helper function to create NativeImage from PixelBuffer.

(WebCore::GraphicsContextGL::paintToCanvas): Deleted.
 Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.h:
* Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
(WebCore::GraphicsContextGLCocoa::paintRenderingResultsToCanvas):
(WebCore::GraphicsContextGLCocoa::paintCompositedResultsToCanvas):

Defer implementation using helper functions and paintToCanvas(NativeImage&, ...)

(WebCore::GraphicsContextGLCocoa::withDrawingBufferAsNativeImage):
(WebCore::GraphicsContextGLCocoa::withDisplayBufferAsNativeImage):

Helper methods to aid borrowing WebGL's IOSurface-backed drawing and display
buffers as NativeImage, taking care of conversion, context creation, flushing,
etc. WebGL contexts not using premultiplied alpha still use the glReadPixels
path because IOSurfaces without premultipled alpha are unsupported by
CoreGraphics. The image is passed by reference to stop the function from hanging
onto the image.

* Source/WebCore/platform/graphics/cocoa/GraphicsContextGLIOSurfaceSwapChain.h:
* Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp:
(WebKit::RemoteGraphicsContextGL::paintRenderingResultsToCanvasWithQualifiedIdentifier):
(WebKit::RemoteGraphicsContextGL::paintCompositedResultsToCanvasWithQualifiedIdentifier):

Defer implementation using helper functions and paintNativeImageToImageBuffer()

(WebKit::RemoteGraphicsContextGL::paintNativeImageToImageBuffer):
(WebKit::RemoteGraphicsContextGL::paintPixelBufferToImageBuffer): Deleted.

Painting to ImageBuffer is only supported via NativeImage. To paint a pixel
buffer, first convert the PixelBuffer to NativeImage using
createNativeImageFromPixelBuffer().

* Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h:

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




More information about the webkit-changes mailing list