Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: cc/resources/picture_pile_base.cc

Issue 235753002: cc: Give TilingData a Rect instead of a Size (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/resources/picture_pile_base.h" 5 #include "cc/resources/picture_pile_base.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 for (PictureMap::const_iterator it = other->picture_map_.begin(); 85 for (PictureMap::const_iterator it = other->picture_map_.begin();
86 it != other->picture_map_.end(); 86 it != other->picture_map_.end();
87 ++it) { 87 ++it) {
88 picture_map_[it->first] = it->second.CloneForThread(thread_index); 88 picture_map_[it->first] = it->second.CloneForThread(thread_index);
89 } 89 }
90 } 90 }
91 91
92 PicturePileBase::~PicturePileBase() { 92 PicturePileBase::~PicturePileBase() {
93 } 93 }
94 94
95 void PicturePileBase::Resize(const gfx::Size& new_size) { 95 void PicturePileBase::SetTilingRect(const gfx::Rect& new_tiling_rect) {
96 if (size() == new_size) 96 if (tiling_rect() == new_tiling_rect)
97 return; 97 return;
98 98
99 gfx::Size old_size = size(); 99 gfx::Rect old_tiling_rect = tiling_rect();
100 tiling_.SetTotalSize(new_size); 100 tiling_.SetTilingRect(new_tiling_rect);
101 101
102 has_any_recordings_ = false; 102 has_any_recordings_ = false;
103 103
104 // Find all tiles that contain any pixels outside the new size. 104 if (new_tiling_rect.x() == old_tiling_rect.x() &&
enne (OOO) 2014/04/11 20:19:51 This could be said more simply as new_tiling_rect.
ernstm 2014/04/11 23:43:51 Done.
105 std::vector<PictureMapKey> to_erase; 105 new_tiling_rect.y() == old_tiling_rect.y()) {
106 int min_toss_x = tiling_.FirstBorderTileXIndexFromSrcCoord( 106 // Find all tiles that contain any pixels outside the new rect.
107 std::min(old_size.width(), new_size.width())); 107 std::vector<PictureMapKey> to_erase;
108 int min_toss_y = tiling_.FirstBorderTileYIndexFromSrcCoord( 108 int min_toss_x = tiling_.FirstBorderTileXIndexFromSrcCoord(
109 std::min(old_size.height(), new_size.height())); 109 std::min(old_tiling_rect.width(), new_tiling_rect.width()));
enne (OOO) 2014/04/11 20:19:51 correctness: I think width/height should be right/
ernstm 2014/04/11 23:43:51 Done.
110 for (PictureMap::const_iterator it = picture_map_.begin(); 110 int min_toss_y = tiling_.FirstBorderTileYIndexFromSrcCoord(
111 it != picture_map_.end(); 111 std::min(old_tiling_rect.height(), new_tiling_rect.height()));
112 ++it) { 112 for (PictureMap::const_iterator it = picture_map_.begin();
113 const PictureMapKey& key = it->first; 113 it != picture_map_.end();
114 if (key.first < min_toss_x && key.second < min_toss_y) { 114 ++it) {
115 has_any_recordings_ |= !!it->second.GetPicture(); 115 const PictureMapKey& key = it->first;
116 continue; 116 if (key.first < min_toss_x && key.second < min_toss_y) {
117 has_any_recordings_ |= !!it->second.GetPicture();
118 continue;
119 }
120 to_erase.push_back(key);
117 } 121 }
118 to_erase.push_back(key); 122
123 for (size_t i = 0; i < to_erase.size(); ++i)
124 picture_map_.erase(to_erase[i]);
125 } else {
126 picture_map_.clear();
enne (OOO) 2014/04/11 20:19:51 style nit: this else clause is far away from its i
ernstm 2014/04/11 23:43:51 Done. I had to move the recorded_viewport_ = gfx::
119 } 127 }
120 128
121 for (size_t i = 0; i < to_erase.size(); ++i)
122 picture_map_.erase(to_erase[i]);
123
124 // Don't waste time in Resize figuring out what these hints should be. 129 // Don't waste time in Resize figuring out what these hints should be.
125 recorded_viewport_ = gfx::Rect(); 130 recorded_viewport_ = gfx::Rect();
126 } 131 }
127 132
128 void PicturePileBase::SetMinContentsScale(float min_contents_scale) { 133 void PicturePileBase::SetMinContentsScale(float min_contents_scale) {
129 DCHECK(min_contents_scale); 134 DCHECK(min_contents_scale);
130 if (min_contents_scale_ == min_contents_scale) 135 if (min_contents_scale_ == min_contents_scale)
131 return; 136 return;
132 137
133 // Picture contents are played back scaled. When the final contents scale is 138 // Picture contents are played back scaled. When the final contents scale is
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 186
182 bool PicturePileBase::HasRecordingAt(int x, int y) { 187 bool PicturePileBase::HasRecordingAt(int x, int y) {
183 PictureMap::const_iterator found = picture_map_.find(PictureMapKey(x, y)); 188 PictureMap::const_iterator found = picture_map_.find(PictureMapKey(x, y));
184 if (found == picture_map_.end()) 189 if (found == picture_map_.end())
185 return false; 190 return false;
186 return !!found->second.GetPicture(); 191 return !!found->second.GetPicture();
187 } 192 }
188 193
189 bool PicturePileBase::CanRaster(float contents_scale, 194 bool PicturePileBase::CanRaster(float contents_scale,
190 const gfx::Rect& content_rect) { 195 const gfx::Rect& content_rect) {
191 if (tiling_.total_size().IsEmpty()) 196 if (tiling_.tiling_rect().IsEmpty())
192 return false; 197 return false;
193 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( 198 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect(
194 content_rect, 1.f / contents_scale); 199 content_rect, 1.f / contents_scale);
195 layer_rect.Intersect(gfx::Rect(tiling_.total_size())); 200 layer_rect.Intersect(tiling_.tiling_rect());
196 201
197 // Common case inside of viewport to avoid the slower map lookups. 202 // Common case inside of viewport to avoid the slower map lookups.
198 if (recorded_viewport_.Contains(layer_rect)) { 203 if (recorded_viewport_.Contains(layer_rect)) {
199 // Sanity check that there are no false positives in recorded_viewport_. 204 // Sanity check that there are no false positives in recorded_viewport_.
200 DCHECK(CanRasterSlowTileCheck(layer_rect)); 205 DCHECK(CanRasterSlowTileCheck(layer_rect));
201 return true; 206 return true;
202 } 207 }
203 208
204 return CanRasterSlowTileCheck(layer_rect); 209 return CanRasterSlowTileCheck(layer_rect);
205 } 210 }
(...skipping 20 matching lines...) Expand all
226 231
227 gfx::Rect PicturePileBase::PadRect(const gfx::Rect& rect) { 232 gfx::Rect PicturePileBase::PadRect(const gfx::Rect& rect) {
228 gfx::Rect padded_rect = rect; 233 gfx::Rect padded_rect = rect;
229 padded_rect.Inset( 234 padded_rect.Inset(
230 -buffer_pixels(), -buffer_pixels(), -buffer_pixels(), -buffer_pixels()); 235 -buffer_pixels(), -buffer_pixels(), -buffer_pixels(), -buffer_pixels());
231 return padded_rect; 236 return padded_rect;
232 } 237 }
233 238
234 scoped_ptr<base::Value> PicturePileBase::AsValue() const { 239 scoped_ptr<base::Value> PicturePileBase::AsValue() const {
235 scoped_ptr<base::ListValue> pictures(new base::ListValue()); 240 scoped_ptr<base::ListValue> pictures(new base::ListValue());
236 gfx::Rect layer_rect(tiling_.total_size()); 241 gfx::Rect tiling_rect(tiling_.tiling_rect());
237 std::set<void*> appended_pictures; 242 std::set<void*> appended_pictures;
238 bool include_borders = true; 243 bool include_borders = true;
239 for (TilingData::Iterator tile_iter(&tiling_, layer_rect, include_borders); 244 for (TilingData::Iterator tile_iter(&tiling_, tiling_rect, include_borders);
240 tile_iter; 245 tile_iter;
241 ++tile_iter) { 246 ++tile_iter) {
242 PictureMap::const_iterator map_iter = picture_map_.find(tile_iter.index()); 247 PictureMap::const_iterator map_iter = picture_map_.find(tile_iter.index());
243 if (map_iter == picture_map_.end()) 248 if (map_iter == picture_map_.end())
244 continue; 249 continue;
245 250
246 Picture* picture = map_iter->second.GetPicture(); 251 Picture* picture = map_iter->second.GetPicture();
247 if (picture && (appended_pictures.count(picture) == 0)) { 252 if (picture && (appended_pictures.count(picture) == 0)) {
248 appended_pictures.insert(picture); 253 appended_pictures.insert(picture);
249 pictures->Append(TracedValue::CreateIDRef(picture).release()); 254 pictures->Append(TracedValue::CreateIDRef(picture).release());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 info.picture_ = picture_->GetCloneForDrawingOnThread(thread_index); 308 info.picture_ = picture_->GetCloneForDrawingOnThread(thread_index);
304 return info; 309 return info;
305 } 310 }
306 311
307 float PicturePileBase::PictureInfo::GetInvalidationFrequency() const { 312 float PicturePileBase::PictureInfo::GetInvalidationFrequency() const {
308 return invalidation_history_.count() / 313 return invalidation_history_.count() /
309 static_cast<float>(INVALIDATION_FRAMES_TRACKED); 314 static_cast<float>(INVALIDATION_FRAMES_TRACKED);
310 } 315 }
311 316
312 } // namespace cc 317 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698