[chromium] Move non-GL-specific code out of LayerRendererChromium
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Aug 2012 19:15:44 +0000 (19:15 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Aug 2012 19:15:44 +0000 (19:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=93927

Patch by Alexandre Elias <aelias@google.com> on 2012-08-20
Reviewed by Adrienne Walker.

This patch moves most of the generic logic dealing with matrices and
render passes into a new class "CCDirectRenderer" that sits between
CCRenderer and LayerRendererChromium, and also publicly exposes a
few other things like the UnthrottledTextureUploader.

The plan is for the future software compositing implementation to also
derive from CCDirectRenderer, whereas the ubercompositor delegating
renderer will still derive from CCRenderer.

No new tests (no-op refactoring).

* WebCore.gypi:
* platform/graphics/chromium/GeometryBinding.cpp:
(WebCore::GeometryBinding::GeometryBinding):
* platform/graphics/chromium/GeometryBinding.h:
(GeometryBinding):
* platform/graphics/chromium/LayerRendererChromium.cpp:
(WebCore::LayerRendererChromium::LayerRendererChromium):
(WebCore::LayerRendererChromium::beginDrawingFrame):
(WebCore::LayerRendererChromium::drawQuad):
(WebCore::LayerRendererChromium::drawRenderPassQuad):
(WebCore::LayerRendererChromium::drawTileQuad):
(WebCore::LayerRendererChromium::finishDrawingFrame):
(WebCore::LayerRendererChromium::drawQuadGeometry):
(WebCore::LayerRendererChromium::bindFramebufferToOutputSurface):
(WebCore):
(WebCore::LayerRendererChromium::bindFramebufferToTexture):
(WebCore::LayerRendererChromium::enableScissorTestRect):
(WebCore::LayerRendererChromium::disableScissorTest):
(WebCore::LayerRendererChromium::setDrawViewportSize):
(WebCore::LayerRendererChromium::makeContextCurrent):
(WebCore::LayerRendererChromium::initializeSharedObjects):
* platform/graphics/chromium/LayerRendererChromium.h:
(LayerRendererChromium):
* platform/graphics/chromium/TextureCopier.h:
(TextureCopier):
* platform/graphics/chromium/TextureUploader.h:
(UnthrottledTextureUploader):
(WebCore::UnthrottledTextureUploader::create):
(WebCore::UnthrottledTextureUploader::~UnthrottledTextureUploader):
(WebCore::UnthrottledTextureUploader::UnthrottledTextureUploader):
(WebCore):
* platform/graphics/chromium/cc/CCDirectRenderer.cpp: Added.
(projectionMatrix):
(canvasMatrix):
(WebCore):
(WebCore::CCDirectRenderer::DrawingFrame::initializeMatrices):
(WebCore::CCDirectRenderer::DrawingFrame::initializeScissors):
(WebCore::CCDirectRenderer::decideRenderPassAllocationsForFrame):
(WebCore::CCDirectRenderer::drawFrame):
(WebCore::CCDirectRenderer::drawRenderPass):
(WebCore::CCDirectRenderer::useRenderPass):
(WebCore::CCDirectRenderer::haveCachedResourcesForRenderPassId):
(WebCore::CCDirectRenderer::renderPassTextureSize):
(WebCore::CCDirectRenderer::renderPassTextureFormat):
* platform/graphics/chromium/cc/CCDirectRenderer.h: Added.
(WebCore):
(CCDirectRenderer):
(WebCore::CCDirectRenderer::~CCDirectRenderer):
(WebCore::CCDirectRenderer::resourceProvider):
(WebCore::CCDirectRenderer::CCDirectRenderer):
(DrawingFrame):
(WebCore::CCDirectRenderer::DrawingFrame::DrawingFrame):
(CachedTexture):
(WebCore::CCDirectRenderer::CachedTexture::create):
(WebCore::CCDirectRenderer::CachedTexture::~CachedTexture):
(WebCore::CCDirectRenderer::CachedTexture::isComplete):
(WebCore::CCDirectRenderer::CachedTexture::setIsComplete):
(WebCore::CCDirectRenderer::CachedTexture::CachedTexture):
(WebCore::CCDirectRenderer::quadVertexRect):
(WebCore::CCDirectRenderer::quadRectTransform):

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

Source/WebCore/ChangeLog
Source/WebCore/WebCore.gypi
Source/WebCore/platform/graphics/chromium/GeometryBinding.cpp
Source/WebCore/platform/graphics/chromium/GeometryBinding.h
Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp
Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h
Source/WebCore/platform/graphics/chromium/TextureCopier.h
Source/WebCore/platform/graphics/chromium/UnthrottledTextureUploader.h [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/cc/CCDirectRenderer.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/cc/CCDirectRenderer.h [new file with mode: 0644]

index 39eea8a..ce717ea 100644 (file)
@@ -1,3 +1,82 @@
+2012-08-20  Alexandre Elias  <aelias@google.com>
+
+        [chromium] Move non-GL-specific code out of LayerRendererChromium
+        https://bugs.webkit.org/show_bug.cgi?id=93927
+
+        Reviewed by Adrienne Walker.
+
+        This patch moves most of the generic logic dealing with matrices and
+        render passes into a new class "CCDirectRenderer" that sits between
+        CCRenderer and LayerRendererChromium, and also publicly exposes a
+        few other things like the UnthrottledTextureUploader.
+
+        The plan is for the future software compositing implementation to also
+        derive from CCDirectRenderer, whereas the ubercompositor delegating
+        renderer will still derive from CCRenderer.
+
+        No new tests (no-op refactoring).
+
+        * WebCore.gypi:
+        * platform/graphics/chromium/GeometryBinding.cpp:
+        (WebCore::GeometryBinding::GeometryBinding):
+        * platform/graphics/chromium/GeometryBinding.h:
+        (GeometryBinding):
+        * platform/graphics/chromium/LayerRendererChromium.cpp:
+        (WebCore::LayerRendererChromium::LayerRendererChromium):
+        (WebCore::LayerRendererChromium::beginDrawingFrame):
+        (WebCore::LayerRendererChromium::drawQuad):
+        (WebCore::LayerRendererChromium::drawRenderPassQuad):
+        (WebCore::LayerRendererChromium::drawTileQuad):
+        (WebCore::LayerRendererChromium::finishDrawingFrame):
+        (WebCore::LayerRendererChromium::drawQuadGeometry):
+        (WebCore::LayerRendererChromium::bindFramebufferToOutputSurface):
+        (WebCore):
+        (WebCore::LayerRendererChromium::bindFramebufferToTexture):
+        (WebCore::LayerRendererChromium::enableScissorTestRect):
+        (WebCore::LayerRendererChromium::disableScissorTest):
+        (WebCore::LayerRendererChromium::setDrawViewportSize):
+        (WebCore::LayerRendererChromium::makeContextCurrent):
+        (WebCore::LayerRendererChromium::initializeSharedObjects):
+        * platform/graphics/chromium/LayerRendererChromium.h:
+        (LayerRendererChromium):
+        * platform/graphics/chromium/TextureCopier.h:
+        (TextureCopier):
+        * platform/graphics/chromium/TextureUploader.h:
+        (UnthrottledTextureUploader):
+        (WebCore::UnthrottledTextureUploader::create):
+        (WebCore::UnthrottledTextureUploader::~UnthrottledTextureUploader):
+        (WebCore::UnthrottledTextureUploader::UnthrottledTextureUploader):
+        (WebCore):
+        * platform/graphics/chromium/cc/CCDirectRenderer.cpp: Added.
+        (projectionMatrix):
+        (canvasMatrix):
+        (WebCore):
+        (WebCore::CCDirectRenderer::DrawingFrame::initializeMatrices):
+        (WebCore::CCDirectRenderer::DrawingFrame::initializeScissors):
+        (WebCore::CCDirectRenderer::decideRenderPassAllocationsForFrame):
+        (WebCore::CCDirectRenderer::drawFrame):
+        (WebCore::CCDirectRenderer::drawRenderPass):
+        (WebCore::CCDirectRenderer::useRenderPass):
+        (WebCore::CCDirectRenderer::haveCachedResourcesForRenderPassId):
+        (WebCore::CCDirectRenderer::renderPassTextureSize):
+        (WebCore::CCDirectRenderer::renderPassTextureFormat):
+        * platform/graphics/chromium/cc/CCDirectRenderer.h: Added.
+        (WebCore):
+        (CCDirectRenderer):
+        (WebCore::CCDirectRenderer::~CCDirectRenderer):
+        (WebCore::CCDirectRenderer::resourceProvider):
+        (WebCore::CCDirectRenderer::CCDirectRenderer):
+        (DrawingFrame):
+        (WebCore::CCDirectRenderer::DrawingFrame::DrawingFrame):
+        (CachedTexture):
+        (WebCore::CCDirectRenderer::CachedTexture::create):
+        (WebCore::CCDirectRenderer::CachedTexture::~CachedTexture):
+        (WebCore::CCDirectRenderer::CachedTexture::isComplete):
+        (WebCore::CCDirectRenderer::CachedTexture::setIsComplete):
+        (WebCore::CCDirectRenderer::CachedTexture::CachedTexture):
+        (WebCore::CCDirectRenderer::quadVertexRect):
+        (WebCore::CCDirectRenderer::quadRectTransform):
+
 2012-08-20  Julien Chaffraix  <jchaffraix@webkit.org>
 
         Introduce a will-be-removed-from-tree notification in RenderObject
index 5b26928..96c676d 100644 (file)
             'platform/graphics/chromium/TiledLayerChromium.h',
             'platform/graphics/chromium/TreeSynchronizer.cpp',
             'platform/graphics/chromium/TreeSynchronizer.h',
+            'platform/graphics/chromium/UnthrottledTextureUploader.h',
             'platform/graphics/chromium/VideoLayerChromium.cpp',
             'platform/graphics/chromium/VideoLayerChromium.h',
             'platform/graphics/chromium/cc/CCActiveAnimation.cpp',
             'platform/graphics/chromium/cc/CCDebugRectHistory.h',
             'platform/graphics/chromium/cc/CCDelayBasedTimeSource.cpp',
             'platform/graphics/chromium/cc/CCDelayBasedTimeSource.h',
+            'platform/graphics/chromium/cc/CCDirectRenderer.h',
+            'platform/graphics/chromium/cc/CCDirectRenderer.cpp',
             'platform/graphics/chromium/cc/CCDrawQuad.cpp',
             'platform/graphics/chromium/cc/CCDrawQuad.h',
             'platform/graphics/chromium/cc/CCFontAtlas.cpp',
             'platform/graphics/chromium/cc/CCQuadSink.h',
             'platform/graphics/chromium/cc/CCQuadCuller.cpp',
             'platform/graphics/chromium/cc/CCQuadCuller.h',
+            'platform/graphics/chromium/cc/CCRenderer.h',
             'platform/graphics/chromium/cc/CCRenderPass.cpp',
             'platform/graphics/chromium/cc/CCRenderPass.h',
             'platform/graphics/chromium/cc/CCRenderPassDrawQuad.cpp',
index 1a4568b..67ab462 100644 (file)
 
 namespace WebCore {
 
-GeometryBinding::GeometryBinding(WebKit::WebGraphicsContext3D* context)
+GeometryBinding::GeometryBinding(WebKit::WebGraphicsContext3D* context, const FloatRect& quadVertexRect)
     : m_context(context)
     , m_quadVerticesVbo(0)
     , m_quadElementsVbo(0)
     , m_initialized(false)
 {
     // Vertex positions and texture coordinates for the 4 corners of a 1x1 quad.
-    float vertices[] = { -0.5f,  0.5f, 0.0f, 0.0f,  1.0f,
-                         -0.5f, -0.5f, 0.0f, 0.0f,  0.0f,
-                         0.5f, -0.5f, 0.0f, 1.0f,  0.0f,
-                         0.5f,  0.5f, 0.0f, 1.0f,  1.0f };
+    float vertices[] = { quadVertexRect.x(), quadVertexRect.maxY(), 0.0f, 0.0f,  1.0f,
+                         quadVertexRect.x(), quadVertexRect.y(), 0.0f, 0.0f,  0.0f,
+                         quadVertexRect.maxX(), quadVertexRect.y(), 0.0f, 1.0f,  0.0f,
+                         quadVertexRect.maxX(),  quadVertexRect.maxY(), 0.0f, 1.0f,  1.0f };
     uint16_t indices[] = { 0, 1, 2, 0, 2, 3, // The two triangles that make up the layer quad.
                            0, 1, 2, 3}; // A line path for drawing the layer border.
 
index 20b2d5a..0af146c 100644 (file)
@@ -26,6 +26,8 @@
 #ifndef GeometryBinding_h
 #define GeometryBinding_h
 
+#include "FloatRect.h"
+
 #if USE(ACCELERATED_COMPOSITING)
 
 namespace WebKit {
@@ -36,7 +38,7 @@ namespace WebCore {
 
 class GeometryBinding {
 public:
-    explicit GeometryBinding(WebKit::WebGraphicsContext3D*);
+    GeometryBinding(WebKit::WebGraphicsContext3D*, const FloatRect& quadVertexRect);
     ~GeometryBinding();
 
     bool initialized() const { return m_initialized; }
index b932800..36e47d1 100644 (file)
@@ -54,6 +54,7 @@
 #include "SkColor.h"
 #include "ThrottledTextureUploader.h"
 #include "TraceEvent.h"
+#include "UnthrottledTextureUploader.h"
 #include <public/WebGraphicsContext3D.h>
 #include <public/WebSharedGraphicsContext3D.h>
 #include <public/WebVideoFrame.h>
@@ -71,40 +72,6 @@ namespace WebCore {
 
 namespace {
 
-static WebTransformationMatrix orthoMatrix(float left, float right, float bottom, float top)
-{
-    float deltaX = right - left;
-    float deltaY = top - bottom;
-    WebTransformationMatrix ortho;
-    if (!deltaX || !deltaY)
-        return ortho;
-    ortho.setM11(2.0f / deltaX);
-    ortho.setM41(-(right + left) / deltaX);
-    ortho.setM22(2.0f / deltaY);
-    ortho.setM42(-(top + bottom) / deltaY);
-
-    // Z component of vertices is always set to zero as we don't use the depth buffer
-    // while drawing.
-    ortho.setM33(0);
-
-    return ortho;
-}
-
-static WebTransformationMatrix screenMatrix(int x, int y, int width, int height)
-{
-    WebTransformationMatrix screen;
-
-    // Map to viewport.
-    screen.translate3d(x, y, 0);
-    screen.scale3d(width, height, 0);
-
-    // Map x, y and z to unit square.
-    screen.translate3d(0.5, 0.5, 0.5);
-    screen.scale3d(0.5, 0.5, 0.5);
-
-    return screen;
-}
-
 bool needsIOSurfaceReadbackWorkaround()
 {
 #if OS(DARWIN)
@@ -114,46 +81,8 @@ bool needsIOSurfaceReadbackWorkaround()
 #endif
 }
 
-class UnthrottledTextureUploader : public TextureUploader {
-    WTF_MAKE_NONCOPYABLE(UnthrottledTextureUploader);
-public:
-    static PassOwnPtr<UnthrottledTextureUploader> create()
-    {
-        return adoptPtr(new UnthrottledTextureUploader());
-    }
-    virtual ~UnthrottledTextureUploader() { }
-
-    virtual bool isBusy() OVERRIDE { return false; }
-    virtual void beginUploads() OVERRIDE { }
-    virtual void endUploads() OVERRIDE { }
-    virtual void uploadTexture(CCResourceProvider* resourceProvider, Parameters upload) OVERRIDE { upload.texture->updateRect(resourceProvider, upload.sourceRect, upload.destOffset); }
-
-protected:
-    UnthrottledTextureUploader() { }
-};
-
 } // anonymous namespace
 
-class LayerRendererChromium::CachedTexture : public CCScopedTexture {
-    WTF_MAKE_NONCOPYABLE(CachedTexture);
-public:
-    static PassOwnPtr<CachedTexture> create(CCResourceProvider* resourceProvider) { return adoptPtr(new CachedTexture(resourceProvider)); }
-    virtual ~CachedTexture() { }
-
-    bool isComplete() const { return m_isComplete; }
-    void setIsComplete(bool isComplete) { m_isComplete = isComplete; }
-
-protected:
-    explicit CachedTexture(CCResourceProvider* resourceProvider)
-        : CCScopedTexture(resourceProvider)
-        , m_isComplete(false)
-    {
-    }
-
-private:
-    bool m_isComplete;
-};
-
 PassOwnPtr<LayerRendererChromium> LayerRendererChromium::create(CCRendererClient* client, CCResourceProvider* resourceProvider, TextureUploaderOption textureUploaderSetting)
 {
     OwnPtr<LayerRendererChromium> layerRenderer(adoptPtr(new LayerRendererChromium(client, resourceProvider, textureUploaderSetting)));
@@ -166,10 +95,9 @@ PassOwnPtr<LayerRendererChromium> LayerRendererChromium::create(CCRendererClient
 LayerRendererChromium::LayerRendererChromium(CCRendererClient* client,
                                              CCResourceProvider* resourceProvider,
                                              TextureUploaderOption textureUploaderSetting)
-    : CCRenderer(client)
+    : CCDirectRenderer(client, resourceProvider)
     , m_offscreenFramebufferId(0)
     , m_sharedGeometryQuad(FloatRect(-0.5f, -0.5f, 1.0f, 1.0f))
-    , m_resourceProvider(resourceProvider)
     , m_context(resourceProvider->graphicsContext3D())
     , m_isViewportChanged(false)
     , m_isFramebufferDiscarded(false)
@@ -299,83 +227,7 @@ void LayerRendererChromium::clearFramebuffer(DrawingFrame& frame)
         m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT);
 }
 
-// static
-IntSize LayerRendererChromium::renderPassTextureSize(const CCRenderPass* pass)
-{
-    return pass->outputRect().size();
-}
-
-// static
-GC3Denum LayerRendererChromium::renderPassTextureFormat(const CCRenderPass*)
-{
-    return GraphicsContext3D::RGBA;
-}
-
-void LayerRendererChromium::decideRenderPassAllocationsForFrame(const CCRenderPassList& renderPassesInDrawOrder)
-{
-    HashMap<int, const CCRenderPass*> renderPassesInFrame;
-    for (size_t i = 0; i < renderPassesInDrawOrder.size(); ++i)
-        renderPassesInFrame.set(renderPassesInDrawOrder[i]->id(), renderPassesInDrawOrder[i]);
-
-    Vector<int> passesToDelete;
-    HashMap<int, OwnPtr<CachedTexture> >::const_iterator passIterator;
-    for (passIterator = m_renderPassTextures.begin(); passIterator != m_renderPassTextures.end(); ++passIterator) {
-        const CCRenderPass* renderPassInFrame = renderPassesInFrame.get(passIterator->first);
-        if (!renderPassInFrame) {
-            passesToDelete.append(passIterator->first);
-            continue;
-        }
-
-        const IntSize& requiredSize = renderPassTextureSize(renderPassInFrame);
-        GC3Denum requiredFormat = renderPassTextureFormat(renderPassInFrame);
-        CachedTexture* texture = passIterator->second.get();
-        ASSERT(texture);
-
-        if (texture->id() && (texture->size() != requiredSize || texture->format() != requiredFormat))
-            texture->free();
-    }
-
-    // Delete RenderPass textures from the previous frame that will not be used again.
-    for (size_t i = 0; i < passesToDelete.size(); ++i)
-        m_renderPassTextures.remove(passesToDelete[i]);
-
-    for (size_t i = 0; i < renderPassesInDrawOrder.size(); ++i) {
-        if (!m_renderPassTextures.contains(renderPassesInDrawOrder[i]->id())) {
-            OwnPtr<CachedTexture> texture = CachedTexture::create(m_resourceProvider);
-            m_renderPassTextures.set(renderPassesInDrawOrder[i]->id(), texture.release());
-        }
-    }
-}
-
-bool LayerRendererChromium::haveCachedResourcesForRenderPassId(int id) const
-{
-    CachedTexture* texture = m_renderPassTextures.get(id);
-    return texture && texture->id() && texture->isComplete();
-}
-
-void LayerRendererChromium::drawFrame(const CCRenderPassList& renderPassesInDrawOrder, const CCRenderPassIdHashMap& renderPassesById)
-{
-    const CCRenderPass* rootRenderPass = renderPassesInDrawOrder.last();
-    ASSERT(rootRenderPass);
-
-    DrawingFrame frame;
-    frame.renderPassesById = &renderPassesById;
-    frame.rootRenderPass = rootRenderPass;
-
-    frame.rootDamageRect = m_capabilities.usingPartialSwap ? frame.rootRenderPass->damageRect() : frame.rootRenderPass->outputRect();
-    frame.rootDamageRect.intersect(IntRect(IntPoint::zero(), viewportSize()));
-
-    beginDrawingFrame();
-
-    for (size_t i = 0; i < renderPassesInDrawOrder.size(); ++i)
-        drawRenderPass(frame, renderPassesInDrawOrder[i]);
-
-    finishDrawingFrame();
-
-    m_swapBufferRect.unite(enclosingIntRect(frame.rootDamageRect));
-}
-
-void LayerRendererChromium::beginDrawingFrame()
+void LayerRendererChromium::beginDrawingFrame(DrawingFrame& frame)
 {
     // FIXME: Remove this once framebuffer is automatically recreated on first use
     ensureFramebuffer();
@@ -409,39 +261,8 @@ void LayerRendererChromium::doNoOp()
     GLC(m_context, m_context->flush());
 }
 
-void LayerRendererChromium::drawRenderPass(DrawingFrame& frame, const CCRenderPass* renderPass)
-{
-    if (!useRenderPass(frame, renderPass))
-        return;
-
-    FloatRect scissorRect = renderPass->outputRect();
-    if (frame.rootDamageRect != frame.rootRenderPass->outputRect()) {
-        WebTransformationMatrix inverseTransformToRoot = renderPass->transformToRootTarget().inverse();
-        scissorRect.intersect(CCMathUtil::projectClippedRect(inverseTransformToRoot, frame.rootDamageRect));
-    }
-
-    setScissorToRect(frame, enclosingIntRect(scissorRect));
-    clearFramebuffer(frame);
-
-    const CCQuadList& quadList = renderPass->quadList();
-    for (CCQuadList::constBackToFrontIterator it = quadList.backToFrontBegin(); it != quadList.backToFrontEnd(); ++it)
-        drawQuad(frame, it->get(), scissorRect);
-
-    CachedTexture* texture = m_renderPassTextures.get(renderPass->id());
-    if (texture)
-        texture->setIsComplete(!renderPass->hasOcclusionFromOutsideTargetSurface());
-}
-
-void LayerRendererChromium::drawQuad(DrawingFrame& frame, const CCDrawQuad* quad, FloatRect scissorRect)
+void LayerRendererChromium::drawQuad(DrawingFrame& frame, const CCDrawQuad* quad)
 {
-    scissorRect.intersect(quad->clippedRectInTarget());
-    if (scissorRect.isEmpty())
-        return;
-
-    // For now, we always do per-quad scissoring because some quad types draw their
-    // un-clipped bounds, relying on scissoring for correct clipping.
-    setScissorToRect(frame, enclosingIntRect(scissorRect));
-
     if (quad->needsBlending())
         GLC(m_context, m_context->enable(GraphicsContext3D::BLEND));
     else
@@ -481,7 +302,7 @@ void LayerRendererChromium::drawQuad(DrawingFrame& frame, const CCDrawQuad* quad
     }
 }
 
-void LayerRendererChromium::drawCheckerboardQuad(DrawingFrame& frame, const CCCheckerboardDrawQuad* quad)
+void LayerRendererChromium::drawCheckerboardQuad(const DrawingFrame& frame, const CCCheckerboardDrawQuad* quad)
 {
     const TileCheckerboardProgram* program = tileCheckerboardProgram();
     ASSERT(program && program->initialized());
@@ -503,7 +324,7 @@ void LayerRendererChromium::drawCheckerboardQuad(DrawingFrame& frame, const CCCh
     drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), program->vertexShader().matrixLocation());
 }
 
-void LayerRendererChromium::drawDebugBorderQuad(DrawingFrame& frame, const CCDebugBorderDrawQuad* quad)
+void LayerRendererChromium::drawDebugBorderQuad(const DrawingFrame& frame, const CCDebugBorderDrawQuad* quad)
 {
     static float glMatrix[16];
     const SolidColorProgram* program = solidColorProgram();
@@ -760,7 +581,7 @@ void LayerRendererChromium::drawRenderPassQuad(DrawingFrame& frame, const CCRend
     drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), shaderMatrixLocation);
 }
 
-void LayerRendererChromium::drawSolidColorQuad(DrawingFrame& frame, const CCSolidColorDrawQuad* quad)
+void LayerRendererChromium::drawSolidColorQuad(const DrawingFrame& frame, const CCSolidColorDrawQuad* quad)
 {
     const SolidColorProgram* program = solidColorProgram();
     GLC(context(), context()->useProgram(program->program()));
@@ -799,7 +620,7 @@ static void tileUniformLocation(T program, TileProgramUniforms& uniforms)
     uniforms.edgeLocation = program->fragmentShader().edgeLocation();
 }
 
-void LayerRendererChromium::drawTileQuad(DrawingFrame& frame, const CCTileDrawQuad* quad)
+void LayerRendererChromium::drawTileQuad(const DrawingFrame& frame, const CCTileDrawQuad* quad)
 {
     IntRect tileRect = quad->quadVisibleRect();
 
@@ -966,7 +787,7 @@ void LayerRendererChromium::drawTileQuad(DrawingFrame& frame, const CCTileDrawQu
     drawQuadGeometry(frame, quad->quadTransform(), centeredRect, uniforms.matrixLocation);
 }
 
-void LayerRendererChromium::drawYUVVideoQuad(DrawingFrame& frame, const CCYUVVideoDrawQuad* quad)
+void LayerRendererChromium::drawYUVVideoQuad(const DrawingFrame& frame, const CCYUVVideoDrawQuad* quad)
 {
     const VideoYUVProgram* program = videoYUVProgram();
     ASSERT(program && program->initialized());
@@ -1026,7 +847,7 @@ void LayerRendererChromium::drawYUVVideoQuad(DrawingFrame& frame, const CCYUVVid
     GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE0));
 }
 
-void LayerRendererChromium::drawStreamVideoQuad(DrawingFrame& frame, const CCStreamVideoDrawQuad* quad)
+void LayerRendererChromium::drawStreamVideoQuad(const DrawingFrame& frame, const CCStreamVideoDrawQuad* quad)
 {
     static float glMatrix[16];
 
@@ -1071,7 +892,7 @@ struct TexTransformTextureProgramBinding : TextureProgramBinding {
     int texTransformLocation;
 };
 
-void LayerRendererChromium::drawTextureQuad(DrawingFrame& frame, const CCTextureDrawQuad* quad)
+void LayerRendererChromium::drawTextureQuad(const DrawingFrame& frame, const CCTextureDrawQuad* quad)
 {
     ASSERT(CCProxy::isImplThread());
 
@@ -1115,7 +936,7 @@ void LayerRendererChromium::drawTextureQuad(DrawingFrame& frame, const CCTexture
         GLC(m_context, m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE_MINUS_SRC_ALPHA));
 }
 
-void LayerRendererChromium::drawIOSurfaceQuad(DrawingFrame& frame, const CCIOSurfaceDrawQuad* quad)
+void LayerRendererChromium::drawIOSurfaceQuad(const DrawingFrame& frame, const CCIOSurfaceDrawQuad* quad)
 {
     ASSERT(CCProxy::isImplThread());
     TexTransformTextureProgramBinding binding;
@@ -1137,8 +958,11 @@ void LayerRendererChromium::drawIOSurfaceQuad(DrawingFrame& frame, const CCIOSur
     GLC(context(), context()->bindTexture(Extensions3D::TEXTURE_RECTANGLE_ARB, 0));
 }
 
-void LayerRendererChromium::finishDrawingFrame()
+void LayerRendererChromium::finishDrawingFrame(DrawingFrame& frame)
 {
+    m_currentFramebufferLock.clear();
+    m_swapBufferRect.unite(enclosingIntRect(frame.rootDamageRect));
+
     GLC(m_context, m_context->disable(GraphicsContext3D::SCISSOR_TEST));
     GLC(m_context, m_context->disable(GraphicsContext3D::BLEND));
 }
@@ -1186,20 +1010,18 @@ void LayerRendererChromium::setShaderOpacity(float opacity, int alphaLocation)
         GLC(m_context, m_context->uniform1f(alphaLocation, opacity));
 }
 
-void LayerRendererChromium::drawQuadGeometry(DrawingFrame& frame, const WebKit::WebTransformationMatrix& drawTransform, const FloatRect& quadRect, int matrixLocation)
+void LayerRendererChromium::drawQuadGeometry(const DrawingFrame& frame, const WebKit::WebTransformationMatrix& drawTransform, const FloatRect& quadRect, int matrixLocation)
 {
-    WebTransformationMatrix quadMatrix = drawTransform;
-    quadMatrix.translate(0.5 * quadRect.width() + quadRect.x(), 0.5 * quadRect.height() + quadRect.y());
-    quadMatrix.scaleNonUniform(quadRect.width(), quadRect.height());
-
+    WebTransformationMatrix quadRectMatrix;
+    quadRectTransform(&quadRectMatrix, drawTransform, quadRect);
     static float glMatrix[16];
-    toGLMatrix(&glMatrix[0], frame.projectionMatrix * quadMatrix);
+    toGLMatrix(&glMatrix[0], frame.projectionMatrix * quadRectMatrix);
     GLC(m_context, m_context->uniformMatrix4fv(matrixLocation, 1, false, &glMatrix[0]));
 
     GLC(m_context, m_context->drawElements(GraphicsContext3D::TRIANGLES, 6, GraphicsContext3D::UNSIGNED_SHORT, 0));
 }
 
-void LayerRendererChromium::copyTextureToFramebuffer(DrawingFrame& frame, int textureId, const IntRect& rect, const WebTransformationMatrix& drawMatrix)
+void LayerRendererChromium::copyTextureToFramebuffer(const DrawingFrame& frame, int textureId, const IntRect& rect, const WebTransformationMatrix& drawMatrix)
 {
     const RenderPassProgram* program = renderPassProgram();
 
@@ -1384,31 +1206,6 @@ bool LayerRendererChromium::getFramebufferTexture(CCScopedTexture* texture, cons
     return true;
 }
 
-bool LayerRendererChromium::isCurrentRenderPass(DrawingFrame& frame, const CCRenderPass* renderPass)
-{
-    return frame.currentRenderPass == renderPass && !frame.currentTexture;
-}
-
-bool LayerRendererChromium::useRenderPass(DrawingFrame& frame, const CCRenderPass* renderPass)
-{
-    frame.currentRenderPass = renderPass;
-    frame.currentTexture = 0;
-
-    if (renderPass == frame.rootRenderPass) {
-        frame.currentFramebufferLock.clear();
-        GLC(m_context, m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0));
-        setDrawFramebufferRect(frame, renderPass->outputRect(), true);
-        return true;
-    }
-
-    CachedTexture* texture = m_renderPassTextures.get(renderPass->id());
-    ASSERT(texture);
-    if (!texture->id() && !texture->allocate(CCRenderer::ImplPool, renderPassTextureSize(renderPass), renderPassTextureFormat(renderPass), CCResourceProvider::TextureUsageFramebuffer))
-        return false;
-
-    return bindFramebufferToTexture(frame, texture, renderPass->outputRect());
-}
-
 bool LayerRendererChromium::useScopedTexture(DrawingFrame& frame, const CCScopedTexture* texture, const IntRect& viewportRect)
 {
     ASSERT(texture->id());
@@ -1418,13 +1215,19 @@ bool LayerRendererChromium::useScopedTexture(DrawingFrame& frame, const CCScoped
     return bindFramebufferToTexture(frame, texture, viewportRect);
 }
 
+void LayerRendererChromium::bindFramebufferToOutputSurface(DrawingFrame& frame)
+{
+    m_currentFramebufferLock.clear();
+    GLC(m_context, m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0));
+}
+
 bool LayerRendererChromium::bindFramebufferToTexture(DrawingFrame& frame, const CCScopedTexture* texture, const IntRect& framebufferRect)
 {
     ASSERT(texture->id());
 
     GLC(m_context, m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_offscreenFramebufferId));
-    frame.currentFramebufferLock = adoptPtr(new CCScopedLockResourceForWrite(m_resourceProvider, texture->id()));
-    unsigned textureId = frame.currentFramebufferLock->textureId();
+    m_currentFramebufferLock = adoptPtr(new CCScopedLockResourceForWrite(m_resourceProvider, texture->id()));
+    unsigned textureId = m_currentFramebufferLock->textureId();
     GLC(m_context, m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, textureId, 0));
 
 #if !defined ( NDEBUG )
@@ -1434,51 +1237,32 @@ bool LayerRendererChromium::bindFramebufferToTexture(DrawingFrame& frame, const
     }
 #endif
 
-    setDrawFramebufferRect(frame, framebufferRect, false);
+    initializeMatrices(frame, framebufferRect, false);
+    setDrawViewportSize(framebufferRect.size());
 
     return true;
 }
 
-// Sets the scissor region to the given rectangle. The coordinate system for the
-// scissorRect has its origin at the top left corner of the current visible rect.
-void LayerRendererChromium::setScissorToRect(DrawingFrame& frame, const IntRect& scissorRect)
+void LayerRendererChromium::enableScissorTestRect(const IntRect& scissorRect)
 {
-    IntRect framebufferOutputRect = frame.currentRenderPass->outputRect();
-
     GLC(m_context, m_context->enable(GraphicsContext3D::SCISSOR_TEST));
-
-    // The scissor coordinates must be supplied in viewport space so we need to offset
-    // by the relative position of the top left corner of the current render pass.
-    int scissorX = scissorRect.x() - framebufferOutputRect.x();
-    // When rendering to the default render surface we're rendering upside down so the top
-    // of the GL scissor is the bottom of our layer.
-    // But, if rendering to offscreen texture, we reverse our sense of 'upside down'.
-    int scissorY;
-    if (isCurrentRenderPass(frame, frame.rootRenderPass))
-        scissorY = framebufferOutputRect.height() - (scissorRect.maxY() - framebufferOutputRect.y());
-    else
-        scissorY = scissorRect.y() - framebufferOutputRect.y();
-    GLC(m_context, m_context->scissor(scissorX, scissorY, scissorRect.width(), scissorRect.height()));
+    GLC(m_context, m_context->scissor(scissorRect.x(), scissorRect.y(), scissorRect.width(), scissorRect.height()));
 }
 
-bool LayerRendererChromium::makeContextCurrent()
+void LayerRendererChromium::disableScissorTest()
 {
-    return m_context->makeContextCurrent();
+    GLC(m_context, m_context->disable(GraphicsContext3D::SCISSOR_TEST));
 }
 
-// Sets the coordinate range of content that ends being drawn onto the target render surface.
-// The target render surface is assumed to have an origin at 0, 0 and the width and height of
-// of the drawRect.
-void LayerRendererChromium::setDrawFramebufferRect(DrawingFrame& frame, const IntRect& drawRect, bool flipY)
+void LayerRendererChromium::setDrawViewportSize(const IntSize& viewportSize)
 {
-    if (flipY)
-        frame.projectionMatrix = orthoMatrix(drawRect.x(), drawRect.maxX(), drawRect.maxY(), drawRect.y());
-    else
-        frame.projectionMatrix = orthoMatrix(drawRect.x(), drawRect.maxX(), drawRect.y(), drawRect.maxY());
-    GLC(m_context, m_context->viewport(0, 0, drawRect.width(), drawRect.height()));
-    frame.windowMatrix = screenMatrix(0, 0, drawRect.width(), drawRect.height());
+    GLC(m_context, m_context->viewport(0, 0, viewportSize.width(), viewportSize.height()));
 }
 
+bool LayerRendererChromium::makeContextCurrent()
+{
+    return m_context->makeContextCurrent();
+}
 
 bool LayerRendererChromium::initializeSharedObjects()
 {
@@ -1490,7 +1274,7 @@ bool LayerRendererChromium::initializeSharedObjects()
 
     // We will always need these programs to render, so create the programs eagerly so that the shader compilation can
     // start while we do other work. Other programs are created lazily on first access.
-    m_sharedGeometry = adoptPtr(new GeometryBinding(m_context));
+    m_sharedGeometry = adoptPtr(new GeometryBinding(m_context, quadVertexRect()));
     m_renderPassProgram = adoptPtr(new RenderPassProgram(m_context));
     m_tileProgram = adoptPtr(new TileProgram(m_context));
     m_tileProgramOpaque = adoptPtr(new TileProgramOpaque(m_context));
index fb51f84..09cd0e2 100644 (file)
@@ -36,6 +36,7 @@
 
 #include "CCCheckerboardDrawQuad.h"
 #include "CCDebugBorderDrawQuad.h"
+#include "CCDirectRenderer.h"
 #include "CCIOSurfaceDrawQuad.h"
 #include "CCRenderPassDrawQuad.h"
 #include "CCRenderer.h"
@@ -59,7 +60,7 @@ class GeometryBinding;
 class ScopedEnsureFramebufferAllocation;
 
 // Class that handles drawing of composited render layers using GL.
-class LayerRendererChromium : public CCRenderer,
+class LayerRendererChromium : public CCDirectRenderer,
                               public WebKit::WebGraphicsContext3D::WebGraphicsSwapBuffersCompleteCallbackCHROMIUM,
                               public WebKit::WebGraphicsContext3D::WebGraphicsMemoryAllocationChangedCallbackCHROMIUM ,
                               public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
@@ -77,11 +78,6 @@ public:
 
     const FloatQuad& sharedGeometryQuad() const { return m_sharedGeometryQuad; }
 
-    virtual void decideRenderPassAllocationsForFrame(const CCRenderPassList&) OVERRIDE;
-    virtual bool haveCachedResourcesForRenderPassId(int id) const OVERRIDE;
-
-    virtual void drawFrame(const CCRenderPassList&, const CCRenderPassIdHashMap&) OVERRIDE;
-
     // waits for rendering to finish
     virtual void finish() OVERRIDE;
 
@@ -103,73 +99,45 @@ public:
 
     virtual void setVisible(bool) OVERRIDE;
 
-    CCResourceProvider* resourceProvider() const { return m_resourceProvider; }
-
 protected:
     LayerRendererChromium(CCRendererClient*, CCResourceProvider*, TextureUploaderOption);
 
-
     bool isFramebufferDiscarded() const { return m_isFramebufferDiscarded; }
     bool initialize();
 
     void releaseRenderPassTextures();
 
-private:
-    struct DrawingFrame {
-        const CCRenderPassIdHashMap* renderPassesById;
-        const CCRenderPass* rootRenderPass;
-        const CCRenderPass* currentRenderPass;
-        const CCScopedTexture* currentTexture;
-        OwnPtr<CCScopedLockResourceForWrite> currentFramebufferLock;
-
-        FloatRect rootDamageRect;
-
-        WebKit::WebTransformationMatrix projectionMatrix;
-        WebKit::WebTransformationMatrix windowMatrix;
-
-        DrawingFrame()
-            : rootRenderPass(0)
-            , currentRenderPass(0)
-            , currentTexture(0)
-        { }
-    };
+    virtual void bindFramebufferToOutputSurface(DrawingFrame&) OVERRIDE;
+    virtual bool bindFramebufferToTexture(DrawingFrame&, const CCScopedTexture*, const IntRect& framebufferRect) OVERRIDE;
+    virtual void setDrawViewportSize(const IntSize&) OVERRIDE;
+    virtual void enableScissorTestRect(const IntRect& scissorRect) OVERRIDE;
+    virtual void disableScissorTest() OVERRIDE;
+    virtual void clearFramebuffer(DrawingFrame&) OVERRIDE;
+    virtual void drawQuad(DrawingFrame&, const CCDrawQuad*) OVERRIDE;
+    virtual void beginDrawingFrame(DrawingFrame&) OVERRIDE;
+    virtual void finishDrawingFrame(DrawingFrame&) OVERRIDE;
 
+private:
     static void toGLMatrix(float*, const WebKit::WebTransformationMatrix&);
 
-    void beginDrawingFrame();
-    void drawRenderPass(DrawingFrame&, const CCRenderPass*);
-    void finishDrawingFrame();
-
-    void drawQuad(DrawingFrame&, const CCDrawQuad*, FloatRect scissorRect);
-    void drawCheckerboardQuad(DrawingFrame&, const CCCheckerboardDrawQuad*);
-    void drawDebugBorderQuad(DrawingFrame&, const CCDebugBorderDrawQuad*);
+    void drawCheckerboardQuad(const DrawingFrame&, const CCCheckerboardDrawQuad*);
+    void drawDebugBorderQuad(const DrawingFrame&, const CCDebugBorderDrawQuad*);
     PassOwnPtr<CCScopedTexture> drawBackgroundFilters(DrawingFrame&, const CCRenderPassDrawQuad*, const WebKit::WebFilterOperations&, const WebKit::WebTransformationMatrix& deviceTransform);
     void drawRenderPassQuad(DrawingFrame&, const CCRenderPassDrawQuad*);
-    void drawSolidColorQuad(DrawingFrame&, const CCSolidColorDrawQuad*);
-    void drawStreamVideoQuad(DrawingFrame&, const CCStreamVideoDrawQuad*);
-    void drawTextureQuad(DrawingFrame&, const CCTextureDrawQuad*);
-    void drawIOSurfaceQuad(DrawingFrame&, const CCIOSurfaceDrawQuad*);
-    void drawTileQuad(DrawingFrame&, const CCTileDrawQuad*);
-    void drawYUVVideoQuad(DrawingFrame&, const CCYUVVideoDrawQuad*);
+    void drawSolidColorQuad(const DrawingFrame&, const CCSolidColorDrawQuad*);
+    void drawStreamVideoQuad(const DrawingFrame&, const CCStreamVideoDrawQuad*);
+    void drawTextureQuad(const DrawingFrame&, const CCTextureDrawQuad*);
+    void drawIOSurfaceQuad(const DrawingFrame&, const CCIOSurfaceDrawQuad*);
+    void drawTileQuad(const DrawingFrame&, const CCTileDrawQuad*);
+    void drawYUVVideoQuad(const DrawingFrame&, const CCYUVVideoDrawQuad*);
 
     void setShaderOpacity(float opacity, int alphaLocation);
     void setShaderFloatQuad(const FloatQuad&, int quadLocation);
-    void drawQuadGeometry(DrawingFrame&, const WebKit::WebTransformationMatrix& drawTransform, const FloatRect& quadRect, int matrixLocation);
-
-    void copyTextureToFramebuffer(DrawingFrame&, int textureId, const IntRect&, const WebKit::WebTransformationMatrix& drawMatrix);
-
-    void setScissorToRect(DrawingFrame&, const IntRect&);
+    void drawQuadGeometry(const DrawingFrame&, const WebKit::WebTransformationMatrix& drawTransform, const FloatRect& quadRect, int matrixLocation);
 
-    void setDrawFramebufferRect(DrawingFrame&, const IntRect&, bool flipY);
+    void copyTextureToFramebuffer(const DrawingFrame&, int textureId, const IntRect&, const WebKit::WebTransformationMatrix& drawMatrix);
 
-    // The current drawing target is either a RenderPass or ScopedTexture. Use these functions to switch to a new drawing target.
-    bool useRenderPass(DrawingFrame&, const CCRenderPass*);
     bool useScopedTexture(DrawingFrame&, const CCScopedTexture*, const IntRect& viewportRect);
-    bool isCurrentRenderPass(DrawingFrame&, const CCRenderPass*);
-
-    bool bindFramebufferToTexture(DrawingFrame&, const CCScopedTexture*, const IntRect& viewportRect);
-
-    void clearFramebuffer(DrawingFrame&);
 
     bool makeContextCurrent();
 
@@ -188,9 +156,6 @@ private:
     // WebGraphicsContext3D::WebGraphicsContextLostCallback implementation.
     virtual void onContextLost() OVERRIDE;
 
-    static IntSize renderPassTextureSize(const CCRenderPass*);
-    static GC3Denum renderPassTextureFormat(const CCRenderPass*);
-
     LayerRendererCapabilities m_capabilities;
 
     unsigned m_offscreenFramebufferId;
@@ -198,8 +163,6 @@ private:
     OwnPtr<GeometryBinding> m_sharedGeometry;
     FloatQuad m_sharedGeometryQuad;
 
-    class CachedTexture;
-
     // This block of bindings defines all of the programs used by the compositor itself.
 
     // Tiled layer shaders.
@@ -273,12 +236,9 @@ private:
 
     OwnPtr<SolidColorProgram> m_solidColorProgram;
 
-    CCResourceProvider* m_resourceProvider;
     OwnPtr<AcceleratedTextureCopier> m_textureCopier;
     OwnPtr<TextureUploader> m_textureUploader;
 
-    HashMap<int, OwnPtr<CachedTexture> > m_renderPassTextures;
-
     WebKit::WebGraphicsContext3D* m_context;
 
     IntRect m_swapBufferRect;
@@ -287,6 +247,8 @@ private:
     bool m_isUsingBindUniform;
     bool m_visible;
     TextureUploaderOption m_textureUploaderSetting;
+
+    OwnPtr<CCScopedLockResourceForWrite> m_currentFramebufferLock;
 };
 
 
index afe2ec0..68b0f16 100644 (file)
@@ -51,7 +51,6 @@ public:
     virtual void copyTexture(Parameters) = 0;
     virtual void flush() = 0;
 
-protected:
     virtual ~TextureCopier() { }
 };
 
diff --git a/Source/WebCore/platform/graphics/chromium/UnthrottledTextureUploader.h b/Source/WebCore/platform/graphics/chromium/UnthrottledTextureUploader.h
new file mode 100644 (file)
index 0000000..fa96899
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2012, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef UnthrottledTextureUploader_h
+#define UnthrottledTextureUploader_h
+
+#include "CCResourceProvider.h"
+#include "TextureUploader.h"
+
+namespace WebCore {
+
+class UnthrottledTextureUploader : public TextureUploader {
+    WTF_MAKE_NONCOPYABLE(UnthrottledTextureUploader);
+public:
+    static PassOwnPtr<UnthrottledTextureUploader> create()
+    {
+        return adoptPtr(new UnthrottledTextureUploader());
+    }
+    virtual ~UnthrottledTextureUploader() { }
+
+    virtual bool isBusy() OVERRIDE { return false; }
+    virtual void beginUploads() OVERRIDE { }
+    virtual void endUploads() OVERRIDE { }
+    virtual void uploadTexture(CCResourceProvider* resourceProvider, Parameters upload) OVERRIDE { upload.texture->updateRect(resourceProvider, upload.sourceRect, upload.destOffset); }
+
+protected:
+    UnthrottledTextureUploader() { }
+};
+
+}
+
+#endif
diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCDirectRenderer.cpp b/Source/WebCore/platform/graphics/chromium/cc/CCDirectRenderer.cpp
new file mode 100644 (file)
index 0000000..4688bed
--- /dev/null
@@ -0,0 +1,233 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "CCDirectRenderer.h"
+
+#include "CCMathUtil.h"
+#include <public/WebTransformationMatrix.h>
+
+using WebKit::WebTransformationMatrix;
+
+static WebTransformationMatrix orthoProjectionMatrix(float left, float right, float bottom, float top)
+{
+    // Use the standard formula to map the clipping frustum to the cube from
+    // [-1, -1, -1] to [1, 1, 1].
+    float deltaX = right - left;
+    float deltaY = top - bottom;
+    WebTransformationMatrix proj;
+    if (!deltaX || !deltaY)
+        return proj;
+    proj.setM11(2.0f / deltaX);
+    proj.setM41(-(right + left) / deltaX);
+    proj.setM22(2.0f / deltaY);
+    proj.setM42(-(top + bottom) / deltaY);
+
+    // Z component of vertices is always set to zero as we don't use the depth buffer
+    // while drawing.
+    proj.setM33(0);
+
+    return proj;
+}
+
+static WebTransformationMatrix windowMatrix(int x, int y, int width, int height)
+{
+    WebTransformationMatrix canvas;
+
+    // Map to window position and scale up to pixel coordinates.
+    canvas.translate3d(x, y, 0);
+    canvas.scale3d(width, height, 0);
+
+    // Map from ([-1, -1] to [1, 1]) -> ([0, 0] to [1, 1])
+    canvas.translate3d(0.5, 0.5, 0.5);
+    canvas.scale3d(0.5, 0.5, 0.5);
+
+    return canvas;
+}
+
+namespace WebCore {
+//
+// static
+FloatRect CCDirectRenderer::quadVertexRect()
+{
+    return FloatRect(-0.5, -0.5, 1, 1);
+}
+
+// static
+void CCDirectRenderer::quadRectTransform(WebKit::WebTransformationMatrix* quadRectTransform, const WebKit::WebTransformationMatrix& quadTransform, const FloatRect& quadRect)
+{
+    *quadRectTransform = quadTransform;
+    quadRectTransform->translate(0.5 * quadRect.width() + quadRect.x(), 0.5 * quadRect.height() + quadRect.y());
+    quadRectTransform->scaleNonUniform(quadRect.width(), quadRect.height());
+}
+
+// static
+void CCDirectRenderer::initializeMatrices(DrawingFrame& frame, const IntRect& drawRect, bool flipY)
+{
+    if (flipY)
+        frame.projectionMatrix = orthoProjectionMatrix(drawRect.x(), drawRect.maxX(), drawRect.maxY(), drawRect.y());
+    else
+        frame.projectionMatrix = orthoProjectionMatrix(drawRect.x(), drawRect.maxX(), drawRect.y(), drawRect.maxY());
+    frame.windowMatrix = windowMatrix(0, 0, drawRect.width(), drawRect.height());
+    frame.flippedY = flipY;
+}
+
+// static
+IntRect CCDirectRenderer::moveScissorToWindowSpace(const DrawingFrame& frame, FloatRect scissorRect)
+{
+    IntRect scissorRectInCanvasSpace = enclosingIntRect(scissorRect);
+    // The scissor coordinates must be supplied in viewport space so we need to offset
+    // by the relative position of the top left corner of the current render pass.
+    IntRect framebufferOutputRect = frame.currentRenderPass->outputRect();
+    scissorRectInCanvasSpace.setX(scissorRectInCanvasSpace.x() - framebufferOutputRect.x());
+    if (frame.flippedY && !frame.currentTexture)
+        scissorRectInCanvasSpace.setY(framebufferOutputRect.height() - (scissorRectInCanvasSpace.maxY() - framebufferOutputRect.y()));
+    else
+        scissorRectInCanvasSpace.setY(scissorRectInCanvasSpace.y() - framebufferOutputRect.y());
+    return scissorRectInCanvasSpace;
+}
+
+void CCDirectRenderer::decideRenderPassAllocationsForFrame(const CCRenderPassList& renderPassesInDrawOrder)
+{
+    HashMap<int, const CCRenderPass*> renderPassesInFrame;
+    for (size_t i = 0; i < renderPassesInDrawOrder.size(); ++i)
+        renderPassesInFrame.set(renderPassesInDrawOrder[i]->id(), renderPassesInDrawOrder[i]);
+
+    Vector<int> passesToDelete;
+    HashMap<int, OwnPtr<CachedTexture> >::const_iterator passIterator;
+    for (passIterator = m_renderPassTextures.begin(); passIterator != m_renderPassTextures.end(); ++passIterator) {
+        const CCRenderPass* renderPassInFrame = renderPassesInFrame.get(passIterator->first);
+        if (!renderPassInFrame) {
+            passesToDelete.append(passIterator->first);
+            continue;
+        }
+
+        const IntSize& requiredSize = renderPassTextureSize(renderPassInFrame);
+        GC3Denum requiredFormat = renderPassTextureFormat(renderPassInFrame);
+        CachedTexture* texture = passIterator->second.get();
+        ASSERT(texture);
+
+        if (texture->id() && (texture->size() != requiredSize || texture->format() != requiredFormat))
+            texture->free();
+    }
+
+    // Delete RenderPass textures from the previous frame that will not be used again.
+    for (size_t i = 0; i < passesToDelete.size(); ++i)
+        m_renderPassTextures.remove(passesToDelete[i]);
+
+    for (size_t i = 0; i < renderPassesInDrawOrder.size(); ++i) {
+        if (!m_renderPassTextures.contains(renderPassesInDrawOrder[i]->id())) {
+            OwnPtr<CachedTexture> texture = CachedTexture::create(m_resourceProvider);
+            m_renderPassTextures.set(renderPassesInDrawOrder[i]->id(), texture.release());
+        }
+    }
+}
+
+void CCDirectRenderer::drawFrame(const CCRenderPassList& renderPassesInDrawOrder, const CCRenderPassIdHashMap& renderPassesById)
+{
+    const CCRenderPass* rootRenderPass = renderPassesInDrawOrder.last();
+    ASSERT(rootRenderPass);
+
+    DrawingFrame frame;
+    frame.renderPassesById = &renderPassesById;
+    frame.rootRenderPass = rootRenderPass;
+    frame.rootDamageRect = capabilities().usingPartialSwap ? rootRenderPass->damageRect() : rootRenderPass->outputRect();
+    frame.rootDamageRect.intersect(IntRect(IntPoint::zero(), viewportSize()));
+
+    beginDrawingFrame(frame);
+    for (size_t i = 0; i < renderPassesInDrawOrder.size(); ++i)
+        drawRenderPass(frame, renderPassesInDrawOrder[i]);
+    finishDrawingFrame(frame);
+}
+
+void CCDirectRenderer::drawRenderPass(DrawingFrame& frame, const CCRenderPass* renderPass)
+{
+    if (!useRenderPass(frame, renderPass))
+        return;
+
+    frame.scissorRectInRenderPassSpace = frame.currentRenderPass->outputRect();
+    if (frame.rootDamageRect != frame.rootRenderPass->outputRect()) {
+        WebTransformationMatrix inverseTransformToRoot = frame.currentRenderPass->transformToRootTarget().inverse();
+        frame.scissorRectInRenderPassSpace.intersect(CCMathUtil::projectClippedRect(inverseTransformToRoot, frame.rootDamageRect));
+    }
+
+    enableScissorTestRect(moveScissorToWindowSpace(frame, frame.scissorRectInRenderPassSpace));
+    clearFramebuffer(frame);
+
+    const CCQuadList& quadList = renderPass->quadList();
+    for (CCQuadList::constBackToFrontIterator it = quadList.backToFrontBegin(); it != quadList.backToFrontEnd(); ++it) {
+        FloatRect quadScissorRect = frame.scissorRectInRenderPassSpace;
+        quadScissorRect.intersect(it->get()->clippedRectInTarget());
+        if (!quadScissorRect.isEmpty()) {
+            enableScissorTestRect(moveScissorToWindowSpace(frame, quadScissorRect));
+            drawQuad(frame, it->get());
+        }
+    }
+
+    CachedTexture* texture = m_renderPassTextures.get(renderPass->id());
+    if (texture)
+        texture->setIsComplete(!renderPass->hasOcclusionFromOutsideTargetSurface());
+}
+
+bool CCDirectRenderer::useRenderPass(DrawingFrame& frame, const CCRenderPass* renderPass)
+{
+    frame.currentRenderPass = renderPass;
+    frame.currentTexture = 0;
+
+    if (renderPass == frame.rootRenderPass) {
+        bindFramebufferToOutputSurface(frame);
+        initializeMatrices(frame, renderPass->outputRect(), true);
+        setDrawViewportSize(renderPass->outputRect().size());
+        return true;
+    }
+
+    CachedTexture* texture = m_renderPassTextures.get(renderPass->id());
+    ASSERT(texture);
+    if (!texture->id() && !texture->allocate(CCRenderer::ImplPool, renderPassTextureSize(renderPass), renderPassTextureFormat(renderPass), CCResourceProvider::TextureUsageFramebuffer))
+        return false;
+
+    return bindFramebufferToTexture(frame, texture, renderPass->outputRect());
+}
+
+bool CCDirectRenderer::haveCachedResourcesForRenderPassId(int id) const
+{
+    CachedTexture* texture = m_renderPassTextures.get(id);
+    return texture && texture->id() && texture->isComplete();
+}
+
+// static
+IntSize CCDirectRenderer::renderPassTextureSize(const CCRenderPass* pass)
+{
+    return pass->outputRect().size();
+}
+
+// static
+GC3Denum CCDirectRenderer::renderPassTextureFormat(const CCRenderPass*)
+{
+    return GraphicsContext3D::RGBA;
+}
+
+}
diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCDirectRenderer.h b/Source/WebCore/platform/graphics/chromium/cc/CCDirectRenderer.h
new file mode 100644 (file)
index 0000000..294152c
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CCDirectRenderer_h
+#define CCDirectRenderer_h
+
+#include "CCRenderer.h"
+#include "CCResourceProvider.h"
+#include "CCScopedTexture.h"
+
+namespace WebCore {
+
+class CCResourceProvider;
+
+// This is the base class for code shared between the GL and software
+// renderer implementations.  "Direct" refers to the fact that it does not
+// delegate rendering to another compositor.
+class CCDirectRenderer : public CCRenderer {
+    WTF_MAKE_NONCOPYABLE(CCDirectRenderer);
+public:
+    virtual ~CCDirectRenderer() { }
+
+    CCResourceProvider* resourceProvider() const { return m_resourceProvider; }
+
+    virtual void decideRenderPassAllocationsForFrame(const CCRenderPassList& renderPassesInDrawOrder) OVERRIDE;
+    virtual bool haveCachedResourcesForRenderPassId(int id) const OVERRIDE;
+    virtual void drawFrame(const CCRenderPassList& renderPassesInDrawOrder, const CCRenderPassIdHashMap& renderPassesById) OVERRIDE;
+
+protected:
+    CCDirectRenderer(CCRendererClient* client, CCResourceProvider* resourceProvider)
+        : CCRenderer(client)
+        , m_resourceProvider(resourceProvider)
+    {
+    }
+
+    struct DrawingFrame {
+        const CCRenderPassIdHashMap* renderPassesById;
+        const CCRenderPass* rootRenderPass;
+        const CCRenderPass* currentRenderPass;
+        const CCScopedTexture* currentTexture;
+
+        FloatRect rootDamageRect;
+
+        WebKit::WebTransformationMatrix projectionMatrix;
+        WebKit::WebTransformationMatrix windowMatrix;
+        bool flippedY;
+        FloatRect scissorRectInRenderPassSpace;
+
+        DrawingFrame()
+            : rootRenderPass(0)
+            , currentRenderPass(0)
+            , currentTexture(0)
+            , flippedY(false)
+        { }
+    };
+
+    class CachedTexture : public CCScopedTexture {
+        WTF_MAKE_NONCOPYABLE(CachedTexture);
+    public:
+        static PassOwnPtr<CachedTexture> create(CCResourceProvider* resourceProvider) { return adoptPtr(new CachedTexture(resourceProvider)); }
+        virtual ~CachedTexture() { }
+
+        bool isComplete() const { return m_isComplete; }
+        void setIsComplete(bool isComplete) { m_isComplete = isComplete; }
+
+    protected:
+        explicit CachedTexture(CCResourceProvider* resourceProvider)
+            : CCScopedTexture(resourceProvider)
+            , m_isComplete(false)
+        {
+        }
+
+    private:
+        bool m_isComplete;
+    };
+
+    static FloatRect quadVertexRect();
+    static void quadRectTransform(WebKit::WebTransformationMatrix* quadRectTransform, const WebKit::WebTransformationMatrix& quadTransform, const FloatRect& quadRect);
+    static void initializeMatrices(DrawingFrame&, const IntRect& drawRect, bool flipY);
+    static IntRect moveScissorToWindowSpace(const DrawingFrame&, FloatRect scissorRect);
+
+    bool haveCachedResources(int renderPassId) const;
+    static IntSize renderPassTextureSize(const CCRenderPass*);
+    static GC3Denum renderPassTextureFormat(const CCRenderPass*);
+
+    void drawRenderPass(DrawingFrame&, const CCRenderPass*);
+    bool useRenderPass(DrawingFrame&, const CCRenderPass*);
+
+    virtual void bindFramebufferToOutputSurface(DrawingFrame&) = 0;
+    virtual bool bindFramebufferToTexture(DrawingFrame&, const CCScopedTexture*, const IntRect& framebufferRect) = 0;
+    virtual void setDrawViewportSize(const IntSize&) = 0;
+    virtual void enableScissorTestRect(const IntRect& scissorRect) = 0;
+    virtual void disableScissorTest() = 0;
+    virtual void clearFramebuffer(DrawingFrame&) = 0;
+    virtual void drawQuad(DrawingFrame&, const CCDrawQuad*) = 0;
+    virtual void beginDrawingFrame(DrawingFrame&) = 0;
+    virtual void finishDrawingFrame(DrawingFrame&) = 0;
+
+    HashMap<int, OwnPtr<CachedTexture> > m_renderPassTextures;
+    CCResourceProvider* m_resourceProvider;
+};
+
+}
+
+#endif // CCDirectRenderer_h