Changeset 106524 in webkit


Ignore:
Timestamp:
Feb 1, 2012 6:42:14 PM (12 years ago)
Author:
noam.rosenthal@nokia.com
Message:

[Texmap] Use glScissors for clipping in TextureMapperGL when possible
https://bugs.webkit.org/show_bug.cgi?id=77575

Reviewed by Martin Robinson.

Source/WebCore:

Maintain a clipping stack, that helps us use stencils in conjunction with scissors.
We apply scissors when the clip region is rectalinear, and stencil when it's not.

No behavior changes so no new tests.

  • platform/graphics/opengl/TextureMapperGL.cpp:

(SharedGLData):
(WebCore::TextureMapperGLData::SharedGLData::SharedGLData):
(WebCore::TextureMapperGL::drawTexture):
(WebCore::TextureMapperGL::bindSurface):
(WebCore):
(WebCore::scissorClip):
(WebCore::TextureMapperGL::beginScissorClip):
(WebCore::TextureMapperGL::endScissorClip):
(WebCore::TextureMapperGL::beginClip):
(WebCore::TextureMapperGL::endClip):

  • platform/graphics/opengl/TextureMapperGL.h:

(TextureMapperGL):

Source/WebKit2:

Instead of applying the scissor clip in QQuickWebPage, we trickle it down to
TextureMapperGL, and apply it there as part of beginClip(). All direct GL operations are
now cleaned out of QQuickWebPage.

  • UIProcess/API/qt/qquickwebpage.cpp:

(QQuickWebPagePrivate::paintToCurrentGLContext):

  • UIProcess/DrawingAreaProxy.h:

(WebKit::DrawingAreaProxy::paintToCurrentGLContext):

  • UIProcess/DrawingAreaProxyImpl.cpp:

(WebKit::DrawingAreaProxyImpl::paintToCurrentGLContext):

  • UIProcess/DrawingAreaProxyImpl.h:

(DrawingAreaProxyImpl):

  • UIProcess/LayerTreeHostProxy.h:

(LayerTreeHostProxy):

  • UIProcess/qt/LayerTreeHostProxyQt.cpp:

(WebKit::LayerTreeHostProxy::paintToCurrentGLContext):

