| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.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/resources/platform_color.h" | |
| 17 #include "cc/resources/raster_worker_pool.h" | 16 #include "cc/resources/raster_worker_pool.h" |
| 18 #include "cc/resources/resource_pool.h" | 17 #include "cc/resources/resource_pool.h" |
| 19 #include "cc/resources/tile.h" | 18 #include "cc/resources/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 |
| 26 // If we raster too fast we become upload bound, and pending | 25 // If we raster too fast we become upload bound, and pending |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 FreeResourcesForTile(tile); | 537 FreeResourcesForTile(tile); |
| 539 continue; | 538 continue; |
| 540 } | 539 } |
| 541 if (tile_bytes > bytes_left) { | 540 if (tile_bytes > bytes_left) { |
| 542 mts.can_use_gpu_memory = false; | 541 mts.can_use_gpu_memory = false; |
| 543 if (mts.bin[HIGH_PRIORITY_BIN] == NOW_BIN || | 542 if (mts.bin[HIGH_PRIORITY_BIN] == NOW_BIN || |
| 544 mts.bin[LOW_PRIORITY_BIN] == NOW_BIN) | 543 mts.bin[LOW_PRIORITY_BIN] == NOW_BIN) |
| 545 bytes_that_exceeded_memory_budget_in_now_bin += tile_bytes; | 544 bytes_that_exceeded_memory_budget_in_now_bin += tile_bytes; |
| 546 FreeResourcesForTile(tile); | 545 FreeResourcesForTile(tile); |
| 547 tile->drawing_info().set_rasterize_on_demand(); | 546 tile->drawing_info().set_rasterize_on_demand(); |
| 548 tile->drawing_info().set_contents_swizzled( | |
| 549 !PlatformColor::SameComponentOrder(tile->format_)); | |
| 550 continue; | 547 continue; |
| 551 } | 548 } |
| 552 tile->drawing_info().set_use_resource(); | 549 tile->drawing_info().set_use_resource(); |
| 553 bytes_left -= tile_bytes; | 550 bytes_left -= tile_bytes; |
| 554 mts.can_use_gpu_memory = true; | 551 mts.can_use_gpu_memory = true; |
| 555 if (!tile->drawing_info().resource_ && | 552 if (!tile->drawing_info().resource_ && |
| 556 !tile->drawing_info().resource_is_being_initialized_) { | 553 !tile->drawing_info().resource_is_being_initialized_) { |
| 557 tiles_that_need_to_be_rasterized_.push_back(tile); | 554 tiles_that_need_to_be_rasterized_.push_back(tile); |
| 558 } | 555 } |
| 559 } | 556 } |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 break; | 750 break; |
| 754 } | 751 } |
| 755 } | 752 } |
| 756 } | 753 } |
| 757 } | 754 } |
| 758 | 755 |
| 759 scoped_ptr<ResourcePool::Resource> TileManager::PrepareTileForRaster( | 756 scoped_ptr<ResourcePool::Resource> TileManager::PrepareTileForRaster( |
| 760 Tile* tile) { | 757 Tile* tile) { |
| 761 ManagedTileState& managed_tile_state = tile->managed_state(); | 758 ManagedTileState& managed_tile_state = tile->managed_state(); |
| 762 DCHECK(managed_tile_state.can_use_gpu_memory); | 759 DCHECK(managed_tile_state.can_use_gpu_memory); |
| 763 scoped_ptr<ResourcePool::Resource> resource = | 760 scoped_ptr<ResourcePool::Resource> resource = resource_pool_->AcquireResource( |
| 764 resource_pool_->AcquireResource(tile->tile_size_.size(), tile->format_); | 761 tile->tile_size_.size(), |
| 762 tile->drawing_info().resource_format_); |
| 765 resource_pool_->resource_provider()->AcquirePixelBuffer(resource->id()); | 763 resource_pool_->resource_provider()->AcquirePixelBuffer(resource->id()); |
| 766 | 764 |
| 767 tile->drawing_info().resource_is_being_initialized_ = true; | 765 tile->drawing_info().resource_is_being_initialized_ = true; |
| 768 tile->drawing_info().can_be_freed_ = false; | 766 tile->drawing_info().can_be_freed_ = false; |
| 769 | 767 |
| 770 return resource.Pass(); | 768 return resource.Pass(); |
| 771 } | 769 } |
| 772 | 770 |
| 773 void TileManager::SetAnticipatedDrawTime(base::TimeTicks time) { | 771 void TileManager::SetAnticipatedDrawTime(base::TimeTicks time) { |
| 774 anticipated_draw_time_ = time; | 772 anticipated_draw_time_ = time; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 // of this could be that this tile is no longer allowed to use gpu | 841 // of this could be that this tile is no longer allowed to use gpu |
| 844 // memory and in that case we need to abort initialization and free all | 842 // memory and in that case we need to abort initialization and free all |
| 845 // associated resources before calling DispatchMoreTasks(). | 843 // associated resources before calling DispatchMoreTasks(). |
| 846 if (manage_tiles_call_count_when_dispatched != manage_tiles_call_count_) | 844 if (manage_tiles_call_count_when_dispatched != manage_tiles_call_count_) |
| 847 AssignGpuMemoryToTiles(); | 845 AssignGpuMemoryToTiles(); |
| 848 | 846 |
| 849 ManagedTileState& managed_tile_state = tile->managed_state(); | 847 ManagedTileState& managed_tile_state = tile->managed_state(); |
| 850 | 848 |
| 851 // Finish resource initialization if |can_use_gpu_memory| is true. | 849 // Finish resource initialization if |can_use_gpu_memory| is true. |
| 852 if (managed_tile_state.can_use_gpu_memory) { | 850 if (managed_tile_state.can_use_gpu_memory) { |
| 853 // The component order may be bgra if we're uploading bgra pixels to rgba | |
| 854 // texture. Mark contents as swizzled if image component order is | |
| 855 // different than texture format. | |
| 856 tile->drawing_info().contents_swizzled_ = | |
| 857 !PlatformColor::SameComponentOrder(tile->format_); | |
| 858 | 851 |
| 859 // Tile resources can't be freed until upload has completed. | 852 // Tile resources can't be freed until upload has completed. |
| 860 tile->drawing_info().can_be_freed_ = false; | 853 tile->drawing_info().can_be_freed_ = false; |
| 861 | 854 |
| 862 resource_pool_->resource_provider()->BeginSetPixels(resource->id()); | 855 resource_pool_->resource_provider()->BeginSetPixels(resource->id()); |
| 863 has_performed_uploads_since_last_flush_ = true; | 856 has_performed_uploads_since_last_flush_ = true; |
| 864 | 857 |
| 865 tile->drawing_info().resource_ = resource.Pass(); | 858 tile->drawing_info().resource_ = resource.Pass(); |
| 866 | 859 |
| 867 bytes_pending_upload_ += tile->bytes_consumed_if_allocated(); | 860 bytes_pending_upload_ += tile->bytes_consumed_if_allocated(); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 skia::LazyPixelRef* pixel_ref, | 1011 skia::LazyPixelRef* pixel_ref, |
| 1019 RenderingStatsInstrumentation* stats_instrumentation) { | 1012 RenderingStatsInstrumentation* stats_instrumentation) { |
| 1020 TRACE_EVENT0("cc", "TileManager::RunImageDecodeTask"); | 1013 TRACE_EVENT0("cc", "TileManager::RunImageDecodeTask"); |
| 1021 base::TimeTicks start_time = stats_instrumentation->StartRecording(); | 1014 base::TimeTicks start_time = stats_instrumentation->StartRecording(); |
| 1022 pixel_ref->Decode(); | 1015 pixel_ref->Decode(); |
| 1023 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time); | 1016 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time); |
| 1024 stats_instrumentation->AddDeferredImageDecode(duration); | 1017 stats_instrumentation->AddDeferredImageDecode(duration); |
| 1025 } | 1018 } |
| 1026 | 1019 |
| 1027 } // namespace cc | 1020 } // namespace cc |
| OLD | NEW |