| 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/resources/picture_pile.h" | 5 #include "cc/resources/picture_pile.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 145 |
| 146 PicturePile::~PicturePile() { | 146 PicturePile::~PicturePile() { |
| 147 } | 147 } |
| 148 | 148 |
| 149 bool PicturePile::UpdateAndExpandInvalidation( | 149 bool PicturePile::UpdateAndExpandInvalidation( |
| 150 ContentLayerClient* painter, | 150 ContentLayerClient* painter, |
| 151 Region* invalidation, | 151 Region* invalidation, |
| 152 SkColor background_color, | 152 SkColor background_color, |
| 153 bool contents_opaque, | 153 bool contents_opaque, |
| 154 bool contents_fill_bounds_completely, | 154 bool contents_fill_bounds_completely, |
| 155 const gfx::Rect& layer_bounds_rect, |
| 155 const gfx::Rect& visible_layer_rect, | 156 const gfx::Rect& visible_layer_rect, |
| 156 int frame_number, | 157 int frame_number, |
| 157 Picture::RecordingMode recording_mode, | 158 Picture::RecordingMode recording_mode, |
| 158 RenderingStatsInstrumentation* stats_instrumentation) { | 159 RenderingStatsInstrumentation* stats_instrumentation) { |
| 159 background_color_ = background_color; | 160 background_color_ = background_color; |
| 160 contents_opaque_ = contents_opaque; | 161 contents_opaque_ = contents_opaque; |
| 161 contents_fill_bounds_completely_ = contents_fill_bounds_completely; | 162 contents_fill_bounds_completely_ = contents_fill_bounds_completely; |
| 162 | 163 |
| 164 bool updated = false; |
| 165 |
| 166 Region resize_invalidation; |
| 167 gfx::Rect old_tiling_rect = tiling_rect(); |
| 168 if (old_tiling_rect != layer_bounds_rect) { |
| 169 tiling_.SetTilingRect(layer_bounds_rect); |
| 170 updated = true; |
| 171 } |
| 172 |
| 163 gfx::Rect interest_rect = visible_layer_rect; | 173 gfx::Rect interest_rect = visible_layer_rect; |
| 164 interest_rect.Inset( | 174 interest_rect.Inset( |
| 165 -kPixelDistanceToRecord, | 175 -kPixelDistanceToRecord, |
| 166 -kPixelDistanceToRecord, | 176 -kPixelDistanceToRecord, |
| 167 -kPixelDistanceToRecord, | 177 -kPixelDistanceToRecord, |
| 168 -kPixelDistanceToRecord); | 178 -kPixelDistanceToRecord); |
| 169 recorded_viewport_ = interest_rect; | 179 recorded_viewport_ = interest_rect; |
| 170 recorded_viewport_.Intersect(tiling_rect()); | 180 recorded_viewport_.Intersect(tiling_rect()); |
| 171 | 181 |
| 172 gfx::Rect interest_rect_over_tiles = | 182 gfx::Rect interest_rect_over_tiles = |
| 173 tiling_.ExpandRectToTileBounds(interest_rect); | 183 tiling_.ExpandRectToTileBounds(interest_rect); |
| 174 | 184 |
| 185 if (old_tiling_rect != layer_bounds_rect) { |
| 186 has_any_recordings_ = false; |
| 187 |
| 188 if (tiling_rect().origin() != old_tiling_rect.origin()) { |
| 189 // If the origin changes we just do something simple. |
| 190 picture_map_.clear(); |
| 191 invalidation->Union(old_tiling_rect); |
| 192 invalidation->Union(tiling_rect()); |
| 193 } else { |
| 194 // Drop recordings that are outside the new layer bounds or that changed |
| 195 // size. |
| 196 std::vector<PictureMapKey> to_erase; |
| 197 int min_toss_x = tiling_.num_tiles_x(); |
| 198 if (tiling_rect().right() > old_tiling_rect.right()) { |
| 199 min_toss_x = |
| 200 tiling_.FirstBorderTileXIndexFromSrcCoord(old_tiling_rect.right()); |
| 201 } |
| 202 int min_toss_y = tiling_.num_tiles_y(); |
| 203 if (tiling_rect().bottom() > old_tiling_rect.bottom()) { |
| 204 min_toss_y = |
| 205 tiling_.FirstBorderTileYIndexFromSrcCoord(old_tiling_rect.bottom()); |
| 206 } |
| 207 for (PictureMap::const_iterator it = picture_map_.begin(); |
| 208 it != picture_map_.end(); |
| 209 ++it) { |
| 210 const PictureMapKey& key = it->first; |
| 211 if (key.first < min_toss_x && key.second < min_toss_y) { |
| 212 has_any_recordings_ |= !!it->second.GetPicture(); |
| 213 continue; |
| 214 } |
| 215 to_erase.push_back(key); |
| 216 } |
| 217 |
| 218 for (size_t i = 0; i < to_erase.size(); ++i) |
| 219 picture_map_.erase(to_erase[i]); |
| 220 |
| 221 // Invalidate dropped recordings that changed size that are outside the |
| 222 // interest rect so that raster tiles that depend on these recordings will |
| 223 // be dropped. |
| 224 gfx::Rect old_tiling_rect_over_tiles = |
| 225 tiling_.ExpandRectToTileBounds(old_tiling_rect); |
| 226 if (min_toss_x < tiling_.num_tiles_x()) { |
| 227 gfx::Rect right_side(tiling_.TilePositionX(min_toss_x), |
| 228 old_tiling_rect_over_tiles.y(), |
| 229 tiling_.TileSizeX(min_toss_x), |
| 230 old_tiling_rect_over_tiles.height()); |
| 231 right_side.Subtract(interest_rect_over_tiles); |
| 232 resize_invalidation.Union(right_side); |
| 233 } |
| 234 if (min_toss_y < tiling_.num_tiles_y()) { |
| 235 gfx::Rect bottom_side(old_tiling_rect_over_tiles.x(), |
| 236 tiling_.TilePositionY(min_toss_y), |
| 237 old_tiling_rect_over_tiles.width(), |
| 238 tiling_.TileSizeY(min_toss_y)); |
| 239 bottom_side.Subtract(interest_rect_over_tiles); |
| 240 resize_invalidation.Union(bottom_side); |
| 241 } |
| 242 } |
| 243 } |
| 244 |
| 175 Region invalidation_expanded_to_full_tiles; | 245 Region invalidation_expanded_to_full_tiles; |
| 176 | |
| 177 bool invalidated = false; | |
| 178 for (Region::Iterator i(*invalidation); i.has_rect(); i.next()) { | 246 for (Region::Iterator i(*invalidation); i.has_rect(); i.next()) { |
| 179 gfx::Rect invalid_rect = i.rect(); | 247 gfx::Rect invalid_rect = i.rect(); |
| 248 |
| 249 // Expand invalidation that is outside tiles that intersect the interest |
| 250 // rect. These tiles are no longer valid and should be considerered fully |
| 251 // invalid, so we can know to not keep around raster tiles that intersect |
| 252 // with these recording tiles. |
| 253 gfx::Rect invalid_rect_outside_interest_rect_tiles = invalid_rect; |
| 254 // TODO(danakj): We should have a Rect-subtract-Rect-to-2-rects operator |
| 255 // instead of using Rect::Subtract which gives you the bounding box of the |
| 256 // subtraction. |
| 257 invalid_rect_outside_interest_rect_tiles.Subtract(interest_rect_over_tiles); |
| 258 invalidation_expanded_to_full_tiles.Union(tiling_.ExpandRectToTileBounds( |
| 259 invalid_rect_outside_interest_rect_tiles)); |
| 260 |
| 180 // Split this inflated invalidation across tile boundaries and apply it | 261 // Split this inflated invalidation across tile boundaries and apply it |
| 181 // to all tiles that it touches. | 262 // to all tiles that it touches. |
| 182 bool include_borders = true; | 263 bool include_borders = true; |
| 183 for (TilingData::Iterator iter(&tiling_, invalid_rect, include_borders); | 264 for (TilingData::Iterator iter(&tiling_, invalid_rect, include_borders); |
| 184 iter; | 265 iter; |
| 185 ++iter) { | 266 ++iter) { |
| 186 const PictureMapKey& key = iter.index(); | 267 const PictureMapKey& key = iter.index(); |
| 187 | 268 |
| 188 PictureMap::iterator picture_it = picture_map_.find(key); | 269 PictureMap::iterator picture_it = picture_map_.find(key); |
| 189 if (picture_it == picture_map_.end()) | 270 if (picture_it == picture_map_.end()) |
| 190 continue; | 271 continue; |
| 191 | 272 |
| 192 // Inform the grid cell that it has been invalidated in this frame. | 273 // Inform the grid cell that it has been invalidated in this frame. |
| 193 invalidated = picture_it->second.Invalidate(frame_number) || invalidated; | 274 updated = picture_it->second.Invalidate(frame_number) || updated; |
| 275 // Invalidate drops the picture so the whole tile better be invalidated if |
| 276 // it won't be re-recorded below. |
| 277 DCHECK( |
| 278 tiling_.TileBounds(key.first, key.second).Intersects(interest_rect) || |
| 279 invalidation_expanded_to_full_tiles.Contains( |
| 280 tiling_.TileBounds(key.first, key.second))); |
| 194 } | 281 } |
| 195 | |
| 196 // Expand invalidation that is outside tiles that intersect the interest | |
| 197 // rect. These tiles are no longer valid and should be considerered fully | |
| 198 // invalid, so we can know to not keep around raster tiles that intersect | |
| 199 // with these recording tiles. | |
| 200 gfx::Rect invalid_rect_outside_interest_rect_tiles = invalid_rect; | |
| 201 // TODO(danakj): We should have a Rect-subtract-Rect-to-2-rects operator | |
| 202 // instead of using Rect::Subtract which gives you the bounding box of the | |
| 203 // subtraction. | |
| 204 invalid_rect_outside_interest_rect_tiles.Subtract(interest_rect_over_tiles); | |
| 205 invalidation_expanded_to_full_tiles.Union(tiling_.ExpandRectToTileBounds( | |
| 206 invalid_rect_outside_interest_rect_tiles)); | |
| 207 } | 282 } |
| 208 | 283 |
| 209 invalidation->Union(invalidation_expanded_to_full_tiles); | 284 invalidation->Union(invalidation_expanded_to_full_tiles); |
| 285 invalidation->Union(resize_invalidation); |
| 210 | 286 |
| 211 // Make a list of all invalid tiles; we will attempt to | 287 // Make a list of all invalid tiles; we will attempt to |
| 212 // cluster these into multiple invalidation regions. | 288 // cluster these into multiple invalidation regions. |
| 213 std::vector<gfx::Rect> invalid_tiles; | 289 std::vector<gfx::Rect> invalid_tiles; |
| 214 bool include_borders = true; | 290 bool include_borders = true; |
| 215 for (TilingData::Iterator it(&tiling_, interest_rect, include_borders); it; | 291 for (TilingData::Iterator it(&tiling_, interest_rect, include_borders); it; |
| 216 ++it) { | 292 ++it) { |
| 217 const PictureMapKey& key = it.index(); | 293 const PictureMapKey& key = it.index(); |
| 218 PictureInfo& info = picture_map_[key]; | 294 PictureInfo& info = picture_map_[key]; |
| 219 | 295 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 237 // to be considered invalid, so that we know not to keep around raster | 313 // to be considered invalid, so that we know not to keep around raster |
| 238 // tiles that intersect this recording tile. | 314 // tiles that intersect this recording tile. |
| 239 invalidation->Union(tiling_.TileBounds(it.index_x(), it.index_y())); | 315 invalidation->Union(tiling_.TileBounds(it.index_x(), it.index_y())); |
| 240 } | 316 } |
| 241 } | 317 } |
| 242 | 318 |
| 243 std::vector<gfx::Rect> record_rects; | 319 std::vector<gfx::Rect> record_rects; |
| 244 ClusterTiles(invalid_tiles, &record_rects); | 320 ClusterTiles(invalid_tiles, &record_rects); |
| 245 | 321 |
| 246 if (record_rects.empty()) | 322 if (record_rects.empty()) |
| 247 return invalidated; | 323 return updated; |
| 248 | 324 |
| 249 for (std::vector<gfx::Rect>::iterator it = record_rects.begin(); | 325 for (std::vector<gfx::Rect>::iterator it = record_rects.begin(); |
| 250 it != record_rects.end(); | 326 it != record_rects.end(); |
| 251 it++) { | 327 it++) { |
| 252 gfx::Rect record_rect = *it; | 328 gfx::Rect record_rect = *it; |
| 253 record_rect = PadRect(record_rect); | 329 record_rect = PadRect(record_rect); |
| 254 | 330 |
| 255 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); | 331 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); |
| 256 scoped_refptr<Picture> picture; | 332 scoped_refptr<Picture> picture; |
| 257 int num_raster_threads = RasterWorkerPool::GetNumRasterThreads(); | 333 int num_raster_threads = RasterWorkerPool::GetNumRasterThreads(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 } | 379 } |
| 304 } | 380 } |
| 305 DCHECK(found_tile_for_recorded_picture); | 381 DCHECK(found_tile_for_recorded_picture); |
| 306 } | 382 } |
| 307 | 383 |
| 308 has_any_recordings_ = true; | 384 has_any_recordings_ = true; |
| 309 DCHECK(CanRasterSlowTileCheck(recorded_viewport_)); | 385 DCHECK(CanRasterSlowTileCheck(recorded_viewport_)); |
| 310 return true; | 386 return true; |
| 311 } | 387 } |
| 312 | 388 |
| 389 void PicturePile::SetEmptyBoundsAndExpandInvalidation(Region* invalidation) { |
| 390 invalidation->Union(tiling_rect()); |
| 391 tiling_.SetTilingRect(gfx::Rect()); |
| 392 picture_map_.clear(); |
| 393 has_any_recordings_ = false; |
| 394 recorded_viewport_ = gfx::Rect(); |
| 395 } |
| 396 |
| 313 } // namespace cc | 397 } // namespace cc |
| OLD | NEW |