| 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/resources/tile_manager.h" | 5 #include "cc/resources/tile_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "cc/debug/devtools_instrumentation.h" | 15 #include "cc/debug/devtools_instrumentation.h" |
| 16 #include "cc/debug/traced_value.h" | 16 #include "cc/debug/traced_value.h" |
| 17 #include "cc/resources/image_raster_worker_pool.h" | 17 #include "cc/resources/image_raster_worker_pool.h" |
| 18 #include "cc/resources/pixel_buffer_raster_worker_pool.h" | 18 #include "cc/resources/pixel_buffer_raster_worker_pool.h" |
| 19 #include "cc/resources/tile.h" | 19 #include "cc/resources/tile.h" |
| 20 #include "third_party/skia/include/core/SkCanvas.h" | 20 #include "third_party/skia/include/core/SkCanvas.h" |
| 21 #include "ui/gfx/rect_conversions.h" | 21 #include "ui/gfx/rect_conversions.h" |
| 22 | 22 |
| 23 namespace cc { | 23 namespace cc { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 // Memory limit policy works by mapping some bin states to the NEVER bin. | 27 // Memory limit policy works by mapping some bin states to the NEVER bin. |
| 28 const ManagedTileBin kBinPolicyMap[NUM_TILE_MEMORY_LIMIT_POLICIES][NUM_BINS] = { | 28 const ManagedTileBin kBinPolicyMap |
| 29 [TileMemoryLimitPolicy_ARRAYSIZE][ManagedTileBin_ARRAYSIZE] = { |
| 29 { // [ALLOW_NOTHING] | 30 { // [ALLOW_NOTHING] |
| 30 NEVER_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | 31 NEVER_BIN, // [NOW_AND_READY_TO_DRAW_BIN] |
| 31 NEVER_BIN, // [NOW_BIN] | 32 NEVER_BIN, // [NOW_BIN] |
| 32 NEVER_BIN, // [SOON_BIN] | 33 NEVER_BIN, // [SOON_BIN] |
| 33 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | 34 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] |
| 34 NEVER_BIN, // [EVENTUALLY_BIN] | 35 NEVER_BIN, // [EVENTUALLY_BIN] |
| 35 NEVER_BIN, // [NEVER_AND_ACTIVE_BIN] | 36 NEVER_BIN, // [NEVER_AND_ACTIVE_BIN] |
| 36 NEVER_BIN // [NEVER_BIN] | 37 NEVER_BIN // [NEVER_BIN] |
| 37 }, { // [ALLOW_ABSOLUTE_MINIMUM] | 38 }, { // [ALLOW_ABSOLUTE_MINIMUM] |
| 38 NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | 39 NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 // If the tile is not needed, free it up. | 529 // If the tile is not needed, free it up. |
| 529 if (mts.is_in_never_bin_on_both_trees()) { | 530 if (mts.is_in_never_bin_on_both_trees()) { |
| 530 FreeResourcesForTile(tile); | 531 FreeResourcesForTile(tile); |
| 531 continue; | 532 continue; |
| 532 } | 533 } |
| 533 | 534 |
| 534 size_t tile_bytes = 0; | 535 size_t tile_bytes = 0; |
| 535 size_t tile_resources = 0; | 536 size_t tile_resources = 0; |
| 536 | 537 |
| 537 // It costs to maintain a resource. | 538 // It costs to maintain a resource. |
| 538 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 539 for (int mode = 0; mode < RasterMode_ARRAYSIZE; ++mode) { |
| 539 if (mts.tile_versions[mode].resource_) { | 540 if (mts.tile_versions[mode].resource_) { |
| 540 tile_bytes += tile->bytes_consumed_if_allocated(); | 541 tile_bytes += tile->bytes_consumed_if_allocated(); |
| 541 tile_resources++; | 542 tile_resources++; |
| 542 } | 543 } |
| 543 } | 544 } |
| 544 | 545 |
| 545 // Allow lower priority tiles with initialized resources to keep | 546 // Allow lower priority tiles with initialized resources to keep |
| 546 // their memory by only assigning memory to new raster tasks if | 547 // their memory by only assigning memory to new raster tasks if |
| 547 // they can be scheduled. | 548 // they can be scheduled. |
| 548 if (tiles_that_need_to_be_rasterized->size() < kMaxRasterTasks) { | 549 if (tiles_that_need_to_be_rasterized->size() < kMaxRasterTasks) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 | 647 |
| 647 DCHECK_GE(bytes_releasable_, tile->bytes_consumed_if_allocated()); | 648 DCHECK_GE(bytes_releasable_, tile->bytes_consumed_if_allocated()); |
| 648 DCHECK_GE(resources_releasable_, 1u); | 649 DCHECK_GE(resources_releasable_, 1u); |
| 649 | 650 |
| 650 bytes_releasable_ -= tile->bytes_consumed_if_allocated(); | 651 bytes_releasable_ -= tile->bytes_consumed_if_allocated(); |
| 651 --resources_releasable_; | 652 --resources_releasable_; |
| 652 } | 653 } |
| 653 } | 654 } |
| 654 | 655 |
| 655 void TileManager::FreeResourcesForTile(Tile* tile) { | 656 void TileManager::FreeResourcesForTile(Tile* tile) { |
| 656 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 657 for (int mode = 0; mode < RasterMode_ARRAYSIZE; ++mode) |
| 657 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); | 658 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); |
| 658 } | |
| 659 } | 659 } |
| 660 | 660 |
| 661 void TileManager::FreeUnusedResourcesForTile(Tile* tile) { | 661 void TileManager::FreeUnusedResourcesForTile(Tile* tile) { |
| 662 DCHECK(tile->IsReadyToDraw()); | 662 DCHECK(tile->IsReadyToDraw()); |
| 663 ManagedTileState& mts = tile->managed_state(); | 663 ManagedTileState& mts = tile->managed_state(); |
| 664 RasterMode used_mode = HIGH_QUALITY_NO_LCD_RASTER_MODE; | 664 RasterMode used_mode = HIGH_QUALITY_NO_LCD_RASTER_MODE; |
| 665 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 665 for (int mode = 0; mode < RasterMode_ARRAYSIZE; ++mode) { |
| 666 if (mts.tile_versions[mode].IsReadyToDraw()) { | 666 if (mts.tile_versions[mode].IsReadyToDraw()) { |
| 667 used_mode = static_cast<RasterMode>(mode); | 667 used_mode = static_cast<RasterMode>(mode); |
| 668 break; | 668 break; |
| 669 } | 669 } |
| 670 } | 670 } |
| 671 | 671 |
| 672 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 672 for (int mode = 0; mode < RasterMode_ARRAYSIZE; ++mode) { |
| 673 if (mode != used_mode) | 673 if (mode != used_mode) |
| 674 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); | 674 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); |
| 675 } | 675 } |
| 676 } | 676 } |
| 677 | 677 |
| 678 void TileManager::ScheduleTasks( | 678 void TileManager::ScheduleTasks( |
| 679 const TileVector& tiles_that_need_to_be_rasterized) { | 679 const TileVector& tiles_that_need_to_be_rasterized) { |
| 680 TRACE_EVENT1("cc", "TileManager::ScheduleTasks", | 680 TRACE_EVENT1("cc", "TileManager::ScheduleTasks", |
| 681 "count", tiles_that_need_to_be_rasterized.size()); | 681 "count", tiles_that_need_to_be_rasterized.size()); |
| 682 RasterWorkerPool::RasterTask::Queue tasks; | 682 RasterWorkerPool::RasterTask::Queue tasks; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 bytes_releasable_ += tile->bytes_consumed_if_allocated(); | 837 bytes_releasable_ += tile->bytes_consumed_if_allocated(); |
| 838 ++resources_releasable_; | 838 ++resources_releasable_; |
| 839 } | 839 } |
| 840 | 840 |
| 841 FreeUnusedResourcesForTile(tile); | 841 FreeUnusedResourcesForTile(tile); |
| 842 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0) | 842 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0) |
| 843 did_initialize_visible_tile_ = true; | 843 did_initialize_visible_tile_ = true; |
| 844 } | 844 } |
| 845 | 845 |
| 846 } // namespace cc | 846 } // namespace cc |
| OLD | NEW |