Title: [135995] trunk/Source/WebCore
Revision
135995
Author
[email protected]
Date
2012-11-28 04:07:27 -0800 (Wed, 28 Nov 2012)

Log Message

GraphicsSurface: Implement usage of GraphicsSurface for WebGL in WK1.
https://bugs.webkit.org/show_bug.cgi?id=103497

Using GraphicsSurface for WebGL in WK1 allows us to share
the code with the WK2 implementation.

Reviewed by Simon Hausmann.

* platform/graphics/qt/GraphicsContext3DQt.cpp:
(WebCore::GraphicsContext3DPrivate::GraphicsContext3DPrivate):
    Remove obsolete code.
(WebCore::GraphicsContext3DPrivate::paintToTextureMapper):
    After blitting the multisample framebuffer,
    we can copy the contents onto the GraphicsSurface.
    Right after that we can use the GraphicsSurface
    as a texture origin to paint to the TextureMapper.
    Flags related to flipping and blending are being resolved
    by GraphicsSurface, and do not need to be handled here anymore.
(WebCore::GraphicsContext3DPrivate::copyToGraphicsSurface):
    Remove a redundant makeCurrentIfNeeded call.
    The original context is being restored by
    blitMultisampleFramebufferAndRestoreContext anyway.
    Instead of explicitly calling swapBuffers here,
    we call swapBuffers on the GraphicsSurface implicitly
    after in GraphicsSurfacePrivate::copyFromTexture().
* platform/graphics/surfaces/mac/GraphicsSurfaceMac.cpp:
    Add members to hold the reading end texture IDs.
    The texture on the reading side are in a different
    context than the texture on the writing side.
    By using GraphicsSurface in WK1 we have to distinguish
    between these textures, as a single instance serves
    for reading and writing.
(WebCore::GraphicsSurfacePrivate::GraphicsSurfacePrivate):
(WebCore::GraphicsSurfacePrivate::~GraphicsSurfacePrivate):
(WebCore::GraphicsSurfacePrivate::swapBuffers):
(WebCore::GraphicsSurfacePrivate::copyFromTexture):
    Add an implicit call to swapBuffers().
(WebCore::GraphicsSurfacePrivate::frontBufferTextureID):
(GraphicsSurfacePrivate):
* platform/graphics/surfaces/qt/GraphicsSurfaceGLX.cpp:
(WebCore::GraphicsSurfacePrivate::GraphicsSurfacePrivate):
    Add a flag to distinguish between sending and receiving/reading
    side of the surface. This flag is being initialized in the constructor
    which is the only place where we know if an instance will be used for
    writing or reading.
    The purpose of this flag is to avoid erroneously swapping the buffers
    on the reading side. We can no longer rely on m_xPixmap for this purpose.
(WebCore::GraphicsSurfacePrivate::swapBuffers):
(WebCore::GraphicsSurfacePrivate::copyFromTexture):
(WebCore::GraphicsSurfacePrivate::glxPixmap):
    Lazily create the GLX pixmap on demand.
(GraphicsSurfacePrivate):
(WebCore::GraphicsSurface::platformImport):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (135994 => 135995)


--- trunk/Source/WebCore/ChangeLog	2012-11-28 11:48:34 UTC (rev 135994)
+++ trunk/Source/WebCore/ChangeLog	2012-11-28 12:07:27 UTC (rev 135995)
@@ -1,3 +1,59 @@
+2012-11-28  Zeno Albisser  <[email protected]>
+
+        GraphicsSurface: Implement usage of GraphicsSurface for WebGL in WK1.
+        https://bugs.webkit.org/show_bug.cgi?id=103497
+
+        Using GraphicsSurface for WebGL in WK1 allows us to share
+        the code with the WK2 implementation.
+
+        Reviewed by Simon Hausmann.
+
+        * platform/graphics/qt/GraphicsContext3DQt.cpp:
+        (WebCore::GraphicsContext3DPrivate::GraphicsContext3DPrivate):
+            Remove obsolete code.
+        (WebCore::GraphicsContext3DPrivate::paintToTextureMapper):
+            After blitting the multisample framebuffer,
+            we can copy the contents onto the GraphicsSurface.
+            Right after that we can use the GraphicsSurface
+            as a texture origin to paint to the TextureMapper.
+            Flags related to flipping and blending are being resolved
+            by GraphicsSurface, and do not need to be handled here anymore.
+        (WebCore::GraphicsContext3DPrivate::copyToGraphicsSurface):
+            Remove a redundant makeCurrentIfNeeded call.
+            The original context is being restored by
+            blitMultisampleFramebufferAndRestoreContext anyway.
+            Instead of explicitly calling swapBuffers here,
+            we call swapBuffers on the GraphicsSurface implicitly
+            after in GraphicsSurfacePrivate::copyFromTexture().
+        * platform/graphics/surfaces/mac/GraphicsSurfaceMac.cpp:
+            Add members to hold the reading end texture IDs.
+            The texture on the reading side are in a different
+            context than the texture on the writing side.
+            By using GraphicsSurface in WK1 we have to distinguish
+            between these textures, as a single instance serves
+            for reading and writing.
+        (WebCore::GraphicsSurfacePrivate::GraphicsSurfacePrivate):
+        (WebCore::GraphicsSurfacePrivate::~GraphicsSurfacePrivate):
+        (WebCore::GraphicsSurfacePrivate::swapBuffers):
+        (WebCore::GraphicsSurfacePrivate::copyFromTexture):
+            Add an implicit call to swapBuffers().
+        (WebCore::GraphicsSurfacePrivate::frontBufferTextureID):
+        (GraphicsSurfacePrivate):
+        * platform/graphics/surfaces/qt/GraphicsSurfaceGLX.cpp:
+        (WebCore::GraphicsSurfacePrivate::GraphicsSurfacePrivate):
+            Add a flag to distinguish between sending and receiving/reading
+            side of the surface. This flag is being initialized in the constructor
+            which is the only place where we know if an instance will be used for
+            writing or reading.
+            The purpose of this flag is to avoid erroneously swapping the buffers
+            on the reading side. We can no longer rely on m_xPixmap for this purpose.
+        (WebCore::GraphicsSurfacePrivate::swapBuffers):
+        (WebCore::GraphicsSurfacePrivate::copyFromTexture):
+        (WebCore::GraphicsSurfacePrivate::glxPixmap):
+            Lazily create the GLX pixmap on demand.
+        (GraphicsSurfacePrivate):
+        (WebCore::GraphicsSurface::platformImport):
+
 2012-11-28  Roger Fong  <[email protected]>
 
         Unreviewed. Fix extra spaces in SimpleFontData::initGDIFont().

