[TextureMapper] Support drawing debug borders
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 May 2012 23:57:55 +0000 (23:57 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 May 2012 23:57:55 +0000 (23:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=86237

Patch by Martin Robinson <mrobinson@igalia.com> on 2012-05-11
Reviewed by Noam Rosenthal.

No new tests. This is the implementation of an interactive debugging
feature.

* platform/graphics/texmap/GraphicsLayerTextureMapper.cpp:
(WebCore::GraphicsLayer::create): Moved this to the top of the file to
reduce contention for the coveted last spot in the file. This also
follows the pattern used in many WebCore files of having the factories
at the top.
(WebCore::GraphicsLayerTextureMapper::setDebugBorder): Added this
plumbing.
* platform/graphics/texmap/GraphicsLayerTextureMapper.h: Added
plumbing.
* platform/graphics/texmap/TextureMapper.h: Ditto.
* platform/graphics/texmap/TextureMapperBackingStore.cpp:
(WebCore::TextureMapperTiledBackingStore::TextureMapperTiledBackingStore):
Initialize the new member.
(WebCore::TextureMapperTiledBackingStore::paintToTextureMapper): When
debug borders are enabled call the new drawBorder method on the TM.
(WebCore::TextureMapperTiledBackingStore::setDebugBorder): Added this
plumbing.
* platform/graphics/texmap/TextureMapperBackingStore.h: Added plumbing
and members to store debug border states. This is necessary because of
the when painting there is no handle on the GraphicsLayers.
* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore::TextureMapperGL::drawRect): Factored out the common bits of
drawTexture and drawBorder into this helper.
(WebCore::TextureMapperGL::drawBorder): Added this method, which works
very similarly to drawTexture, but uses a different shader program and
must also set the line width and color.
(WebCore::TextureMapperGL::drawTexture): Factored out the bits that
are shared with drawRect.
* platform/graphics/texmap/TextureMapperGL.h:
(TextureMapperGL): Added the new method declarations.
* platform/graphics/texmap/TextureMapperImageBuffer.h:
(WebCore::TextureMapperImageBuffer::drawBorder): Added an empty
implementation. Later we can add an implementation for the ImageBuffer
TM.
* platform/graphics/texmap/TextureMapperLayer.cpp:
(WebCore::TextureMapperLayer::updateBackingStore): When updating the
backing store send the debug border information through.
(WebCore::TextureMapperLayer::syncCompositingStateSelf): When updating
the layer state, also update the debug indicators. This is required to
initialize the debug border values for the layer.
(WebCore::TextureMapperLayer::setDebugBorder): Added this plumbing.
* platform/graphics/texmap/TextureMapperLayer.h: Ditto.
* platform/graphics/texmap/TextureMapperShaderManager.cpp: Added a
solid color shader that doesn't care about texture coordinates or
opacity values.
(WebCore::TextureMapperShaderManager::solidColorProgram): Added. This
is a shorter getter for the solid color program that doesn't require
casting from the caller.
(WebCore::TextureMapperShaderManager::getShaderProgram): Added support
for the solid color program.
(WebCore::TextureMapperShaderProgramSolidColor::create): Added.
(WebCore::TextureMapperShaderProgramSolidColor::TextureMapperShaderProgramSolidColor):
Ditto.
(WebCore::TextureMapperShaderProgramSolidColor::vertexShaderSource):
Ditto.
(WebCore::TextureMapperShaderProgramSolidColor::fragmentShaderSource):
Ditto.
* platform/graphics/texmap/TextureMapperShaderManager.h:
(TextureMapperShaderProgramSolidColor): Added.
(WebCore::TextureMapperShaderProgramSolidColor::colorVariable): Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@116823 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp
Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h
Source/WebCore/platform/graphics/texmap/TextureMapper.h
Source/WebCore/platform/graphics/texmap/TextureMapperBackingStore.cpp
Source/WebCore/platform/graphics/texmap/TextureMapperBackingStore.h
Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp
Source/WebCore/platform/graphics/texmap/TextureMapperGL.h
Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.h
Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp
Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h
Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.cpp
Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.h

index 399971dfcbc2d6b1678ff899734904fd0c48d807..278a6c9dd30e3dd1bbb4972446733d6dec7ddea5 100644 (file)
@@ -1,3 +1,74 @@
+2012-05-11  Martin Robinson  <mrobinson@igalia.com>
+
+        [TextureMapper] Support drawing debug borders
+        https://bugs.webkit.org/show_bug.cgi?id=86237
+
+        Reviewed by Noam Rosenthal.
+
+        No new tests. This is the implementation of an interactive debugging
+        feature.
+
+        * platform/graphics/texmap/GraphicsLayerTextureMapper.cpp:
+        (WebCore::GraphicsLayer::create): Moved this to the top of the file to
+        reduce contention for the coveted last spot in the file. This also
+        follows the pattern used in many WebCore files of having the factories
+        at the top.
+        (WebCore::GraphicsLayerTextureMapper::setDebugBorder): Added this
+        plumbing.
+        * platform/graphics/texmap/GraphicsLayerTextureMapper.h: Added
+        plumbing.
+        * platform/graphics/texmap/TextureMapper.h: Ditto.
+        * platform/graphics/texmap/TextureMapperBackingStore.cpp:
+        (WebCore::TextureMapperTiledBackingStore::TextureMapperTiledBackingStore):
+        Initialize the new member.
+        (WebCore::TextureMapperTiledBackingStore::paintToTextureMapper): When
+        debug borders are enabled call the new drawBorder method on the TM.
+        (WebCore::TextureMapperTiledBackingStore::setDebugBorder): Added this
+        plumbing.
+        * platform/graphics/texmap/TextureMapperBackingStore.h: Added plumbing
+        and members to store debug border states. This is necessary because of
+        the when painting there is no handle on the GraphicsLayers.
+        * platform/graphics/texmap/TextureMapperGL.cpp:
+        (WebCore::TextureMapperGL::drawRect): Factored out the common bits of
+        drawTexture and drawBorder into this helper.
+        (WebCore::TextureMapperGL::drawBorder): Added this method, which works
+        very similarly to drawTexture, but uses a different shader program and
+        must also set the line width and color.
+        (WebCore::TextureMapperGL::drawTexture): Factored out the bits that
+        are shared with drawRect.
+        * platform/graphics/texmap/TextureMapperGL.h:
+        (TextureMapperGL): Added the new method declarations.
+        * platform/graphics/texmap/TextureMapperImageBuffer.h:
+        (WebCore::TextureMapperImageBuffer::drawBorder): Added an empty
+        implementation. Later we can add an implementation for the ImageBuffer
+        TM.
+        * platform/graphics/texmap/TextureMapperLayer.cpp:
+        (WebCore::TextureMapperLayer::updateBackingStore): When updating the
+        backing store send the debug border information through.
+        (WebCore::TextureMapperLayer::syncCompositingStateSelf): When updating
+        the layer state, also update the debug indicators. This is required to
+        initialize the debug border values for the layer.
+        (WebCore::TextureMapperLayer::setDebugBorder): Added this plumbing.
+        * platform/graphics/texmap/TextureMapperLayer.h: Ditto.
+        * platform/graphics/texmap/TextureMapperShaderManager.cpp: Added a
+        solid color shader that doesn't care about texture coordinates or
+        opacity values.
+        (WebCore::TextureMapperShaderManager::solidColorProgram): Added. This
+        is a shorter getter for the solid color program that doesn't require
+        casting from the caller.
+        (WebCore::TextureMapperShaderManager::getShaderProgram): Added support
+        for the solid color program.
+        (WebCore::TextureMapperShaderProgramSolidColor::create): Added.
+        (WebCore::TextureMapperShaderProgramSolidColor::TextureMapperShaderProgramSolidColor):
+        Ditto.
+        (WebCore::TextureMapperShaderProgramSolidColor::vertexShaderSource):
+        Ditto.
+        (WebCore::TextureMapperShaderProgramSolidColor::fragmentShaderSource):
+        Ditto.
+        * platform/graphics/texmap/TextureMapperShaderManager.h:
+        (TextureMapperShaderProgramSolidColor): Added.
+        (WebCore::TextureMapperShaderProgramSolidColor::colorVariable): Added.
+
 2012-05-10  Timothy Hatcher  <timothy@apple.com>
 
         Instrument timer function calls so they show up in the Web Inspector Timeline.
index b5d03a1b2779a516a3d3b7384c13bf78cc9edc2b..fbf86992b214e4da22c9d84c7a0ed65eab10e66d 100644 (file)
 
 namespace WebCore {
 
+PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client)
+{
+    if (s_graphicsLayerFactory)
+        return (*s_graphicsLayerFactory)(client);
+    return adoptPtr(new GraphicsLayerTextureMapper(client));
+}
+
 GraphicsLayerTextureMapper::GraphicsLayerTextureMapper(GraphicsLayerClient* client)
     : GraphicsLayer(client)
     , m_layer(adoptPtr(new TextureMapperLayer()))
@@ -383,11 +390,9 @@ void GraphicsLayerTextureMapper::animationStartedTimerFired(Timer<GraphicsLayerT
     client()->notifyAnimationStarted(this, /* DOM time */ WTF::currentTime());
 }
 
-PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client)
+void GraphicsLayerTextureMapper::setDebugBorder(const Color& color, float width)
 {
-    if (s_graphicsLayerFactory)
-        return (*s_graphicsLayerFactory)(client);
-    return adoptPtr(new GraphicsLayerTextureMapper(client));
+    m_layer->setDebugBorder(color, width);
 }
 
 #if ENABLE(CSS_FILTERS)
