 Chromium Code Reviews
 Chromium Code Reviews Issue 196343005:
  cc: Replace recorded region with direct map lookup  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 196343005:
  cc: Replace recorded region with direct map lookup  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| 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 26 matching lines...) Expand all Loading... | |
| 37 } // namespace | 37 } // namespace | 
| 38 | 38 | 
| 39 namespace cc { | 39 namespace cc { | 
| 40 | 40 | 
| 41 PicturePileBase::PicturePileBase() | 41 PicturePileBase::PicturePileBase() | 
| 42 : min_contents_scale_(0), | 42 : min_contents_scale_(0), | 
| 43 background_color_(SkColorSetARGBInline(0, 0, 0, 0)), | 43 background_color_(SkColorSetARGBInline(0, 0, 0, 0)), | 
| 44 slow_down_raster_scale_factor_for_debug_(0), | 44 slow_down_raster_scale_factor_for_debug_(0), | 
| 45 contents_opaque_(false), | 45 contents_opaque_(false), | 
| 46 show_debug_picture_borders_(false), | 46 show_debug_picture_borders_(false), | 
| 47 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting) { | 47 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting), | 
| 48 has_any_recordings_(false) { | |
| 48 tiling_.SetMaxTextureSize(gfx::Size(kBasePictureSize, kBasePictureSize)); | 49 tiling_.SetMaxTextureSize(gfx::Size(kBasePictureSize, kBasePictureSize)); | 
| 49 tile_grid_info_.fTileInterval.setEmpty(); | 50 tile_grid_info_.fTileInterval.setEmpty(); | 
| 50 tile_grid_info_.fMargin.setEmpty(); | 51 tile_grid_info_.fMargin.setEmpty(); | 
| 51 tile_grid_info_.fOffset.setZero(); | 52 tile_grid_info_.fOffset.setZero(); | 
| 52 } | 53 } | 
| 53 | 54 | 
| 54 PicturePileBase::PicturePileBase(const PicturePileBase* other) | 55 PicturePileBase::PicturePileBase(const PicturePileBase* other) | 
| 55 : picture_map_(other->picture_map_), | 56 : picture_map_(other->picture_map_), | 
| 56 tiling_(other->tiling_), | 57 tiling_(other->tiling_), | 
| 57 recorded_region_(other->recorded_region_), | 58 recorded_viewport_(other->recorded_viewport_), | 
| 58 min_contents_scale_(other->min_contents_scale_), | 59 min_contents_scale_(other->min_contents_scale_), | 
| 59 tile_grid_info_(other->tile_grid_info_), | 60 tile_grid_info_(other->tile_grid_info_), | 
| 60 background_color_(other->background_color_), | 61 background_color_(other->background_color_), | 
| 61 slow_down_raster_scale_factor_for_debug_( | 62 slow_down_raster_scale_factor_for_debug_( | 
| 62 other->slow_down_raster_scale_factor_for_debug_), | 63 other->slow_down_raster_scale_factor_for_debug_), | 
| 63 contents_opaque_(other->contents_opaque_), | 64 contents_opaque_(other->contents_opaque_), | 
| 64 show_debug_picture_borders_(other->show_debug_picture_borders_), | 65 show_debug_picture_borders_(other->show_debug_picture_borders_), | 
| 65 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_) { | 66 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), | 
| 66 } | 67 has_any_recordings_(other->has_any_recordings_) {} | 
| 67 | 68 | 
| 68 PicturePileBase::PicturePileBase( | 69 PicturePileBase::PicturePileBase(const PicturePileBase* other, | 
| 69 const PicturePileBase* other, unsigned thread_index) | 70 unsigned thread_index) | 
| 70 : tiling_(other->tiling_), | 71 : tiling_(other->tiling_), | 
| 71 recorded_region_(other->recorded_region_), | 72 recorded_viewport_(other->recorded_viewport_), | 
| 72 min_contents_scale_(other->min_contents_scale_), | 73 min_contents_scale_(other->min_contents_scale_), | 
| 73 tile_grid_info_(other->tile_grid_info_), | 74 tile_grid_info_(other->tile_grid_info_), | 
| 74 background_color_(other->background_color_), | 75 background_color_(other->background_color_), | 
| 75 slow_down_raster_scale_factor_for_debug_( | 76 slow_down_raster_scale_factor_for_debug_( | 
| 76 other->slow_down_raster_scale_factor_for_debug_), | 77 other->slow_down_raster_scale_factor_for_debug_), | 
| 77 contents_opaque_(other->contents_opaque_), | 78 contents_opaque_(other->contents_opaque_), | 
| 78 show_debug_picture_borders_(other->show_debug_picture_borders_), | 79 show_debug_picture_borders_(other->show_debug_picture_borders_), | 
| 79 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_) { | 80 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), | 
| 81 has_any_recordings_(other->has_any_recordings_) { | |
| 80 for (PictureMap::const_iterator it = other->picture_map_.begin(); | 82 for (PictureMap::const_iterator it = other->picture_map_.begin(); | 
| 81 it != other->picture_map_.end(); | 83 it != other->picture_map_.end(); | 
| 82 ++it) { | 84 ++it) { | 
| 83 picture_map_[it->first] = it->second.CloneForThread(thread_index); | 85 picture_map_[it->first] = it->second.CloneForThread(thread_index); | 
| 84 } | 86 } | 
| 85 } | 87 } | 
| 86 | 88 | 
| 87 PicturePileBase::~PicturePileBase() { | 89 PicturePileBase::~PicturePileBase() { | 
| 88 } | 90 } | 
| 89 | 91 | 
| 90 void PicturePileBase::Resize(const gfx::Size& new_size) { | 92 void PicturePileBase::Resize(const gfx::Size& new_size) { | 
| 91 if (size() == new_size) | 93 if (size() == new_size) | 
| 92 return; | 94 return; | 
| 93 | 95 | 
| 94 gfx::Size old_size = size(); | 96 gfx::Size old_size = size(); | 
| 95 tiling_.SetTotalSize(new_size); | 97 tiling_.SetTotalSize(new_size); | 
| 96 | 98 | 
| 99 has_any_recordings_ = false; | |
| 100 | |
| 97 // Find all tiles that contain any pixels outside the new size. | 101 // Find all tiles that contain any pixels outside the new size. | 
| 98 std::vector<PictureMapKey> to_erase; | 102 std::vector<PictureMapKey> to_erase; | 
| 99 int min_toss_x = tiling_.FirstBorderTileXIndexFromSrcCoord( | 103 int min_toss_x = tiling_.FirstBorderTileXIndexFromSrcCoord( | 
| 100 std::min(old_size.width(), new_size.width())); | 104 std::min(old_size.width(), new_size.width())); | 
| 101 int min_toss_y = tiling_.FirstBorderTileYIndexFromSrcCoord( | 105 int min_toss_y = tiling_.FirstBorderTileYIndexFromSrcCoord( | 
| 102 std::min(old_size.height(), new_size.height())); | 106 std::min(old_size.height(), new_size.height())); | 
| 103 for (PictureMap::const_iterator it = picture_map_.begin(); | 107 for (PictureMap::const_iterator it = picture_map_.begin(); | 
| 104 it != picture_map_.end(); | 108 it != picture_map_.end(); | 
| 105 ++it) { | 109 ++it) { | 
| 106 const PictureMapKey& key = it->first; | 110 const PictureMapKey& key = it->first; | 
| 107 if (key.first < min_toss_x && key.second < min_toss_y) | 111 if (key.first < min_toss_x && key.second < min_toss_y) { | 
| 112 has_any_recordings_ |= !!it->second.GetPicture(); | |
| 108 continue; | 113 continue; | 
| 114 } | |
| 109 to_erase.push_back(key); | 115 to_erase.push_back(key); | 
| 110 } | 116 } | 
| 111 | 117 | 
| 112 for (size_t i = 0; i < to_erase.size(); ++i) | 118 for (size_t i = 0; i < to_erase.size(); ++i) | 
| 113 picture_map_.erase(to_erase[i]); | 119 picture_map_.erase(to_erase[i]); | 
| 120 | |
| 121 // Don't waste time in Resize figuring out what these hints should be. | |
| 122 recorded_viewport_ = gfx::Rect(); | |
| 114 } | 123 } | 
| 115 | 124 | 
| 116 void PicturePileBase::SetMinContentsScale(float min_contents_scale) { | 125 void PicturePileBase::SetMinContentsScale(float min_contents_scale) { | 
| 117 DCHECK(min_contents_scale); | 126 DCHECK(min_contents_scale); | 
| 118 if (min_contents_scale_ == min_contents_scale) | 127 if (min_contents_scale_ == min_contents_scale) | 
| 119 return; | 128 return; | 
| 120 | 129 | 
| 121 // Picture contents are played back scaled. When the final contents scale is | 130 // Picture contents are played back scaled. When the final contents scale is | 
| 122 // less than 1 (i.e. low res), then multiple recorded pixels will be used | 131 // less than 1 (i.e. low res), then multiple recorded pixels will be used | 
| 123 // to raster one final pixel. To avoid splitting a final pixel across | 132 // to raster one final pixel. To avoid splitting a final pixel across | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 void PicturePileBase::SetBufferPixels(int new_buffer_pixels) { | 166 void PicturePileBase::SetBufferPixels(int new_buffer_pixels) { | 
| 158 if (new_buffer_pixels == buffer_pixels()) | 167 if (new_buffer_pixels == buffer_pixels()) | 
| 159 return; | 168 return; | 
| 160 | 169 | 
| 161 Clear(); | 170 Clear(); | 
| 162 tiling_.SetBorderTexels(new_buffer_pixels); | 171 tiling_.SetBorderTexels(new_buffer_pixels); | 
| 163 } | 172 } | 
| 164 | 173 | 
| 165 void PicturePileBase::Clear() { | 174 void PicturePileBase::Clear() { | 
| 166 picture_map_.clear(); | 175 picture_map_.clear(); | 
| 167 } | 176 recorded_viewport_ = gfx::Rect(); | 
| 
enne (OOO)
2014/03/18 00:55:20
This isn't part of the bug, but I just noticed it
 
vmpstr
2014/03/18 17:24:54
Good catch.
 | |
| 168 | |
| 169 void PicturePileBase::UpdateRecordedRegion() { | |
| 170 recorded_region_.Clear(); | |
| 171 for (PictureMap::const_iterator it = picture_map_.begin(); | |
| 172 it != picture_map_.end(); | |
| 173 ++it) { | |
| 174 if (it->second.GetPicture()) { | |
| 175 const PictureMapKey& key = it->first; | |
| 176 recorded_region_.Union(tile_bounds(key.first, key.second)); | |
| 177 } | |
| 178 } | |
| 179 } | 177 } | 
| 180 | 178 | 
| 181 bool PicturePileBase::HasRecordingAt(int x, int y) { | 179 bool PicturePileBase::HasRecordingAt(int x, int y) { | 
| 182 PictureMap::const_iterator found = picture_map_.find(PictureMapKey(x, y)); | 180 PictureMap::const_iterator found = picture_map_.find(PictureMapKey(x, y)); | 
| 183 if (found == picture_map_.end()) | 181 if (found == picture_map_.end()) | 
| 184 return false; | 182 return false; | 
| 185 return !!found->second.GetPicture(); | 183 return !!found->second.GetPicture(); | 
| 186 } | 184 } | 
| 187 | 185 | 
| 188 bool PicturePileBase::CanRaster(float contents_scale, | 186 bool PicturePileBase::CanRaster(float contents_scale, | 
| 189 const gfx::Rect& content_rect) { | 187 const gfx::Rect& content_rect) { | 
| 190 if (tiling_.total_size().IsEmpty()) | 188 if (tiling_.total_size().IsEmpty()) | 
| 191 return false; | 189 return false; | 
| 192 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( | 190 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( | 
| 193 content_rect, 1.f / contents_scale); | 191 content_rect, 1.f / contents_scale); | 
| 194 layer_rect.Intersect(gfx::Rect(tiling_.total_size())); | 192 layer_rect.Intersect(gfx::Rect(tiling_.total_size())); | 
| 195 return recorded_region_.Contains(layer_rect); | 193 | 
| 194 // Common case inside of viewport to avoid the slower map lookups. | |
| 195 if (recorded_viewport_.Contains(layer_rect)) { | |
| 196 // Sanity check that there are no false positives in recorded_viewport_. | |
| 197 DCHECK(CanRasterSlowTileCheck(layer_rect)); | |
| 198 return true; | |
| 199 } | |
| 200 | |
| 201 return CanRasterSlowTileCheck(layer_rect); | |
| 202 } | |
| 203 | |
| 204 bool PicturePileBase::CanRasterSlowTileCheck( | |
| 205 const gfx::Rect& layer_rect) const { | |
| 206 bool include_borders = false; | |
| 
enne (OOO)
2014/03/18 00:55:20
This is the other half of the bugfix.  Later on wh
 | |
| 207 for (TilingData::Iterator tile_iter(&tiling_, layer_rect, include_borders); | |
| 208 tile_iter; | |
| 209 ++tile_iter) { | |
| 210 PictureMap::const_iterator map_iter = picture_map_.find(tile_iter.index()); | |
| 211 if (map_iter == picture_map_.end()) | |
| 212 return false; | |
| 213 if (!map_iter->second.GetPicture()) | |
| 214 return false; | |
| 215 } | |
| 216 return true; | |
| 196 } | 217 } | 
| 197 | 218 | 
| 198 gfx::Rect PicturePileBase::PaddedRect(const PictureMapKey& key) { | 219 gfx::Rect PicturePileBase::PaddedRect(const PictureMapKey& key) { | 
| 199 gfx::Rect tile = tiling_.TileBounds(key.first, key.second); | 220 gfx::Rect tile = tiling_.TileBounds(key.first, key.second); | 
| 200 return PadRect(tile); | 221 return PadRect(tile); | 
| 201 } | 222 } | 
| 202 | 223 | 
| 203 gfx::Rect PicturePileBase::PadRect(const gfx::Rect& rect) { | 224 gfx::Rect PicturePileBase::PadRect(const gfx::Rect& rect) { | 
| 204 gfx::Rect padded_rect = rect; | 225 gfx::Rect padded_rect = rect; | 
| 205 padded_rect.Inset( | 226 padded_rect.Inset( | 
| 206 -buffer_pixels(), -buffer_pixels(), -buffer_pixels(), -buffer_pixels()); | 227 -buffer_pixels(), -buffer_pixels(), -buffer_pixels(), -buffer_pixels()); | 
| 207 return padded_rect; | 228 return padded_rect; | 
| 208 } | 229 } | 
| 209 | 230 | 
| 210 scoped_ptr<base::Value> PicturePileBase::AsValue() const { | 231 scoped_ptr<base::Value> PicturePileBase::AsValue() const { | 
| 211 scoped_ptr<base::ListValue> pictures(new base::ListValue()); | 232 scoped_ptr<base::ListValue> pictures(new base::ListValue()); | 
| 212 gfx::Rect layer_rect(tiling_.total_size()); | 233 gfx::Rect layer_rect(tiling_.total_size()); | 
| 213 std::set<void*> appended_pictures; | 234 std::set<void*> appended_pictures; | 
| 214 for (TilingData::Iterator tile_iter(&tiling_, layer_rect); | 235 bool include_borders = true; | 
| 215 tile_iter; ++tile_iter) { | 236 for (TilingData::Iterator tile_iter(&tiling_, layer_rect, include_borders); | 
| 237 tile_iter; | |
| 238 ++tile_iter) { | |
| 216 PictureMap::const_iterator map_iter = picture_map_.find(tile_iter.index()); | 239 PictureMap::const_iterator map_iter = picture_map_.find(tile_iter.index()); | 
| 217 if (map_iter == picture_map_.end()) | 240 if (map_iter == picture_map_.end()) | 
| 218 continue; | 241 continue; | 
| 219 | 242 | 
| 220 Picture* picture = map_iter->second.GetPicture(); | 243 Picture* picture = map_iter->second.GetPicture(); | 
| 221 if (picture && (appended_pictures.count(picture) == 0)) { | 244 if (picture && (appended_pictures.count(picture) == 0)) { | 
| 222 appended_pictures.insert(picture); | 245 appended_pictures.insert(picture); | 
| 223 pictures->Append(TracedValue::CreateIDRef(picture).release()); | 246 pictures->Append(TracedValue::CreateIDRef(picture).release()); | 
| 224 } | 247 } | 
| 225 } | 248 } | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 info.picture_ = picture_->GetCloneForDrawingOnThread(thread_index); | 300 info.picture_ = picture_->GetCloneForDrawingOnThread(thread_index); | 
| 278 return info; | 301 return info; | 
| 279 } | 302 } | 
| 280 | 303 | 
| 281 float PicturePileBase::PictureInfo::GetInvalidationFrequency() const { | 304 float PicturePileBase::PictureInfo::GetInvalidationFrequency() const { | 
| 282 return invalidation_history_.count() / | 305 return invalidation_history_.count() / | 
| 283 static_cast<float>(INVALIDATION_FRAMES_TRACKED); | 306 static_cast<float>(INVALIDATION_FRAMES_TRACKED); | 
| 284 } | 307 } | 
| 285 | 308 | 
| 286 } // namespace cc | 309 } // namespace cc | 
| OLD | NEW |