Changeset 106607 in webkit


Ignore:
Timestamp:
Feb 2, 2012 5:35:29 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Refactor plugin drawing to be more data driven
https://bugs.webkit.org/show_bug.cgi?id=76715

Patch by Tim Dresser <tdresser@chromium.org> on 2012-02-02
Reviewed by James Robinson.

CCPluginLayerImpl no longer handles drawing itself, but produces a list of CCPluginDrawQuads.
These quads are then drawn by LayerRendererChromium.

CCLayerImpl::willDraw(LayerRendererChromium*) is called directly before appendQuads.
This allows for CCLayerImpl objects to allocate textures before appendQuads is called.

This is a refactor, so no new tests were added.
Flash was tested manually on Linux and Mac.

  • platform/graphics/chromium/LayerRendererChromium.cpp:

(WebCore::PluginProgramBinding::set):
(PluginProgramBinding):
(WebCore):
(WebCore::TexStretchPluginProgramBinding::set):
(TexStretchPluginProgramBinding):
(WebCore::TexTransformPluginProgramBinding::set):
(TexTransformPluginProgramBinding):
(WebCore::LayerRendererChromium::drawPluginQuad):

  • platform/graphics/chromium/cc/CCLayerImpl.h:

(WebCore::CCLayerImpl::willDraw):

  • platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:

(WebCore::CCLayerTreeHostImpl::calculateRenderPasses):

  • platform/graphics/chromium/cc/CCPluginDrawQuad.cpp:

(WebCore::CCPluginDrawQuad::create):
(WebCore::CCPluginDrawQuad::CCPluginDrawQuad):

  • platform/graphics/chromium/cc/CCPluginDrawQuad.h:

(CCPluginDrawQuad):
(WebCore::CCPluginDrawQuad::uvRect):
(WebCore::CCPluginDrawQuad::textureId):
(WebCore::CCPluginDrawQuad::flipped):
(WebCore::CCPluginDrawQuad::ioSurfaceWidth):
(WebCore::CCPluginDrawQuad::ioSurfaceHeight):
(WebCore::CCPluginDrawQuad::ioSurfaceTextureId):

  • platform/graphics/chromium/cc/CCPluginLayerImpl.cpp:

(WebCore::CCPluginLayerImpl::willDraw):
(WebCore::CCPluginLayerImpl::appendQuads):

  • platform/graphics/chromium/cc/CCPluginLayerImpl.h:

