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

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

Issue 9289036: aura: Add Layer::LAYER_SOLID_COLOR to compositor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update WorkspaceManagerTest Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/compositor/layer.cc ('k') | ui/views/widget/native_widget_aura.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/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // - LayerWithNullDelegateTest uses NullLayerDelegate as the LayerDelegate. This 111 // - LayerWithNullDelegateTest uses NullLayerDelegate as the LayerDelegate. This
112 // is typically the base class you want to use. 112 // is typically the base class you want to use.
113 // - LayerWithDelegateTest uses LayerDelegate on the delegates. 113 // - LayerWithDelegateTest uses LayerDelegate on the delegates.
114 // - LayerWithRealCompositorTest when a real compositor is required for testing. 114 // - LayerWithRealCompositorTest when a real compositor is required for testing.
115 // - Slow because they bring up a window and run the real compositor. This 115 // - Slow because they bring up a window and run the real compositor. This
116 // is typically not what you want. 116 // is typically not what you want.
117 117
118 class ColoredLayer : public Layer, public LayerDelegate { 118 class ColoredLayer : public Layer, public LayerDelegate {
119 public: 119 public:
120 explicit ColoredLayer(SkColor color) 120 explicit ColoredLayer(SkColor color)
121 : Layer(Layer::LAYER_HAS_TEXTURE), 121 : Layer(Layer::LAYER_TEXTURED),
122 color_(color) { 122 color_(color) {
123 set_delegate(this); 123 set_delegate(this);
124 } 124 }
125 125
126 virtual ~ColoredLayer() { } 126 virtual ~ColoredLayer() { }
127 127
128 // Overridden from LayerDelegate: 128 // Overridden from LayerDelegate:
129 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { 129 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
130 canvas->GetSkCanvas()->drawColor(color_); 130 canvas->GetSkCanvas()->drawColor(color_);
131 } 131 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 return new Layer(type); 164 return new Layer(type);
165 } 165 }
166 166
167 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { 167 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
168 Layer* layer = new ColoredLayer(color); 168 Layer* layer = new ColoredLayer(color);
169 layer->SetBounds(bounds); 169 layer->SetBounds(bounds);
170 return layer; 170 return layer;
171 } 171 }
172 172
173 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { 173 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) {
174 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); 174 Layer* layer = CreateLayer(Layer::LAYER_NOT_DRAWN);
175 layer->SetBounds(bounds); 175 layer->SetBounds(bounds);
176 return layer; 176 return layer;
177 } 177 }
178 178
179 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) { 179 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) {
180 return gfx::Canvas::CreateCanvas(layer->bounds().size(), false); 180 return gfx::Canvas::CreateCanvas(layer->bounds().size(), false);
181 } 181 }
182 182
183 void DrawTree(Layer* root) { 183 void DrawTree(Layer* root) {
184 GetCompositor()->SetRootLayer(root); 184 GetCompositor()->SetRootLayer(root);
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 return new Layer(type); 374 return new Layer(type);
375 } 375 }
376 376
377 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { 377 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
378 Layer* layer = new ColoredLayer(color); 378 Layer* layer = new ColoredLayer(color);
379 layer->SetBounds(bounds); 379 layer->SetBounds(bounds);
380 return layer; 380 return layer;
381 } 381 }
382 382
383 virtual Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { 383 virtual Layer* CreateNoTextureLayer(const gfx::Rect& bounds) {
384 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); 384 Layer* layer = CreateLayer(Layer::LAYER_NOT_DRAWN);
385 layer->SetBounds(bounds); 385 layer->SetBounds(bounds);
386 return layer; 386 return layer;
387 } 387 }
388 388
389 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) { 389 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) {
390 return gfx::Canvas::CreateCanvas(layer->bounds().size(), false); 390 return gfx::Canvas::CreateCanvas(layer->bounds().size(), false);
391 } 391 }
392 392
393 void DrawTree(Layer* root) { 393 void DrawTree(Layer* root) {
394 compositor()->SetRootLayer(root); 394 compositor()->SetRootLayer(root);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 return layer; 580 return layer;
581 } 581 }
582 582
583 Layer* CreateTextureRootLayer(const gfx::Rect& bounds) { 583 Layer* CreateTextureRootLayer(const gfx::Rect& bounds) {
584 Layer* layer = CreateTextureLayer(bounds); 584 Layer* layer = CreateTextureLayer(bounds);
585 compositor()->SetRootLayer(layer); 585 compositor()->SetRootLayer(layer);
586 return layer; 586 return layer;
587 } 587 }
588 588
589 Layer* CreateTextureLayer(const gfx::Rect& bounds) { 589 Layer* CreateTextureLayer(const gfx::Rect& bounds) {
590 Layer* layer = CreateLayer(Layer::LAYER_HAS_TEXTURE); 590 Layer* layer = CreateLayer(Layer::LAYER_TEXTURED);
591 layer->SetBounds(bounds); 591 layer->SetBounds(bounds);
592 return layer; 592 return layer;
593 } 593 }
594 594
595 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) OVERRIDE { 595 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) OVERRIDE {
596 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); 596 Layer* layer = CreateLayer(Layer::LAYER_NOT_DRAWN);
597 layer->SetBounds(bounds); 597 layer->SetBounds(bounds);
598 return layer; 598 return layer;
599 } 599 }
600 600
601 void RunPendingMessages() { 601 void RunPendingMessages() {
602 MessageLoopForUI::current()->RunAllPending(); 602 MessageLoopForUI::current()->RunAllPending();
603 } 603 }
604 604
605 private: 605 private:
606 scoped_ptr<NullLayerDelegate> default_layer_delegate_; 606 scoped_ptr<NullLayerDelegate> default_layer_delegate_;
607 607
608 DISALLOW_COPY_AND_ASSIGN(LayerWithNullDelegateTest); 608 DISALLOW_COPY_AND_ASSIGN(LayerWithNullDelegateTest);
609 }; 609 };
610 610
611 // Various visibile/drawn assertions. 611 // Various visibile/drawn assertions.
612 TEST_F(LayerWithNullDelegateTest, Visibility) { 612 TEST_F(LayerWithNullDelegateTest, Visibility) {
613 scoped_ptr<Layer> l1(new Layer(Layer::LAYER_HAS_TEXTURE)); 613 scoped_ptr<Layer> l1(new Layer(Layer::LAYER_TEXTURED));
614 scoped_ptr<Layer> l2(new Layer(Layer::LAYER_HAS_TEXTURE)); 614 scoped_ptr<Layer> l2(new Layer(Layer::LAYER_TEXTURED));
615 scoped_ptr<Layer> l3(new Layer(Layer::LAYER_HAS_TEXTURE)); 615 scoped_ptr<Layer> l3(new Layer(Layer::LAYER_TEXTURED));
616 l1->Add(l2.get()); 616 l1->Add(l2.get());
617 l2->Add(l3.get()); 617 l2->Add(l3.get());
618 618
619 NullLayerDelegate delegate; 619 NullLayerDelegate delegate;
620 l1->set_delegate(&delegate); 620 l1->set_delegate(&delegate);
621 l2->set_delegate(&delegate); 621 l2->set_delegate(&delegate);
622 l3->set_delegate(&delegate); 622 l3->set_delegate(&delegate);
623 623
624 // Layers should initially be drawn. 624 // Layers should initially be drawn.
625 EXPECT_TRUE(l1->IsDrawn()); 625 EXPECT_TRUE(l1->IsDrawn());
(...skipping 21 matching lines...) Expand all
647 647
648 l1->SetVisible(true); 648 l1->SetVisible(true);
649 EXPECT_TRUE(l1->IsDrawn()); 649 EXPECT_TRUE(l1->IsDrawn());
650 EXPECT_TRUE(l2->IsDrawn()); 650 EXPECT_TRUE(l2->IsDrawn());
651 EXPECT_FALSE(l3->IsDrawn()); 651 EXPECT_FALSE(l3->IsDrawn());
652 EXPECT_EQ(1.f, l1->web_layer().opacity()); 652 EXPECT_EQ(1.f, l1->web_layer().opacity());
653 } 653 }
654 654
655 // Checks that stacking-related methods behave as advertised. 655 // Checks that stacking-related methods behave as advertised.
656 TEST_F(LayerWithNullDelegateTest, Stacking) { 656 TEST_F(LayerWithNullDelegateTest, Stacking) {
657 scoped_ptr<Layer> root(new Layer(Layer::LAYER_HAS_NO_TEXTURE)); 657 scoped_ptr<Layer> root(new Layer(Layer::LAYER_NOT_DRAWN));
658 scoped_ptr<Layer> l1(new Layer(Layer::LAYER_HAS_TEXTURE)); 658 scoped_ptr<Layer> l1(new Layer(Layer::LAYER_TEXTURED));
659 scoped_ptr<Layer> l2(new Layer(Layer::LAYER_HAS_TEXTURE)); 659 scoped_ptr<Layer> l2(new Layer(Layer::LAYER_TEXTURED));
660 scoped_ptr<Layer> l3(new Layer(Layer::LAYER_HAS_TEXTURE)); 660 scoped_ptr<Layer> l3(new Layer(Layer::LAYER_TEXTURED));
661 l1->set_name("1"); 661 l1->set_name("1");
662 l2->set_name("2"); 662 l2->set_name("2");
663 l3->set_name("3"); 663 l3->set_name("3");
664 root->Add(l3.get()); 664 root->Add(l3.get());
665 root->Add(l2.get()); 665 root->Add(l2.get());
666 root->Add(l1.get()); 666 root->Add(l1.get());
667 667
668 // Layers' children are stored in bottom-to-top order. 668 // Layers' children are stored in bottom-to-top order.
669 EXPECT_EQ("3,2,1", GetLayerChildrenNames(*root.get())); 669 EXPECT_EQ("3,2,1", GetLayerChildrenNames(*root.get()));
670 670
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 EXPECT_TRUE(schedule_draw_invoked_); 1015 EXPECT_TRUE(schedule_draw_invoked_);
1016 // Because SchedulePaint() was invoked from OnPaintLayer() |child| should 1016 // Because SchedulePaint() was invoked from OnPaintLayer() |child| should
1017 // still need to be painted. 1017 // still need to be painted.
1018 DrawTree(root.get()); 1018 DrawTree(root.get());
1019 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear()); 1019 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear());
1020 EXPECT_TRUE(child_delegate.last_clip_rect().Contains( 1020 EXPECT_TRUE(child_delegate.last_clip_rect().Contains(
1021 gfx::Rect(10, 10, 30, 30))); 1021 gfx::Rect(10, 10, 30, 30)));
1022 } 1022 }
1023 1023
1024 } // namespace ui 1024 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/layer.cc ('k') | ui/views/widget/native_widget_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698