Changeset 193723 in webkit


Ignore:
Timestamp:
Dec 8, 2015 12:36:02 AM (8 years ago)
Author:
yoon@igalia.com
Message:

[ThreadedCompositor] Support WebGL for OpenGL.
https://bugs.webkit.org/show_bug.cgi?id=143300

Reviewed by Žan Doberšek.

To remove pixel transfer operation, this patch adds m_compositorFBO which uses same depth and stencil
buffer with m_fbo but uses m_compositorTexture as a color attachment in GraphicsContext3D.
Because switching target framebuffer is cheaper than pixel transfer operation and switching color
attachment of m_fbo. In Threaded Compositor, when WebGL renders a scene, prepareTexture swaps
m_fbo with m_compositorFBO and send the color attachment to the compositor thread.
This patch only supports WebGL for OpenGL. OpenGLES will be covered in following-up patches.

No new tests needed.

  • platform/graphics/GraphicsContext3D.h:
  • platform/graphics/GraphicsContext3DPrivate.cpp:

(WebCore::GraphicsContext3DPrivate::GraphicsContext3DPrivate):
(WebCore::GraphicsContext3DPrivate::proxy):
(WebCore::GraphicsContext3DPrivate::swapBuffersIfNeeded):
Implement interfaces to pass a rendered texture to the compositing
thread.

  • platform/graphics/GraphicsContext3DPrivate.h:
  • platform/graphics/cairo/GraphicsContext3DCairo.cpp:

(WebCore::GraphicsContext3D::GraphicsContext3D):
(WebCore::GraphicsContext3D::~GraphicsContext3D):
Create additional compositing texture and FBO to swaping buffers for
threaded compositor.

  • platform/graphics/opengl/GraphicsContext3DOpenGL.cpp:

(WebCore::GraphicsContext3D::reshapeFBOs):
(WebCore::GraphicsContext3D::attachDepthAndStencilBufferIfNeeded):
Split attaching depth and stencil buffer codes from reshapeFBOs
to make complete framebuffer with not only m_fbo but m_compositorFBO also.

  • platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:

