Title: [284371] trunk/Source
Revision
284371
Author
[email protected]
Date
2021-10-18 07:57:22 -0700 (Mon, 18 Oct 2021)

Log Message

Cocoa GraphicsContextGLOpenGL should not use WebGLLayer
https://bugs.webkit.org/show_bug.cgi?id=231804

Patch by Kimmo Kinnunen <[email protected]> on 2021-10-18
Reviewed by Dean Jackson.

Source/WebCore:

Move the "swap chain", e.g. the display buffer IOSurface
from WebGLLayer to GraphicsContextGLOpenGL.
Instantiate WebGLLayer only in new class WebProcessGraphicsContextGLOpenGL,
which is used when WebGL is run in-process in WebContent process.
Simply set the CALayer.contents when new display buffer is ready and
call "setNeedsDisplay" directly.

No new tests, a refactor.

* PlatformMac.cmake:
* SourcesCocoa.txt:
* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/RemoteGraphicsContextGLProxyBase.h:
* platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
(WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
(WebCore::GraphicsContextGLOpenGL::~GraphicsContextGLOpenGL):
(WebCore::GraphicsContextGLOpenGL::isValid const):
(WebCore::GraphicsContextGLOpenGL::reshapeDisplayBufferBacking):
(WebCore::GraphicsContextGLOpenGL::prepareForDisplay):
(WebCore::GraphicsContextGLOpenGL::readCompositedResults):
(WebCore::GraphicsContextGLOpenGL::paintCompositedResultsToMediaSample):
(WebCore::GraphicsContextGLOpenGL::create): Deleted.
(WebCore::GraphicsContextGLOpenGL::createForGPUProcess): Deleted.
GraphicsContextGLOpenGL for GPUProcess is now a new class, described
in WebKit ChangeLog.

* platform/graphics/cocoa/RemoteGraphicsContextGLProxyBaseCocoa.mm:
(WebCore::RemoteGraphicsContextGLProxyBase::platformInitialize):
(WebCore::RemoteGraphicsContextGLProxyBase::paintCompositedResultsToMediaSample):
(WebCore::RemoteGraphicsContextGLProxyBase::platformSwapChain): Deleted.
* platform/graphics/cocoa/WebGLLayer.h:
* platform/graphics/cocoa/WebGLLayer.mm:
(-[WebGLLayer initWithDevicePixelRatio:contentsOpaque:]):
(-[WebGLLayer display]):
(-[WebGLLayer swapChain]): Deleted.
(-[WebGLLayer prepareForDisplay]): Deleted.
(WebGLLayerSwapChain::present): Deleted.
CALayer.contents and setNeedsDisplay is called directly when
a graphics context has new display buffer.

* platform/graphics/cocoa/WebProcessGraphicsContextGLOpenGLCocoa.mm: Added.
(WebCore::GraphicsContextGLOpenGL::create):
* platform/graphics/opengl/GraphicsContextGLOpenGL.cpp:
(WebCore::GraphicsContextGLOpenGL::isValid const):
Add a new function that checks if the constructor exited early.
Before, m_contextObj would be consulted but this is not protected
so it's not so useful. Also it wasn't very accurate, as some constructor
early exists ran after m_contextObj was set. Use m_texture to detect
fully constructed object for now.

* platform/graphics/opengl/GraphicsContextGLOpenGL.h:
* platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp:
(WebCore::GraphicsContextGLOpenGL::create):
(WebCore::GraphicsContextGLOpenGL::createForGPUProcess): Deleted.
GraphicsContextGLOpenGL for GPUProcess is now a new class, described
in WebKit ChangeLog. Remove the HostWindow arguments for
GraphicsContextGLOpenGL, it's not used.

Source/WebKit:

Implement changes so that GPU process side GraphicsContextGLOpenGL,
the new class GPUProcessGraphicsContextGL, does not use
WebGLLayer. Instead, the swap chain is in GraphicsContextGLOpenGL
and the GPUProcessGraphicsContextGL exposes a function to extract
the display buffer out to be sent to WebContent process.

* GPUProcess/graphics/GPUProcessGraphicsContextGL.h: Added.
Add a simpler class for GPUProcess side GraphicsContextGLOpenGL
instance, one that can get the display buffer from the instance.

* GPUProcess/graphics/RemoteGraphicsContextGL.h:
* GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp:
(WebKit::RemoteGraphicsContextGLCocoa::platformWorkQueueInitialize):
(WebKit::RemoteGraphicsContextGLCocoa::prepareForDisplay):
* GPUProcess/graphics/RemoteGraphicsContextGLWin.cpp:
(WebKit::RemoteGraphicsContextGLWin::platformWorkQueueInitialize):
* SourcesCocoa.txt:
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp:
(WebKit::RemoteGraphicsContextGLProxy::~RemoteGraphicsContextGLProxy):
(WebKit::RemoteGraphicsContextGLProxy::prepareForDisplay):
Move Cocoa implemenation to an Objective-C++ file.

* WebProcess/GPU/graphics/cocoa/RemoteGraphicsContextGLProxyCocoa.mm: Added.
(WebKit::RemoteGraphicsContextGLProxy::prepareForDisplay):
Set the display buffer contents directly to the WebGLLayer after
prepare.

* WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
* WebProcess/Plugins/PDF/PDFPluginPasswordField.mm:
* WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemoteModelHosting.mm:
(WebKit::PlatformCALayerRemoteModelHosting::dumpAdditionalProperties):
Unified build fixes.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (284370 => 284371)


--- trunk/Source/WebCore/ChangeLog	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebCore/ChangeLog	2021-10-18 14:57:22 UTC (rev 284371)
@@ -1,3 +1,68 @@
+2021-10-18  Kimmo Kinnunen  <[email protected]>
+
+        Cocoa GraphicsContextGLOpenGL should not use WebGLLayer
+        https://bugs.webkit.org/show_bug.cgi?id=231804
+
+        Reviewed by Dean Jackson.
+
+        Move the "swap chain", e.g. the display buffer IOSurface
+        from WebGLLayer to GraphicsContextGLOpenGL.
+        Instantiate WebGLLayer only in new class WebProcessGraphicsContextGLOpenGL,
+        which is used when WebGL is run in-process in WebContent process.
+        Simply set the CALayer.contents when new display buffer is ready and
+        call "setNeedsDisplay" directly.
+
+        No new tests, a refactor.
+
+        * PlatformMac.cmake:
+        * SourcesCocoa.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/graphics/RemoteGraphicsContextGLProxyBase.h:
+        * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
+        (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
+        (WebCore::GraphicsContextGLOpenGL::~GraphicsContextGLOpenGL):
+        (WebCore::GraphicsContextGLOpenGL::isValid const):
+        (WebCore::GraphicsContextGLOpenGL::reshapeDisplayBufferBacking):
+        (WebCore::GraphicsContextGLOpenGL::prepareForDisplay):
+        (WebCore::GraphicsContextGLOpenGL::readCompositedResults):
+        (WebCore::GraphicsContextGLOpenGL::paintCompositedResultsToMediaSample):
+        (WebCore::GraphicsContextGLOpenGL::create): Deleted.
+        (WebCore::GraphicsContextGLOpenGL::createForGPUProcess): Deleted.
+        GraphicsContextGLOpenGL for GPUProcess is now a new class, described
+        in WebKit ChangeLog.
+
+        * platform/graphics/cocoa/RemoteGraphicsContextGLProxyBaseCocoa.mm:
+        (WebCore::RemoteGraphicsContextGLProxyBase::platformInitialize):
+        (WebCore::RemoteGraphicsContextGLProxyBase::paintCompositedResultsToMediaSample):
+        (WebCore::RemoteGraphicsContextGLProxyBase::platformSwapChain): Deleted.
+        * platform/graphics/cocoa/WebGLLayer.h:
+        * platform/graphics/cocoa/WebGLLayer.mm:
+        (-[WebGLLayer initWithDevicePixelRatio:contentsOpaque:]):
+        (-[WebGLLayer display]):
+        (-[WebGLLayer swapChain]): Deleted.
+        (-[WebGLLayer prepareForDisplay]): Deleted.
+        (WebGLLayerSwapChain::present): Deleted.
+        CALayer.contents and setNeedsDisplay is called directly when
+        a graphics context has new display buffer.
+
+        * platform/graphics/cocoa/WebProcessGraphicsContextGLOpenGLCocoa.mm: Added.
+        (WebCore::GraphicsContextGLOpenGL::create):
+        * platform/graphics/opengl/GraphicsContextGLOpenGL.cpp:
+        (WebCore::GraphicsContextGLOpenGL::isValid const):
+        Add a new function that checks if the constructor exited early.
+        Before, m_contextObj would be consulted but this is not protected
+        so it's not so useful. Also it wasn't very accurate, as some constructor
+        early exists ran after m_contextObj was set. Use m_texture to detect
+        fully constructed object for now.
+
+        * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+        * platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp:
+        (WebCore::GraphicsContextGLOpenGL::create):
+        (WebCore::GraphicsContextGLOpenGL::createForGPUProcess): Deleted.
+        GraphicsContextGLOpenGL for GPUProcess is now a new class, described
+        in WebKit ChangeLog. Remove the HostWindow arguments for
+        GraphicsContextGLOpenGL, it's not used.
+
 2021-10-18  Philippe Normand  <[email protected]>
 
         [GStreamer] fast/mediastream/video-rotation tests are failing due to missing TestController::takeViewPortSnapshot

Modified: trunk/Source/WebCore/PlatformMac.cmake (284370 => 284371)


--- trunk/Source/WebCore/PlatformMac.cmake	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebCore/PlatformMac.cmake	2021-10-18 14:57:22 UTC (rev 284371)
@@ -333,6 +333,7 @@
     platform/graphics/cocoa/WebCoreDecompressionSession.mm
     platform/graphics/cocoa/WebGLLayer.mm
     platform/graphics/cocoa/WebMAudioUtilitiesCocoa.mm
+    platform/graphics/cocoa/WebProcessGraphicsContextGLOpenGLCocoa.mm
 
     platform/graphics/coretext/FontCascadeCoreText.cpp
     platform/graphics/coretext/FontCoreText.cpp

Modified: trunk/Source/WebCore/SourcesCocoa.txt (284370 => 284371)


--- trunk/Source/WebCore/SourcesCocoa.txt	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2021-10-18 14:57:22 UTC (rev 284371)
@@ -388,6 +388,7 @@
 platform/graphics/cocoa/WebCoreCALayerExtras.mm
 platform/graphics/cocoa/WebCoreDecompressionSession.mm
 platform/graphics/cocoa/WebGLLayer.mm
+platform/graphics/cocoa/WebProcessGraphicsContextGLOpenGLCocoa.mm
 platform/graphics/cocoa/VideoTrackPrivateWebM.cpp
 platform/graphics/coretext/DrawGlyphsRecorderCoreText.cpp
 platform/graphics/coretext/FontCascadeCoreText.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (284370 => 284371)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-10-18 14:57:22 UTC (rev 284371)
@@ -1439,7 +1439,7 @@
 		49ECEB701499790D00CDD3A4 /* FilterOperations.h in Headers */ = {isa = PBXBuildFile; fileRef = 49ECEB661499790D00CDD3A4 /* FilterOperations.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		49EED1451051969400099FAB /* JSCanvasRenderingContext2D.h in Headers */ = {isa = PBXBuildFile; fileRef = 49EED13F1051969400099FAB /* JSCanvasRenderingContext2D.h */; };
 		49EED1471051969400099FAB /* JSWebGLRenderingContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 49EED1411051969400099FAB /* JSWebGLRenderingContext.h */; };
-		49FFBF3F11C93EE3006A7118 /* WebGLLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 49FFBF3D11C93EE3006A7118 /* WebGLLayer.h */; };
+		49FFBF3F11C93EE3006A7118 /* WebGLLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 49FFBF3D11C93EE3006A7118 /* WebGLLayer.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		4A0DA2FF129B241900AB61E1 /* FormAssociatedElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 4A0DA2FD129B241900AB61E1 /* FormAssociatedElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		4A0FFA9E1AAF5E7E0062803B /* MockRealtimeMediaSourceCenter.h in Headers */ = {isa = PBXBuildFile; fileRef = 4A0FFA9C1AAF5E6C0062803B /* MockRealtimeMediaSourceCenter.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		4A0FFAA21AAF5EA20062803B /* RealtimeMediaSourceCenter.h in Headers */ = {isa = PBXBuildFile; fileRef = 4A0FFAA01AAF5EA20062803B /* RealtimeMediaSourceCenter.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -10744,6 +10744,7 @@
 		7B10339A2549720000C8C1AC /* GraphicsContextGLCVANGLE.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsContextGLCVANGLE.cpp; sourceTree = "<group>"; };
 		7B10339C2549720100C8C1AC /* GraphicsContextGLCVANGLE.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLCVANGLE.h; sourceTree = "<group>"; };
 		7B10339D2549720100C8C1AC /* GraphicsContextGLCV.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLCV.h; sourceTree = "<group>"; };
+		7B1619102719880E00C40EAC /* WebProcessGraphicsContextGLOpenGLCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebProcessGraphicsContextGLOpenGLCocoa.mm; sourceTree = "<group>"; };
 		7B64C0B4254C3B160006B4AF /* RemoteGraphicsContextGLProxyBaseCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RemoteGraphicsContextGLProxyBaseCocoa.mm; sourceTree = "<group>"; };
 		7B6DC81525712E9100380C70 /* GraphicsContextGLIOSurfaceSwapChain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsContextGLIOSurfaceSwapChain.cpp; sourceTree = "<group>"; };
 		7B6DC81725712E9200380C70 /* GraphicsContextGLIOSurfaceSwapChain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLIOSurfaceSwapChain.h; sourceTree = "<group>"; };
@@ -27634,6 +27635,7 @@
 				49FFBF3E11C93EE3006A7118 /* WebGLLayer.mm */,
 				07F5CFF42582A4F800662EF5 /* WebMAudioUtilitiesCocoa.h */,
 				07F5CFF22582A4F800662EF5 /* WebMAudioUtilitiesCocoa.mm */,
+				7B1619102719880E00C40EAC /* WebProcessGraphicsContextGLOpenGLCocoa.mm */,
 			);
 			path = cocoa;
 			sourceTree = "<group>";

Modified: trunk/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.cpp (284370 => 284371)


--- trunk/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.cpp	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.cpp	2021-10-18 14:57:22 UTC (rev 284371)
@@ -29,6 +29,10 @@
 #if ENABLE(GPU_PROCESS) && ENABLE(WEBGL)
 #include "NotImplemented.h"
 
+#if PLATFORM(COCOA)
+#include "IOSurface.h"
+#endif
+
 namespace WebCore {
 
 RemoteGraphicsContextGLProxyBase::RemoteGraphicsContextGLProxyBase(const GraphicsContextGLAttributes& attrs)

Modified: trunk/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.h (284370 => 284371)


--- trunk/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.h	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.h	2021-10-18 14:57:22 UTC (rev 284371)
@@ -45,6 +45,7 @@
 
 #if PLATFORM(COCOA)
 class GraphicsContextGLIOSurfaceSwapChain;
+class IOSurface;
 #endif
 
 // A base class for RemoteGraphicsContextGL proxy side implementation
@@ -91,15 +92,13 @@
     virtual void waitUntilInitialized() = 0;
     virtual void ensureExtensionEnabled(const String&) = 0;
     virtual void notifyMarkContextChanged() = 0;
+
 #if PLATFORM(COCOA)
-    GraphicsContextGLIOSurfaceSwapChain& platformSwapChain();
+    RetainPtr<WebGLLayer> m_webGLLayer;
+    std::unique_ptr<IOSurface> m_displayBuffer;
 #endif
-
 private:
     void platformInitialize();
-#if PLATFORM(COCOA)
-    RetainPtr<WebGLLayer> m_webGLLayer;
-#endif
 
     // Guarded by waitUntilInitialized().
     HashSet<String> m_availableExtensions;

Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm (284370 => 284371)


--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm	2021-10-18 14:57:22 UTC (rev 284371)
@@ -36,7 +36,6 @@
 #import "GraphicsContextGLOpenGLManager.h"
 #import "Logging.h"
 #import "RuntimeApplicationChecks.h"
-#import "WebGLLayer.h"
 #import <CoreGraphics/CGBitmapContext.h>
 #import <Metal/Metal.h>
 #import <pal/spi/cocoa/MetalSPI.h>
@@ -193,29 +192,7 @@
 }
 #endif
 
-RefPtr<GraphicsContextGLOpenGL> GraphicsContextGLOpenGL::create(GraphicsContextGLAttributes attrs, HostWindow* hostWindow)
-{
-    // Make space for the incoming context if we're full.
-    GraphicsContextGLOpenGLManager::sharedManager().recycleContextIfNecessary();
-    if (GraphicsContextGLOpenGLManager::sharedManager().hasTooManyContexts())
-        return nullptr;
-
-    RefPtr<GraphicsContextGLOpenGL> context = adoptRef(new GraphicsContextGLOpenGL(attrs, hostWindow, nullptr));
-
-    if (!context->m_contextObj)
-        return nullptr;
-
-    GraphicsContextGLOpenGLManager::sharedManager().addContext(context.get());
-
-    return context;
-}
-
-Ref<GraphicsContextGLOpenGL> GraphicsContextGLOpenGL::createForGPUProcess(const GraphicsContextGLAttributes& attrs, GraphicsContextGLIOSurfaceSwapChain* swapChain)
-{
-    return adoptRef(*new GraphicsContextGLOpenGL(attrs, nullptr, swapChain));
-}
-
-GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attrs, HostWindow*, GraphicsContextGLIOSurfaceSwapChain* swapChain)
+GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attrs)
     : GraphicsContextGL(attrs)
 {
     m_isForWebGL2 = attrs.webGLVersion == GraphicsContextGLWebGLVersion::WebGL2;
@@ -353,18 +330,6 @@
     validateAttributes();
     attrs = contextAttributes(); // They may have changed during validation.
 
-    if (swapChain)
-        m_swapChain = swapChain;
-    else {
-    BEGIN_BLOCK_OBJC_EXCEPTIONS
-        m_webGLLayer = adoptNS([[WebGLLayer alloc] initWithDevicePixelRatio:attrs.devicePixelRatio contentsOpaque:!attrs.alpha]);
-#ifndef NDEBUG
-        [m_webGLLayer setName:@"WebGL Layer"];
-#endif
-    END_BLOCK_OBJC_EXCEPTIONS
-        m_swapChain = &[m_webGLLayer swapChain];
-    }
-
     // Create the texture that will be used for the framebuffer.
     GLenum textureTarget = drawingBufferTextureTarget();
 
@@ -439,14 +404,12 @@
     }
     if (m_displayBufferPbuffer)
         EGL_DestroySurface(m_displayObj, m_displayBufferPbuffer);
