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

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

Issue 8222028: Use WebKit compositor in ui::Layer (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: rebase,fixes 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
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
28 class LayerWithRealCompositorTest : public testing::Test { 48 class LayerWithRealCompositorTest : public testing::Test {
29 public: 49 public:
30 LayerWithRealCompositorTest() {} 50 LayerWithRealCompositorTest() {}
31 virtual ~LayerWithRealCompositorTest() {} 51 virtual ~LayerWithRealCompositorTest() {}
32 52
33 // Overridden from testing::Test: 53 // Overridden from testing::Test:
34 virtual void SetUp() OVERRIDE { 54 virtual void SetUp() OVERRIDE {
35 const gfx::Rect host_bounds(10, 10, 500, 500); 55 const gfx::Rect host_bounds(10, 10, 500, 500);
36 window_.reset(TestCompositorHost::Create(host_bounds)); 56 window_.reset(TestCompositorHost::Create(host_bounds));
37 window_->Show(); 57 window_->Show();
38 } 58 }
39 59
40 virtual void TearDown() OVERRIDE { 60 virtual void TearDown() OVERRIDE {
41 } 61 }
42 62
43 Compositor* GetCompositor() { 63 Compositor* GetCompositor() {
44 return window_->GetCompositor(); 64 return window_->GetCompositor();
45 } 65 }
46 66
47 Layer* CreateLayer(Layer::LayerType type) { 67 Layer* CreateLayer(Layer::LayerType type) {
48 return new Layer(GetCompositor(), type); 68 return new Layer(GetCompositor(), type);
49 } 69 }
50 70
51 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { 71 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
52 Layer* layer = CreateLayer(Layer::LAYER_HAS_TEXTURE); 72 Layer* layer = new ColoredLayer(GetCompositor(), color);
53 layer->SetBounds(bounds); 73 layer->SetBounds(bounds);
54 PaintColorToLayer(layer, color);
55 return layer; 74 return layer;
56 } 75 }
57 76
58 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { 77 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) {
59 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); 78 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE);
60 layer->SetBounds(bounds); 79 layer->SetBounds(bounds);
61 return layer; 80 return layer;
62 } 81 }
63 82
64 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) { 83 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) {
65 return gfx::Canvas::CreateCanvas(layer->bounds().width(), 84 return gfx::Canvas::CreateCanvas(layer->bounds().width(),
66 layer->bounds().height(), 85 layer->bounds().height(),
67 false); 86 false);
68 } 87 }
69 88
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
77 void DrawTree(Layer* root) { 89 void DrawTree(Layer* root) {
78 GetCompositor()->SetRootLayer(root); 90 GetCompositor()->SetRootLayer(root);
79 GetCompositor()->Draw(false); 91 GetCompositor()->Draw(false);
80 } 92 }
81 93
82 void RunPendingMessages() { 94 void RunPendingMessages() {
83 MessageLoopForUI::current()->RunAllPending(); 95 MessageLoopForUI::current()->RunAllPending();
84 } 96 }
85 97
86 // Invalidates the entire contents of the layer. 98 // Invalidates the entire contents of the layer.
87 void SchedulePaintForLayer(Layer* layer) { 99 void SchedulePaintForLayer(Layer* layer) {
88 layer->SchedulePaint( 100 layer->SchedulePaint(
89 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); 101 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
90 } 102 }
91 103
92 private: 104 private:
93 MessageLoopForUI message_loop_;
94 scoped_ptr<TestCompositorHost> window_; 105 scoped_ptr<TestCompositorHost> window_;
95 106
96 DISALLOW_COPY_AND_ASSIGN(LayerWithRealCompositorTest); 107 DISALLOW_COPY_AND_ASSIGN(LayerWithRealCompositorTest);
97 }; 108 };
98 109
99 // LayerDelegate that paints colors to the layer. 110 // LayerDelegate that paints colors to the layer.
100 class TestLayerDelegate : public LayerDelegate { 111 class TestLayerDelegate : public LayerDelegate {
101 public: 112 public:
102 explicit TestLayerDelegate(Layer* owner) : owner_(owner), color_index_(0) {} 113 explicit TestLayerDelegate() : color_index_(0) {}
103 virtual ~TestLayerDelegate() {} 114 virtual ~TestLayerDelegate() {}
104 115
105 void AddColor(SkColor color) { 116 void AddColor(SkColor color) {
106 colors_.push_back(color); 117 colors_.push_back(color);
107 } 118 }
108 119
109 gfx::Size paint_size() const { return paint_size_; } 120 gfx::Size paint_size() const { return paint_size_; }
110 int color_index() const { return color_index_; } 121 int color_index() const { return color_index_; }
111 122
112 // Overridden from LayerDelegate: 123 // Overridden from LayerDelegate:
113 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { 124 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
114 SkBitmap contents = canvas->AsCanvasSkia()->ExtractBitmap(); 125 SkBitmap contents = canvas->AsCanvasSkia()->ExtractBitmap();
115 paint_size_ = gfx::Size(contents.width(), contents.height()); 126 paint_size_ = gfx::Size(contents.width(), contents.height());
116 canvas->FillRectInt(colors_.at(color_index_), 0, 0, 127 canvas->FillRectInt(colors_.at(color_index_), 0, 0,
117 contents.width(), 128 contents.width(),
118 contents.height()); 129 contents.height());
119 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size()); 130 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size());
120 } 131 }
121 132
122 private: 133 private:
123 Layer* owner_;
124 std::vector<SkColor> colors_; 134 std::vector<SkColor> colors_;
125 int color_index_; 135 int color_index_;
126 gfx::Size paint_size_; 136 gfx::Size paint_size_;
127 137
128 DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate); 138 DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate);
129 }; 139 };
130 140
131 // LayerDelegate that verifies that a layer was asked to update its canvas. 141 // LayerDelegate that verifies that a layer was asked to update its canvas.
132 class DrawTreeLayerDelegate : public LayerDelegate { 142 class DrawTreeLayerDelegate : public LayerDelegate {
133 public: 143 public:
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 virtual void TearDown() OVERRIDE { 229 virtual void TearDown() OVERRIDE {
220 } 230 }
221 231
222 Compositor* compositor() { return compositor_.get(); } 232 Compositor* compositor() { return compositor_.get(); }
223 233
224 virtual Layer* CreateLayer(Layer::LayerType type) { 234 virtual Layer* CreateLayer(Layer::LayerType type) {
225 return new Layer(compositor(), type); 235 return new Layer(compositor(), type);
226 } 236 }
227 237
228 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { 238 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
229 Layer* layer = CreateLayer(Layer::LAYER_HAS_TEXTURE); 239 Layer* layer = new ColoredLayer(compositor(), color);
230 layer->SetBounds(bounds); 240 layer->SetBounds(bounds);
231 PaintColorToLayer(layer, color);
232 return layer; 241 return layer;
233 } 242 }
234 243
235 virtual Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { 244 virtual Layer* CreateNoTextureLayer(const gfx::Rect& bounds) {
236 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); 245 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE);
237 layer->SetBounds(bounds); 246 layer->SetBounds(bounds);
238 return layer; 247 return layer;
239 } 248 }
240 249
241 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) { 250 gfx::Canvas* CreateCanvasForLayer(const Layer* layer) {
242 return gfx::Canvas::CreateCanvas(layer->bounds().width(), 251 return gfx::Canvas::CreateCanvas(layer->bounds().width(),
243 layer->bounds().height(), 252 layer->bounds().height(),
244 false); 253 false);
245 } 254 }
246 255
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
254 void DrawTree(Layer* root) { 256 void DrawTree(Layer* root) {
255 compositor()->SetRootLayer(root); 257 compositor()->SetRootLayer(root);
256 compositor()->Draw(false); 258 compositor()->Draw(false);
257 } 259 }
258 260
259 // Invalidates the entire contents of the layer. 261 // Invalidates the entire contents of the layer.
260 void SchedulePaintForLayer(Layer* layer) { 262 void SchedulePaintForLayer(Layer* layer) {
261 layer->SchedulePaint( 263 layer->SchedulePaint(
262 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); 264 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
263 } 265 }
264 266
265 // Invokes DrawTree on the compositor. 267 // Invokes DrawTree on the compositor.
266 void Draw() { 268 void Draw() {
267 compositor_->root_layer()->DrawTree(); 269 compositor_->Draw(false);
268 } 270 }
269 271
270 private: 272 private:
271 scoped_refptr<TestCompositor> compositor_; 273 scoped_refptr<TestCompositor> compositor_;
272 274
273 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest); 275 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest);
274 }; 276 };
275 277
276 // L1 278 // L1
277 // +-- L2 279 // +-- L2
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 Layer::ConvertPointToLayer(l3.get(), l1.get(), &point1_in_l3_coords); 314 Layer::ConvertPointToLayer(l3.get(), l1.get(), &point1_in_l3_coords);
313 gfx::Point point1_in_l1_coords(25, 25); 315 gfx::Point point1_in_l1_coords(25, 25);
314 EXPECT_EQ(point1_in_l1_coords, point1_in_l3_coords); 316 EXPECT_EQ(point1_in_l1_coords, point1_in_l3_coords);
315 317
316 gfx::Point point2_in_l1_coords(5, 5); 318 gfx::Point point2_in_l1_coords(5, 5);
317 Layer::ConvertPointToLayer(l1.get(), l3.get(), &point2_in_l1_coords); 319 Layer::ConvertPointToLayer(l1.get(), l3.get(), &point2_in_l1_coords);
318 gfx::Point point2_in_l3_coords(-15, -15); 320 gfx::Point point2_in_l3_coords(-15, -15);
319 EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords); 321 EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords);
320 } 322 }
321 323
322 TEST_F(LayerWithDelegateTest, Delegate) { 324 TEST_F(LayerWithRealCompositorTest, Delegate) {
323 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorBLACK, 325 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorBLACK,
324 gfx::Rect(20, 20, 400, 400))); 326 gfx::Rect(20, 20, 400, 400)));
325 TestLayerDelegate delegate(l1.get()); 327 GetCompositor()->SetRootLayer(l1.get());
328 RunPendingMessages();
329
330 TestLayerDelegate delegate;
326 l1->set_delegate(&delegate); 331 l1->set_delegate(&delegate);
327 delegate.AddColor(SK_ColorWHITE); 332 delegate.AddColor(SK_ColorWHITE);
328 delegate.AddColor(SK_ColorYELLOW); 333 delegate.AddColor(SK_ColorYELLOW);
329 delegate.AddColor(SK_ColorGREEN); 334 delegate.AddColor(SK_ColorGREEN);
330 335
331 compositor()->SetRootLayer(l1.get());
332
333 l1->SchedulePaint(gfx::Rect(0, 0, 400, 400)); 336 l1->SchedulePaint(gfx::Rect(0, 0, 400, 400));
334 Draw(); 337 RunPendingMessages();
335 EXPECT_EQ(delegate.color_index(), 1); 338 EXPECT_EQ(delegate.color_index(), 1);
336 EXPECT_EQ(delegate.paint_size(), l1->bounds().size()); 339 EXPECT_EQ(delegate.paint_size(), l1->bounds().size());
337 340
338 l1->SchedulePaint(gfx::Rect(10, 10, 200, 200)); 341 l1->SchedulePaint(gfx::Rect(10, 10, 200, 200));
339 Draw(); 342 RunPendingMessages();
340 EXPECT_EQ(delegate.color_index(), 2); 343 EXPECT_EQ(delegate.color_index(), 2);
341 EXPECT_EQ(delegate.paint_size(), gfx::Size(200, 200)); 344 EXPECT_EQ(delegate.paint_size(), gfx::Size(200, 200));
342 345
343 l1->SchedulePaint(gfx::Rect(5, 5, 50, 50)); 346 l1->SchedulePaint(gfx::Rect(5, 5, 50, 50));
344 Draw(); 347 RunPendingMessages();
345 EXPECT_EQ(delegate.color_index(), 0); 348 EXPECT_EQ(delegate.color_index(), 0);
346 EXPECT_EQ(delegate.paint_size(), gfx::Size(50, 50)); 349 EXPECT_EQ(delegate.paint_size(), gfx::Size(50, 50));
347 } 350 }
348 351
349 TEST_F(LayerWithDelegateTest, DrawTree) { 352 TEST_F(LayerWithRealCompositorTest, DrawTree) {
350 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, 353 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
351 gfx::Rect(20, 20, 400, 400))); 354 gfx::Rect(20, 20, 400, 400)));
352 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, 355 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE,
353 gfx::Rect(10, 10, 350, 350))); 356 gfx::Rect(10, 10, 350, 350)));
354 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, 357 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW,
355 gfx::Rect(10, 10, 100, 100))); 358 gfx::Rect(10, 10, 100, 100)));
356 l1->Add(l2.get()); 359 l1->Add(l2.get());
357 l2->Add(l3.get()); 360 l2->Add(l3.get());
358 361
362 GetCompositor()->SetRootLayer(l1.get());
363 RunPendingMessages();
364
359 DrawTreeLayerDelegate d1; 365 DrawTreeLayerDelegate d1;
360 l1->set_delegate(&d1); 366 l1->set_delegate(&d1);
361 DrawTreeLayerDelegate d2; 367 DrawTreeLayerDelegate d2;
362 l2->set_delegate(&d2); 368 l2->set_delegate(&d2);
363 DrawTreeLayerDelegate d3; 369 DrawTreeLayerDelegate d3;
364 l3->set_delegate(&d3); 370 l3->set_delegate(&d3);
365 371
366 compositor()->SetRootLayer(l1.get());
367
368 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5)); 372 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5));
369 Draw(); 373 RunPendingMessages();
370 EXPECT_FALSE(d1.painted()); 374 EXPECT_FALSE(d1.painted());
371 EXPECT_TRUE(d2.painted()); 375 EXPECT_TRUE(d2.painted());
372 EXPECT_FALSE(d3.painted()); 376 EXPECT_FALSE(d3.painted());
373 } 377 }
374 378
375 // Tests no-texture Layers. 379 // Tests no-texture Layers.
376 // Create this hierarchy: 380 // Create this hierarchy:
377 // L1 - red 381 // L1 - red
378 // +-- L2 - NO TEXTURE 382 // +-- L2 - NO TEXTURE
379 // | +-- L3 - yellow 383 // | +-- L3 - yellow
380 // +-- L4 - magenta 384 // +-- L4 - magenta
381 // 385 //
382 TEST_F(LayerWithDelegateTest, HierarchyNoTexture) { 386 TEST_F(LayerWithRealCompositorTest, HierarchyNoTexture) {
383 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, 387 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
384 gfx::Rect(20, 20, 400, 400))); 388 gfx::Rect(20, 20, 400, 400)));
385 scoped_ptr<Layer> l2(CreateNoTextureLayer(gfx::Rect(10, 10, 350, 350))); 389 scoped_ptr<Layer> l2(CreateNoTextureLayer(gfx::Rect(10, 10, 350, 350)));
386 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, 390 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW,
387 gfx::Rect(5, 5, 25, 25))); 391 gfx::Rect(5, 5, 25, 25)));
388 scoped_ptr<Layer> l4(CreateColorLayer(SK_ColorMAGENTA, 392 scoped_ptr<Layer> l4(CreateColorLayer(SK_ColorMAGENTA,
389 gfx::Rect(300, 300, 100, 100))); 393 gfx::Rect(300, 300, 100, 100)));
390 394
391 l1->Add(l2.get()); 395 l1->Add(l2.get());
392 l1->Add(l4.get()); 396 l1->Add(l4.get());
393 l2->Add(l3.get()); 397 l2->Add(l3.get());
394 398
399 GetCompositor()->SetRootLayer(l1.get());
400 RunPendingMessages();
401
395 DrawTreeLayerDelegate d2; 402 DrawTreeLayerDelegate d2;
396 l2->set_delegate(&d2); 403 l2->set_delegate(&d2);
397 DrawTreeLayerDelegate d3; 404 DrawTreeLayerDelegate d3;
398 l3->set_delegate(&d3); 405 l3->set_delegate(&d3);
399 406
400 compositor()->SetRootLayer(l1.get());
401
402 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5)); 407 l2->SchedulePaint(gfx::Rect(5, 5, 5, 5));
403 l3->SchedulePaint(gfx::Rect(5, 5, 5, 5)); 408 l3->SchedulePaint(gfx::Rect(5, 5, 5, 5));
404 Draw(); 409 RunPendingMessages();
405 410
406 // |d2| should not have received a paint notification since it has no texture. 411 // |d2| should not have received a paint notification since it has no texture.
407 EXPECT_FALSE(d2.painted()); 412 EXPECT_FALSE(d2.painted());
408 // |d3| should have received a paint notification. 413 // |d3| should have received a paint notification.
409 EXPECT_TRUE(d3.painted()); 414 EXPECT_TRUE(d3.painted());
410 } 415 }
411 416
412 class LayerWithNullDelegateTest : public LayerWithDelegateTest { 417 class LayerWithNullDelegateTest : public LayerWithDelegateTest {
413 public: 418 public:
414 LayerWithNullDelegateTest() {} 419 LayerWithNullDelegateTest() {}
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 scoped_ptr<Layer> parent(CreateNoTextureLayer(gfx::Rect(0, 0, 400, 400))); 464 scoped_ptr<Layer> parent(CreateNoTextureLayer(gfx::Rect(0, 0, 400, 400)));
460 scoped_ptr<Layer> child(CreateNoTextureLayer(gfx::Rect(50, 50, 100, 100))); 465 scoped_ptr<Layer> child(CreateNoTextureLayer(gfx::Rect(50, 50, 100, 100)));
461 parent->Add(child.get()); 466 parent->Add(child.get());
462 467
463 compositor()->SetRootLayer(parent.get()); 468 compositor()->SetRootLayer(parent.get());
464 Draw(); 469 Draw();
465 EXPECT_TRUE(child->texture() == NULL); 470 EXPECT_TRUE(child->texture() == NULL);
466 EXPECT_TRUE(parent->texture() == NULL); 471 EXPECT_TRUE(parent->texture() == NULL);
467 } 472 }
468 473
474 // With the webkit compositor, we don't explicitly textures for layers, making
475 // tests that check that we do fail.
476 #if defined(USE_WEBKIT_COMPOSITOR)
477 #define WEBKIT_COMPOSITOR_FAILS(X) FAILS_ ## X
478 #else
479 #define WEBKIT_COMPOSITOR_FAILS(X) X
480 #endif
481
469 // Verifies that a layer does not have a texture when the hole is the size 482 // Verifies that a layer does not have a texture when the hole is the size
470 // of the parent layer. 483 // of the parent layer.
471 TEST_F(LayerWithNullDelegateTest, LayerNoTextureHoleSizeOfLayer) { 484 TEST_F(LayerWithNullDelegateTest,
485 WEBKIT_COMPOSITOR_FAILS(LayerNoTextureHoleSizeOfLayer)) {
472 scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400))); 486 scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
473 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100))); 487 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
474 parent->Add(child.get()); 488 parent->Add(child.get());
475 489
476 Draw(); 490 Draw();
477 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), parent->hole_rect()); 491 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), parent->hole_rect());
478 EXPECT_TRUE(parent->texture() != NULL); 492 EXPECT_TRUE(parent->texture() != NULL);
479 493
480 child->SetBounds(gfx::Rect(0, 0, 400, 400)); 494 child->SetBounds(gfx::Rect(0, 0, 400, 400));
481 Draw(); 495 Draw();
482 EXPECT_TRUE(parent->texture() == NULL); 496 EXPECT_TRUE(parent->texture() == NULL);
483 } 497 }
484 498
485 // Verifies that a layer which has opacity == 0 does not have a texture. 499 // Verifies that a layer which has opacity == 0 does not have a texture.
486 TEST_F(LayerWithNullDelegateTest, LayerNoTextureTransparent) { 500 TEST_F(LayerWithNullDelegateTest,
501 WEBKIT_COMPOSITOR_FAILS(LayerNoTextureTransparent)) {
487 scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400))); 502 scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
488 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100))); 503 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
489 parent->Add(child.get()); 504 parent->Add(child.get());
490 505
491 parent->SetOpacity(0.0f); 506 parent->SetOpacity(0.0f);
492 child->SetOpacity(0.0f); 507 child->SetOpacity(0.0f);
493 Draw(); 508 Draw();
494 EXPECT_TRUE(parent->texture() == NULL); 509 EXPECT_TRUE(parent->texture() == NULL);
495 EXPECT_TRUE(child->texture() == NULL); 510 EXPECT_TRUE(child->texture() == NULL);
496 511
497 parent->SetOpacity(1.0f); 512 parent->SetOpacity(1.0f);
498 Draw(); 513 Draw();
499 EXPECT_TRUE(parent->texture() != NULL); 514 EXPECT_TRUE(parent->texture() != NULL);
500 EXPECT_TRUE(child->texture() == NULL); 515 EXPECT_TRUE(child->texture() == NULL);
501 516
502 child->SetOpacity(1.0f); 517 child->SetOpacity(1.0f);
503 Draw(); 518 Draw();
504 EXPECT_TRUE(parent->texture() != NULL); 519 EXPECT_TRUE(parent->texture() != NULL);
505 EXPECT_TRUE(child->texture() != NULL); 520 EXPECT_TRUE(child->texture() != NULL);
506 } 521 }
507 522
508 // Verifies that no texture is created for a layer with empty bounds. 523 // Verifies that no texture is created for a layer with empty bounds.
509 TEST_F(LayerWithNullDelegateTest, LayerTextureNonEmptySchedulePaint) { 524 TEST_F(LayerWithNullDelegateTest,
525 WEBKIT_COMPOSITOR_FAILS(LayerTextureNonEmptySchedulePaint)) {
510 scoped_ptr<Layer> layer(CreateTextureRootLayer(gfx::Rect(0, 0, 0, 0))); 526 scoped_ptr<Layer> layer(CreateTextureRootLayer(gfx::Rect(0, 0, 0, 0)));
511 Draw(); 527 Draw();
512 EXPECT_TRUE(layer->texture() == NULL); 528 EXPECT_TRUE(layer->texture() == NULL);
513 529
514 layer->SetBounds(gfx::Rect(0, 0, 400, 400)); 530 layer->SetBounds(gfx::Rect(0, 0, 400, 400));
515 Draw(); 531 Draw();
516 EXPECT_TRUE(layer->texture() != NULL); 532 EXPECT_TRUE(layer->texture() != NULL);
517 } 533 }
518 534
519 // Verifies that when there are many potential holes, the largest one is picked. 535 // Verifies that when there are many potential holes, the largest one is picked.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 EXPECT_EQ(target_rect, parent->hole_rect()); 587 EXPECT_EQ(target_rect, parent->hole_rect());
572 } 588 }
573 } 589 }
574 590
575 // Create this hierarchy: 591 // Create this hierarchy:
576 // L1 (no texture) 592 // L1 (no texture)
577 // +- L11 (texture) 593 // +- L11 (texture)
578 // +- L12 (no texture) (added after L1 is already set as root-layer) 594 // +- L12 (no texture) (added after L1 is already set as root-layer)
579 // +- L121 (texture) 595 // +- L121 (texture)
580 // +- L122 (texture) 596 // +- L122 (texture)
581 TEST_F(LayerWithNullDelegateTest, NoCompositor) { 597 TEST_F(LayerWithNullDelegateTest, WEBKIT_COMPOSITOR_FAILS(NoCompositor)) {
582 scoped_ptr<Layer> l1(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE)); 598 scoped_ptr<Layer> l1(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE));
583 scoped_ptr<Layer> l11(CreateLayer(Layer::LAYER_HAS_TEXTURE)); 599 scoped_ptr<Layer> l11(CreateLayer(Layer::LAYER_HAS_TEXTURE));
584 scoped_ptr<Layer> l12(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE)); 600 scoped_ptr<Layer> l12(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE));
585 scoped_ptr<Layer> l121(CreateLayer(Layer::LAYER_HAS_TEXTURE)); 601 scoped_ptr<Layer> l121(CreateLayer(Layer::LAYER_HAS_TEXTURE));
586 scoped_ptr<Layer> l122(CreateLayer(Layer::LAYER_HAS_TEXTURE)); 602 scoped_ptr<Layer> l122(CreateLayer(Layer::LAYER_HAS_TEXTURE));
587 603
588 EXPECT_EQ(NULL, l1->texture()); 604 EXPECT_EQ(NULL, l1->texture());
589 EXPECT_EQ(NULL, l11->texture()); 605 EXPECT_EQ(NULL, l11->texture());
590 EXPECT_EQ(NULL, l12->texture()); 606 EXPECT_EQ(NULL, l12->texture());
591 EXPECT_EQ(NULL, l121->texture()); 607 EXPECT_EQ(NULL, l121->texture());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 EXPECT_FALSE(l2->IsDrawn()); 680 EXPECT_FALSE(l2->IsDrawn());
665 EXPECT_FALSE(l3->IsDrawn()); 681 EXPECT_FALSE(l3->IsDrawn());
666 682
667 l1->SetVisible(true); 683 l1->SetVisible(true);
668 EXPECT_TRUE(l1->IsDrawn()); 684 EXPECT_TRUE(l1->IsDrawn());
669 EXPECT_TRUE(l2->IsDrawn()); 685 EXPECT_TRUE(l2->IsDrawn());
670 EXPECT_FALSE(l3->IsDrawn()); 686 EXPECT_FALSE(l3->IsDrawn());
671 } 687 }
672 688
673 } // namespace ui 689 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698