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

Side by Side Diff: cc/tile_manager.cc

Issue 12353003: cc: Refactored Tile::GetResourceId (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
« cc/tile.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 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "cc/devtools_instrumentation.h" 14 #include "cc/devtools_instrumentation.h"
15 #include "cc/math_util.h"
16 #include "cc/platform_color.h" 15 #include "cc/platform_color.h"
17 #include "cc/raster_worker_pool.h" 16 #include "cc/raster_worker_pool.h"
18 #include "cc/resource_pool.h" 17 #include "cc/resource_pool.h"
19 #include "cc/tile.h" 18 #include "cc/tile.h"
20 #include "third_party/skia/include/core/SkDevice.h" 19 #include "third_party/skia/include/core/SkDevice.h"
21 20
22 namespace cc { 21 namespace cc {
23 22
24 namespace { 23 namespace {
25 24
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 case UPLOAD_STATE: 137 case UPLOAD_STATE:
139 return scoped_ptr<base::Value>(base::Value::CreateStringValue( 138 return scoped_ptr<base::Value>(base::Value::CreateStringValue(
140 "UPLOAD_STATE")); 139 "UPLOAD_STATE"));
141 default: 140 default:
142 DCHECK(false) << "Unrecognized TileRasterState value"; 141 DCHECK(false) << "Unrecognized TileRasterState value";
143 return scoped_ptr<base::Value>(base::Value::CreateStringValue( 142 return scoped_ptr<base::Value>(base::Value::CreateStringValue(
144 "<unknown TileRasterState value>")); 143 "<unknown TileRasterState value>"));
145 } 144 }
146 } 145 }
147 146
148 ManagedTileState::ManagedTileState()
149 : can_use_gpu_memory(false),
150 can_be_freed(true),
151 resource_is_being_initialized(false),
152 contents_swizzled(false),
153 need_to_gather_pixel_refs(true),
154 gpu_memmgr_stats_bin(NEVER_BIN),
155 raster_state(IDLE_STATE),
156 resolution(NON_IDEAL_RESOLUTION),
157 time_to_needed_in_seconds(std::numeric_limits<float>::infinity()),
158 distance_to_visible_in_pixels(std::numeric_limits<float>::infinity()),
159 picture_pile_analyzed(false) {
160 for (int i = 0; i < NUM_TREES; ++i) {
161 tree_bin[i] = NEVER_BIN;
162 bin[i] = NEVER_BIN;
163 }
164 }
165
166 ManagedTileState::~ManagedTileState() {
167 DCHECK(!resource);
168 DCHECK(!resource_is_being_initialized);
169 }
170
171 scoped_ptr<base::Value> ManagedTileState::AsValue() const {
172 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
173 state->SetBoolean("can_use_gpu_memory", can_use_gpu_memory);
174 state->SetBoolean("can_be_freed", can_be_freed);
175 state->SetBoolean("has_resource", resource.get() != 0);
176 state->SetBoolean("resource_is_being_initialized", resource_is_being_initializ ed);
177 state->Set("raster_state", TileRasterStateAsValue(raster_state).release());
178 state->Set("bin.0", TileManagerBinAsValue(bin[ACTIVE_TREE]).release());
179 state->Set("bin.1", TileManagerBinAsValue(bin[PENDING_TREE]).release());
180 state->Set("gpu_memmgr_stats_bin", TileManagerBinAsValue(bin[ACTIVE_TREE]).rel ease());
181 state->Set("resolution", TileResolutionAsValue(resolution).release());
182 state->Set("time_to_needed_in_seconds", MathUtil::asValueSafely(time_to_needed _in_seconds).release());
183 state->Set("distance_to_visible_in_pixels", MathUtil::asValueSafely(distance_t o_visible_in_pixels).release());
184 state->SetBoolean("is_picture_pile_analyzed", picture_pile_analyzed);
185 state->SetBoolean("is_cheap_to_raster", picture_pile_analysis.is_cheap_to_rast er);
186 state->SetBoolean("is_transparent", picture_pile_analysis.is_transparent);
187 state->SetBoolean("is_solid_color", picture_pile_analysis.is_solid_color);
188 return state.PassAs<base::Value>();
189 }
190
191 TileManager::TileManager( 147 TileManager::TileManager(
192 TileManagerClient* client, 148 TileManagerClient* client,
193 ResourceProvider* resource_provider, 149 ResourceProvider* resource_provider,
194 size_t num_raster_threads, 150 size_t num_raster_threads,
195 bool use_cheapness_estimator, 151 bool use_cheapness_estimator,
196 bool use_color_estimator, 152 bool use_color_estimator,
197 bool prediction_benchmarking) 153 bool prediction_benchmarking)
198 : client_(client), 154 : client_(client),
199 resource_pool_(ResourcePool::Create(resource_provider)), 155 resource_pool_(ResourcePool::Create(resource_provider)),
200 raster_worker_pool_(RasterWorkerPool::Create(this, num_raster_threads)), 156 raster_worker_pool_(RasterWorkerPool::Create(this, num_raster_threads)),
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 DidTileTreeBinChange(tile, 341 DidTileTreeBinChange(tile,
386 bin_map[BinFromTilePriority(tile->priority(ACTIVE_TREE))], 342 bin_map[BinFromTilePriority(tile->priority(ACTIVE_TREE))],
387 ACTIVE_TREE); 343 ACTIVE_TREE);
388 DidTileTreeBinChange(tile, 344 DidTileTreeBinChange(tile,
389 bin_map[BinFromTilePriority(tile->priority(PENDING_TREE))], 345 bin_map[BinFromTilePriority(tile->priority(PENDING_TREE))],
390 PENDING_TREE); 346 PENDING_TREE);
391 347
392 for (int i = 0; i < NUM_BIN_PRIORITIES; ++i) 348 for (int i = 0; i < NUM_BIN_PRIORITIES; ++i)
393 mts.bin[i] = bin_map[mts.bin[i]]; 349 mts.bin[i] = bin_map[mts.bin[i]];
394 350
395 if (!tile->managed_state().resource && 351 if (!mts.drawing_info.resource_ &&
396 !tile->managed_state().resource_is_being_initialized && 352 !mts.drawing_info.resource_is_being_initialized_ &&
397 !tile->priority(ACTIVE_TREE).is_live && 353 !tile->priority(ACTIVE_TREE).is_live &&
398 !tile->priority(PENDING_TREE).is_live) 354 !tile->priority(PENDING_TREE).is_live)
399 continue; 355 continue;
400 356
401 live_or_allocated_tiles_.push_back(tile); 357 live_or_allocated_tiles_.push_back(tile);
402 } 358 }
403 TRACE_COUNTER_ID1("cc", "LiveOrAllocatedTileCount", this, 359 TRACE_COUNTER_ID1("cc", "LiveOrAllocatedTileCount", this,
404 live_or_allocated_tiles_.size()); 360 live_or_allocated_tiles_.size());
405 361
406 SortTiles(); 362 SortTiles();
407 363
408 // Assign gpu memory and determine what tiles need to be rasterized. 364 // Assign gpu memory and determine what tiles need to be rasterized.
409 AssignGpuMemoryToTiles(); 365 AssignGpuMemoryToTiles();
410 366
411 TRACE_EVENT_INSTANT1("cc", "DidManage", "state", 367 TRACE_EVENT_INSTANT1("cc", "DidManage", "state",
412 ValueToString(BasicStateAsValue())); 368 ValueToString(BasicStateAsValue()));
413 369
414 // Finally, kick the rasterizer. 370 // Finally, kick the rasterizer.
415 DispatchMoreTasks(); 371 DispatchMoreTasks();
416 } 372 }
417 373
418 void TileManager::CheckForCompletedTileUploads() { 374 void TileManager::CheckForCompletedTileUploads() {
419 while (!tiles_with_pending_upload_.empty()) { 375 while (!tiles_with_pending_upload_.empty()) {
420 Tile* tile = tiles_with_pending_upload_.front(); 376 Tile* tile = tiles_with_pending_upload_.front();
421 DCHECK(tile->managed_state().resource); 377 ManagedTileState& managed_tile_state = tile->managed_state();
378 DCHECK(managed_tile_state.drawing_info.resource_);
422 379
423 // Set pixel tasks complete in the order they are posted. 380 // Set pixel tasks complete in the order they are posted.
424 if (!resource_pool_->resource_provider()->DidSetPixelsComplete( 381 if (!resource_pool_->resource_provider()->DidSetPixelsComplete(
425 tile->managed_state().resource->id())) { 382 managed_tile_state.drawing_info.resource_->id())) {
426 break; 383 break;
427 } 384 }
428 385
429 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0 && 386 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0 &&
430 tile->priority(ACTIVE_TREE).resolution == HIGH_RESOLUTION) 387 tile->priority(ACTIVE_TREE).resolution == HIGH_RESOLUTION)
431 client_->DidUploadVisibleHighResolutionTile(); 388 client_->DidUploadVisibleHighResolutionTile();
432 389
433 // It's now safe to release the pixel buffer. 390 // It's now safe to release the pixel buffer.
434 resource_pool_->resource_provider()->ReleasePixelBuffer( 391 resource_pool_->resource_provider()->ReleasePixelBuffer(
435 tile->managed_state().resource->id()); 392 managed_tile_state.drawing_info.resource_->id());
436 393
437 DidFinishTileInitialization(tile); 394 DidFinishTileInitialization(tile);
438 395
439 bytes_pending_upload_ -= tile->bytes_consumed_if_allocated(); 396 bytes_pending_upload_ -= tile->bytes_consumed_if_allocated();
440 DidTileRasterStateChange(tile, IDLE_STATE); 397 DidTileRasterStateChange(tile, IDLE_STATE);
441 tiles_with_pending_upload_.pop(); 398 tiles_with_pending_upload_.pop();
442 } 399 }
443 400
444 DispatchMoreTasks(); 401 DispatchMoreTasks();
445 } 402 }
446 403
447 void TileManager::AbortPendingTileUploads() { 404 void TileManager::AbortPendingTileUploads() {
448 while (!tiles_with_pending_upload_.empty()) { 405 while (!tiles_with_pending_upload_.empty()) {
449 Tile* tile = tiles_with_pending_upload_.front(); 406 Tile* tile = tiles_with_pending_upload_.front();
450 ManagedTileState& managed_tile_state = tile->managed_state(); 407 ManagedTileState& managed_tile_state = tile->managed_state();
451 DCHECK(managed_tile_state.resource); 408 DCHECK(managed_tile_state.drawing_info.resource_);
452 409
453 resource_pool_->resource_provider()->AbortSetPixels( 410 resource_pool_->resource_provider()->AbortSetPixels(
454 managed_tile_state.resource->id()); 411 managed_tile_state.drawing_info.resource_->id());
455 resource_pool_->resource_provider()->ReleasePixelBuffer( 412 resource_pool_->resource_provider()->ReleasePixelBuffer(
456 managed_tile_state.resource->id()); 413 managed_tile_state.drawing_info.resource_->id());
457 414
458 managed_tile_state.resource_is_being_initialized = false; 415 managed_tile_state.drawing_info.resource_is_being_initialized_ = false;
459 managed_tile_state.can_be_freed = true; 416 managed_tile_state.drawing_info.can_be_freed_ = true;
460 managed_tile_state.can_use_gpu_memory = false; 417 managed_tile_state.can_use_gpu_memory = false;
461 FreeResourcesForTile(tile); 418 FreeResourcesForTile(tile);
462 419
463 bytes_pending_upload_ -= tile->bytes_consumed_if_allocated(); 420 bytes_pending_upload_ -= tile->bytes_consumed_if_allocated();
464 DidTileRasterStateChange(tile, IDLE_STATE); 421 DidTileRasterStateChange(tile, IDLE_STATE);
465 tiles_with_pending_upload_.pop(); 422 tiles_with_pending_upload_.pop();
466 } 423 }
467 } 424 }
468 425
469 void TileManager::DidCompleteFrame() { 426 void TileManager::DidCompleteFrame() {
470 allow_cheap_tasks_ = true; 427 allow_cheap_tasks_ = true;
471 did_schedule_cheap_tasks_ = false; 428 did_schedule_cheap_tasks_ = false;
472 } 429 }
473 430
474 void TileManager::GetMemoryStats( 431 void TileManager::GetMemoryStats(
475 size_t* memoryRequiredBytes, 432 size_t* memoryRequiredBytes,
476 size_t* memoryNiceToHaveBytes, 433 size_t* memoryNiceToHaveBytes,
477 size_t* memoryUsedBytes) const { 434 size_t* memoryUsedBytes) const {
478 *memoryRequiredBytes = 0; 435 *memoryRequiredBytes = 0;
479 *memoryNiceToHaveBytes = 0; 436 *memoryNiceToHaveBytes = 0;
480 *memoryUsedBytes = 0; 437 *memoryUsedBytes = 0;
481 for (size_t i = 0; i < live_or_allocated_tiles_.size(); i++) { 438 for (size_t i = 0; i < live_or_allocated_tiles_.size(); i++) {
482 const Tile* tile = live_or_allocated_tiles_[i]; 439 const Tile* tile = live_or_allocated_tiles_[i];
483 const ManagedTileState& mts = tile->managed_state(); 440 const ManagedTileState& mts = tile->managed_state();
484 if (tile->is_transparent() || tile->is_solid_color()) 441 ManagedTileState::DrawingInfo::Mode mode = mts.drawing_info.mode();
442 if (mode == ManagedTileState::DrawingInfo::SOLID_COLOR_MODE ||
443 mode == ManagedTileState::DrawingInfo::TRANSPARENT_MODE)
485 continue; 444 continue;
486 445
487 size_t tile_bytes = tile->bytes_consumed_if_allocated(); 446 size_t tile_bytes = tile->bytes_consumed_if_allocated();
488 if (mts.gpu_memmgr_stats_bin == NOW_BIN) 447 if (mts.gpu_memmgr_stats_bin == NOW_BIN)
489 *memoryRequiredBytes += tile_bytes; 448 *memoryRequiredBytes += tile_bytes;
490 if (mts.gpu_memmgr_stats_bin != NEVER_BIN) 449 if (mts.gpu_memmgr_stats_bin != NEVER_BIN)
491 *memoryNiceToHaveBytes += tile_bytes; 450 *memoryNiceToHaveBytes += tile_bytes;
492 if (mts.can_use_gpu_memory) 451 if (mts.can_use_gpu_memory)
493 *memoryUsedBytes += tile_bytes; 452 *memoryUsedBytes += tile_bytes;
494 } 453 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 // By clearing the tiles_that_need_to_be_rasterized_ vector and 556 // By clearing the tiles_that_need_to_be_rasterized_ vector and
598 // tiles_with_image_decoding_tasks_ list above we move all tiles 557 // tiles_with_image_decoding_tasks_ list above we move all tiles
599 // currently waiting for raster to idle state. 558 // currently waiting for raster to idle state.
600 // Call DidTileRasterStateChange() for each of these tiles to 559 // Call DidTileRasterStateChange() for each of these tiles to
601 // have this state change take effect. 560 // have this state change take effect.
602 // Some memory cannot be released. We figure out how much in this 561 // Some memory cannot be released. We figure out how much in this
603 // loop as well. 562 // loop as well.
604 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); 563 for (TileVector::iterator it = live_or_allocated_tiles_.begin();
605 it != live_or_allocated_tiles_.end(); ++it) { 564 it != live_or_allocated_tiles_.end(); ++it) {
606 Tile* tile = *it; 565 Tile* tile = *it;
607 if (tile->is_solid_color() || tile->is_transparent()) 566 ManagedTileState& mts = tile->managed_state();
567 ManagedTileState::DrawingInfo::Mode mode = mts.drawing_info.mode();
568 if (mode == ManagedTileState::DrawingInfo::SOLID_COLOR_MODE ||
569 mode == ManagedTileState::DrawingInfo::TRANSPARENT_MODE)
608 continue; 570 continue;
609 571
610 ManagedTileState& managed_tile_state = tile->managed_state(); 572 if (!mts.drawing_info.can_be_freed_)
611 if (!managed_tile_state.can_be_freed)
612 unreleasable_bytes += tile->bytes_consumed_if_allocated(); 573 unreleasable_bytes += tile->bytes_consumed_if_allocated();
613 if (managed_tile_state.raster_state == WAITING_FOR_RASTER_STATE) 574 if (mts.raster_state == WAITING_FOR_RASTER_STATE)
614 DidTileRasterStateChange(tile, IDLE_STATE); 575 DidTileRasterStateChange(tile, IDLE_STATE);
615 } 576 }
616 577
617 size_t bytes_allocatable = global_state_.memory_limit_in_bytes - unreleasable_ bytes; 578 size_t bytes_allocatable = global_state_.memory_limit_in_bytes - unreleasable_ bytes;
618 size_t bytes_that_exceeded_memory_budget_in_now_bin = 0; 579 size_t bytes_that_exceeded_memory_budget_in_now_bin = 0;
619 size_t bytes_left = bytes_allocatable; 580 size_t bytes_left = bytes_allocatable;
620 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); it != live_or _allocated_tiles_.end(); ++it) { 581 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); it != live_or _allocated_tiles_.end(); ++it) {
621 Tile* tile = *it; 582 Tile* tile = *it;
622 if (tile->is_solid_color() || tile->is_transparent()) 583 ManagedTileState& mts = tile->managed_state();
584 ManagedTileState::DrawingInfo::Mode mode = mts.drawing_info.mode();
585 if (mode == ManagedTileState::DrawingInfo::SOLID_COLOR_MODE ||
586 mode == ManagedTileState::DrawingInfo::TRANSPARENT_MODE)
623 continue; 587 continue;
624 588
625 ManagedTileState& managed_tile_state = tile->managed_state();
626 size_t tile_bytes = tile->bytes_consumed_if_allocated(); 589 size_t tile_bytes = tile->bytes_consumed_if_allocated();
627 if (!managed_tile_state.can_be_freed) 590 if (!mts.drawing_info.can_be_freed_)
628 continue; 591 continue;
629 if (managed_tile_state.bin[HIGH_PRIORITY_BIN] == NEVER_BIN && 592 if (mts.bin[HIGH_PRIORITY_BIN] == NEVER_BIN &&
630 managed_tile_state.bin[LOW_PRIORITY_BIN] == NEVER_BIN) { 593 mts.bin[LOW_PRIORITY_BIN] == NEVER_BIN) {
631 managed_tile_state.can_use_gpu_memory = false; 594 mts.can_use_gpu_memory = false;
632 FreeResourcesForTile(tile); 595 FreeResourcesForTile(tile);
633 continue; 596 continue;
634 } 597 }
635 if (tile_bytes > bytes_left) { 598 if (tile_bytes > bytes_left) {
636 managed_tile_state.can_use_gpu_memory = false; 599 mts.can_use_gpu_memory = false;
637 if (managed_tile_state.bin[HIGH_PRIORITY_BIN] == NOW_BIN || 600 if (mts.bin[HIGH_PRIORITY_BIN] == NOW_BIN ||
638 managed_tile_state.bin[LOW_PRIORITY_BIN] == NOW_BIN) 601 mts.bin[LOW_PRIORITY_BIN] == NOW_BIN)
639 bytes_that_exceeded_memory_budget_in_now_bin += tile_bytes; 602 bytes_that_exceeded_memory_budget_in_now_bin += tile_bytes;
640 FreeResourcesForTile(tile); 603 FreeResourcesForTile(tile);
641 continue; 604 continue;
642 } 605 }
643 bytes_left -= tile_bytes; 606 bytes_left -= tile_bytes;
644 managed_tile_state.can_use_gpu_memory = true; 607 mts.can_use_gpu_memory = true;
645 if (!managed_tile_state.resource && 608 if (!mts.drawing_info.resource_ &&
646 !managed_tile_state.resource_is_being_initialized) { 609 !mts.drawing_info.resource_is_being_initialized_) {
647 tiles_that_need_to_be_rasterized_.push_back(tile); 610 tiles_that_need_to_be_rasterized_.push_back(tile);
648 DidTileRasterStateChange(tile, WAITING_FOR_RASTER_STATE); 611 DidTileRasterStateChange(tile, WAITING_FOR_RASTER_STATE);
649 } 612 }
650 } 613 }
651 614
652 ever_exceeded_memory_budget_ |= 615 ever_exceeded_memory_budget_ |=
653 bytes_that_exceeded_memory_budget_in_now_bin > 0; 616 bytes_that_exceeded_memory_budget_in_now_bin > 0;
654 if (ever_exceeded_memory_budget_) { 617 if (ever_exceeded_memory_budget_) {
655 TRACE_COUNTER_ID2("cc", "over_memory_budget", this, 618 TRACE_COUNTER_ID2("cc", "over_memory_budget", this,
656 "budget", global_state_.memory_limit_in_bytes, 619 "budget", global_state_.memory_limit_in_bytes,
657 "over", bytes_that_exceeded_memory_budget_in_now_bin); 620 "over", bytes_that_exceeded_memory_budget_in_now_bin);
658 } 621 }
659 memory_stats_from_last_assign_.total_budget_in_bytes = 622 memory_stats_from_last_assign_.total_budget_in_bytes =
660 global_state_.memory_limit_in_bytes; 623 global_state_.memory_limit_in_bytes;
661 memory_stats_from_last_assign_.bytes_allocated = 624 memory_stats_from_last_assign_.bytes_allocated =
662 bytes_allocatable - bytes_left; 625 bytes_allocatable - bytes_left;
663 memory_stats_from_last_assign_.bytes_unreleasable = unreleasable_bytes; 626 memory_stats_from_last_assign_.bytes_unreleasable = unreleasable_bytes;
664 memory_stats_from_last_assign_.bytes_over = 627 memory_stats_from_last_assign_.bytes_over =
665 bytes_that_exceeded_memory_budget_in_now_bin; 628 bytes_that_exceeded_memory_budget_in_now_bin;
666 629
667 // Reverse two tiles_that_need_* vectors such that pop_back gets 630 // Reverse two tiles_that_need_* vectors such that pop_back gets
668 // the highest priority tile. 631 // the highest priority tile.
669 std::reverse( 632 std::reverse(
670 tiles_that_need_to_be_rasterized_.begin(), 633 tiles_that_need_to_be_rasterized_.begin(),
671 tiles_that_need_to_be_rasterized_.end()); 634 tiles_that_need_to_be_rasterized_.end());
672 } 635 }
673 636
674 void TileManager::FreeResourcesForTile(Tile* tile) { 637 void TileManager::FreeResourcesForTile(Tile* tile) {
675 ManagedTileState& managed_tile_state = tile->managed_state(); 638 ManagedTileState& managed_tile_state = tile->managed_state();
676 DCHECK(managed_tile_state.can_be_freed); 639 DCHECK(managed_tile_state.drawing_info.can_be_freed_);
677 if (managed_tile_state.resource) 640 if (managed_tile_state.drawing_info.resource_)
678 resource_pool_->ReleaseResource(managed_tile_state.resource.Pass()); 641 resource_pool_->ReleaseResource(
642 managed_tile_state.drawing_info.resource_.Pass());
679 } 643 }
680 644
681 bool TileManager::CanDispatchRasterTask(Tile* tile) const { 645 bool TileManager::CanDispatchRasterTask(Tile* tile) const {
682 if (pending_tasks_ >= max_pending_tasks_) 646 if (pending_tasks_ >= max_pending_tasks_)
683 return false; 647 return false;
684 size_t new_bytes_pending = bytes_pending_upload_; 648 size_t new_bytes_pending = bytes_pending_upload_;
685 new_bytes_pending += tile->bytes_consumed_if_allocated(); 649 new_bytes_pending += tile->bytes_consumed_if_allocated();
686 return new_bytes_pending <= kMaxPendingUploadBytes && 650 return new_bytes_pending <= kMaxPendingUploadBytes &&
687 tiles_with_pending_upload_.size() < kMaxPendingUploads; 651 tiles_with_pending_upload_.size() < kMaxPendingUploads;
688 } 652 }
(...skipping 19 matching lines...) Expand all
708 ++it; 672 ++it;
709 } 673 }
710 } 674 }
711 675
712 // Process all tiles in the need_to_be_rasterized queue. If a tile is 676 // Process all tiles in the need_to_be_rasterized queue. If a tile is
713 // solid/transparent, then we are done (we don't need to rasterize 677 // solid/transparent, then we are done (we don't need to rasterize
714 // the tile). If a tile has image decoding tasks, put it to the back 678 // the tile). If a tile has image decoding tasks, put it to the back
715 // of the image decoding list. 679 // of the image decoding list.
716 while (!tiles_that_need_to_be_rasterized_.empty()) { 680 while (!tiles_that_need_to_be_rasterized_.empty()) {
717 Tile* tile = tiles_that_need_to_be_rasterized_.back(); 681 Tile* tile = tiles_that_need_to_be_rasterized_.back();
718 ManagedTileState& managed_tile_state = tile->managed_state(); 682 ManagedTileState& mts = tile->managed_state();
719 683
720 AnalyzeTile(tile); 684 AnalyzeTile(tile);
721 if (tile->is_solid_color() || tile->is_transparent()) { 685 ManagedTileState::DrawingInfo::Mode mode = mts.drawing_info.mode();
686 if (mode == ManagedTileState::DrawingInfo::SOLID_COLOR_MODE ||
687 mode == ManagedTileState::DrawingInfo::TRANSPARENT_MODE) {
722 DidTileRasterStateChange(tile, IDLE_STATE); 688 DidTileRasterStateChange(tile, IDLE_STATE);
723 tiles_that_need_to_be_rasterized_.pop_back(); 689 tiles_that_need_to_be_rasterized_.pop_back();
724 continue; 690 continue;
725 } 691 }
726 692
727 DispatchImageDecodeTasksForTile(tile); 693 DispatchImageDecodeTasksForTile(tile);
728 if (!managed_tile_state.pending_pixel_refs.empty()) { 694 if (!mts.pending_pixel_refs.empty()) {
729 tiles_with_image_decoding_tasks_.push_back(tile); 695 tiles_with_image_decoding_tasks_.push_back(tile);
730 } else { 696 } else {
731 if (!CanDispatchRasterTask(tile)) 697 if (!CanDispatchRasterTask(tile))
732 return; 698 return;
733 DispatchOneRasterTask(tile); 699 DispatchOneRasterTask(tile);
734 } 700 }
735 tiles_that_need_to_be_rasterized_.pop_back(); 701 tiles_that_need_to_be_rasterized_.pop_back();
736 } 702 }
737 } 703 }
738 704
739 void TileManager::AnalyzeTile(Tile* tile) { 705 void TileManager::AnalyzeTile(Tile* tile) {
740 ManagedTileState& managed_tile_state = tile->managed_state(); 706 ManagedTileState& managed_tile_state = tile->managed_state();
741 if ((use_cheapness_estimator_ || use_color_estimator_) && 707 if ((use_cheapness_estimator_ || use_color_estimator_) &&
742 !managed_tile_state.picture_pile_analyzed) { 708 !managed_tile_state.picture_pile_analyzed) {
743 tile->picture_pile()->AnalyzeInRect( 709 tile->picture_pile()->AnalyzeInRect(
744 tile->content_rect(), 710 tile->content_rect(),
745 tile->contents_scale(), 711 tile->contents_scale(),
746 &managed_tile_state.picture_pile_analysis); 712 &managed_tile_state.picture_pile_analysis);
747 managed_tile_state.picture_pile_analysis.is_cheap_to_raster &= 713 managed_tile_state.picture_pile_analysis.is_cheap_to_raster &=
748 use_cheapness_estimator_; 714 use_cheapness_estimator_;
749 managed_tile_state.picture_pile_analysis.is_solid_color &= 715 managed_tile_state.picture_pile_analysis.is_solid_color &=
750 use_color_estimator_; 716 use_color_estimator_;
751 managed_tile_state.picture_pile_analysis.is_transparent &= 717 managed_tile_state.picture_pile_analysis.is_transparent &=
752 use_color_estimator_; 718 use_color_estimator_;
753 managed_tile_state.picture_pile_analyzed = true; 719 managed_tile_state.picture_pile_analyzed = true;
720
721 if (managed_tile_state.picture_pile_analysis.is_solid_color)
722 tile->drawing_info().set_solid_color(
723 managed_tile_state.picture_pile_analysis.solid_color);
724 else if (managed_tile_state.picture_pile_analysis.is_transparent)
725 tile->drawing_info().set_transparent();
754 } 726 }
755 } 727 }
756 728
757 void TileManager::GatherPixelRefsForTile(Tile* tile) { 729 void TileManager::GatherPixelRefsForTile(Tile* tile) {
758 TRACE_EVENT0("cc", "TileManager::GatherPixelRefsForTile"); 730 TRACE_EVENT0("cc", "TileManager::GatherPixelRefsForTile");
759 ManagedTileState& managed_tile_state = tile->managed_state(); 731 ManagedTileState& managed_tile_state = tile->managed_state();
760 if (managed_tile_state.need_to_gather_pixel_refs) { 732 if (managed_tile_state.need_to_gather_pixel_refs) {
761 base::TimeTicks gather_begin_time; 733 base::TimeTicks gather_begin_time;
762 if (record_rendering_stats_) 734 if (record_rendering_stats_)
763 gather_begin_time = base::TimeTicks::HighResNow(); 735 gather_begin_time = base::TimeTicks::HighResNow();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 } 808 }
837 809
838 scoped_ptr<ResourcePool::Resource> TileManager::PrepareTileForRaster( 810 scoped_ptr<ResourcePool::Resource> TileManager::PrepareTileForRaster(
839 Tile* tile) { 811 Tile* tile) {
840 ManagedTileState& managed_tile_state = tile->managed_state(); 812 ManagedTileState& managed_tile_state = tile->managed_state();
841 DCHECK(managed_tile_state.can_use_gpu_memory); 813 DCHECK(managed_tile_state.can_use_gpu_memory);
842 scoped_ptr<ResourcePool::Resource> resource = 814 scoped_ptr<ResourcePool::Resource> resource =
843 resource_pool_->AcquireResource(tile->tile_size_.size(), tile->format_); 815 resource_pool_->AcquireResource(tile->tile_size_.size(), tile->format_);
844 resource_pool_->resource_provider()->AcquirePixelBuffer(resource->id()); 816 resource_pool_->resource_provider()->AcquirePixelBuffer(resource->id());
845 817
846 managed_tile_state.resource_is_being_initialized = true; 818 managed_tile_state.drawing_info.resource_is_being_initialized_ = true;
847 managed_tile_state.can_be_freed = false; 819 managed_tile_state.drawing_info.can_be_freed_ = false;
848 820
849 DidTileRasterStateChange(tile, RASTER_STATE); 821 DidTileRasterStateChange(tile, RASTER_STATE);
850 return resource.Pass(); 822 return resource.Pass();
851 } 823 }
852 824
853 void TileManager::DispatchOneRasterTask(scoped_refptr<Tile> tile) { 825 void TileManager::DispatchOneRasterTask(scoped_refptr<Tile> tile) {
854 TRACE_EVENT0("cc", "TileManager::DispatchOneRasterTask"); 826 TRACE_EVENT0("cc", "TileManager::DispatchOneRasterTask");
855 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile); 827 scoped_ptr<ResourcePool::Resource> resource = PrepareTileForRaster(tile);
856 ResourceProvider::ResourceId resource_id = resource->id(); 828 ResourceProvider::ResourceId resource_id = resource->id();
857 uint8* buffer = 829 uint8* buffer =
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 scoped_ptr<ResourcePool::Resource> resource, 875 scoped_ptr<ResourcePool::Resource> resource,
904 int manage_tiles_call_count_when_dispatched) { 876 int manage_tiles_call_count_when_dispatched) {
905 TRACE_EVENT0("cc", "TileManager::OnRasterTaskCompleted"); 877 TRACE_EVENT0("cc", "TileManager::OnRasterTaskCompleted");
906 878
907 pending_tasks_--; 879 pending_tasks_--;
908 880
909 // Release raster resources. 881 // Release raster resources.
910 resource_pool_->resource_provider()->UnmapPixelBuffer(resource->id()); 882 resource_pool_->resource_provider()->UnmapPixelBuffer(resource->id());
911 883
912 ManagedTileState& managed_tile_state = tile->managed_state(); 884 ManagedTileState& managed_tile_state = tile->managed_state();
913 managed_tile_state.can_be_freed = true; 885 managed_tile_state.drawing_info.can_be_freed_ = true;
914 886
915 // Tile can be freed after the completion of the raster task. Call 887 // Tile can be freed after the completion of the raster task. Call
916 // AssignGpuMemoryToTiles() to re-assign gpu memory to highest priority 888 // AssignGpuMemoryToTiles() to re-assign gpu memory to highest priority
917 // tiles if ManageTiles() was called since task was dispatched. The result 889 // tiles if ManageTiles() was called since task was dispatched. The result
918 // of this could be that this tile is no longer allowed to use gpu 890 // of this could be that this tile is no longer allowed to use gpu
919 // memory and in that case we need to abort initialization and free all 891 // memory and in that case we need to abort initialization and free all
920 // associated resources before calling DispatchMoreTasks(). 892 // associated resources before calling DispatchMoreTasks().
921 if (manage_tiles_call_count_when_dispatched != manage_tiles_call_count_) 893 if (manage_tiles_call_count_when_dispatched != manage_tiles_call_count_)
922 AssignGpuMemoryToTiles(); 894 AssignGpuMemoryToTiles();
923 895
924 // Finish resource initialization if |can_use_gpu_memory| is true. 896 // Finish resource initialization if |can_use_gpu_memory| is true.
925 if (managed_tile_state.can_use_gpu_memory) { 897 if (managed_tile_state.can_use_gpu_memory) {
926 // The component order may be bgra if we're uploading bgra pixels to rgba 898 // The component order may be bgra if we're uploading bgra pixels to rgba
927 // texture. Mark contents as swizzled if image component order is 899 // texture. Mark contents as swizzled if image component order is
928 // different than texture format. 900 // different than texture format.
929 managed_tile_state.contents_swizzled = 901 managed_tile_state.drawing_info.contents_swizzled_ =
930 !PlatformColor::sameComponentOrder(tile->format_); 902 !PlatformColor::sameComponentOrder(tile->format_);
931 903
932 // Tile resources can't be freed until upload has completed. 904 // Tile resources can't be freed until upload has completed.
933 managed_tile_state.can_be_freed = false; 905 managed_tile_state.drawing_info.can_be_freed_ = false;
934 906
935 resource_pool_->resource_provider()->BeginSetPixels(resource->id()); 907 resource_pool_->resource_provider()->BeginSetPixels(resource->id());
936 has_performed_uploads_since_last_flush_ = true; 908 has_performed_uploads_since_last_flush_ = true;
937 909
938 managed_tile_state.resource = resource.Pass(); 910 managed_tile_state.drawing_info.resource_ = resource.Pass();
939 911
940 bytes_pending_upload_ += tile->bytes_consumed_if_allocated(); 912 bytes_pending_upload_ += tile->bytes_consumed_if_allocated();
941 DidTileRasterStateChange(tile, UPLOAD_STATE); 913 DidTileRasterStateChange(tile, UPLOAD_STATE);
942 tiles_with_pending_upload_.push(tile); 914 tiles_with_pending_upload_.push(tile);
943 } else { 915 } else {
944 resource_pool_->resource_provider()->ReleasePixelBuffer(resource->id()); 916 resource_pool_->resource_provider()->ReleasePixelBuffer(resource->id());
945 resource_pool_->ReleaseResource(resource.Pass()); 917 resource_pool_->ReleaseResource(resource.Pass());
946 managed_tile_state.resource_is_being_initialized = false; 918 managed_tile_state.drawing_info.resource_is_being_initialized_ = false;
947 DidTileRasterStateChange(tile, IDLE_STATE); 919 DidTileRasterStateChange(tile, IDLE_STATE);
948 } 920 }
949 } 921 }
950 922
951 void TileManager::DidFinishTileInitialization(Tile* tile) { 923 void TileManager::DidFinishTileInitialization(Tile* tile) {
952 ManagedTileState& managed_tile_state = tile->managed_state(); 924 ManagedTileState& managed_state = tile->managed_state();
953 DCHECK(managed_tile_state.resource); 925 DCHECK(managed_state.drawing_info.resource_);
954 managed_tile_state.resource_is_being_initialized = false; 926 managed_state.drawing_info.resource_is_being_initialized_ = false;
955 managed_tile_state.can_be_freed = true; 927 managed_state.drawing_info.can_be_freed_ = true;
956 } 928 }
957 929
958 void TileManager::DidTileRasterStateChange(Tile* tile, TileRasterState state) { 930 void TileManager::DidTileRasterStateChange(Tile* tile, TileRasterState state) {
959 ManagedTileState& mts = tile->managed_state(); 931 ManagedTileState& mts = tile->managed_state();
960 DCHECK_LT(state, NUM_STATES); 932 DCHECK_LT(state, NUM_STATES);
961 933
962 for (int i = 0; i < NUM_TREES; ++i) { 934 for (int i = 0; i < NUM_TREES; ++i) {
963 // Decrement count for current state. 935 // Decrement count for current state.
964 --raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; 936 --raster_state_count_[mts.raster_state][i][mts.tree_bin[i]];
965 DCHECK_GE(raster_state_count_[mts.raster_state][i][mts.tree_bin[i]], 0); 937 DCHECK_GE(raster_state_count_[mts.raster_state][i][mts.tree_bin[i]], 0);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 decode_begin_time = base::TimeTicks::HighResNow(); 1098 decode_begin_time = base::TimeTicks::HighResNow();
1127 pixel_ref->Decode(); 1099 pixel_ref->Decode();
1128 if (stats) { 1100 if (stats) {
1129 stats->totalDeferredImageDecodeCount++; 1101 stats->totalDeferredImageDecodeCount++;
1130 stats->totalDeferredImageDecodeTime += 1102 stats->totalDeferredImageDecodeTime +=
1131 base::TimeTicks::HighResNow() - decode_begin_time; 1103 base::TimeTicks::HighResNow() - decode_begin_time;
1132 } 1104 }
1133 } 1105 }
1134 1106
1135 } // namespace cc 1107 } // namespace cc
OLDNEW
« cc/tile.h ('K') | « cc/tile_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698