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

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

Issue 8360018: Revert 106606 - Use WebKit compositor in ui::Layer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 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/gfx/compositor/test_compositor.h » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/canvas_skia.h" 9 #include "ui/gfx/canvas_skia.h"
10 #include "ui/gfx/compositor/compositor_observer.h" 10 #include "ui/gfx/compositor/compositor_observer.h"
11 #include "ui/gfx/compositor/layer.h" 11 #include "ui/gfx/compositor/layer.h"
12 #include "ui/gfx/compositor/test_compositor.h" 12 #include "ui/gfx/compositor/test_compositor.h"
13 #include "ui/gfx/compositor/test_compositor_host.h" 13 #include "ui/gfx/compositor/test_compositor_host.h"
14 14
15 namespace ui { 15 namespace ui {
16 16
17 namespace { 17 namespace {
18 18
19 // There are three test classes in here that configure the Compositor and 19 // There are three test classes in here that configure the Compositor and
20 // Layer's slightly differently: 20 // Layer's slightly differently:
21 // - LayerWithNullDelegateTest uses TestCompositor and NullLayerDelegate as the 21 // - LayerWithNullDelegateTest uses TestCompositor and NullLayerDelegate as the
22 // LayerDelegate. This is typically the base class you want to use. 22 // LayerDelegate. This is typically the base class you want to use.
23 // - LayerWithDelegateTest uses TestCompositor and does not set a LayerDelegate 23 // - LayerWithDelegateTest uses TestCompositor and does not set a LayerDelegate
24 // on the delegates. 24 // on the delegates.
25 // - LayerWithRealCompositorTest when a real compositor is required for testing. 25 // - LayerWithRealCompositorTest when a real compositor is required for testing.
26 // - Slow because they bring up a window and run the real compositor. This 26 // - Slow because they bring up a window and run the real compositor. This
27 // is typically not what you want. 27 // is typically not what you want.
28
29 class ColoredLayer : public Layer, public LayerDelegate {
30 public:
31 ColoredLayer(Compositor* compositor, SkColor color)
32 : Layer(compositor, Layer::LAYER_HAS_TEXTURE),
33 color_(color) {
34 set_delegate(this);
35 }
36
37 virtual ~ColoredLayer() { }
38
39 // Overridden from LayerDelegate:
40 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
41 canvas->GetSkCanvas()->drawColor(color_);
42 }
43
44 private:
45 SkColor color_;
46 };
47
48 class LayerWithRealCompositorTest : public testing::Test { 28 class LayerWithRealCompositorTest : public testing::Test {
49 public: 29 public:
50 LayerWithRealCompositorTest() {} 30 LayerWithRealCompositorTest() {}
51 virtual ~LayerWithRealCompositorTest() {} 31 virtual ~LayerWithRealCompositorTest() {}
52 32
53 // Overridden from testing::Test: 33 // Overridden from testing::Test:
54 virtual void SetUp() OVERRIDE { 34 virtual void SetUp() OVERRIDE {
55 const gfx::Rect host_bounds(10, 10, 500, 500); 35 const gfx::Rect host_bounds(10, 10, 500, 500);
56 window_.reset(TestCompositorHost::Create(host_bounds)); 36 window_.reset(TestCompositorHost::Create(host_bounds));
57 window_->Show(); 37 window_->Show();
58 } 38 }
59 39
60 virtual void TearDown() OVERRIDE { 40 virtual void TearDown() OVERRIDE {
61 } 41 }
62 42
63 Compositor* GetCompositor() { 43 Compositor* GetCompositor() {
64 return window_->GetCompositor(); 44 return window_->GetCompositor();
65 } 45 }
66 46
67 Layer* CreateLayer(Layer::LayerType type) { 47 Layer* CreateLayer(Layer::LayerType type) {
68 return new Layer(GetCompositor(), type); 48 return new Layer(GetCompositor(), type);
69 } 49 }
70 50
71 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { 51 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
72 Layer* layer = new ColoredLayer(GetCompositor(), color); 52 Layer* layer = CreateLayer(Layer::LAYER_HAS_TEXTURE);
73 layer->SetBounds(bounds); 53 layer->SetBounds(bounds);
54 PaintColorToLayer(layer, color);
74 return layer; 55 return layer;
75 } 56 }
76 57
77 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { 58 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) {
78 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); 59 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE);
79 layer->SetBounds(bounds); 60 layer->SetBounds(bounds);
80 return layer; 61 return layer;
81 } 62 }
82 63
83 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) { 64 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) {
84 return gfx::Canvas::CreateCanvas(layer->bounds().width(), 65 return gfx::Canvas::CreateCanvas(layer->bounds().width(),
85 layer->bounds().height(), 66 layer->bounds().height(),
86 false); 67 false);
87 } 68 }
88 69
70 void PaintColorToLayer(Layer* layer, SkColor color) {
71 scoped_ptr<gfx::Canvas> canvas(CreateCanvasForLayer(layer));
72 canvas->FillRectInt(color, 0, 0, layer->bounds().width(),
73 layer->bounds().height());
74 layer->SetCanvas(*canvas->GetSkCanvas(), layer->bounds().origin());
75 }
76
89 void DrawTree(Layer* root) { 77 void DrawTree(Layer* root) {
90 GetCompositor()->SetRootLayer(root); 78 GetCompositor()->SetRootLayer(root);
91 GetCompositor()->Draw(false); 79 GetCompositor()->Draw(false);
92 } 80 }
93 81
94 void RunPendingMessages() { 82 void RunPendingMessages() {
95 MessageLoopForUI::current()->RunAllPending(); 83 MessageLoopForUI::current()->RunAllPending();
96 } 84 }
97 85
98 // Invalidates the entire contents of the layer. 86 // Invalidates the entire contents of the layer.
99 void SchedulePaintForLayer(Layer* layer) { 87 void SchedulePaintForLayer(Layer* layer) {
100 layer->SchedulePaint( 88 layer->SchedulePaint(
101 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); 89 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
102 } 90 }
103 91
104 private: 92 private:
93 MessageLoopForUI message_loop_;
105 scoped_ptr<TestCompositorHost> window_; 94 scoped_ptr<TestCompositorHost> window_;
106 95
107 DISALLOW_COPY_AND_ASSIGN(LayerWithRealCompositorTest); 96 DISALLOW_COPY_AND_ASSIGN(LayerWithRealCompositorTest);
108 }; 97 };
109 98
110 // LayerDelegate that paints colors to the layer. 99 // LayerDelegate that paints colors to the layer.
111 class TestLayerDelegate : public LayerDelegate { 100 class TestLayerDelegate : public LayerDelegate {
112 public: 101 public:
113 explicit TestLayerDelegate() : color_index_(0) {} 102 explicit TestLayerDelegate(Layer* owner) : owner_(owner), color_index_(0) {}
114 virtual ~TestLayerDelegate() {} 103 virtual ~TestLayerDelegate() {}
115 104
116 void AddColor(SkColor color) { 105 void AddColor(SkColor color) {
117 colors_.push_back(color); 106 colors_.push_back(color);
118 } 107 }
119 108
120 gfx::Size paint_size() const { return paint_size_; } 109 gfx::Size paint_size() const { return paint_size_; }
121 int color_index() const { return color_index_; } 110 int color_index() const { return color_index_; }
122 111
123 // Overridden from LayerDelegate: 112 // Overridden from LayerDelegate:
124 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { 113 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
125 SkBitmap contents = canvas->AsCanvasSkia()->ExtractBitmap(); 114 SkBitmap contents = canvas->AsCanvasSkia()->ExtractBitmap();
126 paint_size_ = gfx::Size(contents.width(), contents.height()); 115 paint_size_ = gfx::Size(contents.width(), contents.height());
127 canvas->FillRectInt(colors_.at(color_index_), 0, 0, 116 canvas->FillRectInt(colors_.at(color_index_), 0, 0,
128 contents.width(), 117 contents.width(),
129 contents.height()); 118 contents.height());
130 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size()); 119 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size());
131 } 120 }
132 121
133 private: 122 private:
123 Layer* owner_;
134 std::vector<SkColor> colors_; 124 std::vector<SkColor> colors_;
135 int color_index_; 125 int color_index_;
136 gfx::Size paint_size_; 126 gfx::Size paint_size_;
137 127
138 DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate); 128 DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate);
139 }; 129 };
140 130
141 // LayerDelegate that verifies that a layer was asked to update its canvas. 131 // LayerDelegate that verifies that a layer was asked to update its canvas.
142 class DrawTreeLayerDelegate : public LayerDelegate { 132 class DrawTreeLayerDelegate : public LayerDelegate {
143 public: 133 public:
(...skipping 29 matching lines...) Expand all
173 } 163 }
174 164
175 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); 165 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate);
176 }; 166 };
177 167
178 } 168 }
179 169
180 #if defined(OS_WIN) 170 #if defined(OS_WIN)
181 // These are disabled on windows as they don't run correctly on the buildbot. 171 // These are disabled on windows as they don't run correctly on the buildbot.
182 // Reenable once we move to the real compositor. 172 // Reenable once we move to the real compositor.
183 #define MAYBE_Delegate DISABLED_Delegate
184 #define MAYBE_Draw DISABLED_Draw 173 #define MAYBE_Draw DISABLED_Draw
185 #define MAYBE_DrawTree DISABLED_DrawTree
186 #define MAYBE_Hierarchy DISABLED_Hierarchy 174 #define MAYBE_Hierarchy DISABLED_Hierarchy
187 #define MAYBE_HierarchyNoTexture DISABLED_HierarchyNoTexture
188 #else 175 #else
189 #define MAYBE_Delegate Delegate
190 #define MAYBE_Draw Draw 176 #define MAYBE_Draw Draw
191 #define MAYBE_DrawTree DrawTree
192 #define MAYBE_Hierarchy Hierarchy 177 #define MAYBE_Hierarchy Hierarchy
193 #define MAYBE_HierarchyNoTexture HierarchyNoTexture
194 #endif 178 #endif
195 179
196 TEST_F(LayerWithRealCompositorTest, MAYBE_Draw) { 180 TEST_F(LayerWithRealCompositorTest, MAYBE_Draw) {
197 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, 181 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED,
198 gfx::Rect(20, 20, 50, 50))); 182 gfx::Rect(20, 20, 50, 50)));
199 DrawTree(layer.get()); 183 DrawTree(layer.get());
200 } 184 }
201 185
202 // Create this hierarchy: 186 // Create this hierarchy:
203 // L1 - red 187 // L1 - red
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 virtual void TearDown() OVERRIDE { 219 virtual void TearDown() OVERRIDE {
236 } 220 }
237 221
238 Compositor* compositor() { return compositor_.get(); } 222 Compositor* compositor() { return compositor_.get(); }
239 223
240 virtual Layer* CreateLayer(Layer::LayerType type) { 224 virtual Layer* CreateLayer(Layer::LayerType type) {
241 return new Layer(compositor(), type); 225 return new Layer(compositor(), type);
242 } 226 }
243 227
244 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { 228 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
245 Layer* layer = new ColoredLayer(compositor(), color); 229 Layer* layer = CreateLayer(Layer::LAYER_HAS_TEXTURE);
246 layer->SetBounds(bounds); 230 layer->SetBounds(bounds);
231 PaintColorToLayer(layer, color);
247 return layer; 232 return layer;
248 } 233 }
249 234
250 virtual Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { 235 virtual Layer* CreateNoTextureLayer(const gfx::Rect& bounds) {
251 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); 236 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE);
252 layer->SetBounds(bounds); 237 layer->SetBounds(bounds);
253 return layer; 238 return layer;
254 } 239 }
255 240
256 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) { 241 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) {
257 return gfx::Canvas::CreateCanvas(layer->bounds().width(), 242 return gfx::Canvas::CreateCanvas(layer->bounds().width(),
258 layer->bounds().height(), 243 layer->bounds().height(),
259 false); 244 false);
260 } 245 }
261 246
247 void PaintColorToLayer(Layer* layer, SkColor color) {
248 scoped_ptr<gfx::Canvas> canvas(CreateCanvasForLayer(layer));
249 canvas->FillRectInt(color, 0, 0, layer->bounds().width(),
250 layer->bounds().height());
251 layer->SetCanvas(*canvas->GetSkCanvas(), layer->bounds().origin());
252 }
253
262 void DrawTree(Layer* root) { 254 void DrawTree(Layer* root) {
263 compositor()->SetRootLayer(root); 255 compositor()->SetRootLayer(root);
264 compositor()->Draw(false); 256 compositor()->Draw(false);
265 } 257 }
266 258
267 // Invalidates the entire contents of the layer. 259 // Invalidates the entire contents of the layer.
268 void SchedulePaintForLayer(Layer* layer) { 260 void SchedulePaintForLayer(Layer* layer) {
269 layer->SchedulePaint( 261 layer->SchedulePaint(
270 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); 262 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
271 } 263 }
272 264
273 // Invokes DrawTree on the compositor. 265 // Invokes DrawTree on the compositor.
274 void Draw() { 266 void Draw() {
275 compositor_->Draw(false); 267 compositor_->root_layer()->DrawTree();
276 } 268 }
277 269
278 private: 270 private:
279 scoped_refptr<TestCompositor> compositor_; 271 scoped_refptr<TestCompositor> compositor_;
280 272
281 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest); 273 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest);
282 }; 274 };
283 275
284 // L1 276 // L1
285 // +-- L2 277 // +-- L2
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 Layer::ConvertPointToLayer(l3.get(), l1.get(), &point1_in_l3_coords); 312 Layer::ConvertPointToLayer(l3.get(), l1.get(), &point1_in_l3_coords);
321 gfx::Point point1_in_l1_coords(25, 25); 313 gfx::Point point1_in_l1_coords(25, 25);
322 EXPECT_EQ(point1_in_l1_coords, point1_in_l3_coords); 314 EXPECT_EQ(point1_in_l1_coords, point1_in_l3_coords);
323 315
324 gfx::Point point2_in_l1_coords(5, 5); 316 gfx::Point point2_in_l1_coords(5, 5);
325 Layer::ConvertPointToLayer(l1.get(), l3.get(), &point2_in_l1_coords); 317 Layer::ConvertPointToLayer(l1.get(), l3.get(), &point2_in_l1_coords);
326 gfx::Point point2_in_l3_coords(-15, -15); 318 gfx::Point point2_in_l3_coords(-15, -15);
327 EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords); 319 EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords);
328 } 320 }
329 321
330 TEST_F(LayerWithRealCompositorTest, MAYBE_Delegate) { 322 TEST_F(LayerWithDelegateTest, Delegate) {
331 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorBLACK, 323 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorBLACK,
332 gfx::Rect(20, 20, 400, 400))); 324 gfx::Rect(20, 20, 400, 400)));
333 GetCompositor()->SetRootLayer(l1.get()); 325 TestLayerDelegate delegate(l1.get());
334 RunPendingMessages();
335
336 TestLayerDelegate delegate;
337 l1->set_delegate(&delegate); 326 l1->set_delegate(&delegate);
338 delegate.AddColor(SK_ColorWHITE); 327 delegate.AddColor(SK_ColorWHITE);
339 delegate.AddColor(SK_ColorYELLOW); 328 delegate.AddColor(SK_ColorYELLOW);
340 delegate.AddColor(SK_ColorGREEN); 329 delegate.AddColor(SK_ColorGREEN);
341 330
331 compositor()->SetRootLayer(l1.get());
332
342 l1->SchedulePaint(gfx::Rect(0, 0, 400, 400)); 333 l1->SchedulePaint(gfx::Rect(0, 0, 400, 400));
343 RunPendingMessages(); 334 Draw();
344 EXPECT_EQ(delegate.color_index(), 1); 335 EXPECT_EQ(delegate.color_index(), 1);
345 EXPECT_EQ(delegate.paint_size(), l1->bounds().size()); 336 EXPECT_EQ(delegate.paint_size(), l1->bounds().size());
346 337
347 l1->SchedulePaint(gfx::Rect(10, 10, 200, 200)); 338 l1->SchedulePaint(gfx::Rect(10, 10, 200, 200));
348 RunPendingMessages(); 339 Draw();
349 EXPECT_EQ(delegate.color_index(), 2); 340 EXPECT_EQ(delegate.color_index(), 2);
350 EXPECT_EQ(delegate.paint_size(), gfx::Size(200, 200)); 341 EXPECT_EQ(delegate.paint_size(), gfx::Size(200, 200));
351 342
352 l1->SchedulePaint(gfx::Rect(5, 5, 50, 50)); 343 l1->SchedulePaint(gfx::Rect(5, 5, 50, 50));
353 RunPendingMessages(); 344 Draw();
354 EXPECT_EQ(delegate.color_index(), 0); 345 EXPECT_EQ(delegate.color_index(), 0);
355 EXPECT_EQ(delegate.paint_size(), gfx::Size(50, 50)); 346 EXPECT_EQ(delegate.paint_size(), gfx::Size(50, 50));
356 } 347 }
357 348
358 TEST_F(LayerWithRealCompositorTest, MAYBE_DrawTree) { 349 TEST_F(LayerWithDelegateTest, DrawTree) {
359 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, 350 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
360 gfx::Rect(20, 20, 400, 400))); 351 gfx::Rect(20, 20, 400, 400)));
361 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, 352 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE,
362 gfx::Rect(10, 10, 350, 350))); 353 gfx::Rect(10, 10, 350, 350)));
363 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, 354 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW,
364 gfx::Rect(10, 10, 100, 100))); 355 gfx::Rect(10, 10, 100, 100)));
365 l1->Add(l2.get()); 356 l1->Add(l2.get());
366 l2->Add(l3.get()); 357 l2->Add(l3.get());
367 358
368 GetCompositor()->SetRootLayer(l1.get());
369 RunPendingMessages();
370
371 DrawTreeLayerDelegate d1; 359 DrawTreeLayerDelegate d1;
372 l1->set_delegate(&d1); 360 l1->set_delegate(&d1);
373 DrawTreeLayerDelegate d2; 361 DrawTreeLayerDelegate d2;
374 l2->set_delegate(&d2); 362 l2->set_delegate(&d2);
375 DrawTreeLayerDelegate d3; 363 DrawTreeLayerDelegate d3;
376 l3->set_delegate(&d3); 364 l3->set_delegate(&d3);
377 365
366 compositor()->SetRootLayer(l1.get());
367
378 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5)); 368 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5));
379 RunPendingMessages(); 369 Draw();
380 EXPECT_FALSE(d1.painted()); 370 EXPECT_FALSE(d1.painted());
381 EXPECT_TRUE(d2.painted()); 371 EXPECT_TRUE(d2.painted());
382 EXPECT_FALSE(d3.painted()); 372 EXPECT_FALSE(d3.painted());
383 } 373 }
384 374
385 // Tests no-texture Layers. 375 // Tests no-texture Layers.
386 // Create this hierarchy: 376 // Create this hierarchy:
387 // L1 - red 377 // L1 - red
388 // +-- L2 - NO TEXTURE 378 // +-- L2 - NO TEXTURE
389 // | +-- L3 - yellow 379 // | +-- L3 - yellow
390 // +-- L4 - magenta 380 // +-- L4 - magenta
391 // 381 //
392 TEST_F(LayerWithRealCompositorTest, MAYBE_HierarchyNoTexture) { 382 TEST_F(LayerWithDelegateTest, HierarchyNoTexture) {
393 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, 383 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
394 gfx::Rect(20, 20, 400, 400))); 384 gfx::Rect(20, 20, 400, 400)));
395 scoped_ptr<Layer> l2(CreateNoTextureLayer(gfx::Rect(10, 10, 350, 350))); 385 scoped_ptr<Layer> l2(CreateNoTextureLayer(gfx::Rect(10, 10, 350, 350)));
396 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, 386 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW,
397 gfx::Rect(5, 5, 25, 25))); 387 gfx::Rect(5, 5, 25, 25)));
398 scoped_ptr<Layer> l4(CreateColorLayer(SK_ColorMAGENTA, 388 scoped_ptr<Layer> l4(CreateColorLayer(SK_ColorMAGENTA,
399 gfx::Rect(300, 300, 100, 100))); 389 gfx::Rect(300, 300, 100, 100)));
400 390
401 l1->Add(l2.get()); 391 l1->Add(l2.get());
402 l1->Add(l4.get()); 392 l1->Add(l4.get());
403 l2->Add(l3.get()); 393 l2->Add(l3.get());
404 394
405 GetCompositor()->SetRootLayer(l1.get());
406 RunPendingMessages();
407
408 DrawTreeLayerDelegate d2; 395 DrawTreeLayerDelegate d2;
409 l2->set_delegate(&d2); 396 l2->set_delegate(&d2);
410 DrawTreeLayerDelegate d3; 397 DrawTreeLayerDelegate d3;
411 l3->set_delegate(&d3); 398 l3->set_delegate(&d3);
412 399
400 compositor()->SetRootLayer(l1.get());
401
413 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5)); 402 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5));
414 l3->SchedulePaint(gfx::Rect(5, 5, 5, 5)); 403 l3->SchedulePaint(gfx::Rect(5, 5, 5, 5));
415 RunPendingMessages(); 404 Draw();
416 405
417 // |d2| should not have received a paint notification since it has no texture. 406 // |d2| should not have received a paint notification since it has no texture.
418 EXPECT_FALSE(d2.painted()); 407 EXPECT_FALSE(d2.painted());
419 // |d3| should have received a paint notification. 408 // |d3| should have received a paint notification.
420 EXPECT_TRUE(d3.painted()); 409 EXPECT_TRUE(d3.painted());
421 } 410 }
422 411
423 class LayerWithNullDelegateTest : public LayerWithDelegateTest { 412 class LayerWithNullDelegateTest : public LayerWithDelegateTest {
424 public: 413 public:
425 LayerWithNullDelegateTest() {} 414 LayerWithNullDelegateTest() {}
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 scoped_ptr<Layer> parent(CreateNoTextureLayer(gfx::Rect(0, 0, 400, 400))); 459 scoped_ptr<Layer> parent(CreateNoTextureLayer(gfx::Rect(0, 0, 400, 400)));
471 scoped_ptr<Layer> child(CreateNoTextureLayer(gfx::Rect(50, 50, 100, 100))); 460 scoped_ptr<Layer> child(CreateNoTextureLayer(gfx::Rect(50, 50, 100, 100)));
472 parent->Add(child.get()); 461 parent->Add(child.get());
473 462
474 compositor()->SetRootLayer(parent.get()); 463 compositor()->SetRootLayer(parent.get());
475 Draw(); 464 Draw();
476 EXPECT_TRUE(child->texture() == NULL); 465 EXPECT_TRUE(child->texture() == NULL);
477 EXPECT_TRUE(parent->texture() == NULL); 466 EXPECT_TRUE(parent->texture() == NULL);
478 } 467 }
479 468
480 // With the webkit compositor, we don't explicitly textures for layers, making
481 // tests that check that we do fail.
482 #if defined(USE_WEBKIT_COMPOSITOR)
483 #define WEBKIT_COMPOSITOR_FAILS(X) FAILS_ ## X
484 #else
485 #define WEBKIT_COMPOSITOR_FAILS(X) X
486 #endif
487
488 // Verifies that a layer does not have a texture when the hole is the size 469 // Verifies that a layer does not have a texture when the hole is the size
489 // of the parent layer. 470 // of the parent layer.
490 TEST_F(LayerWithNullDelegateTest, 471 TEST_F(LayerWithNullDelegateTest, LayerNoTextureHoleSizeOfLayer) {
491 WEBKIT_COMPOSITOR_FAILS(LayerNoTextureHoleSizeOfLayer)) {
492 scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400))); 472 scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
493 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100))); 473 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
494 parent->Add(child.get()); 474 parent->Add(child.get());
495 475
496 Draw(); 476 Draw();
497 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), parent->hole_rect()); 477 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), parent->hole_rect());
498 EXPECT_TRUE(parent->texture() != NULL); 478 EXPECT_TRUE(parent->texture() != NULL);
499 479
500 child->SetBounds(gfx::Rect(0, 0, 400, 400)); 480 child->SetBounds(gfx::Rect(0, 0, 400, 400));
501 Draw(); 481 Draw();
502 EXPECT_TRUE(parent->texture() == NULL); 482 EXPECT_TRUE(parent->texture() == NULL);
503 } 483 }
504 484
505 // Verifies that a layer which has opacity == 0 does not have a texture. 485 // Verifies that a layer which has opacity == 0 does not have a texture.
506 TEST_F(LayerWithNullDelegateTest, 486 TEST_F(LayerWithNullDelegateTest, LayerNoTextureTransparent) {
507 WEBKIT_COMPOSITOR_FAILS(LayerNoTextureTransparent)) {
508 scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400))); 487 scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
509 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100))); 488 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
510 parent->Add(child.get()); 489 parent->Add(child.get());
511 490
512 parent->SetOpacity(0.0f); 491 parent->SetOpacity(0.0f);
513 child->SetOpacity(0.0f); 492 child->SetOpacity(0.0f);
514 Draw(); 493 Draw();
515 EXPECT_TRUE(parent->texture() == NULL); 494 EXPECT_TRUE(parent->texture() == NULL);
516 EXPECT_TRUE(child->texture() == NULL); 495 EXPECT_TRUE(child->texture() == NULL);
517 496
518 parent->SetOpacity(1.0f); 497 parent->SetOpacity(1.0f);
519 Draw(); 498 Draw();
520 EXPECT_TRUE(parent->texture() != NULL); 499 EXPECT_TRUE(parent->texture() != NULL);
521 EXPECT_TRUE(child->texture() == NULL); 500 EXPECT_TRUE(child->texture() == NULL);
522 501
523 child->SetOpacity(1.0f); 502 child->SetOpacity(1.0f);
524 Draw(); 503 Draw();
525 EXPECT_TRUE(parent->texture() != NULL); 504 EXPECT_TRUE(parent->texture() != NULL);
526 EXPECT_TRUE(child->texture() != NULL); 505 EXPECT_TRUE(child->texture() != NULL);
527 } 506 }
528 507
529 // Verifies that no texture is created for a layer with empty bounds. 508 // Verifies that no texture is created for a layer with empty bounds.
530 TEST_F(LayerWithNullDelegateTest, 509 TEST_F(LayerWithNullDelegateTest, LayerTextureNonEmptySchedulePaint) {
531 WEBKIT_COMPOSITOR_FAILS(LayerTextureNonEmptySchedulePaint)) {
532 scoped_ptr<Layer> layer(CreateTextureRootLayer(gfx::Rect(0, 0, 0, 0))); 510 scoped_ptr<Layer> layer(CreateTextureRootLayer(gfx::Rect(0, 0, 0, 0)));
533 Draw(); 511 Draw();
534 EXPECT_TRUE(layer->texture() == NULL); 512 EXPECT_TRUE(layer->texture() == NULL);
535 513
536 layer->SetBounds(gfx::Rect(0, 0, 400, 400)); 514 layer->SetBounds(gfx::Rect(0, 0, 400, 400));
537 Draw(); 515 Draw();
538 EXPECT_TRUE(layer->texture() != NULL); 516 EXPECT_TRUE(layer->texture() != NULL);
539 } 517 }
540 518
541 // Verifies that when there are many potential holes, the largest one is picked. 519 // Verifies that when there are many potential holes, the largest one is picked.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 EXPECT_EQ(target_rect, parent->hole_rect()); 582 EXPECT_EQ(target_rect, parent->hole_rect());
605 } 583 }
606 } 584 }
607 585
608 // Create this hierarchy: 586 // Create this hierarchy:
609 // L1 (no texture) 587 // L1 (no texture)
610 // +- L11 (texture) 588 // +- L11 (texture)
611 // +- L12 (no texture) (added after L1 is already set as root-layer) 589 // +- L12 (no texture) (added after L1 is already set as root-layer)
612 // +- L121 (texture) 590 // +- L121 (texture)
613 // +- L122 (texture) 591 // +- L122 (texture)
614 TEST_F(LayerWithNullDelegateTest, WEBKIT_COMPOSITOR_FAILS(NoCompositor)) { 592 TEST_F(LayerWithNullDelegateTest, NoCompositor) {
615 scoped_ptr<Layer> l1(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE)); 593 scoped_ptr<Layer> l1(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE));
616 scoped_ptr<Layer> l11(CreateLayer(Layer::LAYER_HAS_TEXTURE)); 594 scoped_ptr<Layer> l11(CreateLayer(Layer::LAYER_HAS_TEXTURE));
617 scoped_ptr<Layer> l12(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE)); 595 scoped_ptr<Layer> l12(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE));
618 scoped_ptr<Layer> l121(CreateLayer(Layer::LAYER_HAS_TEXTURE)); 596 scoped_ptr<Layer> l121(CreateLayer(Layer::LAYER_HAS_TEXTURE));
619 scoped_ptr<Layer> l122(CreateLayer(Layer::LAYER_HAS_TEXTURE)); 597 scoped_ptr<Layer> l122(CreateLayer(Layer::LAYER_HAS_TEXTURE));
620 598
621 EXPECT_EQ(NULL, l1->texture()); 599 EXPECT_EQ(NULL, l1->texture());
622 EXPECT_EQ(NULL, l11->texture()); 600 EXPECT_EQ(NULL, l11->texture());
623 EXPECT_EQ(NULL, l12->texture()); 601 EXPECT_EQ(NULL, l12->texture());
624 EXPECT_EQ(NULL, l121->texture()); 602 EXPECT_EQ(NULL, l121->texture());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 EXPECT_FALSE(l2->IsDrawn()); 675 EXPECT_FALSE(l2->IsDrawn());
698 EXPECT_FALSE(l3->IsDrawn()); 676 EXPECT_FALSE(l3->IsDrawn());
699 677
700 l1->SetVisible(true); 678 l1->SetVisible(true);
701 EXPECT_TRUE(l1->IsDrawn()); 679 EXPECT_TRUE(l1->IsDrawn());
702 EXPECT_TRUE(l2->IsDrawn()); 680 EXPECT_TRUE(l2->IsDrawn());
703 EXPECT_FALSE(l3->IsDrawn()); 681 EXPECT_FALSE(l3->IsDrawn());
704 } 682 }
705 683
706 } // namespace ui 684 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/layer.cc ('k') | ui/gfx/compositor/test_compositor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698