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

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: minor changes 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
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // - LayerWithNullDelegateTest uses NullLayerDelegate as the LayerDelegate. This 115 // - LayerWithNullDelegateTest uses NullLayerDelegate as the LayerDelegate. This
116 // is typically the base class you want to use. 116 // is typically the base class you want to use.
117 // - LayerWithDelegateTest uses LayerDelegate on the delegates. 117 // - LayerWithDelegateTest uses LayerDelegate on the delegates.
118 // - LayerWithRealCompositorTest when a real compositor is required for testing. 118 // - LayerWithRealCompositorTest when a real compositor is required for testing.
119 // - Slow because they bring up a window and run the real compositor. This 119 // - Slow because they bring up a window and run the real compositor. This
120 // is typically not what you want. 120 // is typically not what you want.
121 121
122 class ColoredLayer : public Layer, public LayerDelegate { 122 class ColoredLayer : public Layer, public LayerDelegate {
123 public: 123 public:
124 explicit ColoredLayer(SkColor color) 124 explicit ColoredLayer(SkColor color)
125 : Layer(Layer::LAYER_HAS_TEXTURE), 125 : Layer(Layer::LAYER_TEXTURED),
126 color_(color) { 126 color_(color) {
127 set_delegate(this); 127 set_delegate(this);
128 } 128 }
129 129
130 virtual ~ColoredLayer() { } 130 virtual ~ColoredLayer() { }
131 131
132 // Overridden from LayerDelegate: 132 // Overridden from LayerDelegate:
133 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { 133 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
134 canvas->GetSkCanvas()->drawColor(color_); 134 canvas->GetSkCanvas()->drawColor(color_);
135 } 135 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 return new Layer(type); 170 return new Layer(type);
171 } 171 }
172 172
173 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { 173 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
174 Layer* layer = new ColoredLayer(color); 174 Layer* layer = new ColoredLayer(color);
175 layer->SetBounds(bounds); 175 layer->SetBounds(bounds);
176 return layer; 176 return layer;
177 } 177 }
178 178
179 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { 179 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) {
180 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); 180 Layer* layer = CreateLayer(Layer::LAYER_NOT_DRAWN);
181 layer->SetBounds(bounds); 181 layer->SetBounds(bounds);
182 return layer; 182 return layer;
183 } 183 }
184 184
185 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) { 185 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) {
186 return gfx::Canvas::CreateCanvas(layer->bounds().size(), false); 186 return gfx::Canvas::CreateCanvas(layer->bounds().size(), false);
187 } 187 }
188 188
189 void DrawTree(Layer* root) { 189 void DrawTree(Layer* root) {
190 GetCompositor()->SetRootLayer(root); 190 GetCompositor()->SetRootLayer(root);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 return new Layer(type); 384 return new Layer(type);
385 } 385 }
386 386
387 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { 387 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
388 Layer* layer = new ColoredLayer(color); 388 Layer* layer = new ColoredLayer(color);
389 layer->SetBounds(bounds); 389 layer->SetBounds(bounds);
390 return layer; 390 return layer;
391 } 391 }
392 392
393 virtual Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { 393 virtual Layer* CreateNoTextureLayer(const gfx::Rect& bounds) {
394 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); 394 Layer* layer = CreateLayer(Layer::LAYER_NOT_DRAWN);
395 layer->SetBounds(bounds); 395 layer->SetBounds(bounds);
396 return layer; 396 return layer;
397 } 397 }
398 398
399 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) { 399 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) {
400 return gfx::Canvas::CreateCanvas(layer->bounds().size(), false); 400 return gfx::Canvas::CreateCanvas(layer->bounds().size(), false);
401 } 401 }
402 402
403 void DrawTree(Layer* root) { 403 void DrawTree(Layer* root) {
404 compositor()->SetRootLayer(root); 404 compositor()->SetRootLayer(root);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 return layer; 590 return layer;
591 } 591 }
592 592
593 Layer* CreateTextureRootLayer(const gfx::Rect& bounds) { 593 Layer* CreateTextureRootLayer(const gfx::Rect& bounds) {
594 Layer* layer = CreateTextureLayer(bounds); 594 Layer* layer = CreateTextureLayer(bounds);
595 compositor()->SetRootLayer(layer); 595 compositor()->SetRootLayer(layer);
596 return layer; 596 return layer;
597 } 597 }
598 598
599 Layer* CreateTextureLayer(const gfx::Rect& bounds) { 599 Layer* CreateTextureLayer(const gfx::Rect& bounds) {
600 Layer* layer = CreateLayer(Layer::LAYER_HAS_TEXTURE); 600 Layer* layer = CreateLayer(Layer::LAYER_TEXTURED);
601 layer->SetBounds(bounds); 601 layer->SetBounds(bounds);
602 return layer; 602 return layer;
603 } 603 }
604 604
605 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) OVERRIDE { 605 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) OVERRIDE {
606 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); 606 Layer* layer = CreateLayer(Layer::LAYER_NOT_DRAWN);
607 layer->SetBounds(bounds); 607 layer->SetBounds(bounds);
608 return layer; 608 return layer;
609 } 609 }
610 610
611 void RunPendingMessages() { 611 void RunPendingMessages() {
612 MessageLoopForUI::current()->RunAllPending(); 612 MessageLoopForUI::current()->RunAllPending();
613 } 613 }
614 614
615 private: 615 private:
616 scoped_ptr<NullLayerDelegate> default_layer_delegate_; 616 scoped_ptr<NullLayerDelegate> default_layer_delegate_;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 } 961 }
962 962
963 // Create this hierarchy: 963 // Create this hierarchy:
964 // L1 (no texture) 964 // L1 (no texture)
965 // +- L11 (texture) 965 // +- L11 (texture)
966 // +- L12 (no texture) (added after L1 is already set as root-layer) 966 // +- L12 (no texture) (added after L1 is already set as root-layer)
967 // +- L121 (texture) 967 // +- L121 (texture)
968 // +- L122 (texture) 968 // +- L122 (texture)
969 TEST_F(LayerWithNullDelegateTest, 969 TEST_F(LayerWithNullDelegateTest,
970 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(NoCompositor)) { 970 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(NoCompositor)) {
971 scoped_ptr<Layer> l1(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE)); 971 scoped_ptr<Layer> l1(CreateLayer(Layer::LAYER_NOT_DRAWN));
972 scoped_ptr<Layer> l11(CreateLayer(Layer::LAYER_HAS_TEXTURE)); 972 scoped_ptr<Layer> l11(CreateLayer(Layer::LAYER_TEXTURED));
973 scoped_ptr<Layer> l12(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE)); 973 scoped_ptr<Layer> l12(CreateLayer(Layer::LAYER_NOT_DRAWN));
974 scoped_ptr<Layer> l121(CreateLayer(Layer::LAYER_HAS_TEXTURE)); 974 scoped_ptr<Layer> l121(CreateLayer(Layer::LAYER_TEXTURED));
975 scoped_ptr<Layer> l122(CreateLayer(Layer::LAYER_HAS_TEXTURE)); 975 scoped_ptr<Layer> l122(CreateLayer(Layer::LAYER_TEXTURED));
976 976
977 EXPECT_EQ(NULL, l1->texture()); 977 EXPECT_EQ(NULL, l1->texture());
978 EXPECT_EQ(NULL, l11->texture()); 978 EXPECT_EQ(NULL, l11->texture());
979 EXPECT_EQ(NULL, l12->texture()); 979 EXPECT_EQ(NULL, l12->texture());
980 EXPECT_EQ(NULL, l121->texture()); 980 EXPECT_EQ(NULL, l121->texture());
981 EXPECT_EQ(NULL, l122->texture()); 981 EXPECT_EQ(NULL, l122->texture());
982 982
983 l1->Add(l11.get()); 983 l1->Add(l11.get());
984 l1->SetBounds(gfx::Rect(0, 0, 500, 500)); 984 l1->SetBounds(gfx::Rect(0, 0, 500, 500));
985 l11->SetBounds(gfx::Rect(5, 5, 490, 490)); 985 l11->SetBounds(gfx::Rect(5, 5, 490, 490));
986 986
987 EXPECT_EQ(NULL, l11->texture()); 987 EXPECT_EQ(NULL, l11->texture());
988 988
989 compositor()->SetRootLayer(l1.get()); 989 compositor()->SetRootLayer(l1.get());
990 990
991 EXPECT_EQ(NULL, l1->texture()); 991 EXPECT_EQ(NULL, l1->texture());
992 992
993 // Despite having type LAYER_HAS_TEXTURE, l11 will not have one set yet 993 // Despite having type LAYER_TEXTURED, l11 will not have one set yet
994 // because it has never been asked to draw. 994 // because it has never been asked to draw.
995 EXPECT_EQ(NULL, l11->texture()); 995 EXPECT_EQ(NULL, l11->texture());
996 996
997 l12->Add(l121.get()); 997 l12->Add(l121.get());
998 l12->Add(l122.get()); 998 l12->Add(l122.get());
999 l12->SetBounds(gfx::Rect(5, 5, 480, 480)); 999 l12->SetBounds(gfx::Rect(5, 5, 480, 480));
1000 l121->SetBounds(gfx::Rect(5, 5, 100, 100)); 1000 l121->SetBounds(gfx::Rect(5, 5, 100, 100));
1001 l122->SetBounds(gfx::Rect(110, 110, 100, 100)); 1001 l122->SetBounds(gfx::Rect(110, 110, 100, 100));
1002 1002
1003 EXPECT_EQ(NULL, l121->texture()); 1003 EXPECT_EQ(NULL, l121->texture());
(...skipping 12 matching lines...) Expand all
1016 1016
1017 // Toggling l2's visibility should drop all sub-layer textures. 1017 // Toggling l2's visibility should drop all sub-layer textures.
1018 l12->SetVisible(false); 1018 l12->SetVisible(false);
1019 EXPECT_EQ(NULL, l12->texture()); 1019 EXPECT_EQ(NULL, l12->texture());
1020 EXPECT_EQ(NULL, l121->texture()); 1020 EXPECT_EQ(NULL, l121->texture());
1021 EXPECT_EQ(NULL, l122->texture()); 1021 EXPECT_EQ(NULL, l122->texture());
1022 } 1022 }
1023 1023
1024 // Various visibile/drawn assertions. 1024 // Various visibile/drawn assertions.
1025 TEST_F(LayerWithNullDelegateTest, Visibility) { 1025 TEST_F(LayerWithNullDelegateTest, Visibility) {
1026 scoped_ptr<Layer> l1(new Layer(Layer::LAYER_HAS_TEXTURE)); 1026 scoped_ptr<Layer> l1(new Layer(Layer::LAYER_TEXTURED));
1027 scoped_ptr<Layer> l2(new Layer(Layer::LAYER_HAS_TEXTURE)); 1027 scoped_ptr<Layer> l2(new Layer(Layer::LAYER_TEXTURED));
1028 scoped_ptr<Layer> l3(new Layer(Layer::LAYER_HAS_TEXTURE)); 1028 scoped_ptr<Layer> l3(new Layer(Layer::LAYER_TEXTURED));
1029 l1->Add(l2.get()); 1029 l1->Add(l2.get());
1030 l2->Add(l3.get()); 1030 l2->Add(l3.get());
1031 1031
1032 NullLayerDelegate delegate; 1032 NullLayerDelegate delegate;
1033 l1->set_delegate(&delegate); 1033 l1->set_delegate(&delegate);
1034 l2->set_delegate(&delegate); 1034 l2->set_delegate(&delegate);
1035 l3->set_delegate(&delegate); 1035 l3->set_delegate(&delegate);
1036 1036
1037 // Layers should initially be drawn. 1037 // Layers should initially be drawn.
1038 EXPECT_TRUE(l1->IsDrawn()); 1038 EXPECT_TRUE(l1->IsDrawn());
(...skipping 29 matching lines...) Expand all
1068 EXPECT_TRUE(l1->IsDrawn()); 1068 EXPECT_TRUE(l1->IsDrawn());
1069 EXPECT_TRUE(l2->IsDrawn()); 1069 EXPECT_TRUE(l2->IsDrawn());
1070 EXPECT_FALSE(l3->IsDrawn()); 1070 EXPECT_FALSE(l3->IsDrawn());
1071 #if defined(USE_WEBKIT_COMPOSITOR) 1071 #if defined(USE_WEBKIT_COMPOSITOR)
1072 EXPECT_EQ(1.f, l1->web_layer().opacity()); 1072 EXPECT_EQ(1.f, l1->web_layer().opacity());
1073 #endif 1073 #endif
1074 } 1074 }
1075 1075
1076 // Checks that stacking-related methods behave as advertised. 1076 // Checks that stacking-related methods behave as advertised.
1077 TEST_F(LayerWithNullDelegateTest, Stacking) { 1077 TEST_F(LayerWithNullDelegateTest, Stacking) {
1078 scoped_ptr<Layer> root(new Layer(Layer::LAYER_HAS_NO_TEXTURE)); 1078 scoped_ptr<Layer> root(new Layer(Layer::LAYER_NOT_DRAWN));
1079 scoped_ptr<Layer> l1(new Layer(Layer::LAYER_HAS_TEXTURE)); 1079 scoped_ptr<Layer> l1(new Layer(Layer::LAYER_TEXTURED));
1080 scoped_ptr<Layer> l2(new Layer(Layer::LAYER_HAS_TEXTURE)); 1080 scoped_ptr<Layer> l2(new Layer(Layer::LAYER_TEXTURED));
1081 scoped_ptr<Layer> l3(new Layer(Layer::LAYER_HAS_TEXTURE)); 1081 scoped_ptr<Layer> l3(new Layer(Layer::LAYER_TEXTURED));
1082 l1->set_name("1"); 1082 l1->set_name("1");
1083 l2->set_name("2"); 1083 l2->set_name("2");
1084 l3->set_name("3"); 1084 l3->set_name("3");
1085 root->Add(l3.get()); 1085 root->Add(l3.get());
1086 root->Add(l2.get()); 1086 root->Add(l2.get());
1087 root->Add(l1.get()); 1087 root->Add(l1.get());
1088 1088
1089 // Layers' children are stored in bottom-to-top order. 1089 // Layers' children are stored in bottom-to-top order.
1090 EXPECT_EQ("3,2,1", GetLayerChildrenNames(*root.get())); 1090 EXPECT_EQ("3,2,1", GetLayerChildrenNames(*root.get()));
1091 1091
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1458 EXPECT_TRUE(schedule_draw_invoked_); 1458 EXPECT_TRUE(schedule_draw_invoked_);
1459 // Because SchedulePaint() was invoked from OnPaintLayer() |child| should 1459 // Because SchedulePaint() was invoked from OnPaintLayer() |child| should
1460 // still need to be painted. 1460 // still need to be painted.
1461 DrawTree(root.get()); 1461 DrawTree(root.get());
1462 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear()); 1462 EXPECT_EQ(1, child_delegate.GetPaintCountAndClear());
1463 EXPECT_TRUE(child_delegate.last_clip_rect().Contains( 1463 EXPECT_TRUE(child_delegate.last_clip_rect().Contains(
1464 gfx::Rect(10, 10, 30, 30))); 1464 gfx::Rect(10, 10, 30, 30)));
1465 } 1465 }
1466 1466
1467 } // namespace ui 1467 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698