OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "cc/layers/layer.h" | 15 #include "cc/layers/layer.h" |
16 #include "cc/output/delegated_frame_data.h" | 16 #include "cc/output/delegated_frame_data.h" |
17 #include "cc/test/pixel_test_utils.h" | 17 #include "cc/test/pixel_test_utils.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "ui/compositor/compositor_observer.h" | 19 #include "ui/compositor/compositor_observer.h" |
20 #include "ui/compositor/compositor_setup.h" | |
21 #include "ui/compositor/layer.h" | 20 #include "ui/compositor/layer.h" |
22 #include "ui/compositor/layer_animation_sequence.h" | 21 #include "ui/compositor/layer_animation_sequence.h" |
23 #include "ui/compositor/layer_animator.h" | 22 #include "ui/compositor/layer_animator.h" |
24 #include "ui/compositor/test/test_compositor_host.h" | 23 #include "ui/compositor/test/test_compositor_host.h" |
25 #include "ui/compositor/test/test_layers.h" | 24 #include "ui/compositor/test/test_layers.h" |
26 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
27 #include "ui/gfx/codec/png_codec.h" | 26 #include "ui/gfx/codec/png_codec.h" |
28 #include "ui/gfx/gfx_paths.h" | 27 #include "ui/gfx/gfx_paths.h" |
29 #include "ui/gfx/skia_util.h" | 28 #include "ui/gfx/skia_util.h" |
30 | 29 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) { | 74 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) { |
76 test_data_directory_ = test_data_directory_.AppendASCII("compositor"); | 75 test_data_directory_ = test_data_directory_.AppendASCII("compositor"); |
77 } else { | 76 } else { |
78 LOG(ERROR) << "Could not open test data directory."; | 77 LOG(ERROR) << "Could not open test data directory."; |
79 } | 78 } |
80 } | 79 } |
81 virtual ~LayerWithRealCompositorTest() {} | 80 virtual ~LayerWithRealCompositorTest() {} |
82 | 81 |
83 // Overridden from testing::Test: | 82 // Overridden from testing::Test: |
84 virtual void SetUp() OVERRIDE { | 83 virtual void SetUp() OVERRIDE { |
85 DisableTestCompositor(); | 84 bool allow_test_contexts = false; |
| 85 Compositor::InitializeContextFactoryForTests(allow_test_contexts); |
| 86 Compositor::Initialize(); |
| 87 |
86 const gfx::Rect host_bounds(10, 10, 500, 500); | 88 const gfx::Rect host_bounds(10, 10, 500, 500); |
87 window_.reset(TestCompositorHost::Create(host_bounds)); | 89 window_.reset(TestCompositorHost::Create(host_bounds)); |
88 window_->Show(); | 90 window_->Show(); |
89 } | 91 } |
90 | 92 |
91 virtual void TearDown() OVERRIDE { | 93 virtual void TearDown() OVERRIDE { |
| 94 window_.reset(); |
| 95 Compositor::Terminate(); |
92 } | 96 } |
93 | 97 |
94 Compositor* GetCompositor() { | 98 Compositor* GetCompositor() { |
95 return window_->GetCompositor(); | 99 return window_->GetCompositor(); |
96 } | 100 } |
97 | 101 |
98 Layer* CreateLayer(LayerType type) { | 102 Layer* CreateLayer(LayerType type) { |
99 return new Layer(type); | 103 return new Layer(type); |
100 } | 104 } |
101 | 105 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 bool committed_; | 304 bool committed_; |
301 bool started_; | 305 bool started_; |
302 bool ended_; | 306 bool ended_; |
303 bool aborted_; | 307 bool aborted_; |
304 | 308 |
305 DISALLOW_COPY_AND_ASSIGN(TestCompositorObserver); | 309 DISALLOW_COPY_AND_ASSIGN(TestCompositorObserver); |
306 }; | 310 }; |
307 | 311 |
308 } // namespace | 312 } // namespace |
309 | 313 |
310 #if defined(OS_WIN) | 314 TEST_F(LayerWithRealCompositorTest, Draw) { |
311 // These are disabled on windows as they don't run correctly on the buildbot. | |
312 // Reenable once we move to the real compositor. | |
313 #define MAYBE_Delegate DISABLED_Delegate | |
314 #define MAYBE_Draw DISABLED_Draw | |
315 #define MAYBE_DrawTree DISABLED_DrawTree | |
316 #define MAYBE_Hierarchy DISABLED_Hierarchy | |
317 #define MAYBE_HierarchyNoTexture DISABLED_HierarchyNoTexture | |
318 #define MAYBE_DrawPixels DISABLED_DrawPixels | |
319 #define MAYBE_SetRootLayer DISABLED_SetRootLayer | |
320 #define MAYBE_CompositorObservers DISABLED_CompositorObservers | |
321 #define MAYBE_ModifyHierarchy DISABLED_ModifyHierarchy | |
322 #define MAYBE_Opacity DISABLED_Opacity | |
323 #define MAYBE_ScaleUpDown DISABLED_ScaleUpDown | |
324 #define MAYBE_ScaleReparent DISABLED_ScaleReparent | |
325 #define MAYBE_NoScaleCanvas DISABLED_NoScaleCanvas | |
326 #define MAYBE_AddRemoveThreadedAnimations DISABLED_AddRemoveThreadedAnimations | |
327 #define MAYBE_SwitchCCLayerAnimations DISABLED_SwitchCCLayerAnimations | |
328 #else | |
329 #define MAYBE_Delegate Delegate | |
330 #define MAYBE_Draw Draw | |
331 #define MAYBE_DrawTree DrawTree | |
332 #define MAYBE_Hierarchy Hierarchy | |
333 #define MAYBE_HierarchyNoTexture HierarchyNoTexture | |
334 #define MAYBE_DrawPixels DrawPixels | |
335 #define MAYBE_SetRootLayer SetRootLayer | |
336 #define MAYBE_CompositorObservers CompositorObservers | |
337 #define MAYBE_ModifyHierarchy ModifyHierarchy | |
338 #define MAYBE_Opacity Opacity | |
339 #define MAYBE_ScaleUpDown ScaleUpDown | |
340 #define MAYBE_ScaleReparent ScaleReparent | |
341 #define MAYBE_NoScaleCanvas NoScaleCanvas | |
342 #define MAYBE_AddRemoveThreadedAnimations AddRemoveThreadedAnimations | |
343 #define MAYBE_SwitchCCLayerAnimations SwitchCCLayerAnimations | |
344 #endif | |
345 | |
346 TEST_F(LayerWithRealCompositorTest, MAYBE_Draw) { | |
347 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, | 315 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, |
348 gfx::Rect(20, 20, 50, 50))); | 316 gfx::Rect(20, 20, 50, 50))); |
349 DrawTree(layer.get()); | 317 DrawTree(layer.get()); |
350 } | 318 } |
351 | 319 |
352 // Create this hierarchy: | 320 // Create this hierarchy: |
353 // L1 - red | 321 // L1 - red |
354 // +-- L2 - blue | 322 // +-- L2 - blue |
355 // | +-- L3 - yellow | 323 // | +-- L3 - yellow |
356 // +-- L4 - magenta | 324 // +-- L4 - magenta |
357 // | 325 // |
358 TEST_F(LayerWithRealCompositorTest, MAYBE_Hierarchy) { | 326 TEST_F(LayerWithRealCompositorTest, Hierarchy) { |
359 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 327 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, |
360 gfx::Rect(20, 20, 400, 400))); | 328 gfx::Rect(20, 20, 400, 400))); |
361 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, | 329 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, |
362 gfx::Rect(10, 10, 350, 350))); | 330 gfx::Rect(10, 10, 350, 350))); |
363 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, | 331 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, |
364 gfx::Rect(5, 5, 25, 25))); | 332 gfx::Rect(5, 5, 25, 25))); |
365 scoped_ptr<Layer> l4(CreateColorLayer(SK_ColorMAGENTA, | 333 scoped_ptr<Layer> l4(CreateColorLayer(SK_ColorMAGENTA, |
366 gfx::Rect(300, 300, 100, 100))); | 334 gfx::Rect(300, 300, 100, 100))); |
367 | 335 |
368 l1->Add(l2.get()); | 336 l1->Add(l2.get()); |
369 l1->Add(l4.get()); | 337 l1->Add(l4.get()); |
370 l2->Add(l3.get()); | 338 l2->Add(l3.get()); |
371 | 339 |
372 DrawTree(l1.get()); | 340 DrawTree(l1.get()); |
373 } | 341 } |
374 | 342 |
375 class LayerWithDelegateTest : public testing::Test, public CompositorDelegate { | 343 class LayerWithDelegateTest : public testing::Test, public CompositorDelegate { |
376 public: | 344 public: |
377 LayerWithDelegateTest() {} | 345 LayerWithDelegateTest() {} |
378 virtual ~LayerWithDelegateTest() {} | 346 virtual ~LayerWithDelegateTest() {} |
379 | 347 |
380 // Overridden from testing::Test: | 348 // Overridden from testing::Test: |
381 virtual void SetUp() OVERRIDE { | 349 virtual void SetUp() OVERRIDE { |
382 ui::SetupTestCompositor(); | 350 bool allow_test_contexts = true; |
| 351 Compositor::InitializeContextFactoryForTests(allow_test_contexts); |
| 352 Compositor::Initialize(); |
383 compositor_.reset(new Compositor(this, gfx::kNullAcceleratedWidget)); | 353 compositor_.reset(new Compositor(this, gfx::kNullAcceleratedWidget)); |
384 compositor_->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); | 354 compositor_->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); |
385 } | 355 } |
386 | 356 |
387 virtual void TearDown() OVERRIDE { | 357 virtual void TearDown() OVERRIDE { |
| 358 compositor_.reset(); |
| 359 Compositor::Terminate(); |
388 } | 360 } |
389 | 361 |
390 Compositor* compositor() { return compositor_.get(); } | 362 Compositor* compositor() { return compositor_.get(); } |
391 | 363 |
392 virtual Layer* CreateLayer(LayerType type) { | 364 virtual Layer* CreateLayer(LayerType type) { |
393 return new Layer(type); | 365 return new Layer(type); |
394 } | 366 } |
395 | 367 |
396 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { | 368 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { |
397 Layer* layer = new ColoredLayer(color); | 369 Layer* layer = new ColoredLayer(color); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 Layer::ConvertPointToLayer(l3.get(), l1.get(), &point1_in_l3_coords); | 456 Layer::ConvertPointToLayer(l3.get(), l1.get(), &point1_in_l3_coords); |
485 gfx::Point point1_in_l1_coords(25, 25); | 457 gfx::Point point1_in_l1_coords(25, 25); |
486 EXPECT_EQ(point1_in_l1_coords, point1_in_l3_coords); | 458 EXPECT_EQ(point1_in_l1_coords, point1_in_l3_coords); |
487 | 459 |
488 gfx::Point point2_in_l1_coords(5, 5); | 460 gfx::Point point2_in_l1_coords(5, 5); |
489 Layer::ConvertPointToLayer(l1.get(), l3.get(), &point2_in_l1_coords); | 461 Layer::ConvertPointToLayer(l1.get(), l3.get(), &point2_in_l1_coords); |
490 gfx::Point point2_in_l3_coords(-15, -15); | 462 gfx::Point point2_in_l3_coords(-15, -15); |
491 EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords); | 463 EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords); |
492 } | 464 } |
493 | 465 |
494 TEST_F(LayerWithRealCompositorTest, MAYBE_Delegate) { | 466 TEST_F(LayerWithRealCompositorTest, Delegate) { |
495 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorBLACK, | 467 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorBLACK, |
496 gfx::Rect(20, 20, 400, 400))); | 468 gfx::Rect(20, 20, 400, 400))); |
497 GetCompositor()->SetRootLayer(l1.get()); | 469 GetCompositor()->SetRootLayer(l1.get()); |
498 WaitForDraw(); | 470 WaitForDraw(); |
499 | 471 |
500 TestLayerDelegate delegate; | 472 TestLayerDelegate delegate; |
501 l1->set_delegate(&delegate); | 473 l1->set_delegate(&delegate); |
502 delegate.AddColor(SK_ColorWHITE); | 474 delegate.AddColor(SK_ColorWHITE); |
503 delegate.AddColor(SK_ColorYELLOW); | 475 delegate.AddColor(SK_ColorYELLOW); |
504 delegate.AddColor(SK_ColorGREEN); | 476 delegate.AddColor(SK_ColorGREEN); |
505 | 477 |
506 l1->SchedulePaint(gfx::Rect(0, 0, 400, 400)); | 478 l1->SchedulePaint(gfx::Rect(0, 0, 400, 400)); |
507 WaitForDraw(); | 479 WaitForDraw(); |
508 | 480 |
509 EXPECT_EQ(delegate.color_index(), 1); | 481 EXPECT_EQ(delegate.color_index(), 1); |
510 EXPECT_EQ(delegate.paint_size(), l1->bounds().size()); | 482 EXPECT_EQ(delegate.paint_size(), l1->bounds().size()); |
511 | 483 |
512 l1->SchedulePaint(gfx::Rect(10, 10, 200, 200)); | 484 l1->SchedulePaint(gfx::Rect(10, 10, 200, 200)); |
513 WaitForDraw(); | 485 WaitForDraw(); |
514 EXPECT_EQ(delegate.color_index(), 2); | 486 EXPECT_EQ(delegate.color_index(), 2); |
515 EXPECT_EQ(delegate.paint_size(), gfx::Size(200, 200)); | 487 EXPECT_EQ(delegate.paint_size(), gfx::Size(200, 200)); |
516 | 488 |
517 l1->SchedulePaint(gfx::Rect(5, 5, 50, 50)); | 489 l1->SchedulePaint(gfx::Rect(5, 5, 50, 50)); |
518 WaitForDraw(); | 490 WaitForDraw(); |
519 EXPECT_EQ(delegate.color_index(), 0); | 491 EXPECT_EQ(delegate.color_index(), 0); |
520 EXPECT_EQ(delegate.paint_size(), gfx::Size(50, 50)); | 492 EXPECT_EQ(delegate.paint_size(), gfx::Size(50, 50)); |
521 } | 493 } |
522 | 494 |
523 TEST_F(LayerWithRealCompositorTest, MAYBE_DrawTree) { | 495 TEST_F(LayerWithRealCompositorTest, DrawTree) { |
524 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 496 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, |
525 gfx::Rect(20, 20, 400, 400))); | 497 gfx::Rect(20, 20, 400, 400))); |
526 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, | 498 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, |
527 gfx::Rect(10, 10, 350, 350))); | 499 gfx::Rect(10, 10, 350, 350))); |
528 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, | 500 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, |
529 gfx::Rect(10, 10, 100, 100))); | 501 gfx::Rect(10, 10, 100, 100))); |
530 l1->Add(l2.get()); | 502 l1->Add(l2.get()); |
531 l2->Add(l3.get()); | 503 l2->Add(l3.get()); |
532 | 504 |
533 GetCompositor()->SetRootLayer(l1.get()); | 505 GetCompositor()->SetRootLayer(l1.get()); |
(...skipping 13 matching lines...) Expand all Loading... |
547 EXPECT_FALSE(d3.painted()); | 519 EXPECT_FALSE(d3.painted()); |
548 } | 520 } |
549 | 521 |
550 // Tests no-texture Layers. | 522 // Tests no-texture Layers. |
551 // Create this hierarchy: | 523 // Create this hierarchy: |
552 // L1 - red | 524 // L1 - red |
553 // +-- L2 - NO TEXTURE | 525 // +-- L2 - NO TEXTURE |
554 // | +-- L3 - yellow | 526 // | +-- L3 - yellow |
555 // +-- L4 - magenta | 527 // +-- L4 - magenta |
556 // | 528 // |
557 TEST_F(LayerWithRealCompositorTest, MAYBE_HierarchyNoTexture) { | 529 TEST_F(LayerWithRealCompositorTest, HierarchyNoTexture) { |
558 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 530 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, |
559 gfx::Rect(20, 20, 400, 400))); | 531 gfx::Rect(20, 20, 400, 400))); |
560 scoped_ptr<Layer> l2(CreateNoTextureLayer(gfx::Rect(10, 10, 350, 350))); | 532 scoped_ptr<Layer> l2(CreateNoTextureLayer(gfx::Rect(10, 10, 350, 350))); |
561 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, | 533 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, |
562 gfx::Rect(5, 5, 25, 25))); | 534 gfx::Rect(5, 5, 25, 25))); |
563 scoped_ptr<Layer> l4(CreateColorLayer(SK_ColorMAGENTA, | 535 scoped_ptr<Layer> l4(CreateColorLayer(SK_ColorMAGENTA, |
564 gfx::Rect(300, 300, 100, 100))); | 536 gfx::Rect(300, 300, 100, 100))); |
565 | 537 |
566 l1->Add(l2.get()); | 538 l1->Add(l2.get()); |
567 l1->Add(l4.get()); | 539 l1->Add(l4.get()); |
(...skipping 15 matching lines...) Expand all Loading... |
583 EXPECT_FALSE(d2.painted()); | 555 EXPECT_FALSE(d2.painted()); |
584 // |d3| should have received a paint notification. | 556 // |d3| should have received a paint notification. |
585 EXPECT_TRUE(d3.painted()); | 557 EXPECT_TRUE(d3.painted()); |
586 } | 558 } |
587 | 559 |
588 class LayerWithNullDelegateTest : public LayerWithDelegateTest { | 560 class LayerWithNullDelegateTest : public LayerWithDelegateTest { |
589 public: | 561 public: |
590 LayerWithNullDelegateTest() {} | 562 LayerWithNullDelegateTest() {} |
591 virtual ~LayerWithNullDelegateTest() {} | 563 virtual ~LayerWithNullDelegateTest() {} |
592 | 564 |
593 // Overridden from testing::Test: | |
594 virtual void SetUp() OVERRIDE { | 565 virtual void SetUp() OVERRIDE { |
595 LayerWithDelegateTest::SetUp(); | 566 LayerWithDelegateTest::SetUp(); |
596 default_layer_delegate_.reset(new NullLayerDelegate()); | 567 default_layer_delegate_.reset(new NullLayerDelegate()); |
597 } | 568 } |
598 | 569 |
599 virtual void TearDown() OVERRIDE { | |
600 } | |
601 | |
602 virtual Layer* CreateLayer(LayerType type) OVERRIDE { | 570 virtual Layer* CreateLayer(LayerType type) OVERRIDE { |
603 Layer* layer = new Layer(type); | 571 Layer* layer = new Layer(type); |
604 layer->set_delegate(default_layer_delegate_.get()); | 572 layer->set_delegate(default_layer_delegate_.get()); |
605 return layer; | 573 return layer; |
606 } | 574 } |
607 | 575 |
608 Layer* CreateTextureRootLayer(const gfx::Rect& bounds) { | 576 Layer* CreateTextureRootLayer(const gfx::Rect& bounds) { |
609 Layer* layer = CreateTextureLayer(bounds); | 577 Layer* layer = CreateTextureLayer(bounds); |
610 compositor()->SetRootLayer(layer); | 578 compositor()->SetRootLayer(layer); |
611 return layer; | 579 return layer; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 // The CompositorDelegate (us) should have been told to draw for a move. | 762 // The CompositorDelegate (us) should have been told to draw for a move. |
795 WaitForDraw(); | 763 WaitForDraw(); |
796 | 764 |
797 l1->SetBounds(gfx::Rect(5, 5, 100, 100)); | 765 l1->SetBounds(gfx::Rect(5, 5, 100, 100)); |
798 | 766 |
799 // The CompositorDelegate (us) should have been told to draw for a resize. | 767 // The CompositorDelegate (us) should have been told to draw for a resize. |
800 WaitForDraw(); | 768 WaitForDraw(); |
801 } | 769 } |
802 | 770 |
803 // Checks that pixels are actually drawn to the screen with a read back. | 771 // Checks that pixels are actually drawn to the screen with a read back. |
804 // Currently disabled on all platforms, see http://crbug.com/148709. | 772 TEST_F(LayerWithRealCompositorTest, DrawPixels) { |
805 TEST_F(LayerWithRealCompositorTest, MAYBE_DrawPixels) { | 773 gfx::Size viewport_size = GetCompositor()->size(); |
806 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, | 774 |
807 gfx::Rect(0, 0, 500, 500))); | 775 // The window should be some non-trivial size but may not be exactly |
808 scoped_ptr<Layer> layer2(CreateColorLayer(SK_ColorBLUE, | 776 // 500x500 on all platforms/bots. |
809 gfx::Rect(0, 0, 500, 10))); | 777 EXPECT_GE(viewport_size.width(), 200); |
| 778 EXPECT_GE(viewport_size.height(), 200); |
| 779 |
| 780 int blue_height = 10; |
| 781 |
| 782 scoped_ptr<Layer> layer( |
| 783 CreateColorLayer(SK_ColorRED, gfx::Rect(viewport_size))); |
| 784 scoped_ptr<Layer> layer2( |
| 785 CreateColorLayer(SK_ColorBLUE, |
| 786 gfx::Rect(0, 0, viewport_size.width(), blue_height))); |
810 | 787 |
811 layer->Add(layer2.get()); | 788 layer->Add(layer2.get()); |
812 | 789 |
813 DrawTree(layer.get()); | 790 DrawTree(layer.get()); |
814 | 791 |
815 SkBitmap bitmap; | 792 SkBitmap bitmap; |
816 gfx::Size size = GetCompositor()->size(); | 793 ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap, gfx::Rect(viewport_size))); |
817 ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap, | |
818 gfx::Rect(0, 10, | |
819 size.width(), size.height() - 10))); | |
820 ASSERT_FALSE(bitmap.empty()); | 794 ASSERT_FALSE(bitmap.empty()); |
821 | 795 |
822 SkAutoLockPixels lock(bitmap); | 796 SkAutoLockPixels lock(bitmap); |
823 bool is_all_red = true; | 797 for (int x = 0; x < viewport_size.width(); x++) { |
824 for (int x = 0; is_all_red && x < 500; x++) | 798 for (int y = 0; y < viewport_size.height(); y++) { |
825 for (int y = 0; is_all_red && y < 490; y++) | 799 SkColor actual_color = bitmap.getColor(x, y); |
826 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED); | 800 SkColor expected_color = y < blue_height ? SK_ColorBLUE : SK_ColorRED; |
827 | 801 EXPECT_EQ(expected_color, actual_color) |
828 EXPECT_TRUE(is_all_red); | 802 << "Pixel error at x=" << x << " y=" << y << "; " |
| 803 << "actual RGBA=(" |
| 804 << SkColorGetR(actual_color) << "," |
| 805 << SkColorGetG(actual_color) << "," |
| 806 << SkColorGetB(actual_color) << "," |
| 807 << SkColorGetA(actual_color) << "); " |
| 808 << "expected RGBA=(" |
| 809 << SkColorGetR(expected_color) << "," |
| 810 << SkColorGetG(expected_color) << "," |
| 811 << SkColorGetB(expected_color) << "," |
| 812 << SkColorGetA(expected_color) << ")"; |
| 813 } |
| 814 } |
829 } | 815 } |
830 | 816 |
831 // Checks the logic around Compositor::SetRootLayer and Layer::SetCompositor. | 817 // Checks the logic around Compositor::SetRootLayer and Layer::SetCompositor. |
832 TEST_F(LayerWithRealCompositorTest, MAYBE_SetRootLayer) { | 818 TEST_F(LayerWithRealCompositorTest, SetRootLayer) { |
833 Compositor* compositor = GetCompositor(); | 819 Compositor* compositor = GetCompositor(); |
834 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 820 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, |
835 gfx::Rect(20, 20, 400, 400))); | 821 gfx::Rect(20, 20, 400, 400))); |
836 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, | 822 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, |
837 gfx::Rect(10, 10, 350, 350))); | 823 gfx::Rect(10, 10, 350, 350))); |
838 | 824 |
839 EXPECT_EQ(NULL, l1->GetCompositor()); | 825 EXPECT_EQ(NULL, l1->GetCompositor()); |
840 EXPECT_EQ(NULL, l2->GetCompositor()); | 826 EXPECT_EQ(NULL, l2->GetCompositor()); |
841 | 827 |
842 compositor->SetRootLayer(l1.get()); | 828 compositor->SetRootLayer(l1.get()); |
(...skipping 11 matching lines...) Expand all Loading... |
854 compositor->SetRootLayer(NULL); | 840 compositor->SetRootLayer(NULL); |
855 EXPECT_EQ(NULL, l1->GetCompositor()); | 841 EXPECT_EQ(NULL, l1->GetCompositor()); |
856 EXPECT_EQ(NULL, l2->GetCompositor()); | 842 EXPECT_EQ(NULL, l2->GetCompositor()); |
857 } | 843 } |
858 | 844 |
859 // Checks that compositor observers are notified when: | 845 // Checks that compositor observers are notified when: |
860 // - DrawTree is called, | 846 // - DrawTree is called, |
861 // - After ScheduleDraw is called, or | 847 // - After ScheduleDraw is called, or |
862 // - Whenever SetBounds, SetOpacity or SetTransform are called. | 848 // - Whenever SetBounds, SetOpacity or SetTransform are called. |
863 // TODO(vollick): could be reorganized into compositor_unittest.cc | 849 // TODO(vollick): could be reorganized into compositor_unittest.cc |
864 TEST_F(LayerWithRealCompositorTest, MAYBE_CompositorObservers) { | 850 TEST_F(LayerWithRealCompositorTest, CompositorObservers) { |
865 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, | 851 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, |
866 gfx::Rect(20, 20, 400, 400))); | 852 gfx::Rect(20, 20, 400, 400))); |
867 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, | 853 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, |
868 gfx::Rect(10, 10, 350, 350))); | 854 gfx::Rect(10, 10, 350, 350))); |
869 l1->Add(l2.get()); | 855 l1->Add(l2.get()); |
870 TestCompositorObserver observer; | 856 TestCompositorObserver observer; |
871 GetCompositor()->AddObserver(&observer); | 857 GetCompositor()->AddObserver(&observer); |
872 | 858 |
873 // Explicitly called DrawTree should cause the observers to be notified. | 859 // Explicitly called DrawTree should cause the observers to be notified. |
874 // NOTE: this call to DrawTree sets l1 to be the compositor's root layer. | 860 // NOTE: this call to DrawTree sets l1 to be the compositor's root layer. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 | 914 |
929 // Opacity changes should no longer alert the removed observer. | 915 // Opacity changes should no longer alert the removed observer. |
930 observer.Reset(); | 916 observer.Reset(); |
931 l2->SetOpacity(0.5f); | 917 l2->SetOpacity(0.5f); |
932 WaitForDraw(); | 918 WaitForDraw(); |
933 | 919 |
934 EXPECT_FALSE(observer.notified()); | 920 EXPECT_FALSE(observer.notified()); |
935 } | 921 } |
936 | 922 |
937 // Checks that modifying the hierarchy correctly affects final composite. | 923 // Checks that modifying the hierarchy correctly affects final composite. |
938 TEST_F(LayerWithRealCompositorTest, MAYBE_ModifyHierarchy) { | 924 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) { |
939 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); | 925 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); |
940 | 926 |
941 // l0 | 927 // l0 |
942 // +-l11 | 928 // +-l11 |
943 // | +-l21 | 929 // | +-l21 |
944 // +-l12 | 930 // +-l12 |
945 scoped_ptr<Layer> l0(CreateColorLayer(SK_ColorRED, | 931 scoped_ptr<Layer> l0(CreateColorLayer(SK_ColorRED, |
946 gfx::Rect(0, 0, 50, 50))); | 932 gfx::Rect(0, 0, 50, 50))); |
947 scoped_ptr<Layer> l11(CreateColorLayer(SK_ColorGREEN, | 933 scoped_ptr<Layer> l11(CreateColorLayer(SK_ColorGREEN, |
948 gfx::Rect(0, 0, 25, 25))); | 934 gfx::Rect(0, 0, 25, 25))); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 // l11 back to front | 983 // l11 back to front |
998 l0->StackAbove(l11.get(), l12.get()); | 984 l0->StackAbove(l11.get(), l12.get()); |
999 DrawTree(l0.get()); | 985 DrawTree(l0.get()); |
1000 ASSERT_TRUE(ReadPixels(&bitmap)); | 986 ASSERT_TRUE(ReadPixels(&bitmap)); |
1001 ASSERT_FALSE(bitmap.empty()); | 987 ASSERT_FALSE(bitmap.empty()); |
1002 EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2, cc::ExactPixelComparator(true))); | 988 EXPECT_TRUE(MatchesPNGFile(bitmap, ref_img2, cc::ExactPixelComparator(true))); |
1003 } | 989 } |
1004 | 990 |
1005 // Opacity is rendered correctly. | 991 // Opacity is rendered correctly. |
1006 // Checks that modifying the hierarchy correctly affects final composite. | 992 // Checks that modifying the hierarchy correctly affects final composite. |
1007 TEST_F(LayerWithRealCompositorTest, MAYBE_Opacity) { | 993 TEST_F(LayerWithRealCompositorTest, Opacity) { |
1008 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); | 994 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); |
1009 | 995 |
1010 // l0 | 996 // l0 |
1011 // +-l11 | 997 // +-l11 |
1012 scoped_ptr<Layer> l0(CreateColorLayer(SK_ColorRED, | 998 scoped_ptr<Layer> l0(CreateColorLayer(SK_ColorRED, |
1013 gfx::Rect(0, 0, 50, 50))); | 999 gfx::Rect(0, 0, 50, 50))); |
1014 scoped_ptr<Layer> l11(CreateColorLayer(SK_ColorGREEN, | 1000 scoped_ptr<Layer> l11(CreateColorLayer(SK_ColorGREEN, |
1015 gfx::Rect(0, 0, 25, 25))); | 1001 gfx::Rect(0, 0, 25, 25))); |
1016 | 1002 |
1017 base::FilePath ref_img = test_data_directory().AppendASCII("Opacity.png"); | 1003 base::FilePath ref_img = test_data_directory().AppendASCII("Opacity.png"); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear()); | 1091 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear()); |
1106 | 1092 |
1107 // Because SchedulePaint() was invoked from OnPaintLayer() |child| should | 1093 // Because SchedulePaint() was invoked from OnPaintLayer() |child| should |
1108 // still need to be painted. | 1094 // still need to be painted. |
1109 WaitForCommit(); | 1095 WaitForCommit(); |
1110 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear()); | 1096 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear()); |
1111 EXPECT_TRUE(child_delegate.last_clip_rect().Contains( | 1097 EXPECT_TRUE(child_delegate.last_clip_rect().Contains( |
1112 gfx::Rect(10, 10, 30, 30))); | 1098 gfx::Rect(10, 10, 30, 30))); |
1113 } | 1099 } |
1114 | 1100 |
1115 TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleUpDown) { | 1101 TEST_F(LayerWithRealCompositorTest, ScaleUpDown) { |
1116 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, | 1102 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, |
1117 gfx::Rect(10, 20, 200, 220))); | 1103 gfx::Rect(10, 20, 200, 220))); |
1118 TestLayerDelegate root_delegate; | 1104 TestLayerDelegate root_delegate; |
1119 root_delegate.AddColor(SK_ColorWHITE); | 1105 root_delegate.AddColor(SK_ColorWHITE); |
1120 root->set_delegate(&root_delegate); | 1106 root->set_delegate(&root_delegate); |
1121 | 1107 |
1122 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, | 1108 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, |
1123 gfx::Rect(10, 20, 140, 180))); | 1109 gfx::Rect(10, 20, 140, 180))); |
1124 TestLayerDelegate l1_delegate; | 1110 TestLayerDelegate l1_delegate; |
1125 l1_delegate.AddColor(SK_ColorWHITE); | 1111 l1_delegate.AddColor(SK_ColorWHITE); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 // No scale change, so no scale notification. | 1177 // No scale change, so no scale notification. |
1192 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); | 1178 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); |
1193 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); | 1179 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); |
1194 WaitForDraw(); | 1180 WaitForDraw(); |
1195 EXPECT_EQ("0x0", root_delegate.paint_size().ToString()); | 1181 EXPECT_EQ("0x0", root_delegate.paint_size().ToString()); |
1196 EXPECT_EQ("0.0 0.0", root_delegate.ToScaleString()); | 1182 EXPECT_EQ("0.0 0.0", root_delegate.ToScaleString()); |
1197 EXPECT_EQ("0x0", l1_delegate.paint_size().ToString()); | 1183 EXPECT_EQ("0x0", l1_delegate.paint_size().ToString()); |
1198 EXPECT_EQ("0.0 0.0", l1_delegate.ToScaleString()); | 1184 EXPECT_EQ("0.0 0.0", l1_delegate.ToScaleString()); |
1199 } | 1185 } |
1200 | 1186 |
1201 TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleReparent) { | 1187 TEST_F(LayerWithRealCompositorTest, ScaleReparent) { |
1202 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, | 1188 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, |
1203 gfx::Rect(10, 20, 200, 220))); | 1189 gfx::Rect(10, 20, 200, 220))); |
1204 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, | 1190 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, |
1205 gfx::Rect(10, 20, 140, 180))); | 1191 gfx::Rect(10, 20, 140, 180))); |
1206 TestLayerDelegate l1_delegate; | 1192 TestLayerDelegate l1_delegate; |
1207 l1_delegate.AddColor(SK_ColorWHITE); | 1193 l1_delegate.AddColor(SK_ColorWHITE); |
1208 l1->set_delegate(&l1_delegate); | 1194 l1->set_delegate(&l1_delegate); |
1209 | 1195 |
1210 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); | 1196 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); |
1211 GetCompositor()->SetRootLayer(root.get()); | 1197 GetCompositor()->SetRootLayer(root.get()); |
(...skipping 24 matching lines...) Expand all Loading... |
1236 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); | 1222 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); |
1237 size_in_pixel = l1->cc_layer()->bounds(); | 1223 size_in_pixel = l1->cc_layer()->bounds(); |
1238 EXPECT_EQ("280x360", size_in_pixel.ToString()); | 1224 EXPECT_EQ("280x360", size_in_pixel.ToString()); |
1239 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); | 1225 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); |
1240 WaitForDraw(); | 1226 WaitForDraw(); |
1241 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); | 1227 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); |
1242 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); | 1228 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); |
1243 } | 1229 } |
1244 | 1230 |
1245 // Tests layer::set_scale_content(false). | 1231 // Tests layer::set_scale_content(false). |
1246 TEST_F(LayerWithRealCompositorTest, MAYBE_NoScaleCanvas) { | 1232 TEST_F(LayerWithRealCompositorTest, NoScaleCanvas) { |
1247 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, | 1233 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, |
1248 gfx::Rect(10, 20, 200, 220))); | 1234 gfx::Rect(10, 20, 200, 220))); |
1249 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, | 1235 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, |
1250 gfx::Rect(10, 20, 140, 180))); | 1236 gfx::Rect(10, 20, 140, 180))); |
1251 l1->set_scale_content(false); | 1237 l1->set_scale_content(false); |
1252 root->Add(l1.get()); | 1238 root->Add(l1.get()); |
1253 TestLayerDelegate l1_delegate; | 1239 TestLayerDelegate l1_delegate; |
1254 l1_delegate.AddColor(SK_ColorWHITE); | 1240 l1_delegate.AddColor(SK_ColorWHITE); |
1255 l1->set_delegate(&l1_delegate); | 1241 l1->set_delegate(&l1_delegate); |
1256 | 1242 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1351 EXPECT_EQ(child->cc_layer()->bounds().ToString(), | 1337 EXPECT_EQ(child->cc_layer()->bounds().ToString(), |
1352 gfx::Size(20, 20).ToString()); | 1338 gfx::Size(20, 20).ToString()); |
1353 | 1339 |
1354 // Low-DPI content on hi-DPI layer. | 1340 // Low-DPI content on hi-DPI layer. |
1355 child->SetDelegatedFrame(MakeFrameData(gfx::Size(10, 10)), gfx::Size(10, 10)); | 1341 child->SetDelegatedFrame(MakeFrameData(gfx::Size(10, 10)), gfx::Size(10, 10)); |
1356 EXPECT_EQ(child->cc_layer()->bounds().ToString(), | 1342 EXPECT_EQ(child->cc_layer()->bounds().ToString(), |
1357 gfx::Size(20, 20).ToString()); | 1343 gfx::Size(20, 20).ToString()); |
1358 } | 1344 } |
1359 | 1345 |
1360 // Tests Layer::AddThreadedAnimation and Layer::RemoveThreadedAnimation. | 1346 // Tests Layer::AddThreadedAnimation and Layer::RemoveThreadedAnimation. |
1361 TEST_F(LayerWithRealCompositorTest, MAYBE_AddRemoveThreadedAnimations) { | 1347 TEST_F(LayerWithRealCompositorTest, AddRemoveThreadedAnimations) { |
1362 scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); | 1348 scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); |
1363 scoped_ptr<Layer> l1(CreateLayer(LAYER_TEXTURED)); | 1349 scoped_ptr<Layer> l1(CreateLayer(LAYER_TEXTURED)); |
1364 scoped_ptr<Layer> l2(CreateLayer(LAYER_TEXTURED)); | 1350 scoped_ptr<Layer> l2(CreateLayer(LAYER_TEXTURED)); |
1365 | 1351 |
1366 l1->SetAnimator(LayerAnimator::CreateImplicitAnimator()); | 1352 l1->SetAnimator(LayerAnimator::CreateImplicitAnimator()); |
1367 l2->SetAnimator(LayerAnimator::CreateImplicitAnimator()); | 1353 l2->SetAnimator(LayerAnimator::CreateImplicitAnimator()); |
1368 | 1354 |
1369 EXPECT_FALSE(l1->HasPendingThreadedAnimations()); | 1355 EXPECT_FALSE(l1->HasPendingThreadedAnimations()); |
1370 | 1356 |
1371 // Trigger a threaded animation. | 1357 // Trigger a threaded animation. |
(...skipping 26 matching lines...) Expand all Loading... |
1398 // animations to get dispatched. | 1384 // animations to get dispatched. |
1399 l2->SetOpacity(0.5f); | 1385 l2->SetOpacity(0.5f); |
1400 EXPECT_TRUE(l2->HasPendingThreadedAnimations()); | 1386 EXPECT_TRUE(l2->HasPendingThreadedAnimations()); |
1401 | 1387 |
1402 l1->Add(l2.get()); | 1388 l1->Add(l2.get()); |
1403 EXPECT_FALSE(l2->HasPendingThreadedAnimations()); | 1389 EXPECT_FALSE(l2->HasPendingThreadedAnimations()); |
1404 } | 1390 } |
1405 | 1391 |
1406 // Tests that in-progress threaded animations complete when a Layer's | 1392 // Tests that in-progress threaded animations complete when a Layer's |
1407 // cc::Layer changes. | 1393 // cc::Layer changes. |
1408 TEST_F(LayerWithRealCompositorTest, MAYBE_SwitchCCLayerAnimations) { | 1394 TEST_F(LayerWithRealCompositorTest, SwitchCCLayerAnimations) { |
1409 scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); | 1395 scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); |
1410 scoped_ptr<Layer> l1(CreateLayer(LAYER_TEXTURED)); | 1396 scoped_ptr<Layer> l1(CreateLayer(LAYER_TEXTURED)); |
1411 GetCompositor()->SetRootLayer(root.get()); | 1397 GetCompositor()->SetRootLayer(root.get()); |
1412 root->Add(l1.get()); | 1398 root->Add(l1.get()); |
1413 | 1399 |
1414 l1->SetAnimator(LayerAnimator::CreateImplicitAnimator()); | 1400 l1->SetAnimator(LayerAnimator::CreateImplicitAnimator()); |
1415 | 1401 |
1416 EXPECT_FLOAT_EQ(l1->opacity(), 1.0f); | 1402 EXPECT_FLOAT_EQ(l1->opacity(), 1.0f); |
1417 | 1403 |
1418 // Trigger a threaded animation. | 1404 // Trigger a threaded animation. |
1419 l1->SetOpacity(0.5f); | 1405 l1->SetOpacity(0.5f); |
1420 | 1406 |
1421 // Change l1's cc::Layer. | 1407 // Change l1's cc::Layer. |
1422 l1->SwitchCCLayerForTest(); | 1408 l1->SwitchCCLayerForTest(); |
1423 | 1409 |
1424 // Ensure that the opacity animation completed. | 1410 // Ensure that the opacity animation completed. |
1425 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); | 1411 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); |
1426 } | 1412 } |
1427 | 1413 |
1428 } // namespace ui | 1414 } // namespace ui |
OLD | NEW |