OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 ideal_source_scale_(0.f), | 68 ideal_source_scale_(0.f), |
69 ideal_contents_scale_(0.f), | 69 ideal_contents_scale_(0.f), |
70 raster_page_scale_(0.f), | 70 raster_page_scale_(0.f), |
71 raster_device_scale_(0.f), | 71 raster_device_scale_(0.f), |
72 raster_source_scale_(0.f), | 72 raster_source_scale_(0.f), |
73 raster_contents_scale_(0.f), | 73 raster_contents_scale_(0.f), |
74 low_res_raster_contents_scale_(0.f), | 74 low_res_raster_contents_scale_(0.f), |
75 raster_source_scale_is_fixed_(false), | 75 raster_source_scale_is_fixed_(false), |
76 was_screen_space_transform_animating_(false), | 76 was_screen_space_transform_animating_(false), |
77 needs_post_commit_initialization_(true), | 77 needs_post_commit_initialization_(true), |
78 should_update_tile_priorities_(false) { | 78 should_update_tile_priorities_(false), |
| 79 is_solid_color_(false), |
| 80 solid_color_(SK_ColorBLACK) { |
79 layer_tree_impl()->RegisterPictureLayerImpl(this); | 81 layer_tree_impl()->RegisterPictureLayerImpl(this); |
80 } | 82 } |
81 | 83 |
82 PictureLayerImpl::~PictureLayerImpl() { | 84 PictureLayerImpl::~PictureLayerImpl() { |
83 layer_tree_impl()->UnregisterPictureLayerImpl(this); | 85 layer_tree_impl()->UnregisterPictureLayerImpl(this); |
84 } | 86 } |
85 | 87 |
86 const char* PictureLayerImpl::LayerTypeAsString() const { | 88 const char* PictureLayerImpl::LayerTypeAsString() const { |
87 return "cc::PictureLayerImpl"; | 89 return "cc::PictureLayerImpl"; |
88 } | 90 } |
89 | 91 |
90 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( | 92 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( |
91 LayerTreeImpl* tree_impl) { | 93 LayerTreeImpl* tree_impl) { |
92 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); | 94 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); |
93 } | 95 } |
94 | 96 |
95 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { | 97 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { |
96 // It's possible this layer was never drawn or updated (e.g. because it was | 98 // It's possible this layer was never drawn or updated (e.g. because it was |
97 // a descendant of an opacity 0 layer). | 99 // a descendant of an opacity 0 layer). |
98 DoPostCommitInitializationIfNeeded(); | 100 DoPostCommitInitializationIfNeeded(); |
| 101 |
99 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | 102 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
100 | 103 |
101 // We have already synced the important bits from the the active layer, and | 104 // We have already synced the important bits from the the active layer, and |
102 // we will soon swap out its tilings and use them for recycling. However, | 105 // we will soon swap out its tilings and use them for recycling. However, |
103 // there are now tiles in this layer's tilings that were unref'd and replaced | 106 // there are now tiles in this layer's tilings that were unref'd and replaced |
104 // with new tiles (due to invalidation). This resets all active priorities on | 107 // with new tiles (due to invalidation). This resets all active priorities on |
105 // the to-be-recycled tiling to ensure replaced tiles don't linger and take | 108 // the to-be-recycled tiling to ensure replaced tiles don't linger and take |
106 // memory (due to a stale 'active' priority). | 109 // memory (due to a stale 'active' priority). |
107 if (layer_impl->tilings_) | 110 if (layer_impl->tilings_) |
108 layer_impl->tilings_->DidBecomeRecycled(); | 111 layer_impl->tilings_->DidBecomeRecycled(); |
109 | 112 |
110 LayerImpl::PushPropertiesTo(base_layer); | 113 LayerImpl::PushPropertiesTo(base_layer); |
111 | 114 |
112 // When the pending tree pushes to the active tree, the pending twin | 115 // When the pending tree pushes to the active tree, the pending twin |
113 // becomes recycled. | 116 // becomes recycled. |
114 layer_impl->twin_layer_ = NULL; | 117 layer_impl->twin_layer_ = NULL; |
115 twin_layer_ = NULL; | 118 twin_layer_ = NULL; |
116 | 119 |
117 layer_impl->SetIsMask(is_mask_); | 120 layer_impl->SetIsMask(is_mask_); |
118 layer_impl->pile_ = pile_; | 121 layer_impl->pile_ = pile_; |
119 | 122 |
| 123 DCHECK(!IsSolidColor() || !tilings_->num_tilings()); |
| 124 layer_impl->is_solid_color_ = is_solid_color_; |
| 125 layer_impl->solid_color_ = solid_color_; |
| 126 |
120 // Tilings would be expensive to push, so we swap. | 127 // Tilings would be expensive to push, so we swap. |
121 layer_impl->tilings_.swap(tilings_); | 128 layer_impl->tilings_.swap(tilings_); |
122 | 129 |
123 // Remove invalidated tiles from what will become a recycle tree. | 130 // Remove invalidated tiles from what will become a recycle tree. |
124 if (tilings_) | 131 if (tilings_) |
125 tilings_->RemoveTilesInRegion(invalidation_); | 132 tilings_->RemoveTilesInRegion(invalidation_); |
126 | 133 |
127 layer_impl->tilings_->SetClient(layer_impl); | 134 layer_impl->tilings_->SetClient(layer_impl); |
128 if (tilings_) | 135 if (tilings_) |
129 tilings_->SetClient(this); | 136 tilings_->SetClient(this); |
(...skipping 14 matching lines...) Expand all Loading... |
144 | 151 |
145 // We always need to push properties. | 152 // We always need to push properties. |
146 // See http://crbug.com/303943 | 153 // See http://crbug.com/303943 |
147 needs_push_properties_ = true; | 154 needs_push_properties_ = true; |
148 } | 155 } |
149 | 156 |
150 void PictureLayerImpl::AppendQuads( | 157 void PictureLayerImpl::AppendQuads( |
151 RenderPass* render_pass, | 158 RenderPass* render_pass, |
152 const OcclusionTracker<LayerImpl>& occlusion_tracker, | 159 const OcclusionTracker<LayerImpl>& occlusion_tracker, |
153 AppendQuadsData* append_quads_data) { | 160 AppendQuadsData* append_quads_data) { |
| 161 if (IsSolidColor()) { |
| 162 AppendSolidQuads( |
| 163 render_pass, occlusion_tracker, append_quads_data, solid_color_); |
| 164 return; |
| 165 } |
| 166 |
154 DCHECK(!needs_post_commit_initialization_); | 167 DCHECK(!needs_post_commit_initialization_); |
155 | 168 |
156 float max_contents_scale = MaximumTilingContentsScale(); | 169 float max_contents_scale = MaximumTilingContentsScale(); |
157 gfx::Transform scaled_draw_transform = draw_transform(); | 170 gfx::Transform scaled_draw_transform = draw_transform(); |
158 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale, | 171 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale, |
159 SK_MScalar1 / max_contents_scale); | 172 SK_MScalar1 / max_contents_scale); |
160 gfx::Size scaled_content_bounds = | 173 gfx::Size scaled_content_bounds = |
161 gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), max_contents_scale)); | 174 gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), max_contents_scale)); |
162 | 175 |
163 gfx::Rect scaled_visible_content_rect = | 176 gfx::Rect scaled_visible_content_rect = |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 // to force tilings to get managed. | 590 // to force tilings to get managed. |
578 layer_tree_impl()->set_needs_update_draw_properties(); | 591 layer_tree_impl()->set_needs_update_draw_properties(); |
579 } | 592 } |
580 | 593 |
581 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { | 594 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { |
582 return pile_->GetFlattenedPicture(); | 595 return pile_->GetFlattenedPicture(); |
583 } | 596 } |
584 | 597 |
585 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, | 598 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, |
586 const gfx::Rect& content_rect) { | 599 const gfx::Rect& content_rect) { |
| 600 DCHECK(!IsSolidColor()); |
587 if (!pile_->CanRaster(tiling->contents_scale(), content_rect)) | 601 if (!pile_->CanRaster(tiling->contents_scale(), content_rect)) |
588 return scoped_refptr<Tile>(); | 602 return scoped_refptr<Tile>(); |
589 | 603 |
590 // TODO(vmpstr): Revisit this. For now, enabling analysis means that we get as | 604 // TODO(vmpstr): Revisit this. For now, enabling analysis means that we get as |
591 // much savings on memory as we can. However, for some cases like ganesh or | 605 // much savings on memory as we can. However, for some cases like ganesh or |
592 // small layers, the amount of time we spend analyzing might not justify | 606 // small layers, the amount of time we spend analyzing might not justify |
593 // memory savings that we can get. | 607 // memory savings that we can get. |
594 // Bugs: crbug.com/397198, crbug.com/396908 | 608 // Bugs: crbug.com/397198, crbug.com/396908 |
595 int flags = Tile::USE_PICTURE_ANALYSIS; | 609 int flags = Tile::USE_PICTURE_ANALYSIS; |
596 | 610 |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 raster_contents_scale_ = 0.f; | 1324 raster_contents_scale_ = 0.f; |
1311 low_res_raster_contents_scale_ = 0.f; | 1325 low_res_raster_contents_scale_ = 0.f; |
1312 raster_source_scale_is_fixed_ = false; | 1326 raster_source_scale_is_fixed_ = false; |
1313 | 1327 |
1314 // When raster scales aren't valid, don't update tile priorities until | 1328 // When raster scales aren't valid, don't update tile priorities until |
1315 // this layer has been updated via UpdateDrawProperties. | 1329 // this layer has been updated via UpdateDrawProperties. |
1316 should_update_tile_priorities_ = false; | 1330 should_update_tile_priorities_ = false; |
1317 } | 1331 } |
1318 | 1332 |
1319 bool PictureLayerImpl::CanHaveTilings() const { | 1333 bool PictureLayerImpl::CanHaveTilings() const { |
| 1334 if (IsSolidColor()) |
| 1335 return false; |
1320 if (!DrawsContent()) | 1336 if (!DrawsContent()) |
1321 return false; | 1337 return false; |
1322 if (!pile_->HasRecordings()) | 1338 if (!pile_->HasRecordings()) |
1323 return false; | 1339 return false; |
1324 return true; | 1340 return true; |
1325 } | 1341 } |
1326 | 1342 |
1327 bool PictureLayerImpl::CanHaveTilingWithScale(float contents_scale) const { | 1343 bool PictureLayerImpl::CanHaveTilingWithScale(float contents_scale) const { |
1328 if (!CanHaveTilings()) | 1344 if (!CanHaveTilings()) |
1329 return false; | 1345 return false; |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1773 case PictureLayerTilingSet::LOWER_THAN_LOW_RES: { | 1789 case PictureLayerTilingSet::LOWER_THAN_LOW_RES: { |
1774 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); | 1790 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); |
1775 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; | 1791 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; |
1776 return tiling_range.end - 1 - current_tiling_range_offset; | 1792 return tiling_range.end - 1 - current_tiling_range_offset; |
1777 } | 1793 } |
1778 } | 1794 } |
1779 NOTREACHED(); | 1795 NOTREACHED(); |
1780 return 0; | 1796 return 0; |
1781 } | 1797 } |
1782 | 1798 |
| 1799 void PictureLayerImpl::SetSolidColorState(bool is_solid_color, |
| 1800 SkColor solid_color) { |
| 1801 is_solid_color_ = is_solid_color; |
| 1802 solid_color_ = solid_color; |
| 1803 } |
| 1804 |
1783 } // namespace cc | 1805 } // namespace cc |
OLD | NEW |