-    if (m_swapChain) {
-        auto recycledBuffer = m_swapChain->recycleBuffer();
-        if (recycledBuffer.handle)
-            EGL_DestroySurface(m_displayObj, recycledBuffer.handle);
-        auto contentsHandle = m_swapChain->detachClient();
-        if (contentsHandle)
-            EGL_DestroySurface(m_displayObj, contentsHandle);
-    }
+    auto recycledBuffer = m_swapChain.recycleBuffer();
+    if (recycledBuffer.handle)
+        EGL_DestroySurface(m_displayObj, recycledBuffer.handle);
+    auto contentsHandle = m_swapChain.detachClient();
+    if (contentsHandle)
+        EGL_DestroySurface(m_displayObj, contentsHandle);
     if (m_contextObj) {
         makeCurrent(m_displayObj, EGL_NO_CONTEXT);
         EGL_DestroyContext(m_displayObj, m_contextObj);
@@ -455,6 +418,16 @@
     LOG(WebGL, "Destroyed a GraphicsContextGLOpenGL (%p).", this);
 }
 
+bool GraphicsContextGLOpenGL::isValid() const
+{
+    return m_texture;
+}
+
+PlatformLayer* GraphicsContextGLOpenGL::platformLayer() const
+{
+    return nullptr;
+}
+
 GCGLenum GraphicsContextGLOpenGL::drawingBufferTextureTarget()
 {
 #if PLATFORM(MACCATALYST)
@@ -567,12 +540,10 @@
         m_displayBufferPbuffer = EGL_NO_SURFACE;
     }
     // Reset the future recycled buffer now, because it most likely will not be reusable at the time it will be reused.
