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/tile_manager.h" | 5 #include "cc/tile_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | |
9 | 8 |
10 #include "base/bind.h" | 9 #include "base/bind.h" |
11 #include "base/command_line.h" | |
12 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
13 #include "base/logging.h" | 11 #include "base/logging.h" |
14 #include "base/stringprintf.h" | |
15 #include "base/threading/thread.h" | |
16 #include "cc/platform_color.h" | 12 #include "cc/platform_color.h" |
17 #include "cc/rendering_stats.h" | 13 #include "cc/raster_worker_pool.h" |
18 #include "cc/resource_pool.h" | 14 #include "cc/resource_pool.h" |
19 #include "cc/switches.h" | |
20 #include "cc/tile.h" | 15 #include "cc/tile.h" |
21 #include "third_party/skia/include/core/SkDevice.h" | 16 |
| 17 namespace cc { |
22 | 18 |
23 namespace { | 19 namespace { |
24 | 20 |
25 const char* kRasterThreadNamePrefix = "CompositorRaster"; | |
26 | |
27 const int kMaxRasterThreads = 64; | |
28 const int kDefaultNumberOfRasterThreads = 1; | |
29 | |
30 // Allow two pending raster tasks per thread. This keeps resource usage | |
31 // low while making sure raster threads aren't unnecessarily idle. | |
32 const int kNumPendingRasterTasksPerThread = 2; | |
33 | |
34 // Determine bin based on three categories of tiles: things we need now, | 21 // Determine bin based on three categories of tiles: things we need now, |
35 // things we need soon, and eventually. | 22 // things we need soon, and eventually. |
36 cc::TileManagerBin BinFromTilePriority(const cc::TilePriority& prio) { | 23 TileManagerBin BinFromTilePriority(const TilePriority& prio) { |
37 | 24 |
38 // The amount of time for which we want to have prepainting coverage. | 25 // The amount of time for which we want to have prepainting coverage. |
39 const double prepainting_window_time_seconds = 1.0; | 26 const double prepainting_window_time_seconds = 1.0; |
40 const double backfling_guard_distance_pixels = 314.0; | 27 const double backfling_guard_distance_pixels = 314.0; |
41 | 28 |
42 // Explicitly limit how far ahead we will prepaint for low and non-low res. | 29 // Explicitly limit how far ahead we will prepaint for low and non-low res. |
43 const double max_lores_paint_distance_pixels = 8192.0; | 30 const double max_lores_paint_distance_pixels = 8192.0; |
44 const double max_hires_paint_distance_pixels = 4096.0; | 31 const double max_hires_paint_distance_pixels = 4096.0; |
45 if (prio.resolution == cc::LOW_RESOLUTION) { | 32 if (prio.resolution == cc::LOW_RESOLUTION) { |
46 if (prio.distance_to_visible_in_pixels > max_lores_paint_distance_pixels) | 33 if (prio.distance_to_visible_in_pixels > max_lores_paint_distance_pixels) |
47 return cc::NEVER_BIN; | 34 return cc::NEVER_BIN; |
48 } | 35 } |
49 else { | 36 else { |
50 if (prio.distance_to_visible_in_pixels > max_hires_paint_distance_pixels) | 37 if (prio.distance_to_visible_in_pixels > max_hires_paint_distance_pixels) |
51 return cc::NEVER_BIN; | 38 return cc::NEVER_BIN; |
52 } | 39 } |
53 | 40 |
54 if (prio.time_to_needed_in_seconds() == std::numeric_limits<float>::max()) | 41 if (prio.time_to_needed_in_seconds() == std::numeric_limits<float>::max()) |
55 return cc::NEVER_BIN; | 42 return NEVER_BIN; |
56 | 43 |
57 if (prio.resolution == cc::NON_IDEAL_RESOLUTION) | 44 if (prio.resolution == NON_IDEAL_RESOLUTION) |
58 return cc::EVENTUALLY_BIN; | 45 return EVENTUALLY_BIN; |
59 | 46 |
60 if (prio.time_to_needed_in_seconds() == 0 || | 47 if (prio.time_to_needed_in_seconds() == 0 || |
61 prio.distance_to_visible_in_pixels < backfling_guard_distance_pixels) | 48 prio.distance_to_visible_in_pixels < backfling_guard_distance_pixels) |
62 return cc::NOW_BIN; | 49 return NOW_BIN; |
63 | 50 |
64 if (prio.time_to_needed_in_seconds() < prepainting_window_time_seconds) | 51 if (prio.time_to_needed_in_seconds() < prepainting_window_time_seconds) |
65 return cc::SOON_BIN; | 52 return SOON_BIN; |
66 | 53 |
67 return cc::EVENTUALLY_BIN; | 54 return EVENTUALLY_BIN; |
68 } | 55 } |
69 | 56 |
70 } // namespace | 57 } // namespace |
71 | 58 |
72 namespace cc { | |
73 | |
74 class RasterThread : public base::Thread { | |
75 public: | |
76 RasterThread(const std::string name) | |
77 : base::Thread(name.c_str()), | |
78 num_pending_tasks_(0) { | |
79 Start(); | |
80 } | |
81 virtual ~RasterThread() { | |
82 Stop(); | |
83 } | |
84 | |
85 int num_pending_tasks() { return num_pending_tasks_; } | |
86 | |
87 void PostRasterTaskAndReply(const tracked_objects::Location& from_here, | |
88 PicturePileImpl* picture_pile, | |
89 uint8_t* mapped_buffer, | |
90 const gfx::Rect& rect, | |
91 float contents_scale, | |
92 RenderingStats* stats, | |
93 const base::Closure& reply) { | |
94 ++num_pending_tasks_; | |
95 message_loop_proxy()->PostTaskAndReply( | |
96 from_here, | |
97 base::Bind(&RunRasterTask, | |
98 base::Unretained(picture_pile), | |
99 mapped_buffer, | |
100 rect, | |
101 contents_scale, | |
102 stats), | |
103 base::Bind(&RasterThread::RunReply, base::Unretained(this), reply)); | |
104 } | |
105 | |
106 void PostImageDecodingTaskAndReply(const tracked_objects::Location& from_here, | |
107 skia::LazyPixelRef* pixel_ref, | |
108 RenderingStats* stats, | |
109 const base::Closure& reply) { | |
110 ++num_pending_tasks_; | |
111 message_loop_proxy()->PostTaskAndReply( | |
112 from_here, | |
113 base::Bind(&RunImageDecodeTask, pixel_ref, stats), | |
114 base::Bind(&RasterThread::RunReply, base::Unretained(this), reply)); | |
115 } | |
116 | |
117 private: | |
118 static void RunRasterTask(PicturePileImpl* picture_pile, | |
119 uint8_t* mapped_buffer, | |
120 const gfx::Rect& rect, | |
121 float contents_scale, | |
122 RenderingStats* stats) { | |
123 TRACE_EVENT0("cc", "RasterThread::RunRasterTask"); | |
124 DCHECK(picture_pile); | |
125 DCHECK(mapped_buffer); | |
126 SkBitmap bitmap; | |
127 bitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); | |
128 bitmap.setPixels(mapped_buffer); | |
129 SkDevice device(bitmap); | |
130 SkCanvas canvas(&device); | |
131 picture_pile->Raster( | |
132 &canvas, | |
133 rect, | |
134 contents_scale, | |
135 stats); | |
136 } | |
137 | |
138 static void RunImageDecodeTask(skia::LazyPixelRef* pixel_ref, | |
139 RenderingStats* stats) { | |
140 TRACE_EVENT0("cc", "RasterThread::RunImageDecodeTask"); | |
141 base::TimeTicks decodeBeginTime = base::TimeTicks::Now(); | |
142 pixel_ref->Decode(); | |
143 stats->totalDeferredImageDecodeTimeInSeconds += | |
144 (base::TimeTicks::Now() - decodeBeginTime).InSecondsF(); | |
145 } | |
146 | |
147 void RunReply(const base::Closure& reply) { | |
148 --num_pending_tasks_; | |
149 reply.Run(); | |
150 } | |
151 | |
152 int num_pending_tasks_; | |
153 | |
154 DISALLOW_COPY_AND_ASSIGN(RasterThread); | |
155 }; | |
156 | |
157 ManagedTileState::ManagedTileState() | 59 ManagedTileState::ManagedTileState() |
158 : can_use_gpu_memory(false), | 60 : can_use_gpu_memory(false), |
159 can_be_freed(true), | 61 can_be_freed(true), |
160 resource_is_being_initialized(false), | 62 resource_is_being_initialized(false), |
161 contents_swizzled(false), | 63 contents_swizzled(false), |
162 need_to_gather_pixel_refs(true), | 64 need_to_gather_pixel_refs(true), |
163 gpu_memmgr_stats_bin(NEVER_BIN) { | 65 gpu_memmgr_stats_bin(NEVER_BIN) { |
164 } | 66 } |
165 | 67 |
166 ManagedTileState::~ManagedTileState() { | 68 ManagedTileState::~ManagedTileState() { |
167 DCHECK(!resource); | 69 DCHECK(!resource); |
168 DCHECK(!resource_is_being_initialized); | 70 DCHECK(!resource_is_being_initialized); |
169 } | 71 } |
170 | 72 |
171 TileManager::TileManager( | 73 TileManager::TileManager( |
172 TileManagerClient* client, | 74 TileManagerClient* client, |
173 ResourceProvider* resource_provider, | 75 ResourceProvider* resource_provider, |
174 size_t num_raster_threads) | 76 size_t num_raster_threads) |
175 : client_(client), | 77 : client_(client), |
176 resource_pool_(ResourcePool::Create(resource_provider)), | 78 resource_pool_(ResourcePool::Create(resource_provider)), |
| 79 raster_worker_(RasterWorkerPool::Create(num_raster_threads)), |
177 manage_tiles_pending_(false), | 80 manage_tiles_pending_(false), |
178 manage_tiles_call_count_(0), | 81 manage_tiles_call_count_(0), |
179 check_for_completed_set_pixels_pending_(false) { | 82 check_for_completed_set_pixels_pending_(false) { |
180 // Initialize all threads. | |
181 const std::string thread_name_prefix = kRasterThreadNamePrefix; | |
182 while (raster_threads_.size() < num_raster_threads) { | |
183 int thread_number = raster_threads_.size() + 1; | |
184 scoped_ptr<RasterThread> thread = make_scoped_ptr( | |
185 new RasterThread(thread_name_prefix + | |
186 StringPrintf("Worker%d", thread_number).c_str())); | |
187 raster_threads_.push_back(thread.Pass()); | |
188 } | |
189 | |
190 ResetBinCounts(); | 83 ResetBinCounts(); |
191 } | 84 } |
192 | 85 |
193 TileManager::~TileManager() { | 86 TileManager::~TileManager() { |
194 // Reset global state and manage. This should cause | 87 // Reset global state and manage. This should cause |
195 // our memory usage to drop to zero. | 88 // our memory usage to drop to zero. |
196 global_state_ = GlobalStateThatImpactsTilePriority(); | 89 global_state_ = GlobalStateThatImpactsTilePriority(); |
197 AssignGpuMemoryToTiles(); | 90 AssignGpuMemoryToTiles(); |
198 // This should finish all pending raster tasks and release any | 91 // This should finish all pending tasks and release any uninitialized |
199 // uninitialized resources. | 92 // resources. |
200 raster_threads_.clear(); | 93 raster_worker_.reset(); |
201 ManageTiles(); | 94 ManageTiles(); |
202 DCHECK(tiles_.size() == 0); | 95 DCHECK(tiles_.size() == 0); |
203 } | 96 } |
204 | 97 |
205 void TileManager::SetGlobalState(const GlobalStateThatImpactsTilePriority& globa
l_state) { | 98 void TileManager::SetGlobalState( |
| 99 const GlobalStateThatImpactsTilePriority& global_state) { |
206 global_state_ = global_state; | 100 global_state_ = global_state; |
207 resource_pool_->SetMaxMemoryUsageBytes(global_state_.memory_limit_in_bytes); | 101 resource_pool_->SetMaxMemoryUsageBytes(global_state_.memory_limit_in_bytes); |
208 ScheduleManageTiles(); | 102 ScheduleManageTiles(); |
209 } | 103 } |
210 | 104 |
211 void TileManager::RegisterTile(Tile* tile) { | 105 void TileManager::RegisterTile(Tile* tile) { |
212 tiles_.push_back(tile); | 106 tiles_.push_back(tile); |
213 ScheduleManageTiles(); | 107 ScheduleManageTiles(); |
214 } | 108 } |
215 | 109 |
216 void TileManager::UnregisterTile(Tile* tile) { | 110 void TileManager::UnregisterTile(Tile* tile) { |
217 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); | 111 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); |
218 it != tiles_with_image_decoding_tasks_.end(); it++) { | 112 it != tiles_with_image_decoding_tasks_.end(); it++) { |
219 if (*it == tile) { | 113 if (*it == tile) { |
220 tiles_with_image_decoding_tasks_.erase(it); | 114 tiles_with_image_decoding_tasks_.erase(it); |
221 break;; | 115 break; |
222 } | 116 } |
223 } | 117 } |
224 for (TileVector::iterator it = tiles_that_need_to_be_rasterized_.begin(); | 118 for (TileVector::iterator it = tiles_that_need_to_be_rasterized_.begin(); |
225 it != tiles_that_need_to_be_rasterized_.end(); it++) { | 119 it != tiles_that_need_to_be_rasterized_.end(); it++) { |
226 if (*it == tile) { | 120 if (*it == tile) { |
227 tiles_that_need_to_be_rasterized_.erase(it); | 121 tiles_that_need_to_be_rasterized_.erase(it); |
228 break; | 122 break; |
229 } | 123 } |
230 } | 124 } |
231 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); it++) { | 125 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); it++) { |
232 if (*it == tile) { | 126 if (*it == tile) { |
233 FreeResourcesForTile(tile); | 127 FreeResourcesForTile(tile); |
234 tiles_.erase(it); | 128 tiles_.erase(it); |
235 return; | 129 return; |
236 } | 130 } |
237 } | 131 } |
238 DCHECK(false) << "Could not find tile version."; | 132 DCHECK(false) << "Could not find tile version."; |
239 } | 133 } |
240 | 134 |
241 void TileManager::WillModifyTilePriority(Tile*, WhichTree tree, const TilePriori
ty& new_priority) { | 135 void TileManager::WillModifyTilePriority( |
| 136 Tile* tile, WhichTree tree, const TilePriority& new_priority) { |
242 // TODO(nduca): Do something smarter if reprioritization turns out to be | 137 // TODO(nduca): Do something smarter if reprioritization turns out to be |
243 // costly. | 138 // costly. |
244 ScheduleManageTiles(); | 139 ScheduleManageTiles(); |
245 } | 140 } |
246 | 141 |
247 void TileManager::ScheduleManageTiles() { | 142 void TileManager::ScheduleManageTiles() { |
248 if (manage_tiles_pending_) | 143 if (manage_tiles_pending_) |
249 return; | 144 return; |
250 client_->ScheduleManageTiles(); | 145 client_->ScheduleManageTiles(); |
251 manage_tiles_pending_ = true; | 146 manage_tiles_pending_ = true; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 // It's now safe to release the pixel buffer. | 270 // It's now safe to release the pixel buffer. |
376 resource_pool_->resource_provider()->releasePixelBuffer( | 271 resource_pool_->resource_provider()->releasePixelBuffer( |
377 tile->managed_state().resource->id()); | 272 tile->managed_state().resource->id()); |
378 | 273 |
379 DidFinishTileInitialization(tile); | 274 DidFinishTileInitialization(tile); |
380 tiles_with_pending_set_pixels_.pop(); | 275 tiles_with_pending_set_pixels_.pop(); |
381 } | 276 } |
382 } | 277 } |
383 | 278 |
384 void TileManager::GetRenderingStats(RenderingStats* stats) { | 279 void TileManager::GetRenderingStats(RenderingStats* stats) { |
385 stats->totalRasterizeTimeInSeconds = | 280 raster_worker_->GetRenderingStats(stats); |
386 rendering_stats_.totalRasterizeTimeInSeconds; | |
387 stats->totalPixelsRasterized = rendering_stats_.totalPixelsRasterized; | |
388 stats->totalDeferredImageDecodeCount = | |
389 rendering_stats_.totalDeferredImageDecodeCount; | |
390 stats->totalDeferredImageCacheHitCount = | 281 stats->totalDeferredImageCacheHitCount = |
391 rendering_stats_.totalDeferredImageCacheHitCount; | 282 rendering_stats_.totalDeferredImageCacheHitCount; |
392 stats->totalImageGatheringCount = rendering_stats_.totalImageGatheringCount; | 283 stats->totalImageGatheringCount = rendering_stats_.totalImageGatheringCount; |
393 stats->totalDeferredImageDecodeTimeInSeconds = | |
394 rendering_stats_.totalDeferredImageDecodeTimeInSeconds; | |
395 stats->totalImageGatheringTimeInSeconds = | 284 stats->totalImageGatheringTimeInSeconds = |
396 rendering_stats_.totalImageGatheringTimeInSeconds; | 285 rendering_stats_.totalImageGatheringTimeInSeconds; |
397 } | 286 } |
398 | 287 |
399 int TileManager::GetTilesInBinCount(TileManagerBin bin, WhichTree tree) { | 288 int TileManager::GetTilesInBinCount(TileManagerBin bin, WhichTree tree) { |
400 DCHECK(bin >= 0); | 289 DCHECK(bin >= 0); |
401 DCHECK(bin < NUM_BINS); | 290 DCHECK(bin < NUM_BINS); |
402 DCHECK(tree >= 0); | 291 DCHECK(tree >= 0); |
403 DCHECK(tree < NUM_TREES); | 292 DCHECK(tree < NUM_TREES); |
404 return tiles_in_bin_count_[bin][tree]; | 293 return tiles_in_bin_count_[bin][tree]; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 tiles_that_need_to_be_rasterized_.end()); | 380 tiles_that_need_to_be_rasterized_.end()); |
492 } | 381 } |
493 | 382 |
494 void TileManager::FreeResourcesForTile(Tile* tile) { | 383 void TileManager::FreeResourcesForTile(Tile* tile) { |
495 ManagedTileState& managed_tile_state = tile->managed_state(); | 384 ManagedTileState& managed_tile_state = tile->managed_state(); |
496 DCHECK(managed_tile_state.can_be_freed); | 385 DCHECK(managed_tile_state.can_be_freed); |
497 if (managed_tile_state.resource) | 386 if (managed_tile_state.resource) |
498 resource_pool_->ReleaseResource(managed_tile_state.resource.Pass()); | 387 resource_pool_->ReleaseResource(managed_tile_state.resource.Pass()); |
499 } | 388 } |
500 | 389 |
501 RasterThread* TileManager::GetFreeRasterThread() { | |
502 RasterThread* thread = 0; | |
503 for (RasterThreadVector::iterator it = raster_threads_.begin(); | |
504 it != raster_threads_.end(); ++it) { | |
505 if ((*it)->num_pending_tasks() == kNumPendingRasterTasksPerThread) | |
506 continue; | |
507 // Check if this is the best thread we've found so far. | |
508 if (!thread || (*it)->num_pending_tasks() < thread->num_pending_tasks()) | |
509 thread = *it; | |
510 } | |
511 return thread; | |
512 } | |
513 | |
514 void TileManager::DispatchMoreTasks() { | 390 void TileManager::DispatchMoreTasks() { |
515 // Because tiles in the image decoding list have higher priorities, we | 391 // Because tiles in the image decoding list have higher priorities, we |
516 // need to process those tiles first before we start to handle the tiles | 392 // need to process those tiles first before we start to handle the tiles |
517 // in the need_to_be_rasterized queue. | 393 // in the need_to_be_rasterized queue. |
518 std::list<Tile*>::iterator it = tiles_with_image_decoding_tasks_.begin(); | 394 std::list<Tile*>::iterator it = tiles_with_image_decoding_tasks_.begin(); |
519 while (it != tiles_with_image_decoding_tasks_.end()) { | 395 while (it != tiles_with_image_decoding_tasks_.end()) { |
520 DispatchImageDecodingTasksForTile(*it); | 396 DispatchImageDecodeTasksForTile(*it); |
521 ManagedTileState& managed_state = (*it)->managed_state(); | 397 ManagedTileState& managed_state = (*it)->managed_state(); |
522 if (managed_state.pending_pixel_refs.empty()) { | 398 if (managed_state.pending_pixel_refs.empty()) { |
523 RasterThread* thread = GetFreeRasterThread(); | 399 if (raster_worker_->IsBusy()) |
524 if (!thread) | |
525 return; | 400 return; |
526 DispatchOneRasterTask(thread, *it); | 401 DispatchOneRasterTask(*it); |
527 tiles_with_image_decoding_tasks_.erase(it++); | 402 tiles_with_image_decoding_tasks_.erase(it++); |
528 } else { | 403 } else { |
529 ++it; | 404 ++it; |
530 } | 405 } |
531 } | 406 } |
532 | 407 |
533 // Process all tiles in the need_to_be_rasterized queue. If a tile has | 408 // Process all tiles in the need_to_be_rasterized queue. If a tile has |
534 // image decoding tasks, put it to the back of the image decoding list. | 409 // image decoding tasks, put it to the back of the image decoding list. |
535 while (!tiles_that_need_to_be_rasterized_.empty()) { | 410 while (!tiles_that_need_to_be_rasterized_.empty()) { |
536 Tile* tile = tiles_that_need_to_be_rasterized_.back(); | 411 Tile* tile = tiles_that_need_to_be_rasterized_.back(); |
537 DispatchImageDecodingTasksForTile(tile); | 412 DispatchImageDecodeTasksForTile(tile); |
538 ManagedTileState& managed_state = tile->managed_state(); | 413 ManagedTileState& managed_state = tile->managed_state(); |
539 if (!managed_state.pending_pixel_refs.empty()) { | 414 if (!managed_state.pending_pixel_refs.empty()) { |
540 tiles_with_image_decoding_tasks_.push_back(tile); | 415 tiles_with_image_decoding_tasks_.push_back(tile); |
541 } else { | 416 } else { |
542 RasterThread* thread = GetFreeRasterThread(); | 417 if (raster_worker_->IsBusy()) |
543 if (!thread) | |
544 return; | 418 return; |
545 DispatchOneRasterTask(thread, tile); | 419 DispatchOneRasterTask(tile); |
546 } | 420 } |
547 tiles_that_need_to_be_rasterized_.pop_back(); | 421 tiles_that_need_to_be_rasterized_.pop_back(); |
548 } | 422 } |
549 } | 423 } |
550 | 424 |
551 void TileManager::GatherPixelRefsForTile(Tile* tile) { | 425 void TileManager::GatherPixelRefsForTile(Tile* tile) { |
552 TRACE_EVENT0("cc", "TileManager::GatherPixelRefsForTile"); | 426 TRACE_EVENT0("cc", "TileManager::GatherPixelRefsForTile"); |
553 ManagedTileState& managed_state = tile->managed_state(); | 427 ManagedTileState& managed_state = tile->managed_state(); |
554 if (managed_state.need_to_gather_pixel_refs) { | 428 if (managed_state.need_to_gather_pixel_refs) { |
555 base::TimeTicks gather_begin_time = base::TimeTicks::Now(); | 429 base::TimeTicks gather_begin_time = base::TimeTicks::Now(); |
556 const_cast<PicturePileImpl *>(tile->picture_pile())->GatherPixelRefs( | 430 const_cast<PicturePileImpl *>(tile->picture_pile())->GatherPixelRefs( |
557 tile->content_rect_, managed_state.pending_pixel_refs); | 431 tile->content_rect_, managed_state.pending_pixel_refs); |
558 rendering_stats_.totalImageGatheringCount++; | 432 rendering_stats_.totalImageGatheringCount++; |
559 rendering_stats_.totalImageGatheringTimeInSeconds += | 433 rendering_stats_.totalImageGatheringTimeInSeconds += |
560 (base::TimeTicks::Now() - gather_begin_time).InSecondsF(); | 434 (base::TimeTicks::Now() - gather_begin_time).InSecondsF(); |
561 managed_state.need_to_gather_pixel_refs = false; | 435 managed_state.need_to_gather_pixel_refs = false; |
562 } | 436 } |
563 } | 437 } |
564 | 438 |
565 void TileManager::DispatchImageDecodingTasksForTile(Tile* tile) { | 439 void TileManager::DispatchImageDecodeTasksForTile(Tile* tile) { |
566 GatherPixelRefsForTile(tile); | 440 GatherPixelRefsForTile(tile); |
567 std::list<skia::LazyPixelRef*>& pending_pixel_refs = | 441 std::list<skia::LazyPixelRef*>& pending_pixel_refs = |
568 tile->managed_state().pending_pixel_refs; | 442 tile->managed_state().pending_pixel_refs; |
569 std::list<skia::LazyPixelRef*>::iterator it = pending_pixel_refs.begin(); | 443 std::list<skia::LazyPixelRef*>::iterator it = pending_pixel_refs.begin(); |
570 while (it != pending_pixel_refs.end()) { | 444 while (it != pending_pixel_refs.end()) { |
571 if (pending_decode_tasks_.end() != pending_decode_tasks_.find( | 445 if (pending_decode_tasks_.end() != pending_decode_tasks_.find( |
572 (*it)->getGenerationID())) { | 446 (*it)->getGenerationID())) { |
573 ++it; | 447 ++it; |
574 continue; | 448 continue; |
575 } | 449 } |
576 // TODO(qinmin): passing correct image size to PrepareToDecode(). | 450 // TODO(qinmin): passing correct image size to PrepareToDecode(). |
577 if ((*it)->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) { | 451 if ((*it)->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) { |
578 rendering_stats_.totalDeferredImageCacheHitCount++; | 452 rendering_stats_.totalDeferredImageCacheHitCount++; |
579 pending_pixel_refs.erase(it++); | 453 pending_pixel_refs.erase(it++); |
580 } else { | 454 } else { |
581 RasterThread* thread = GetFreeRasterThread(); | 455 if (raster_worker_->IsBusy()) |
582 if (!thread) | |
583 return; | 456 return; |
584 DispatchOneImageDecodingTask(thread, tile, *it); | 457 DispatchOneImageDecodeTask(tile, *it); |
585 ++it; | 458 ++it; |
586 } | 459 } |
587 } | 460 } |
588 } | 461 } |
589 | 462 |
590 void TileManager::DispatchOneImageDecodingTask(RasterThread* thread, | 463 void TileManager::DispatchOneImageDecodeTask( |
591 scoped_refptr<Tile> tile, | 464 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref) { |
592 skia::LazyPixelRef* pixel_ref) { | 465 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodeTask"); |
593 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodingTask"); | |
594 uint32_t pixel_ref_id = pixel_ref->getGenerationID(); | 466 uint32_t pixel_ref_id = pixel_ref->getGenerationID(); |
595 DCHECK(pending_decode_tasks_.end() == | 467 DCHECK(pending_decode_tasks_.end() == |
596 pending_decode_tasks_.find(pixel_ref_id)); | 468 pending_decode_tasks_.find(pixel_ref_id)); |
597 pending_decode_tasks_[pixel_ref_id] = pixel_ref; | 469 pending_decode_tasks_[pixel_ref_id] = pixel_ref; |
598 RenderingStats* stats = new RenderingStats(); | |
599 | 470 |
600 thread->PostImageDecodingTaskAndReply( | 471 raster_worker_->PostImageDecodeTaskAndReply( |
601 FROM_HERE, | 472 pixel_ref, |
602 pixel_ref, | 473 base::Bind(&TileManager::OnImageDecodeTaskCompleted, |
603 stats, | 474 base::Unretained(this), |
604 base::Bind(&TileManager::OnImageDecodingTaskCompleted, | 475 tile, |
605 base::Unretained(this), | 476 pixel_ref_id)); |
606 tile, | |
607 pixel_ref_id, | |
608 stats)); | |
609 } | 477 } |
610 | 478 |
611 void TileManager::OnImageDecodingTaskCompleted(scoped_refptr<Tile> tile, | 479 void TileManager::OnImageDecodeTaskCompleted( |
612 uint32_t pixel_ref_id, | 480 scoped_refptr<Tile> tile, uint32_t pixel_ref_id) { |
613 RenderingStats* stats) { | 481 TRACE_EVENT0("cc", "TileManager::OnImageDecodeTaskCompleted"); |
614 TRACE_EVENT0("cc", "TileManager::OnImageDecoded"); | |
615 pending_decode_tasks_.erase(pixel_ref_id); | 482 pending_decode_tasks_.erase(pixel_ref_id); |
616 rendering_stats_.totalDeferredImageDecodeTimeInSeconds += | 483 |
617 stats->totalDeferredImageDecodeTimeInSeconds; | |
618 rendering_stats_.totalDeferredImageDecodeCount++; | |
619 delete stats; | |
620 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); | 484 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); |
621 it != tiles_with_image_decoding_tasks_.end(); ++it) { | 485 it != tiles_with_image_decoding_tasks_.end(); ++it) { |
622 std::list<skia::LazyPixelRef*>& pixel_refs = | 486 std::list<skia::LazyPixelRef*>& pixel_refs = |
623 (*it)->managed_state().pending_pixel_refs; | 487 (*it)->managed_state().pending_pixel_refs; |
624 for (std::list<skia::LazyPixelRef*>::iterator pixel_it = | 488 for (std::list<skia::LazyPixelRef*>::iterator pixel_it = |
625 pixel_refs.begin(); pixel_it != pixel_refs.end(); ++pixel_it) { | 489 pixel_refs.begin(); pixel_it != pixel_refs.end(); ++pixel_it) { |
626 if (pixel_ref_id == (*pixel_it)->getGenerationID()) { | 490 if (pixel_ref_id == (*pixel_it)->getGenerationID()) { |
627 pixel_refs.erase(pixel_it); | 491 pixel_refs.erase(pixel_it); |
628 break; | 492 break; |
629 } | 493 } |
630 } | 494 } |
631 } | 495 } |
| 496 |
632 DispatchMoreTasks(); | 497 DispatchMoreTasks(); |
633 } | 498 } |
634 | 499 |
635 void TileManager::DispatchOneRasterTask( | 500 void TileManager::DispatchOneRasterTask(scoped_refptr<Tile> tile) { |
636 RasterThread* thread, scoped_refptr<Tile> tile) { | |
637 TRACE_EVENT0("cc", "TileManager::DispatchOneRasterTask"); | 501 TRACE_EVENT0("cc", "TileManager::DispatchOneRasterTask"); |
638 ManagedTileState& managed_tile_state = tile->managed_state(); | 502 ManagedTileState& managed_tile_state = tile->managed_state(); |
639 DCHECK(managed_tile_state.can_use_gpu_memory); | 503 DCHECK(managed_tile_state.can_use_gpu_memory); |
640 scoped_ptr<ResourcePool::Resource> resource = | 504 scoped_ptr<ResourcePool::Resource> resource = |
641 resource_pool_->AcquireResource(tile->tile_size_.size(), tile->format_); | 505 resource_pool_->AcquireResource(tile->tile_size_.size(), tile->format_); |
642 resource_pool_->resource_provider()->acquirePixelBuffer(resource->id()); | 506 resource_pool_->resource_provider()->acquirePixelBuffer(resource->id()); |
643 | 507 |
644 managed_tile_state.resource_is_being_initialized = true; | 508 managed_tile_state.resource_is_being_initialized = true; |
645 managed_tile_state.can_be_freed = false; | 509 managed_tile_state.can_be_freed = false; |
646 | 510 |
647 ResourceProvider::ResourceId resource_id = resource->id(); | 511 ResourceProvider::ResourceId resource_id = resource->id(); |
648 scoped_refptr<PicturePileImpl> picture_pile_clone = | |
649 tile->picture_pile()->GetCloneForDrawingOnThread(thread); | |
650 RenderingStats* stats = new RenderingStats(); | |
651 | 512 |
652 thread->PostRasterTaskAndReply( | 513 raster_worker_->PostRasterTaskAndReply( |
653 FROM_HERE, | 514 tile->picture_pile(), |
654 picture_pile_clone.get(), | |
655 resource_pool_->resource_provider()->mapPixelBuffer(resource_id), | 515 resource_pool_->resource_provider()->mapPixelBuffer(resource_id), |
656 tile->content_rect_, | 516 tile->content_rect_, |
657 tile->contents_scale(), | 517 tile->contents_scale(), |
658 stats, | |
659 base::Bind(&TileManager::OnRasterTaskCompleted, | 518 base::Bind(&TileManager::OnRasterTaskCompleted, |
660 base::Unretained(this), | 519 base::Unretained(this), |
661 tile, | 520 tile, |
662 base::Passed(&resource), | 521 base::Passed(&resource), |
663 picture_pile_clone, | 522 manage_tiles_call_count_)); |
664 manage_tiles_call_count_, | |
665 stats)); | |
666 } | 523 } |
667 | 524 |
668 void TileManager::OnRasterTaskCompleted( | 525 void TileManager::OnRasterTaskCompleted( |
669 scoped_refptr<Tile> tile, | 526 scoped_refptr<Tile> tile, |
670 scoped_ptr<ResourcePool::Resource> resource, | 527 scoped_ptr<ResourcePool::Resource> resource, |
671 scoped_refptr<PicturePileImpl> picture_pile_clone, | 528 int manage_tiles_call_count_when_dispatched) { |
672 int manage_tiles_call_count_when_dispatched, | |
673 RenderingStats* stats) { | |
674 TRACE_EVENT0("cc", "TileManager::OnRasterTaskCompleted"); | 529 TRACE_EVENT0("cc", "TileManager::OnRasterTaskCompleted"); |
675 rendering_stats_.totalRasterizeTimeInSeconds += | |
676 stats->totalRasterizeTimeInSeconds; | |
677 rendering_stats_.totalPixelsRasterized += stats->totalPixelsRasterized; | |
678 delete stats; | |
679 | 530 |
680 // Release raster resources. | 531 // Release raster resources. |
681 resource_pool_->resource_provider()->unmapPixelBuffer(resource->id()); | 532 resource_pool_->resource_provider()->unmapPixelBuffer(resource->id()); |
682 | 533 |
683 ManagedTileState& managed_tile_state = tile->managed_state(); | 534 ManagedTileState& managed_tile_state = tile->managed_state(); |
684 managed_tile_state.can_be_freed = true; | 535 managed_tile_state.can_be_freed = true; |
685 | 536 |
686 // Tile can be freed after the completion of the raster task. Call | 537 // Tile can be freed after the completion of the raster task. Call |
687 // AssignGpuMemoryToTiles() to re-assign gpu memory to highest priority | 538 // AssignGpuMemoryToTiles() to re-assign gpu memory to highest priority |
688 // tiles if ManageTiles() was called since task was dispatched. The result | 539 // tiles if ManageTiles() was called since task was dispatched. The result |
(...skipping 17 matching lines...) Expand all Loading... |
706 resource_pool_->resource_provider()->beginSetPixels(resource->id()); | 557 resource_pool_->resource_provider()->beginSetPixels(resource->id()); |
707 managed_tile_state.resource = resource.Pass(); | 558 managed_tile_state.resource = resource.Pass(); |
708 tiles_with_pending_set_pixels_.push(tile); | 559 tiles_with_pending_set_pixels_.push(tile); |
709 | 560 |
710 ScheduleCheckForCompletedSetPixels(); | 561 ScheduleCheckForCompletedSetPixels(); |
711 } else { | 562 } else { |
712 resource_pool_->resource_provider()->releasePixelBuffer(resource->id()); | 563 resource_pool_->resource_provider()->releasePixelBuffer(resource->id()); |
713 resource_pool_->ReleaseResource(resource.Pass()); | 564 resource_pool_->ReleaseResource(resource.Pass()); |
714 managed_tile_state.resource_is_being_initialized = false; | 565 managed_tile_state.resource_is_being_initialized = false; |
715 } | 566 } |
| 567 |
716 DispatchMoreTasks(); | 568 DispatchMoreTasks(); |
717 } | 569 } |
718 | 570 |
719 void TileManager::DidFinishTileInitialization(Tile* tile) { | 571 void TileManager::DidFinishTileInitialization(Tile* tile) { |
720 ManagedTileState& managed_tile_state = tile->managed_state(); | 572 ManagedTileState& managed_tile_state = tile->managed_state(); |
721 DCHECK(managed_tile_state.resource); | 573 DCHECK(managed_tile_state.resource); |
722 managed_tile_state.resource_is_being_initialized = false; | 574 managed_tile_state.resource_is_being_initialized = false; |
723 managed_tile_state.can_be_freed = true; | 575 managed_tile_state.can_be_freed = true; |
724 for (int i = 0; i < NUM_TREES; ++i) | 576 for (int i = 0; i < NUM_TREES; ++i) |
725 drawable_tiles_in_bin_count_[managed_tile_state.bin[i]][i]++; | 577 drawable_tiles_in_bin_count_[managed_tile_state.bin[i]][i]++; |
726 } | 578 } |
727 | 579 |
728 } | 580 } // namespace cc |
OLD | NEW |