| 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 |
| 11 #include "cc/base/region.h" | 11 #include "cc/base/region.h" |
| 12 #include "cc/resources/picture_pile_impl.h" | 12 #include "cc/resources/picture_pile_impl.h" |
| 13 #include "cc/resources/raster_worker_pool.h" | 13 #include "cc/resources/raster_worker_pool.h" |
| 14 #include "skia/ext/analysis_canvas.h" | 14 #include "skia/ext/analysis_canvas.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 // Layout pixel buffer around the visible layer rect to record. Any base | 17 // Layout pixel buffer around the visible layer rect to record. Any base |
| 18 // picture that intersects the visible layer rect expanded by this distance | 18 // picture that intersects the visible layer rect expanded by this distance |
| 19 // will be recorded. | 19 // will be recorded. |
| 20 const int kPixelDistanceToRecord = 8000; | 20 const int kPixelDistanceToRecord = 8000; |
| 21 // We don't perform solid color analysis on images that have more than 10 skia | 21 // We don't perform solid color analysis on images that have more than 10 skia |
| 22 // operations. | 22 // operations. |
| 23 const int kOpCountThatIsOkToAnalyze = 10; | 23 const int kOpCountThatIsOkToAnalyze = 10; |
| 24 | 24 |
| 25 // Dimensions of the tiles in this picture pile as well as the dimensions of | 25 // Dimensions of the tiles in this picture pile as well as the dimensions of |
| 26 // the base picture in each tile. | 26 // the base picture in each tile. |
| 27 const int kBasePictureSize = 512; | 27 const int kBasePictureSize = 512; |
| 28 const int kTileGridBorderPixels = 1; | 28 const int kTileGridBorderPixels = 1; |
| 29 #ifdef NDEBUG | |
| 30 const bool kDefaultClearCanvasSetting = false; | |
| 31 #else | |
| 32 const bool kDefaultClearCanvasSetting = true; | |
| 33 #endif | |
| 34 | 29 |
| 35 // Invalidation frequency settings. kInvalidationFrequencyThreshold is a value | 30 // Invalidation frequency settings. kInvalidationFrequencyThreshold is a value |
| 36 // between 0 and 1 meaning invalidation frequency between 0% and 100% that | 31 // between 0 and 1 meaning invalidation frequency between 0% and 100% that |
| 37 // indicates when to stop invalidating offscreen regions. | 32 // indicates when to stop invalidating offscreen regions. |
| 38 // kFrequentInvalidationDistanceThreshold defines what it means to be | 33 // kFrequentInvalidationDistanceThreshold defines what it means to be |
| 39 // "offscreen" in terms of distance to visible in css pixels. | 34 // "offscreen" in terms of distance to visible in css pixels. |
| 40 const float kInvalidationFrequencyThreshold = 0.75f; | 35 const float kInvalidationFrequencyThreshold = 0.75f; |
| 41 const int kFrequentInvalidationDistanceThreshold = 512; | 36 const int kFrequentInvalidationDistanceThreshold = 512; |
| 42 | 37 |
| 43 // TODO(humper): The density threshold here is somewhat arbitrary; need a | 38 // TODO(humper): The density threshold here is somewhat arbitrary; need a |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 return vertical_density; | 157 return vertical_density; |
| 163 } | 158 } |
| 164 | 159 |
| 165 } // namespace | 160 } // namespace |
| 166 | 161 |
| 167 namespace cc { | 162 namespace cc { |
| 168 | 163 |
| 169 PicturePile::PicturePile() | 164 PicturePile::PicturePile() |
| 170 : min_contents_scale_(0), | 165 : min_contents_scale_(0), |
| 171 slow_down_raster_scale_factor_for_debug_(0), | 166 slow_down_raster_scale_factor_for_debug_(0), |
| 172 contents_opaque_(false), | |
| 173 contents_fill_bounds_completely_(false), | |
| 174 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting), | |
| 175 has_any_recordings_(false), | 167 has_any_recordings_(false), |
| 176 is_mask_(false), | |
| 177 is_solid_color_(false), | 168 is_solid_color_(false), |
| 178 solid_color_(SK_ColorTRANSPARENT), | 169 solid_color_(SK_ColorTRANSPARENT), |
| 179 pixel_record_distance_(kPixelDistanceToRecord), | 170 pixel_record_distance_(kPixelDistanceToRecord), |
| 180 is_suitable_for_gpu_rasterization_(true) { | 171 is_suitable_for_gpu_rasterization_(true) { |
| 181 tiling_.SetMaxTextureSize(gfx::Size(kBasePictureSize, kBasePictureSize)); | 172 tiling_.SetMaxTextureSize(gfx::Size(kBasePictureSize, kBasePictureSize)); |
| 182 tile_grid_info_.fTileInterval.setEmpty(); | 173 tile_grid_info_.fTileInterval.setEmpty(); |
| 183 tile_grid_info_.fMargin.setEmpty(); | 174 tile_grid_info_.fMargin.setEmpty(); |
| 184 tile_grid_info_.fOffset.setZero(); | 175 tile_grid_info_.fOffset.setZero(); |
| 185 } | 176 } |
| 186 | 177 |
| 187 PicturePile::~PicturePile() { | 178 PicturePile::~PicturePile() { |
| 188 } | 179 } |
| 189 | 180 |
| 190 bool PicturePile::UpdateAndExpandInvalidation( | 181 bool PicturePile::UpdateAndExpandInvalidation( |
| 191 ContentLayerClient* painter, | 182 ContentLayerClient* painter, |
| 192 Region* invalidation, | 183 Region* invalidation, |
| 193 SkColor background_color, | |
| 194 bool contents_opaque, | |
| 195 bool contents_fill_bounds_completely, | |
| 196 const gfx::Size& layer_size, | 184 const gfx::Size& layer_size, |
| 197 const gfx::Rect& visible_layer_rect, | 185 const gfx::Rect& visible_layer_rect, |
| 198 int frame_number, | 186 int frame_number, |
| 199 Picture::RecordingMode recording_mode) { | 187 Picture::RecordingMode recording_mode) { |
| 200 background_color_ = background_color; | |
| 201 contents_opaque_ = contents_opaque; | |
| 202 contents_fill_bounds_completely_ = contents_fill_bounds_completely; | |
| 203 | |
| 204 bool updated = false; | 188 bool updated = false; |
| 205 | 189 |
| 206 Region resize_invalidation; | 190 Region resize_invalidation; |
| 207 gfx::Size old_tiling_size = GetSize(); | 191 gfx::Size old_tiling_size = GetSize(); |
| 208 if (old_tiling_size != layer_size) { | 192 if (old_tiling_size != layer_size) { |
| 209 tiling_.SetTilingSize(layer_size); | 193 tiling_.SetTilingSize(layer_size); |
| 210 updated = true; | 194 updated = true; |
| 211 } | 195 } |
| 212 | 196 |
| 213 gfx::Rect interest_rect = visible_layer_rect; | 197 gfx::Rect interest_rect = visible_layer_rect; |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 } | 546 } |
| 563 DetermineIfSolidColor(); | 547 DetermineIfSolidColor(); |
| 564 DCHECK(found_tile_for_recorded_picture); | 548 DCHECK(found_tile_for_recorded_picture); |
| 565 } | 549 } |
| 566 | 550 |
| 567 has_any_recordings_ = true; | 551 has_any_recordings_ = true; |
| 568 DCHECK(CanRasterSlowTileCheck(recorded_viewport_)); | 552 DCHECK(CanRasterSlowTileCheck(recorded_viewport_)); |
| 569 return true; | 553 return true; |
| 570 } | 554 } |
| 571 | 555 |
| 556 scoped_refptr<RasterSource> PicturePile::CreateRasterSource() const { |
| 557 return scoped_refptr<RasterSource>( |
| 558 PicturePileImpl::CreateFromPicturePile(this)); |
| 559 } |
| 560 |
| 572 gfx::Size PicturePile::GetSize() const { | 561 gfx::Size PicturePile::GetSize() const { |
| 573 return tiling_.tiling_size(); | 562 return tiling_.tiling_size(); |
| 574 } | 563 } |
| 575 | 564 |
| 576 void PicturePile::SetEmptyBounds() { | 565 void PicturePile::SetEmptyBounds() { |
| 577 tiling_.SetTilingSize(gfx::Size()); | 566 tiling_.SetTilingSize(gfx::Size()); |
| 578 Clear(); | 567 Clear(); |
| 579 } | 568 } |
| 580 | 569 |
| 581 void PicturePile::SetMinContentsScale(float min_contents_scale) { | 570 void PicturePile::SetMinContentsScale(float min_contents_scale) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 592 // | 581 // |
| 593 // For example, if a 1/4 contents scale is used, then that would be 3 buffer | 582 // For example, if a 1/4 contents scale is used, then that would be 3 buffer |
| 594 // pixels, since that's the minimum number of pixels to add so that resulting | 583 // pixels, since that's the minimum number of pixels to add so that resulting |
| 595 // content can be snapped to a four pixel aligned grid. | 584 // content can be snapped to a four pixel aligned grid. |
| 596 int buffer_pixels = static_cast<int>(ceil(1 / min_contents_scale) - 1); | 585 int buffer_pixels = static_cast<int>(ceil(1 / min_contents_scale) - 1); |
| 597 buffer_pixels = std::max(0, buffer_pixels); | 586 buffer_pixels = std::max(0, buffer_pixels); |
| 598 SetBufferPixels(buffer_pixels); | 587 SetBufferPixels(buffer_pixels); |
| 599 min_contents_scale_ = min_contents_scale; | 588 min_contents_scale_ = min_contents_scale; |
| 600 } | 589 } |
| 601 | 590 |
| 591 void PicturePile::SetSlowdownRasterScaleFactor(int factor) { |
| 592 slow_down_raster_scale_factor_for_debug_ = factor; |
| 593 } |
| 594 |
| 595 bool PicturePile::IsSuitableForGpuRasterization() const { |
| 596 return is_suitable_for_gpu_rasterization_; |
| 597 } |
| 598 |
| 602 // static | 599 // static |
| 603 void PicturePile::ComputeTileGridInfo(const gfx::Size& tile_grid_size, | 600 void PicturePile::ComputeTileGridInfo(const gfx::Size& tile_grid_size, |
| 604 SkTileGridFactory::TileGridInfo* info) { | 601 SkTileGridFactory::TileGridInfo* info) { |
| 605 DCHECK(info); | 602 DCHECK(info); |
| 606 info->fTileInterval.set(tile_grid_size.width() - 2 * kTileGridBorderPixels, | 603 info->fTileInterval.set(tile_grid_size.width() - 2 * kTileGridBorderPixels, |
| 607 tile_grid_size.height() - 2 * kTileGridBorderPixels); | 604 tile_grid_size.height() - 2 * kTileGridBorderPixels); |
| 608 DCHECK_GT(info->fTileInterval.width(), 0); | 605 DCHECK_GT(info->fTileInterval.width(), 0); |
| 609 DCHECK_GT(info->fTileInterval.height(), 0); | 606 DCHECK_GT(info->fTileInterval.height(), 0); |
| 610 info->fMargin.set(kTileGridBorderPixels, kTileGridBorderPixels); | 607 info->fMargin.set(kTileGridBorderPixels, kTileGridBorderPixels); |
| 611 // Offset the tile grid coordinate space to take into account the fact | 608 // Offset the tile grid coordinate space to take into account the fact |
| 612 // that the top-most and left-most tiles do not have top and left borders | 609 // that the top-most and left-most tiles do not have top and left borders |
| 613 // respectively. | 610 // respectively. |
| 614 info->fOffset.set(-kTileGridBorderPixels, -kTileGridBorderPixels); | 611 info->fOffset.set(-kTileGridBorderPixels, -kTileGridBorderPixels); |
| 615 } | 612 } |
| 616 | 613 |
| 617 void PicturePile::SetTileGridSize(const gfx::Size& tile_grid_size) { | 614 void PicturePile::SetTileGridSize(const gfx::Size& tile_grid_size) { |
| 618 ComputeTileGridInfo(tile_grid_size, &tile_grid_info_); | 615 ComputeTileGridInfo(tile_grid_size, &tile_grid_info_); |
| 619 } | 616 } |
| 620 | 617 |
| 621 void PicturePile::SetSlowdownRasterScaleFactor(int factor) { | |
| 622 slow_down_raster_scale_factor_for_debug_ = factor; | |
| 623 } | |
| 624 | |
| 625 void PicturePile::SetIsMask(bool is_mask) { | |
| 626 is_mask_ = is_mask; | |
| 627 } | |
| 628 | |
| 629 void PicturePile::SetUnsuitableForGpuRasterizationForTesting() { | 618 void PicturePile::SetUnsuitableForGpuRasterizationForTesting() { |
| 630 is_suitable_for_gpu_rasterization_ = false; | 619 is_suitable_for_gpu_rasterization_ = false; |
| 631 } | 620 } |
| 632 | 621 |
| 633 bool PicturePile::IsSuitableForGpuRasterization() const { | |
| 634 return is_suitable_for_gpu_rasterization_; | |
| 635 } | |
| 636 | |
| 637 scoped_refptr<RasterSource> PicturePile::CreateRasterSource() const { | |
| 638 return scoped_refptr<RasterSource>( | |
| 639 PicturePileImpl::CreateFromPicturePile(this)); | |
| 640 } | |
| 641 | |
| 642 SkTileGridFactory::TileGridInfo PicturePile::GetTileGridInfoForTesting() const { | 622 SkTileGridFactory::TileGridInfo PicturePile::GetTileGridInfoForTesting() const { |
| 643 return tile_grid_info_; | 623 return tile_grid_info_; |
| 644 } | 624 } |
| 645 | 625 |
| 646 bool PicturePile::CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const { | 626 bool PicturePile::CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const { |
| 647 bool include_borders = false; | 627 bool include_borders = false; |
| 648 for (TilingData::Iterator tile_iter(&tiling_, layer_rect, include_borders); | 628 for (TilingData::Iterator tile_iter(&tiling_, layer_rect, include_borders); |
| 649 tile_iter; ++tile_iter) { | 629 tile_iter; ++tile_iter) { |
| 650 PictureMap::const_iterator map_iter = picture_map_.find(tile_iter.index()); | 630 PictureMap::const_iterator map_iter = picture_map_.find(tile_iter.index()); |
| 651 if (map_iter == picture_map_.end()) | 631 if (map_iter == picture_map_.end()) |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 const Picture* PicturePile::PictureInfo::GetPicture() const { | 739 const Picture* PicturePile::PictureInfo::GetPicture() const { |
| 760 return picture_.get(); | 740 return picture_.get(); |
| 761 } | 741 } |
| 762 | 742 |
| 763 float PicturePile::PictureInfo::GetInvalidationFrequency() const { | 743 float PicturePile::PictureInfo::GetInvalidationFrequency() const { |
| 764 return invalidation_history_.count() / | 744 return invalidation_history_.count() / |
| 765 static_cast<float>(INVALIDATION_FRAMES_TRACKED); | 745 static_cast<float>(INVALIDATION_FRAMES_TRACKED); |
| 766 } | 746 } |
| 767 | 747 |
| 768 } // namespace cc | 748 } // namespace cc |
| OLD | NEW |