| 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/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/numerics/safe_conversions.h" | 19 #include "base/numerics/safe_conversions.h" |
| 20 #include "base/trace_event/trace_event_argument.h" | 20 #include "base/trace_event/trace_event_argument.h" |
| 21 #include "cc/base/histograms.h" | 21 #include "cc/base/histograms.h" |
| 22 #include "cc/debug/devtools_instrumentation.h" | 22 #include "cc/debug/devtools_instrumentation.h" |
| 23 #include "cc/debug/frame_viewer_instrumentation.h" | 23 #include "cc/debug/frame_viewer_instrumentation.h" |
| 24 #include "cc/debug/traced_value.h" | 24 #include "cc/debug/traced_value.h" |
| 25 #include "cc/layers/picture_layer_impl.h" | 25 #include "cc/layers/picture_layer_impl.h" |
| 26 #include "cc/raster/rastering_info.h" |
| 26 #include "cc/raster/task_category.h" | 27 #include "cc/raster/task_category.h" |
| 27 #include "cc/raster/tile_task_runner.h" | 28 #include "cc/raster/tile_task_runner.h" |
| 28 #include "cc/tiles/tile.h" | 29 #include "cc/tiles/tile.h" |
| 29 #include "ui/gfx/geometry/rect_conversions.h" | 30 #include "ui/gfx/geometry/rect_conversions.h" |
| 30 | 31 |
| 31 namespace cc { | 32 namespace cc { |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 // Flag to indicate whether we should try and detect that | 35 // Flag to indicate whether we should try and detect that |
| 35 // a tile is of solid color. | 36 // a tile is of solid color. |
| 36 const bool kUseColorEstimator = true; | 37 const bool kUseColorEstimator = true; |
| 37 | 38 |
| 38 DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER( | 39 DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER( |
| 39 ScopedRasterTaskTimer, | 40 ScopedRasterTaskTimer, |
| 40 "Compositing.%s.RasterTask.RasterUs", | 41 "Compositing.%s.RasterTask.RasterUs", |
| 41 "Compositing.%s.RasterTask.RasterPixelsPerMs"); | 42 "Compositing.%s.RasterTask.RasterPixelsPerMs"); |
| 42 | 43 |
| 43 class RasterTaskImpl : public Task { | 44 class RasterTaskImpl : public Task { |
| 44 public: | 45 public: |
| 45 RasterTaskImpl(RasterBufferProvider* raster_buffer_provider, | 46 RasterTaskImpl(scoped_ptr<RasteringInfo> rastering_info, |
| 46 const Resource* resource, | |
| 47 scoped_refptr<RasterSource> raster_source, | |
| 48 const gfx::Rect& content_rect, | |
| 49 const gfx::Rect& invalid_content_rect, | |
| 50 float contents_scale, | |
| 51 const RasterSource::PlaybackSettings& playback_settings, | |
| 52 TileResolution tile_resolution, | |
| 53 int layer_id, | |
| 54 uint64_t source_prepare_tiles_id, | |
| 55 const void* tile, | |
| 56 uint64_t new_content_id, | |
| 57 uint64_t previous_content_id, | |
| 58 uint64_t resource_content_id, | |
| 59 int source_frame_number, | |
| 60 const base::Callback<void(bool)>& reply, | |
| 61 Task::Vector* dependencies) | 47 Task::Vector* dependencies) |
| 62 : Task(dependencies), | 48 : Task(dependencies), rastering_info_(std::move(rastering_info)) {} |
| 63 raster_buffer_provider_(raster_buffer_provider), | |
| 64 resource_(resource), | |
| 65 raster_source_(std::move(raster_source)), | |
| 66 content_rect_(content_rect), | |
| 67 invalid_content_rect_(invalid_content_rect), | |
| 68 contents_scale_(contents_scale), | |
| 69 playback_settings_(playback_settings), | |
| 70 tile_resolution_(tile_resolution), | |
| 71 layer_id_(layer_id), | |
| 72 source_prepare_tiles_id_(source_prepare_tiles_id), | |
| 73 tile_(tile), | |
| 74 new_content_id_(new_content_id), | |
| 75 previous_content_id_(previous_content_id), | |
| 76 resource_content_id_(resource_content_id), | |
| 77 source_frame_number_(source_frame_number), | |
| 78 reply_(reply) {} | |
| 79 | 49 |
| 80 // Overridden from Task: | 50 // Overridden from Task: |
| 81 void ScheduleOnOriginThread() override { | 51 void ScheduleOnOriginThread() override { |
| 82 DCHECK(raster_buffer_provider_); | 52 DCHECK(rastering_info_->raster_buffer_provider); |
| 83 DCHECK(!raster_buffer_); | 53 DCHECK(!rastering_info_->raster_buffer); |
| 84 raster_buffer_ = raster_buffer_provider_->AcquireBufferForRaster( | 54 rastering_info_->raster_buffer = |
| 85 resource_, resource_content_id_, previous_content_id_); | 55 rastering_info_->raster_buffer_provider->AcquireBufferForRaster( |
| 56 rastering_info_->resource, rastering_info_->resource_content_id, |
| 57 rastering_info_->previous_content_id); |
| 86 } | 58 } |
| 87 | 59 |
| 88 void CompleteOnOriginThread() override { | 60 void CompleteOnOriginThread() override { |
| 89 DCHECK(raster_buffer_provider_); | 61 DCHECK(rastering_info_->raster_buffer_provider); |
| 90 raster_buffer_provider_->ReleaseBufferForRaster(std::move(raster_buffer_)); | 62 rastering_info_->raster_buffer_provider->ReleaseBufferForRaster( |
| 91 reply_.Run(!HasFinishedRunning()); | 63 std::move(rastering_info_->raster_buffer)); |
| 64 rastering_info_->reply.Run(!HasFinishedRunning()); |
| 92 } | 65 } |
| 93 | 66 |
| 94 void RunOnWorkerThread() override { | 67 void RunOnWorkerThread() override { |
| 95 TRACE_EVENT1("cc", "RasterizerTaskImpl::RunOnWorkerThread", | 68 TRACE_EVENT1("cc", "RasterizerTaskImpl::RunOnWorkerThread", |
| 96 "source_prepare_tiles_id", source_prepare_tiles_id_); | 69 "source_prepare_tiles_id", |
| 70 rastering_info_->source_prepare_tiles_id); |
| 97 | 71 |
| 98 DCHECK(raster_source_.get()); | 72 DCHECK(rastering_info_->raster_source.get()); |
| 99 DCHECK(raster_buffer_); | 73 DCHECK(rastering_info_->raster_buffer); |
| 100 | 74 |
| 101 frame_viewer_instrumentation::ScopedRasterTask raster_task( | 75 frame_viewer_instrumentation::ScopedRasterTask raster_task( |
| 102 tile_, tile_resolution_, source_frame_number_, layer_id_); | 76 rastering_info_->tile, rastering_info_->tile_resolution, |
| 77 rastering_info_->source_frame_number, rastering_info_->layer_id); |
| 103 ScopedRasterTaskTimer timer; | 78 ScopedRasterTaskTimer timer; |
| 104 timer.SetArea(content_rect_.size().GetArea()); | 79 timer.SetArea(rastering_info_->content_rect.size().GetArea()); |
| 105 | 80 |
| 106 DCHECK(raster_source_); | 81 DCHECK(rastering_info_->raster_source); |
| 107 | 82 |
| 108 raster_buffer_->Playback(raster_source_.get(), content_rect_, | 83 rastering_info_->raster_buffer->Playback( |
| 109 invalid_content_rect_, new_content_id_, | 84 rastering_info_->raster_source.get(), rastering_info_->content_rect, |
| 110 contents_scale_, playback_settings_); | 85 rastering_info_->invalid_content_rect, rastering_info_->new_content_id, |
| 86 rastering_info_->contents_scale, rastering_info_->playback_settings); |
| 111 } | 87 } |
| 112 | 88 |
| 113 protected: | 89 protected: |
| 114 ~RasterTaskImpl() override { DCHECK(!raster_buffer_); } | 90 ~RasterTaskImpl() override { DCHECK(!rastering_info_->raster_buffer); } |
| 115 | 91 |
| 116 private: | 92 private: |
| 117 RasterBufferProvider* raster_buffer_provider_; | 93 scoped_ptr<RasteringInfo> rastering_info_; |
| 118 const Resource* resource_; | |
| 119 scoped_refptr<RasterSource> raster_source_; | |
| 120 gfx::Rect content_rect_; | |
| 121 gfx::Rect invalid_content_rect_; | |
| 122 float contents_scale_; | |
| 123 RasterSource::PlaybackSettings playback_settings_; | |
| 124 TileResolution tile_resolution_; | |
| 125 int layer_id_; | |
| 126 uint64_t source_prepare_tiles_id_; | |
| 127 const void* tile_; | |
| 128 uint64_t new_content_id_; | |
| 129 uint64_t previous_content_id_; | |
| 130 uint64_t resource_content_id_; | |
| 131 int source_frame_number_; | |
| 132 const base::Callback<void(bool)> reply_; | |
| 133 scoped_ptr<RasterBuffer> raster_buffer_; | |
| 134 | 94 |
| 135 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); | 95 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); |
| 136 }; | 96 }; |
| 137 | 97 |
| 138 // Task priorities that make sure that the task set done tasks run before any | 98 // Task priorities that make sure that the task set done tasks run before any |
| 139 // other remaining tasks. | 99 // other remaining tasks. |
| 140 const size_t kRequiredForActivationDoneTaskPriority = 1u; | 100 const size_t kRequiredForActivationDoneTaskPriority = 1u; |
| 141 const size_t kRequiredForDrawDoneTaskPriority = 2u; | 101 const size_t kRequiredForDrawDoneTaskPriority = 2u; |
| 142 const size_t kAllDoneTaskPriority = 3u; | 102 const size_t kAllDoneTaskPriority = 3u; |
| 143 | 103 |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 *it, prepare_tiles_count_, &task); | 832 *it, prepare_tiles_count_, &task); |
| 873 if (task) | 833 if (task) |
| 874 decode_tasks.push_back(task); | 834 decode_tasks.push_back(task); |
| 875 | 835 |
| 876 if (need_to_unref_when_finished) | 836 if (need_to_unref_when_finished) |
| 877 ++it; | 837 ++it; |
| 878 else | 838 else |
| 879 it = images.erase(it); | 839 it = images.erase(it); |
| 880 } | 840 } |
| 881 | 841 |
| 882 return make_scoped_refptr(new RasterTaskImpl( | 842 scoped_ptr<RasteringInfo> rastering_info = RasteringInfo::Create( |
| 883 tile_task_runner_, resource, prioritized_tile.raster_source(), | 843 tile_task_runner_, resource, prioritized_tile.raster_source(), |
| 884 tile->content_rect(), tile->invalidated_content_rect(), | 844 tile->content_rect(), tile->invalidated_content_rect(), |
| 885 tile->contents_scale(), playback_settings, | 845 tile->contents_scale(), playback_settings, |
| 886 prioritized_tile.priority().resolution, tile->layer_id(), | 846 prioritized_tile.priority().resolution, tile->layer_id(), |
| 887 prepare_tiles_count_, static_cast<const void*>(tile), tile->id(), | 847 prepare_tiles_count_, static_cast<const void*>(tile), tile->id(), |
| 888 tile->invalidated_id(), resource_content_id, tile->source_frame_number(), | 848 tile->invalidated_id(), resource_content_id, tile->source_frame_number(), |
| 889 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), | 849 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), |
| 890 tile->id(), resource), | 850 tile->id(), resource)); |
| 891 &decode_tasks)); | 851 return make_scoped_refptr( |
| 852 new RasterTaskImpl(std::move(rastering_info), &decode_tasks)); |
| 892 } | 853 } |
| 893 | 854 |
| 894 void TileManager::OnRasterTaskCompleted( | 855 void TileManager::OnRasterTaskCompleted( |
| 895 Tile::Id tile_id, | 856 Tile::Id tile_id, |
| 896 Resource* resource, | 857 Resource* resource, |
| 897 bool was_canceled) { | 858 bool was_canceled) { |
| 898 DCHECK(tiles_.find(tile_id) != tiles_.end()); | 859 DCHECK(tiles_.find(tile_id) != tiles_.end()); |
| 899 | 860 |
| 900 Tile* tile = tiles_[tile_id]; | 861 Tile* tile = tiles_[tile_id]; |
| 901 TileDrawInfo& draw_info = tile->draw_info(); | 862 TileDrawInfo& draw_info = tile->draw_info(); |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 void TileManager::Signals::reset() { | 1179 void TileManager::Signals::reset() { |
| 1219 ready_to_activate = false; | 1180 ready_to_activate = false; |
| 1220 did_notify_ready_to_activate = false; | 1181 did_notify_ready_to_activate = false; |
| 1221 ready_to_draw = false; | 1182 ready_to_draw = false; |
| 1222 did_notify_ready_to_draw = false; | 1183 did_notify_ready_to_draw = false; |
| 1223 all_tile_tasks_completed = false; | 1184 all_tile_tasks_completed = false; |
| 1224 did_notify_all_tile_tasks_completed = false; | 1185 did_notify_all_tile_tasks_completed = false; |
| 1225 } | 1186 } |
| 1226 | 1187 |
| 1227 } // namespace cc | 1188 } // namespace cc |
| OLD | NEW |