| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 142 } |
| 143 | 143 |
| 144 *record_rects = vertical_clustering; | 144 *record_rects = vertical_clustering; |
| 145 return vertical_density; | 145 return vertical_density; |
| 146 } | 146 } |
| 147 | 147 |
| 148 } // namespace | 148 } // namespace |
| 149 | 149 |
| 150 namespace cc { | 150 namespace cc { |
| 151 | 151 |
| 152 PicturePile::PicturePile() : is_suitable_for_gpu_rasterization_(true) { | 152 PicturePile::PicturePile() |
| 153 : is_suitable_for_gpu_rasterization_(true), |
| 154 pixel_record_distance_(kPixelDistanceToRecord) { |
| 153 } | 155 } |
| 154 | 156 |
| 155 PicturePile::~PicturePile() { | 157 PicturePile::~PicturePile() { |
| 156 } | 158 } |
| 157 | 159 |
| 158 bool PicturePile::UpdateAndExpandInvalidation( | 160 bool PicturePile::UpdateAndExpandInvalidation( |
| 159 ContentLayerClient* painter, | 161 ContentLayerClient* painter, |
| 160 Region* invalidation, | 162 Region* invalidation, |
| 161 SkColor background_color, | 163 SkColor background_color, |
| 162 bool contents_opaque, | 164 bool contents_opaque, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 173 bool updated = false; | 175 bool updated = false; |
| 174 | 176 |
| 175 Region resize_invalidation; | 177 Region resize_invalidation; |
| 176 gfx::Size old_tiling_size = tiling_size(); | 178 gfx::Size old_tiling_size = tiling_size(); |
| 177 if (old_tiling_size != layer_size) { | 179 if (old_tiling_size != layer_size) { |
| 178 tiling_.SetTilingSize(layer_size); | 180 tiling_.SetTilingSize(layer_size); |
| 179 updated = true; | 181 updated = true; |
| 180 } | 182 } |
| 181 | 183 |
| 182 gfx::Rect interest_rect = visible_layer_rect; | 184 gfx::Rect interest_rect = visible_layer_rect; |
| 183 interest_rect.Inset( | 185 interest_rect.Inset(-pixel_record_distance_, -pixel_record_distance_); |
| 184 -kPixelDistanceToRecord, | |
| 185 -kPixelDistanceToRecord, | |
| 186 -kPixelDistanceToRecord, | |
| 187 -kPixelDistanceToRecord); | |
| 188 recorded_viewport_ = interest_rect; | 186 recorded_viewport_ = interest_rect; |
| 189 recorded_viewport_.Intersect(gfx::Rect(tiling_size())); | 187 recorded_viewport_.Intersect(gfx::Rect(tiling_size())); |
| 190 | 188 |
| 191 gfx::Rect interest_rect_over_tiles = | 189 gfx::Rect interest_rect_over_tiles = |
| 192 tiling_.ExpandRectToTileBounds(interest_rect); | 190 tiling_.ExpandRectToTileBounds(interest_rect); |
| 193 | 191 |
| 194 if (old_tiling_size != layer_size) { | 192 if (old_tiling_size != layer_size) { |
| 195 has_any_recordings_ = false; | 193 has_any_recordings_ = false; |
| 196 | 194 |
| 197 // Drop recordings that are outside the new layer bounds or that changed | 195 // Drop recordings that are outside the new layer bounds or that changed |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 } | 376 } |
| 379 } | 377 } |
| 380 | 378 |
| 381 // Detect cases where the full pile is invalidated, in this situation we | 379 // Detect cases where the full pile is invalidated, in this situation we |
| 382 // can just drop/invalidate everything. | 380 // can just drop/invalidate everything. |
| 383 if (invalidation->Contains(gfx::Rect(old_tiling_size)) || | 381 if (invalidation->Contains(gfx::Rect(old_tiling_size)) || |
| 384 invalidation->Contains(gfx::Rect(tiling_size()))) { | 382 invalidation->Contains(gfx::Rect(tiling_size()))) { |
| 385 for (auto& it : picture_map_) | 383 for (auto& it : picture_map_) |
| 386 updated = it.second.Invalidate(frame_number) || updated; | 384 updated = it.second.Invalidate(frame_number) || updated; |
| 387 } else { | 385 } else { |
| 388 // Expand invalidation that is outside tiles that intersect the interest | 386 // Expand invalidation that is on tiles that aren't in the interest rect and |
| 389 // rect. These tiles are no longer valid and should be considerered fully | 387 // will not be re-recorded below. These tiles are no longer valid and should |
| 390 // invalid, so we can know to not keep around raster tiles that intersect | 388 // be considerered fully invalid, so we can know to not keep around raster |
| 391 // with these recording tiles. | 389 // tiles that intersect with these recording tiles. |
| 392 Region invalidation_expanded_to_full_tiles; | 390 Region invalidation_expanded_to_full_tiles; |
| 393 | 391 |
| 394 for (Region::Iterator i(*invalidation); i.has_rect(); i.next()) { | 392 for (Region::Iterator i(*invalidation); i.has_rect(); i.next()) { |
| 395 gfx::Rect invalid_rect = i.rect(); | 393 gfx::Rect invalid_rect = i.rect(); |
| 396 | 394 |
| 397 gfx::Rect invalid_rect_outside_interest_rect_tiles = invalid_rect; | 395 // This rect covers the bounds (excluding borders) of all tiles whose |
| 396 // bounds (including borders) touch the |interest_rect|. This matches |
| 397 // the iteration of the |invalid_rect| below which includes borders when |
| 398 // calling Invalidate() on pictures. |
| 399 gfx::Rect invalid_rect_outside_interest_rect_tiles = |
| 400 tiling_.ExpandRectToTileBounds(invalid_rect); |
| 401 // We subtract the |interest_rect_over_tiles| which represents the bounds |
| 402 // of tiles that will be re-recorded below. This matches the iteration of |
| 403 // |interest_rect| below which includes borders. |
| 398 // TODO(danakj): We should have a Rect-subtract-Rect-to-2-rects operator | 404 // TODO(danakj): We should have a Rect-subtract-Rect-to-2-rects operator |
| 399 // instead of using Rect::Subtract which gives you the bounding box of the | 405 // instead of using Rect::Subtract which gives you the bounding box of the |
| 400 // subtraction. | 406 // subtraction. |
| 401 invalid_rect_outside_interest_rect_tiles.Subtract( | 407 invalid_rect_outside_interest_rect_tiles.Subtract( |
| 402 interest_rect_over_tiles); | 408 interest_rect_over_tiles); |
| 403 invalidation_expanded_to_full_tiles.Union(tiling_.ExpandRectToTileBounds( | 409 invalidation_expanded_to_full_tiles.Union( |
| 404 invalid_rect_outside_interest_rect_tiles)); | 410 invalid_rect_outside_interest_rect_tiles); |
| 405 | 411 |
| 406 // Split this inflated invalidation across tile boundaries and apply it | 412 // Split this inflated invalidation across tile boundaries and apply it |
| 407 // to all tiles that it touches. | 413 // to all tiles that it touches. |
| 408 bool include_borders = true; | 414 bool include_borders = true; |
| 409 for (TilingData::Iterator iter(&tiling_, invalid_rect, include_borders); | 415 for (TilingData::Iterator iter(&tiling_, invalid_rect, include_borders); |
| 410 iter; | 416 iter; |
| 411 ++iter) { | 417 ++iter) { |
| 412 const PictureMapKey& key = iter.index(); | 418 const PictureMapKey& key = iter.index(); |
| 413 | 419 |
| 414 PictureMap::iterator picture_it = picture_map_.find(key); | 420 PictureMap::iterator picture_it = picture_map_.find(key); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 if (it->second.GetPicture() != picture) | 570 if (it->second.GetPicture() != picture) |
| 565 return; | 571 return; |
| 566 } | 572 } |
| 567 skia::AnalysisCanvas canvas(recorded_viewport_.width(), | 573 skia::AnalysisCanvas canvas(recorded_viewport_.width(), |
| 568 recorded_viewport_.height()); | 574 recorded_viewport_.height()); |
| 569 picture->Raster(&canvas, NULL, Region(), 1.0f); | 575 picture->Raster(&canvas, NULL, Region(), 1.0f); |
| 570 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); | 576 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); |
| 571 } | 577 } |
| 572 | 578 |
| 573 } // namespace cc | 579 } // namespace cc |
| OLD | NEW |