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

Unified Diff: cc/trees/layer_tree_host_unittest.cc

Issue 23478004: UI resource are evicted when LTH is set to not visible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CanDraw returns false when UI resources are evicted Created 7 years, 4 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/trees/layer_tree_host_impl_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 73033a19b4866e75645d5cf21735c3bcd0ab92b8..9ac59cf3548eb0d4a21b24ca4050f41a5c363c83 100644
--- a/cc/trees/layer_tree_host_unittest.cc
+++ b/cc/trees/layer_tree_host_unittest.cc
@@ -4469,6 +4469,139 @@ class LayerTreeHostTestAbortEvictedTextures : public LayerTreeHostTest {
// Commits can only be aborted when using the thread proxy.
MULTI_THREAD_TEST_F(LayerTreeHostTestAbortEvictedTextures);
+class TestWebGraphicsContext3DWithTextureCounts
+ : public TestWebGraphicsContext3D {
+ public:
+ static scoped_ptr<TestWebGraphicsContext3DWithTextureCounts> Create() {
+ return make_scoped_ptr(new TestWebGraphicsContext3DWithTextureCounts());
+ }
+
+ virtual ~TestWebGraphicsContext3DWithTextureCounts() {}
+
+ virtual WebKit::WebGLId createTexture() OVERRIDE {
+ ++num_create_texture_calls_;
+ return TestWebGraphicsContext3D::createTexture();
+ }
+
+ virtual void deleteTexture(WebKit::WebGLId texture_id) OVERRIDE {
+ ++num_delete_texture_calls_;
+ TestWebGraphicsContext3D::deleteTexture(texture_id);
+ }
+
+ int num_create_texture_calls_;
+ int num_delete_texture_calls_;
+
+ private:
+ TestWebGraphicsContext3DWithTextureCounts()
+ : TestWebGraphicsContext3D(),
+ num_create_texture_calls_(0),
+ num_delete_texture_calls_(0) {}
+};
+
+// UI resources should be evicted when visibility is set to false and recreated
+// when visibility is set to true.
+class LayerTreeHostEvictUIResourceTest : public LayerTreeHostTest {
+ public:
+ LayerTreeHostEvictUIResourceTest()
+ : LayerTreeHostTest(), num_commits_(0), context3d_(NULL) {}
+
+ virtual scoped_ptr<TestWebGraphicsContext3DWithTextureCounts>
+ CreateContext3d() {
+ return TestWebGraphicsContext3DWithTextureCounts::Create();
+ }
+
+ virtual scoped_ptr<OutputSurface> CreateOutputSurface(
+ bool fallback) OVERRIDE {
+ scoped_ptr<TestWebGraphicsContext3DWithTextureCounts> context3d =
+ CreateContext3d();
+ context3d_ = context3d.get();
+ return FakeOutputSurface::Create3d(
+ context3d.PassAs<TestWebGraphicsContext3D>()).PassAs<OutputSurface>();
+ }
+
+ virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
+
+ virtual void SetupTree() OVERRIDE {
+ root_ = Layer::Create();
+ bool paint_scrollbar = true;
+ bool has_thumb = false;
+ scrollbar_layer_ = FakePaintedScrollbarLayer::Create(
+ paint_scrollbar, has_thumb, root_->id());
+
+ root_->AddChild(scrollbar_layer_);
+ layer_tree_host()->SetRootLayer(root_);
+ LayerTreeHostTest::SetupTree();
+ }
+
+ virtual void DidCommit() OVERRIDE {
+ int frame = num_commits_;
+ scoped_ptr<base::AutoReset<bool> > ignore;
+ switch (frame) {
+ case 1:
+ PostSetNeedsCommitToMainThread();
+ break;
+ case 2:
+ PostSetVisibleToMainThread(false);
+ PostSetNeedsRedrawToMainThread();
+ PostSetVisibleToMainThread(true);
+ PostSetNeedsCommitToMainThread();
+ break;
+ case 3:
+ PostSetNeedsCommitToMainThread();
+ break;
+ case 4:
+ EndTest();
+ break;
+ }
+ }
+
+ virtual void PerformTest(LayerTreeHostImpl* impl) {
+ int frame = num_commits_;
+ switch (frame) {
+ case 1:
+ // Expect one texture has been created. None has been deleted.
+ EXPECT_EQ(context3d_->num_create_texture_calls_, 1);
+ EXPECT_EQ(context3d_->num_delete_texture_calls_, 0);
+ break;
+ case 2:
+ // Expect two textures has been created. One has been deleted.
+ EXPECT_EQ(context3d_->num_create_texture_calls_, 2);
+ EXPECT_EQ(context3d_->num_delete_texture_calls_, 1);
+ break;
+ case 3:
+ // Visibility has been changed once. So resource was evicted in LTHI
+ // and recreated in LTH. Expect four textures has been created. Three
+ // has been deleted.
+ EXPECT_EQ(context3d_->num_create_texture_calls_, 4);
+ EXPECT_EQ(context3d_->num_delete_texture_calls_, 3);
+ break;
+ default:
+ break;
+ }
+ }
+
+ virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
+ ++num_commits_;
+ if (!layer_tree_host()->settings().impl_side_painting)
+ PerformTest(impl);
+ }
+
+ virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
+ if (layer_tree_host()->settings().impl_side_painting)
+ PerformTest(impl);
+ }
+
+ virtual void AfterTest() OVERRIDE {}
+
+ protected:
+ scoped_refptr<Layer> root_;
+ scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_;
+ int num_commits_;
+ TestWebGraphicsContext3DWithTextureCounts* context3d_;
+};
+
+SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostEvictUIResourceTest);
+
} // namespace
} // namespace cc
« no previous file with comments | « cc/trees/layer_tree_host_impl_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698