Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3335)

Unified Diff: cc/trees/layer_tree_host_unittest_delegated.cc

Issue 24078024: cc: Return resources to child compositor via a Callback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: deletechild: No AndReceiveAck needed, change STP Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/test/layer_tree_test.h ('k') | cc/trees/single_thread_proxy.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/trees/layer_tree_host_unittest_delegated.cc
diff --git a/cc/trees/layer_tree_host_unittest_delegated.cc b/cc/trees/layer_tree_host_unittest_delegated.cc
index af79c84eb2dbaaf053cba25e2aba3eb130e16349..012f6f82fdf85cde9bf2ad008d2d9b32d50bf2b2 100644
--- a/cc/trees/layer_tree_host_unittest_delegated.cc
+++ b/cc/trees/layer_tree_host_unittest_delegated.cc
@@ -7,6 +7,7 @@
#include <algorithm>
#include "base/bind.h"
+#include "base/location.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
@@ -765,8 +766,8 @@ class LayerTreeHostDelegatedTestMergeResources
EXPECT_EQ(1u, map.count(555));
EXPECT_EQ(2u, delegated_impl->Resources().size());
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second));
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(999));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(555));
EndTest();
}
@@ -850,11 +851,6 @@ class LayerTreeHostDelegatedTestReturnUnusedResources
delegated_->SetFrameData(frame.Pass());
break;
case 2:
- // Retrieve unused resources to the main thread.
- // TODO(danakj): Shouldn't need to commit to get resources.
- layer_tree_host()->SetNeedsCommit();
- return;
- case 3:
// All of the resources are in use.
delegated_->TakeUnusedResourcesForChildCompositor(&resources);
EXPECT_EQ(0u, resources.size());
@@ -862,16 +858,12 @@ class LayerTreeHostDelegatedTestReturnUnusedResources
// Keep using 999 but stop using 555.
frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
AddTextureQuad(frame.get(), 999);
+ AddTransferableResource(frame.get(), 999);
AddTextureQuad(frame.get(), 444);
AddTransferableResource(frame.get(), 444);
delegated_->SetFrameData(frame.Pass());
break;
- case 4:
- // Retrieve unused resources to the main thread.
- // TODO(danakj): Shouldn't need to commit to get resources.
- layer_tree_host()->SetNeedsCommit();
- return;
- case 5:
+ case 3:
// 555 is no longer in use.
delegated_->TakeUnusedResourcesForChildCompositor(&resources);
{
@@ -883,16 +875,17 @@ class LayerTreeHostDelegatedTestReturnUnusedResources
frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
delegated_->SetFrameData(frame.Pass());
break;
- case 6:
+ case 4:
// Postpone collecting resources for a frame. They should still be there
// the next frame.
layer_tree_host()->SetNeedsCommit();
return;
- case 7:
- // 444 and 999 are no longer in use.
+ case 5:
+ // 444 and 999 are no longer in use. We sent two refs to 999, so we
+ // should get two back.
delegated_->TakeUnusedResourcesForChildCompositor(&resources);
{
- unsigned expected[] = {444, 999};
+ unsigned expected[] = {444, 999, 999};
EXPECT_RESOURCES(expected, resources);
}
EndTest();
@@ -941,11 +934,6 @@ class LayerTreeHostDelegatedTestReusedResources
delegated_->SetFrameData(frame.Pass());
break;
case 2:
- // Retrieve unused resources to the main thread.
- // TODO(danakj): Shouldn't need to commit to get resources.
- layer_tree_host()->SetNeedsCommit();
- return;
- case 3:
// All of the resources are in use.
delegated_->TakeUnusedResourcesForChildCompositor(&resources);
EXPECT_EQ(0u, resources.size());
@@ -953,6 +941,7 @@ class LayerTreeHostDelegatedTestReusedResources
// Keep using 999 but stop using 555 and 444.
frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
AddTextureQuad(frame.get(), 999);
+ AddTransferableResource(frame.get(), 999);
delegated_->SetFrameData(frame.Pass());
// Resource are not immediately released.
@@ -962,19 +951,17 @@ class LayerTreeHostDelegatedTestReusedResources
// Now using 555 and 444 again, but not 999.
frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
AddTextureQuad(frame.get(), 555);
+ AddTransferableResource(frame.get(), 555);
AddTextureQuad(frame.get(), 444);
+ AddTransferableResource(frame.get(), 444);
delegated_->SetFrameData(frame.Pass());
break;
- case 4:
- // Retrieve unused resources to the main thread.
- // TODO(danakj): Shouldn't need to commit to get resources.
- layer_tree_host()->SetNeedsCommit();
- return;
- case 5:
- // The 999 resource is the only unused one.
+ case 3:
+ // The 999 resource is the only unused one. Two references were sent, so
+ // two should be returned.
delegated_->TakeUnusedResourcesForChildCompositor(&resources);
{
- unsigned expected[] = {999};
+ unsigned expected[] = {999, 999};
EXPECT_RESOURCES(expected, resources);
}
EndTest();
@@ -1017,11 +1004,6 @@ class LayerTreeHostDelegatedTestFrameBeforeAck
delegated_->SetFrameData(frame.Pass());
break;
case 2:
- // Retrieve unused resources to the main thread.
- // TODO(danakj): Shouldn't need to commit to get resources.
- layer_tree_host()->SetNeedsCommit();
- return;
- case 3:
// All of the resources are in use.
delegated_->TakeUnusedResourcesForChildCompositor(&resources);
EXPECT_EQ(0u, resources.size());
@@ -1029,6 +1011,7 @@ class LayerTreeHostDelegatedTestFrameBeforeAck
// Keep using 999 but stop using 555 and 444.
frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
AddTextureQuad(frame.get(), 999);
+ AddTransferableResource(frame.get(), 999);
delegated_->SetFrameData(frame.Pass());
// Resource are not immediately released.
@@ -1037,20 +1020,15 @@ class LayerTreeHostDelegatedTestFrameBeforeAck
// The parent compositor (this one) does a commit.
break;
- case 4:
- // Retrieve unused resources to the main thread.
- // TODO(danakj): Shouldn't need to commit to get resources.
- layer_tree_host()->SetNeedsCommit();
- return;
- case 5:
+ case 3:
delegated_->TakeUnusedResourcesForChildCompositor(&resources);
{
unsigned expected[] = {444, 555};
EXPECT_RESOURCES(expected, resources);
}
- // The child compositor sends a frame before receiving an for the
- // second frame. It uses 999, 444, and 555 again.
+ // The child compositor sends a frame referring to resources not in the
+ // frame.
frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
AddTextureQuad(frame.get(), 999);
AddTextureQuad(frame.get(), 555);
@@ -1061,7 +1039,7 @@ class LayerTreeHostDelegatedTestFrameBeforeAck
}
virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
- if (host_impl->active_tree()->source_frame_number() != 5)
+ if (host_impl->active_tree()->source_frame_number() != 3)
return;
LayerImpl* root_impl = host_impl->active_tree()->root_layer();
@@ -1079,7 +1057,7 @@ class LayerTreeHostDelegatedTestFrameBeforeAck
EXPECT_EQ(1u, map.count(999));
EXPECT_EQ(1u, delegated_impl->Resources().size());
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(999));
const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0];
EXPECT_EQ(1u, pass->quad_list.size());
@@ -1125,11 +1103,6 @@ class LayerTreeHostDelegatedTestFrameBeforeTakeResources
delegated_->SetFrameData(frame.Pass());
break;
case 2:
- // Retrieve unused resources to the main thread.
- // TODO(danakj): Shouldn't need to commit to get resources.
- layer_tree_host()->SetNeedsCommit();
- return;
- case 3:
// All of the resources are in use.
delegated_->TakeUnusedResourcesForChildCompositor(&resources);
EXPECT_EQ(0u, resources.size());
@@ -1146,12 +1119,7 @@ class LayerTreeHostDelegatedTestFrameBeforeTakeResources
// The parent compositor (this one) does a commit.
break;
- case 4:
- // Retrieve unused resources to the main thread.
- // TODO(danakj): Shouldn't need to commit to get resources.
- layer_tree_host()->SetNeedsCommit();
- return;
- case 5:
+ case 3:
// The child compositor sends a frame before taking resources back
// from the previous commit. This frame makes use of the resources 555
// and 444, which were just released during commit.
@@ -1172,12 +1140,7 @@ class LayerTreeHostDelegatedTestFrameBeforeTakeResources
EXPECT_RESOURCES(expected, resources);
}
break;
- case 6:
- // Retrieve unused resources to the main thread.
- // TODO(danakj): Shouldn't need to commit to get resources.
- layer_tree_host()->SetNeedsCommit();
- return;
- case 7:
+ case 4:
delegated_->TakeUnusedResourcesForChildCompositor(&resources);
EXPECT_EQ(0u, resources.size());
EndTest();
@@ -1186,7 +1149,7 @@ class LayerTreeHostDelegatedTestFrameBeforeTakeResources
}
virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
- if (host_impl->active_tree()->source_frame_number() != 5)
+ if (host_impl->active_tree()->source_frame_number() != 3)
return;
LayerImpl* root_impl = host_impl->active_tree()->root_layer();
@@ -1205,9 +1168,9 @@ class LayerTreeHostDelegatedTestFrameBeforeTakeResources
EXPECT_EQ(1u, map.count(444));
EXPECT_EQ(3u, delegated_impl->Resources().size());
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second));
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(444)->second));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(999));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(555));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(444));
const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0];
EXPECT_EQ(3u, pass->quad_list.size());
@@ -1256,11 +1219,6 @@ class LayerTreeHostDelegatedTestBadFrame
delegated_->SetFrameData(frame.Pass());
break;
case 2:
- // Retrieve unused resources to the main thread.
- // TODO(danakj): Shouldn't need to commit to get resources.
- layer_tree_host()->SetNeedsCommit();
- return;
- case 3:
// All of the resources are in use.
delegated_->TakeUnusedResourcesForChildCompositor(&resources);
EXPECT_EQ(0u, resources.size());
@@ -1279,12 +1237,7 @@ class LayerTreeHostDelegatedTestBadFrame
// The parent compositor (this one) does a commit.
break;
- case 4:
- // Retrieve unused resources to the main thread.
- // TODO(danakj): Shouldn't need to commit to get resources.
- layer_tree_host()->SetNeedsCommit();
- return;
- case 5:
+ case 3:
// The bad frame's resource is given back to the child compositor.
delegated_->TakeUnusedResourcesForChildCompositor(&resources);
{
@@ -1297,12 +1250,7 @@ class LayerTreeHostDelegatedTestBadFrame
AddTextureQuad(frame.get(), 999);
delegated_->SetFrameData(frame.Pass());
break;
- case 6:
- // Retrieve unused resources to the main thread.
- // TODO(danakj): Shouldn't need to commit to get resources.
- layer_tree_host()->SetNeedsCommit();
- return;
- case 7:
+ case 4:
// The unused 555 from the last good frame is now released.
delegated_->TakeUnusedResourcesForChildCompositor(&resources);
{
@@ -1339,8 +1287,8 @@ class LayerTreeHostDelegatedTestBadFrame
EXPECT_EQ(1u, map.count(555));
EXPECT_EQ(2u, delegated_impl->Resources().size());
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second));
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(999));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(555));
const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0];
EXPECT_EQ(2u, pass->quad_list.size());
@@ -1352,15 +1300,15 @@ class LayerTreeHostDelegatedTestBadFrame
EXPECT_EQ(map.find(555)->second, quad2->resource_id);
break;
}
- case 3: {
+ case 2: {
// We only keep resources from the last valid frame.
EXPECT_EQ(2u, map.size());
EXPECT_EQ(1u, map.count(999));
EXPECT_EQ(1u, map.count(555));
EXPECT_EQ(2u, delegated_impl->Resources().size());
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second));
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(999));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(555));
// The bad frame is dropped though, we still have the frame with 999 and
// 555 in it.
@@ -1374,20 +1322,13 @@ class LayerTreeHostDelegatedTestBadFrame
EXPECT_EQ(map.find(555)->second, quad2->resource_id);
break;
}
- case 5:
- // Resources given to our parent compositor will be returned now, but
- // the DelegatedRendererLayerImpl doesn't know about it until the next
- // commit.
- // TODO(danakj): Shouldn't need a commit to return resources to the
- // DelegatedRendererLayerImpl or to the main thread.
- break;
- case 6: {
+ case 3: {
// We have the new good frame with just 999 in it.
EXPECT_EQ(1u, map.size());
EXPECT_EQ(1u, map.count(999));
EXPECT_EQ(1u, delegated_impl->Resources().size());
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(999));
const RenderPass* pass = delegated_impl->RenderPassesInDrawOrder()[0];
EXPECT_EQ(1u, pass->quad_list.size());
@@ -1455,7 +1396,7 @@ class LayerTreeHostDelegatedTestUnnamedResource
EXPECT_EQ(1u, map.count(555));
EXPECT_EQ(1u, delegated_impl->Resources().size());
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(555));
}
virtual void AfterTest() OVERRIDE {}
@@ -1470,7 +1411,7 @@ class LayerTreeHostDelegatedTestDontLeakResource
PostSetNeedsCommitToMainThread();
}
- virtual void DidCommit() OVERRIDE {
+ virtual void DidCommitAndDrawFrame() OVERRIDE {
scoped_ptr<DelegatedFrameData> frame;
ReturnedResourceArray resources;
@@ -1504,11 +1445,6 @@ class LayerTreeHostDelegatedTestDontLeakResource
delegated_->SetFrameData(frame.Pass());
break;
case 3:
- // The impl side will get back the resource at some point.
- // TODO(piman): The test should work without this.
- layer_tree_host()->SetNeedsCommit();
- break;
- case 4:
// The now unused resource 555 should be returned.
resources.clear();
delegated_->TakeUnusedResourcesForChildCompositor(&resources);
@@ -1538,7 +1474,7 @@ class LayerTreeHostDelegatedTestDontLeakResource
EXPECT_EQ(1u, map.count(555));
EXPECT_EQ(1u, delegated_impl->Resources().size());
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(555));
}
virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
@@ -1577,6 +1513,7 @@ class LayerTreeHostDelegatedTestResourceSentToParent
// it present.
frame = CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
AddTextureQuad(frame.get(), 555);
+ AddTransferableResource(frame.get(), 555);
delegated_->SetFrameData(frame.Pass());
break;
case 3:
@@ -1585,20 +1522,46 @@ class LayerTreeHostDelegatedTestResourceSentToParent
EXPECT_EQ(0u, resources.size());
// The impl side will get back the resource at some point.
- // TODO(danakj): The test should work without this.
- layer_tree_host()->SetNeedsCommit();
+ ImplThreadTaskRunner()->PostTask(FROM_HERE,
+ receive_resource_on_thread_);
break;
- case 4:
- // 999 was returned from the grandparent and could be released.
- delegated_->TakeUnusedResourcesForChildCompositor(&resources);
- {
- unsigned expected[] = {999};
- EXPECT_RESOURCES(expected, resources);
- }
+ }
+ }
- EndTest();
- break;
+ void ReceiveResourceOnThread(LayerTreeHostImpl* host_impl) {
+ LayerImpl* root_impl = host_impl->active_tree()->root_layer();
+ FakeDelegatedRendererLayerImpl* delegated_impl =
+ static_cast<FakeDelegatedRendererLayerImpl*>(root_impl->children()[0]);
+
+ const ResourceProvider::ResourceIdMap& map =
+ host_impl->resource_provider()->GetChildToParentMap(
+ delegated_impl->ChildId());
+
+ // Receive 999 back from the grandparent.
+ CompositorFrameAck ack;
+ output_surface()->ReturnResource(map.find(999)->second, &ack);
+ host_impl->ReclaimResources(&ack);
+ host_impl->OnSwapBuffersComplete();
+
+ // And then it should be released by the DelegatedRendererLayer.
+ MainThreadTaskRunner()->PostTask(
+ FROM_HERE,
+ base::Bind(&LayerTreeHostDelegatedTestResourceSentToParent::
+ DidReceiveResourceOnMainThread,
+ base::Unretained(this)));
+ }
+
+ void DidReceiveResourceOnMainThread() {
+ ReturnedResourceArray resources;
+
+ // 999 was returned from the grandparent and could be released.
+ delegated_->TakeUnusedResourcesForChildCompositor(&resources);
+ {
+ unsigned expected[] = {999};
+ EXPECT_RESOURCES(expected, resources);
}
+
+ EndTest();
}
virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
@@ -1620,8 +1583,8 @@ class LayerTreeHostDelegatedTestResourceSentToParent
EXPECT_EQ(1u, map.count(555));
EXPECT_EQ(2u, delegated_impl->Resources().size());
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second));
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(999));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(555));
// The 999 resource will be sent to a grandparent compositor.
break;
@@ -1633,13 +1596,13 @@ class LayerTreeHostDelegatedTestResourceSentToParent
// 999 is in the parent, so not held by delegated renderer layer.
EXPECT_EQ(1u, delegated_impl->Resources().size());
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(555));
- // Receive 999 back from the grandparent.
- CompositorFrameAck ack;
- output_surface()->ReturnResource(map.find(999)->second, &ack);
- host_impl->ReclaimResources(&ack);
- host_impl->OnSwapBuffersComplete();
+ receive_resource_on_thread_ =
+ base::Bind(&LayerTreeHostDelegatedTestResourceSentToParent::
+ ReceiveResourceOnThread,
+ base::Unretained(this),
+ host_impl);
break;
}
case 3:
@@ -1655,7 +1618,7 @@ class LayerTreeHostDelegatedTestResourceSentToParent
virtual void AfterTest() OVERRIDE {}
- TransferableResource resource_in_grandparent;
+ base::Closure receive_resource_on_thread_;
};
SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F(
@@ -1753,16 +1716,16 @@ class LayerTreeHostDelegatedTestCommitWithoutTake
EXPECT_EQ(1u, map.count(444));
EXPECT_EQ(3u, delegated_impl->Resources().size());
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second));
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(444)->second));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(999));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(555));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(444));
break;
case 2:
EXPECT_EQ(1u, map.size());
EXPECT_EQ(1u, map.count(555));
EXPECT_EQ(1u, delegated_impl->Resources().size());
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(555));
break;
case 3:
EXPECT_EQ(2u, map.size());
@@ -1770,8 +1733,8 @@ class LayerTreeHostDelegatedTestCommitWithoutTake
EXPECT_EQ(1u, map.count(555));
EXPECT_EQ(2u, delegated_impl->Resources().size());
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(999)->second));
- EXPECT_EQ(1u, delegated_impl->Resources().count(map.find(555)->second));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(999));
+ EXPECT_EQ(1u, delegated_impl->Resources().count(555));
}
}
« no previous file with comments | « cc/test/layer_tree_test.h ('k') | cc/trees/single_thread_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698