Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 // - LayerWithNullDelegateTest uses TestCompositor and NullLayerDelegate as the | 22 // - LayerWithNullDelegateTest uses TestCompositor and NullLayerDelegate as the |
| 23 // LayerDelegate. This is typically the base class you want to use. | 23 // LayerDelegate. This is typically the base class you want to use. |
| 24 // - LayerWithDelegateTest uses TestCompositor and does not set a LayerDelegate | 24 // - LayerWithDelegateTest uses TestCompositor and does not set a LayerDelegate |
| 25 // on the delegates. | 25 // on the delegates. |
| 26 // - LayerWithRealCompositorTest when a real compositor is required for testing. | 26 // - LayerWithRealCompositorTest when a real compositor is required for testing. |
| 27 // - Slow because they bring up a window and run the real compositor. This | 27 // - Slow because they bring up a window and run the real compositor. This |
| 28 // is typically not what you want. | 28 // is typically not what you want. |
| 29 | 29 |
| 30 class ColoredLayer : public Layer, public LayerDelegate { | 30 class ColoredLayer : public Layer, public LayerDelegate { |
| 31 public: | 31 public: |
| 32 ColoredLayer(Compositor* compositor, SkColor color) | 32 ColoredLayer(SkColor color) |
|
sky
2011/11/15 04:57:04
explicit
piman
2011/11/15 22:06:33
Done.
| |
| 33 : Layer(compositor, Layer::LAYER_HAS_TEXTURE), | 33 : Layer(Layer::LAYER_HAS_TEXTURE), |
| 34 color_(color) { | 34 color_(color) { |
| 35 set_delegate(this); | 35 set_delegate(this); |
| 36 } | 36 } |
| 37 | 37 |
| 38 virtual ~ColoredLayer() { } | 38 virtual ~ColoredLayer() { } |
| 39 | 39 |
| 40 // Overridden from LayerDelegate: | 40 // Overridden from LayerDelegate: |
| 41 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { | 41 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { |
| 42 canvas->GetSkCanvas()->drawColor(color_); | 42 canvas->GetSkCanvas()->drawColor(color_); |
| 43 } | 43 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 59 } | 59 } |
| 60 | 60 |
| 61 virtual void TearDown() OVERRIDE { | 61 virtual void TearDown() OVERRIDE { |
| 62 } | 62 } |
| 63 | 63 |
| 64 Compositor* GetCompositor() { | 64 Compositor* GetCompositor() { |
| 65 return window_->GetCompositor(); | 65 return window_->GetCompositor(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 Layer* CreateLayer(Layer::LayerType type) { | 68 Layer* CreateLayer(Layer::LayerType type) { |
| 69 return new Layer(GetCompositor(), type); | 69 return new Layer(type); |
| 70 } | 70 } |
| 71 | 71 |
| 72 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { | 72 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { |
| 73 Layer* layer = new ColoredLayer(GetCompositor(), color); | 73 Layer* layer = new ColoredLayer(color); |
| 74 layer->SetBounds(bounds); | 74 layer->SetBounds(bounds); |
| 75 return layer; | 75 return layer; |
| 76 } | 76 } |
| 77 | 77 |
| 78 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { | 78 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { |
| 79 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); | 79 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); |
| 80 layer->SetBounds(bounds); | 80 layer->SetBounds(bounds); |
| 81 return layer; | 81 return layer; |
| 82 } | 82 } |
| 83 | 83 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 virtual void SetUp() OVERRIDE { | 231 virtual void SetUp() OVERRIDE { |
| 232 compositor_ = new TestCompositor(this); | 232 compositor_ = new TestCompositor(this); |
| 233 } | 233 } |
| 234 | 234 |
| 235 virtual void TearDown() OVERRIDE { | 235 virtual void TearDown() OVERRIDE { |
| 236 } | 236 } |
| 237 | 237 |
| 238 Compositor* compositor() { return compositor_.get(); } | 238 Compositor* compositor() { return compositor_.get(); } |
| 239 | 239 |
| 240 virtual Layer* CreateLayer(Layer::LayerType type) { | 240 virtual Layer* CreateLayer(Layer::LayerType type) { |
| 241 return new Layer(compositor(), type); | 241 return new Layer(type); |
| 242 } | 242 } |
| 243 | 243 |
| 244 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { | 244 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { |
| 245 Layer* layer = new ColoredLayer(compositor(), color); | 245 Layer* layer = new ColoredLayer(color); |
| 246 layer->SetBounds(bounds); | 246 layer->SetBounds(bounds); |
| 247 return layer; | 247 return layer; |
| 248 } | 248 } |
| 249 | 249 |
| 250 virtual Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { | 250 virtual Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { |
| 251 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); | 251 Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); |
| 252 layer->SetBounds(bounds); | 252 layer->SetBounds(bounds); |
| 253 return layer; | 253 return layer; |
| 254 } | 254 } |
| 255 | 255 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 // Overridden from testing::Test: | 435 // Overridden from testing::Test: |
| 436 virtual void SetUp() OVERRIDE { | 436 virtual void SetUp() OVERRIDE { |
| 437 LayerWithDelegateTest::SetUp(); | 437 LayerWithDelegateTest::SetUp(); |
| 438 default_layer_delegate_.reset(new NullLayerDelegate()); | 438 default_layer_delegate_.reset(new NullLayerDelegate()); |
| 439 } | 439 } |
| 440 | 440 |
| 441 virtual void TearDown() OVERRIDE { | 441 virtual void TearDown() OVERRIDE { |
| 442 } | 442 } |
| 443 | 443 |
| 444 Layer* CreateLayer(Layer::LayerType type) OVERRIDE { | 444 Layer* CreateLayer(Layer::LayerType type) OVERRIDE { |
| 445 Layer* layer = new Layer(compositor(), type); | 445 Layer* layer = new Layer(type); |
| 446 layer->set_delegate(default_layer_delegate_.get()); | 446 layer->set_delegate(default_layer_delegate_.get()); |
| 447 return layer; | 447 return layer; |
| 448 } | 448 } |
| 449 | 449 |
| 450 Layer* CreateTextureRootLayer(const gfx::Rect& bounds) { | 450 Layer* CreateTextureRootLayer(const gfx::Rect& bounds) { |
| 451 Layer* layer = CreateTextureLayer(bounds); | 451 Layer* layer = CreateTextureLayer(bounds); |
| 452 compositor()->SetRootLayer(layer); | 452 compositor()->SetRootLayer(layer); |
| 453 return layer; | 453 return layer; |
| 454 } | 454 } |
| 455 | 455 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 686 | 686 |
| 687 // Toggling l2's visibility should drop all sub-layer textures. | 687 // Toggling l2's visibility should drop all sub-layer textures. |
| 688 l12->SetVisible(false); | 688 l12->SetVisible(false); |
| 689 EXPECT_EQ(NULL, l12->texture()); | 689 EXPECT_EQ(NULL, l12->texture()); |
| 690 EXPECT_EQ(NULL, l121->texture()); | 690 EXPECT_EQ(NULL, l121->texture()); |
| 691 EXPECT_EQ(NULL, l122->texture()); | 691 EXPECT_EQ(NULL, l122->texture()); |
| 692 } | 692 } |
| 693 | 693 |
| 694 // Various visibile/drawn assertions. | 694 // Various visibile/drawn assertions. |
| 695 TEST_F(LayerWithNullDelegateTest, Visibility) { | 695 TEST_F(LayerWithNullDelegateTest, Visibility) { |
| 696 scoped_ptr<Layer> l1(new Layer(NULL, Layer::LAYER_HAS_TEXTURE)); | 696 scoped_ptr<Layer> l1(new Layer(Layer::LAYER_HAS_TEXTURE)); |
| 697 scoped_ptr<Layer> l2(new Layer(NULL, Layer::LAYER_HAS_TEXTURE)); | 697 scoped_ptr<Layer> l2(new Layer(Layer::LAYER_HAS_TEXTURE)); |
| 698 scoped_ptr<Layer> l3(new Layer(NULL, Layer::LAYER_HAS_TEXTURE)); | 698 scoped_ptr<Layer> l3(new Layer(Layer::LAYER_HAS_TEXTURE)); |
| 699 l1->Add(l2.get()); | 699 l1->Add(l2.get()); |
| 700 l2->Add(l3.get()); | 700 l2->Add(l3.get()); |
| 701 | 701 |
| 702 NullLayerDelegate delegate; | 702 NullLayerDelegate delegate; |
| 703 l1->set_delegate(&delegate); | 703 l1->set_delegate(&delegate); |
| 704 l2->set_delegate(&delegate); | 704 l2->set_delegate(&delegate); |
| 705 l3->set_delegate(&delegate); | 705 l3->set_delegate(&delegate); |
| 706 | 706 |
| 707 // Layers should initially be drawn. | 707 // Layers should initially be drawn. |
| 708 EXPECT_TRUE(l1->IsDrawn()); | 708 EXPECT_TRUE(l1->IsDrawn()); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 SkAutoLockPixels lock(bitmap); | 798 SkAutoLockPixels lock(bitmap); |
| 799 bool is_all_red = true; | 799 bool is_all_red = true; |
| 800 for (int x = 0; is_all_red && x < 500; x++) | 800 for (int x = 0; is_all_red && x < 500; x++) |
| 801 for (int y = 0; is_all_red && y < 500; y++) | 801 for (int y = 0; is_all_red && y < 500; y++) |
| 802 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED); | 802 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED); |
| 803 | 803 |
| 804 EXPECT_TRUE(is_all_red); | 804 EXPECT_TRUE(is_all_red); |
| 805 } | 805 } |
| 806 | 806 |
| 807 } // namespace ui | 807 } // namespace ui |
| OLD | NEW |