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> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 base::Unretained(picture_pile), | 62 base::Unretained(picture_pile), |
63 mapped_buffer, | 63 mapped_buffer, |
64 rect, | 64 rect, |
65 contents_scale, | 65 contents_scale, |
66 stats), | 66 stats), |
67 base::Bind(&RasterThread::RunReply, base::Unretained(this), reply)); | 67 base::Bind(&RasterThread::RunReply, base::Unretained(this), reply)); |
68 } | 68 } |
69 | 69 |
70 void PostImageDecodingTaskAndReply(const tracked_objects::Location& from_here, | 70 void PostImageDecodingTaskAndReply(const tracked_objects::Location& from_here, |
71 skia::LazyPixelRef* pixel_ref, | 71 skia::LazyPixelRef* pixel_ref, |
| 72 RenderingStats* stats, |
72 const base::Closure& reply) { | 73 const base::Closure& reply) { |
73 ++num_pending_tasks_; | 74 ++num_pending_tasks_; |
74 message_loop_proxy()->PostTaskAndReply( | 75 message_loop_proxy()->PostTaskAndReply( |
75 from_here, | 76 from_here, |
76 base::Bind(&RunImageDecodeTask, base::Unretained(pixel_ref)), | 77 base::Bind(&RunImageDecodeTask, pixel_ref, stats), |
77 base::Bind(&RasterThread::RunReply, base::Unretained(this), reply)); | 78 base::Bind(&RasterThread::RunReply, base::Unretained(this), reply)); |
78 } | 79 } |
79 | 80 |
80 private: | 81 private: |
81 static void RunRasterTask(PicturePileImpl* picture_pile, | 82 static void RunRasterTask(PicturePileImpl* picture_pile, |
82 uint8_t* mapped_buffer, | 83 uint8_t* mapped_buffer, |
83 const gfx::Rect& rect, | 84 const gfx::Rect& rect, |
84 float contents_scale, | 85 float contents_scale, |
85 RenderingStats* stats) { | 86 RenderingStats* stats) { |
86 TRACE_EVENT0("cc", "RasterThread::RunRasterTask"); | 87 TRACE_EVENT0("cc", "RasterThread::RunRasterTask"); |
87 DCHECK(picture_pile); | 88 DCHECK(picture_pile); |
88 DCHECK(mapped_buffer); | 89 DCHECK(mapped_buffer); |
89 SkBitmap bitmap; | 90 SkBitmap bitmap; |
90 bitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); | 91 bitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); |
91 bitmap.setPixels(mapped_buffer); | 92 bitmap.setPixels(mapped_buffer); |
92 SkDevice device(bitmap); | 93 SkDevice device(bitmap); |
93 SkCanvas canvas(&device); | 94 SkCanvas canvas(&device); |
94 picture_pile->Raster( | 95 picture_pile->Raster( |
95 &canvas, | 96 &canvas, |
96 rect, | 97 rect, |
97 contents_scale, | 98 contents_scale, |
98 stats); | 99 stats); |
99 } | 100 } |
100 | 101 |
101 static void RunImageDecodeTask(skia::LazyPixelRef* pixel_ref) { | 102 static void RunImageDecodeTask(skia::LazyPixelRef* pixel_ref, |
| 103 RenderingStats* stats) { |
102 TRACE_EVENT0("cc", "RasterThread::RunImageDecodeTask"); | 104 TRACE_EVENT0("cc", "RasterThread::RunImageDecodeTask"); |
| 105 base::TimeTicks decodeBeginTime = base::TimeTicks::Now(); |
103 pixel_ref->Decode(); | 106 pixel_ref->Decode(); |
| 107 stats->totalDeferredImageDecodeTimeInSeconds += |
| 108 (base::TimeTicks::Now() - decodeBeginTime).InSecondsF(); |
104 } | 109 } |
105 | 110 |
106 void RunReply(const base::Closure& reply) { | 111 void RunReply(const base::Closure& reply) { |
107 --num_pending_tasks_; | 112 --num_pending_tasks_; |
108 reply.Run(); | 113 reply.Run(); |
109 } | 114 } |
110 | 115 |
111 int num_pending_tasks_; | 116 int num_pending_tasks_; |
112 | 117 |
113 DISALLOW_COPY_AND_ASSIGN(RasterThread); | 118 DISALLOW_COPY_AND_ASSIGN(RasterThread); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 resource_pool_->resource_provider()->releasePixelBuffer( | 327 resource_pool_->resource_provider()->releasePixelBuffer( |
323 tile->managed_state().resource->id()); | 328 tile->managed_state().resource->id()); |
324 | 329 |
325 DidFinishTileInitialization(tile); | 330 DidFinishTileInitialization(tile); |
326 tiles_with_pending_set_pixels_.pop(); | 331 tiles_with_pending_set_pixels_.pop(); |
327 } | 332 } |
328 } | 333 } |
329 | 334 |
330 void TileManager::renderingStats(RenderingStats* stats) { | 335 void TileManager::renderingStats(RenderingStats* stats) { |
331 stats->totalRasterizeTimeInSeconds = | 336 stats->totalRasterizeTimeInSeconds = |
332 rendering_stats_.totalRasterizeTimeInSeconds; | 337 rendering_stats_.totalRasterizeTimeInSeconds; |
333 stats->totalPixelsRasterized = rendering_stats_.totalPixelsRasterized; | 338 stats->totalPixelsRasterized = rendering_stats_.totalPixelsRasterized; |
| 339 stats->totalDeferredImageDecodeCount = |
| 340 rendering_stats_.totalDeferredImageDecodeCount; |
| 341 stats->totalDeferredImageCacheHitCount = |
| 342 rendering_stats_.totalDeferredImageCacheHitCount; |
| 343 stats->totalImageGatheringCount = rendering_stats_.totalImageGatheringCount; |
| 344 stats->totalDeferredImageDecodeTimeInSeconds = |
| 345 rendering_stats_.totalDeferredImageDecodeTimeInSeconds; |
| 346 stats->totalImageGatheringTimeInSeconds = |
| 347 rendering_stats_.totalImageGatheringTimeInSeconds; |
334 } | 348 } |
335 | 349 |
336 void TileManager::AssignGpuMemoryToTiles() { | 350 void TileManager::AssignGpuMemoryToTiles() { |
337 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); | 351 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); |
338 // Some memory cannot be released. Figure out which. | 352 // Some memory cannot be released. Figure out which. |
339 size_t unreleasable_bytes = 0; | 353 size_t unreleasable_bytes = 0; |
340 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 354 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
341 Tile* tile = *it; | 355 Tile* tile = *it; |
342 if (!tile->managed_state().can_be_freed) | 356 if (!tile->managed_state().can_be_freed) |
343 unreleasable_bytes += tile->bytes_consumed_if_allocated(); | 357 unreleasable_bytes += tile->bytes_consumed_if_allocated(); |
344 } | 358 } |
345 | 359 |
346 // Now give memory out to the tiles until we're out, and build | 360 // Now give memory out to the tiles until we're out, and build |
347 // the needs-to-be-rasterized queue. | 361 // the needs-to-be-rasterized queue. |
348 tiles_that_need_to_be_rasterized_.erase( | 362 tiles_that_need_to_be_rasterized_.erase( |
349 tiles_that_need_to_be_rasterized_.begin(), | 363 tiles_that_need_to_be_rasterized_.begin(), |
350 tiles_that_need_to_be_rasterized_.end()); | 364 tiles_that_need_to_be_rasterized_.end()); |
351 | 365 |
352 // Record all the tiles in the image decoding list. A tile will not be | 366 // Reset the image decoding list so that we don't mess up with tile |
353 // inserted to the rasterizer queue if it is waiting for image decoding. | 367 // priorities. Tiles will be added to the image decoding list again |
354 std::set<Tile*> image_decoding_tile_set; | 368 // when DispatchMoreTasks() is called. |
355 for (std::list<Tile*>::iterator it = tiles_with_image_decoding_tasks_.begin(); | |
356 it != tiles_with_image_decoding_tasks_.end(); ++it) { | |
357 image_decoding_tile_set.insert(*it); | |
358 } | |
359 tiles_with_image_decoding_tasks_.clear(); | 369 tiles_with_image_decoding_tasks_.clear(); |
360 | 370 |
361 size_t bytes_left = global_state_.memory_limit_in_bytes - unreleasable_bytes; | 371 size_t bytes_left = global_state_.memory_limit_in_bytes - unreleasable_bytes; |
362 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 372 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
363 Tile* tile = *it; | 373 Tile* tile = *it; |
364 size_t tile_bytes = tile->bytes_consumed_if_allocated(); | 374 size_t tile_bytes = tile->bytes_consumed_if_allocated(); |
365 ManagedTileState& managed_tile_state = tile->managed_state(); | 375 ManagedTileState& managed_tile_state = tile->managed_state(); |
366 if (!managed_tile_state.can_be_freed) | 376 if (!managed_tile_state.can_be_freed) |
367 continue; | 377 continue; |
368 if (managed_tile_state.bin == NEVER_BIN) { | 378 if (managed_tile_state.bin == NEVER_BIN) { |
369 managed_tile_state.can_use_gpu_memory = false; | 379 managed_tile_state.can_use_gpu_memory = false; |
370 FreeResourcesForTile(tile); | 380 FreeResourcesForTile(tile); |
371 continue; | 381 continue; |
372 } | 382 } |
373 if (tile_bytes > bytes_left) { | 383 if (tile_bytes > bytes_left) { |
374 managed_tile_state.can_use_gpu_memory = false; | 384 managed_tile_state.can_use_gpu_memory = false; |
375 FreeResourcesForTile(tile); | 385 FreeResourcesForTile(tile); |
376 continue; | 386 continue; |
377 } | 387 } |
378 bytes_left -= tile_bytes; | 388 bytes_left -= tile_bytes; |
379 managed_tile_state.can_use_gpu_memory = true; | 389 managed_tile_state.can_use_gpu_memory = true; |
380 if (!managed_tile_state.resource && | 390 if (!managed_tile_state.resource && |
381 !managed_tile_state.resource_is_being_initialized) { | 391 !managed_tile_state.resource_is_being_initialized) |
382 if (image_decoding_tile_set.end() != image_decoding_tile_set.find(tile)) | 392 tiles_that_need_to_be_rasterized_.push_back(tile); |
383 tiles_with_image_decoding_tasks_.push_back(tile); | |
384 else | |
385 tiles_that_need_to_be_rasterized_.push_back(tile); | |
386 } | |
387 } | 393 } |
388 | 394 |
389 // Reverse two tiles_that_need_* vectors such that pop_back gets | 395 // Reverse two tiles_that_need_* vectors such that pop_back gets |
390 // the highest priority tile. | 396 // the highest priority tile. |
391 std::reverse( | 397 std::reverse( |
392 tiles_that_need_to_be_rasterized_.begin(), | 398 tiles_that_need_to_be_rasterized_.begin(), |
393 tiles_that_need_to_be_rasterized_.end()); | 399 tiles_that_need_to_be_rasterized_.end()); |
394 } | 400 } |
395 | 401 |
396 void TileManager::FreeResourcesForTile(Tile* tile) { | 402 void TileManager::FreeResourcesForTile(Tile* tile) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 } else { | 449 } else { |
444 RasterThread* thread = GetFreeRasterThread(); | 450 RasterThread* thread = GetFreeRasterThread(); |
445 if (!thread) | 451 if (!thread) |
446 return; | 452 return; |
447 DispatchOneRasterTask(thread, tile); | 453 DispatchOneRasterTask(thread, tile); |
448 } | 454 } |
449 tiles_that_need_to_be_rasterized_.pop_back(); | 455 tiles_that_need_to_be_rasterized_.pop_back(); |
450 } | 456 } |
451 } | 457 } |
452 | 458 |
| 459 void TileManager::GatherPixelRefsForFile(Tile* tile) { |
| 460 TRACE_EVENT0("cc", "TileManager::GatherPixelRefsForFile"); |
| 461 ManagedTileState& managed_state = tile->managed_state(); |
| 462 if (managed_state.need_to_gather_pixel_refs) { |
| 463 base::TimeTicks gatherBeginTime = base::TimeTicks::Now(); |
| 464 const_cast<PicturePileImpl *>(tile->picture_pile())->GatherPixelRefs( |
| 465 tile->content_rect_, managed_state.pending_pixel_refs); |
| 466 rendering_stats_.totalImageGatheringCount++; |
| 467 rendering_stats_.totalImageGatheringTimeInSeconds += |
| 468 (base::TimeTicks::Now() - gatherBeginTime).InSecondsF(); |
| 469 managed_state.need_to_gather_pixel_refs = false; |
| 470 } |
| 471 } |
| 472 |
453 void TileManager::DispatchImageDecodingTasksForTile(Tile* tile) { | 473 void TileManager::DispatchImageDecodingTasksForTile(Tile* tile) { |
454 ManagedTileState& managed_state = tile->managed_state(); | 474 GatherPixelRefsForFile(tile); |
455 if (managed_state.need_to_gather_pixel_refs) { | |
456 TRACE_EVENT0("cc", | |
457 "TileManager::DispatchImageDecodingTaskForTile: Gather PixelRefs"); | |
458 const_cast<PicturePileImpl *>(tile->picture_pile())->GatherPixelRefs( | |
459 tile->content_rect_, managed_state.pending_pixel_refs); | |
460 managed_state.need_to_gather_pixel_refs = false; | |
461 } | |
462 | |
463 std::list<skia::LazyPixelRef*>& pending_pixel_refs = | 475 std::list<skia::LazyPixelRef*>& pending_pixel_refs = |
464 tile->managed_state().pending_pixel_refs; | 476 tile->managed_state().pending_pixel_refs; |
465 std::list<skia::LazyPixelRef*>::iterator it = pending_pixel_refs.begin(); | 477 std::list<skia::LazyPixelRef*>::iterator it = pending_pixel_refs.begin(); |
466 while (it != pending_pixel_refs.end()) { | 478 while (it != pending_pixel_refs.end()) { |
467 if (pending_decode_tasks_.end() != pending_decode_tasks_.find( | 479 if (pending_decode_tasks_.end() != pending_decode_tasks_.find( |
468 (*it)->getGenerationID())) { | 480 (*it)->getGenerationID())) { |
469 ++it; | 481 ++it; |
470 continue; | 482 continue; |
471 } | 483 } |
472 // TODO(qinmin): passing correct image size to PrepareToDecode(). | 484 // TODO(qinmin): passing correct image size to PrepareToDecode(). |
473 if ((*it)->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) { | 485 if ((*it)->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) { |
| 486 rendering_stats_.totalDeferredImageCacheHitCount++; |
474 pending_pixel_refs.erase(it++); | 487 pending_pixel_refs.erase(it++); |
475 } else { | 488 } else { |
476 RasterThread* thread = GetFreeRasterThread(); | 489 RasterThread* thread = GetFreeRasterThread(); |
477 if (thread) | 490 if (!thread) |
478 DispatchOneImageDecodingTask(thread, tile, *it); | 491 return; |
| 492 DispatchOneImageDecodingTask(thread, tile, *it); |
479 ++it; | 493 ++it; |
480 } | 494 } |
481 } | 495 } |
482 } | 496 } |
483 | 497 |
484 void TileManager::DispatchOneImageDecodingTask(RasterThread* thread, | 498 void TileManager::DispatchOneImageDecodingTask(RasterThread* thread, |
485 scoped_refptr<Tile> tile, | 499 scoped_refptr<Tile> tile, |
486 skia::LazyPixelRef* pixel_ref) { | 500 skia::LazyPixelRef* pixel_ref) { |
487 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodingTask"); | 501 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodingTask"); |
488 uint32_t pixel_ref_id = pixel_ref->getGenerationID(); | 502 uint32_t pixel_ref_id = pixel_ref->getGenerationID(); |
489 DCHECK(pending_decode_tasks_.end() == | 503 DCHECK(pending_decode_tasks_.end() == |
490 pending_decode_tasks_.find(pixel_ref_id)); | 504 pending_decode_tasks_.find(pixel_ref_id)); |
491 pending_decode_tasks_[pixel_ref_id] = pixel_ref; | 505 pending_decode_tasks_[pixel_ref_id] = pixel_ref; |
| 506 RenderingStats* stats = new RenderingStats(); |
492 | 507 |
493 thread->PostImageDecodingTaskAndReply( | 508 thread->PostImageDecodingTaskAndReply( |
494 FROM_HERE, | 509 FROM_HERE, |
495 pixel_ref, | 510 pixel_ref, |
| 511 stats, |
496 base::Bind(&TileManager::OnImageDecodingTaskCompleted, | 512 base::Bind(&TileManager::OnImageDecodingTaskCompleted, |
497 base::Unretained(this), | 513 base::Unretained(this), |
498 tile, | 514 tile, |
499 pixel_ref_id)); | 515 pixel_ref_id, |
| 516 stats)); |
500 } | 517 } |
501 | 518 |
502 void TileManager::OnImageDecodingTaskCompleted(scoped_refptr<Tile> tile, | 519 void TileManager::OnImageDecodingTaskCompleted(scoped_refptr<Tile> tile, |
503 uint32_t pixel_ref_id) { | 520 uint32_t pixel_ref_id, |
| 521 RenderingStats* stats) { |
504 TRACE_EVENT0("cc", "TileManager::OnImageDecoded"); | 522 TRACE_EVENT0("cc", "TileManager::OnImageDecoded"); |
505 pending_decode_tasks_.erase(pixel_ref_id); | 523 pending_decode_tasks_.erase(pixel_ref_id); |
506 | 524 rendering_stats_.totalDeferredImageDecodeTimeInSeconds += |
| 525 stats->totalDeferredImageDecodeTimeInSeconds; |
| 526 rendering_stats_.totalDeferredImageDecodeCount++; |
| 527 delete stats; |
507 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); | 528 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); |
508 it != tiles_with_image_decoding_tasks_.end(); ++it) { | 529 it != tiles_with_image_decoding_tasks_.end(); ++it) { |
509 std::list<skia::LazyPixelRef*>& pixel_refs = | 530 std::list<skia::LazyPixelRef*>& pixel_refs = |
510 (*it)->managed_state().pending_pixel_refs; | 531 (*it)->managed_state().pending_pixel_refs; |
511 for (std::list<skia::LazyPixelRef*>::iterator pixel_it = | 532 for (std::list<skia::LazyPixelRef*>::iterator pixel_it = |
512 pixel_refs.begin(); pixel_it != pixel_refs.end(); ++pixel_it) { | 533 pixel_refs.begin(); pixel_it != pixel_refs.end(); ++pixel_it) { |
513 if (pixel_ref_id == (*pixel_it)->getGenerationID()) { | 534 if (pixel_ref_id == (*pixel_it)->getGenerationID()) { |
514 pixel_refs.erase(pixel_it); | 535 pixel_refs.erase(pixel_it); |
515 break; | 536 break; |
516 } | 537 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 } | 622 } |
602 | 623 |
603 void TileManager::DidFinishTileInitialization(Tile* tile) { | 624 void TileManager::DidFinishTileInitialization(Tile* tile) { |
604 ManagedTileState& managed_tile_state = tile->managed_state(); | 625 ManagedTileState& managed_tile_state = tile->managed_state(); |
605 DCHECK(managed_tile_state.resource); | 626 DCHECK(managed_tile_state.resource); |
606 managed_tile_state.resource_is_being_initialized = false; | 627 managed_tile_state.resource_is_being_initialized = false; |
607 managed_tile_state.can_be_freed = true; | 628 managed_tile_state.can_be_freed = true; |
608 } | 629 } |
609 | 630 |
610 } | 631 } |
OLD | NEW |