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 | 9 |
10 #include "base/debug/trace_event_argument.h" | 10 #include "base/debug/trace_event_argument.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 PictureLayerImpl* pending_layer) | 53 PictureLayerImpl* pending_layer) |
54 : active(active_layer), pending(pending_layer) { | 54 : active(active_layer), pending(pending_layer) { |
55 } | 55 } |
56 | 56 |
57 PictureLayerImpl::Pair::~Pair() { | 57 PictureLayerImpl::Pair::~Pair() { |
58 } | 58 } |
59 | 59 |
60 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id) | 60 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id) |
61 : LayerImpl(tree_impl, id), | 61 : LayerImpl(tree_impl, id), |
62 twin_layer_(NULL), | 62 twin_layer_(NULL), |
| 63 recycled_twin_layer_(NULL), |
63 pile_(PicturePileImpl::Create()), | 64 pile_(PicturePileImpl::Create()), |
64 is_mask_(false), | 65 is_mask_(false), |
65 ideal_page_scale_(0.f), | 66 ideal_page_scale_(0.f), |
66 ideal_device_scale_(0.f), | 67 ideal_device_scale_(0.f), |
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), |
(...skipping 29 matching lines...) Expand all Loading... |
102 // there are now tiles in this layer's tilings that were unref'd and replaced | 103 // 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 | 104 // 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 | 105 // the to-be-recycled tiling to ensure replaced tiles don't linger and take |
105 // memory (due to a stale 'active' priority). | 106 // memory (due to a stale 'active' priority). |
106 if (layer_impl->tilings_) | 107 if (layer_impl->tilings_) |
107 layer_impl->tilings_->DidBecomeRecycled(); | 108 layer_impl->tilings_->DidBecomeRecycled(); |
108 | 109 |
109 LayerImpl::PushPropertiesTo(base_layer); | 110 LayerImpl::PushPropertiesTo(base_layer); |
110 | 111 |
111 // When the pending tree pushes to the active tree, the pending twin | 112 // When the pending tree pushes to the active tree, the pending twin |
112 // disappears. | 113 // becomes recycled. |
113 layer_impl->twin_layer_ = NULL; | 114 layer_impl->twin_layer_ = NULL; |
| 115 layer_impl->recycled_twin_layer_ = this; |
| 116 DCHECK(!recycled_twin_layer_); |
114 twin_layer_ = NULL; | 117 twin_layer_ = NULL; |
115 | 118 |
116 layer_impl->SetIsMask(is_mask_); | 119 layer_impl->SetIsMask(is_mask_); |
117 layer_impl->pile_ = pile_; | 120 layer_impl->pile_ = pile_; |
118 | 121 |
119 // Tilings would be expensive to push, so we swap. | 122 // Tilings would be expensive to push, so we swap. |
120 layer_impl->tilings_.swap(tilings_); | 123 layer_impl->tilings_.swap(tilings_); |
121 | 124 |
122 // Remove invalidated tiles from what will become a recycle tree. | 125 // Remove invalidated tiles from what will become a recycle tree. |
123 if (tilings_) | 126 if (tilings_) |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 const PictureLayerTiling* tiling) const { | 606 const PictureLayerTiling* tiling) const { |
604 if (!twin_layer_) | 607 if (!twin_layer_) |
605 return NULL; | 608 return NULL; |
606 for (size_t i = 0; i < twin_layer_->tilings_->num_tilings(); ++i) | 609 for (size_t i = 0; i < twin_layer_->tilings_->num_tilings(); ++i) |
607 if (twin_layer_->tilings_->tiling_at(i)->contents_scale() == | 610 if (twin_layer_->tilings_->tiling_at(i)->contents_scale() == |
608 tiling->contents_scale()) | 611 tiling->contents_scale()) |
609 return twin_layer_->tilings_->tiling_at(i); | 612 return twin_layer_->tilings_->tiling_at(i); |
610 return NULL; | 613 return NULL; |
611 } | 614 } |
612 | 615 |
| 616 PictureLayerTiling* PictureLayerImpl::GetRecycledTwinTiling( |
| 617 const PictureLayerTiling* tiling) const { |
| 618 if (!recycled_twin_layer_ || !recycled_twin_layer_->tilings_) |
| 619 return NULL; |
| 620 return recycled_twin_layer_->tilings_->TilingAtScale( |
| 621 tiling->contents_scale()); |
| 622 } |
| 623 |
613 size_t PictureLayerImpl::GetMaxTilesForInterestArea() const { | 624 size_t PictureLayerImpl::GetMaxTilesForInterestArea() const { |
614 return layer_tree_impl()->settings().max_tiles_for_interest_area; | 625 return layer_tree_impl()->settings().max_tiles_for_interest_area; |
615 } | 626 } |
616 | 627 |
617 float PictureLayerImpl::GetSkewportTargetTimeInSeconds() const { | 628 float PictureLayerImpl::GetSkewportTargetTimeInSeconds() const { |
618 float skewport_target_time_in_frames = | 629 float skewport_target_time_in_frames = |
619 layer_tree_impl()->use_gpu_rasterization() | 630 layer_tree_impl()->use_gpu_rasterization() |
620 ? kGpuSkewportTargetTimeInFrames | 631 ? kGpuSkewportTargetTimeInFrames |
621 : kCpuSkewportTargetTimeInFrames; | 632 : kCpuSkewportTargetTimeInFrames; |
622 return skewport_target_time_in_frames * | 633 return skewport_target_time_in_frames * |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 | 950 |
940 if (!tilings_) | 951 if (!tilings_) |
941 tilings_.reset(new PictureLayerTilingSet(this, bounds())); | 952 tilings_.reset(new PictureLayerTilingSet(this, bounds())); |
942 | 953 |
943 DCHECK(!twin_layer_); | 954 DCHECK(!twin_layer_); |
944 twin_layer_ = static_cast<PictureLayerImpl*>( | 955 twin_layer_ = static_cast<PictureLayerImpl*>( |
945 layer_tree_impl()->FindActiveTreeLayerById(id())); | 956 layer_tree_impl()->FindActiveTreeLayerById(id())); |
946 if (twin_layer_) { | 957 if (twin_layer_) { |
947 DCHECK(!twin_layer_->twin_layer_); | 958 DCHECK(!twin_layer_->twin_layer_); |
948 twin_layer_->twin_layer_ = this; | 959 twin_layer_->twin_layer_ = this; |
| 960 twin_layer_->recycled_twin_layer_ = NULL; |
949 // If the twin has never been pushed to, do not sync from it. | 961 // If the twin has never been pushed to, do not sync from it. |
950 // This can happen if this function is called during activation. | 962 // This can happen if this function is called during activation. |
951 if (!twin_layer_->needs_post_commit_initialization_) | 963 if (!twin_layer_->needs_post_commit_initialization_) |
952 SyncFromActiveLayer(twin_layer_); | 964 SyncFromActiveLayer(twin_layer_); |
953 } | 965 } |
954 | 966 |
955 needs_post_commit_initialization_ = false; | 967 needs_post_commit_initialization_ = false; |
956 } | 968 } |
957 | 969 |
958 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { | 970 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 if (std::find(used_tilings.begin(), used_tilings.end(), tiling) != | 1255 if (std::find(used_tilings.begin(), used_tilings.end(), tiling) != |
1244 used_tilings.end()) | 1256 used_tilings.end()) |
1245 continue; | 1257 continue; |
1246 | 1258 |
1247 to_remove.push_back(tiling); | 1259 to_remove.push_back(tiling); |
1248 } | 1260 } |
1249 | 1261 |
1250 if (to_remove.empty()) | 1262 if (to_remove.empty()) |
1251 return; | 1263 return; |
1252 | 1264 |
1253 PictureLayerImpl* recycled_twin = static_cast<PictureLayerImpl*>( | |
1254 layer_tree_impl()->FindRecycleTreeLayerById(id())); | |
1255 // Remove tilings on this tree and the twin tree. | 1265 // Remove tilings on this tree and the twin tree. |
1256 for (size_t i = 0; i < to_remove.size(); ++i) { | 1266 for (size_t i = 0; i < to_remove.size(); ++i) { |
1257 const PictureLayerTiling* twin_tiling = GetTwinTiling(to_remove[i]); | 1267 const PictureLayerTiling* twin_tiling = GetTwinTiling(to_remove[i]); |
1258 // Only remove tilings from the twin layer if they have | 1268 // Only remove tilings from the twin layer if they have |
1259 // NON_IDEAL_RESOLUTION. | 1269 // NON_IDEAL_RESOLUTION. |
1260 if (twin_tiling && twin_tiling->resolution() == NON_IDEAL_RESOLUTION) | 1270 if (twin_tiling && twin_tiling->resolution() == NON_IDEAL_RESOLUTION) |
1261 twin->RemoveTiling(to_remove[i]->contents_scale()); | 1271 twin->RemoveTiling(to_remove[i]->contents_scale()); |
1262 // Remove the tiling from the recycle tree. Note that we ignore resolution, | 1272 // Remove the tiling from the recycle tree. Note that we ignore resolution, |
1263 // since we don't need to maintain high/low res on the recycle tree. | 1273 // since we don't need to maintain high/low res on the recycle tree. |
1264 if (recycled_twin) | 1274 if (recycled_twin_layer_) |
1265 recycled_twin->RemoveTiling(to_remove[i]->contents_scale()); | 1275 recycled_twin_layer_->RemoveTiling(to_remove[i]->contents_scale()); |
1266 // TODO(enne): temporary sanity CHECK for http://crbug.com/358350 | 1276 // TODO(enne): temporary sanity CHECK for http://crbug.com/358350 |
1267 CHECK_NE(HIGH_RESOLUTION, to_remove[i]->resolution()); | 1277 CHECK_NE(HIGH_RESOLUTION, to_remove[i]->resolution()); |
1268 tilings_->Remove(to_remove[i]); | 1278 tilings_->Remove(to_remove[i]); |
1269 } | 1279 } |
1270 | 1280 |
1271 DCHECK_GT(tilings_->num_tilings(), 0u); | 1281 DCHECK_GT(tilings_->num_tilings(), 0u); |
1272 SanityCheckTilingState(); | 1282 SanityCheckTilingState(); |
1273 } | 1283 } |
1274 | 1284 |
1275 float PictureLayerImpl::MinimumContentsScale() const { | 1285 float PictureLayerImpl::MinimumContentsScale() const { |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1748 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); | 1758 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); |
1749 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; | 1759 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; |
1750 return tiling_range.end - 1 - current_tiling_range_offset; | 1760 return tiling_range.end - 1 - current_tiling_range_offset; |
1751 } | 1761 } |
1752 } | 1762 } |
1753 NOTREACHED(); | 1763 NOTREACHED(); |
1754 return 0; | 1764 return 0; |
1755 } | 1765 } |
1756 | 1766 |
1757 } // namespace cc | 1767 } // namespace cc |
OLD | NEW |