Index: cc/trees/layer_tree_host_unittest.cc |
diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc |
index b81bd047c1d7f302bb448f8cfbb01a429cb850f2..3ae9800294ef364092414fb42ffeb4cd21ed8219 100644 |
--- a/cc/trees/layer_tree_host_unittest.cc |
+++ b/cc/trees/layer_tree_host_unittest.cc |
@@ -2564,5 +2564,198 @@ class LayerTreeHostTestIOSurfaceDrawing : public LayerTreeHostTest { |
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestIOSurfaceDrawing); |
+class LayerTreeHostTestAsyncReadback : public LayerTreeHostTest { |
+ protected: |
+ virtual void SetupTree() OVERRIDE { |
+ root = FakeContentLayer::Create(&client_); |
+ root->SetBounds(gfx::Size(20, 20)); |
+ |
+ child = FakeContentLayer::Create(&client_); |
+ child->SetBounds(gfx::Size(10, 10)); |
+ root->AddChild(child); |
+ |
+ layer_tree_host()->SetRootLayer(root); |
+ LayerTreeHostTest::SetupTree(); |
+ } |
+ |
+ virtual void BeginTest() OVERRIDE { |
+ PostSetNeedsCommitToMainThread(); |
+ } |
+ |
+ virtual void DidCommitAndDrawFrame() { |
+ int frame = layer_tree_host()->commit_number(); |
+ switch (frame) { |
+ case 1: |
+ child->RequestCopyAsBitmap(base::Bind( |
+ &LayerTreeHostTestAsyncReadback::BitmapCallback, |
+ base::Unretained(this))); |
+ EXPECT_EQ(0u, callbacks_.size()); |
+ break; |
+ case 2: |
+ // Flush the message loops and make sure the callbacks run. |
+ layer_tree_host()->SetNeedsCommit(); |
+ break; |
+ case 3: |
+ ASSERT_EQ(1u, callbacks_.size()); |
+ EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[0].ToString()); |
+ |
+ child->RequestCopyAsBitmap(base::Bind( |
+ &LayerTreeHostTestAsyncReadback::BitmapCallback, |
+ base::Unretained(this))); |
+ root->RequestCopyAsBitmap(base::Bind( |
+ &LayerTreeHostTestAsyncReadback::BitmapCallback, |
+ base::Unretained(this))); |
+ child->RequestCopyAsBitmap(base::Bind( |
+ &LayerTreeHostTestAsyncReadback::BitmapCallback, |
+ base::Unretained(this))); |
+ EXPECT_EQ(1u, callbacks_.size()); |
+ break; |
+ case 4: |
+ // Flush the message loops and make sure the callbacks run. |
+ layer_tree_host()->SetNeedsCommit(); |
+ break; |
+ case 5: |
+ ASSERT_EQ(4u, callbacks_.size()); |
+ // The child was copied to a bitmap and passed back twice. |
+ EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[1].ToString()); |
+ EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[2].ToString()); |
+ // The root was copied to a bitmap and passed back also. |
+ EXPECT_EQ(gfx::Size(20, 20).ToString(), callbacks_[3].ToString()); |
+ EndTest(); |
+ break; |
+ } |
+ } |
+ |
+ void BitmapCallback(scoped_ptr<SkBitmap> bitmap) { |
+ EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |
+ EXPECT_TRUE(bitmap); |
+ callbacks_.push_back(gfx::Size(bitmap->width(), bitmap->height())); |
+ } |
+ |
+ virtual void AfterTest() {} |
+ |
+ virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE { |
+ if (use_gl_renderer_) |
+ return FakeOutputSurface::Create3d().PassAs<OutputSurface>(); |
+ return FakeOutputSurface::CreateSoftware( |
+ make_scoped_ptr(new SoftwareOutputDevice)).PassAs<OutputSurface>(); |
+ } |
+ |
+ bool use_gl_renderer_; |
+ std::vector<gfx::Size> callbacks_; |
+ FakeContentLayerClient client_; |
+ scoped_refptr<FakeContentLayer> root; |
+ scoped_refptr<FakeContentLayer> child; |
+}; |
+ |
+TEST_F(LayerTreeHostTestAsyncReadback, GLRenderer_RunSingleThread) { |
+ use_gl_renderer_ = true; |
+ RunTest(false); |
+} |
+ |
+TEST_F(LayerTreeHostTestAsyncReadback, GLRenderer_RunMultiThread) { |
+ use_gl_renderer_ = true; |
+ RunTest(true); |
+} |
+ |
+TEST_F(LayerTreeHostTestAsyncReadback, SoftwareRenderer_RunSingleThread) { |
+ use_gl_renderer_ = false; |
+ RunTest(false); |
+} |
+ |
+TEST_F(LayerTreeHostTestAsyncReadback, SoftwareRenderer_RunMultiThread) { |
+ use_gl_renderer_ = false; |
+ RunTest(true); |
+} |
+ |
+class LayerTreeHostTestAsyncReadbackLayerDestroyed : public LayerTreeHostTest { |
+ protected: |
+ virtual void SetupTree() OVERRIDE { |
+ root = FakeContentLayer::Create(&client_); |
+ root->SetBounds(gfx::Size(20, 20)); |
+ |
+ main_destroyed = FakeContentLayer::Create(&client_); |
+ main_destroyed->SetBounds(gfx::Size(15, 15)); |
+ root->AddChild(main_destroyed); |
+ |
+ impl_destroyed = FakeContentLayer::Create(&client_); |
+ impl_destroyed->SetBounds(gfx::Size(10, 10)); |
+ root->AddChild(impl_destroyed); |
+ |
+ layer_tree_host()->SetRootLayer(root); |
+ LayerTreeHostTest::SetupTree(); |
+ } |
+ |
+ virtual void BeginTest() OVERRIDE { |
+ callback_count_ = 0; |
+ PostSetNeedsCommitToMainThread(); |
+ } |
+ |
+ virtual void DidCommit() { |
+ int frame = layer_tree_host()->commit_number(); |
+ switch (frame) { |
+ case 1: |
+ main_destroyed->RequestCopyAsBitmap(base::Bind( |
+ &LayerTreeHostTestAsyncReadbackLayerDestroyed::BitmapCallback, |
+ base::Unretained(this))); |
+ impl_destroyed->RequestCopyAsBitmap(base::Bind( |
+ &LayerTreeHostTestAsyncReadbackLayerDestroyed::BitmapCallback, |
+ base::Unretained(this))); |
+ EXPECT_EQ(0, callback_count_); |
+ |
+ // Destroy the main thread layer right away. |
+ main_destroyed->RemoveFromParent(); |
+ main_destroyed = NULL; |
+ |
+ // Should callback with a NULL bitmap. |
+ EXPECT_EQ(1, callback_count_); |
+ |
+ // Prevent drawing so we can't make a copy of the impl_destroyed layer. |
+ layer_tree_host()->SetViewportSize(gfx::Size()); |
+ break; |
+ case 2: |
+ // Flush the message loops and make sure the callbacks run. |
+ layer_tree_host()->SetNeedsCommit(); |
+ break; |
+ case 3: |
+ // No drawing means no readback yet. |
+ EXPECT_EQ(1, callback_count_); |
+ |
+ // Destroy the impl thread layer. |
+ impl_destroyed->RemoveFromParent(); |
+ impl_destroyed = NULL; |
+ |
+ // No callback yet because it's on the impl side. |
+ EXPECT_EQ(1, callback_count_); |
+ break; |
+ case 4: |
+ // Flush the message loops and make sure the callbacks run. |
+ layer_tree_host()->SetNeedsCommit(); |
+ break; |
+ case 5: |
+ // We should get another callback with a NULL bitmap. |
+ EXPECT_EQ(2, callback_count_); |
+ EndTest(); |
+ break; |
+ } |
+ } |
+ |
+ void BitmapCallback(scoped_ptr<SkBitmap> bitmap) { |
+ EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |
+ EXPECT_FALSE(bitmap); |
+ ++callback_count_; |
+ } |
+ |
+ virtual void AfterTest() {} |
+ |
+ int callback_count_; |
+ FakeContentLayerClient client_; |
+ scoped_refptr<FakeContentLayer> root; |
piman
2013/04/26 00:15:02
nit: trailing _ on fields, here and below
danakj
2013/04/26 01:00:06
Done.
|
+ scoped_refptr<FakeContentLayer> main_destroyed; |
+ scoped_refptr<FakeContentLayer> impl_destroyed; |
+}; |
+ |
+SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestAsyncReadbackLayerDestroyed); |
+ |
} // namespace |
} // namespace cc |