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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
17 #include "cc/layers/delegated_frame_provider.h" | 17 #include "cc/layers/delegated_frame_provider.h" |
18 #include "cc/layers/delegated_frame_resource_collection.h" | 18 #include "cc/layers/delegated_frame_resource_collection.h" |
19 #include "cc/layers/layer.h" | 19 #include "cc/layers/layer.h" |
20 #include "cc/output/copy_output_request.h" | 20 #include "cc/output/copy_output_request.h" |
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/test/context_factories_for_test.h" | 31 #include "ui/compositor/test/context_factories_for_test.h" |
31 #include "ui/compositor/test/draw_waiter_for_test.h" | 32 #include "ui/compositor/test/draw_waiter_for_test.h" |
32 #include "ui/compositor/test/test_compositor_host.h" | 33 #include "ui/compositor/test/test_compositor_host.h" |
33 #include "ui/compositor/test/test_layers.h" | 34 #include "ui/compositor/test/test_layers.h" |
34 #include "ui/gfx/canvas.h" | 35 #include "ui/gfx/canvas.h" |
35 #include "ui/gfx/codec/png_codec.h" | 36 #include "ui/gfx/codec/png_codec.h" |
36 #include "ui/gfx/gfx_paths.h" | 37 #include "ui/gfx/gfx_paths.h" |
37 #include "ui/gfx/skia_util.h" | 38 #include "ui/gfx/skia_util.h" |
38 | 39 |
39 using cc::MatchesPNGFile; | 40 using cc::MatchesPNGFile; |
(...skipping 15 matching lines...) Expand all Loading... |
55 public: | 56 public: |
56 explicit ColoredLayer(SkColor color) | 57 explicit ColoredLayer(SkColor color) |
57 : Layer(LAYER_TEXTURED), | 58 : Layer(LAYER_TEXTURED), |
58 color_(color) { | 59 color_(color) { |
59 set_delegate(this); | 60 set_delegate(this); |
60 } | 61 } |
61 | 62 |
62 ~ColoredLayer() override {} | 63 ~ColoredLayer() override {} |
63 | 64 |
64 // Overridden from LayerDelegate: | 65 // Overridden from LayerDelegate: |
65 void OnPaintLayer(gfx::Canvas* canvas) override { canvas->DrawColor(color_); } | 66 void OnPaintLayer(const ui::PaintContext& context) override { |
| 67 context.canvas()->DrawColor(color_); |
| 68 } |
66 | 69 |
67 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | 70 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
68 | 71 |
69 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} | 72 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} |
70 | 73 |
71 base::Closure PrepareForLayerBoundsChange() override { | 74 base::Closure PrepareForLayerBoundsChange() override { |
72 return base::Closure(); | 75 return base::Closure(); |
73 } | 76 } |
74 | 77 |
75 private: | 78 private: |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 colors_.push_back(color); | 221 colors_.push_back(color); |
219 } | 222 } |
220 | 223 |
221 int color_index() const { return color_index_; } | 224 int color_index() const { return color_index_; } |
222 | 225 |
223 float device_scale_factor() const { | 226 float device_scale_factor() const { |
224 return device_scale_factor_; | 227 return device_scale_factor_; |
225 } | 228 } |
226 | 229 |
227 // Overridden from LayerDelegate: | 230 // Overridden from LayerDelegate: |
228 void OnPaintLayer(gfx::Canvas* canvas) override { | 231 void OnPaintLayer(const ui::PaintContext& context) override { |
229 canvas->DrawColor(colors_[color_index_]); | 232 context.canvas()->DrawColor(colors_[color_index_]); |
230 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size()); | 233 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size()); |
231 } | 234 } |
232 | 235 |
233 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | 236 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
234 | 237 |
235 void OnDeviceScaleFactorChanged(float device_scale_factor) override { | 238 void OnDeviceScaleFactorChanged(float device_scale_factor) override { |
236 device_scale_factor_ = device_scale_factor; | 239 device_scale_factor_ = device_scale_factor; |
237 } | 240 } |
238 | 241 |
239 base::Closure PrepareForLayerBoundsChange() override { | 242 base::Closure PrepareForLayerBoundsChange() override { |
(...skipping 20 matching lines...) Expand all Loading... |
260 ~DrawTreeLayerDelegate() override {} | 263 ~DrawTreeLayerDelegate() override {} |
261 | 264 |
262 void Reset() { | 265 void Reset() { |
263 painted_ = false; | 266 painted_ = false; |
264 } | 267 } |
265 | 268 |
266 bool painted() const { return painted_; } | 269 bool painted() const { return painted_; } |
267 | 270 |
268 private: | 271 private: |
269 // Overridden from LayerDelegate: | 272 // Overridden from LayerDelegate: |
270 void OnPaintLayer(gfx::Canvas* canvas) override { | 273 void OnPaintLayer(const ui::PaintContext& context) override { |
271 painted_ = true; | 274 painted_ = true; |
272 canvas->DrawColor(SK_ColorWHITE); | 275 context.canvas()->DrawColor(SK_ColorWHITE); |
273 } | 276 } |
274 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | 277 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
275 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} | 278 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} |
276 base::Closure PrepareForLayerBoundsChange() override { | 279 base::Closure PrepareForLayerBoundsChange() override { |
277 return base::Closure(); | 280 return base::Closure(); |
278 } | 281 } |
279 | 282 |
280 bool painted_; | 283 bool painted_; |
281 | 284 |
282 DISALLOW_COPY_AND_ASSIGN(DrawTreeLayerDelegate); | 285 DISALLOW_COPY_AND_ASSIGN(DrawTreeLayerDelegate); |
283 }; | 286 }; |
284 | 287 |
285 // The simplest possible layer delegate. Does nothing. | 288 // The simplest possible layer delegate. Does nothing. |
286 class NullLayerDelegate : public LayerDelegate { | 289 class NullLayerDelegate : public LayerDelegate { |
287 public: | 290 public: |
288 NullLayerDelegate() {} | 291 NullLayerDelegate() {} |
289 ~NullLayerDelegate() override {} | 292 ~NullLayerDelegate() override {} |
290 | 293 |
291 private: | 294 private: |
292 // Overridden from LayerDelegate: | 295 // Overridden from LayerDelegate: |
293 void OnPaintLayer(gfx::Canvas* canvas) override {} | 296 void OnPaintLayer(const ui::PaintContext& context) override {} |
294 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | 297 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
295 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} | 298 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} |
296 base::Closure PrepareForLayerBoundsChange() override { | 299 base::Closure PrepareForLayerBoundsChange() override { |
297 return base::Closure(); | 300 return base::Closure(); |
298 } | 301 } |
299 | 302 |
300 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); | 303 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); |
301 }; | 304 }; |
302 | 305 |
303 // Remembers if it has been notified. | 306 // Remembers if it has been notified. |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 int GetPaintCountAndClear() { | 1203 int GetPaintCountAndClear() { |
1201 int value = paint_count_; | 1204 int value = paint_count_; |
1202 paint_count_ = 0; | 1205 paint_count_ = 0; |
1203 return value; | 1206 return value; |
1204 } | 1207 } |
1205 | 1208 |
1206 const gfx::RectF& last_clip_rect() const { return last_clip_rect_; } | 1209 const gfx::RectF& last_clip_rect() const { return last_clip_rect_; } |
1207 | 1210 |
1208 private: | 1211 private: |
1209 // Overridden from LayerDelegate: | 1212 // Overridden from LayerDelegate: |
1210 void OnPaintLayer(gfx::Canvas* canvas) override { | 1213 void OnPaintLayer(const ui::PaintContext& context) override { |
| 1214 gfx::Canvas* canvas = context.canvas(); |
1211 paint_count_++; | 1215 paint_count_++; |
1212 if (!schedule_paint_rect_.IsEmpty()) { | 1216 if (!schedule_paint_rect_.IsEmpty()) { |
1213 layer_->SchedulePaint(schedule_paint_rect_); | 1217 layer_->SchedulePaint(schedule_paint_rect_); |
1214 schedule_paint_rect_ = gfx::Rect(); | 1218 schedule_paint_rect_ = gfx::Rect(); |
1215 } | 1219 } |
1216 SkRect sk_clip_rect; | 1220 SkRect sk_clip_rect; |
1217 if (canvas->sk_canvas()->getClipBounds(&sk_clip_rect)) | 1221 if (canvas->sk_canvas()->getClipBounds(&sk_clip_rect)) |
1218 last_clip_rect_ = gfx::SkRectToRectF(sk_clip_rect); | 1222 last_clip_rect_ = gfx::SkRectToRectF(sk_clip_rect); |
1219 } | 1223 } |
1220 | 1224 |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1725 MakeFrameData(gfx::Size(10, 10)))); | 1729 MakeFrameData(gfx::Size(10, 10)))); |
1726 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); | 1730 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); |
1727 | 1731 |
1728 EXPECT_FALSE(delegate.delegated_frame_damage_called()); | 1732 EXPECT_FALSE(delegate.delegated_frame_damage_called()); |
1729 layer->OnDelegatedFrameDamage(damage_rect); | 1733 layer->OnDelegatedFrameDamage(damage_rect); |
1730 EXPECT_TRUE(delegate.delegated_frame_damage_called()); | 1734 EXPECT_TRUE(delegate.delegated_frame_damage_called()); |
1731 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); | 1735 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); |
1732 } | 1736 } |
1733 | 1737 |
1734 } // namespace ui | 1738 } // namespace ui |
OLD | NEW |