-    if (m_swapChain) {
-        auto recycledBuffer = m_swapChain->recycleBuffer();
-        if (recycledBuffer.handle)
-            EGL_DestroySurface(m_displayObj, recycledBuffer.handle);
-        recycledBuffer.surface.reset();
-    }
+    auto recycledBuffer = m_swapChain.recycleBuffer();
+    if (recycledBuffer.handle)
+        EGL_DestroySurface(m_displayObj, recycledBuffer.handle);
+    recycledBuffer.surface.reset();
     return allocateAndBindDisplayBufferBacking();
 }
 
@@ -724,10 +695,10 @@
     // The IOSurface will be used from other graphics subsystem, so flush GL commands.
     gl::Flush();
 
-    auto recycledBuffer = m_swapChain->recycleBuffer();
+    auto recycledBuffer = m_swapChain.recycleBuffer();
 
     EGL_ReleaseTexImage(m_displayObj, m_displayBufferPbuffer, EGL_BACK_BUFFER);
-    m_swapChain->present({ WTFMove(m_displayBufferBacking), m_displayBufferPbuffer });
+    m_swapChain.present({ WTFMove(m_displayBufferBacking), m_displayBufferPbuffer });
     m_displayBufferPbuffer = EGL_NO_SURFACE;
 
     bool hasNewBacking = false;