index c82e943eb6d5de64413a8215023b9d0ea3fc7d42..94530dbcaaecedc48b7917b5eb27e4514943ea1b 100644 (file)
@@ -90,6 +90,8 @@ public:
     bool needsDisplay() const { return m_needsDisplay; }
     IntRect needsDisplayRect() const { return enclosingIntRect(m_needsDisplayRect); }
 
+    virtual void setDebugBorder(const Color&, float width);
+
 #if ENABLE(CSS_FILTERS)
     virtual bool setFilters(const FilterOperations&);
 #endif
index ca31d1769976fdbac8def1d0eadf659ef259c8b6..2907d1ac8e15f487817bfb0b422faa61ae5a671e 100644 (file)
@@ -112,6 +112,7 @@ public:
     static PassOwnPtr<TextureMapper> create(AccelerationMode newMode = SoftwareMode);
     virtual ~TextureMapper() { }
 
+    virtual void drawBorder(const Color&, float borderWidth, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix = TransformationMatrix()) = 0;
     virtual void drawTexture(const BitmapTexture&, const FloatRect& target, const TransformationMatrix& modelViewMatrix = TransformationMatrix(), float opacity = 1.0f, const BitmapTexture* maskTexture = 0) = 0;
 
     // makes a surface the target for the following drawTexture calls.