(WebCore::GraphicsContext3D::prepareTexture):
If we are in the threaded compositor, we will swap m_fbo with
m_compositorFBO instead of copying it.

Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r193688 r193723  
     12015-12-08  Gwang Yoon Hwang  <yoon@igalia.com>
     2
     3        [ThreadedCompositor] Support WebGL for OpenGL.
     4        https://bugs.webkit.org/show_bug.cgi?id=143300
     5
     6        Reviewed by Žan Doberšek.
     7
     8        To remove pixel transfer operation, this patch adds m_compositorFBO which uses same depth and stencil
     9        buffer with m_fbo but uses m_compositorTexture as a color attachment in GraphicsContext3D.
     10        Because switching target framebuffer is cheaper than pixel transfer operation and switching color
     11        attachment of m_fbo. In Threaded Compositor, when WebGL renders a scene, prepareTexture swaps
     12        m_fbo with m_compositorFBO and send the color attachment to the compositor thread.
     13        This patch only supports WebGL for OpenGL. OpenGLES will be covered in following-up patches.
     14
     15        No new tests needed.
     16
     17        * platform/graphics/GraphicsContext3D.h:
     18        * platform/graphics/GraphicsContext3DPrivate.cpp:
     19        (WebCore::GraphicsContext3DPrivate::GraphicsContext3DPrivate):
     20        (WebCore::GraphicsContext3DPrivate::proxy):
     21        (WebCore::GraphicsContext3DPrivate::swapBuffersIfNeeded):
     22        Implement interfaces to pass a rendered texture to the compositing
     23        thread.
     24        * platform/graphics/GraphicsContext3DPrivate.h:
     25        * platform/graphics/cairo/GraphicsContext3DCairo.cpp:
     26        (WebCore::GraphicsContext3D::GraphicsContext3D):
     27        (WebCore::GraphicsContext3D::~GraphicsContext3D):
     28        Create additional compositing texture and FBO to swaping buffers for
     29        threaded compositor.
     30        * platform/graphics/opengl/GraphicsContext3DOpenGL.cpp:
     31        (WebCore::GraphicsContext3D::reshapeFBOs):
     32        (WebCore::GraphicsContext3D::attachDepthAndStencilBufferIfNeeded):
     33        Split attaching depth and stencil buffer codes from reshapeFBOs
     34        to make complete framebuffer with not only m_fbo but m_compositorFBO also.
     35        * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
     36        (WebCore::GraphicsContext3D::prepareTexture):
     37        If we are in the threaded compositor, we will swap m_fbo with
     38        m_compositorFBO instead of copying it.
     39
    1402015-12-07  Zalan Bujtas  <zalan@apple.com>
    241
  • trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h

    r189144 r193723  
    12941294    bool reshapeFBOs(const IntSize&);
    12951295    void resolveMultisamplingIfNecessary(const IntRect& = IntRect());
     1296    void attachDepthAndStencilBufferIfNeeded(GLuint internalDepthStencilFormat, int width, int height);
    12961297#if PLATFORM(EFL) && USE(GRAPHICS_SURFACE)
    12971298    void createGraphicsSurfaces(const IntSize&);
     
    14181419    GC3Duint m_compositorTexture;
    14191420    GC3Duint m_fbo;
     1421#if USE(COORDINATED_GRAPHICS_THREADED)
     1422    GC3Duint m_compositorFBO;
     1423#endif
    14201424
    14211425    GC3Duint m_depthBuffer;
  • trunk/Source/WebCore/platform/graphics/GraphicsContext3DPrivate.cpp

    r193630 r193723  
    4242#endif
    4343
     44#if USE(COORDINATED_GRAPHICS_THREADED)
     45#include "TextureMapperPlatformLayerBuffer.h"
     46#endif
     47
    4448using namespace std;
    4549
     
    6064        break;
    6165    }
     66
     67#if USE(COORDINATED_GRAPHICS_THREADED)
     68    if (m_renderStyle == GraphicsContext3D::RenderOffscreen)
     69        m_platformLayerProxy = adoptRef(new TextureMapperPlatformLayerProxy());
     70#endif
    6271}
    6372
     
    8392RefPtr<TextureMapperPlatformLayerProxy> GraphicsContext3DPrivate::proxy() const
    8493{
    85     notImplemented();
    86     return nullptr;
     94    return m_platformLayerProxy.copyRef();
    8795}
    88 #elif USE(TEXTURE_MAPPER)
     96
     97void GraphicsContext3DPrivate::swapBuffersIfNeeded()
     98{
     99    ASSERT(m_renderStyle == GraphicsContext3D::RenderOffscreen);
     100    if (m_context->layerComposited())
     101        return;
     102
     103    m_context->prepareTexture();
     104    IntSize textureSize(m_context->m_currentWidth, m_context->m_currentHeight);
     105    TextureMapperGL::Flags flags = TextureMapperGL::ShouldFlipTexture | (m_context->m_attrs.alpha ? TextureMapperGL::ShouldBlend : 0);
     106
     107    {
     108        LockHolder holder(m_platformLayerProxy->lock());
     109        m_platformLayerProxy->pushNextBuffer(std::make_unique<TextureMapperPlatformLayerBuffer>(m_context->m_compositorTexture, textureSize, flags));
     110    }
     111
     112    m_context->markLayerComposited();
     113}
     114#elif USE(TEXTURE_MAPPER) && !USE(COORDINATED_GRAPHICS_THREADED)
    89115void GraphicsContext3DPrivate::paintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity)
    90116{
  • trunk/Source/WebCore/platform/graphics/GraphicsContext3DPrivate.h

    r193630 r193723  
    2525
    2626#if USE(COORDINATED_GRAPHICS_THREADED)
     27#include "BitmapTextureGL.h"
    2728#include "TextureMapperPlatformLayerProxy.h"
    2829#elif USE(TEXTURE_MAPPER)
     
    4950#if USE(COORDINATED_GRAPHICS_THREADED)
    5051    virtual RefPtr<TextureMapperPlatformLayerProxy> proxy() const override;
    51     virtual void swapBuffersIfNeeded() override { };
     52    virtual void swapBuffersIfNeeded() override;
    5253#elif USE(TEXTURE_MAPPER)
    5354    virtual void paintToTextureMapper(TextureMapper*, const FloatRect& target, const TransformationMatrix&, float opacity);
     
    5859    std::unique_ptr<GLContext> m_glContext;
    5960    GraphicsContext3D::RenderStyle m_renderStyle;
     61
     62#if USE(COORDINATED_GRAPHICS_THREADED)
     63    RefPtr<TextureMapperPlatformLayerProxy> m_platformLayerProxy;
     64    RefPtr<BitmapTextureGL> m_compositorTexture;
     65#endif
    6066};
    6167
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp

    r183432 r193723  
    8686    , m_compositorTexture(0)
    8787    , m_fbo(0)
     88#if USE(COORDINATED_GRAPHICS_THREADED)
     89    , m_compositorFBO(0)
     90#endif
    8891    , m_depthStencilBuffer(0)
     92    , m_layerComposited(false)
    8993    , m_multisampleFBO(0)
    9094    , m_multisampleDepthStencilBuffer(0)
     
    110114        ::glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
    111115
     116#if USE(COORDINATED_GRAPHICS_THREADED)
     117        ::glGenFramebuffers(1, &m_compositorFBO);
     118        ::glGenTextures(1, &m_compositorTexture);
     119        ::glBindTexture(GL_TEXTURE_2D, m_compositorTexture);
     120        ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     121        ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     122        ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
     123        ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
     124        ::glBindTexture(GL_TEXTURE_2D, 0);
     125#endif
     126
    112127        m_state.boundFBO = m_fbo;
    113128        if (!m_attrs.antialias && (m_attrs.stencil || m_attrs.depth))
     
    175190    }
    176191    ::glDeleteFramebuffers(1, &m_fbo);
     192#if USE(COORDINATED_GRAPHICS_THREADED)
     193    ::glDeleteFramebuffers(1, &m_compositorFBO);
     194#endif
    177195}
    178196
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp

    r183432 r193723  
    173173        ::glTexImage2D(GL_TEXTURE_2D, 0, m_internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
    174174        ::glBindTexture(GL_TEXTURE_2D, 0);
    175     }
    176 #endif
    177 
     175#if USE(COORDINATED_GRAPHICS_THREADED)
     176        ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_compositorFBO);
     177        ::glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_compositorTexture, 0);
     178        attachDepthAndStencilBufferIfNeeded(internalDepthStencilFormat, width, height);
     179        ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
     180#endif
     181    }
     182#endif
     183
     184    attachDepthAndStencilBufferIfNeeded(internalDepthStencilFormat, width, height);
     185
     186    bool mustRestoreFBO = true;
     187    if (m_attrs.antialias) {
     188        ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO);
     189        if (m_state.boundFBO == m_multisampleFBO)
     190            mustRestoreFBO = false;
     191    } else {
     192        if (m_state.boundFBO == m_fbo)
     193            mustRestoreFBO = false;
     194    }
     195
     196    return mustRestoreFBO;
     197}
     198
     199void GraphicsContext3D::attachDepthAndStencilBufferIfNeeded(GLuint internalDepthStencilFormat, int width, int height)
     200{
    178201    if (!m_attrs.antialias && (m_attrs.stencil || m_attrs.depth)) {
    179202        ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthStencilBuffer);
     
    190213        notImplemented();
    191214    }
    192 
    193     bool mustRestoreFBO = true;
    194     if (m_attrs.antialias) {
    195         ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO);
    196         if (m_state.boundFBO == m_multisampleFBO)
    197             mustRestoreFBO = false;
    198     } else {
    199         if (m_state.boundFBO == m_fbo)
    200             mustRestoreFBO = false;
    201     }
    202 
    203     return mustRestoreFBO;
    204215}
    205216
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp

    r190382 r193723  
    224224    makeContextCurrent();
    225225
     226#if !USE(COORDINATED_GRAPHICS_THREADED)
    226227    TemporaryOpenGLSetting scopedScissor(GL_SCISSOR_TEST, GL_FALSE);
    227228    TemporaryOpenGLSetting scopedDither(GL_DITHER, GL_FALSE);
    228    
     229#endif
     230
    229231    if (m_attrs.antialias)
    230232        resolveMultisamplingIfNecessary();
     233
     234#if USE(COORDINATED_GRAPHICS_THREADED)
     235    std::swap(m_fbo, m_compositorFBO);
     236    std::swap(m_texture, m_compositorTexture);
     237
     238    if (m_state.boundFBO != m_compositorFBO)
     239        ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_state.boundFBO);
     240    else
     241        ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_fbo);
     242    return;
     243#endif
    231244
    232245    ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_fbo);
  • trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp

    r193630 r193723  
    387387    if (m_platformLayer)
    388388        m_pendingPlatformLayerOperation |= SyncPlatformLayer;
     389#elif USE(COORDINATED_GRAPHICS_THREADED)
     390    if (m_platformLayer)
     391        m_shouldSyncPlatformLayer = true;
    389392#endif
    390393
Note: See TracChangeset for help on using the changeset viewer.