Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: fbe51f1e5d75c40d718a1a39ec5f2ca479d9c183
      
https://github.com/WebKit/WebKit/commit/fbe51f1e5d75c40d718a1a39ec5f2ca479d9c183
  Author: Kimmo Kinnunen <[email protected]>
  Date:   2026-08-20 (Thu, 20 Aug 2026)

  Changed paths:
    M Source/WebCore/Configurations/AllowedSPI.toml
    M Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h
    M Source/WebCore/PlatformCocoa.cmake
    M Source/WebCore/SourcesCocoa.txt
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
    M Source/WebCore/platform/graphics/GraphicsContextGL.cpp
    M Source/WebCore/platform/graphics/GraphicsContextGL.h
    M Source/WebCore/platform/graphics/NativeImage.h
    M Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp
    M Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h
    M Source/WebCore/platform/graphics/avfoundation/AudioVideoRendererAVFObjC.mm
    M 
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm
    M 
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm
    M Source/WebCore/platform/graphics/cg/NativeImageCG.cpp
    M Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.h
    M Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm
    R Source/WebCore/platform/graphics/cocoa/IOSurfaceDrawingBuffer.cpp
    M Source/WebCore/platform/graphics/cocoa/IOSurfaceDrawingBuffer.h
    M Source/WebCore/platform/graphics/cv/CVUtilities.h
    M Source/WebCore/platform/graphics/cv/CVUtilities.mm
    M Source/WebCore/platform/graphics/cv/PixelBufferConformerCV.cpp
    M Source/WebCore/platform/graphics/cv/PixelBufferConformerCV.h
    M Source/WebCore/platform/graphics/cv/VideoFrameCV.mm
    M Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp
    M Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h
    M Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.messages.in
    M Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp
    M Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h
    M 
Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.cpp
    M Tools/Scripts/generate-gpup-webgl
    M Tools/TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLCocoa.mm
    M Tools/TestWebKitAPI/Tests/WebCore/glib/GraphicsContextGLTextureMapper.cpp

  Log Message:
  -----------
  WebGL: Copy context to NativeImage in straight orientation
https://bugs.webkit.org/show_bug.cgi?id=321790
rdar://184913852

Reviewed by Dan Glastonbury.

Change copyNativeImageYFlipped to copyNativeImage. In later commits,
this enables the NativeImage be used directly instead of yet another
NativeImage -> ImageBuffer draw.

This is work towards being able to use NativeImages for fast
access between context types (2d, WebGL, WebGPU, bitmaprenderer).

Before, the WebGL drawing or display buffer would be used directly
in the CGImage created by wrapping the CGIOSurfaceContext. Then
all WebGL draw commands would invoke copy-on-write explicitly through
that context. This had the downside that the image was flipped and
had to be drawn flipped to extra ImageBuffer and then copied out.

Instead, do a copy + flip at the copyNativeImage() moment.
Benefits:
- This is quite much faster than non-copy + flip draw to new copy
- Does not suffer from copy during next WebGL draw or WebGL
  context discard.
- Keeps the data in an IOSurface for later commits to add direct
  consumption from IOSurfaces.

Requires adding a CG image provider API that is able to return
IOSurfaces to CA.

Moves CVUtilities.mm createImageFrom32BGRAPixelBuffer to
more complete reusable NativeImage::create(CVPixelBufferRef, ...)
constructor. Uses CG SPI to be able to return IOSurfaces to CA.

For contents stored in the NativeImage copy:
1. Create a IOSurface -backed CVPixelBuffer.
2. Flip the WebGL rendering with BlitFramebuffer to the IOSurface.
3. Mark the CVPixelBuffer and its underlying IOSurface as having
   unpremultiplied content, if needed.

