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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 PictureLayerImpl::Pair::~Pair() { | 63 PictureLayerImpl::Pair::~Pair() { |
64 } | 64 } |
65 | 65 |
66 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, | 66 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, |
67 int id, | 67 int id, |
68 bool is_mask) | 68 bool is_mask) |
69 : LayerImpl(tree_impl, id), | 69 : LayerImpl(tree_impl, id), |
70 twin_layer_(nullptr), | 70 twin_layer_(nullptr), |
71 tilings_(CreatePictureLayerTilingSet()), | 71 tilings_(CreatePictureLayerTilingSet()), |
72 // TODO(danakj): Can this be null to start? | |
73 raster_source_(PicturePileImpl::Create()), | |
74 ideal_page_scale_(0.f), | 72 ideal_page_scale_(0.f), |
75 ideal_device_scale_(0.f), | 73 ideal_device_scale_(0.f), |
76 ideal_source_scale_(0.f), | 74 ideal_source_scale_(0.f), |
77 ideal_contents_scale_(0.f), | 75 ideal_contents_scale_(0.f), |
78 raster_page_scale_(0.f), | 76 raster_page_scale_(0.f), |
79 raster_device_scale_(0.f), | 77 raster_device_scale_(0.f), |
80 raster_source_scale_(0.f), | 78 raster_source_scale_(0.f), |
81 raster_contents_scale_(0.f), | 79 raster_contents_scale_(0.f), |
82 low_res_raster_contents_scale_(0.f), | 80 low_res_raster_contents_scale_(0.f), |
83 raster_source_scale_is_fixed_(false), | 81 raster_source_scale_is_fixed_(false), |
84 was_screen_space_transform_animating_(false), | 82 was_screen_space_transform_animating_(false), |
85 needs_post_commit_initialization_(true), | |
86 should_update_tile_priorities_(false), | 83 should_update_tile_priorities_(false), |
87 only_used_low_res_last_append_quads_(false), | 84 only_used_low_res_last_append_quads_(false), |
88 is_mask_(is_mask), | 85 is_mask_(is_mask), |
89 nearest_neighbor_(false) { | 86 nearest_neighbor_(false) { |
90 layer_tree_impl()->RegisterPictureLayerImpl(this); | 87 layer_tree_impl()->RegisterPictureLayerImpl(this); |
91 } | 88 } |
92 | 89 |
93 PictureLayerImpl::~PictureLayerImpl() { | 90 PictureLayerImpl::~PictureLayerImpl() { |
94 if (twin_layer_) | 91 if (twin_layer_) |
95 twin_layer_->twin_layer_ = nullptr; | 92 twin_layer_->twin_layer_ = nullptr; |
(...skipping 21 matching lines...) Expand all Loading... |
117 const char* PictureLayerImpl::LayerTypeAsString() const { | 114 const char* PictureLayerImpl::LayerTypeAsString() const { |
118 return "cc::PictureLayerImpl"; | 115 return "cc::PictureLayerImpl"; |
119 } | 116 } |
120 | 117 |
121 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( | 118 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( |
122 LayerTreeImpl* tree_impl) { | 119 LayerTreeImpl* tree_impl) { |
123 return PictureLayerImpl::Create(tree_impl, id(), is_mask_); | 120 return PictureLayerImpl::Create(tree_impl, id(), is_mask_); |
124 } | 121 } |
125 | 122 |
126 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { | 123 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { |
127 // It's possible this layer was never drawn or updated (e.g. because it was | |
128 // a descendant of an opacity 0 layer). | |
129 DoPostCommitInitializationIfNeeded(); | |
130 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | 124 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
131 DCHECK_EQ(layer_impl->is_mask_, is_mask_); | 125 DCHECK_EQ(layer_impl->is_mask_, is_mask_); |
132 | 126 |
133 LayerImpl::PushPropertiesTo(base_layer); | 127 LayerImpl::PushPropertiesTo(base_layer); |
134 | 128 |
135 // Twin relationships should never change once established. | 129 // Twin relationships should never change once established. |
136 DCHECK_IMPLIES(twin_layer_, twin_layer_ == layer_impl); | 130 DCHECK_IMPLIES(twin_layer_, twin_layer_ == layer_impl); |
137 DCHECK_IMPLIES(twin_layer_, layer_impl->twin_layer_ == this); | 131 DCHECK_IMPLIES(twin_layer_, layer_impl->twin_layer_ == this); |
138 // The twin relationship does not need to exist before the first | 132 // The twin relationship does not need to exist before the first |
139 // PushPropertiesTo from pending to active layer since before that the active | 133 // PushPropertiesTo from pending to active layer since before that the active |
(...skipping 19 matching lines...) Expand all Loading... |
159 layer_impl->tilings_->num_tilings() == 0); | 153 layer_impl->tilings_->num_tilings() == 0); |
160 | 154 |
161 layer_impl->raster_page_scale_ = raster_page_scale_; | 155 layer_impl->raster_page_scale_ = raster_page_scale_; |
162 layer_impl->raster_device_scale_ = raster_device_scale_; | 156 layer_impl->raster_device_scale_ = raster_device_scale_; |
163 layer_impl->raster_source_scale_ = raster_source_scale_; | 157 layer_impl->raster_source_scale_ = raster_source_scale_; |
164 layer_impl->raster_contents_scale_ = raster_contents_scale_; | 158 layer_impl->raster_contents_scale_ = raster_contents_scale_; |
165 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_; | 159 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_; |
166 | 160 |
167 layer_impl->SanityCheckTilingState(); | 161 layer_impl->SanityCheckTilingState(); |
168 | 162 |
169 layer_impl->needs_post_commit_initialization_ = false; | |
170 needs_post_commit_initialization_ = true; | |
171 | |
172 // We always need to push properties. | 163 // We always need to push properties. |
173 // See http://crbug.com/303943 | 164 // See http://crbug.com/303943 |
174 // TODO(danakj): Stop always pushing properties since we don't swap tilings. | 165 // TODO(danakj): Stop always pushing properties since we don't swap tilings. |
175 needs_push_properties_ = true; | 166 needs_push_properties_ = true; |
176 } | 167 } |
177 | 168 |
178 void PictureLayerImpl::AppendQuads(RenderPass* render_pass, | 169 void PictureLayerImpl::AppendQuads(RenderPass* render_pass, |
179 const Occlusion& occlusion_in_content_space, | 170 const Occlusion& occlusion_in_content_space, |
180 AppendQuadsData* append_quads_data) { | 171 AppendQuadsData* append_quads_data) { |
181 DCHECK(!needs_post_commit_initialization_); | |
182 // The bounds and the pile size may differ if the pile wasn't updated (ie. | 172 // The bounds and the pile size may differ if the pile wasn't updated (ie. |
183 // PictureLayer::Update didn't happen). In that case the pile will be empty. | 173 // PictureLayer::Update didn't happen). In that case the pile will be empty. |
184 DCHECK_IMPLIES(!raster_source_->GetSize().IsEmpty(), | 174 DCHECK_IMPLIES(!raster_source_->GetSize().IsEmpty(), |
185 bounds() == raster_source_->GetSize()) | 175 bounds() == raster_source_->GetSize()) |
186 << " bounds " << bounds().ToString() << " pile " | 176 << " bounds " << bounds().ToString() << " pile " |
187 << raster_source_->GetSize().ToString(); | 177 << raster_source_->GetSize().ToString(); |
188 | 178 |
189 SharedQuadState* shared_quad_state = | 179 SharedQuadState* shared_quad_state = |
190 render_pass->CreateAndAppendSharedQuadState(); | 180 render_pass->CreateAndAppendSharedQuadState(); |
191 | 181 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 // better scheme would be to maintain a tighter visible_content_rect for the | 446 // better scheme would be to maintain a tighter visible_content_rect for the |
457 // finer tilings. | 447 // finer tilings. |
458 CleanUpTilingsOnActiveLayer(seen_tilings); | 448 CleanUpTilingsOnActiveLayer(seen_tilings); |
459 } | 449 } |
460 | 450 |
461 void PictureLayerImpl::UpdateTiles(const Occlusion& occlusion_in_content_space, | 451 void PictureLayerImpl::UpdateTiles(const Occlusion& occlusion_in_content_space, |
462 bool resourceless_software_draw) { | 452 bool resourceless_software_draw) { |
463 DCHECK_EQ(1.f, contents_scale_x()); | 453 DCHECK_EQ(1.f, contents_scale_x()); |
464 DCHECK_EQ(1.f, contents_scale_y()); | 454 DCHECK_EQ(1.f, contents_scale_y()); |
465 | 455 |
466 DoPostCommitInitializationIfNeeded(); | |
467 | |
468 if (!resourceless_software_draw) { | 456 if (!resourceless_software_draw) { |
469 visible_rect_for_tile_priority_ = visible_content_rect(); | 457 visible_rect_for_tile_priority_ = visible_content_rect(); |
470 } | 458 } |
471 | 459 |
472 if (!CanHaveTilings()) { | 460 if (!CanHaveTilings()) { |
473 ideal_page_scale_ = 0.f; | 461 ideal_page_scale_ = 0.f; |
474 ideal_device_scale_ = 0.f; | 462 ideal_device_scale_ = 0.f; |
475 ideal_contents_scale_ = 0.f; | 463 ideal_contents_scale_ = 0.f; |
476 ideal_source_scale_ = 0.f; | 464 ideal_source_scale_ = 0.f; |
477 SanityCheckTilingState(); | 465 SanityCheckTilingState(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 scoped_refptr<RasterSource> raster_source, | 566 scoped_refptr<RasterSource> raster_source, |
579 Region* new_invalidation, | 567 Region* new_invalidation, |
580 const PictureLayerTilingSet* pending_set) { | 568 const PictureLayerTilingSet* pending_set) { |
581 // The bounds and the pile size may differ if the pile wasn't updated (ie. | 569 // The bounds and the pile size may differ if the pile wasn't updated (ie. |
582 // PictureLayer::Update didn't happen). In that case the pile will be empty. | 570 // PictureLayer::Update didn't happen). In that case the pile will be empty. |
583 DCHECK_IMPLIES(!raster_source->GetSize().IsEmpty(), | 571 DCHECK_IMPLIES(!raster_source->GetSize().IsEmpty(), |
584 bounds() == raster_source->GetSize()) | 572 bounds() == raster_source->GetSize()) |
585 << " bounds " << bounds().ToString() << " pile " | 573 << " bounds " << bounds().ToString() << " pile " |
586 << raster_source->GetSize().ToString(); | 574 << raster_source->GetSize().ToString(); |
587 | 575 |
588 bool could_have_tilings = CanHaveTilings(); | 576 // The |raster_source_| is initially null, so have to check for that for the |
| 577 // first frame. |
| 578 bool could_have_tilings = raster_source_.get() && CanHaveTilings(); |
589 raster_source_.swap(raster_source); | 579 raster_source_.swap(raster_source); |
590 | 580 |
591 // The |new_invalidation| must be cleared before updating tilings since they | 581 // The |new_invalidation| must be cleared before updating tilings since they |
592 // access the invalidation through the PictureLayerTilingClient interface. | 582 // access the invalidation through the PictureLayerTilingClient interface. |
593 invalidation_.Clear(); | 583 invalidation_.Clear(); |
594 invalidation_.Swap(new_invalidation); | 584 invalidation_.Swap(new_invalidation); |
595 | 585 |
596 bool can_have_tilings = CanHaveTilings(); | 586 bool can_have_tilings = CanHaveTilings(); |
597 | 587 |
598 // Need to call UpdateTiles again if CanHaveTilings changed. | 588 // Need to call UpdateTiles again if CanHaveTilings changed. |
599 if (could_have_tilings != can_have_tilings) | 589 if (could_have_tilings != can_have_tilings) |
600 layer_tree_impl()->set_needs_update_draw_properties(); | 590 layer_tree_impl()->set_needs_update_draw_properties(); |
601 | 591 |
602 if (!can_have_tilings) { | 592 if (!can_have_tilings) { |
603 RemoveAllTilings(); | 593 RemoveAllTilings(); |
604 return; | 594 return; |
605 } | 595 } |
606 | 596 |
607 // We could do this after doing UpdateTiles, which would avoid doing this for | 597 // We could do this after doing UpdateTiles, which would avoid doing this for |
608 // tilings that are going to disappear on the pending tree (if scale changed). | 598 // tilings that are going to disappear on the pending tree (if scale changed). |
609 // But that would also be more complicated, so we just do it here for now. | 599 // But that would also be more complicated, so we just do it here for now. |
610 tilings_->UpdateTilingsToCurrentRasterSource( | 600 tilings_->UpdateTilingsToCurrentRasterSource( |
611 raster_source_.get(), pending_set, raster_source_->GetSize(), | 601 raster_source_.get(), pending_set, invalidation_, MinimumContentsScale()); |
612 invalidation_, MinimumContentsScale()); | |
613 } | 602 } |
614 | 603 |
615 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { | 604 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { |
616 if (layer_tree_impl()->IsActiveTree()) { | 605 if (layer_tree_impl()->IsActiveTree()) { |
617 gfx::RectF layer_damage_rect = | 606 gfx::RectF layer_damage_rect = |
618 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); | 607 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); |
619 AddDamageRect(layer_damage_rect); | 608 AddDamageRect(layer_damage_rect); |
620 } | 609 } |
621 } | 610 } |
622 | 611 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 } | 805 } |
817 | 806 |
818 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor) { | 807 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor) { |
819 if (nearest_neighbor_ == nearest_neighbor) | 808 if (nearest_neighbor_ == nearest_neighbor) |
820 return; | 809 return; |
821 | 810 |
822 nearest_neighbor_ = nearest_neighbor; | 811 nearest_neighbor_ = nearest_neighbor; |
823 NoteLayerPropertyChanged(); | 812 NoteLayerPropertyChanged(); |
824 } | 813 } |
825 | 814 |
826 void PictureLayerImpl::DoPostCommitInitialization() { | |
827 // TODO(danakj): Remove this. | |
828 DCHECK(needs_post_commit_initialization_); | |
829 DCHECK(layer_tree_impl()->IsPendingTree()); | |
830 needs_post_commit_initialization_ = false; | |
831 } | |
832 | |
833 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { | 815 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { |
834 DCHECK(CanHaveTilingWithScale(contents_scale)) << | 816 DCHECK(CanHaveTilingWithScale(contents_scale)) << |
835 "contents_scale: " << contents_scale; | 817 "contents_scale: " << contents_scale; |
836 | 818 |
837 PictureLayerTiling* tiling = | 819 PictureLayerTiling* tiling = |
838 tilings_->AddTiling(contents_scale, raster_source_->GetSize()); | 820 tilings_->AddTiling(contents_scale, raster_source_->GetSize()); |
839 | 821 |
840 DCHECK(raster_source_->HasRecordings()); | 822 DCHECK(raster_source_->HasRecordings()); |
841 | 823 |
842 return tiling; | 824 return tiling; |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 } | 1179 } |
1198 | 1180 |
1199 void PictureLayerImpl::GetAllTilesForTracing( | 1181 void PictureLayerImpl::GetAllTilesForTracing( |
1200 std::set<const Tile*>* tiles) const { | 1182 std::set<const Tile*>* tiles) const { |
1201 if (!tilings_) | 1183 if (!tilings_) |
1202 return; | 1184 return; |
1203 tilings_->GetAllTilesForTracing(tiles); | 1185 tilings_->GetAllTilesForTracing(tiles); |
1204 } | 1186 } |
1205 | 1187 |
1206 void PictureLayerImpl::AsValueInto(base::debug::TracedValue* state) const { | 1188 void PictureLayerImpl::AsValueInto(base::debug::TracedValue* state) const { |
1207 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded(); | |
1208 LayerImpl::AsValueInto(state); | 1189 LayerImpl::AsValueInto(state); |
1209 state->SetDouble("ideal_contents_scale", ideal_contents_scale_); | 1190 state->SetDouble("ideal_contents_scale", ideal_contents_scale_); |
1210 state->SetDouble("geometry_contents_scale", MaximumTilingContentsScale()); | 1191 state->SetDouble("geometry_contents_scale", MaximumTilingContentsScale()); |
1211 state->BeginArray("tilings"); | 1192 state->BeginArray("tilings"); |
1212 tilings_->AsValueInto(state); | 1193 tilings_->AsValueInto(state); |
1213 state->EndArray(); | 1194 state->EndArray(); |
1214 | 1195 |
1215 state->BeginArray("tile_priority_rect"); | 1196 state->BeginArray("tile_priority_rect"); |
1216 MathUtil::AddToTracedValue(GetViewportForTilePriorityInContentSpace(), state); | 1197 MathUtil::AddToTracedValue(GetViewportForTilePriorityInContentSpace(), state); |
1217 state->EndArray(); | 1198 state->EndArray(); |
(...skipping 23 matching lines...) Expand all Loading... |
1241 | 1222 |
1242 if (*iter) | 1223 if (*iter) |
1243 TracedValue::SetIDRef(*iter, state, "tile"); | 1224 TracedValue::SetIDRef(*iter, state, "tile"); |
1244 | 1225 |
1245 state->EndDictionary(); | 1226 state->EndDictionary(); |
1246 } | 1227 } |
1247 state->EndArray(); | 1228 state->EndArray(); |
1248 } | 1229 } |
1249 | 1230 |
1250 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const { | 1231 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const { |
1251 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded(); | |
1252 return tilings_->GPUMemoryUsageInBytes(); | 1232 return tilings_->GPUMemoryUsageInBytes(); |
1253 } | 1233 } |
1254 | 1234 |
1255 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { | 1235 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { |
1256 benchmark->RunOnLayer(this); | 1236 benchmark->RunOnLayer(this); |
1257 } | 1237 } |
1258 | 1238 |
1259 WhichTree PictureLayerImpl::GetTree() const { | 1239 WhichTree PictureLayerImpl::GetTree() const { |
1260 return layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE; | 1240 return layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE; |
1261 } | 1241 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1326 | 1306 |
1327 bool PictureLayerImpl::AllTilesRequiredForDrawAreReadyToDraw() const { | 1307 bool PictureLayerImpl::AllTilesRequiredForDrawAreReadyToDraw() const { |
1328 if (!layer_tree_impl()->IsActiveTree()) | 1308 if (!layer_tree_impl()->IsActiveTree()) |
1329 return true; | 1309 return true; |
1330 | 1310 |
1331 return AllTilesRequiredAreReadyToDraw( | 1311 return AllTilesRequiredAreReadyToDraw( |
1332 &PictureLayerTiling::IsTileRequiredForDrawIfVisible); | 1312 &PictureLayerTiling::IsTileRequiredForDrawIfVisible); |
1333 } | 1313 } |
1334 | 1314 |
1335 } // namespace cc | 1315 } // namespace cc |
OLD | NEW |