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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 uint64_t total_bytes = ResourceUtil::UncheckedSizeInBytesAligned<size_t>( | 32 uint64_t total_bytes = ResourceUtil::UncheckedSizeInBytesAligned<size_t>( |
33 resource->size(), resource->format()); | 33 resource->size(), resource->format()); |
34 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 34 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
35 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 35 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
36 total_bytes); | 36 total_bytes); |
37 dump->AddScalar("free_size", | 37 dump->AddScalar("free_size", |
38 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 38 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
39 is_free ? total_bytes : 0); | 39 is_free ? total_bytes : 0); |
40 } | 40 } |
| 41 ResourcePool::ResourcePool(ResourceProvider* resource_provider) |
| 42 : resource_provider_(resource_provider), |
| 43 target_(0), |
| 44 max_memory_usage_bytes_(0), |
| 45 max_unused_memory_usage_bytes_(0), |
| 46 max_resource_count_(0), |
| 47 memory_usage_bytes_(0), |
| 48 unused_memory_usage_bytes_(0), |
| 49 resource_count_(0) { |
| 50 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 51 this, base::ThreadTaskRunnerHandle::Get()); |
| 52 } |
41 | 53 |
42 ResourcePool::ResourcePool(ResourceProvider* resource_provider, GLenum target) | 54 ResourcePool::ResourcePool(ResourceProvider* resource_provider, GLenum target) |
43 : resource_provider_(resource_provider), | 55 : resource_provider_(resource_provider), |
44 target_(target), | 56 target_(target), |
45 max_memory_usage_bytes_(0), | 57 max_memory_usage_bytes_(0), |
46 max_unused_memory_usage_bytes_(0), | 58 max_unused_memory_usage_bytes_(0), |
47 max_resource_count_(0), | 59 max_resource_count_(0), |
48 memory_usage_bytes_(0), | 60 memory_usage_bytes_(0), |
49 unused_memory_usage_bytes_(0), | 61 unused_memory_usage_bytes_(0), |
50 resource_count_(0) { | 62 resource_count_(0) { |
| 63 DCHECK_NE(0u, target); |
51 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 64 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
52 this, base::ThreadTaskRunnerHandle::Get()); | 65 this, base::ThreadTaskRunnerHandle::Get()); |
53 } | 66 } |
54 | 67 |
55 ResourcePool::~ResourcePool() { | 68 ResourcePool::~ResourcePool() { |
56 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 69 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
57 this); | 70 this); |
58 while (!busy_resources_.empty()) { | 71 while (!busy_resources_.empty()) { |
59 auto const& front = busy_resources_.front(); | 72 auto const& front = busy_resources_.front(); |
60 DidFinishUsingResource(front.resource, front.content_id); | 73 DidFinishUsingResource(front.resource, front.content_id); |
(...skipping 21 matching lines...) Expand all Loading... |
82 continue; | 95 continue; |
83 | 96 |
84 unused_resources_.erase(it); | 97 unused_resources_.erase(it); |
85 unused_memory_usage_bytes_ -= | 98 unused_memory_usage_bytes_ -= |
86 ResourceUtil::UncheckedSizeInBytes<size_t>(size, format); | 99 ResourceUtil::UncheckedSizeInBytes<size_t>(size, format); |
87 return make_scoped_ptr(resource); | 100 return make_scoped_ptr(resource); |
88 } | 101 } |
89 | 102 |
90 scoped_ptr<ScopedResource> resource = | 103 scoped_ptr<ScopedResource> resource = |
91 ScopedResource::Create(resource_provider_); | 104 ScopedResource::Create(resource_provider_); |
92 resource->AllocateManaged(size, target_, format); | 105 GLenum target = |
| 106 target_ ? target_ : resource_provider_->GetImageTextureTarget(format); |
| 107 resource->AllocateManaged(size, target, format); |
93 | 108 |
94 DCHECK(ResourceUtil::VerifySizeInBytes<size_t>(resource->size(), | 109 DCHECK(ResourceUtil::VerifySizeInBytes<size_t>(resource->size(), |
95 resource->format())); | 110 resource->format())); |
96 memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( | 111 memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( |
97 resource->size(), resource->format()); | 112 resource->size(), resource->format()); |
98 ++resource_count_; | 113 ++resource_count_; |
99 return resource.Pass(); | 114 return resource.Pass(); |
100 } | 115 } |
101 | 116 |
102 scoped_ptr<ScopedResource> ResourcePool::TryAcquireResourceWithContentId( | 117 scoped_ptr<ScopedResource> ResourcePool::TryAcquireResourceWithContentId( |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 } | 223 } |
209 for (const auto& resource : busy_resources_) { | 224 for (const auto& resource : busy_resources_) { |
210 resource.OnMemoryDump(pmd, false /* is_free */); | 225 resource.OnMemoryDump(pmd, false /* is_free */); |
211 } | 226 } |
212 // TODO(ericrk): Dump vended out resources once that data is available. | 227 // TODO(ericrk): Dump vended out resources once that data is available. |
213 // crbug.com/516541 | 228 // crbug.com/516541 |
214 return true; | 229 return true; |
215 } | 230 } |
216 | 231 |
217 } // namespace cc | 232 } // namespace cc |
OLD | NEW |