Title: [291878] trunk/Source/WebCore
Revision
291878
Author
[email protected]
Date
2022-03-25 12:19:14 -0700 (Fri, 25 Mar 2022)

Log Message

[TextureMapper] Implement GraphicsContextGLTextureMapperANGLE::prepareForDisplay()
https://bugs.webkit.org/show_bug.cgi?id=238322

Patch by Zan Dobersek <[email protected]> on 2022-03-25
Reviewed by Darin Adler.

Use GraphicsContextGLTextureMapperANGLE::prepareForDisplay() to handle
buffer/texture preparation during the composition state flush instead of
doing it in the platform layer integration class.

The virtual GraphicsContextGL::prepareForDisplay() method is called
during the composition state flush on every context-backed canvas that
was changed since the previous flush. It's the most optimal location to
handle content display preparation, and it simplifies the actual display
through the TextureMapper facilities. It's a simple matter of ensuring
a current context and invoking texture preparation.

In Nicosia::GCGLANGLELayer::swapBuffersIfNeeded(), there's no need to
bother with the state of layer composition, everything is already set
to be wrapped into a buffer and pushed into the composition engine.

Similarly in TextureMapperGCGLPlatformLayer::paintToTextureMapper(),
the texture is already prepared and can be painted immediately, with
no further need for GL context switching.

GraphicsContextGLANGLE::prepareTexture() is not really used anymore
so it can be removed, and prepareTextureImpl() can use that name.
The method is still virtual so that GraphicsContextGLTextureMapperANGLE
can provide a more focused override, but GraphicsContextGLCocoa should
at some point also use its own implementation, at which point the
method could just be rolled into each class's prepareForDisplay().

No new tests, covered by existing tests.

* platform/graphics/angle/GraphicsContextGLANGLE.cpp:
(WebCore::GraphicsContextGLANGLE::prepareTexture):
(WebCore::GraphicsContextGLANGLE::prepareTextureImpl): Deleted.
* platform/graphics/angle/GraphicsContextGLANGLE.h:
* platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
(WebCore::GraphicsContextGLCocoa::prepareForDisplay):
* platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp:
(Nicosia::GCGLANGLELayer::swapBuffersIfNeeded):
* platform/graphics/opengl/GraphicsContextGLOpenGL.h:
Remove unused prepareTextureImpl() method declaration.
* platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp:
(WebCore::GraphicsContextGLTextureMapperANGLE::prepareTexture):
(WebCore::GraphicsContextGLTextureMapperANGLE::prepareForDisplay):
(WebCore::GraphicsContextGLTextureMapperANGLE::prepareTextureImpl): Deleted.
* platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h:
* platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp:
(WebCore::TextureMapperGCGLPlatformLayer::paintToTextureMapper):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (291877 => 291878)


