| 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/resource_pool.h" | 5 #include "cc/resources/resource_pool.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 dump->AddScalar(MemoryAllocatorDump::kNameSize, | 48 dump->AddScalar(MemoryAllocatorDump::kNameSize, |
| 49 MemoryAllocatorDump::kUnitsBytes, total_bytes); | 49 MemoryAllocatorDump::kUnitsBytes, total_bytes); |
| 50 | 50 |
| 51 if (is_free) { | 51 if (is_free) { |
| 52 dump->AddScalar("free_size", MemoryAllocatorDump::kUnitsBytes, total_bytes); | 52 dump->AddScalar("free_size", MemoryAllocatorDump::kUnitsBytes, total_bytes); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 ResourcePool::ResourcePool(ResourceProvider* resource_provider, | 56 ResourcePool::ResourcePool(ResourceProvider* resource_provider, |
| 57 base::SingleThreadTaskRunner* task_runner, | 57 base::SingleThreadTaskRunner* task_runner, |
| 58 bool use_gpu_memory_buffers, | 58 gfx::BufferUsage usage, |
| 59 const base::TimeDelta& expiration_delay) | 59 const base::TimeDelta& expiration_delay) |
| 60 : resource_provider_(resource_provider), | 60 : resource_provider_(resource_provider), |
| 61 use_gpu_memory_buffers_(use_gpu_memory_buffers), | 61 use_gpu_memory_buffers_(true), |
| 62 max_memory_usage_bytes_(0), | 62 usage_(usage), |
| 63 max_resource_count_(0), | |
| 64 in_use_memory_usage_bytes_(0), | |
| 65 total_memory_usage_bytes_(0), | |
| 66 total_resource_count_(0), | |
| 67 task_runner_(task_runner), | 63 task_runner_(task_runner), |
| 68 evict_expired_resources_pending_(false), | |
| 69 resource_expiration_delay_(expiration_delay), | 64 resource_expiration_delay_(expiration_delay), |
| 70 weak_ptr_factory_(this) { | 65 weak_ptr_factory_(this) { |
| 71 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 66 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 67 this, "cc::ResourcePool", task_runner_.get()); |
| 68 |
| 69 // Register this component with base::MemoryCoordinatorClientRegistry. |
| 70 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
| 71 } |
| 72 |
| 73 ResourcePool::ResourcePool(ResourceProvider* resource_provider, |
| 74 base::SingleThreadTaskRunner* task_runner, |
| 75 ResourceProvider::TextureHint hint, |
| 76 const base::TimeDelta& expiration_delay) |
| 77 : resource_provider_(resource_provider), |
| 78 use_gpu_memory_buffers_(false), |
| 79 hint_(hint), |
| 80 task_runner_(task_runner), |
| 81 resource_expiration_delay_(expiration_delay), |
| 82 weak_ptr_factory_(this) { |
| 83 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 72 this, "cc::ResourcePool", task_runner_.get()); | 84 this, "cc::ResourcePool", task_runner_.get()); |
| 73 | 85 |
| 74 // Register this component with base::MemoryCoordinatorClientRegistry. | 86 // Register this component with base::MemoryCoordinatorClientRegistry. |
| 75 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); | 87 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
| 76 } | 88 } |
| 77 | 89 |
| 78 ResourcePool::~ResourcePool() { | 90 ResourcePool::~ResourcePool() { |
| 79 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 91 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| 80 this); | 92 this); |
| 81 // Unregister this component with memory_coordinator::ClientRegistry. | 93 // Unregister this component with memory_coordinator::ClientRegistry. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 Resource* ResourcePool::CreateResource(const gfx::Size& size, | 137 Resource* ResourcePool::CreateResource(const gfx::Size& size, |
| 126 ResourceFormat format, | 138 ResourceFormat format, |
| 127 const gfx::ColorSpace& color_space) { | 139 const gfx::ColorSpace& color_space) { |
| 128 std::unique_ptr<PoolResource> pool_resource = | 140 std::unique_ptr<PoolResource> pool_resource = |
| 129 PoolResource::Create(resource_provider_); | 141 PoolResource::Create(resource_provider_); |
| 130 | 142 |
| 131 if (use_gpu_memory_buffers_) { | 143 if (use_gpu_memory_buffers_) { |
| 132 pool_resource->AllocateWithGpuMemoryBuffer(size, format, usage_, | 144 pool_resource->AllocateWithGpuMemoryBuffer(size, format, usage_, |
| 133 color_space); | 145 color_space); |
| 134 } else { | 146 } else { |
| 135 pool_resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 147 pool_resource->Allocate(size, hint_, format, color_space); |
| 136 format, color_space); | |
| 137 } | 148 } |
| 138 | 149 |
| 139 DCHECK(ResourceUtil::VerifySizeInBytes<size_t>(pool_resource->size(), | 150 DCHECK(ResourceUtil::VerifySizeInBytes<size_t>(pool_resource->size(), |
| 140 pool_resource->format())); | 151 pool_resource->format())); |
| 141 total_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( | 152 total_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( |
| 142 pool_resource->size(), pool_resource->format()); | 153 pool_resource->size(), pool_resource->format()); |
| 143 ++total_resource_count_; | 154 ++total_resource_count_; |
| 144 | 155 |
| 145 // Clear the invalidated rect and content ID, as we are about to raster new | 156 // Clear the invalidated rect and content ID, as we are about to raster new |
| 146 // content. These will be re-set when rasterization completes successfully. | 157 // content. These will be re-set when rasterization completes successfully. |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 // Release all resources, regardless of how recently they were used. | 490 // Release all resources, regardless of how recently they were used. |
| 480 EvictResourcesNotUsedSince(base::TimeTicks() + base::TimeDelta::Max()); | 491 EvictResourcesNotUsedSince(base::TimeTicks() + base::TimeDelta::Max()); |
| 481 break; | 492 break; |
| 482 case base::MemoryState::UNKNOWN: | 493 case base::MemoryState::UNKNOWN: |
| 483 // NOT_REACHED. | 494 // NOT_REACHED. |
| 484 break; | 495 break; |
| 485 } | 496 } |
| 486 } | 497 } |
| 487 | 498 |
| 488 } // namespace cc | 499 } // namespace cc |
| OLD | NEW |