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

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

Issue 8362006: Reland r107720 - Enable the new layer animation framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge 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
« no previous file with comments | « ui/gfx/compositor/layer_delegate.h ('k') | ui/gfx/compositor/test_layer_animation_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "ui/gfx/compositor/layer.h" 11 #include "ui/gfx/compositor/layer.h"
12 #include "ui/gfx/compositor/layer_animation_sequence.h"
12 #include "ui/gfx/compositor/test_compositor.h" 13 #include "ui/gfx/compositor/test_compositor.h"
13 #include "ui/gfx/compositor/test_compositor_host.h" 14 #include "ui/gfx/compositor/test_compositor_host.h"
14 15
15 namespace ui { 16 namespace ui {
16 17
17 namespace { 18 namespace {
18 19
19 // There are three test classes in here that configure the Compositor and 20 // There are three test classes in here that configure the Compositor and
20 // Layer's slightly differently: 21 // Layer's slightly differently:
21 // - LayerWithNullDelegateTest uses TestCompositor and NullLayerDelegate as the 22 // - LayerWithNullDelegateTest uses TestCompositor and NullLayerDelegate as the
(...skipping 12 matching lines...) Expand all
34 set_delegate(this); 35 set_delegate(this);
35 } 36 }
36 37
37 virtual ~ColoredLayer() { } 38 virtual ~ColoredLayer() { }
38 39
39 // Overridden from LayerDelegate: 40 // Overridden from LayerDelegate:
40 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { 41 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
41 canvas->GetSkCanvas()->drawColor(color_); 42 canvas->GetSkCanvas()->drawColor(color_);
42 } 43 }
43 44
44 virtual void OnLayerAnimationEnded(const ui::Animation* animation) OVERRIDE { 45 virtual void OnLayerAnimationEnded(
46 const LayerAnimationSequence* animation) OVERRIDE {
45 } 47 }
46 48
47 private: 49 private:
48 SkColor color_; 50 SkColor color_;
49 }; 51 };
50 52
51 class LayerWithRealCompositorTest : public testing::Test { 53 class LayerWithRealCompositorTest : public testing::Test {
52 public: 54 public:
53 LayerWithRealCompositorTest() {} 55 LayerWithRealCompositorTest() {}
54 virtual ~LayerWithRealCompositorTest() {} 56 virtual ~LayerWithRealCompositorTest() {}
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 127
126 // Overridden from LayerDelegate: 128 // Overridden from LayerDelegate:
127 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { 129 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
128 SkBitmap contents = canvas->AsCanvasSkia()->ExtractBitmap(); 130 SkBitmap contents = canvas->AsCanvasSkia()->ExtractBitmap();
129 paint_size_ = gfx::Size(contents.width(), contents.height()); 131 paint_size_ = gfx::Size(contents.width(), contents.height());
130 canvas->FillRectInt(colors_.at(color_index_), 0, 0, 132 canvas->FillRectInt(colors_.at(color_index_), 0, 0,
131 contents.width(), 133 contents.width(),
132 contents.height()); 134 contents.height());
133 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size()); 135 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size());
134 } 136 }
135 virtual void OnLayerAnimationEnded(const ui::Animation* animation) OVERRIDE { 137 virtual void OnLayerAnimationEnded(
138 const LayerAnimationSequence* animation) OVERRIDE {
136 } 139 }
137 140
138 private: 141 private:
139 std::vector<SkColor> colors_; 142 std::vector<SkColor> colors_;
140 int color_index_; 143 int color_index_;
141 gfx::Size paint_size_; 144 gfx::Size paint_size_;
142 145
143 DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate); 146 DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate);
144 }; 147 };
145 148
146 // LayerDelegate that verifies that a layer was asked to update its canvas. 149 // LayerDelegate that verifies that a layer was asked to update its canvas.
147 class DrawTreeLayerDelegate : public LayerDelegate { 150 class DrawTreeLayerDelegate : public LayerDelegate {
148 public: 151 public:
149 DrawTreeLayerDelegate() : painted_(false) {} 152 DrawTreeLayerDelegate() : painted_(false) {}
150 virtual ~DrawTreeLayerDelegate() {} 153 virtual ~DrawTreeLayerDelegate() {}
151 154
152 void Reset() { 155 void Reset() {
153 painted_ = false; 156 painted_ = false;
154 } 157 }
155 158
156 bool painted() const { return painted_; } 159 bool painted() const { return painted_; }
157 160
158 private: 161 private:
159 // Overridden from LayerDelegate: 162 // Overridden from LayerDelegate:
160 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { 163 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
161 painted_ = true; 164 painted_ = true;
162 } 165 }
163 virtual void OnLayerAnimationEnded(const ui::Animation* animation) OVERRIDE { 166 virtual void OnLayerAnimationEnded(
167 const LayerAnimationSequence* animation) OVERRIDE {
164 } 168 }
165 169
166 bool painted_; 170 bool painted_;
167 171
168 DISALLOW_COPY_AND_ASSIGN(DrawTreeLayerDelegate); 172 DISALLOW_COPY_AND_ASSIGN(DrawTreeLayerDelegate);
169 }; 173 };
170 174
171 // The simplest possible layer delegate. Does nothing. 175 // The simplest possible layer delegate. Does nothing.
172 class NullLayerDelegate : public LayerDelegate { 176 class NullLayerDelegate : public LayerDelegate {
173 public: 177 public:
174 NullLayerDelegate() {} 178 NullLayerDelegate() {}
175 virtual ~NullLayerDelegate() {} 179 virtual ~NullLayerDelegate() {}
176 180
177 private: 181 private:
178 // Overridden from LayerDelegate: 182 // Overridden from LayerDelegate:
179 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { 183 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
180 } 184 }
181 virtual void OnLayerAnimationEnded(const ui::Animation* animation) OVERRIDE { 185 virtual void OnLayerAnimationEnded(
186 const LayerAnimationSequence* animation) OVERRIDE {
182 } 187 }
183 188
184 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); 189 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate);
185 }; 190 };
186 191
187 } 192 }
188 193
189 #if defined(OS_WIN) 194 #if defined(OS_WIN)
190 // These are disabled on windows as they don't run correctly on the buildbot. 195 // These are disabled on windows as they don't run correctly on the buildbot.
191 // Reenable once we move to the real compositor. 196 // Reenable once we move to the real compositor.
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 l1->SetVisible(true); 901 l1->SetVisible(true);
897 EXPECT_TRUE(l1->IsDrawn()); 902 EXPECT_TRUE(l1->IsDrawn());
898 EXPECT_TRUE(l2->IsDrawn()); 903 EXPECT_TRUE(l2->IsDrawn());
899 EXPECT_FALSE(l3->IsDrawn()); 904 EXPECT_FALSE(l3->IsDrawn());
900 #if defined(USE_WEBKIT_COMPOSITOR) 905 #if defined(USE_WEBKIT_COMPOSITOR)
901 EXPECT_EQ(1.f, l1->web_layer().opacity()); 906 EXPECT_EQ(1.f, l1->web_layer().opacity());
902 #endif 907 #endif
903 } 908 }
904 909
905 } // namespace ui 910 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/layer_delegate.h ('k') | ui/gfx/compositor/test_layer_animation_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698