Index: cc/layers/texture_layer_unittest.cc |
diff --git a/cc/layers/texture_layer_unittest.cc b/cc/layers/texture_layer_unittest.cc |
index cfbe8133fbf51cd445a1397fd2dde1b0a19434a8..4d3db845cd20c77c995e2d8838e9259533585831 100644 |
--- a/cc/layers/texture_layer_unittest.cc |
+++ b/cc/layers/texture_layer_unittest.cc |
@@ -795,13 +795,6 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { |
root_->AddChild(layer_); |
layer_tree_host()->SetRootLayer(root_); |
layer_tree_host()->SetViewportSize(bounds); |
- SetMailbox('1'); |
- EXPECT_EQ(0, callback_count_); |
- |
- // Case #1: change mailbox before the commit. The old mailbox should be |
- // released immediately. |
- SetMailbox('2'); |
- EXPECT_EQ(1, callback_count_); |
PostSetNeedsCommitToMainThread(); |
} |
@@ -809,27 +802,32 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { |
++commit_count_; |
switch (commit_count_) { |
case 1: |
+ // First commit from setting up tree. Nothing to check. |
+ SetMailbox('1'); |
+ EXPECT_EQ(0, callback_count_); |
+ break; |
+ case 2: |
// Case #2: change mailbox after the commit (and draw), where the |
// layer draws. The old mailbox should be released during the next |
// commit. |
- SetMailbox('3'); |
- EXPECT_EQ(1, callback_count_); |
+ SetMailbox('2'); |
+ EXPECT_EQ(0, callback_count_); |
break; |
- case 2: |
- EXPECT_EQ(2, callback_count_); |
+ case 3: |
+ EXPECT_EQ(1, callback_count_); |
// Case #3: change mailbox when the layer doesn't draw. The old |
// mailbox should be released during the next commit. |
layer_->SetBounds(gfx::Size()); |
- SetMailbox('4'); |
+ SetMailbox('3'); |
break; |
- case 3: |
- EXPECT_EQ(3, callback_count_); |
+ case 4: |
+ EXPECT_EQ(2, callback_count_); |
// Case #4: release mailbox that was committed but never drawn. The |
// old mailbox should be released during the next commit. |
layer_->SetTextureMailbox(TextureMailbox(), |
scoped_ptr<SingleReleaseCallback>()); |
break; |
- case 4: |
+ case 5: |
if (layer_tree_host()->settings().impl_side_painting) { |
// With impl painting, the texture mailbox will still be on the impl |
// thread when the commit finishes, because the layer is not drawble |
@@ -841,18 +839,18 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { |
} else { |
++commit_count_; |
} |
- case 5: |
- EXPECT_EQ(4, callback_count_); |
+ case 6: |
+ EXPECT_EQ(3, callback_count_); |
// Restore a mailbox for the next step. |
- SetMailbox('5'); |
+ SetMailbox('4'); |
break; |
- case 6: |
+ case 7: |
// Case #5: remove layer from tree. Callback should *not* be called, the |
// mailbox is returned to the main thread. |
- EXPECT_EQ(4, callback_count_); |
+ EXPECT_EQ(3, callback_count_); |
layer_->RemoveFromParent(); |
break; |
- case 7: |
+ case 8: |
if (layer_tree_host()->settings().impl_side_painting) { |
// With impl painting, the texture mailbox will still be on the impl |
// thread when the commit finishes, because the layer is not around to |
@@ -863,12 +861,12 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { |
} else { |
++commit_count_; |
} |
- case 8: |
- EXPECT_EQ(4, callback_count_); |
+ case 9: |
+ EXPECT_EQ(3, callback_count_); |
// Resetting the mailbox will call the callback now. |
layer_->SetTextureMailbox(TextureMailbox(), |
scoped_ptr<SingleReleaseCallback>()); |
- EXPECT_EQ(5, callback_count_); |
+ EXPECT_EQ(4, callback_count_); |
EndTest(); |
break; |
default: |
@@ -1871,6 +1869,65 @@ class TextureLayerChangeInvisibleMailboxTest |
SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest); |
+class TrackMailboxReleaseTextureHelper { |
+ public: |
+ TrackMailboxReleaseTextureHelper() |
+ : mailbox_id_(0), |
+ last_released_mailbox_(0) {} |
+ |
+ void ReleaseCallback(int mailbox_id, uint32 sync_point, bool lost_resource) { |
+ last_released_mailbox_++; |
+ EXPECT_EQ(last_released_mailbox_, mailbox_id); |
+ } |
+ |
+ void SetNextMailbox(TextureLayer* layer) { |
+ mailbox_id_++; |
+ |
+ TextureMailbox mailbox = TextureMailbox( |
+ MailboxFromString(std::string(mailbox_id_, 'a')), GL_TEXTURE_2D, 0); |
+ scoped_ptr<SingleReleaseCallback> release_callback = |
+ SingleReleaseCallback::Create( |
+ base::Bind(&TrackMailboxReleaseTextureHelper::ReleaseCallback, |
+ base::Unretained(this), |
+ mailbox_id_)); |
+ layer->SetTextureMailbox(mailbox, release_callback.Pass()); |
+ } |
+ |
+ int last_released_mailbox() { return last_released_mailbox_; } |
+ |
+ private: |
+ int mailbox_id_; |
+ int last_released_mailbox_; |
+}; |
+ |
+TEST(TextureLayerUnitTest, ReleaseMailboxOnReset) { |
+ TrackMailboxReleaseTextureHelper helper; |
+ scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); |
+ |
+ // Set first mailbox. |
+ helper.SetNextMailbox(test_layer.get()); |
+ EXPECT_EQ(0, helper.last_released_mailbox()); |
+ |
+ // Set second mailbox. First should be released immediately. |
+ helper.SetNextMailbox(test_layer.get()); |
+ EXPECT_EQ(1, helper.last_released_mailbox()); |
+ |
+ test_layer = NULL; |
+ EXPECT_EQ(2, helper.last_released_mailbox()); |
+} |
+ |
+TEST(TextureLayerUnitTest, ReleaseMailboxRendererCapChange) { |
+ TrackMailboxReleaseTextureHelper helper; |
+ scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); |
+ |
+ helper.SetNextMailbox(test_layer.get()); |
+ EXPECT_EQ(0, helper.last_released_mailbox()); |
+ |
+ test_layer->OnOutputSurfaceCreated(); |
+ helper.SetNextMailbox(test_layer.get()); |
+ EXPECT_EQ(1, helper.last_released_mailbox()); |
+} |
+ |
// Test that TextureLayerImpl::ReleaseResources can be called which releases |
// the mailbox back to TextureLayerClient. |
class TextureLayerReleaseResourcesBase |