| 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/tiles/tile_manager.h" | 5 #include "cc/tiles/tile_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <limits> | 11 #include <limits> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 19 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
| 20 #include "base/numerics/safe_conversions.h" | 20 #include "base/numerics/safe_conversions.h" |
| 21 #include "base/optional.h" | 21 #include "base/optional.h" |
| 22 #include "base/threading/thread_checker.h" | 22 #include "base/threading/thread_checker.h" |
| 23 #include "base/trace_event/trace_event_argument.h" | 23 #include "base/trace_event/trace_event_argument.h" |
| 24 #include "cc/base/devtools_instrumentation.h" | 24 #include "cc/base/devtools_instrumentation.h" |
| 25 #include "cc/base/histograms.h" | 25 #include "cc/base/histograms.h" |
| 26 #include "cc/base/scale_translate2d.h" |
| 26 #include "cc/debug/traced_value.h" | 27 #include "cc/debug/traced_value.h" |
| 27 #include "cc/layers/picture_layer_impl.h" | 28 #include "cc/layers/picture_layer_impl.h" |
| 28 #include "cc/raster/raster_buffer.h" | 29 #include "cc/raster/raster_buffer.h" |
| 29 #include "cc/raster/task_category.h" | 30 #include "cc/raster/task_category.h" |
| 30 #include "cc/tiles/frame_viewer_instrumentation.h" | 31 #include "cc/tiles/frame_viewer_instrumentation.h" |
| 31 #include "cc/tiles/tile.h" | 32 #include "cc/tiles/tile.h" |
| 32 #include "ui/gfx/geometry/rect_conversions.h" | 33 #include "ui/gfx/geometry/rect_conversions.h" |
| 33 | 34 |
| 34 namespace cc { | 35 namespace cc { |
| 35 namespace { | 36 namespace { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 std::unique_ptr<RasterBuffer> raster_buffer, | 92 std::unique_ptr<RasterBuffer> raster_buffer, |
| 92 TileTask::Vector* dependencies, | 93 TileTask::Vector* dependencies, |
| 93 bool is_gpu_rasterization) | 94 bool is_gpu_rasterization) |
| 94 : TileTask(!is_gpu_rasterization, dependencies), | 95 : TileTask(!is_gpu_rasterization, dependencies), |
| 95 tile_manager_(tile_manager), | 96 tile_manager_(tile_manager), |
| 96 tile_id_(tile->id()), | 97 tile_id_(tile->id()), |
| 97 resource_(resource), | 98 resource_(resource), |
| 98 raster_source_(std::move(raster_source)), | 99 raster_source_(std::move(raster_source)), |
| 99 content_rect_(tile->content_rect()), | 100 content_rect_(tile->content_rect()), |
| 100 invalid_content_rect_(invalidated_rect), | 101 invalid_content_rect_(invalidated_rect), |
| 101 raster_scale_(tile->contents_scale()), | 102 raster_transform_(tile->raster_transform()), |
| 102 playback_settings_(playback_settings), | 103 playback_settings_(playback_settings), |
| 103 tile_resolution_(tile_resolution), | 104 tile_resolution_(tile_resolution), |
| 104 layer_id_(tile->layer_id()), | 105 layer_id_(tile->layer_id()), |
| 105 source_prepare_tiles_id_(source_prepare_tiles_id), | 106 source_prepare_tiles_id_(source_prepare_tiles_id), |
| 106 tile_tracing_id_(static_cast<void*>(tile)), | 107 tile_tracing_id_(static_cast<void*>(tile)), |
| 107 new_content_id_(tile->id()), | 108 new_content_id_(tile->id()), |
| 108 source_frame_number_(tile->source_frame_number()), | 109 source_frame_number_(tile->source_frame_number()), |
| 109 is_gpu_rasterization_(is_gpu_rasterization), | 110 is_gpu_rasterization_(is_gpu_rasterization), |
| 110 raster_buffer_(std::move(raster_buffer)) { | 111 raster_buffer_(std::move(raster_buffer)) { |
| 111 DCHECK(origin_thread_checker_.CalledOnValidThread()); | 112 DCHECK(origin_thread_checker_.CalledOnValidThread()); |
| 112 } | 113 } |
| 113 | 114 |
| 114 // Overridden from Task: | 115 // Overridden from Task: |
| 115 void RunOnWorkerThread() override { | 116 void RunOnWorkerThread() override { |
| 116 TRACE_EVENT1("cc", "RasterizerTaskImpl::RunOnWorkerThread", | 117 TRACE_EVENT1("cc", "RasterizerTaskImpl::RunOnWorkerThread", |
| 117 "source_prepare_tiles_id", source_prepare_tiles_id_); | 118 "source_prepare_tiles_id", source_prepare_tiles_id_); |
| 118 | 119 |
| 119 DCHECK(raster_source_.get()); | 120 DCHECK(raster_source_.get()); |
| 120 DCHECK(raster_buffer_); | 121 DCHECK(raster_buffer_); |
| 121 | 122 |
| 122 frame_viewer_instrumentation::ScopedRasterTask raster_task( | 123 frame_viewer_instrumentation::ScopedRasterTask raster_task( |
| 123 tile_tracing_id_, tile_resolution_, source_frame_number_, layer_id_); | 124 tile_tracing_id_, tile_resolution_, source_frame_number_, layer_id_); |
| 124 ScopedRasterTaskTimer timer(is_gpu_rasterization_); | 125 ScopedRasterTaskTimer timer(is_gpu_rasterization_); |
| 125 timer.SetArea(content_rect_.size().GetArea()); | 126 timer.SetArea(content_rect_.size().GetArea()); |
| 126 | 127 |
| 127 DCHECK(raster_source_); | 128 DCHECK(raster_source_); |
| 128 | 129 |
| 129 raster_buffer_->Playback(raster_source_.get(), content_rect_, | 130 raster_buffer_->Playback(raster_source_.get(), content_rect_, |
| 130 invalid_content_rect_, new_content_id_, | 131 invalid_content_rect_, new_content_id_, |
| 131 raster_scale_, playback_settings_); | 132 raster_transform_, playback_settings_); |
| 132 } | 133 } |
| 133 | 134 |
| 134 // Overridden from TileTask: | 135 // Overridden from TileTask: |
| 135 void OnTaskCompleted() override { | 136 void OnTaskCompleted() override { |
| 136 DCHECK(origin_thread_checker_.CalledOnValidThread()); | 137 DCHECK(origin_thread_checker_.CalledOnValidThread()); |
| 137 | 138 |
| 138 // Here calling state().IsCanceled() is thread-safe, because this task is | 139 // Here calling state().IsCanceled() is thread-safe, because this task is |
| 139 // already concluded as FINISHED or CANCELLED and no longer will be worked | 140 // already concluded as FINISHED or CANCELLED and no longer will be worked |
| 140 // upon by task graph runner. | 141 // upon by task graph runner. |
| 141 tile_manager_->OnRasterTaskCompleted(std::move(raster_buffer_), tile_id_, | 142 tile_manager_->OnRasterTaskCompleted(std::move(raster_buffer_), tile_id_, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 155 // origin thread. These are not thread-safe and should be accessed only in | 156 // origin thread. These are not thread-safe and should be accessed only in |
| 156 // origin thread. Ensure their access by checking CalledOnValidThread(). | 157 // origin thread. Ensure their access by checking CalledOnValidThread(). |
| 157 TileManager* tile_manager_; | 158 TileManager* tile_manager_; |
| 158 Tile::Id tile_id_; | 159 Tile::Id tile_id_; |
| 159 Resource* resource_; | 160 Resource* resource_; |
| 160 | 161 |
| 161 // The following members should be used for running the task. | 162 // The following members should be used for running the task. |
| 162 scoped_refptr<RasterSource> raster_source_; | 163 scoped_refptr<RasterSource> raster_source_; |
| 163 gfx::Rect content_rect_; | 164 gfx::Rect content_rect_; |
| 164 gfx::Rect invalid_content_rect_; | 165 gfx::Rect invalid_content_rect_; |
| 165 float raster_scale_; | 166 ScaleTranslate2d raster_transform_; |
| 166 RasterSource::PlaybackSettings playback_settings_; | 167 RasterSource::PlaybackSettings playback_settings_; |
| 167 TileResolution tile_resolution_; | 168 TileResolution tile_resolution_; |
| 168 int layer_id_; | 169 int layer_id_; |
| 169 uint64_t source_prepare_tiles_id_; | 170 uint64_t source_prepare_tiles_id_; |
| 170 void* tile_tracing_id_; | 171 void* tile_tracing_id_; |
| 171 uint64_t new_content_id_; | 172 uint64_t new_content_id_; |
| 172 int source_frame_number_; | 173 int source_frame_number_; |
| 173 bool is_gpu_rasterization_; | 174 bool is_gpu_rasterization_; |
| 174 std::unique_ptr<RasterBuffer> raster_buffer_; | 175 std::unique_ptr<RasterBuffer> raster_buffer_; |
| 175 | 176 |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 | 658 |
| 658 bool tile_is_needed_now = priority.priority_bin == TilePriority::NOW; | 659 bool tile_is_needed_now = priority.priority_bin == TilePriority::NOW; |
| 659 if (!tile->is_solid_color_analysis_performed() && | 660 if (!tile->is_solid_color_analysis_performed() && |
| 660 tile->use_picture_analysis() && kUseColorEstimator) { | 661 tile->use_picture_analysis() && kUseColorEstimator) { |
| 661 // We analyze for solid color here, to decide to continue | 662 // We analyze for solid color here, to decide to continue |
| 662 // or drop the tile for scheduling and raster. | 663 // or drop the tile for scheduling and raster. |
| 663 // TODO(sohanjg): Check if we could use a shared analysis | 664 // TODO(sohanjg): Check if we could use a shared analysis |
| 664 // canvas which is reset between tiles. | 665 // canvas which is reset between tiles. |
| 665 tile->set_solid_color_analysis_performed(true); | 666 tile->set_solid_color_analysis_performed(true); |
| 666 SkColor color = SK_ColorTRANSPARENT; | 667 SkColor color = SK_ColorTRANSPARENT; |
| 668 gfx::RectF layer_rect = tile->raster_transform().TransformRectReverse( |
| 669 gfx::RectF(tile->content_rect())); |
| 667 bool is_solid_color = | 670 bool is_solid_color = |
| 668 prioritized_tile.raster_source()->PerformSolidColorAnalysis( | 671 prioritized_tile.raster_source()->PerformSolidColorAnalysis( |
| 669 tile->content_rect(), tile->contents_scale(), &color); | 672 gfx::ToEnclosingRect(layer_rect), 1.f, &color); |
| 670 if (is_solid_color) { | 673 if (is_solid_color) { |
| 671 tile->draw_info().set_solid_color(color); | 674 tile->draw_info().set_solid_color(color); |
| 672 client_->NotifyTileStateChanged(tile); | 675 client_->NotifyTileStateChanged(tile); |
| 673 continue; | 676 continue; |
| 674 } | 677 } |
| 675 } | 678 } |
| 676 | 679 |
| 677 // Prepaint tiles that are far away are only processed for images. | 680 // Prepaint tiles that are far away are only processed for images. |
| 678 if (!tile->required_for_activation() && !tile->required_for_draw() && | 681 if (!tile->required_for_activation() && !tile->required_for_draw() && |
| 679 prioritized_tile.is_process_for_images_only()) { | 682 prioritized_tile.is_process_for_images_only()) { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 const std::vector<PrioritizedTile>& tiles_to_process_for_images = | 859 const std::vector<PrioritizedTile>& tiles_to_process_for_images = |
| 857 work_to_schedule.tiles_to_process_for_images; | 860 work_to_schedule.tiles_to_process_for_images; |
| 858 std::vector<DrawImage> new_locked_images; | 861 std::vector<DrawImage> new_locked_images; |
| 859 for (const PrioritizedTile& prioritized_tile : tiles_to_process_for_images) { | 862 for (const PrioritizedTile& prioritized_tile : tiles_to_process_for_images) { |
| 860 Tile* tile = prioritized_tile.tile(); | 863 Tile* tile = prioritized_tile.tile(); |
| 861 | 864 |
| 862 // TODO(khushalsagar): Send these images to the ImageDecodeService, through | 865 // TODO(khushalsagar): Send these images to the ImageDecodeService, through |
| 863 // the CheckerImageTracker as well. See crbug.com/691087. | 866 // the CheckerImageTracker as well. See crbug.com/691087. |
| 864 std::vector<DrawImage> images; | 867 std::vector<DrawImage> images; |
| 865 prioritized_tile.raster_source()->GetDiscardableImagesInRect( | 868 prioritized_tile.raster_source()->GetDiscardableImagesInRect( |
| 866 tile->enclosing_layer_rect(), tile->contents_scale(), &images); | 869 tile->enclosing_layer_rect(), tile->raster_transform().scale(), |
| 870 &images); |
| 867 new_locked_images.insert(new_locked_images.end(), images.begin(), | 871 new_locked_images.insert(new_locked_images.end(), images.begin(), |
| 868 images.end()); | 872 images.end()); |
| 869 } | 873 } |
| 870 | 874 |
| 871 // TODO(vmpstr): SOON is misleading here, but these images can come from | 875 // TODO(vmpstr): SOON is misleading here, but these images can come from |
| 872 // several diffent tiles. Rethink what we actually want to trace here. Note | 876 // several diffent tiles. Rethink what we actually want to trace here. Note |
| 873 // that I'm using SOON, since it can't be NOW (these are prepaint). | 877 // that I'm using SOON, since it can't be NOW (these are prepaint). |
| 874 ImageDecodeCache::TracingInfo tracing_info(prepare_tiles_count_, | 878 ImageDecodeCache::TracingInfo tracing_info(prepare_tiles_count_, |
| 875 TilePriority::SOON); | 879 TilePriority::SOON); |
| 876 std::vector<scoped_refptr<TileTask>> new_locked_image_tasks = | 880 std::vector<scoped_refptr<TileTask>> new_locked_image_tasks = |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 playback_settings.skip_images = | 964 playback_settings.skip_images = |
| 961 prioritized_tile.priority().resolution == LOW_RESOLUTION; | 965 prioritized_tile.priority().resolution == LOW_RESOLUTION; |
| 962 | 966 |
| 963 // Create and queue all image decode tasks that this tile depends on. | 967 // Create and queue all image decode tasks that this tile depends on. |
| 964 TileTask::Vector decode_tasks; | 968 TileTask::Vector decode_tasks; |
| 965 std::vector<DrawImage>& images = scheduled_draw_images_[tile->id()]; | 969 std::vector<DrawImage>& images = scheduled_draw_images_[tile->id()]; |
| 966 ImageIdFlatSet images_to_skip; | 970 ImageIdFlatSet images_to_skip; |
| 967 images.clear(); | 971 images.clear(); |
| 968 if (!playback_settings.skip_images) { | 972 if (!playback_settings.skip_images) { |
| 969 prioritized_tile.raster_source()->GetDiscardableImagesInRect( | 973 prioritized_tile.raster_source()->GetDiscardableImagesInRect( |
| 970 tile->enclosing_layer_rect(), tile->contents_scale(), &images); | 974 tile->enclosing_layer_rect(), tile->raster_transform().scale(), |
| 975 &images); |
| 971 checker_image_tracker_.FilterImagesForCheckeringForTile( | 976 checker_image_tracker_.FilterImagesForCheckeringForTile( |
| 972 &images, &images_to_skip, prioritized_tile.tile()->tiling()->tree()); | 977 &images, &images_to_skip, prioritized_tile.tile()->tiling()->tree()); |
| 973 } | 978 } |
| 974 | 979 |
| 975 // We can skip the image hijack canvas if we have no images, or no images to | 980 // We can skip the image hijack canvas if we have no images, or no images to |
| 976 // skip during raster. | 981 // skip during raster. |
| 977 playback_settings.use_image_hijack_canvas = | 982 playback_settings.use_image_hijack_canvas = |
| 978 !images.empty() || !images_to_skip.empty(); | 983 !images.empty() || !images_to_skip.empty(); |
| 979 playback_settings.images_to_skip = std::move(images_to_skip); | 984 playback_settings.images_to_skip = std::move(images_to_skip); |
| 980 | 985 |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1432 all_tile_tasks_completed = false; | 1437 all_tile_tasks_completed = false; |
| 1433 did_notify_all_tile_tasks_completed = false; | 1438 did_notify_all_tile_tasks_completed = false; |
| 1434 } | 1439 } |
| 1435 | 1440 |
| 1436 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule() = default; | 1441 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule() = default; |
| 1437 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule( | 1442 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule( |
| 1438 PrioritizedWorkToSchedule&& other) = default; | 1443 PrioritizedWorkToSchedule&& other) = default; |
| 1439 TileManager::PrioritizedWorkToSchedule::~PrioritizedWorkToSchedule() = default; | 1444 TileManager::PrioritizedWorkToSchedule::~PrioritizedWorkToSchedule() = default; |
| 1440 | 1445 |
| 1441 } // namespace cc | 1446 } // namespace cc |
| OLD | NEW |