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

Side by Side Diff: cc/layer_tree_host_unittest_context.cc

Issue 11662003: cc: Put context-loss tests in layer_tree_host_unittest_context.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rm macros Created 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "cc/layer_tree_host.h"
6
7 #include "base/basictypes.h"
8 #include "cc/content_layer.h"
9 #include "cc/delegated_renderer_layer.h"
10 #include "cc/delegated_renderer_layer_impl.h"
11 #include "cc/heads_up_display_layer.h"
12 #include "cc/io_surface_layer.h"
13 #include "cc/layer_impl.h"
14 #include "cc/layer_tree_host_impl.h"
15 #include "cc/layer_tree_impl.h"
16 #include "cc/scrollbar_layer.h"
17 #include "cc/single_thread_proxy.h"
18 #include "cc/test/fake_content_layer.h"
19 #include "cc/test/fake_content_layer_client.h"
20 #include "cc/test/fake_content_layer_impl.h"
21 #include "cc/test/fake_output_surface.h"
22 #include "cc/test/fake_scrollbar_theme_painter.h"
23 #include "cc/test/fake_video_frame.h"
24 #include "cc/test/fake_video_frame_provider.h"
25 #include "cc/test/fake_web_graphics_context_3d.h"
26 #include "cc/test/fake_web_scrollbar.h"
27 #include "cc/test/fake_web_scrollbar_theme_geometry.h"
28 #include "cc/test/layer_tree_test_common.h"
29 #include "cc/test/render_pass_test_common.h"
30 #include "cc/texture_layer.h"
31 #include "cc/video_layer.h"
32 #include "cc/video_layer_impl.h"
33 #include "media/base/media.h"
34
35 using media::VideoFrame;
36 using WebKit::WebGraphicsContext3D;
37
38 namespace cc {
39 namespace {
40
41 // These tests deal with losing the 3d graphics context.
42 class LayerTreeHostContextTest : public ThreadedTest {
43 public:
44 LayerTreeHostContextTest()
45 : ThreadedTest(),
46 context3d_(NULL),
47 times_to_fail_create_(0),
48 times_to_create_and_lose_(0),
49 times_to_lose_during_commit_(0),
50 times_to_repeat_loss_(0),
51 times_to_fail_recreate_(0) {
52 media::InitializeMediaLibraryForTesting();
53 }
54
55 void LoseContext() {
56 context3d_->loseContextCHROMIUM();
57 context3d_ = NULL;
58 }
59
60 virtual scoped_ptr<FakeWebGraphicsContext3D> CreateContext3d() {
61 return FakeWebGraphicsContext3D::Create();
62 }
63
64 virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE {
65 if (times_to_fail_create_) {
66 --times_to_fail_create_;
67 return scoped_ptr<OutputSurface>();
68 }
69
70 scoped_ptr<FakeWebGraphicsContext3D> context3d = CreateContext3d();
71 context3d_ = context3d.get();
72
73 if (times_to_create_and_lose_) {
74 --times_to_create_and_lose_;
75 // Make the context get lost during reinitialization.
76 // The number of times MakeCurrent succeeds is not important, and
77 // can be changed if needed to make this pass with future changes.
78 context3d_->set_times_make_current_succeeds(2);
79 }
80
81 return FakeOutputSurface::Create3d(
82 context3d.PassAs<WebGraphicsContext3D>()).PassAs<OutputSurface>();
83 }
84
85 virtual void commitCompleteOnThread(LayerTreeHostImpl *host_impl) OVERRIDE {
86 if (!times_to_lose_during_commit_)
87 return;
88 --times_to_lose_during_commit_;
89 LoseContext();
90
91 times_to_create_and_lose_ = times_to_repeat_loss_;
92 times_to_repeat_loss_ = 0;
93 times_to_fail_create_ = times_to_fail_recreate_;
94 times_to_fail_recreate_ = 0;
95 }
96
97 protected:
98 FakeWebGraphicsContext3D* context3d_;
99 int times_to_fail_create_;
100 int times_to_create_and_lose_;
101 int times_to_lose_during_commit_;
102 int times_to_repeat_loss_;
103 int times_to_fail_recreate_;
104 };
105
106 class LayerTreeHostContextTestLostContextSucceeds :
107 public LayerTreeHostContextTest {
108 public:
109 LayerTreeHostContextTestLostContextSucceeds()
110 : LayerTreeHostContextTest(),
111 test_case_(0),
112 num_losses_(0) {
113 }
114
115 virtual void beginTest() OVERRIDE {
116 postSetNeedsCommitToMainThread();
117 }
118
119 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE {
120 EXPECT_TRUE(succeeded);
121 ++num_losses_;
122 }
123
124 virtual void afterTest() OVERRIDE {
125 EXPECT_EQ(3, test_case_);
126 EXPECT_EQ(3, num_losses_);
127 }
128
129 bool SourceFrameHasContextLoss(int source_frame) const {
130 return source_frame % 2 == 1;
131 }
132
133 virtual void didCommitAndDrawFrame() OVERRIDE {
134 // If the last frame had a context loss, then we'll commit again to
135 // recover.
136 if (SourceFrameHasContextLoss(m_layerTreeHost->commitNumber()) - 1)
137 return;
138
139 if (NextTestCase())
140 m_layerTreeHost->setNeedsCommit();
141 else
142 endTest();
143 }
144
145 bool NextTestCase() {
146 static const TestCase kTests[] = {
147 // Losing the context and failing to recreate it (or losing it again
148 // immediately) a small number of times should succeed.
149 { 1, // times_to_lose_during_commit
150 0, // times_to_repeat_loss
151 0, // times_to_fail_recreate
152 },
153 { 1,
154 3, // times_to_repeat_loss
155 0, // times_to_fail_recreate
156 },
157 { 1,
158 0, // times_to_repeat_loss
159 3, // times_to_fail_recreate
160 },
161 };
162
163 if (test_case_ >= arraysize(kTests))
164 return false;
165
166 times_to_lose_during_commit_ =
167 kTests[test_case_].times_to_lose_during_commit;
168 times_to_repeat_loss_ = kTests[test_case_].times_to_repeat_loss;
169 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate;
170 ++test_case_;
171 return true;
172 }
173
174 struct TestCase {
175 int times_to_lose_during_commit;
176 int times_to_repeat_loss;
177 int times_to_fail_recreate;
178 };
179
180 private:
181 size_t test_case_;
182 int num_losses_;
183 };
184
185 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds)
186
187 template<bool kUseSurface>
jamesr 2013/01/03 22:59:07 Why the template? Code inside a TEST_F body is a
188 class LayerTreeHostContextTestLostContextSucceedsWithContent :
189 public LayerTreeHostContextTestLostContextSucceeds {
190 public:
191
192 LayerTreeHostContextTestLostContextSucceedsWithContent()
193 : LayerTreeHostContextTestLostContextSucceeds() {
194 }
195
196 virtual void setupTree() OVERRIDE {
197 scoped_refptr<Layer> root_ = Layer::create();
198 root_->setBounds(gfx::Size(10, 10));
199 root_->setAnchorPoint(gfx::PointF());
200 root_->setIsDrawable(true);
201
202 scoped_refptr<FakeContentLayer> content_ =
203 FakeContentLayer::Create(&client_);
204 content_->setBounds(gfx::Size(10, 10));
205 content_->setAnchorPoint(gfx::PointF());
206 content_->setIsDrawable(true);
207 if (kUseSurface)
208 content_->setForceRenderSurface(true);
209 root_->addChild(content_);
210
211 m_layerTreeHost->setRootLayer(root_);
212 LayerTreeHostContextTest::setupTree();
213 }
214
215 virtual void drawLayersOnThread(LayerTreeHostImpl* host_impl) {
216 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>(
217 host_impl->rootLayer()->children()[0]);
218 // Even though the context was lost, we should have a resource. The
219 // FakeWebGraphicsContext3D ensures that this resource is created with
220 // the active context.
221 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0));
222 }
223
224 protected:
225 FakeContentLayerClient client_;
226 scoped_refptr<Layer> root_;
227 scoped_refptr<ContentLayer> content_;
228 };
229
230 class LayerTreeHostContextTestLostContextSucceedsWithContent_NoSurface
231 : public LayerTreeHostContextTestLostContextSucceedsWithContent<false> {};
232
233 SINGLE_AND_MULTI_THREAD_TEST_F(
234 LayerTreeHostContextTestLostContextSucceedsWithContent_NoSurface)
235
236 class LayerTreeHostContextTestLostContextSucceedsWithContent_WithSurface
237 : public LayerTreeHostContextTestLostContextSucceedsWithContent<true> {};
238
239 SINGLE_AND_MULTI_THREAD_TEST_F(
240 LayerTreeHostContextTestLostContextSucceedsWithContent_WithSurface)
241
242 template<int kTimesToRepeatLoss, int kTimesToFailRecreate>
243 class LayerTreeHostContextTestLostContextFails :
244 public LayerTreeHostContextTest {
245 public:
246 LayerTreeHostContextTestLostContextFails()
247 : LayerTreeHostContextTest(),
248 num_commits_(0) {
249 times_to_lose_during_commit_ = 1;
250 times_to_repeat_loss_ = kTimesToRepeatLoss;
251 times_to_fail_recreate_ = kTimesToFailRecreate;
252 }
253
254 virtual void beginTest() OVERRIDE {
255 postSetNeedsCommitToMainThread();
256 }
257
258 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE {
259 EXPECT_FALSE(succeeded);
260 endTest();
261 }
262
263 virtual void commitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
264 LayerTreeHostContextTest::commitCompleteOnThread(host_impl);
265
266 ++num_commits_;
267 if (num_commits_ == 1) {
268 // When the context is ok, we should have these things.
269 EXPECT_TRUE(host_impl->outputSurface());
270 EXPECT_TRUE(host_impl->renderer());
271 EXPECT_TRUE(host_impl->resourceProvider());
272 return;
273 }
274
275 // When context recreation fails we shouldn't be left with any of them.
276 EXPECT_FALSE(host_impl->outputSurface());
277 EXPECT_FALSE(host_impl->renderer());
278 EXPECT_FALSE(host_impl->resourceProvider());
279 }
280
281 virtual void afterTest() OVERRIDE {}
282
283 private:
284 int num_commits_;
285 };
286
287 class LayerTreeHostContextTestLostContextFails_RepeatLoss100
288 : public LayerTreeHostContextTestLostContextFails<100, 0> {};
289
290 SINGLE_AND_MULTI_THREAD_TEST_F(
291 LayerTreeHostContextTestLostContextFails_RepeatLoss100)
292
293 class LayerTreeHostContextTestLostContextFails_FailRecreate100
294 : public LayerTreeHostContextTestLostContextFails<0, 100> {};
295
296 SINGLE_AND_MULTI_THREAD_TEST_F(
297 LayerTreeHostContextTestLostContextFails_FailRecreate100)
298
299 class LayerTreeHostContextTestFinishAllRenderingAfterLoss :
300 public LayerTreeHostContextTest {
301 public:
302 virtual void beginTest() OVERRIDE {
303 // Lose the context until the compositor gives up on it.
304 times_to_lose_during_commit_ = 1;
305 times_to_repeat_loss_ = 10;
306 postSetNeedsCommitToMainThread();
307 }
308
309 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE {
310 EXPECT_FALSE(succeeded);
311 m_layerTreeHost->finishAllRendering();
312 endTest();
313 }
314
315 virtual void afterTest() OVERRIDE {}
316 };
317
318 SINGLE_AND_MULTI_THREAD_TEST_F(
319 LayerTreeHostContextTestFinishAllRenderingAfterLoss)
320
321 template<bool kLoseAfterEvict>
322 class LayerTreeHostContextTestLostContextAndEvictTextures :
323 public LayerTreeHostContextTest {
324 public:
325 LayerTreeHostContextTestLostContextAndEvictTextures()
326 : LayerTreeHostContextTest(),
327 layer_(FakeContentLayer::Create(&client_)),
328 impl_host_(0),
329 num_commits_(0) {
330 }
331
332 virtual void setupTree() OVERRIDE {
333 layer_->setBounds(gfx::Size(10, 20));
334 m_layerTreeHost->setRootLayer(layer_);
335 LayerTreeHostContextTest::setupTree();
336 }
337
338 virtual void beginTest() OVERRIDE {
339 postSetNeedsCommitToMainThread();
340 }
341
342 void PostEvictTextures() {
343 if (implThread()) {
344 implThread()->postTask(
345 base::Bind(
346 &LayerTreeHostContextTestLostContextAndEvictTextures::
347 EvictTexturesOnImplThread,
348 base::Unretained(this)));
349 } else {
350 DebugScopedSetImplThread impl(proxy());
351 EvictTexturesOnImplThread();
352 }
353 }
354
355 void EvictTexturesOnImplThread() {
356 impl_host_->enforceManagedMemoryPolicy(ManagedMemoryPolicy(0));
357 if (kLoseAfterEvict)
358 LoseContext();
359 }
360
361 virtual void didCommitAndDrawFrame() OVERRIDE {
362 if (num_commits_ > 1)
363 return;
364 EXPECT_TRUE(layer_->HaveBackingAt(0, 0));
365 PostEvictTextures();
366 }
367
368 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
369 if (num_commits_ > 1)
370 return;
371 ++num_commits_;
372 if (!kLoseAfterEvict)
373 LoseContext();
374 impl_host_ = impl;
375 }
376
377 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE {
378 EXPECT_TRUE(succeeded);
379 endTest();
380 }
381
382 virtual void afterTest() OVERRIDE {}
383
384 private:
385 FakeContentLayerClient client_;
386 scoped_refptr<FakeContentLayer> layer_;
387 LayerTreeHostImpl* impl_host_;
388 int num_commits_;
389 };
390
391 class LayerTreeHostContextTestLostContextAndEvictTextures_LoseAfterEvict
392 : public LayerTreeHostContextTestLostContextAndEvictTextures<true> {};
393
394 SINGLE_AND_MULTI_THREAD_TEST_F(
395 LayerTreeHostContextTestLostContextAndEvictTextures_LoseAfterEvict);
396
397 class LayerTreeHostContextTestLostContextAndEvictTextures_LoseBeforeEvict
398 : public LayerTreeHostContextTestLostContextAndEvictTextures<false> {};
399
400 SINGLE_AND_MULTI_THREAD_TEST_F(
401 LayerTreeHostContextTestLostContextAndEvictTextures_LoseBeforeEvict);
402
403 class LayerTreeHostContextTestLostContextWhileUpdatingResources :
404 public LayerTreeHostContextTest {
405 public:
406 LayerTreeHostContextTestLostContextWhileUpdatingResources()
407 : parent_(FakeContentLayer::Create(&client_)),
408 num_children_(50),
409 times_to_lose_on_end_query_(3) {
410 }
411
412 virtual scoped_ptr<FakeWebGraphicsContext3D> CreateContext3d() {
413 scoped_ptr<FakeWebGraphicsContext3D> context =
414 LayerTreeHostContextTest::CreateContext3d();
415 if (times_to_lose_on_end_query_) {
416 --times_to_lose_on_end_query_;
417 context->set_times_end_query_succeeds(5);
418 }
419 return context.Pass();
420 }
421
422 virtual void setupTree() {
423 parent_->setBounds(gfx::Size(num_children_, 1));
424
425 for (int i = 0; i < num_children_; i++) {
426 scoped_refptr<FakeContentLayer> child =
427 FakeContentLayer::Create(&client_);
428 child->setPosition(gfx::PointF(i, 0.f));
429 child->setBounds(gfx::Size(1, 1));
430 parent_->addChild(child);
431 }
432
433 m_layerTreeHost->setRootLayer(parent_);
434 LayerTreeHostContextTest::setupTree();
435 }
436
437 virtual void beginTest() {
438 postSetNeedsCommitToMainThread();
439 }
440
441 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) {
442 endTest();
443 }
444
445 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE {
446 EXPECT_TRUE(succeeded);
447 }
448
449 virtual void afterTest() {
450 EXPECT_EQ(0, times_to_lose_on_end_query_);
451 }
452
453 private:
454 FakeContentLayerClient client_;
455 scoped_refptr<FakeContentLayer> parent_;
456 int num_children_;
457 int times_to_lose_on_end_query_;
458 };
459
460 SINGLE_AND_MULTI_THREAD_TEST_F(
461 LayerTreeHostContextTestLostContextWhileUpdatingResources)
462
463 class LayerTreeHostContextTestLayersNotified :
464 public LayerTreeHostContextTest {
465 public:
466 LayerTreeHostContextTestLayersNotified()
467 : LayerTreeHostContextTest(),
468 num_commits_(0) {
469 }
470
471 virtual void setupTree() OVERRIDE {
472 root_ = FakeContentLayer::Create(&client_);
473 child_ = FakeContentLayer::Create(&client_);
474 grandchild_ = FakeContentLayer::Create(&client_);
475
476 root_->addChild(child_);
477 child_->addChild(grandchild_);
478
479 m_layerTreeHost->setRootLayer(root_);
480 LayerTreeHostContextTest::setupTree();
481 }
482
483 virtual void beginTest() OVERRIDE {
484 postSetNeedsCommitToMainThread();
485 }
486
487 virtual void commitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
488 FakeContentLayerImpl* root = static_cast<FakeContentLayerImpl*>(
489 host_impl->rootLayer());
490 FakeContentLayerImpl* child = static_cast<FakeContentLayerImpl*>(
491 root->children()[0]);
492 FakeContentLayerImpl* grandchild = static_cast<FakeContentLayerImpl*>(
493 child->children()[0]);
494
495 ++num_commits_;
496 switch (num_commits_) {
497 case 1:
498 EXPECT_EQ(0u, root->lost_output_surface_count());
499 EXPECT_EQ(0u, child->lost_output_surface_count());
500 EXPECT_EQ(0u, grandchild->lost_output_surface_count());
501 // Lose the context and struggle to recreate it.
502 LoseContext();
503 times_to_fail_create_ = 1;
504 break;
505 case 2:
506 EXPECT_EQ(1u, root->lost_output_surface_count());
507 EXPECT_EQ(1u, child->lost_output_surface_count());
508 EXPECT_EQ(1u, grandchild->lost_output_surface_count());
509 // Lose the context and again during recreate.
510 LoseContext();
511 times_to_create_and_lose_ = 1;
512 break;
513 case 3:
514 EXPECT_EQ(3u, root->lost_output_surface_count());
515 EXPECT_EQ(3u, child->lost_output_surface_count());
516 EXPECT_EQ(3u, grandchild->lost_output_surface_count());
517 endTest();
518 break;
519 default:
520 NOTREACHED();
521 }
522 }
523
524 virtual void afterTest() OVERRIDE {}
525
526 private:
527 int num_commits_;
528
529 FakeContentLayerClient client_;
530 scoped_refptr<FakeContentLayer> root_;
531 scoped_refptr<FakeContentLayer> child_;
532 scoped_refptr<FakeContentLayer> grandchild_;
533 };
534
535 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLayersNotified)
536
537 class LayerTreeHostContextTestDontUseLostResources :
538 public LayerTreeHostContextTest {
539 public:
540 virtual void setupTree() OVERRIDE {
541 context3d_->set_have_extension_io_surface(true);
542 context3d_->set_have_extension_egl_image(true);
543
544 scoped_refptr<Layer> root_ = Layer::create();
545 root_->setBounds(gfx::Size(10, 10));
546 root_->setAnchorPoint(gfx::PointF());
547 root_->setIsDrawable(true);
548
549 scoped_refptr<DelegatedRendererLayer> delegated_ =
550 DelegatedRendererLayer::create();
551 delegated_->setBounds(gfx::Size(10, 10));
552 delegated_->setAnchorPoint(gfx::PointF());
553 delegated_->setIsDrawable(true);
554 root_->addChild(delegated_);
555
556 scoped_refptr<ContentLayer> content_ = ContentLayer::create(&client_);
557 content_->setBounds(gfx::Size(10, 10));
558 content_->setAnchorPoint(gfx::PointF());
559 content_->setIsDrawable(true);
560 root_->addChild(content_);
561
562 scoped_refptr<TextureLayer> texture_ = TextureLayer::create(NULL);
563 texture_->setBounds(gfx::Size(10, 10));
564 texture_->setAnchorPoint(gfx::PointF());
565 texture_->setTextureId(FakeWebGraphicsContext3D::kExternalTextureId);
566 texture_->setIsDrawable(true);
567 root_->addChild(texture_);
568
569 scoped_refptr<ContentLayer> mask_ = ContentLayer::create(&client_);
570 mask_->setBounds(gfx::Size(10, 10));
571 mask_->setAnchorPoint(gfx::PointF());
572
573 scoped_refptr<ContentLayer> content_with_mask_ =
574 ContentLayer::create(&client_);
575 content_with_mask_->setBounds(gfx::Size(10, 10));
576 content_with_mask_->setAnchorPoint(gfx::PointF());
577 content_with_mask_->setIsDrawable(true);
578 content_with_mask_->setMaskLayer(mask_.get());
579 root_->addChild(content_with_mask_);
580
581 VideoLayerImpl::FrameUnwrapper unwrapper =
582 base::Bind(FakeVideoFrame::ToVideoFrame);
583
584 scoped_refptr<VideoLayer> video_color_ = VideoLayer::create(
585 &color_frame_provider_, unwrapper);
586 video_color_->setBounds(gfx::Size(10, 10));
587 video_color_->setAnchorPoint(gfx::PointF());
588 video_color_->setIsDrawable(true);
589 root_->addChild(video_color_);
590
591 scoped_refptr<VideoLayer> video_hw_ = VideoLayer::create(
592 &hw_frame_provider_, unwrapper);
593 video_hw_->setBounds(gfx::Size(10, 10));
594 video_hw_->setAnchorPoint(gfx::PointF());
595 video_hw_->setIsDrawable(true);
596 root_->addChild(video_hw_);
597
598 scoped_refptr<VideoLayer> video_scaled_hw_ = VideoLayer::create(
599 &scaled_hw_frame_provider_, unwrapper);
600 video_scaled_hw_->setBounds(gfx::Size(10, 10));
601 video_scaled_hw_->setAnchorPoint(gfx::PointF());
602 video_scaled_hw_->setIsDrawable(true);
603 root_->addChild(video_scaled_hw_);
604
605 scoped_refptr<IOSurfaceLayer> io_surface_ = IOSurfaceLayer::create();
606 io_surface_->setBounds(gfx::Size(10, 10));
607 io_surface_->setAnchorPoint(gfx::PointF());
608 io_surface_->setIsDrawable(true);
609 io_surface_->setIOSurfaceProperties(1, gfx::Size(10, 10));
610 root_->addChild(io_surface_);
611
612 scoped_refptr<HeadsUpDisplayLayer> hud_ = HeadsUpDisplayLayer::create();
613 hud_->setBounds(gfx::Size(10, 10));
614 hud_->setAnchorPoint(gfx::PointF());
615 hud_->setIsDrawable(true);
616 root_->addChild(hud_);
617 // Enable the hud.
618 LayerTreeDebugState debug_state;
619 debug_state.showFPSCounter = true;
620 m_layerTreeHost->setDebugState(debug_state);
621
622 bool paint_scrollbar = true;
623 bool has_thumb = true;
624 scoped_refptr<ScrollbarLayer> scrollbar_ = ScrollbarLayer::create(
625 FakeWebScrollbar::create().PassAs<WebKit::WebScrollbar>(),
626 FakeScrollbarThemePainter::Create(paint_scrollbar)
627 .PassAs<ScrollbarThemePainter>(),
628 FakeWebScrollbarThemeGeometry::create(has_thumb)
629 .PassAs<WebKit::WebScrollbarThemeGeometry>(),
630 content_->id());
631 scrollbar_->setBounds(gfx::Size(10, 10));
632 scrollbar_->setAnchorPoint(gfx::PointF());
633 scrollbar_->setIsDrawable(true);
634 root_->addChild(scrollbar_);
635
636 m_layerTreeHost->setRootLayer(root_);
637 LayerTreeHostContextTest::setupTree();
638 }
639
640 virtual void beginTest() OVERRIDE {
641 postSetNeedsCommitToMainThread();
642 }
643
644 virtual void commitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
645 ResourceProvider* resource_provider = host_impl->resourceProvider();
646
647 if (host_impl->activeTree()->source_frame_number() == 0) {
648 // Set up impl resources on the first commit.
649
650 scoped_ptr<TestRenderPass> pass_for_quad = TestRenderPass::Create();
651 pass_for_quad->SetNew(
652 // AppendOneOfEveryQuadType() makes a RenderPass quad with this id.
653 RenderPass::Id(1, 1),
654 gfx::Rect(0, 0, 10, 10),
655 gfx::Rect(0, 0, 10, 10),
656 gfx::Transform());
657
658 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create();
659 pass->SetNew(
660 RenderPass::Id(2, 1),
661 gfx::Rect(0, 0, 10, 10),
662 gfx::Rect(0, 0, 10, 10),
663 gfx::Transform());
664 pass->AppendOneOfEveryQuadType(resource_provider);
665
666 ScopedPtrVector<RenderPass> pass_list;
667 pass_list.append(pass_for_quad.PassAs<RenderPass>());
668 pass_list.append(pass.PassAs<RenderPass>());
669
670 // First child is the delegated layer.
671 DelegatedRendererLayerImpl* delegated_impl =
672 static_cast<DelegatedRendererLayerImpl*>(
673 host_impl->rootLayer()->children()[0]);
674 delegated_impl->setRenderPasses(pass_list);
675 EXPECT_TRUE(pass_list.isEmpty());
676
677 color_video_frame_ = make_scoped_ptr(new FakeVideoFrame(
678 VideoFrame::CreateColorFrame(
679 gfx::Size(4, 4), 0x80, 0x80, 0x80, base::TimeDelta())));
680 hw_video_frame_ = make_scoped_ptr(new FakeVideoFrame(
681 VideoFrame::WrapNativeTexture(
682 resource_provider->graphicsContext3D()->createTexture(),
683 GL_TEXTURE_2D,
684 gfx::Size(4, 4), gfx::Rect(0, 0, 4, 4), gfx::Size(4, 4),
685 base::TimeDelta(),
686 VideoFrame::ReadPixelsCB(),
687 base::Closure())));
688 scaled_hw_video_frame_ = make_scoped_ptr(new FakeVideoFrame(
689 VideoFrame::WrapNativeTexture(
690 resource_provider->graphicsContext3D()->createTexture(),
691 GL_TEXTURE_2D,
692 gfx::Size(4, 4), gfx::Rect(0, 0, 3, 2), gfx::Size(4, 4),
693 base::TimeDelta(),
694 VideoFrame::ReadPixelsCB(),
695 base::Closure())));
696
697 color_frame_provider_.set_frame(color_video_frame_.get());
698 hw_frame_provider_.set_frame(hw_video_frame_.get());
699 scaled_hw_frame_provider_.set_frame(scaled_hw_video_frame_.get());
700 return;
701 }
702
703 if (host_impl->activeTree()->source_frame_number() == 3) {
704 // On the third commit we're recovering from context loss. Hardware
705 // video frames should not be reused by the VideoFrameProvider, but
706 // software frames can be.
707 hw_frame_provider_.set_frame(NULL);
708 scaled_hw_frame_provider_.set_frame(NULL);
709 }
710 }
711
712 virtual bool prepareToDrawOnThread(LayerTreeHostImpl* host_impl) {
713 if (host_impl->activeTree()->source_frame_number() == 2) {
714 // Lose the context during draw on the second commit. This will cause
715 // a third commit to recover.
716 if (context3d_)
717 context3d_->set_times_bind_texture_succeeds(4);
718 }
719 return true;
720 }
721
722 virtual void didCommitAndDrawFrame() OVERRIDE {
723 // End the test once we know the 3nd frame drew.
724 if (m_layerTreeHost->commitNumber() == 4)
725 endTest();
726 }
727
728 virtual void afterTest() OVERRIDE {}
729
730 private:
731 FakeContentLayerClient client_;
732
733 scoped_refptr<Layer> root_;
734 scoped_refptr<DelegatedRendererLayer> delegated_;
735 scoped_refptr<ContentLayer> content_;
736 scoped_refptr<TextureLayer> texture_;
737 scoped_refptr<ContentLayer> mask_;
738 scoped_refptr<ContentLayer> content_with_mask_;
739 scoped_refptr<VideoLayer> video_color_;
740 scoped_refptr<VideoLayer> video_hw_;
741 scoped_refptr<VideoLayer> video_scaled_hw_;
742 scoped_refptr<IOSurfaceLayer> io_surface_;
743 scoped_refptr<HeadsUpDisplayLayer> hud_;
744 scoped_refptr<ScrollbarLayer> scrollbar_;
745
746 scoped_ptr<FakeVideoFrame> color_video_frame_;
747 scoped_ptr<FakeVideoFrame> hw_video_frame_;
748 scoped_ptr<FakeVideoFrame> scaled_hw_video_frame_;
749
750 FakeVideoFrameProvider color_frame_provider_;
751 FakeVideoFrameProvider hw_frame_provider_;
752 FakeVideoFrameProvider scaled_hw_frame_provider_;
753 };
754
755 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestDontUseLostResources)
756
757 } // namespace
758 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698