@@ -763,7 +734,7 @@
 
 std::optional<PixelBuffer> GraphicsContextGLOpenGL::readCompositedResults()
 {
-    auto& displayBuffer = m_swapChain->displayBuffer();
+    auto& displayBuffer = m_swapChain.displayBuffer();
     if (!displayBuffer.surface || !displayBuffer.handle)
         return std::nullopt;
     if (displayBuffer.surface->size() != getInternalFramebufferSize())
@@ -795,12 +766,12 @@
 #if ENABLE(MEDIA_STREAM)
 RefPtr<MediaSample> GraphicsContextGLOpenGL::paintCompositedResultsToMediaSample()
 {
-    auto &displayBuffer = m_swapChain->displayBuffer();
+    auto &displayBuffer = m_swapChain.displayBuffer();
     if (!displayBuffer.surface || !displayBuffer.handle)
         return nullptr;
     if (displayBuffer.surface->size() != getInternalFramebufferSize())
         return nullptr;
-    m_swapChain->markDisplayBufferInUse();
+    m_swapChain.markDisplayBufferInUse();
     auto pixelBuffer = createCVPixelBuffer(displayBuffer.surface->surface());
     if (!pixelBuffer)
         return nullptr;

Modified: trunk/Source/WebCore/platform/graphics/cocoa/RemoteGraphicsContextGLProxyBaseCocoa.mm (284370 => 284371)


--- trunk/Source/WebCore/platform/graphics/cocoa/RemoteGraphicsContextGLProxyBaseCocoa.mm	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebCore/platform/graphics/cocoa/RemoteGraphicsContextGLProxyBaseCocoa.mm	2021-10-18 14:57:22 UTC (rev 284371)
@@ -43,9 +43,9 @@
 {
     auto attrs = contextAttributes();
     BEGIN_BLOCK_OBJC_EXCEPTIONS
-        m_webGLLayer = adoptNS([[WebGLLayer alloc] initWithDevicePixelRatio:attrs.devicePixelRatio contentsOpaque:!attrs.alpha]);
+    m_webGLLayer = adoptNS([[WebGLLayer alloc] initWithDevicePixelRatio:attrs.devicePixelRatio contentsOpaque:!attrs.alpha]);
 #ifndef NDEBUG
-        [m_webGLLayer setName:@"WebGL Layer"];
+    [m_webGLLayer setName:@"WebGL Layer"];
 #endif
     END_BLOCK_OBJC_EXCEPTIONS
 }
@@ -63,20 +63,12 @@
 }
 #endif
 
-GraphicsContextGLIOSurfaceSwapChain& RemoteGraphicsContextGLProxyBase::platformSwapChain()
-{
-    return [m_webGLLayer swapChain];
-}
-
 #if ENABLE(MEDIA_STREAM)
 RefPtr<MediaSample> RemoteGraphicsContextGLProxyBase::paintCompositedResultsToMediaSample()
 {
-    auto& sc = platformSwapChain();
-    auto& displayBuffer = sc.displayBuffer();
-    if (!displayBuffer.surface)
+    if (!m_displayBuffer)
         return nullptr;
-    sc.markDisplayBufferInUse();
-    auto pixelBuffer = createCVPixelBuffer(displayBuffer.surface->surface());
+    auto pixelBuffer = createCVPixelBuffer(m_displayBuffer->surface());
     if (!pixelBuffer)
         return nullptr;
     return MediaSampleAVFObjC::createImageSample(WTFMove(*pixelBuffer), MediaSampleAVFObjC::VideoRotation::UpsideDown, true);

Modified: trunk/Source/WebCore/platform/graphics/cocoa/WebGLLayer.h (284370 => 284371)


--- trunk/Source/WebCore/platform/graphics/cocoa/WebGLLayer.h	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebCore/platform/graphics/cocoa/WebGLLayer.h	2021-10-18 14:57:22 UTC (rev 284371)
@@ -23,21 +23,15 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#import "GraphicsContextGLIOSurfaceSwapChain.h"
 #import <QuartzCore/QuartzCore.h>
-#import <memory>
-#import <wtf/NakedPtr.h>
 
 ALLOW_DEPRECATED_DECLARATIONS_BEGIN
 
-// A layer class implementing front buffer management of a 3-buffering swap
-// chain of IOSurfaces.
+// A layer class showing one IOSurface.
 @interface WebGLLayer : CALayer
 
 - (id)initWithDevicePixelRatio:(float)devicePixelRatio contentsOpaque:(bool)contentsOpaque;
 
-- (WebCore::GraphicsContextGLIOSurfaceSwapChain&) swapChain;
-
 @end
 
 ALLOW_DEPRECATED_DECLARATIONS_END

Modified: trunk/Source/WebCore/platform/graphics/cocoa/WebGLLayer.mm (284370 => 284371)


--- trunk/Source/WebCore/platform/graphics/cocoa/WebGLLayer.mm	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebCore/platform/graphics/cocoa/WebGLLayer.mm	2021-10-18 14:57:22 UTC (rev 284371)
@@ -31,24 +31,9 @@
 #import "GraphicsLayer.h"
 #import "GraphicsLayerCA.h"
 #import "PlatformCALayer.h"
-#import <pal/spi/cocoa/QuartzCoreSPI.h>
 
-class WebGLLayerSwapChain final : public WebCore::GraphicsContextGLIOSurfaceSwapChain {
-public:
-    explicit WebGLLayerSwapChain(WebGLLayer* layer)  : m_layer(layer) { };
-    ~WebGLLayerSwapChain() override = default;
-    void present(Buffer&&) override;
+@implementation WebGLLayer
 
-    WebCore::IOSurface* displaySurface() { return m_displayBuffer.surface.get(); }
-private:
-    WebGLLayer* const m_layer;
-};
-
-@implementation WebGLLayer {
-    BOOL _preparedForDisplay;
-    std::optional<WebGLLayerSwapChain> _swapChain;
-}
-
 - (id)initWithDevicePixelRatio:(float)devicePixelRatio contentsOpaque:(bool)contentsOpaque
 {
     self = [super init];
@@ -55,7 +40,6 @@
     self.transform = CATransform3DIdentity;
     self.contentsOpaque = contentsOpaque;
     self.contentsScale = devicePixelRatio;
-    _swapChain.emplace(self);
     return self;
 }
 
@@ -75,37 +59,15 @@
     [super setAnchorPoint:CGPointMake(p.x, 1.0 - p.y)];
 }
 
-- (WebCore::GraphicsContextGLIOSurfaceSwapChain&) swapChain
-{
-    return _swapChain.value();
-}
-
-- (void)prepareForDisplay
-{
-    [self setNeedsDisplay];
-    _preparedForDisplay = YES;
-}
-
 - (void)display
 {
-    if (_swapChain->displaySurface() && _preparedForDisplay) {
-        self.contents = _swapChain->displaySurface()->asLayerContents();
-        [self reloadValueForKeyPath:@"contents"];
-    }
+    // Show the self.contents as the contents by not doing anything in this function.
     auto layer = WebCore::PlatformCALayer::platformCALayerForLayer((__bridge void*)self);
     if (layer && layer->owner())
         layer->owner()->platformCALayerLayerDidDisplay(layer.get());
 
-    _preparedForDisplay = NO;
 }
 
 @end
 
-void WebGLLayerSwapChain::present(Buffer&& buffer)
-{
-    ASSERT(!m_spareBuffer.surface);
-    GraphicsContextGLIOSurfaceSwapChain::present(WTFMove(buffer));
-    [m_layer prepareForDisplay];
-}
-
 #endif // ENABLE(WEBGL)

Added: trunk/Source/WebCore/platform/graphics/cocoa/WebProcessGraphicsContextGLOpenGLCocoa.mm (0 => 284371)


--- trunk/Source/WebCore/platform/graphics/cocoa/WebProcessGraphicsContextGLOpenGLCocoa.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cocoa/WebProcessGraphicsContextGLOpenGLCocoa.mm	2021-10-18 14:57:22 UTC (rev 284371)
@@ -0,0 +1,98 @@
+
+/*
+ * Copyright (C) 2009-2018 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.
+ */
+
+#import "config.h"
+
+#if ENABLE(WEBGL)
+#import "GraphicsContextGLOpenGL.h" // NOLINT
+#import "GraphicsContextGLOpenGLManager.h"
+#import "WebGLLayer.h"
+#import <wtf/BlockObjCExceptions.h>
+
+namespace WebCore {
+namespace {
+
+static RetainPtr<WebGLLayer> createWebGLLayer(const GraphicsContextGLAttributes& attributes)
+{
+    RetainPtr<WebGLLayer> layer;
+    BEGIN_BLOCK_OBJC_EXCEPTIONS
+    layer = adoptNS([[WebGLLayer alloc] initWithDevicePixelRatio:attributes.devicePixelRatio contentsOpaque:!attributes.alpha]);
+#ifndef NDEBUG
+    [layer setName:@"WebGL Layer"];
+#endif
+    END_BLOCK_OBJC_EXCEPTIONS
+    return layer;
+}
+
+// GraphicsContextGLOpenGL type that is used when WebGL is run in-process in WebContent process.
+class WebProcessGraphicsContextGLOpenGL final : public GraphicsContextGLOpenGL {
+public:
+    ~WebProcessGraphicsContextGLOpenGL() = default;
+    bool isValid() const { return GraphicsContextGLOpenGL::isValid() && m_webGLLayer; }
+    // GraphicsContextGLOpenGL overrides.
+    PlatformLayer* platformLayer() const final { return reinterpret_cast<CALayer*>(m_webGLLayer.get()); }
+    void prepareForDisplay() final;
+private:
+    WebProcessGraphicsContextGLOpenGL(GraphicsContextGLAttributes attributes)
+        : GraphicsContextGLOpenGL(attributes)
+        , m_webGLLayer(createWebGLLayer(attributes))
+    {
+    }
+    RetainPtr<WebGLLayer> m_webGLLayer;
+
+    friend class GraphicsContextGLOpenGL;
+};
+
+void WebProcessGraphicsContextGLOpenGL::prepareForDisplay()
+{
+    GraphicsContextGLOpenGL::prepareForDisplay();
+    auto surface = m_swapChain.displayBuffer().surface.get();
+    if (!surface)
+        return;
+    BEGIN_BLOCK_OBJC_EXCEPTIONS
+    [m_webGLLayer setContents:surface->asLayerContents()];
+    [m_webGLLayer setNeedsDisplay];
+    END_BLOCK_OBJC_EXCEPTIONS
+}
+
+}
+
+RefPtr<GraphicsContextGLOpenGL> GraphicsContextGLOpenGL::create(GraphicsContextGLAttributes attributes, HostWindow*)
+{
+    // Make space for the incoming context if we're full.
+    GraphicsContextGLOpenGLManager::sharedManager().recycleContextIfNecessary();
+    if (GraphicsContextGLOpenGLManager::sharedManager().hasTooManyContexts())
+        return nullptr;
+    auto context = adoptRef(new WebProcessGraphicsContextGLOpenGL(WTFMove(attributes)));
+    if (!context->isValid())
+        return nullptr;
+    GraphicsContextGLOpenGLManager::sharedManager().addContext(context.get());
+
+    return context;
+}
+}
+
+#endif

Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp (284370 => 284371)


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp	2021-10-18 14:57:22 UTC (rev 284371)
@@ -47,6 +47,13 @@
 
 namespace WebCore {
 
+#if !PLATFORM(COCOA)
+bool GraphicsContextGLOpenGL::isValid() const
+{
+    return true;
+}
+#endif
+
 void GraphicsContextGLOpenGL::resetBuffersToAutoClear()
 {
     GCGLuint buffers = GraphicsContextGL::COLOR_BUFFER_BIT;

Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h (284370 => 284371)


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2021-10-18 14:57:22 UTC (rev 284371)
@@ -37,6 +37,7 @@
 #include <wtf/UniqueRef.h>
 
 #if PLATFORM(COCOA)
+#include "GraphicsContextGLIOSurfaceSwapChain.h"
 #include "IOSurface.h"
 #endif
 
@@ -67,7 +68,6 @@
 OBJC_CLASS CALayer;
 OBJC_CLASS WebGLLayer;
 namespace WebCore {
-class GraphicsContextGLIOSurfaceSwapChain;
 class GraphicsContextGLCVANGLE;
 }
 #endif // PLATFORM(COCOA)
@@ -97,22 +97,18 @@
 
 typedef WTF::HashMap<CString, uint64_t> ShaderNameHash;
 
-class WEBCORE_EXPORT GraphicsContextGLOpenGL final : public GraphicsContextGL
+class WEBCORE_EXPORT GraphicsContextGLOpenGL : public GraphicsContextGL
 {
 public:
     static RefPtr<GraphicsContextGLOpenGL> create(GraphicsContextGLAttributes, HostWindow*);
     virtual ~GraphicsContextGLOpenGL();
-
 #if PLATFORM(COCOA)
-    static Ref<GraphicsContextGLOpenGL> createForGPUProcess(const GraphicsContextGLAttributes&, GraphicsContextGLIOSurfaceSwapChain*);
-
-    CALayer* platformLayer() const final { return reinterpret_cast<CALayer*>(m_webGLLayer.get()); }
+    PlatformLayer* platformLayer() const override;
     PlatformGraphicsContextGLDisplay platformDisplay() const { return m_displayObj; }
     PlatformGraphicsContextGLConfig platformConfig() const { return m_configObj; }
     static GCGLenum drawingBufferTextureTargetQuery();
     static GCGLint EGLDrawingBufferTextureTarget();
 #else
-    static Ref<GraphicsContextGLOpenGL> createForGPUProcess(const GraphicsContextGLAttributes&);
     PlatformLayer* platformLayer() const final;
 #endif
 #if USE(ANGLE)
@@ -518,7 +514,7 @@
 
     unsigned textureSeed(GCGLuint texture) { return m_state.textureSeedCount.count(texture); }
 
-    void prepareForDisplay() final;
+    void prepareForDisplay() override;
 
 #if ENABLE(VIDEO) && USE(AVFOUNDATION)
     GraphicsContextGLCV* asCV() final;
@@ -538,13 +534,13 @@
 #endif
 #endif
 
-private:
+protected:
+    GraphicsContextGLOpenGL(GraphicsContextGLAttributes);
+    bool isValid() const;
 #if PLATFORM(COCOA)
-    GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*, GraphicsContextGLIOSurfaceSwapChain* = nullptr);
-#else
-    GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*);
+    GraphicsContextGLIOSurfaceSwapChain m_swapChain;
 #endif
-
+private:
     // 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;
@@ -586,9 +582,7 @@
 
 
 #if PLATFORM(COCOA)
-    GraphicsContextGLIOSurfaceSwapChain* m_swapChain { nullptr };
     // TODO: this should be removed once the context draws to a image buffer. See https://bugs.webkit.org/show_bug.cgi?id=218179 .
-    RetainPtr<WebGLLayer> m_webGLLayer;
     EGLDisplay m_displayObj { nullptr };
     PlatformGraphicsContextGL m_contextObj { nullptr };
     PlatformGraphicsContextGLConfig m_configObj { nullptr };

Modified: trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp (284370 => 284371)


--- trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp	2021-10-18 14:57:22 UTC (rev 284371)
@@ -66,7 +66,7 @@
 
 namespace WebCore {
 
-RefPtr<GraphicsContextGLOpenGL> GraphicsContextGLOpenGL::create(GraphicsContextGLAttributes attributes, HostWindow* hostWindow)
+RefPtr<GraphicsContextGLOpenGL> GraphicsContextGLOpenGL::create(GraphicsContextGLAttributes attributes, HostWindow*)
 {
     static bool initialized = false;
     static bool success = true;
@@ -85,7 +85,7 @@
         return nullptr;
 
     // Create the GraphicsContextGLOpenGL object first in order to establist a current context on this thread.
-    auto context = adoptRef(new GraphicsContextGLOpenGL(attributes, hostWindow));
+    auto context = adoptRef(new GraphicsContextGLOpenGL(attributes));
 
 #if USE(LIBEPOXY) && USE(OPENGL_ES) && ENABLE(WEBGL2)
     // Bail if GLES3 was requested but cannot be provided.
@@ -98,13 +98,8 @@
     return context;
 }
 
-Ref<GraphicsContextGLOpenGL> GraphicsContextGLOpenGL::createForGPUProcess(const GraphicsContextGLAttributes& attributes)
-{
-    return adoptRef(*new GraphicsContextGLOpenGL(attributes, nullptr));
-}
-
 #if USE(ANGLE)
-GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attributes, HostWindow*)
+GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attributes)
     : GraphicsContextGL(attributes)
 {
 #if ENABLE(WEBGL2)
@@ -173,7 +168,7 @@
     gl::ClearColor(0, 0, 0, 0);
 }
 #else
-GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attributes, HostWindow*)
+GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attributes)
     : GraphicsContextGL(attributes)
 {
 #if USE(NICOSIA)

Modified: trunk/Source/WebKit/ChangeLog (284370 => 284371)


--- trunk/Source/WebKit/ChangeLog	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebKit/ChangeLog	2021-10-18 14:57:22 UTC (rev 284371)
@@ -1,3 +1,44 @@
+2021-10-18  Kimmo Kinnunen  <[email protected]>
+
+        Cocoa GraphicsContextGLOpenGL should not use WebGLLayer
+        https://bugs.webkit.org/show_bug.cgi?id=231804
+
+        Reviewed by Dean Jackson.
+
+        Implement changes so that GPU process side GraphicsContextGLOpenGL,
+        the new class GPUProcessGraphicsContextGL, does not use
+        WebGLLayer. Instead, the swap chain is in GraphicsContextGLOpenGL
+        and the GPUProcessGraphicsContextGL exposes a function to extract
+        the display buffer out to be sent to WebContent process.
+
+        * GPUProcess/graphics/GPUProcessGraphicsContextGL.h: Added.
+        Add a simpler class for GPUProcess side GraphicsContextGLOpenGL
+        instance, one that can get the display buffer from the instance.
+
+        * GPUProcess/graphics/RemoteGraphicsContextGL.h:
+        * GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp:
+        (WebKit::RemoteGraphicsContextGLCocoa::platformWorkQueueInitialize):
+        (WebKit::RemoteGraphicsContextGLCocoa::prepareForDisplay):
+        * GPUProcess/graphics/RemoteGraphicsContextGLWin.cpp:
+        (WebKit::RemoteGraphicsContextGLWin::platformWorkQueueInitialize):
+        * SourcesCocoa.txt:
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp:
+        (WebKit::RemoteGraphicsContextGLProxy::~RemoteGraphicsContextGLProxy):
+        (WebKit::RemoteGraphicsContextGLProxy::prepareForDisplay):
+        Move Cocoa implemenation to an Objective-C++ file.
+
+        * WebProcess/GPU/graphics/cocoa/RemoteGraphicsContextGLProxyCocoa.mm: Added.
+        (WebKit::RemoteGraphicsContextGLProxy::prepareForDisplay):
+        Set the display buffer contents directly to the WebGLLayer after
+        prepare.
+
+        * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
+        * WebProcess/Plugins/PDF/PDFPluginPasswordField.mm:
+        * WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemoteModelHosting.mm:
+        (WebKit::PlatformCALayerRemoteModelHosting::dumpAdditionalProperties):
+        Unified build fixes.
+
 2021-10-18  Carlos Garcia Campos  <[email protected]>
 
         [GLIB] Simplify SleepDisabler by checking if we are under sandbox

Added: trunk/Source/WebKit/GPUProcess/graphics/GPUProcessGraphicsContextGL.h (0 => 284371)


--- trunk/Source/WebKit/GPUProcess/graphics/GPUProcessGraphicsContextGL.h	                        (rev 0)
+++ trunk/Source/WebKit/GPUProcess/graphics/GPUProcessGraphicsContextGL.h	2021-10-18 14:57:22 UTC (rev 284371)
@@ -0,0 +1,53 @@
+/*
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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(GPU_PROCESS) && ENABLE(WEBGL)
+#include <WebCore/ExtensionsGL.h>
+#include <WebCore/GraphicsContextGLOpenGL.h>
+
+class GPUProcessGraphicsContextGLOpenGL final : public WebCore::GraphicsContextGLOpenGL {
+public:
+    static RefPtr<GPUProcessGraphicsContextGLOpenGL> create(WebCore::GraphicsContextGLAttributes attributes)
+    {
+        auto context = adoptRef(*new GPUProcessGraphicsContextGLOpenGL(WTFMove(attributes)));
+        if (!context->isValid())
+            return nullptr;
+        return context;
+    }
+
+#if PLATFORM(COCOA)
+    WebCore::IOSurface* displayBuffer() { return m_swapChain.displayBuffer().surface.get(); }
+    void markDisplayBufferInUse() { return m_swapChain.markDisplayBufferInUse(); }
+#endif
+private:
+    GPUProcessGraphicsContextGLOpenGL(WebCore::GraphicsContextGLAttributes attributes)
+        : GraphicsContextGLOpenGL(attributes)
+    {
+    }
+};
+
+#endif

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h (284370 => 284371)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h	2021-10-18 14:57:22 UTC (rev 284371)
@@ -29,6 +29,7 @@
 
 #include "Connection.h"
 #include "GPUConnectionToWebProcess.h"
+#include "GPUProcessGraphicsContextGL.h"
 #include "GraphicsContextGLIdentifier.h"
 #include "QualifiedRenderingResourceIdentifier.h"
 #include "RemoteRenderingBackend.h"
@@ -35,16 +36,10 @@
 #include "ScopedWebGLRenderingResourcesRequest.h"
 #include "StreamMessageReceiver.h"
 #include "StreamServerConnection.h"
-#include <WebCore/ExtensionsGL.h>
-#include <WebCore/GraphicsContextGLOpenGL.h>
 #include <WebCore/NotImplemented.h>
 #include <wtf/ThreadAssertions.h>
 #include <wtf/WeakPtr.h>
 
-#if PLATFORM(COCOA)
-#include <WebCore/GraphicsContextGLIOSurfaceSwapChain.h>
-#endif
-
 #if PLATFORM(MAC)
 #include <CoreGraphics/CGDisplayConfiguration.h>
 #endif
@@ -114,7 +109,7 @@
 protected:
     WeakPtr<GPUConnectionToWebProcess> m_gpuConnectionToWebProcess;
     RefPtr<IPC::StreamServerConnection> m_streamConnection;
-    RefPtr<WebCore::GraphicsContextGLOpenGL> m_context WTF_GUARDED_BY_LOCK(m_streamThread);
+    RefPtr<GPUProcessGraphicsContextGLOpenGL> m_context WTF_GUARDED_BY_LOCK(m_streamThread);
     GraphicsContextGLIdentifier m_graphicsContextGLIdentifier;
     Ref<RemoteRenderingBackend> m_renderingBackend;
     ScopedWebGLRenderingResourcesRequest m_renderingResourcesRequest;

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp (284370 => 284371)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp	2021-10-18 14:57:22 UTC (rev 284371)
@@ -73,7 +73,7 @@
 void RemoteGraphicsContextGLCocoa::platformWorkQueueInitialize(WebCore::GraphicsContextGLAttributes&& attributes)
 {
     assertIsCurrent(m_streamThread);
-    m_context = GraphicsContextGLOpenGL::createForGPUProcess(WTFMove(attributes), &m_swapChain);
+    m_context = GPUProcessGraphicsContextGLOpenGL::create(WTFMove(attributes));
 }
 
 void RemoteGraphicsContextGLCocoa::prepareForDisplay(CompletionHandler<void(WTF::MachSendRight&&)>&& completionHandler)
@@ -80,13 +80,15 @@
 {
     assertIsCurrent(m_streamThread);
     m_context->prepareForDisplay();
+    IOSurface* displayBuffer = m_context->displayBuffer();
     MachSendRight sendRight;
-    if (auto* surface = m_swapChain.displayBuffer().surface.get()) {
+    if (displayBuffer) {
+        m_context->markDisplayBufferInUse();
 #if HAVE(IOSURFACE_SET_OWNERSHIP_IDENTITY)
         // Mark the IOSurface as being owned by the WebProcess even though it was constructed by the GPUProcess so that Jetsam knows which process to kill.
-        surface->setOwnershipIdentity(m_webProcessIdentityToken);
+        displayBuffer->setOwnershipIdentity(m_webProcessIdentityToken);
 #endif
-        sendRight = surface->createSendRight();
+        sendRight = displayBuffer->createSendRight();
     }
     completionHandler(WTFMove(sendRight));
 }

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLWin.cpp (284370 => 284371)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLWin.cpp	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLWin.cpp	2021-10-18 14:57:22 UTC (rev 284371)
@@ -57,7 +57,7 @@
 
 void RemoteGraphicsContextGLWin::platformWorkQueueInitialize(WebCore::GraphicsContextGLAttributes&& attributes)
 {
-    m_context = GraphicsContextGLOpenGL::createForGPUProcess(WTFMove(attributes));
+    m_context = GPUProcessGraphicsContextGLOpenGL::create(WTFMove(attributes));
 }
 
 void RemoteGraphicsContextGL::prepareForDisplay(CompletionHandler<void()>&& completionHandler)

Modified: trunk/Source/WebKit/SourcesCocoa.txt (284370 => 284371)


--- trunk/Source/WebKit/SourcesCocoa.txt	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebKit/SourcesCocoa.txt	2021-10-18 14:57:22 UTC (rev 284371)
@@ -624,6 +624,7 @@
 
 WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp
 WebProcess/GPU/graphics/cocoa/ImageBufferShareableMappedIOSurfaceBackend.cpp
+WebProcess/GPU/graphics/cocoa/RemoteGraphicsContextGLProxyCocoa.mm
 WebProcess/GPU/media/RemoteAudioSourceProvider.cpp
 WebProcess/GPU/media/RemoteAudioSourceProviderManager.cpp
 WebProcess/GPU/media/RemoteImageDecoderAVF.cpp

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (284370 => 284371)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2021-10-18 14:57:22 UTC (rev 284371)
@@ -4806,6 +4806,8 @@
 		7AFBD36221E50F39005DBACB /* WebResourceLoadStatisticsStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebResourceLoadStatisticsStore.h; path = Classifier/WebResourceLoadStatisticsStore.h; sourceTree = "<group>"; };
 		7AFBD36D21E546E3005DBACB /* PersistencyUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PersistencyUtils.h; sourceTree = "<group>"; };
 		7AFBD36E21E546E3005DBACB /* PersistencyUtils.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PersistencyUtils.cpp; sourceTree = "<group>"; };
+		7B16191227198AA900C40EAC /* RemoteGraphicsContextGLProxyCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RemoteGraphicsContextGLProxyCocoa.mm; sourceTree = "<group>"; };
+		7B1619132719AE7600C40EAC /* GPUProcessGraphicsContextGL.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUProcessGraphicsContextGL.h; sourceTree = "<group>"; };
 		7B1DB26525668CE0000E26BC /* ArrayReference.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArrayReference.h; sourceTree = "<group>"; };
 		7B483F1B25CDDA9B00120486 /* MessageReceiveQueueMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageReceiveQueueMap.h; sourceTree = "<group>"; };
 		7B483F1C25CDDA9B00120486 /* MessageReceiveQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageReceiveQueue.h; sourceTree = "<group>"; };
@@ -9198,6 +9200,7 @@
 			children = (
 				F4094CBC255304AF003D73E3 /* DisplayListReaderHandle.cpp */,
 				F4094CBB255304AF003D73E3 /* DisplayListReaderHandle.h */,
+				7B1619132719AE7600C40EAC /* GPUProcessGraphicsContextGL.h */,
 				55AD09432408A0E600DE4D2F /* PlatformRemoteImageBuffer.h */,
 				1CC54AFD270F9654005BF8BE /* QualifiedRenderingResourceIdentifier.h */,
 				1CBF9012271018B5000C457D /* QualifiedResourceHeap.h */,
@@ -9670,6 +9673,7 @@
 				2D25F32825758E9000231A8B /* ImageBufferShareableIOSurfaceBackend.h */,
 				727A7F342407857D004D2931 /* ImageBufferShareableMappedIOSurfaceBackend.cpp */,
 				727A7F352407857F004D2931 /* ImageBufferShareableMappedIOSurfaceBackend.h */,
+				7B16191227198AA900C40EAC /* RemoteGraphicsContextGLProxyCocoa.mm */,
 			);
 			path = cocoa;
 			sourceTree = "<group>";

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp (284370 => 284371)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp	2021-10-18 14:57:22 UTC (rev 284371)
@@ -67,9 +67,6 @@
 RemoteGraphicsContextGLProxy::~RemoteGraphicsContextGLProxy()
 {
     disconnectGpuProcessIfNeeded();
-#if PLATFORM(COCOA)
-    platformSwapChain().recycleBuffer();
-#endif
 }
 
 void RemoteGraphicsContextGLProxy::reshape(int width, int height)
