| 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/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 set_delegate(this); | 59 set_delegate(this); |
| 60 } | 60 } |
| 61 | 61 |
| 62 virtual ~ColoredLayer() { } | 62 virtual ~ColoredLayer() { } |
| 63 | 63 |
| 64 // Overridden from LayerDelegate: | 64 // Overridden from LayerDelegate: |
| 65 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { | 65 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { |
| 66 canvas->DrawColor(color_); | 66 canvas->DrawColor(color_); |
| 67 } | 67 } |
| 68 | 68 |
| 69 virtual void OnDelegatedFrameDamage( |
| 70 const gfx::Rect& damage_rect_in_dip) OVERRIDE {} |
| 71 |
| 69 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { | 72 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { |
| 70 } | 73 } |
| 71 | 74 |
| 72 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE { | 75 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE { |
| 73 return base::Closure(); | 76 return base::Closure(); |
| 74 } | 77 } |
| 75 | 78 |
| 76 private: | 79 private: |
| 77 SkColor color_; | 80 SkColor color_; |
| 78 }; | 81 }; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { | 236 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { |
| 234 SkISize size = canvas->sk_canvas()->getBaseLayerSize(); | 237 SkISize size = canvas->sk_canvas()->getBaseLayerSize(); |
| 235 paint_size_ = gfx::Size(size.width(), size.height()); | 238 paint_size_ = gfx::Size(size.width(), size.height()); |
| 236 canvas->FillRect(gfx::Rect(paint_size_), colors_[color_index_]); | 239 canvas->FillRect(gfx::Rect(paint_size_), colors_[color_index_]); |
| 237 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size()); | 240 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size()); |
| 238 const SkMatrix& matrix = canvas->sk_canvas()->getTotalMatrix(); | 241 const SkMatrix& matrix = canvas->sk_canvas()->getTotalMatrix(); |
| 239 scale_x_ = matrix.getScaleX(); | 242 scale_x_ = matrix.getScaleX(); |
| 240 scale_y_ = matrix.getScaleY(); | 243 scale_y_ = matrix.getScaleY(); |
| 241 } | 244 } |
| 242 | 245 |
| 246 virtual void OnDelegatedFrameDamage( |
| 247 const gfx::Rect& damage_rect_in_dip) OVERRIDE {} |
| 248 |
| 243 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { | 249 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { |
| 244 device_scale_factor_ = device_scale_factor; | 250 device_scale_factor_ = device_scale_factor; |
| 245 } | 251 } |
| 246 | 252 |
| 247 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE { | 253 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE { |
| 248 return base::Closure(); | 254 return base::Closure(); |
| 249 } | 255 } |
| 250 | 256 |
| 251 void reset() { | 257 void reset() { |
| 252 color_index_ = 0; | 258 color_index_ = 0; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 276 painted_ = false; | 282 painted_ = false; |
| 277 } | 283 } |
| 278 | 284 |
| 279 bool painted() const { return painted_; } | 285 bool painted() const { return painted_; } |
| 280 | 286 |
| 281 private: | 287 private: |
| 282 // Overridden from LayerDelegate: | 288 // Overridden from LayerDelegate: |
| 283 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { | 289 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { |
| 284 painted_ = true; | 290 painted_ = true; |
| 285 } | 291 } |
| 292 virtual void OnDelegatedFrameDamage( |
| 293 const gfx::Rect& damage_rect_in_dip) OVERRIDE {} |
| 286 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { | 294 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { |
| 287 } | 295 } |
| 288 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE { | 296 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE { |
| 289 return base::Closure(); | 297 return base::Closure(); |
| 290 } | 298 } |
| 291 | 299 |
| 292 bool painted_; | 300 bool painted_; |
| 293 | 301 |
| 294 DISALLOW_COPY_AND_ASSIGN(DrawTreeLayerDelegate); | 302 DISALLOW_COPY_AND_ASSIGN(DrawTreeLayerDelegate); |
| 295 }; | 303 }; |
| 296 | 304 |
| 297 // The simplest possible layer delegate. Does nothing. | 305 // The simplest possible layer delegate. Does nothing. |
| 298 class NullLayerDelegate : public LayerDelegate { | 306 class NullLayerDelegate : public LayerDelegate { |
| 299 public: | 307 public: |
| 300 NullLayerDelegate() {} | 308 NullLayerDelegate() {} |
| 301 virtual ~NullLayerDelegate() {} | 309 virtual ~NullLayerDelegate() {} |
| 302 | 310 |
| 303 private: | 311 private: |
| 304 // Overridden from LayerDelegate: | 312 // Overridden from LayerDelegate: |
| 305 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { | 313 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {} |
| 306 } | 314 virtual void OnDelegatedFrameDamage( |
| 307 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { | 315 const gfx::Rect& damage_rect_in_dip) OVERRIDE {} |
| 308 } | 316 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {} |
| 309 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE { | 317 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE { |
| 310 return base::Closure(); | 318 return base::Closure(); |
| 311 } | 319 } |
| 312 | 320 |
| 313 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); | 321 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); |
| 314 }; | 322 }; |
| 315 | 323 |
| 316 // Remembers if it has been notified. | 324 // Remembers if it has been notified. |
| 317 class TestCompositorObserver : public CompositorObserver { | 325 class TestCompositorObserver : public CompositorObserver { |
| 318 public: | 326 public: |
| (...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 paint_count_++; | 1122 paint_count_++; |
| 1115 if (!schedule_paint_rect_.IsEmpty()) { | 1123 if (!schedule_paint_rect_.IsEmpty()) { |
| 1116 layer_->SchedulePaint(schedule_paint_rect_); | 1124 layer_->SchedulePaint(schedule_paint_rect_); |
| 1117 schedule_paint_rect_ = gfx::Rect(); | 1125 schedule_paint_rect_ = gfx::Rect(); |
| 1118 } | 1126 } |
| 1119 SkRect sk_clip_rect; | 1127 SkRect sk_clip_rect; |
| 1120 if (canvas->sk_canvas()->getClipBounds(&sk_clip_rect)) | 1128 if (canvas->sk_canvas()->getClipBounds(&sk_clip_rect)) |
| 1121 last_clip_rect_ = gfx::SkRectToRectF(sk_clip_rect); | 1129 last_clip_rect_ = gfx::SkRectToRectF(sk_clip_rect); |
| 1122 } | 1130 } |
| 1123 | 1131 |
| 1132 virtual void OnDelegatedFrameDamage( |
| 1133 const gfx::Rect& damage_rect_in_dip) OVERRIDE {} |
| 1134 |
| 1124 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { | 1135 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { |
| 1125 } | 1136 } |
| 1126 | 1137 |
| 1127 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE { | 1138 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE { |
| 1128 return base::Closure(); | 1139 return base::Closure(); |
| 1129 } | 1140 } |
| 1130 | 1141 |
| 1131 int paint_count_; | 1142 int paint_count_; |
| 1132 Layer* layer_; | 1143 Layer* layer_; |
| 1133 gfx::Rect schedule_paint_rect_; | 1144 gfx::Rect schedule_paint_rect_; |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1584 Vector2dFTo100thPercisionString(c11->subpixel_position_offset())); | 1595 Vector2dFTo100thPercisionString(c11->subpixel_position_offset())); |
| 1585 | 1596 |
| 1586 c11->SetBounds(gfx::Rect(2, 2, 10, 10)); | 1597 c11->SetBounds(gfx::Rect(2, 2, 10, 10)); |
| 1587 SnapLayerToPhysicalPixelBoundary(root.get(), c11.get()); | 1598 SnapLayerToPhysicalPixelBoundary(root.get(), c11.get()); |
| 1588 // c11 is now off the pixel. | 1599 // c11 is now off the pixel. |
| 1589 // 0.5 / 1.5 = 0.333... | 1600 // 0.5 / 1.5 = 0.333... |
| 1590 EXPECT_EQ("0.33 0.33", | 1601 EXPECT_EQ("0.33 0.33", |
| 1591 Vector2dFTo100thPercisionString(c11->subpixel_position_offset())); | 1602 Vector2dFTo100thPercisionString(c11->subpixel_position_offset())); |
| 1592 } | 1603 } |
| 1593 | 1604 |
| 1605 class FrameDamageCheckingDelegate : public TestLayerDelegate { |
| 1606 public: |
| 1607 FrameDamageCheckingDelegate() : delegated_frame_damage_called_(false) {} |
| 1608 |
| 1609 virtual void OnDelegatedFrameDamage( |
| 1610 const gfx::Rect& damage_rect_in_dip) OVERRIDE { |
| 1611 delegated_frame_damage_called_ = true; |
| 1612 delegated_frame_damage_rect_ = damage_rect_in_dip; |
| 1613 } |
| 1614 |
| 1615 const gfx::Rect& delegated_frame_damage_rect() const { |
| 1616 return delegated_frame_damage_rect_; |
| 1617 } |
| 1618 bool delegated_frame_damage_called() const { |
| 1619 return delegated_frame_damage_called_; |
| 1620 } |
| 1621 |
| 1622 private: |
| 1623 gfx::Rect delegated_frame_damage_rect_; |
| 1624 bool delegated_frame_damage_called_; |
| 1625 }; |
| 1626 |
| 1627 TEST(LayerDelegateTest, DelegatedFrameDamage) { |
| 1628 scoped_ptr<Layer> layer(new Layer(LAYER_TEXTURED)); |
| 1629 gfx::Rect damage_rect(2, 1, 5, 3); |
| 1630 |
| 1631 FrameDamageCheckingDelegate delegate; |
| 1632 layer->set_delegate(&delegate); |
| 1633 scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection = |
| 1634 new cc::DelegatedFrameResourceCollection; |
| 1635 scoped_refptr<cc::DelegatedFrameProvider> frame_provider( |
| 1636 new cc::DelegatedFrameProvider(resource_collection.get(), |
| 1637 MakeFrameData(gfx::Size(10, 10)))); |
| 1638 layer->SetShowDelegatedContent(frame_provider, gfx::Size(10, 10)); |
| 1639 |
| 1640 EXPECT_FALSE(delegate.delegated_frame_damage_called()); |
| 1641 layer->OnDelegatedFrameDamage(damage_rect); |
| 1642 EXPECT_TRUE(delegate.delegated_frame_damage_called()); |
| 1643 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); |
| 1644 } |
| 1645 |
| 1594 } // namespace ui | 1646 } // namespace ui |
| OLD | NEW |