| 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/tile_task_worker_pool.h" | 13 #include "cc/resources/tile_task_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; | |
| 29 | 28 |
| 30 // Invalidation frequency settings. kInvalidationFrequencyThreshold is a value | 29 // Invalidation frequency settings. kInvalidationFrequencyThreshold is a value |
| 31 // between 0 and 1 meaning invalidation frequency between 0% and 100% that | 30 // between 0 and 1 meaning invalidation frequency between 0% and 100% that |
| 32 // indicates when to stop invalidating offscreen regions. | 31 // indicates when to stop invalidating offscreen regions. |
| 33 // kFrequentInvalidationDistanceThreshold defines what it means to be | 32 // kFrequentInvalidationDistanceThreshold defines what it means to be |
| 34 // "offscreen" in terms of distance to visible in css pixels. | 33 // "offscreen" in terms of distance to visible in css pixels. |
| 35 const float kInvalidationFrequencyThreshold = 0.75f; | 34 const float kInvalidationFrequencyThreshold = 0.75f; |
| 36 const int kFrequentInvalidationDistanceThreshold = 512; | 35 const int kFrequentInvalidationDistanceThreshold = 512; |
| 37 | 36 |
| 38 // TODO(humper): The density threshold here is somewhat arbitrary; need a | 37 // TODO(humper): The density threshold here is somewhat arbitrary; need a |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 PicturePile::PicturePile() | 159 PicturePile::PicturePile() |
| 161 : min_contents_scale_(0), | 160 : min_contents_scale_(0), |
| 162 slow_down_raster_scale_factor_for_debug_(0), | 161 slow_down_raster_scale_factor_for_debug_(0), |
| 163 can_use_lcd_text_(true), | 162 can_use_lcd_text_(true), |
| 164 has_any_recordings_(false), | 163 has_any_recordings_(false), |
| 165 is_solid_color_(false), | 164 is_solid_color_(false), |
| 166 solid_color_(SK_ColorTRANSPARENT), | 165 solid_color_(SK_ColorTRANSPARENT), |
| 167 pixel_record_distance_(kPixelDistanceToRecord), | 166 pixel_record_distance_(kPixelDistanceToRecord), |
| 168 is_suitable_for_gpu_rasterization_(true) { | 167 is_suitable_for_gpu_rasterization_(true) { |
| 169 tiling_.SetMaxTextureSize(gfx::Size(kBasePictureSize, kBasePictureSize)); | 168 tiling_.SetMaxTextureSize(gfx::Size(kBasePictureSize, kBasePictureSize)); |
| 170 tile_grid_info_.fTileInterval.setEmpty(); | |
| 171 tile_grid_info_.fMargin.setEmpty(); | |
| 172 tile_grid_info_.fOffset.setZero(); | |
| 173 } | 169 } |
| 174 | 170 |
| 175 PicturePile::~PicturePile() { | 171 PicturePile::~PicturePile() { |
| 176 } | 172 } |
| 177 | 173 |
| 178 bool PicturePile::UpdateAndExpandInvalidation( | 174 bool PicturePile::UpdateAndExpandInvalidation( |
| 179 ContentLayerClient* painter, | 175 ContentLayerClient* painter, |
| 180 Region* invalidation, | 176 Region* invalidation, |
| 181 bool can_use_lcd_text, | 177 bool can_use_lcd_text, |
| 182 const gfx::Size& layer_size, | 178 const gfx::Size& layer_size, |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); | 537 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); |
| 542 scoped_refptr<Picture> picture; | 538 scoped_refptr<Picture> picture; |
| 543 | 539 |
| 544 // Note: Currently, gathering of pixel refs when using a single | 540 // Note: Currently, gathering of pixel refs when using a single |
| 545 // raster thread doesn't provide any benefit. This might change | 541 // raster thread doesn't provide any benefit. This might change |
| 546 // in the future but we avoid it for now to reduce the cost of | 542 // in the future but we avoid it for now to reduce the cost of |
| 547 // Picture::Create. | 543 // Picture::Create. |
| 548 bool gather_pixel_refs = TileTaskWorkerPool::GetNumWorkerThreads() > 1; | 544 bool gather_pixel_refs = TileTaskWorkerPool::GetNumWorkerThreads() > 1; |
| 549 | 545 |
| 550 for (int i = 0; i < repeat_count; i++) { | 546 for (int i = 0; i < repeat_count; i++) { |
| 551 picture = Picture::Create(padded_record_rect, painter, tile_grid_info_, | 547 picture = Picture::Create(padded_record_rect, painter, tile_grid_size_, |
| 552 gather_pixel_refs, recording_mode); | 548 gather_pixel_refs, recording_mode); |
| 553 // Note the '&&' with previous is-suitable state. | 549 // Note the '&&' with previous is-suitable state. |
| 554 // This means that once a picture-pile becomes unsuitable for gpu | 550 // This means that once a picture-pile becomes unsuitable for gpu |
| 555 // rasterization due to some content, it will continue to be unsuitable | 551 // rasterization due to some content, it will continue to be unsuitable |
| 556 // even if that content is replaced by gpu-friendly content. | 552 // even if that content is replaced by gpu-friendly content. |
| 557 // This is an optimization to avoid iterating though all pictures in | 553 // This is an optimization to avoid iterating though all pictures in |
| 558 // the pile after each invalidation. | 554 // the pile after each invalidation. |
| 559 if (is_suitable_for_gpu_rasterization_) { | 555 if (is_suitable_for_gpu_rasterization_) { |
| 560 const char* reason = nullptr; | 556 const char* reason = nullptr; |
| 561 is_suitable_for_gpu_rasterization_ &= | 557 is_suitable_for_gpu_rasterization_ &= |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 } | 617 } |
| 622 | 618 |
| 623 void PicturePile::SetSlowdownRasterScaleFactor(int factor) { | 619 void PicturePile::SetSlowdownRasterScaleFactor(int factor) { |
| 624 slow_down_raster_scale_factor_for_debug_ = factor; | 620 slow_down_raster_scale_factor_for_debug_ = factor; |
| 625 } | 621 } |
| 626 | 622 |
| 627 bool PicturePile::IsSuitableForGpuRasterization() const { | 623 bool PicturePile::IsSuitableForGpuRasterization() const { |
| 628 return is_suitable_for_gpu_rasterization_; | 624 return is_suitable_for_gpu_rasterization_; |
| 629 } | 625 } |
| 630 | 626 |
| 631 // static | 627 void PicturePile::SetTileGridSize(const gfx::Size& tile_grid_size) { |
| 632 void PicturePile::ComputeTileGridInfo(const gfx::Size& tile_grid_size, | 628 DCHECK_GT(tile_grid_size.width(), 0); |
| 633 SkTileGridFactory::TileGridInfo* info) { | 629 DCHECK_GT(tile_grid_size.height(), 0); |
| 634 DCHECK(info); | |
| 635 info->fTileInterval.set(tile_grid_size.width() - 2 * kTileGridBorderPixels, | |
| 636 tile_grid_size.height() - 2 * kTileGridBorderPixels); | |
| 637 DCHECK_GT(info->fTileInterval.width(), 0); | |
| 638 DCHECK_GT(info->fTileInterval.height(), 0); | |
| 639 info->fMargin.set(kTileGridBorderPixels, kTileGridBorderPixels); | |
| 640 // Offset the tile grid coordinate space to take into account the fact | |
| 641 // that the top-most and left-most tiles do not have top and left borders | |
| 642 // respectively. | |
| 643 info->fOffset.set(-kTileGridBorderPixels, -kTileGridBorderPixels); | |
| 644 } | |
| 645 | 630 |
| 646 void PicturePile::SetTileGridSize(const gfx::Size& tile_grid_size) { | 631 tile_grid_size_ = tile_grid_size; |
| 647 ComputeTileGridInfo(tile_grid_size, &tile_grid_info_); | |
| 648 } | 632 } |
| 649 | 633 |
| 650 void PicturePile::SetUnsuitableForGpuRasterizationForTesting() { | 634 void PicturePile::SetUnsuitableForGpuRasterizationForTesting() { |
| 651 is_suitable_for_gpu_rasterization_ = false; | 635 is_suitable_for_gpu_rasterization_ = false; |
| 652 } | 636 } |
| 653 | 637 |
| 654 SkTileGridFactory::TileGridInfo PicturePile::GetTileGridInfoForTesting() const { | 638 gfx::Size PicturePile::GetTileGridSizeForTesting() const { |
| 655 return tile_grid_info_; | 639 return tile_grid_size_; |
| 656 } | 640 } |
| 657 | 641 |
| 658 bool PicturePile::CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const { | 642 bool PicturePile::CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const { |
| 659 bool include_borders = false; | 643 bool include_borders = false; |
| 660 for (TilingData::Iterator tile_iter(&tiling_, layer_rect, include_borders); | 644 for (TilingData::Iterator tile_iter(&tiling_, layer_rect, include_borders); |
| 661 tile_iter; ++tile_iter) { | 645 tile_iter; ++tile_iter) { |
| 662 PictureMap::const_iterator map_iter = picture_map_.find(tile_iter.index()); | 646 PictureMap::const_iterator map_iter = picture_map_.find(tile_iter.index()); |
| 663 if (map_iter == picture_map_.end()) | 647 if (map_iter == picture_map_.end()) |
| 664 return false; | 648 return false; |
| 665 if (!map_iter->second.GetPicture()) | 649 if (!map_iter->second.GetPicture()) |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 const Picture* PicturePile::PictureInfo::GetPicture() const { | 756 const Picture* PicturePile::PictureInfo::GetPicture() const { |
| 773 return picture_.get(); | 757 return picture_.get(); |
| 774 } | 758 } |
| 775 | 759 |
| 776 float PicturePile::PictureInfo::GetInvalidationFrequency() const { | 760 float PicturePile::PictureInfo::GetInvalidationFrequency() const { |
| 777 return invalidation_history_.count() / | 761 return invalidation_history_.count() / |
| 778 static_cast<float>(INVALIDATION_FRAMES_TRACKED); | 762 static_cast<float>(INVALIDATION_FRAMES_TRACKED); |
| 779 } | 763 } |
| 780 | 764 |
| 781 } // namespace cc | 765 } // namespace cc |
| OLD | NEW |