Changeset 116795 in webkit


Ignore:
Timestamp:
May 11, 2012 12:45:39 PM (12 years ago)
Author:
Alexandru Chiculita
Message:

[CSS Shaders] Make CSS Shaders render to texture framebuffers
https://bugs.webkit.org/show_bug.cgi?id=85113

Reviewed by Dean Jackson.

Source/WebCore:

Added the required members to store the framebuffer, the texture and the depth buffer. Also removed the m_drawingBuffer
because context->readPixels doesn't require one anymore.

ReadPixels is not flipping the result, so I've also removed the flipping projection matrix that was specific only to Chromium.

Added a test to check that colors are not switched and the resulting image is not mirrored.

Test: css3/filters/custom/effect-color-check.html

  • platform/graphics/filters/FECustomFilter.cpp:

(WebCore::FECustomFilter::FECustomFilter):
(WebCore::FECustomFilter::~FECustomFilter):
(WebCore):
(WebCore::FECustomFilter::deleteRenderBuffers):
(WebCore::FECustomFilter::platformApplySoftware):
(WebCore::FECustomFilter::initializeContext):
(WebCore::FECustomFilter::resizeContext):
(WebCore::FECustomFilter::bindProgramAndBuffers):

  • platform/graphics/filters/FECustomFilter.h:

(FECustomFilter):

LayoutTests:

Added a test to check that colors are not switched and the resulting image is not mirrored.

  • css3/filters/custom/effect-color-check-expected.png: Added.
  • css3/filters/custom/effect-color-check-expected.txt: Added.
  • css3/filters/custom/effect-color-check.html: Added.
  • css3/filters/resources/color-fill.fs: Added.
  • platform/chromium-linux/css3/filters/custom/custom-filter-shader-cache-expected.png:
  • platform/chromium-linux/css3/filters/custom/effect-custom-combined-missing-expected.png:
  • platform/chromium-linux/css3/filters/custom/effect-custom-expected.png:
  • platform/chromium-mac/css3/filters/custom/effect-color-check-expected.png: Added.
  • platform/chromium/test_expectations.txt:
Location:
trunk
Files:
5 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r116793 r116795  
     12012-05-11  Alexandru Chiculita  <achicu@adobe.com>
     2
     3        [CSS Shaders] Make CSS Shaders render to texture framebuffers
     4        https://bugs.webkit.org/show_bug.cgi?id=85113
     5
     6        Reviewed by Dean Jackson.
     7
     8        Added a test to check that colors are not switched and the resulting image is not mirrored.
     9
     10        * css3/filters/custom/effect-color-check-expected.png: Added.
     11        * css3/filters/custom/effect-color-check-expected.txt: Added.
     12        * css3/filters/custom/effect-color-check.html: Added.
     13        * css3/filters/resources/color-fill.fs: Added.
     14        * platform/chromium-linux/css3/filters/custom/custom-filter-shader-cache-expected.png:
     15        * platform/chromium-linux/css3/filters/custom/effect-custom-combined-missing-expected.png:
     16        * platform/chromium-linux/css3/filters/custom/effect-custom-expected.png:
     17        * platform/chromium-mac/css3/filters/custom/effect-color-check-expected.png: Added.
     18        * platform/chromium/test_expectations.txt:
     19
    1202012-05-11  Thiago Marcos P. Santos  <thiago.santos@intel.com>
    221
  • trunk/LayoutTests/platform/chromium/test_expectations.txt

    r116784 r116795  
    27902790BUGWK84800 SKIP WIN LINUX : css3/filters/custom/filter-repaint-custom-rotated.html = FAIL
    27912791BUGWK84800 SKIP WIN LINUX : css3/filters/custom/filter-repaint-custom.html = FAIL
     2792BUGWK84800 SKIP WIN LINUX : css3/filters/custom/effect-color-check.html = FAIL
    27922793
    27932794// <style scoped> not yet enabled.
  • trunk/Source/WebCore/ChangeLog

    r116794 r116795  
     12012-05-11  Alexandru Chiculita  <achicu@adobe.com>
     2
     3        [CSS Shaders] Make CSS Shaders render to texture framebuffers
     4        https://bugs.webkit.org/show_bug.cgi?id=85113
     5
     6        Reviewed by Dean Jackson.
     7
     8        Added the required members to store the framebuffer, the texture and the depth buffer. Also removed the m_drawingBuffer
     9        because context->readPixels doesn't require one anymore.
     10
     11        ReadPixels is not flipping the result, so I've also removed the flipping projection matrix that was specific only to Chromium.
     12
     13        Added a test to check that colors are not switched and the resulting image is not mirrored.
     14
     15        Test: css3/filters/custom/effect-color-check.html
     16
     17        * platform/graphics/filters/FECustomFilter.cpp:
     18        (WebCore::FECustomFilter::FECustomFilter):
     19        (WebCore::FECustomFilter::~FECustomFilter):
     20        (WebCore):
     21        (WebCore::FECustomFilter::deleteRenderBuffers):
     22        (WebCore::FECustomFilter::platformApplySoftware):
     23        (WebCore::FECustomFilter::initializeContext):
     24        (WebCore::FECustomFilter::resizeContext):
     25        (WebCore::FECustomFilter::bindProgramAndBuffers):
     26        * platform/graphics/filters/FECustomFilter.h:
     27        (FECustomFilter):
     28
    1292012-05-11  Anders Carlsson  <andersca@apple.com>
    230
  • trunk/Source/WebCore/platform/graphics/filters/FECustomFilter.cpp

    r114992 r116795  
    7878    : FilterEffect(filter)
    7979    , m_hostWindow(hostWindow)
     80    , m_frameBuffer(0)
     81    , m_depthBuffer(0)
     82    , m_destTexture(0)
    8083    , m_program(program)
    8184    , m_parameters(parameters)
     
    9497}
    9598
     99FECustomFilter::~FECustomFilter()
     100{
     101    deleteRenderBuffers();
     102}
     103
     104void FECustomFilter::deleteRenderBuffers()
     105{
     106    if (m_frameBuffer) {
     107        m_context->deleteFramebuffer(m_frameBuffer);
     108        m_frameBuffer = 0;
     109    }
     110    if (m_depthBuffer) {
     111        m_context->deleteRenderbuffer(m_depthBuffer);
     112        m_depthBuffer = 0;
     113    }
     114    if (m_destTexture) {
     115        m_context->deleteTexture(m_destTexture);
     116        m_destTexture = 0;
     117    }
     118}
     119
    96120void FECustomFilter::platformApplySoftware()
    97121{
     
    107131    bool hadContext = m_context;
    108132    if (!m_context)
    109         initializeContext(newContextSize);
     133        initializeContext();
    110134   
    111135    if (!hadContext || m_contextSize != newContextSize)
    112136        resizeContext(newContextSize);
    113    
     137
    114138    // Do not draw the filter if the input image cannot fit inside a single GPU texture.
    115139    if (m_inputTexture->tiles().numTilesX() != 1 || m_inputTexture->tiles().numTilesY() != 1)
     
    119143    if (!m_shader->isInitialized())
    120144        return;
     145
     146    m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_frameBuffer);
     147    m_context->viewport(0, 0, newContextSize.width(), newContextSize.height());
    121148   
    122149    m_context->clearColor(0, 0, 0, 0);
     
    127154    m_context->drawElements(GraphicsContext3D::TRIANGLES, m_mesh->indicesCount(), GraphicsContext3D::UNSIGNED_SHORT, 0);
    128155   
    129     m_drawingBuffer->commit();
    130 
    131     RefPtr<ImageData> imageData = m_context->paintRenderingResultsToImageData(m_drawingBuffer.get());
    132     Uint8ClampedArray* gpuResult = imageData->data();
    133     ASSERT(gpuResult->length() == dstPixelArray->length());
    134     memcpy(dstPixelArray->data(), gpuResult->data(), gpuResult->length());
    135 }
    136 
    137 void FECustomFilter::initializeContext(const IntSize& contextSize)
     156    ASSERT(static_cast<size_t>(newContextSize.width() * newContextSize.height() * 4) == dstPixelArray->length());
     157    m_context->readPixels(0, 0, newContextSize.width(), newContextSize.height(), GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, dstPixelArray->data());
     158}
     159
     160void FECustomFilter::initializeContext()
    138161{
    139162    GraphicsContext3D::Attributes attributes;
     
    143166    ASSERT(!m_context.get());
    144167    m_context = GraphicsContext3D::create(attributes, m_hostWindow, GraphicsContext3D::RenderOffscreen);
    145     m_drawingBuffer = DrawingBuffer::create(m_context.get(), contextSize, DrawingBuffer::Discard, DrawingBuffer::Alpha);
     168    m_context->enable(GraphicsContext3D::DEPTH_TEST);
    146169   
    147170    m_shader = m_program->createShaderWithContext(m_context.get());
     
    153176void FECustomFilter::resizeContext(const IntSize& newContextSize)
    154177{
    155     m_inputTexture = 0;
    156     m_drawingBuffer->reset(newContextSize);
    157     m_context->reshape(newContextSize.width(), newContextSize.height());
    158     m_context->viewport(0, 0, newContextSize.width(), newContextSize.height());
    159178    m_inputTexture = Texture::create(m_context.get(), Texture::RGBA8, newContextSize.width(), newContextSize.height());
     179   
     180    if (!m_frameBuffer)
     181        m_frameBuffer = m_context->createFramebuffer();
     182    if (!m_depthBuffer)
     183        m_depthBuffer = m_context->createRenderbuffer();
     184    if (!m_destTexture) {
     185        m_destTexture = m_context->createTexture();
     186        m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_destTexture);
     187        m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR);
     188        m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR);
     189        m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE);
     190        m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE);
     191    }
     192   
     193    m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_destTexture);
     194    m_context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, newContextSize.width(), newContextSize.height(), 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE);
     195
     196    m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_frameBuffer);
     197    m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_destTexture, 0);
     198   
     199    m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_depthBuffer);
     200    m_context->renderbufferStorage(GraphicsContext3D::RENDERBUFFER, GraphicsContext3D::DEPTH_COMPONENT16, newContextSize.width(), newContextSize.height());
     201    m_context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::DEPTH_ATTACHMENT, GraphicsContext3D::RENDERBUFFER, m_depthBuffer);
     202   
    160203    m_contextSize = newContextSize;
    161204}
     
    223266    if (m_shader->projectionMatrixLocation() != -1) {
    224267        TransformationMatrix projectionMatrix;
    225 #if PLATFORM(CHROMIUM)
    226         // We flip-y the projection matrix here because Chromium will flip-y the resulting image for us.
    227         orthogonalProjectionMatrix(projectionMatrix, -0.5, 0.5, 0.5, -0.5);
    228 #else
    229268        orthogonalProjectionMatrix(projectionMatrix, -0.5, 0.5, -0.5, 0.5);
    230 #endif
    231269        float glProjectionMatrix[16];
    232270        projectionMatrix.toColumnMajorFloatArray(glProjectionMatrix);
  • trunk/Source/WebCore/platform/graphics/filters/FECustomFilter.h

    r114992 r116795  
    3636#include "Filter.h"
    3737#include "FilterEffect.h"
     38#include "GraphicsTypes3D.h"
    3839#include <wtf/RefPtr.h>
    3940
     
    7071                   unsigned meshRows, unsigned meshColumns, CustomFilterOperation::MeshBoxType,
    7172                   CustomFilterOperation::MeshType);
     73    ~FECustomFilter();
    7274   
    73     void initializeContext(const IntSize& contextSize);
     75    void initializeContext();
     76    void deleteRenderBuffers();
    7477    void resizeContext(const IntSize& newContextSize);
    7578    void bindVertexAttribute(int attributeLocation, unsigned size, unsigned& offset);
     
    8184   
    8285    RefPtr<GraphicsContext3D> m_context;
    83     RefPtr<DrawingBuffer> m_drawingBuffer;
    8486    RefPtr<Texture> m_inputTexture;
    8587    RefPtr<CustomFilterShader> m_shader;
    8688    RefPtr<CustomFilterMesh> m_mesh;
    8789    IntSize m_contextSize;
     90
     91    Platform3DObject m_frameBuffer;
     92    Platform3DObject m_depthBuffer;
     93    Platform3DObject m_destTexture;
    8894
    8995    RefPtr<CustomFilterProgram> m_program;
Note: See TracChangeset for help on using the changeset viewer.