index 43ac7810b8cffbf8cd1c3748ffbbcd0a8e1b18e6..8877bfe344abcc2f0d0cd69365a73c6c13167945 100644 (file)
@@ -52,6 +52,11 @@ void TextureMapperTile::paint(TextureMapper* textureMapper, const Transformation
     textureMapper->drawTexture(*texture().get(), rect(), transform, opacity, mask);
 }
 
+TextureMapperTiledBackingStore::TextureMapperTiledBackingStore()
+    : m_drawsDebugBorders(false)
+{
+}
+
 void TextureMapperTiledBackingStore::updateContentsFromImageIfNeeded(TextureMapper* textureMapper)
 {
     if (!m_image)
@@ -66,8 +71,11 @@ void TextureMapperTiledBackingStore::paintToTextureMapper(TextureMapper* texture
     updateContentsFromImageIfNeeded(textureMapper);
     TransformationMatrix adjustedTransform = transform;
     adjustedTransform.multiply(TransformationMatrix::rectToRect(rect(), targetRect));
-    for (size_t i = 0; i < m_tiles.size(); ++i)
+    for (size_t i = 0; i < m_tiles.size(); ++i) {
         m_tiles[i].paint(textureMapper, adjustedTransform, opacity, mask);
+        if (m_drawsDebugBorders)
+            textureMapper->drawBorder(m_debugBorderColor, m_debugBorderWidth, m_tiles[i].rect(), adjustedTransform);
+    }
 }
 
 void TextureMapperTiledBackingStore::createOrDestroyTilesIfNeeded(const FloatSize& size, const IntSize& tileSize, bool hasAlpha)
@@ -152,4 +160,10 @@ PassRefPtr<BitmapTexture> TextureMapperTiledBackingStore::texture() const
     return PassRefPtr<BitmapTexture>();
 }
 
