[chromium] Move deferral-related logic out of Canvas2DLayerChromium
authorjamesr@google.com <jamesr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Jun 2012 23:35:54 +0000 (23:35 +0000)
committerjamesr@google.com <jamesr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Jun 2012 23:35:54 +0000 (23:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=86050

Reviewed by Stephen White.

Source/WebCore:

This removes Canvas2DLayerChromium and puts the deferral and double-buffering related logic in a new class,
Canvas2DLayerBridge, that uses TextureLayerChromium for compositing.  The bridge is responsible for managing the
front texture when double buffering is active, inserting the correct makeContextCurrent() and flush() calls on
the GraphicsContext3D and SkCanvas when appropriate, and owning the lifetime of the layer.

* WebCore.gypi:
* platform/graphics/chromium/Canvas2DLayerBridge.cpp: Added.
(WebCore):
(AcceleratedDeviceContext):
(WebCore::AcceleratedDeviceContext::AcceleratedDeviceContext):
(WebCore::AcceleratedDeviceContext::prepareForDraw):
(WebCore::Canvas2DLayerBridge::Canvas2DLayerBridge):
(WebCore::Canvas2DLayerBridge::~Canvas2DLayerBridge):
(WebCore::Canvas2DLayerBridge::skCanvas):
(WebCore::Canvas2DLayerBridge::prepareTexture):
(WebCore::Canvas2DLayerBridge::context):
(WebCore::Canvas2DLayerBridge::layer):
(WebCore::Canvas2DLayerBridge::contextAcquired):
* platform/graphics/chromium/Canvas2DLayerBridge.h: Added.
(WebCore):
(Canvas2DLayerBridge):
(WebCore::Canvas2DLayerBridge::create):
* platform/graphics/chromium/Canvas2DLayerChromium.cpp: Removed.
* platform/graphics/chromium/Canvas2DLayerChromium.h: Removed.
* platform/graphics/chromium/GraphicsLayerChromium.cpp:
* platform/graphics/chromium/ImageBufferDataSkia.h:
(WebCore):
(ImageBufferData):
* platform/graphics/chromium/TextureLayerChromium.cpp:
(WebCore::TextureLayerChromium::willModifyTexture):
    willModifyTexture() is called whenever the texture currently owned by the TextureLayerChromium will be
    modified by a system out of the compositor's control. It makes sure that the compositor does not attempt to
    draw with the potentially-modified texture until the next commit. For canvas, this is used when threading is
    enabled and a non-deferrable drawing command is invoked from JS.
(WebCore):
* platform/graphics/chromium/TextureLayerChromium.h:
(TextureLayerChromium):
* platform/graphics/chromium/cc/CCTextureUpdater.cpp:
(WebCore::CCTextureUpdater::hasMoreUpdates):
(WebCore::CCTextureUpdater::update):
(WebCore::CCTextureUpdater::clear):
* platform/graphics/chromium/cc/CCTextureUpdater.h:
(CCTextureUpdater):
* platform/graphics/skia/ImageBufferSkia.cpp:
(WebCore::createAcceleratedCanvas):
(WebCore::ImageBuffer::~ImageBuffer):
(WebCore::ImageBuffer::context):
(WebCore::ImageBuffer::platformLayer):

Source/WebKit/chromium:

* WebKit.gypi:
* tests/Canvas2DLayerBridgeTest.cpp: Renamed from tests/Canvas2DLayerChromiumTest
(Canvas2DLayerBridgeTest):
(Canvas2DLayerBridgeTest::fullLifecycleTest):

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

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.gypi
Source/WebCore/platform/graphics/chromium/Canvas2DLayerBridge.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/Canvas2DLayerBridge.h [new file with mode: 0644]
Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp [deleted file]
Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.h [deleted file]
Source/WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp
Source/WebCore/platform/graphics/chromium/ImageBufferDataSkia.h
Source/WebCore/platform/graphics/chromium/TextureLayerChromium.cpp
Source/WebCore/platform/graphics/chromium/TextureLayerChromium.h
Source/WebCore/platform/graphics/chromium/cc/CCTextureUpdater.cpp
Source/WebCore/platform/graphics/chromium/cc/CCTextureUpdater.h
Source/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/WebKit.gypi
Source/WebKit/chromium/tests/Canvas2DLayerBridgeTest.cpp [new file with mode: 0644]
Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp [deleted file]

index 640bc05a4d8ebc9e1419e5b5148f4492bbd19c69..ba44bade09833395592e109e4cdc0f909b0eb0bc 100644 (file)
@@ -1,3 +1,59 @@
+2012-06-05  James Robinson  <jamesr@chromium.org>
+
+        [chromium] Move deferral-related logic out of Canvas2DLayerChromium
+        https://bugs.webkit.org/show_bug.cgi?id=86050
+
+        Reviewed by Stephen White.
+
+        This removes Canvas2DLayerChromium and puts the deferral and double-buffering related logic in a new class,
+        Canvas2DLayerBridge, that uses TextureLayerChromium for compositing.  The bridge is responsible for managing the
+        front texture when double buffering is active, inserting the correct makeContextCurrent() and flush() calls on
+        the GraphicsContext3D and SkCanvas when appropriate, and owning the lifetime of the layer.
+
+        * WebCore.gypi:
+        * platform/graphics/chromium/Canvas2DLayerBridge.cpp: Added.
+        (WebCore):
+        (AcceleratedDeviceContext):
+        (WebCore::AcceleratedDeviceContext::AcceleratedDeviceContext):
+        (WebCore::AcceleratedDeviceContext::prepareForDraw):
+        (WebCore::Canvas2DLayerBridge::Canvas2DLayerBridge):
+        (WebCore::Canvas2DLayerBridge::~Canvas2DLayerBridge):
+        (WebCore::Canvas2DLayerBridge::skCanvas):
+        (WebCore::Canvas2DLayerBridge::prepareTexture):
+        (WebCore::Canvas2DLayerBridge::context):
+        (WebCore::Canvas2DLayerBridge::layer):
+        (WebCore::Canvas2DLayerBridge::contextAcquired):
+        * platform/graphics/chromium/Canvas2DLayerBridge.h: Added.
+        (WebCore):
+        (Canvas2DLayerBridge):
+        (WebCore::Canvas2DLayerBridge::create):
+        * platform/graphics/chromium/Canvas2DLayerChromium.cpp: Removed.
+        * platform/graphics/chromium/Canvas2DLayerChromium.h: Removed.
+        * platform/graphics/chromium/GraphicsLayerChromium.cpp:
+        * platform/graphics/chromium/ImageBufferDataSkia.h:
+        (WebCore):
+        (ImageBufferData):
+        * platform/graphics/chromium/TextureLayerChromium.cpp:
+        (WebCore::TextureLayerChromium::willModifyTexture):
+            willModifyTexture() is called whenever the texture currently owned by the TextureLayerChromium will be
+            modified by a system out of the compositor's control. It makes sure that the compositor does not attempt to
+            draw with the potentially-modified texture until the next commit. For canvas, this is used when threading is
+            enabled and a non-deferrable drawing command is invoked from JS.
+        (WebCore):
+        * platform/graphics/chromium/TextureLayerChromium.h:
+        (TextureLayerChromium):
+        * platform/graphics/chromium/cc/CCTextureUpdater.cpp:
+        (WebCore::CCTextureUpdater::hasMoreUpdates):
+        (WebCore::CCTextureUpdater::update):
+        (WebCore::CCTextureUpdater::clear):
+        * platform/graphics/chromium/cc/CCTextureUpdater.h:
+        (CCTextureUpdater):
+        * platform/graphics/skia/ImageBufferSkia.cpp:
+        (WebCore::createAcceleratedCanvas):
+        (WebCore::ImageBuffer::~ImageBuffer):
+        (WebCore::ImageBuffer::context):
+        (WebCore::ImageBuffer::platformLayer):
+
 2012-06-07  Patrick Gansterer  <paroga@webkit.org>
 
         Remove HAVE(PATH_BASED_BORDER_RADIUS_DRAWING)
index 992702721e6b10ee5115bdcc5a435dc598a51b8f..b3e6627ecd244f4d7c7374e2c4d6874875a3449f 100644 (file)
             'platform/graphics/chromium/BitmapCanvasLayerTextureUpdater.h',
             'platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.cpp',
             'platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.h',
-            'platform/graphics/chromium/Canvas2DLayerChromium.cpp',
-            'platform/graphics/chromium/Canvas2DLayerChromium.h',
-            'platform/graphics/chromium/CanvasLayerChromium.cpp',
-            'platform/graphics/chromium/CanvasLayerChromium.h',
+            'platform/graphics/chromium/Canvas2DLayerBridge.cpp',
+            'platform/graphics/chromium/Canvas2DLayerBridge.h',
             'platform/graphics/chromium/CanvasLayerTextureUpdater.cpp',
             'platform/graphics/chromium/CanvasLayerTextureUpdater.h',
             'platform/graphics/chromium/ContentLayerChromium.cpp',
diff --git a/Source/WebCore/platform/graphics/chromium/Canvas2DLayerBridge.cpp b/Source/WebCore/platform/graphics/chromium/Canvas2DLayerBridge.cpp
new file mode 100644 (file)
index 0000000..565a445
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ * 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 "Canvas2DLayerBridge.h"
+
+#include "GrContext.h"
+#include "GraphicsContext3D.h"
+#include "LayerRendererChromium.h" // For GLC() macro.
+#include "SkCanvas.h"
+#include "SkDeferredCanvas.h"
+#include "TextureLayerChromium.h"
+#include "cc/CCProxy.h"
+#include "cc/CCTextureUpdater.h"
+
+namespace WebCore {
+
+class AcceleratedDeviceContext : public SkDeferredCanvas::DeviceContext {
+public:
+    AcceleratedDeviceContext(GraphicsContext3D* context, TextureLayerChromium* layer, bool useDoubleBuffering)
+        : m_layer(layer)
+        , m_context()
+        , m_useDoubleBuffering(useDoubleBuffering)
+    {
+        ASSERT(context);
+        ASSERT(layer);
+        m_context = context;
+    }
+
+    virtual void prepareForDraw()
+    {
+        if (!m_useDoubleBuffering)
+            m_layer->willModifyTexture();
+        m_context->makeContextCurrent();
+    }
+
+private:
+    TextureLayerChromium* m_layer;
+    GraphicsContext3D* m_context;
+    bool m_useDoubleBuffering;
+};
+
+Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context, const IntSize& size, DeferralMode deferralMode, unsigned textureId)
+    : m_deferralMode(deferralMode)
+    // FIXME: We currently turn off double buffering when canvas rendering is
+    // deferred. What we should be doing is to use a smarter heuristic based
+    // on GPU resource monitoring and other factors to chose between single
+    // and double buffering.
+    , m_useDoubleBuffering(CCProxy::hasImplThread() && deferralMode == NonDeferred)
+    , m_frontBufferTexture(0)
+    , m_backBufferTexture(textureId)
+    , m_size(size)
+    , m_canvas(0)
+    , m_context(context)
+{
+    if (m_useDoubleBuffering) {
+        m_context->makeContextCurrent();
+        GLC(m_context.get(), m_frontBufferTexture = m_context->createTexture());
+        GLC(m_context.get(), m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_frontBufferTexture));
+        // Do basic linear filtering on resize.
+        GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR));
+        GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR));
+        // NPOT textures in GL ES only work when the wrap mode is set to GraphicsContext3D::CLAMP_TO_EDGE.
+        GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE));
+        GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE));
+        GLC(m_context.get(), m_context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, size.width(), size.height(), 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE));
+        if (GrContext* grContext = m_context->grContext())
+            grContext->resetContext();
+    }
+
+    m_layer = TextureLayerChromium::create(this);
+    m_layer->setTextureId(textureId);
+    m_layer->setRateLimitContext(!CCProxy::hasImplThread() || m_useDoubleBuffering);
+}
+
+
+Canvas2DLayerBridge::~Canvas2DLayerBridge()
+{
+    m_layer->setTextureId(0);
+    if (m_useDoubleBuffering) {
+        m_context->makeContextCurrent();
+        GLC(m_context.get(), m_context->deleteTexture(m_frontBufferTexture));
+        m_context->flush();
+    }
+}
+
+SkCanvas* Canvas2DLayerBridge::skCanvas(SkDevice* device)
+{
+    if (m_deferralMode == Deferred) {
+        SkAutoTUnref<AcceleratedDeviceContext> deviceContext(new AcceleratedDeviceContext(m_context.get(), m_layer.get(), m_useDoubleBuffering));
+        m_canvas = new SkDeferredCanvas(device, deviceContext.get());
+    } else
+        m_canvas = new SkCanvas(device);
+
+    return m_canvas;
+}
+
+
+unsigned Canvas2DLayerBridge::prepareTexture(CCTextureUpdater& updater)
+{
+    m_context->makeContextCurrent();
+
+    if (m_canvas) {
+        TRACE_EVENT0("cc", "Canvas2DLayerBridge::SkCanvas::flush");
+        m_canvas->flush();
+    }
+
+    m_context->flush();
+
+    if (m_useDoubleBuffering) {
+        updater.appendCopy(m_backBufferTexture, m_frontBufferTexture, m_size);
+        return m_frontBufferTexture;
+    }
+
+    return m_backBufferTexture;
+}
+
+GraphicsContext3D* Canvas2DLayerBridge::context()
+{
+    return m_context.get();
+}
+
+LayerChromium* Canvas2DLayerBridge::layer() const
+{
+    return m_layer.get();
+}
+
+void Canvas2DLayerBridge::contextAcquired()
+{
+    if (m_deferralMode == NonDeferred && !m_useDoubleBuffering)
+        m_layer->willModifyTexture();
+}
+
+}
+
diff --git a/Source/WebCore/platform/graphics/chromium/Canvas2DLayerBridge.h b/Source/WebCore/platform/graphics/chromium/Canvas2DLayerBridge.h
new file mode 100644 (file)
index 0000000..9ba5931
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * 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 Canvas2DLayerBridge_h
+#define Canvas2DLayerBridge_h
+
+#include "ImageBuffer.h" // For DeferralMode enum.
+#include "IntSize.h"
+#include "TextureLayerChromium.h"
+#include <wtf/PassOwnPtr.h>
+#include <wtf/RefPtr.h>
+
+class SkCanvas;
+class SkDevice;
+
+namespace WebCore {
+
+class LayerChromium;
+class TextureLayerChromium;
+
+class Canvas2DLayerBridge : public TextureLayerChromiumClient {
+    WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge);
+public:
+    static PassOwnPtr<Canvas2DLayerBridge> create(PassRefPtr<GraphicsContext3D> context, const IntSize& size, DeferralMode deferralMode, unsigned textureId)
+    {
+        return adoptPtr(new Canvas2DLayerBridge(context, size, deferralMode, textureId));
+    }
+
+    virtual ~Canvas2DLayerBridge();
+
+    // TextureLayerChromiumClient implementation.
+    virtual unsigned prepareTexture(CCTextureUpdater&) OVERRIDE;
+    virtual GraphicsContext3D* context() OVERRIDE;
+
+    SkCanvas* skCanvas(SkDevice*);
+    LayerChromium* layer() const;
+    void contextAcquired();
+
+private:
+    Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D>, const IntSize&, DeferralMode, unsigned textureId);
+
+    DeferralMode m_deferralMode;
+    bool m_useDoubleBuffering;
+    unsigned m_frontBufferTexture;
+    unsigned m_backBufferTexture;
+    IntSize m_size;
+    SkCanvas* m_canvas;
+    RefPtr<TextureLayerChromium> m_layer;
+    RefPtr<GraphicsContext3D> m_context;
+};
+
+}
+
+#endif
diff --git a/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp b/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp
deleted file mode 100644 (file)
index a479297..0000000
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright (C) 2010 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:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * 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.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
- * OWNER OR 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"
-
-#if USE(ACCELERATED_COMPOSITING)
-
-#include "Canvas2DLayerChromium.h"
-
-#include "Extensions3DChromium.h"
-#include "GraphicsContext3D.h"
-#include "LayerRendererChromium.h" // For the GLC() macro
-#include "TextureCopier.h"
-#include "cc/CCLayerTreeHost.h"
-#include "cc/CCTextureLayerImpl.h"
-#include "cc/CCTextureUpdater.h"
-
-#include "SkCanvas.h"
-
-namespace WebCore {
-
-PassRefPtr<Canvas2DLayerChromium> Canvas2DLayerChromium::create(PassRefPtr<GraphicsContext3D> context, const IntSize& size, DeferralMode deferralMode)
-{
-    return adoptRef(new Canvas2DLayerChromium(context, size, deferralMode));
-}
-
-Canvas2DLayerChromium::Canvas2DLayerChromium(PassRefPtr<GraphicsContext3D> context, const IntSize& size, DeferralMode deferralMode)
-    : CanvasLayerChromium()
-    , m_context(context)
-    , m_contextLost(false)
-    , m_size(size)
-    , m_backTextureId(0)
-    , m_canvas(0)
-    , m_deferralMode(deferralMode)
-{
-    // FIXME: We currently turn off double buffering when canvas rendering is
-    // deferred. What we should be doing is to use a smarter heuristic based
-    // on GPU resource monitoring and other factors to chose between single
-    // and double buffering.
-    m_useDoubleBuffering = CCProxy::hasImplThread() && deferralMode == NonDeferred;
-
-    // The threaded compositor is self rate-limiting when rendering
-    // to a single buffered canvas layer.
-    m_useRateLimiter = !CCProxy::hasImplThread() || m_useDoubleBuffering;
-}
-
-Canvas2DLayerChromium::~Canvas2DLayerChromium()
-{
-    setTextureId(0);
-    if (m_context && m_useRateLimiter && layerTreeHost())
-        layerTreeHost()->stopRateLimiter(m_context.get());
-}
-
-bool Canvas2DLayerChromium::drawingIntoImplThreadTexture() const
-{
-    return !m_useDoubleBuffering && CCProxy::hasImplThread() && layerTreeHost();
-}
-
-void Canvas2DLayerChromium::setTextureId(unsigned textureId)
-{
-    if (m_backTextureId == textureId)
-        return;
-
-    if (m_backTextureId && drawingIntoImplThreadTexture()) {
-        // The impl tree may be referencing the old m_backTexture, which may
-        // soon be deleted. We must make sure the layer tree on the impl thread
-        // is not drawn until the next commit, which will re-synchronize the
-        // layer trees.
-        layerTreeHost()->acquireLayerTextures();
-    }
-    m_backTextureId = textureId;
-    setNeedsCommit();
-}
-
-void Canvas2DLayerChromium::setNeedsDisplayRect(const FloatRect& dirtyRect)
-{
-    LayerChromium::setNeedsDisplayRect(dirtyRect);
-
-    if (m_useRateLimiter && layerTreeHost())
-        layerTreeHost()->startRateLimiter(m_context.get());
-}
-
-bool Canvas2DLayerChromium::drawsContent() const
-{
-    return LayerChromium::drawsContent() && m_backTextureId && !m_size.isEmpty()
-        && !m_contextLost;
-}
-
-void Canvas2DLayerChromium::setCanvas(SkCanvas* canvas)
-{
-    m_canvas = canvas;
-}
-
-void Canvas2DLayerChromium::update(CCTextureUpdater& updater, const CCOcclusionTracker*)
-{
-    TRACE_EVENT0("cc", "Canvas2DLayerChromium::update");
-    if (!drawsContent())
-        return;
-
-    if (m_useDoubleBuffering && layerTreeHost()) {
-        TextureManager* textureManager = layerTreeHost()->contentsTextureManager();
-        if (m_frontTexture)
-            m_frontTexture->setTextureManager(textureManager);
-        else
-            m_frontTexture = ManagedTexture::create(textureManager);
-        if (m_frontTexture->reserve(m_size, GraphicsContext3D::RGBA))
-            updater.appendManagedCopy(m_backTextureId, m_frontTexture.get(), m_size);
-    }
-
-    if (!needsDisplay())
-        return;
-
-    m_needsDisplay = false;
-
-    bool success = m_context->makeContextCurrent();
-    ASSERT_UNUSED(success, success);
-
-    m_contextLost = m_context->getExtensions()->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR;
-    if (m_contextLost)
-        return;
-
-    if (m_canvas) {
-        TRACE_EVENT0("cc", "SkCanvas::flush");
-        m_canvas->flush();
-    }
-
-    TRACE_EVENT0("cc", "GraphicsContext3D::flush");
-    m_context->flush();
-}
-
-void Canvas2DLayerChromium::layerWillDraw(WillDrawCondition condition) const
-{
-    if (drawingIntoImplThreadTexture()) {
-        if (condition == WillDrawUnconditionally || m_deferralMode == NonDeferred)
-            layerTreeHost()->acquireLayerTextures();
-    }
-}
-
-
-void Canvas2DLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
-{
-    CanvasLayerChromium::pushPropertiesTo(layer);
-
-    CCTextureLayerImpl* textureLayer = static_cast<CCTextureLayerImpl*>(layer);
-    if (m_useDoubleBuffering) {
-        if (m_frontTexture && m_frontTexture->isValid(m_size, GraphicsContext3D::RGBA))
-            textureLayer->setTextureId(m_frontTexture->textureId());
-        else
-            textureLayer->setTextureId(0);
-    } else
-        textureLayer->setTextureId(m_backTextureId);
-}
-
-}
-
-#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.h b/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.h
deleted file mode 100644 (file)
index ad3c686..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (C) 2010 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:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * 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.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
- * OWNER OR 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 Canvas2DLayerChromium_h
-#define Canvas2DLayerChromium_h
-
-#if USE(ACCELERATED_COMPOSITING)
-
-#include "CanvasLayerChromium.h"
-#include "ImageBuffer.h"
-#include "ManagedTexture.h"
-
-class SkCanvas;
-
-namespace WebCore {
-
-class GraphicsContext3D;
-class Region;
-
-// A layer containing an accelerated 2d canvas
-class Canvas2DLayerChromium : public CanvasLayerChromium {
-public:
-    enum WillDrawCondition {
-        WillDrawUnconditionally,
-        WillDrawIfLayerNotDeferred,
-    };
-
-    static PassRefPtr<Canvas2DLayerChromium> create(PassRefPtr<GraphicsContext3D>, const IntSize&, DeferralMode);
-    virtual ~Canvas2DLayerChromium();
-
-    void setTextureId(unsigned);
-
-    virtual void setNeedsDisplayRect(const FloatRect&) OVERRIDE;
-
-    virtual bool drawsContent() const OVERRIDE;
-    virtual void update(CCTextureUpdater&, const CCOcclusionTracker*) OVERRIDE;
-    virtual void pushPropertiesTo(CCLayerImpl*) OVERRIDE;
-
-    void setCanvas(SkCanvas*);
-    void layerWillDraw(WillDrawCondition) const;
-
-private:
-    Canvas2DLayerChromium(PassRefPtr<GraphicsContext3D>, const IntSize&, DeferralMode);
-    bool drawingIntoImplThreadTexture() const;
-
-    RefPtr<GraphicsContext3D> m_context;
-    bool m_contextLost;
-    IntSize m_size;
-    unsigned m_backTextureId;
-    // When m_useDoubleBuffering is true, the compositor will draw using a copy of the
-    // canvas' backing texture. This option should be used with the compositor doesn't
-    // synchronize its draws with the canvas updates.
-    bool m_useDoubleBuffering;
-    OwnPtr<ManagedTexture> m_frontTexture;
-    SkCanvas* m_canvas;
-    bool m_useRateLimiter;
-    DeferralMode m_deferralMode;
-};
-
-}
-#endif // USE(ACCELERATED_COMPOSITING)
-
-#endif
index 18433360951b2bfcea7cb11bbe9001ea985f4e01..1e0e1346fe64859bf339f39ecc7727a3049f6a75 100644 (file)
@@ -46,7 +46,6 @@
 #include "GraphicsLayerChromium.h"
 
 #include "AnimationIdVendor.h"
