Title: [284943] branches/safari-612-branch/Source/WebCore
Revision
284943
Author
[email protected]
Date
2021-10-27 14:05:30 -0700 (Wed, 27 Oct 2021)

Log Message

Cherry-pick r283362. rdar://problem/84629481

    Cocoa GraphicsContextGLOpenGL should not be used by GraphicsContextGLCVANGLE
    https://bugs.webkit.org/show_bug.cgi?id=231010

    Patch by Kimmo Kinnunen <[email protected]> on 2021-10-01
    Reviewed by Kenneth Russell.

    GraphicsContextGLOpenGL creates a GraphicsContextGLCVANGLE helper to do
    do YUV texture uploads. This GraphicsContextGLCVANGLE creates a OpenGL ES context that
    shares the OpenGL state by the caller.

    Previously the new context would be a GraphicsContextGLOpenGL. This would be a problem
    since GraphicsContextGLOpenGL has compositor related logic and objects, for example
    the WebGL layer as well as resources for default framebuffer operation. Shared context
    would also go to the GraphicsContextGLOpenGLManager context list even though
    they could not be deleted behind the owners back during context recycling.

    Instead, create just a normal ANGLE context and call ANGLE directly from
    GraphicsContextGLCVANGLE. This is more consistent with software layers:
    GraphicsContextGLOpenGL and GraphicsContextGLCVANGLE are at the same software
    level, part of the same GraphicsContextGLOpenGL implementation.

    Makes it possible to remove otherwise unused and unfitting "shared context"
    related functionality from WebGL level from GraphicsContextGL.

    No new tests, refactor.

    * SourcesCocoa.txt:
    * WebCore.xcodeproj/project.pbxproj:
    * platform/graphics/GraphicsContextGL.cpp:
    (WebCore::GraphicsContextGL::GraphicsContextGL):
    * platform/graphics/GraphicsContextGL.h:
    * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
    (WebCore::GraphicsContextGLOpenGL::asCV): Deleted.
    * platform/graphics/cocoa/ANGLEUtilitiesCocoa.cpp: Added.
    (WebCore::createPbufferAndAttachIOSurface):
    (WebCore::destroyPbufferAndDetachIOSurface):
    * platform/graphics/cocoa/ANGLEUtilitiesCocoa.h: Added.
    Move the createPbufferAndAttachIOSurface to Cocoa specific
    ANGLE utility file.
    See also bug 226504 - Adopt createPbufferAndAttachIOSurface/destroyPbufferAndDetachIOSurface
    in GraphicsContextGLCVANGLE.cpp and GraphicsContextGLOpenGLCocoa.mm

    * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
    (WebCore::GraphicsContextGLOpenGL::create):
    (WebCore::GraphicsContextGLOpenGL::createForGPUProcess):
    (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
    (WebCore::GraphicsContextGLOpenGL::~GraphicsContextGLOpenGL):
    (WebCore::GraphicsContextGLOpenGL::checkGPUStatus):
    (WebCore::GraphicsContextGLOpenGL::makeCurrent):
    Add a new function to make the EGL context current and maintain
    the GraphicsContextGLOpenGL::currentContext cache value correctly.
    Cache needs to be invalidated always when EGL context changes.
    The cache value is reset always, and then set only when needed
    during GraphicsContextGLOpenGL::makeContextCurrent().

    Make GraphicsContextGLCVANGLE friend of GraphicsContextGLOpenGL, since
    essentially the former is part of the implementation of latter.

    (WebCore::GraphicsContextGLOpenGL::createPbufferAndAttachIOSurface):
    (WebCore::GraphicsContextGLOpenGL::destroyPbufferAndDetachIOSurface):
    Move the implementation to a ANGLE related helper files above.

    (WebCore::GraphicsContextGLOpenGL::asCV):
    Move the asCV to the implementaton file for Cococa, as that is
    the platform which uses the implementation.

    (WebCore::GraphicsContextGLOpenGL::createShared): Deleted.
    (WebCore::GraphicsContextGLOpenGL::clearCurrentContext): Deleted.
    Replace with GraphicsContextGLOpenGL::makeCurrent().

    * platform/graphics/cv/GraphicsContextGLCVANGLE.cpp:
    (WebCore::YCbCrMatrix::operator const GLfloat* const):
    (WebCore::YCbCrToRGBMatrixForRangeAndTransferFunction):
    (WebCore::GraphicsContextGLCVANGLE::create):
    (WebCore::GraphicsContextGLCVANGLE::~GraphicsContextGLCVANGLE):
    (WebCore::GraphicsContextGLCVANGLE::GraphicsContextGLCVANGLE):
    Reorder the resource initialization with ScopeExit cleanup functions.
    Avoid storing the yuvProgram, instead just use the program as program
    binary and delete the program.

    (WebCore::GraphicsContextGLCVANGLE::copyPixelBufferToTexture):
    (WebCore::YCbCrMatrix::operator GCGLSpan<const GLfloat, 16> const): Deleted.
    (WebCore::GraphicsContextGLCVANGLE::initializeUVContextObjects): Deleted.
    Move the resource initialization into the constructor. The object
    itself is already initialized only on demand.
    (WebCore::GraphicsContextGLCVANGLE::attachIOSurfaceToTexture): Deleted.
    (WebCore::GraphicsContextGLCVANGLE::detachIOSurfaceFromTexture): Deleted.
    Share the implementation with the existing implementation from
    WebCore::GraphicsContextGLOpenGL::createPbufferAndAttachIOSurface that
    was moved to WebCore::createPbufferAndAttachIOSurface.

    * platform/graphics/cv/GraphicsContextGLCVANGLE.h:
    Remove the m_yuvProgram, rather use just the program binary.

    * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
    * platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp:
    (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
    Remove the redundant sharedContext parameter.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@283362 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-612-branch/Source/WebCore/ChangeLog (284942 => 284943)


--- branches/safari-612-branch/Source/WebCore/ChangeLog	2021-10-27 21:05:24 UTC (rev 284942)
+++ branches/safari-612-branch/Source/WebCore/ChangeLog	2021-10-27 21:05:30 UTC (rev 284943)
@@ -1,5 +1,210 @@
 2021-10-26  Alan Coon  <[email protected]>
 
+        Cherry-pick r283362. rdar://problem/84629481
+
+    Cocoa GraphicsContextGLOpenGL should not be used by GraphicsContextGLCVANGLE
+    https://bugs.webkit.org/show_bug.cgi?id=231010
+    
+    Patch by Kimmo Kinnunen <[email protected]> on 2021-10-01
+    Reviewed by Kenneth Russell.
+    
+    GraphicsContextGLOpenGL creates a GraphicsContextGLCVANGLE helper to do
+    do YUV texture uploads. This GraphicsContextGLCVANGLE creates a OpenGL ES context that
+    shares the OpenGL state by the caller.
+    
+    Previously the new context would be a GraphicsContextGLOpenGL. This would be a problem
+    since GraphicsContextGLOpenGL has compositor related logic and objects, for example
+    the WebGL layer as well as resources for default framebuffer operation. Shared context
+    would also go to the GraphicsContextGLOpenGLManager context list even though
+    they could not be deleted behind the owners back during context recycling.
+    
+    Instead, create just a normal ANGLE context and call ANGLE directly from
+    GraphicsContextGLCVANGLE. This is more consistent with software layers:
+    GraphicsContextGLOpenGL and GraphicsContextGLCVANGLE are at the same software
+    level, part of the same GraphicsContextGLOpenGL implementation.
+    
+    Makes it possible to remove otherwise unused and unfitting "shared context"
+    related functionality from WebGL level from GraphicsContextGL.
+    
+    No new tests, refactor.
+    
+    * SourcesCocoa.txt:
+    * WebCore.xcodeproj/project.pbxproj:
+    * platform/graphics/GraphicsContextGL.cpp:
+    (WebCore::GraphicsContextGL::GraphicsContextGL):
+    * platform/graphics/GraphicsContextGL.h:
+    * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
+    (WebCore::GraphicsContextGLOpenGL::asCV): Deleted.
+    * platform/graphics/cocoa/ANGLEUtilitiesCocoa.cpp: Added.
+    (WebCore::createPbufferAndAttachIOSurface):
+    (WebCore::destroyPbufferAndDetachIOSurface):
+    * platform/graphics/cocoa/ANGLEUtilitiesCocoa.h: Added.
+    Move the createPbufferAndAttachIOSurface to Cocoa specific
+    ANGLE utility file.
+    See also bug 226504 - Adopt createPbufferAndAttachIOSurface/destroyPbufferAndDetachIOSurface
+    in GraphicsContextGLCVANGLE.cpp and GraphicsContextGLOpenGLCocoa.mm
+    
+    * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
+    (WebCore::GraphicsContextGLOpenGL::create):
+    (WebCore::GraphicsContextGLOpenGL::createForGPUProcess):
+    (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
+    (WebCore::GraphicsContextGLOpenGL::~GraphicsContextGLOpenGL):
+    (WebCore::GraphicsContextGLOpenGL::checkGPUStatus):
+    (WebCore::GraphicsContextGLOpenGL::makeCurrent):
+    Add a new function to make the EGL context current and maintain
+    the GraphicsContextGLOpenGL::currentContext cache value correctly.
+    Cache needs to be invalidated always when EGL context changes.
+    The cache value is reset always, and then set only when needed
+    during GraphicsContextGLOpenGL::makeContextCurrent().
+    
+    Make GraphicsContextGLCVANGLE friend of GraphicsContextGLOpenGL, since
+    essentially the former is part of the implementation of latter.
+    
+    (WebCore::GraphicsContextGLOpenGL::createPbufferAndAttachIOSurface):
+    (WebCore::GraphicsContextGLOpenGL::destroyPbufferAndDetachIOSurface):
+    Move the implementation to a ANGLE related helper files above.
+    
+    (WebCore::GraphicsContextGLOpenGL::asCV):
+    Move the asCV to the implementaton file for Cococa, as that is
+    the platform which uses the implementation.
+    
+    (WebCore::GraphicsContextGLOpenGL::createShared): Deleted.
+    (WebCore::GraphicsContextGLOpenGL::clearCurrentContext): Deleted.
+    Replace with GraphicsContextGLOpenGL::makeCurrent().
+    
+    * platform/graphics/cv/GraphicsContextGLCVANGLE.cpp:
+    (WebCore::YCbCrMatrix::operator const GLfloat* const):
+    (WebCore::YCbCrToRGBMatrixForRangeAndTransferFunction):
+    (WebCore::GraphicsContextGLCVANGLE::create):
+    (WebCore::GraphicsContextGLCVANGLE::~GraphicsContextGLCVANGLE):
+    (WebCore::GraphicsContextGLCVANGLE::GraphicsContextGLCVANGLE):
+    Reorder the resource initialization with ScopeExit cleanup functions.
+    Avoid storing the yuvProgram, instead just use the program as program
+    binary and delete the program.
+    
+    (WebCore::GraphicsContextGLCVANGLE::copyPixelBufferToTexture):
+    (WebCore::YCbCrMatrix::operator GCGLSpan<const GLfloat, 16> const): Deleted.
+    (WebCore::GraphicsContextGLCVANGLE::initializeUVContextObjects): Deleted.
+    Move the resource initialization into the constructor. The object
+    itself is already initialized only on demand.
+    (WebCore::GraphicsContextGLCVANGLE::attachIOSurfaceToTexture): Deleted.
+    (WebCore::GraphicsContextGLCVANGLE::detachIOSurfaceFromTexture): Deleted.
+    Share the implementation with the existing implementation from
+    WebCore::GraphicsContextGLOpenGL::createPbufferAndAttachIOSurface that
+    was moved to WebCore::createPbufferAndAttachIOSurface.
+    
+    * platform/graphics/cv/GraphicsContextGLCVANGLE.h:
+    Remove the m_yuvProgram, rather use just the program binary.
+    
+    * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+    * platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp:
+    (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
+    Remove the redundant sharedContext parameter.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@283362 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-10-01  Kimmo Kinnunen  <[email protected]>
+
+            Cocoa GraphicsContextGLOpenGL should not be used by GraphicsContextGLCVANGLE
+            https://bugs.webkit.org/show_bug.cgi?id=231010
+
+            Reviewed by Kenneth Russell.
+
+            GraphicsContextGLOpenGL creates a GraphicsContextGLCVANGLE helper to do
+            do YUV texture uploads. This GraphicsContextGLCVANGLE creates a OpenGL ES context that
+            shares the OpenGL state by the caller.
+
+            Previously the new context would be a GraphicsContextGLOpenGL. This would be a problem
+            since GraphicsContextGLOpenGL has compositor related logic and objects, for example
+            the WebGL layer as well as resources for default framebuffer operation. Shared context
+            would also go to the GraphicsContextGLOpenGLManager context list even though
+            they could not be deleted behind the owners back during context recycling.
+
+            Instead, create just a normal ANGLE context and call ANGLE directly from
+            GraphicsContextGLCVANGLE. This is more consistent with software layers:
+            GraphicsContextGLOpenGL and GraphicsContextGLCVANGLE are at the same software
+            level, part of the same GraphicsContextGLOpenGL implementation.
+
+            Makes it possible to remove otherwise unused and unfitting "shared context"
+            related functionality from WebGL level from GraphicsContextGL.
+
+            No new tests, refactor.
+
+            * SourcesCocoa.txt:
+            * WebCore.xcodeproj/project.pbxproj:
+            * platform/graphics/GraphicsContextGL.cpp:
+            (WebCore::GraphicsContextGL::GraphicsContextGL):
+            * platform/graphics/GraphicsContextGL.h:
+            * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
+            (WebCore::GraphicsContextGLOpenGL::asCV): Deleted.
+            * platform/graphics/cocoa/ANGLEUtilitiesCocoa.cpp: Added.
+            (WebCore::createPbufferAndAttachIOSurface):
+            (WebCore::destroyPbufferAndDetachIOSurface):
+            * platform/graphics/cocoa/ANGLEUtilitiesCocoa.h: Added.
+            Move the createPbufferAndAttachIOSurface to Cocoa specific
+            ANGLE utility file.
+            See also bug 226504 - Adopt createPbufferAndAttachIOSurface/destroyPbufferAndDetachIOSurface
+            in GraphicsContextGLCVANGLE.cpp and GraphicsContextGLOpenGLCocoa.mm
+
+            * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
+            (WebCore::GraphicsContextGLOpenGL::create):
+            (WebCore::GraphicsContextGLOpenGL::createForGPUProcess):
+            (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
+            (WebCore::GraphicsContextGLOpenGL::~GraphicsContextGLOpenGL):
+            (WebCore::GraphicsContextGLOpenGL::checkGPUStatus):
+            (WebCore::GraphicsContextGLOpenGL::makeCurrent):
+            Add a new function to make the EGL context current and maintain
+            the GraphicsContextGLOpenGL::currentContext cache value correctly.
+            Cache needs to be invalidated always when EGL context changes.
+            The cache value is reset always, and then set only when needed
+            during GraphicsContextGLOpenGL::makeContextCurrent().
+
+            Make GraphicsContextGLCVANGLE friend of GraphicsContextGLOpenGL, since
+            essentially the former is part of the implementation of latter.
+
+            (WebCore::GraphicsContextGLOpenGL::createPbufferAndAttachIOSurface):
+            (WebCore::GraphicsContextGLOpenGL::destroyPbufferAndDetachIOSurface):
+            Move the implementation to a ANGLE related helper files above.
+
+            (WebCore::GraphicsContextGLOpenGL::asCV):
+            Move the asCV to the implementaton file for Cococa, as that is
+            the platform which uses the implementation.
+
+            (WebCore::GraphicsContextGLOpenGL::createShared): Deleted.
+            (WebCore::GraphicsContextGLOpenGL::clearCurrentContext): Deleted.
+            Replace with GraphicsContextGLOpenGL::makeCurrent().
+
+            * platform/graphics/cv/GraphicsContextGLCVANGLE.cpp:
+            (WebCore::YCbCrMatrix::operator const GLfloat* const):
+            (WebCore::YCbCrToRGBMatrixForRangeAndTransferFunction):
+            (WebCore::GraphicsContextGLCVANGLE::create):
+            (WebCore::GraphicsContextGLCVANGLE::~GraphicsContextGLCVANGLE):
+            (WebCore::GraphicsContextGLCVANGLE::GraphicsContextGLCVANGLE):
+            Reorder the resource initialization with ScopeExit cleanup functions.
+            Avoid storing the yuvProgram, instead just use the program as program
+            binary and delete the program.
+
+            (WebCore::GraphicsContextGLCVANGLE::copyPixelBufferToTexture):
+            (WebCore::YCbCrMatrix::operator GCGLSpan<const GLfloat, 16> const): Deleted.
+            (WebCore::GraphicsContextGLCVANGLE::initializeUVContextObjects): Deleted.
+            Move the resource initialization into the constructor. The object
+            itself is already initialized only on demand.
+            (WebCore::GraphicsContextGLCVANGLE::attachIOSurfaceToTexture): Deleted.
+            (WebCore::GraphicsContextGLCVANGLE::detachIOSurfaceFromTexture): Deleted.
+            Share the implementation with the existing implementation from
+            WebCore::GraphicsContextGLOpenGL::createPbufferAndAttachIOSurface that
+            was moved to WebCore::createPbufferAndAttachIOSurface.
+
+            * platform/graphics/cv/GraphicsContextGLCVANGLE.h:
+            Remove the m_yuvProgram, rather use just the program binary.
+
+            * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+            * platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp:
+            (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
+            Remove the redundant sharedContext parameter.
+
+2021-10-26  Alan Coon  <[email protected]>
+
         Cherry-pick r282160. rdar://problem/84630406
 
     webgl/2.0.y/conformance/extensions/webgl-compressed-texture-etc.html fails on Metal

Modified: branches/safari-612-branch/Source/WebCore/SourcesCocoa.txt (284942 => 284943)


--- branches/safari-612-branch/Source/WebCore/SourcesCocoa.txt	2021-10-27 21:05:24 UTC (rev 284942)
+++ branches/safari-612-branch/Source/WebCore/SourcesCocoa.txt	2021-10-27 21:05:30 UTC (rev 284943)
@@ -359,6 +359,7 @@
 platform/graphics/cg/SubimageCacheWithTimer.cpp
 platform/graphics/cg/TransformationMatrixCG.cpp
 platform/graphics/cg/UTIRegistry.cpp
+platform/graphics/cocoa/ANGLEUtilitiesCocoa.cpp
 platform/graphics/cocoa/AudioTrackPrivateWebM.cpp
 platform/graphics/cocoa/ColorCocoa.mm
 platform/graphics/cocoa/FloatRectCocoa.mm

Modified: branches/safari-612-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj (284942 => 284943)


--- branches/safari-612-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-10-27 21:05:24 UTC (rev 284942)
+++ branches/safari-612-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-10-27 21:05:30 UTC (rev 284943)
@@ -10476,6 +10476,8 @@
 		7BB34A47253776C700029D08 /* GraphicsContextGLImageExtractor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsContextGLImageExtractor.cpp; sourceTree = "<group>"; };
 		7BB680B725BA1BE3002B8738 /* GraphicsChecksMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsChecksMac.cpp; sourceTree = "<group>"; };
 		7BB680B825BA1BE4002B8738 /* GraphicsChecksMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsChecksMac.h; sourceTree = "<group>"; };
+		7BCD42DA2705C94900EB2127 /* ANGLEUtilitiesCocoa.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ANGLEUtilitiesCocoa.cpp; sourceTree = "<group>"; };
+		7BCD42DC2705C94900EB2127 /* ANGLEUtilitiesCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ANGLEUtilitiesCocoa.h; sourceTree = "<group>"; };
 		7BE7265B25763B8D00E85D98 /* RemoteGraphicsContextGLProxyBase.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteGraphicsContextGLProxyBase.cpp; sourceTree = "<group>"; };
 		7C011F3D24FAD360005BEF10 /* Settings.cpp.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = Settings.cpp.erb; sourceTree = "<group>"; };
 		7C011F3E24FAD360005BEF10 /* InternalSettingsGenerated.cpp.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = InternalSettingsGenerated.cpp.erb; sourceTree = "<group>"; };
@@ -26959,6 +26961,8 @@
 		B5320D68122A24E9002D1440 /* cocoa */ = {
 			isa = PBXGroup;
 			children = (
+				7BCD42DA2705C94900EB2127 /* ANGLEUtilitiesCocoa.cpp */,
+				7BCD42DC2705C94900EB2127 /* ANGLEUtilitiesCocoa.h */,
 				CDF9950124C28149002EA062 /* AudioTrackPrivateWebM.cpp */,
 				CDF9950024C28149002EA062 /* AudioTrackPrivateWebM.h */,
 				F48D2AA32159740D00C6752B /* ColorCocoa.h */,
@@ -31002,6 +31006,7 @@
 				E7E0357224D4E196008DFEFB /* AnalyserOptions.h in Headers */,
 				27E3C808257F5E6E00C986AB /* ANGLEHeaders.h in Headers */,
 				31A795C71888BCB200382F90 /* ANGLEInstancedArrays.h in Headers */,
+				7BB34A1725345CB200029D08 /* ANGLEUtilities.h in Headers */,
 				49E912AB0EFAC906009D0CAF /* Animation.h in Headers */,
 				71EFCEDC202B38A900D7C411 /* AnimationEffect.h in Headers */,
 				71E2C42621C935280024F8C8 /* AnimationEffectPhase.h in Headers */,
@@ -32220,7 +32225,6 @@
 				934907E4125BBBC8007F23A0 /* GraphicsContextCG.h in Headers */,
 				313DE87023A96973008FC47B /* GraphicsContextGL.h in Headers */,
 				7B45AB5525FBA9DE00FD27F4 /* GraphicsContextGLANGLEEGLUtilities.h in Headers */,
-				7BB34A1725345CB200029D08 /* GraphicsContextGLANGLEUtilities.h in Headers */,
 				7C330A021DF8FAC600D3395C /* GraphicsContextGLAttributes.h in Headers */,
 				7B10339E2549721700C8C1AC /* GraphicsContextGLCV.h in Headers */,
 				7B10339F2549721E00C8C1AC /* GraphicsContextGLCVANGLE.h in Headers */,

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/GraphicsContextGL.cpp (284942 => 284943)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/GraphicsContextGL.cpp	2021-10-27 21:05:24 UTC (rev 284942)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/GraphicsContextGL.cpp	2021-10-27 21:05:30 UTC (rev 284943)
@@ -357,7 +357,7 @@
     return result;
 }
 
-GraphicsContextGL::GraphicsContextGL(GraphicsContextGLAttributes attrs, GraphicsContextGL*)
+GraphicsContextGL::GraphicsContextGL(GraphicsContextGLAttributes attrs)
     : m_attrs(attrs)
 {
 }

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/GraphicsContextGL.h (284942 => 284943)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/GraphicsContextGL.h	2021-10-27 21:05:24 UTC (rev 284942)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/GraphicsContextGL.h	2021-10-27 21:05:30 UTC (rev 284943)
@@ -915,7 +915,7 @@
     // HostWindow might affect the decision which backend is to be used.
     WEBCORE_EXPORT static RefPtr<GraphicsContextGL> create(const GraphicsContextGLAttributes&, HostWindow*);
 
-    GraphicsContextGL(GraphicsContextGLAttributes, GraphicsContextGL* sharedContext = nullptr);
+    GraphicsContextGL(GraphicsContextGLAttributes);
     virtual ~GraphicsContextGL() = default;
 
     void addClient(Client& client) { m_clients.add(&client); }

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp (284942 => 284943)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp	2021-10-27 21:05:24 UTC (rev 284942)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp	2021-10-27 21:05:30 UTC (rev 284943)
@@ -2844,15 +2844,6 @@
     gl::MultiDrawElementsInstancedANGLE(mode, counts.data, type, pointers.data(), instanceCounts.data, drawcount);
 }
 
-#if ENABLE(VIDEO) && USE(AVFOUNDATION)
-GraphicsContextGLCV* GraphicsContextGLOpenGL::asCV()
-{
-    if (!m_cv)
-        m_cv = makeUnique<GraphicsContextGLCVANGLE>(*this);
-    return m_cv.get();
-}
-#endif
-
 bool GraphicsContextGLOpenGL::waitAndUpdateOldestFrame()
 {
     size_t oldestFrameCompletionFence = m_oldestFrameCompletionFence++ % maxPendingFrames;

Added: branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/ANGLEUtilitiesCocoa.cpp (0 => 284943)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/ANGLEUtilitiesCocoa.cpp	                        (rev 0)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/ANGLEUtilitiesCocoa.cpp	2021-10-27 21:05:30 UTC (rev 284943)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ANGLEUtilitiesCocoa.h"
+
+#if ENABLE(WEBGL)
+
+#include "Logging.h"
+
+namespace WebCore {
+
+void* createPbufferAndAttachIOSurface(EGLDisplay display, EGLConfig config, GLenum target, EGLint usageHint, GLenum internalFormat, GLsizei width, GLsizei height, GLenum type, IOSurfaceRef surface, GLuint plane)
+{
+    auto eglTextureTarget = target == GL_TEXTURE_RECTANGLE_ANGLE ? EGL_TEXTURE_RECTANGLE_ANGLE : EGL_TEXTURE_2D;
+
+    const EGLint surfaceAttributes[] = {
+        EGL_WIDTH, width,
+        EGL_HEIGHT, height,
+        EGL_IOSURFACE_PLANE_ANGLE, static_cast<EGLint>(plane),
+        EGL_TEXTURE_TARGET, static_cast<EGLint>(eglTextureTarget),
+        EGL_TEXTURE_INTERNAL_FORMAT_ANGLE, static_cast<EGLint>(internalFormat),
+        EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
+        EGL_TEXTURE_TYPE_ANGLE, static_cast<EGLint>(type),
+        // Only has an effect on the iOS Simulator.
+        EGL_IOSURFACE_USAGE_HINT_ANGLE, usageHint,
+        EGL_NONE, EGL_NONE
+    };
+
+    EGLSurface pbuffer = EGL_CreatePbufferFromClientBuffer(display, EGL_IOSURFACE_ANGLE, surface, config, surfaceAttributes);
+    if (!pbuffer)
+        return nullptr;
+
+    if (!EGL_BindTexImage(display, pbuffer, EGL_BACK_BUFFER)) {
+        EGL_DestroySurface(display, pbuffer);
+        return nullptr;
+    }
+
+    return pbuffer;
+}
+
+void destroyPbufferAndDetachIOSurface(EGLDisplay display, void* handle)
+{
+    EGL_ReleaseTexImage(display, handle, EGL_BACK_BUFFER);
+    EGL_DestroySurface(display, handle);
+}
+
+}
+
+#endif

Added: branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/ANGLEUtilitiesCocoa.h (0 => 284943)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/ANGLEUtilitiesCocoa.h	                        (rev 0)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/ANGLEUtilitiesCocoa.h	2021-10-27 21:05:30 UTC (rev 284943)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBGL)
+
+#include "ANGLEHeaders.h"
+
+typedef struct __IOSurface *IOSurfaceRef;
+
+namespace WebCore {
+
+// Returns a handle which, if non-null, must be released with destroyPbufferAndDetachIOSurface().
+void* createPbufferAndAttachIOSurface(EGLDisplay, EGLConfig, GLenum target, EGLint usageHint, GLenum internalFormat, GLsizei width, GLsizei height, GLenum type, IOSurfaceRef, GLuint plane);
+
+void destroyPbufferAndDetachIOSurface(EGLDisplay, void* handle);
+
+}
+
+#endif

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm (284942 => 284943)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm	2021-10-27 21:05:24 UTC (rev 284942)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm	2021-10-27 21:05:30 UTC (rev 284943)
@@ -28,6 +28,7 @@
 #if ENABLE(WEBGL)
 #import "GraphicsContextGLOpenGL.h"
 
+#import "ANGLEUtilitiesCocoa.h"
 #import "CVUtilities.h"
 #import "ExtensionsGLANGLE.h"
 #import "GraphicsContextGLANGLEUtilities.h"
@@ -48,7 +49,7 @@
 #endif
 
 #if ENABLE(VIDEO) && USE(AVFOUNDATION)
-#include "GraphicsContextGLCV.h"
+#include "GraphicsContextGLCVANGLE.h"
 #endif
 
 #if ENABLE(MEDIA_STREAM)
@@ -198,7 +199,7 @@
     if (GraphicsContextGLOpenGLManager::sharedManager().hasTooManyContexts())
         return nullptr;
 
-    RefPtr<GraphicsContextGLOpenGL> context = adoptRef(new GraphicsContextGLOpenGL(attrs, hostWindow, nullptr, nullptr));
+    RefPtr<GraphicsContextGLOpenGL> context = adoptRef(new GraphicsContextGLOpenGL(attrs, hostWindow, nullptr));
 
     if (!context->m_contextObj)
         return nullptr;
@@ -208,23 +209,13 @@
     return context;
 }
 
-Ref<GraphicsContextGLOpenGL> GraphicsContextGLOpenGL::createShared(GraphicsContextGLOpenGL& sharedContext)
-{
-
-    auto context = adoptRef(*new GraphicsContextGLOpenGL(sharedContext.contextAttributes(), nullptr, &sharedContext, nullptr));
-
-    GraphicsContextGLOpenGLManager::sharedManager().addContext(context.ptr());
-
-    return context;
-}
-
 Ref<GraphicsContextGLOpenGL> GraphicsContextGLOpenGL::createForGPUProcess(const GraphicsContextGLAttributes& attrs, GraphicsContextGLIOSurfaceSwapChain* swapChain)
 {
-    return adoptRef(*new GraphicsContextGLOpenGL(attrs, nullptr, nullptr, swapChain));
+    return adoptRef(*new GraphicsContextGLOpenGL(attrs, nullptr, swapChain));
 }
 
-GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attrs, HostWindow*, GraphicsContextGLOpenGL* sharedContext, GraphicsContextGLIOSurfaceSwapChain* swapChain)
-    : GraphicsContextGL(attrs, sharedContext)
+GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attrs, HostWindow*, GraphicsContextGLIOSurfaceSwapChain* swapChain)
+    : GraphicsContextGL(attrs)
 {
     m_isForWebGL2 = attrs.webGLVersion == GraphicsContextGLWebGLVersion::WebGL2;
     if (attrs.useMetal && !platformSupportsMetal(m_isForWebGL2)) {
@@ -295,21 +286,13 @@
         eglContextAttributes.append(EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE);
         eglContextAttributes.append(EGL_FALSE);
     }
-    if (!sharedContext) {
-        // The shared context is only non-null when creating a context
-        // on behalf of the VideoTextureCopier. WebGL-specific rendering
-        // feedback loop validation does not work in multi-context
-        // scenarios, and must be disabled for the VideoTextureCopier's
-        // context.
-        eglContextAttributes.append(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE);
-        eglContextAttributes.append(EGL_TRUE);
-        // WebGL requires that all resources are cleared at creation.
-        // FIXME: performing robust resource initialization in the VideoTextureCopier adds a large amount of overhead
-        // so it would be nice to avoid that there (we should always be touching every pixel as we copy).
-        eglContextAttributes.append(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE);
-        eglContextAttributes.append(EGL_TRUE);
-    }
+    eglContextAttributes.append(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE);
+    eglContextAttributes.append(EGL_TRUE);
 
+    // WebGL requires that all resources are cleared at creation.
+    eglContextAttributes.append(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE);
+    eglContextAttributes.append(EGL_TRUE);
+
     // WebGL doesn't allow client arrays.
     eglContextAttributes.append(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE);
     eglContextAttributes.append(EGL_FALSE);
@@ -319,15 +302,13 @@
 
     eglContextAttributes.append(EGL_NONE);
 
-    m_contextObj = EGL_CreateContext(m_displayObj, m_configObj, sharedContext ? static_cast<EGLContext>(sharedContext->m_contextObj) : EGL_NO_CONTEXT, eglContextAttributes.data());
-    if (m_contextObj == EGL_NO_CONTEXT) {
+    m_contextObj = EGL_CreateContext(m_displayObj, m_configObj, EGL_NO_CONTEXT, eglContextAttributes.data());
+    if (m_contextObj == EGL_NO_CONTEXT || !makeCurrent(m_displayObj, m_contextObj)) {
         LOG(WebGL, "EGLContext Initialization failed.");
         return;
     }
     LOG(WebGL, "Got EGLContext");
 
-    EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, m_contextObj);
-
     if (m_isForWebGL2)
         gl::Enable(GraphicsContextGL::PRIMITIVE_RESTART_FIXED_INDEX);
 
@@ -465,7 +446,7 @@
             EGL_DestroySurface(m_displayObj, contentsHandle);
     }
     if (m_contextObj) {
-        clearCurrentContext();
+        makeCurrent(m_displayObj, EGL_NO_CONTEXT);
         EGL_DestroyContext(m_displayObj, m_contextObj);
     }
     ASSERT(currentContext != this);
@@ -529,13 +510,6 @@
     return true;
 }
 
-void GraphicsContextGLOpenGL::clearCurrentContext()
-{
-    EGLBoolean result = EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
-    ASSERT_UNUSED(result, result);
-    currentContext = nullptr;
-}
-
 #if PLATFORM(IOS_FAMILY)
 bool GraphicsContextGLOpenGL::releaseCurrentContext(ReleaseBehavior releaseBehavior)
 {
@@ -581,7 +555,7 @@
         LOG(WebGL, "Pretending the GPU has reset (%p). Lose the context.", this);
         m_failNextStatusCheck = false;
         forceContextLost();
-        clearCurrentContext();
+        makeCurrent(m_displayObj, EGL_NO_CONTEXT);
         return;
     }
 
@@ -682,25 +656,20 @@
     return true;
 }
 
+bool GraphicsContextGLOpenGL::makeCurrent(PlatformGraphicsContextGLDisplay display, PlatformGraphicsContextGL context)
+{
+    currentContext = nullptr;
+    return EGL_MakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, context);
+}
+
 void* GraphicsContextGLOpenGL::createPbufferAndAttachIOSurface(GCGLenum target, PbufferAttachmentUsage usage, GCGLenum internalFormat, GCGLsizei width, GCGLsizei height, GCGLenum type, IOSurfaceRef surface, GCGLuint plane)
 {
-    if (target != GraphicsContextGL::TEXTURE_RECTANGLE_ARB && target != GraphicsContextGL::TEXTURE_2D) {
+    if (target != GraphicsContextGLOpenGL::drawingBufferTextureTarget()) {
         LOG(WebGL, "Unknown texture target %d.", static_cast<int>(target));
         return nullptr;
     }
 
-    auto eglTextureTarget = [&] () -> EGLint {
-        if (target == GraphicsContextGL::TEXTURE_RECTANGLE_ARB)
-            return EGL_TEXTURE_RECTANGLE_ANGLE;
-        return EGL_TEXTURE_2D;
-    }();
-
-    if (eglTextureTarget != GraphicsContextGLOpenGL::EGLDrawingBufferTextureTarget()) {
-        LOG(WebGL, "Mismatch in EGL texture target: %d should be %d.", static_cast<int>(target), GraphicsContextGLOpenGL::EGLDrawingBufferTextureTarget());
-        return nullptr;
-    }
-
-    auto usageHintAngle = [&] () -> EGLint {
+    auto usageHint = [&] () -> EGLint {
         if (usage == PbufferAttachmentUsage::Read)
             return EGL_IOSURFACE_READ_HINT_ANGLE;
         if (usage == PbufferAttachmentUsage::Write)
@@ -708,40 +677,12 @@
         return EGL_IOSURFACE_READ_HINT_ANGLE | EGL_IOSURFACE_WRITE_HINT_ANGLE;
     }();
 
-    const EGLint surfaceAttributes[] = {
-        EGL_WIDTH, width,
-        EGL_HEIGHT, height,
-        EGL_IOSURFACE_PLANE_ANGLE, static_cast<EGLint>(plane),
-        EGL_TEXTURE_TARGET, static_cast<EGLint>(eglTextureTarget),
-        EGL_TEXTURE_INTERNAL_FORMAT_ANGLE, static_cast<EGLint>(internalFormat),
-        EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
-        EGL_TEXTURE_TYPE_ANGLE, static_cast<EGLint>(type),
-        // Only has an effect on the iOS Simulator.
-        EGL_IOSURFACE_USAGE_HINT_ANGLE, usageHintAngle,
-        EGL_NONE, EGL_NONE
-    };
-
-    auto display = platformDisplay();
-    EGLSurface pbuffer = EGL_CreatePbufferFromClientBuffer(display, EGL_IOSURFACE_ANGLE, surface, platformConfig(), surfaceAttributes);
-    if (!pbuffer) {
-        LOG(WebGL, "EGL_CreatePbufferFromClientBuffer failed.");
-        return nullptr;
-    }
-
-    if (!EGL_BindTexImage(display, pbuffer, EGL_BACK_BUFFER)) {
-        LOG(WebGL, "EGL_BindTexImage failed.");
-        EGL_DestroySurface(display, pbuffer);
-        return nullptr;
-    }
-
-    return pbuffer;
+    return WebCore::createPbufferAndAttachIOSurface(m_displayObj, m_configObj, target, usageHint, internalFormat, width, height, type, surface, plane);
 }
 
 void GraphicsContextGLOpenGL::destroyPbufferAndDetachIOSurface(void* handle)
 {
-    auto display = platformDisplay();
-    EGL_ReleaseTexImage(display, handle, EGL_BACK_BUFFER);
-    EGL_DestroySurface(display, handle);
+    WebCore::destroyPbufferAndDetachIOSurface(m_displayObj, handle);
 }
 
 #if !PLATFORM(IOS_FAMILY_SIMULATOR)
@@ -849,6 +790,16 @@
     }
 }
 
