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

Side by Side Diff: cc/trees/layer_tree_host_unittest_context.cc

Issue 132163004: Remove WebGraphicsContext3D getter from cc::ContextProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "cc/layers/content_layer.h" 8 #include "cc/layers/content_layer.h"
9 #include "cc/layers/delegated_frame_provider.h" 9 #include "cc/layers/delegated_frame_provider.h"
10 #include "cc/layers/delegated_frame_resource_collection.h" 10 #include "cc/layers/delegated_frame_resource_collection.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 void LoseContext() { 70 void LoseContext() {
71 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 71 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
72 GL_INNOCENT_CONTEXT_RESET_ARB); 72 GL_INNOCENT_CONTEXT_RESET_ARB);
73 context3d_ = NULL; 73 context3d_ = NULL;
74 } 74 }
75 75
76 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() { 76 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() {
77 return TestWebGraphicsContext3D::Create(); 77 return TestWebGraphicsContext3D::Create();
78 } 78 }
79 79
80 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) 80 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurfaceForTest(
81 OVERRIDE { 81 bool fallback) OVERRIDE {
82 if (times_to_fail_create_) { 82 if (times_to_fail_create_) {
83 --times_to_fail_create_; 83 --times_to_fail_create_;
84 ExpectCreateToFail(); 84 ExpectCreateToFail();
85 return scoped_ptr<OutputSurface>(); 85 return scoped_ptr<FakeOutputSurface>();
86 } 86 }
87 87
88 scoped_ptr<TestWebGraphicsContext3D> context3d = CreateContext3d(); 88 scoped_ptr<TestWebGraphicsContext3D> context3d = CreateContext3d();
89 context3d_ = context3d.get(); 89 context3d_ = context3d.get();
90 90
91 if (context_should_support_io_surface_) { 91 if (context_should_support_io_surface_) {
92 context3d_->set_have_extension_io_surface(true); 92 context3d_->set_have_extension_io_surface(true);
93 context3d_->set_have_extension_egl_image(true); 93 context3d_->set_have_extension_egl_image(true);
94 } 94 }
95 95
96 if (delegating_renderer()) { 96 if (delegating_renderer())
97 return FakeOutputSurface::CreateDelegating3d(context3d.Pass()) 97 return FakeOutputSurface::CreateDelegating3d(context3d.Pass());
98 .PassAs<OutputSurface>(); 98 else
99 } 99 return FakeOutputSurface::Create3d(context3d.Pass());
100 return FakeOutputSurface::Create3d(context3d.Pass())
101 .PassAs<OutputSurface>();
102 } 100 }
103 101
104 scoped_ptr<TestWebGraphicsContext3D> CreateOffscreenContext3d() { 102 scoped_ptr<TestWebGraphicsContext3D> CreateOffscreenContext3d() {
105 if (!context3d_) 103 if (!context3d_)
106 return scoped_ptr<TestWebGraphicsContext3D>(); 104 return scoped_ptr<TestWebGraphicsContext3D>();
107 105
108 ++times_offscreen_created_; 106 ++times_offscreen_created_;
109 107
110 if (times_to_fail_create_offscreen_) { 108 if (times_to_fail_create_offscreen_) {
111 --times_to_fail_create_offscreen_; 109 --times_to_fail_create_offscreen_;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 162
165 virtual void DidFailToInitializeOutputSurface() OVERRIDE { 163 virtual void DidFailToInitializeOutputSurface() OVERRIDE {
166 ++times_create_failed_; 164 ++times_create_failed_;
167 } 165 }
168 166
169 virtual void TearDown() OVERRIDE { 167 virtual void TearDown() OVERRIDE {
170 LayerTreeTest::TearDown(); 168 LayerTreeTest::TearDown();
171 EXPECT_EQ(times_to_expect_create_failed_, times_create_failed_); 169 EXPECT_EQ(times_to_expect_create_failed_, times_create_failed_);
172 } 170 }
173 171
174 void ExpectCreateToFail() { 172 void ExpectCreateToFail() { ++times_to_expect_create_failed_; }
175 ++times_to_expect_create_failed_;
176 }
177 173
178 protected: 174 protected:
179 TestWebGraphicsContext3D* context3d_; 175 TestWebGraphicsContext3D* context3d_;
180 int times_to_fail_create_; 176 int times_to_fail_create_;
181 int times_to_lose_during_commit_; 177 int times_to_lose_during_commit_;
182 int times_to_lose_during_draw_; 178 int times_to_lose_during_draw_;
183 int times_to_fail_recreate_; 179 int times_to_fail_recreate_;
184 int times_to_fail_create_offscreen_; 180 int times_to_fail_create_offscreen_;
185 int times_to_fail_recreate_offscreen_; 181 int times_to_fail_recreate_offscreen_;
186 int times_to_expect_create_failed_; 182 int times_to_expect_create_failed_;
(...skipping 10 matching lines...) Expand all
197 : public LayerTreeHostContextTest { 193 : public LayerTreeHostContextTest {
198 public: 194 public:
199 LayerTreeHostContextTestLostContextSucceeds() 195 LayerTreeHostContextTestLostContextSucceeds()
200 : LayerTreeHostContextTest(), 196 : LayerTreeHostContextTest(),
201 test_case_(0), 197 test_case_(0),
202 num_losses_(0), 198 num_losses_(0),
203 num_losses_last_test_case_(-1), 199 num_losses_last_test_case_(-1),
204 recovered_context_(true), 200 recovered_context_(true),
205 first_initialized_(false) {} 201 first_initialized_(false) {}
206 202
207 virtual void BeginTest() OVERRIDE { 203 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
208 PostSetNeedsCommitToMainThread();
209 }
210 204
211 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE { 205 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE {
212 EXPECT_TRUE(succeeded); 206 EXPECT_TRUE(succeeded);
213 207
214 if (first_initialized_) 208 if (first_initialized_)
215 ++num_losses_; 209 ++num_losses_;
216 else 210 else
217 first_initialized_ = true; 211 first_initialized_ = true;
218 212
219 recovered_context_ = true; 213 recovered_context_ = true;
(...skipping 19 matching lines...) Expand all
239 } 233 }
240 234
241 virtual void InvalidateAndSetNeedsCommit() { 235 virtual void InvalidateAndSetNeedsCommit() {
242 // Cause damage so we try to draw. 236 // Cause damage so we try to draw.
243 layer_tree_host()->root_layer()->SetNeedsDisplay(); 237 layer_tree_host()->root_layer()->SetNeedsDisplay();
244 layer_tree_host()->SetNeedsCommit(); 238 layer_tree_host()->SetNeedsCommit();
245 } 239 }
246 240
247 bool NextTestCase() { 241 bool NextTestCase() {
248 static const TestCase kTests[] = { 242 static const TestCase kTests[] = {
249 // Losing the context and failing to recreate it (or losing it again 243 // Losing the context and failing to recreate it (or losing it again
250 // immediately) a small number of times should succeed. 244 // immediately) a small number of times should succeed.
251 { 1, // times_to_lose_during_commit 245 {1, // times_to_lose_during_commit
252 0, // times_to_lose_during_draw 246 0, // times_to_lose_during_draw
253 0, // times_to_fail_recreate 247 0, // times_to_fail_recreate
254 0, // times_to_fail_recreate_offscreen 248 0, // times_to_fail_recreate_offscreen
255 false, // fallback_context_works 249 false, // fallback_context_works
256 }, 250 },
257 { 0, // times_to_lose_during_commit 251 {0, // times_to_lose_during_commit
258 1, // times_to_lose_during_draw 252 1, // times_to_lose_during_draw
259 0, // times_to_fail_recreate 253 0, // times_to_fail_recreate
260 0, // times_to_fail_recreate_offscreen 254 0, // times_to_fail_recreate_offscreen
261 false, // fallback_context_works 255 false, // fallback_context_works
262 }, 256 },
263 { 1, // times_to_lose_during_commit 257 {1, // times_to_lose_during_commit
264 0, // times_to_lose_during_draw 258 0, // times_to_lose_during_draw
265 3, // times_to_fail_recreate 259 3, // times_to_fail_recreate
266 0, // times_to_fail_recreate_offscreen 260 0, // times_to_fail_recreate_offscreen
267 false, // fallback_context_works 261 false, // fallback_context_works
268 }, 262 },
269 { 0, // times_to_lose_during_commit 263 {0, // times_to_lose_during_commit
270 1, // times_to_lose_during_draw 264 1, // times_to_lose_during_draw
271 3, // times_to_fail_recreate 265 3, // times_to_fail_recreate
272 0, // times_to_fail_recreate_offscreen 266 0, // times_to_fail_recreate_offscreen
273 false, // fallback_context_works 267 false, // fallback_context_works
274 }, 268 },
275 { 1, // times_to_lose_during_commit 269 {1, // times_to_lose_during_commit
276 0, // times_to_lose_during_draw 270 0, // times_to_lose_during_draw
277 0, // times_to_fail_recreate 271 0, // times_to_fail_recreate
278 3, // times_to_fail_recreate_offscreen 272 3, // times_to_fail_recreate_offscreen
279 false, // fallback_context_works 273 false, // fallback_context_works
280 }, 274 },
281 { 0, // times_to_lose_during_commit 275 {0, // times_to_lose_during_commit
282 1, // times_to_lose_during_draw 276 1, // times_to_lose_during_draw
283 0, // times_to_fail_recreate 277 0, // times_to_fail_recreate
284 3, // times_to_fail_recreate_offscreen 278 3, // times_to_fail_recreate_offscreen
285 false, // fallback_context_works 279 false, // fallback_context_works
286 }, 280 },
287 // Losing the context and recreating it any number of times should 281 // Losing the context and recreating it any number of times should
288 // succeed. 282 // succeed.
289 { 10, // times_to_lose_during_commit 283 {10, // times_to_lose_during_commit
290 0, // times_to_lose_during_draw 284 0, // times_to_lose_during_draw
291 0, // times_to_fail_recreate 285 0, // times_to_fail_recreate
292 0, // times_to_fail_recreate_offscreen 286 0, // times_to_fail_recreate_offscreen
293 false, // fallback_context_works 287 false, // fallback_context_works
294 }, 288 },
295 { 0, // times_to_lose_during_commit 289 {0, // times_to_lose_during_commit
296 10, // times_to_lose_during_draw 290 10, // times_to_lose_during_draw
297 0, // times_to_fail_recreate 291 0, // times_to_fail_recreate
298 0, // times_to_fail_recreate_offscreen 292 0, // times_to_fail_recreate_offscreen
299 false, // fallback_context_works 293 false, // fallback_context_works
300 }, 294 },
301 // Losing the context, failing to reinitialize it, and making a fallback 295 // Losing the context, failing to reinitialize it, and making a fallback
302 // context should work. 296 // context should work.
303 { 0, // times_to_lose_during_commit 297 {0, // times_to_lose_during_commit
304 1, // times_to_lose_during_draw 298 1, // times_to_lose_during_draw
305 0, // times_to_fail_recreate 299 0, // times_to_fail_recreate
306 0, // times_to_fail_recreate_offscreen 300 0, // times_to_fail_recreate_offscreen
307 true, // fallback_context_works 301 true, // fallback_context_works
308 }, 302 }, };
309 };
310 303
311 if (test_case_ >= arraysize(kTests)) 304 if (test_case_ >= arraysize(kTests))
312 return false; 305 return false;
313 // Make sure that we lost our context at least once in the last test run so 306 // Make sure that we lost our context at least once in the last test run so
314 // the test did something. 307 // the test did something.
315 EXPECT_GT(num_losses_, num_losses_last_test_case_); 308 EXPECT_GT(num_losses_, num_losses_last_test_case_);
316 num_losses_last_test_case_ = num_losses_; 309 num_losses_last_test_case_ = num_losses_;
317 310
318 times_to_lose_during_commit_ = 311 times_to_lose_during_commit_ =
319 kTests[test_case_].times_to_lose_during_commit; 312 kTests[test_case_].times_to_lose_during_commit;
320 times_to_lose_during_draw_ = 313 times_to_lose_during_draw_ = kTests[test_case_].times_to_lose_during_draw;
321 kTests[test_case_].times_to_lose_during_draw;
322 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate; 314 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate;
323 times_to_fail_recreate_offscreen_ = 315 times_to_fail_recreate_offscreen_ =
324 kTests[test_case_].times_to_fail_recreate_offscreen; 316 kTests[test_case_].times_to_fail_recreate_offscreen;
325 fallback_context_works_ = kTests[test_case_].fallback_context_works; 317 fallback_context_works_ = kTests[test_case_].fallback_context_works;
326 ++test_case_; 318 ++test_case_;
327 return true; 319 return true;
328 } 320 }
329 321
330 struct TestCase { 322 struct TestCase {
331 int times_to_lose_during_commit; 323 int times_to_lose_during_commit;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>( 411 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>(
420 host_impl->active_tree()->root_layer()->children()[0]); 412 host_impl->active_tree()->root_layer()->children()[0]);
421 // Even though the context was lost, we should have a resource. The 413 // Even though the context was lost, we should have a resource. The
422 // TestWebGraphicsContext3D ensures that this resource is created with 414 // TestWebGraphicsContext3D ensures that this resource is created with
423 // the active context. 415 // the active context.
424 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); 416 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0));
425 417
426 ContextProvider* contexts = host_impl->offscreen_context_provider(); 418 ContextProvider* contexts = host_impl->offscreen_context_provider();
427 if (use_surface_) { 419 if (use_surface_) {
428 ASSERT_TRUE(contexts); 420 ASSERT_TRUE(contexts);
429 EXPECT_TRUE(contexts->Context3d()); 421 EXPECT_TRUE(contexts->ContextGL());
430 // TODO(danakj): Make a fake GrContext. 422 // TODO(danakj): Make a fake GrContext.
431 // EXPECT_TRUE(contexts->GrContext()); 423 // EXPECT_TRUE(contexts->GrContext());
432 } else { 424 } else {
433 EXPECT_FALSE(contexts); 425 EXPECT_FALSE(contexts);
434 } 426 }
435 } 427 }
436 428
437 virtual void AfterTest() OVERRIDE { 429 virtual void AfterTest() OVERRIDE {
438 LayerTreeHostContextTestLostContextSucceeds::AfterTest(); 430 LayerTreeHostContextTestLostContextSucceeds::AfterTest();
439 if (use_surface_) { 431 if (use_surface_) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 scoped_refptr<Layer> root_; 622 scoped_refptr<Layer> root_;
631 scoped_refptr<ContentLayer> content_; 623 scoped_refptr<ContentLayer> content_;
632 }; 624 };
633 625
634 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestOffscreenContextFails); 626 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestOffscreenContextFails);
635 627
636 class LayerTreeHostContextTestLostContextFails 628 class LayerTreeHostContextTestLostContextFails
637 : public LayerTreeHostContextTest { 629 : public LayerTreeHostContextTest {
638 public: 630 public:
639 LayerTreeHostContextTestLostContextFails() 631 LayerTreeHostContextTestLostContextFails()
640 : LayerTreeHostContextTest(), 632 : LayerTreeHostContextTest(), num_commits_(0), first_initialized_(false) {
641 num_commits_(0),
642 first_initialized_(false) {
643 times_to_lose_during_commit_ = 1; 633 times_to_lose_during_commit_ = 1;
644 } 634 }
645 635
646 virtual void BeginTest() OVERRIDE { 636 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
647 PostSetNeedsCommitToMainThread();
648 }
649 637
650 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE { 638 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE {
651 if (first_initialized_) { 639 if (first_initialized_) {
652 EXPECT_FALSE(succeeded); 640 EXPECT_FALSE(succeeded);
653 EndTest(); 641 EndTest();
654 } else { 642 } else {
655 first_initialized_ = true; 643 first_initialized_ = true;
656 } 644 }
657 } 645 }
658 646
(...skipping 30 matching lines...) Expand all
689 layer_(FakeContentLayer::Create(&client_)), 677 layer_(FakeContentLayer::Create(&client_)),
690 impl_host_(0), 678 impl_host_(0),
691 num_commits_(0) {} 679 num_commits_(0) {}
692 680
693 virtual void SetupTree() OVERRIDE { 681 virtual void SetupTree() OVERRIDE {
694 layer_->SetBounds(gfx::Size(10, 20)); 682 layer_->SetBounds(gfx::Size(10, 20));
695 layer_tree_host()->SetRootLayer(layer_); 683 layer_tree_host()->SetRootLayer(layer_);
696 LayerTreeHostContextTest::SetupTree(); 684 LayerTreeHostContextTest::SetupTree();
697 } 685 }
698 686
699 virtual void BeginTest() OVERRIDE { 687 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
700 PostSetNeedsCommitToMainThread();
701 }
702 688
703 void PostEvictTextures() { 689 void PostEvictTextures() {
704 if (HasImplThread()) { 690 if (HasImplThread()) {
705 ImplThreadTaskRunner()->PostTask( 691 ImplThreadTaskRunner()->PostTask(
706 FROM_HERE, 692 FROM_HERE,
707 base::Bind( 693 base::Bind(&LayerTreeHostContextTestLostContextAndEvictTextures::
708 &LayerTreeHostContextTestLostContextAndEvictTextures:: 694 EvictTexturesOnImplThread,
709 EvictTexturesOnImplThread, 695 base::Unretained(this)));
710 base::Unretained(this)));
711 } else { 696 } else {
712 DebugScopedSetImplThread impl(proxy()); 697 DebugScopedSetImplThread impl(proxy());
713 EvictTexturesOnImplThread(); 698 EvictTexturesOnImplThread();
714 } 699 }
715 } 700 }
716 701
717 void EvictTexturesOnImplThread() { 702 void EvictTexturesOnImplThread() {
718 impl_host_->EvictTexturesForTesting(); 703 impl_host_->EvictTexturesForTesting();
719 if (lose_after_evict_) 704 if (lose_after_evict_)
720 LoseContext(); 705 LoseContext();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 FakeContentLayer::Create(&client_); 830 FakeContentLayer::Create(&client_);
846 child->SetPosition(gfx::PointF(i, 0.f)); 831 child->SetPosition(gfx::PointF(i, 0.f));
847 child->SetBounds(gfx::Size(1, 1)); 832 child->SetBounds(gfx::Size(1, 1));
848 parent_->AddChild(child); 833 parent_->AddChild(child);
849 } 834 }
850 835
851 layer_tree_host()->SetRootLayer(parent_); 836 layer_tree_host()->SetRootLayer(parent_);
852 LayerTreeHostContextTest::SetupTree(); 837 LayerTreeHostContextTest::SetupTree();
853 } 838 }
854 839
855 virtual void BeginTest() OVERRIDE { 840 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
856 PostSetNeedsCommitToMainThread();
857 }
858 841
859 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 842 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
860 EXPECT_EQ(0, times_to_lose_on_end_query_); 843 EXPECT_EQ(0, times_to_lose_on_end_query_);
861 EndTest(); 844 EndTest();
862 } 845 }
863 846
864 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE { 847 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE {
865 EXPECT_TRUE(succeeded); 848 EXPECT_TRUE(succeeded);
866 } 849 }
867 850
868 virtual void AfterTest() OVERRIDE { 851 virtual void AfterTest() OVERRIDE {
869 EXPECT_EQ(0, times_to_lose_on_end_query_); 852 EXPECT_EQ(0, times_to_lose_on_end_query_);
870 } 853 }
871 854
872 private: 855 private:
873 FakeContentLayerClient client_; 856 FakeContentLayerClient client_;
874 scoped_refptr<FakeContentLayer> parent_; 857 scoped_refptr<FakeContentLayer> parent_;
875 int num_children_; 858 int num_children_;
876 int times_to_lose_on_end_query_; 859 int times_to_lose_on_end_query_;
877 }; 860 };
878 861
879 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( 862 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F(
880 LayerTreeHostContextTestLostContextWhileUpdatingResources); 863 LayerTreeHostContextTestLostContextWhileUpdatingResources);
881 864
882 class LayerTreeHostContextTestLayersNotified 865 class LayerTreeHostContextTestLayersNotified : public LayerTreeHostContextTest {
883 : public LayerTreeHostContextTest {
884 public: 866 public:
885 LayerTreeHostContextTestLayersNotified() 867 LayerTreeHostContextTestLayersNotified()
886 : LayerTreeHostContextTest(), 868 : LayerTreeHostContextTest(), num_commits_(0) {}
887 num_commits_(0) {}
888 869
889 virtual void SetupTree() OVERRIDE { 870 virtual void SetupTree() OVERRIDE {
890 root_ = FakeContentLayer::Create(&client_); 871 root_ = FakeContentLayer::Create(&client_);
891 child_ = FakeContentLayer::Create(&client_); 872 child_ = FakeContentLayer::Create(&client_);
892 grandchild_ = FakeContentLayer::Create(&client_); 873 grandchild_ = FakeContentLayer::Create(&client_);
893 874
894 root_->AddChild(child_); 875 root_->AddChild(child_);
895 child_->AddChild(grandchild_); 876 child_->AddChild(grandchild_);
896 877
897 layer_tree_host()->SetRootLayer(root_); 878 layer_tree_host()->SetRootLayer(root_);
898 LayerTreeHostContextTest::SetupTree(); 879 LayerTreeHostContextTest::SetupTree();
899 } 880 }
900 881
901 virtual void BeginTest() OVERRIDE { 882 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
902 PostSetNeedsCommitToMainThread();
903 }
904 883
905 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 884 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
906 LayerTreeHostContextTest::DidActivateTreeOnThread(host_impl); 885 LayerTreeHostContextTest::DidActivateTreeOnThread(host_impl);
907 886
908 FakeContentLayerImpl* root = static_cast<FakeContentLayerImpl*>( 887 FakeContentLayerImpl* root = static_cast<FakeContentLayerImpl*>(
909 host_impl->active_tree()->root_layer()); 888 host_impl->active_tree()->root_layer());
910 FakeContentLayerImpl* child = static_cast<FakeContentLayerImpl*>( 889 FakeContentLayerImpl* child =
911 root->children()[0]); 890 static_cast<FakeContentLayerImpl*>(root->children()[0]);
912 FakeContentLayerImpl* grandchild = static_cast<FakeContentLayerImpl*>( 891 FakeContentLayerImpl* grandchild =
913 child->children()[0]); 892 static_cast<FakeContentLayerImpl*>(child->children()[0]);
914 893
915 ++num_commits_; 894 ++num_commits_;
916 switch (num_commits_) { 895 switch (num_commits_) {
917 case 1: 896 case 1:
918 EXPECT_EQ(0u, root->lost_output_surface_count()); 897 EXPECT_EQ(0u, root->lost_output_surface_count());
919 EXPECT_EQ(0u, child->lost_output_surface_count()); 898 EXPECT_EQ(0u, child->lost_output_surface_count());
920 EXPECT_EQ(0u, grandchild->lost_output_surface_count()); 899 EXPECT_EQ(0u, grandchild->lost_output_surface_count());
921 // Lose the context and struggle to recreate it. 900 // Lose the context and struggle to recreate it.
922 LoseContext(); 901 LoseContext();
923 times_to_fail_create_ = 1; 902 times_to_fail_create_ = 1;
(...skipping 18 matching lines...) Expand all
942 scoped_refptr<FakeContentLayer> root_; 921 scoped_refptr<FakeContentLayer> root_;
943 scoped_refptr<FakeContentLayer> child_; 922 scoped_refptr<FakeContentLayer> child_;
944 scoped_refptr<FakeContentLayer> grandchild_; 923 scoped_refptr<FakeContentLayer> grandchild_;
945 }; 924 };
946 925
947 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLayersNotified); 926 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLayersNotified);
948 927
949 class LayerTreeHostContextTestDontUseLostResources 928 class LayerTreeHostContextTestDontUseLostResources
950 : public LayerTreeHostContextTest { 929 : public LayerTreeHostContextTest {
951 public: 930 public:
952 LayerTreeHostContextTestDontUseLostResources() 931 LayerTreeHostContextTestDontUseLostResources() : lost_context_(false) {
953 : lost_context_(false) {
954 context_should_support_io_surface_ = true; 932 context_should_support_io_surface_ = true;
955 933
956 child_output_surface_ = FakeOutputSurface::Create3d(); 934 child_output_surface_ = FakeOutputSurface::Create3d();
957 child_output_surface_->BindToClient(&output_surface_client_); 935 child_output_surface_->BindToClient(&output_surface_client_);
958 child_resource_provider_ = 936 child_resource_provider_ = ResourceProvider::Create(
959 ResourceProvider::Create(child_output_surface_.get(), 937 child_output_surface_.get(), NULL, 0, false, 1);
960 NULL,
961 0,
962 false,
963 1);
964 } 938 }
965 939
966 static void EmptyReleaseCallback(unsigned sync_point, bool lost) {} 940 static void EmptyReleaseCallback(unsigned sync_point, bool lost) {}
967 941
968 virtual void SetupTree() OVERRIDE { 942 virtual void SetupTree() OVERRIDE {
969 blink::WebGraphicsContext3D* context3d = 943 gpu::gles2::GLES2Interface* gl =
970 child_output_surface_->context_provider()->Context3d(); 944 child_output_surface_->context_provider()->ContextGL();
971 945
972 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 946 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
973 947
974 scoped_ptr<TestRenderPass> pass_for_quad = TestRenderPass::Create(); 948 scoped_ptr<TestRenderPass> pass_for_quad = TestRenderPass::Create();
975 pass_for_quad->SetNew( 949 pass_for_quad->SetNew(
976 // AppendOneOfEveryQuadType() makes a RenderPass quad with this id. 950 // AppendOneOfEveryQuadType() makes a RenderPass quad with this id.
977 RenderPass::Id(2, 1), 951 RenderPass::Id(2, 1),
978 gfx::Rect(0, 0, 10, 10), 952 gfx::Rect(0, 0, 10, 10),
979 gfx::Rect(0, 0, 10, 10), 953 gfx::Rect(0, 0, 10, 10),
980 gfx::Transform()); 954 gfx::Transform());
(...skipping 16 matching lines...) Expand all
997 ResourceProvider::ResourceId resource = 971 ResourceProvider::ResourceId resource =
998 child_resource_provider_->CreateResource( 972 child_resource_provider_->CreateResource(
999 gfx::Size(4, 4), 973 gfx::Size(4, 4),
1000 GL_CLAMP_TO_EDGE, 974 GL_CLAMP_TO_EDGE,
1001 ResourceProvider::TextureUsageAny, 975 ResourceProvider::TextureUsageAny,
1002 RGBA_8888); 976 RGBA_8888);
1003 ResourceProvider::ScopedWriteLockGL lock(child_resource_provider_.get(), 977 ResourceProvider::ScopedWriteLockGL lock(child_resource_provider_.get(),
1004 resource); 978 resource);
1005 979
1006 gpu::Mailbox mailbox; 980 gpu::Mailbox mailbox;
1007 context3d->genMailboxCHROMIUM(mailbox.name); 981 gl->GenMailboxCHROMIUM(mailbox.name);
1008 unsigned sync_point = context3d->insertSyncPoint(); 982 GLuint sync_point = gl->InsertSyncPointCHROMIUM();
1009 983
1010 scoped_refptr<Layer> root = Layer::Create(); 984 scoped_refptr<Layer> root = Layer::Create();
1011 root->SetBounds(gfx::Size(10, 10)); 985 root->SetBounds(gfx::Size(10, 10));
1012 root->SetAnchorPoint(gfx::PointF()); 986 root->SetAnchorPoint(gfx::PointF());
1013 root->SetIsDrawable(true); 987 root->SetIsDrawable(true);
1014 988
1015 scoped_refptr<FakeDelegatedRendererLayer> delegated = 989 scoped_refptr<FakeDelegatedRendererLayer> delegated =
1016 FakeDelegatedRendererLayer::Create(delegated_frame_provider_.get()); 990 FakeDelegatedRendererLayer::Create(delegated_frame_provider_.get());
1017 delegated->SetBounds(gfx::Size(10, 10)); 991 delegated->SetBounds(gfx::Size(10, 10));
1018 delegated->SetAnchorPoint(gfx::PointF()); 992 delegated->SetAnchorPoint(gfx::PointF());
1019 delegated->SetIsDrawable(true); 993 delegated->SetIsDrawable(true);
1020 root->AddChild(delegated); 994 root->AddChild(delegated);
1021 995
1022 scoped_refptr<ContentLayer> content = ContentLayer::Create(&client_); 996 scoped_refptr<ContentLayer> content = ContentLayer::Create(&client_);
1023 content->SetBounds(gfx::Size(10, 10)); 997 content->SetBounds(gfx::Size(10, 10));
1024 content->SetAnchorPoint(gfx::PointF()); 998 content->SetAnchorPoint(gfx::PointF());
1025 content->SetIsDrawable(true); 999 content->SetIsDrawable(true);
1026 root->AddChild(content); 1000 root->AddChild(content);
1027 1001
1028 scoped_refptr<TextureLayer> texture = TextureLayer::CreateForMailbox(NULL); 1002 scoped_refptr<TextureLayer> texture = TextureLayer::CreateForMailbox(NULL);
1029 texture->SetBounds(gfx::Size(10, 10)); 1003 texture->SetBounds(gfx::Size(10, 10));
1030 texture->SetAnchorPoint(gfx::PointF()); 1004 texture->SetAnchorPoint(gfx::PointF());
1031 texture->SetIsDrawable(true); 1005 texture->SetIsDrawable(true);
1032 texture->SetTextureMailbox( 1006 texture->SetTextureMailbox(
1033 TextureMailbox(mailbox, sync_point), 1007 TextureMailbox(mailbox, sync_point),
1034 SingleReleaseCallback::Create(base::Bind( 1008 SingleReleaseCallback::Create(
1035 &LayerTreeHostContextTestDontUseLostResources:: 1009 base::Bind(&LayerTreeHostContextTestDontUseLostResources::
1036 EmptyReleaseCallback))); 1010 EmptyReleaseCallback)));
1037 root->AddChild(texture); 1011 root->AddChild(texture);
1038 1012
1039 scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client_); 1013 scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client_);
1040 mask->SetBounds(gfx::Size(10, 10)); 1014 mask->SetBounds(gfx::Size(10, 10));
1041 mask->SetAnchorPoint(gfx::PointF()); 1015 mask->SetAnchorPoint(gfx::PointF());
1042 1016
1043 scoped_refptr<ContentLayer> content_with_mask = 1017 scoped_refptr<ContentLayer> content_with_mask =
1044 ContentLayer::Create(&client_); 1018 ContentLayer::Create(&client_);
1045 content_with_mask->SetBounds(gfx::Size(10, 10)); 1019 content_with_mask->SetBounds(gfx::Size(10, 10));
1046 content_with_mask->SetAnchorPoint(gfx::PointF()); 1020 content_with_mask->SetAnchorPoint(gfx::PointF());
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 LayerTreeHostImpl::FrameData* frame, 1119 LayerTreeHostImpl::FrameData* frame,
1146 bool result) OVERRIDE { 1120 bool result) OVERRIDE {
1147 if (host_impl->active_tree()->source_frame_number() == 2) { 1121 if (host_impl->active_tree()->source_frame_number() == 2) {
1148 // Lose the context during draw on the second commit. This will cause 1122 // Lose the context during draw on the second commit. This will cause
1149 // a third commit to recover. 1123 // a third commit to recover.
1150 context3d_->set_times_bind_texture_succeeds(0); 1124 context3d_->set_times_bind_texture_succeeds(0);
1151 } 1125 }
1152 return true; 1126 return true;
1153 } 1127 }
1154 1128
1155 virtual scoped_ptr<OutputSurface> CreateOutputSurface( 1129 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
1156 bool fallback) OVERRIDE { 1130 OVERRIDE {
1157 // This will get called twice: 1131 // This will get called twice:
1158 // First when we create the initial output surface... 1132 // First when we create the initial output surface...
1159 if (layer_tree_host()->source_frame_number() > 0) { 1133 if (layer_tree_host()->source_frame_number() > 0) {
1160 // ... and then again after we forced the context to be lost on the third 1134 // ... and then again after we forced the context to be lost on the third
1161 // frame. Verify this assumption here. 1135 // frame. Verify this assumption here.
1162 lost_context_ = true; 1136 lost_context_ = true;
1163 EXPECT_EQ(layer_tree_host()->source_frame_number(), 3); 1137 EXPECT_EQ(layer_tree_host()->source_frame_number(), 3);
1164 } 1138 }
1165 return LayerTreeHostContextTest::CreateOutputSurface(fallback); 1139 return LayerTreeHostContextTest::CreateOutputSurface(fallback);
1166 } 1140 }
1167 1141
1168 virtual void DidCommitAndDrawFrame() OVERRIDE { 1142 virtual void DidCommitAndDrawFrame() OVERRIDE {
1169 ASSERT_TRUE(layer_tree_host()->hud_layer()); 1143 ASSERT_TRUE(layer_tree_host()->hud_layer());
1170 // End the test once we know the 3nd frame drew. 1144 // End the test once we know the 3nd frame drew.
1171 if (layer_tree_host()->source_frame_number() < 4) { 1145 if (layer_tree_host()->source_frame_number() < 4) {
1172 layer_tree_host()->root_layer()->SetNeedsDisplay(); 1146 layer_tree_host()->root_layer()->SetNeedsDisplay();
1173 layer_tree_host()->SetNeedsCommit(); 1147 layer_tree_host()->SetNeedsCommit();
1174 } else { 1148 } else {
1175 EndTest(); 1149 EndTest();
1176 } 1150 }
1177 } 1151 }
1178 1152
1179 virtual void AfterTest() OVERRIDE { 1153 virtual void AfterTest() OVERRIDE { EXPECT_TRUE(lost_context_); }
1180 EXPECT_TRUE(lost_context_);
1181 }
1182 1154
1183 private: 1155 private:
1184 FakeContentLayerClient client_; 1156 FakeContentLayerClient client_;
1185 bool lost_context_; 1157 bool lost_context_;
1186 1158
1187 FakeOutputSurfaceClient output_surface_client_; 1159 FakeOutputSurfaceClient output_surface_client_;
1188 scoped_ptr<FakeOutputSurface> child_output_surface_; 1160 scoped_ptr<FakeOutputSurface> child_output_surface_;
1189 scoped_ptr<ResourceProvider> child_resource_provider_; 1161 scoped_ptr<ResourceProvider> child_resource_provider_;
1190 1162
1191 scoped_refptr<DelegatedFrameResourceCollection> 1163 scoped_refptr<DelegatedFrameResourceCollection>
(...skipping 20 matching lines...) Expand all
1212 ASSERT_TRUE(layer_tree_host()->output_surface_lost()); 1184 ASSERT_TRUE(layer_tree_host()->output_surface_lost());
1213 1185
1214 times_output_surface_created_ = 0; 1186 times_output_surface_created_ = 0;
1215 1187
1216 // Post the SetNeedsCommit before the readback to make sure it is run 1188 // Post the SetNeedsCommit before the readback to make sure it is run
1217 // on the main thread before the readback's replacement commit when 1189 // on the main thread before the readback's replacement commit when
1218 // we have a threaded compositor. 1190 // we have a threaded compositor.
1219 PostSetNeedsCommitToMainThread(); 1191 PostSetNeedsCommitToMainThread();
1220 1192
1221 char pixels[4]; 1193 char pixels[4];
1222 bool result = layer_tree_host()->CompositeAndReadback( 1194 bool result =
1223 &pixels, gfx::Rect(1, 1)); 1195 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(1, 1));
1224 EXPECT_EQ(!delegating_renderer(), result); 1196 EXPECT_EQ(!delegating_renderer(), result);
1225 EXPECT_EQ(1, times_output_surface_created_); 1197 EXPECT_EQ(1, times_output_surface_created_);
1226 } 1198 }
1227 1199
1228 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE { 1200 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE {
1229 EXPECT_TRUE(succeeded); 1201 EXPECT_TRUE(succeeded);
1230 ++times_output_surface_created_; 1202 ++times_output_surface_created_;
1231 } 1203 }
1232 1204
1233 virtual void DidCommitAndDrawFrame() OVERRIDE { 1205 virtual void DidCommitAndDrawFrame() OVERRIDE { EndTest(); }
1234 EndTest();
1235 }
1236 1206
1237 virtual void AfterTest() OVERRIDE { 1207 virtual void AfterTest() OVERRIDE {
1238 // Should not try to create output surface again after successfully 1208 // Should not try to create output surface again after successfully
1239 // created by CompositeAndReadback. 1209 // created by CompositeAndReadback.
1240 EXPECT_EQ(1, times_output_surface_created_); 1210 EXPECT_EQ(1, times_output_surface_created_);
1241 } 1211 }
1242 1212
1243 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, 1213 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
1244 LayerTreeHostImpl::FrameData* frame_data, 1214 LayerTreeHostImpl::FrameData* frame_data,
1245 bool result) OVERRIDE { 1215 bool result) OVERRIDE {
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 }; 1449 };
1480 1450
1481 MULTI_THREAD_TEST_F(LayerTreeHostContextTestImplSidePainting); 1451 MULTI_THREAD_TEST_F(LayerTreeHostContextTestImplSidePainting);
1482 1452
1483 class ScrollbarLayerLostContext : public LayerTreeHostContextTest { 1453 class ScrollbarLayerLostContext : public LayerTreeHostContextTest {
1484 public: 1454 public:
1485 ScrollbarLayerLostContext() : commits_(0) {} 1455 ScrollbarLayerLostContext() : commits_(0) {}
1486 1456
1487 virtual void BeginTest() OVERRIDE { 1457 virtual void BeginTest() OVERRIDE {
1488 scoped_refptr<Layer> scroll_layer = Layer::Create(); 1458 scoped_refptr<Layer> scroll_layer = Layer::Create();
1489 scrollbar_layer_ = FakePaintedScrollbarLayer::Create( 1459 scrollbar_layer_ =
1490 false, true, scroll_layer->id()); 1460 FakePaintedScrollbarLayer::Create(false, true, scroll_layer->id());
1491 scrollbar_layer_->SetBounds(gfx::Size(10, 100)); 1461 scrollbar_layer_->SetBounds(gfx::Size(10, 100));
1492 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); 1462 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_);
1493 layer_tree_host()->root_layer()->AddChild(scroll_layer); 1463 layer_tree_host()->root_layer()->AddChild(scroll_layer);
1494 PostSetNeedsCommitToMainThread(); 1464 PostSetNeedsCommitToMainThread();
1495 } 1465 }
1496 1466
1497 virtual void AfterTest() OVERRIDE {} 1467 virtual void AfterTest() OVERRIDE {}
1498 1468
1499 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1469 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1500 LayerTreeHostContextTest::CommitCompleteOnThread(impl); 1470 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 // DidActivateTreeOnThread, which happens after DidCommit with impl-side 1518 // DidActivateTreeOnThread, which happens after DidCommit with impl-side
1549 // painting. 1519 // painting.
1550 virtual void StepCompleteOnMainThread(int time_step) = 0; 1520 virtual void StepCompleteOnMainThread(int time_step) = 0;
1551 1521
1552 // Called after DidActivateTreeOnThread. If this is done during the commit, 1522 // Called after DidActivateTreeOnThread. If this is done during the commit,
1553 // the call to StepCompleteOnMainThread will not occur until after 1523 // the call to StepCompleteOnMainThread will not occur until after
1554 // the commit completes, because the main thread is blocked. 1524 // the commit completes, because the main thread is blocked.
1555 void PostStepCompleteToMainThread() { 1525 void PostStepCompleteToMainThread() {
1556 proxy()->MainThreadTaskRunner()->PostTask( 1526 proxy()->MainThreadTaskRunner()->PostTask(
1557 FROM_HERE, 1527 FROM_HERE,
1558 base::Bind( 1528 base::Bind(&UIResourceLostTest::StepCompleteOnMainThreadInternal,
1559 &UIResourceLostTest::StepCompleteOnMainThreadInternal, 1529 base::Unretained(this),
1560 base::Unretained(this), 1530 time_step_));
1561 time_step_));
1562 } 1531 }
1563 1532
1564 void PostLoseContextToImplThread() { 1533 void PostLoseContextToImplThread() {
1565 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); 1534 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread());
1566 base::SingleThreadTaskRunner* task_runner = 1535 base::SingleThreadTaskRunner* task_runner =
1567 HasImplThread() ? ImplThreadTaskRunner() 1536 HasImplThread() ? ImplThreadTaskRunner()
1568 : base::MessageLoopProxy::current(); 1537 : base::MessageLoopProxy::current();
1569 task_runner->PostTask( 1538 task_runner->PostTask(FROM_HERE,
1570 FROM_HERE, 1539 base::Bind(&LayerTreeHostContextTest::LoseContext,
1571 base::Bind( 1540 base::Unretained(this)));
1572 &LayerTreeHostContextTest::LoseContext,
1573 base::Unretained(this)));
1574 } 1541 }
1575 1542
1576 protected: 1543 protected:
1577 int time_step_; 1544 int time_step_;
1578 scoped_ptr<FakeScopedUIResource> ui_resource_; 1545 scoped_ptr<FakeScopedUIResource> ui_resource_;
1579 1546
1580 private: 1547 private:
1581 void StepCompleteOnMainThreadInternal(int step) { 1548 void StepCompleteOnMainThreadInternal(int step) {
1582 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); 1549 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread());
1583 StepCompleteOnMainThread(step); 1550 StepCompleteOnMainThread(step);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 // of creation/deletion are considered: 1632 // of creation/deletion are considered:
1666 // 1. Create one resource -> Context Lost => Expect the resource to have been 1633 // 1. Create one resource -> Context Lost => Expect the resource to have been
1667 // created. 1634 // created.
1668 // 2. Delete an exisiting resource (test_id0_) -> create a second resource 1635 // 2. Delete an exisiting resource (test_id0_) -> create a second resource
1669 // (test_id1_) -> Context Lost => Expect the test_id0_ to be removed and 1636 // (test_id1_) -> Context Lost => Expect the test_id0_ to be removed and
1670 // test_id1_ to have been created. 1637 // test_id1_ to have been created.
1671 // 3. Create one resource -> Delete that same resource -> Context Lost => Expect 1638 // 3. Create one resource -> Delete that same resource -> Context Lost => Expect
1672 // the resource to not exist in the manager. 1639 // the resource to not exist in the manager.
1673 class UIResourceLostBeforeCommit : public UIResourceLostTestSimple { 1640 class UIResourceLostBeforeCommit : public UIResourceLostTestSimple {
1674 public: 1641 public:
1675 UIResourceLostBeforeCommit() 1642 UIResourceLostBeforeCommit() : test_id0_(0), test_id1_(0) {}
1676 : test_id0_(0),
1677 test_id1_(0) {}
1678 1643
1679 virtual void StepCompleteOnMainThread(int step) OVERRIDE { 1644 virtual void StepCompleteOnMainThread(int step) OVERRIDE {
1680 switch (step) { 1645 switch (step) {
1681 case 0: 1646 case 0:
1682 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); 1647 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host());
1683 // Lose the context on the impl thread before the commit. 1648 // Lose the context on the impl thread before the commit.
1684 PostLoseContextToImplThread(); 1649 PostLoseContextToImplThread();
1685 break; 1650 break;
1686 case 2: 1651 case 2:
1687 // Sequence 2: 1652 // Sequence 2:
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 ui_resource_.reset(); 1857 ui_resource_.reset();
1893 EndTest(); 1858 EndTest();
1894 break; 1859 break;
1895 case 4: 1860 case 4:
1896 NOTREACHED(); 1861 NOTREACHED();
1897 } 1862 }
1898 } 1863 }
1899 1864
1900 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* impl, 1865 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* impl,
1901 bool visible) OVERRIDE { 1866 bool visible) OVERRIDE {
1902 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( 1867 TestWebGraphicsContext3D* context = TestContext();
1903 impl->output_surface()->context_provider()->Context3d());
1904 if (!visible) { 1868 if (!visible) {
1905 // All resources should have been evicted. 1869 // All resources should have been evicted.
1906 ASSERT_EQ(0u, context->NumTextures()); 1870 ASSERT_EQ(0u, context->NumTextures());
1907 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); 1871 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1908 EXPECT_EQ(2, ui_resource_->resource_create_count); 1872 EXPECT_EQ(2, ui_resource_->resource_create_count);
1909 EXPECT_EQ(1, ui_resource_->lost_resource_count); 1873 EXPECT_EQ(1, ui_resource_->lost_resource_count);
1910 // Drawing is disabled both because of the evicted resources and 1874 // Drawing is disabled both because of the evicted resources and
1911 // because the renderer is not visible. 1875 // because the renderer is not visible.
1912 EXPECT_FALSE(impl->CanDraw()); 1876 EXPECT_FALSE(impl->CanDraw());
1913 // Make the renderer visible again. 1877 // Make the renderer visible again.
1914 PostSetVisibleToMainThread(true); 1878 PostSetVisibleToMainThread(true);
1915 } 1879 }
1916 } 1880 }
1917 1881
1918 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { 1882 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE {
1919 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( 1883 TestWebGraphicsContext3D* context = TestContext();
1920 impl->output_surface()->context_provider()->Context3d());
1921 LayerTreeHostContextTest::CommitCompleteOnThread(impl); 1884 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
1922 switch (time_step_) { 1885 switch (time_step_) {
1923 case 1: 1886 case 1:
1924 // The resource should have been created on LTHI after the commit. 1887 // The resource should have been created on LTHI after the commit.
1925 ASSERT_EQ(1u, context->NumTextures()); 1888 ASSERT_EQ(1u, context->NumTextures());
1926 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); 1889 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1927 EXPECT_EQ(1, ui_resource_->resource_create_count); 1890 EXPECT_EQ(1, ui_resource_->resource_create_count);
1928 EXPECT_EQ(0, ui_resource_->lost_resource_count); 1891 EXPECT_EQ(0, ui_resource_->lost_resource_count);
1929 EXPECT_TRUE(impl->CanDraw()); 1892 EXPECT_TRUE(impl->CanDraw());
1930 // Evict all UI resources. This will trigger a commit. 1893 // Evict all UI resources. This will trigger a commit.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 : LayerTreeHostContextTest(), 1928 : LayerTreeHostContextTest(),
1966 layer_(FakeContentLayer::Create(&client_)), 1929 layer_(FakeContentLayer::Create(&client_)),
1967 num_commits_(0) {} 1930 num_commits_(0) {}
1968 1931
1969 virtual void SetupTree() OVERRIDE { 1932 virtual void SetupTree() OVERRIDE {
1970 layer_->SetBounds(gfx::Size(10, 20)); 1933 layer_->SetBounds(gfx::Size(10, 20));
1971 layer_tree_host()->SetRootLayer(layer_); 1934 layer_tree_host()->SetRootLayer(layer_);
1972 LayerTreeHostContextTest::SetupTree(); 1935 LayerTreeHostContextTest::SetupTree();
1973 } 1936 }
1974 1937
1975 virtual void BeginTest() OVERRIDE { 1938 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
1976 PostSetNeedsCommitToMainThread();
1977 }
1978 1939
1979 virtual void DidCommit() OVERRIDE { 1940 virtual void DidCommit() OVERRIDE {
1980 switch (num_commits_) { 1941 switch (num_commits_) {
1981 case 0: 1942 case 0:
1982 EXPECT_EQ(1u, layer_->output_surface_created_count()); 1943 EXPECT_EQ(1u, layer_->output_surface_created_count());
1983 layer_tree_host()->SetNeedsCommit(); 1944 layer_tree_host()->SetNeedsCommit();
1984 break; 1945 break;
1985 case 1: 1946 case 1:
1986 EXPECT_EQ(1u, layer_->output_surface_created_count()); 1947 EXPECT_EQ(1u, layer_->output_surface_created_count());
1987 layer_tree_host()->SetNeedsCommit(); 1948 layer_tree_host()->SetNeedsCommit();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2022 protected: 1983 protected:
2023 FakeContentLayerClient client_; 1984 FakeContentLayerClient client_;
2024 scoped_refptr<FakeContentLayer> layer_; 1985 scoped_refptr<FakeContentLayer> layer_;
2025 int num_commits_; 1986 int num_commits_;
2026 }; 1987 };
2027 1988
2028 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); 1989 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback);
2029 1990
2030 } // namespace 1991 } // namespace
2031 } // namespace cc 1992 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698