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

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

Issue 8395046: Allows observers to be notified when layer animations complete. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address reviewer comments. Created 9 years, 1 month 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"
(...skipping 24 matching lines...) Expand all
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 }
44 44
45 virtual void OnLayerAnimationEnded(
46 const LayerAnimationSequence* animation) OVERRIDE {
47 }
48
49 private: 45 private:
50 SkColor color_; 46 SkColor color_;
51 }; 47 };
52 48
53 class LayerWithRealCompositorTest : public testing::Test { 49 class LayerWithRealCompositorTest : public testing::Test {
54 public: 50 public:
55 LayerWithRealCompositorTest() {} 51 LayerWithRealCompositorTest() {}
56 virtual ~LayerWithRealCompositorTest() {} 52 virtual ~LayerWithRealCompositorTest() {}
57 53
58 // Overridden from testing::Test: 54 // Overridden from testing::Test:
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 123
128 // Overridden from LayerDelegate: 124 // Overridden from LayerDelegate:
129 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { 125 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
130 SkBitmap contents = canvas->AsCanvasSkia()->ExtractBitmap(); 126 SkBitmap contents = canvas->AsCanvasSkia()->ExtractBitmap();
131 paint_size_ = gfx::Size(contents.width(), contents.height()); 127 paint_size_ = gfx::Size(contents.width(), contents.height());
132 canvas->FillRectInt(colors_.at(color_index_), 0, 0, 128 canvas->FillRectInt(colors_.at(color_index_), 0, 0,
133 contents.width(), 129 contents.width(),
134 contents.height()); 130 contents.height());
135 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size()); 131 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size());
136 } 132 }
137 virtual void OnLayerAnimationEnded(
138 const LayerAnimationSequence* animation) OVERRIDE {
139 }
140 133
141 private: 134 private:
142 std::vector<SkColor> colors_; 135 std::vector<SkColor> colors_;
143 int color_index_; 136 int color_index_;
144 gfx::Size paint_size_; 137 gfx::Size paint_size_;
145 138
146 DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate); 139 DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate);
147 }; 140 };
148 141
149 // LayerDelegate that verifies that a layer was asked to update its canvas. 142 // LayerDelegate that verifies that a layer was asked to update its canvas.
150 class DrawTreeLayerDelegate : public LayerDelegate { 143 class DrawTreeLayerDelegate : public LayerDelegate {
151 public: 144 public:
152 DrawTreeLayerDelegate() : painted_(false) {} 145 DrawTreeLayerDelegate() : painted_(false) {}
153 virtual ~DrawTreeLayerDelegate() {} 146 virtual ~DrawTreeLayerDelegate() {}
154 147
155 void Reset() { 148 void Reset() {
156 painted_ = false; 149 painted_ = false;
157 } 150 }
158 151
159 bool painted() const { return painted_; } 152 bool painted() const { return painted_; }
160 153
161 private: 154 private:
162 // Overridden from LayerDelegate: 155 // Overridden from LayerDelegate:
163 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { 156 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
164 painted_ = true; 157 painted_ = true;
165 } 158 }
166 virtual void OnLayerAnimationEnded(
167 const LayerAnimationSequence* animation) OVERRIDE {
168 }
169 159
170 bool painted_; 160 bool painted_;
171 161
172 DISALLOW_COPY_AND_ASSIGN(DrawTreeLayerDelegate); 162 DISALLOW_COPY_AND_ASSIGN(DrawTreeLayerDelegate);
173 }; 163 };
174 164
175 // The simplest possible layer delegate. Does nothing. 165 // The simplest possible layer delegate. Does nothing.
176 class NullLayerDelegate : public LayerDelegate { 166 class NullLayerDelegate : public LayerDelegate {
177 public: 167 public:
178 NullLayerDelegate() {} 168 NullLayerDelegate() {}
179 virtual ~NullLayerDelegate() {} 169 virtual ~NullLayerDelegate() {}
180 170
181 private: 171 private:
182 // Overridden from LayerDelegate: 172 // Overridden from LayerDelegate:
183 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { 173 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
184 } 174 }
185 virtual void OnLayerAnimationEnded(
186 const LayerAnimationSequence* animation) OVERRIDE {
187 }
188 175
189 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); 176 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate);
190 }; 177 };
191 178
192 } 179 }
193 180
194 #if defined(OS_WIN) 181 #if defined(OS_WIN)
195 // These are disabled on windows as they don't run correctly on the buildbot. 182 // These are disabled on windows as they don't run correctly on the buildbot.
196 // Reenable once we move to the real compositor. 183 // Reenable once we move to the real compositor.
197 #define MAYBE_Delegate DISABLED_Delegate 184 #define MAYBE_Delegate DISABLED_Delegate
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 l1->SetVisible(true); 888 l1->SetVisible(true);
902 EXPECT_TRUE(l1->IsDrawn()); 889 EXPECT_TRUE(l1->IsDrawn());
903 EXPECT_TRUE(l2->IsDrawn()); 890 EXPECT_TRUE(l2->IsDrawn());
904 EXPECT_FALSE(l3->IsDrawn()); 891 EXPECT_FALSE(l3->IsDrawn());
905 #if defined(USE_WEBKIT_COMPOSITOR) 892 #if defined(USE_WEBKIT_COMPOSITOR)
906 EXPECT_EQ(1.f, l1->web_layer().opacity()); 893 EXPECT_EQ(1.f, l1->web_layer().opacity());
907 #endif 894 #endif
908 } 895 }
909 896
910 } // namespace ui 897 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698