[chromium] Split off tiled layer constructs for unit tests into a common header
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Mar 2012 18:18:47 +0000 (18:18 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Mar 2012 18:18:47 +0000 (18:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=82425

Patch by Dana Jansens <danakj@chromium.org> on 2012-03-29
Reviewed by Adrienne Walker.

* WebKit.gypi:
* tests/CCTiledLayerTestCommon.cpp: Added.
(WebKitTests):
(WebKitTests::FakeLayerTextureUpdater::Texture::Texture):
(WebKitTests::FakeLayerTextureUpdater::Texture::~Texture):
(WebKitTests::FakeLayerTextureUpdater::Texture::updateRect):
(WebKitTests::FakeLayerTextureUpdater::Texture::prepareRect):
(WebKitTests::FakeLayerTextureUpdater::FakeLayerTextureUpdater):
(WebKitTests::FakeLayerTextureUpdater::~FakeLayerTextureUpdater):
(WebKitTests::FakeLayerTextureUpdater::prepareToUpdate):
(WebKitTests::FakeLayerTextureUpdater::setRectToInvalidate):
(WebKitTests::FakeLayerTextureUpdater::createTexture):
(WebKitTests::FakeCCTiledLayerImpl::FakeCCTiledLayerImpl):
(WebKitTests::FakeCCTiledLayerImpl::~FakeCCTiledLayerImpl):
(WebKitTests::FakeTiledLayerChromium::FakeTiledLayerChromium):
(WebKitTests::FakeTiledLayerChromium::~FakeTiledLayerChromium):
(WebKitTests::FakeTiledLayerChromium::setNeedsDisplayRect):
(WebKitTests::FakeTiledLayerChromium::paintContentsIfDirty):
(WebKitTests::FakeTiledLayerWithScaledBounds::FakeTiledLayerWithScaledBounds):
(WebKitTests::FakeCCTextureUpdater::FakeCCTextureUpdater):
* tests/CCTiledLayerTestCommon.h: Added.
(WebKitTests):
(FakeLayerTextureUpdater):
(Texture):
(WebKitTests::FakeLayerTextureUpdater::sampledTexelFormat):
(WebKitTests::FakeLayerTextureUpdater::lastUpdateRect):
(WebKitTests::FakeLayerTextureUpdater::prepareCount):
(WebKitTests::FakeLayerTextureUpdater::clearPrepareCount):
(WebKitTests::FakeLayerTextureUpdater::updateCount):
(WebKitTests::FakeLayerTextureUpdater::clearUpdateCount):
(WebKitTests::FakeLayerTextureUpdater::updateRect):
(WebKitTests::FakeLayerTextureUpdater::prepareRectCount):
(WebKitTests::FakeLayerTextureUpdater::clearPrepareRectCount):
(WebKitTests::FakeLayerTextureUpdater::prepareRect):
(WebKitTests::FakeLayerTextureUpdater::setOpaquePaintRect):
(FakeCCTiledLayerImpl):
(FakeTiledLayerChromium):
(WebKitTests::FakeTiledLayerChromium::tileSize):
(WebKitTests::FakeTiledLayerChromium::lastNeedsDisplayRect):
(WebKitTests::FakeTiledLayerChromium::textureManager):
(WebKitTests::FakeTiledLayerChromium::fakeLayerTextureUpdater):
(WebKitTests::FakeTiledLayerChromium::updateRect):
(WebKitTests::FakeTiledLayerChromium::textureUpdater):
(WebKitTests::FakeTiledLayerChromium::createTextureUpdaterIfNeeded):
(FakeTiledLayerWithScaledBounds):
(WebKitTests::FakeTiledLayerWithScaledBounds::setContentBounds):
(WebKitTests::FakeTiledLayerWithScaledBounds::contentBounds):
(FakeTextureAllocator):
(WebKitTests::FakeTextureAllocator::createTexture):
(WebKitTests::FakeTextureAllocator::deleteTexture):
(FakeTextureCopier):
(WebKitTests::FakeTextureCopier::copyTexture):
(FakeCCTextureUpdater):
(WebKitTests::FakeCCTextureUpdater::textureAllocator):
* tests/TextureManagerTest.cpp:
* tests/TiledLayerChromiumTest.cpp:

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

Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/WebKit.gypi
Source/WebKit/chromium/tests/CCTiledLayerTestCommon.cpp [new file with mode: 0644]
Source/WebKit/chromium/tests/CCTiledLayerTestCommon.h [new file with mode: 0644]
Source/WebKit/chromium/tests/TextureManagerTest.cpp
Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp

index e53342f..88bee44 100644 (file)
@@ -1,5 +1,69 @@
 2012-03-29  Dana Jansens  <danakj@chromium.org>
 
+        [chromium] Split off tiled layer constructs for unit tests into a common header
+        https://bugs.webkit.org/show_bug.cgi?id=82425
+
+        Reviewed by Adrienne Walker.
+
+        * WebKit.gypi:
+        * tests/CCTiledLayerTestCommon.cpp: Added.
+        (WebKitTests):
+        (WebKitTests::FakeLayerTextureUpdater::Texture::Texture):
+        (WebKitTests::FakeLayerTextureUpdater::Texture::~Texture):
+        (WebKitTests::FakeLayerTextureUpdater::Texture::updateRect):
+        (WebKitTests::FakeLayerTextureUpdater::Texture::prepareRect):
+        (WebKitTests::FakeLayerTextureUpdater::FakeLayerTextureUpdater):
+        (WebKitTests::FakeLayerTextureUpdater::~FakeLayerTextureUpdater):
+        (WebKitTests::FakeLayerTextureUpdater::prepareToUpdate):
+        (WebKitTests::FakeLayerTextureUpdater::setRectToInvalidate):
+        (WebKitTests::FakeLayerTextureUpdater::createTexture):
+        (WebKitTests::FakeCCTiledLayerImpl::FakeCCTiledLayerImpl):
+        (WebKitTests::FakeCCTiledLayerImpl::~FakeCCTiledLayerImpl):
+        (WebKitTests::FakeTiledLayerChromium::FakeTiledLayerChromium):
+        (WebKitTests::FakeTiledLayerChromium::~FakeTiledLayerChromium):
+        (WebKitTests::FakeTiledLayerChromium::setNeedsDisplayRect):
+        (WebKitTests::FakeTiledLayerChromium::paintContentsIfDirty):
+        (WebKitTests::FakeTiledLayerWithScaledBounds::FakeTiledLayerWithScaledBounds):
+        (WebKitTests::FakeCCTextureUpdater::FakeCCTextureUpdater):
+        * tests/CCTiledLayerTestCommon.h: Added.
+        (WebKitTests):
+        (FakeLayerTextureUpdater):
+        (Texture):
+        (WebKitTests::FakeLayerTextureUpdater::sampledTexelFormat):
+        (WebKitTests::FakeLayerTextureUpdater::lastUpdateRect):
+        (WebKitTests::FakeLayerTextureUpdater::prepareCount):
+        (WebKitTests::FakeLayerTextureUpdater::clearPrepareCount):
+        (WebKitTests::FakeLayerTextureUpdater::updateCount):
+        (WebKitTests::FakeLayerTextureUpdater::clearUpdateCount):
+        (WebKitTests::FakeLayerTextureUpdater::updateRect):
+        (WebKitTests::FakeLayerTextureUpdater::prepareRectCount):
+        (WebKitTests::FakeLayerTextureUpdater::clearPrepareRectCount):
+        (WebKitTests::FakeLayerTextureUpdater::prepareRect):
+        (WebKitTests::FakeLayerTextureUpdater::setOpaquePaintRect):
+        (FakeCCTiledLayerImpl):
+        (FakeTiledLayerChromium):
+        (WebKitTests::FakeTiledLayerChromium::tileSize):
+        (WebKitTests::FakeTiledLayerChromium::lastNeedsDisplayRect):
+        (WebKitTests::FakeTiledLayerChromium::textureManager):
+        (WebKitTests::FakeTiledLayerChromium::fakeLayerTextureUpdater):
+        (WebKitTests::FakeTiledLayerChromium::updateRect):
+        (WebKitTests::FakeTiledLayerChromium::textureUpdater):
+        (WebKitTests::FakeTiledLayerChromium::createTextureUpdaterIfNeeded):
+        (FakeTiledLayerWithScaledBounds):
+        (WebKitTests::FakeTiledLayerWithScaledBounds::setContentBounds):
+        (WebKitTests::FakeTiledLayerWithScaledBounds::contentBounds):
+        (FakeTextureAllocator):
+        (WebKitTests::FakeTextureAllocator::createTexture):
+        (WebKitTests::FakeTextureAllocator::deleteTexture):
+        (FakeTextureCopier):
+        (WebKitTests::FakeTextureCopier::copyTexture):
+        (FakeCCTextureUpdater):
+        (WebKitTests::FakeCCTextureUpdater::textureAllocator):
+        * tests/TextureManagerTest.cpp:
+        * tests/TiledLayerChromiumTest.cpp:
+
+2012-03-29  Dana Jansens  <danakj@chromium.org>
+
         [chromium] Remove unneeded code+fixmes from CCOcclusionTracker
         https://bugs.webkit.org/show_bug.cgi?id=82380
 
index eb08cca..9abc1f8 100644 (file)
@@ -87,6 +87,8 @@
             'tests/CCSchedulerTest.cpp',
             'tests/CCSolidColorLayerImplTest.cpp',
             'tests/CCTiledLayerImplTest.cpp',
+            'tests/CCTiledLayerTestCommon.h',
+            'tests/CCTiledLayerTestCommon.cpp',
             'tests/CCThreadTaskTest.cpp',
             'tests/CCTimerTest.cpp',
             'tests/ClipboardChromiumTest.cpp',
diff --git a/Source/WebKit/chromium/tests/CCTiledLayerTestCommon.cpp b/Source/WebKit/chromium/tests/CCTiledLayerTestCommon.cpp
new file mode 100644 (file)
index 0000000..603d421
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+#include "config.h"
+
+#include "CCTiledLayerTestCommon.h"
+
+using namespace WebCore;
+
+namespace WebKitTests {
+
+FakeLayerTextureUpdater::Texture::Texture(FakeLayerTextureUpdater* layer, PassOwnPtr<ManagedTexture> texture)
+    : LayerTextureUpdater::Texture(texture)
+    , m_layer(layer)
+{
+}
+
+FakeLayerTextureUpdater::Texture::~Texture()
+{
+}
+
+void FakeLayerTextureUpdater::Texture::updateRect(GraphicsContext3D*, TextureAllocator* allocator, const IntRect&, const IntRect&)
+{
+    if (allocator)
+        texture()->allocate(allocator);
+    m_layer->updateRect();
+}
+
+void FakeLayerTextureUpdater::Texture::prepareRect(const IntRect&)
+{
+    m_layer->prepareRect();
+}
+
+FakeLayerTextureUpdater::FakeLayerTextureUpdater()
+    : m_prepareCount(0)
+    , m_updateCount(0)
+    , m_prepareRectCount(0)
+{
+}
+
+FakeLayerTextureUpdater::~FakeLayerTextureUpdater()
+{
+}
+
+void FakeLayerTextureUpdater::prepareToUpdate(const IntRect& contentRect, const IntSize&, int, float, IntRect* resultingOpaqueRect)
+{
+    m_prepareCount++;
+    m_lastUpdateRect = contentRect;
+    if (!m_rectToInvalidate.isEmpty()) {
+        m_layer->invalidateRect(m_rectToInvalidate);
+        m_rectToInvalidate = IntRect();
+        m_layer = 0;
+    }
+    *resultingOpaqueRect = m_opaquePaintRect;
+}
+
+void FakeLayerTextureUpdater::setRectToInvalidate(const IntRect& rect, FakeTiledLayerChromium* layer)
+{
+    m_rectToInvalidate = rect;
+    m_layer = layer;
+}
+
+PassOwnPtr<LayerTextureUpdater::Texture> FakeLayerTextureUpdater::createTexture(TextureManager* manager)
+{
+    return adoptPtr(new Texture(this, ManagedTexture::create(manager)));
+}
+
+FakeCCTiledLayerImpl::FakeCCTiledLayerImpl(int id)
+    : CCTiledLayerImpl(id)
+{
+}
+
+FakeCCTiledLayerImpl::~FakeCCTiledLayerImpl()
+{
+}
+
+FakeTiledLayerChromium::FakeTiledLayerChromium(TextureManager* textureManager)
+    : TiledLayerChromium()
+    , m_fakeTextureUpdater(adoptRef(new FakeLayerTextureUpdater))
+    , m_textureManager(textureManager)
+{
+    setTileSize(tileSize());
+    setTextureFormat(GraphicsContext3D::RGBA);
+    setBorderTexelOption(CCLayerTilingData::NoBorderTexels);
+    setIsDrawable(true); // So that we don't get false positives if any of these tests expect to return false from drawsContent() for other reasons.
+}
+
+FakeTiledLayerChromium::~FakeTiledLayerChromium()
+{
+}
+
+void FakeTiledLayerChromium::setNeedsDisplayRect(const FloatRect& rect)
+{
+    m_lastNeedsDisplayRect = rect;
+    TiledLayerChromium::setNeedsDisplayRect(rect);
+}
+
+void FakeTiledLayerChromium::paintContentsIfDirty(const CCOcclusionTracker* occlusion)
+{
+    prepareToUpdate(visibleLayerRect(), occlusion);
+}
+
+FakeTiledLayerWithScaledBounds::FakeTiledLayerWithScaledBounds(TextureManager* textureManager)
+    : FakeTiledLayerChromium(textureManager)
+{
+}
+
+FakeCCTextureUpdater::FakeCCTextureUpdater()
+    : CCTextureUpdater(&m_textureAllocator, &m_textureCopier)
+{
+}
+
+} // namespace
diff --git a/Source/WebKit/chromium/tests/CCTiledLayerTestCommon.h b/Source/WebKit/chromium/tests/CCTiledLayerTestCommon.h
new file mode 100644 (file)
index 0000000..efb8ae8
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * 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 CCTiledLayerTestCommon_h
+#define CCTiledLayerTestCommon_h
+
+#include "GraphicsContext3D.h"
+#include "IntRect.h"
+#include "IntSize.h"
+#include "LayerTextureUpdater.h"
+#include "Region.h"
+#include "TextureCopier.h"
+#include "TextureManager.h"
+#include "TiledLayerChromium.h"
+#include "cc/CCTextureUpdater.h"
+#include "cc/CCTiledLayerImpl.h"
+
+namespace WebKitTests {
+
+class FakeTiledLayerChromium;
+
+class FakeLayerTextureUpdater : public WebCore::LayerTextureUpdater {
+public:
+    class Texture : public WebCore::LayerTextureUpdater::Texture {
+    public:
+        Texture(FakeLayerTextureUpdater*, PassOwnPtr<WebCore::ManagedTexture>);
+        virtual ~Texture();
+
+        virtual void updateRect(WebCore::GraphicsContext3D*, WebCore::TextureAllocator* , const WebCore::IntRect&, const WebCore::IntRect&);
+        virtual void prepareRect(const WebCore::IntRect&);
+
+    private:
+        FakeLayerTextureUpdater* m_layer;
+    };
+
+    FakeLayerTextureUpdater();
+    virtual ~FakeLayerTextureUpdater();
+
+    virtual PassOwnPtr<WebCore::LayerTextureUpdater::Texture> createTexture(WebCore::TextureManager*);
+    virtual SampledTexelFormat sampledTexelFormat(GC3Denum) { return SampledTexelFormatRGBA; }
+
+    virtual void prepareToUpdate(const WebCore::IntRect& contentRect, const WebCore::IntSize&, int, float, WebCore::IntRect* resultingOpaqueRect);
+    // Sets the rect to invalidate during the next call to prepareToUpdate(). After the next
+    // call to prepareToUpdate() the rect is reset.
+    void setRectToInvalidate(const WebCore::IntRect&, FakeTiledLayerChromium*);
+    // Last rect passed to prepareToUpdate().
+    const WebCore::IntRect& lastUpdateRect()  const { return m_lastUpdateRect; }
+
+    // Number of times prepareToUpdate has been invoked.
+    int prepareCount() const { return m_prepareCount; }
+    void clearPrepareCount() { m_prepareCount = 0; }
+
+    // Number of times updateRect has been invoked.
+    int updateCount() const { return m_updateCount; }
+    void clearUpdateCount() { m_updateCount = 0; }
+    void updateRect() { m_updateCount++; }
+
+    // Number of times prepareRect() has been invoked on a texture.
+    int prepareRectCount() const { return m_prepareRectCount; }
+    void clearPrepareRectCount() { m_prepareRectCount = 0; }
+    void prepareRect() { m_prepareRectCount++; }
+
+    void setOpaquePaintRect(const WebCore::IntRect& opaquePaintRect) { m_opaquePaintRect = opaquePaintRect; }
+
+private:
+    int m_prepareCount;
+    int m_updateCount;
+    int m_prepareRectCount;
+    WebCore::IntRect m_rectToInvalidate;
+    WebCore::IntRect m_lastUpdateRect;
+    WebCore::IntRect m_opaquePaintRect;
+    RefPtr<FakeTiledLayerChromium> m_layer;
+};
+
+class FakeCCTiledLayerImpl : public WebCore::CCTiledLayerImpl {
+public:
+    explicit FakeCCTiledLayerImpl(int id);
+    virtual ~FakeCCTiledLayerImpl();
+
+    using WebCore::CCTiledLayerImpl::hasTileAt;
+    using WebCore::CCTiledLayerImpl::hasTextureIdForTileAt;
+};
+
+class FakeTiledLayerChromium : public WebCore::TiledLayerChromium {
+public:
+    explicit FakeTiledLayerChromium(WebCore::TextureManager*);
+    virtual ~FakeTiledLayerChromium();
+
+    static WebCore::IntSize tileSize() { return WebCore::IntSize(100, 100); }
+
+    using WebCore::TiledLayerChromium::invalidateRect;
+    using WebCore::TiledLayerChromium::prepareToUpdate;
+    using WebCore::TiledLayerChromium::prepareToUpdateIdle;
+    using WebCore::TiledLayerChromium::needsIdlePaint;
+    using WebCore::TiledLayerChromium::skipsDraw;
+    using WebCore::TiledLayerChromium::numPaintedTiles;
+    using WebCore::TiledLayerChromium::idlePaintRect;
+
+    virtual void setNeedsDisplayRect(const WebCore::FloatRect&);
+    const WebCore::FloatRect& lastNeedsDisplayRect() const { return m_lastNeedsDisplayRect; }
+
+    // Updates the visibleLayerRect().
+    virtual void paintContentsIfDirty(const WebCore::CCOcclusionTracker*);
+
+    virtual WebCore::TextureManager* textureManager() const { return m_textureManager; }
+    FakeLayerTextureUpdater* fakeLayerTextureUpdater() { return m_fakeTextureUpdater.get(); }
+    WebCore::FloatRect updateRect() { return m_updateRect; }
+
+private:
+    virtual WebCore::LayerTextureUpdater* textureUpdater() const { return m_fakeTextureUpdater.get(); }
+    virtual void createTextureUpdaterIfNeeded() { }
+
+    RefPtr<FakeLayerTextureUpdater> m_fakeTextureUpdater;
+    WebCore::TextureManager* m_textureManager;
+    WebCore::FloatRect m_lastNeedsDisplayRect;
+};
+
+class FakeTiledLayerWithScaledBounds : public FakeTiledLayerChromium {
+public:
+    explicit FakeTiledLayerWithScaledBounds(WebCore::TextureManager*);
+
+    void setContentBounds(const WebCore::IntSize& contentBounds) { m_forcedContentBounds = contentBounds; }
+    virtual WebCore::IntSize contentBounds() const { return m_forcedContentBounds; }
+
+protected:
+    WebCore::IntSize m_forcedContentBounds;
+};
+
+class FakeTextureAllocator : public WebCore::TextureAllocator {
+public:
+    virtual unsigned createTexture(const WebCore::IntSize&, GC3Denum) { return 1; }
+    virtual void deleteTexture(unsigned, const WebCore::IntSize&, GC3Denum) { }
+};
+
+class FakeTextureCopier : public WebCore::TextureCopier {
+public:
+    virtual void copyTexture(WebCore::GraphicsContext3D*, unsigned, unsigned, const WebCore::IntSize&) { }
+};
+
+class FakeCCTextureUpdater : public WebCore::CCTextureUpdater {
+public:
+    explicit FakeCCTextureUpdater();
+
+    FakeTextureAllocator& textureAllocator() { return m_textureAllocator; }
+
+protected:
+    FakeTextureAllocator m_textureAllocator;
+    FakeTextureCopier m_textureCopier;
+};
+
+}
+#endif // CCTiledLayerTestCommon_h
index 3b576af..d5313f5 100644 (file)
 
 #include "config.h"
 
+#include "CCTiledLayerTestCommon.h"
 #include "ManagedTexture.h"
 #include "TextureManager.h"
 
 #include <gtest/gtest.h>
 
 using namespace WebCore;
+using namespace WebKitTests;
 using namespace WTF;
 
 namespace {
 
-class FakeTextureAllocator : public TextureAllocator {
-public:
-    virtual ~FakeTextureAllocator() { }
-    virtual unsigned createTexture(const IntSize&, GC3Denum) { return 1; }
-    virtual void deleteTexture(unsigned, const IntSize&, GC3Denum) { }
-};
-
 class TextureManagerTest : public testing::Test {
 public:
     TextureManagerTest()
index 46106e4..150d65d 100644 (file)
 
 #include "CCAnimationTestCommon.h"
 #include "CCLayerTreeTestCommon.h"
+#include "CCTiledLayerTestCommon.h"
 #include "FakeCCLayerTreeHostClient.h"
-#include "LayerTextureUpdater.h"
-#include "Region.h"
-#include "TextureCopier.h"
-#include "TextureManager.h"
 #include "WebCompositor.h"
 #include "cc/CCSingleThreadProxy.h" // For DebugScopedSetImplThread
-#include "cc/CCTextureUpdater.h"
-#include "cc/CCTiledLayerImpl.h"
 #include <gtest/gtest.h>
 
 using namespace WebCore;
@@ -70,202 +65,6 @@ private:
     IntRect m_scissorRectInScreen;
 };
 
-class FakeTextureAllocator : public TextureAllocator {
-public:
-    virtual unsigned createTexture(const IntSize&, GC3Denum) { return 1; }
-    virtual void deleteTexture(unsigned, const IntSize&, GC3Denum) { }
-};
-
-class FakeTextureCopier : public TextureCopier {
-public:
-    virtual void copyTexture(GraphicsContext3D*, unsigned, unsigned, const IntSize&) { }
-};
-
-class FakeTiledLayerChromium;
-
-class FakeLayerTextureUpdater : public LayerTextureUpdater {
-public:
-    class Texture : public LayerTextureUpdater::Texture {
-    public:
-        Texture(FakeLayerTextureUpdater* layer, PassOwnPtr<ManagedTexture> texture)
-            : LayerTextureUpdater::Texture(texture)
-            , m_layer(layer)
-        {
-        }
-        virtual ~Texture() { }
-
-        virtual void updateRect(GraphicsContext3D*, TextureAllocator* allocator, const IntRect&, const IntRect&)
-        {
-            if (allocator)
-                texture()->allocate(allocator);
-            m_layer->updateRect();
-        }
-        virtual void prepareRect(const IntRect&) { m_layer->prepareRect(); }
-
-    private:
-        FakeLayerTextureUpdater* m_layer;
-    };
-
-    FakeLayerTextureUpdater()
-        : m_prepareCount(0)
-        , m_updateCount(0)
-        , m_prepareRectCount(0)
-    {
-    }
-    virtual ~FakeLayerTextureUpdater() { }
-
-    // Sets the rect to invalidate during the next call to prepareToUpdate(). After the next
-    // call to prepareToUpdate() the rect is reset.
-    void setRectToInvalidate(const IntRect&, FakeTiledLayerChromium*);
-
-    // Number of times prepareToUpdate has been invoked.
-    int prepareCount() const { return m_prepareCount; }
-    void clearPrepareCount() { m_prepareCount = 0; }
-
-    // Number of times updateRect has been invoked.
-    int updateCount() const { return m_updateCount; }
-    void clearUpdateCount() { m_updateCount = 0; }
-    void updateRect() { m_updateCount++; }
-
-    // Number of times prepareRect() has been invoked on a texture.
-    int prepareRectCount() const { return m_prepareRectCount; }
-    void clearPrepareRectCount() { m_prepareRectCount = 0; }
-    void prepareRect() { m_prepareRectCount++; }
-
-    void setOpaquePaintRect(const IntRect& opaquePaintRect) { m_opaquePaintRect = opaquePaintRect; }
-
-    // Last rect passed to prepareToUpdate().
-    const IntRect& lastUpdateRect()  const { return m_lastUpdateRect; }
-
-    virtual PassOwnPtr<LayerTextureUpdater::Texture> createTexture(TextureManager* manager) { return adoptPtr(new Texture(this, ManagedTexture::create(manager))); }
-    virtual SampledTexelFormat sampledTexelFormat(GC3Denum) { return SampledTexelFormatRGBA; }
-    virtual void prepareToUpdate(const IntRect& contentRect, const IntSize&, int, float, IntRect* resultingOpaqueRect);
-
-private:
-    int m_prepareCount;
-    int m_updateCount;
-    int m_prepareRectCount;
-    IntRect m_rectToInvalidate;
-    IntRect m_lastUpdateRect;
-    IntRect m_opaquePaintRect;
-    RefPtr<FakeTiledLayerChromium> m_layer;
-};
-
-class FakeCCTiledLayerImpl : public CCTiledLayerImpl {
-public:
-    explicit FakeCCTiledLayerImpl(int id)
-        : CCTiledLayerImpl(id) { }
-    virtual ~FakeCCTiledLayerImpl() { }
-
-    using CCTiledLayerImpl::hasTileAt;
-    using CCTiledLayerImpl::hasTextureIdForTileAt;
-};
-
-class FakeTiledLayerChromium : public TiledLayerChromium {
-public:
-    explicit FakeTiledLayerChromium(TextureManager* textureManager)
-        : TiledLayerChromium()
-        , m_fakeTextureUpdater(adoptRef(new FakeLayerTextureUpdater))
-        , m_textureManager(textureManager)
-    {
-        setTileSize(tileSize());
-        setTextureFormat(GraphicsContext3D::RGBA);
-        setBorderTexelOption(CCLayerTilingData::NoBorderTexels);
-        setIsDrawable(true); // So that we don't get false positives if any of these tests expect to return false from drawsContent() for other reasons.
-    }
-    virtual ~FakeTiledLayerChromium() { }
-
-    static IntSize tileSize() { return IntSize(100, 100); }
-
-    using TiledLayerChromium::invalidateRect;
-    using TiledLayerChromium::prepareToUpdate;
-    using TiledLayerChromium::prepareToUpdateIdle;
-    using TiledLayerChromium::needsIdlePaint;
-    using TiledLayerChromium::skipsDraw;
-    using TiledLayerChromium::numPaintedTiles;
-    using TiledLayerChromium::idlePaintRect;
-
-    virtual void setNeedsDisplayRect(const FloatRect& rect)
-    {
-        m_lastNeedsDisplayRect = rect;
-        TiledLayerChromium::setNeedsDisplayRect(rect);
-    }
-
-    const FloatRect& lastNeedsDisplayRect() const { return m_lastNeedsDisplayRect; }
-
-    FakeLayerTextureUpdater* fakeLayerTextureUpdater() { return m_fakeTextureUpdater.get(); }
-
-    virtual TextureManager* textureManager() const { return m_textureManager; }
-
-    virtual void paintContentsIfDirty(const CCOcclusionTracker* occlusion)
-    {
-        prepareToUpdate(visibleLayerRect(), occlusion);
-    }
-
-private:
-    virtual LayerTextureUpdater* textureUpdater() const
-    {
-        return m_fakeTextureUpdater.get();
-    }
-
-    virtual void createTextureUpdaterIfNeeded() { }
-
-    RefPtr<FakeLayerTextureUpdater> m_fakeTextureUpdater;
-    TextureManager* m_textureManager;
-    FloatRect m_lastNeedsDisplayRect;
-};
-
-class FakeTiledLayerWithScaledBounds : public FakeTiledLayerChromium {
-public:
-    explicit FakeTiledLayerWithScaledBounds(TextureManager* textureManager)
-        : FakeTiledLayerChromium(textureManager)
-    {
-    }
-
-    void setContentBounds(const IntSize& contentBounds) { m_forcedContentBounds = contentBounds; }
-    virtual IntSize contentBounds() const { return m_forcedContentBounds; }
-
-    FloatRect updateRect() { return m_updateRect; }
-
-protected:
-    IntSize m_forcedContentBounds;
-};
-
-void FakeLayerTextureUpdater::setRectToInvalidate(const IntRect& rect, FakeTiledLayerChromium* layer)
-{
-    m_rectToInvalidate = rect;
-    m_layer = layer;
-}
-
-void FakeLayerTextureUpdater::prepareToUpdate(const IntRect& contentRect, const IntSize&, int, float, IntRect* resultingOpaqueRect)
-{
-    m_prepareCount++;
-    m_lastUpdateRect = contentRect;
-    if (!m_rectToInvalidate.isEmpty()) {
-        m_layer->invalidateRect(m_rectToInvalidate);
-        m_rectToInvalidate = IntRect();
-        m_layer = 0;
-    }
-    *resultingOpaqueRect = m_opaquePaintRect;
-}
-
-class FakeCCTextureUpdater : public CCTextureUpdater {
-public:
-    explicit FakeCCTextureUpdater()
-        : CCTextureUpdater(&m_textureAllocator, &m_textureCopier)
-    {
-    }
-
-    FakeTextureAllocator& textureAllocator()
-    {
-        return m_textureAllocator;
-    }
-
-protected:
-    FakeTextureAllocator m_textureAllocator;
-    FakeTextureCopier m_textureCopier;
-};
-
 TEST(TiledLayerChromiumTest, pushDirtyTiles)
 {
     OwnPtr<TextureManager> textureManager = TextureManager::create(4*1024*1024, 2*1024*1024, 1024);