--- trunk/Source/WebCore/ChangeLog	2022-03-25 19:18:10 UTC (rev 291877)
+++ trunk/Source/WebCore/ChangeLog	2022-03-25 19:19:14 UTC (rev 291878)
@@ -1,3 +1,56 @@
+2022-03-25  Zan Dobersek  <[email protected]>
+
+        [TextureMapper] Implement GraphicsContextGLTextureMapperANGLE::prepareForDisplay()
+        https://bugs.webkit.org/show_bug.cgi?id=238322
+
+        Reviewed by Darin Adler.
+
+        Use GraphicsContextGLTextureMapperANGLE::prepareForDisplay() to handle
+        buffer/texture preparation during the composition state flush instead of
+        doing it in the platform layer integration class.
+
+        The virtual GraphicsContextGL::prepareForDisplay() method is called
+        during the composition state flush on every context-backed canvas that
+        was changed since the previous flush. It's the most optimal location to
+        handle content display preparation, and it simplifies the actual display
+        through the TextureMapper facilities. It's a simple matter of ensuring
+        a current context and invoking texture preparation.
+
+        In Nicosia::GCGLANGLELayer::swapBuffersIfNeeded(), there's no need to
+        bother with the state of layer composition, everything is already set
+        to be wrapped into a buffer and pushed into the composition engine.
+
+        Similarly in TextureMapperGCGLPlatformLayer::paintToTextureMapper(),
+        the texture is already prepared and can be painted immediately, with
+        no further need for GL context switching.
+
+        GraphicsContextGLANGLE::prepareTexture() is not really used anymore
+        so it can be removed, and prepareTextureImpl() can use that name.
+        The method is still virtual so that GraphicsContextGLTextureMapperANGLE
+        can provide a more focused override, but GraphicsContextGLCocoa should
+        at some point also use its own implementation, at which point the
+        method could just be rolled into each class's prepareForDisplay().
+
+        No new tests, covered by existing tests.
+
+        * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
+        (WebCore::GraphicsContextGLANGLE::prepareTexture):
+        (WebCore::GraphicsContextGLANGLE::prepareTextureImpl): Deleted.
+        * platform/graphics/angle/GraphicsContextGLANGLE.h:
+        * platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
+        (WebCore::GraphicsContextGLCocoa::prepareForDisplay):
+        * platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp:
+        (Nicosia::GCGLANGLELayer::swapBuffersIfNeeded):
+        * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+        Remove unused prepareTextureImpl() method declaration.
+        * platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp:
+        (WebCore::GraphicsContextGLTextureMapperANGLE::prepareTexture):
+        (WebCore::GraphicsContextGLTextureMapperANGLE::prepareForDisplay):
+        (WebCore::GraphicsContextGLTextureMapperANGLE::prepareTextureImpl): Deleted.
+        * platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h:
+        * platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp:
+        (WebCore::TextureMapperGCGLPlatformLayer::paintToTextureMapper):
+
 2022-03-25  Alex Christensen  <[email protected]>
 
         Add css-typed-om color IDL skeletons

Modified: trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp (291877 => 291878)


--- trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp	2022-03-25 19:18:10 UTC (rev 291877)
+++ trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp	2022-03-25 19:19:14 UTC (rev 291878)
@@ -545,17 +545,6 @@
 
 void GraphicsContextGLANGLE::prepareTexture()
 {
-    if (m_layerComposited)
-        return;
-
-    if (!makeContextCurrent())
-        return;
-
-    prepareTextureImpl();
-}
-
-void GraphicsContextGLANGLE::prepareTextureImpl()
-{
     ASSERT(!m_layerComposited);
 
     if (contextAttributes().antialias)

Modified: trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h (291877 => 291878)


--- trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h	2022-03-25 19:18:10 UTC (rev 291877)
+++ trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h	2022-03-25 19:19:14 UTC (rev 291878)
@@ -62,9 +62,6 @@
     };
     static bool releaseThreadResources(ReleaseThreadResourceBehavior);
 
-    // With multisampling on, blit from multisampleFBO to regular FBO.
-    void prepareTexture();
-
     // Get an attribute location without checking the name -> mangledname mapping.
     int getAttribLocationDirect(PlatformGLObject program, const String& name);
 
@@ -369,7 +366,7 @@
     std::optional<PixelBuffer> readPixelsForPaintResults();
 
     bool reshapeFBOs(const IntSize&);
-    virtual void prepareTextureImpl();
+    virtual void prepareTexture();
     void resolveMultisamplingIfNecessary(const IntRect& = IntRect());
     void attachDepthAndStencilBufferIfNeeded(GCGLuint internalDepthStencilFormat, int width, int height);
 #if PLATFORM(COCOA)

Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm (291877 => 291878)


--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm	2022-03-25 19:18:10 UTC (rev 291877)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm	2022-03-25 19:19:14 UTC (rev 291878)
@@ -707,7 +707,7 @@
         return;
     if (!makeContextCurrent())
         return;
-    prepareTextureImpl();
+    prepareTexture();
 
     // The IOSurface will be used from other graphics subsystem, so flush GL commands.
     GL_Flush();

Modified: trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp (291877 => 291878)


--- trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp	2022-03-25 19:18:10 UTC (rev 291877)
+++ trunk/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLELayer.cpp	2022-03-25 19:19:14 UTC (rev 291878)
@@ -45,11 +45,6 @@
 
 void GCGLANGLELayer::swapBuffersIfNeeded()
 {
-    if (m_context.layerComposited())
-        return;
-
-    m_context.prepareTexture();
-
     auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(contentLayer().impl()).proxy();
     auto size = m_context.getInternalFramebufferSize();
 
@@ -66,8 +61,6 @@
             ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy));
             downcast<TextureMapperPlatformLayerProxyGL>(proxy).pushNextBuffer(makeUnique<TextureMapperPlatformLayerDmabuf>(size, format, stride, fd));
         }
-
-        m_context.markLayerComposited();
         return;
     }
 
@@ -90,7 +83,6 @@
         layerBuffer->textureGL().setPendingContents(ImageBuffer::sinkIntoImage(WTFMove(imageBuffer)));
         downcast<TextureMapperPlatformLayerProxyGL>(proxy).pushNextBuffer(WTFMove(layerBuffer));
     }
-    m_context.markLayerComposited();
 }
 
 GCGLANGLELayer::GCGLANGLELayer(GraphicsContextGLTextureMapperANGLE& context)

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


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2022-03-25 19:18:10 UTC (rev 291877)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2022-03-25 19:19:14 UTC (rev 291878)
@@ -446,7 +446,6 @@
     std::optional<PixelBuffer> readPixelsForPaintResults();
 
     bool reshapeFBOs(const IntSize&);
-    void prepareTextureImpl();
     void resolveMultisamplingIfNecessary(const IntRect& = IntRect());
     void attachDepthAndStencilBufferIfNeeded(GCGLuint internalDepthStencilFormat, int width, int height);
 

Modified: trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp (291877 => 291878)


--- trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp	2022-03-25 19:18:10 UTC (rev 291877)
+++ trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp	2022-03-25 19:19:14 UTC (rev 291878)
@@ -346,7 +346,7 @@
     return GraphicsContextGLANGLE::platformInitialize();
 }
 
-void GraphicsContextGLTextureMapperANGLE::prepareTextureImpl()
+void GraphicsContextGLTextureMapperANGLE::prepareTexture()
 {
     ASSERT(!m_layerComposited);
 
@@ -423,6 +423,11 @@
 
 void GraphicsContextGLTextureMapperANGLE::prepareForDisplay()
 {
+    if (m_layerComposited || !makeContextCurrent())
+        return;
+
+    prepareTexture();
+    markLayerComposited();
 }
 
 #if USE(NICOSIA)

Modified: trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h (291877 => 291878)


--- trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h	2022-03-25 19:18:10 UTC (rev 291877)
+++ trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h	2022-03-25 19:19:14 UTC (rev 291878)
@@ -69,7 +69,7 @@
     bool platformInitializeContext() final;
     bool platformInitialize() final;
 
-    void prepareTextureImpl() final;
+    void prepareTexture() final;
 
     RefPtr<GraphicsLayerContentsDisplayDelegate> m_layerContentsDisplayDelegate;
 

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp (291877 => 291878)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp	2022-03-25 19:18:10 UTC (rev 291877)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp	2022-03-25 19:19:14 UTC (rev 291878)
@@ -45,20 +45,11 @@
 
 void TextureMapperGCGLPlatformLayer::paintToTextureMapper(TextureMapper& textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity)
 {
-    GLContext* previousActiveContext = GLContext::current();
-
-    m_context.prepareTexture();
-
-    if (previousActiveContext)
-        previousActiveContext->makeContextCurrent();
-
     auto attrs = m_context.contextAttributes();
     TextureMapperGL& texmapGL = static_cast<TextureMapperGL&>(textureMapper);
     TextureMapperGL::Flags flags = TextureMapperGL::ShouldFlipTexture | (attrs.alpha ? TextureMapperGL::ShouldBlend : 0);
     IntSize textureSize(m_context.m_currentWidth, m_context.m_currentHeight);
     texmapGL.drawTexture(m_context.m_compositorTexture, flags, textureSize, targetRect, matrix, opacity);
-
-    m_context.markLayerComposited();
 }
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to