+void TextureMapperTiledBackingStore::setDebugBorder(const Color& color, float width)
+{
+    m_debugBorderColor = color;
+    m_debugBorderWidth = width;
+}
+
 }
index df61b862624a07802ecb5920d931f1735a78712c..37a365036a8aa3b1c162ba954f564ce16cc601f7 100644 (file)
@@ -72,13 +72,20 @@ public:
     void setContentsToImage(Image* image) { m_image = image; }
     void updateContentsFromImageIfNeeded(TextureMapper*);
 
+    void setShowDebugBorders(bool drawsDebugBorders) { m_drawsDebugBorders = drawsDebugBorders; }
+    void setDebugBorder(const Color&, float width);
+
 private:
-    TextureMapperTiledBackingStore() { }
+    TextureMapperTiledBackingStore();
     void createOrDestroyTilesIfNeeded(const FloatSize& backingStoreSize, const IntSize& tileSize, bool hasAlpha);
 
     Vector<TextureMapperTile> m_tiles;
     FloatSize m_size;
     RefPtr<Image> m_image;
+
+    bool m_drawsDebugBorders;
+    Color m_debugBorderColor;
+    float m_debugBorderWidth;
 };
 
 }
index df9b8b03e2ce18654b54e365bb04058340e2d134..d8aba0c49f1595f7978dbde16d9c40a1b20c7658 100644 (file)
@@ -304,6 +304,55 @@ void TextureMapperGL::endPainting()
 #endif
 }
 