-#include "Canvas2DLayerChromium.h"
 #include "ContentLayerChromium.h"
 #include "FloatConversion.h"
 #include "FloatRect.h"
index c909304ce5e5bc407ea50c6d3ba2d6e08eb52dbe..6d49c55787f8d60d6f0bdb4f6189fc4b08aaab6e 100644 (file)
@@ -35,7 +35,7 @@
 namespace WebCore {
 
 #if USE(ACCELERATED_COMPOSITING)
-class Canvas2DLayerChromium;
+class Canvas2DLayerBridge;
 #endif
 
 class ImageBufferData {
@@ -45,7 +45,7 @@ public:
     OwnPtr<SkCanvas> m_canvas;
     PlatformContextSkia m_platformContext;
 #if USE(ACCELERATED_COMPOSITING)
-    RefPtr<Canvas2DLayerChromium> m_platformLayer;
+    OwnPtr<Canvas2DLayerBridge> m_layerBridge;
 #endif
 };
 
index 73844926417cccf16c61c550e42991be1bfea4f9..63ed244b03a238f9837e106ceefa89b78adb49ca 100644 (file)
@@ -103,6 +103,12 @@ void TextureLayerChromium::setTextureId(unsigned id)
     setNeedsCommit();
 }
 
+void TextureLayerChromium::willModifyTexture()
+{
+    if (layerTreeHost())
+        layerTreeHost()->acquireLayerTextures();
+}
+
 void TextureLayerChromium::setNeedsDisplayRect(const FloatRect& dirtyRect)
 {
     LayerChromium::setNeedsDisplayRect(dirtyRect);
index 43f492703ed93cd5c31c01e745e653d413c04f9b..a33d100a4d50c4500a3a2da3823be06f9bacacd4 100644 (file)
@@ -77,6 +77,8 @@ public:
     // Code path for plugins which supply their own texture ID.
     void setTextureId(unsigned);
 
+    void willModifyTexture();
+
     virtual void setNeedsDisplayRect(const FloatRect&) OVERRIDE;
 
     virtual void setLayerTreeHost(CCLayerTreeHost*) OVERRIDE;
index 05e9f54ddaecaab241e9b5a4adc5bf15c742d202..1fd0c736ee349f788abc8984efbe6bfba8b46273 100644 (file)
@@ -31,7 +31,6 @@
 
 #include "GraphicsContext3D.h"
 #include "LayerTextureUpdater.h"
-#include "ManagedTexture.h"
 #include "TextureCopier.h"
 #include "TextureUploader.h"
 
@@ -78,18 +77,9 @@ void CCTextureUpdater::appendCopy(unsigned sourceTexture, unsigned destTexture,
     m_copyEntries.append(copy);
 }
 
-void CCTextureUpdater::appendManagedCopy(unsigned sourceTexture, ManagedTexture* destTexture, const IntSize& size)
-{
-    ManagedCopyEntry copy;
-    copy.sourceTexture = sourceTexture;
-    copy.destTexture = destTexture;
-    copy.size = size;
-    m_managedCopyEntries.append(copy);
-}
-
 bool CCTextureUpdater::hasMoreUpdates() const
 {
-    return m_entries.size() || m_partialEntries.size() || m_copyEntries.size() || m_managedCopyEntries.size();
+    return m_entries.size() || m_partialEntries.size() || m_copyEntries.size();
 }
 
 void CCTextureUpdater::update(CCGraphicsContext* context, TextureAllocator* allocator, TextureCopier* copier, TextureUploader* uploader, size_t count)
@@ -134,15 +124,11 @@ void CCTextureUpdater::update(CCGraphicsContext* context, TextureAllocator* allo
         CopyEntry& copyEntry = m_copyEntries[index];
         copier->copyTexture(context, copyEntry.sourceTexture, copyEntry.destTexture, copyEntry.size);
     }
-    for (index = 0; index < m_managedCopyEntries.size(); ++index) {
-        ManagedCopyEntry& managedCopyEntry = m_managedCopyEntries[index];
-        managedCopyEntry.destTexture->allocate(allocator);
-        copier->copyTexture(context, managedCopyEntry.sourceTexture, managedCopyEntry.destTexture->textureId(), managedCopyEntry.size);
-    }
+
     // If we've performed any texture copies, we need to insert a flush here into the compositor context
     // before letting the main thread proceed as it may make draw calls to the source texture of one of
     // our copy operations.
-    if (m_copyEntries.size() || m_managedCopyEntries.size()) {
+    if (m_copyEntries.size()) {
         GraphicsContext3D* context3d = context->context3D();
         if (context3d)
             context3d->flush();
@@ -159,7 +145,6 @@ void CCTextureUpdater::clear()
     m_entries.clear();
     m_partialEntries.clear();
     m_copyEntries.clear();
-    m_managedCopyEntries.clear();
 }
 
 }
index 7c9fe2e308ca4f244c26761e83a84582bc3cd4dd..0f139f385c3a1d90c65f5b2ba02f28fc726e2594 100644 (file)
@@ -44,7 +44,6 @@ public:
     void appendUpdate(LayerTextureUpdater::Texture*, const IntRect& sourceRect, const IntRect& destRect);
     void appendPartialUpdate(LayerTextureUpdater::Texture*, const IntRect& sourceRect, const IntRect& destRect);
     void appendCopy(unsigned sourceTexture, unsigned destTexture, const IntSize&);
-    void appendManagedCopy(unsigned sourceTexture, ManagedTexture* destTexture, const IntSize&);
 
     bool hasMoreUpdates() const;
 
@@ -66,19 +65,12 @@ private:
         unsigned destTexture;
     };
 
