| 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/debug/rendering_stats_instrumentation.h" | |
| 13 #include "cc/resources/raster_worker_pool.h" | 12 #include "cc/resources/raster_worker_pool.h" |
| 14 #include "skia/ext/analysis_canvas.h" | 13 #include "skia/ext/analysis_canvas.h" |
| 15 | 14 |
| 16 namespace { | 15 namespace { |
| 17 // Layout pixel buffer around the visible layer rect to record. Any base | 16 // Layout pixel buffer around the visible layer rect to record. Any base |
| 18 // picture that intersects the visible layer rect expanded by this distance | 17 // picture that intersects the visible layer rect expanded by this distance |
| 19 // will be recorded. | 18 // will be recorded. |
| 20 const int kPixelDistanceToRecord = 8000; | 19 const int kPixelDistanceToRecord = 8000; |
| 21 // We don't perform solid color analysis on images that have more than 10 skia | 20 // We don't perform solid color analysis on images that have more than 10 skia |
| 22 // operations. | 21 // operations. |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 157 |
| 159 bool PicturePile::UpdateAndExpandInvalidation( | 158 bool PicturePile::UpdateAndExpandInvalidation( |
| 160 ContentLayerClient* painter, | 159 ContentLayerClient* painter, |
| 161 Region* invalidation, | 160 Region* invalidation, |
| 162 SkColor background_color, | 161 SkColor background_color, |
| 163 bool contents_opaque, | 162 bool contents_opaque, |
| 164 bool contents_fill_bounds_completely, | 163 bool contents_fill_bounds_completely, |
| 165 const gfx::Size& layer_size, | 164 const gfx::Size& layer_size, |
| 166 const gfx::Rect& visible_layer_rect, | 165 const gfx::Rect& visible_layer_rect, |
| 167 int frame_number, | 166 int frame_number, |
| 168 Picture::RecordingMode recording_mode, | 167 Picture::RecordingMode recording_mode) { |
| 169 RenderingStatsInstrumentation* stats_instrumentation) { | |
| 170 background_color_ = background_color; | 168 background_color_ = background_color; |
| 171 contents_opaque_ = contents_opaque; | 169 contents_opaque_ = contents_opaque; |
| 172 contents_fill_bounds_completely_ = contents_fill_bounds_completely; | 170 contents_fill_bounds_completely_ = contents_fill_bounds_completely; |
| 173 | 171 |
| 174 bool updated = false; | 172 bool updated = false; |
| 175 | 173 |
| 176 Region resize_invalidation; | 174 Region resize_invalidation; |
| 177 gfx::Size old_tiling_size = tiling_size(); | 175 gfx::Size old_tiling_size = tiling_size(); |
| 178 if (old_tiling_size != layer_size) { | 176 if (old_tiling_size != layer_size) { |
| 179 tiling_.SetTilingSize(layer_size); | 177 tiling_.SetTilingSize(layer_size); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); | 480 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_); |
| 483 scoped_refptr<Picture> picture; | 481 scoped_refptr<Picture> picture; |
| 484 | 482 |
| 485 // Note: Currently, gathering of pixel refs when using a single | 483 // Note: Currently, gathering of pixel refs when using a single |
| 486 // raster thread doesn't provide any benefit. This might change | 484 // raster thread doesn't provide any benefit. This might change |
| 487 // in the future but we avoid it for now to reduce the cost of | 485 // in the future but we avoid it for now to reduce the cost of |
| 488 // Picture::Create. | 486 // Picture::Create. |
| 489 bool gather_pixel_refs = RasterWorkerPool::GetNumRasterThreads() > 1; | 487 bool gather_pixel_refs = RasterWorkerPool::GetNumRasterThreads() > 1; |
| 490 | 488 |
| 491 { | 489 { |
| 492 base::TimeDelta best_duration = base::TimeDelta::Max(); | |
| 493 for (int i = 0; i < repeat_count; i++) { | 490 for (int i = 0; i < repeat_count; i++) { |
| 494 base::TimeTicks start_time = stats_instrumentation->StartRecording(); | |
| 495 picture = Picture::Create(record_rect, | 491 picture = Picture::Create(record_rect, |
| 496 painter, | 492 painter, |
| 497 tile_grid_info_, | 493 tile_grid_info_, |
| 498 gather_pixel_refs, | 494 gather_pixel_refs, |
| 499 recording_mode); | 495 recording_mode); |
| 500 // Note the '&&' with previous is-suitable state. | 496 // Note the '&&' with previous is-suitable state. |
| 501 // This means that once a picture-pile becomes unsuitable for gpu | 497 // This means that once a picture-pile becomes unsuitable for gpu |
| 502 // rasterization due to some content, it will continue to be unsuitable | 498 // rasterization due to some content, it will continue to be unsuitable |
| 503 // even if that content is replaced by gpu-friendly content. | 499 // even if that content is replaced by gpu-friendly content. |
| 504 // This is an optimization to avoid iterating though all pictures in | 500 // This is an optimization to avoid iterating though all pictures in |
| 505 // the pile after each invalidation. | 501 // the pile after each invalidation. |
| 506 is_suitable_for_gpu_rasterization_ &= | 502 is_suitable_for_gpu_rasterization_ &= |
| 507 picture->IsSuitableForGpuRasterization(); | 503 picture->IsSuitableForGpuRasterization(); |
| 508 base::TimeDelta duration = | |
| 509 stats_instrumentation->EndRecording(start_time); | |
| 510 best_duration = std::min(duration, best_duration); | |
| 511 } | 504 } |
| 512 int recorded_pixel_count = | |
| 513 picture->LayerRect().width() * picture->LayerRect().height(); | |
| 514 stats_instrumentation->AddRecord(best_duration, recorded_pixel_count); | |
| 515 } | 505 } |
| 516 | 506 |
| 517 bool found_tile_for_recorded_picture = false; | 507 bool found_tile_for_recorded_picture = false; |
| 518 | 508 |
| 519 bool include_borders = true; | 509 bool include_borders = true; |
| 520 for (TilingData::Iterator it(&tiling_, record_rect, include_borders); it; | 510 for (TilingData::Iterator it(&tiling_, record_rect, include_borders); it; |
| 521 ++it) { | 511 ++it) { |
| 522 const PictureMapKey& key = it.index(); | 512 const PictureMapKey& key = it.index(); |
| 523 gfx::Rect tile = PaddedRect(key); | 513 gfx::Rect tile = PaddedRect(key); |
| 524 if (record_rect.Contains(tile)) { | 514 if (record_rect.Contains(tile)) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 return; | 570 return; |
| 581 } | 571 } |
| 582 skia::AnalysisCanvas canvas(recorded_viewport_.width(), | 572 skia::AnalysisCanvas canvas(recorded_viewport_.width(), |
| 583 recorded_viewport_.height()); | 573 recorded_viewport_.height()); |
| 584 canvas.translate(-recorded_viewport_.x(), -recorded_viewport_.y()); | 574 canvas.translate(-recorded_viewport_.x(), -recorded_viewport_.y()); |
| 585 picture->Raster(&canvas, nullptr, Region(), 1.0f); | 575 picture->Raster(&canvas, nullptr, Region(), 1.0f); |
| 586 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); | 576 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); |
| 587 } | 577 } |
| 588 | 578 |
| 589 } // namespace cc | 579 } // namespace cc |
| OLD | NEW |