OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 6 #include "base/bind.h" |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "cc/output/copy_output_result.h" | 21 #include "cc/output/copy_output_result.h" |
22 #include "cc/output/delegated_frame_data.h" | 22 #include "cc/output/delegated_frame_data.h" |
23 #include "cc/test/pixel_test_utils.h" | 23 #include "cc/test/pixel_test_utils.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "ui/compositor/compositor_observer.h" | 25 #include "ui/compositor/compositor_observer.h" |
26 #include "ui/compositor/dip_util.h" | 26 #include "ui/compositor/dip_util.h" |
27 #include "ui/compositor/layer.h" | 27 #include "ui/compositor/layer.h" |
28 #include "ui/compositor/layer_animation_sequence.h" | 28 #include "ui/compositor/layer_animation_sequence.h" |
29 #include "ui/compositor/layer_animator.h" | 29 #include "ui/compositor/layer_animator.h" |
30 #include "ui/compositor/paint_context.h" | 30 #include "ui/compositor/paint_context.h" |
| 31 #include "ui/compositor/paint_recorder.h" |
31 #include "ui/compositor/test/context_factories_for_test.h" | 32 #include "ui/compositor/test/context_factories_for_test.h" |
32 #include "ui/compositor/test/draw_waiter_for_test.h" | 33 #include "ui/compositor/test/draw_waiter_for_test.h" |
33 #include "ui/compositor/test/test_compositor_host.h" | 34 #include "ui/compositor/test/test_compositor_host.h" |
34 #include "ui/compositor/test/test_layers.h" | 35 #include "ui/compositor/test/test_layers.h" |
35 #include "ui/gfx/canvas.h" | 36 #include "ui/gfx/canvas.h" |
36 #include "ui/gfx/codec/png_codec.h" | 37 #include "ui/gfx/codec/png_codec.h" |
37 #include "ui/gfx/gfx_paths.h" | 38 #include "ui/gfx/gfx_paths.h" |
38 #include "ui/gfx/skia_util.h" | 39 #include "ui/gfx/skia_util.h" |
39 | 40 |
40 using cc::MatchesPNGFile; | 41 using cc::MatchesPNGFile; |
(...skipping 16 matching lines...) Expand all Loading... |
57 explicit ColoredLayer(SkColor color) | 58 explicit ColoredLayer(SkColor color) |
58 : Layer(LAYER_TEXTURED), | 59 : Layer(LAYER_TEXTURED), |
59 color_(color) { | 60 color_(color) { |
60 set_delegate(this); | 61 set_delegate(this); |
61 } | 62 } |
62 | 63 |
63 ~ColoredLayer() override {} | 64 ~ColoredLayer() override {} |
64 | 65 |
65 // Overridden from LayerDelegate: | 66 // Overridden from LayerDelegate: |
66 void OnPaintLayer(const ui::PaintContext& context) override { | 67 void OnPaintLayer(const ui::PaintContext& context) override { |
67 context.canvas()->DrawColor(color_); | 68 ui::PaintRecorder recorder(context); |
| 69 recorder.canvas()->DrawColor(color_); |
68 } | 70 } |
69 | 71 |
70 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | 72 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
71 | 73 |
72 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} | 74 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} |
73 | 75 |
74 base::Closure PrepareForLayerBoundsChange() override { | 76 base::Closure PrepareForLayerBoundsChange() override { |
75 return base::Closure(); | 77 return base::Closure(); |
76 } | 78 } |
77 | 79 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 224 } |
223 | 225 |
224 int color_index() const { return color_index_; } | 226 int color_index() const { return color_index_; } |
225 | 227 |
226 float device_scale_factor() const { | 228 float device_scale_factor() const { |
227 return device_scale_factor_; | 229 return device_scale_factor_; |
228 } | 230 } |
229 | 231 |
230 // Overridden from LayerDelegate: | 232 // Overridden from LayerDelegate: |
231 void OnPaintLayer(const ui::PaintContext& context) override { | 233 void OnPaintLayer(const ui::PaintContext& context) override { |
232 context.canvas()->DrawColor(colors_[color_index_]); | 234 ui::PaintRecorder recorder(context); |
| 235 recorder.canvas()->DrawColor(colors_[color_index_]); |
233 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size()); | 236 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size()); |
234 } | 237 } |
235 | 238 |
236 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | 239 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
237 | 240 |
238 void OnDeviceScaleFactorChanged(float device_scale_factor) override { | 241 void OnDeviceScaleFactorChanged(float device_scale_factor) override { |
239 device_scale_factor_ = device_scale_factor; | 242 device_scale_factor_ = device_scale_factor; |
240 } | 243 } |
241 | 244 |
242 base::Closure PrepareForLayerBoundsChange() override { | 245 base::Closure PrepareForLayerBoundsChange() override { |
(...skipping 22 matching lines...) Expand all Loading... |
265 void Reset() { | 268 void Reset() { |
266 painted_ = false; | 269 painted_ = false; |
267 } | 270 } |
268 | 271 |
269 bool painted() const { return painted_; } | 272 bool painted() const { return painted_; } |
270 | 273 |
271 private: | 274 private: |
272 // Overridden from LayerDelegate: | 275 // Overridden from LayerDelegate: |
273 void OnPaintLayer(const ui::PaintContext& context) override { | 276 void OnPaintLayer(const ui::PaintContext& context) override { |
274 painted_ = true; | 277 painted_ = true; |
275 context.canvas()->DrawColor(SK_ColorWHITE); | 278 ui::PaintRecorder recorder(context); |
| 279 recorder.canvas()->DrawColor(SK_ColorWHITE); |
276 } | 280 } |
277 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | 281 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
278 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} | 282 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} |
279 base::Closure PrepareForLayerBoundsChange() override { | 283 base::Closure PrepareForLayerBoundsChange() override { |
280 return base::Closure(); | 284 return base::Closure(); |
281 } | 285 } |
282 | 286 |
283 bool painted_; | 287 bool painted_; |
284 | 288 |
285 DISALLOW_COPY_AND_ASSIGN(DrawTreeLayerDelegate); | 289 DISALLOW_COPY_AND_ASSIGN(DrawTreeLayerDelegate); |
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 void SetSchedulePaintRect(const gfx::Rect& rect) { | 1203 void SetSchedulePaintRect(const gfx::Rect& rect) { |
1200 schedule_paint_rect_ = rect; | 1204 schedule_paint_rect_ = rect; |
1201 } | 1205 } |
1202 | 1206 |
1203 int GetPaintCountAndClear() { | 1207 int GetPaintCountAndClear() { |
1204 int value = paint_count_; | 1208 int value = paint_count_; |
1205 paint_count_ = 0; | 1209 paint_count_ = 0; |
1206 return value; | 1210 return value; |
1207 } | 1211 } |
1208 | 1212 |
1209 const gfx::RectF& last_clip_rect() const { return last_clip_rect_; } | 1213 const gfx::Rect& last_clip_rect() const { return last_clip_rect_; } |
1210 | 1214 |
1211 private: | 1215 private: |
1212 // Overridden from LayerDelegate: | 1216 // Overridden from LayerDelegate: |
1213 void OnPaintLayer(const ui::PaintContext& context) override { | 1217 void OnPaintLayer(const ui::PaintContext& context) override { |
1214 gfx::Canvas* canvas = context.canvas(); | |
1215 paint_count_++; | 1218 paint_count_++; |
1216 if (!schedule_paint_rect_.IsEmpty()) { | 1219 if (!schedule_paint_rect_.IsEmpty()) { |
1217 layer_->SchedulePaint(schedule_paint_rect_); | 1220 layer_->SchedulePaint(schedule_paint_rect_); |
1218 schedule_paint_rect_ = gfx::Rect(); | 1221 schedule_paint_rect_ = gfx::Rect(); |
1219 } | 1222 } |
1220 SkRect sk_clip_rect; | 1223 last_clip_rect_ = context.InvalidationForTesting(); |
1221 if (canvas->sk_canvas()->getClipBounds(&sk_clip_rect)) | |
1222 last_clip_rect_ = gfx::SkRectToRectF(sk_clip_rect); | |
1223 } | 1224 } |
1224 | 1225 |
1225 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | 1226 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
1226 | 1227 |
1227 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} | 1228 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} |
1228 | 1229 |
1229 base::Closure PrepareForLayerBoundsChange() override { | 1230 base::Closure PrepareForLayerBoundsChange() override { |
1230 return base::Closure(); | 1231 return base::Closure(); |
1231 } | 1232 } |
1232 | 1233 |
1233 int paint_count_; | 1234 int paint_count_; |
1234 Layer* layer_; | 1235 Layer* layer_; |
1235 gfx::Rect schedule_paint_rect_; | 1236 gfx::Rect schedule_paint_rect_; |
1236 gfx::RectF last_clip_rect_; | 1237 gfx::Rect last_clip_rect_; |
1237 | 1238 |
1238 DISALLOW_COPY_AND_ASSIGN(SchedulePaintLayerDelegate); | 1239 DISALLOW_COPY_AND_ASSIGN(SchedulePaintLayerDelegate); |
1239 }; | 1240 }; |
1240 | 1241 |
1241 } // namespace | 1242 } // namespace |
1242 | 1243 |
1243 // Verifies that if SchedulePaint is invoked during painting the layer is still | 1244 // Verifies that if SchedulePaint is invoked during painting the layer is still |
1244 // marked dirty. | 1245 // marked dirty. |
1245 TEST_F(LayerWithDelegateTest, SchedulePaintFromOnPaintLayer) { | 1246 TEST_F(LayerWithDelegateTest, SchedulePaintFromOnPaintLayer) { |
1246 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorRED, | 1247 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorRED, |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1729 MakeFrameData(gfx::Size(10, 10)))); | 1730 MakeFrameData(gfx::Size(10, 10)))); |
1730 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); | 1731 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); |
1731 | 1732 |
1732 EXPECT_FALSE(delegate.delegated_frame_damage_called()); | 1733 EXPECT_FALSE(delegate.delegated_frame_damage_called()); |
1733 layer->OnDelegatedFrameDamage(damage_rect); | 1734 layer->OnDelegatedFrameDamage(damage_rect); |
1734 EXPECT_TRUE(delegate.delegated_frame_damage_called()); | 1735 EXPECT_TRUE(delegate.delegated_frame_damage_called()); |
1735 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); | 1736 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); |
1736 } | 1737 } |
1737 | 1738 |
1738 } // namespace ui | 1739 } // namespace ui |
OLD | NEW |