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

Side by Side Diff: trunk/src/ui/compositor/layer_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698