+
+#if ENABLE(VIDEO) && USE(AVFOUNDATION)
+GraphicsContextGLCV* GraphicsContextGLOpenGL::asCV()
+{
+    if (!m_cv)
+        m_cv = GraphicsContextGLCVANGLE::create(*this);
+    return m_cv.get();
+}
+#endif
+
 std::optional<PixelBuffer> GraphicsContextGLOpenGL::readCompositedResults()
 {
     auto& displayBuffer = m_swapChain->displayBuffer();

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.cpp (284942 => 284943)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.cpp	2021-10-27 21:05:24 UTC (rev 284942)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.cpp	2021-10-27 21:05:30 UTC (rev 284943)
@@ -28,13 +28,15 @@
 
 #if ENABLE(WEBGL) && ENABLE(VIDEO) && USE(AVFOUNDATION)
 
-#include "ANGLEHeaders.h"
+#include "ANGLEUtilitiesCocoa.h"
 #include "CoreVideoSoftLink.h"
 #include "FourCC.h"
+#include "GraphicsContextGLOpenGL.h"
 #include "Logging.h"
 #include <pal/spi/cf/CoreVideoSPI.h>
 #include <pal/spi/cocoa/IOSurfaceSPI.h>
 #include <wtf/NeverDestroyed.h>
+#include <wtf/Scope.h>
 #include <wtf/StdMap.h>
 #include <wtf/text/StringBuilder.h>
 
@@ -228,9 +230,9 @@
 
     constexpr YCbCrMatrix(PixelRange, GLfloat cbCoefficient, GLfloat crCoefficient);
 
-    operator GCGLSpan<const GLfloat, 16>() const
+    operator const GLfloat*() const
     {
-        return makeGCGLSpan<16>(&rows[0][0]);
+        return &rows[0][0];
     }
 
     constexpr GLfloatColor operator*(const GLfloatColor&) const;
@@ -302,7 +304,7 @@
     );
 }
 