-    struct ManagedCopyEntry {
-        IntSize size;
-        unsigned sourceTexture;
-        ManagedTexture* destTexture;
-    };
-
     static void appendUpdate(LayerTextureUpdater::Texture*, const IntRect& sourceRect, const IntRect& destRect, Vector<UpdateEntry>&);
 
     size_t m_entryIndex;
     Vector<UpdateEntry> m_entries;
     Vector<UpdateEntry> m_partialEntries;
     Vector<CopyEntry> m_copyEntries;
-    Vector<ManagedCopyEntry> m_managedCopyEntries;
 };
 
 }
index 8b086a0798b646f805f10a3410459473e3addbcd..22c3cffadac82c181ee160a971c8a4591d4b7c28 100644 (file)
@@ -51,7 +51,7 @@
 #include "WEBPImageEncoder.h"
 
 #if USE(ACCELERATED_COMPOSITING)
-#include "Canvas2DLayerChromium.h"
+#include "Canvas2DLayerBridge.h"
 #endif
 
 #include <wtf/text/WTFString.h>
@@ -69,30 +69,6 @@ ImageBufferData::ImageBufferData(const IntSize& size)
 {
 }
 
-#if USE(ACCELERATED_COMPOSITING)
-class AcceleratedDeviceContext : public SkDeferredCanvas::DeviceContext {
-public:
-    AcceleratedDeviceContext(GraphicsContext3D* context3D, Canvas2DLayerChromium* layer)
-        : m_platformLayer(layer)
-        , m_context3D()
-    {
-        ASSERT(context3D);
-        ASSERT(layer);
-        m_context3D = context3D;
-    }
-
-    virtual void prepareForDraw()
-    {
-        m_platformLayer->layerWillDraw(Canvas2DLayerChromium::WillDrawUnconditionally);
-        m_context3D->makeContextCurrent();
-    }
-
-private:
-    Canvas2DLayerChromium* m_platformLayer;
-    GraphicsContext3D* m_context3D;
-};
-#endif
-
 static SkCanvas* createAcceleratedCanvas(const IntSize& size, ImageBufferData* data, DeferralMode deferralMode)
 {
     RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get();
@@ -114,20 +90,12 @@ static SkCanvas* createAcceleratedCanvas(const IntSize& size, ImageBufferData* d
     SkCanvas* canvas;
     SkAutoTUnref<SkDevice> device(new SkGpuDevice(gr, texture.get()));
 #if USE(ACCELERATED_COMPOSITING)
-    data->m_platformLayer = Canvas2DLayerChromium::create(context3D, size, deferralMode);
-    if (deferralMode == Deferred) {
-        SkAutoTUnref<AcceleratedDeviceContext> deviceContext(new AcceleratedDeviceContext(context3D.get(), data->m_platformLayer.get()));
-        canvas = new SkDeferredCanvas(device.get(), deviceContext.get());
-    } else
-        canvas = new SkCanvas(device.get());
+    data->m_layerBridge = Canvas2DLayerBridge::create(context3D.release(), size, deferralMode, texture.get()->getTextureHandle());
+    canvas = data->m_layerBridge->skCanvas(device.get());
 #else
     canvas = new SkCanvas(device.get());
 #endif
     data->m_platformContext.setAccelerated(true);
-#if USE(ACCELERATED_COMPOSITING)
-    data->m_platformLayer->setTextureId(texture.get()->getTextureHandle());
-    data->m_platformLayer->setCanvas(canvas);
-#endif
     return canvas;
 }
 
@@ -174,17 +142,16 @@ ImageBuffer::ImageBuffer(const IntSize& size, float /* resolutionScale */, Color
 
 ImageBuffer::~ImageBuffer()
 {
-#if USE(ACCELERATED_COMPOSITING)
-    if (m_data.m_platformLayer)
-        m_data.m_platformLayer->setTextureId(0);
-#endif
 }
 
 GraphicsContext* ImageBuffer::context() const
 {
 #if USE(ACCELERATED_COMPOSITING)
-    if (m_data.m_platformLayer)
-        m_data.m_platformLayer->layerWillDraw(Canvas2DLayerChromium::WillDrawIfLayerNotDeferred);
+    if (m_data.m_layerBridge) {
+        // We're using context acquisition as a signal that someone is about to render into our buffer and we need
+        // to be ready. This isn't logically const-correct, hence the cast.
+        const_cast<Canvas2DLayerBridge*>(m_data.m_layerBridge.get())->contextAcquired();
+    }
 #endif
     return m_context.get();
 }
@@ -196,7 +163,7 @@ PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyBehavior) const
 
 PlatformLayer* ImageBuffer::platformLayer() const
 {
-    return m_data.m_platformLayer.get();
+    return m_data.m_layerBridge ? m_data.m_layerBridge->layer() : 0;
 }
 
 void ImageBuffer::clip(GraphicsContext* context, const FloatRect& rect) const
index e44171f83914de7a4bc96655a7b566e963ede095..c2cacc1de4887f9a0d91321c4335bc3c34904297 100644 (file)
@@ -1,3 +1,15 @@
+2012-06-05  James Robinson  <jamesr@chromium.org>
+
+        [chromium] Move deferral-related logic out of Canvas2DLayerChromium
+        https://bugs.webkit.org/show_bug.cgi?id=86050
+
+        Reviewed by Stephen White.
+
+        * WebKit.gypi:
+        * tests/Canvas2DLayerBridgeTest.cpp: Renamed from tests/Canvas2DLayerChromiumTest
+        (Canvas2DLayerBridgeTest):
+        (Canvas2DLayerBridgeTest::fullLifecycleTest):
+
 2012-06-07  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r119744.
index 1c11f2d7906c90e38a189bbe4d37b2b77ccc7323..f23154ae40457b7e8079973873194bca20a67b71 100644 (file)
@@ -59,7 +59,7 @@
         'webkit_unittest_files': [
             'tests/ArenaTestHelpers.h',
             'tests/AssociatedURLLoaderTest.cpp',
-            'tests/Canvas2DLayerChromiumTest.cpp',
+            'tests/Canvas2DLayerBridgeTest.cpp',
             'tests/CCActiveAnimationTest.cpp',
             'tests/CCAnimationTestCommon.cpp',
             'tests/CCAnimationTestCommon.h',
diff --git a/Source/WebKit/chromium/tests/Canvas2DLayerBridgeTest.cpp b/Source/WebKit/chromium/tests/Canvas2DLayerBridgeTest.cpp
new file mode 100644 (file)
index 0000000..0e1ef20
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+#include "config.h"
+
+#include "Canvas2DLayerBridge.h"
+
+#include "FakeWebGraphicsContext3D.h"
+#include "GraphicsContext3DPrivate.h"
+#include "ImageBuffer.h"
+#include "TextureCopier.h"
+#include "TextureManager.h"
+#include "WebCompositor.h"
+#include "WebKit.h"
+#include "cc/CCGraphicsContext.h"
+#include "cc/CCTextureUpdater.h"
+#include "platform/WebKitPlatformSupport.h"
+#include "platform/WebThread.h"
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <wtf/RefPtr.h>
+
+using namespace WebCore;
+using namespace WebKit;
+using testing::InSequence;
+using testing::Return;
+using testing::Test;
+
+namespace {
+
+class MockCanvasContext : public FakeWebGraphicsContext3D {
+public:
+    MOCK_METHOD0(flush, void(void));
+    MOCK_METHOD0(createTexture, unsigned(void));
+    MOCK_METHOD1(deleteTexture, void(unsigned));
+
+    virtual GrGLInterface* onCreateGrGLInterface() OVERRIDE { return 0; }
+};
+
+class MockTextureCopier : public TextureCopier {
+public:
+    MOCK_METHOD4(copyTexture, void(CCGraphicsContext*, unsigned, unsigned, const IntSize&));
+};
+
+} // namespace
+
+enum ThreadMode {
+    SingleThreaded, Threaded
+};
+
+class Canvas2DLayerBridgeTest : public Test {
+protected:
+    void fullLifecycleTest(ThreadMode threadMode, DeferralMode deferralMode)
+    {
+        GraphicsContext3D::Attributes attrs;
+
+        RefPtr<GraphicsContext3D> mainContext = GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new MockCanvasContext()), GraphicsContext3D::RenderDirectlyToHostWindow);
+        RefPtr<CCGraphicsContext> ccMainContext = CCGraphicsContext::create3D(mainContext);
+        RefPtr<GraphicsContext3D> implContext = GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new MockCanvasContext()), GraphicsContext3D::RenderDirectlyToHostWindow);
+        RefPtr<CCGraphicsContext> ccImplContext = CCGraphicsContext::create3D(implContext);
+
+        MockCanvasContext& mainMock = *static_cast<MockCanvasContext*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(mainContext.get()));
+        MockCanvasContext& implMock = *static_cast<MockCanvasContext*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(implContext.get()));
+
+        MockTextureCopier copierMock;
+        CCTextureUpdater updater;
+
+        const IntSize size(300, 150);
+
+        OwnPtr<WebThread> thread;
+        if (threadMode == Threaded)
+            thread = adoptPtr(WebKit::Platform::current()->createThread("Canvas2DLayerBridgeTest"));
+        WebCompositor::initialize(thread.get());
+
+        WebGLId backTextureId = 1;
+        WebGLId frontTextureId = 1;
+
+        // Threaded and non deferred canvases are double buffered.
+        if (threadMode == Threaded && deferralMode == NonDeferred) {
+            frontTextureId = 2;
+            // Create texture (on the main thread) and do the copy (on the impl thread).
+            EXPECT_CALL(mainMock, createTexture()).WillOnce(Return(frontTextureId));
+        }
+
+        OwnPtr<Canvas2DLayerBridge> bridge = Canvas2DLayerBridge::create(mainContext.get(), size, deferralMode, backTextureId);
+
+        ::testing::Mock::VerifyAndClearExpectations(&mainMock);
+
+        EXPECT_CALL(mainMock, flush());
+        EXPECT_EQ(frontTextureId, bridge->prepareTexture(updater));
+        ::testing::Mock::VerifyAndClearExpectations(&mainMock);
+
+        if (threadMode == Threaded && deferralMode == NonDeferred) {
+            EXPECT_CALL(copierMock, copyTexture(ccImplContext.get(), backTextureId, frontTextureId, size));
+            EXPECT_CALL(implMock, flush());
+        }
+        updater.update(ccImplContext.get(), 0, &copierMock, 0, 100);
+        ::testing::Mock::VerifyAndClearExpectations(&implMock);
+
+        if (threadMode == Threaded && deferralMode == NonDeferred) {
+            EXPECT_CALL(mainMock, deleteTexture(frontTextureId));
+            EXPECT_CALL(mainMock, flush());
+        }
+        bridge.clear();
+        ::testing::Mock::VerifyAndClearExpectations(&implMock);
+
+        WebCompositor::shutdown();
+    }
+};
+
+namespace {
+
+TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreadedDeferred)
+{
+    fullLifecycleTest(SingleThreaded, NonDeferred);
+}
+
+TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreadedNonDeferred)
+{
+    fullLifecycleTest(SingleThreaded, Deferred);
+}
+
+TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleThreadedNonDeferred)
+{
+    fullLifecycleTest(Threaded, NonDeferred);
+}
+
+TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleThreadedDeferred)
+{
+    fullLifecycleTest(Threaded, Deferred);
+}
+
+} // namespace
+
diff --git a/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp b/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp
deleted file mode 100644 (file)
index a565146..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Copyright (C) 2011 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.
- */
-
-#include "config.h"
-
-#include "Canvas2DLayerChromium.h"
-
-#include "CCSchedulerTestCommon.h"
-#include "FakeCCLayerTreeHostClient.h"
-#include "FakeWebGraphicsContext3D.h"
-#include "GraphicsContext3DPrivate.h"
-#include "Region.h"
-#include "TextureCopier.h"
-#include "TextureManager.h"
-#include "WebCompositor.h"
-#include "WebKit.h"
-#include "cc/CCSingleThreadProxy.h"
-#include "cc/CCTextureLayerImpl.h"
-#include "cc/CCTextureUpdater.h"
-#include "platform/WebKitPlatformSupport.h"
-#include "platform/WebThread.h"
-
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
-#include <wtf/RefPtr.h>
-
-using namespace WebCore;
-using namespace WebKit;
-using namespace WebKitTests;
-using testing::InSequence;
-using testing::Return;
-using testing::Test;
-
-namespace {
-
-class FakeCCLayerTreeHost : public CCLayerTreeHost {
-public:
-    static PassOwnPtr<FakeCCLayerTreeHost> create()
-    {
-        OwnPtr<FakeCCLayerTreeHost> host(adoptPtr(new FakeCCLayerTreeHost));
-        host->initialize();
-        return host.release();
-    }
-
-private:
-    FakeCCLayerTreeHost()
-        : CCLayerTreeHost(&m_client, CCSettings())
-    {
-    }
-
-    FakeCCLayerTreeHostClient m_client;
-};
-
-class MockCanvasContext : public FakeWebGraphicsContext3D {
-public:
-    MOCK_METHOD0(flush, void(void));
-};
-
-class MockTextureAllocator : public TextureAllocator {
-public:
-    MOCK_METHOD2(createTexture, unsigned(const IntSize&, GC3Denum));
-    MOCK_METHOD3(deleteTexture, void(unsigned, const IntSize&, GC3Denum));
-};
-
-class MockTextureCopier : public TextureCopier {
-public:
-    MOCK_METHOD4(copyTexture, void(CCGraphicsContext*, unsigned, unsigned, const IntSize&));
-};
-
-class MockTextureUploader : public TextureUploader {
-public:
-    MOCK_METHOD0(isBusy, bool());
-    MOCK_METHOD0(beginUploads, void());
-    MOCK_METHOD0(endUploads, void());
-    MOCK_METHOD5(uploadTexture, void(CCGraphicsContext*, LayerTextureUpdater::Texture*, TextureAllocator*, const IntRect, const IntRect));
-};
-
-} // namespace
-
-class Canvas2DLayerChromiumTest : public Test {
-protected:
-    void fullLifecycleTest(bool threaded, bool deferred)
-    {
-        GraphicsContext3D::Attributes attrs;
-
-        RefPtr<GraphicsContext3D> mainContext = GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new MockCanvasContext()), GraphicsContext3D::RenderDirectlyToHostWindow);
-        RefPtr<CCGraphicsContext> ccMainContext = CCGraphicsContext::create3D(mainContext);
-        RefPtr<GraphicsContext3D> implContext = GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new MockCanvasContext()), GraphicsContext3D::RenderDirectlyToHostWindow);
-        RefPtr<CCGraphicsContext> ccImplContext = CCGraphicsContext::create3D(implContext);
-
-        MockCanvasContext& mainMock = *static_cast<MockCanvasContext*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(mainContext.get()));
-        MockCanvasContext& implMock = *static_cast<MockCanvasContext*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(implContext.get()));
-
-        MockTextureAllocator allocatorMock;
-        MockTextureCopier copierMock;
-        MockTextureUploader uploaderMock;
-        CCTextureUpdater updater;
-
-        const IntSize size(300, 150);
-
-        OwnPtr<WebThread> thread;
-        if (threaded)
-            thread = adoptPtr(WebKit::Platform::current()->createThread("Canvas2DLayerChromiumTest"));
-        WebCompositor::initialize(thread.get());
-
-        OwnPtr<FakeCCLayerTreeHost> layerTreeHost(FakeCCLayerTreeHost::create());
-        // Force an update, so that we get a valid TextureManager.
-        layerTreeHost->updateLayers(updater);
-
-        const WebGLId backTextureId = 1;
-        const WebGLId frontTextureId = 2;
-        {
-            InSequence sequence;
-
-            // Paint canvas contents on the main thread.
-            EXPECT_CALL(mainMock, flush());
-
-            // Note that the canvas backing texture is doublebuffered only when using the threaded
-            // compositor and not using deferred canvas rendering
-            if (threaded && !deferred) {
-                // Create texture and do the copy (on the impl thread).
-                EXPECT_CALL(allocatorMock, createTexture(size, GraphicsContext3D::RGBA))
-                    .WillOnce(Return(frontTextureId));
-                EXPECT_CALL(copierMock, copyTexture(ccImplContext.get(), backTextureId, frontTextureId, size));
-                EXPECT_CALL(implMock, flush());
-
-                // Teardown TextureManager.
-                EXPECT_CALL(allocatorMock, deleteTexture(frontTextureId, size, GraphicsContext3D::RGBA));
-            }
-        }
-
-        RefPtr<Canvas2DLayerChromium> canvas = Canvas2DLayerChromium::create(mainContext.get(), size, deferred ? Deferred : NonDeferred);
-        canvas->setIsDrawable(true);
-        canvas->setLayerTreeHost(layerTreeHost.get());
-        canvas->setBounds(IntSize(600, 300));
-        canvas->setTextureId(backTextureId);
-
-        canvas->setNeedsDisplay();
-        EXPECT_TRUE(canvas->needsDisplay());
-        canvas->update(updater, 0);
-        EXPECT_FALSE(canvas->needsDisplay());
-        {
-            DebugScopedSetImplThread scopedImplThread;
-
-            OwnPtr<CCLayerImpl> layerImpl = canvas->createCCLayerImpl();
-            EXPECT_EQ(0u, static_cast<CCTextureLayerImpl*>(layerImpl.get())->textureId());
-
-            updater.update(ccImplContext.get(), &allocatorMock, &copierMock, &uploaderMock, 1);
-            canvas->pushPropertiesTo(layerImpl.get());
-
-            if (threaded && !deferred)
-                EXPECT_EQ(frontTextureId, static_cast<CCTextureLayerImpl*>(layerImpl.get())->textureId());
-            else
-                EXPECT_EQ(backTextureId, static_cast<CCTextureLayerImpl*>(layerImpl.get())->textureId());
-        }
-        canvas.clear();
-        layerTreeHost->contentsTextureManager()->reduceMemoryToLimit(0);
-        layerTreeHost->contentsTextureManager()->deleteEvictedTextures(&allocatorMock);
-        layerTreeHost.clear();
-        WebCompositor::shutdown();
-    }
-};
-
-namespace {
-
-TEST_F(Canvas2DLayerChromiumTest, testFullLifecycleSingleThread)
-{
-    fullLifecycleTest(false, false);
-}
-
-TEST_F(Canvas2DLayerChromiumTest, testFullLifecycleThreaded)
-{
-    fullLifecycleTest(true, false);
-}
-
-TEST_F(Canvas2DLayerChromiumTest, testFullLifecycleSingleThreadDeferred)
-{
-    fullLifecycleTest(false, true);
-}
-
-TEST_F(Canvas2DLayerChromiumTest, testFullLifecycleThreadedDeferred)
-{
-    fullLifecycleTest(true, true);
-}
-
-} // namespace