Chromium Code Reviews| 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/picture_layer_tiling_set.h" | 5 #include "cc/picture_layer_tiling_set.h" |
| 6 | 6 |
| 7 namespace cc { | 7 namespace cc { |
| 8 | 8 |
| 9 namespace { | |
| 10 | |
| 11 class LargestToSmallestScaleFunctor { | |
| 12 public: | |
| 13 bool operator() (PictureLayerTiling* left, PictureLayerTiling* right) { | |
| 14 return left->contents_scale() > right->contents_scale(); | |
| 15 } | |
| 16 }; | |
| 17 | |
| 18 } // namespace | |
| 19 | |
| 20 | |
| 9 PictureLayerTilingSet::PictureLayerTilingSet( | 21 PictureLayerTilingSet::PictureLayerTilingSet( |
| 10 PictureLayerTilingClient * client) | 22 PictureLayerTilingClient * client) |
| 11 : client_(client) { | 23 : client_(client) { |
| 12 } | 24 } |
| 13 | 25 |
| 14 PictureLayerTilingSet::~PictureLayerTilingSet() { | 26 PictureLayerTilingSet::~PictureLayerTilingSet() { |
| 15 } | 27 } |
| 16 | 28 |
| 17 void PictureLayerTilingSet::CloneAll( | 29 void PictureLayerTilingSet::CloneAll( |
| 18 const PictureLayerTilingSet& other, | 30 const PictureLayerTilingSet& other, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 30 void PictureLayerTilingSet::Clone( | 42 void PictureLayerTilingSet::Clone( |
| 31 const PictureLayerTiling* tiling, | 43 const PictureLayerTiling* tiling, |
| 32 const Region& invalidation) { | 44 const Region& invalidation) { |
| 33 | 45 |
| 34 for (size_t i = 0; i < tilings_.size(); ++i) | 46 for (size_t i = 0; i < tilings_.size(); ++i) |
| 35 DCHECK_NE(tilings_[i]->contents_scale(), tiling->contents_scale()); | 47 DCHECK_NE(tilings_[i]->contents_scale(), tiling->contents_scale()); |
| 36 | 48 |
| 37 tilings_.append(tiling->Clone()); | 49 tilings_.append(tiling->Clone()); |
| 38 tilings_.last()->SetClient(client_); | 50 tilings_.last()->SetClient(client_); |
| 39 tilings_.last()->Invalidate(invalidation); | 51 tilings_.last()->Invalidate(invalidation); |
| 52 | |
| 53 sort(tilings_.begin(), tilings_.end(), LargestToSmallestScaleFunctor()); | |
| 40 } | 54 } |
| 41 | 55 |
| 42 void PictureLayerTilingSet::SetLayerBounds(gfx::Size layer_bounds) { | 56 void PictureLayerTilingSet::SetLayerBounds(gfx::Size layer_bounds) { |
| 43 if (layer_bounds_ == layer_bounds) | 57 if (layer_bounds_ == layer_bounds) |
| 44 return; | 58 return; |
| 45 layer_bounds_ = layer_bounds; | 59 layer_bounds_ = layer_bounds; |
| 46 for (size_t i = 0; i < tilings_.size(); ++i) | 60 for (size_t i = 0; i < tilings_.size(); ++i) |
| 47 tilings_[i]->SetLayerBounds(layer_bounds); | 61 tilings_[i]->SetLayerBounds(layer_bounds); |
| 48 } | 62 } |
| 49 | 63 |
| 50 gfx::Size PictureLayerTilingSet::LayerBounds() const { | 64 gfx::Size PictureLayerTilingSet::LayerBounds() const { |
| 51 return layer_bounds_; | 65 return layer_bounds_; |
| 52 } | 66 } |
| 53 | 67 |
| 54 const PictureLayerTiling* PictureLayerTilingSet::AddTiling( | 68 PictureLayerTiling* PictureLayerTilingSet::AddTiling( |
| 55 float contents_scale, | 69 float contents_scale, |
| 56 gfx::Size tile_size) { | 70 gfx::Size tile_size) { |
| 57 tilings_.append(PictureLayerTiling::Create(contents_scale, tile_size)); | 71 tilings_.append(PictureLayerTiling::Create(contents_scale, tile_size)); |
| 58 tilings_.last()->SetClient(client_); | 72 PictureLayerTiling* appended = tilings_.last(); |
| 59 tilings_.last()->SetLayerBounds(layer_bounds_); | 73 appended->SetClient(client_); |
| 60 return tilings_.last(); | 74 appended->SetLayerBounds(layer_bounds_); |
| 75 | |
| 76 sort(tilings_.begin(), tilings_.end(), LargestToSmallestScaleFunctor()); | |
| 77 return appended; | |
| 78 } | |
| 79 | |
| 80 void PictureLayerTilingSet::RemoveAll() { | |
| 81 tilings_.clear(); | |
| 82 } | |
| 83 | |
| 84 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { | |
| 85 for (size_t i = 0; i < tilings_.size(); ++i) { | |
|
danakj
2013/01/07 22:35:56
did you consider the erase(std::remove_if()) parad
enne (OOO)
2013/01/08 01:08:00
I feel like remove_if only makes sense if you have
danakj
2013/01/08 23:27:16
Ah, ok good point.
| |
| 86 if (tilings_[i] == tiling) { | |
| 87 tilings_.remove(i); | |
| 88 return; | |
| 89 } | |
| 90 } | |
| 61 } | 91 } |
| 62 | 92 |
| 63 void PictureLayerTilingSet::Reset() { | 93 void PictureLayerTilingSet::Reset() { |
| 64 for (size_t i = 0; i < tilings_.size(); ++i) | 94 for (size_t i = 0; i < tilings_.size(); ++i) |
| 65 tilings_[i]->Reset(); | 95 tilings_[i]->Reset(); |
| 66 } | 96 } |
| 67 | 97 |
| 68 PictureLayerTilingSet::Iterator::Iterator(const PictureLayerTilingSet* set, | 98 PictureLayerTilingSet::Iterator::Iterator( |
| 69 float contents_scale, | 99 const PictureLayerTilingSet* set, |
| 70 gfx::Rect content_rect) | 100 float contents_scale, |
| 101 gfx::Rect content_rect, | |
| 102 float ideal_contents_scale) | |
| 71 : set_(set), | 103 : set_(set), |
| 72 contents_scale_(contents_scale), | 104 contents_scale_(contents_scale), |
| 105 ideal_contents_scale_(ideal_contents_scale), | |
| 73 current_tiling_(-1) { | 106 current_tiling_(-1) { |
| 74 missing_region_.Union(content_rect); | 107 missing_region_.Union(content_rect); |
| 108 | |
| 109 for (ideal_tiling_ = 0; | |
|
danakj
2013/01/07 22:35:56
can the set ever have 0 tilings? Is it okay for id
enne (OOO)
2013/01/08 01:08:00
Yeah, it can, but this works out. If ideal_tiling
| |
| 110 ideal_tiling_ < set_->tilings_.size(); | |
| 111 ++ideal_tiling_) { | |
| 112 PictureLayerTiling* tiling = set_->tilings_[ideal_tiling_]; | |
| 113 if (tiling->contents_scale() < ideal_contents_scale_) { | |
| 114 if (ideal_tiling_ > 0) | |
| 115 ideal_tiling_--; | |
|
danakj
2013/01/07 22:35:56
this seems less "ideal" and more "best" ? should w
enne (OOO)
2013/01/08 01:08:00
The ideal tiling here is just the tiling that is c
danakj
2013/01/08 23:27:16
I felt like ideal is used elsewhere to refer to th
| |
| 116 break; | |
| 117 } | |
| 118 } | |
| 119 | |
| 75 ++(*this); | 120 ++(*this); |
| 76 } | 121 } |
| 77 | 122 |
| 78 PictureLayerTilingSet::Iterator::~Iterator() { | 123 PictureLayerTilingSet::Iterator::~Iterator() { |
| 79 } | 124 } |
| 80 | 125 |
| 81 gfx::Rect PictureLayerTilingSet::Iterator::geometry_rect() const { | 126 gfx::Rect PictureLayerTilingSet::Iterator::geometry_rect() const { |
| 82 if (!tiling_iter_) { | 127 if (!tiling_iter_) { |
| 83 if (!region_iter_.has_rect()) | 128 if (!region_iter_.has_rect()) |
| 84 return gfx::Rect(); | 129 return gfx::Rect(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 104 return NULL; | 149 return NULL; |
| 105 return *tiling_iter_; | 150 return *tiling_iter_; |
| 106 } | 151 } |
| 107 | 152 |
| 108 Tile* PictureLayerTilingSet::Iterator::operator*() const { | 153 Tile* PictureLayerTilingSet::Iterator::operator*() const { |
| 109 if (!tiling_iter_) | 154 if (!tiling_iter_) |
| 110 return NULL; | 155 return NULL; |
| 111 return *tiling_iter_; | 156 return *tiling_iter_; |
| 112 } | 157 } |
| 113 | 158 |
| 159 PictureLayerTiling* PictureLayerTilingSet::Iterator::CurrentTiling() { | |
| 160 if (current_tiling_ < 0 || current_tiling_ >= set_->tilings_.size()) | |
| 161 return NULL; | |
| 162 return set_->tilings_[current_tiling_]; | |
| 163 } | |
| 164 | |
| 165 int PictureLayerTilingSet::Iterator::NextTiling() const { | |
| 166 // Prefer hi-res tiles, but prefer the least hi-res if bigger than ideal, | |
|
danakj
2013/01/08 23:27:16
I'm still not sure what "prefer the least hi-res i
enne (OOO)
2013/01/08 23:54:38
Done.
| |
| 167 // since it won't add any additional fidelity on screen. | |
| 168 if (current_tiling_ < 0) | |
| 169 return ideal_tiling_; | |
| 170 else if (current_tiling_ > ideal_tiling_) | |
| 171 return current_tiling_ + 1; | |
| 172 else | |
|
danakj
2013/01/07 22:35:56
would "else if (current_tiling_) ... else ..." mak
enne (OOO)
2013/01/08 01:08:00
Done.
| |
| 173 return current_tiling_ ? current_tiling_ - 1 : ideal_tiling_ + 1; | |
| 174 } | |
| 175 | |
| 114 PictureLayerTilingSet::Iterator& PictureLayerTilingSet::Iterator::operator++() { | 176 PictureLayerTilingSet::Iterator& PictureLayerTilingSet::Iterator::operator++() { |
| 115 bool first_time = current_tiling_ < 0; | 177 bool first_time = current_tiling_ < 0; |
| 116 | 178 |
| 117 if (!*this && !first_time) | 179 if (!*this && !first_time) |
| 118 return *this; | 180 return *this; |
| 119 | 181 |
| 120 if (tiling_iter_) | 182 if (tiling_iter_) |
| 121 ++tiling_iter_; | 183 ++tiling_iter_; |
| 122 | 184 |
| 123 // Loop until we find a valid place to stop. | 185 // Loop until we find a valid place to stop. |
| 124 while (true) { | 186 while (true) { |
| 125 while (tiling_iter_ && (!*tiling_iter_ || !tiling_iter_->GetResourceId())) { | 187 while (tiling_iter_ && (!*tiling_iter_ || !tiling_iter_->GetResourceId())) { |
| 126 missing_region_.Union(tiling_iter_.geometry_rect()); | 188 missing_region_.Union(tiling_iter_.geometry_rect()); |
| 127 ++tiling_iter_; | 189 ++tiling_iter_; |
| 128 } | 190 } |
| 129 if (tiling_iter_) | 191 if (tiling_iter_) |
| 130 return *this; | 192 return *this; |
| 131 | 193 |
| 132 // If the set of current rects for this tiling is done, go to the next | 194 // If the set of current rects for this tiling is done, go to the next |
| 133 // tiling and set up to iterate through all of the remaining holes. | 195 // tiling and set up to iterate through all of the remaining holes. |
| 134 // This will also happen the first time through the loop. | 196 // This will also happen the first time through the loop. |
| 135 if (!region_iter_.has_rect()) { | 197 if (!region_iter_.has_rect()) { |
| 136 current_tiling_++; | 198 current_tiling_ = NextTiling(); |
| 137 current_region_.Swap(missing_region_); | 199 current_region_.Swap(missing_region_); |
| 138 missing_region_.Clear(); | 200 missing_region_.Clear(); |
| 139 region_iter_ = Region::Iterator(current_region_); | 201 region_iter_ = Region::Iterator(current_region_); |
| 140 | 202 |
| 141 // All done and all filled. | 203 // All done and all filled. |
| 142 if (!region_iter_.has_rect()) { | 204 if (!region_iter_.has_rect()) { |
| 143 current_tiling_ = set_->tilings_.size(); | 205 current_tiling_ = set_->tilings_.size(); |
| 144 return *this; | 206 return *this; |
| 145 } | 207 } |
| 146 | 208 |
| 147 // No more valid tiles, return this checkerboard rect. | 209 // No more valid tiles, return this checkerboard rect. |
| 148 if (current_tiling_ >= static_cast<int>(set_->tilings_.size())) | 210 if (current_tiling_ >= static_cast<int>(set_->tilings_.size())) |
|
danakj
2013/01/07 22:35:56
Does this still happen now? Seems like NextTiling(
enne (OOO)
2013/01/08 01:08:00
Yes, this case is definitely still hit. This will
| |
| 149 return *this; | 211 return *this; |
| 150 } | 212 } |
| 151 | 213 |
| 152 // Pop a rect off. If there are no more tilings, then these will be | 214 // Pop a rect off. If there are no more tilings, then these will be |
| 153 // treated as geometry with null tiles that the caller can checkerboard. | 215 // treated as geometry with null tiles that the caller can checkerboard. |
| 154 gfx::Rect last_rect = region_iter_.rect(); | 216 gfx::Rect last_rect = region_iter_.rect(); |
| 155 region_iter_.next(); | 217 region_iter_.next(); |
| 156 | 218 |
| 157 // Done, found next checkerboard rect to return. | 219 // Done, found next checkerboard rect to return. |
| 158 if (current_tiling_ >= static_cast<int>(set_->tilings_.size())) | 220 if (current_tiling_ >= static_cast<int>(set_->tilings_.size())) |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 188 device_viewport, | 250 device_viewport, |
| 189 layer_content_scale_x, | 251 layer_content_scale_x, |
| 190 layer_content_scale_y, | 252 layer_content_scale_y, |
| 191 last_screen_transform, | 253 last_screen_transform, |
| 192 current_screen_transform, | 254 current_screen_transform, |
| 193 time_delta); | 255 time_delta); |
| 194 } | 256 } |
| 195 } | 257 } |
| 196 | 258 |
| 197 } // namespace cc | 259 } // namespace cc |
| OLD | NEW |