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) { | |
49 tiling_.SetMaxTextureSize(gfx::Size(kBasePictureSize, kBasePictureSize)); | 48 tiling_.SetMaxTextureSize(gfx::Size(kBasePictureSize, kBasePictureSize)); |
50 tile_grid_info_.fTileInterval.setEmpty(); | 49 tile_grid_info_.fTileInterval.setEmpty(); |
51 tile_grid_info_.fMargin.setEmpty(); | 50 tile_grid_info_.fMargin.setEmpty(); |
52 tile_grid_info_.fOffset.setZero(); | 51 tile_grid_info_.fOffset.setZero(); |
53 } | 52 } |
54 | 53 |
55 PicturePileBase::PicturePileBase(const PicturePileBase* other) | 54 PicturePileBase::PicturePileBase(const PicturePileBase* other) |
56 : picture_map_(other->picture_map_), | 55 : picture_map_(other->picture_map_), |
57 tiling_(other->tiling_), | 56 tiling_(other->tiling_), |
58 recorded_viewport_(other->recorded_viewport_), | 57 recorded_region_(other->recorded_region_), |
59 min_contents_scale_(other->min_contents_scale_), | 58 min_contents_scale_(other->min_contents_scale_), |
60 tile_grid_info_(other->tile_grid_info_), | 59 tile_grid_info_(other->tile_grid_info_), |
61 background_color_(other->background_color_), | 60 background_color_(other->background_color_), |
62 slow_down_raster_scale_factor_for_debug_( | 61 slow_down_raster_scale_factor_for_debug_( |
63 other->slow_down_raster_scale_factor_for_debug_), | 62 other->slow_down_raster_scale_factor_for_debug_), |
64 contents_opaque_(other->contents_opaque_), | 63 contents_opaque_(other->contents_opaque_), |
65 show_debug_picture_borders_(other->show_debug_picture_borders_), | 64 show_debug_picture_borders_(other->show_debug_picture_borders_), |
66 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), | 65 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_) { |
67 has_any_recordings_(other->has_any_recordings_) {} | 66 } |
68 | 67 |
69 PicturePileBase::PicturePileBase(const PicturePileBase* other, | 68 PicturePileBase::PicturePileBase( |
70 unsigned thread_index) | 69 const PicturePileBase* other, unsigned thread_index) |
71 : tiling_(other->tiling_), | 70 : tiling_(other->tiling_), |
72 recorded_viewport_(other->recorded_viewport_), | 71 recorded_region_(other->recorded_region_), |
73 min_contents_scale_(other->min_contents_scale_), | 72 min_contents_scale_(other->min_contents_scale_), |
74 tile_grid_info_(other->tile_grid_info_), | 73 tile_grid_info_(other->tile_grid_info_), |
75 background_color_(other->background_color_), | 74 background_color_(other->background_color_), |
76 slow_down_raster_scale_factor_for_debug_( | 75 slow_down_raster_scale_factor_for_debug_( |
77 other->slow_down_raster_scale_factor_for_debug_), | 76 other->slow_down_raster_scale_factor_for_debug_), |
78 contents_opaque_(other->contents_opaque_), | 77 contents_opaque_(other->contents_opaque_), |
79 show_debug_picture_borders_(other->show_debug_picture_borders_), | 78 show_debug_picture_borders_(other->show_debug_picture_borders_), |
80 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), | 79 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_) { |
81 has_any_recordings_(other->has_any_recordings_) { | |
82 for (PictureMap::const_iterator it = other->picture_map_.begin(); | 80 for (PictureMap::const_iterator it = other->picture_map_.begin(); |
83 it != other->picture_map_.end(); | 81 it != other->picture_map_.end(); |
84 ++it) { | 82 ++it) { |
85 picture_map_[it->first] = it->second.CloneForThread(thread_index); | 83 picture_map_[it->first] = it->second.CloneForThread(thread_index); |
86 } | 84 } |
87 } | 85 } |
88 | 86 |
89 PicturePileBase::~PicturePileBase() { | 87 PicturePileBase::~PicturePileBase() { |
90 } | 88 } |
91 | 89 |
92 void PicturePileBase::Resize(const gfx::Size& new_size) { | 90 void PicturePileBase::Resize(const gfx::Size& new_size) { |
93 if (size() == new_size) | 91 if (size() == new_size) |
94 return; | 92 return; |
95 | 93 |
96 gfx::Size old_size = size(); | 94 gfx::Size old_size = size(); |
97 tiling_.SetTotalSize(new_size); | 95 tiling_.SetTotalSize(new_size); |
98 | 96 |
99 has_any_recordings_ = false; | |
100 | |
101 // Find all tiles that contain any pixels outside the new size. | 97 // Find all tiles that contain any pixels outside the new size. |
102 std::vector<PictureMapKey> to_erase; | 98 std::vector<PictureMapKey> to_erase; |
103 int min_toss_x = tiling_.FirstBorderTileXIndexFromSrcCoord( | 99 int min_toss_x = tiling_.FirstBorderTileXIndexFromSrcCoord( |
104 std::min(old_size.width(), new_size.width())); | 100 std::min(old_size.width(), new_size.width())); |
105 int min_toss_y = tiling_.FirstBorderTileYIndexFromSrcCoord( | 101 int min_toss_y = tiling_.FirstBorderTileYIndexFromSrcCoord( |
106 std::min(old_size.height(), new_size.height())); | 102 std::min(old_size.height(), new_size.height())); |
107 for (PictureMap::const_iterator it = picture_map_.begin(); | 103 for (PictureMap::const_iterator it = picture_map_.begin(); |
108 it != picture_map_.end(); | 104 it != picture_map_.end(); |
109 ++it) { | 105 ++it) { |
110 const PictureMapKey& key = it->first; | 106 const PictureMapKey& key = it->first; |
111 if (key.first < min_toss_x && key.second < min_toss_y) { | 107 if (key.first < min_toss_x && key.second < min_toss_y) |
112 has_any_recordings_ |= !!it->second.GetPicture(); | |
113 continue; | 108 continue; |
114 } | |
115 to_erase.push_back(key); | 109 to_erase.push_back(key); |
116 } | 110 } |
117 | 111 |
118 for (size_t i = 0; i < to_erase.size(); ++i) | 112 for (size_t i = 0; i < to_erase.size(); ++i) |
119 picture_map_.erase(to_erase[i]); | 113 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(); | |
123 } | 114 } |
124 | 115 |
125 void PicturePileBase::SetMinContentsScale(float min_contents_scale) { | 116 void PicturePileBase::SetMinContentsScale(float min_contents_scale) { |
126 DCHECK(min_contents_scale); | 117 DCHECK(min_contents_scale); |
127 if (min_contents_scale_ == min_contents_scale) | 118 if (min_contents_scale_ == min_contents_scale) |
128 return; | 119 return; |
129 | 120 |
130 // Picture contents are played back scaled. When the final contents scale is | 121 // Picture contents are played back scaled. When the final contents scale is |
131 // less than 1 (i.e. low res), then multiple recorded pixels will be used | 122 // less than 1 (i.e. low res), then multiple recorded pixels will be used |
132 // to raster one final pixel. To avoid splitting a final pixel across | 123 // 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... |
168 return; | 159 return; |
169 | 160 |
170 Clear(); | 161 Clear(); |
171 tiling_.SetBorderTexels(new_buffer_pixels); | 162 tiling_.SetBorderTexels(new_buffer_pixels); |
172 } | 163 } |
173 | 164 |
174 void PicturePileBase::Clear() { | 165 void PicturePileBase::Clear() { |
175 picture_map_.clear(); | 166 picture_map_.clear(); |
176 } | 167 } |
177 | 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 } |
| 180 |
178 bool PicturePileBase::HasRecordingAt(int x, int y) { | 181 bool PicturePileBase::HasRecordingAt(int x, int y) { |
179 PictureMap::const_iterator found = picture_map_.find(PictureMapKey(x, y)); | 182 PictureMap::const_iterator found = picture_map_.find(PictureMapKey(x, y)); |
180 if (found == picture_map_.end()) | 183 if (found == picture_map_.end()) |
181 return false; | 184 return false; |
182 return !!found->second.GetPicture(); | 185 return !!found->second.GetPicture(); |
183 } | 186 } |
184 | 187 |
185 bool PicturePileBase::CanRaster(float contents_scale, | 188 bool PicturePileBase::CanRaster(float contents_scale, |
186 const gfx::Rect& content_rect) { | 189 const gfx::Rect& content_rect) { |
187 if (tiling_.total_size().IsEmpty()) | 190 if (tiling_.total_size().IsEmpty()) |
188 return false; | 191 return false; |
189 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( | 192 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( |
190 content_rect, 1.f / contents_scale); | 193 content_rect, 1.f / contents_scale); |
191 layer_rect.Intersect(gfx::Rect(tiling_.total_size())); | 194 layer_rect.Intersect(gfx::Rect(tiling_.total_size())); |
192 | 195 return recorded_region_.Contains(layer_rect); |
193 // Common case inside of viewport to avoid the slower map lookups. | |
194 if (recorded_viewport_.Contains(layer_rect)) { | |
195 // Sanity check that there are no false positives in recorded_viewport_. | |
196 DCHECK(CanRasterSlowTileCheck(layer_rect)); | |
197 return true; | |
198 } | |
199 | |
200 return CanRasterSlowTileCheck(layer_rect); | |
201 } | |
202 | |
203 bool PicturePileBase::CanRasterSlowTileCheck( | |
204 const gfx::Rect& layer_rect) const { | |
205 for (TilingData::Iterator tile_iter(&tiling_, layer_rect); tile_iter; | |
206 ++tile_iter) { | |
207 PictureMap::const_iterator map_iter = picture_map_.find(tile_iter.index()); | |
208 if (map_iter == picture_map_.end()) | |
209 return false; | |
210 if (!map_iter->second.GetPicture()) | |
211 return false; | |
212 } | |
213 return true; | |
214 } | 196 } |
215 | 197 |
216 gfx::Rect PicturePileBase::PaddedRect(const PictureMapKey& key) { | 198 gfx::Rect PicturePileBase::PaddedRect(const PictureMapKey& key) { |
217 gfx::Rect tile = tiling_.TileBounds(key.first, key.second); | 199 gfx::Rect tile = tiling_.TileBounds(key.first, key.second); |
218 return PadRect(tile); | 200 return PadRect(tile); |
219 } | 201 } |
220 | 202 |
221 gfx::Rect PicturePileBase::PadRect(const gfx::Rect& rect) { | 203 gfx::Rect PicturePileBase::PadRect(const gfx::Rect& rect) { |
222 gfx::Rect padded_rect = rect; | 204 gfx::Rect padded_rect = rect; |
223 padded_rect.Inset( | 205 padded_rect.Inset( |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 info.picture_ = picture_->GetCloneForDrawingOnThread(thread_index); | 277 info.picture_ = picture_->GetCloneForDrawingOnThread(thread_index); |
296 return info; | 278 return info; |
297 } | 279 } |
298 | 280 |
299 float PicturePileBase::PictureInfo::GetInvalidationFrequency() const { | 281 float PicturePileBase::PictureInfo::GetInvalidationFrequency() const { |
300 return invalidation_history_.count() / | 282 return invalidation_history_.count() / |
301 static_cast<float>(INVALIDATION_FRAMES_TRACKED); | 283 static_cast<float>(INVALIDATION_FRAMES_TRACKED); |
302 } | 284 } |
303 | 285 |
304 } // namespace cc | 286 } // namespace cc |
OLD | NEW |