Location:
trunk/Source
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r106523 r106524  
     12012-02-01  No'am Rosenthal  <noam.rosenthal@nokia.com>
     2
     3        [Texmap] Use glScissors for clipping in TextureMapperGL when possible
     4        https://bugs.webkit.org/show_bug.cgi?id=77575
     5
     6        Reviewed by Martin Robinson.
     7
     8        Maintain a clipping stack, that helps us use stencils in conjunction with scissors.
     9        We apply scissors when the clip region is rectalinear, and stencil when it's not.
     10
     11        No behavior changes so no new tests.
     12
     13        * platform/graphics/opengl/TextureMapperGL.cpp:
     14        (SharedGLData):
     15        (WebCore::TextureMapperGLData::SharedGLData::SharedGLData):
     16        (WebCore::TextureMapperGL::drawTexture):
     17        (WebCore::TextureMapperGL::bindSurface):
     18        (WebCore):
     19        (WebCore::scissorClip):
     20        (WebCore::TextureMapperGL::beginScissorClip):
     21        (WebCore::TextureMapperGL::endScissorClip):
     22        (WebCore::TextureMapperGL::beginClip):
     23        (WebCore::TextureMapperGL::endClip):
     24        * platform/graphics/opengl/TextureMapperGL.h:
     25        (TextureMapperGL):
     26
    1272012-02-01  Anders Carlsson  <andersca@apple.com>
    228
  • trunk/Source/WebCore/platform/graphics/opengl/TextureMapperGL.cpp

    r105737 r106524  
    239239
    240240        int stencilIndex;
    241 
    242         SharedGLData(GLContext glContext) : stencilIndex(1)
     241        Vector<IntRect> clipStack;
     242
     243        SharedGLData(GLContext glContext)
     244            : stencilIndex(1)
    243245        {
    244246            glContextDataMap().add(glContext, this);
     
    322324    TextureMapperGLData()
    323325        : currentProgram(SharedGLData::NoProgram)
     326        , previousProgram(0)
     327        , previousScissorState(0)
    324328        , m_sharedGLData(TextureMapperGLData::SharedGLData::currentSharedGLData())
    325329    { }
     
    327331    TransformationMatrix projectionMatrix;
    328332    int currentProgram;
    329     int previousProgram;
     333    GLint previousProgram;
     334    GLint previousScissorState;
    330335    RefPtr<SharedGLData> m_sharedGLData;
    331336};
     
    521526void TextureMapperGL::beginPainting()
    522527{
     528    // Make sure that no GL error code stays from previous operations.
     529    glGetError();
     530
     531    if (!initializeOpenGLShims())
     532        return;
     533
     534    glGetIntegerv(GL_CURRENT_PROGRAM, &data().previousProgram);
     535    data().previousScissorState = glIsEnabled(GL_SCISSOR_TEST);
     536
     537    glEnable(GL_SCISSOR_TEST);
    523538#if PLATFORM(QT)
    524     if (!initializeOpenGLShims())
    525         return;
    526 
    527     glGetIntegerv(GL_CURRENT_PROGRAM, &m_data->previousProgram);
    528539    if (m_context) {
    529540        QPainter* painter = m_context->platformContext();
     
    531542        painter->beginNativePainting();
    532543    }
     544#endif
    533545    glClearStencil(0);
    534546    glClear(GL_STENCIL_BUFFER_BIT);
    535547    bindSurface(0);
    536 #endif
    537548}
    538549
    539550void TextureMapperGL::endPainting()
    540551{
    541 #if PLATFORM(QT)
    542552    glClearStencil(1);
    543553    glClear(GL_STENCIL_BUFFER_BIT);
    544     glUseProgram(m_data->previousProgram);
     554    glUseProgram(data().previousProgram);
     555
     556    if (data().previousScissorState)
     557        glEnable(GL_SCISSOR_TEST);
     558    else
     559        glDisable(GL_SCISSOR_TEST);
     560
     561#if PLATFORM(QT)
    545562    if (!m_context)
    546563        return;
     
    621638
    622639    GL_CMD(glDisable(GL_DEPTH_TEST))
     640
    623641    GL_CMD(glDrawArrays(GL_TRIANGLE_FAN, 0, 4))
    624642    GL_CMD(glDisableVertexAttribArray(programInfo.vertexAttrib))
     
    816834    GL_CMD(glViewport(0, 0, size().width(), size().height()))
    817835    m_textureMapper->data().projectionMatrix = createProjectionMatrix(size(), false);
    818     glDisable(GL_SCISSOR_TEST);
    819836}
    820837
     
    861878        GL_CMD(glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP))
    862879        GL_CMD(glViewport(0, 0, viewportSize().width(), viewportSize().height()))
     880        data().sharedGLData().clipStack.append(IntRect(IntPoint::zero(), viewportSize()));
    863881        return;
    864882    }
     
    867885}
    868886
     887static void scissorClip(const IntRect& rect)
     888{
     889    GLint viewport[4];
     890    glGetIntegerv(GL_VIEWPORT, viewport);
     891    glScissor(rect.x(), viewport[3] - rect.maxY(), rect.width(), rect.height());
     892}
     893
     894bool TextureMapperGL::beginScissorClip(const TransformationMatrix& modelViewMatrix, const FloatRect& targetRect)
     895{
     896    FloatQuad quad = modelViewMatrix.projectQuad(targetRect);
     897    IntRect rect = quad.enclosingBoundingBox();
     898
     899    // Only use scissors on rectilinear clips.
     900    if (!quad.isRectilinear() || rect.isEmpty()) {
     901        data().sharedGLData().clipStack.append(IntRect());
     902        return false;
     903    }
     904
     905    // Intersect with previous clip.
     906    if (!data().sharedGLData().clipStack.isEmpty())
     907        rect.intersect(data().sharedGLData().clipStack.last());
     908
     909    scissorClip(rect);
     910    data().sharedGLData().clipStack.append(rect);
     911
     912    return true;
     913}
     914
     915bool TextureMapperGL::endScissorClip()
     916{
     917    data().sharedGLData().clipStack.removeLast();
     918    ASSERT(!data().sharedGLData().clipStack.isEmpty());
     919
     920    IntRect rect = data().sharedGLData().clipStack.last();
     921    if (rect.isEmpty())
     922        return false;
     923
     924    scissorClip(rect);
     925    return true;
     926}
     927
    869928void TextureMapperGL::beginClip(const TransformationMatrix& modelViewMatrix, const FloatRect& targetRect)
    870929{
     930    if (beginScissorClip(modelViewMatrix, targetRect))
     931        return;
    871932    TextureMapperGLData::SharedGLData::ShaderProgramIndex program = TextureMapperGLData::SharedGLData::ClipProgram;
    872933    const TextureMapperGLData::SharedGLData::ProgramInfo& programInfo = data().sharedGLData().programs[program];
     
    906967void TextureMapperGL::endClip()
    907968{
     969    if (endScissorClip())
     970        return;
     971
    908972    data().sharedGLData().stencilIndex >>= 1;
    909     glStencilFunc(data().sharedGLData().stencilIndex > 1 ? GL_EQUAL : GL_ALWAYS, data().sharedGLData().stencilIndex - 1, data().sharedGLData().stencilIndex - 1);
     973    glStencilFunc(data().sharedGLData().stencilIndex > 1 ? GL_EQUAL : GL_ALWAYS, data().sharedGLData().stencilIndex - 1, data().sharedGLData().stencilIndex - 1);   
     974
     975    // After we've cleared the last non-rectalinear clip, we disable the stencil test.
     976    if (data().sharedGLData().stencilIndex == 1)
     977        GL_CMD(glDisable(GL_STENCIL_TEST))
     978
    910979}
    911980
  • trunk/Source/WebCore/platform/graphics/opengl/TextureMapperGL.h

    r104651 r106524  
    5656
    5757private:
     58    bool beginScissorClip(const TransformationMatrix&, const FloatRect&);
     59    bool endScissorClip();
    5860    inline TextureMapperGLData& data() { return *m_data; }
    5961    TextureMapperGLData* m_data;
  • trunk/Source/WebKit2/ChangeLog

    r106511 r106524  
     12012-02-01  No'am Rosenthal  <noam.rosenthal@nokia.com>
     2
     3        [Texmap] Use glScissors for clipping in TextureMapperGL when possible
     4        https://bugs.webkit.org/show_bug.cgi?id=77575
     5
     6        Reviewed by Martin Robinson.
     7
     8        Instead of applying the scissor clip in QQuickWebPage, we trickle it down to
     9        TextureMapperGL, and apply it there as part of beginClip(). All direct GL operations are
     10        now cleaned out of QQuickWebPage.
     11
     12        * UIProcess/API/qt/qquickwebpage.cpp:
     13        (QQuickWebPagePrivate::paintToCurrentGLContext):
     14        * UIProcess/DrawingAreaProxy.h:
     15        (WebKit::DrawingAreaProxy::paintToCurrentGLContext):
     16        * UIProcess/DrawingAreaProxyImpl.cpp:
     17        (WebKit::DrawingAreaProxyImpl::paintToCurrentGLContext):
     18        * UIProcess/DrawingAreaProxyImpl.h:
     19        (DrawingAreaProxyImpl):
     20        * UIProcess/LayerTreeHostProxy.h:
     21        (LayerTreeHostProxy):
     22        * UIProcess/qt/LayerTreeHostProxyQt.cpp:
     23        (WebKit::LayerTreeHostProxy::paintToCurrentGLContext):
     24
    1252012-02-01  Dan Bernstein  <mitz@apple.com>
    226
  • trunk/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp

    r106250 r106524  
    125125        return;
    126126
    127     // Make sure that no GL error code stays from previous QT operations.
    128     glGetError();
    129 
    130     glEnable(GL_SCISSOR_TEST);
    131     ASSERT(!glGetError());
    132     const int left = clipRect.left();
    133     const int width = clipRect.width();
    134     const int bottom = q->canvas()->height() - (clipRect.bottom() + 1);
    135     const int height = clipRect.height();
    136 
    137     glScissor(left, bottom, width, height);
    138     ASSERT(!glGetError());
    139 
    140     drawingArea->paintToCurrentGLContext(transform, opacity);
    141 
    142     glDisable(GL_SCISSOR_TEST);
    143     ASSERT(!glGetError());
     127    drawingArea->paintToCurrentGLContext(transform, opacity, clipRect);
    144128}
    145129
  • trunk/Source/WebKit2/UIProcess/DrawingAreaProxy.h

    r106250 r106524  
    8989    virtual WebCore::IntRect contentsRect() const;
    9090    virtual bool isBackingStoreReady() const { return true; }
    91     virtual void paintToCurrentGLContext(const WebCore::TransformationMatrix&, float opacity) { }
     91    virtual void paintToCurrentGLContext(const WebCore::TransformationMatrix&, float, const WebCore::FloatRect&) { }
    9292    virtual void paintLayerTree(BackingStore::PlatformGraphicsContext) { }
    9393    LayerTreeHostProxy* layerTreeHostProxy() const { return m_layerTreeHostProxy.get(); }
  • trunk/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp

    r106250 r106524  
    367367}
    368368
    369 void DrawingAreaProxyImpl::paintToCurrentGLContext(const TransformationMatrix& matrix, float opacity)
     369void DrawingAreaProxyImpl::paintToCurrentGLContext(const TransformationMatrix& matrix, float opacity, const FloatRect& clipRect)
    370370{
    371371    if (m_layerTreeHostProxy)
    372         m_layerTreeHostProxy->paintToCurrentGLContext(matrix, opacity);
     372        m_layerTreeHostProxy->paintToCurrentGLContext(matrix, opacity, clipRect);
    373373}
    374374#endif
  • trunk/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.h

    r106250 r106524  
    8181    virtual void setVisibleContentsRectAndScale(const WebCore::IntRect& visibleContentsRect, float scale);
    8282    virtual void setVisibleContentRectTrajectoryVector(const WebCore::FloatPoint&);
    83     virtual void paintToCurrentGLContext(const WebCore::TransformationMatrix&, float opacity);
     83    virtual void paintToCurrentGLContext(const WebCore::TransformationMatrix&, float opacity, const WebCore::FloatRect&);
    8484    virtual void paintLayerTree(BackingStore::PlatformGraphicsContext);
    8585    void didReceiveLayerTreeHostProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
  • trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.h

    r106250 r106524  
    5353    void setRootCompositingLayer(WebLayerID);
    5454    void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
    55     void paintToCurrentGLContext(const WebCore::TransformationMatrix&, float);
     55    void paintToCurrentGLContext(const WebCore::TransformationMatrix&, float, const WebCore::FloatRect&);
    5656    void paintToGraphicsContext(BackingStore::PlatformGraphicsContext);
    5757    void purgeGLResources();
  • trunk/Source/WebKit2/UIProcess/qt/LayerTreeHostProxyQt.cpp

    r106250 r106524  
    169169
    170170// This function needs to be reentrant.
    171 void LayerTreeHostProxy::paintToCurrentGLContext(const TransformationMatrix& matrix, float opacity)
     171void LayerTreeHostProxy::paintToCurrentGLContext(const TransformationMatrix& matrix, float opacity, const FloatRect& clipRect)
    172172{
    173173    if (!m_textureMapper)
     
    191191    m_textureMapper->beginPainting();
    192192    m_textureMapper->bindSurface(0);
     193    m_textureMapper->beginClip(TransformationMatrix(), clipRect);
    193194
    194195    if (currentRootLayer->opacity() != opacity || currentRootLayer->transform() != matrix) {
     
    199200
    200201    node->paint();
     202    m_textureMapper->endClip();
    201203    m_textureMapper->endPainting();
    202204
Note: See TracChangeset for help on using the changeset viewer.