Changeset 115838 in webkit


Ignore:
Timestamp:
May 2, 2012 8:30:29 AM (12 years ago)
Author:
noam.rosenthal@nokia.com
Message:

[Texmap] Enable css filters in TextureMapperGL
https://bugs.webkit.org/show_bug.cgi?id=75778

Source/WebCore:

Reviewed by Jocelyn Turcotte.

Added support for color filters in TextureMapperGL. Blur and shadow would be done in a
different patch.

Modified BitmapTexture::applyFilters to return a texture, since GL cannot paint a texture
into itself.
Created a shader map for standard filters, since all of them work more or less the same way
with a single uniform. Added the colorization shaders based on the W3C filter spec, as
already implemented in FEFilterRenderer.cpp and FEColorMatrix.cpp.
We use two swapping textures to render the filters.

Covered by tests in css3/filters.

  • platform/graphics/texmap/TextureMapper.cpp:

(WebCore::TextureMapper::acquireTextureFromPool):

  • platform/graphics/texmap/TextureMapper.h:

(WebCore::BitmapTexture::applyFilters):

  • platform/graphics/texmap/TextureMapperGL.cpp:

(WebCore::BitmapTextureGL::updateContents):
(WebCore):
(WebCore::TextureMapperGL::drawFiltered):
(WebCore::BitmapTextureGL::applyFilters):
(WebCore::BitmapTextureGL::bind):

  • platform/graphics/texmap/TextureMapperGL.h:

(TextureMapperGL):
(BitmapTextureGL):

  • platform/graphics/texmap/TextureMapperImageBuffer.cpp:

(WebCore::BitmapTextureImageBuffer::applyFilters):

  • platform/graphics/texmap/TextureMapperImageBuffer.h:

(BitmapTextureImageBuffer):

  • platform/graphics/texmap/TextureMapperLayer.cpp:

(WebCore::applyFilters):
(WebCore::TextureMapperLayer::syncCompositingStateSelf):

  • platform/graphics/texmap/TextureMapperShaderManager.cpp:

(WebCore::TextureMapperShaderManager::~TextureMapperShaderManager):
(WebCore):
(WebCore::StandardFilterProgram::~StandardFilterProgram):
(WebCore::StandardFilterProgram::StandardFilterProgram):
(WebCore::StandardFilterProgram::create):
(WebCore::StandardFilterProgram::prepare):
(WebCore::TextureMapperShaderManager::getShaderForFilter):

  • platform/graphics/texmap/TextureMapperShaderManager.h:

(WebCore):
(StandardFilterProgram):
(WebCore::StandardFilterProgram::vertexAttrib):
(WebCore::StandardFilterProgram::texCoordAttrib):
(WebCore::StandardFilterProgram::textureUniform):
(TextureMapperShaderManager):

Source/WebKit2:

Add the plumbing in the ui-side compositing code in Qt to support filters.
Serialize the filter operations for a layer when it's changed.

Reviewed by Jocelyn Turcotte.

  • Shared/WebCoreArgumentCoders.cpp:

(CoreIPC):
(CoreIPC::::encode):
(CoreIPC::::decode):

  • Shared/WebCoreArgumentCoders.h:

(WebCore):

  • UIProcess/LayerTreeHostProxy.cpp:

(WebKit):
(WebKit::LayerTreeHostProxy::setCompositingLayerFilters):

  • UIProcess/LayerTreeHostProxy.h:

(LayerTreeHostProxy):

  • UIProcess/LayerTreeHostProxy.messages.in:
  • UIProcess/WebLayerTreeRenderer.cpp:

(WebKit):
(WebKit::WebLayerTreeRenderer::setLayerFilters):

  • UIProcess/WebLayerTreeRenderer.h:

(WebLayerTreeRenderer):

  • WebProcess/WebCoreSupport/WebGraphicsLayer.cpp:

(WebCore):
(WebCore::WebGraphicsLayer::didChangeFilters):
(WebCore::WebGraphicsLayer::setFilters):
(WebCore::WebGraphicsLayer::syncFilters):
(WebCore::WebGraphicsLayer::syncCompositingStateForThisLayerOnly):

  • WebProcess/WebCoreSupport/WebGraphicsLayer.h:

(WebGraphicsLayerClient):
(WebGraphicsLayer):

  • WebProcess/WebPage/qt/LayerTreeHostQt.cpp:

(WebKit):
(WebKit::LayerTreeHostQt::syncLayerFilters):

  • WebProcess/WebPage/qt/LayerTreeHostQt.h:

(LayerTreeHostQt):

