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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 | 89 |
89 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( | 90 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( |
90 LayerTreeImpl* tree_impl) { | 91 LayerTreeImpl* tree_impl) { |
91 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); | 92 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); |
92 } | 93 } |
93 | 94 |
94 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { | 95 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { |
95 // It's possible this layer was never drawn or updated (e.g. because it was | 96 // It's possible this layer was never drawn or updated (e.g. because it was |
96 // a descendant of an opacity 0 layer). | 97 // a descendant of an opacity 0 layer). |
97 DoPostCommitInitializationIfNeeded(); | 98 DoPostCommitInitializationIfNeeded(); |
99 | |
98 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | 100 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
99 | 101 |
100 // We have already synced the important bits from the the active layer, and | 102 // 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, | 103 // 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 | 104 // 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 | 105 // 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 | 106 // the to-be-recycled tiling to ensure replaced tiles don't linger and take |
105 // memory (due to a stale 'active' priority). | 107 // memory (due to a stale 'active' priority). |
106 if (layer_impl->tilings_) | 108 if (layer_impl->tilings_) |
107 layer_impl->tilings_->DidBecomeRecycled(); | 109 layer_impl->tilings_->DidBecomeRecycled(); |
108 | 110 |
109 LayerImpl::PushPropertiesTo(base_layer); | 111 LayerImpl::PushPropertiesTo(base_layer); |
110 | 112 |
111 // When the pending tree pushes to the active tree, the pending twin | 113 // When the pending tree pushes to the active tree, the pending twin |
112 // becomes recycled. | 114 // becomes recycled. |
113 layer_impl->twin_layer_ = NULL; | 115 layer_impl->twin_layer_ = NULL; |
114 twin_layer_ = NULL; | 116 twin_layer_ = NULL; |
115 | 117 |
116 layer_impl->pile_ = pile_; | 118 layer_impl->pile_ = pile_; |
117 | 119 |
120 DCHECK(!pile_->is_solid_color() || !tilings_->num_tilings()); | |
118 // Tilings would be expensive to push, so we swap. | 121 // Tilings would be expensive to push, so we swap. |
119 layer_impl->tilings_.swap(tilings_); | 122 layer_impl->tilings_.swap(tilings_); |
123 | |
124 // Ensure that the recycle tree doesn't have any unshared tiles. | |
125 if (tilings_ && pile_->is_solid_color()) | |
126 tilings_->RemoveAllTilings(); | |
danakj
2014/09/19 20:44:28
can you do this down by RemoveTilesInRegion (ie af
hendrikw
2014/09/19 22:27:13
The only reason we're removing the tiles is becaus
danakj
2014/09/19 22:46:38
Ya, it's the same with RemoveTilesInRegion, but th
| |
127 | |
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 |
128 layer_impl->raster_page_scale_ = raster_page_scale_; | 136 layer_impl->raster_page_scale_ = raster_page_scale_; |
129 layer_impl->raster_device_scale_ = raster_device_scale_; | 137 layer_impl->raster_device_scale_ = raster_device_scale_; |
(...skipping 13 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(); | |
163 | |
164 if (pile_->is_solid_color()) { | |
165 PopulateSharedQuadState(shared_quad_state); | |
166 | |
167 AppendDebugBorderQuad( | |
168 render_pass, content_bounds(), shared_quad_state, append_quads_data); | |
169 | |
170 SolidColorLayerImpl::AppendSolidQuads( | |
171 render_pass, | |
172 occlusion_tracker, | |
173 append_quads_data, | |
174 shared_quad_state, | |
175 content_bounds(), | |
176 draw_properties().target_space_transform, | |
177 pile_->solid_color()); | |
178 return; | |
179 } | |
180 | |
153 float max_contents_scale = MaximumTilingContentsScale(); | 181 float max_contents_scale = MaximumTilingContentsScale(); |
154 gfx::Transform scaled_draw_transform = draw_transform(); | 182 gfx::Transform scaled_draw_transform = draw_transform(); |
155 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale, | 183 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale, |
156 SK_MScalar1 / max_contents_scale); | 184 SK_MScalar1 / max_contents_scale); |
157 gfx::Size scaled_content_bounds = | 185 gfx::Size scaled_content_bounds = |
158 gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), max_contents_scale)); | 186 gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), max_contents_scale)); |
159 | 187 |
160 gfx::Rect scaled_visible_content_rect = | 188 gfx::Rect scaled_visible_content_rect = |
161 gfx::ScaleToEnclosingRect(visible_content_rect(), max_contents_scale); | 189 gfx::ScaleToEnclosingRect(visible_content_rect(), max_contents_scale); |
162 scaled_visible_content_rect.Intersect(gfx::Rect(scaled_content_bounds)); | 190 scaled_visible_content_rect.Intersect(gfx::Rect(scaled_content_bounds)); |
163 | 191 |
164 SharedQuadState* shared_quad_state = | |
165 render_pass->CreateAndAppendSharedQuadState(); | |
166 shared_quad_state->SetAll(scaled_draw_transform, | 192 shared_quad_state->SetAll(scaled_draw_transform, |
167 scaled_content_bounds, | 193 scaled_content_bounds, |
168 scaled_visible_content_rect, | 194 scaled_visible_content_rect, |
169 draw_properties().clip_rect, | 195 draw_properties().clip_rect, |
170 draw_properties().is_clipped, | 196 draw_properties().is_clipped, |
171 draw_properties().opacity, | 197 draw_properties().opacity, |
172 blend_mode(), | 198 blend_mode(), |
173 sorting_context_id_); | 199 sorting_context_id_); |
174 | 200 |
175 if (current_draw_mode_ == DRAW_MODE_RESOURCELESS_SOFTWARE) { | 201 if (current_draw_mode_ == DRAW_MODE_RESOURCELESS_SOFTWARE) { |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 should_update_tile_priorities_ = true; | 488 should_update_tile_priorities_ = true; |
463 | 489 |
464 UpdateTilePriorities(occlusion_in_content_space); | 490 UpdateTilePriorities(occlusion_in_content_space); |
465 | 491 |
466 if (layer_tree_impl()->IsPendingTree()) | 492 if (layer_tree_impl()->IsPendingTree()) |
467 MarkVisibleResourcesAsRequired(); | 493 MarkVisibleResourcesAsRequired(); |
468 } | 494 } |
469 | 495 |
470 void PictureLayerImpl::UpdateTilePriorities( | 496 void PictureLayerImpl::UpdateTilePriorities( |
471 const Occlusion& occlusion_in_content_space) { | 497 const Occlusion& occlusion_in_content_space) { |
498 DCHECK(!pile_->is_solid_color() || !tilings_->num_tilings()); | |
499 | |
472 TRACE_EVENT0("cc", "PictureLayerImpl::UpdateTilePriorities"); | 500 TRACE_EVENT0("cc", "PictureLayerImpl::UpdateTilePriorities"); |
473 | 501 |
474 double current_frame_time_in_seconds = | 502 double current_frame_time_in_seconds = |
475 (layer_tree_impl()->CurrentBeginFrameArgs().frame_time - | 503 (layer_tree_impl()->CurrentBeginFrameArgs().frame_time - |
476 base::TimeTicks()).InSecondsF(); | 504 base::TimeTicks()).InSecondsF(); |
477 | 505 |
478 bool tiling_needs_update = false; | 506 bool tiling_needs_update = false; |
479 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | 507 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { |
480 if (tilings_->tiling_at(i)->NeedsUpdateForFrameAtTime( | 508 if (tilings_->tiling_at(i)->NeedsUpdateForFrameAtTime( |
481 current_frame_time_in_seconds)) { | 509 current_frame_time_in_seconds)) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
563 // to force tilings to get managed. | 591 // to force tilings to get managed. |
564 layer_tree_impl()->set_needs_update_draw_properties(); | 592 layer_tree_impl()->set_needs_update_draw_properties(); |
565 } | 593 } |
566 | 594 |
567 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { | 595 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { |
568 return pile_->GetFlattenedPicture(); | 596 return pile_->GetFlattenedPicture(); |
569 } | 597 } |
570 | 598 |
571 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, | 599 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, |
572 const gfx::Rect& content_rect) { | 600 const gfx::Rect& content_rect) { |
601 DCHECK(!pile_->is_solid_color()); | |
573 if (!pile_->CanRaster(tiling->contents_scale(), content_rect)) | 602 if (!pile_->CanRaster(tiling->contents_scale(), content_rect)) |
574 return scoped_refptr<Tile>(); | 603 return scoped_refptr<Tile>(); |
575 | 604 |
576 int flags = 0; | 605 int flags = 0; |
577 | 606 |
578 // TODO(vmpstr): Revisit this. For now, enabling analysis means that we get as | 607 // TODO(vmpstr): Revisit this. For now, enabling analysis means that we get as |
579 // much savings on memory as we can. However, for some cases like ganesh or | 608 // much savings on memory as we can. However, for some cases like ganesh or |
580 // small layers, the amount of time we spend analyzing might not justify | 609 // small layers, the amount of time we spend analyzing might not justify |
581 // memory savings that we can get. Note that we don't handle solid color | 610 // memory savings that we can get. Note that we don't handle solid color |
582 // masks, so we shouldn't bother analyzing those. | 611 // masks, so we shouldn't bother analyzing those. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 // should refactor this code a little bit and actually recalculate this. | 757 // should refactor this code a little bit and actually recalculate this. |
729 // However, this is a larger undertaking, so this will work for now. | 758 // However, this is a larger undertaking, so this will work for now. |
730 if (!synced_high_res_tiling) | 759 if (!synced_high_res_tiling) |
731 ResetRasterScale(); | 760 ResetRasterScale(); |
732 else | 761 else |
733 SanityCheckTilingState(); | 762 SanityCheckTilingState(); |
734 } | 763 } |
735 | 764 |
736 void PictureLayerImpl::SyncTiling( | 765 void PictureLayerImpl::SyncTiling( |
737 const PictureLayerTiling* tiling) { | 766 const PictureLayerTiling* tiling) { |
767 DCHECK(!pile_->is_solid_color() || !tilings_->num_tilings()); | |
danakj
2014/09/19 20:44:28
this seems like a funny place to dcheck this..
ma
hendrikw
2014/09/19 22:27:13
I added this on request, now I'm removing it on re
danakj
2014/09/19 22:46:38
Darn I tried to find a review request to add it so
| |
768 | |
738 if (!CanHaveTilingWithScale(tiling->contents_scale())) | 769 if (!CanHaveTilingWithScale(tiling->contents_scale())) |
739 return; | 770 return; |
740 tilings_->AddTiling(tiling->contents_scale()); | 771 tilings_->AddTiling(tiling->contents_scale()); |
741 | 772 |
742 // If this tree needs update draw properties, then the tiling will | 773 // If this tree needs update draw properties, then the tiling will |
743 // get updated prior to drawing or activation. If this tree does not | 774 // get updated prior to drawing or activation. If this tree does not |
744 // need update draw properties, then its transforms are up to date and | 775 // need update draw properties, then its transforms are up to date and |
745 // we can create tiles for this tiling immediately. | 776 // we can create tiles for this tiling immediately. |
746 if (!layer_tree_impl()->needs_update_draw_properties() && | 777 if (!layer_tree_impl()->needs_update_draw_properties() && |
747 should_update_tile_priorities_) { | 778 should_update_tile_priorities_) { |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1288 raster_contents_scale_ = 0.f; | 1319 raster_contents_scale_ = 0.f; |
1289 low_res_raster_contents_scale_ = 0.f; | 1320 low_res_raster_contents_scale_ = 0.f; |
1290 raster_source_scale_is_fixed_ = false; | 1321 raster_source_scale_is_fixed_ = false; |
1291 | 1322 |
1292 // When raster scales aren't valid, don't update tile priorities until | 1323 // When raster scales aren't valid, don't update tile priorities until |
1293 // this layer has been updated via UpdateDrawProperties. | 1324 // this layer has been updated via UpdateDrawProperties. |
1294 should_update_tile_priorities_ = false; | 1325 should_update_tile_priorities_ = false; |
1295 } | 1326 } |
1296 | 1327 |
1297 bool PictureLayerImpl::CanHaveTilings() const { | 1328 bool PictureLayerImpl::CanHaveTilings() const { |
1329 if (pile_->is_solid_color()) | |
1330 return false; | |
1298 if (!DrawsContent()) | 1331 if (!DrawsContent()) |
1299 return false; | 1332 return false; |
1300 if (!pile_->HasRecordings()) | 1333 if (!pile_->HasRecordings()) |
1301 return false; | 1334 return false; |
1302 return true; | 1335 return true; |
1303 } | 1336 } |
1304 | 1337 |
1305 bool PictureLayerImpl::CanHaveTilingWithScale(float contents_scale) const { | 1338 bool PictureLayerImpl::CanHaveTilingWithScale(float contents_scale) const { |
1306 if (!CanHaveTilings()) | 1339 if (!CanHaveTilings()) |
1307 return false; | 1340 return false; |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1762 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); | 1795 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); |
1763 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; | 1796 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; |
1764 return tiling_range.end - 1 - current_tiling_range_offset; | 1797 return tiling_range.end - 1 - current_tiling_range_offset; |
1765 } | 1798 } |
1766 } | 1799 } |
1767 NOTREACHED(); | 1800 NOTREACHED(); |
1768 return 0; | 1801 return 0; |
1769 } | 1802 } |
1770 | 1803 |
1771 } // namespace cc | 1804 } // namespace cc |
OLD | NEW |