+void TextureMapperGL::drawRect(const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, TextureMapperShaderProgram* shaderProgram, GLenum drawingMode, bool needsBlending)
+{
+    GL_CMD(glEnableVertexAttribArray(shaderProgram->vertexAttrib()));
+    GL_CMD(glBindBuffer(GL_ARRAY_BUFFER, 0));
+    const GLfloat unitRect[] = {0, 0, 1, 0, 1, 1, 0, 1};
+    GL_CMD(glVertexAttribPointer(shaderProgram->vertexAttrib(), 2, GL_FLOAT, GL_FALSE, 0, unitRect));
+
+    TransformationMatrix matrix = TransformationMatrix(data().projectionMatrix).multiply(modelViewMatrix).multiply(TransformationMatrix(
+            targetRect.width(), 0, 0, 0,
+            0, targetRect.height(), 0, 0,
+            0, 0, 1, 0,
+            targetRect.x(), targetRect.y(), 0, 1));
+
+    const GLfloat m4[] = {
+        matrix.m11(), matrix.m12(), matrix.m13(), matrix.m14(),
+        matrix.m21(), matrix.m22(), matrix.m23(), matrix.m24(),
+        matrix.m31(), matrix.m32(), matrix.m33(), matrix.m34(),
+        matrix.m41(), matrix.m42(), matrix.m43(), matrix.m44()
+    };
+    GL_CMD(glUniformMatrix4fv(shaderProgram->matrixVariable(), 1, GL_FALSE, m4));
+
+    if (needsBlending) {
+        GL_CMD(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
+        GL_CMD(glEnable(GL_BLEND));
+    } else
+        GL_CMD(glDisable(GL_BLEND));
+
+    GL_CMD(glDrawArrays(drawingMode, 0, 4));
+    GL_CMD(glDisableVertexAttribArray(shaderProgram->vertexAttrib()));
+}
+
+void TextureMapperGL::drawBorder(const Color& color, float width, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix)
+{
+    if (clipStack().current().scissorBox.isEmpty())
+        return;
+
+    RefPtr<TextureMapperShaderProgramSolidColor> shaderInfo = data().sharedGLData().textureMapperShaderManager.solidColorProgram();
+    GL_CMD(glUseProgram(shaderInfo->id()));
+
+    float alpha = color.alpha() / 255.0;
+    GL_CMD(glUniform4f(shaderInfo->colorVariable(),
+                       (color.red() / 255.0) * alpha,
+                       (color.green() / 255.0) * alpha,
+                       (color.blue() / 255.0) * alpha,
+                       alpha));
+    GL_CMD(glLineWidth(width));
+
+    drawRect(targetRect, modelViewMatrix, shaderInfo.get(), GL_LINE_LOOP, color.hasAlpha());
+}
 
 void TextureMapperGL::drawTexture(const BitmapTexture& texture, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity, const BitmapTexture* mask)
 {
@@ -324,50 +373,24 @@ void TextureMapperGL::drawTexture(uint32_t texture, Flags flags, const IntSize&
         shaderInfo = data().sharedGLData().textureMapperShaderManager.getShaderProgram(TextureMapperShaderManager::OpacityAndMask);
     else
         shaderInfo = data().sharedGLData().textureMapperShaderManager.getShaderProgram(TextureMapperShaderManager::Simple);
-
     GL_CMD(glUseProgram(shaderInfo->id()));
+
     GL_CMD(glEnableVertexAttribArray(shaderInfo->vertexAttrib()));
     GL_CMD(glActiveTexture(GL_TEXTURE0));
     GL_CMD(glBindTexture(GL_TEXTURE_2D, texture));
-    GL_CMD(glBindBuffer(GL_ARRAY_BUFFER, 0));
-    const GLfloat unitRect[] = {0, 0, 1, 0, 1, 1, 0, 1};
-    GL_CMD(glVertexAttribPointer(shaderInfo->vertexAttrib(), 2, GL_FLOAT, GL_FALSE, 0, unitRect));
-
-    TransformationMatrix matrix = TransformationMatrix(data().projectionMatrix).multiply(modelViewMatrix).multiply(TransformationMatrix(
-            targetRect.width(), 0, 0, 0,
-            0, targetRect.height(), 0, 0,
-            0, 0, 1, 0,
-            targetRect.x(), targetRect.y(), 0, 1));
-
-    const GLfloat m4[] = {
-        matrix.m11(), matrix.m12(), matrix.m13(), matrix.m14(),
-        matrix.m21(), matrix.m22(), matrix.m23(), matrix.m24(),
-        matrix.m31(), matrix.m32(), matrix.m33(), matrix.m34(),
-        matrix.m41(), matrix.m42(), matrix.m43(), matrix.m44()
-    };
+    GL_CMD(glUniform1i(shaderInfo->sourceTextureVariable(), 0));
 
     const GLfloat m4src[] = {
         1, 0, 0, 0,
         0, (flags & ShouldFlipTexture) ? -1 : 1, 0, 0,
         0, 0, 1, 0,
         0, (flags & ShouldFlipTexture) ? 1 : 0, 0, 1};
-
-    GL_CMD(glUniformMatrix4fv(shaderInfo->matrixVariable(), 1, GL_FALSE, m4));
     GL_CMD(glUniformMatrix4fv(shaderInfo->sourceMatrixVariable(), 1, GL_FALSE, m4src));
-    GL_CMD(glUniform1i(shaderInfo->sourceTextureVariable(), 0));
 
     shaderInfo->prepare(opacity, maskTexture);
 
     bool needsBlending = (flags & SupportsBlending) || opacity < 0.99 || maskTexture;
-
-    if (needsBlending) {
-        GL_CMD(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
-        GL_CMD(glEnable(GL_BLEND));
-    } else
-        GL_CMD(glDisable(GL_BLEND));
-
-    GL_CMD(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
-    GL_CMD(glDisableVertexAttribArray(shaderInfo->vertexAttrib()));
+    drawRect(targetRect, modelViewMatrix, shaderInfo.get(), GL_TRIANGLE_FAN, needsBlending);
 }
 
 const char* TextureMapperGL::type() const
index 4279499fc69c9be9a3c36586564d3c53278f3bc6..c9a46cc59a570be82afeb477b5ae4af3199b3ca4 100644 (file)
@@ -48,6 +48,7 @@ public:
     typedef int Flags;
 
     // reimps from TextureMapper
+    virtual void drawBorder(const Color&, float borderWidth, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix = TransformationMatrix());
     virtual void drawTexture(const BitmapTexture&, const FloatRect&, const TransformationMatrix&, float opacity, const BitmapTexture* maskTexture);
     virtual void drawTexture(uint32_t texture, Flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, const BitmapTexture* maskTexture);
     virtual void bindSurface(BitmapTexture* surface);
@@ -94,6 +95,7 @@ private:
         Vector<ClipState> clipStack;
     };
 
+    void drawRect(const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, TextureMapperShaderProgram*, GLenum drawingMode, bool needsBlending);
     bool beginScissorClip(const TransformationMatrix&, const FloatRect&);
     void bindDefaultSurface();
     ClipStack& clipStack();
index 8a035628eb3e40844371da634fa825912661a457..0de153efb240950a63667e47b60d936ea2985143 100644 (file)
@@ -48,6 +48,7 @@ private:
 
 class TextureMapperImageBuffer : public TextureMapper {
 public:
+    virtual void drawBorder(const Color& color, float borderWidth, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix = TransformationMatrix()) { };
     virtual void drawTexture(const BitmapTexture&, const FloatRect& targetRect, const TransformationMatrix&, float opacity, const BitmapTexture* maskTexture);
     virtual void beginClip(const TransformationMatrix&, const FloatRect&);
     virtual void bindSurface(BitmapTexture* surface) { m_currentSurface = surface;}
index 84a6601f26d8f4a9d1fd5aae76794fc5c8807c01..40f0c983613b33b475e78f3979e31d131666f621 100644 (file)
@@ -90,7 +90,7 @@ void TextureMapperLayer::computeTransformsRecursive()
         sortByZOrder(m_children, 0, m_children.size());
 }
 
-void TextureMapperLayer::updateBackingStore(TextureMapper* textureMapper, GraphicsLayer* layer)
+void TextureMapperLayer::updateBackingStore(TextureMapper* textureMapper, GraphicsLayerTextureMapper* layer)
 {
     if (!layer || !textureMapper)
         return;
@@ -123,7 +123,13 @@ void TextureMapperLayer::updateBackingStore(TextureMapper* textureMapper, Graphi
     layer->paintGraphicsLayerContents(*context, dirtyRect);
 
     RefPtr<Image> image = imageBuffer->copyImage(DontCopyBackingStore);
-    static_cast<TextureMapperTiledBackingStore*>(m_backingStore.get())->updateContents(textureMapper, image.get(), m_size, dirtyRect);
+
+    TextureMapperTiledBackingStore* backingStore = static_cast<TextureMapperTiledBackingStore*>(m_backingStore.get());
+    backingStore->updateContents(textureMapper, image.get(), m_size, dirtyRect);
+
+    backingStore->setShowDebugBorders(layer->showDebugBorders());
+    backingStore->setDebugBorder(m_debugBorderColor, m_debugBorderWidth);
+
     m_state.needsDisplay = false;
     m_state.needsDisplayRect = IntRect();
 }
@@ -372,6 +378,8 @@ void TextureMapperLayer::syncCompositingStateSelf(GraphicsLayerTextureMapper* gr
     if (changeMask == NoChanges && graphicsLayer->m_animations.isEmpty())
         return;
 
+    graphicsLayer->updateDebugIndicators();
+
     if (changeMask & ParentChange) {
         TextureMapperLayer* newParent = toTextureMapperLayer(graphicsLayer->parent());
         if (newParent != m_parent) {
@@ -546,5 +554,13 @@ void TextureMapperLayer::setScrollPositionDeltaIfNeeded(const IntPoint& delta)
     m_transform.setPosition(m_state.pos + m_scrollPositionDelta);
 }
 
+void TextureMapperLayer::setDebugBorder(const Color& color, float width)
+{
+    // The default values for GraphicsLayer debug borders are a little
+    // hard to see (some less than one pixel wide), so we double their size here.
+    m_debugBorderColor = color;
+    m_debugBorderWidth = width * 2;
+}
+
 }
 #endif
index 172ca5cb148e5b91655c3e9618db6a5815eb7f1b..da1ac99167488f2780011f6872941ed0ebb2d03f 100644 (file)
@@ -106,6 +106,7 @@ public:
         , m_centerZ(0)
         , m_shouldUpdateBackingStoreFromLayer(true)
         , m_textureMapper(0)
+        , m_debugBorderWidth(0)
     { }
 
     virtual ~TextureMapperLayer();
@@ -129,6 +130,8 @@ public:
     void setScrollPositionDeltaIfNeeded(const IntPoint&);
     void setFixedToViewport(bool fixed) { m_fixedToViewport = fixed; }
 
+    void setDebugBorder(const Color&, float width);
+
 private:
     TextureMapperLayer* rootLayer();
     void computeTransformsRecursive();
@@ -152,7 +155,7 @@ private:
     void paintSelf(const TextureMapperPaintOptions&);
     void paintSelfAndChildren(const TextureMapperPaintOptions&);
     void paintSelfAndChildrenWithReplica(const TextureMapperPaintOptions&);
-    void updateBackingStore(TextureMapper*, GraphicsLayer*);
+    void updateBackingStore(TextureMapper*, GraphicsLayerTextureMapper*);
 
     void syncAnimations();
     bool isVisible() const;
@@ -230,6 +233,8 @@ private:
     TextureMapperAnimations m_animations;
     IntPoint m_scrollPositionDelta;
     bool m_fixedToViewport;
+    Color m_debugBorderColor;
+    float m_debugBorderWidth;
 };
 
 
index a759c5f4ca15ce75e1985f2c66fa2a9781994728..56fa742240df587e29874183a62e46cc223995ba 100644 (file)
@@ -92,6 +92,58 @@ static const char* vertexShaderSourceSimple =
         }
     );
 
+static const char* vertexShaderSourceSolidColor =
+    VERTEX_SHADER(
+        uniform mat4 InMatrix;
+        attribute vec4 InVertex;
+        void main(void)
+        {
+            gl_Position = InMatrix * InVertex;
+        }
+    );
+
+
+static const char* fragmentShaderSourceSolidColor =
+    VERTEX_SHADER(
+        uniform vec4 Color;
+        void main(void)
+        {
+            gl_FragColor = Color;
+        }
+    );
+
+PassRefPtr<TextureMapperShaderProgramSolidColor> TextureMapperShaderManager::solidColorProgram()
+{
+    return static_pointer_cast<TextureMapperShaderProgramSolidColor>(getShaderProgram(SolidColor));
+}
+
+PassRefPtr<TextureMapperShaderProgram> TextureMapperShaderManager::getShaderProgram(ShaderType shaderType)
+{
+    RefPtr<TextureMapperShaderProgram> program;
+    if (shaderType == Invalid)
+        return program;
+
+    TextureMapperShaderProgramMap::iterator it = m_textureMapperShaderProgramMap.find(shaderType);
+    if (it != m_textureMapperShaderProgramMap.end())
+        return it->second;
+
+    switch (shaderType) {
+    case Simple:
+        program = TextureMapperShaderProgramSimple::create();
+        break;
+    case OpacityAndMask:
+        program = TextureMapperShaderProgramOpacityAndMask::create();
+        break;
+    case SolidColor:
+        program = TextureMapperShaderProgramSolidColor::create();
+        break;
+    case Invalid:
+        ASSERT_NOT_REACHED();
+    }
+    m_textureMapperShaderProgramMap.add(shaderType, program);
+    return program;
+}
+
 void TextureMapperShaderProgram::initializeProgram()
 {
     const char* vertexShaderSourceProgram = vertexShaderSource();
@@ -161,6 +213,28 @@ void TextureMapperShaderProgramSimple::prepare(float opacity, const BitmapTextur
     glUniform1f(m_opacityVariable, opacity);
 }
 
+PassRefPtr<TextureMapperShaderProgramSolidColor> TextureMapperShaderProgramSolidColor::create()
+{
+    return adoptRef(new TextureMapperShaderProgramSolidColor());
+}
+
+TextureMapperShaderProgramSolidColor::TextureMapperShaderProgramSolidColor()
+{
+    initializeProgram();
+    getUniformLocation(m_matrixVariable, "InMatrix");
+    getUniformLocation(m_colorVariable, "Color");
+}
+
+const char* TextureMapperShaderProgramSolidColor::vertexShaderSource() const
+{
+    return vertexShaderSourceSolidColor;
+}
+
+const char* TextureMapperShaderProgramSolidColor::fragmentShaderSource() const
+{
+    return fragmentShaderSourceSolidColor;
+}
+
 PassRefPtr<TextureMapperShaderProgramOpacityAndMask> TextureMapperShaderProgramOpacityAndMask::create()
 {
     return adoptRef(new TextureMapperShaderProgramOpacityAndMask());
index d0593e6c7fd89c53ad488f244cc230bcc0968251..16221acdadd578912ac76a55df7b512aff11611a 100644 (file)
@@ -123,12 +123,26 @@ private:
     GLint m_maskTextureVariable;
 };
 
+class TextureMapperShaderProgramSolidColor : public TextureMapperShaderProgram {
+public:
+    static PassRefPtr<TextureMapperShaderProgramSolidColor> create();
+    GLint colorVariable() const { return m_colorVariable; }
+
+private:
+    virtual const char* vertexShaderSource() const;
+    virtual const char* fragmentShaderSource() const;
+    TextureMapperShaderProgramSolidColor();
+    GLint m_colorVariable;
+};
+
+
 class TextureMapperShaderManager {
 public:
     enum ShaderType {
         Invalid = 0, // HashMaps do not like 0 as a key.
         Simple,
-        OpacityAndMask
+        OpacityAndMask,
+        SolidColor,
     };
 
     TextureMapperShaderManager();
@@ -137,30 +151,8 @@ public:
 #if ENABLE(CSS_FILTERS)
     PassRefPtr<StandardFilterProgram> getShaderForFilter(const FilterOperation&);
 #endif
-
-    PassRefPtr<TextureMapperShaderProgram> getShaderProgram(ShaderType shaderType)
-    {
-        RefPtr<TextureMapperShaderProgram> program;
-        if (shaderType == Invalid)
-            return program;
-
-        TextureMapperShaderProgramMap::iterator it = m_textureMapperShaderProgramMap.find(shaderType);
-        if (it != m_textureMapperShaderProgramMap.end())
-            return it->second;
-
-        switch (shaderType) {
-        case Simple:
-            program = TextureMapperShaderProgramSimple::create();
-            break;
-        case OpacityAndMask:
-            program = TextureMapperShaderProgramOpacityAndMask::create();
-            break;
-        case Invalid:
-            ASSERT_NOT_REACHED();
-        }
-        m_textureMapperShaderProgramMap.add(shaderType, program);
-        return program;
-    }
+    PassRefPtr<TextureMapperShaderProgram> getShaderProgram(ShaderType);
+    PassRefPtr<TextureMapperShaderProgramSolidColor> solidColorProgram();
 
 private:
     typedef HashMap<ShaderType, RefPtr<TextureMapperShaderProgram>, DefaultHash<int>::Hash, HashTraits<int> > TextureMapperShaderProgramMap;