* Source/WebCore/Configurations/AllowedSPI.toml:
* Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h:
* Source/WebCore/PlatformCocoa.cmake:
* Source/WebCore/SourcesCocoa.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::surfaceBufferToImageBuffer):
(WebCore::WebGLRenderingContextBase::transferToImageBuffer):
* Source/WebCore/platform/graphics/GraphicsContextGL.cpp:
(WebCore::GraphicsContextGL::paintToCanvas):
* Source/WebCore/platform/graphics/GraphicsContextGL.h:
* Source/WebCore/platform/graphics/NativeImage.h:
* Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp:
(WebCore::GraphicsContextGLANGLE::resolveMultisamplingIfNecessary):
(WebCore::GraphicsContextGLANGLE::prepareTexture):
(WebCore::GraphicsContextGLANGLE::clear):
(WebCore::GraphicsContextGLANGLE::drawArrays):
(WebCore::GraphicsContextGLANGLE::drawElements):
(WebCore::GraphicsContextGLANGLE::drawArraysInstanced):
(WebCore::GraphicsContextGLANGLE::drawElementsInstanced):
(WebCore::GraphicsContextGLANGLE::blitFramebuffer):
(WebCore::GraphicsContextGLANGLE::invalidateFramebuffer):
(WebCore::GraphicsContextGLANGLE::invalidateSubFramebuffer):
(WebCore::GraphicsContextGLANGLE::drawRangeElements):
(WebCore::GraphicsContextGLANGLE::clearBufferiv):
(WebCore::GraphicsContextGLANGLE::clearBufferuiv):
(WebCore::GraphicsContextGLANGLE::clearBufferfv):
(WebCore::GraphicsContextGLANGLE::multiDrawArraysANGLE):
(WebCore::GraphicsContextGLANGLE::multiDrawArraysInstancedANGLE):
(WebCore::GraphicsContextGLANGLE::multiDrawElementsANGLE):
(WebCore::GraphicsContextGLANGLE::multiDrawElementsInstancedANGLE):
(WebCore::GraphicsContextGLANGLE::drawArraysInstancedBaseInstanceANGLE):
(WebCore::GraphicsContextGLANGLE::drawElementsInstancedBaseVertexBaseInstanceANGLE):
(WebCore::GraphicsContextGLANGLE::multiDrawArraysInstancedBaseInstanceANGLE):
(WebCore::GraphicsContextGLANGLE::multiDrawElementsInstancedBaseVertexBaseInstanceANGLE):
(WebCore::flipPixelBufferRows):
(WebCore::GraphicsContextGLANGLE::copyNativeImage):
(WebCore::GraphicsContextGLANGLE::copyNativeImageYFlipped): Deleted.
(WebCore::GraphicsContextGLANGLE::drawingBufferToPixelBuffer): Deleted.
(WebCore::GraphicsContextGLANGLE::prepareForDrawingBufferWriteIfBound): Deleted.
(WebCore::GraphicsContextGLANGLE::prepareForDrawingBufferWrite): Deleted.
* Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h:
* Source/WebCore/platform/graphics/avfoundation/AudioVideoRendererAVFObjC.mm:
(WebCore::AudioVideoRendererAVFObjC::currentNativeImage const):
* 
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::updateLastImage):
* 
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updateCurrentFrameImage):
* Source/WebCore/platform/graphics/cg/NativeImageCG.cpp:
(WebCore::releaseImageBlock):
(WebCore::canSatisfyBlockSetOptions):
(WebCore::copyImageBlockSet):
(WebCore::copyIOSurface):
(WebCore::releaseProviderInfo):
(WebCore::NativeImage::create):
* Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.h:
* Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
(WebCore::GraphicsContextGLCocoa::platformInitializeExtensions):
(WebCore::GraphicsContextGLCocoa::copySurfaceBuffer):
(WebCore::GraphicsContextGLCocoa::drawingBuffer):
(WebCore::GraphicsContextGLCocoa::displayBuffer):
(WebCore::GraphicsContextGLCocoa::copyBuffer):
(WebCore::GraphicsContextGLCocoa::surfaceBuffer):
(WebCore::GraphicsContextGLCocoa::createDrawingBuffer):
(WebCore::GraphicsContextGLCocoa::bindNextDrawingBuffer):
(WebCore::GraphicsContextGLCocoa::surfaceBufferToVideoFrame):
(WebCore::alphaInfoForSurfaceBufferContents):
(WebCore::GraphicsContextGLCocoa::copyNativeImage):
(WebCore::GraphicsContextGLCocoa::copyNativeImageYFlipped): Deleted.
(WebCore::GraphicsContextGLCocoa::prepareForDrawingBufferWrite): Deleted.
* Source/WebCore/platform/graphics/cocoa/IOSurfaceDrawingBuffer.cpp: Removed.
* Source/WebCore/platform/graphics/cocoa/IOSurfaceDrawingBuffer.h:
(WebCore::IOSurfaceDrawingBuffer::IOSurfaceDrawingBuffer):
(WebCore::IOSurfaceDrawingBuffer::operator=):
(WebCore::IOSurfaceDrawingBuffer::prepareForWrite): Deleted.
* Source/WebCore/platform/graphics/cv/CVUtilities.h:
* Source/WebCore/platform/graphics/cv/CVUtilities.mm:
(WebCore::createImageFrom32BGRAPixelBuffer): Deleted.
* Source/WebCore/platform/graphics/cv/PixelBufferConformerCV.cpp:
(WebCore::PixelBufferConformerCV::createImageFromPixelBuffer):
* Source/WebCore/platform/graphics/cv/PixelBufferConformerCV.h:
* Source/WebCore/platform/graphics/cv/VideoFrameCV.mm:
(WebCore::VideoFrame::copyNativeImage const):
* Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp:
(WebKit::RemoteGraphicsContextGL::copyNativeImage):
(WebKit::RemoteGraphicsContextGL::copyNativeImageYFlipped): Deleted.
* Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h:
* Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.messages.in:
* Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp:
(WebKit::RemoteGraphicsContextGLProxy::copyNativeImage):
(WebKit::RemoteGraphicsContextGLProxy::copyNativeImageYFlipped): Deleted.
* Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h:
* 
Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.cpp:
(WebKit::RemoteVideoFrameObjectHeapProxyProcessor::getNativeImage):
* Tools/Scripts/generate-gpup-webgl:
* Tools/TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLCocoa.mm:
(TestWebKitAPI::WebCore::AnyContextAttributeTest::alphaMode const):
(TestWebKitAPI::WebCore::AnyContextAttributeTest::hasAlpha const):
(TestWebKitAPI::WebCore::AnyContextAttributeTest::contentsAlphaPremultiplication
 const):
(TestWebKitAPI::WebCore::AnyContextAttributeTest::attributes):
(TestWebKitAPI::TEST_F(GraphicsContextGLCocoaTest, 
CopyNativeImageNoDrawingBufferReturnsNullptr)):
(TestWebKitAPI::TEST_F(GraphicsContextGLCocoaTest, 
CopyNativeImageAfterReshape)):
(TestWebKitAPI::clearBottomHalf):
(TestWebKitAPI::TEST_P):
(TestWebKitAPI::TEST_F(GraphicsContextGLCocoaTest, 
CopyImageAndMutateDrawingBuffer)):
(TestWebKitAPI::anyContextAttributeTestName):
* Tools/TestWebKitAPI/Tests/WebCore/glib/GraphicsContextGLTextureMapper.cpp:
(TestWebKitAPI::TEST_F(GraphicsContextGLTextureMapperTest, 
CopyNativeImageNoDrawingBufferReturnsNullptr)):
(TestWebKitAPI::TEST_F(GraphicsContextGLTextureMapperTest, 
CopyNativeImageIsNotYFlipped)):
(TestWebKitAPI::TEST_F(GraphicsContextGLTextureMapperTest, 
CopyImageAndMutateDrawingBuffer)):

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to