-static GCGLSpan<const GLfloat, 16> YCbCrToRGBMatrixForRangeAndTransferFunction(PixelRange range, TransferFunctionCV transferFunction)
+static const GLfloat* YCbCrToRGBMatrixForRangeAndTransferFunction(PixelRange range, TransferFunctionCV transferFunction)
 {
     using MapKey = std::pair<PixelRange, TransferFunctionCV>;
     using MatrixMap = StdMap<MapKey, const YCbCrMatrix&>;
@@ -428,169 +430,135 @@
     return iterator->second;
 }
 
-namespace {
-
-// Scoped holder of a cleanup function. Calls the function at the end of the scope.
-// Note: Releases the reference to the function only after the scope, not
-// at the time of `reset()` call.
-template <typename F>
-class ScopedCleanup {
-public:
-    explicit ScopedCleanup(F&& function)
-        : m_function(WTFMove(function))
-    {
-    }
-    ~ScopedCleanup()
-    {
-        if (m_shouldCall)
-            m_function();
-    }
-    void reset() { m_shouldCall = false; }
-private:
-    bool m_shouldCall = true;
-    const F m_function;
-};
-
-}
-
-GraphicsContextGLCVANGLE::GraphicsContextGLCVANGLE(GraphicsContextGLOpenGL& context)
-    : m_context(GraphicsContextGLOpenGL::createShared(context))
-    , m_framebuffer(m_context->createFramebuffer())
+std::unique_ptr<GraphicsContextGLCVANGLE> GraphicsContextGLCVANGLE::create(GraphicsContextGLOpenGL& context)
 {
+    std::unique_ptr<GraphicsContextGLCVANGLE> cv { new GraphicsContextGLCVANGLE(context) };
+    if (!cv->m_context)
+        return nullptr;
+    return cv;
 }
 
 GraphicsContextGLCVANGLE::~GraphicsContextGLCVANGLE()
 {
-    if (m_yuvVertexBuffer)
-        m_context->deleteBuffer(m_yuvVertexBuffer);
-    if (m_yuvProgram)
-        m_context->deleteProgram(m_yuvProgram);
-    m_context->deleteFramebuffer(m_framebuffer);
+    if (!m_context || !GraphicsContextGLOpenGL::makeCurrent(m_display, m_context))
+        return;
+    gl::DeleteBuffers(1, &m_yuvVertexBuffer);
+    gl::DeleteFramebuffers(1, &m_framebuffer);
+    EGL_DestroyContext(m_display, m_context);
 }
 
