Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: cc/tiles/tile_manager.cc

Issue 1208683002: cc: Associate scheduled tasks with a prepare tiles call. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/tiles/tile_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 10
(...skipping 28 matching lines...) Expand all
39 class RasterTaskImpl : public RasterTask { 39 class RasterTaskImpl : public RasterTask {
40 public: 40 public:
41 RasterTaskImpl( 41 RasterTaskImpl(
42 const Resource* resource, 42 const Resource* resource,
43 RasterSource* raster_source, 43 RasterSource* raster_source,
44 const gfx::Rect& content_rect, 44 const gfx::Rect& content_rect,
45 const gfx::Rect& invalid_content_rect, 45 const gfx::Rect& invalid_content_rect,
46 float contents_scale, 46 float contents_scale,
47 TileResolution tile_resolution, 47 TileResolution tile_resolution,
48 int layer_id, 48 int layer_id,
49 uint64_t source_prepare_tiles_id,
49 const void* tile, 50 const void* tile,
50 uint64_t new_content_id, 51 uint64_t new_content_id,
51 uint64_t previous_content_id, 52 uint64_t previous_content_id,
52 uint64_t resource_content_id, 53 uint64_t resource_content_id,
53 int source_frame_number, 54 int source_frame_number,
54 bool analyze_picture, 55 bool analyze_picture,
55 const base::Callback<void(const RasterSource::SolidColorAnalysis&, bool)>& 56 const base::Callback<void(const RasterSource::SolidColorAnalysis&, bool)>&
56 reply, 57 reply,
57 ImageDecodeTask::Vector* dependencies) 58 ImageDecodeTask::Vector* dependencies)
58 : RasterTask(resource, dependencies), 59 : RasterTask(resource, dependencies),
59 raster_source_(raster_source), 60 raster_source_(raster_source),
60 content_rect_(content_rect), 61 content_rect_(content_rect),
61 invalid_content_rect_(invalid_content_rect), 62 invalid_content_rect_(invalid_content_rect),
62 contents_scale_(contents_scale), 63 contents_scale_(contents_scale),
63 tile_resolution_(tile_resolution), 64 tile_resolution_(tile_resolution),
64 layer_id_(layer_id), 65 layer_id_(layer_id),
66 source_prepare_tiles_id_(source_prepare_tiles_id),
65 tile_(tile), 67 tile_(tile),
66 new_content_id_(new_content_id), 68 new_content_id_(new_content_id),
67 previous_content_id_(previous_content_id), 69 previous_content_id_(previous_content_id),
68 resource_content_id_(resource_content_id), 70 resource_content_id_(resource_content_id),
69 source_frame_number_(source_frame_number), 71 source_frame_number_(source_frame_number),
70 analyze_picture_(analyze_picture), 72 analyze_picture_(analyze_picture),
71 reply_(reply) {} 73 reply_(reply) {}
72 74
73 // Overridden from Task: 75 // Overridden from Task:
74 void RunOnWorkerThread() override { 76 void RunOnWorkerThread() override {
75 TRACE_EVENT0("cc", "RasterizerTaskImpl::RunOnWorkerThread"); 77 TRACE_EVENT1("cc", "RasterizerTaskImpl::RunOnWorkerThread",
78 "source_prepare_tiles_id", source_prepare_tiles_id_);
76 79
77 DCHECK(raster_source_.get()); 80 DCHECK(raster_source_.get());
78 DCHECK(raster_buffer_); 81 DCHECK(raster_buffer_);
79 82
80 if (analyze_picture_) { 83 if (analyze_picture_) {
81 Analyze(raster_source_.get()); 84 Analyze(raster_source_.get());
82 if (analysis_.is_solid_color) 85 if (analysis_.is_solid_color)
83 return; 86 return;
84 } 87 }
85 88
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 contents_scale_); 132 contents_scale_);
130 } 133 }
131 134
132 RasterSource::SolidColorAnalysis analysis_; 135 RasterSource::SolidColorAnalysis analysis_;
133 scoped_refptr<RasterSource> raster_source_; 136 scoped_refptr<RasterSource> raster_source_;
134 gfx::Rect content_rect_; 137 gfx::Rect content_rect_;
135 gfx::Rect invalid_content_rect_; 138 gfx::Rect invalid_content_rect_;
136 float contents_scale_; 139 float contents_scale_;
137 TileResolution tile_resolution_; 140 TileResolution tile_resolution_;
138 int layer_id_; 141 int layer_id_;
142 uint64_t source_prepare_tiles_id_;
139 const void* tile_; 143 const void* tile_;
140 uint64_t new_content_id_; 144 uint64_t new_content_id_;
141 uint64_t previous_content_id_; 145 uint64_t previous_content_id_;
142 uint64_t resource_content_id_; 146 uint64_t resource_content_id_;
143 int source_frame_number_; 147 int source_frame_number_;
144 bool analyze_picture_; 148 bool analyze_picture_;
145 const base::Callback<void(const RasterSource::SolidColorAnalysis&, bool)> 149 const base::Callback<void(const RasterSource::SolidColorAnalysis&, bool)>
146 reply_; 150 reply_;
147 scoped_ptr<RasterBuffer> raster_buffer_; 151 scoped_ptr<RasterBuffer> raster_buffer_;
148 152
149 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); 153 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl);
150 }; 154 };
151 155
152 class ImageDecodeTaskImpl : public ImageDecodeTask { 156 class ImageDecodeTaskImpl : public ImageDecodeTask {
153 public: 157 public:
154 ImageDecodeTaskImpl(SkPixelRef* pixel_ref, 158 ImageDecodeTaskImpl(SkPixelRef* pixel_ref,
159 uint64_t source_prepare_tiles_id,
155 const base::Callback<void(bool was_canceled)>& reply) 160 const base::Callback<void(bool was_canceled)>& reply)
156 : pixel_ref_(skia::SharePtr(pixel_ref)), 161 : pixel_ref_(skia::SharePtr(pixel_ref)),
162 source_prepare_tiles_id_(source_prepare_tiles_id),
157 reply_(reply) {} 163 reply_(reply) {}
158 164
159 // Overridden from Task: 165 // Overridden from Task:
160 void RunOnWorkerThread() override { 166 void RunOnWorkerThread() override {
161 TRACE_EVENT0("cc", "ImageDecodeTaskImpl::RunOnWorkerThread"); 167 TRACE_EVENT1("cc", "ImageDecodeTaskImpl::RunOnWorkerThread",
168 "source_prepare_tiles_id", source_prepare_tiles_id_);
162 169
163 devtools_instrumentation::ScopedImageDecodeTask image_decode_task( 170 devtools_instrumentation::ScopedImageDecodeTask image_decode_task(
164 pixel_ref_.get()); 171 pixel_ref_.get());
165 // This will cause the image referred to by pixel ref to be decoded. 172 // This will cause the image referred to by pixel ref to be decoded.
166 pixel_ref_->lockPixels(); 173 pixel_ref_->lockPixels();
167 pixel_ref_->unlockPixels(); 174 pixel_ref_->unlockPixels();
168 175
169 // Release the reference after decoding image to ensure that it is not 176 // Release the reference after decoding image to ensure that it is not
170 // kept alive unless needed. 177 // kept alive unless needed.
171 pixel_ref_.clear(); 178 pixel_ref_.clear();
172 } 179 }
173 180
174 // Overridden from TileTask: 181 // Overridden from TileTask:
175 void ScheduleOnOriginThread(TileTaskClient* client) override {} 182 void ScheduleOnOriginThread(TileTaskClient* client) override {}
176 void CompleteOnOriginThread(TileTaskClient* client) override {} 183 void CompleteOnOriginThread(TileTaskClient* client) override {}
177 void RunReplyOnOriginThread() override { reply_.Run(!HasFinishedRunning()); } 184 void RunReplyOnOriginThread() override { reply_.Run(!HasFinishedRunning()); }
178 185
179 protected: 186 protected:
180 ~ImageDecodeTaskImpl() override {} 187 ~ImageDecodeTaskImpl() override {}
181 188
182 private: 189 private:
183 skia::RefPtr<SkPixelRef> pixel_ref_; 190 skia::RefPtr<SkPixelRef> pixel_ref_;
191 uint64_t source_prepare_tiles_id_;
184 const base::Callback<void(bool was_canceled)> reply_; 192 const base::Callback<void(bool was_canceled)> reply_;
185 193
186 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl); 194 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl);
187 }; 195 };
188 196
189 const char* TaskSetName(TaskSet task_set) { 197 const char* TaskSetName(TaskSet task_set) {
190 switch (task_set) { 198 switch (task_set) {
191 case TileManager::ALL: 199 case TileManager::ALL:
192 return "ALL"; 200 return "ALL";
193 case TileManager::REQUIRED_FOR_ACTIVATION: 201 case TileManager::REQUIRED_FOR_ACTIVATION:
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 task_runner_.get(), 261 task_runner_.get(),
254 base::Bind(&TileManager::CheckIfAllTileTasksCompleted, 262 base::Bind(&TileManager::CheckIfAllTileTasksCompleted,
255 base::Unretained(this))), 263 base::Unretained(this))),
256 more_tiles_need_prepare_check_notifier_( 264 more_tiles_need_prepare_check_notifier_(
257 task_runner_.get(), 265 task_runner_.get(),
258 base::Bind(&TileManager::CheckIfMoreTilesNeedToBePrepared, 266 base::Bind(&TileManager::CheckIfMoreTilesNeedToBePrepared,
259 base::Unretained(this))), 267 base::Unretained(this))),
260 did_notify_ready_to_activate_(false), 268 did_notify_ready_to_activate_(false),
261 did_notify_ready_to_draw_(false), 269 did_notify_ready_to_draw_(false),
262 did_notify_all_tile_tasks_completed_(false), 270 did_notify_all_tile_tasks_completed_(false),
263 has_scheduled_tile_tasks_(false) { 271 has_scheduled_tile_tasks_(false),
272 prepare_tiles_count_(0u) {
264 tile_task_runner_->SetClient(this); 273 tile_task_runner_->SetClient(this);
265 } 274 }
266 275
267 TileManager::~TileManager() { 276 TileManager::~TileManager() {
268 // Reset global state and manage. This should cause 277 // Reset global state and manage. This should cause
269 // our memory usage to drop to zero. 278 // our memory usage to drop to zero.
270 global_state_ = GlobalStateThatImpactsTilePriority(); 279 global_state_ = GlobalStateThatImpactsTilePriority();
271 280
272 TileTaskQueue empty; 281 TileTaskQueue empty;
273 tile_task_runner_->ScheduleTasks(&empty); 282 tile_task_runner_->ScheduleTasks(&empty);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 case REQUIRED_FOR_DRAW: 362 case REQUIRED_FOR_DRAW:
354 ready_to_draw_check_notifier_.Schedule(); 363 ready_to_draw_check_notifier_.Schedule();
355 return; 364 return;
356 } 365 }
357 366
358 NOTREACHED(); 367 NOTREACHED();
359 } 368 }
360 369
361 void TileManager::PrepareTiles( 370 void TileManager::PrepareTiles(
362 const GlobalStateThatImpactsTilePriority& state) { 371 const GlobalStateThatImpactsTilePriority& state) {
363 TRACE_EVENT0("cc", "TileManager::PrepareTiles"); 372 ++prepare_tiles_count_;
373
374 TRACE_EVENT1("cc", "TileManager::PrepareTiles", "prepare_tiles_id",
375 prepare_tiles_count_);
364 376
365 global_state_ = state; 377 global_state_ = state;
366 378
367 // We need to call CheckForCompletedTasks() once in-between each call 379 // We need to call CheckForCompletedTasks() once in-between each call
368 // to ScheduleTasks() to prevent canceled tasks from being scheduled. 380 // to ScheduleTasks() to prevent canceled tasks from being scheduled.
369 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { 381 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) {
370 tile_task_runner_->CheckForCompletedTasks(); 382 tile_task_runner_->CheckForCompletedTasks();
371 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; 383 did_check_for_completed_tasks_since_last_schedule_tasks_ = true;
372 } 384 }
373 385
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 // been called. 691 // been called.
680 orphan_raster_tasks_.clear(); 692 orphan_raster_tasks_.clear();
681 693
682 did_check_for_completed_tasks_since_last_schedule_tasks_ = false; 694 did_check_for_completed_tasks_since_last_schedule_tasks_ = false;
683 } 695 }
684 696
685 scoped_refptr<ImageDecodeTask> TileManager::CreateImageDecodeTask( 697 scoped_refptr<ImageDecodeTask> TileManager::CreateImageDecodeTask(
686 Tile* tile, 698 Tile* tile,
687 SkPixelRef* pixel_ref) { 699 SkPixelRef* pixel_ref) {
688 return make_scoped_refptr(new ImageDecodeTaskImpl( 700 return make_scoped_refptr(new ImageDecodeTaskImpl(
689 pixel_ref, 701 pixel_ref, prepare_tiles_count_,
690 base::Bind(&TileManager::OnImageDecodeTaskCompleted, 702 base::Bind(&TileManager::OnImageDecodeTaskCompleted,
691 base::Unretained(this), 703 base::Unretained(this), tile->layer_id(),
692 tile->layer_id(),
693 base::Unretained(pixel_ref)))); 704 base::Unretained(pixel_ref))));
694 } 705 }
695 706
696 scoped_refptr<RasterTask> TileManager::CreateRasterTask( 707 scoped_refptr<RasterTask> TileManager::CreateRasterTask(
697 const PrioritizedTile& prioritized_tile) { 708 const PrioritizedTile& prioritized_tile) {
698 Tile* tile = prioritized_tile.tile(); 709 Tile* tile = prioritized_tile.tile();
699 uint64_t resource_content_id = 0; 710 uint64_t resource_content_id = 0;
700 scoped_ptr<ScopedResource> resource; 711 scoped_ptr<ScopedResource> resource;
701 if (tile->invalidated_id()) { 712 if (tile->invalidated_id()) {
702 // TODO(danakj): For resources that are in use, we should still grab them 713 // TODO(danakj): For resources that are in use, we should still grab them
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 scoped_refptr<ImageDecodeTask> decode_task = 746 scoped_refptr<ImageDecodeTask> decode_task =
736 CreateImageDecodeTask(tile, pixel_ref); 747 CreateImageDecodeTask(tile, pixel_ref);
737 decode_tasks.push_back(decode_task); 748 decode_tasks.push_back(decode_task);
738 existing_pixel_refs[id] = decode_task; 749 existing_pixel_refs[id] = decode_task;
739 } 750 }
740 751
741 return make_scoped_refptr(new RasterTaskImpl( 752 return make_scoped_refptr(new RasterTaskImpl(
742 const_resource, prioritized_tile.raster_source(), tile->content_rect(), 753 const_resource, prioritized_tile.raster_source(), tile->content_rect(),
743 tile->invalidated_content_rect(), tile->contents_scale(), 754 tile->invalidated_content_rect(), tile->contents_scale(),
744 prioritized_tile.priority().resolution, tile->layer_id(), 755 prioritized_tile.priority().resolution, tile->layer_id(),
745 static_cast<const void*>(tile), tile->id(), tile->invalidated_id(), 756 prepare_tiles_count_, static_cast<const void*>(tile), tile->id(),
746 resource_content_id, tile->source_frame_number(), 757 tile->invalidated_id(), resource_content_id, tile->source_frame_number(),
747 tile->use_picture_analysis(), 758 tile->use_picture_analysis(),
748 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), 759 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this),
749 tile->id(), base::Passed(&resource)), 760 tile->id(), base::Passed(&resource)),
750 &decode_tasks)); 761 &decode_tasks));
751 } 762 }
752 763
753 void TileManager::OnImageDecodeTaskCompleted(int layer_id, 764 void TileManager::OnImageDecodeTaskCompleted(int layer_id,
754 SkPixelRef* pixel_ref, 765 SkPixelRef* pixel_ref,
755 bool was_canceled) { 766 bool was_canceled) {
756 // If the task was canceled, we need to clean it up 767 // If the task was canceled, we need to clean it up
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 result -= other; 1071 result -= other;
1061 return result; 1072 return result;
1062 } 1073 }
1063 1074
1064 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { 1075 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const {
1065 return memory_bytes_ > limit.memory_bytes_ || 1076 return memory_bytes_ > limit.memory_bytes_ ||
1066 resource_count_ > limit.resource_count_; 1077 resource_count_ > limit.resource_count_;
1067 } 1078 }
1068 1079
1069 } // namespace cc 1080 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/tile_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698