summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-28 23:45:38 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-28 23:45:38 +0000
commit4916d62ca7ae3365d8234682dc28b815ad4c5031 (patch)
treecee8d9c4f6bba9d3bdcfc4bf7d2c7378a3ce58c1
parent5bce52305fac51d1bafffbd9dee9bb1e261c01ef (diff)
downloadchromium_src-4916d62ca7ae3365d8234682dc28b815ad4c5031.zip
chromium_src-4916d62ca7ae3365d8234682dc28b815ad4c5031.tar.gz
chromium_src-4916d62ca7ae3365d8234682dc28b815ad4c5031.tar.bz2
Refactors TestCompositor out of views_unittests into a place it can be
used by both the layer tests and the views test. Also fixes a bug that was causing test to fail and fixes up defines. I've disabled a portion of the compositor unit tests on linux as they don't compile. BUG=none TEST=none R=ben@chromium.org Review URL: http://codereview.chromium.org/8072010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103208 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--build/common.gypi5
-rw-r--r--ui/gfx/compositor/compositor.gyp12
-rw-r--r--ui/gfx/compositor/compositor.h2
-rw-r--r--ui/gfx/compositor/layer.cc3
-rw-r--r--ui/gfx/compositor/layer_unittest.cc111
-rw-r--r--ui/gfx/compositor/test_compositor.cc46
-rw-r--r--ui/gfx/compositor/test_compositor.h41
-rw-r--r--ui/gfx/compositor/test_texture.cc35
-rw-r--r--ui/gfx/compositor/test_texture.h50
-rw-r--r--views/view.cc2
-rw-r--r--views/view_unittest.cc110
-rw-r--r--views/views.gyp4
12 files changed, 310 insertions, 111 deletions
diff --git a/build/common.gypi b/build/common.gypi
index 1d77143..90b8451 100644
--- a/build/common.gypi
+++ b/build/common.gypi
@@ -74,8 +74,9 @@
'use_only_pure_views%': 0,
}],
- # Use the views compositor when using the Aura window manager.
- ['use_aura==1', {
+ # Use the views compositor when using the Aura window manager or
+ # touch.
+ ['use_aura==1 or touchui==1', {
'views_compositor%': 1,
}],
],
diff --git a/ui/gfx/compositor/compositor.gyp b/ui/gfx/compositor/compositor.gyp
index 18ae769..a0317d7 100644
--- a/ui/gfx/compositor/compositor.gyp
+++ b/ui/gfx/compositor/compositor.gyp
@@ -96,14 +96,26 @@
'sources': [
'layer_unittest.cc',
'run_all_unittests.cc',
+ 'test_compositor.cc',
+ 'test_compositor.h',
'test_compositor_host.h',
'test_compositor_host_linux.cc',
'test_compositor_host_win.cc',
'test_suite.cc',
'test_suite.h',
+ 'test_texture.cc',
+ 'test_texture.h',
'<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.rc',
'<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/ui_resources.rc',
],
+ 'conditions': [
+ ['OS=="linux"', {
+ 'sources!': [
+ 'test_compositor_host.h',
+ 'test_compositor_host_linux.cc',
+ ],
+ }],
+ ],
},
],
}
diff --git a/ui/gfx/compositor/compositor.h b/ui/gfx/compositor/compositor.h
index f1932c0..75cd2a9 100644
--- a/ui/gfx/compositor/compositor.h
+++ b/ui/gfx/compositor/compositor.h
@@ -113,7 +113,7 @@ class COMPOSITOR_EXPORT Compositor : public base::RefCounted<Compositor> {
// Sets the root of the layer tree drawn by this Compositor.
// The Compositor does not own the root layer.
- const Layer* root_layer() const { return root_layer_; }
+ Layer* root_layer() { return root_layer_; }
void SetRootLayer(Layer* root_layer);
// Draws the scene created by the layer tree and any visual effects. If
diff --git a/ui/gfx/compositor/layer.cc b/ui/gfx/compositor/layer.cc
index 79d587e..ff5a5ff 100644
--- a/ui/gfx/compositor/layer.cc
+++ b/ui/gfx/compositor/layer.cc
@@ -279,7 +279,8 @@ void Layer::UpdateLayerCanvas() {
if (!delegate_ || layer_updated_externally_)
return;
gfx::Rect local_bounds = gfx::Rect(gfx::Point(), bounds_.size());
- gfx::Rect draw_rect = invalid_rect_.Intersect(local_bounds);
+ gfx::Rect draw_rect = texture_.get() ? invalid_rect_.Intersect(local_bounds) :
+ local_bounds;
if (draw_rect.IsEmpty()) {
invalid_rect_ = gfx::Rect();
return;
diff --git a/ui/gfx/compositor/layer_unittest.cc b/ui/gfx/compositor/layer_unittest.cc
index beac36d..a0693ed 100644
--- a/ui/gfx/compositor/layer_unittest.cc
+++ b/ui/gfx/compositor/layer_unittest.cc
@@ -9,16 +9,22 @@
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/compositor/compositor_observer.h"
#include "ui/gfx/compositor/layer.h"
+#include "ui/gfx/compositor/test_compositor.h"
+
+// TestCompositorHost needs to be ported to linux for these to work.
+#if !defined(OS_LINUX)
#include "ui/gfx/compositor/test_compositor_host.h"
+#endif
namespace ui {
namespace {
-class LayerTest : public testing::Test {
+#if !defined(OS_LINUX)
+class LayerWithRealCompositorTest : public testing::Test {
public:
- LayerTest() {}
- virtual ~LayerTest() {}
+ LayerWithRealCompositorTest() {}
+ virtual ~LayerWithRealCompositorTest() {}
// Overridden from testing::Test:
virtual void SetUp() OVERRIDE {
@@ -83,8 +89,9 @@ class LayerTest : public testing::Test {
MessageLoopForUI message_loop_;
scoped_ptr<TestCompositorHost> window_;
- DISALLOW_COPY_AND_ASSIGN(LayerTest);
+ DISALLOW_COPY_AND_ASSIGN(LayerWithRealCompositorTest);
};
+#endif
// LayerDelegate that paints colors to the layer.
class TestLayerDelegate : public LayerDelegate {
@@ -157,7 +164,9 @@ class NullLayerDelegate : public LayerDelegate {
}
-TEST_F(LayerTest, Draw) {
+#if !defined(OS_LINUX)
+
+TEST_F(LayerWithRealCompositorTest, Draw) {
scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED,
gfx::Rect(20, 20, 50, 50)));
DrawTree(layer.get());
@@ -169,7 +178,7 @@ TEST_F(LayerTest, Draw) {
// | +-- L3 - yellow
// +-- L4 - magenta
//
-TEST_F(LayerTest, Hierarchy) {
+TEST_F(LayerWithRealCompositorTest, Hierarchy) {
scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
gfx::Rect(20, 20, 400, 400)));
scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE,
@@ -186,6 +195,76 @@ TEST_F(LayerTest, Hierarchy) {
DrawTree(l1.get());
}
+#endif
+
+// LayerTest uses TestCompositor as the Compositor implementation.
+class LayerTest : public testing::Test {
+ public:
+ LayerTest() {}
+ virtual ~LayerTest() {}
+
+ // Overridden from testing::Test:
+ virtual void SetUp() OVERRIDE {
+ compositor_ = new TestCompositor();
+ }
+
+ virtual void TearDown() OVERRIDE {
+ }
+
+ Compositor* compositor() { return compositor_.get(); }
+
+ Layer* CreateLayer(Layer::LayerType type) {
+ return new Layer(compositor(), type);
+ }
+
+ Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
+ Layer* layer = CreateLayer(Layer::LAYER_HAS_TEXTURE);
+ layer->SetBounds(bounds);
+ PaintColorToLayer(layer, color);
+ return layer;
+ }
+
+ Layer* CreateNoTextureLayer(const gfx::Rect& bounds) {
+ Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE);
+ layer->SetBounds(bounds);
+ return layer;
+ }
+
+ gfx::Canvas* CreateCanvasForLayer(const Layer* layer) {
+ return gfx::Canvas::CreateCanvas(layer->bounds().width(),
+ layer->bounds().height(),
+ 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->AsCanvasSkia(), layer->bounds().origin());
+ }
+
+ void DrawTree(Layer* root) {
+ compositor()->SetRootLayer(root);
+ compositor()->Draw(false);
+ }
+
+ // Invalidates the entire contents of the layer.
+ void SchedulePaintForLayer(Layer* layer) {
+ layer->SchedulePaint(
+ gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
+ }
+
+ // Invokes DrawTree on the compositor.
+ void Draw() {
+ compositor_->root_layer()->DrawTree();
+ }
+
+ private:
+ scoped_refptr<TestCompositor> compositor_;
+
+ DISALLOW_COPY_AND_ASSIGN(LayerTest);
+};
+
// L1
// +-- L2
TEST_F(LayerTest, ConvertPointToLayer_Simple) {
@@ -241,20 +320,20 @@ TEST_F(LayerTest, Delegate) {
delegate.AddColor(SK_ColorYELLOW);
delegate.AddColor(SK_ColorGREEN);
- GetCompositor()->SetRootLayer(l1.get());
+ compositor()->SetRootLayer(l1.get());
l1->SchedulePaint(gfx::Rect(0, 0, 400, 400));
- RunPendingMessages();
+ Draw();
EXPECT_EQ(delegate.color_index(), 1);
EXPECT_EQ(delegate.paint_size(), l1->bounds().size());
l1->SchedulePaint(gfx::Rect(10, 10, 200, 200));
- RunPendingMessages();
+ Draw();
EXPECT_EQ(delegate.color_index(), 2);
EXPECT_EQ(delegate.paint_size(), gfx::Size(200, 200));
l1->SchedulePaint(gfx::Rect(5, 5, 50, 50));
- RunPendingMessages();
+ Draw();
EXPECT_EQ(delegate.color_index(), 0);
EXPECT_EQ(delegate.paint_size(), gfx::Size(50, 50));
}
@@ -276,10 +355,10 @@ TEST_F(LayerTest, DrawTree) {
DrawTreeLayerDelegate d3;
l3->set_delegate(&d3);
- GetCompositor()->SetRootLayer(l1.get());
+ compositor()->SetRootLayer(l1.get());
l2->SchedulePaint(gfx::Rect(5, 5, 5, 5));
- RunPendingMessages();
+ Draw();
EXPECT_FALSE(d1.painted());
EXPECT_TRUE(d2.painted());
EXPECT_FALSE(d3.painted());
@@ -310,11 +389,11 @@ TEST_F(LayerTest, HierarchyNoTexture) {
DrawTreeLayerDelegate d3;
l3->set_delegate(&d3);
- GetCompositor()->SetRootLayer(l1.get());
+ compositor()->SetRootLayer(l1.get());
l2->SchedulePaint(gfx::Rect(5, 5, 5, 5));
l3->SchedulePaint(gfx::Rect(5, 5, 5, 5));
- RunPendingMessages();
+ Draw();
// |d2| should not have received a paint notification since it has no texture.
EXPECT_FALSE(d2.painted());
@@ -372,7 +451,7 @@ TEST_F(LayerTest, NoCompositor) {
EXPECT_EQ(NULL, l11->texture());
- GetCompositor()->SetRootLayer(l1.get());
+ compositor()->SetRootLayer(l1.get());
EXPECT_EQ(NULL, l1->texture());
@@ -394,7 +473,7 @@ TEST_F(LayerTest, NoCompositor) {
// By asking l121 and l122 to paint, we cause them to generate a texture.
SchedulePaintForLayer(l121.get());
SchedulePaintForLayer(l122.get());
- RunPendingMessages();
+ Draw();
EXPECT_EQ(NULL, l12->texture());
EXPECT_TRUE(NULL != l121->texture());
diff --git a/ui/gfx/compositor/test_compositor.cc b/ui/gfx/compositor/test_compositor.cc
new file mode 100644
index 0000000..2c32bef
--- /dev/null
+++ b/ui/gfx/compositor/test_compositor.cc
@@ -0,0 +1,46 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/compositor/test_compositor.h"
+
+#include "ui/gfx/compositor/test_texture.h"
+
+namespace ui {
+
+class TestCompositorDelegate : public ui::CompositorDelegate {
+ public:
+ TestCompositorDelegate() {}
+ virtual ~TestCompositorDelegate() {}
+
+ virtual void ScheduleCompositorPaint() OVERRIDE {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestCompositorDelegate);
+};
+
+TestCompositor::TestCompositor()
+ : Compositor(new TestCompositorDelegate, gfx::Size(100, 100)) {
+ owned_delegate_.reset(static_cast<TestCompositorDelegate*>(delegate()));
+}
+
+TestCompositor::~TestCompositor() {
+}
+
+ui::Texture* TestCompositor::CreateTexture() {
+ return new TestTexture();
+}
+
+void TestCompositor::OnNotifyStart(bool clear) {
+}
+
+void TestCompositor::OnNotifyEnd() {
+}
+
+void TestCompositor::Blur(const gfx::Rect& bounds) {
+}
+
+void TestCompositor::OnWidgetSizeChanged() {
+}
+
+} // namespace ui
diff --git a/ui/gfx/compositor/test_compositor.h b/ui/gfx/compositor/test_compositor.h
new file mode 100644
index 0000000..b7d2cfa
--- /dev/null
+++ b/ui/gfx/compositor/test_compositor.h
@@ -0,0 +1,41 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_GFX_COMPOSITOR_TEST_COMPOSITOR_H_
+#define UI_GFX_COMPOSITOR_TEST_COMPOSITOR_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/compiler_specific.h"
+#include "ui/gfx/compositor/compositor.h"
+
+namespace ui {
+
+class TestCompositorDelegate;
+
+// Trivial Compositor implementation that creates Textures of type TestTexture.
+class TestCompositor : public ui::Compositor {
+ public:
+ TestCompositor();
+ virtual ~TestCompositor();
+
+ // ui::Compositor:
+ virtual ui::Texture* CreateTexture() OVERRIDE;
+ virtual void OnNotifyStart(bool clear) OVERRIDE;
+ virtual void OnNotifyEnd() OVERRIDE;
+ virtual void Blur(const gfx::Rect& bounds) OVERRIDE;
+
+ protected:
+ virtual void OnWidgetSizeChanged() OVERRIDE;
+
+ private:
+ scoped_ptr<TestCompositorDelegate> owned_delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestCompositor);
+};
+
+} // namespace ui
+
+#endif // UI_GFX_COMPOSITOR_TEST_COMPOSITOR_H_
diff --git a/ui/gfx/compositor/test_texture.cc b/ui/gfx/compositor/test_texture.cc
new file mode 100644
index 0000000..ce1b9f4
--- /dev/null
+++ b/ui/gfx/compositor/test_texture.cc
@@ -0,0 +1,35 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/compositor/test_texture.h"
+
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/core/SkDevice.h"
+
+namespace ui {
+
+// static
+int TestTexture::live_count_ = 0;
+
+TestTexture::TestTexture() {
+ live_count_++;
+}
+
+TestTexture::~TestTexture() {
+ live_count_--;
+}
+
+void TestTexture::SetCanvas(const SkCanvas& canvas,
+ const gfx::Point& origin,
+ const gfx::Size& overall_size) {
+ const SkBitmap& bitmap = canvas.getDevice()->accessBitmap(false);
+ bounds_of_last_paint_.SetRect(
+ origin.x(), origin.y(), bitmap.width(), bitmap.height());
+}
+
+void TestTexture::Draw(const ui::TextureDrawParams& params,
+ const gfx::Rect& clip_bounds) {
+}
+
+} // namespace ui
diff --git a/ui/gfx/compositor/test_texture.h b/ui/gfx/compositor/test_texture.h
new file mode 100644
index 0000000..95a6f2a
--- /dev/null
+++ b/ui/gfx/compositor/test_texture.h
@@ -0,0 +1,50 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_GFX_COMPOSITOR_TEST_TEXTURE_H_
+#define UI_GFX_COMPOSITOR_TEST_TEXTURE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/gfx/compositor/compositor.h"
+#include "ui/gfx/rect.h"
+
+namespace ui {
+
+// Texture implementation that TextCompositor creates. Doesn't actually draw
+// anything.
+class TestTexture : public ui::Texture {
+ public:
+ TestTexture();
+ virtual ~TestTexture();
+
+ // Number of textures that have been created.
+ static void reset_live_count() { live_count_ = 0; }
+ static int live_count() { return live_count_; }
+
+ // Bounds of the last bitmap passed to SetCanvas.
+ const gfx::Rect& bounds_of_last_paint() const {
+ return bounds_of_last_paint_;
+ }
+
+ // ui::Texture
+ virtual void SetCanvas(const SkCanvas& canvas,
+ const gfx::Point& origin,
+ const gfx::Size& overall_size) OVERRIDE;
+ virtual void Draw(const ui::TextureDrawParams& params,
+ const gfx::Rect& clip_bounds) OVERRIDE;
+
+ private:
+ // Number of live instances.
+ static int live_count_;
+
+ gfx::Rect bounds_of_last_paint_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestTexture);
+};
+
+} // namespace ui
+
+#endif // UI_GFX_COMPOSITOR_TEST_TEXTURE_H_
diff --git a/views/view.cc b/views/view.cc
index 3aa4fbf..2239187 100644
--- a/views/view.cc
+++ b/views/view.cc
@@ -46,7 +46,7 @@ namespace {
// Whether to use accelerated compositing when necessary (e.g. when a view has a
// transformation).
-#if !defined(OS_CHROMEOS) || defined(TOUCH_UI) || defined(USE_AURA)
+#if defined(VIEWS_COMPOSITOR)
bool use_acceleration_when_possible = true;
#else
bool use_acceleration_when_possible = false;
diff --git a/views/view_unittest.cc b/views/view_unittest.cc
index 6811da8..bd3f2ef 100644
--- a/views/view_unittest.cc
+++ b/views/view_unittest.cc
@@ -14,6 +14,8 @@
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/compositor/layer.h"
+#include "ui/gfx/compositor/test_compositor.h"
+#include "ui/gfx/compositor/test_texture.h"
#include "ui/gfx/path.h"
#include "ui/gfx/transform.h"
#include "views/background.h"
@@ -2300,88 +2302,8 @@ TEST_F(ViewTest, GetViewByID) {
namespace {
-class TestTexture : public ui::Texture {
- public:
- TestTexture() {
- live_count_++;
- }
-
- ~TestTexture() {
- live_count_--;
- }
-
- static void reset_live_count() { live_count_ = 0; }
- static int live_count() { return live_count_; }
-
- // Bounds of the last bitmap passed to SetCanvas.
- const gfx::Rect& bounds_of_last_paint() const {
- return bounds_of_last_paint_;
- }
-
- // ui::Texture
- virtual void SetCanvas(const SkCanvas& canvas,
- const gfx::Point& origin,
- const gfx::Size& overall_size) OVERRIDE;
-
- virtual void Draw(const ui::TextureDrawParams& params,
- const gfx::Rect& clip_bounds) OVERRIDE {}
-
- private:
- // Number of live instances.
- static int live_count_;
-
- gfx::Rect bounds_of_last_paint_;
-
- DISALLOW_COPY_AND_ASSIGN(TestTexture);
-};
-
-// static
-int TestTexture::live_count_ = 0;
-
-void TestTexture::SetCanvas(const SkCanvas& canvas,
- const gfx::Point& origin,
- const gfx::Size& overall_size) {
- const SkBitmap& bitmap = canvas.getDevice()->accessBitmap(false);
- bounds_of_last_paint_.SetRect(
- origin.x(), origin.y(), bitmap.width(), bitmap.height());
-}
-
-class TestCompositorDelegate : public ui::CompositorDelegate {
- public:
- TestCompositorDelegate() {}
- ~TestCompositorDelegate() {}
- virtual void ScheduleCompositorPaint() OVERRIDE {}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(TestCompositorDelegate);
-};
-
-class TestCompositor : public ui::Compositor {
- public:
- TestCompositor() : Compositor(new TestCompositorDelegate,
- gfx::Size(100, 100)) {
- owned_delegate_.reset(static_cast<TestCompositorDelegate*>(delegate()));
- }
-
- // ui::Compositor:
- virtual ui::Texture* CreateTexture() OVERRIDE {
- return new TestTexture();
- }
- virtual void OnNotifyStart(bool clear) OVERRIDE {}
- virtual void OnNotifyEnd() OVERRIDE {}
- virtual void Blur(const gfx::Rect& bounds) OVERRIDE {}
-
- protected:
- virtual void OnWidgetSizeChanged() OVERRIDE {}
-
- private:
- scoped_ptr<TestCompositorDelegate> owned_delegate_;
-
- DISALLOW_COPY_AND_ASSIGN(TestCompositor);
-};
-
static ui::Compositor* TestCreateCompositor() {
- return new TestCompositor();
+ return new ui::TestCompositor();
}
// Test implementation of LayerPropertySetter;
@@ -2451,7 +2373,7 @@ class ViewLayerTest : public ViewsTestBase {
old_use_acceleration_ = View::get_use_acceleration_when_possible();
View::set_use_acceleration_when_possible(true);
- TestTexture::reset_live_count();
+ ui::TestTexture::reset_live_count();
#if defined(USE_AURA)
aura::Desktop::set_compositor_factory_for_testing(&TestCreateCompositor);
@@ -2462,6 +2384,7 @@ class ViewLayerTest : public ViewsTestBase {
Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
params.bounds = gfx::Rect(50, 50, 200, 200);
widget_->Init(params);
+ widget_->GetRootView()->SetBounds(0, 0, 200, 200);
}
virtual void TearDown() OVERRIDE {
@@ -2505,14 +2428,16 @@ TEST_F(ViewLayerTest, PaintAll) {
view->SetBounds(0, 0, 200, 200);
widget()->OnNativeWidgetPaintAccelerated(gfx::Rect(0, 0, 1, 1));
ASSERT_TRUE(layer != NULL);
- const TestTexture* texture =
- static_cast<const TestTexture*>(layer->texture());
+ const ui::TestTexture* texture =
+ static_cast<const ui::TestTexture*>(layer->texture());
ASSERT_TRUE(texture != NULL);
EXPECT_EQ(view->GetLocalBounds(), texture->bounds_of_last_paint());
}
#endif
TEST_F(ViewLayerTest, LayerToggling) {
+ // Because we lazily create textures the calls to DrawTree are necessary to
+ // ensure we trigger creation of textures.
#if defined(USE_AURA)
ui::Layer* root_layer = NULL;
gfx::Point origin;
@@ -2526,13 +2451,15 @@ TEST_F(ViewLayerTest, LayerToggling) {
// Create v1, give it a bounds and verify everything is set up correctly.
View* v1 = new View;
v1->SetPaintToLayer(true);
- EXPECT_EQ(1, TestTexture::live_count());
+ root_layer->DrawTree();
+ EXPECT_EQ(1, ui::TestTexture::live_count());
EXPECT_TRUE(v1->layer() == NULL);
+ v1->SetBounds(20, 30, 140, 150);
content_view->AddChildView(v1);
- EXPECT_EQ(2, TestTexture::live_count());
+ root_layer->DrawTree();
+ EXPECT_EQ(2, ui::TestTexture::live_count());
ASSERT_TRUE(v1->layer() != NULL);
EXPECT_EQ(root_layer, v1->layer()->parent());
- v1->SetBounds(20, 30, 140, 150);
EXPECT_EQ(gfx::Rect(20, 30, 140, 150), v1->layer()->bounds());
// Create v2 as a child of v1 and do basic assertion testing.
@@ -2541,7 +2468,8 @@ TEST_F(ViewLayerTest, LayerToggling) {
EXPECT_TRUE(v2->layer() == NULL);
v2->SetBounds(10, 20, 30, 40);
v2->SetPaintToLayer(true);
- EXPECT_EQ(3, TestTexture::live_count());
+ root_layer->DrawTree();
+ EXPECT_EQ(3, ui::TestTexture::live_count());
ASSERT_TRUE(v2->layer() != NULL);
EXPECT_EQ(v1->layer(), v2->layer()->parent());
EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds());
@@ -2549,7 +2477,8 @@ TEST_F(ViewLayerTest, LayerToggling) {
// Turn off v1s layer. v2 should still have a layer but its parent should have
// changed.
v1->SetPaintToLayer(false);
- EXPECT_EQ(2, TestTexture::live_count());
+ root_layer->DrawTree();
+ EXPECT_EQ(2, ui::TestTexture::live_count());
EXPECT_TRUE(v1->layer() == NULL);
EXPECT_TRUE(v2->layer() != NULL);
EXPECT_EQ(root_layer, v2->layer()->parent());
@@ -2563,7 +2492,8 @@ TEST_F(ViewLayerTest, LayerToggling) {
ui::Transform transform;
transform.SetScale(2.0f, 2.0f);
v1->SetTransform(transform);
- EXPECT_EQ(3, TestTexture::live_count());
+ root_layer->DrawTree();
+ EXPECT_EQ(3, ui::TestTexture::live_count());
EXPECT_TRUE(v1->layer() != NULL);
EXPECT_TRUE(v2->layer() != NULL);
EXPECT_EQ(root_layer, v1->layer()->parent());
diff --git a/views/views.gyp b/views/views.gyp
index 3c0ade1..e4d054e 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -601,6 +601,10 @@
'widget/native_widget_unittest.cc',
'widget/native_widget_win_unittest.cc',
'widget/widget_unittest.cc',
+ '../ui/gfx/compositor/test_compositor.cc',
+ '../ui/gfx/compositor/test_compositor.h',
+ '../ui/gfx/compositor/test_texture.cc',
+ '../ui/gfx/compositor/test_texture.h',
'<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.rc',
'<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/ui_resources.rc',