-bool GraphicsContextGLCVANGLE::initializeUVContextObjects()
+GraphicsContextGLCVANGLE::GraphicsContextGLCVANGLE(GraphicsContextGLOpenGL& owner)
+    : m_owner(owner)
 {
-    const bool useTexture2D = GraphicsContextGLOpenGL::drawingBufferTextureTarget() == GraphicsContextGL::TEXTURE_2D;
+    // Create compatible context that shares state with owner, but one that does not
+    // have robustness or WebGL compatibility.
+    const EGLint contextAttributes[] = {
+        EGL_CONTEXT_CLIENT_VERSION,
+        owner.m_isForWebGL2 ? 3 : 2,
+        EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE,
+        EGL_FALSE,
+        EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE,
+        EGL_FALSE,
+        EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM,
+        EGL_FALSE,
+        EGL_NONE
+    };
+    EGLDisplay display = owner.platformDisplay();
+    EGLConfig config = owner.platformConfig();
+    EGLContext context = EGL_CreateContext(display, config, owner.m_contextObj, contextAttributes);
+    if (context == EGL_NO_CONTEXT)
+        return;
+    GraphicsContextGLOpenGL::makeCurrent(display, context);
 
-    PlatformGLObject vertexShader = m_context->createShader(GraphicsContextGL::VERTEX_SHADER);
-    if (useTexture2D)
-        m_context->shaderSource(vertexShader, s_yuvVertexShaderTexture2D);
-    else
-        m_context->shaderSource(vertexShader, s_yuvVertexShaderTextureRectangle);
+    auto contextCleanup = makeScopeExit([display, context] {
+        GraphicsContextGLOpenGL::makeCurrent(display, EGL_NO_CONTEXT);
+        EGL_DestroyContext(display, context);
+    });
 
-    m_context->compileShaderDirect(vertexShader);
+    const bool useTexture2D = GraphicsContextGLOpenGL::drawingBufferTextureTarget() == GL_TEXTURE_2D;
 
-    GCGLint status = m_context->getShaderi(vertexShader, GraphicsContextGL::COMPILE_STATUS);
-    if (!status) {
-        LOG(WebGL, "GraphicsContextGLCVANGLE::initializeUVContextObjects(%p) - Vertex shader failed to compile.", this);
-        m_context->deleteShader(vertexShader);
-        return false;
+#if PLATFORM(MAC) || PLATFORM(MACCATALYST)
+    if (!useTexture2D) {
+        gl::RequestExtensionANGLE("GL_ANGLE_texture_rectangle");
+        gl::RequestExtensionANGLE("GL_EXT_texture_format_BGRA8888");
+        if (gl::GetError() != GL_NO_ERROR)
+            return;
     }
+#endif
 
-    PlatformGLObject fragmentShader = m_context->createShader(GraphicsContextGL::FRAGMENT_SHADER);
-    if (useTexture2D)
-        m_context->shaderSource(fragmentShader, s_yuvFragmentShaderTexture2D);
-    else
-        m_context->shaderSource(fragmentShader, s_yuvFragmentShaderTextureRectangle);
+    GLint vertexShader = gl::CreateShader(GL_VERTEX_SHADER);
+    GLint fragmentShader = gl::CreateShader(GL_FRAGMENT_SHADER);
+    GLuint yuvProgram = gl::CreateProgram();
+    auto programCleanup = makeScopeExit([vertexShader, fragmentShader, yuvProgram] {
+        gl::DeleteShader(vertexShader);
+        gl::DeleteShader(fragmentShader);
+        gl::DeleteProgram(yuvProgram);
+    });
+    // These are written so strlen might be compile-time.
+    GLint vsLength = useTexture2D ? s_yuvVertexShaderTexture2D.length() : s_yuvVertexShaderTextureRectangle.length();
+    GLint fsLength = useTexture2D ? s_yuvFragmentShaderTexture2D.length() : s_yuvFragmentShaderTextureRectangle.length();
+    const char* vertexShaderSource = useTexture2D ? s_yuvVertexShaderTexture2D : s_yuvVertexShaderTextureRectangle;
+    const char* fragmentShaderSource = useTexture2D ? s_yuvFragmentShaderTexture2D : s_yuvFragmentShaderTextureRectangle;
 
-    m_context->compileShaderDirect(fragmentShader);
+    gl::ShaderSource(vertexShader, 1, &vertexShaderSource, &vsLength);
+    gl::ShaderSource(fragmentShader, 1, &fragmentShaderSource, &fsLength);
+    gl::CompileShader(vertexShader);
+    gl::CompileShader(fragmentShader);
+    gl::AttachShader(yuvProgram, vertexShader);
+    gl::AttachShader(yuvProgram, fragmentShader);
+    gl::LinkProgram(yuvProgram);
+    // Link status is checked afterwards for theoretical parallel compilation benefit.
 
-    status = m_context->getShaderi(fragmentShader, GraphicsContextGL::COMPILE_STATUS);
-    if (!status) {
-        LOG(WebGL, "GraphicsContextGLCVANGLE::initializeUVContextObjects(%p) - Fragment shader failed to compile.", this);
-        m_context->deleteShader(vertexShader);
-        m_context->deleteShader(fragmentShader);
-        return false;
-    }
+    GLuint yuvVertexBuffer = 0;
+    gl::GenBuffers(1, &yuvVertexBuffer);
+    auto yuvVertexBufferCleanup = makeScopeExit([yuvVertexBuffer] {
+        gl::DeleteBuffers(1, &yuvVertexBuffer);
+    });
+    float vertices[12] = { -1, -1, 1, -1, 1, 1, 1, 1, -1, 1, -1, -1 };
+    gl::BindBuffer(GL_ARRAY_BUFFER, yuvVertexBuffer);
+    gl::BufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
 
-    m_yuvProgram = m_context->createProgram();
-    m_context->attachShader(m_yuvProgram, vertexShader);
-    m_context->attachShader(m_yuvProgram, fragmentShader);
-    m_context->linkProgram(m_yuvProgram);
+    GLuint framebuffer = 0;
+    gl::GenFramebuffers(1, &framebuffer);
+    auto framebufferCleanup = makeScopeExit([framebuffer] {
+        gl::DeleteFramebuffers(1, &framebuffer);
+    });
 
-    status = m_context->getProgrami(m_yuvProgram, GraphicsContextGL::LINK_STATUS);
+    GLint status = 0;
+    gl::GetProgramivRobustANGLE(yuvProgram, GL_LINK_STATUS, 1, nullptr, &status);
     if (!status) {
-        LOG(WebGL, "GraphicsContextGLCVANGLE::initializeUVContextObjects(%p) - Program failed to link.", this);
-        m_context->deleteShader(vertexShader);
-        m_context->deleteShader(fragmentShader);
-        m_context->deleteProgram(m_yuvProgram);
-        m_yuvProgram = 0;
-        return false;
+        GLint vsStatus = 0;
+        gl::GetShaderivRobustANGLE(vertexShader, GL_COMPILE_STATUS, 1, nullptr, &vsStatus);
+        GLint fsStatus = 0;
+        gl::GetShaderivRobustANGLE(fragmentShader, GL_COMPILE_STATUS, 1, nullptr, &fsStatus);
+        LOG(WebGL, "GraphicsContextGLCVANGLE(%p) - YUV program failed to link: %d, %d, %d.", this, status, vsStatus, fsStatus);
+        return;
     }
-
-    m_yTextureUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_yTexture"_s);
-    m_uvTextureUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_uvTexture"_s);
-    m_colorMatrixUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_colorMatrix"_s);
-    m_yuvFlipYUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_flipY"_s);
-    m_yTextureSizeUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_yTextureSize"_s);
-    m_uvTextureSizeUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_uvTextureSize"_s);
-    m_yuvPositionAttributeLocation = m_context->getAttribLocationDirect(m_yuvProgram, "a_position"_s);
-
-    m_context->detachShader(m_yuvProgram, vertexShader);
-    m_context->detachShader(m_yuvProgram, fragmentShader);
-    m_context->deleteShader(vertexShader);
-    m_context->deleteShader(fragmentShader);
-
-    m_yuvVertexBuffer = m_context->createBuffer();
-    float vertices[12] = { -1, -1, 1, -1, 1, 1, 1, 1, -1, 1, -1, -1 };
-
-    m_context->bindBuffer(GraphicsContextGL::ARRAY_BUFFER, m_yuvVertexBuffer);
-    m_context->bufferData(GraphicsContextGL::ARRAY_BUFFER, GCGLSpan<const GCGLvoid>(vertices, sizeof(vertices)), GraphicsContextGL::STATIC_DRAW);
-    m_context->enableVertexAttribArray(m_yuvPositionAttributeLocation);
-    m_context->vertexAttribPointer(m_yuvPositionAttributeLocation, 2, GraphicsContextGL::FLOAT, false, 0, 0);
-
-    return true;
+    contextCleanup.release();
+    yuvVertexBufferCleanup.release();
+    framebufferCleanup.release();
+    m_display = display;
+    m_context = context;
+    m_config = config;
+    m_yuvVertexBuffer = yuvVertexBuffer;
+    m_framebuffer = framebuffer;
+    m_yTextureUniformLocation = gl::GetUniformLocation(yuvProgram, "u_yTexture");
+    m_uvTextureUniformLocation = gl::GetUniformLocation(yuvProgram, "u_uvTexture");
+    m_colorMatrixUniformLocation = gl::GetUniformLocation(yuvProgram, "u_colorMatrix");
+    m_yuvFlipYUniformLocation = gl::GetUniformLocation(yuvProgram, "u_flipY");
+    m_yTextureSizeUniformLocation = gl::GetUniformLocation(yuvProgram, "u_yTextureSize");
+    m_uvTextureSizeUniformLocation = gl::GetUniformLocation(yuvProgram, "u_uvTextureSize");
+    m_yuvPositionAttributeLocation = gl::GetAttribLocation(yuvProgram, "a_position");
+    // Program is deleted by the cleanup while the program binary stays in use.
+    gl::UseProgram(yuvProgram);
+    gl::EnableVertexAttribArray(m_yuvPositionAttributeLocation);
+    gl::VertexAttribPointer(m_yuvPositionAttributeLocation, 2, GL_FLOAT, false, 0, 0);
+    gl::ClearColor(0, 0, 0, 0);
+    gl::BindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
 }
 
-void* GraphicsContextGLCVANGLE::attachIOSurfaceToTexture(GCGLenum target, GCGLenum internalFormat, GCGLsizei width, GCGLsizei height, GCGLenum type, IOSurfaceRef surface, GCGLuint plane)
+bool GraphicsContextGLCVANGLE::copyPixelBufferToTexture(CVPixelBufferRef image, PlatformGLObject outputTexture, GLint level, GLenum internalFormat, GLenum format, GLenum type, FlipY flipY)
 {
-    auto display = m_context->platformDisplay();
-    EGLint eglTextureTarget = 0;
-
-    if (target == GraphicsContextGL::TEXTURE_RECTANGLE_ARB)
-        eglTextureTarget = EGL_TEXTURE_RECTANGLE_ANGLE;
-    else if (target == GraphicsContextGL::TEXTURE_2D)
-        eglTextureTarget = EGL_TEXTURE_2D;
-    else {
-        LOG(WebGL, "Unknown texture target %d.", static_cast<int>(target));
-        return nullptr;
-    }
-    if (eglTextureTarget != GraphicsContextGLOpenGL::EGLDrawingBufferTextureTarget()) {
-        LOG(WebGL, "Mismatch in EGL texture target %d.", static_cast<int>(target));
-        return nullptr;
-    }
-
-    const EGLint surfaceAttributes[] = {
-        EGL_WIDTH, width,
-        EGL_HEIGHT, height,
-        EGL_IOSURFACE_PLANE_ANGLE, static_cast<EGLint>(plane),
-        EGL_TEXTURE_TARGET, static_cast<EGLint>(eglTextureTarget),
-        EGL_TEXTURE_INTERNAL_FORMAT_ANGLE, static_cast<EGLint>(internalFormat),
-        EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
-        EGL_TEXTURE_TYPE_ANGLE, static_cast<EGLint>(type),
-        // Only has an effect on the iOS Simulator.
-        EGL_IOSURFACE_USAGE_HINT_ANGLE, EGL_IOSURFACE_READ_HINT_ANGLE,
-        EGL_NONE, EGL_NONE
-    };
-    EGLSurface pbuffer = EGL_CreatePbufferFromClientBuffer(display, EGL_IOSURFACE_ANGLE, surface, m_context->platformConfig(), surfaceAttributes);
-    if (!pbuffer)
-        return nullptr;
-    if (!EGL_BindTexImage(display, pbuffer, EGL_BACK_BUFFER)) {
-        EGL_DestroySurface(display, pbuffer);
-        return nullptr;
-    }
-    return pbuffer;
-}
-
-void GraphicsContextGLCVANGLE::detachIOSurfaceFromTexture(void* handle)
-{
-    auto display = m_context->platformDisplay();
-    EGL_ReleaseTexImage(display, handle, EGL_BACK_BUFFER);
-    EGL_DestroySurface(display, handle);
-}
-
-bool GraphicsContextGLCVANGLE::copyPixelBufferToTexture(CVPixelBufferRef image, PlatformGLObject outputTexture, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, FlipY flipY)
-{
     // FIXME: This currently only supports '420v' and '420f' pixel formats. Investigate supporting more pixel formats.
     OSType pixelFormat = CVPixelBufferGetPixelFormatType(image);
     if (pixelFormat != kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
@@ -609,53 +577,44 @@
 
     auto newSurfaceSeed = IOSurfaceGetSeed(surface);
     if (flipY == m_lastFlipY
-        && surface == m_lastSurface 
+        && surface == m_lastSurface
         && newSurfaceSeed == m_lastSurfaceSeed
-        && lastTextureSeed(outputTexture) == m_context->textureSeed(outputTexture)) {
+        && lastTextureSeed(outputTexture) == m_owner.textureSeed(outputTexture)) {
         // If the texture hasn't been modified since the last time we copied to it, and the
         // image hasn't been modified since the last time it was copied, this is a no-op.
         return true;
     }
+    if (!m_context || !GraphicsContextGLOpenGL::makeCurrent(m_display, m_context))
+        return false;
 
-    if (!m_yuvProgram) {
-        if (!initializeUVContextObjects()) {
-            LOG(WebGL, "GraphicsContextGLCVANGLE::copyVideoTextureToPlatformTexture(%p) - Unable to initialize OpenGL context objects.", this);
-            return false;
-        }
-    }
     size_t width = CVPixelBufferGetWidth(image);
     size_t height = CVPixelBufferGetHeight(image);
 
-    m_context->bindFramebuffer(GraphicsContextGL::FRAMEBUFFER, m_framebuffer);
+    gl::Viewport(0, 0, width, height);
 
     // The outputTexture might contain uninitialized content on early-outs. Clear it in cases
     // autoClearTextureOnError is not reset.
-    auto autoClearTextureOnError = ScopedCleanup {
-        [outputTexture, level, internalFormat, format, type, context = m_context.ptr()] {
-            context->bindTexture(GraphicsContextGL::TEXTURE_2D, outputTexture);
-            context->texImage2DDirect(GL_TEXTURE_2D, level, internalFormat, 0, 0, 0, format, type, nullptr);
-            context->bindTexture(GraphicsContextGL::TEXTURE_2D, 0);
-        }
-    };
+    auto autoClearTextureOnError = makeScopeExit([outputTexture, level, internalFormat, format, type] {
+        gl::BindTexture(GL_TEXTURE_2D, outputTexture);
+        gl::TexImage2D(GL_TEXTURE_2D, level, internalFormat, 0, 0, 0, format, type, nullptr);
+        gl::BindTexture(GL_TEXTURE_2D, 0);
+    });
     // Allocate memory for the output texture.
-    m_context->bindTexture(GraphicsContextGL::TEXTURE_2D, outputTexture);
-    m_context->texParameteri(GraphicsContextGL::TEXTURE_2D, GraphicsContextGL::TEXTURE_MAG_FILTER, GraphicsContextGL::LINEAR);
-    m_context->texParameteri(GraphicsContextGL::TEXTURE_2D, GraphicsContextGL::TEXTURE_MIN_FILTER, GraphicsContextGL::LINEAR);
-    m_context->texParameteri(GraphicsContextGL::TEXTURE_2D, GraphicsContextGL::TEXTURE_WRAP_S, GraphicsContextGL::CLAMP_TO_EDGE);
-    m_context->texParameteri(GraphicsContextGL::TEXTURE_2D, GraphicsContextGL::TEXTURE_WRAP_T, GraphicsContextGL::CLAMP_TO_EDGE);
-    m_context->texImage2DDirect(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type, nullptr);
+    gl::BindTexture(GL_TEXTURE_2D, outputTexture);
+    gl::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+    gl::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+    gl::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+    gl::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+    gl::TexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type, nullptr);
 
-    m_context->framebufferTexture2D(GraphicsContextGL::FRAMEBUFFER, GraphicsContextGL::COLOR_ATTACHMENT0, GraphicsContextGL::TEXTURE_2D, outputTexture, level);
-    GCGLenum status = m_context->checkFramebufferStatus(GraphicsContextGL::FRAMEBUFFER);
-    if (status != GraphicsContextGL::FRAMEBUFFER_COMPLETE) {
+    gl::FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, outputTexture, level);
+    GLenum status = gl::CheckFramebufferStatus(GL_FRAMEBUFFER);
+    if (status != GL_FRAMEBUFFER_COMPLETE) {
         LOG(WebGL, "GraphicsContextGLCVANGLE::copyVideoTextureToPlatformTexture(%p) - Unable to create framebuffer for outputTexture.", this);
         return false;
     }
-    m_context->bindTexture(GraphicsContextGL::TEXTURE_2D, 0);
+    gl::BindTexture(GL_TEXTURE_2D, 0);
 
-    m_context->useProgram(m_yuvProgram);
-    m_context->viewport(0, 0, width, height);
-
     // Bind and set up the textures for the video source.
     auto yPlaneWidth = IOSurfaceGetWidthOfPlane(surface, 0);
     auto yPlaneHeight = IOSurfaceGetHeightOfPlane(surface, 0);
@@ -662,61 +621,64 @@
     auto uvPlaneWidth = IOSurfaceGetWidthOfPlane(surface, 1);
     auto uvPlaneHeight = IOSurfaceGetHeightOfPlane(surface, 1);
 
-    GCGLenum videoTextureTarget = GraphicsContextGLOpenGL::drawingBufferTextureTarget();
+    GLenum videoTextureTarget = GraphicsContextGLOpenGL::drawingBufferTextureTarget();
 
-    auto uvTexture = m_context->createTexture();
-    m_context->activeTexture(GraphicsContextGL::TEXTURE1);
-    m_context->bindTexture(videoTextureTarget, uvTexture);
-    m_context->texParameteri(videoTextureTarget, GraphicsContextGL::TEXTURE_MAG_FILTER, GraphicsContextGL::LINEAR);
-    m_context->texParameteri(videoTextureTarget, GraphicsContextGL::TEXTURE_MIN_FILTER, GraphicsContextGL::LINEAR);
-    m_context->texParameteri(videoTextureTarget, GraphicsContextGL::TEXTURE_WRAP_S, GraphicsContextGL::CLAMP_TO_EDGE);
-    m_context->texParameteri(videoTextureTarget, GraphicsContextGL::TEXTURE_WRAP_T, GraphicsContextGL::CLAMP_TO_EDGE);
-    auto uvHandle = attachIOSurfaceToTexture(videoTextureTarget, GraphicsContextGL::RG, uvPlaneWidth, uvPlaneHeight, GraphicsContextGL::UNSIGNED_BYTE, surface, 1);
-    if (!uvHandle) {
-        m_context->deleteTexture(uvTexture);
+    GLuint uvTexture = 0;
+    gl::GenTextures(1, &uvTexture);
+    auto uvTextureCleanup = makeScopeExit([uvTexture] {
+        gl::DeleteTextures(1, &uvTexture);
+    });
+    gl::ActiveTexture(GL_TEXTURE1);
+    gl::BindTexture(videoTextureTarget, uvTexture);
+    gl::TexParameteri(videoTextureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+    gl::TexParameteri(videoTextureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+    gl::TexParameteri(videoTextureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+    gl::TexParameteri(videoTextureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+    auto uvHandle = WebCore::createPbufferAndAttachIOSurface(m_display, m_config, videoTextureTarget, EGL_IOSURFACE_READ_HINT_ANGLE, GL_RG, uvPlaneWidth, uvPlaneHeight, GL_UNSIGNED_BYTE, surface, 1);
+    if (!uvHandle)
         return false;
-    }
+    auto uvHandleCleanup = makeScopeExit([display = m_display, uvHandle] {
+        WebCore::destroyPbufferAndDetachIOSurface(display, uvHandle);
+    });
 
-    auto yTexture = m_context->createTexture();
-    m_context->activeTexture(GraphicsContextGL::TEXTURE0);
-    m_context->bindTexture(videoTextureTarget, yTexture);
-    m_context->texParameteri(videoTextureTarget, GraphicsContextGL::TEXTURE_MAG_FILTER, GraphicsContextGL::LINEAR);
-    m_context->texParameteri(videoTextureTarget, GraphicsContextGL::TEXTURE_MIN_FILTER, GraphicsContextGL::LINEAR);
-    m_context->texParameteri(videoTextureTarget, GraphicsContextGL::TEXTURE_WRAP_S, GraphicsContextGL::CLAMP_TO_EDGE);
-    m_context->texParameteri(videoTextureTarget, GraphicsContextGL::TEXTURE_WRAP_T, GraphicsContextGL::CLAMP_TO_EDGE);
-    auto yHandle = attachIOSurfaceToTexture(videoTextureTarget, GraphicsContextGL::RED, yPlaneWidth, yPlaneHeight, GraphicsContextGL::UNSIGNED_BYTE, surface, 0);
-    if (!yHandle) {
-        m_context->deleteTexture(yTexture);
-        m_context->deleteTexture(uvTexture);
+    GLuint yTexture = 0;
+    gl::GenTextures(1, &yTexture);
+    auto yTextureCleanup = makeScopeExit([yTexture] {
+        gl::DeleteTextures(1, &yTexture);
+    });
+    gl::ActiveTexture(GL_TEXTURE0);
+    gl::BindTexture(videoTextureTarget, yTexture);
+    gl::TexParameteri(videoTextureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+    gl::TexParameteri(videoTextureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+    gl::TexParameteri(videoTextureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+    gl::TexParameteri(videoTextureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+    auto yHandle = WebCore::createPbufferAndAttachIOSurface(m_display, m_config, videoTextureTarget, EGL_IOSURFACE_READ_HINT_ANGLE, GL_RED, yPlaneWidth, yPlaneHeight, GL_UNSIGNED_BYTE, surface, 0);
+    if (!yHandle)
         return false;
-    }
+    auto yHandleCleanup = makeScopeExit([display = m_display, yHandle] {
+        destroyPbufferAndDetachIOSurface(display, yHandle);
+    });
 
     // Configure the drawing parameters.
-    m_context->uniform1i(m_yTextureUniformLocation, 0);
-    m_context->uniform1i(m_uvTextureUniformLocation, 1);
-    m_context->uniform1i(m_yuvFlipYUniformLocation, flipY == FlipY::Yes ? 1 : 0);
-    m_context->uniform2f(m_yTextureSizeUniformLocation, yPlaneWidth, yPlaneHeight);
-    m_context->uniform2f(m_uvTextureSizeUniformLocation, uvPlaneWidth, uvPlaneHeight);
+    gl::Uniform1i(m_yTextureUniformLocation, 0);
+    gl::Uniform1i(m_uvTextureUniformLocation, 1);
+    gl::Uniform1i(m_yuvFlipYUniformLocation, flipY == FlipY::Yes ? 1 : 0);
+    gl::Uniform2f(m_yTextureSizeUniformLocation, yPlaneWidth, yPlaneHeight);
+    gl::Uniform2f(m_uvTextureSizeUniformLocation, uvPlaneWidth, uvPlaneHeight);
 
     auto range = pixelRangeFromPixelFormat(pixelFormat);
     auto transferFunction = transferFunctionFromString((CFStringRef)CVBufferGetAttachment(image, kCVImageBufferYCbCrMatrixKey, nil));
     auto colorMatrix = YCbCrToRGBMatrixForRangeAndTransferFunction(range, transferFunction);
-    m_context->uniformMatrix4fv(m_colorMatrixUniformLocation, GL_FALSE, colorMatrix);
+    gl::UniformMatrix4fv(m_colorMatrixUniformLocation, 1, GL_FALSE, colorMatrix);
 
     // Do the actual drawing.
-    m_context->drawArrays(GraphicsContextGL::TRIANGLES, 0, 6);
+    gl::DrawArrays(GL_TRIANGLES, 0, 6);
 
-    // Clean-up.
-    m_context->deleteTexture(yTexture);
-    m_context->deleteTexture(uvTexture);
-    detachIOSurfaceFromTexture(yHandle);
-    detachIOSurfaceFromTexture(uvHandle);
-
     m_lastSurface = surface;
     m_lastSurfaceSeed = newSurfaceSeed;
-    m_lastTextureSeed.set(outputTexture, m_context->textureSeed(outputTexture));
+    m_lastTextureSeed.set(outputTexture, m_owner.textureSeed(outputTexture));
     m_lastFlipY = flipY;
-    autoClearTextureOnError.reset();
+    autoClearTextureOnError.release();
     return true;
 }
 

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.h (284942 => 284943)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.h	2021-10-27 21:05:24 UTC (rev 284942)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.h	2021-10-27 21:05:30 UTC (rev 284943)
@@ -27,24 +27,27 @@
 
 #if ENABLE(WEBGL) && ENABLE(VIDEO) && USE(AVFOUNDATION)
 
-#import "GraphicsContextGLCV.h"
-#import "GraphicsContextGLOpenGL.h"
+#include "GraphicsContextGLCV.h"
 
-#import <wtf/UnsafePointer.h>
+#include <memory>
+#include <wtf/UnsafePointer.h>
 
 namespace WebCore {
+class GraphicsContextGLOpenGL;
 
 // GraphicsContextGLCV implementation for ANGLE flavour of GraphicsContextGLOpenGL.
+// This class is part of the internal implementation of GraphicsContextGLOpenGL for ANGLE Cocoa.
 class GraphicsContextGLCVANGLE final : public GraphicsContextGLCV {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    GraphicsContextGLCVANGLE(GraphicsContextGLOpenGL&);
+    static std::unique_ptr<GraphicsContextGLCVANGLE> create(GraphicsContextGLOpenGL&);
+
     ~GraphicsContextGLCVANGLE() final;
 
     bool copyPixelBufferToTexture(CVPixelBufferRef, PlatformGLObject outputTexture, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, FlipY) final;
 
 private:
-    bool initializeUVContextObjects();
+    GraphicsContextGLCVANGLE(GraphicsContextGLOpenGL&);
 
     unsigned lastTextureSeed(GCGLuint texture)
     {
@@ -51,15 +54,12 @@
         return m_lastTextureSeed.get(texture);
     }
 
-    // Returns a handle which, if non-null, must be released via the
-    // detach call below.
-    void* attachIOSurfaceToTexture(GCGLenum target, GCGLenum internalFormat, GCGLsizei width, GCGLsizei height, GCGLenum type, IOSurfaceRef, GCGLuint plane);
-    void detachIOSurfaceFromTexture(void* handle);
+    GraphicsContextGLOpenGL& m_owner;
+    PlatformGraphicsContextGLDisplay m_display { nullptr };
+    PlatformGraphicsContextGL m_context { nullptr };
+    PlatformGraphicsContextGLConfig m_config { nullptr };
 
-    Ref<GraphicsContextGLOpenGL> m_context;
-
     PlatformGLObject m_framebuffer { 0 };
-    PlatformGLObject m_yuvProgram { 0 };
     PlatformGLObject m_yuvVertexBuffer { 0 };
     GCGLint m_yTextureUniformLocation { -1 };
     GCGLint m_uvTextureUniformLocation { -1 };

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h (284942 => 284943)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2021-10-27 21:05:24 UTC (rev 284942)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2021-10-27 21:05:30 UTC (rev 284943)
@@ -69,6 +69,7 @@
 OBJC_CLASS WebGLLayer;
 namespace WebCore {
 class GraphicsContextGLIOSurfaceSwapChain;
+class GraphicsContextGLCVANGLE;
 }
 #endif // PLATFORM(COCOA)
 
@@ -104,7 +105,6 @@
     virtual ~GraphicsContextGLOpenGL();
 
 #if PLATFORM(COCOA)
-    static Ref<GraphicsContextGLOpenGL> createShared(GraphicsContextGLOpenGL& sharedContext);
     static Ref<GraphicsContextGLOpenGL> createForGPUProcess(const GraphicsContextGLAttributes&, GraphicsContextGLIOSurfaceSwapChain*);
 
     CALayer* platformLayer() const final { return reinterpret_cast<CALayer*>(m_webGLLayer.get()); }
@@ -546,15 +546,14 @@
 
 private:
 #if PLATFORM(COCOA)
-    GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*, GraphicsContextGLOpenGL* sharedContext = nullptr, GraphicsContextGLIOSurfaceSwapChain* = nullptr);
+    GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*, GraphicsContextGLIOSurfaceSwapChain* = nullptr);
 #else
-    GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*, GraphicsContextGLOpenGL* sharedContext = nullptr);
+    GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*);
 #endif
 
     // Called once by all the public entry points that eventually call OpenGL.
     // Called once by all the public entry points of ExtensionsGL that eventually call OpenGL.
     bool makeContextCurrent() WARN_UNUSED_RETURN;
-    void clearCurrentContext();
 
     // Take into account the user's requested context creation attributes,
     // in particular stencil and antialias, and determine which could or
@@ -581,6 +580,8 @@
     bool reshapeDisplayBufferBacking();
     bool allocateAndBindDisplayBufferBacking();
     bool bindDisplayBufferBacking(std::unique_ptr<IOSurface> backing, void* pbuffer);
+    static bool makeCurrent(PlatformGraphicsContextGLDisplay, PlatformGraphicsContextGL);
+    friend class GraphicsContextGLCVANGLE;
 #endif
 #if USE(ANGLE)
     // Returns false if context should be lost due to timeout.
@@ -797,7 +798,7 @@
     ScopedHighPerformanceGPURequest m_highPerformanceGPURequest;
 #endif
 #if ENABLE(VIDEO) && USE(AVFOUNDATION)
-    std::unique_ptr<GraphicsContextGLCV> m_cv;
+    std::unique_ptr<GraphicsContextGLCVANGLE> m_cv;
 #endif
 #if USE(ANGLE)
     static constexpr size_t maxPendingFrames = 3;

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp (284942 => 284943)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp	2021-10-27 21:05:24 UTC (rev 284942)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp	2021-10-27 21:05:30 UTC (rev 284943)
@@ -104,10 +104,9 @@
 }
 
 #if USE(ANGLE)
-GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attributes, HostWindow*, GraphicsContextGLOpenGL* sharedContext)
-    : GraphicsContextGL(attributes, sharedContext)
+GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attributes, HostWindow*)
+    : GraphicsContextGL(attributes)
 {
-    ASSERT_UNUSED(sharedContext, !sharedContext);
 #if ENABLE(WEBGL2)
     m_isForWebGL2 = attributes.webGLVersion == GraphicsContextGLWebGLVersion::WebGL2;
 #endif
@@ -174,10 +173,9 @@
     gl::ClearColor(0, 0, 0, 0);
 }
 #else
-GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attributes, HostWindow*, GraphicsContextGLOpenGL* sharedContext)
-    : GraphicsContextGL(attributes, sharedContext)
+GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attributes, HostWindow*)
+    : GraphicsContextGL(attributes)
 {
-    ASSERT_UNUSED(sharedContext, !sharedContext);
 #if USE(NICOSIA)
     m_nicosiaLayer = makeUnique<Nicosia::GCGLLayer>(*this);
 #else
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to