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

Side by Side Diff: cc/tile_manager.cc

Issue 11593030: cc: Add RasterWorkerPool class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 | Annotate | Revision Log
« cc/raster_worker.h ('K') | « cc/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/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.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 if (prio.time_to_needed_in_seconds() == std::numeric_limits<float>::max()) 29 if (prio.time_to_needed_in_seconds() == std::numeric_limits<float>::max())
43 return cc::NEVER_BIN; 30 return NEVER_BIN;
44 31
45 if (prio.resolution == cc::NON_IDEAL_RESOLUTION) 32 if (prio.resolution == NON_IDEAL_RESOLUTION)
46 return cc::EVENTUALLY_BIN; 33 return EVENTUALLY_BIN;
47 34
48 if (prio.time_to_needed_in_seconds() == 0 || 35 if (prio.time_to_needed_in_seconds() == 0 ||
49 prio.distance_to_visible_in_pixels < backfling_guard_distance_pixels) 36 prio.distance_to_visible_in_pixels < backfling_guard_distance_pixels)
50 return cc::NOW_BIN; 37 return NOW_BIN;
51 38
52 if (prio.time_to_needed_in_seconds() < prepainting_window_time_seconds) 39 if (prio.time_to_needed_in_seconds() < prepainting_window_time_seconds)
53 return cc::SOON_BIN; 40 return SOON_BIN;
54 41
55 return cc::EVENTUALLY_BIN; 42 return EVENTUALLY_BIN;
56 } 43 }
57 44
58 } // namespace 45 } // namespace
59 46
60 namespace cc {
61
62 class RasterThread : public base::Thread {
63 public:
64 RasterThread(const std::string name)
65 : base::Thread(name.c_str()),
66 num_pending_tasks_(0) {
67 Start();
68 }
69 virtual ~RasterThread() {
70 Stop();
71 }
72
73 int num_pending_tasks() { return num_pending_tasks_; }
74
75 void PostRasterTaskAndReply(const tracked_objects::Location& from_here,
76 PicturePileImpl* picture_pile,
77 uint8_t* mapped_buffer,
78 const gfx::Rect& rect,
79 float contents_scale,
80 RenderingStats* stats,
81 const base::Closure& reply) {
82 ++num_pending_tasks_;
83 message_loop_proxy()->PostTaskAndReply(
84 from_here,
85 base::Bind(&RunRasterTask,
86 base::Unretained(picture_pile),
87 mapped_buffer,
88 rect,
89 contents_scale,
90 stats),
91 base::Bind(&RasterThread::RunReply, base::Unretained(this), reply));
92 }
93
94 void PostImageDecodingTaskAndReply(const tracked_objects::Location& from_here,
95 skia::LazyPixelRef* pixel_ref,
96 RenderingStats* stats,
97 const base::Closure& reply) {
98 ++num_pending_tasks_;
99 message_loop_proxy()->PostTaskAndReply(
100 from_here,
101 base::Bind(&RunImageDecodeTask, pixel_ref, stats),
102 base::Bind(&RasterThread::RunReply, base::Unretained(this), reply));
103 }
104
105 private:
106 static void RunRasterTask(PicturePileImpl* picture_pile,
107 uint8_t* mapped_buffer,
108 const gfx::Rect& rect,
109 float contents_scale,
110 RenderingStats* stats) {
111 TRACE_EVENT0("cc", "RasterThread::RunRasterTask");
112 DCHECK(picture_pile);
113 DCHECK(mapped_buffer);
114 SkBitmap bitmap;
115 bitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height());
116 bitmap.setPixels(mapped_buffer);
117 SkDevice device(bitmap);
118 SkCanvas canvas(&device);
119 picture_pile->Raster(
120 &canvas,
121 rect,
122 contents_scale,
123 stats);
124 }
125
126 static void RunImageDecodeTask(skia::LazyPixelRef* pixel_ref,
127 RenderingStats* stats) {
128 TRACE_EVENT0("cc", "RasterThread::RunImageDecodeTask");
129 base::TimeTicks decodeBeginTime = base::TimeTicks::Now();
130 pixel_ref->Decode();
131 stats->totalDeferredImageDecodeTimeInSeconds +=
132 (base::TimeTicks::Now() - decodeBeginTime).InSecondsF();
133 }
134
135 void RunReply(const base::Closure& reply) {
136 --num_pending_tasks_;
137 reply.Run();
138 }
139
140 int num_pending_tasks_;
141
142 DISALLOW_COPY_AND_ASSIGN(RasterThread);
143 };
144
145 ManagedTileState::ManagedTileState() 47 ManagedTileState::ManagedTileState()
146 : can_use_gpu_memory(false), 48 : can_use_gpu_memory(false),
147 can_be_freed(true), 49 can_be_freed(true),
148 resource_is_being_initialized(false), 50 resource_is_being_initialized(false),
149 contents_swizzled(false), 51 contents_swizzled(false),
150 need_to_gather_pixel_refs(true) { 52 need_to_gather_pixel_refs(true) {
151 } 53 }
152 54
153 ManagedTileState::~ManagedTileState() { 55 ManagedTileState::~ManagedTileState() {
154 DCHECK(!resource); 56 DCHECK(!resource);
155 DCHECK(!resource_is_being_initialized); 57 DCHECK(!resource_is_being_initialized);
156 } 58 }
157 59
158 TileManager::TileManager( 60 TileManager::TileManager(
159 TileManagerClient* client, 61 TileManagerClient* client,
160 ResourceProvider* resource_provider, 62 ResourceProvider* resource_provider,
161 size_t num_raster_threads) 63 size_t num_raster_threads)
162 : client_(client), 64 : client_(client),
163 resource_pool_(ResourcePool::Create(resource_provider)), 65 resource_pool_(ResourcePool::Create(resource_provider)),
66 raster_worker_(RasterWorker::Create(num_raster_threads)),
164 manage_tiles_pending_(false), 67 manage_tiles_pending_(false),
165 manage_tiles_call_count_(0), 68 manage_tiles_call_count_(0),
166 check_for_completed_set_pixels_pending_(false) { 69 check_for_completed_set_pixels_pending_(false) {
167 // Initialize all threads.
168 const std::string thread_name_prefix = kRasterThreadNamePrefix;
169 while (raster_threads_.size() < num_raster_threads) {
170 int thread_number = raster_threads_.size() + 1;
171 scoped_ptr<RasterThread> thread = make_scoped_ptr(
172 new RasterThread(thread_name_prefix +
173 StringPrintf("Worker%d", thread_number).c_str()));
174 raster_threads_.append(thread.Pass());
175 }
176
177 ResetBinCounts(); 70 ResetBinCounts();
178 } 71 }
179 72
180 TileManager::~TileManager() { 73 TileManager::~TileManager() {
181 // Reset global state and manage. This should cause 74 // Reset global state and manage. This should cause
182 // our memory usage to drop to zero. 75 // our memory usage to drop to zero.
183 global_state_ = GlobalStateThatImpactsTilePriority(); 76 global_state_ = GlobalStateThatImpactsTilePriority();
184 AssignGpuMemoryToTiles(); 77 AssignGpuMemoryToTiles();
185 // This should finish all pending raster tasks and release any 78 // This should finish all pending tasks and release any uninitialized
186 // uninitialized resources. 79 // resources.
187 raster_threads_.clear(); 80 raster_worker_.reset();
188 ManageTiles(); 81 ManageTiles();
189 DCHECK(tiles_.size() == 0); 82 DCHECK(tiles_.size() == 0);
190 } 83 }
191 84
192 void TileManager::SetGlobalState(const GlobalStateThatImpactsTilePriority& globa l_state) { 85 void TileManager::SetGlobalState(
86 const GlobalStateThatImpactsTilePriority& global_state) {
193 global_state_ = global_state; 87 global_state_ = global_state;
194 resource_pool_->SetMaxMemoryUsageBytes(global_state_.memory_limit_in_bytes); 88 resource_pool_->SetMaxMemoryUsageBytes(global_state_.memory_limit_in_bytes);
195 ScheduleManageTiles(); 89 ScheduleManageTiles();
196 } 90 }
197 91
198 void TileManager::RegisterTile(Tile* tile) { 92 void TileManager::RegisterTile(Tile* tile) {
199 tiles_.push_back(tile); 93 tiles_.push_back(tile);
200 ScheduleManageTiles(); 94 ScheduleManageTiles();
201 } 95 }
202 96
203 void TileManager::UnregisterTile(Tile* tile) { 97 void TileManager::UnregisterTile(Tile* tile) {
204 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); 98 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin();
205 it != tiles_with_image_decoding_tasks_.end(); it++) { 99 it != tiles_with_image_decoding_tasks_.end(); it++) {
206 if (*it == tile) { 100 if (*it == tile) {
207 tiles_with_image_decoding_tasks_.erase(it); 101 tiles_with_image_decoding_tasks_.erase(it);
208 break;; 102 break;
209 } 103 }
210 } 104 }
211 for (TileVector::iterator it = tiles_that_need_to_be_rasterized_.begin(); 105 for (TileVector::iterator it = tiles_that_need_to_be_rasterized_.begin();
212 it != tiles_that_need_to_be_rasterized_.end(); it++) { 106 it != tiles_that_need_to_be_rasterized_.end(); it++) {
213 if (*it == tile) { 107 if (*it == tile) {
214 tiles_that_need_to_be_rasterized_.erase(it); 108 tiles_that_need_to_be_rasterized_.erase(it);
215 break; 109 break;
216 } 110 }
217 } 111 }
218 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); it++) { 112 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); it++) {
219 if (*it == tile) { 113 if (*it == tile) {
220 FreeResourcesForTile(tile); 114 FreeResourcesForTile(tile);
221 tiles_.erase(it); 115 tiles_.erase(it);
222 return; 116 return;
223 } 117 }
224 } 118 }
225 DCHECK(false) << "Could not find tile version."; 119 DCHECK(false) << "Could not find tile version.";
226 } 120 }
227 121
228 void TileManager::WillModifyTilePriority(Tile*, WhichTree tree, const TilePriori ty& new_priority) { 122 void TileManager::WillModifyTilePriority(
123 Tile* tile, WhichTree tree, const TilePriority& new_priority) {
229 // TODO(nduca): Do something smarter if reprioritization turns out to be 124 // TODO(nduca): Do something smarter if reprioritization turns out to be
230 // costly. 125 // costly.
231 ScheduleManageTiles(); 126 ScheduleManageTiles();
232 } 127 }
233 128
234 void TileManager::ScheduleManageTiles() { 129 void TileManager::ScheduleManageTiles() {
235 if (manage_tiles_pending_) 130 if (manage_tiles_pending_)
236 return; 131 return;
237 client_->ScheduleManageTiles(); 132 client_->ScheduleManageTiles();
238 manage_tiles_pending_ = true; 133 manage_tiles_pending_ = true;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 // It's now safe to release the pixel buffer. 256 // It's now safe to release the pixel buffer.
362 resource_pool_->resource_provider()->releasePixelBuffer( 257 resource_pool_->resource_provider()->releasePixelBuffer(
363 tile->managed_state().resource->id()); 258 tile->managed_state().resource->id());
364 259
365 DidFinishTileInitialization(tile); 260 DidFinishTileInitialization(tile);
366 tiles_with_pending_set_pixels_.pop(); 261 tiles_with_pending_set_pixels_.pop();
367 } 262 }
368 } 263 }
369 264
370 void TileManager::GetRenderingStats(RenderingStats* stats) { 265 void TileManager::GetRenderingStats(RenderingStats* stats) {
371 stats->totalRasterizeTimeInSeconds = 266 raster_worker_->GetRenderingStats(stats);
372 rendering_stats_.totalRasterizeTimeInSeconds;
373 stats->totalPixelsRasterized = rendering_stats_.totalPixelsRasterized;
374 stats->totalDeferredImageDecodeCount =
375 rendering_stats_.totalDeferredImageDecodeCount;
376 stats->totalDeferredImageCacheHitCount = 267 stats->totalDeferredImageCacheHitCount =
377 rendering_stats_.totalDeferredImageCacheHitCount; 268 rendering_stats_.totalDeferredImageCacheHitCount;
378 stats->totalImageGatheringCount = rendering_stats_.totalImageGatheringCount; 269 stats->totalImageGatheringCount = rendering_stats_.totalImageGatheringCount;
379 stats->totalDeferredImageDecodeTimeInSeconds =
380 rendering_stats_.totalDeferredImageDecodeTimeInSeconds;
381 stats->totalImageGatheringTimeInSeconds = 270 stats->totalImageGatheringTimeInSeconds =
382 rendering_stats_.totalImageGatheringTimeInSeconds; 271 rendering_stats_.totalImageGatheringTimeInSeconds;
383 } 272 }
384 273
385 int TileManager::GetTilesInBinCount(TileManagerBin bin, WhichTree tree) { 274 int TileManager::GetTilesInBinCount(TileManagerBin bin, WhichTree tree) {
386 DCHECK(bin >= 0); 275 DCHECK(bin >= 0);
387 DCHECK(bin < NUM_BINS); 276 DCHECK(bin < NUM_BINS);
388 DCHECK(tree >= 0); 277 DCHECK(tree >= 0);
389 DCHECK(tree < NUM_TREES); 278 DCHECK(tree < NUM_TREES);
390 return tiles_in_bin_count_[bin][tree]; 279 return tiles_in_bin_count_[bin][tree];
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 tiles_that_need_to_be_rasterized_.end()); 346 tiles_that_need_to_be_rasterized_.end());
458 } 347 }
459 348
460 void TileManager::FreeResourcesForTile(Tile* tile) { 349 void TileManager::FreeResourcesForTile(Tile* tile) {
461 ManagedTileState& managed_tile_state = tile->managed_state(); 350 ManagedTileState& managed_tile_state = tile->managed_state();
462 DCHECK(managed_tile_state.can_be_freed); 351 DCHECK(managed_tile_state.can_be_freed);
463 if (managed_tile_state.resource) 352 if (managed_tile_state.resource)
464 resource_pool_->ReleaseResource(managed_tile_state.resource.Pass()); 353 resource_pool_->ReleaseResource(managed_tile_state.resource.Pass());
465 } 354 }
466 355
467 RasterThread* TileManager::GetFreeRasterThread() {
468 RasterThread* thread = 0;
469 for (RasterThreadVector::iterator it = raster_threads_.begin();
470 it != raster_threads_.end(); ++it) {
471 if ((*it)->num_pending_tasks() == kNumPendingRasterTasksPerThread)
472 continue;
473 // Check if this is the best thread we've found so far.
474 if (!thread || (*it)->num_pending_tasks() < thread->num_pending_tasks())
475 thread = *it;
476 }
477 return thread;
478 }
479
480 void TileManager::DispatchMoreTasks() { 356 void TileManager::DispatchMoreTasks() {
481 // Because tiles in the image decoding list have higher priorities, we 357 // Because tiles in the image decoding list have higher priorities, we
482 // need to process those tiles first before we start to handle the tiles 358 // need to process those tiles first before we start to handle the tiles
483 // in the need_to_be_rasterized queue. 359 // in the need_to_be_rasterized queue.
484 std::list<Tile*>::iterator it = tiles_with_image_decoding_tasks_.begin(); 360 std::list<Tile*>::iterator it = tiles_with_image_decoding_tasks_.begin();
485 while (it != tiles_with_image_decoding_tasks_.end()) { 361 while (it != tiles_with_image_decoding_tasks_.end()) {
486 DispatchImageDecodingTasksForTile(*it); 362 DispatchImageDecodingTasksForTile(*it);
487 ManagedTileState& managed_state = (*it)->managed_state(); 363 ManagedTileState& managed_state = (*it)->managed_state();
488 if (managed_state.pending_pixel_refs.empty()) { 364 if (managed_state.pending_pixel_refs.empty()) {
489 RasterThread* thread = GetFreeRasterThread(); 365 if (raster_worker_->IsBusy())
nduca 2012/12/19 04:46:50 how about making it bool DispatchOneBlahBlah? In t
reveman 2012/12/27 15:26:58 Makes sense. It will be easy to do this once resou
490 if (!thread)
491 return; 366 return;
492 DispatchOneRasterTask(thread, *it); 367 DispatchOneRasterTask(*it);
493 tiles_with_image_decoding_tasks_.erase(it++); 368 tiles_with_image_decoding_tasks_.erase(it++);
494 } else { 369 } else {
495 ++it; 370 ++it;
496 } 371 }
497 } 372 }
498 373
499 // Process all tiles in the need_to_be_rasterized queue. If a tile has 374 // Process all tiles in the need_to_be_rasterized queue. If a tile has
500 // image decoding tasks, put it to the back of the image decoding list. 375 // image decoding tasks, put it to the back of the image decoding list.
501 while (!tiles_that_need_to_be_rasterized_.empty()) { 376 while (!tiles_that_need_to_be_rasterized_.empty()) {
502 Tile* tile = tiles_that_need_to_be_rasterized_.back(); 377 Tile* tile = tiles_that_need_to_be_rasterized_.back();
503 DispatchImageDecodingTasksForTile(tile); 378 DispatchImageDecodingTasksForTile(tile);
504 ManagedTileState& managed_state = tile->managed_state(); 379 ManagedTileState& managed_state = tile->managed_state();
505 if (!managed_state.pending_pixel_refs.empty()) { 380 if (!managed_state.pending_pixel_refs.empty()) {
506 tiles_with_image_decoding_tasks_.push_back(tile); 381 tiles_with_image_decoding_tasks_.push_back(tile);
507 } else { 382 } else {
508 RasterThread* thread = GetFreeRasterThread(); 383 if (raster_worker_->IsBusy())
509 if (!thread)
510 return; 384 return;
511 DispatchOneRasterTask(thread, tile); 385 DispatchOneRasterTask(tile);
512 } 386 }
513 tiles_that_need_to_be_rasterized_.pop_back(); 387 tiles_that_need_to_be_rasterized_.pop_back();
514 } 388 }
515 } 389 }
516 390
517 void TileManager::GatherPixelRefsForTile(Tile* tile) { 391 void TileManager::GatherPixelRefsForTile(Tile* tile) {
518 TRACE_EVENT0("cc", "TileManager::GatherPixelRefsForTile"); 392 TRACE_EVENT0("cc", "TileManager::GatherPixelRefsForTile");
519 ManagedTileState& managed_state = tile->managed_state(); 393 ManagedTileState& managed_state = tile->managed_state();
520 if (managed_state.need_to_gather_pixel_refs) { 394 if (managed_state.need_to_gather_pixel_refs) {
521 base::TimeTicks gather_begin_time = base::TimeTicks::Now(); 395 base::TimeTicks gather_begin_time = base::TimeTicks::Now();
(...skipping 15 matching lines...) Expand all
537 if (pending_decode_tasks_.end() != pending_decode_tasks_.find( 411 if (pending_decode_tasks_.end() != pending_decode_tasks_.find(
538 (*it)->getGenerationID())) { 412 (*it)->getGenerationID())) {
539 ++it; 413 ++it;
540 continue; 414 continue;
541 } 415 }
542 // TODO(qinmin): passing correct image size to PrepareToDecode(). 416 // TODO(qinmin): passing correct image size to PrepareToDecode().
543 if ((*it)->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) { 417 if ((*it)->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) {
544 rendering_stats_.totalDeferredImageCacheHitCount++; 418 rendering_stats_.totalDeferredImageCacheHitCount++;
545 pending_pixel_refs.erase(it++); 419 pending_pixel_refs.erase(it++);
546 } else { 420 } else {
547 RasterThread* thread = GetFreeRasterThread(); 421 if (raster_worker_->IsBusy())
548 if (!thread)
549 return; 422 return;
550 DispatchOneImageDecodingTask(thread, tile, *it); 423 DispatchOneImageDecodingTask(tile, *it);
551 ++it; 424 ++it;
552 } 425 }
553 } 426 }
554 } 427 }
555 428
556 void TileManager::DispatchOneImageDecodingTask(RasterThread* thread, 429 void TileManager::DispatchOneImageDecodingTask(
557 scoped_refptr<Tile> tile, 430 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref) {
558 skia::LazyPixelRef* pixel_ref) {
559 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodingTask"); 431 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodingTask");
560 uint32_t pixel_ref_id = pixel_ref->getGenerationID(); 432 uint32_t pixel_ref_id = pixel_ref->getGenerationID();
561 DCHECK(pending_decode_tasks_.end() == 433 DCHECK(pending_decode_tasks_.end() ==
562 pending_decode_tasks_.find(pixel_ref_id)); 434 pending_decode_tasks_.find(pixel_ref_id));
563 pending_decode_tasks_[pixel_ref_id] = pixel_ref; 435 pending_decode_tasks_[pixel_ref_id] = pixel_ref;
564 RenderingStats* stats = new RenderingStats();
565 436
566 thread->PostImageDecodingTaskAndReply( 437 raster_worker_->PostImageDecodingTaskAndReply(
567 FROM_HERE, 438 pixel_ref,
568 pixel_ref, 439 base::Bind(&TileManager::OnImageDecodingTaskCompleted,
569 stats, 440 base::Unretained(this),
570 base::Bind(&TileManager::OnImageDecodingTaskCompleted, 441 tile,
571 base::Unretained(this), 442 pixel_ref_id));
572 tile,
573 pixel_ref_id,
574 stats));
575 } 443 }
576 444
577 void TileManager::OnImageDecodingTaskCompleted(scoped_refptr<Tile> tile, 445 void TileManager::OnImageDecodingTaskCompleted(
578 uint32_t pixel_ref_id, 446 scoped_refptr<Tile> tile, uint32_t pixel_ref_id) {
579 RenderingStats* stats) { 447 TRACE_EVENT0("cc", "TileManager::OnImageDecodingTaskCompleted");
580 TRACE_EVENT0("cc", "TileManager::OnImageDecoded");
581 pending_decode_tasks_.erase(pixel_ref_id); 448 pending_decode_tasks_.erase(pixel_ref_id);
582 rendering_stats_.totalDeferredImageDecodeTimeInSeconds += 449
583 stats->totalDeferredImageDecodeTimeInSeconds;
584 rendering_stats_.totalDeferredImageDecodeCount++;
585 delete stats;
586 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); 450 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin();
587 it != tiles_with_image_decoding_tasks_.end(); ++it) { 451 it != tiles_with_image_decoding_tasks_.end(); ++it) {
588 std::list<skia::LazyPixelRef*>& pixel_refs = 452 std::list<skia::LazyPixelRef*>& pixel_refs =
589 (*it)->managed_state().pending_pixel_refs; 453 (*it)->managed_state().pending_pixel_refs;
590 for (std::list<skia::LazyPixelRef*>::iterator pixel_it = 454 for (std::list<skia::LazyPixelRef*>::iterator pixel_it =
591 pixel_refs.begin(); pixel_it != pixel_refs.end(); ++pixel_it) { 455 pixel_refs.begin(); pixel_it != pixel_refs.end(); ++pixel_it) {
592 if (pixel_ref_id == (*pixel_it)->getGenerationID()) { 456 if (pixel_ref_id == (*pixel_it)->getGenerationID()) {
593 pixel_refs.erase(pixel_it); 457 pixel_refs.erase(pixel_it);
594 break; 458 break;
595 } 459 }
596 } 460 }
597 } 461 }
462
598 DispatchMoreTasks(); 463 DispatchMoreTasks();
599 } 464 }
600 465
601 void TileManager::DispatchOneRasterTask( 466 void TileManager::DispatchOneRasterTask(scoped_refptr<Tile> tile) {
602 RasterThread* thread, scoped_refptr<Tile> tile) {
603 TRACE_EVENT0("cc", "TileManager::DispatchOneRasterTask"); 467 TRACE_EVENT0("cc", "TileManager::DispatchOneRasterTask");
604 ManagedTileState& managed_tile_state = tile->managed_state(); 468 ManagedTileState& managed_tile_state = tile->managed_state();
605 DCHECK(managed_tile_state.can_use_gpu_memory); 469 DCHECK(managed_tile_state.can_use_gpu_memory);
606 scoped_ptr<ResourcePool::Resource> resource = 470 scoped_ptr<ResourcePool::Resource> resource =
607 resource_pool_->AcquireResource(tile->tile_size_.size(), tile->format_); 471 resource_pool_->AcquireResource(tile->tile_size_.size(), tile->format_);
608 resource_pool_->resource_provider()->acquirePixelBuffer(resource->id()); 472 resource_pool_->resource_provider()->acquirePixelBuffer(resource->id());
609 473
610 managed_tile_state.resource_is_being_initialized = true; 474 managed_tile_state.resource_is_being_initialized = true;
611 managed_tile_state.can_be_freed = false; 475 managed_tile_state.can_be_freed = false;
612 476
613 ResourceProvider::ResourceId resource_id = resource->id(); 477 ResourceProvider::ResourceId resource_id = resource->id();
614 scoped_refptr<PicturePileImpl> picture_pile_clone =
615 tile->picture_pile()->GetCloneForDrawingOnThread(thread);
616 RenderingStats* stats = new RenderingStats();
617 478
618 thread->PostRasterTaskAndReply( 479 raster_worker_->PostRasterTaskAndReply(
619 FROM_HERE, 480 tile->picture_pile(),
620 picture_pile_clone.get(),
621 resource_pool_->resource_provider()->mapPixelBuffer(resource_id), 481 resource_pool_->resource_provider()->mapPixelBuffer(resource_id),
622 tile->content_rect_, 482 tile->content_rect_,
623 tile->contents_scale(), 483 tile->contents_scale(),
624 stats,
625 base::Bind(&TileManager::OnRasterTaskCompleted, 484 base::Bind(&TileManager::OnRasterTaskCompleted,
626 base::Unretained(this), 485 base::Unretained(this),
627 tile, 486 tile,
628 base::Passed(&resource), 487 base::Passed(&resource),
629 picture_pile_clone, 488 manage_tiles_call_count_));
630 manage_tiles_call_count_,
631 stats));
632 } 489 }
633 490
634 void TileManager::OnRasterTaskCompleted( 491 void TileManager::OnRasterTaskCompleted(
635 scoped_refptr<Tile> tile, 492 scoped_refptr<Tile> tile,
636 scoped_ptr<ResourcePool::Resource> resource, 493 scoped_ptr<ResourcePool::Resource> resource,
637 scoped_refptr<PicturePileImpl> picture_pile_clone, 494 int manage_tiles_call_count_when_dispatched) {
638 int manage_tiles_call_count_when_dispatched,
639 RenderingStats* stats) {
640 TRACE_EVENT0("cc", "TileManager::OnRasterTaskCompleted"); 495 TRACE_EVENT0("cc", "TileManager::OnRasterTaskCompleted");
641 rendering_stats_.totalRasterizeTimeInSeconds +=
642 stats->totalRasterizeTimeInSeconds;
643 rendering_stats_.totalPixelsRasterized += stats->totalPixelsRasterized;
644 delete stats;
645 496
646 // Release raster resources. 497 // Release raster resources.
nduca 2012/12/19 04:46:50 I guess I'm a bit confused about why this is stuff
reveman 2012/12/27 15:26:58 I was planning to do some of that in a second patc
647 resource_pool_->resource_provider()->unmapPixelBuffer(resource->id()); 498 resource_pool_->resource_provider()->unmapPixelBuffer(resource->id());
648 499
649 ManagedTileState& managed_tile_state = tile->managed_state(); 500 ManagedTileState& managed_tile_state = tile->managed_state();
650 managed_tile_state.can_be_freed = true; 501 managed_tile_state.can_be_freed = true;
651 502
652 // Tile can be freed after the completion of the raster task. Call 503 // Tile can be freed after the completion of the raster task. Call
653 // AssignGpuMemoryToTiles() to re-assign gpu memory to highest priority 504 // AssignGpuMemoryToTiles() to re-assign gpu memory to highest priority
654 // tiles if ManageTiles() was called since task was dispatched. The result 505 // tiles if ManageTiles() was called since task was dispatched. The result
655 // of this could be that this tile is no longer allowed to use gpu 506 // of this could be that this tile is no longer allowed to use gpu
656 // memory and in that case we need to abort initialization and free all 507 // memory and in that case we need to abort initialization and free all
(...skipping 15 matching lines...) Expand all
672 resource_pool_->resource_provider()->beginSetPixels(resource->id()); 523 resource_pool_->resource_provider()->beginSetPixels(resource->id());
673 managed_tile_state.resource = resource.Pass(); 524 managed_tile_state.resource = resource.Pass();
674 tiles_with_pending_set_pixels_.push(tile); 525 tiles_with_pending_set_pixels_.push(tile);
675 526
676 ScheduleCheckForCompletedSetPixels(); 527 ScheduleCheckForCompletedSetPixels();
677 } else { 528 } else {
678 resource_pool_->resource_provider()->releasePixelBuffer(resource->id()); 529 resource_pool_->resource_provider()->releasePixelBuffer(resource->id());
679 resource_pool_->ReleaseResource(resource.Pass()); 530 resource_pool_->ReleaseResource(resource.Pass());
680 managed_tile_state.resource_is_being_initialized = false; 531 managed_tile_state.resource_is_being_initialized = false;
681 } 532 }
533
682 DispatchMoreTasks(); 534 DispatchMoreTasks();
683 } 535 }
684 536
685 void TileManager::DidFinishTileInitialization(Tile* tile) { 537 void TileManager::DidFinishTileInitialization(Tile* tile) {
686 ManagedTileState& managed_tile_state = tile->managed_state(); 538 ManagedTileState& managed_tile_state = tile->managed_state();
687 DCHECK(managed_tile_state.resource); 539 DCHECK(managed_tile_state.resource);
688 managed_tile_state.resource_is_being_initialized = false; 540 managed_tile_state.resource_is_being_initialized = false;
689 managed_tile_state.can_be_freed = true; 541 managed_tile_state.can_be_freed = true;
690 for (int i = 0; i < NUM_TREES; ++i) 542 for (int i = 0; i < NUM_TREES; ++i)
691 drawable_tiles_in_bin_count_[managed_tile_state.bin[i]][i]++; 543 drawable_tiles_in_bin_count_[managed_tile_state.bin[i]][i]++;
692 } 544 }
693 545
694 } 546 } // namespace cc
OLDNEW
« cc/raster_worker.h ('K') | « cc/tile_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698