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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/gfx/compositor/layer_unittest.cc
diff --git a/ui/gfx/compositor/layer_unittest.cc b/ui/gfx/compositor/layer_unittest.cc
index bb05c0ba6673bc426d08f8854fa6a790f90d2411..96c0ef58a9702749aefefa07cc452d63ca61cc74 100644
--- a/ui/gfx/compositor/layer_unittest.cc
+++ b/ui/gfx/compositor/layer_unittest.cc
@@ -25,6 +25,26 @@ namespace {
// - LayerWithRealCompositorTest when a real compositor is required for testing.
// - Slow because they bring up a window and run the real compositor. This
// is typically not what you want.
+
+class ColoredLayer : public Layer, public LayerDelegate {
+ public:
+ ColoredLayer(Compositor* compositor, SkColor color)
+ : Layer(compositor, Layer::LAYER_HAS_TEXTURE),
+ color_(color) {
+ set_delegate(this);
+ }
+
+ virtual ~ColoredLayer() { }
+
+ // Overridden from LayerDelegate:
+ virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
+ canvas->GetSkCanvas()->drawColor(color_);
+ }
+
+ private:
+ SkColor color_;
+};
+
class LayerWithRealCompositorTest : public testing::Test {
public:
LayerWithRealCompositorTest() {}
@@ -49,9 +69,8 @@ class LayerWithRealCompositorTest : public testing::Test {
}
Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
- Layer* layer = CreateLayer(Layer::LAYER_HAS_TEXTURE);
+ Layer* layer = new ColoredLayer(GetCompositor(), color);
layer->SetBounds(bounds);
- PaintColorToLayer(layer, color);
return layer;
}
@@ -67,13 +86,6 @@ class LayerWithRealCompositorTest : public testing::Test {
false);
}
- void PaintColorToLayer(Layer* layer, SkColor color) {
- scoped_ptr<gfx::Canvas> canvas(CreateCanvasForLayer(layer));
- canvas->FillRectInt(color, 0, 0, layer->bounds().width(),
- layer->bounds().height());
- layer->SetCanvas(*canvas->GetSkCanvas(), layer->bounds().origin());
- }
-
void DrawTree(Layer* root) {
GetCompositor()->SetRootLayer(root);
GetCompositor()->Draw(false);
@@ -90,7 +102,6 @@ class LayerWithRealCompositorTest : public testing::Test {
}
private:
- MessageLoopForUI message_loop_;
scoped_ptr<TestCompositorHost> window_;
DISALLOW_COPY_AND_ASSIGN(LayerWithRealCompositorTest);
@@ -99,7 +110,7 @@ class LayerWithRealCompositorTest : public testing::Test {
// LayerDelegate that paints colors to the layer.
class TestLayerDelegate : public LayerDelegate {
public:
- explicit TestLayerDelegate(Layer* owner) : owner_(owner), color_index_(0) {}
+ explicit TestLayerDelegate() : color_index_(0) {}
virtual ~TestLayerDelegate() {}
void AddColor(SkColor color) {
@@ -120,7 +131,6 @@ class TestLayerDelegate : public LayerDelegate {
}
private:
- Layer* owner_;
std::vector<SkColor> colors_;
int color_index_;
gfx::Size paint_size_;
@@ -226,9 +236,8 @@ class LayerWithDelegateTest : public testing::Test {
}
Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
- Layer* layer = CreateLayer(Layer::LAYER_HAS_TEXTURE);
+ Layer* layer = new ColoredLayer(compositor(), color);
layer->SetBounds(bounds);
- PaintColorToLayer(layer, color);
return layer;
}
@@ -244,13 +253,6 @@ class LayerWithDelegateTest : public testing::Test {
false);
}
- void PaintColorToLayer(Layer* layer, SkColor color) {
- scoped_ptr<gfx::Canvas> canvas(CreateCanvasForLayer(layer));
- canvas->FillRectInt(color, 0, 0, layer->bounds().width(),
- layer->bounds().height());
- layer->SetCanvas(*canvas->GetSkCanvas(), layer->bounds().origin());
- }
-
void DrawTree(Layer* root) {
compositor()->SetRootLayer(root);
compositor()->Draw(false);
@@ -264,7 +266,7 @@ class LayerWithDelegateTest : public testing::Test {
// Invokes DrawTree on the compositor.
void Draw() {
- compositor_->root_layer()->DrawTree();
+ compositor_->Draw(false);
}
private:
@@ -319,34 +321,35 @@ TEST_F(LayerWithDelegateTest, ConvertPointToLayer_Medium) {
EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords);
}
-TEST_F(LayerWithDelegateTest, Delegate) {
+TEST_F(LayerWithRealCompositorTest, Delegate) {
scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorBLACK,
gfx::Rect(20, 20, 400, 400)));
- TestLayerDelegate delegate(l1.get());
+ GetCompositor()->SetRootLayer(l1.get());
+ RunPendingMessages();
+
+ TestLayerDelegate delegate;
l1->set_delegate(&delegate);
delegate.AddColor(SK_ColorWHITE);
delegate.AddColor(SK_ColorYELLOW);
delegate.AddColor(SK_ColorGREEN);
- compositor()->SetRootLayer(l1.get());
-
l1->SchedulePaint(gfx::Rect(0, 0, 400, 400));
- Draw();
+ RunPendingMessages();
EXPECT_EQ(delegate.color_index(), 1);
EXPECT_EQ(delegate.paint_size(), l1->bounds().size());
l1->SchedulePaint(gfx::Rect(10, 10, 200, 200));
- Draw();
+ RunPendingMessages();
EXPECT_EQ(delegate.color_index(), 2);
EXPECT_EQ(delegate.paint_size(), gfx::Size(200, 200));
l1->SchedulePaint(gfx::Rect(5, 5, 50, 50));
- Draw();
+ RunPendingMessages();
EXPECT_EQ(delegate.color_index(), 0);
EXPECT_EQ(delegate.paint_size(), gfx::Size(50, 50));
}
-TEST_F(LayerWithDelegateTest, DrawTree) {
+TEST_F(LayerWithRealCompositorTest, DrawTree) {
scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
gfx::Rect(20, 20, 400, 400)));
scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE,
@@ -356,6 +359,9 @@ TEST_F(LayerWithDelegateTest, DrawTree) {
l1->Add(l2.get());
l2->Add(l3.get());
+ GetCompositor()->SetRootLayer(l1.get());
+ RunPendingMessages();
+
DrawTreeLayerDelegate d1;
l1->set_delegate(&d1);
DrawTreeLayerDelegate d2;
@@ -363,10 +369,8 @@ TEST_F(LayerWithDelegateTest, DrawTree) {
DrawTreeLayerDelegate d3;
l3->set_delegate(&d3);
- compositor()->SetRootLayer(l1.get());
-
l2->SchedulePaint(gfx::Rect(5, 5, 5, 5));
- Draw();
+ RunPendingMessages();
EXPECT_FALSE(d1.painted());
EXPECT_TRUE(d2.painted());
EXPECT_FALSE(d3.painted());
@@ -379,7 +383,7 @@ TEST_F(LayerWithDelegateTest, DrawTree) {
// | +-- L3 - yellow
// +-- L4 - magenta
//
-TEST_F(LayerWithDelegateTest, HierarchyNoTexture) {
+TEST_F(LayerWithRealCompositorTest, HierarchyNoTexture) {
scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
gfx::Rect(20, 20, 400, 400)));
scoped_ptr<Layer> l2(CreateNoTextureLayer(gfx::Rect(10, 10, 350, 350)));
@@ -392,16 +396,17 @@ TEST_F(LayerWithDelegateTest, HierarchyNoTexture) {
l1->Add(l4.get());
l2->Add(l3.get());
+ GetCompositor()->SetRootLayer(l1.get());
+ RunPendingMessages();
+
DrawTreeLayerDelegate d2;
l2->set_delegate(&d2);
DrawTreeLayerDelegate d3;
l3->set_delegate(&d3);
- compositor()->SetRootLayer(l1.get());
-
l2->SchedulePaint(gfx::Rect(5, 5, 5, 5));
l3->SchedulePaint(gfx::Rect(5, 5, 5, 5));
- Draw();
+ RunPendingMessages();
// |d2| should not have received a paint notification since it has no texture.
EXPECT_FALSE(d2.painted());
@@ -466,9 +471,18 @@ TEST_F(LayerWithNullDelegateTest, LayerNoTextureSetFillsBoundsOpaquely) {
EXPECT_TRUE(parent->texture() == NULL);
}
+// With the webkit compositor, we don't explicitly textures for layers, making
+// tests that check that we do fail.
+#if defined(USE_WEBKIT_COMPOSITOR)
+#define WEBKIT_COMPOSITOR_FAILS(X) FAILS_ ## X
+#else
+#define WEBKIT_COMPOSITOR_FAILS(X) X
+#endif
+
// Verifies that a layer does not have a texture when the hole is the size
// of the parent layer.
-TEST_F(LayerWithNullDelegateTest, LayerNoTextureHoleSizeOfLayer) {
+TEST_F(LayerWithNullDelegateTest,
+ WEBKIT_COMPOSITOR_FAILS(LayerNoTextureHoleSizeOfLayer)) {
scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
parent->Add(child.get());
@@ -483,7 +497,8 @@ TEST_F(LayerWithNullDelegateTest, LayerNoTextureHoleSizeOfLayer) {
}
// Verifies that a layer which has opacity == 0 does not have a texture.
-TEST_F(LayerWithNullDelegateTest, LayerNoTextureTransparent) {
+TEST_F(LayerWithNullDelegateTest,
+ WEBKIT_COMPOSITOR_FAILS(LayerNoTextureTransparent)) {
scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
parent->Add(child.get());
@@ -506,7 +521,8 @@ TEST_F(LayerWithNullDelegateTest, LayerNoTextureTransparent) {
}
// Verifies that no texture is created for a layer with empty bounds.
-TEST_F(LayerWithNullDelegateTest, LayerTextureNonEmptySchedulePaint) {
+TEST_F(LayerWithNullDelegateTest,
+ WEBKIT_COMPOSITOR_FAILS(LayerTextureNonEmptySchedulePaint)) {
scoped_ptr<Layer> layer(CreateTextureRootLayer(gfx::Rect(0, 0, 0, 0)));
Draw();
EXPECT_TRUE(layer->texture() == NULL);
@@ -578,7 +594,7 @@ TEST_F(LayerWithNullDelegateTest, HoleWithNinetyDegreeTransforms) {
// +- L12 (no texture) (added after L1 is already set as root-layer)
// +- L121 (texture)
// +- L122 (texture)
-TEST_F(LayerWithNullDelegateTest, NoCompositor) {
+TEST_F(LayerWithNullDelegateTest, WEBKIT_COMPOSITOR_FAILS(NoCompositor)) {
scoped_ptr<Layer> l1(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE));
scoped_ptr<Layer> l11(CreateLayer(Layer::LAYER_HAS_TEXTURE));
scoped_ptr<Layer> l12(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE));

Powered by Google App Engine
This is Rietveld 408576698