Modified: trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp (135994 => 135995)


--- trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp	2012-11-28 11:48:34 UTC (rev 135994)
+++ trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp	2012-11-28 12:07:27 UTC (rev 135995)
@@ -108,17 +108,6 @@
     , m_platformContext(0)
     , m_surfaceOwner(0)
 {
-    if (m_hostWindow && m_hostWindow->platformPageClient()) {
-        // This is the WebKit1 code path.
-        QWebPageClient* webPageClient = m_hostWindow->platformPageClient();
-        webPageClient->createPlatformGraphicsContext3D(&m_platformContext, &m_surface, &m_surfaceOwner);
-        if (!m_surface)
-            return;
-
-        makeCurrentIfNeeded();
-        return;
-    }
-
     if (renderStyle == GraphicsContext3D::RenderToCurrentGLContext) {
         m_platformContext = QOpenGLContext::currentContext();
         m_surface = m_platformContext->surface();
@@ -224,10 +213,10 @@
     blitMultisampleFramebufferAndRestoreContext();
 
     if (textureMapper->accelerationMode() == TextureMapper::OpenGLMode) {
+        m_graphicsSurface->copyFromTexture(m_context->m_texture, IntRect(0, 0, m_context->m_currentWidth, m_context->m_currentHeight));
+
         TextureMapperGL* texmapGL = static_cast<TextureMapperGL*>(textureMapper);
-        TextureMapperGL::Flags flags = TextureMapperGL::ShouldFlipTexture | (m_context->m_attrs.alpha ? TextureMapperGL::SupportsBlending : 0);
-        IntSize textureSize(m_context->m_currentWidth, m_context->m_currentHeight);
-        texmapGL->drawTexture(m_context->m_texture, flags, textureSize, targetRect, matrix, opacity, mask);
+        m_graphicsSurface->paintToTextureMapper(texmapGL, targetRect, matrix, opacity, mask);
         return;
     }
 
@@ -288,10 +277,8 @@
         return 0;
 
     blitMultisampleFramebufferAndRestoreContext();
-    makeCurrentIfNeeded();
     m_graphicsSurface->copyFromTexture(m_context->m_texture, IntRect(0, 0, m_context->m_currentWidth, m_context->m_currentHeight));
-    uint32_t frontBuffer = m_graphicsSurface->swapBuffers();
-    return frontBuffer;
+    return m_graphicsSurface->frontBuffer();
 }
 
 GraphicsSurfaceToken GraphicsContext3DPrivate::graphicsSurfaceToken() const

Modified: trunk/Source/WebCore/platform/graphics/surfaces/mac/GraphicsSurfaceMac.cpp (135994 => 135995)


--- trunk/Source/WebCore/platform/graphics/surfaces/mac/GraphicsSurfaceMac.cpp	2012-11-28 11:48:34 UTC (rev 135994)
+++ trunk/Source/WebCore/platform/graphics/surfaces/mac/GraphicsSurfaceMac.cpp	2012-11-28 12:07:27 UTC (rev 135995)
@@ -77,7 +77,9 @@
         , m_size(size)
         , m_token(token)
         , m_frontBufferTexture(0)
+        , m_frontBufferReadTexture(0)
         , m_backBufferTexture(0)
+        , m_backBufferReadTexture(0)
         , m_readFbo(0)
         , m_drawFbo(0)
     {
@@ -89,7 +91,9 @@
         : m_context(0)
         , m_size(size)
         , m_frontBufferTexture(0)
+        , m_frontBufferReadTexture(0)
         , m_backBufferTexture(0)
+        , m_backBufferReadTexture(0)
         , m_readFbo(0)
         , m_drawFbo(0)
     {
@@ -152,9 +156,15 @@
         if (m_frontBufferTexture)
             glDeleteTextures(1, &m_frontBufferTexture);
 
+        if (m_frontBufferReadTexture)
+            glDeleteTextures(1, &m_frontBufferReadTexture);
+
         if (m_backBufferTexture)
             glDeleteTextures(1, &m_backBufferTexture);
 
+        if (m_backBufferReadTexture)
+            glDeleteTextures(1, &m_backBufferReadTexture);
+
         if (m_frontBuffer)
             CFRelease(IOSurfaceRef(m_frontBuffer));
 
@@ -181,6 +191,7 @@
     {
         std::swap(m_frontBuffer, m_backBuffer);
         std::swap(m_frontBufferTexture, m_backBufferTexture);
+        std::swap(m_frontBufferReadTexture, m_backBufferReadTexture);
 
         return IOSurfaceGetID(m_frontBuffer);
     }
@@ -237,6 +248,7 @@
         // Flushing the gl command buffer is necessary to ensure the texture has correctly been bound to the IOSurface.
         glFlush();
 
+        swapBuffers();
         doneCurrent();
     }
 
@@ -247,10 +259,10 @@
 
     uint32_t frontBufferTextureID()
     {
-        if (!m_frontBufferTexture)
-            m_frontBufferTexture = createTexture(m_frontBuffer);
+        if (!m_frontBufferReadTexture)
+            m_frontBufferReadTexture = createTexture(m_frontBuffer);
 
-        return m_frontBufferTexture;
+        return m_frontBufferReadTexture;
     }
 
     uint32_t backBufferTextureID()
@@ -283,7 +295,9 @@
     PlatformGraphicsSurface m_frontBuffer;
     PlatformGraphicsSurface m_backBuffer;
     uint32_t m_frontBufferTexture;
+    uint32_t m_frontBufferReadTexture;
     uint32_t m_backBufferTexture;
+    uint32_t m_backBufferReadTexture;
     uint32_t m_readFbo;
     uint32_t m_drawFbo;
     GraphicsSurfaceToken m_token;

Modified: trunk/Source/WebCore/platform/graphics/surfaces/qt/GraphicsSurfaceGLX.cpp (135994 => 135995)


--- trunk/Source/WebCore/platform/graphics/surfaces/qt/GraphicsSurfaceGLX.cpp	2012-11-28 11:48:34 UTC (rev 135994)
+++ trunk/Source/WebCore/platform/graphics/surfaces/qt/GraphicsSurfaceGLX.cpp	2012-11-28 12:07:27 UTC (rev 135995)
@@ -138,7 +138,7 @@
 
 struct GraphicsSurfacePrivate {
     GraphicsSurfacePrivate(const PlatformGraphicsContext3D shareContext = 0)
-        : m_display(0)
+        : m_display(m_offScreenWindow.display())
         , m_xPixmap(0)
         , m_glxPixmap(0)
         , m_surface(0)
@@ -149,9 +149,9 @@
         , m_fbConfig(0)
         , m_textureIsYInverted(false)
         , m_hasAlpha(false)
+        , m_isReceiver(false)
     {
         GLXContext shareContextObject = 0;
-        m_display = m_offScreenWindow.display();
 
 #if PLATFORM(QT)
         if (shareContext) {
@@ -211,6 +211,7 @@
         , m_fbConfig(0)
         , m_textureIsYInverted(false)
         , m_hasAlpha(false)
+        , m_isReceiver(true)
     { }
 
     ~GraphicsSurfacePrivate()
@@ -299,10 +300,9 @@
 
     void swapBuffers()
     {
-        // If there is a xpixmap, we are on the reading side and do not want to swap any buffers.
         // The buffers are being switched on the writing side, the reading side just reads
         // whatever texture the XWindow contains.
-        if (m_xPixmap)
+        if (m_isReceiver)
             return;
 
         GLXContext glContext = glXGetCurrentContext();
@@ -343,12 +343,19 @@
         pGlDeleteFramebuffers(1, &originFBO);
 
         glPopAttrib();
+
+        swapBuffers();
         doneCurrent();
     }
 
     Display* display() const { return m_display; }
 
-    GLXPixmap glxPixmap() const { return m_glxPixmap; }
+    GLXPixmap glxPixmap() const
+    {
+        if (!m_glxPixmap && m_surface)
+            const_cast<GraphicsSurfacePrivate*>(this)->createPixmap(m_surface);
+        return m_glxPixmap;
+    }
 
     IntSize size() const
     {
@@ -374,6 +381,7 @@
     GLXFBConfig m_fbConfig;
     bool m_textureIsYInverted;
     bool m_hasAlpha;
+    bool m_isReceiver;
 };
 
 static bool resolveGLMethods(GraphicsSurfacePrivate*)
@@ -485,8 +493,6 @@
     if (!resolveGLMethods(surface->m_private))
         return PassRefPtr<GraphicsSurface>();
 
-    surface->m_private->createPixmap(surface->m_platformSurface);
-
     return surface;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to