Changeset 116823 in webkit


Ignore:
Timestamp:
May 11, 2012 4:57:55 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[TextureMapper] Support drawing debug borders
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.

Location:
trunk/Source/WebCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r116821 r116823  
     12012-05-11  Martin Robinson  <mrobinson@igalia.com>
     2
     3        [TextureMapper] Support drawing debug borders
     4        https://bugs.webkit.org/show_bug.cgi?id=86237
     5
     6        Reviewed by Noam Rosenthal.
     7
     8        No new tests. This is the implementation of an interactive debugging
     9        feature.
     10
     11        * platform/graphics/texmap/GraphicsLayerTextureMapper.cpp:
     12        (WebCore::GraphicsLayer::create): Moved this to the top of the file to
     13        reduce contention for the coveted last spot in the file. This also
     14        follows the pattern used in many WebCore files of having the factories
     15        at the top.
     16        (WebCore::GraphicsLayerTextureMapper::setDebugBorder): Added this
     17        plumbing.
     18        * platform/graphics/texmap/GraphicsLayerTextureMapper.h: Added
     19        plumbing.
     20        * platform/graphics/texmap/TextureMapper.h: Ditto.
     21        * platform/graphics/texmap/TextureMapperBackingStore.cpp:
     22        (WebCore::TextureMapperTiledBackingStore::TextureMapperTiledBackingStore):
     23        Initialize the new member.
     24        (WebCore::TextureMapperTiledBackingStore::paintToTextureMapper): When
     25        debug borders are enabled call the new drawBorder method on the TM.
     26        (WebCore::TextureMapperTiledBackingStore::setDebugBorder): Added this
     27        plumbing.
     28        * platform/graphics/texmap/TextureMapperBackingStore.h: Added plumbing
     29        and members to store debug border states. This is necessary because of
     30        the when painting there is no handle on the GraphicsLayers.
     31        * platform/graphics/texmap/TextureMapperGL.cpp:
     32        (WebCore::TextureMapperGL::drawRect): Factored out the common bits of
     33        drawTexture and drawBorder into this helper.
     34        (WebCore::TextureMapperGL::drawBorder): Added this method, which works
     35        very similarly to drawTexture, but uses a different shader program and
     36        must also set the line width and color.
     37        (WebCore::TextureMapperGL::drawTexture): Factored out the bits that
     38        are shared with drawRect.
     39        * platform/graphics/texmap/TextureMapperGL.h:
     40        (TextureMapperGL): Added the new method declarations.
     41        * platform/graphics/texmap/TextureMapperImageBuffer.h:
     42        (WebCore::TextureMapperImageBuffer::drawBorder): Added an empty
     43        implementation. Later we can add an implementation for the ImageBuffer
     44        TM.
     45        * platform/graphics/texmap/TextureMapperLayer.cpp:
     46        (WebCore::TextureMapperLayer::updateBackingStore): When updating the
     47        backing store send the debug border information through.
     48        (WebCore::TextureMapperLayer::syncCompositingStateSelf): When updating
     49        the layer state, also update the debug indicators. This is required to
     50        initialize the debug border values for the layer.
     51        (WebCore::TextureMapperLayer::setDebugBorder): Added this plumbing.
     52        * platform/graphics/texmap/TextureMapperLayer.h: Ditto.
     53        * platform/graphics/texmap/TextureMapperShaderManager.cpp: Added a
     54        solid color shader that doesn't care about texture coordinates or
     55        opacity values.
     56        (WebCore::TextureMapperShaderManager::solidColorProgram): Added. This
     57        is a shorter getter for the solid color program that doesn't require
     58        casting from the caller.
     59        (WebCore::TextureMapperShaderManager::getShaderProgram): Added support
     60        for the solid color program.
     61        (WebCore::TextureMapperShaderProgramSolidColor::create): Added.
     62        (WebCore::TextureMapperShaderProgramSolidColor::TextureMapperShaderProgramSolidColor):
     63        Ditto.
     64        (WebCore::TextureMapperShaderProgramSolidColor::vertexShaderSource):
     65        Ditto.
     66        (WebCore::TextureMapperShaderProgramSolidColor::fragmentShaderSource):
     67        Ditto.
     68        * platform/graphics/texmap/TextureMapperShaderManager.h:
     69        (TextureMapperShaderProgramSolidColor): Added.
     70        (WebCore::TextureMapperShaderProgramSolidColor::colorVariable): Added.
     71
    1722012-05-10  Timothy Hatcher  <timothy@apple.com>
    273
  • trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp

    r113983 r116823  
    2424
    2525namespace WebCore {
     26
     27PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client)
     28{
     29    if (s_graphicsLayerFactory)
     30        return (*s_graphicsLayerFactory)(client);
     31    return adoptPtr(new GraphicsLayerTextureMapper(client));
     32}
    2633
    2734GraphicsLayerTextureMapper::GraphicsLayerTextureMapper(GraphicsLayerClient* client)
     
    384391}
    385392
    386 PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client)
    387 {
    388     if (s_graphicsLayerFactory)
    389         return (*s_graphicsLayerFactory)(client);
    390     return adoptPtr(new GraphicsLayerTextureMapper(client));
     393void GraphicsLayerTextureMapper::setDebugBorder(const Color& color, float width)
     394{
     395    m_layer->setDebugBorder(color, width);
    391396}
    392397
  • trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h

    r113983 r116823  
    9191    IntRect needsDisplayRect() const { return enclosingIntRect(m_needsDisplayRect); }
    9292
     93    virtual void setDebugBorder(const Color&, float width);
     94
    9395#if ENABLE(CSS_FILTERS)
    9496    virtual bool setFilters(const FilterOperations&);
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.h

    r115838 r116823  
    113113    virtual ~TextureMapper() { }
    114114
     115    virtual void drawBorder(const Color&, float borderWidth, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix = TransformationMatrix()) = 0;
    115116    virtual void drawTexture(const BitmapTexture&, const FloatRect& target, const TransformationMatrix& modelViewMatrix = TransformationMatrix(), float opacity = 1.0f, const BitmapTexture* maskTexture = 0) = 0;
    116117
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperBackingStore.cpp

    r113678 r116823  
    5353}
    5454
     55TextureMapperTiledBackingStore::TextureMapperTiledBackingStore()
     56    : m_drawsDebugBorders(false)
     57{
     58}
     59
    5560void TextureMapperTiledBackingStore::updateContentsFromImageIfNeeded(TextureMapper* textureMapper)
    5661{
     
    6772    TransformationMatrix adjustedTransform = transform;
    6873    adjustedTransform.multiply(TransformationMatrix::rectToRect(rect(), targetRect));
    69     for (size_t i = 0; i < m_tiles.size(); ++i)
     74    for (size_t i = 0; i < m_tiles.size(); ++i) {
    7075        m_tiles[i].paint(textureMapper, adjustedTransform, opacity, mask);
     76        if (m_drawsDebugBorders)
     77            textureMapper->drawBorder(m_debugBorderColor, m_debugBorderWidth, m_tiles[i].rect(), adjustedTransform);
     78    }
    7179}
    7280
     
    153161}
    154162
     163void TextureMapperTiledBackingStore::setDebugBorder(const Color& color, float width)
     164{
     165    m_debugBorderColor = color;
     166    m_debugBorderWidth = width;
    155167}
     168
     169}
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperBackingStore.h

    r113678 r116823  
    7373    void updateContentsFromImageIfNeeded(TextureMapper*);
    7474
     75    void setShowDebugBorders(bool drawsDebugBorders) { m_drawsDebugBorders = drawsDebugBorders; }
     76    void setDebugBorder(const Color&, float width);
     77
    7578private:
    76     TextureMapperTiledBackingStore() { }
     79    TextureMapperTiledBackingStore();
    7780    void createOrDestroyTilesIfNeeded(const FloatSize& backingStoreSize, const IntSize& tileSize, bool hasAlpha);
    7881
     
    8083    FloatSize m_size;
    8184    RefPtr<Image> m_image;
     85
     86    bool m_drawsDebugBorders;
     87    Color m_debugBorderColor;
     88    float m_debugBorderWidth;
    8289};
    8390
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp

    r115838 r116823  
    305305}
    306306
    307 
    308 void TextureMapperGL::drawTexture(const BitmapTexture& texture, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity, const BitmapTexture* mask)
    309 {
    310     if (!texture.isValid())
    311         return;
    312 
    313     if (clipStack().current().scissorBox.isEmpty())
    314         return;
    315 
    316     const BitmapTextureGL& textureGL = static_cast<const BitmapTextureGL&>(texture);
    317     drawTexture(textureGL.id(), textureGL.isOpaque() ? 0 : SupportsBlending, textureGL.size(), targetRect, matrix, opacity, mask);
    318 }
    319 
    320 void TextureMapperGL::drawTexture(uint32_t texture, Flags flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, const BitmapTexture* maskTexture)
    321 {
    322     RefPtr<TextureMapperShaderProgram> shaderInfo;
    323     if (maskTexture)
    324         shaderInfo = data().sharedGLData().textureMapperShaderManager.getShaderProgram(TextureMapperShaderManager::OpacityAndMask);
    325     else
    326         shaderInfo = data().sharedGLData().textureMapperShaderManager.getShaderProgram(TextureMapperShaderManager::Simple);
    327 
    328     GL_CMD(glUseProgram(shaderInfo->id()));
    329     GL_CMD(glEnableVertexAttribArray(shaderInfo->vertexAttrib()));
    330     GL_CMD(glActiveTexture(GL_TEXTURE0));
    331     GL_CMD(glBindTexture(GL_TEXTURE_2D, texture));
     307void TextureMapperGL::drawRect(const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, TextureMapperShaderProgram* shaderProgram, GLenum drawingMode, bool needsBlending)
     308{
     309    GL_CMD(glEnableVertexAttribArray(shaderProgram->vertexAttrib()));
    332310    GL_CMD(glBindBuffer(GL_ARRAY_BUFFER, 0));
    333311    const GLfloat unitRect[] = {0, 0, 1, 0, 1, 1, 0, 1};
    334     GL_CMD(glVertexAttribPointer(shaderInfo->vertexAttrib(), 2, GL_FLOAT, GL_FALSE, 0, unitRect));
     312    GL_CMD(glVertexAttribPointer(shaderProgram->vertexAttrib(), 2, GL_FLOAT, GL_FALSE, 0, unitRect));
    335313
    336314    TransformationMatrix matrix = TransformationMatrix(data().projectionMatrix).multiply(modelViewMatrix).multiply(TransformationMatrix(
     
    346324        matrix.m41(), matrix.m42(), matrix.m43(), matrix.m44()
    347325    };
     326    GL_CMD(glUniformMatrix4fv(shaderProgram->matrixVariable(), 1, GL_FALSE, m4));
     327
     328    if (needsBlending) {
     329        GL_CMD(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
     330        GL_CMD(glEnable(GL_BLEND));
     331    } else
     332        GL_CMD(glDisable(GL_BLEND));
     333
     334    GL_CMD(glDrawArrays(drawingMode, 0, 4));
     335    GL_CMD(glDisableVertexAttribArray(shaderProgram->vertexAttrib()));
     336}
     337
     338void TextureMapperGL::drawBorder(const Color& color, float width, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix)
     339{
     340    if (clipStack().current().scissorBox.isEmpty())
     341        return;
     342
     343    RefPtr<TextureMapperShaderProgramSolidColor> shaderInfo = data().sharedGLData().textureMapperShaderManager.solidColorProgram();
     344    GL_CMD(glUseProgram(shaderInfo->id()));
     345
     346    float alpha = color.alpha() / 255.0;
     347    GL_CMD(glUniform4f(shaderInfo->colorVariable(),
     348                       (color.red() / 255.0) * alpha,
     349                       (color.green() / 255.0) * alpha,
     350                       (color.blue() / 255.0) * alpha,
     351                       alpha));
     352    GL_CMD(glLineWidth(width));
     353
     354    drawRect(targetRect, modelViewMatrix, shaderInfo.get(), GL_LINE_LOOP, color.hasAlpha());
     355}
     356
     357void TextureMapperGL::drawTexture(const BitmapTexture& texture, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity, const BitmapTexture* mask)
     358{
     359    if (!texture.isValid())
     360        return;
     361
     362    if (clipStack().current().scissorBox.isEmpty())
     363        return;
     364
     365    const BitmapTextureGL& textureGL = static_cast<const BitmapTextureGL&>(texture);
     366    drawTexture(textureGL.id(), textureGL.isOpaque() ? 0 : SupportsBlending, textureGL.size(), targetRect, matrix, opacity, mask);
     367}
     368
     369void TextureMapperGL::drawTexture(uint32_t texture, Flags flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, const BitmapTexture* maskTexture)
     370{
     371    RefPtr<TextureMapperShaderProgram> shaderInfo;
     372    if (maskTexture)
     373        shaderInfo = data().sharedGLData().textureMapperShaderManager.getShaderProgram(TextureMapperShaderManager::OpacityAndMask);
     374    else
     375        shaderInfo = data().sharedGLData().textureMapperShaderManager.getShaderProgram(TextureMapperShaderManager::Simple);
     376    GL_CMD(glUseProgram(shaderInfo->id()));
     377
     378    GL_CMD(glEnableVertexAttribArray(shaderInfo->vertexAttrib()));
     379    GL_CMD(glActiveTexture(GL_TEXTURE0));
     380    GL_CMD(glBindTexture(GL_TEXTURE_2D, texture));
     381    GL_CMD(glUniform1i(shaderInfo->sourceTextureVariable(), 0));
    348382
    349383    const GLfloat m4src[] = {
     
    352386        0, 0, 1, 0,
    353387        0, (flags & ShouldFlipTexture) ? 1 : 0, 0, 1};
    354 
    355     GL_CMD(glUniformMatrix4fv(shaderInfo->matrixVariable(), 1, GL_FALSE, m4));
    356388    GL_CMD(glUniformMatrix4fv(shaderInfo->sourceMatrixVariable(), 1, GL_FALSE, m4src));
    357     GL_CMD(glUniform1i(shaderInfo->sourceTextureVariable(), 0));
    358389
    359390    shaderInfo->prepare(opacity, maskTexture);
    360391
    361392    bool needsBlending = (flags & SupportsBlending) || opacity < 0.99 || maskTexture;
    362 
    363     if (needsBlending) {
    364         GL_CMD(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
    365         GL_CMD(glEnable(GL_BLEND));
    366     } else
    367         GL_CMD(glDisable(GL_BLEND));
    368 
    369     GL_CMD(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
    370     GL_CMD(glDisableVertexAttribArray(shaderInfo->vertexAttrib()));
     393    drawRect(targetRect, modelViewMatrix, shaderInfo.get(), GL_TRIANGLE_FAN, needsBlending);
    371394}
    372395
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h

    r115838 r116823  
    4949
    5050    // reimps from TextureMapper
     51    virtual void drawBorder(const Color&, float borderWidth, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix = TransformationMatrix());
    5152    virtual void drawTexture(const BitmapTexture&, const FloatRect&, const TransformationMatrix&, float opacity, const BitmapTexture* maskTexture);
    5253    virtual void drawTexture(uint32_t texture, Flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, const BitmapTexture* maskTexture);
     
    9596    };
    9697
     98    void drawRect(const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, TextureMapperShaderProgram*, GLenum drawingMode, bool needsBlending);
    9799    bool beginScissorClip(const TransformationMatrix&, const FloatRect&);
    98100    void bindDefaultSurface();
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.h

    r115838 r116823  
    4949class TextureMapperImageBuffer : public TextureMapper {
    5050public:
     51    virtual void drawBorder(const Color& color, float borderWidth, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix = TransformationMatrix()) { };
    5152    virtual void drawTexture(const BitmapTexture&, const FloatRect& targetRect, const TransformationMatrix&, float opacity, const BitmapTexture* maskTexture);
    5253    virtual void beginClip(const TransformationMatrix&, const FloatRect&);
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp

    r116365 r116823  
    9191}
    9292
    93 void TextureMapperLayer::updateBackingStore(TextureMapper* textureMapper, GraphicsLayer* layer)
     93void TextureMapperLayer::updateBackingStore(TextureMapper* textureMapper, GraphicsLayerTextureMapper* layer)
    9494{
    9595    if (!layer || !textureMapper)
     
    124124
    125125    RefPtr<Image> image = imageBuffer->copyImage(DontCopyBackingStore);
    126     static_cast<TextureMapperTiledBackingStore*>(m_backingStore.get())->updateContents(textureMapper, image.get(), m_size, dirtyRect);
     126
     127    TextureMapperTiledBackingStore* backingStore = static_cast<TextureMapperTiledBackingStore*>(m_backingStore.get());
     128    backingStore->updateContents(textureMapper, image.get(), m_size, dirtyRect);
     129
     130    backingStore->setShowDebugBorders(layer->showDebugBorders());
     131    backingStore->setDebugBorder(m_debugBorderColor, m_debugBorderWidth);
     132
    127133    m_state.needsDisplay = false;
    128134    m_state.needsDisplayRect = IntRect();
     
    372378    if (changeMask == NoChanges && graphicsLayer->m_animations.isEmpty())
    373379        return;
     380
     381    graphicsLayer->updateDebugIndicators();
    374382
    375383    if (changeMask & ParentChange) {
     
    547555}
    548556
     557void TextureMapperLayer::setDebugBorder(const Color& color, float width)
     558{
     559    // The default values for GraphicsLayer debug borders are a little
     560    // hard to see (some less than one pixel wide), so we double their size here.
     561    m_debugBorderColor = color;
     562    m_debugBorderWidth = width * 2;
     563}
     564
    549565}
    550566#endif
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h

    r115629 r116823  
    107107        , m_shouldUpdateBackingStoreFromLayer(true)
    108108        , m_textureMapper(0)
     109        , m_debugBorderWidth(0)
    109110    { }
    110111
     
    129130    void setScrollPositionDeltaIfNeeded(const IntPoint&);
    130131    void setFixedToViewport(bool fixed) { m_fixedToViewport = fixed; }
     132
     133    void setDebugBorder(const Color&, float width);
    131134
    132135private:
     
    153156    void paintSelfAndChildren(const TextureMapperPaintOptions&);
    154157    void paintSelfAndChildrenWithReplica(const TextureMapperPaintOptions&);
    155     void updateBackingStore(TextureMapper*, GraphicsLayer*);
     158    void updateBackingStore(TextureMapper*, GraphicsLayerTextureMapper*);
    156159
    157160    void syncAnimations();
     
    231234    IntPoint m_scrollPositionDelta;
    232235    bool m_fixedToViewport;
     236    Color m_debugBorderColor;
     237    float m_debugBorderWidth;
    233238};
    234239
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.cpp

    r115838 r116823  
    9292        }
    9393    );
     94
     95static const char* vertexShaderSourceSolidColor =
     96    VERTEX_SHADER(
     97        uniform mat4 InMatrix;
     98        attribute vec4 InVertex;
     99        void main(void)
     100        {
     101            gl_Position = InMatrix * InVertex;
     102        }
     103    );
     104
     105
     106static const char* fragmentShaderSourceSolidColor =
     107    VERTEX_SHADER(
     108        uniform vec4 Color;
     109        void main(void)
     110        {
     111            gl_FragColor = Color;
     112        }
     113    );
     114
     115PassRefPtr<TextureMapperShaderProgramSolidColor> TextureMapperShaderManager::solidColorProgram()
     116{
     117    return static_pointer_cast<TextureMapperShaderProgramSolidColor>(getShaderProgram(SolidColor));
     118}
     119
     120PassRefPtr<TextureMapperShaderProgram> TextureMapperShaderManager::getShaderProgram(ShaderType shaderType)
     121{
     122    RefPtr<TextureMapperShaderProgram> program;
     123    if (shaderType == Invalid)
     124        return program;
     125
     126    TextureMapperShaderProgramMap::iterator it = m_textureMapperShaderProgramMap.find(shaderType);
     127    if (it != m_textureMapperShaderProgramMap.end())
     128        return it->second;
     129
     130    switch (shaderType) {
     131    case Simple:
     132        program = TextureMapperShaderProgramSimple::create();
     133        break;
     134    case OpacityAndMask:
     135        program = TextureMapperShaderProgramOpacityAndMask::create();
     136        break;
     137    case SolidColor:
     138        program = TextureMapperShaderProgramSolidColor::create();
     139        break;
     140    case Invalid:
     141        ASSERT_NOT_REACHED();
     142    }
     143    m_textureMapperShaderProgramMap.add(shaderType, program);
     144    return program;
     145}
    94146
    95147void TextureMapperShaderProgram::initializeProgram()
     
    160212{
    161213    glUniform1f(m_opacityVariable, opacity);
     214}
     215
     216PassRefPtr<TextureMapperShaderProgramSolidColor> TextureMapperShaderProgramSolidColor::create()
     217{
     218    return adoptRef(new TextureMapperShaderProgramSolidColor());
     219}
     220
     221TextureMapperShaderProgramSolidColor::TextureMapperShaderProgramSolidColor()
     222{
     223    initializeProgram();
     224    getUniformLocation(m_matrixVariable, "InMatrix");
     225    getUniformLocation(m_colorVariable, "Color");
     226}
     227
     228const char* TextureMapperShaderProgramSolidColor::vertexShaderSource() const
     229{
     230    return vertexShaderSourceSolidColor;
     231}
     232
     233const char* TextureMapperShaderProgramSolidColor::fragmentShaderSource() const
     234{
     235    return fragmentShaderSourceSolidColor;
    162236}
    163237
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.h

    r115855 r116823  
    124124};
    125125
     126class TextureMapperShaderProgramSolidColor : public TextureMapperShaderProgram {
     127public:
     128    static PassRefPtr<TextureMapperShaderProgramSolidColor> create();
     129    GLint colorVariable() const { return m_colorVariable; }
     130
     131private:
     132    virtual const char* vertexShaderSource() const;
     133    virtual const char* fragmentShaderSource() const;
     134    TextureMapperShaderProgramSolidColor();
     135    GLint m_colorVariable;
     136};
     137
     138
    126139class TextureMapperShaderManager {
    127140public:
     
    129142        Invalid = 0, // HashMaps do not like 0 as a key.
    130143        Simple,
    131         OpacityAndMask
     144        OpacityAndMask,
     145        SolidColor,
    132146    };
    133147
     
    138152    PassRefPtr<StandardFilterProgram> getShaderForFilter(const FilterOperation&);
    139153#endif
    140 
    141     PassRefPtr<TextureMapperShaderProgram> getShaderProgram(ShaderType shaderType)
    142     {
    143         RefPtr<TextureMapperShaderProgram> program;
    144         if (shaderType == Invalid)
    145             return program;
    146 
    147         TextureMapperShaderProgramMap::iterator it = m_textureMapperShaderProgramMap.find(shaderType);
    148         if (it != m_textureMapperShaderProgramMap.end())
    149             return it->second;
    150 
    151         switch (shaderType) {
    152         case Simple:
    153             program = TextureMapperShaderProgramSimple::create();
    154             break;
    155         case OpacityAndMask:
    156             program = TextureMapperShaderProgramOpacityAndMask::create();
    157             break;
    158         case Invalid:
    159             ASSERT_NOT_REACHED();
    160         }
    161         m_textureMapperShaderProgramMap.add(shaderType, program);
    162         return program;
    163     }
     154    PassRefPtr<TextureMapperShaderProgram> getShaderProgram(ShaderType);
     155    PassRefPtr<TextureMapperShaderProgramSolidColor> solidColorProgram();
    164156
    165157private:
Note: See TracChangeset for help on using the changeset viewer.