Chromium Code Reviews| 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 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 104 it != picture_map_.end(); | 106 it != picture_map_.end(); |
| 105 ++it) { | 107 ++it) { |
| 106 const PictureMapKey& key = it->first; | 108 const PictureMapKey& key = it->first; |
| 107 if (key.first < min_toss_x && key.second < min_toss_y) | 109 if (key.first < min_toss_x && key.second < min_toss_y) |
| 108 continue; | 110 continue; |
| 109 to_erase.push_back(key); | 111 to_erase.push_back(key); |
| 110 } | 112 } |
| 111 | 113 |
| 112 for (size_t i = 0; i < to_erase.size(); ++i) | 114 for (size_t i = 0; i < to_erase.size(); ++i) |
| 113 picture_map_.erase(to_erase[i]); | 115 picture_map_.erase(to_erase[i]); |
| 116 | |
| 117 // Don't waste time in Resize figuring out what these hints should be. | |
|
vmpstr
2014/03/12 23:57:35
Is this because Resize is (always?) followed by Up
enne (OOO)
2014/03/13 01:35:43
Well, calculating what the "viewport" here is woul
| |
| 118 recorded_viewport_ = gfx::Rect(); | |
| 119 if (new_size.IsEmpty()) | |
| 120 has_any_recordings_ = false; | |
|
vmpstr
2014/03/12 23:57:35
This one in particular, I think if you add a has_a
enne (OOO)
2014/03/13 01:35:43
Done.
| |
| 114 } | 121 } |
| 115 | 122 |
| 116 void PicturePileBase::SetMinContentsScale(float min_contents_scale) { | 123 void PicturePileBase::SetMinContentsScale(float min_contents_scale) { |
| 117 DCHECK(min_contents_scale); | 124 DCHECK(min_contents_scale); |
| 118 if (min_contents_scale_ == min_contents_scale) | 125 if (min_contents_scale_ == min_contents_scale) |
| 119 return; | 126 return; |
| 120 | 127 |
| 121 // Picture contents are played back scaled. When the final contents scale is | 128 // 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 | 129 // 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 | 130 // to raster one final pixel. To avoid splitting a final pixel across |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 return; | 166 return; |
| 160 | 167 |
| 161 Clear(); | 168 Clear(); |
| 162 tiling_.SetBorderTexels(new_buffer_pixels); | 169 tiling_.SetBorderTexels(new_buffer_pixels); |
| 163 } | 170 } |
| 164 | 171 |
| 165 void PicturePileBase::Clear() { | 172 void PicturePileBase::Clear() { |
| 166 picture_map_.clear(); | 173 picture_map_.clear(); |
| 167 } | 174 } |
| 168 | 175 |
| 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 } | |
| 180 | |
| 181 bool PicturePileBase::HasRecordingAt(int x, int y) { | 176 bool PicturePileBase::HasRecordingAt(int x, int y) { |
| 182 PictureMap::const_iterator found = picture_map_.find(PictureMapKey(x, y)); | 177 PictureMap::const_iterator found = picture_map_.find(PictureMapKey(x, y)); |
| 183 if (found == picture_map_.end()) | 178 if (found == picture_map_.end()) |
| 184 return false; | 179 return false; |
| 185 return !!found->second.GetPicture(); | 180 return !!found->second.GetPicture(); |
| 186 } | 181 } |
| 187 | 182 |
| 188 bool PicturePileBase::CanRaster(float contents_scale, | 183 bool PicturePileBase::CanRaster(float contents_scale, |
| 189 const gfx::Rect& content_rect) { | 184 const gfx::Rect& content_rect) { |
| 190 if (tiling_.total_size().IsEmpty()) | 185 if (tiling_.total_size().IsEmpty()) |
| 191 return false; | 186 return false; |
| 192 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( | 187 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( |
| 193 content_rect, 1.f / contents_scale); | 188 content_rect, 1.f / contents_scale); |
| 194 layer_rect.Intersect(gfx::Rect(tiling_.total_size())); | 189 layer_rect.Intersect(gfx::Rect(tiling_.total_size())); |
| 195 return recorded_region_.Contains(layer_rect); | 190 |
| 191 // Common case inside of viewport to avoid the slower map lookups. | |
| 192 if (recorded_viewport_.Contains(layer_rect)) { | |
| 193 // Sanity check that there are no false positives in recorded_viewport_. | |
| 194 DCHECK(CanRasterSlowTileCheck(layer_rect)); | |
| 195 return true; | |
| 196 } | |
| 197 | |
| 198 return CanRasterSlowTileCheck(layer_rect); | |
| 199 } | |
| 200 | |
| 201 bool PicturePileBase::CanRasterSlowTileCheck( | |
|
vmpstr
2014/03/12 23:57:35
I don't really buy that this function is that slow
enne (OOO)
2014/03/13 01:35:43
PicturePileBase::CanRasterNotAsSlowAsPreviousVersi
vmpstr
2014/03/13 16:30:35
I like it!
| |
| 202 const gfx::Rect& layer_rect) const { | |
| 203 for (TilingData::Iterator tile_iter(&tiling_, layer_rect); tile_iter; | |
| 204 ++tile_iter) { | |
| 205 PictureMap::const_iterator map_iter = picture_map_.find(tile_iter.index()); | |
| 206 if (map_iter == picture_map_.end()) | |
| 207 return false; | |
| 208 if (!map_iter->second.GetPicture()) | |
| 209 return false; | |
| 210 } | |
| 211 return true; | |
| 196 } | 212 } |
| 197 | 213 |
| 198 gfx::Rect PicturePileBase::PaddedRect(const PictureMapKey& key) { | 214 gfx::Rect PicturePileBase::PaddedRect(const PictureMapKey& key) { |
| 199 gfx::Rect tile = tiling_.TileBounds(key.first, key.second); | 215 gfx::Rect tile = tiling_.TileBounds(key.first, key.second); |
| 200 return PadRect(tile); | 216 return PadRect(tile); |
| 201 } | 217 } |
| 202 | 218 |
| 203 gfx::Rect PicturePileBase::PadRect(const gfx::Rect& rect) { | 219 gfx::Rect PicturePileBase::PadRect(const gfx::Rect& rect) { |
| 204 gfx::Rect padded_rect = rect; | 220 gfx::Rect padded_rect = rect; |
| 205 padded_rect.Inset( | 221 padded_rect.Inset( |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 info.picture_ = picture_->GetCloneForDrawingOnThread(thread_index); | 293 info.picture_ = picture_->GetCloneForDrawingOnThread(thread_index); |
| 278 return info; | 294 return info; |
| 279 } | 295 } |
| 280 | 296 |
| 281 float PicturePileBase::PictureInfo::GetInvalidationFrequency() const { | 297 float PicturePileBase::PictureInfo::GetInvalidationFrequency() const { |
| 282 return invalidation_history_.count() / | 298 return invalidation_history_.count() / |
| 283 static_cast<float>(INVALIDATION_FRAMES_TRACKED); | 299 static_cast<float>(INVALIDATION_FRAMES_TRACKED); |
| 284 } | 300 } |
| 285 | 301 |
| 286 } // namespace cc | 302 } // namespace cc |
| OLD | NEW |