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

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

Issue 13555004: Aura: Make compositor_unittests work with --ui-enable-threaded-compositing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Set the delegates. DCHECK not called if threaded. Created 7 years, 8 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 | « ui/compositor/compositor.cc ('k') | ui/compositor/test/test_compositor_host_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/cancelable_callback.h" 7 #include "base/cancelable_callback.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 81 }
82 82
83 private: 83 private:
84 SkColor color_; 84 SkColor color_;
85 }; 85 };
86 86
87 const int kDrawWaitTimeOutMs = 1000; 87 const int kDrawWaitTimeOutMs = 1000;
88 88
89 class DrawWaiter : public ui::CompositorObserver { 89 class DrawWaiter : public ui::CompositorObserver {
90 public: 90 public:
91 DrawWaiter() {} 91 DrawWaiter() : did_draw_(false) {}
92 92
93 void Wait(ui::Compositor* compositor) { 93 bool Wait(ui::Compositor* compositor) {
94 did_draw_ = false;
94 compositor->AddObserver(this); 95 compositor->AddObserver(this);
95 wait_run_loop_.reset(new base::RunLoop()); 96 wait_run_loop_.reset(new base::RunLoop());
96 base::CancelableClosure timeout( 97 base::CancelableClosure timeout(
97 base::Bind(&DrawWaiter::TimedOutWhileWaiting, 98 base::Bind(&DrawWaiter::TimedOutWhileWaiting,
98 base::Unretained(this))); 99 base::Unretained(this)));
99 MessageLoop::current()->PostDelayedTask( 100 MessageLoop::current()->PostDelayedTask(
100 FROM_HERE, timeout.callback(), 101 FROM_HERE, timeout.callback(),
101 base::TimeDelta::FromMilliseconds(kDrawWaitTimeOutMs)); 102 base::TimeDelta::FromMilliseconds(kDrawWaitTimeOutMs));
102 wait_run_loop_->Run(); 103 wait_run_loop_->Run();
103 compositor->RemoveObserver(this); 104 compositor->RemoveObserver(this);
105 return did_draw_;
104 } 106 }
105 107
106 private: 108 private:
107 void TimedOutWhileWaiting() { 109 void TimedOutWhileWaiting() {
108 LOG(ERROR) << "Timed out waiting for draw."; 110 LOG(ERROR) << "Timed out waiting for draw.";
109 wait_run_loop_->Quit(); 111 wait_run_loop_->Quit();
110 } 112 }
111 113
112 // ui::CompositorObserver implementation. 114 // ui::CompositorObserver implementation.
113 virtual void OnCompositingDidCommit(Compositor* compositor) OVERRIDE {} 115 virtual void OnCompositingDidCommit(Compositor* compositor) OVERRIDE {}
114 virtual void OnCompositingStarted(Compositor* compositor, 116 virtual void OnCompositingStarted(Compositor* compositor,
115 base::TimeTicks start_time) OVERRIDE {} 117 base::TimeTicks start_time) OVERRIDE {}
116 virtual void OnCompositingEnded(Compositor* compositor) OVERRIDE { 118 virtual void OnCompositingEnded(Compositor* compositor) OVERRIDE {
119 did_draw_ = true;
117 wait_run_loop_->Quit(); 120 wait_run_loop_->Quit();
118 } 121 }
119 virtual void OnCompositingAborted(Compositor* compositor) OVERRIDE {} 122 virtual void OnCompositingAborted(Compositor* compositor) OVERRIDE {}
120 virtual void OnCompositingLockStateChanged(Compositor* compositor) OVERRIDE {} 123 virtual void OnCompositingLockStateChanged(Compositor* compositor) OVERRIDE {}
121 virtual void OnUpdateVSyncParameters(Compositor* compositor, 124 virtual void OnUpdateVSyncParameters(Compositor* compositor,
122 base::TimeTicks timebase, 125 base::TimeTicks timebase,
123 base::TimeDelta interval) OVERRIDE {} 126 base::TimeDelta interval) OVERRIDE {}
124 127
125 scoped_ptr<base::RunLoop> wait_run_loop_; 128 scoped_ptr<base::RunLoop> wait_run_loop_;
129 bool did_draw_;
126 130
127 DISALLOW_COPY_AND_ASSIGN(DrawWaiter); 131 DISALLOW_COPY_AND_ASSIGN(DrawWaiter);
128 }; 132 };
129 133
130 class LayerWithRealCompositorTest : public testing::Test { 134 class LayerWithRealCompositorTest : public testing::Test {
131 public: 135 public:
132 LayerWithRealCompositorTest() { 136 LayerWithRealCompositorTest() {
133 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) { 137 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) {
134 test_data_directory_ = test_data_directory_.AppendASCII("compositor"); 138 test_data_directory_ = test_data_directory_.AppendASCII("compositor");
135 } else { 139 } else {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 GetCompositor()->SetRootLayer(root); 177 GetCompositor()->SetRootLayer(root);
174 GetCompositor()->ScheduleDraw(); 178 GetCompositor()->ScheduleDraw();
175 WaitForDraw(); 179 WaitForDraw();
176 } 180 }
177 181
178 bool ReadPixels(SkBitmap* bitmap) { 182 bool ReadPixels(SkBitmap* bitmap) {
179 return GetCompositor()->ReadPixels(bitmap, 183 return GetCompositor()->ReadPixels(bitmap,
180 gfx::Rect(GetCompositor()->size())); 184 gfx::Rect(GetCompositor()->size()));
181 } 185 }
182 186
183 void WaitForDraw() { 187 bool WaitForDraw() {
184 DrawWaiter draw_waiter; 188 DrawWaiter draw_waiter;
185 draw_waiter.Wait(GetCompositor()); 189 return draw_waiter.Wait(GetCompositor());
186 } 190 }
187 191
188 // Invalidates the entire contents of the layer. 192 // Invalidates the entire contents of the layer.
189 void SchedulePaintForLayer(Layer* layer) { 193 void SchedulePaintForLayer(Layer* layer) {
190 layer->SchedulePaint( 194 layer->SchedulePaint(
191 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); 195 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
192 } 196 }
193 197
194 const base::FilePath& test_data_directory() const { 198 const base::FilePath& test_data_directory() const {
195 return test_data_directory_; 199 return test_data_directory_;
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 422
419 l1->Add(l2.get()); 423 l1->Add(l2.get());
420 l1->Add(l4.get()); 424 l1->Add(l4.get());
421 l2->Add(l3.get()); 425 l2->Add(l3.get());
422 426
423 DrawTree(l1.get()); 427 DrawTree(l1.get());
424 } 428 }
425 429
426 class LayerWithDelegateTest : public testing::Test, public CompositorDelegate { 430 class LayerWithDelegateTest : public testing::Test, public CompositorDelegate {
427 public: 431 public:
428 LayerWithDelegateTest() : schedule_draw_invoked_(false) {} 432 LayerWithDelegateTest() {}
429 virtual ~LayerWithDelegateTest() {} 433 virtual ~LayerWithDelegateTest() {}
430 434
431 // Overridden from testing::Test: 435 // Overridden from testing::Test:
432 virtual void SetUp() OVERRIDE { 436 virtual void SetUp() OVERRIDE {
433 ui::SetupTestCompositor(); 437 ui::SetupTestCompositor();
434 compositor_.reset(new Compositor( 438 compositor_.reset(new Compositor(this, gfx::kNullAcceleratedWidget));
435 this, gfx::kNullAcceleratedWidget));
436 compositor_->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); 439 compositor_->SetScaleAndSize(1.0f, gfx::Size(1000, 1000));
437 } 440 }
438 441
439 virtual void TearDown() OVERRIDE { 442 virtual void TearDown() OVERRIDE {
440 } 443 }
441 444
442 Compositor* compositor() { return compositor_.get(); } 445 Compositor* compositor() { return compositor_.get(); }
443 446
444 virtual Layer* CreateLayer(LayerType type) { 447 virtual Layer* CreateLayer(LayerType type) {
445 return new Layer(type); 448 return new Layer(type);
446 } 449 }
447 450
448 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { 451 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
449 Layer* layer = new ColoredLayer(color); 452 Layer* layer = new ColoredLayer(color);
450 layer->SetBounds(bounds); 453 layer->SetBounds(bounds);
451 return layer; 454 return layer;
452 } 455 }
453 456
454 virtual Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { 457 virtual Layer* CreateNoTextureLayer(const gfx::Rect& bounds) {
455 Layer* layer = CreateLayer(LAYER_NOT_DRAWN); 458 Layer* layer = CreateLayer(LAYER_NOT_DRAWN);
456 layer->SetBounds(bounds); 459 layer->SetBounds(bounds);
457 return layer; 460 return layer;
458 } 461 }
459 462
460 void DrawTree(Layer* root) { 463 void DrawTree(Layer* root) {
461 compositor()->SetRootLayer(root); 464 compositor()->SetRootLayer(root);
462 compositor()->Draw(false); 465 Draw();
463 } 466 }
464 467
465 // Invalidates the entire contents of the layer. 468 // Invalidates the entire contents of the layer.
466 void SchedulePaintForLayer(Layer* layer) { 469 void SchedulePaintForLayer(Layer* layer) {
467 layer->SchedulePaint( 470 layer->SchedulePaint(
468 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); 471 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
469 } 472 }
470 473
471 // Invokes DrawTree on the compositor. 474 // Invokes DrawTree on the compositor.
472 void Draw() { 475 void Draw() {
473 compositor_->Draw(false); 476 compositor()->ScheduleDraw();
477 WaitForDraw();
478 }
479
480 bool WaitForDraw() {
481 DrawWaiter draw_waiter;
482 return draw_waiter.Wait(compositor());
474 } 483 }
475 484
476 // CompositorDelegate overrides. 485 // CompositorDelegate overrides.
477 virtual void ScheduleDraw() OVERRIDE { 486 virtual void ScheduleDraw() OVERRIDE {
478 schedule_draw_invoked_ = true; 487 DCHECK(!ui::Compositor::WasInitializedWithThread());
488 if (compositor_) {
489 MessageLoop::current()->PostTask(
490 FROM_HERE,
491 base::Bind(&Compositor::Draw, compositor_->AsWeakPtr(), false));
492 }
479 } 493 }
480 494
481 protected:
482 // Set to true when ScheduleDraw (CompositorDelegate override) is invoked.
483 bool schedule_draw_invoked_;
484
485 private: 495 private:
486 scoped_ptr<Compositor> compositor_; 496 scoped_ptr<Compositor> compositor_;
487 497
488 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest); 498 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest);
489 }; 499 };
490 500
491 // L1 501 // L1
492 // +-- L2 502 // +-- L2
493 TEST_F(LayerWithDelegateTest, ConvertPointToLayer_Simple) { 503 TEST_F(LayerWithDelegateTest, ConvertPointToLayer_Simple) {
494 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, 504 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 gfx::Point point2_in_l1_coords(5, 5); 541 gfx::Point point2_in_l1_coords(5, 5);
532 Layer::ConvertPointToLayer(l1.get(), l3.get(), &point2_in_l1_coords); 542 Layer::ConvertPointToLayer(l1.get(), l3.get(), &point2_in_l1_coords);
533 gfx::Point point2_in_l3_coords(-15, -15); 543 gfx::Point point2_in_l3_coords(-15, -15);
534 EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords); 544 EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords);
535 } 545 }
536 546
537 TEST_F(LayerWithRealCompositorTest, MAYBE_Delegate) { 547 TEST_F(LayerWithRealCompositorTest, MAYBE_Delegate) {
538 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorBLACK, 548 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorBLACK,
539 gfx::Rect(20, 20, 400, 400))); 549 gfx::Rect(20, 20, 400, 400)));
540 GetCompositor()->SetRootLayer(l1.get()); 550 GetCompositor()->SetRootLayer(l1.get());
541 WaitForDraw(); 551 EXPECT_TRUE(WaitForDraw());
542 552
543 TestLayerDelegate delegate; 553 TestLayerDelegate delegate;
544 l1->set_delegate(&delegate); 554 l1->set_delegate(&delegate);
545 delegate.AddColor(SK_ColorWHITE); 555 delegate.AddColor(SK_ColorWHITE);
546 delegate.AddColor(SK_ColorYELLOW); 556 delegate.AddColor(SK_ColorYELLOW);
547 delegate.AddColor(SK_ColorGREEN); 557 delegate.AddColor(SK_ColorGREEN);
548 558
549 l1->SchedulePaint(gfx::Rect(0, 0, 400, 400)); 559 l1->SchedulePaint(gfx::Rect(0, 0, 400, 400));
550 WaitForDraw(); 560 EXPECT_TRUE(WaitForDraw());
551 561
552 EXPECT_EQ(delegate.color_index(), 1); 562 EXPECT_EQ(delegate.color_index(), 1);
553 EXPECT_EQ(delegate.paint_size(), l1->bounds().size()); 563 EXPECT_EQ(delegate.paint_size(), l1->bounds().size());
554 564
555 l1->SchedulePaint(gfx::Rect(10, 10, 200, 200)); 565 l1->SchedulePaint(gfx::Rect(10, 10, 200, 200));
556 WaitForDraw(); 566 EXPECT_TRUE(WaitForDraw());
557 EXPECT_EQ(delegate.color_index(), 2); 567 EXPECT_EQ(delegate.color_index(), 2);
558 EXPECT_EQ(delegate.paint_size(), gfx::Size(200, 200)); 568 EXPECT_EQ(delegate.paint_size(), gfx::Size(200, 200));
559 569
560 l1->SchedulePaint(gfx::Rect(5, 5, 50, 50)); 570 l1->SchedulePaint(gfx::Rect(5, 5, 50, 50));
561 WaitForDraw(); 571 EXPECT_TRUE(WaitForDraw());
562 EXPECT_EQ(delegate.color_index(), 0); 572 EXPECT_EQ(delegate.color_index(), 0);
563 EXPECT_EQ(delegate.paint_size(), gfx::Size(50, 50)); 573 EXPECT_EQ(delegate.paint_size(), gfx::Size(50, 50));
564 } 574 }
565 575
566 TEST_F(LayerWithRealCompositorTest, MAYBE_DrawTree) { 576 TEST_F(LayerWithRealCompositorTest, MAYBE_DrawTree) {
567 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, 577 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
568 gfx::Rect(20, 20, 400, 400))); 578 gfx::Rect(20, 20, 400, 400)));
569 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, 579 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE,
570 gfx::Rect(10, 10, 350, 350))); 580 gfx::Rect(10, 10, 350, 350)));
571 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, 581 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW,
572 gfx::Rect(10, 10, 100, 100))); 582 gfx::Rect(10, 10, 100, 100)));
573 l1->Add(l2.get()); 583 l1->Add(l2.get());
574 l2->Add(l3.get()); 584 l2->Add(l3.get());
575 585
576 GetCompositor()->SetRootLayer(l1.get()); 586 GetCompositor()->SetRootLayer(l1.get());
577 WaitForDraw(); 587 EXPECT_TRUE(WaitForDraw());
578 588
579 DrawTreeLayerDelegate d1; 589 DrawTreeLayerDelegate d1;
580 l1->set_delegate(&d1); 590 l1->set_delegate(&d1);
581 DrawTreeLayerDelegate d2; 591 DrawTreeLayerDelegate d2;
582 l2->set_delegate(&d2); 592 l2->set_delegate(&d2);
583 DrawTreeLayerDelegate d3; 593 DrawTreeLayerDelegate d3;
584 l3->set_delegate(&d3); 594 l3->set_delegate(&d3);
585 595
586 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5)); 596 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5));
587 WaitForDraw(); 597 EXPECT_TRUE(WaitForDraw());
588 EXPECT_FALSE(d1.painted()); 598 EXPECT_FALSE(d1.painted());
589 EXPECT_TRUE(d2.painted()); 599 EXPECT_TRUE(d2.painted());
590 EXPECT_FALSE(d3.painted()); 600 EXPECT_FALSE(d3.painted());
591 } 601 }
592 602
593 // Tests no-texture Layers. 603 // Tests no-texture Layers.
594 // Create this hierarchy: 604 // Create this hierarchy:
595 // L1 - red 605 // L1 - red
596 // +-- L2 - NO TEXTURE 606 // +-- L2 - NO TEXTURE
597 // | +-- L3 - yellow 607 // | +-- L3 - yellow
598 // +-- L4 - magenta 608 // +-- L4 - magenta
599 // 609 //
600 TEST_F(LayerWithRealCompositorTest, MAYBE_HierarchyNoTexture) { 610 TEST_F(LayerWithRealCompositorTest, MAYBE_HierarchyNoTexture) {
601 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, 611 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
602 gfx::Rect(20, 20, 400, 400))); 612 gfx::Rect(20, 20, 400, 400)));
603 scoped_ptr<Layer> l2(CreateNoTextureLayer(gfx::Rect(10, 10, 350, 350))); 613 scoped_ptr<Layer> l2(CreateNoTextureLayer(gfx::Rect(10, 10, 350, 350)));
604 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, 614 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW,
605 gfx::Rect(5, 5, 25, 25))); 615 gfx::Rect(5, 5, 25, 25)));
606 scoped_ptr<Layer> l4(CreateColorLayer(SK_ColorMAGENTA, 616 scoped_ptr<Layer> l4(CreateColorLayer(SK_ColorMAGENTA,
607 gfx::Rect(300, 300, 100, 100))); 617 gfx::Rect(300, 300, 100, 100)));
608 618
609 l1->Add(l2.get()); 619 l1->Add(l2.get());
610 l1->Add(l4.get()); 620 l1->Add(l4.get());
611 l2->Add(l3.get()); 621 l2->Add(l3.get());
612 622
613 GetCompositor()->SetRootLayer(l1.get()); 623 GetCompositor()->SetRootLayer(l1.get());
614 WaitForDraw(); 624 EXPECT_TRUE(WaitForDraw());
615 625
616 DrawTreeLayerDelegate d2; 626 DrawTreeLayerDelegate d2;
617 l2->set_delegate(&d2); 627 l2->set_delegate(&d2);
618 DrawTreeLayerDelegate d3; 628 DrawTreeLayerDelegate d3;
619 l3->set_delegate(&d3); 629 l3->set_delegate(&d3);
620 630
621 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5)); 631 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5));
622 l3->SchedulePaint(gfx::Rect(5, 5, 5, 5)); 632 l3->SchedulePaint(gfx::Rect(5, 5, 5, 5));
623 WaitForDraw(); 633 EXPECT_TRUE(WaitForDraw());
624 634
625 // |d2| should not have received a paint notification since it has no texture. 635 // |d2| should not have received a paint notification since it has no texture.
626 EXPECT_FALSE(d2.painted()); 636 EXPECT_FALSE(d2.painted());
627 // |d3| should have received a paint notification. 637 // |d3| should have received a paint notification.
628 EXPECT_TRUE(d3.painted()); 638 EXPECT_TRUE(d3.painted());
629 } 639 }
630 640
631 class LayerWithNullDelegateTest : public LayerWithDelegateTest { 641 class LayerWithNullDelegateTest : public LayerWithDelegateTest {
632 public: 642 public:
633 LayerWithNullDelegateTest() {} 643 LayerWithNullDelegateTest() {}
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 EXPECT_EQ("2,3,1", GetLayerChildrenNames(*root.get())); 791 EXPECT_EQ("2,3,1", GetLayerChildrenNames(*root.get()));
782 } 792 }
783 793
784 // Verifies SetBounds triggers the appropriate painting/drawing. 794 // Verifies SetBounds triggers the appropriate painting/drawing.
785 TEST_F(LayerWithNullDelegateTest, SetBoundsSchedulesPaint) { 795 TEST_F(LayerWithNullDelegateTest, SetBoundsSchedulesPaint) {
786 scoped_ptr<Layer> l1(CreateTextureLayer(gfx::Rect(0, 0, 200, 200))); 796 scoped_ptr<Layer> l1(CreateTextureLayer(gfx::Rect(0, 0, 200, 200)));
787 compositor()->SetRootLayer(l1.get()); 797 compositor()->SetRootLayer(l1.get());
788 798
789 Draw(); 799 Draw();
790 800
791 schedule_draw_invoked_ = false;
792 l1->SetBounds(gfx::Rect(5, 5, 200, 200)); 801 l1->SetBounds(gfx::Rect(5, 5, 200, 200));
793 802
794 // The CompositorDelegate (us) should have been told to draw for a move. 803 // The CompositorDelegate (us) should have been told to draw for a move.
795 EXPECT_TRUE(schedule_draw_invoked_); 804 EXPECT_TRUE(WaitForDraw());
796 805
797 schedule_draw_invoked_ = false;
798 l1->SetBounds(gfx::Rect(5, 5, 100, 100)); 806 l1->SetBounds(gfx::Rect(5, 5, 100, 100));
799 807
800 // The CompositorDelegate (us) should have been told to draw for a resize. 808 // The CompositorDelegate (us) should have been told to draw for a resize.
801 EXPECT_TRUE(schedule_draw_invoked_); 809 EXPECT_TRUE(WaitForDraw());
802 } 810 }
803 811
804 // Checks that pixels are actually drawn to the screen with a read back. 812 // Checks that pixels are actually drawn to the screen with a read back.
805 // Currently disabled on all platforms, see http://crbug.com/148709. 813 // Currently disabled on all platforms, see http://crbug.com/148709.
806 TEST_F(LayerWithRealCompositorTest, MAYBE_DrawPixels) { 814 TEST_F(LayerWithRealCompositorTest, MAYBE_DrawPixels) {
807 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, 815 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED,
808 gfx::Rect(0, 0, 500, 500))); 816 gfx::Rect(0, 0, 500, 500)));
809 scoped_ptr<Layer> layer2(CreateColorLayer(SK_ColorBLUE, 817 scoped_ptr<Layer> layer2(CreateColorLayer(SK_ColorBLUE,
810 gfx::Rect(0, 0, 500, 10))); 818 gfx::Rect(0, 0, 500, 10)));
811 819
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 GetCompositor()->AddObserver(&observer); 880 GetCompositor()->AddObserver(&observer);
873 881
874 // Explicitly called DrawTree should cause the observers to be notified. 882 // Explicitly called DrawTree should cause the observers to be notified.
875 // NOTE: this call to DrawTree sets l1 to be the compositor's root layer. 883 // NOTE: this call to DrawTree sets l1 to be the compositor's root layer.
876 DrawTree(l1.get()); 884 DrawTree(l1.get());
877 EXPECT_TRUE(observer.notified()); 885 EXPECT_TRUE(observer.notified());
878 886
879 // As should scheduling a draw and waiting. 887 // As should scheduling a draw and waiting.
880 observer.Reset(); 888 observer.Reset();
881 l1->ScheduleDraw(); 889 l1->ScheduleDraw();
882 WaitForDraw(); 890 EXPECT_TRUE(WaitForDraw());
883 EXPECT_TRUE(observer.notified()); 891 EXPECT_TRUE(observer.notified());
884 892
885 // Moving, but not resizing, a layer should alert the observers. 893 // Moving, but not resizing, a layer should alert the observers.
886 observer.Reset(); 894 observer.Reset();
887 l2->SetBounds(gfx::Rect(0, 0, 350, 350)); 895 l2->SetBounds(gfx::Rect(0, 0, 350, 350));
888 WaitForDraw(); 896 EXPECT_TRUE(WaitForDraw());
889 EXPECT_TRUE(observer.notified()); 897 EXPECT_TRUE(observer.notified());
890 898
891 // So should resizing a layer. 899 // So should resizing a layer.
892 observer.Reset(); 900 observer.Reset();
893 l2->SetBounds(gfx::Rect(0, 0, 400, 400)); 901 l2->SetBounds(gfx::Rect(0, 0, 400, 400));
894 WaitForDraw(); 902 EXPECT_TRUE(WaitForDraw());
895 EXPECT_TRUE(observer.notified()); 903 EXPECT_TRUE(observer.notified());
896 904
897 // Opacity changes should alert the observers. 905 // Opacity changes should alert the observers.
898 observer.Reset(); 906 observer.Reset();
899 l2->SetOpacity(0.5f); 907 l2->SetOpacity(0.5f);
900 WaitForDraw(); 908 EXPECT_TRUE(WaitForDraw());
901 EXPECT_TRUE(observer.notified()); 909 EXPECT_TRUE(observer.notified());
902 910
903 // So should setting the opacity back. 911 // So should setting the opacity back.
904 observer.Reset(); 912 observer.Reset();
905 l2->SetOpacity(1.0f); 913 l2->SetOpacity(1.0f);
906 WaitForDraw(); 914 EXPECT_TRUE(WaitForDraw());
907 EXPECT_TRUE(observer.notified()); 915 EXPECT_TRUE(observer.notified());
908 916
909 // Setting the transform of a layer should alert the observers. 917 // Setting the transform of a layer should alert the observers.
910 observer.Reset(); 918 observer.Reset();
911 gfx::Transform transform; 919 gfx::Transform transform;
912 transform.Translate(200.0, 200.0); 920 transform.Translate(200.0, 200.0);
913 transform.Rotate(90.0); 921 transform.Rotate(90.0);
914 transform.Translate(-200.0, -200.0); 922 transform.Translate(-200.0, -200.0);
915 l2->SetTransform(transform); 923 l2->SetTransform(transform);
916 WaitForDraw(); 924 EXPECT_TRUE(WaitForDraw());
917 EXPECT_TRUE(observer.notified()); 925 EXPECT_TRUE(observer.notified());
918 926
919 // A change resulting in an aborted swap buffer should alert the observer 927 // A change resulting in an aborted swap buffer should alert the observer
920 // and also signal an abort. 928 // and also signal an abort.
921 observer.Reset(); 929 observer.Reset();
922 l2->SetOpacity(0.1f); 930 l2->SetOpacity(0.1f);
923 GetCompositor()->OnSwapBuffersAborted(); 931 GetCompositor()->OnSwapBuffersAborted();
924 WaitForDraw(); 932 EXPECT_TRUE(WaitForDraw());
925 EXPECT_TRUE(observer.notified()); 933 EXPECT_TRUE(observer.notified());
926 EXPECT_TRUE(observer.aborted()); 934 EXPECT_TRUE(observer.aborted());
927 935
928 GetCompositor()->RemoveObserver(&observer); 936 GetCompositor()->RemoveObserver(&observer);
929 937
930 // Opacity changes should no longer alert the removed observer. 938 // Opacity changes should no longer alert the removed observer.
931 observer.Reset(); 939 observer.Reset();
932 l2->SetOpacity(0.5f); 940 l2->SetOpacity(0.5f);
933 WaitForDraw(); 941 EXPECT_TRUE(WaitForDraw());
934 942
935 EXPECT_FALSE(observer.notified()); 943 EXPECT_FALSE(observer.notified());
936 } 944 }
937 945
938 // Checks that modifying the hierarchy correctly affects final composite. 946 // Checks that modifying the hierarchy correctly affects final composite.
939 TEST_F(LayerWithRealCompositorTest, MAYBE_ModifyHierarchy) { 947 TEST_F(LayerWithRealCompositorTest, MAYBE_ModifyHierarchy) {
940 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); 948 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50));
941 949
942 // l0 950 // l0
943 // +-l11 951 // +-l11
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 gfx::Rect(0, 0, 500, 500))); 1090 gfx::Rect(0, 0, 500, 500)));
1083 SchedulePaintLayerDelegate child_delegate; 1091 SchedulePaintLayerDelegate child_delegate;
1084 scoped_ptr<Layer> child(CreateColorLayer(SK_ColorBLUE, 1092 scoped_ptr<Layer> child(CreateColorLayer(SK_ColorBLUE,
1085 gfx::Rect(0, 0, 200, 200))); 1093 gfx::Rect(0, 0, 200, 200)));
1086 child_delegate.set_layer(child.get()); 1094 child_delegate.set_layer(child.get());
1087 1095
1088 root->Add(child.get()); 1096 root->Add(child.get());
1089 1097
1090 SchedulePaintForLayer(root.get()); 1098 SchedulePaintForLayer(root.get());
1091 DrawTree(root.get()); 1099 DrawTree(root.get());
1092 schedule_draw_invoked_ = false;
1093 child->SchedulePaint(gfx::Rect(0, 0, 20, 20)); 1100 child->SchedulePaint(gfx::Rect(0, 0, 20, 20));
1094 child_delegate.GetPaintCountAndClear(); 1101 child_delegate.GetPaintCountAndClear();
1095 EXPECT_TRUE(schedule_draw_invoked_); 1102
1096 schedule_draw_invoked_ = false;
1097 // Set a rect so that when OnPaintLayer() is invoked SchedulePaint is invoked 1103 // Set a rect so that when OnPaintLayer() is invoked SchedulePaint is invoked
1098 // again. 1104 // again.
1099 child_delegate.SetSchedulePaintRect(gfx::Rect(10, 10, 30, 30)); 1105 child_delegate.SetSchedulePaintRect(gfx::Rect(10, 10, 30, 30));
1100 DrawTree(root.get()); 1106 EXPECT_TRUE(WaitForDraw());
1101 // |child| should have been painted once. 1107 // |child| should have been painted once.
1102 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear()); 1108 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear());
1103 // ScheduleDraw() should have been invoked. 1109
1104 EXPECT_TRUE(schedule_draw_invoked_);
1105 // Because SchedulePaint() was invoked from OnPaintLayer() |child| should 1110 // Because SchedulePaint() was invoked from OnPaintLayer() |child| should
1106 // still need to be painted. 1111 // still need to be painted.
1107 DrawTree(root.get()); 1112 EXPECT_TRUE(WaitForDraw());
1108 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear()); 1113 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear());
1109 EXPECT_TRUE(child_delegate.last_clip_rect().Contains( 1114 EXPECT_TRUE(child_delegate.last_clip_rect().Contains(
1110 gfx::Rect(10, 10, 30, 30))); 1115 gfx::Rect(10, 10, 30, 30)));
1111 } 1116 }
1112 1117
1113 TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleUpDown) { 1118 TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleUpDown) {
1114 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, 1119 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE,
1115 gfx::Rect(10, 20, 200, 220))); 1120 gfx::Rect(10, 20, 200, 220)));
1116 TestLayerDelegate root_delegate; 1121 TestLayerDelegate root_delegate;
1117 root_delegate.AddColor(SK_ColorWHITE); 1122 root_delegate.AddColor(SK_ColorWHITE);
1118 root->set_delegate(&root_delegate); 1123 root->set_delegate(&root_delegate);
1119 1124
1120 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, 1125 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE,
1121 gfx::Rect(10, 20, 140, 180))); 1126 gfx::Rect(10, 20, 140, 180)));
1122 TestLayerDelegate l1_delegate; 1127 TestLayerDelegate l1_delegate;
1123 l1_delegate.AddColor(SK_ColorWHITE); 1128 l1_delegate.AddColor(SK_ColorWHITE);
1124 l1->set_delegate(&l1_delegate); 1129 l1->set_delegate(&l1_delegate);
1125 1130
1126 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); 1131 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500));
1127 GetCompositor()->SetRootLayer(root.get()); 1132 GetCompositor()->SetRootLayer(root.get());
1128 root->Add(l1.get()); 1133 root->Add(l1.get());
1129 WaitForDraw(); 1134 EXPECT_TRUE(WaitForDraw());
1130 1135
1131 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); 1136 EXPECT_EQ("10,20 200x220", root->bounds().ToString());
1132 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); 1137 EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
1133 gfx::Size size_in_pixel = root->cc_layer()->bounds(); 1138 gfx::Size size_in_pixel = root->cc_layer()->bounds();
1134 EXPECT_EQ("200x220", size_in_pixel.ToString()); 1139 EXPECT_EQ("200x220", size_in_pixel.ToString());
1135 size_in_pixel = l1->cc_layer()->bounds(); 1140 size_in_pixel = l1->cc_layer()->bounds();
1136 EXPECT_EQ("140x180", size_in_pixel.ToString()); 1141 EXPECT_EQ("140x180", size_in_pixel.ToString());
1137 // No scale change, so no scale notification. 1142 // No scale change, so no scale notification.
1138 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); 1143 EXPECT_EQ(0.0f, root_delegate.device_scale_factor());
1139 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); 1144 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor());
1140 1145
1141 EXPECT_EQ("200x220", root_delegate.paint_size().ToString()); 1146 EXPECT_EQ("200x220", root_delegate.paint_size().ToString());
1142 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); 1147 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString());
1143 1148
1144 // Scale up to 2.0. Changing scale doesn't change the bounds in DIP. 1149 // Scale up to 2.0. Changing scale doesn't change the bounds in DIP.
1145 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); 1150 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500));
1146 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); 1151 EXPECT_EQ("10,20 200x220", root->bounds().ToString());
1147 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); 1152 EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
1148 // Pixel size must have been scaled up. 1153 // Pixel size must have been scaled up.
1149 size_in_pixel = root->cc_layer()->bounds(); 1154 size_in_pixel = root->cc_layer()->bounds();
1150 EXPECT_EQ("400x440", size_in_pixel.ToString()); 1155 EXPECT_EQ("400x440", size_in_pixel.ToString());
1151 size_in_pixel = l1->cc_layer()->bounds(); 1156 size_in_pixel = l1->cc_layer()->bounds();
1152 EXPECT_EQ("280x360", size_in_pixel.ToString()); 1157 EXPECT_EQ("280x360", size_in_pixel.ToString());
1153 // New scale factor must have been notified. 1158 // New scale factor must have been notified.
1154 EXPECT_EQ(2.0f, root_delegate.device_scale_factor()); 1159 EXPECT_EQ(2.0f, root_delegate.device_scale_factor());
1155 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); 1160 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor());
1156 1161
1157 // Canvas size must have been scaled down up. 1162 // Canvas size must have been scaled down up.
1158 WaitForDraw(); 1163 EXPECT_TRUE(WaitForDraw());
1159 EXPECT_EQ("400x440", root_delegate.paint_size().ToString()); 1164 EXPECT_EQ("400x440", root_delegate.paint_size().ToString());
1160 EXPECT_EQ("2.0 2.0", root_delegate.ToScaleString()); 1165 EXPECT_EQ("2.0 2.0", root_delegate.ToScaleString());
1161 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); 1166 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString());
1162 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); 1167 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString());
1163 1168
1164 // Scale down back to 1.0f. 1169 // Scale down back to 1.0f.
1165 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); 1170 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500));
1166 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); 1171 EXPECT_EQ("10,20 200x220", root->bounds().ToString());
1167 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); 1172 EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
1168 // Pixel size must have been scaled down. 1173 // Pixel size must have been scaled down.
1169 size_in_pixel = root->cc_layer()->bounds(); 1174 size_in_pixel = root->cc_layer()->bounds();
1170 EXPECT_EQ("200x220", size_in_pixel.ToString()); 1175 EXPECT_EQ("200x220", size_in_pixel.ToString());
1171 size_in_pixel = l1->cc_layer()->bounds(); 1176 size_in_pixel = l1->cc_layer()->bounds();
1172 EXPECT_EQ("140x180", size_in_pixel.ToString()); 1177 EXPECT_EQ("140x180", size_in_pixel.ToString());
1173 // New scale factor must have been notified. 1178 // New scale factor must have been notified.
1174 EXPECT_EQ(1.0f, root_delegate.device_scale_factor()); 1179 EXPECT_EQ(1.0f, root_delegate.device_scale_factor());
1175 EXPECT_EQ(1.0f, l1_delegate.device_scale_factor()); 1180 EXPECT_EQ(1.0f, l1_delegate.device_scale_factor());
1176 1181
1177 // Canvas size must have been scaled down too. 1182 // Canvas size must have been scaled down too.
1178 WaitForDraw(); 1183 EXPECT_TRUE(WaitForDraw());
1179 EXPECT_EQ("200x220", root_delegate.paint_size().ToString()); 1184 EXPECT_EQ("200x220", root_delegate.paint_size().ToString());
1180 EXPECT_EQ("1.0 1.0", root_delegate.ToScaleString()); 1185 EXPECT_EQ("1.0 1.0", root_delegate.ToScaleString());
1181 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); 1186 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString());
1182 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); 1187 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString());
1183 1188
1184 root_delegate.reset(); 1189 root_delegate.reset();
1185 l1_delegate.reset(); 1190 l1_delegate.reset();
1186 // Just changing the size shouldn't notify the scale change nor 1191 // Just changing the size shouldn't notify the scale change nor
1187 // trigger repaint. 1192 // trigger repaint.
1188 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); 1193 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(1000, 1000));
1189 // No scale change, so no scale notification. 1194 // No scale change, so no scale notification.
1190 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); 1195 EXPECT_EQ(0.0f, root_delegate.device_scale_factor());
1191 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); 1196 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor());
1192 WaitForDraw(); 1197 EXPECT_TRUE(WaitForDraw());
1193 EXPECT_EQ("0x0", root_delegate.paint_size().ToString()); 1198 EXPECT_EQ("0x0", root_delegate.paint_size().ToString());
1194 EXPECT_EQ("0.0 0.0", root_delegate.ToScaleString()); 1199 EXPECT_EQ("0.0 0.0", root_delegate.ToScaleString());
1195 EXPECT_EQ("0x0", l1_delegate.paint_size().ToString()); 1200 EXPECT_EQ("0x0", l1_delegate.paint_size().ToString());
1196 EXPECT_EQ("0.0 0.0", l1_delegate.ToScaleString()); 1201 EXPECT_EQ("0.0 0.0", l1_delegate.ToScaleString());
1197 } 1202 }
1198 1203
1199 TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleReparent) { 1204 TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleReparent) {
1200 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, 1205 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE,
1201 gfx::Rect(10, 20, 200, 220))); 1206 gfx::Rect(10, 20, 200, 220)));
1202 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, 1207 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE,
1203 gfx::Rect(10, 20, 140, 180))); 1208 gfx::Rect(10, 20, 140, 180)));
1204 TestLayerDelegate l1_delegate; 1209 TestLayerDelegate l1_delegate;
1205 l1_delegate.AddColor(SK_ColorWHITE); 1210 l1_delegate.AddColor(SK_ColorWHITE);
1206 l1->set_delegate(&l1_delegate); 1211 l1->set_delegate(&l1_delegate);
1207 1212
1208 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); 1213 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500));
1209 GetCompositor()->SetRootLayer(root.get()); 1214 GetCompositor()->SetRootLayer(root.get());
1210 WaitForDraw(); 1215 EXPECT_TRUE(WaitForDraw());
1211 1216
1212 root->Add(l1.get()); 1217 root->Add(l1.get());
1213 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); 1218 EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
1214 gfx::Size size_in_pixel = l1->cc_layer()->bounds(); 1219 gfx::Size size_in_pixel = l1->cc_layer()->bounds();
1215 EXPECT_EQ("140x180", size_in_pixel.ToString()); 1220 EXPECT_EQ("140x180", size_in_pixel.ToString());
1216 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); 1221 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor());
1217 1222
1218 WaitForDraw(); 1223 EXPECT_TRUE(WaitForDraw());
1219 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); 1224 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString());
1220 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); 1225 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString());
1221 1226
1222 // Remove l1 from root and change the scale. 1227 // Remove l1 from root and change the scale.
1223 root->Remove(l1.get()); 1228 root->Remove(l1.get());
1224 EXPECT_EQ(NULL, l1->parent()); 1229 EXPECT_EQ(NULL, l1->parent());
1225 EXPECT_EQ(NULL, l1->GetCompositor()); 1230 EXPECT_EQ(NULL, l1->GetCompositor());
1226 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); 1231 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500));
1227 // Sanity check on root and l1. 1232 // Sanity check on root and l1.
1228 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); 1233 EXPECT_EQ("10,20 200x220", root->bounds().ToString());
1229 size_in_pixel = l1->cc_layer()->bounds(); 1234 size_in_pixel = l1->cc_layer()->bounds();
1230 EXPECT_EQ("140x180", size_in_pixel.ToString()); 1235 EXPECT_EQ("140x180", size_in_pixel.ToString());
1231 1236
1232 1237
1233 root->Add(l1.get()); 1238 root->Add(l1.get());
1234 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); 1239 EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
1235 size_in_pixel = l1->cc_layer()->bounds(); 1240 size_in_pixel = l1->cc_layer()->bounds();
1236 EXPECT_EQ("280x360", size_in_pixel.ToString()); 1241 EXPECT_EQ("280x360", size_in_pixel.ToString());
1237 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); 1242 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor());
1238 WaitForDraw(); 1243 EXPECT_TRUE(WaitForDraw());
1239 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); 1244 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString());
1240 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); 1245 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString());
1241 } 1246 }
1242 1247
1243 // Tests layer::set_scale_content(false). 1248 // Tests layer::set_scale_content(false).
1244 TEST_F(LayerWithRealCompositorTest, MAYBE_NoScaleCanvas) { 1249 TEST_F(LayerWithRealCompositorTest, MAYBE_NoScaleCanvas) {
1245 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, 1250 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE,
1246 gfx::Rect(10, 20, 200, 220))); 1251 gfx::Rect(10, 20, 200, 220)));
1247 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, 1252 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE,
1248 gfx::Rect(10, 20, 140, 180))); 1253 gfx::Rect(10, 20, 140, 180)));
1249 l1->set_scale_content(false); 1254 l1->set_scale_content(false);
1250 root->Add(l1.get()); 1255 root->Add(l1.get());
1251 TestLayerDelegate l1_delegate; 1256 TestLayerDelegate l1_delegate;
1252 l1_delegate.AddColor(SK_ColorWHITE); 1257 l1_delegate.AddColor(SK_ColorWHITE);
1253 l1->set_delegate(&l1_delegate); 1258 l1->set_delegate(&l1_delegate);
1254 1259
1255 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); 1260 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500));
1256 GetCompositor()->SetRootLayer(root.get()); 1261 GetCompositor()->SetRootLayer(root.get());
1257 // Scale factor change is notified regardless of scale_content flag. 1262 // Scale factor change is notified regardless of scale_content flag.
1258 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); 1263 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor());
1259 1264
1260 WaitForDraw(); 1265 EXPECT_TRUE(WaitForDraw());
1261 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); 1266 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString());
1262 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); 1267 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString());
1263 } 1268 }
1264 1269
1265 // Verifies that when changing bounds on a layer that is invisible, and then 1270 // Verifies that when changing bounds on a layer that is invisible, and then
1266 // made visible, the right thing happens: 1271 // made visible, the right thing happens:
1267 // - if just a move, then no painting should happen. 1272 // - if just a move, then no painting should happen.
1268 // - if a resize, the layer should be repainted. 1273 // - if a resize, the layer should be repainted.
1269 TEST_F(LayerWithDelegateTest, SetBoundsWhenInvisible) { 1274 TEST_F(LayerWithDelegateTest, SetBoundsWhenInvisible) {
1270 scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); 1275 scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000)));
1271 1276
1272 scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); 1277 scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED));
1273 child->SetBounds(gfx::Rect(0, 0, 500, 500)); 1278 child->SetBounds(gfx::Rect(0, 0, 500, 500));
1274 DrawTreeLayerDelegate delegate; 1279 DrawTreeLayerDelegate delegate;
1275 child->set_delegate(&delegate); 1280 child->set_delegate(&delegate);
1276 root->Add(child.get()); 1281 root->Add(child.get());
1277 1282
1278 // Paint once for initial damage. 1283 // Paint once for initial damage.
1279 child->SetVisible(true); 1284 child->SetVisible(true);
1280 DrawTree(root.get()); 1285 DrawTree(root.get());
1281 1286
1282 // Reset into invisible state. 1287 // Reset into invisible state.
1283 child->SetVisible(false); 1288 child->SetVisible(false);
1284 DrawTree(root.get()); 1289 DrawTree(root.get());
1285 schedule_draw_invoked_ = false;
1286 delegate.Reset(); 1290 delegate.Reset();
1287 1291
1288 // Move layer. 1292 // Move layer.
1289 child->SetBounds(gfx::Rect(200, 200, 500, 500)); 1293 child->SetBounds(gfx::Rect(200, 200, 500, 500));
1290 child->SetVisible(true); 1294 child->SetVisible(true);
1291 EXPECT_TRUE(schedule_draw_invoked_); 1295 EXPECT_TRUE(WaitForDraw());
1292 DrawTree(root.get()); 1296 DrawTree(root.get());
1293 EXPECT_FALSE(delegate.painted()); 1297 EXPECT_FALSE(delegate.painted());
1294 1298
1295 // Reset into invisible state. 1299 // Reset into invisible state.
1296 child->SetVisible(false); 1300 child->SetVisible(false);
1297 DrawTree(root.get()); 1301 DrawTree(root.get());
1298 schedule_draw_invoked_ = false;
1299 delegate.Reset(); 1302 delegate.Reset();
1300 1303
1301 // Resize layer. 1304 // Resize layer.
1302 child->SetBounds(gfx::Rect(200, 200, 400, 400)); 1305 child->SetBounds(gfx::Rect(200, 200, 400, 400));
1303 child->SetVisible(true); 1306 child->SetVisible(true);
1304 EXPECT_TRUE(schedule_draw_invoked_); 1307 EXPECT_TRUE(WaitForDraw());
1305 DrawTree(root.get()); 1308 DrawTree(root.get());
1306 EXPECT_TRUE(delegate.painted()); 1309 EXPECT_TRUE(delegate.painted());
1307 } 1310 }
1308 1311
1309 static scoped_ptr<cc::DelegatedFrameData> MakeFrameData(gfx::Size size) { 1312 static scoped_ptr<cc::DelegatedFrameData> MakeFrameData(gfx::Size size) {
1310 scoped_ptr<cc::DelegatedFrameData> frame_data(new cc::DelegatedFrameData); 1313 scoped_ptr<cc::DelegatedFrameData> frame_data(new cc::DelegatedFrameData);
1311 scoped_ptr<cc::RenderPass> render_pass(cc::RenderPass::Create()); 1314 scoped_ptr<cc::RenderPass> render_pass(cc::RenderPass::Create());
1312 render_pass->SetNew(cc::RenderPass::Id(1, 1), 1315 render_pass->SetNew(cc::RenderPass::Id(1, 1),
1313 gfx::Rect(size), 1316 gfx::Rect(size),
1314 gfx::RectF(), 1317 gfx::RectF(),
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 l1->SetOpacity(0.5f); 1424 l1->SetOpacity(0.5f);
1422 1425
1423 // Change l1's cc::Layer. 1426 // Change l1's cc::Layer.
1424 l1->SwitchCCLayerForTest(); 1427 l1->SwitchCCLayerForTest();
1425 1428
1426 // Ensure that the opacity animation completed. 1429 // Ensure that the opacity animation completed.
1427 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); 1430 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f);
1428 } 1431 }
1429 1432
1430 } // namespace ui 1433 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/compositor.cc ('k') | ui/compositor/test/test_compositor_host_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698