(CCPluginLayerImpl):

Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r106605 r106607  
     12012-02-02  Tim Dresser  <tdresser@chromium.org>
     2
     3        Refactor plugin drawing to be more data driven
     4        https://bugs.webkit.org/show_bug.cgi?id=76715
     5
     6        Reviewed by James Robinson.
     7
     8        CCPluginLayerImpl no longer handles drawing itself, but produces a list of CCPluginDrawQuads.
     9        These quads are then drawn by LayerRendererChromium.
     10
     11        CCLayerImpl::willDraw(LayerRendererChromium*) is called directly before appendQuads.
     12        This allows for CCLayerImpl objects to allocate textures before appendQuads is called.
     13
     14        This is a refactor, so no new tests were added.
     15        Flash was tested manually on Linux and Mac.
     16
     17        * platform/graphics/chromium/LayerRendererChromium.cpp:
     18        (WebCore::PluginProgramBinding::set):
     19        (PluginProgramBinding):
     20        (WebCore):
     21        (WebCore::TexStretchPluginProgramBinding::set):
     22        (TexStretchPluginProgramBinding):
     23        (WebCore::TexTransformPluginProgramBinding::set):
     24        (TexTransformPluginProgramBinding):
     25        (WebCore::LayerRendererChromium::drawPluginQuad):
     26        * platform/graphics/chromium/cc/CCLayerImpl.h:
     27        (WebCore::CCLayerImpl::willDraw):
     28        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
     29        (WebCore::CCLayerTreeHostImpl::calculateRenderPasses):
     30        * platform/graphics/chromium/cc/CCPluginDrawQuad.cpp:
     31        (WebCore::CCPluginDrawQuad::create):
     32        (WebCore::CCPluginDrawQuad::CCPluginDrawQuad):
     33        * platform/graphics/chromium/cc/CCPluginDrawQuad.h:
     34        (CCPluginDrawQuad):
     35        (WebCore::CCPluginDrawQuad::uvRect):
     36        (WebCore::CCPluginDrawQuad::textureId):
     37        (WebCore::CCPluginDrawQuad::flipped):
     38        (WebCore::CCPluginDrawQuad::ioSurfaceWidth):
     39        (WebCore::CCPluginDrawQuad::ioSurfaceHeight):
     40        (WebCore::CCPluginDrawQuad::ioSurfaceTextureId):
     41        * platform/graphics/chromium/cc/CCPluginLayerImpl.cpp:
     42        (WebCore::CCPluginLayerImpl::willDraw):
     43        (WebCore::CCPluginLayerImpl::appendQuads):
     44        * platform/graphics/chromium/cc/CCPluginLayerImpl.h:
     45        (CCPluginLayerImpl):
     46
    1472012-01-29  Pablo Flouret  <pablof@motorola.com>
    248
  • trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp

    r106601 r106607  
    698698}
    699699
     700struct PluginProgramBinding {
     701    template<class Program> void set(Program* program)
     702    {
     703        ASSERT(program && program->initialized());
     704        programId = program->program();
     705        samplerLocation = program->fragmentShader().samplerLocation();
     706        matrixLocation = program->vertexShader().matrixLocation();
     707        alphaLocation = program->fragmentShader().alphaLocation();
     708    }
     709    int programId;
     710    int samplerLocation;
     711    int matrixLocation;
     712    int alphaLocation;
     713};
     714
     715struct TexStretchPluginProgramBinding : PluginProgramBinding {
     716    template<class Program> void set(Program* program)
     717    {
     718        PluginProgramBinding::set(program);
     719        offsetLocation = program->vertexShader().offsetLocation();
     720        scaleLocation = program->vertexShader().scaleLocation();
     721    }
     722    int offsetLocation;
     723    int scaleLocation;
     724};
     725
     726struct TexTransformPluginProgramBinding : PluginProgramBinding {
     727    template<class Program> void set(Program* program)
     728    {
     729        PluginProgramBinding::set(program);
     730        texTransformLocation = program->vertexShader().texTransformLocation();
     731    }
     732    int texTransformLocation;
     733};
     734
    700735void LayerRendererChromium::drawPluginQuad(const CCPluginDrawQuad* quad)
    701736{
    702     CCLayerImpl* layer = quad->layer();
    703     layer->draw(this);
     737    ASSERT(CCProxy::isImplThread());
     738
     739    if (quad->ioSurfaceTextureId()) {
     740        TexTransformPluginProgramBinding binding;
     741        if (quad->flipped())
     742            binding.set(pluginLayerTexRectProgramFlip());
     743        else
     744            binding.set(pluginLayerTexRectProgram());
     745
     746        GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE0));
     747        GLC(context(), context()->bindTexture(Extensions3D::TEXTURE_RECTANGLE_ARB, quad->ioSurfaceTextureId()));
     748
     749        GLC(context(), context()->useProgram(binding.programId));
     750        GLC(context(), context()->uniform1i(binding.samplerLocation, 0));
     751        // Note: this code path ignores quad->uvRect().
     752        GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0, quad->ioSurfaceWidth(), quad->ioSurfaceHeight()));
     753        const IntSize& bounds = quad->quadRect().size();
     754        drawTexturedQuad(quad->layerTransform(), bounds.width(), bounds.height(), quad->opacity(), sharedGeometryQuad(),
     755                                        binding.matrixLocation,
     756                                        binding.alphaLocation,
     757                                        -1);
     758        GLC(context(), context()->bindTexture(Extensions3D::TEXTURE_RECTANGLE_ARB, 0));
     759    } else {
     760        TexStretchPluginProgramBinding binding;
     761        if (quad->flipped())
     762            binding.set(pluginLayerProgramFlip());
     763        else
     764            binding.set(pluginLayerProgram());
     765
     766        GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE0));
     767        GLC(context(), context()->bindTexture(GraphicsContext3D::TEXTURE_2D, quad->textureId()));
     768
     769        // FIXME: setting the texture parameters every time is redundant. Move this code somewhere
     770        // where it will only happen once per texture.
     771        GLC(context, context()->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR));
     772        GLC(context, context()->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR));
     773        GLC(context, context()->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE));
     774        GLC(context, context()->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE));
     775
     776        GLC(context, context()->useProgram(binding.programId));
     777        GLC(context, context()->uniform1i(binding.samplerLocation, 0));
     778        GLC(context, context()->uniform2f(binding.offsetLocation, quad->uvRect().x(), quad->uvRect().y()));
     779        GLC(context, context()->uniform2f(binding.scaleLocation, quad->uvRect().width(), quad->uvRect().height()));
     780        const IntSize& bounds = quad->quadRect().size();
     781        drawTexturedQuad(quad->layerTransform(), bounds.width(), bounds.height(), quad->opacity(), sharedGeometryQuad(),
     782                                        binding.matrixLocation,
     783                                        binding.alphaLocation,
     784                                        -1);
     785    }
    704786}
    705787
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.h

    r105470 r106607  
    7373
    7474    PassOwnPtr<CCSharedQuadState> createSharedQuadState() const;
     75    virtual void willDraw(LayerRendererChromium*) { }
    7576    virtual void appendQuads(CCQuadList&, const CCSharedQuadState*);
    7677    void appendDebugBorderQuad(CCQuadList&, const CCSharedQuadState*) const;
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp

    r106306 r106607  
    232232            }
    233233
     234            layer->willDraw(m_layerRenderer.get());
    234235            pass->appendQuadsForLayer(layer);
    235236        }
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCPluginDrawQuad.cpp

    r105311 r106607  
    3030namespace WebCore {
    3131
    32 PassOwnPtr<CCPluginDrawQuad> CCPluginDrawQuad::create(const CCSharedQuadState* sharedQuadState, const IntRect& quadRect, CCLayerImpl* layer)
     32PassOwnPtr<CCPluginDrawQuad> CCPluginDrawQuad::create(const CCSharedQuadState* sharedQuadState, const IntRect& quadRect, const FloatRect& uvRect, unsigned textureId, bool flipped, int ioSurfaceWidth, int ioSurfaceHeight, unsigned ioSurfaceTextureId)
    3333{
    34     return adoptPtr(new CCPluginDrawQuad(sharedQuadState, quadRect, layer));
     34    return adoptPtr(new CCPluginDrawQuad(sharedQuadState, quadRect, uvRect, textureId, flipped, ioSurfaceWidth, ioSurfaceHeight, ioSurfaceTextureId));
    3535}
    3636
    37 CCPluginDrawQuad::CCPluginDrawQuad(const CCSharedQuadState* sharedQuadState, const IntRect& quadRect, CCLayerImpl* layer)
     37CCPluginDrawQuad::CCPluginDrawQuad(const CCSharedQuadState* sharedQuadState, const IntRect& quadRect, const FloatRect& uvRect, unsigned textureId, bool flipped, int ioSurfaceWidth, int ioSurfaceHeight, unsigned ioSurfaceTextureId)
    3838    : CCDrawQuad(sharedQuadState, CCDrawQuad::PluginContent, quadRect)
    39     , m_layer(layer)
     39    , m_uvRect(uvRect)
     40    , m_textureId(textureId)
     41    , m_flipped(flipped)
     42    , m_ioSurfaceWidth(ioSurfaceWidth)
     43    , m_ioSurfaceHeight(ioSurfaceHeight)
     44    , m_ioSurfaceTextureId(ioSurfaceTextureId)
    4045{
    41     ASSERT(m_layer);
    4246}
    4347
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCPluginDrawQuad.h

    r105311 r106607  
    3737    WTF_MAKE_NONCOPYABLE(CCPluginDrawQuad);
    3838public:
    39     static PassOwnPtr<CCPluginDrawQuad> create(const CCSharedQuadState*, const IntRect&, CCLayerImpl*);
     39    static PassOwnPtr<CCPluginDrawQuad> create(const CCSharedQuadState*, const IntRect& quadRect, const FloatRect& uvRect, unsigned textureId, bool flipped, int ioSurfaceWidth, int ioSurfaceHeight, unsigned m_ioSurfaceTextureId);
    4040
    41     CCLayerImpl* layer() const { return m_layer; }
     41    FloatRect uvRect() const { return m_uvRect; }
     42    unsigned textureId() const { return m_textureId; }
     43    bool flipped() const { return m_flipped; }
     44    int ioSurfaceWidth() const { return m_ioSurfaceWidth; }
     45    int ioSurfaceHeight() const { return m_ioSurfaceHeight; }
    4246
     47    unsigned ioSurfaceTextureId() const { return m_ioSurfaceTextureId; }
     48   
    4349private:
    44     CCPluginDrawQuad(const CCSharedQuadState*, const IntRect&, CCLayerImpl*);
     50    CCPluginDrawQuad(const CCSharedQuadState*, const IntRect& quadRect, const FloatRect& uvRect, unsigned textureId, bool flipped, int ioSurfaceWidth, int ioSurfaceHeight, unsigned ioSurfaceTextureId);
    4551
    46     CCLayerImpl* m_layer;
     52    FloatRect m_uvRect;
     53    unsigned m_textureId;
     54    bool m_flipped;
     55    int m_ioSurfaceWidth;
     56    int m_ioSurfaceHeight;
     57    unsigned m_ioSurfaceTextureId;
    4758};
    4859
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCPluginLayerImpl.cpp

    r105311 r106607  
    3737#include <wtf/text/WTFString.h>
    3838
    39 namespace {
    40 
    41 struct PluginProgramBinding {
    42     template<class Program> void set(Program* program)
    43     {
    44         ASSERT(program && program->initialized());
    45         programId = program->program();
    46         samplerLocation = program->fragmentShader().samplerLocation();
    47         matrixLocation = program->vertexShader().matrixLocation();
    48         alphaLocation = program->fragmentShader().alphaLocation();
    49     }
    50     int programId;
    51     int samplerLocation;
    52     int matrixLocation;
    53     int alphaLocation;
    54 };
    55 
    56 struct TexStretchPluginProgramBinding : PluginProgramBinding {
    57     template<class Program> void set(Program* program)
    58     {
    59         PluginProgramBinding::set(program);
    60         offsetLocation = program->vertexShader().offsetLocation();
    61         scaleLocation = program->vertexShader().scaleLocation();
    62     }
    63     int offsetLocation;
    64     int scaleLocation;
    65 };
    66 
    67 struct TexTransformPluginProgramBinding : PluginProgramBinding {
    68     template<class Program> void set(Program* program)
    69     {
    70         PluginProgramBinding::set(program);
    71         texTransformLocation = program->vertexShader().texTransformLocation();
    72     }
    73     int texTransformLocation;
    74 };
    75 
    76 } // anonymous namespace
    77 
    7839namespace WebCore {
    7940
     
    9657}
    9758
    98 void CCPluginLayerImpl::draw(LayerRendererChromium* layerRenderer)
     59void CCPluginLayerImpl::willDraw(LayerRendererChromium* layerRenderer)
    9960{
    100     ASSERT(CCProxy::isImplThread());
    101 
    10261    if (m_ioSurfaceChanged) {
    10362        GraphicsContext3D* context = layerRenderer->context();
     
    12887        m_ioSurfaceChanged = false;
    12988    }
    130 
    131     if (m_ioSurfaceTextureId) {
    132         TexTransformPluginProgramBinding binding;
    133         if (m_flipped)
    134             binding.set(layerRenderer->pluginLayerTexRectProgramFlip());
    135         else
    136             binding.set(layerRenderer->pluginLayerTexRectProgram());
    137 
    138         GraphicsContext3D* context = layerRenderer->context();
    139         GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0));
    140         GLC(context, context->bindTexture(Extensions3D::TEXTURE_RECTANGLE_ARB, m_ioSurfaceTextureId));
    141 
    142         GLC(context, context->useProgram(binding.programId));
    143         GLC(context, context->uniform1i(binding.samplerLocation, 0));
    144         // Note: this code path ignores m_uvRect.
    145         GLC(context, context->uniform4f(binding.texTransformLocation, 0, 0, m_ioSurfaceWidth, m_ioSurfaceHeight));
    146         layerRenderer->drawTexturedQuad(drawTransform(), bounds().width(), bounds().height(), drawOpacity(), layerRenderer->sharedGeometryQuad(),
    147                                         binding.matrixLocation,
    148                                         binding.alphaLocation,
    149                                         -1);
    150         GLC(context, context->bindTexture(Extensions3D::TEXTURE_RECTANGLE_ARB, 0));
    151     } else {
    152         TexStretchPluginProgramBinding binding;
    153         if (m_flipped)
    154             binding.set(layerRenderer->pluginLayerProgramFlip());
    155         else
    156             binding.set(layerRenderer->pluginLayerProgram());
    157 
    158         GraphicsContext3D* context = layerRenderer->context();
    159         GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0));
    160         GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId));
    161 
    162         // FIXME: setting the texture parameters every time is redundant. Move this code somewhere
    163         // where it will only happen once per texture.
    164         GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR));
    165         GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR));
    166         GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE));
    167         GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE));
    168 
    169         GLC(context, context->useProgram(binding.programId));
    170         GLC(context, context->uniform1i(binding.samplerLocation, 0));
    171         GLC(context, context->uniform2f(binding.offsetLocation, m_uvRect.x(), m_uvRect.y()));
    172         GLC(context, context->uniform2f(binding.scaleLocation, m_uvRect.width(), m_uvRect.height()));
    173         layerRenderer->drawTexturedQuad(drawTransform(), bounds().width(), bounds().height(), drawOpacity(), layerRenderer->sharedGeometryQuad(),
    174                                         binding.matrixLocation,
    175                                         binding.alphaLocation,
    176                                         -1);
    177     }
    17889}
    17990
     
    18192{
    18293    IntRect quadRect(IntPoint(), bounds());
    183     quadList.append(CCPluginDrawQuad::create(sharedQuadState, quadRect, this));
     94    quadList.append(CCPluginDrawQuad::create(sharedQuadState, quadRect, m_uvRect, m_textureId, m_flipped, m_ioSurfaceWidth, m_ioSurfaceHeight, m_ioSurfaceTextureId));
    18495}
    18596
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCPluginLayerImpl.h

    r105311 r106607  
    4242    virtual ~CCPluginLayerImpl();
    4343
     44    virtual void willDraw(LayerRendererChromium*);
    4445    virtual void appendQuads(CCQuadList&, const CCSharedQuadState*);
    4546
     
    4849    typedef ProgramBinding<VertexShaderPosTexTransform, FragmentShaderRGBATexRectAlpha> TexRectProgram;
    4950    typedef ProgramBinding<VertexShaderPosTexTransform, FragmentShaderRGBATexRectFlipAlpha> TexRectProgramFlip;
    50 
    51     virtual void draw(LayerRendererChromium*);
    5251
    5352    virtual void dumpLayerProperties(TextStream&, int indent) const;
Note: See TracChangeset for help on using the changeset viewer.