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

Unified Diff: ui/gfx/compositor/layer_unittest.cc

Issue 7845033: Rework View Layer Draw() to use the Layer::DrawTree() method and the LayerDelegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 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
« no previous file with comments | « ui/gfx/compositor/layer_delegate.h ('k') | ui/gfx/compositor/test_compositor_host_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/compositor/layer_unittest.cc
===================================================================
--- ui/gfx/compositor/layer_unittest.cc (revision 100773)
+++ ui/gfx/compositor/layer_unittest.cc (working copy)
@@ -7,6 +7,7 @@
#include "base/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
#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_host.h"
@@ -14,6 +15,21 @@
namespace {
+// Simple class that exits the current message loop when compositing finishes.
+class CompositingEndedObserver : public CompositorObserver {
+ public:
+ CompositingEndedObserver() {}
+ virtual ~CompositingEndedObserver() {}
+
+ // Overridden from CompositorObserver:
+ virtual void OnCompositingEnded() OVERRIDE {
+ MessageLoop::current()->Quit();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(CompositingEndedObserver);
+};
+
class TestLayerDelegate : public LayerDelegate {
public:
explicit TestLayerDelegate(Layer* owner) : owner_(owner), color_index_(0) {}
@@ -27,15 +43,13 @@
int color_index() const { return color_index_; }
// Overridden from LayerDelegate:
- virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
+ virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
SkBitmap contents = canvas->AsCanvasSkia()->ExtractBitmap();
paint_size_ = gfx::Size(contents.width(), contents.height());
canvas->FillRectInt(colors_.at(color_index_), 0, 0,
contents.width(),
contents.height());
color_index_ = ++color_index_ % colors_.size();
-
- MessageLoop::current()->Quit();
}
private:
@@ -94,19 +108,10 @@
void DrawTree(Layer* root) {
window_->GetCompositor()->NotifyStart();
- DrawLayerChildren(root);
+ root->DrawTree();
window_->GetCompositor()->NotifyEnd();
}
- void DrawLayerChildren(Layer* layer) {
- layer->Draw();
- std::vector<Layer*>::const_iterator it = layer->children().begin();
- while (it != layer->children().end()) {
- DrawLayerChildren(*it);
- ++it;
- }
- }
-
void RunPendingMessages() {
MessageLoopForUI::current()->Run(NULL);
}
@@ -118,7 +123,7 @@
// Overridden from TestCompositorHostDelegate:
virtual void Draw() {
if (root_layer_)
- DrawLayerChildren(root_layer_);
+ root_layer_->DrawTree();
}
MessageLoopForUI message_loop_;
@@ -128,6 +133,28 @@
DISALLOW_COPY_AND_ASSIGN(LayerTest);
};
+class LayerQuitOnCompositedTest : public LayerTest {
+ public:
+ LayerQuitOnCompositedTest() {}
+ virtual ~LayerQuitOnCompositedTest() {}
+
+ // Overridden from LayerTest:
+ virtual void SetUp() OVERRIDE {
+ LayerTest::SetUp();
+ GetCompositor()->AddObserver(&compositor_observer_);
+ }
+
+ virtual void TearDown() OVERRIDE {
+ LayerTest::TearDown();
+ GetCompositor()->RemoveObserver(&compositor_observer_);
+ }
+
+ private:
+ CompositingEndedObserver compositor_observer_;
+
+ DISALLOW_COPY_AND_ASSIGN(LayerQuitOnCompositedTest);
+};
+
}
TEST_F(LayerTest, Draw) {
@@ -205,7 +232,7 @@
EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords);
}
-TEST_F(LayerTest, Delegate) {
+TEST_F(LayerQuitOnCompositedTest, Delegate) {
scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorBLACK,
gfx::Rect(20, 20, 400, 400)));
TestLayerDelegate delegate(l1.get());
@@ -232,5 +259,57 @@
EXPECT_EQ(delegate.paint_size(), gfx::Size(50, 50));
}
+namespace {
+
+class DrawTreeLayerDelegate : public LayerDelegate {
+ public:
+ DrawTreeLayerDelegate() : painted_(false) {}
+ virtual ~DrawTreeLayerDelegate() {}
+
+ void Reset() {
+ painted_ = false;
+ }
+
+ bool painted() const { return painted_; }
+
+ // Overridden from LayerDelegate:
+ virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
+ painted_ = true;
+ }
+
+ private:
+ bool painted_;
+
+ DISALLOW_COPY_AND_ASSIGN(DrawTreeLayerDelegate);
+};
+
+} // namespace
+
+TEST_F(LayerQuitOnCompositedTest, DrawTree) {
+ scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
+ gfx::Rect(20, 20, 400, 400)));
+ scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE,
+ gfx::Rect(10, 10, 350, 350)));
+ scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW,
+ gfx::Rect(10, 10, 100, 100)));
+ l1->Add(l2.get());
+ l2->Add(l3.get());
+
+ DrawTreeLayerDelegate d1;
+ l1->set_delegate(&d1);
+ DrawTreeLayerDelegate d2;
+ l2->set_delegate(&d2);
+ DrawTreeLayerDelegate d3;
+ l3->set_delegate(&d3);
+
+ set_root_layer(l1.get());
+
+ l2->SchedulePaint(gfx::Rect(5, 5, 5, 5));
+ RunPendingMessages();
+ EXPECT_FALSE(d1.painted());
+ EXPECT_TRUE(d2.painted());
+ EXPECT_FALSE(d3.painted());
+}
+
} // namespace ui
« no previous file with comments | « ui/gfx/compositor/layer_delegate.h ('k') | ui/gfx/compositor/test_compositor_host_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698