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 |
11 #include "base/debug/trace_event_argument.h" | 11 #include "base/debug/trace_event_argument.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "cc/base/math_util.h" | 13 #include "cc/base/math_util.h" |
14 #include "cc/base/util.h" | 14 #include "cc/base/util.h" |
15 #include "cc/debug/debug_colors.h" | 15 #include "cc/debug/debug_colors.h" |
16 #include "cc/debug/micro_benchmark_impl.h" | 16 #include "cc/debug/micro_benchmark_impl.h" |
17 #include "cc/debug/traced_value.h" | 17 #include "cc/debug/traced_value.h" |
18 #include "cc/layers/append_quads_data.h" | 18 #include "cc/layers/append_quads_data.h" |
19 #include "cc/layers/solid_color_layer_impl.h" | |
19 #include "cc/output/begin_frame_args.h" | 20 #include "cc/output/begin_frame_args.h" |
20 #include "cc/quads/checkerboard_draw_quad.h" | 21 #include "cc/quads/checkerboard_draw_quad.h" |
21 #include "cc/quads/debug_border_draw_quad.h" | 22 #include "cc/quads/debug_border_draw_quad.h" |
22 #include "cc/quads/picture_draw_quad.h" | 23 #include "cc/quads/picture_draw_quad.h" |
23 #include "cc/quads/solid_color_draw_quad.h" | 24 #include "cc/quads/solid_color_draw_quad.h" |
24 #include "cc/quads/tile_draw_quad.h" | 25 #include "cc/quads/tile_draw_quad.h" |
25 #include "cc/resources/tile_manager.h" | 26 #include "cc/resources/tile_manager.h" |
26 #include "cc/trees/layer_tree_impl.h" | 27 #include "cc/trees/layer_tree_impl.h" |
27 #include "cc/trees/occlusion_tracker.h" | 28 #include "cc/trees/occlusion_tracker.h" |
28 #include "ui/gfx/quad_f.h" | 29 #include "ui/gfx/quad_f.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 ideal_source_scale_(0.f), | 68 ideal_source_scale_(0.f), |
68 ideal_contents_scale_(0.f), | 69 ideal_contents_scale_(0.f), |
69 raster_page_scale_(0.f), | 70 raster_page_scale_(0.f), |
70 raster_device_scale_(0.f), | 71 raster_device_scale_(0.f), |
71 raster_source_scale_(0.f), | 72 raster_source_scale_(0.f), |
72 raster_contents_scale_(0.f), | 73 raster_contents_scale_(0.f), |
73 low_res_raster_contents_scale_(0.f), | 74 low_res_raster_contents_scale_(0.f), |
74 raster_source_scale_is_fixed_(false), | 75 raster_source_scale_is_fixed_(false), |
75 was_screen_space_transform_animating_(false), | 76 was_screen_space_transform_animating_(false), |
76 needs_post_commit_initialization_(true), | 77 needs_post_commit_initialization_(true), |
77 should_update_tile_priorities_(false) { | 78 should_update_tile_priorities_(false), |
79 is_solid_color_(false), | |
80 solid_color_(SK_ColorBLACK) { | |
78 layer_tree_impl()->RegisterPictureLayerImpl(this); | 81 layer_tree_impl()->RegisterPictureLayerImpl(this); |
79 } | 82 } |
80 | 83 |
81 PictureLayerImpl::~PictureLayerImpl() { | 84 PictureLayerImpl::~PictureLayerImpl() { |
82 layer_tree_impl()->UnregisterPictureLayerImpl(this); | 85 layer_tree_impl()->UnregisterPictureLayerImpl(this); |
83 } | 86 } |
84 | 87 |
85 const char* PictureLayerImpl::LayerTypeAsString() const { | 88 const char* PictureLayerImpl::LayerTypeAsString() const { |
86 return "cc::PictureLayerImpl"; | 89 return "cc::PictureLayerImpl"; |
87 } | 90 } |
88 | 91 |
89 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( | 92 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( |
90 LayerTreeImpl* tree_impl) { | 93 LayerTreeImpl* tree_impl) { |
91 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); | 94 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); |
92 } | 95 } |
93 | 96 |
94 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { | 97 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { |
95 // 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 |
96 // a descendant of an opacity 0 layer). | 99 // a descendant of an opacity 0 layer). |
97 DoPostCommitInitializationIfNeeded(); | 100 DoPostCommitInitializationIfNeeded(); |
101 | |
98 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | 102 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
99 | 103 |
100 // 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 |
101 // 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, |
102 // 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 |
103 // 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 |
104 // 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 |
105 // memory (due to a stale 'active' priority). | 109 // memory (due to a stale 'active' priority). |
106 if (layer_impl->tilings_) | 110 if (layer_impl->tilings_) |
107 layer_impl->tilings_->DidBecomeRecycled(); | 111 layer_impl->tilings_->DidBecomeRecycled(); |
108 | 112 |
109 LayerImpl::PushPropertiesTo(base_layer); | 113 LayerImpl::PushPropertiesTo(base_layer); |
110 | 114 |
111 // 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 |
112 // becomes recycled. | 116 // becomes recycled. |
113 layer_impl->twin_layer_ = NULL; | 117 layer_impl->twin_layer_ = NULL; |
114 twin_layer_ = NULL; | 118 twin_layer_ = NULL; |
115 | 119 |
116 layer_impl->pile_ = pile_; | 120 layer_impl->pile_ = pile_; |
117 | 121 |
122 DCHECK(!IsSolidColor() || !tilings_->num_tilings()); | |
123 layer_impl->is_solid_color_ = is_solid_color_; | |
124 layer_impl->solid_color_ = solid_color_; | |
125 | |
118 // Tilings would be expensive to push, so we swap. | 126 // Tilings would be expensive to push, so we swap. |
119 layer_impl->tilings_.swap(tilings_); | 127 layer_impl->tilings_.swap(tilings_); |
120 layer_impl->tilings_->SetClient(layer_impl); | 128 layer_impl->tilings_->SetClient(layer_impl); |
121 if (tilings_) | 129 if (tilings_) |
122 tilings_->SetClient(this); | 130 tilings_->SetClient(this); |
123 | 131 |
124 // Remove invalidated tiles from what will become a recycle tree. | 132 // Remove invalidated tiles from what will become a recycle tree. |
125 if (tilings_) | 133 if (tilings_) |
126 tilings_->RemoveTilesInRegion(invalidation_); | 134 tilings_->RemoveTilesInRegion(invalidation_); |
127 | 135 |
(...skipping 15 matching lines...) Expand all Loading... | |
143 // See http://crbug.com/303943 | 151 // See http://crbug.com/303943 |
144 needs_push_properties_ = true; | 152 needs_push_properties_ = true; |
145 } | 153 } |
146 | 154 |
147 void PictureLayerImpl::AppendQuads( | 155 void PictureLayerImpl::AppendQuads( |
148 RenderPass* render_pass, | 156 RenderPass* render_pass, |
149 const OcclusionTracker<LayerImpl>& occlusion_tracker, | 157 const OcclusionTracker<LayerImpl>& occlusion_tracker, |
150 AppendQuadsData* append_quads_data) { | 158 AppendQuadsData* append_quads_data) { |
151 DCHECK(!needs_post_commit_initialization_); | 159 DCHECK(!needs_post_commit_initialization_); |
152 | 160 |
161 SharedQuadState* shared_quad_state = | |
162 render_pass->CreateAndAppendSharedQuadState(); | |
danakj
2014/09/10 18:46:40
nit: whitespace below this to show it's not only u
hendrikw
2014/09/11 00:27:40
Acknowledged.
| |
163 if (IsSolidColor()) { | |
164 PopulateSharedQuadState(shared_quad_state); | |
danakj
2014/09/10 18:46:40
can you add a PLI unittest that hits this code pat
hendrikw
2014/09/11 00:27:40
There are several tests which hit both code paths,
danakj
2014/09/11 23:43:50
A test designed to explictly hit both would be nic
| |
165 | |
166 AppendDebugBorderQuad( | |
167 render_pass, content_bounds(), shared_quad_state, append_quads_data); | |
168 | |
169 SolidColorLayerImpl::AppendSolidQuads( | |
170 render_pass, | |
171 occlusion_tracker, | |
172 append_quads_data, | |
173 shared_quad_state, | |
174 content_bounds(), | |
175 draw_properties().target_space_transform, | |
176 solid_color_); | |
177 return; | |
178 } | |
179 | |
153 float max_contents_scale = MaximumTilingContentsScale(); | 180 float max_contents_scale = MaximumTilingContentsScale(); |
154 gfx::Transform scaled_draw_transform = draw_transform(); | 181 gfx::Transform scaled_draw_transform = draw_transform(); |
155 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale, | 182 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale, |
156 SK_MScalar1 / max_contents_scale); | 183 SK_MScalar1 / max_contents_scale); |
157 gfx::Size scaled_content_bounds = | 184 gfx::Size scaled_content_bounds = |
158 gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), max_contents_scale)); | 185 gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), max_contents_scale)); |
159 | 186 |
160 gfx::Rect scaled_visible_content_rect = | 187 gfx::Rect scaled_visible_content_rect = |
161 gfx::ScaleToEnclosingRect(visible_content_rect(), max_contents_scale); | 188 gfx::ScaleToEnclosingRect(visible_content_rect(), max_contents_scale); |
162 scaled_visible_content_rect.Intersect(gfx::Rect(scaled_content_bounds)); | 189 scaled_visible_content_rect.Intersect(gfx::Rect(scaled_content_bounds)); |
163 | 190 |
164 SharedQuadState* shared_quad_state = | |
165 render_pass->CreateAndAppendSharedQuadState(); | |
166 shared_quad_state->SetAll(scaled_draw_transform, | 191 shared_quad_state->SetAll(scaled_draw_transform, |
167 scaled_content_bounds, | 192 scaled_content_bounds, |
168 scaled_visible_content_rect, | 193 scaled_visible_content_rect, |
169 draw_properties().clip_rect, | 194 draw_properties().clip_rect, |
170 draw_properties().is_clipped, | 195 draw_properties().is_clipped, |
171 draw_properties().opacity, | 196 draw_properties().opacity, |
172 blend_mode(), | 197 blend_mode(), |
173 sorting_context_id_); | 198 sorting_context_id_); |
174 | 199 |
175 if (current_draw_mode_ == DRAW_MODE_RESOURCELESS_SOFTWARE) { | 200 if (current_draw_mode_ == DRAW_MODE_RESOURCELESS_SOFTWARE) { |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
570 // to force tilings to get managed. | 595 // to force tilings to get managed. |
571 layer_tree_impl()->set_needs_update_draw_properties(); | 596 layer_tree_impl()->set_needs_update_draw_properties(); |
572 } | 597 } |
573 | 598 |
574 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { | 599 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { |
575 return pile_->GetFlattenedPicture(); | 600 return pile_->GetFlattenedPicture(); |
576 } | 601 } |
577 | 602 |
578 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, | 603 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, |
579 const gfx::Rect& content_rect) { | 604 const gfx::Rect& content_rect) { |
605 DCHECK(!IsSolidColor()); | |
580 if (!pile_->CanRaster(tiling->contents_scale(), content_rect)) | 606 if (!pile_->CanRaster(tiling->contents_scale(), content_rect)) |
581 return scoped_refptr<Tile>(); | 607 return scoped_refptr<Tile>(); |
582 | 608 |
583 int flags = 0; | 609 int flags = 0; |
584 | 610 |
585 // TODO(vmpstr): Revisit this. For now, enabling analysis means that we get as | 611 // TODO(vmpstr): Revisit this. For now, enabling analysis means that we get as |
586 // much savings on memory as we can. However, for some cases like ganesh or | 612 // much savings on memory as we can. However, for some cases like ganesh or |
587 // small layers, the amount of time we spend analyzing might not justify | 613 // small layers, the amount of time we spend analyzing might not justify |
588 // memory savings that we can get. Note that we don't handle solid color | 614 // memory savings that we can get. Note that we don't handle solid color |
589 // masks, so we shouldn't bother analyzing those. | 615 // masks, so we shouldn't bother analyzing those. |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1306 raster_contents_scale_ = 0.f; | 1332 raster_contents_scale_ = 0.f; |
1307 low_res_raster_contents_scale_ = 0.f; | 1333 low_res_raster_contents_scale_ = 0.f; |
1308 raster_source_scale_is_fixed_ = false; | 1334 raster_source_scale_is_fixed_ = false; |
1309 | 1335 |
1310 // When raster scales aren't valid, don't update tile priorities until | 1336 // When raster scales aren't valid, don't update tile priorities until |
1311 // this layer has been updated via UpdateDrawProperties. | 1337 // this layer has been updated via UpdateDrawProperties. |
1312 should_update_tile_priorities_ = false; | 1338 should_update_tile_priorities_ = false; |
1313 } | 1339 } |
1314 | 1340 |
1315 bool PictureLayerImpl::CanHaveTilings() const { | 1341 bool PictureLayerImpl::CanHaveTilings() const { |
1342 if (IsSolidColor()) | |
1343 return false; | |
1316 if (!DrawsContent()) | 1344 if (!DrawsContent()) |
1317 return false; | 1345 return false; |
1318 if (!pile_->HasRecordings()) | 1346 if (!pile_->HasRecordings()) |
1319 return false; | 1347 return false; |
1320 return true; | 1348 return true; |
1321 } | 1349 } |
1322 | 1350 |
1323 bool PictureLayerImpl::CanHaveTilingWithScale(float contents_scale) const { | 1351 bool PictureLayerImpl::CanHaveTilingWithScale(float contents_scale) const { |
1324 if (!CanHaveTilings()) | 1352 if (!CanHaveTilings()) |
1325 return false; | 1353 return false; |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1769 case PictureLayerTilingSet::LOWER_THAN_LOW_RES: { | 1797 case PictureLayerTilingSet::LOWER_THAN_LOW_RES: { |
1770 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); | 1798 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); |
1771 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; | 1799 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; |
1772 return tiling_range.end - 1 - current_tiling_range_offset; | 1800 return tiling_range.end - 1 - current_tiling_range_offset; |
1773 } | 1801 } |
1774 } | 1802 } |
1775 NOTREACHED(); | 1803 NOTREACHED(); |
1776 return 0; | 1804 return 0; |
1777 } | 1805 } |
1778 | 1806 |
1807 void PictureLayerImpl::SetSolidColorState(bool is_solid_color, | |
1808 SkColor solid_color) { | |
1809 is_solid_color_ = is_solid_color; | |
1810 solid_color_ = solid_color; | |
1811 } | |
1812 | |
1779 } // namespace cc | 1813 } // namespace cc |
OLD | NEW |