diff options
75 files changed, 964 insertions, 643 deletions
diff --git a/cc/cc_tests.gyp b/cc/cc_tests.gyp index 1ba44b5..1c735f4 100644 --- a/cc/cc_tests.gyp +++ b/cc/cc_tests.gyp @@ -66,9 +66,14 @@ 'test/compositor_fake_web_graphics_context_3d.h', 'test/fake_content_layer_client.cc', 'test/fake_content_layer_client.h', + 'test/fake_impl_proxy.h', 'test/fake_output_surface.h', 'test/fake_layer_tree_host_client.cc', 'test/fake_layer_tree_host_client.h', + 'test/fake_layer_tree_host_impl.cc', + 'test/fake_layer_tree_host_impl_client.cc', + 'test/fake_layer_tree_host_impl_client.h', + 'test/fake_layer_tree_host_impl.h', 'test/fake_picture_layer_tiling_client.cc', 'test/fake_picture_layer_tiling_client.h', 'test/fake_proxy.cc', diff --git a/cc/damage_tracker_unittest.cc b/cc/damage_tracker_unittest.cc index 97fe88c..88cd441 100644 --- a/cc/damage_tracker_unittest.cc +++ b/cc/damage_tracker_unittest.cc @@ -8,6 +8,8 @@ #include "cc/layer_tree_host_common.h" #include "cc/math_util.h" #include "cc/single_thread_proxy.h" +#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/geometry_test_utils.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/effects/SkBlurImageFilter.h" @@ -63,106 +65,115 @@ void emulateDrawingOneFrame(LayerImpl* root) root->resetAllChangeTrackingForSubtree(); } -scoped_ptr<LayerImpl> createTestTreeWithOneSurface() -{ - scoped_ptr<LayerImpl> root = LayerImpl::create(1); - scoped_ptr<LayerImpl> child = LayerImpl::create(2); - - root->setPosition(gfx::PointF()); - root->setAnchorPoint(gfx::PointF()); - root->setBounds(gfx::Size(500, 500)); - root->setContentBounds(gfx::Size(500, 500)); - root->setDrawsContent(true); - root->createRenderSurface(); - root->renderSurface()->setContentRect(gfx::Rect(gfx::Point(), gfx::Size(500, 500))); +class DamageTrackerTest : public testing::Test { +public: + DamageTrackerTest() + : m_hostImpl(&m_proxy) + { + } - child->setPosition(gfx::PointF(100, 100)); - child->setAnchorPoint(gfx::PointF()); - child->setBounds(gfx::Size(30, 30)); - child->setContentBounds(gfx::Size(30, 30)); - child->setDrawsContent(true); - root->addChild(child.Pass()); + scoped_ptr<LayerImpl> createTestTreeWithOneSurface() + { + scoped_ptr<LayerImpl> root = LayerImpl::create(&m_hostImpl, 1); + scoped_ptr<LayerImpl> child = LayerImpl::create(&m_hostImpl, 2); + + root->setPosition(gfx::PointF()); + root->setAnchorPoint(gfx::PointF()); + root->setBounds(gfx::Size(500, 500)); + root->setContentBounds(gfx::Size(500, 500)); + root->setDrawsContent(true); + root->createRenderSurface(); + root->renderSurface()->setContentRect(gfx::Rect(gfx::Point(), gfx::Size(500, 500))); + + child->setPosition(gfx::PointF(100, 100)); + child->setAnchorPoint(gfx::PointF()); + child->setBounds(gfx::Size(30, 30)); + child->setContentBounds(gfx::Size(30, 30)); + child->setDrawsContent(true); + root->addChild(child.Pass()); + + return root.Pass(); + } - return root.Pass(); -} + scoped_ptr<LayerImpl> createTestTreeWithTwoSurfaces() + { + // This test tree has two render surfaces: one for the root, and one for + // child1. Additionally, the root has a second child layer, and child1 has two + // children of its own. + + scoped_ptr<LayerImpl> root = LayerImpl::create(&m_hostImpl, 1); + scoped_ptr<LayerImpl> child1 = LayerImpl::create(&m_hostImpl, 2); + scoped_ptr<LayerImpl> child2 = LayerImpl::create(&m_hostImpl, 3); + scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(&m_hostImpl, 4); + scoped_ptr<LayerImpl> grandChild2 = LayerImpl::create(&m_hostImpl, 5); + + root->setPosition(gfx::PointF()); + root->setAnchorPoint(gfx::PointF()); + root->setBounds(gfx::Size(500, 500)); + root->setContentBounds(gfx::Size(500, 500)); + root->setDrawsContent(true); + root->createRenderSurface(); + root->renderSurface()->setContentRect(gfx::Rect(gfx::Point(), gfx::Size(500, 500))); + + child1->setPosition(gfx::PointF(100, 100)); + child1->setAnchorPoint(gfx::PointF()); + child1->setBounds(gfx::Size(30, 30)); + child1->setContentBounds(gfx::Size(30, 30)); + child1->setOpacity(0.5); // with a child that drawsContent, this will cause the layer to create its own renderSurface. + child1->setDrawsContent(false); // this layer does not draw, but is intended to create its own renderSurface. + child1->setForceRenderSurface(true); + + child2->setPosition(gfx::PointF(11, 11)); + child2->setAnchorPoint(gfx::PointF()); + child2->setBounds(gfx::Size(18, 18)); + child2->setContentBounds(gfx::Size(18, 18)); + child2->setDrawsContent(true); -scoped_ptr<LayerImpl> createTestTreeWithTwoSurfaces() -{ - // This test tree has two render surfaces: one for the root, and one for - // child1. Additionally, the root has a second child layer, and child1 has two - // children of its own. - - scoped_ptr<LayerImpl> root = LayerImpl::create(1); - scoped_ptr<LayerImpl> child1 = LayerImpl::create(2); - scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); - scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(4); - scoped_ptr<LayerImpl> grandChild2 = LayerImpl::create(5); - - root->setPosition(gfx::PointF()); - root->setAnchorPoint(gfx::PointF()); - root->setBounds(gfx::Size(500, 500)); - root->setContentBounds(gfx::Size(500, 500)); - root->setDrawsContent(true); - root->createRenderSurface(); - root->renderSurface()->setContentRect(gfx::Rect(gfx::Point(), gfx::Size(500, 500))); - - child1->setPosition(gfx::PointF(100, 100)); - child1->setAnchorPoint(gfx::PointF()); - child1->setBounds(gfx::Size(30, 30)); - child1->setContentBounds(gfx::Size(30, 30)); - child1->setOpacity(0.5); // with a child that drawsContent, this will cause the layer to create its own renderSurface. - child1->setDrawsContent(false); // this layer does not draw, but is intended to create its own renderSurface. - child1->setForceRenderSurface(true); + grandChild1->setPosition(gfx::PointF(200, 200)); + grandChild1->setAnchorPoint(gfx::PointF()); + grandChild1->setBounds(gfx::Size(6, 8)); + grandChild1->setContentBounds(gfx::Size(6, 8)); + grandChild1->setDrawsContent(true); + + grandChild2->setPosition(gfx::PointF(190, 190)); + grandChild2->setAnchorPoint(gfx::PointF()); + grandChild2->setBounds(gfx::Size(6, 8)); + grandChild2->setContentBounds(gfx::Size(6, 8)); + grandChild2->setDrawsContent(true); + + child1->addChild(grandChild1.Pass()); + child1->addChild(grandChild2.Pass()); + root->addChild(child1.Pass()); + root->addChild(child2.Pass()); - child2->setPosition(gfx::PointF(11, 11)); - child2->setAnchorPoint(gfx::PointF()); - child2->setBounds(gfx::Size(18, 18)); - child2->setContentBounds(gfx::Size(18, 18)); - child2->setDrawsContent(true); - - grandChild1->setPosition(gfx::PointF(200, 200)); - grandChild1->setAnchorPoint(gfx::PointF()); - grandChild1->setBounds(gfx::Size(6, 8)); - grandChild1->setContentBounds(gfx::Size(6, 8)); - grandChild1->setDrawsContent(true); - - grandChild2->setPosition(gfx::PointF(190, 190)); - grandChild2->setAnchorPoint(gfx::PointF()); - grandChild2->setBounds(gfx::Size(6, 8)); - grandChild2->setContentBounds(gfx::Size(6, 8)); - grandChild2->setDrawsContent(true); - - child1->addChild(grandChild1.Pass()); - child1->addChild(grandChild2.Pass()); - root->addChild(child1.Pass()); - root->addChild(child2.Pass()); - - return root.Pass(); -} + return root.Pass(); + } -scoped_ptr<LayerImpl> createAndSetUpTestTreeWithOneSurface() -{ - scoped_ptr<LayerImpl> root = createTestTreeWithOneSurface(); + scoped_ptr<LayerImpl> createAndSetUpTestTreeWithOneSurface() + { + scoped_ptr<LayerImpl> root = createTestTreeWithOneSurface(); - // Setup includes going past the first frame which always damages everything, so - // that we can actually perform specific tests. - emulateDrawingOneFrame(root.get()); + // Setup includes going past the first frame which always damages everything, so + // that we can actually perform specific tests. + emulateDrawingOneFrame(root.get()); - return root.Pass(); -} + return root.Pass(); + } -scoped_ptr<LayerImpl> createAndSetUpTestTreeWithTwoSurfaces() -{ - scoped_ptr<LayerImpl> root = createTestTreeWithTwoSurfaces(); + scoped_ptr<LayerImpl> createAndSetUpTestTreeWithTwoSurfaces() + { + scoped_ptr<LayerImpl> root = createTestTreeWithTwoSurfaces(); - // Setup includes going past the first frame which always damages everything, so - // that we can actually perform specific tests. - emulateDrawingOneFrame(root.get()); + // Setup includes going past the first frame which always damages everything, so + // that we can actually perform specific tests. + emulateDrawingOneFrame(root.get()); - return root.Pass(); -} + return root.Pass(); + } -class DamageTrackerTest : public testing::Test { +protected: + FakeImplProxy m_proxy; + FakeLayerTreeHostImpl m_hostImpl; }; TEST_F(DamageTrackerTest, sanityCheckTestTreeWithOneSurface) @@ -525,7 +536,7 @@ TEST_F(DamageTrackerTest, verifyDamageForAddingAndRemovingLayer) // clearDamageForAllSurfaces(root.get()); { - scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); + scoped_ptr<LayerImpl> child2 = LayerImpl::create(&m_hostImpl, 3); child2->setPosition(gfx::PointF(400, 380)); child2->setAnchorPoint(gfx::PointF()); child2->setBounds(gfx::Size(6, 8)); @@ -565,7 +576,7 @@ TEST_F(DamageTrackerTest, verifyDamageForNewUnchangedLayer) clearDamageForAllSurfaces(root.get()); { - scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); + scoped_ptr<LayerImpl> child2 = LayerImpl::create(&m_hostImpl, 3); child2->setPosition(gfx::PointF(400, 380)); child2->setAnchorPoint(gfx::PointF()); child2->setBounds(gfx::Size(6, 8)); @@ -595,7 +606,7 @@ TEST_F(DamageTrackerTest, verifyDamageForMultipleLayers) // In this test we don't want the above tree manipulation to be considered part of the same frame. clearDamageForAllSurfaces(root.get()); { - scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); + scoped_ptr<LayerImpl> child2 = LayerImpl::create(&m_hostImpl, 3); child2->setPosition(gfx::PointF(400, 380)); child2->setAnchorPoint(gfx::PointF()); child2->setBounds(gfx::Size(6, 8)); @@ -816,7 +827,7 @@ TEST_F(DamageTrackerTest, verifyDamageForReplica) // contentBounds of the surface. grandChild2->setPosition(gfx::PointF(180, 180)); { - scoped_ptr<LayerImpl> grandChild3 = LayerImpl::create(6); + scoped_ptr<LayerImpl> grandChild3 = LayerImpl::create(&m_hostImpl, 6); grandChild3->setPosition(gfx::PointF(240, 240)); grandChild3->setAnchorPoint(gfx::PointF()); grandChild3->setBounds(gfx::Size(10, 10)); @@ -831,7 +842,7 @@ TEST_F(DamageTrackerTest, verifyDamageForReplica) // clearDamageForAllSurfaces(root.get()); { - scoped_ptr<LayerImpl> grandChild1Replica = LayerImpl::create(7); + scoped_ptr<LayerImpl> grandChild1Replica = LayerImpl::create(&m_hostImpl, 7); grandChild1Replica->setPosition(gfx::PointF()); grandChild1Replica->setAnchorPoint(gfx::PointF()); gfx::Transform reflection; @@ -899,7 +910,7 @@ TEST_F(DamageTrackerTest, verifyDamageForMask) // Set up the mask layer. { - scoped_ptr<LayerImpl> maskLayer = LayerImpl::create(3); + scoped_ptr<LayerImpl> maskLayer = LayerImpl::create(&m_hostImpl, 3); maskLayer->setPosition(child->position()); maskLayer->setAnchorPoint(gfx::PointF()); maskLayer->setBounds(child->bounds()); @@ -911,7 +922,7 @@ TEST_F(DamageTrackerTest, verifyDamageForMask) // Add opacity and a grandChild so that the render surface persists even after we remove the mask. child->setOpacity(0.5); { - scoped_ptr<LayerImpl> grandChild = LayerImpl::create(4); + scoped_ptr<LayerImpl> grandChild = LayerImpl::create(&m_hostImpl, 4); grandChild->setPosition(gfx::PointF(2, 2)); grandChild->setAnchorPoint(gfx::PointF()); grandChild->setBounds(gfx::Size(2, 2)); @@ -984,7 +995,7 @@ TEST_F(DamageTrackerTest, verifyDamageForReplicaMask) // Create a reflection about the left edge of grandChild1. { - scoped_ptr<LayerImpl> grandChild1Replica = LayerImpl::create(6); + scoped_ptr<LayerImpl> grandChild1Replica = LayerImpl::create(&m_hostImpl, 6); grandChild1Replica->setPosition(gfx::PointF()); grandChild1Replica->setAnchorPoint(gfx::PointF()); gfx::Transform reflection; @@ -996,7 +1007,7 @@ TEST_F(DamageTrackerTest, verifyDamageForReplicaMask) // Set up the mask layer on the replica layer { - scoped_ptr<LayerImpl> replicaMaskLayer = LayerImpl::create(7); + scoped_ptr<LayerImpl> replicaMaskLayer = LayerImpl::create(&m_hostImpl, 7); replicaMaskLayer->setPosition(gfx::PointF()); replicaMaskLayer->setAnchorPoint(gfx::PointF()); replicaMaskLayer->setBounds(grandChild1->bounds()); @@ -1046,7 +1057,7 @@ TEST_F(DamageTrackerTest, verifyDamageForReplicaMaskWithAnchor) grandChild1->setAnchorPoint(gfx::PointF(1, 0)); // This is not exactly the anchor being tested, but by convention its expected to be the same as the replica's anchor point. { - scoped_ptr<LayerImpl> grandChild1Replica = LayerImpl::create(6); + scoped_ptr<LayerImpl> grandChild1Replica = LayerImpl::create(&m_hostImpl, 6); grandChild1Replica->setPosition(gfx::PointF()); grandChild1Replica->setAnchorPoint(gfx::PointF(1, 0)); // This is the anchor being tested. gfx::Transform reflection; @@ -1058,7 +1069,7 @@ TEST_F(DamageTrackerTest, verifyDamageForReplicaMaskWithAnchor) // Set up the mask layer on the replica layer { - scoped_ptr<LayerImpl> replicaMaskLayer = LayerImpl::create(7); + scoped_ptr<LayerImpl> replicaMaskLayer = LayerImpl::create(&m_hostImpl, 7); replicaMaskLayer->setPosition(gfx::PointF()); replicaMaskLayer->setAnchorPoint(gfx::PointF()); // note, this is not the anchor being tested. replicaMaskLayer->setBounds(grandChild1->bounds()); @@ -1112,7 +1123,7 @@ TEST_F(DamageTrackerTest, verifyDamageForEmptyLayerList) // Though it should never happen, its a good idea to verify that the damage tracker // does not crash when it receives an empty layerList. - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + scoped_ptr<LayerImpl> root = LayerImpl::create(&m_hostImpl, 1); root->createRenderSurface(); ASSERT_TRUE(root == root->renderTarget()); diff --git a/cc/delegated_renderer_layer.cc b/cc/delegated_renderer_layer.cc index 0fb1ada..a1c7853 100644 --- a/cc/delegated_renderer_layer.cc +++ b/cc/delegated_renderer_layer.cc @@ -24,9 +24,9 @@ DelegatedRendererLayer::~DelegatedRendererLayer() { } -scoped_ptr<LayerImpl> DelegatedRendererLayer::createLayerImpl() +scoped_ptr<LayerImpl> DelegatedRendererLayer::createLayerImpl(LayerTreeHostImpl* hostImpl) { - return DelegatedRendererLayerImpl::create(m_layerId).PassAs<LayerImpl>(); + return DelegatedRendererLayerImpl::create(hostImpl, m_layerId).PassAs<LayerImpl>(); } } // namespace cc diff --git a/cc/delegated_renderer_layer.h b/cc/delegated_renderer_layer.h index 83188d9..11a53a9 100644 --- a/cc/delegated_renderer_layer.h +++ b/cc/delegated_renderer_layer.h @@ -14,7 +14,7 @@ class CC_EXPORT DelegatedRendererLayer : public Layer { public: static scoped_refptr<DelegatedRendererLayer> create(); - virtual scoped_ptr<LayerImpl> createLayerImpl() OVERRIDE; + virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeHostImpl* hostImpl) OVERRIDE; protected: DelegatedRendererLayer(); diff --git a/cc/delegated_renderer_layer_impl.cc b/cc/delegated_renderer_layer_impl.cc index 7b17eaf..5364c70 100644 --- a/cc/delegated_renderer_layer_impl.cc +++ b/cc/delegated_renderer_layer_impl.cc @@ -12,8 +12,8 @@ namespace cc { -DelegatedRendererLayerImpl::DelegatedRendererLayerImpl(int id) - : LayerImpl(id) +DelegatedRendererLayerImpl::DelegatedRendererLayerImpl(LayerTreeHostImpl* hostImpl, int id) + : LayerImpl(hostImpl, id) { } diff --git a/cc/delegated_renderer_layer_impl.h b/cc/delegated_renderer_layer_impl.h index 88f811e..8ee0f9f 100644 --- a/cc/delegated_renderer_layer_impl.h +++ b/cc/delegated_renderer_layer_impl.h @@ -13,7 +13,7 @@ namespace cc { class CC_EXPORT DelegatedRendererLayerImpl : public LayerImpl { public: - static scoped_ptr<DelegatedRendererLayerImpl> create(int id) { return make_scoped_ptr(new DelegatedRendererLayerImpl(id)); } + static scoped_ptr<DelegatedRendererLayerImpl> create(LayerTreeHostImpl* hostImpl, int id) { return make_scoped_ptr(new DelegatedRendererLayerImpl(hostImpl, id)); } virtual ~DelegatedRendererLayerImpl(); virtual int descendantsDrawContent() OVERRIDE; @@ -32,7 +32,7 @@ public: virtual void appendQuads(QuadSink&, AppendQuadsData&) OVERRIDE; private: - explicit DelegatedRendererLayerImpl(int); + DelegatedRendererLayerImpl(LayerTreeHostImpl* hostImpl, int id); RenderPass::Id convertDelegatedRenderPassId(RenderPass::Id delegatedRenderPassId) const; diff --git a/cc/delegated_renderer_layer_impl_unittest.cc b/cc/delegated_renderer_layer_impl_unittest.cc index 60edc8e..08ca76c 100644 --- a/cc/delegated_renderer_layer_impl_unittest.cc +++ b/cc/delegated_renderer_layer_impl_unittest.cc @@ -12,6 +12,7 @@ #include "cc/single_thread_proxy.h" #include "cc/solid_color_draw_quad.h" #include "cc/solid_color_layer_impl.h" +#include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_output_surface.h" #include "cc/test/fake_proxy.h" #include "cc/test/fake_web_compositor_output_surface.h" @@ -101,10 +102,10 @@ public: DelegatedRendererLayerImplTestSimple() : DelegatedRendererLayerImplTest() { - scoped_ptr<LayerImpl> rootLayer = SolidColorLayerImpl::create(1).PassAs<LayerImpl>(); - scoped_ptr<LayerImpl> layerBefore = SolidColorLayerImpl::create(2).PassAs<LayerImpl>(); - scoped_ptr<LayerImpl> layerAfter = SolidColorLayerImpl::create(3).PassAs<LayerImpl>(); - scoped_ptr<DelegatedRendererLayerImpl> delegatedRendererLayer = DelegatedRendererLayerImpl::create(4); + scoped_ptr<LayerImpl> rootLayer = SolidColorLayerImpl::create(m_hostImpl.get(), 1).PassAs<LayerImpl>(); + scoped_ptr<LayerImpl> layerBefore = SolidColorLayerImpl::create(m_hostImpl.get(), 2).PassAs<LayerImpl>(); + scoped_ptr<LayerImpl> layerAfter = SolidColorLayerImpl::create(m_hostImpl.get(), 3).PassAs<LayerImpl>(); + scoped_ptr<DelegatedRendererLayerImpl> delegatedRendererLayer = DelegatedRendererLayerImpl::create(m_hostImpl.get(), 4); m_hostImpl->setViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); rootLayer->setBounds(gfx::Size(100, 100)); @@ -421,8 +422,8 @@ public: DelegatedRendererLayerImplTestSharedData() : DelegatedRendererLayerImplTest() { - scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(1); - scoped_ptr<DelegatedRendererLayerImpl> delegatedRendererLayer = DelegatedRendererLayerImpl::create(2); + scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(m_hostImpl.get(), 1); + scoped_ptr<DelegatedRendererLayerImpl> delegatedRendererLayer = DelegatedRendererLayerImpl::create(m_hostImpl.get(), 2); m_hostImpl->setViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); rootLayer->setBounds(gfx::Size(100, 100)); diff --git a/cc/gl_renderer_unittest.cc b/cc/gl_renderer_unittest.cc index 9e040bf..909ca59 100644 --- a/cc/gl_renderer_unittest.cc +++ b/cc/gl_renderer_unittest.cc @@ -7,6 +7,8 @@ #include "cc/draw_quad.h" #include "cc/prioritized_resource_manager.h" #include "cc/resource_provider.h" +#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_web_compositor_output_surface.h" #include "cc/test/fake_web_graphics_context_3d.h" #include "cc/test/render_pass_test_common.h" @@ -57,9 +59,10 @@ private: class FakeRendererClient : public RendererClient { public: FakeRendererClient() - : m_setFullRootLayerDamageCount(0) + : m_hostImpl(&m_proxy) + , m_setFullRootLayerDamageCount(0) , m_lastCallWasSetVisibility(0) - , m_rootLayer(LayerImpl::create(1)) + , m_rootLayer(LayerImpl::create(&m_hostImpl, 1)) , m_memoryAllocationLimitBytes(PrioritizedResourceManager::defaultMemoryAllocationLimit()) { m_rootLayer->createRenderSurface(); @@ -91,6 +94,8 @@ public: size_t memoryAllocationLimitBytes() const { return m_memoryAllocationLimitBytes; } private: + FakeImplProxy m_proxy; + FakeLayerTreeHostImpl m_hostImpl; int m_setFullRootLayerDamageCount; bool* m_lastCallWasSetVisibility; scoped_ptr<LayerImpl> m_rootLayer; diff --git a/cc/heads_up_display_layer.cc b/cc/heads_up_display_layer.cc index b3d85cd..675c5cf3 100644 --- a/cc/heads_up_display_layer.cc +++ b/cc/heads_up_display_layer.cc @@ -59,9 +59,9 @@ void HeadsUpDisplayLayer::setFontAtlas(scoped_ptr<FontAtlas> fontAtlas) m_hasFontAtlas = true; } -scoped_ptr<LayerImpl> HeadsUpDisplayLayer::createLayerImpl() +scoped_ptr<LayerImpl> HeadsUpDisplayLayer::createLayerImpl(LayerTreeHostImpl* hostImpl) { - return HeadsUpDisplayLayerImpl::create(m_layerId).PassAs<LayerImpl>(); + return HeadsUpDisplayLayerImpl::create(hostImpl, m_layerId).PassAs<LayerImpl>(); } void HeadsUpDisplayLayer::pushPropertiesTo(LayerImpl* layerImpl) diff --git a/cc/heads_up_display_layer.h b/cc/heads_up_display_layer.h index ff276b5..1413243 100644 --- a/cc/heads_up_display_layer.h +++ b/cc/heads_up_display_layer.h @@ -20,7 +20,7 @@ public: void setFontAtlas(scoped_ptr<FontAtlas>); - virtual scoped_ptr<LayerImpl> createLayerImpl() OVERRIDE; + virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeHostImpl* hostImpl) OVERRIDE; virtual void pushPropertiesTo(LayerImpl*) OVERRIDE; bool hasFontAtlas() const { return m_hasFontAtlas; } diff --git a/cc/heads_up_display_layer_impl.cc b/cc/heads_up_display_layer_impl.cc index 4fb57c8..4490519 100644 --- a/cc/heads_up_display_layer_impl.cc +++ b/cc/heads_up_display_layer_impl.cc @@ -46,8 +46,8 @@ static inline SkPaint createPaint() return paint; } -HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(int id) - : LayerImpl(id) +HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeHostImpl* hostImpl, int id) + : LayerImpl(hostImpl, id) , m_averageFPS(0) , m_minFPS(0) , m_maxFPS(0) diff --git a/cc/heads_up_display_layer_impl.h b/cc/heads_up_display_layer_impl.h index 03a90d1..2d5c03a 100644 --- a/cc/heads_up_display_layer_impl.h +++ b/cc/heads_up_display_layer_impl.h @@ -24,9 +24,9 @@ class FrameRateCounter; class CC_EXPORT HeadsUpDisplayLayerImpl : public LayerImpl { public: - static scoped_ptr<HeadsUpDisplayLayerImpl> create(int id) + static scoped_ptr<HeadsUpDisplayLayerImpl> create(LayerTreeHostImpl* hostImpl, int id) { - return make_scoped_ptr(new HeadsUpDisplayLayerImpl(id)); + return make_scoped_ptr(new HeadsUpDisplayLayerImpl(hostImpl, id)); } virtual ~HeadsUpDisplayLayerImpl(); @@ -42,7 +42,7 @@ public: virtual bool layerIsAlwaysDamaged() const OVERRIDE; private: - explicit HeadsUpDisplayLayerImpl(int); + HeadsUpDisplayLayerImpl(LayerTreeHostImpl* hostImpl, int id); virtual const char* layerTypeAsString() const OVERRIDE; diff --git a/cc/io_surface_layer.cc b/cc/io_surface_layer.cc index f2351c8..dd824bc 100644 --- a/cc/io_surface_layer.cc +++ b/cc/io_surface_layer.cc @@ -30,9 +30,9 @@ void IOSurfaceLayer::setIOSurfaceProperties(uint32_t ioSurfaceId, const gfx::Siz setNeedsCommit(); } -scoped_ptr<LayerImpl> IOSurfaceLayer::createLayerImpl() +scoped_ptr<LayerImpl> IOSurfaceLayer::createLayerImpl(LayerTreeHostImpl* hostImpl) { - return IOSurfaceLayerImpl::create(m_layerId).PassAs<LayerImpl>(); + return IOSurfaceLayerImpl::create(hostImpl, m_layerId).PassAs<LayerImpl>(); } bool IOSurfaceLayer::drawsContent() const diff --git a/cc/io_surface_layer.h b/cc/io_surface_layer.h index 69a9f60..088976b 100644 --- a/cc/io_surface_layer.h +++ b/cc/io_surface_layer.h @@ -16,7 +16,7 @@ public: void setIOSurfaceProperties(uint32_t ioSurfaceId, const gfx::Size&); - virtual scoped_ptr<LayerImpl> createLayerImpl() OVERRIDE; + virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeHostImpl* hostImpl) OVERRIDE; virtual bool drawsContent() const OVERRIDE; virtual void pushPropertiesTo(LayerImpl*) OVERRIDE; diff --git a/cc/io_surface_layer_impl.cc b/cc/io_surface_layer_impl.cc index 10d80f3..f600721 100644 --- a/cc/io_surface_layer_impl.cc +++ b/cc/io_surface_layer_impl.cc @@ -16,8 +16,8 @@ namespace cc { -IOSurfaceLayerImpl::IOSurfaceLayerImpl(int id) - : LayerImpl(id) +IOSurfaceLayerImpl::IOSurfaceLayerImpl(LayerTreeHostImpl* hostImpl, int id) + : LayerImpl(hostImpl, id) , m_ioSurfaceId(0) , m_ioSurfaceChanged(false) , m_ioSurfaceTextureId(0) diff --git a/cc/io_surface_layer_impl.h b/cc/io_surface_layer_impl.h index 451373b..f7d4a58 100644 --- a/cc/io_surface_layer_impl.h +++ b/cc/io_surface_layer_impl.h @@ -13,9 +13,9 @@ namespace cc { class CC_EXPORT IOSurfaceLayerImpl : public LayerImpl { public: - static scoped_ptr<IOSurfaceLayerImpl> create(int id) + static scoped_ptr<IOSurfaceLayerImpl> create(LayerTreeHostImpl* hostImpl, int id) { - return make_scoped_ptr(new IOSurfaceLayerImpl(id)); + return make_scoped_ptr(new IOSurfaceLayerImpl(hostImpl, id)); } virtual ~IOSurfaceLayerImpl(); @@ -29,7 +29,7 @@ public: virtual void dumpLayerProperties(std::string*, int indent) const OVERRIDE; private: - explicit IOSurfaceLayerImpl(int); + IOSurfaceLayerImpl(LayerTreeHostImpl* hostImpl, int id); virtual const char* layerTypeAsString() const OVERRIDE; diff --git a/cc/layer.cc b/cc/layer.cc index 42247fd..d0b3808 100644 --- a/cc/layer.cc +++ b/cc/layer.cc @@ -616,9 +616,9 @@ void Layer::pushPropertiesTo(LayerImpl* layer) m_updateRect = gfx::RectF(); } -scoped_ptr<LayerImpl> Layer::createLayerImpl() +scoped_ptr<LayerImpl> Layer::createLayerImpl(LayerTreeHostImpl* hostImpl) { - return LayerImpl::create(m_layerId); + return LayerImpl::create(hostImpl, m_layerId); } bool Layer::drawsContent() const @@ -35,6 +35,7 @@ struct AnimationEvent; class LayerAnimationDelegate; class LayerImpl; class LayerTreeHost; +class LayerTreeHostImpl; class PriorityCalculator; class ResourceUpdateQueue; class ScrollbarLayer; @@ -301,7 +302,7 @@ protected: scoped_refptr<Layer> m_maskLayer; // Constructs a LayerImpl of the correct runtime type for this Layer type. - virtual scoped_ptr<LayerImpl> createLayerImpl(); + virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeHostImpl* hostImpl); int m_layerId; private: diff --git a/cc/layer_impl.cc b/cc/layer_impl.cc index c9c41c1..fa68613 100644 --- a/cc/layer_impl.cc +++ b/cc/layer_impl.cc @@ -18,12 +18,12 @@ namespace cc { -LayerImpl::LayerImpl(int id) +LayerImpl::LayerImpl(LayerTreeHostImpl* hostImpl, int id) : m_parent(0) , m_maskLayerId(-1) , m_replicaLayerId(-1) , m_layerId(id) - , m_layerTreeHostImpl(0) + , m_layerTreeHostImpl(hostImpl) , m_anchorPoint(0.5, 0.5) , m_anchorPointZ(0) , m_contentsScaleX(1.0) @@ -52,7 +52,9 @@ LayerImpl::LayerImpl(int id) , m_layerAnimationController(LayerAnimationController::create()) { DCHECK(m_layerId > 0); + DCHECK(m_layerTreeHostImpl); m_layerAnimationController->setId(m_layerId); + m_layerAnimationController->setAnimationRegistrar(hostImpl); } LayerImpl::~LayerImpl() @@ -65,6 +67,7 @@ LayerImpl::~LayerImpl() void LayerImpl::addChild(scoped_ptr<LayerImpl> child) { child->setParent(this); + DCHECK_EQ(layerTreeHostImpl(), child->layerTreeHostImpl()); m_children.append(child.Pass()); } @@ -115,12 +118,6 @@ int LayerImpl::descendantsDrawContent() return result; } -void LayerImpl::setLayerTreeHostImpl(LayerTreeHostImpl* hostImpl) -{ - m_layerTreeHostImpl = hostImpl; - m_layerAnimationController->setAnimationRegistrar(hostImpl); -} - scoped_ptr<SharedQuadState> LayerImpl::createSharedQuadState() const { scoped_ptr<SharedQuadState> state = SharedQuadState::Create(); @@ -152,8 +149,6 @@ void LayerImpl::didDraw(ResourceProvider*) bool LayerImpl::showDebugBorders() const { - if (!m_layerTreeHostImpl) - return false; return m_layerTreeHostImpl->debugState().showDebugBorders; } @@ -436,6 +431,8 @@ void LayerImpl::setBounds(const gfx::Size& bounds) void LayerImpl::setMaskLayer(scoped_ptr<LayerImpl> maskLayer) { + if (maskLayer) + DCHECK_EQ(layerTreeHostImpl(), maskLayer->layerTreeHostImpl()); m_maskLayer = maskLayer.Pass(); int newLayerId = m_maskLayer ? m_maskLayer->id() : -1; @@ -448,6 +445,8 @@ void LayerImpl::setMaskLayer(scoped_ptr<LayerImpl> maskLayer) void LayerImpl::setReplicaLayer(scoped_ptr<LayerImpl> replicaLayer) { + if (replicaLayer) + DCHECK_EQ(layerTreeHostImpl(), replicaLayer->layerTreeHostImpl()); m_replicaLayer = replicaLayer.Pass(); int newLayerId = m_replicaLayer ? m_replicaLayer->id() : -1; diff --git a/cc/layer_impl.h b/cc/layer_impl.h index 76a3e38..e155e49 100644 --- a/cc/layer_impl.h +++ b/cc/layer_impl.h @@ -42,9 +42,9 @@ class CC_EXPORT LayerImpl { public: typedef ScopedPtrVector<LayerImpl> LayerList; - static scoped_ptr<LayerImpl> create(int id) + static scoped_ptr<LayerImpl> create(LayerTreeHostImpl* hostImpl, int id) { - return make_scoped_ptr(new LayerImpl(id)); + return make_scoped_ptr(new LayerImpl(hostImpl, id)); } virtual ~LayerImpl(); @@ -72,7 +72,6 @@ public: bool replicaHasMask() const { return m_replicaLayer && (m_maskLayer || m_replicaLayer->m_maskLayer); } LayerTreeHostImpl* layerTreeHostImpl() const { return m_layerTreeHostImpl; } - void setLayerTreeHostImpl(LayerTreeHostImpl* hostImpl); scoped_ptr<SharedQuadState> createSharedQuadState() const; // willDraw must be called before appendQuads. If willDraw is called, @@ -276,7 +275,7 @@ public: gfx::Rect layerRectToContentRect(const gfx::RectF& layerRect) const; protected: - explicit LayerImpl(int); + LayerImpl(LayerTreeHostImpl* hostImpl, int); // Get the color and size of the layer's debug border. virtual void getDebugBorderProperties(SkColor*, float* width) const; diff --git a/cc/layer_impl_unittest.cc b/cc/layer_impl_unittest.cc index 56aa8ff..bf8e96e 100644 --- a/cc/layer_impl_unittest.cc +++ b/cc/layer_impl_unittest.cc @@ -5,6 +5,8 @@ #include "cc/layer_impl.h" #include "cc/single_thread_proxy.h" +#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_layer_tree_host_impl.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/effects/SkBlurImageFilter.h" @@ -57,10 +59,12 @@ TEST(LayerImplTest, verifyLayerChangesAreTrackedProperly) // The constructor on this will fake that we are on the correct thread. // Create a simple LayerImpl tree: - scoped_ptr<LayerImpl> root = LayerImpl::create(1); - root->addChild(LayerImpl::create(2)); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 1); + root->addChild(LayerImpl::create(&hostImpl, 2)); LayerImpl* child = root->children()[0]; - child->addChild(LayerImpl::create(3)); + child->addChild(LayerImpl::create(&hostImpl, 3)); LayerImpl* grandChild = child->children()[0]; // Adding children is an internal operation and should not mark layers as changed. @@ -93,10 +97,10 @@ TEST(LayerImplTest, verifyLayerChangesAreTrackedProperly) EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setFilters(arbitraryFilters)); EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setFilters(WebFilterOperations())); EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setFilter(arbitraryFilter)); - EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setMaskLayer(LayerImpl::create(4))); + EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setMaskLayer(LayerImpl::create(&hostImpl, 4))); EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setMasksToBounds(true)); EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setContentsOpaque(true)); - EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setReplicaLayer(LayerImpl::create(5))); + EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setReplicaLayer(LayerImpl::create(&hostImpl, 5))); EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setPosition(arbitraryPointF)); EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setPreserves3D(true)); EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->setDoubleSided(false)); // constructor initializes it to "true". diff --git a/cc/layer_sorter_unittest.cc b/cc/layer_sorter_unittest.cc index 578ec284..da86383 100644 --- a/cc/layer_sorter_unittest.cc +++ b/cc/layer_sorter_unittest.cc @@ -7,6 +7,8 @@ #include "cc/layer_impl.h" #include "cc/math_util.h" #include "cc/single_thread_proxy.h" +#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_layer_tree_host_impl.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/transform.h" @@ -197,11 +199,14 @@ TEST(LayerSorterTest, verifyExistingOrderingPreservedWhenNoZDiff) // - 3 and 4 do not have a 3d z difference, and therefore their relative ordering should be retained. // - 3 and 4 should be re-sorted so they are in front of 1, 2, and 5. - scoped_ptr<LayerImpl> layer1 = LayerImpl::create(1); - scoped_ptr<LayerImpl> layer2 = LayerImpl::create(2); - scoped_ptr<LayerImpl> layer3 = LayerImpl::create(3); - scoped_ptr<LayerImpl> layer4 = LayerImpl::create(4); - scoped_ptr<LayerImpl> layer5 = LayerImpl::create(5); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + + scoped_ptr<LayerImpl> layer1 = LayerImpl::create(&hostImpl, 1); + scoped_ptr<LayerImpl> layer2 = LayerImpl::create(&hostImpl, 2); + scoped_ptr<LayerImpl> layer3 = LayerImpl::create(&hostImpl, 3); + scoped_ptr<LayerImpl> layer4 = LayerImpl::create(&hostImpl, 4); + scoped_ptr<LayerImpl> layer5 = LayerImpl::create(&hostImpl, 5); gfx::Transform BehindMatrix; BehindMatrix.Translate3d(0, 0, 2); diff --git a/cc/layer_tree_host_common_unittest.cc b/cc/layer_tree_host_common_unittest.cc index d343c78..3964a1a 100644 --- a/cc/layer_tree_host_common_unittest.cc +++ b/cc/layer_tree_host_common_unittest.cc @@ -13,6 +13,8 @@ #include "cc/proxy.h" #include "cc/single_thread_proxy.h" #include "cc/test/animation_test_common.h" +#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/geometry_test_utils.h" #include "cc/thread.h" #include "testing/gmock/include/gmock/gmock.h" @@ -73,12 +75,12 @@ void executeCalculateDrawProperties(LayerImpl* rootLayer, float deviceScaleFacto LayerTreeHostCommon::calculateDrawProperties(rootLayer, deviceViewportSize, deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, dummyRenderSurfaceLayerList); } -scoped_ptr<LayerImpl> createTreeForFixedPositionTests() +scoped_ptr<LayerImpl> createTreeForFixedPositionTests(LayerTreeHostImpl* hostImpl) { - scoped_ptr<LayerImpl> root = LayerImpl::create(1); - scoped_ptr<LayerImpl> child = LayerImpl::create(2); - scoped_ptr<LayerImpl> grandChild = LayerImpl::create(3); - scoped_ptr<LayerImpl> greatGrandChild = LayerImpl::create(4); + scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl, 1); + scoped_ptr<LayerImpl> child = LayerImpl::create(hostImpl, 2); + scoped_ptr<LayerImpl> grandChild = LayerImpl::create(hostImpl, 3); + scoped_ptr<LayerImpl> greatGrandChild = LayerImpl::create(hostImpl, 4); gfx::Transform IdentityMatrix; gfx::PointF anchor(0, 0); @@ -775,7 +777,9 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithD { // This test checks for correct scroll compensation when the fixed-position container // is the direct parent of the fixed-position layer. - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; @@ -814,7 +818,9 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithT // gfx::Transforms are in general non-commutative; using something like a non-uniform scale // helps to verify that translations and non-uniform scales are applied in the correct // order. - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; @@ -855,7 +861,9 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithD { // This test checks for correct scroll compensation when the fixed-position container // is NOT the direct parent of the fixed-position layer. - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; LayerImpl* greatGrandChild = grandChild->children()[0]; @@ -897,7 +905,9 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithD // This test checks for correct scroll compensation when the fixed-position container // is NOT the direct parent of the fixed-position layer, and the hierarchy has various // transforms that have to be processed in the correct order. - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; LayerImpl* greatGrandChild = grandChild->children()[0]; @@ -957,7 +967,9 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithM // This test checks for correct scroll compensation when the fixed-position container // is NOT the direct parent of the fixed-position layer, and the hierarchy has various // transforms that have to be processed in the correct order. - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; LayerImpl* greatGrandChild = grandChild->children()[0]; @@ -1017,7 +1029,9 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithI // contributes to a different renderSurface than the fixed-position layer. In this // case, the surface drawTransforms also have to be accounted for when checking the // scrollDelta. - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; LayerImpl* greatGrandChild = grandChild->children()[0]; @@ -1088,7 +1102,9 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithM // contributes to a different renderSurface than the fixed-position layer, with // additional renderSurfaces in-between. This checks that the conversion to ancestor // surfaces is accumulated properly in the final matrix transform. - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; LayerImpl* greatGrandChild = grandChild->children()[0]; @@ -1096,7 +1112,7 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithM // Add one more layer to the test tree for this scenario. { gfx::Transform identity; - scoped_ptr<LayerImpl> fixedPositionChild = LayerImpl::create(5); + scoped_ptr<LayerImpl> fixedPositionChild = LayerImpl::create(&hostImpl, 5); setLayerPropertiesForTesting(fixedPositionChild.get(), identity, identity, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); greatGrandChild->addChild(fixedPositionChild.Pass()); } @@ -1197,7 +1213,9 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithC // itself has a renderSurface. In this case, the container layer should be treated // like a layer that contributes to a renderTarget, and that renderTarget // is completely irrelevant; it should not affect the scroll compensation. - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; @@ -1242,7 +1260,9 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerThatI // This test checks the scenario where a fixed-position layer also happens to be a // container itself for a descendant fixed position layer. In particular, the layer // should not accidentally be fixed to itself. - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; @@ -1277,7 +1297,9 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerThatH // This test checks scroll compensation when a fixed-position layer does not find any // ancestor that is a "containerForFixedPositionLayers". In this situation, the layer should // be fixed to the viewport -- not the rootLayer, which may have transforms of its own. - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(&hostImpl); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; @@ -2769,7 +2791,9 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForEmptyLayerList) TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayer) { - scoped_ptr<LayerImpl> root = LayerImpl::create(12345); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 12345); gfx::Transform identityMatrix; gfx::PointF anchor(0, 0); @@ -2809,7 +2833,9 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayer) TEST(LayerTreeHostCommonTest, verifyHitTestingForUninvertibleTransform) { - scoped_ptr<LayerImpl> root = LayerImpl::create(12345); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 12345); gfx::Transform uninvertibleTransform; uninvertibleTransform.matrix().setDouble(0, 0, 0); @@ -2868,7 +2894,9 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForUninvertibleTransform) TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePositionedLayer) { - scoped_ptr<LayerImpl> root = LayerImpl::create(12345); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 12345); gfx::Transform identityMatrix; gfx::PointF anchor(0, 0); @@ -2909,7 +2937,9 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePositionedLayer) TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer) { - scoped_ptr<LayerImpl> root = LayerImpl::create(12345); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 12345); gfx::Transform identityMatrix; gfx::Transform rotation45DegreesAboutCenter; @@ -2958,7 +2988,9 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer) TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePerspectiveLayer) { - scoped_ptr<LayerImpl> root = LayerImpl::create(12345); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 12345); gfx::Transform identityMatrix; @@ -3018,7 +3050,9 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayerWithScaledContents) // contentsScale is ignored, then hit testing will mis-interpret the visibleContentRect // as being larger than the actual bounds of the layer. // - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 1); gfx::Transform identityMatrix; gfx::PointF anchor(0, 0); @@ -3028,7 +3062,7 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayerWithScaledContents) { gfx::PointF position(25, 25); gfx::Size bounds(50, 50); - scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345); + scoped_ptr<LayerImpl> testLayer = LayerImpl::create(&hostImpl, 12345); setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMatrix, anchor, position, bounds, false); // override contentBounds and contentsScale @@ -3082,17 +3116,19 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForSimpleClippedLayer) gfx::Transform identityMatrix; gfx::PointF anchor(0, 0); - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 1); setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, gfx::PointF(0, 0), gfx::Size(100, 100), false); { - scoped_ptr<LayerImpl> clippingLayer = LayerImpl::create(123); + scoped_ptr<LayerImpl> clippingLayer = LayerImpl::create(&hostImpl, 123); gfx::PointF position(25, 25); // this layer is positioned, and hit testing should correctly know where the layer is located. gfx::Size bounds(50, 50); setLayerPropertiesForTesting(clippingLayer.get(), identityMatrix, identityMatrix, anchor, position, bounds, false); clippingLayer->setMasksToBounds(true); - scoped_ptr<LayerImpl> child = LayerImpl::create(456); + scoped_ptr<LayerImpl> child = LayerImpl::create(&hostImpl, 456); position = gfx::PointF(-50, -50); bounds = gfx::Size(300, 300); setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, anchor, position, bounds, false); @@ -3145,7 +3181,9 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForMultiClippedRotatedLayer) // combined create a triangle. The rotatedLeaf will only be visible where it overlaps // this triangle. // - scoped_ptr<LayerImpl> root = LayerImpl::create(123); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 123); gfx::Transform identityMatrix; gfx::PointF anchor(0, 0); @@ -3155,9 +3193,9 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForMultiClippedRotatedLayer) root->setMasksToBounds(true); { - scoped_ptr<LayerImpl> child = LayerImpl::create(456); - scoped_ptr<LayerImpl> grandChild = LayerImpl::create(789); - scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(2468); + scoped_ptr<LayerImpl> child = LayerImpl::create(&hostImpl, 456); + scoped_ptr<LayerImpl> grandChild = LayerImpl::create(&hostImpl, 789); + scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(&hostImpl, 2468); position = gfx::PointF(10, 10); bounds = gfx::Size(80, 80); @@ -3246,11 +3284,13 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForNonClippingIntermediateLayer) gfx::Transform identityMatrix; gfx::PointF anchor(0, 0); - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 1); setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, gfx::PointF(0, 0), gfx::Size(100, 100), false); { - scoped_ptr<LayerImpl> intermediateLayer = LayerImpl::create(123); + scoped_ptr<LayerImpl> intermediateLayer = LayerImpl::create(&hostImpl, 123); gfx::PointF position(10, 10); // this layer is positioned, and hit testing should correctly know where the layer is located. gfx::Size bounds(50, 50); setLayerPropertiesForTesting(intermediateLayer.get(), identityMatrix, identityMatrix, anchor, position, bounds, false); @@ -3260,7 +3300,7 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForNonClippingIntermediateLayer) // The child of the intermediateLayer is translated so that it does not overlap intermediateLayer at all. // If child is incorrectly clipped, we would not be able to hit it successfully. - scoped_ptr<LayerImpl> child = LayerImpl::create(456); + scoped_ptr<LayerImpl> child = LayerImpl::create(&hostImpl, 456); position = gfx::PointF(60, 60); // 70, 70 in screen space bounds = gfx::Size(20, 20); setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, anchor, position, bounds, false); @@ -3302,7 +3342,9 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForNonClippingIntermediateLayer) TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayers) { - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 1); gfx::Transform identityMatrix; gfx::PointF anchor(0, 0); @@ -3317,9 +3359,9 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayers) // The expected stacking order is: // (front) child2, (second) grandChild, (third) child1, and (back) the root layer behind all other layers. - scoped_ptr<LayerImpl> child1 = LayerImpl::create(2); - scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); - scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(4); + scoped_ptr<LayerImpl> child1 = LayerImpl::create(&hostImpl, 2); + scoped_ptr<LayerImpl> child2 = LayerImpl::create(&hostImpl, 3); + scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(&hostImpl, 4); position = gfx::PointF(10, 10); bounds = gfx::Size(50, 50); @@ -3405,7 +3447,9 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists) // The geometry is set up similarly to the previous case, but // all layers are forced to be renderSurfaces now. // - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 1); gfx::Transform identityMatrix; gfx::PointF anchor(0, 0); @@ -3420,9 +3464,9 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists) // The expected stacking order is: // (front) child2, (second) grandChild, (third) child1, and (back) the root layer behind all other layers. - scoped_ptr<LayerImpl> child1 = LayerImpl::create(2); - scoped_ptr<LayerImpl> child2 = LayerImpl::create(3); - scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(4); + scoped_ptr<LayerImpl> child1 = LayerImpl::create(&hostImpl, 2); + scoped_ptr<LayerImpl> child2 = LayerImpl::create(&hostImpl, 3); + scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(&hostImpl, 4); position = gfx::PointF(10, 10); bounds = gfx::Size(50, 50); @@ -3527,7 +3571,9 @@ TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForEmptyLayerL TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayer) { - scoped_ptr<LayerImpl> root = LayerImpl::create(12345); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 12345); gfx::Transform identityMatrix; Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50)); @@ -3583,7 +3629,9 @@ TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayer TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForUninvertibleTransform) { - scoped_ptr<LayerImpl> root = LayerImpl::create(12345); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 12345); gfx::Transform uninvertibleTransform; uninvertibleTransform.matrix().setDouble(0, 0, 0); @@ -3644,7 +3692,9 @@ TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForUninvertibl TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSinglePositionedLayer) { - scoped_ptr<LayerImpl> root = LayerImpl::create(12345); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 12345); gfx::Transform identityMatrix; Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50)); @@ -3702,7 +3752,9 @@ TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayer // contentsScale is ignored, then hit checking will mis-interpret the visibleContentRect // as being larger than the actual bounds of the layer. // - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 1); gfx::Transform identityMatrix; gfx::PointF anchor(0, 0); @@ -3713,7 +3765,7 @@ TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayer Region touchHandlerRegion(gfx::Rect(10, 10, 30, 30)); gfx::PointF position(25, 25); gfx::Size bounds(50, 50); - scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345); + scoped_ptr<LayerImpl> testLayer = LayerImpl::create(&hostImpl, 12345); setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMatrix, anchor, position, bounds, false); // override contentBounds and contentsScale @@ -3774,7 +3826,9 @@ TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayer { // The layer's deviceScalefactor and pageScaleFactor should scale the contentRect and we should // be able to hit the touch handler region by scaling the points accordingly. - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 1); gfx::Transform identityMatrix; gfx::PointF anchor(0, 0); @@ -3785,7 +3839,7 @@ TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSingleLayer Region touchHandlerRegion(gfx::Rect(10, 10, 30, 30)); gfx::PointF position(25, 25); gfx::Size bounds(50, 50); - scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345); + scoped_ptr<LayerImpl> testLayer = LayerImpl::create(&hostImpl, 12345); setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMatrix, anchor, position, bounds, false); testLayer->setDrawsContent(true); @@ -3860,17 +3914,19 @@ TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForSimpleClipp gfx::Transform identityMatrix; gfx::PointF anchor(0, 0); - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> root = LayerImpl::create(&hostImpl, 1); setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, gfx::PointF(0, 0), gfx::Size(100, 100), false); { - scoped_ptr<LayerImpl> clippingLayer = LayerImpl::create(123); + scoped_ptr<LayerImpl> clippingLayer = LayerImpl::create(&hostImpl, 123); gfx::PointF position(25, 25); // this layer is positioned, and hit testing should correctly know where the layer is located. gfx::Size bounds(50, 50); setLayerPropertiesForTesting(clippingLayer.get(), identityMatrix, identityMatrix, anchor, position, bounds, false); clippingLayer->setMasksToBounds(true); - scoped_ptr<LayerImpl> child = LayerImpl::create(456); + scoped_ptr<LayerImpl> child = LayerImpl::create(&hostImpl, 456); Region touchHandlerRegion(gfx::Rect(10, 10, 50, 50)); position = gfx::PointF(-50, -50); bounds = gfx::Size(300, 300); diff --git a/cc/layer_tree_host_impl_unittest.cc b/cc/layer_tree_host_impl_unittest.cc index 6de5665..9cc385f 100644 --- a/cc/layer_tree_host_impl_unittest.cc +++ b/cc/layer_tree_host_impl_unittest.cc @@ -103,25 +103,27 @@ public: void setReduceMemoryResult(bool reduceMemoryResult) { m_reduceMemoryResult = reduceMemoryResult; } - scoped_ptr<LayerTreeHostImpl> createLayerTreeHost(bool partialSwap, scoped_ptr<OutputSurface> outputSurface, scoped_ptr<LayerImpl> root) + void createLayerTreeHost(bool partialSwap, scoped_ptr<OutputSurface> outputSurface) { LayerTreeSettings settings; settings.minimumOcclusionTrackingSize = gfx::Size(); settings.partialSwapEnabled = partialSwap; - scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); + m_hostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); - myHostImpl->initializeRenderer(outputSurface.Pass()); - myHostImpl->setViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); + m_hostImpl->initializeRenderer(outputSurface.Pass()); + m_hostImpl->setViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); + } + void setupRootLayerImpl(scoped_ptr<LayerImpl> root) + { root->setAnchorPoint(gfx::PointF(0, 0)); root->setPosition(gfx::PointF(0, 0)); root->setBounds(gfx::Size(10, 10)); root->setContentBounds(gfx::Size(10, 10)); root->setDrawsContent(true); root->drawProperties().visible_content_rect = gfx::Rect(0, 0, 10, 10); - myHostImpl->setRootLayer(root.Pass()); - return myHostImpl.Pass(); + m_hostImpl->setRootLayer(root.Pass()); } static void expectClearedScrollDeltasRecursive(LayerImpl* layer) @@ -160,7 +162,7 @@ public: void setupScrollAndContentsLayers(const gfx::Size& contentSize) { - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + scoped_ptr<LayerImpl> root = LayerImpl::create(m_hostImpl.get(), 1); root->setScrollable(true); root->setScrollOffset(gfx::Vector2d(0, 0)); root->setMaxScrollOffset(gfx::Vector2d(contentSize.width(), contentSize.height())); @@ -169,7 +171,7 @@ public: root->setPosition(gfx::PointF(0, 0)); root->setAnchorPoint(gfx::PointF(0, 0)); - scoped_ptr<LayerImpl> contents = LayerImpl::create(2); + scoped_ptr<LayerImpl> contents = LayerImpl::create(m_hostImpl.get(), 2); contents->setDrawsContent(true); contents->setBounds(contentSize); contents->setContentBounds(contentSize); @@ -179,9 +181,9 @@ public: m_hostImpl->setRootLayer(root.Pass()); } - static scoped_ptr<LayerImpl> createScrollableLayer(int id, const gfx::Size& size) + scoped_ptr<LayerImpl> createScrollableLayer(int id, const gfx::Size& size) { - scoped_ptr<LayerImpl> layer = LayerImpl::create(id); + scoped_ptr<LayerImpl> layer = LayerImpl::create(m_hostImpl.get(), id); layer->setScrollable(true); layer->setDrawsContent(true); layer->setBounds(size); @@ -295,12 +297,12 @@ TEST_P(LayerTreeHostImplTest, scrollDeltaNoLayers) TEST_P(LayerTreeHostImplTest, scrollDeltaTreeButNoChanges) { { - scoped_ptr<LayerImpl> root = LayerImpl::create(1); - root->addChild(LayerImpl::create(2)); - root->addChild(LayerImpl::create(3)); - root->children()[1]->addChild(LayerImpl::create(4)); - root->children()[1]->addChild(LayerImpl::create(5)); - root->children()[1]->children()[0]->addChild(LayerImpl::create(6)); + scoped_ptr<LayerImpl> root = LayerImpl::create(m_hostImpl.get(), 1); + root->addChild(LayerImpl::create(m_hostImpl.get(), 2)); + root->addChild(LayerImpl::create(m_hostImpl.get(), 3)); + root->children()[1]->addChild(LayerImpl::create(m_hostImpl.get(), 4)); + root->children()[1]->addChild(LayerImpl::create(m_hostImpl.get(), 5)); + root->children()[1]->children()[0]->addChild(LayerImpl::create(m_hostImpl.get(), 6)); m_hostImpl->setRootLayer(root.Pass()); } LayerImpl* root = m_hostImpl->rootLayer(); @@ -323,7 +325,7 @@ TEST_P(LayerTreeHostImplTest, scrollDeltaRepeatedScrolls) gfx::Vector2d scrollOffset(20, 30); gfx::Vector2d scrollDelta(11, -15); { - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + scoped_ptr<LayerImpl> root = LayerImpl::create(m_hostImpl.get(), 1); root->setScrollOffset(scrollOffset); root->setScrollable(true); root->setMaxScrollOffset(gfx::Vector2d(100, 100)); @@ -878,7 +880,7 @@ TEST_P(LayerTreeHostImplTest, inhibitScrollAndPageScaleUpdatesWhileAnimatingPage class DidDrawCheckLayer : public TiledLayerImpl { public: - static scoped_ptr<LayerImpl> create(int id) { return scoped_ptr<LayerImpl>(new DidDrawCheckLayer(id)); } + static scoped_ptr<LayerImpl> create(LayerTreeHostImpl* hostImpl, int id) { return scoped_ptr<LayerImpl>(new DidDrawCheckLayer(hostImpl, id)); } virtual void didDraw(ResourceProvider*) OVERRIDE { @@ -900,8 +902,8 @@ public: } protected: - explicit DidDrawCheckLayer(int id) - : TiledLayerImpl(id) + DidDrawCheckLayer(LayerTreeHostImpl* hostImpl, int id) + : TiledLayerImpl(hostImpl, id) , m_didDrawCalled(false) , m_willDrawCalled(false) { @@ -926,11 +928,11 @@ TEST_P(LayerTreeHostImplTest, didDrawNotCalledOnHiddenLayer) { // The root layer is always drawn, so run this test on a child layer that // will be masked out by the root layer's bounds. - m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); + m_hostImpl->setRootLayer(DidDrawCheckLayer::create(m_hostImpl.get(), 1)); DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLayer()); root->setMasksToBounds(true); - root->addChild(DidDrawCheckLayer::create(2)); + root->addChild(DidDrawCheckLayer::create(m_hostImpl.get(), 2)); DidDrawCheckLayer* layer = static_cast<DidDrawCheckLayer*>(root->children()[0]); // Ensure visibleContentRect for layer is empty layer->setPosition(gfx::PointF(100, 100)); @@ -972,13 +974,13 @@ TEST_P(LayerTreeHostImplTest, willDrawNotCalledOnOccludedLayer) gfx::Size bigSize(1000, 1000); m_hostImpl->setViewportSize(bigSize, bigSize); - m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); + m_hostImpl->setRootLayer(DidDrawCheckLayer::create(m_hostImpl.get(), 1)); DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLayer()); - root->addChild(DidDrawCheckLayer::create(2)); + root->addChild(DidDrawCheckLayer::create(m_hostImpl.get(), 2)); DidDrawCheckLayer* occludedLayer = static_cast<DidDrawCheckLayer*>(root->children()[0]); - root->addChild(DidDrawCheckLayer::create(3)); + root->addChild(DidDrawCheckLayer::create(m_hostImpl.get(), 3)); DidDrawCheckLayer* topLayer = static_cast<DidDrawCheckLayer*>(root->children()[1]); // This layer covers the occludedLayer above. Make this layer large so it can occlude. topLayer->setBounds(bigSize); @@ -1004,13 +1006,13 @@ TEST_P(LayerTreeHostImplTest, willDrawNotCalledOnOccludedLayer) TEST_P(LayerTreeHostImplTest, didDrawCalledOnAllLayers) { - m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); + m_hostImpl->setRootLayer(DidDrawCheckLayer::create(m_hostImpl.get(), 1)); DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLayer()); - root->addChild(DidDrawCheckLayer::create(2)); + root->addChild(DidDrawCheckLayer::create(m_hostImpl.get(), 2)); DidDrawCheckLayer* layer1 = static_cast<DidDrawCheckLayer*>(root->children()[0]); - layer1->addChild(DidDrawCheckLayer::create(3)); + layer1->addChild(DidDrawCheckLayer::create(m_hostImpl.get(), 3)); DidDrawCheckLayer* layer2 = static_cast<DidDrawCheckLayer*>(layer1->children()[0]); layer1->setOpacity(0.3f); @@ -1035,14 +1037,14 @@ TEST_P(LayerTreeHostImplTest, didDrawCalledOnAllLayers) class MissingTextureAnimatingLayer : public DidDrawCheckLayer { public: - static scoped_ptr<LayerImpl> create(int id, bool tileMissing, bool skipsDraw, bool animating, ResourceProvider* resourceProvider) + static scoped_ptr<LayerImpl> create(LayerTreeHostImpl* hostImpl, int id, bool tileMissing, bool skipsDraw, bool animating, ResourceProvider* resourceProvider) { - return scoped_ptr<LayerImpl>(new MissingTextureAnimatingLayer(id, tileMissing, skipsDraw, animating, resourceProvider)); + return scoped_ptr<LayerImpl>(new MissingTextureAnimatingLayer(hostImpl, id, tileMissing, skipsDraw, animating, resourceProvider)); } private: - explicit MissingTextureAnimatingLayer(int id, bool tileMissing, bool skipsDraw, bool animating, ResourceProvider* resourceProvider) - : DidDrawCheckLayer(id) + MissingTextureAnimatingLayer(LayerTreeHostImpl* hostImpl, int id, bool tileMissing, bool skipsDraw, bool animating, ResourceProvider* resourceProvider) + : DidDrawCheckLayer(hostImpl, id) { scoped_ptr<LayerTilingData> tilingData = LayerTilingData::create(gfx::Size(10, 10), LayerTilingData::NoBorderTexels); tilingData->setBounds(bounds()); @@ -1060,9 +1062,9 @@ private: TEST_P(LayerTreeHostImplTest, prepareToDrawFailsWhenAnimationUsesCheckerboard) { // When the texture is not missing, we draw as usual. - m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); + m_hostImpl->setRootLayer(DidDrawCheckLayer::create(m_hostImpl.get(), 1)); DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLayer()); - root->addChild(MissingTextureAnimatingLayer::create(2, false, false, true, m_hostImpl->resourceProvider())); + root->addChild(MissingTextureAnimatingLayer::create(m_hostImpl.get(), 2, false, false, true, m_hostImpl->resourceProvider())); LayerTreeHostImpl::FrameData frame; @@ -1071,27 +1073,27 @@ TEST_P(LayerTreeHostImplTest, prepareToDrawFailsWhenAnimationUsesCheckerboard) m_hostImpl->didDrawAllLayers(frame); // When a texture is missing and we're not animating, we draw as usual with checkerboarding. - m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); + m_hostImpl->setRootLayer(DidDrawCheckLayer::create(m_hostImpl.get(), 1)); root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLayer()); - root->addChild(MissingTextureAnimatingLayer::create(2, true, false, false, m_hostImpl->resourceProvider())); + root->addChild(MissingTextureAnimatingLayer::create(m_hostImpl.get(), 2, true, false, false, m_hostImpl->resourceProvider())); EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); m_hostImpl->drawLayers(frame); m_hostImpl->didDrawAllLayers(frame); // When a texture is missing and we're animating, we don't want to draw anything. - m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); + m_hostImpl->setRootLayer(DidDrawCheckLayer::create(m_hostImpl.get(), 1)); root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLayer()); - root->addChild(MissingTextureAnimatingLayer::create(2, true, false, true, m_hostImpl->resourceProvider())); + root->addChild(MissingTextureAnimatingLayer::create(m_hostImpl.get(), 2, true, false, true, m_hostImpl->resourceProvider())); EXPECT_FALSE(m_hostImpl->prepareToDraw(frame)); m_hostImpl->drawLayers(frame); m_hostImpl->didDrawAllLayers(frame); // When the layer skips draw and we're animating, we still draw the frame. - m_hostImpl->setRootLayer(DidDrawCheckLayer::create(1)); + m_hostImpl->setRootLayer(DidDrawCheckLayer::create(m_hostImpl.get(), 1)); root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLayer()); - root->addChild(MissingTextureAnimatingLayer::create(2, false, true, true, m_hostImpl->resourceProvider())); + root->addChild(MissingTextureAnimatingLayer::create(m_hostImpl.get(), 2, false, true, true, m_hostImpl->resourceProvider())); EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); m_hostImpl->drawLayers(frame); @@ -1100,7 +1102,7 @@ TEST_P(LayerTreeHostImplTest, prepareToDrawFailsWhenAnimationUsesCheckerboard) TEST_P(LayerTreeHostImplTest, scrollRootIgnored) { - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + scoped_ptr<LayerImpl> root = LayerImpl::create(m_hostImpl.get(), 1); root->setScrollable(false); m_hostImpl->setRootLayer(root.Pass()); initializeRendererAndDrawFrame(); @@ -1117,7 +1119,7 @@ TEST_P(LayerTreeHostImplTest, scrollNonCompositedRoot) // scrollable outer layer. gfx::Size surfaceSize(10, 10); - scoped_ptr<LayerImpl> contentLayer = LayerImpl::create(1); + scoped_ptr<LayerImpl> contentLayer = LayerImpl::create(m_hostImpl.get(), 1); contentLayer->setUseLCDText(true); contentLayer->setDrawsContent(true); contentLayer->setPosition(gfx::PointF(0, 0)); @@ -1126,7 +1128,7 @@ TEST_P(LayerTreeHostImplTest, scrollNonCompositedRoot) contentLayer->setContentBounds(gfx::Size(surfaceSize.width() * 2, surfaceSize.height() * 2)); contentLayer->setContentsScale(2, 2); - scoped_ptr<LayerImpl> scrollLayer = LayerImpl::create(2); + scoped_ptr<LayerImpl> scrollLayer = LayerImpl::create(m_hostImpl.get(), 2); scrollLayer->setScrollable(true); scrollLayer->setMaxScrollOffset(gfx::Vector2d(surfaceSize.width(), surfaceSize.height())); scrollLayer->setBounds(surfaceSize); @@ -1149,7 +1151,7 @@ TEST_P(LayerTreeHostImplTest, scrollNonCompositedRoot) TEST_P(LayerTreeHostImplTest, scrollChildCallsCommitAndRedraw) { gfx::Size surfaceSize(10, 10); - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + scoped_ptr<LayerImpl> root = LayerImpl::create(m_hostImpl.get(), 1); root->setBounds(surfaceSize); root->setContentBounds(surfaceSize); root->addChild(createScrollableLayer(2, surfaceSize)); @@ -1167,7 +1169,7 @@ TEST_P(LayerTreeHostImplTest, scrollChildCallsCommitAndRedraw) TEST_P(LayerTreeHostImplTest, scrollMissesChild) { gfx::Size surfaceSize(10, 10); - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + scoped_ptr<LayerImpl> root = LayerImpl::create(m_hostImpl.get(), 1); root->addChild(createScrollableLayer(2, surfaceSize)); m_hostImpl->setRootLayer(root.Pass()); m_hostImpl->setViewportSize(surfaceSize, surfaceSize); @@ -1182,7 +1184,7 @@ TEST_P(LayerTreeHostImplTest, scrollMissesChild) TEST_P(LayerTreeHostImplTest, scrollMissesBackfacingChild) { gfx::Size surfaceSize(10, 10); - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + scoped_ptr<LayerImpl> root = LayerImpl::create(m_hostImpl.get(), 1); scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize); m_hostImpl->setViewportSize(surfaceSize, surfaceSize); @@ -1356,7 +1358,7 @@ TEST_P(LayerTreeHostImplTest, pageScaleDeltaAppliedToRootScrollLayerOnly) TEST_P(LayerTreeHostImplTest, scrollChildAndChangePageScaleOnMainThread) { gfx::Size surfaceSize(10, 10); - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + scoped_ptr<LayerImpl> root = LayerImpl::create(m_hostImpl.get(), 1); root->setBounds(surfaceSize); root->setContentBounds(surfaceSize); // Also mark the root scrollable so it becomes the root scroll layer. @@ -1632,7 +1634,7 @@ private: class BlendStateCheckLayer : public LayerImpl { public: - static scoped_ptr<LayerImpl> create(int id, ResourceProvider* resourceProvider) { return scoped_ptr<LayerImpl>(new BlendStateCheckLayer(id, resourceProvider)); } + static scoped_ptr<LayerImpl> create(LayerTreeHostImpl* hostImpl, int id, ResourceProvider* resourceProvider) { return scoped_ptr<LayerImpl>(new BlendStateCheckLayer(hostImpl, id, resourceProvider)); } virtual void appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuadsData) OVERRIDE { @@ -1667,8 +1669,8 @@ public: void setOpaqueContentRect(const gfx::Rect& rect) { m_opaqueContentRect = rect; } private: - explicit BlendStateCheckLayer(int id, ResourceProvider* resourceProvider) - : LayerImpl(id) + BlendStateCheckLayer(LayerTreeHostImpl* hostImpl, int id, ResourceProvider* resourceProvider) + : LayerImpl(hostImpl, id) , m_blend(false) , m_hasRenderSurface(false) , m_quadsAppended(false) @@ -1694,7 +1696,7 @@ private: TEST_P(LayerTreeHostImplTest, blendingOffWhenDrawingOpaqueLayers) { { - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + scoped_ptr<LayerImpl> root = LayerImpl::create(m_hostImpl.get(), 1); root->setAnchorPoint(gfx::PointF(0, 0)); root->setBounds(gfx::Size(10, 10)); root->setContentBounds(root->bounds()); @@ -1703,7 +1705,7 @@ TEST_P(LayerTreeHostImplTest, blendingOffWhenDrawingOpaqueLayers) } LayerImpl* root = m_hostImpl->rootLayer(); - root->addChild(BlendStateCheckLayer::create(2, m_hostImpl->resourceProvider())); + root->addChild(BlendStateCheckLayer::create(m_hostImpl.get(), 2, m_hostImpl->resourceProvider())); BlendStateCheckLayer* layer1 = static_cast<BlendStateCheckLayer*>(root->children()[0]); layer1->setPosition(gfx::PointF(2, 2)); @@ -1743,7 +1745,7 @@ TEST_P(LayerTreeHostImplTest, blendingOffWhenDrawingOpaqueLayers) EXPECT_TRUE(layer1->quadsAppended()); m_hostImpl->didDrawAllLayers(frame); - layer1->addChild(BlendStateCheckLayer::create(3, m_hostImpl->resourceProvider())); + layer1->addChild(BlendStateCheckLayer::create(m_hostImpl.get(), 3, m_hostImpl->resourceProvider())); BlendStateCheckLayer* layer2 = static_cast<BlendStateCheckLayer*>(layer1->children()[0]); layer2->setPosition(gfx::PointF(4, 4)); @@ -1891,8 +1893,8 @@ TEST_P(LayerTreeHostImplTest, viewportCovered) gfx::Size viewportSize(1000, 1000); m_hostImpl->setViewportSize(viewportSize, viewportSize); - m_hostImpl->setRootLayer(LayerImpl::create(1)); - m_hostImpl->rootLayer()->addChild(BlendStateCheckLayer::create(2, m_hostImpl->resourceProvider())); + m_hostImpl->setRootLayer(LayerImpl::create(m_hostImpl.get(), 1)); + m_hostImpl->rootLayer()->addChild(BlendStateCheckLayer::create(m_hostImpl.get(), 2, m_hostImpl->resourceProvider())); BlendStateCheckLayer* child = static_cast<BlendStateCheckLayer*>(m_hostImpl->rootLayer()->children()[0]); child->setExpectation(false, false); child->setContentsOpaque(true); @@ -1987,9 +1989,9 @@ private: class FakeDrawableLayerImpl: public LayerImpl { public: - static scoped_ptr<LayerImpl> create(int id) { return scoped_ptr<LayerImpl>(new FakeDrawableLayerImpl(id)); } + static scoped_ptr<LayerImpl> create(LayerTreeHostImpl* hostImpl, int id) { return scoped_ptr<LayerImpl>(new FakeDrawableLayerImpl(hostImpl, id)); } protected: - explicit FakeDrawableLayerImpl(int id) : LayerImpl(id) { } + FakeDrawableLayerImpl(LayerTreeHostImpl* hostImpl, int id) : LayerImpl(hostImpl, id) { } }; // Only reshape when we know we are going to draw. Otherwise, the reshape @@ -2001,7 +2003,7 @@ TEST_P(LayerTreeHostImplTest, reshapeNotCalledUntilDraw) ReshapeTrackerContext* reshapeTracker = static_cast<ReshapeTrackerContext*>(outputSurface->context3D()); m_hostImpl->initializeRenderer(outputSurface.Pass()); - scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::create(1); + scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::create(m_hostImpl.get(), 1); root->setAnchorPoint(gfx::PointF(0, 0)); root->setBounds(gfx::Size(10, 10)); root->setDrawsContent(true); @@ -2051,8 +2053,8 @@ TEST_P(LayerTreeHostImplTest, partialSwapReceivesDamageRect) layerTreeHostImpl->initializeRenderer(outputSurface.Pass()); layerTreeHostImpl->setViewportSize(gfx::Size(500, 500), gfx::Size(500, 500)); - scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::create(1); - scoped_ptr<LayerImpl> child = FakeDrawableLayerImpl::create(2); + scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::create(m_hostImpl.get(), 1); + scoped_ptr<LayerImpl> child = FakeDrawableLayerImpl::create(m_hostImpl.get(), 2); child->setPosition(gfx::PointF(12, 13)); child->setAnchorPoint(gfx::PointF(0, 0)); child->setBounds(gfx::Size(14, 15)); @@ -2114,8 +2116,8 @@ TEST_P(LayerTreeHostImplTest, partialSwapReceivesDamageRect) TEST_P(LayerTreeHostImplTest, rootLayerDoesntCreateExtraSurface) { - scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::create(1); - scoped_ptr<LayerImpl> child = FakeDrawableLayerImpl::create(2); + scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::create(m_hostImpl.get(), 1); + scoped_ptr<LayerImpl> child = FakeDrawableLayerImpl::create(m_hostImpl.get(), 2); child->setAnchorPoint(gfx::PointF(0, 0)); child->setBounds(gfx::Size(10, 10)); child->setContentBounds(gfx::Size(10, 10)); @@ -2141,7 +2143,7 @@ TEST_P(LayerTreeHostImplTest, rootLayerDoesntCreateExtraSurface) class FakeLayerWithQuads : public LayerImpl { public: - static scoped_ptr<LayerImpl> create(int id) { return scoped_ptr<LayerImpl>(new FakeLayerWithQuads(id)); } + static scoped_ptr<LayerImpl> create(LayerTreeHostImpl* hostImpl, int id) { return scoped_ptr<LayerImpl>(new FakeLayerWithQuads(hostImpl, id)); } virtual void appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuadsData) OVERRIDE { @@ -2155,8 +2157,8 @@ public: } private: - FakeLayerWithQuads(int id) - : LayerImpl(id) + FakeLayerWithQuads(LayerTreeHostImpl* hostImpl, int id) + : LayerImpl(hostImpl, id) { } }; @@ -2260,28 +2262,29 @@ TEST_P(LayerTreeHostImplTest, noPartialSwap) MockContextHarness harness(mockContext); // Run test case - scoped_ptr<LayerTreeHostImpl> myHostImpl = createLayerTreeHost(false, outputSurface.Pass(), FakeLayerWithQuads::create(1)); + createLayerTreeHost(false, outputSurface.Pass()); + setupRootLayerImpl(FakeLayerWithQuads::create(m_hostImpl.get(), 1)); // without partial swap, and no clipping, no scissor is set. harness.mustDrawSolidQuad(); harness.mustSetNoScissor(); { LayerTreeHostImpl::FrameData frame; - EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); - myHostImpl->drawLayers(frame); - myHostImpl->didDrawAllLayers(frame); + EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); + m_hostImpl->drawLayers(frame); + m_hostImpl->didDrawAllLayers(frame); } Mock::VerifyAndClearExpectations(&mockContext); // without partial swap, but a layer does clip its subtree, one scissor is set. - myHostImpl->rootLayer()->setMasksToBounds(true); + m_hostImpl->rootLayer()->setMasksToBounds(true); harness.mustDrawSolidQuad(); harness.mustSetScissor(0, 0, 10, 10); { LayerTreeHostImpl::FrameData frame; - EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); - myHostImpl->drawLayers(frame); - myHostImpl->didDrawAllLayers(frame); + EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); + m_hostImpl->drawLayers(frame); + m_hostImpl->didDrawAllLayers(frame); } Mock::VerifyAndClearExpectations(&mockContext); } @@ -2292,30 +2295,31 @@ TEST_P(LayerTreeHostImplTest, partialSwap) MockContext* mockContext = static_cast<MockContext*>(outputSurface->context3D()); MockContextHarness harness(mockContext); - scoped_ptr<LayerTreeHostImpl> myHostImpl = createLayerTreeHost(true, outputSurface.Pass(), FakeLayerWithQuads::create(1)); + createLayerTreeHost(true, outputSurface.Pass()); + setupRootLayerImpl(FakeLayerWithQuads::create(m_hostImpl.get(), 1)); // The first frame is not a partially-swapped one. harness.mustSetScissor(0, 0, 10, 10); harness.mustDrawSolidQuad(); { LayerTreeHostImpl::FrameData frame; - EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); - myHostImpl->drawLayers(frame); - myHostImpl->didDrawAllLayers(frame); + EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); + m_hostImpl->drawLayers(frame); + m_hostImpl->didDrawAllLayers(frame); } Mock::VerifyAndClearExpectations(&mockContext); // Damage a portion of the frame. - myHostImpl->rootLayer()->setUpdateRect(gfx::Rect(0, 0, 2, 3)); + m_hostImpl->rootLayer()->setUpdateRect(gfx::Rect(0, 0, 2, 3)); // The second frame will be partially-swapped (the y coordinates are flipped). harness.mustSetScissor(0, 7, 2, 3); harness.mustDrawSolidQuad(); { LayerTreeHostImpl::FrameData frame; - EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); - myHostImpl->drawLayers(frame); - myHostImpl->didDrawAllLayers(frame); + EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); + m_hostImpl->drawLayers(frame); + m_hostImpl->didDrawAllLayers(frame); } Mock::VerifyAndClearExpectations(&mockContext); } @@ -2370,9 +2374,9 @@ static scoped_ptr<LayerTreeHostImpl> setupLayersForOpacity(bool partialSwap, Lay Layers 1, 2 have render surfaces */ - scoped_ptr<LayerImpl> root = LayerImpl::create(1); - scoped_ptr<LayerImpl> child = LayerImpl::create(2); - scoped_ptr<LayerImpl> grandChild = FakeLayerWithQuads::create(3); + scoped_ptr<LayerImpl> root = LayerImpl::create(myHostImpl.get(), 1); + scoped_ptr<LayerImpl> child = LayerImpl::create(myHostImpl.get(), 2); + scoped_ptr<LayerImpl> grandChild = FakeLayerWithQuads::create(myHostImpl.get(), 3); gfx::Rect rootRect(0, 0, 100, 100); gfx::Rect childRect(10, 10, 50, 50); @@ -2453,7 +2457,7 @@ TEST_P(LayerTreeHostImplTest, contributingLayerEmptyScissorNoPartialSwap) // Make sure that output surface lost notifications are propagated through the tree. class OutputSurfaceLostNotificationCheckLayer : public LayerImpl { public: - static scoped_ptr<LayerImpl> create(int id) { return scoped_ptr<LayerImpl>(new OutputSurfaceLostNotificationCheckLayer(id)); } + static scoped_ptr<LayerImpl> create(LayerTreeHostImpl* hostImpl, int id) { return scoped_ptr<LayerImpl>(new OutputSurfaceLostNotificationCheckLayer(hostImpl, id)); } virtual void didLoseOutputSurface() OVERRIDE { @@ -2463,8 +2467,8 @@ public: bool didLoseOutputSurfaceCalled() const { return m_didLoseOutputSurfaceCalled; } private: - explicit OutputSurfaceLostNotificationCheckLayer(int id) - : LayerImpl(id) + OutputSurfaceLostNotificationCheckLayer(LayerTreeHostImpl* hostImpl, int id) + : LayerImpl(hostImpl, id) , m_didLoseOutputSurfaceCalled(false) { } @@ -2474,13 +2478,13 @@ private: TEST_P(LayerTreeHostImplTest, outputSurfaceLostAndRestoredNotificationSentToAllLayers) { - m_hostImpl->setRootLayer(OutputSurfaceLostNotificationCheckLayer::create(1)); + m_hostImpl->setRootLayer(OutputSurfaceLostNotificationCheckLayer::create(m_hostImpl.get(), 1)); OutputSurfaceLostNotificationCheckLayer* root = static_cast<OutputSurfaceLostNotificationCheckLayer*>(m_hostImpl->rootLayer()); - root->addChild(OutputSurfaceLostNotificationCheckLayer::create(1)); + root->addChild(OutputSurfaceLostNotificationCheckLayer::create(m_hostImpl.get(), 1)); OutputSurfaceLostNotificationCheckLayer* layer1 = static_cast<OutputSurfaceLostNotificationCheckLayer*>(root->children()[0]); - layer1->addChild(OutputSurfaceLostNotificationCheckLayer::create(2)); + layer1->addChild(OutputSurfaceLostNotificationCheckLayer::create(m_hostImpl.get(), 2)); OutputSurfaceLostNotificationCheckLayer* layer2 = static_cast<OutputSurfaceLostNotificationCheckLayer*>(layer1->children()[0]); EXPECT_FALSE(root->didLoseOutputSurfaceCalled()); @@ -2740,9 +2744,9 @@ class FakeWebScrollbarThemeGeometryNonEmpty : public FakeWebScrollbarThemeGeomet class FakeScrollbarLayerImpl : public ScrollbarLayerImpl { public: - static scoped_ptr<FakeScrollbarLayerImpl> create(int id) + static scoped_ptr<FakeScrollbarLayerImpl> create(LayerTreeHostImpl* hostImpl, int id) { - return make_scoped_ptr(new FakeScrollbarLayerImpl(id)); + return make_scoped_ptr(new FakeScrollbarLayerImpl(hostImpl, id)); } void createResources(ResourceProvider* provider) @@ -2760,8 +2764,8 @@ public: } protected: - explicit FakeScrollbarLayerImpl(int id) - : ScrollbarLayerImpl(id) + FakeScrollbarLayerImpl(LayerTreeHostImpl* hostImpl, int id) + : ScrollbarLayerImpl(hostImpl, id) { } }; @@ -2787,11 +2791,11 @@ TEST_P(LayerTreeHostImplTest, dontUseOldResourcesAfterLostOutputSurface) { int layerId = 1; - scoped_ptr<LayerImpl> rootLayer(LayerImpl::create(layerId++)); + scoped_ptr<LayerImpl> rootLayer(LayerImpl::create(m_hostImpl.get(), layerId++)); rootLayer->setBounds(gfx::Size(10, 10)); rootLayer->setAnchorPoint(gfx::PointF(0, 0)); - scoped_ptr<TiledLayerImpl> tileLayer = TiledLayerImpl::create(layerId++); + scoped_ptr<TiledLayerImpl> tileLayer = TiledLayerImpl::create(m_hostImpl.get(), layerId++); tileLayer->setBounds(gfx::Size(10, 10)); tileLayer->setAnchorPoint(gfx::PointF(0, 0)); tileLayer->setContentBounds(gfx::Size(10, 10)); @@ -2803,7 +2807,7 @@ TEST_P(LayerTreeHostImplTest, dontUseOldResourcesAfterLostOutputSurface) tileLayer->pushTileProperties(0, 0, 1, gfx::Rect(0, 0, 10, 10), false); rootLayer->addChild(tileLayer.PassAs<LayerImpl>()); - scoped_ptr<TextureLayerImpl> textureLayer = TextureLayerImpl::create(layerId++); + scoped_ptr<TextureLayerImpl> textureLayer = TextureLayerImpl::create(m_hostImpl.get(), layerId++); textureLayer->setBounds(gfx::Size(10, 10)); textureLayer->setAnchorPoint(gfx::PointF(0, 0)); textureLayer->setContentBounds(gfx::Size(10, 10)); @@ -2811,7 +2815,7 @@ TEST_P(LayerTreeHostImplTest, dontUseOldResourcesAfterLostOutputSurface) textureLayer->setTextureId(StrictWebGraphicsContext3D::kExternalTextureId); rootLayer->addChild(textureLayer.PassAs<LayerImpl>()); - scoped_ptr<TiledLayerImpl> maskLayer = TiledLayerImpl::create(layerId++); + scoped_ptr<TiledLayerImpl> maskLayer = TiledLayerImpl::create(m_hostImpl.get(), layerId++); maskLayer->setBounds(gfx::Size(10, 10)); maskLayer->setAnchorPoint(gfx::PointF(0, 0)); maskLayer->setContentBounds(gfx::Size(10, 10)); @@ -2820,7 +2824,7 @@ TEST_P(LayerTreeHostImplTest, dontUseOldResourcesAfterLostOutputSurface) maskLayer->setTilingData(*tilingData); maskLayer->pushTileProperties(0, 0, 1, gfx::Rect(0, 0, 10, 10), false); - scoped_ptr<TextureLayerImpl> textureLayerWithMask = TextureLayerImpl::create(layerId++); + scoped_ptr<TextureLayerImpl> textureLayerWithMask = TextureLayerImpl::create(m_hostImpl.get(), layerId++); textureLayerWithMask->setBounds(gfx::Size(10, 10)); textureLayerWithMask->setAnchorPoint(gfx::PointF(0, 0)); textureLayerWithMask->setContentBounds(gfx::Size(10, 10)); @@ -2836,62 +2840,55 @@ TEST_P(LayerTreeHostImplTest, dontUseOldResourcesAfterLostOutputSurface) base::Bind(FakeVideoFrame::toVideoFrame); FakeVideoFrameProvider provider; provider.setFrame(&videoFrame); - scoped_ptr<VideoLayerImpl> videoLayer = VideoLayerImpl::create(layerId++, &provider, unwrapper); + scoped_ptr<VideoLayerImpl> videoLayer = VideoLayerImpl::create(m_hostImpl.get(), layerId++, &provider, unwrapper); videoLayer->setBounds(gfx::Size(10, 10)); videoLayer->setAnchorPoint(gfx::PointF(0, 0)); videoLayer->setContentBounds(gfx::Size(10, 10)); videoLayer->setDrawsContent(true); - videoLayer->setLayerTreeHostImpl(m_hostImpl.get()); rootLayer->addChild(videoLayer.PassAs<LayerImpl>()); FakeVideoFrameProvider providerScaled; - scoped_ptr<VideoLayerImpl> videoLayerScaled = VideoLayerImpl::create(layerId++, &providerScaled, unwrapper); + scoped_ptr<VideoLayerImpl> videoLayerScaled = VideoLayerImpl::create(m_hostImpl.get(), layerId++, &providerScaled, unwrapper); videoLayerScaled->setBounds(gfx::Size(10, 10)); videoLayerScaled->setAnchorPoint(gfx::PointF(0, 0)); videoLayerScaled->setContentBounds(gfx::Size(10, 10)); videoLayerScaled->setDrawsContent(true); - videoLayerScaled->setLayerTreeHostImpl(m_hostImpl.get()); rootLayer->addChild(videoLayerScaled.PassAs<LayerImpl>()); FakeVideoFrameProvider hwProvider; - scoped_ptr<VideoLayerImpl> hwVideoLayer = VideoLayerImpl::create(layerId++, &hwProvider, unwrapper); + scoped_ptr<VideoLayerImpl> hwVideoLayer = VideoLayerImpl::create(m_hostImpl.get(), layerId++, &hwProvider, unwrapper); hwVideoLayer->setBounds(gfx::Size(10, 10)); hwVideoLayer->setAnchorPoint(gfx::PointF(0, 0)); hwVideoLayer->setContentBounds(gfx::Size(10, 10)); hwVideoLayer->setDrawsContent(true); - hwVideoLayer->setLayerTreeHostImpl(m_hostImpl.get()); rootLayer->addChild(hwVideoLayer.PassAs<LayerImpl>()); - scoped_ptr<IOSurfaceLayerImpl> ioSurfaceLayer = IOSurfaceLayerImpl::create(layerId++); + scoped_ptr<IOSurfaceLayerImpl> ioSurfaceLayer = IOSurfaceLayerImpl::create(m_hostImpl.get(), layerId++); ioSurfaceLayer->setBounds(gfx::Size(10, 10)); ioSurfaceLayer->setAnchorPoint(gfx::PointF(0, 0)); ioSurfaceLayer->setContentBounds(gfx::Size(10, 10)); ioSurfaceLayer->setDrawsContent(true); ioSurfaceLayer->setIOSurfaceProperties(1, gfx::Size(10, 10)); - ioSurfaceLayer->setLayerTreeHostImpl(m_hostImpl.get()); rootLayer->addChild(ioSurfaceLayer.PassAs<LayerImpl>()); - scoped_ptr<HeadsUpDisplayLayerImpl> hudLayer = HeadsUpDisplayLayerImpl::create(layerId++); + scoped_ptr<HeadsUpDisplayLayerImpl> hudLayer = HeadsUpDisplayLayerImpl::create(m_hostImpl.get(), layerId++); hudLayer->setBounds(gfx::Size(10, 10)); hudLayer->setAnchorPoint(gfx::PointF(0, 0)); hudLayer->setContentBounds(gfx::Size(10, 10)); hudLayer->setDrawsContent(true); - hudLayer->setLayerTreeHostImpl(m_hostImpl.get()); rootLayer->addChild(hudLayer.PassAs<LayerImpl>()); - scoped_ptr<FakeScrollbarLayerImpl> scrollbarLayer(FakeScrollbarLayerImpl::create(layerId++)); + scoped_ptr<FakeScrollbarLayerImpl> scrollbarLayer(FakeScrollbarLayerImpl::create(m_hostImpl.get(), layerId++)); scrollbarLayer->setBounds(gfx::Size(10, 10)); scrollbarLayer->setContentBounds(gfx::Size(10, 10)); scrollbarLayer->setDrawsContent(true); - scrollbarLayer->setLayerTreeHostImpl(m_hostImpl.get()); scrollbarLayer->createResources(m_hostImpl->resourceProvider()); rootLayer->addChild(scrollbarLayer.PassAs<LayerImpl>()); - scoped_ptr<DelegatedRendererLayerImpl> delegatedRendererLayer(DelegatedRendererLayerImpl::create(layerId++)); + scoped_ptr<DelegatedRendererLayerImpl> delegatedRendererLayer(DelegatedRendererLayerImpl::create(m_hostImpl.get(), layerId++)); delegatedRendererLayer->setBounds(gfx::Size(10, 10)); delegatedRendererLayer->setContentBounds(gfx::Size(10, 10)); delegatedRendererLayer->setDrawsContent(true); - delegatedRendererLayer->setLayerTreeHostImpl(m_hostImpl.get()); ScopedPtrVector<RenderPass> passList; passList.append(createRenderPassWithResource(m_hostImpl->resourceProvider())); delegatedRendererLayer->setRenderPasses(passList); @@ -3003,11 +3000,11 @@ private: TEST_P(LayerTreeHostImplTest, layersFreeTextures) { - scoped_ptr<LayerImpl> rootLayer(LayerImpl::create(1)); + scoped_ptr<LayerImpl> rootLayer(LayerImpl::create(m_hostImpl.get(), 1)); rootLayer->setBounds(gfx::Size(10, 10)); rootLayer->setAnchorPoint(gfx::PointF(0, 0)); - scoped_ptr<TiledLayerImpl> tileLayer = TiledLayerImpl::create(2); + scoped_ptr<TiledLayerImpl> tileLayer = TiledLayerImpl::create(m_hostImpl.get(), 2); tileLayer->setBounds(gfx::Size(10, 10)); tileLayer->setAnchorPoint(gfx::PointF(0, 0)); tileLayer->setContentBounds(gfx::Size(10, 10)); @@ -3019,7 +3016,7 @@ TEST_P(LayerTreeHostImplTest, layersFreeTextures) tileLayer->pushTileProperties(0, 0, 1, gfx::Rect(0, 0, 10, 10), false); rootLayer->addChild(tileLayer.PassAs<LayerImpl>()); - scoped_ptr<TextureLayerImpl> textureLayer = TextureLayerImpl::create(3); + scoped_ptr<TextureLayerImpl> textureLayer = TextureLayerImpl::create(m_hostImpl.get(), 3); textureLayer->setBounds(gfx::Size(10, 10)); textureLayer->setAnchorPoint(gfx::PointF(0, 0)); textureLayer->setContentBounds(gfx::Size(10, 10)); @@ -3030,21 +3027,19 @@ TEST_P(LayerTreeHostImplTest, layersFreeTextures) VideoLayerImpl::FrameUnwrapper unwrapper = base::Bind(FakeVideoFrame::toVideoFrame); FakeVideoFrameProvider provider; - scoped_ptr<VideoLayerImpl> videoLayer = VideoLayerImpl::create(4, &provider, unwrapper); + scoped_ptr<VideoLayerImpl> videoLayer = VideoLayerImpl::create(m_hostImpl.get(), 4, &provider, unwrapper); videoLayer->setBounds(gfx::Size(10, 10)); videoLayer->setAnchorPoint(gfx::PointF(0, 0)); videoLayer->setContentBounds(gfx::Size(10, 10)); videoLayer->setDrawsContent(true); - videoLayer->setLayerTreeHostImpl(m_hostImpl.get()); rootLayer->addChild(videoLayer.PassAs<LayerImpl>()); - scoped_ptr<IOSurfaceLayerImpl> ioSurfaceLayer = IOSurfaceLayerImpl::create(5); + scoped_ptr<IOSurfaceLayerImpl> ioSurfaceLayer = IOSurfaceLayerImpl::create(m_hostImpl.get(), 5); ioSurfaceLayer->setBounds(gfx::Size(10, 10)); ioSurfaceLayer->setAnchorPoint(gfx::PointF(0, 0)); ioSurfaceLayer->setContentBounds(gfx::Size(10, 10)); ioSurfaceLayer->setDrawsContent(true); ioSurfaceLayer->setIOSurfaceProperties(1, gfx::Size(10, 10)); - ioSurfaceLayer->setLayerTreeHostImpl(m_hostImpl.get()); rootLayer->addChild(ioSurfaceLayer.PassAs<LayerImpl>()); // Lose the WebGraphicsContext3D, replacing it with a TrackingWebGraphicsContext3D (which the LayerTreeHostImpl takes ownership of). @@ -3063,7 +3058,7 @@ TEST_P(LayerTreeHostImplTest, layersFreeTextures) EXPECT_GT(trackingWebGraphicsContext3D->numTextures(), 0u); // Kill the layer tree. - m_hostImpl->setRootLayer(LayerImpl::create(100)); + m_hostImpl->setRootLayer(LayerImpl::create(m_hostImpl.get(), 100)); // There should be no textures left in use after. EXPECT_EQ(0u, trackingWebGraphicsContext3D->numTextures()); } @@ -3080,32 +3075,33 @@ TEST_P(LayerTreeHostImplTest, hasTransparentBackground) MockDrawQuadsToFillScreenContext* mockContext = static_cast<MockDrawQuadsToFillScreenContext*>(outputSurface->context3D()); // Run test case - scoped_ptr<LayerTreeHostImpl> myHostImpl = createLayerTreeHost(false, outputSurface.Pass(), LayerImpl::create(1)); - myHostImpl->setBackgroundColor(SK_ColorWHITE); + createLayerTreeHost(false, outputSurface.Pass()); + setupRootLayerImpl(LayerImpl::create(m_hostImpl.get(), 1)); + m_hostImpl->setBackgroundColor(SK_ColorWHITE); // Verify one quad is drawn when transparent background set is not set. - myHostImpl->setHasTransparentBackground(false); + m_hostImpl->setHasTransparentBackground(false); EXPECT_CALL(*mockContext, useProgram(_)) .Times(1); EXPECT_CALL(*mockContext, drawElements(_, _, _, _)) .Times(1); LayerTreeHostImpl::FrameData frame; - EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); - myHostImpl->drawLayers(frame); - myHostImpl->didDrawAllLayers(frame); + EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); + m_hostImpl->drawLayers(frame); + m_hostImpl->didDrawAllLayers(frame); Mock::VerifyAndClearExpectations(&mockContext); // Verify no quads are drawn when transparent background is set. - myHostImpl->setHasTransparentBackground(true); - EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); - myHostImpl->drawLayers(frame); - myHostImpl->didDrawAllLayers(frame); + m_hostImpl->setHasTransparentBackground(true); + EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); + m_hostImpl->drawLayers(frame); + m_hostImpl->didDrawAllLayers(frame); Mock::VerifyAndClearExpectations(&mockContext); } static void addDrawingLayerTo(LayerImpl* parent, int id, const gfx::Rect& layerRect, LayerImpl** result) { - scoped_ptr<LayerImpl> layer = FakeLayerWithQuads::create(id); + scoped_ptr<LayerImpl> layer = FakeLayerWithQuads::create(parent->layerTreeHostImpl(), id); LayerImpl* layerPtr = layer.get(); layerPtr->setAnchorPoint(gfx::PointF(0, 0)); layerPtr->setPosition(gfx::PointF(layerRect.origin())); @@ -3125,7 +3121,7 @@ static void setupLayersForTextureCaching(LayerTreeHostImpl* layerTreeHostImpl, L layerTreeHostImpl->initializeRenderer(outputSurface.Pass()); layerTreeHostImpl->setViewportSize(rootSize, rootSize); - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + scoped_ptr<LayerImpl> root = LayerImpl::create(layerTreeHostImpl, 1); rootPtr = root.get(); root->setAnchorPoint(gfx::PointF(0, 0)); @@ -3171,7 +3167,7 @@ TEST_P(LayerTreeHostImplTest, textureCachingWithClipping) myHostImpl->initializeRenderer(outputSurface.Pass()); myHostImpl->setViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height())); - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + scoped_ptr<LayerImpl> root = LayerImpl::create(myHostImpl.get(), 1); rootPtr = root.get(); root->setAnchorPoint(gfx::PointF(0, 0)); @@ -3282,7 +3278,7 @@ TEST_P(LayerTreeHostImplTest, textureCachingWithOcclusion) myHostImpl->initializeRenderer(outputSurface.Pass()); myHostImpl->setViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height())); - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + scoped_ptr<LayerImpl> root = LayerImpl::create(myHostImpl.get(), 1); rootPtr = root.get(); root->setAnchorPoint(gfx::PointF(0, 0)); @@ -3393,7 +3389,7 @@ TEST_P(LayerTreeHostImplTest, textureCachingWithOcclusionEarlyOut) myHostImpl->initializeRenderer(outputSurface.Pass()); myHostImpl->setViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height())); - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + scoped_ptr<LayerImpl> root = LayerImpl::create(myHostImpl.get(), 1); rootPtr = root.get(); root->setAnchorPoint(gfx::PointF(0, 0)); @@ -3505,7 +3501,7 @@ TEST_P(LayerTreeHostImplTest, textureCachingWithOcclusionExternalOverInternal) myHostImpl->initializeRenderer(outputSurface.Pass()); myHostImpl->setViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height())); - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + scoped_ptr<LayerImpl> root = LayerImpl::create(myHostImpl.get(), 1); rootPtr = root.get(); root->setAnchorPoint(gfx::PointF(0, 0)); @@ -3586,7 +3582,7 @@ TEST_P(LayerTreeHostImplTest, textureCachingWithOcclusionExternalNotAligned) myHostImpl->initializeRenderer(outputSurface.Pass()); myHostImpl->setViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height())); - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + scoped_ptr<LayerImpl> root = LayerImpl::create(myHostImpl.get(), 1); rootPtr = root.get(); root->setAnchorPoint(gfx::PointF(0, 0)); @@ -3670,7 +3666,7 @@ TEST_P(LayerTreeHostImplTest, textureCachingWithOcclusionPartialSwap) myHostImpl->initializeRenderer(outputSurface.Pass()); myHostImpl->setViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height())); - scoped_ptr<LayerImpl> root = LayerImpl::create(1); + scoped_ptr<LayerImpl> root = LayerImpl::create(myHostImpl.get(), 1); rootPtr = root.get(); root->setAnchorPoint(gfx::PointF(0, 0)); @@ -3774,9 +3770,9 @@ TEST_P(LayerTreeHostImplTest, textureCachingWithScissor) Layers 1, 2 have render surfaces */ - scoped_ptr<LayerImpl> root = LayerImpl::create(1); - scoped_ptr<TiledLayerImpl> child = TiledLayerImpl::create(2); - scoped_ptr<LayerImpl> grandChild = LayerImpl::create(3); + scoped_ptr<LayerImpl> root = LayerImpl::create(myHostImpl.get(), 1); + scoped_ptr<TiledLayerImpl> child = TiledLayerImpl::create(myHostImpl.get(), 2); + scoped_ptr<LayerImpl> grandChild = LayerImpl::create(myHostImpl.get(), 3); gfx::Rect rootRect(0, 0, 100, 100); gfx::Rect childRect(10, 10, 50, 50); diff --git a/cc/layer_tree_host_unittest.cc b/cc/layer_tree_host_unittest.cc index a9a5e0f..c7c61fc 100644 --- a/cc/layer_tree_host_unittest.cc +++ b/cc/layer_tree_host_unittest.cc @@ -2617,7 +2617,7 @@ public: virtual void update(ResourceUpdateQueue&, const OcclusionTracker*, RenderingStats&) OVERRIDE; virtual bool drawsContent() const OVERRIDE { return true; } - virtual scoped_ptr<LayerImpl> createLayerImpl() OVERRIDE; + virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeHostImpl* hostImpl) OVERRIDE; virtual void pushPropertiesTo(LayerImpl*) OVERRIDE; virtual void setTexturePriorities(const PriorityCalculator&) OVERRIDE; @@ -2642,9 +2642,9 @@ private: class EvictionTestLayerImpl : public LayerImpl { public: - static scoped_ptr<EvictionTestLayerImpl> create(int id) + static scoped_ptr<EvictionTestLayerImpl> create(LayerTreeHostImpl* hostImpl, int id) { - return make_scoped_ptr(new EvictionTestLayerImpl(id)); + return make_scoped_ptr(new EvictionTestLayerImpl(hostImpl, id)); } virtual ~EvictionTestLayerImpl() { } @@ -2657,8 +2657,8 @@ public: void setHasTexture(bool hasTexture) { m_hasTexture = hasTexture; } private: - explicit EvictionTestLayerImpl(int id) - : LayerImpl(id) + EvictionTestLayerImpl(LayerTreeHostImpl* hostImpl, int id) + : LayerImpl(hostImpl, id) , m_hasTexture(false) { } bool m_hasTexture; @@ -2684,9 +2684,9 @@ void EvictionTestLayer::update(ResourceUpdateQueue& queue, const OcclusionTracke queue.appendFullUpload(upload); } -scoped_ptr<LayerImpl> EvictionTestLayer::createLayerImpl() +scoped_ptr<LayerImpl> EvictionTestLayer::createLayerImpl(LayerTreeHostImpl* hostImpl) { - return EvictionTestLayerImpl::create(m_layerId).PassAs<LayerImpl>(); + return EvictionTestLayerImpl::create(hostImpl, m_layerId).PassAs<LayerImpl>(); } void EvictionTestLayer::pushPropertiesTo(LayerImpl* layerImpl) diff --git a/cc/layer_unittest.cc b/cc/layer_unittest.cc index 5267659..60358a4 100644 --- a/cc/layer_unittest.cc +++ b/cc/layer_unittest.cc @@ -10,9 +10,11 @@ #include "cc/layer_tree_host.h" #include "cc/math_util.h" #include "cc/single_thread_proxy.h" -#include "cc/thread.h" +#include "cc/test/fake_impl_proxy.h" #include "cc/test/fake_layer_tree_host_client.h" +#include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/geometry_test_utils.h" +#include "cc/thread.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/transform.h" @@ -63,6 +65,7 @@ public: class LayerTest : public testing::Test { public: LayerTest() + : m_hostImpl(&m_proxy) { } @@ -136,8 +139,17 @@ protected: verifyTestTreeInitialState(); } + FakeImplProxy m_proxy; + FakeLayerTreeHostImpl m_hostImpl; + scoped_ptr<StrictMock<MockLayerImplTreeHost> > m_layerTreeHost; - scoped_refptr<Layer> m_parent, m_child1, m_child2, m_child3, m_grandChild1, m_grandChild2, m_grandChild3; + scoped_refptr<Layer> m_parent; + scoped_refptr<Layer> m_child1; + scoped_refptr<Layer> m_child2; + scoped_refptr<Layer> m_child3; + scoped_refptr<Layer> m_grandChild1; + scoped_refptr<Layer> m_grandChild2; + scoped_refptr<Layer> m_grandChild3; }; TEST_F(LayerTest, basicCreateAndDestroy) @@ -547,7 +559,7 @@ TEST_F(LayerTest, checkPropertyChangeCausesCorrectBehavior) TEST_F(LayerTest, verifyPushPropertiesAccumulatesUpdateRect) { scoped_refptr<Layer> testLayer = Layer::create(); - scoped_ptr<LayerImpl> implLayer = LayerImpl::create(1); + scoped_ptr<LayerImpl> implLayer = LayerImpl::create(&m_hostImpl, 1); testLayer->setNeedsDisplayRect(gfx::RectF(gfx::PointF(), gfx::SizeF(5, 5))); testLayer->pushPropertiesTo(implLayer.get()); diff --git a/cc/nine_patch_layer.cc b/cc/nine_patch_layer.cc index b4001b2..f121fc9 100644 --- a/cc/nine_patch_layer.cc +++ b/cc/nine_patch_layer.cc @@ -25,9 +25,9 @@ NinePatchLayer::~NinePatchLayer() { } -scoped_ptr<LayerImpl> NinePatchLayer::createLayerImpl() +scoped_ptr<LayerImpl> NinePatchLayer::createLayerImpl(LayerTreeHostImpl* hostImpl) { - return NinePatchLayerImpl::create(id()).PassAs<LayerImpl>(); + return NinePatchLayerImpl::create(hostImpl, id()).PassAs<LayerImpl>(); } void NinePatchLayer::setTexturePriorities(const PriorityCalculator& priorityCalc) diff --git a/cc/nine_patch_layer.h b/cc/nine_patch_layer.h index a11cd65..6a8c613 100644 --- a/cc/nine_patch_layer.h +++ b/cc/nine_patch_layer.h @@ -36,7 +36,7 @@ public: private: NinePatchLayer(); virtual ~NinePatchLayer(); - virtual scoped_ptr<LayerImpl> createLayerImpl() OVERRIDE; + virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeHostImpl* hostImpl) OVERRIDE; void createUpdaterIfNeeded(); void createResource(); diff --git a/cc/nine_patch_layer_impl.cc b/cc/nine_patch_layer_impl.cc index 46a8af2..e4d36eb 100644 --- a/cc/nine_patch_layer_impl.cc +++ b/cc/nine_patch_layer_impl.cc @@ -11,8 +11,8 @@ namespace cc { -NinePatchLayerImpl::NinePatchLayerImpl(int id) - : LayerImpl(id) +NinePatchLayerImpl::NinePatchLayerImpl(LayerTreeHostImpl* hostImpl, int id) + : LayerImpl(hostImpl, id) , m_resourceId(0) { } diff --git a/cc/nine_patch_layer_impl.h b/cc/nine_patch_layer_impl.h index f574c3a..404ae2b 100644 --- a/cc/nine_patch_layer_impl.h +++ b/cc/nine_patch_layer_impl.h @@ -15,9 +15,9 @@ namespace cc { class CC_EXPORT NinePatchLayerImpl : public LayerImpl { public: - static scoped_ptr<NinePatchLayerImpl> create(int id) + static scoped_ptr<NinePatchLayerImpl> create(LayerTreeHostImpl* hostImpl, int id) { - return make_scoped_ptr(new NinePatchLayerImpl(id)); + return make_scoped_ptr(new NinePatchLayerImpl(hostImpl, id)); } virtual ~NinePatchLayerImpl(); @@ -32,7 +32,7 @@ public: virtual void didLoseOutputSurface() OVERRIDE; protected: - explicit NinePatchLayerImpl(int id); + NinePatchLayerImpl(LayerTreeHostImpl* hostImpl, int id); private: virtual const char* layerTypeAsString() const OVERRIDE; diff --git a/cc/nine_patch_layer_impl_unittest.cc b/cc/nine_patch_layer_impl_unittest.cc index acda97d..058e94b 100644 --- a/cc/nine_patch_layer_impl_unittest.cc +++ b/cc/nine_patch_layer_impl_unittest.cc @@ -8,6 +8,8 @@ #include "cc/append_quads_data.h" #include "cc/single_thread_proxy.h" +#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/geometry_test_utils.h" #include "cc/test/layer_test_common.h" #include "cc/test/mock_quad_culler.h" @@ -37,7 +39,9 @@ TEST(NinePatchLayerImplTest, verifyDrawQuads) gfx::Rect apertureRect(20, 30, 40, 50); gfx::Rect scaledApertureNonUniform(20, 30, 340, 350); - scoped_ptr<NinePatchLayerImpl> layer = NinePatchLayerImpl::create(1); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<NinePatchLayerImpl> layer = NinePatchLayerImpl::create(&hostImpl, 1); layer->drawProperties().visible_content_rect = visibleContentRect; layer->setBounds(layerSize); layer->setContentBounds(layerSize); @@ -96,7 +100,9 @@ TEST(NinePatchLayerImplTest, verifyDrawQuadsForSqueezedLayer) gfx::Rect visibleContentRect(gfx::Point(), layerSize); gfx::Rect apertureRect(20, 30, 40, 45); // rightWidth: 40, botHeight: 25 - scoped_ptr<NinePatchLayerImpl> layer = NinePatchLayerImpl::create(1); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<NinePatchLayerImpl> layer = NinePatchLayerImpl::create(&hostImpl, 1); layer->drawProperties().visible_content_rect = visibleContentRect; layer->setBounds(layerSize); layer->setContentBounds(layerSize); diff --git a/cc/occlusion_tracker_unittest.cc b/cc/occlusion_tracker_unittest.cc index 6b23aca..5f366fb 100644 --- a/cc/occlusion_tracker_unittest.cc +++ b/cc/occlusion_tracker_unittest.cc @@ -15,6 +15,8 @@ #include "cc/overdraw_metrics.h" #include "cc/single_thread_proxy.h" #include "cc/test/animation_test_common.h" +#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/geometry_test_utils.h" #include "cc/test/occlusion_tracker_test_common.h" #include "testing/gmock/include/gmock/gmock.h" @@ -59,8 +61,8 @@ private: class TestContentLayerImpl : public LayerImpl { public: - TestContentLayerImpl(int id) - : LayerImpl(id) + TestContentLayerImpl(LayerTreeHostImpl* hostImpl, int id) + : LayerImpl(hostImpl, id) , m_overrideOpaqueContentsRect(false) { setDrawsContent(true); @@ -119,6 +121,7 @@ private: struct OcclusionTrackerTestMainThreadTypes { typedef Layer LayerType; + typedef LayerTreeHost HostType; typedef RenderSurface RenderSurfaceType; typedef TestContentLayer ContentLayerType; typedef scoped_refptr<Layer> LayerPtrType; @@ -126,11 +129,11 @@ struct OcclusionTrackerTestMainThreadTypes { typedef LayerIterator<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, LayerIteratorActions::FrontToBack> TestLayerIterator; typedef OcclusionTracker OcclusionTrackerType; - static LayerPtrType createLayer() + static LayerPtrType createLayer(HostType*) { return Layer::create(); } - static ContentLayerPtrType createContentLayer() { return make_scoped_refptr(new ContentLayerType()); } + static ContentLayerPtrType createContentLayer(HostType*) { return make_scoped_refptr(new ContentLayerType()); } static LayerPtrType passLayerPtr(ContentLayerPtrType& layer) { @@ -154,6 +157,7 @@ struct OcclusionTrackerTestMainThreadTypes { struct OcclusionTrackerTestImplThreadTypes { typedef LayerImpl LayerType; + typedef LayerTreeHostImpl HostType; typedef RenderSurfaceImpl RenderSurfaceType; typedef TestContentLayerImpl ContentLayerType; typedef scoped_ptr<LayerImpl> LayerPtrType; @@ -161,8 +165,8 @@ struct OcclusionTrackerTestImplThreadTypes { typedef LayerIterator<LayerImpl, std::vector<LayerImpl*>, RenderSurfaceImpl, LayerIteratorActions::FrontToBack> TestLayerIterator; typedef OcclusionTrackerImpl OcclusionTrackerType; - static LayerPtrType createLayer() { return LayerImpl::create(nextLayerImplId++); } - static ContentLayerPtrType createContentLayer() { return make_scoped_ptr(new ContentLayerType(nextLayerImplId++)); } + static LayerPtrType createLayer(HostType* host) { return LayerImpl::create(host, nextLayerImplId++); } + static ContentLayerPtrType createContentLayer(HostType* host) { return make_scoped_ptr(new ContentLayerType(host, nextLayerImplId++)); } static int nextLayerImplId; static LayerPtrType passLayerPtr(LayerPtrType& layer) @@ -187,8 +191,10 @@ template<typename Types> class OcclusionTrackerTest : public testing::Test { protected: OcclusionTrackerTest(bool opaqueLayers) - : m_opaqueLayers(opaqueLayers) - { } + : m_hostImpl(&m_proxy) + , m_opaqueLayers(opaqueLayers) + { + } virtual void runMyTest() = 0; @@ -202,9 +208,11 @@ protected: LayerTreeHost::setNeedsFilterContext(false); } + typename Types::HostType* getHost(); + typename Types::ContentLayerType* createRoot(const gfx::Transform& transform, const gfx::PointF& position, const gfx::Size& bounds) { - typename Types::ContentLayerPtrType layer(Types::createContentLayer()); + typename Types::ContentLayerPtrType layer(Types::createContentLayer(getHost())); typename Types::ContentLayerType* layerPtr = layer.get(); setProperties(layerPtr, transform, position, bounds); @@ -215,7 +223,7 @@ protected: typename Types::LayerType* createLayer(typename Types::LayerType* parent, const gfx::Transform& transform, const gfx::PointF& position, const gfx::Size& bounds) { - typename Types::LayerPtrType layer(Types::createLayer()); + typename Types::LayerPtrType layer(Types::createLayer(getHost())); typename Types::LayerType* layerPtr = layer.get(); setProperties(layerPtr, transform, position, bounds); parent->addChild(Types::passLayerPtr(layer)); @@ -233,7 +241,7 @@ protected: typename Types::ContentLayerType* createDrawingLayer(typename Types::LayerType* parent, const gfx::Transform& transform, const gfx::PointF& position, const gfx::Size& bounds, bool opaque) { - typename Types::ContentLayerPtrType layer(Types::createContentLayer()); + typename Types::ContentLayerPtrType layer(Types::createContentLayer(getHost())); typename Types::ContentLayerType* layerPtr = layer.get(); setProperties(layerPtr, transform, position, bounds); @@ -253,7 +261,7 @@ protected: typename Types::LayerType* createReplicaLayer(typename Types::LayerType* owningLayer, const gfx::Transform& transform, const gfx::PointF& position, const gfx::Size& bounds) { - typename Types::ContentLayerPtrType layer(Types::createContentLayer()); + typename Types::ContentLayerPtrType layer(Types::createContentLayer(getHost())); typename Types::ContentLayerType* layerPtr = layer.get(); setProperties(layerPtr, transform, position, bounds); setReplica(owningLayer, Types::passLayerPtr(layer)); @@ -262,7 +270,7 @@ protected: typename Types::LayerType* createMaskLayer(typename Types::LayerType* owningLayer, const gfx::Size& bounds) { - typename Types::ContentLayerPtrType layer(Types::createContentLayer()); + typename Types::ContentLayerPtrType layer(Types::createContentLayer(getHost())); typename Types::ContentLayerType* layerPtr = layer.get(); setProperties(layerPtr, identityMatrix, gfx::PointF(), bounds); setMask(owningLayer, Types::passLayerPtr(layer)); @@ -399,6 +407,8 @@ private: owningLayer->setMaskLayer(layer.Pass()); } + FakeImplProxy m_proxy; + FakeLayerTreeHostImpl m_hostImpl; bool m_opaqueLayers; // These hold ownership of the layers for the duration of the test. typename Types::LayerPtrType m_root; @@ -411,6 +421,18 @@ private: std::vector<scoped_refptr<Layer> > m_maskLayers; }; +template<> +LayerTreeHost* OcclusionTrackerTest<OcclusionTrackerTestMainThreadTypes>::getHost() +{ + return 0; +} + +template<> +LayerTreeHostImpl* OcclusionTrackerTest<OcclusionTrackerTestImplThreadTypes>::getHost() +{ + return &m_hostImpl; +} + #define RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \ class ClassName##MainThreadOpaqueLayers : public ClassName<OcclusionTrackerTestMainThreadTypes> { \ public: \ diff --git a/cc/picture_layer.cc b/cc/picture_layer.cc index ba95603..c90d511 100644 --- a/cc/picture_layer.cc +++ b/cc/picture_layer.cc @@ -23,8 +23,8 @@ bool PictureLayer::drawsContent() const { return Layer::drawsContent() && client_; } -scoped_ptr<LayerImpl> PictureLayer::createLayerImpl() { - return PictureLayerImpl::create(id()).PassAs<LayerImpl>(); +scoped_ptr<LayerImpl> PictureLayer::createLayerImpl(LayerTreeHostImpl* host) { + return PictureLayerImpl::create(host, id()).PassAs<LayerImpl>(); } void PictureLayer::pushPropertiesTo(LayerImpl* base_layer) { diff --git a/cc/picture_layer.h b/cc/picture_layer.h index 3aab8fd..cf9cf05 100644 --- a/cc/picture_layer.h +++ b/cc/picture_layer.h @@ -24,7 +24,8 @@ public: // Implement Layer interface virtual bool drawsContent() const OVERRIDE; - virtual scoped_ptr<LayerImpl> createLayerImpl() OVERRIDE; + virtual scoped_ptr<LayerImpl> createLayerImpl( + LayerTreeHostImpl* host) OVERRIDE; virtual void pushPropertiesTo(LayerImpl*) OVERRIDE; virtual void setNeedsDisplayRect(const gfx::RectF& layerRect) OVERRIDE; virtual void update(ResourceUpdateQueue&, const OcclusionTracker*, diff --git a/cc/picture_layer_impl.cc b/cc/picture_layer_impl.cc index 4959d42..14b9404 100644 --- a/cc/picture_layer_impl.cc +++ b/cc/picture_layer_impl.cc @@ -18,11 +18,11 @@ namespace cc { -PictureLayerImpl::PictureLayerImpl(int id) : - LayerImpl(id), - tilings_(this), - pile_(PicturePileImpl::Create()), - last_update_time_(0) { +PictureLayerImpl::PictureLayerImpl(LayerTreeHostImpl* host, int id) + : LayerImpl(host, id), + tilings_(this), + pile_(PicturePileImpl::Create()), + last_update_time_(0) { } PictureLayerImpl::~PictureLayerImpl() { diff --git a/cc/picture_layer_impl.h b/cc/picture_layer_impl.h index 7bc2018..8b1e4eb 100644 --- a/cc/picture_layer_impl.h +++ b/cc/picture_layer_impl.h @@ -19,9 +19,9 @@ class QuadSink; class CC_EXPORT PictureLayerImpl : public LayerImpl, public PictureLayerTilingClient { public: - static scoped_ptr<PictureLayerImpl> create(int id) + static scoped_ptr<PictureLayerImpl> create(LayerTreeHostImpl* host, int id) { - return make_scoped_ptr(new PictureLayerImpl(id)); + return make_scoped_ptr(new PictureLayerImpl(host, id)); } virtual ~PictureLayerImpl(); @@ -39,7 +39,7 @@ public: void SyncFromActiveLayer(const PictureLayerImpl* other); protected: - PictureLayerImpl(int id); + PictureLayerImpl(LayerTreeHostImpl* host, int id); PictureLayerTilingSet tilings_; scoped_refptr<PicturePileImpl> pile_; diff --git a/cc/prioritized_resource_unittest.cc b/cc/prioritized_resource_unittest.cc index 173fd14..f04df01 100644 --- a/cc/prioritized_resource_unittest.cc +++ b/cc/prioritized_resource_unittest.cc @@ -12,8 +12,6 @@ #include "cc/test/tiled_layer_test_common.h" #include "testing/gtest/include/gtest/gtest.h" -using namespace WebKitTests; - namespace cc { class PrioritizedResourceTest : public testing::Test { diff --git a/cc/quad_culler_unittest.cc b/cc/quad_culler_unittest.cc index 07de91f..d17c331 100644 --- a/cc/quad_culler_unittest.cc +++ b/cc/quad_culler_unittest.cc @@ -10,6 +10,8 @@ #include "cc/occlusion_tracker.h" #include "cc/overdraw_metrics.h" #include "cc/single_thread_proxy.h" +#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_layer_tree_host_impl.h" #include "cc/tile_draw_quad.h" #include "cc/tiled_layer_impl.h" #include "testing/gmock/include/gmock/gmock.h" @@ -36,52 +38,65 @@ private: typedef LayerIterator<LayerImpl, std::vector<LayerImpl*>, RenderSurfaceImpl, LayerIteratorActions::FrontToBack> LayerIteratorType; -static scoped_ptr<TiledLayerImpl> makeLayer(TiledLayerImpl* parent, const gfx::Transform& drawTransform, const gfx::Rect& layerRect, float opacity, bool opaque, const gfx::Rect& layerOpaqueRect, std::vector<LayerImpl*>& surfaceLayerList) +class QuadCullerTest : public testing::Test { - scoped_ptr<TiledLayerImpl> layer = TiledLayerImpl::create(1); - scoped_ptr<LayerTilingData> tiler = LayerTilingData::create(gfx::Size(100, 100), LayerTilingData::NoBorderTexels); - tiler->setBounds(layerRect.size()); - layer->setTilingData(*tiler); - layer->setSkipsDraw(false); - layer->drawProperties().target_space_transform = drawTransform; - layer->drawProperties().screen_space_transform = drawTransform; - layer->drawProperties().visible_content_rect = layerRect; - layer->drawProperties().opacity = opacity; - layer->setContentsOpaque(opaque); - layer->setBounds(layerRect.size()); - layer->setContentBounds(layerRect.size()); - - ResourceProvider::ResourceId resourceId = 1; - for (int i = 0; i < tiler->numTilesX(); ++i) - for (int j = 0; j < tiler->numTilesY(); ++j) { - gfx::Rect tileOpaqueRect = opaque ? tiler->tileBounds(i, j) : gfx::IntersectRects(tiler->tileBounds(i, j), layerOpaqueRect); - layer->pushTileProperties(i, j, resourceId++, tileOpaqueRect, false); +public: + QuadCullerTest() + : m_hostImpl(&m_proxy) + { + } + + scoped_ptr<TiledLayerImpl> makeLayer(TiledLayerImpl* parent, const gfx::Transform& drawTransform, const gfx::Rect& layerRect, float opacity, bool opaque, const gfx::Rect& layerOpaqueRect, std::vector<LayerImpl*>& surfaceLayerList) + { + scoped_ptr<TiledLayerImpl> layer = TiledLayerImpl::create(&m_hostImpl, 1); + scoped_ptr<LayerTilingData> tiler = LayerTilingData::create(gfx::Size(100, 100), LayerTilingData::NoBorderTexels); + tiler->setBounds(layerRect.size()); + layer->setTilingData(*tiler); + layer->setSkipsDraw(false); + layer->drawProperties().target_space_transform = drawTransform; + layer->drawProperties().screen_space_transform = drawTransform; + layer->drawProperties().visible_content_rect = layerRect; + layer->drawProperties().opacity = opacity; + layer->setContentsOpaque(opaque); + layer->setBounds(layerRect.size()); + layer->setContentBounds(layerRect.size()); + + ResourceProvider::ResourceId resourceId = 1; + for (int i = 0; i < tiler->numTilesX(); ++i) + for (int j = 0; j < tiler->numTilesY(); ++j) { + gfx::Rect tileOpaqueRect = opaque ? tiler->tileBounds(i, j) : gfx::IntersectRects(tiler->tileBounds(i, j), layerOpaqueRect); + layer->pushTileProperties(i, j, resourceId++, tileOpaqueRect, false); + } + + gfx::Rect rectInTarget = MathUtil::mapClippedRect(layer->drawTransform(), layer->visibleContentRect()); + if (!parent) { + layer->createRenderSurface(); + surfaceLayerList.push_back(layer.get()); + layer->renderSurface()->layerList().push_back(layer.get()); + } else { + layer->drawProperties().render_target = parent->renderTarget(); + parent->renderSurface()->layerList().push_back(layer.get()); + rectInTarget.Union(MathUtil::mapClippedRect(parent->drawTransform(), parent->visibleContentRect())); } + layer->drawProperties().drawable_content_rect = rectInTarget; - gfx::Rect rectInTarget = MathUtil::mapClippedRect(layer->drawTransform(), layer->visibleContentRect()); - if (!parent) { - layer->createRenderSurface(); - surfaceLayerList.push_back(layer.get()); - layer->renderSurface()->layerList().push_back(layer.get()); - } else { - layer->drawProperties().render_target = parent->renderTarget(); - parent->renderSurface()->layerList().push_back(layer.get()); - rectInTarget.Union(MathUtil::mapClippedRect(parent->drawTransform(), parent->visibleContentRect())); + return layer.Pass(); } - layer->drawProperties().drawable_content_rect = rectInTarget; - return layer.Pass(); -} + void appendQuads(QuadList& quadList, SharedQuadStateList& sharedStateList, TiledLayerImpl* layer, LayerIteratorType& it, OcclusionTrackerImpl& occlusionTracker) + { + occlusionTracker.enterLayer(it); + QuadCuller quadCuller(quadList, sharedStateList, layer, occlusionTracker, false, false); + AppendQuadsData data; + layer->appendQuads(quadCuller, data); + occlusionTracker.leaveLayer(it); + ++it; + } -static void appendQuads(QuadList& quadList, SharedQuadStateList& sharedStateList, TiledLayerImpl* layer, LayerIteratorType& it, OcclusionTrackerImpl& occlusionTracker) -{ - occlusionTracker.enterLayer(it); - QuadCuller quadCuller(quadList, sharedStateList, layer, occlusionTracker, false, false); - AppendQuadsData data; - layer->appendQuads(quadCuller, data); - occlusionTracker.leaveLayer(it); - ++it; -} +protected: + FakeImplProxy m_proxy; + FakeLayerTreeHostImpl m_hostImpl; +}; #define DECLARE_AND_INITIALIZE_TEST_QUADS \ QuadList quadList; \ @@ -93,7 +108,7 @@ static void appendQuads(QuadList& quadList, SharedQuadStateList& sharedStateList gfx::Size childSize = gfx::Size(200, 200); \ gfx::Rect childRect = gfx::Rect(childSize); -TEST(QuadCullerTest, verifyNoCulling) +TEST_F(QuadCullerTest, verifyNoCulling) { DECLARE_AND_INITIALIZE_TEST_QUADS @@ -110,7 +125,7 @@ TEST(QuadCullerTest, verifyNoCulling) EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulledForDrawing(), 0, 1); } -TEST(QuadCullerTest, verifyCullChildLinesUpTopLeft) +TEST_F(QuadCullerTest, verifyCullChildLinesUpTopLeft) { DECLARE_AND_INITIALIZE_TEST_QUADS @@ -127,7 +142,7 @@ TEST(QuadCullerTest, verifyCullChildLinesUpTopLeft) EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulledForDrawing(), 40000, 1); } -TEST(QuadCullerTest, verifyCullWhenChildOpacityNotOne) +TEST_F(QuadCullerTest, verifyCullWhenChildOpacityNotOne) { DECLARE_AND_INITIALIZE_TEST_QUADS @@ -144,7 +159,7 @@ TEST(QuadCullerTest, verifyCullWhenChildOpacityNotOne) EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulledForDrawing(), 0, 1); } -TEST(QuadCullerTest, verifyCullWhenChildOpaqueFlagFalse) +TEST_F(QuadCullerTest, verifyCullWhenChildOpaqueFlagFalse) { DECLARE_AND_INITIALIZE_TEST_QUADS @@ -161,7 +176,7 @@ TEST(QuadCullerTest, verifyCullWhenChildOpaqueFlagFalse) EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulledForDrawing(), 0, 1); } -TEST(QuadCullerTest, verifyCullCenterTileOnly) +TEST_F(QuadCullerTest, verifyCullCenterTileOnly) { DECLARE_AND_INITIALIZE_TEST_QUADS @@ -196,7 +211,7 @@ TEST(QuadCullerTest, verifyCullCenterTileOnly) EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulledForDrawing(), 30000, 1); } -TEST(QuadCullerTest, verifyCullCenterTileNonIntegralSize1) +TEST_F(QuadCullerTest, verifyCullCenterTileNonIntegralSize1) { DECLARE_AND_INITIALIZE_TEST_QUADS @@ -224,7 +239,7 @@ TEST(QuadCullerTest, verifyCullCenterTileNonIntegralSize1) EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulledForDrawing(), 0, 1); } -TEST(QuadCullerTest, verifyCullCenterTileNonIntegralSize2) +TEST_F(QuadCullerTest, verifyCullCenterTileNonIntegralSize2) { DECLARE_AND_INITIALIZE_TEST_QUADS @@ -252,7 +267,7 @@ TEST(QuadCullerTest, verifyCullCenterTileNonIntegralSize2) EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulledForDrawing(), 0, 1); } -TEST(QuadCullerTest, verifyCullChildLinesUpBottomRight) +TEST_F(QuadCullerTest, verifyCullChildLinesUpBottomRight) { DECLARE_AND_INITIALIZE_TEST_QUADS @@ -271,7 +286,7 @@ TEST(QuadCullerTest, verifyCullChildLinesUpBottomRight) EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulledForDrawing(), 40000, 1); } -TEST(QuadCullerTest, verifyCullSubRegion) +TEST_F(QuadCullerTest, verifyCullSubRegion) { DECLARE_AND_INITIALIZE_TEST_QUADS @@ -291,7 +306,7 @@ TEST(QuadCullerTest, verifyCullSubRegion) EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulledForDrawing(), 10000, 1); } -TEST(QuadCullerTest, verifyCullSubRegion2) +TEST_F(QuadCullerTest, verifyCullSubRegion2) { DECLARE_AND_INITIALIZE_TEST_QUADS @@ -311,7 +326,7 @@ TEST(QuadCullerTest, verifyCullSubRegion2) EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulledForDrawing(), 15000, 1); } -TEST(QuadCullerTest, verifyCullSubRegionCheckOvercull) +TEST_F(QuadCullerTest, verifyCullSubRegionCheckOvercull) { DECLARE_AND_INITIALIZE_TEST_QUADS @@ -331,7 +346,7 @@ TEST(QuadCullerTest, verifyCullSubRegionCheckOvercull) EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulledForDrawing(), 10000, 1); } -TEST(QuadCullerTest, verifyNonAxisAlignedQuadsDontOcclude) +TEST_F(QuadCullerTest, verifyNonAxisAlignedQuadsDontOcclude) { DECLARE_AND_INITIALIZE_TEST_QUADS @@ -356,7 +371,7 @@ TEST(QuadCullerTest, verifyNonAxisAlignedQuadsDontOcclude) // tile parent layer is rotated by 1 degree. Of the four tiles the child would // normally occlude, three will move (slightly) out from under the child layer, and // one moves further under the child. Only this last tile should be culled. -TEST(QuadCullerTest, verifyNonAxisAlignedQuadsSafelyCulled) +TEST_F(QuadCullerTest, verifyNonAxisAlignedQuadsSafelyCulled) { DECLARE_AND_INITIALIZE_TEST_QUADS @@ -377,7 +392,7 @@ TEST(QuadCullerTest, verifyNonAxisAlignedQuadsSafelyCulled) EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulledForDrawing(), 29400, 1); } -TEST(QuadCullerTest, verifyCullOutsideScissorOverTile) +TEST_F(QuadCullerTest, verifyCullOutsideScissorOverTile) { DECLARE_AND_INITIALIZE_TEST_QUADS @@ -394,7 +409,7 @@ TEST(QuadCullerTest, verifyCullOutsideScissorOverTile) EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulledForDrawing(), 120000, 1); } -TEST(QuadCullerTest, verifyCullOutsideScissorOverCulledTile) +TEST_F(QuadCullerTest, verifyCullOutsideScissorOverCulledTile) { DECLARE_AND_INITIALIZE_TEST_QUADS @@ -411,7 +426,7 @@ TEST(QuadCullerTest, verifyCullOutsideScissorOverCulledTile) EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulledForDrawing(), 120000, 1); } -TEST(QuadCullerTest, verifyCullOutsideScissorOverPartialTiles) +TEST_F(QuadCullerTest, verifyCullOutsideScissorOverPartialTiles) { DECLARE_AND_INITIALIZE_TEST_QUADS @@ -428,7 +443,7 @@ TEST(QuadCullerTest, verifyCullOutsideScissorOverPartialTiles) EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulledForDrawing(), 90000, 1); } -TEST(QuadCullerTest, verifyCullOutsideScissorOverNoTiles) +TEST_F(QuadCullerTest, verifyCullOutsideScissorOverNoTiles) { DECLARE_AND_INITIALIZE_TEST_QUADS @@ -445,7 +460,7 @@ TEST(QuadCullerTest, verifyCullOutsideScissorOverNoTiles) EXPECT_NEAR(occlusionTracker.overdrawMetrics().pixelsCulledForDrawing(), 130000, 1); } -TEST(QuadCullerTest, verifyWithoutMetrics) +TEST_F(QuadCullerTest, verifyWithoutMetrics) { DECLARE_AND_INITIALIZE_TEST_QUADS diff --git a/cc/render_surface_unittest.cc b/cc/render_surface_unittest.cc index 885dac1..0fd5247 100644 --- a/cc/render_surface_unittest.cc +++ b/cc/render_surface_unittest.cc @@ -10,6 +10,8 @@ #include "cc/scoped_ptr_vector.h" #include "cc/shared_quad_state.h" #include "cc/single_thread_proxy.h" +#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/geometry_test_utils.h" #include "cc/test/mock_quad_culler.h" #include "testing/gmock/include/gmock/gmock.h" @@ -35,7 +37,9 @@ TEST(RenderSurfaceTest, verifySurfaceChangesAreTrackedProperly) // This test checks that surfacePropertyChanged() has the correct behavior. // - scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(1); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(&hostImpl, 1); owningLayer->createRenderSurface(); ASSERT_TRUE(owningLayer->renderSurface()); RenderSurfaceImpl* renderSurface = owningLayer->renderSurface(); @@ -55,7 +59,7 @@ TEST(RenderSurfaceTest, verifySurfaceChangesAreTrackedProperly) EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setClipRect(testRect)); EXECUTE_AND_VERIFY_SURFACE_DID_NOT_CHANGE(renderSurface->setContentRect(testRect)); - scoped_ptr<LayerImpl> dummyMask = LayerImpl::create(1); + scoped_ptr<LayerImpl> dummyMask = LayerImpl::create(&hostImpl, 1); gfx::Transform dummyMatrix; dummyMatrix.Translate(1.0, 2.0); @@ -69,9 +73,11 @@ TEST(RenderSurfaceTest, verifySurfaceChangesAreTrackedProperly) TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectSharedQuadState) { - scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(1); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(&hostImpl, 1); - scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(2); + scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(&hostImpl, 2); owningLayer->createRenderSurface(); ASSERT_TRUE(owningLayer->renderSurface()); owningLayer->drawProperties().render_target = owningLayer.get(); @@ -119,9 +125,11 @@ private: TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectRenderPass) { - scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(1); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(&hostImpl, 1); - scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(2); + scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(&hostImpl, 2); owningLayer->createRenderSurface(); ASSERT_TRUE(owningLayer->renderSurface()); owningLayer->drawProperties().render_target = owningLayer.get(); diff --git a/cc/scrollbar_animation_controller_linear_fade_unittest.cc b/cc/scrollbar_animation_controller_linear_fade_unittest.cc index e335a80..dd941c1 100644 --- a/cc/scrollbar_animation_controller_linear_fade_unittest.cc +++ b/cc/scrollbar_animation_controller_linear_fade_unittest.cc @@ -6,19 +6,27 @@ #include "cc/scrollbar_layer_impl.h" #include "cc/single_thread_proxy.h" +#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_layer_tree_host_impl.h" #include "testing/gtest/include/gtest/gtest.h" namespace cc { namespace { class ScrollbarAnimationControllerLinearFadeTest : public testing::Test { +public: + ScrollbarAnimationControllerLinearFadeTest() + : m_hostImpl(&m_proxy) + { + } + protected: virtual void SetUp() { - m_scrollLayer = LayerImpl::create(1); - m_scrollLayer->addChild(LayerImpl::create(2)); + m_scrollLayer = LayerImpl::create(&m_hostImpl, 1); + m_scrollLayer->addChild(LayerImpl::create(&m_hostImpl, 2)); m_contentLayer = m_scrollLayer->children()[0]; - m_scrollbarLayer = ScrollbarLayerImpl::create(3); + m_scrollbarLayer = ScrollbarLayerImpl::create(&m_hostImpl, 3); m_scrollLayer->setMaxScrollOffset(gfx::Vector2d(50, 50)); m_contentLayer->setBounds(gfx::Size(50, 50)); @@ -27,6 +35,8 @@ protected: m_scrollbarController->setHorizontalScrollbarLayer(m_scrollbarLayer.get()); } + FakeImplProxy m_proxy; + FakeLayerTreeHostImpl m_hostImpl; scoped_ptr<ScrollbarAnimationControllerLinearFade> m_scrollbarController; scoped_ptr<LayerImpl> m_scrollLayer; LayerImpl* m_contentLayer; diff --git a/cc/scrollbar_layer.cc b/cc/scrollbar_layer.cc index 9c7ae73..83152bb 100644 --- a/cc/scrollbar_layer.cc +++ b/cc/scrollbar_layer.cc @@ -17,9 +17,9 @@ using WebKit::WebRect; namespace cc { -scoped_ptr<LayerImpl> ScrollbarLayer::createLayerImpl() +scoped_ptr<LayerImpl> ScrollbarLayer::createLayerImpl(LayerTreeHostImpl* hostImpl) { - return ScrollbarLayerImpl::create(id()).PassAs<LayerImpl>(); + return ScrollbarLayerImpl::create(hostImpl, id()).PassAs<LayerImpl>(); } scoped_refptr<ScrollbarLayer> ScrollbarLayer::create(scoped_ptr<WebKit::WebScrollbar> scrollbar, WebKit::WebScrollbarThemePainter painter, scoped_ptr<WebKit::WebScrollbarThemeGeometry> geometry, int scrollLayerId) diff --git a/cc/scrollbar_layer.h b/cc/scrollbar_layer.h index 5d1cd06..dd8abdd 100644 --- a/cc/scrollbar_layer.h +++ b/cc/scrollbar_layer.h @@ -21,7 +21,7 @@ class ScrollbarThemeComposite; class CC_EXPORT ScrollbarLayer : public ContentsScalingLayer { public: - virtual scoped_ptr<LayerImpl> createLayerImpl() OVERRIDE; + virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeHostImpl* hostImpl) OVERRIDE; static scoped_refptr<ScrollbarLayer> create(scoped_ptr<WebKit::WebScrollbar>, WebKit::WebScrollbarThemePainter, scoped_ptr<WebKit::WebScrollbarThemeGeometry>, int scrollLayerId); diff --git a/cc/scrollbar_layer_impl.cc b/cc/scrollbar_layer_impl.cc index d43e70a..db9fb4f 100644 --- a/cc/scrollbar_layer_impl.cc +++ b/cc/scrollbar_layer_impl.cc @@ -14,13 +14,13 @@ using WebKit::WebScrollbar; namespace cc { -scoped_ptr<ScrollbarLayerImpl> ScrollbarLayerImpl::create(int id) +scoped_ptr<ScrollbarLayerImpl> ScrollbarLayerImpl::create(LayerTreeHostImpl* hostImpl, int id) { - return make_scoped_ptr(new ScrollbarLayerImpl(id)); + return make_scoped_ptr(new ScrollbarLayerImpl(hostImpl, id)); } -ScrollbarLayerImpl::ScrollbarLayerImpl(int id) - : LayerImpl(id) +ScrollbarLayerImpl::ScrollbarLayerImpl(LayerTreeHostImpl* hostImpl, int id) + : LayerImpl(hostImpl, id) , m_scrollbar(this) , m_backTrackResourceId(0) , m_foreTrackResourceId(0) diff --git a/cc/scrollbar_layer_impl.h b/cc/scrollbar_layer_impl.h index 6b55aa8..a35ae3b 100644 --- a/cc/scrollbar_layer_impl.h +++ b/cc/scrollbar_layer_impl.h @@ -18,7 +18,7 @@ class ScrollView; class CC_EXPORT ScrollbarLayerImpl : public LayerImpl { public: - static scoped_ptr<ScrollbarLayerImpl> create(int id); + static scoped_ptr<ScrollbarLayerImpl> create(LayerTreeHostImpl* hostImpl, int id); virtual ~ScrollbarLayerImpl(); ScrollbarGeometryFixedThumb* scrollbarGeometry() const { return m_geometry.get(); } @@ -45,7 +45,7 @@ public: virtual void didLoseOutputSurface() OVERRIDE; protected: - explicit ScrollbarLayerImpl(int id); + ScrollbarLayerImpl(LayerTreeHostImpl* hostImpl, int id); private: // nested class only to avoid namespace problem diff --git a/cc/scrollbar_layer_unittest.cc b/cc/scrollbar_layer_unittest.cc index 275f98b..3aba55d 100644 --- a/cc/scrollbar_layer_unittest.cc +++ b/cc/scrollbar_layer_unittest.cc @@ -7,6 +7,8 @@ #include "cc/scrollbar_animation_controller.h" #include "cc/scrollbar_layer_impl.h" #include "cc/single_thread_proxy.h" +#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_web_scrollbar_theme_geometry.h" #include "cc/test/layer_tree_test_common.h" #include "cc/tree_synchronizer.h" @@ -43,6 +45,8 @@ public: TEST(ScrollbarLayerTest, resolveScrollLayerPointer) { + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); WebKit::WebScrollbarThemePainter painter; { @@ -53,7 +57,7 @@ TEST(ScrollbarLayerTest, resolveScrollLayerPointer) layerTreeRoot->addChild(child1); layerTreeRoot->addChild(child2); - scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), 0); + scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), &hostImpl); LayerImpl* ccChild1 = layerImplTreeRoot->children()[0]; ScrollbarLayerImpl* ccChild2 = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[1]); @@ -70,7 +74,7 @@ TEST(ScrollbarLayerTest, resolveScrollLayerPointer) layerTreeRoot->addChild(child1); layerTreeRoot->addChild(child2); - scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), 0); + scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), &hostImpl); ScrollbarLayerImpl* ccChild1 = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[0]); LayerImpl* ccChild2 = layerImplTreeRoot->children()[1]; @@ -82,6 +86,8 @@ TEST(ScrollbarLayerTest, resolveScrollLayerPointer) TEST(ScrollbarLayerTest, scrollOffsetSynchronization) { + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); WebKit::WebScrollbarThemePainter painter; scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); @@ -95,7 +101,7 @@ TEST(ScrollbarLayerTest, scrollOffsetSynchronization) layerTreeRoot->setMaxScrollOffset(gfx::Vector2d(30, 50)); contentLayer->setBounds(gfx::Size(100, 200)); - scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), 0); + scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), &hostImpl); ScrollbarLayerImpl* ccScrollbarLayer = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[1]); @@ -108,7 +114,7 @@ TEST(ScrollbarLayerTest, scrollOffsetSynchronization) contentLayer->setBounds(gfx::Size(1000, 2000)); ScrollbarAnimationController* scrollbarController = layerImplTreeRoot->scrollbarAnimationController(); - layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), 0); + layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), &hostImpl); EXPECT_EQ(scrollbarController, layerImplTreeRoot->scrollbarAnimationController()); EXPECT_EQ(100, ccScrollbarLayer->currentPos()); diff --git a/cc/solid_color_layer.cc b/cc/solid_color_layer.cc index 29d3708..4510e00 100644 --- a/cc/solid_color_layer.cc +++ b/cc/solid_color_layer.cc @@ -8,9 +8,9 @@ namespace cc { -scoped_ptr<LayerImpl> SolidColorLayer::createLayerImpl() +scoped_ptr<LayerImpl> SolidColorLayer::createLayerImpl(LayerTreeHostImpl* hostImpl) { - return SolidColorLayerImpl::create(id()).PassAs<LayerImpl>(); + return SolidColorLayerImpl::create(hostImpl, id()).PassAs<LayerImpl>(); } scoped_refptr<SolidColorLayer> SolidColorLayer::create() diff --git a/cc/solid_color_layer.h b/cc/solid_color_layer.h index d6da379..cf1c456 100644 --- a/cc/solid_color_layer.h +++ b/cc/solid_color_layer.h @@ -17,7 +17,7 @@ class CC_EXPORT SolidColorLayer : public Layer { public: static scoped_refptr<SolidColorLayer> create(); - virtual scoped_ptr<LayerImpl> createLayerImpl() OVERRIDE; + virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeHostImpl* hostImpl) OVERRIDE; virtual void setBackgroundColor(SkColor) OVERRIDE; diff --git a/cc/solid_color_layer_impl.cc b/cc/solid_color_layer_impl.cc index 53a635e..aa2c278 100644 --- a/cc/solid_color_layer_impl.cc +++ b/cc/solid_color_layer_impl.cc @@ -9,8 +9,8 @@ namespace cc { -SolidColorLayerImpl::SolidColorLayerImpl(int id) - : LayerImpl(id) +SolidColorLayerImpl::SolidColorLayerImpl(LayerTreeHostImpl* hostImpl, int id) + : LayerImpl(hostImpl, id) , m_tileSize(256) { } diff --git a/cc/solid_color_layer_impl.h b/cc/solid_color_layer_impl.h index 30231cb..c2da466 100644 --- a/cc/solid_color_layer_impl.h +++ b/cc/solid_color_layer_impl.h @@ -12,16 +12,16 @@ namespace cc { class CC_EXPORT SolidColorLayerImpl : public LayerImpl { public: - static scoped_ptr<SolidColorLayerImpl> create(int id) + static scoped_ptr<SolidColorLayerImpl> create(LayerTreeHostImpl* hostImpl, int id) { - return make_scoped_ptr(new SolidColorLayerImpl(id)); + return make_scoped_ptr(new SolidColorLayerImpl(hostImpl, id)); } virtual ~SolidColorLayerImpl(); virtual void appendQuads(QuadSink&, AppendQuadsData&) OVERRIDE; protected: - explicit SolidColorLayerImpl(int id); + SolidColorLayerImpl(LayerTreeHostImpl* hostImpl, int id); private: virtual const char* layerTypeAsString() const OVERRIDE; diff --git a/cc/solid_color_layer_impl_unittest.cc b/cc/solid_color_layer_impl_unittest.cc index bbc2203..fdad5c2 100644 --- a/cc/solid_color_layer_impl_unittest.cc +++ b/cc/solid_color_layer_impl_unittest.cc @@ -8,6 +8,8 @@ #include "cc/single_thread_proxy.h" #include "cc/solid_color_draw_quad.h" #include "cc/solid_color_layer.h" +#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/layer_test_common.h" #include "cc/test/mock_quad_culler.h" #include "testing/gmock/include/gmock/gmock.h" @@ -24,7 +26,9 @@ TEST(SolidColorLayerImplTest, verifyTilingCompleteAndNoOverlap) gfx::Size layerSize = gfx::Size(800, 600); gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); - scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(1); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(&hostImpl, 1); layer->drawProperties().visible_content_rect = visibleContentRect; layer->setBounds(layerSize); layer->setContentBounds(layerSize); @@ -45,7 +49,9 @@ TEST(SolidColorLayerImplTest, verifyCorrectBackgroundColorInQuad) gfx::Size layerSize = gfx::Size(100, 100); gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); - scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(1); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(&hostImpl, 1); layer->drawProperties().visible_content_rect = visibleContentRect; layer->setBounds(layerSize); layer->setContentBounds(layerSize); @@ -68,7 +74,9 @@ TEST(SolidColorLayerImplTest, verifyCorrectOpacityInQuad) gfx::Size layerSize = gfx::Size(100, 100); gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); - scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(1); + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(&hostImpl, 1); layer->drawProperties().visible_content_rect = visibleContentRect; layer->setBounds(layerSize); layer->setContentBounds(layerSize); @@ -85,6 +93,9 @@ TEST(SolidColorLayerImplTest, verifyCorrectOpacityInQuad) TEST(SolidColorLayerImplTest, verifyOpaqueRect) { + FakeImplProxy proxy; + FakeLayerTreeHostImpl hostImpl(&proxy); + scoped_refptr<SolidColorLayer> layer = SolidColorLayer::create(); gfx::Size layerSize = gfx::Size(100, 100); gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); @@ -99,7 +110,7 @@ TEST(SolidColorLayerImplTest, verifyOpaqueRect) EXPECT_TRUE(layer->contentsOpaque()); { - scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::create(layer->id()); + scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::create(&hostImpl, layer->id()); layer->pushPropertiesTo(layerImpl.get()); // The impl layer should call itself opaque as well. @@ -121,7 +132,7 @@ TEST(SolidColorLayerImplTest, verifyOpaqueRect) EXPECT_FALSE(layer->contentsOpaque()); { - scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::create(layer->id()); + scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::create(&hostImpl, layer->id()); layer->pushPropertiesTo(layerImpl.get()); // The impl layer should callnot itself opaque anymore. diff --git a/cc/test/fake_impl_proxy.h b/cc/test/fake_impl_proxy.h new file mode 100644 index 0000000..afabcc1 --- /dev/null +++ b/cc/test/fake_impl_proxy.h @@ -0,0 +1,27 @@ +// Copyright 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CC_TEST_FAKE_IMPL_PROXY_H_ +#define CC_TEST_FAKE_IMPL_PROXY_H_ + +#include "cc/single_thread_proxy.h" +#include "cc/test/fake_proxy.h" + +namespace cc { + +class FakeImplProxy : public FakeProxy { + public: + FakeImplProxy() + : FakeProxy(scoped_ptr<Thread>()), + set_impl_thread_(this) + { + } + + private: + DebugScopedSetImplThread set_impl_thread_; +}; + +} // namespace cc + +#endif // CC_TEST_FAKE_IMPL_PROXY_H_ diff --git a/cc/test/fake_layer_tree_host_impl.cc b/cc/test/fake_layer_tree_host_impl.cc new file mode 100644 index 0000000..f2df058 --- /dev/null +++ b/cc/test/fake_layer_tree_host_impl.cc @@ -0,0 +1,20 @@ +// Copyright 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "cc/test/fake_layer_tree_host_impl.h" + +namespace cc { + +FakeLayerTreeHostImpl::FakeLayerTreeHostImpl(Proxy* proxy) + : LayerTreeHostImpl(settings_, &client_, proxy) +{ + // Explicitly clear all debug settings. + setDebugState(LayerTreeDebugState()); +} + +FakeLayerTreeHostImpl::~FakeLayerTreeHostImpl() +{ +} + +} // namespace cc diff --git a/cc/test/fake_layer_tree_host_impl.h b/cc/test/fake_layer_tree_host_impl.h new file mode 100644 index 0000000..c21c998 --- /dev/null +++ b/cc/test/fake_layer_tree_host_impl.h @@ -0,0 +1,26 @@ +// Copyright 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CC_TEST_FAKE_LAYER_TREE_HOST_IMPL_H_ +#define CC_TEST_FAKE_LAYER_TREE_HOST_IMPL_H_ + +#include "cc/layer_tree_host_impl.h" +#include "cc/single_thread_proxy.h" +#include "cc/test/fake_layer_tree_host_impl_client.h" + +namespace cc { + +class FakeLayerTreeHostImpl : public LayerTreeHostImpl { + public: + FakeLayerTreeHostImpl(Proxy* proxy); + virtual ~FakeLayerTreeHostImpl(); + + private: + FakeLayerTreeHostImplClient client_; + LayerTreeSettings settings_; +}; + +} // namespace cc + +#endif // CC_TEST_FAKE_LAYER_TREE_HOST_IMPL_H_ diff --git a/cc/test/fake_layer_tree_host_impl_client.cc b/cc/test/fake_layer_tree_host_impl_client.cc new file mode 100644 index 0000000..c97b5c4 --- /dev/null +++ b/cc/test/fake_layer_tree_host_impl_client.cc @@ -0,0 +1,15 @@ +// Copyright 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "cc/test/fake_layer_tree_host_impl_client.h" + +namespace cc { + +bool FakeLayerTreeHostImplClient::reduceContentsTextureMemoryOnImplThread( + size_t, + int) { + return false; +} + +} // namespace cc diff --git a/cc/test/fake_layer_tree_host_impl_client.h b/cc/test/fake_layer_tree_host_impl_client.h new file mode 100644 index 0000000..fdeb7ea --- /dev/null +++ b/cc/test/fake_layer_tree_host_impl_client.h @@ -0,0 +1,33 @@ +// Copyright 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CC_TEST_FAKE_LAYER_TREE_HOST_IMPL_CLIENT_H_ +#define CC_TEST_FAKE_LAYER_TREE_HOST_IMPL_CLIENT_H_ + +#include "cc/layer_tree_host_impl.h" + +namespace cc { + +class FakeLayerTreeHostImplClient : public LayerTreeHostImplClient { + public: + // LayerTreeHostImplClient implementation. + virtual void didLoseOutputSurfaceOnImplThread() OVERRIDE { } + virtual void onSwapBuffersCompleteOnImplThread() OVERRIDE { } + virtual void onVSyncParametersChanged( + base::TimeTicks, + base::TimeDelta) OVERRIDE { } + virtual void onCanDrawStateChanged(bool) OVERRIDE { } + virtual void setNeedsRedrawOnImplThread() OVERRIDE { } + virtual void setNeedsCommitOnImplThread() OVERRIDE { } + virtual void setNeedsManageTilesOnImplThread() OVERRIDE { } + virtual void postAnimationEventsToMainThreadOnImplThread( + scoped_ptr<AnimationEventsVector>, + base::Time) OVERRIDE { } + virtual bool reduceContentsTextureMemoryOnImplThread(size_t, int) OVERRIDE; + virtual void sendManagedMemoryStats() OVERRIDE { } +}; + +} // namespace cc + +#endif // CC_TEST_FAKE_LAYER_TREE_HOST_IMPL_CLIENT_H_ diff --git a/cc/test/tiled_layer_test_common.cc b/cc/test/tiled_layer_test_common.cc index 2279fe4..0d52ad0 100644 --- a/cc/test/tiled_layer_test_common.cc +++ b/cc/test/tiled_layer_test_common.cc @@ -13,7 +13,7 @@ using cc::RenderingStats; using cc::ResourceUpdate; using cc::ResourceUpdateQueue; -namespace WebKitTests { +namespace cc { FakeLayerUpdater::Resource::Resource(FakeLayerUpdater* layer, scoped_ptr<PrioritizedResource> texture) : LayerUpdater::Resource(texture.Pass()) @@ -73,8 +73,8 @@ scoped_ptr<LayerUpdater::Resource> FakeLayerUpdater::createResource(PrioritizedR return scoped_ptr<LayerUpdater::Resource>(new Resource(this, PrioritizedResource::create(manager))); } -FakeTiledLayerImpl::FakeTiledLayerImpl(int id) - : TiledLayerImpl(id) +FakeTiledLayerImpl::FakeTiledLayerImpl(LayerTreeHostImpl* hostImpl, int id) + : TiledLayerImpl(hostImpl, id) { } diff --git a/cc/test/tiled_layer_test_common.h b/cc/test/tiled_layer_test_common.h index 8079f1d..83934c4 100644 --- a/cc/test/tiled_layer_test_common.h +++ b/cc/test/tiled_layer_test_common.h @@ -17,7 +17,7 @@ #include "ui/gfx/rect.h" #include "ui/gfx/size.h" -namespace WebKitTests { +namespace cc { class FakeTiledLayer; @@ -71,7 +71,7 @@ private: class FakeTiledLayerImpl : public cc::TiledLayerImpl { public: - explicit FakeTiledLayerImpl(int id); + FakeTiledLayerImpl(LayerTreeHostImpl* hostImpl, int id); virtual ~FakeTiledLayerImpl(); using cc::TiledLayerImpl::hasTileAt; diff --git a/cc/texture_layer.cc b/cc/texture_layer.cc index b6007f0..2cb8ad7 100644 --- a/cc/texture_layer.cc +++ b/cc/texture_layer.cc @@ -40,9 +40,9 @@ TextureLayer::~TextureLayer() } } -scoped_ptr<LayerImpl> TextureLayer::createLayerImpl() +scoped_ptr<LayerImpl> TextureLayer::createLayerImpl(LayerTreeHostImpl* hostImpl) { - return TextureLayerImpl::create(m_layerId).PassAs<LayerImpl>(); + return TextureLayerImpl::create(hostImpl, m_layerId).PassAs<LayerImpl>(); } void TextureLayer::setFlipped(bool flipped) diff --git a/cc/texture_layer.h b/cc/texture_layer.h index cfa5ddb..b77ebb0 100644 --- a/cc/texture_layer.h +++ b/cc/texture_layer.h @@ -26,7 +26,7 @@ public: void clearClient() { m_client = 0; } - virtual scoped_ptr<LayerImpl> createLayerImpl() OVERRIDE; + virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeHostImpl* hostImpl) OVERRIDE; // Sets whether this texture should be Y-flipped at draw time. Defaults to true. void setFlipped(bool); diff --git a/cc/texture_layer_impl.cc b/cc/texture_layer_impl.cc index 37b9843..57e06a5 100644 --- a/cc/texture_layer_impl.cc +++ b/cc/texture_layer_impl.cc @@ -11,8 +11,8 @@ namespace cc { -TextureLayerImpl::TextureLayerImpl(int id) - : LayerImpl(id) +TextureLayerImpl::TextureLayerImpl(LayerTreeHostImpl* hostImpl, int id) + : LayerImpl(hostImpl, id) , m_textureId(0) , m_externalTextureResource(0) , m_premultipliedAlpha(true) diff --git a/cc/texture_layer_impl.h b/cc/texture_layer_impl.h index f800a2c..97c2dc9 100644 --- a/cc/texture_layer_impl.h +++ b/cc/texture_layer_impl.h @@ -12,9 +12,9 @@ namespace cc { class CC_EXPORT TextureLayerImpl : public LayerImpl { public: - static scoped_ptr<TextureLayerImpl> create(int id) + static scoped_ptr<TextureLayerImpl> create(LayerTreeHostImpl* hostImpl, int id) { - return make_scoped_ptr(new TextureLayerImpl(id)); + return make_scoped_ptr(new TextureLayerImpl(hostImpl, id)); } virtual ~TextureLayerImpl(); @@ -33,7 +33,7 @@ public: void setUVRect(const gfx::RectF& rect) { m_uvRect = rect; } private: - explicit TextureLayerImpl(int); + TextureLayerImpl(LayerTreeHostImpl* hostImpl, int id); virtual const char* layerTypeAsString() const OVERRIDE; diff --git a/cc/texture_layer_unittest.cc b/cc/texture_layer_unittest.cc index 258f128..887f1b4 100644 --- a/cc/texture_layer_unittest.cc +++ b/cc/texture_layer_unittest.cc @@ -6,8 +6,10 @@ #include "cc/layer_tree_host.h" #include "cc/single_thread_proxy.h" -#include "cc/texture_layer_impl.h" +#include "cc/test/fake_impl_proxy.h" #include "cc/test/fake_layer_tree_host_client.h" +#include "cc/test/fake_layer_tree_host_impl.h" +#include "cc/texture_layer_impl.h" #include "cc/thread.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -39,6 +41,7 @@ private: class TextureLayerTest : public testing::Test { public: TextureLayerTest() + : m_hostImpl(&m_proxy) { } @@ -59,7 +62,8 @@ protected: } scoped_ptr<MockLayerImplTreeHost> m_layerTreeHost; -private: + FakeImplProxy m_proxy; + FakeLayerTreeHostImpl m_hostImpl; }; TEST_F(TextureLayerTest, syncImplWhenChangingTextureId) @@ -96,7 +100,7 @@ TEST_F(TextureLayerTest, syncImplWhenDrawing) scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0); ASSERT_TRUE(testLayer); scoped_ptr<TextureLayerImpl> implLayer; - implLayer = TextureLayerImpl::create(1); + implLayer = TextureLayerImpl::create(&m_hostImpl, 1); ASSERT_TRUE(implLayer); EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); diff --git a/cc/tiled_layer.cc b/cc/tiled_layer.cc index 77a32e6..cbb89bf 100644 --- a/cc/tiled_layer.cc +++ b/cc/tiled_layer.cc @@ -95,9 +95,9 @@ TiledLayer::~TiledLayer() { } -scoped_ptr<LayerImpl> TiledLayer::createLayerImpl() +scoped_ptr<LayerImpl> TiledLayer::createLayerImpl(LayerTreeHostImpl* hostImpl) { - return TiledLayerImpl::create(id()).PassAs<LayerImpl>(); + return TiledLayerImpl::create(hostImpl, id()).PassAs<LayerImpl>(); } void TiledLayer::updateTileSizeAndTilingOption() diff --git a/cc/tiled_layer.h b/cc/tiled_layer.h index eca0972..fe1270c 100644 --- a/cc/tiled_layer.h +++ b/cc/tiled_layer.h @@ -65,7 +65,7 @@ protected: virtual PrioritizedResourceManager* resourceManager() const; private: - virtual scoped_ptr<LayerImpl> createLayerImpl() OVERRIDE; + virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeHostImpl* hostImpl) OVERRIDE; void createTilerIfNeeded(); void setTilingOption(TilingOption); diff --git a/cc/tiled_layer_impl.cc b/cc/tiled_layer_impl.cc index cfd2243..fbfb005 100644 --- a/cc/tiled_layer_impl.cc +++ b/cc/tiled_layer_impl.cc @@ -43,8 +43,8 @@ private: DISALLOW_COPY_AND_ASSIGN(DrawableTile); }; -TiledLayerImpl::TiledLayerImpl(int id) - : LayerImpl(id) +TiledLayerImpl::TiledLayerImpl(LayerTreeHostImpl* hostImpl, int id) + : LayerImpl(hostImpl, id) , m_skipsDraw(true) { } diff --git a/cc/tiled_layer_impl.h b/cc/tiled_layer_impl.h index 73c757b..8638310 100644 --- a/cc/tiled_layer_impl.h +++ b/cc/tiled_layer_impl.h @@ -15,9 +15,9 @@ class DrawableTile; class CC_EXPORT TiledLayerImpl : public LayerImpl { public: - static scoped_ptr<TiledLayerImpl> create(int id) + static scoped_ptr<TiledLayerImpl> create(LayerTreeHostImpl* hostImpl, int id) { - return make_scoped_ptr(new TiledLayerImpl(id)); + return make_scoped_ptr(new TiledLayerImpl(hostImpl, id)); } virtual ~TiledLayerImpl(); @@ -36,7 +36,7 @@ public: virtual void didLoseOutputSurface() OVERRIDE; protected: - explicit TiledLayerImpl(int id); + TiledLayerImpl(LayerTreeHostImpl* hostImpl, int id); // Exposed for testing. bool hasTileAt(int, int) const; bool hasResourceIdForTileAt(int, int) const; diff --git a/cc/tiled_layer_impl_unittest.cc b/cc/tiled_layer_impl_unittest.cc index 257b07c..e0f5433 100644 --- a/cc/tiled_layer_impl_unittest.cc +++ b/cc/tiled_layer_impl_unittest.cc @@ -7,6 +7,8 @@ #include "cc/append_quads_data.h" #include "cc/layer_tiling_data.h" #include "cc/single_thread_proxy.h" +#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/layer_test_common.h" #include "cc/test/mock_quad_culler.h" #include "cc/tile_draw_quad.h" @@ -16,33 +18,58 @@ using namespace LayerTestCommon; namespace cc { + namespace { -// Create a default tiled layer with textures for all tiles and a default -// visibility of the entire layer size. -static scoped_ptr<TiledLayerImpl> createLayer(const gfx::Size& tileSize, const gfx::Size& layerSize, LayerTilingData::BorderTexelOption borderTexels) +class TiledLayerImplTest : public testing::Test { - scoped_ptr<TiledLayerImpl> layer = TiledLayerImpl::create(1); - scoped_ptr<LayerTilingData> tiler = LayerTilingData::create(tileSize, borderTexels); - tiler->setBounds(layerSize); - layer->setTilingData(*tiler); - layer->setSkipsDraw(false); - layer->drawProperties().visible_content_rect = gfx::Rect(gfx::Point(), layerSize); - layer->drawProperties().opacity = 1; - layer->setBounds(layerSize); - layer->setContentBounds(layerSize); - layer->createRenderSurface(); - layer->drawProperties().render_target = layer.get(); - - ResourceProvider::ResourceId resourceId = 1; - for (int i = 0; i < tiler->numTilesX(); ++i) - for (int j = 0; j < tiler->numTilesY(); ++j) - layer->pushTileProperties(i, j, resourceId++, gfx::Rect(0, 0, 1, 1), false); - - return layer.Pass(); -} +public: + TiledLayerImplTest() + : m_hostImpl(&m_proxy) + { + } + + // Create a default tiled layer with textures for all tiles and a default + // visibility of the entire layer size. + scoped_ptr<TiledLayerImpl> createLayer(const gfx::Size& tileSize, const gfx::Size& layerSize, LayerTilingData::BorderTexelOption borderTexels) + { + scoped_ptr<TiledLayerImpl> layer = TiledLayerImpl::create(&m_hostImpl, 1); + scoped_ptr<LayerTilingData> tiler = LayerTilingData::create(tileSize, borderTexels); + tiler->setBounds(layerSize); + layer->setTilingData(*tiler); + layer->setSkipsDraw(false); + layer->drawProperties().visible_content_rect = gfx::Rect(gfx::Point(), layerSize); + layer->drawProperties().opacity = 1; + layer->setBounds(layerSize); + layer->setContentBounds(layerSize); + layer->createRenderSurface(); + layer->drawProperties().render_target = layer.get(); + + ResourceProvider::ResourceId resourceId = 1; + for (int i = 0; i < tiler->numTilesX(); ++i) + for (int j = 0; j < tiler->numTilesY(); ++j) + layer->pushTileProperties(i, j, resourceId++, gfx::Rect(0, 0, 1, 1), false); + + return layer.Pass(); + } + + void getQuads(QuadList& quads, SharedQuadStateList& sharedStates, gfx::Size tileSize, const gfx::Size& layerSize, LayerTilingData::BorderTexelOption borderTexelOption, const gfx::Rect& visibleContentRect) + { + scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, borderTexelOption); + layer->drawProperties().visible_content_rect = visibleContentRect; + layer->setBounds(layerSize); + + MockQuadCuller quadCuller(quads, sharedStates); + AppendQuadsData data; + layer->appendQuads(quadCuller, data); + } -TEST(TiledLayerImplTest, emptyQuadList) +protected: + FakeImplProxy m_proxy; + FakeLayerTreeHostImpl m_hostImpl; +}; + +TEST_F(TiledLayerImplTest, emptyQuadList) { const gfx::Size tileSize(90, 90); const int numTilesX = 8; @@ -95,7 +122,7 @@ TEST(TiledLayerImplTest, emptyQuadList) } } -TEST(TiledLayerImplTest, checkerboarding) +TEST_F(TiledLayerImplTest, checkerboarding) { const gfx::Size tileSize(10, 10); const int numTilesX = 2; @@ -132,65 +159,60 @@ TEST(TiledLayerImplTest, checkerboarding) } } -static void getQuads(QuadList& quads, SharedQuadStateList& sharedStates, gfx::Size tileSize, const gfx::Size& layerSize, LayerTilingData::BorderTexelOption borderTexelOption, const gfx::Rect& visibleContentRect) -{ - scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, borderTexelOption); - layer->drawProperties().visible_content_rect = visibleContentRect; - layer->setBounds(layerSize); - - MockQuadCuller quadCuller(quads, sharedStates); - AppendQuadsData data; - layer->appendQuads(quadCuller, data); -} - // Test with both border texels and without. -#define WITH_AND_WITHOUT_BORDER_TEST(testFixtureName) \ - TEST(TiledLayerImplTest, testFixtureName##NoBorders) \ - { \ - testFixtureName(LayerTilingData::NoBorderTexels); \ - } \ - TEST(TiledLayerImplTest, testFixtureName##HasBorders) \ - { \ - testFixtureName(LayerTilingData::HasBorderTexels);\ +#define WITH_AND_WITHOUT_BORDER_TEST(testFixtureName) \ + TEST_F(TiledLayerImplBorderTest, testFixtureName##NoBorders) \ + { \ + testFixtureName(LayerTilingData::NoBorderTexels); \ + } \ + TEST_F(TiledLayerImplBorderTest, testFixtureName##HasBorders) \ + { \ + testFixtureName(LayerTilingData::HasBorderTexels); \ } -static void coverageVisibleRectOnTileBoundaries(LayerTilingData::BorderTexelOption borders) +class TiledLayerImplBorderTest : public TiledLayerImplTest { - gfx::Size layerSize(1000, 1000); - QuadList quads; - SharedQuadStateList sharedStates; - getQuads(quads, sharedStates, gfx::Size(100, 100), layerSize, borders, gfx::Rect(gfx::Point(), layerSize)); - verifyQuadsExactlyCoverRect(quads, gfx::Rect(gfx::Point(), layerSize)); -} -WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectOnTileBoundaries); +public: + void coverageVisibleRectOnTileBoundaries(LayerTilingData::BorderTexelOption borders) + { + gfx::Size layerSize(1000, 1000); + QuadList quads; + SharedQuadStateList sharedStates; + getQuads(quads, sharedStates, gfx::Size(100, 100), layerSize, borders, gfx::Rect(gfx::Point(), layerSize)); + verifyQuadsExactlyCoverRect(quads, gfx::Rect(gfx::Point(), layerSize)); + } -static void coverageVisibleRectIntersectsTiles(LayerTilingData::BorderTexelOption borders) -{ - // This rect intersects the middle 3x3 of the 5x5 tiles. - gfx::Point topLeft(65, 73); - gfx::Point bottomRight(182, 198); - gfx::Rect visibleContentRect = gfx::BoundingRect(topLeft, bottomRight); + void coverageVisibleRectIntersectsTiles(LayerTilingData::BorderTexelOption borders) + { + // This rect intersects the middle 3x3 of the 5x5 tiles. + gfx::Point topLeft(65, 73); + gfx::Point bottomRight(182, 198); + gfx::Rect visibleContentRect = gfx::BoundingRect(topLeft, bottomRight); + + gfx::Size layerSize(250, 250); + QuadList quads; + SharedQuadStateList sharedStates; + getQuads(quads, sharedStates, gfx::Size(50, 50), gfx::Size(250, 250), LayerTilingData::NoBorderTexels, visibleContentRect); + verifyQuadsExactlyCoverRect(quads, visibleContentRect); + } + + void coverageVisibleRectIntersectsBounds(LayerTilingData::BorderTexelOption borders) + { + gfx::Size layerSize(220, 210); + gfx::Rect visibleContentRect(gfx::Point(), layerSize); + QuadList quads; + SharedQuadStateList sharedStates; + getQuads(quads, sharedStates, gfx::Size(100, 100), layerSize, LayerTilingData::NoBorderTexels, visibleContentRect); + verifyQuadsExactlyCoverRect(quads, visibleContentRect); + } +}; +WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectOnTileBoundaries); - gfx::Size layerSize(250, 250); - QuadList quads; - SharedQuadStateList sharedStates; - getQuads(quads, sharedStates, gfx::Size(50, 50), gfx::Size(250, 250), LayerTilingData::NoBorderTexels, visibleContentRect); - verifyQuadsExactlyCoverRect(quads, visibleContentRect); -} WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectIntersectsTiles); -static void coverageVisibleRectIntersectsBounds(LayerTilingData::BorderTexelOption borders) -{ - gfx::Size layerSize(220, 210); - gfx::Rect visibleContentRect(gfx::Point(), layerSize); - QuadList quads; - SharedQuadStateList sharedStates; - getQuads(quads, sharedStates, gfx::Size(100, 100), layerSize, LayerTilingData::NoBorderTexels, visibleContentRect); - verifyQuadsExactlyCoverRect(quads, visibleContentRect); -} WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectIntersectsBounds); -TEST(TiledLayerImplTest, textureInfoForLayerNoBorders) +TEST_F(TiledLayerImplTest, textureInfoForLayerNoBorders) { gfx::Size tileSize(50, 50); gfx::Size layerSize(250, 250); diff --git a/cc/tiled_layer_unittest.cc b/cc/tiled_layer_unittest.cc index 44f1bd9..d23df5f 100644 --- a/cc/tiled_layer_unittest.cc +++ b/cc/tiled_layer_unittest.cc @@ -12,6 +12,7 @@ #include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread #include "cc/test/animation_test_common.h" #include "cc/test/fake_layer_tree_host_client.h" +#include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_output_surface.h" #include "cc/test/fake_proxy.h" #include "cc/test/geometry_test_utils.h" @@ -62,6 +63,7 @@ public: m_layerTreeHost->initializeRendererIfNeeded(); DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy); m_resourceProvider = ResourceProvider::create(m_outputSurface.get()); + m_hostImpl = make_scoped_ptr(new FakeLayerTreeHostImpl(m_proxy)); } virtual ~TiledLayerTest() @@ -69,13 +71,14 @@ public: resourceManagerClearAllMemory(m_resourceManager.get(), m_resourceProvider.get()); DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy); m_resourceProvider.reset(); + m_hostImpl.reset(); } class ScopedFakeTiledLayerImpl { public: - ScopedFakeTiledLayerImpl(int id) + ScopedFakeTiledLayerImpl(LayerTreeHostImpl* hostImpl, int id) { - m_layerImpl = new FakeTiledLayerImpl(id); + m_layerImpl = new FakeTiledLayerImpl(hostImpl, id); } ~ScopedFakeTiledLayerImpl() { @@ -171,6 +174,7 @@ public: PriorityCalculator m_priorityCalculator; FakeLayerImplTreeHostClient m_fakeLayerImplTreeHostClient; scoped_ptr<LayerTreeHost> m_layerTreeHost; + scoped_ptr<FakeLayerTreeHostImpl> m_hostImpl; scoped_ptr<PrioritizedResourceManager> m_resourceManager; TestOcclusionTracker* m_occlusion; }; @@ -178,7 +182,7 @@ public: TEST_F(TiledLayerTest, pushDirtyTiles) { scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); // The tile size is 100x100, so this invalidates and then paints two tiles. layer->setBounds(gfx::Size(100, 200)); @@ -204,7 +208,7 @@ TEST_F(TiledLayerTest, pushDirtyTiles) TEST_F(TiledLayerTest, pushOccludedDirtyTiles) { scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); TestOcclusionTracker occluded; m_occlusion = &occluded; @@ -241,7 +245,7 @@ TEST_F(TiledLayerTest, pushOccludedDirtyTiles) TEST_F(TiledLayerTest, pushDeletedTiles) { scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); // The tile size is 100x100, so this invalidates and then paints two tiles. layer->setBounds(gfx::Size(100, 200)); @@ -276,7 +280,7 @@ TEST_F(TiledLayerTest, pushDeletedTiles) TEST_F(TiledLayerTest, pushIdlePaintTiles) { scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); // The tile size is 100x100. Setup 5x5 tiles with one visible tile in the center. // This paints 1 visible of the 25 invalid tiles. @@ -312,7 +316,7 @@ TEST_F(TiledLayerTest, pushIdlePaintTiles) TEST_F(TiledLayerTest, predictivePainting) { scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); // Prepainting should occur in the scroll direction first, and the // visible rect should be extruded only along the dominant axis. @@ -386,9 +390,9 @@ TEST_F(TiledLayerTest, pushTilesAfterIdlePaintFailed) // Start with 2mb of memory, but the test is going to try to use just more than 1mb, so we reduce to 1mb later. m_resourceManager->setMaxMemoryLimitBytes(2 * 1024 * 1024); scoped_refptr<FakeTiledLayer> layer1 = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); - ScopedFakeTiledLayerImpl layerImpl1(1); + ScopedFakeTiledLayerImpl layerImpl1(m_hostImpl.get(), 1); scoped_refptr<FakeTiledLayer> layer2 = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); - ScopedFakeTiledLayerImpl layerImpl2(2); + ScopedFakeTiledLayerImpl layerImpl2(m_hostImpl.get(), 2); // For this test we have two layers. layer1 exhausts most texture memory, leaving room for 2 more tiles from // layer2, but not all three tiles. First we paint layer1, and one tile from layer2. Then when we idle paint @@ -438,7 +442,7 @@ TEST_F(TiledLayerTest, pushTilesAfterIdlePaintFailed) TEST_F(TiledLayerTest, pushIdlePaintedOccludedTiles) { scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); TestOcclusionTracker occluded; m_occlusion = &occluded; @@ -457,7 +461,7 @@ TEST_F(TiledLayerTest, pushIdlePaintedOccludedTiles) TEST_F(TiledLayerTest, pushTilesMarkedDirtyDuringPaint) { scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); // The tile size is 100x100, so this invalidates and then paints two tiles. // However, during the paint, we invalidate one of the tiles. This should @@ -476,8 +480,8 @@ TEST_F(TiledLayerTest, pushTilesLayerMarkedDirtyDuringPaintOnNextLayer) { scoped_refptr<FakeTiledLayer> layer1 = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); scoped_refptr<FakeTiledLayer> layer2 = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); - ScopedFakeTiledLayerImpl layer1Impl(1); - ScopedFakeTiledLayerImpl layer2Impl(2); + ScopedFakeTiledLayerImpl layer1Impl(m_hostImpl.get(), 1); + ScopedFakeTiledLayerImpl layer2Impl(m_hostImpl.get(), 2); // Invalidate a tile on layer1, during update of layer 2. layer2->fakeLayerUpdater()->setRectToInvalidate(gfx::Rect(0, 50, 100, 50), layer1.get()); @@ -499,8 +503,8 @@ TEST_F(TiledLayerTest, pushTilesLayerMarkedDirtyDuringPaintOnPreviousLayer) { scoped_refptr<FakeTiledLayer> layer1 = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); scoped_refptr<FakeTiledLayer> layer2 = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); - ScopedFakeTiledLayerImpl layer1Impl(1); - ScopedFakeTiledLayerImpl layer2Impl(2); + ScopedFakeTiledLayerImpl layer1Impl(m_hostImpl.get(), 1); + ScopedFakeTiledLayerImpl layer2Impl(m_hostImpl.get(), 2); layer1->fakeLayerUpdater()->setRectToInvalidate(gfx::Rect(0, 50, 100, 50), layer2.get()); layer1->setBounds(gfx::Size(100, 200)); @@ -541,7 +545,7 @@ TEST_F(TiledLayerTest, paintSmallAnimatedLayersImmediately) m_resourceManager->setMaxMemoryLimitBytes(memoryForLayer); scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); // Full size layer with half being visible. gfx::Size contentBounds(layerWidth, layerHeight); @@ -583,7 +587,7 @@ TEST_F(TiledLayerTest, paintSmallAnimatedLayersImmediately) TEST_F(TiledLayerTest, idlePaintOutOfMemory) { scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); // We have enough memory for only the visible rect, so we will run out of memory in first idle paint. int memoryLimit = 4 * 100 * 100; // 1 tiles, 4 bytes per pixel. @@ -606,7 +610,7 @@ TEST_F(TiledLayerTest, idlePaintOutOfMemory) TEST_F(TiledLayerTest, idlePaintZeroSizedLayer) { scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); bool animating[2] = {false, true}; for (int i = 0; i < 2; i++) { @@ -633,7 +637,7 @@ TEST_F(TiledLayerTest, idlePaintZeroSizedLayer) TEST_F(TiledLayerTest, idlePaintNonVisibleLayers) { scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); // Alternate between not visible and visible. gfx::Rect v(0, 0, 100, 100); @@ -663,7 +667,7 @@ TEST_F(TiledLayerTest, idlePaintNonVisibleLayers) TEST_F(TiledLayerTest, invalidateFromPrepare) { scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); // The tile size is 100x100, so this invalidates and then paints two tiles. layer->setBounds(gfx::Size(100, 200)); @@ -736,7 +740,7 @@ TEST_F(TiledLayerTest, verifyUpdateRectWhenContentBoundsAreScaled) TEST_F(TiledLayerTest, verifyInvalidationWhenContentsScaleChanges) { scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(m_resourceManager.get())); - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); // Create a layer with one tile. layer->setBounds(gfx::Size(100, 100)); @@ -888,7 +892,7 @@ TEST_F(TiledLayerPartialUpdateTest, partialUpdates) m_layerTreeHost->updateLayers( *m_queue.get(), std::numeric_limits<size_t>::max()); { - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); EXPECT_EQ(6, m_queue->fullUploadSize()); EXPECT_EQ(0, m_queue->partialUploadSize()); updateTextures(); @@ -903,7 +907,7 @@ TEST_F(TiledLayerPartialUpdateTest, partialUpdates) layer->invalidateContentRect(gfx::Rect(0, 0, 300, 150)); m_layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max()); { - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); EXPECT_EQ(3, m_queue->fullUploadSize()); EXPECT_EQ(3, m_queue->partialUploadSize()); updateTextures(); @@ -917,7 +921,7 @@ TEST_F(TiledLayerPartialUpdateTest, partialUpdates) // Partial update of 6 tiles. layer->invalidateContentRect(gfx::Rect(50, 50, 200, 100)); { - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); m_layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max()); EXPECT_EQ(2, m_queue->fullUploadSize()); EXPECT_EQ(4, m_queue->partialUploadSize()); @@ -932,7 +936,7 @@ TEST_F(TiledLayerPartialUpdateTest, partialUpdates) // Checkerboard all tiles. layer->invalidateContentRect(gfx::Rect(0, 0, 300, 200)); { - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); layerPushPropertiesTo(layer.get(), layerImpl.get()); } m_layerTreeHost->commitComplete(); @@ -940,7 +944,7 @@ TEST_F(TiledLayerPartialUpdateTest, partialUpdates) // Partial update of 6 checkerboard tiles. layer->invalidateContentRect(gfx::Rect(50, 50, 200, 100)); { - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); m_layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max()); EXPECT_EQ(6, m_queue->fullUploadSize()); EXPECT_EQ(0, m_queue->partialUploadSize()); @@ -955,7 +959,7 @@ TEST_F(TiledLayerPartialUpdateTest, partialUpdates) // Partial update of 4 tiles. layer->invalidateContentRect(gfx::Rect(50, 50, 100, 100)); { - ScopedFakeTiledLayerImpl layerImpl(1); + ScopedFakeTiledLayerImpl layerImpl(m_hostImpl.get(), 1); m_layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max()); EXPECT_EQ(0, m_queue->fullUploadSize()); EXPECT_EQ(4, m_queue->partialUploadSize()); @@ -1435,9 +1439,9 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated) child->fakeLayerUpdater()->clearUpdateCount(); child2->fakeLayerUpdater()->clearUpdateCount(); - ScopedFakeTiledLayerImpl rootImpl(root->id()); - ScopedFakeTiledLayerImpl childImpl(child->id()); - ScopedFakeTiledLayerImpl child2Impl(child2->id()); + ScopedFakeTiledLayerImpl rootImpl(m_hostImpl.get(), root->id()); + ScopedFakeTiledLayerImpl childImpl(m_hostImpl.get(), child->id()); + ScopedFakeTiledLayerImpl child2Impl(m_hostImpl.get(), child2->id()); layerPushPropertiesTo(root.get(), rootImpl.get()); layerPushPropertiesTo(child.get(), childImpl.get()); layerPushPropertiesTo(child2.get(), child2Impl.get()); @@ -1470,9 +1474,9 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated) child->fakeLayerUpdater()->clearUpdateCount(); child2->fakeLayerUpdater()->clearUpdateCount(); - ScopedFakeTiledLayerImpl rootImpl(root->id()); - ScopedFakeTiledLayerImpl childImpl(child->id()); - ScopedFakeTiledLayerImpl child2Impl(child2->id()); + ScopedFakeTiledLayerImpl rootImpl(m_hostImpl.get(), root->id()); + ScopedFakeTiledLayerImpl childImpl(m_hostImpl.get(), child->id()); + ScopedFakeTiledLayerImpl child2Impl(m_hostImpl.get(), child2->id()); layerPushPropertiesTo(root.get(), rootImpl.get()); layerPushPropertiesTo(child.get(), childImpl.get()); layerPushPropertiesTo(child2.get(), child2Impl.get()); @@ -1506,9 +1510,9 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated) child->fakeLayerUpdater()->clearUpdateCount(); child2->fakeLayerUpdater()->clearUpdateCount(); - ScopedFakeTiledLayerImpl rootImpl(root->id()); - ScopedFakeTiledLayerImpl childImpl(child->id()); - ScopedFakeTiledLayerImpl child2Impl(child2->id()); + ScopedFakeTiledLayerImpl rootImpl(m_hostImpl.get(), root->id()); + ScopedFakeTiledLayerImpl childImpl(m_hostImpl.get(), child->id()); + ScopedFakeTiledLayerImpl child2Impl(m_hostImpl.get(), child2->id()); layerPushPropertiesTo(root.get(), rootImpl.get()); layerPushPropertiesTo(child.get(), childImpl.get()); layerPushPropertiesTo(child2.get(), child2Impl.get()); diff --git a/cc/tree_synchronizer.cc b/cc/tree_synchronizer.cc index 8dd94d1..863edef 100644 --- a/cc/tree_synchronizer.cc +++ b/cc/tree_synchronizer.cc @@ -44,12 +44,12 @@ void TreeSynchronizer::collectExistingLayerImplRecursive(ScopedPtrLayerImplMap& oldLayers.set(id, layerImpl.Pass()); } -scoped_ptr<LayerImpl> TreeSynchronizer::reuseOrCreateLayerImpl(RawPtrLayerImplMap& newLayers, ScopedPtrLayerImplMap& oldLayers, Layer* layer) +scoped_ptr<LayerImpl> TreeSynchronizer::reuseOrCreateLayerImpl(RawPtrLayerImplMap& newLayers, ScopedPtrLayerImplMap& oldLayers, Layer* layer, LayerTreeHostImpl* hostImpl) { scoped_ptr<LayerImpl> layerImpl = oldLayers.take(layer->id()); if (!layerImpl) - layerImpl = layer->createLayerImpl(); + layerImpl = layer->createLayerImpl(hostImpl); newLayers[layer->id()] = layerImpl.get(); return layerImpl.Pass(); @@ -60,7 +60,7 @@ scoped_ptr<LayerImpl> TreeSynchronizer::synchronizeTreeRecursive(RawPtrLayerImpl if (!layer) return scoped_ptr<LayerImpl>(); - scoped_ptr<LayerImpl> layerImpl = reuseOrCreateLayerImpl(newLayers, oldLayers, layer); + scoped_ptr<LayerImpl> layerImpl = reuseOrCreateLayerImpl(newLayers, oldLayers, layer, hostImpl); layerImpl->clearChildList(); const std::vector<scoped_refptr<Layer> >& children = layer->children(); @@ -71,7 +71,6 @@ scoped_ptr<LayerImpl> TreeSynchronizer::synchronizeTreeRecursive(RawPtrLayerImpl layerImpl->setReplicaLayer(synchronizeTreeRecursive(newLayers, oldLayers, layer->replicaLayer(), hostImpl)); layer->pushPropertiesTo(layerImpl.get()); - layerImpl->setLayerTreeHostImpl(hostImpl); // Remove all dangling pointers. The pointers will be setup later in updateScrollbarLayerPointersRecursive phase if (ScrollbarAnimationController* scrollbarController = layerImpl->scrollbarAnimationController()) { diff --git a/cc/tree_synchronizer.h b/cc/tree_synchronizer.h index 8974882..65ff3ba 100644 --- a/cc/tree_synchronizer.h +++ b/cc/tree_synchronizer.h @@ -29,7 +29,7 @@ private: typedef base::hash_map<int, LayerImpl*> RawPtrLayerImplMap; // Declared as static member functions so they can access functions on Layer as a friend class. - static scoped_ptr<LayerImpl> reuseOrCreateLayerImpl(RawPtrLayerImplMap& newLayers, ScopedPtrLayerImplMap& oldLayers, Layer*); + static scoped_ptr<LayerImpl> reuseOrCreateLayerImpl(RawPtrLayerImplMap& newLayers, ScopedPtrLayerImplMap& oldLayers, Layer*, LayerTreeHostImpl*); static void collectExistingLayerImplRecursive(ScopedPtrLayerImplMap& oldLayers, scoped_ptr<LayerImpl>); static scoped_ptr<LayerImpl> synchronizeTreeRecursive(RawPtrLayerImplMap& newLayers, ScopedPtrLayerImplMap& oldLayers, Layer*, LayerTreeHostImpl*); static void updateScrollbarLayerPointersRecursive(const RawPtrLayerImplMap& newLayers, Layer*); diff --git a/cc/tree_synchronizer_unittest.cc b/cc/tree_synchronizer_unittest.cc index 61aeb2b..893ed56 100644 --- a/cc/tree_synchronizer_unittest.cc +++ b/cc/tree_synchronizer_unittest.cc @@ -22,9 +22,9 @@ namespace { class MockLayerImpl : public LayerImpl { public: - static scoped_ptr<MockLayerImpl> create(int layerId) + static scoped_ptr<MockLayerImpl> create(LayerTreeHostImpl* hostImpl, int layerId) { - return make_scoped_ptr(new MockLayerImpl(layerId)); + return make_scoped_ptr(new MockLayerImpl(hostImpl, layerId)); } virtual ~MockLayerImpl() { @@ -35,8 +35,8 @@ public: void setLayerImplDestructionList(std::vector<int>* list) { m_layerImplDestructionList = list; } private: - MockLayerImpl(int layerId) - : LayerImpl(layerId) + MockLayerImpl(LayerTreeHostImpl* hostImpl, int layerId) + : LayerImpl(hostImpl, layerId) , m_layerImplDestructionList(0) { } @@ -51,9 +51,9 @@ public: return make_scoped_refptr(new MockLayer(layerImplDestructionList)); } - virtual scoped_ptr<LayerImpl> createLayerImpl() OVERRIDE + virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeHostImpl* hostImpl) OVERRIDE { - return MockLayerImpl::create(m_layerId).PassAs<LayerImpl>(); + return MockLayerImpl::create(hostImpl, m_layerId).PassAs<LayerImpl>(); } virtual void pushPropertiesTo(LayerImpl* layerImpl) OVERRIDE diff --git a/cc/video_layer.cc b/cc/video_layer.cc index e8a9fad..05f2c16 100644 --- a/cc/video_layer.cc +++ b/cc/video_layer.cc @@ -27,9 +27,9 @@ VideoLayer::~VideoLayer() { } -scoped_ptr<LayerImpl> VideoLayer::createLayerImpl() +scoped_ptr<LayerImpl> VideoLayer::createLayerImpl(LayerTreeHostImpl* hostImpl) { - return VideoLayerImpl::create(m_layerId, m_provider, m_unwrapper).PassAs<LayerImpl>(); + return VideoLayerImpl::create(hostImpl, m_layerId, m_provider, m_unwrapper).PassAs<LayerImpl>(); } } // namespace cc diff --git a/cc/video_layer.h b/cc/video_layer.h index 0e86839..ba90500 100644 --- a/cc/video_layer.h +++ b/cc/video_layer.h @@ -30,7 +30,7 @@ public: static scoped_refptr<VideoLayer> create(WebKit::WebVideoFrameProvider*, const FrameUnwrapper&); - virtual scoped_ptr<LayerImpl> createLayerImpl() OVERRIDE; + virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeHostImpl* hostImpl) OVERRIDE; private: VideoLayer(WebKit::WebVideoFrameProvider*, const FrameUnwrapper&); diff --git a/cc/video_layer_impl.cc b/cc/video_layer_impl.cc index 5555528..d729156 100644 --- a/cc/video_layer_impl.cc +++ b/cc/video_layer_impl.cc @@ -19,9 +19,9 @@ namespace cc { -VideoLayerImpl::VideoLayerImpl(int id, WebKit::WebVideoFrameProvider* provider, +VideoLayerImpl::VideoLayerImpl(LayerTreeHostImpl* hostImpl, int id, WebKit::WebVideoFrameProvider* provider, const FrameUnwrapper& unwrapper) - : LayerImpl(id) + : LayerImpl(hostImpl, id) , m_provider(provider) , m_unwrapper(unwrapper) , m_webFrame(0) diff --git a/cc/video_layer_impl.h b/cc/video_layer_impl.h index 59a0ca1a9..00ab57f 100644 --- a/cc/video_layer_impl.h +++ b/cc/video_layer_impl.h @@ -34,10 +34,10 @@ class CC_EXPORT VideoLayerImpl : public LayerImpl public: typedef base::Callback<media::VideoFrame* (WebKit::WebVideoFrame*)> FrameUnwrapper; - static scoped_ptr<VideoLayerImpl> create(int id, WebKit::WebVideoFrameProvider* provider, + static scoped_ptr<VideoLayerImpl> create(LayerTreeHostImpl* hostImpl, int id, WebKit::WebVideoFrameProvider* provider, const FrameUnwrapper& unwrapper) { - return make_scoped_ptr(new VideoLayerImpl(id, provider, unwrapper)); + return make_scoped_ptr(new VideoLayerImpl(hostImpl, id, provider, unwrapper)); } virtual ~VideoLayerImpl(); @@ -66,7 +66,7 @@ public: }; private: - VideoLayerImpl(int, WebKit::WebVideoFrameProvider*, const FrameUnwrapper&); + VideoLayerImpl(LayerTreeHostImpl*, int, WebKit::WebVideoFrameProvider*, const FrameUnwrapper&); virtual const char* layerTypeAsString() const OVERRIDE; |