Location:
trunk/Source
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r115829 r115838  
     12012-05-02  No'am Rosenthal  <noam.rosenthal@nokia.com>
     2
     3        [Texmap] Enable css filters in TextureMapperGL
     4        https://bugs.webkit.org/show_bug.cgi?id=75778
     5
     6        Reviewed by Jocelyn Turcotte.
     7
     8        Added support for color filters in TextureMapperGL. Blur and shadow would be done in a
     9        different patch.
     10
     11        Modified BitmapTexture::applyFilters to return a texture, since GL cannot paint a texture
     12        into itself.
     13        Created a shader map for standard filters, since all of them work more or less the same way
     14        with a single uniform. Added the colorization shaders based on the W3C filter spec, as
     15        already implemented in FEFilterRenderer.cpp and FEColorMatrix.cpp.
     16        We use two swapping textures to render the filters.
     17
     18        Covered by tests in css3/filters.
     19
     20        * platform/graphics/texmap/TextureMapper.cpp:
     21        (WebCore::TextureMapper::acquireTextureFromPool):
     22        * platform/graphics/texmap/TextureMapper.h:
     23        (WebCore::BitmapTexture::applyFilters):
     24        * platform/graphics/texmap/TextureMapperGL.cpp:
     25        (WebCore::BitmapTextureGL::updateContents):
     26        (WebCore):
     27        (WebCore::TextureMapperGL::drawFiltered):
     28        (WebCore::BitmapTextureGL::applyFilters):
     29        (WebCore::BitmapTextureGL::bind):
     30        * platform/graphics/texmap/TextureMapperGL.h:
     31        (TextureMapperGL):
     32        (BitmapTextureGL):
     33        * platform/graphics/texmap/TextureMapperImageBuffer.cpp:
     34        (WebCore::BitmapTextureImageBuffer::applyFilters):
     35        * platform/graphics/texmap/TextureMapperImageBuffer.h:
     36        (BitmapTextureImageBuffer):
     37        * platform/graphics/texmap/TextureMapperLayer.cpp:
     38        (WebCore::applyFilters):
     39        (WebCore::TextureMapperLayer::syncCompositingStateSelf):
     40        * platform/graphics/texmap/TextureMapperShaderManager.cpp:
     41        (WebCore::TextureMapperShaderManager::~TextureMapperShaderManager):
     42        (WebCore):
     43        (WebCore::StandardFilterProgram::~StandardFilterProgram):
     44        (WebCore::StandardFilterProgram::StandardFilterProgram):
     45        (WebCore::StandardFilterProgram::create):
     46        (WebCore::StandardFilterProgram::prepare):
     47        (WebCore::TextureMapperShaderManager::getShaderForFilter):
     48        * platform/graphics/texmap/TextureMapperShaderManager.h:
     49        (WebCore):
     50        (StandardFilterProgram):
     51        (WebCore::StandardFilterProgram::vertexAttrib):
     52        (WebCore::StandardFilterProgram::texCoordAttrib):
     53        (WebCore::StandardFilterProgram::textureUniform):
     54        (TextureMapperShaderManager):
     55
    1562012-05-02  Philippe Normand  <pnormand@igalia.com>
    257
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp

    r110979 r115838  
    4949    }
    5050
    51     selectedTexture->reset(size);
     51    selectedTexture->reset(size, BitmapTexture::SupportsAlpha);
    5252    return selectedTexture;
    5353}
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.h

    r113859 r115838  
    8888
    8989#if ENABLE(CSS_FILTERS)
    90     virtual void applyFilters(const BitmapTexture& contentTexture, const FilterOperations&) { }
     90    virtual PassRefPtr<BitmapTexture> applyFilters(const BitmapTexture& contentTexture, const FilterOperations&) { return this; }
    9191#endif
    9292
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp

    r115576 r115838  
    504504
    505505    updateContents(imageData, targetRect, offset, bytesPerLine);
    506 
    507 }
     506}
     507
     508#if ENABLE(CSS_FILTERS)
     509void TextureMapperGL::drawFiltered(const BitmapTexture& sourceTexture, const BitmapTexture& contentTexture, const FilterOperation& filter)
     510{
     511    // For standard filters, we always draw the whole texture without transformations.
     512    RefPtr<StandardFilterProgram> program = data().sharedGLData().textureMapperShaderManager.getShaderForFilter(filter);
     513    if (!program) {
     514        drawTexture(sourceTexture, FloatRect(FloatPoint::zero(), sourceTexture.size()), TransformationMatrix(), 1, 0);
     515        return;
     516    }
     517    GL_CMD(glEnableVertexAttribArray(program->vertexAttrib()));
     518    GL_CMD(glEnableVertexAttribArray(program->texCoordAttrib()));
     519    GL_CMD(glActiveTexture(GL_TEXTURE0));
     520    GL_CMD(glBindTexture(GL_TEXTURE_2D, static_cast<const BitmapTextureGL&>(sourceTexture).id()));
     521    glUniform1i(program->textureUniform(), 0);
     522    const GLfloat targetVertices[] = {-1, -1, 1, -1, 1, 1, -1, 1};
     523    const GLfloat sourceVertices[] = {0, 0, 1, 0, 1, 1, 0, 1};
     524    GL_CMD(glVertexAttribPointer(program->vertexAttrib(), 2, GL_FLOAT, GL_FALSE, 0, targetVertices));
     525    GL_CMD(glVertexAttribPointer(program->texCoordAttrib(), 2, GL_FLOAT, GL_FALSE, 0, sourceVertices));
     526    GL_CMD(glDisable(GL_BLEND));
     527    GL_CMD(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
     528    GL_CMD(glDisableVertexAttribArray(program->vertexAttrib()));
     529    GL_CMD(glDisableVertexAttribArray(program->texCoordAttrib()));
     530}
     531
     532PassRefPtr<BitmapTexture> BitmapTextureGL::applyFilters(const BitmapTexture& contentTexture, const FilterOperations& filters)
     533{
     534    RefPtr<BitmapTexture> previousSurface = m_textureMapper->data().currentSurface;
     535
     536    RefPtr<BitmapTexture> source = this;
     537    RefPtr<BitmapTexture> target = m_textureMapper->acquireTextureFromPool(m_textureSize);
     538    for (int i = 0; i < filters.size(); ++i) {
     539        const FilterOperation* filter = filters.at(i);
     540        ASSERT(filter);
     541
     542        m_textureMapper->bindSurface(target.get());
     543        m_textureMapper->drawFiltered(i ? *source.get() : contentTexture, contentTexture, *filter);
     544        std::swap(source, target);
     545    }
     546
     547    m_textureMapper->bindSurface(previousSurface.get());
     548    return source;
     549}
     550#endif
    508551
    509552static inline TransformationMatrix createProjectionMatrix(const IntSize& size, bool mirrored)
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h

    r115574 r115838  
    6666    virtual AccelerationMode accelerationMode() const { return OpenGLMode; }
    6767
     68#if ENABLE(CSS_FILTERS)
     69    void drawFiltered(const BitmapTexture& sourceTexture, const BitmapTexture& contentTexture, const FilterOperation&);
     70#endif
     71
     72
    6873private:
    6974
     
    117122    virtual bool isBackedByOpenGL() const { return true; }
    118123
     124#if ENABLE(CSS_FILTERS)
     125    virtual PassRefPtr<BitmapTexture> applyFilters(const BitmapTexture& contentTexture, const FilterOperations&);
     126#endif
     127
    119128private:
    120129    GLuint m_id;
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.cpp

    r115123 r115838  
    111111
    112112#if ENABLE(CSS_FILTERS)
    113 void BitmapTextureImageBuffer::applyFilters(const BitmapTexture& contentTexture, const FilterOperations& filters)
     113PassRefPtr<BitmapTexture> BitmapTextureImageBuffer::applyFilters(const BitmapTexture& contentTexture, const FilterOperations& filters)
    114114{
    115115    RefPtr<FilterEffectRenderer> renderer = FilterEffectRenderer::create();
     
    123123    renderer->apply();
    124124    m_image->context()->drawImageBuffer(renderer->output(), ColorSpaceDeviceRGB, renderer->outputRect());
     125    return this;
    125126}
    126127#endif
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperImageBuffer.h

    r113678 r115838  
    3838    virtual void updateContents(const void*, const IntRect& target, const IntPoint& sourceOffset, int bytesPerLine);
    3939#if ENABLE(CSS_FILTERS)
    40     void applyFilters(const BitmapTexture&, const FilterOperations&);
     40    PassRefPtr<BitmapTexture> applyFilters(const BitmapTexture&, const FilterOperations&);
    4141#endif
    4242
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp

    r115629 r115838  
    305305    }
    306306
    307     filterSurface->applyFilters(*source, filters);
    308     return filterSurface;
     307    return filterSurface->applyFilters(*source, filters);
    309308}
    310309#endif
     
    443442    m_state.opacity = graphicsLayer->opacity();
    444443#if ENABLE(CSS_FILTERS)
    445     m_state.filters = graphicsLayer->filters();
     444    if (changeMask & FilterChange)
     445        m_state.filters = graphicsLayer->filters();
    446446#endif
    447447    m_fixedToViewport = graphicsLayer->fixedToViewport();
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.cpp

    r110438 r115838  
    207207TextureMapperShaderManager::~TextureMapperShaderManager()
    208208{
    209     m_textureMapperShaderProgramMap.clear();
    210 }
    211 
     209}
     210
     211#if ENABLE(CSS_FILTERS)
     212StandardFilterProgram::~StandardFilterProgram()
     213{
     214    glDetachShader(m_id, m_vertexShader);
     215    glDeleteShader(m_vertexShader);
     216    glDetachShader(m_id, m_fragmentShader);
     217    glDeleteShader(m_fragmentShader);
     218    glDeleteProgram(m_id);
     219}
     220
     221StandardFilterProgram::StandardFilterProgram(FilterOperation::OperationType type)
     222    : m_id(0)
     223{
     224    const char* vertexShaderSource =
     225            VERTEX_SHADER(
     226                attribute vec4 a_vertex;
     227                attribute vec4 a_texCoord;
     228                varying highp vec2 v_texCoord;
     229                void main(void)
     230                {
     231                    v_texCoord = vec2(a_texCoord);
     232                    gl_Position = a_vertex;
     233                }
     234            );
     235
     236#define STANDARD_FILTER(x...) \
     237        OES2_PRECISION_DEFINITIONS\
     238        OES2_FRAGMENT_SHADER_DEFAULT_PRECISION\
     239        "varying highp vec2 v_texCoord;\n"\
     240        "uniform highp float u_amount;\n"\
     241        "uniform sampler2D u_texture;\n"\
     242        #x\
     243        "void main(void)\n { gl_FragColor = shade(texture2D(u_texture, v_texCoord)); }"
     244
     245    const char* fragmentShaderSource = 0;
     246    switch (type) {
     247    case FilterOperation::GRAYSCALE:
     248        fragmentShaderSource = STANDARD_FILTER(
     249            lowp vec4 shade(lowp vec4 color)
     250            {
     251                lowp float amount = 1.0 - u_amount;
     252                return vec4((0.2126 + 0.7874 * amount) * color.r + (0.7152 - 0.7152 * amount) * color.g + (0.0722 - 0.0722 * amount) * color.b,
     253                            (0.2126 - 0.2126 * amount) * color.r + (0.7152 + 0.2848 * amount) * color.g + (0.0722 - 0.0722 * amount) * color.b,
     254                            (0.2126 - 0.2126 * amount) * color.r + (0.7152 - 0.7152 * amount) * color.g + (0.0722 + 0.9278 * amount) * color.b,
     255                            color.a);
     256            }
     257        );
     258        break;
     259    case FilterOperation::SEPIA:
     260        fragmentShaderSource = STANDARD_FILTER(
     261            lowp vec4 shade(lowp vec4 color)
     262            {
     263                lowp float amount = 1.0 - u_amount;
     264                return vec4((0.393 + 0.607 * amount) * color.r + (0.769 - 0.769 * amount) * color.g + (0.189 - 0.189 * amount) * color.b,
     265                            (0.349 - 0.349 * amount) * color.r + (0.686 + 0.314 * amount) * color.g + (0.168 - 0.168 * amount) * color.b,
     266                            (0.272 - 0.272 * amount) * color.r + (0.534 - 0.534 * amount) * color.g + (0.131 + 0.869 * amount) * color.b,
     267                            color.a);
     268            }
     269        );
     270        break;
     271    case FilterOperation::SATURATE:
     272        fragmentShaderSource = STANDARD_FILTER(
     273            lowp vec4 shade(lowp vec4 color)
     274            {
     275                return vec4((0.213 + 0.787 * u_amount) * color.r + (0.715 - 0.715 * u_amount) * color.g + (0.072 - 0.072 * u_amount) * color.b,
     276                            (0.213 - 0.213 * u_amount) * color.r + (0.715 + 0.285 * u_amount) * color.g + (0.072 - 0.072 * u_amount) * color.b,
     277                            (0.213 - 0.213 * u_amount) * color.r + (0.715 - 0.715 * u_amount) * color.g + (0.072 + 0.928 * u_amount) * color.b,
     278                            color.a);
     279            }
     280        );
     281        break;
     282    case FilterOperation::HUE_ROTATE:
     283        fragmentShaderSource = STANDARD_FILTER(
     284            lowp vec4 shade(lowp vec4 color)
     285            {
     286                highp float pi = 3.14159265358979323846;
     287                highp float c = cos(u_amount * pi / 180.0);
     288                highp float s = sin(u_amount * pi / 180.0);
     289                return vec4(color.r * (0.213 + c * 0.787 - s * 0.213) + color.g * (0.715 - c * 0.715 - s * 0.715) + color.b * (0.072 - c * 0.072 + s * 0.928),
     290                            color.r * (0.213 - c * 0.213 + s * 0.143) + color.g * (0.715 + c * 0.285 + s * 0.140) + color.b * (0.072 - c * 0.072 - s * 0.283),
     291                            color.r * (0.213 - c * 0.213 - s * 0.787) +  color.g * (0.715 - c * 0.715 + s * 0.715) + color.b * (0.072 + c * 0.928 + s * 0.072),
     292                            color.a);
     293            }
     294        );
     295        break;
     296    case FilterOperation::INVERT:
     297        fragmentShaderSource = STANDARD_FILTER(
     298            lowp float invert(lowp float n) { return (1.0 - n) * u_amount + n * (1.0 - u_amount); }
     299            lowp vec4 shade(lowp vec4 color)
     300            {
     301                return vec4(invert(color.r), invert(color.g), invert(color.b), color.a);
     302            }
     303        );
     304        break;
     305    case FilterOperation::BRIGHTNESS:
     306        fragmentShaderSource = STANDARD_FILTER(
     307            lowp vec4 shade(lowp vec4 color)
     308            {
     309                return vec4(color.rgb * (1.0 + u_amount), color.a);
     310            }
     311        );
     312        break;
     313    case FilterOperation::CONTRAST:
     314        fragmentShaderSource = STANDARD_FILTER(
     315            lowp float contrast(lowp float n) { return (n - 0.5) * u_amount + 0.5; }
     316            lowp vec4 shade(lowp vec4 color)
     317            {
     318                return vec4(contrast(color.r), contrast(color.g), contrast(color.b), color.a);
     319            }
     320        );
     321        break;
     322    case FilterOperation::OPACITY:
     323        fragmentShaderSource = STANDARD_FILTER(
     324            lowp vec4 shade(lowp vec4 color)
     325            {
     326                return vec4(color.r, color.g, color.b, color.a * u_amount);
     327            }
     328        );
     329        break;
     330    default:
     331        break;
     332    }
     333
     334    if (!fragmentShaderSource)
     335        return;
     336    GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
     337    GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
     338    glShaderSource(vertexShader, 1, &vertexShaderSource, 0);
     339    glShaderSource(fragmentShader, 1, &fragmentShaderSource, 0);
     340    GLchar log[100];
     341    GLint len;
     342    GLuint programID = glCreateProgram();
     343    glCompileShader(vertexShader);
     344    glCompileShader(fragmentShader);
     345    glGetShaderInfoLog(fragmentShader, 100, &len, log);
     346    glAttachShader(programID, vertexShader);
     347    glAttachShader(programID, fragmentShader);
     348    glLinkProgram(programID);
     349
     350    m_vertexAttrib = glGetAttribLocation(programID, "a_vertex");
     351    m_texCoordAttrib = glGetAttribLocation(programID, "a_texCoord");
     352    m_textureUniformLocation = glGetUniformLocation(programID, "u_texture");
     353    switch (type) {
     354    case FilterOperation::GRAYSCALE:
     355    case FilterOperation::SEPIA:
     356    case FilterOperation::SATURATE:
     357    case FilterOperation::HUE_ROTATE:
     358    case FilterOperation::INVERT:
     359    case FilterOperation::BRIGHTNESS:
     360    case FilterOperation::CONTRAST:
     361    case FilterOperation::OPACITY:
     362        m_uniformLocations.amount = glGetUniformLocation(programID, "u_amount");
     363        break;
     364    default:
     365        break;
     366    }
     367    m_id = programID;
     368    m_vertexShader = vertexShader;
     369    m_fragmentShader = fragmentShader;
     370}
     371
     372PassRefPtr<StandardFilterProgram> StandardFilterProgram::create(FilterOperation::OperationType type)
     373{
     374    RefPtr<StandardFilterProgram> program = adoptRef(new StandardFilterProgram(type));
     375    if (!program->m_id)
     376        return 0;
     377
     378    return program;
     379}
     380
     381void StandardFilterProgram::prepare(const FilterOperation& operation)
     382{
     383    double amount = 0;
     384    switch (operation.getOperationType()) {
     385    case FilterOperation::GRAYSCALE:
     386    case FilterOperation::SEPIA:
     387    case FilterOperation::SATURATE:
     388    case FilterOperation::HUE_ROTATE:
     389        amount = static_cast<const BasicColorMatrixFilterOperation&>(operation).amount();
     390        break;
     391    case FilterOperation::INVERT:
     392    case FilterOperation::BRIGHTNESS:
     393    case FilterOperation::CONTRAST:
     394    case FilterOperation::OPACITY:
     395        amount = static_cast<const BasicComponentTransferFilterOperation&>(operation).amount();
     396        break;
     397    default:
     398        break;
     399    }
     400    glUseProgram(m_id);
     401    glUniform1f(m_uniformLocations.amount, amount);
     402}
     403
     404PassRefPtr<StandardFilterProgram> TextureMapperShaderManager::getShaderForFilter(const FilterOperation& filter)
     405{
     406    RefPtr<StandardFilterProgram> program;
     407    FilterOperation::OperationType type = filter.getOperationType();
     408    FilterMap::iterator iterator = m_filterMap.find(type);
     409    if (iterator == m_filterMap.end()) {
     410        program = StandardFilterProgram::create(type);
     411        if (!program)
     412            return 0;
     413
     414        m_filterMap.add(type, program);
     415    } else
     416        program = iterator->second;
     417
     418    program->prepare(filter);
     419    return program;
     420}
     421
     422#endif
    212423};
    213424
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.h

    r113746 r115838  
    3131#include <wtf/PassRefPtr.h>
    3232#include <wtf/RefPtr.h>
     33
     34#if ENABLE(CSS_FILTERS)
     35#include "FilterOperations.h"
     36#endif
    3337
    3438namespace WebCore {
     
    6569    GLint m_opacityVariable;
    6670};
     71
     72#if ENABLE(CSS_FILTERS)
     73class StandardFilterProgram : public RefCounted<StandardFilterProgram> {
     74public:
     75    virtual ~StandardFilterProgram();
     76    virtual void prepare(const FilterOperation&);
     77    static PassRefPtr<StandardFilterProgram> create(FilterOperation::OperationType);
     78    GLuint vertexAttrib() const { return m_vertexAttrib; }
     79    GLuint texCoordAttrib() const { return m_texCoordAttrib; }
     80    GLuint textureUniform() const { return m_textureUniformLocation; }
     81private:
     82    StandardFilterProgram(FilterOperation::OperationType);
     83    GLuint m_id;
     84    GLuint m_vertexShader;
     85    GLuint m_fragmentShader;
     86    GLuint m_vertexAttrib;
     87    GLuint m_texCoordAttrib;
     88    GLuint m_textureUniformLocation;
     89    union {
     90        GLuint amount;
     91        GLuint stddev;
     92        struct {
     93            GLuint stddev;
     94            GLuint color;
     95            GLuint offset;
     96        } shadow;
     97    } m_uniformLocations;
     98};
     99#endif
    67100
    68101class TextureMapperShaderProgramSimple : public TextureMapperShaderProgram {
     
    102135    virtual ~TextureMapperShaderManager();
    103136
     137    PassRefPtr<StandardFilterProgram> getShaderForFilter(const FilterOperation&);
     138
    104139    PassRefPtr<TextureMapperShaderProgram> getShaderProgram(ShaderType shaderType)
    105140    {
     
    129164    typedef HashMap<ShaderType, RefPtr<TextureMapperShaderProgram>, DefaultHash<int>::Hash, HashTraits<int> > TextureMapperShaderProgramMap;
    130165    TextureMapperShaderProgramMap m_textureMapperShaderProgramMap;
     166
     167#if ENABLE(CSS_FILTERS)
     168    typedef HashMap<FilterOperation::OperationType, RefPtr<StandardFilterProgram>, DefaultHash<int>::Hash, HashTraits<int> > FilterMap;
     169    FilterMap m_filterMap;
     170#endif
     171
    131172};
    132173
  • trunk/Source/WebKit2/ChangeLog

    r115831 r115838  
     12012-05-02  No'am Rosenthal  <noam.rosenthal@nokia.com>
     2
     3        [Texmap] Enable css filters in TextureMapperGL
     4        https://bugs.webkit.org/show_bug.cgi?id=75778
     5
     6        Add the plumbing in the ui-side compositing code in Qt to support filters.
     7        Serialize the filter operations for a layer when it's changed.
     8
     9        Reviewed by Jocelyn Turcotte.
     10
     11        * Shared/WebCoreArgumentCoders.cpp:
     12        (CoreIPC):
     13        (CoreIPC::::encode):
     14        (CoreIPC::::decode):
     15        * Shared/WebCoreArgumentCoders.h:
     16        (WebCore):
     17        * UIProcess/LayerTreeHostProxy.cpp:
     18        (WebKit):
     19        (WebKit::LayerTreeHostProxy::setCompositingLayerFilters):
     20        * UIProcess/LayerTreeHostProxy.h:
     21        (LayerTreeHostProxy):
     22        * UIProcess/LayerTreeHostProxy.messages.in:
     23        * UIProcess/WebLayerTreeRenderer.cpp:
     24        (WebKit):
     25        (WebKit::WebLayerTreeRenderer::setLayerFilters):
     26        * UIProcess/WebLayerTreeRenderer.h:
     27        (WebLayerTreeRenderer):
     28        * WebProcess/WebCoreSupport/WebGraphicsLayer.cpp:
     29        (WebCore):
     30        (WebCore::WebGraphicsLayer::didChangeFilters):
     31        (WebCore::WebGraphicsLayer::setFilters):
     32        (WebCore::WebGraphicsLayer::syncFilters):
     33        (WebCore::WebGraphicsLayer::syncCompositingStateForThisLayerOnly):
     34        * WebProcess/WebCoreSupport/WebGraphicsLayer.h:
     35        (WebGraphicsLayerClient):
     36        (WebGraphicsLayer):
     37        * WebProcess/WebPage/qt/LayerTreeHostQt.cpp:
     38        (WebKit):
     39        (WebKit::LayerTreeHostQt::syncLayerFilters):
     40        * WebProcess/WebPage/qt/LayerTreeHostQt.h:
     41        (LayerTreeHostQt):
     42
    1432012-05-02  Simon Hausmann  <simon.hausmann@nokia.com>
    244
  • trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp

    r113974 r115838  
    6262#endif
    6363
     64#if USE(UI_SIDE_COMPOSITING) && ENABLE(CSS_FILTERS)
     65#include <WebCore/FilterOperations.h>
     66#endif
     67
    6468using namespace WebCore;
    6569using namespace WebKit;
     
    12421246#endif
    12431247
     1248#if USE(UI_SIDE_COMPOSITING) && ENABLE(CSS_FILTERS)
     1249void ArgumentCoder<WebCore::FilterOperations>::encode(ArgumentEncoder* encoder, const WebCore::FilterOperations& filters)
     1250{
     1251    encoder->encodeUInt32(filters.size());
     1252    for (size_t i = 0; i < filters.size(); ++i) {
     1253        const FilterOperation* filter = filters.at(i);
     1254        FilterOperation::OperationType type = filter->getOperationType();
     1255        encoder->encodeEnum(type);
     1256        switch (type) {
     1257        case FilterOperation::GRAYSCALE:
     1258        case FilterOperation::SEPIA:
     1259        case FilterOperation::SATURATE:
     1260        case FilterOperation::HUE_ROTATE:
     1261            encoder->encodeDouble(static_cast<const BasicColorMatrixFilterOperation*>(filter)->amount());
     1262            break;
     1263        case FilterOperation::INVERT:
     1264        case FilterOperation::BRIGHTNESS:
     1265        case FilterOperation::CONTRAST:
     1266        case FilterOperation::OPACITY:
     1267            encoder->encodeDouble(static_cast<const BasicComponentTransferFilterOperation*>(filter)->amount());
     1268            break;
     1269        case FilterOperation::BLUR:
     1270            ArgumentCoder<Length>::encode(encoder, static_cast<const BlurFilterOperation*>(filter)->stdDeviation());
     1271            break;
     1272        case FilterOperation::DROP_SHADOW: {
     1273            const DropShadowFilterOperation* shadow = static_cast<const DropShadowFilterOperation*>(filter);
     1274            ArgumentCoder<IntPoint>::encode(encoder, shadow->location());
     1275            encoder->encodeInt32(shadow->stdDeviation());
     1276            ArgumentCoder<Color>::encode(encoder, shadow->color());
     1277            break;
     1278        }
     1279        default:
     1280            break;
     1281        }
     1282    }
     1283}
     1284
     1285bool ArgumentCoder<WebCore::FilterOperations>::decode(ArgumentDecoder* decoder, WebCore::FilterOperations& filters)
     1286{
     1287    uint32_t size;
     1288    if (!decoder->decodeUInt32(size))
     1289        return false;
     1290
     1291    Vector<RefPtr<FilterOperation> >& operations = filters.operations();
     1292
     1293    for (size_t i = 0; i < size; ++i) {
     1294        FilterOperation::OperationType type;
     1295        RefPtr<FilterOperation> filter;
     1296        if (!decoder->decodeEnum(type))
     1297            return false;
     1298
     1299        switch (type) {
     1300        case FilterOperation::GRAYSCALE:
     1301        case FilterOperation::SEPIA:
     1302        case FilterOperation::SATURATE:
     1303        case FilterOperation::HUE_ROTATE: {
     1304            double value;
     1305            if (!decoder->decodeDouble(value))
     1306                return false;
     1307            filter = BasicColorMatrixFilterOperation::create(value, type);
     1308            break;
     1309        }
     1310        case FilterOperation::INVERT:
     1311        case FilterOperation::BRIGHTNESS:
     1312        case FilterOperation::CONTRAST:
     1313        case FilterOperation::OPACITY: {
     1314            double value;
     1315            if (!decoder->decodeDouble(value))
     1316                return false;
     1317            filter = BasicComponentTransferFilterOperation::create(value, type);
     1318            break;
     1319        }
     1320        case FilterOperation::BLUR: {
     1321            Length length;
     1322            if (!ArgumentCoder<Length>::decode(decoder, length))
     1323                return false;
     1324            filter = BlurFilterOperation::create(length, type);
     1325            break;
     1326        }
     1327        case FilterOperation::DROP_SHADOW: {
     1328            IntPoint location;
     1329            int32_t stdDeviation;
     1330            Color color;
     1331            if (!ArgumentCoder<IntPoint>::decode(decoder, location))
     1332                return false;
     1333            if (!decoder->decodeInt32(stdDeviation))
     1334                return false;
     1335            if (!ArgumentCoder<Color>::decode(decoder, color))
     1336                return false;
     1337            filter = DropShadowFilterOperation::create(location, stdDeviation, color, type);
     1338            break;
     1339        }
     1340        default:
     1341            break;
     1342        }
     1343
     1344        if (filter)
     1345            operations.append(filter);
     1346    }
     1347
     1348    return true;
     1349}
    12441350#endif
    12451351
     1352#endif
     1353
    12461354} // namespace CoreIPC
  • trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.h

    r113974 r115838  
    8686#endif
    8787
     88#if USE(UI_SIDE_COMPOSITING) && ENABLE(CSS_FILTERS)
     89namespace WebCore {
     90    class FilterOperations;
     91}
     92#endif
     93
    8894namespace CoreIPC {
    8995
     
    302308#endif
    303309
     310#if USE(UI_SIDE_COMPOSITING) && ENABLE(CSS_FILTERS)
     311template<> struct ArgumentCoder<WebCore::FilterOperations> {
     312    static void encode(ArgumentEncoder*, const WebCore::FilterOperations&);
     313    static bool decode(ArgumentDecoder*, WebCore::FilterOperations&);
     314};
     315#endif
     316
    304317#if USE(ACCELERATED_COMPOSITING)
    305318template<> struct ArgumentCoder<WebCore::KeyframeValueList> {
  • trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.cpp

    r115696 r115838  
    106106}
    107107
     108#if ENABLE(CSS_FILTERS)
     109void LayerTreeHostProxy::setCompositingLayerFilters(WebLayerID id, const FilterOperations& filters)
     110{
     111    dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerFilters, m_renderer.get(), id, filters));
     112}
     113#endif
     114
    108115void LayerTreeHostProxy::didRenderFrame()
    109116{
  • trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.h

    r115696 r115838  
    5151    void setCompositingLayerState(WebLayerID, const WebLayerInfo&);
    5252    void setCompositingLayerChildren(WebLayerID, const Vector<WebLayerID>&);
     53#if ENABLE(CSS_FILTERS)
     54    void setCompositingLayerFilters(WebLayerID, const WebCore::FilterOperations&);
     55#endif
    5356    void deleteCompositingLayer(WebLayerID);
    5457    void setRootCompositingLayer(WebLayerID);
  • trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.messages.in

    r113791 r115838  
    2222    SetCompositingLayerState(uint32_t id, WebKit::WebLayerInfo layerInfo)
    2323    SetCompositingLayerChildren(uint32_t id, Vector<uint32_t> children)
     24#if ENABLE(CSS_FILTERS)
     25    SetCompositingLayerFilters(uint32_t id, WebCore::FilterOperations filters)
     26#endif
    2427    SetRootCompositingLayer(uint32_t id)
    2528    DeleteCompositingLayer(uint32_t id)
  • trunk/Source/WebKit2/UIProcess/WebLayerTreeRenderer.cpp

    r115696 r115838  
    214214}
    215215
     216#if ENABLE(CSS_FILTERS)
     217void WebLayerTreeRenderer::setLayerFilters(WebLayerID id, const FilterOperations& filters)
     218{
     219    ensureLayer(id);
     220    LayerMap::iterator it = m_layers.find(id);
     221    ASSERT(it != m_layers.end());
     222
     223    GraphicsLayer* layer = it->second;
     224    layer->setFilters(filters);
     225}
     226#endif
     227
    216228void WebLayerTreeRenderer::setLayerState(WebLayerID id, const WebLayerInfo& layerInfo)
    217229{
  • trunk/Source/WebKit2/UIProcess/WebLayerTreeRenderer.h

    r115696 r115838  
    7878    void setLayerChildren(WebLayerID, const Vector<WebLayerID>&);
    7979    void setLayerState(WebLayerID, const WebLayerInfo&);
     80#if ENABLE(CSS_FILTERS)
     81    void setLayerFilters(WebLayerID, const WebCore::FilterOperations&);
     82#endif
     83
    8084    void createTile(WebLayerID, int, float scale);
    8185    void removeTile(WebLayerID, int);
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebGraphicsLayer.cpp

    r114705 r115838  
    7575}
    7676
     77#if ENABLE(CSS_FILTERS)
     78void WebGraphicsLayer::didChangeFilters()
     79{
     80    m_shouldSyncFilters = true;
     81    if (client())
     82        client()->notifySyncRequired(this);
     83}
     84#endif
     85
    7786void WebGraphicsLayer::setShouldUpdateVisibleRect()
    7887{
     
    309318    setContentsToImage(image.get());
    310319}
     320
     321#if ENABLE(CSS_FILTERS)
     322bool WebGraphicsLayer::setFilters(const FilterOperations& newFilters)
     323{
     324    if (filters() == newFilters)
     325        return true;
     326    didChangeFilters();
     327    return GraphicsLayer::setFilters(newFilters);
     328}
     329#endif
     330
    311331
    312332void WebGraphicsLayer::setContentsToImage(Image* image)
     
    413433    m_webGraphicsLayerClient->syncLayerChildren(m_id, childIDs);
    414434}
     435
     436#if ENABLE(CSS_FILTERS)
     437void WebGraphicsLayer::syncFilters()
     438{
     439    if (!m_shouldSyncFilters)
     440        return;
     441    m_shouldSyncFilters = false;
     442    m_webGraphicsLayerClient->syncLayerFilters(m_id, filters());
     443}
     444#endif
    415445
    416446void WebGraphicsLayer::syncLayerState()
     
    453483    syncChildren();
    454484    syncLayerState();
     485#if ENABLE(CSS_FILTERS)
     486    syncFilters();
     487#endif
    455488    updateContentBuffers();
    456489}
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebGraphicsLayer.h

    r113791 r115838  
    5858    virtual void syncLayerState(WebLayerID, const WebLayerInfo&) = 0;
    5959    virtual void syncLayerChildren(WebLayerID, const Vector<WebLayerID>&) = 0;
     60#if ENABLE(CSS_FILTERS)
     61    virtual void syncLayerFilters(WebLayerID, const WebCore::FilterOperations&) = 0;
     62#endif
    6063    virtual void attachLayer(WebCore::WebGraphicsLayer*) = 0;
    6164    virtual void detachLayer(WebCore::WebGraphicsLayer*) = 0;
     
    105108    virtual void syncCompositingState(const FloatRect&);
    106109    virtual void syncCompositingStateForThisLayerOnly();
     110#if ENABLE(CSS_FILTERS)
     111    bool setFilters(const FilterOperations&);
     112#endif
    107113
    108114    void setRootLayer(bool);
     
    139145    void syncChildren();
    140146    void syncLayerState();
     147#if ENABLE(CSS_FILTERS)
     148    void syncFilters();
     149#endif
    141150    void ensureImageBackingStore();
    142151
     
    158167    bool m_shouldSyncLayerState: 1;
    159168    bool m_shouldSyncChildren: 1;
     169    bool m_shouldSyncFilters: 1;
    160170    bool m_fixedToViewport : 1;
    161171
     
    164174    void didChangeLayerState();
    165175    void didChangeChildren();
     176#if ENABLE(CSS_FILTERS)
     177    void didChangeFilters();
     178#endif
     179
    166180    void createBackingStore();
    167181
  • trunk/Source/WebKit2/WebProcess/WebPage/qt/LayerTreeHostQt.cpp

    r115310 r115838  
    257257}
    258258
     259#if ENABLE(CSS_FILTERS)
     260void LayerTreeHostQt::syncLayerFilters(WebLayerID id, const FilterOperations& filters)
     261{
     262    m_shouldSyncFrame = true;
     263    m_webPage->send(Messages::LayerTreeHostProxy::SetCompositingLayerFilters(id, filters));
     264}
     265#endif
     266
    259267void LayerTreeHostQt::attachLayer(WebGraphicsLayer* layer)
    260268{
  • trunk/Source/WebKit2/WebProcess/WebPage/qt/LayerTreeHostQt.h

    r115310 r115838  
    7777    virtual void syncLayerState(WebLayerID, const WebLayerInfo&);
    7878    virtual void syncLayerChildren(WebLayerID, const Vector<WebLayerID>&);
     79#if ENABLE(CSS_FILTERS)
     80    virtual void syncLayerFilters(WebLayerID, const WebCore::FilterOperations&);
     81#endif
    7982    virtual void attachLayer(WebCore::WebGraphicsLayer*);
    8083    virtual void detachLayer(WebCore::WebGraphicsLayer*);
Note: See TracChangeset for help on using the changeset viewer.