@@ -83,32 +80,19 @@
         markContextLost();
 }
 
+#if !PLATFORM(COCOA)
 void RemoteGraphicsContextGLProxy::prepareForDisplay()
 {
     if (isContextLost())
         return;
-#if PLATFORM(COCOA)
-    MachSendRight displayBufferSendRight;
-    auto sendResult = sendSync(Messages::RemoteGraphicsContextGL::PrepareForDisplay(), Messages::RemoteGraphicsContextGL::PrepareForDisplay::Reply(displayBufferSendRight));
-    if (!sendResult) {
-        markContextLost();
-        return;
-    }
-    auto displayBuffer = IOSurface::createFromSendRight(WTFMove(displayBufferSendRight), WebCore::DestinationColorSpace::SRGB());
-    if (displayBuffer) {
-        auto& sc = platformSwapChain();
-        sc.recycleBuffer();
-        sc.present({ WTFMove(displayBuffer), nullptr });
-    }
-#else
     auto sendResult = sendSync(Messages::RemoteGraphicsContextGL::PrepareForDisplay(), Messages::RemoteGraphicsContextGL::PrepareForDisplay::Reply());
     if (!sendResult) {
         markContextLost();
         return;
     }
-#endif
     markLayerComposited();
 }
+#endif
 
 void RemoteGraphicsContextGLProxy::ensureExtensionEnabled(const String& extension)
 {

Added: trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/RemoteGraphicsContextGLProxyCocoa.mm (0 => 284371)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/RemoteGraphicsContextGLProxyCocoa.mm	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/RemoteGraphicsContextGLProxyCocoa.mm	2021-10-18 14:57:22 UTC (rev 284371)
@@ -0,0 +1,64 @@
+/*
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#import "config.h"
+#import "RemoteGraphicsContextGLProxy.h"
+
+#if ENABLE(GPU_PROCESS) && ENABLE(WEBGL)
+#import "RemoteGraphicsContextGLMessages.h"
+#import <WebCore/IOSurface.h>
+#import <WebCore/WebGLLayer.h>
+#import <wtf/BlockObjCExceptions.h>
+
+namespace WebKit {
+using namespace WebCore;
+
+void RemoteGraphicsContextGLProxy::prepareForDisplay()
+{
+    if (isContextLost())
+        return;
+    MachSendRight displayBufferSendRight;
+    auto sendResult = sendSync(Messages::RemoteGraphicsContextGL::PrepareForDisplay(), Messages::RemoteGraphicsContextGL::PrepareForDisplay::Reply(displayBufferSendRight));
+    if (!sendResult) {
+        markContextLost();
+        return;
+    }
+    if (!displayBufferSendRight)
+        return;
+    auto displayBuffer = WebCore::IOSurface::createFromSendRight(WTFMove(displayBufferSendRight), WebCore::DestinationColorSpace::SRGB());
+    if (!displayBuffer) {
+        markContextLost();
+        return;
+    }
+    m_displayBuffer = WTFMove(displayBuffer);
+    BEGIN_BLOCK_OBJC_EXCEPTIONS
+    [m_webGLLayer setContents:m_displayBuffer->asLayerContents()];
+    END_BLOCK_OBJC_EXCEPTIONS
+    markLayerComposited();
+}
+
+}
+
+#endif

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm (284370 => 284371)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm	2021-10-18 14:57:22 UTC (rev 284371)
@@ -63,6 +63,7 @@
 #import <WebCore/HTMLInputElement.h>
 #import <WebCore/WebCoreObjCExtras.h>
 #import <wtf/WeakObjCPtr.h>
+#import <wtf/cocoa/VectorCocoa.h>
 
 @interface NSObject (WKDeprecatedDelegateMethods)
 - (void)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller didSameDocumentNavigationForFrame:(WKWebProcessPlugInFrame *)frame;

Modified: trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPluginPasswordField.mm (284370 => 284371)


--- trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPluginPasswordField.mm	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPluginPasswordField.mm	2021-10-18 14:57:22 UTC (rev 284371)
@@ -31,6 +31,7 @@
 #import "PDFLayerControllerSPI.h"
 #import "PDFPlugin.h"
 #import <Quartz/Quartz.h>
+#import <WebCore/AddEventListenerOptions.h>
 #import <WebCore/Event.h>
 #import <WebCore/EventNames.h>
 #import <WebCore/HTMLElement.h>

Modified: trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemoteModelHosting.mm (284370 => 284371)


--- trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemoteModelHosting.mm	2021-10-18 13:18:33 UTC (rev 284370)
+++ trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemoteModelHosting.mm	2021-10-18 14:57:22 UTC (rev 284371)
@@ -66,9 +66,9 @@
     properties.model = m_model.ptr();
 }
 
-void PlatformCALayerRemoteModelHosting::dumpAdditionalProperties(TextStream& ts, OptionSet<PlatformLayerTreeAsTextFlags> flags)
+void PlatformCALayerRemoteModelHosting::dumpAdditionalProperties(TextStream& ts, OptionSet<WebCore::PlatformLayerTreeAsTextFlags> flags)
 {
-    if (flags.contains(PlatformLayerTreeAsTextFlags::IncludeModels))
+    if (flags.contains(WebCore::PlatformLayerTreeAsTextFlags::IncludeModels))
         ts << indent << "(model data size " << m_model->data()->size() << ")\n";
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to