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

Side by Side Diff: cc/resources/resource_pool.cc

Issue 2235623003: cc: Add gfx::ColorSpace to cc::ResourceProvider resource creation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 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
« no previous file with comments | « cc/resources/resource_pool.h ('k') | cc/resources/resource_pool_unittest.cc » ('j') | 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/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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 88 }
89 89
90 SetResourceUsageLimits(0, 0); 90 SetResourceUsageLimits(0, 0);
91 DCHECK_EQ(0u, unused_resources_.size()); 91 DCHECK_EQ(0u, unused_resources_.size());
92 DCHECK_EQ(0u, in_use_memory_usage_bytes_); 92 DCHECK_EQ(0u, in_use_memory_usage_bytes_);
93 DCHECK_EQ(0u, total_memory_usage_bytes_); 93 DCHECK_EQ(0u, total_memory_usage_bytes_);
94 DCHECK_EQ(0u, total_resource_count_); 94 DCHECK_EQ(0u, total_resource_count_);
95 } 95 }
96 96
97 Resource* ResourcePool::AcquireResource(const gfx::Size& size, 97 Resource* ResourcePool::AcquireResource(const gfx::Size& size,
98 ResourceFormat format) { 98 ResourceFormat format,
99 const gfx::ColorSpace& color_space) {
99 // Finding resources in |unused_resources_| from MRU to LRU direction, touches 100 // Finding resources in |unused_resources_| from MRU to LRU direction, touches
100 // LRU resources only if needed, which increases possibility of expiring more 101 // LRU resources only if needed, which increases possibility of expiring more
101 // LRU resources within kResourceExpirationDelayMs. 102 // LRU resources within kResourceExpirationDelayMs.
102 for (ResourceDeque::iterator it = unused_resources_.begin(); 103 for (ResourceDeque::iterator it = unused_resources_.begin();
103 it != unused_resources_.end(); ++it) { 104 it != unused_resources_.end(); ++it) {
104 ScopedResource* resource = it->get(); 105 ScopedResource* resource = it->get();
105 DCHECK(resource_provider_->CanLockForWrite(resource->id())); 106 DCHECK(resource_provider_->CanLockForWrite(resource->id()));
106 107
107 if (resource->format() != format) 108 if (resource->format() != format)
108 continue; 109 continue;
109 if (resource->size() != size) 110 if (resource->size() != size)
110 continue; 111 continue;
112 if (resource->color_space() != color_space)
113 continue;
111 114
112 // Transfer resource to |in_use_resources_|. 115 // Transfer resource to |in_use_resources_|.
113 in_use_resources_[resource->id()] = std::move(*it); 116 in_use_resources_[resource->id()] = std::move(*it);
114 unused_resources_.erase(it); 117 unused_resources_.erase(it);
115 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( 118 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
116 resource->size(), resource->format()); 119 resource->size(), resource->format());
117 return resource; 120 return resource;
118 } 121 }
119 122
120 std::unique_ptr<PoolResource> pool_resource = 123 std::unique_ptr<PoolResource> pool_resource =
121 PoolResource::Create(resource_provider_); 124 PoolResource::Create(resource_provider_);
122 125
123 if (use_gpu_memory_buffers_) { 126 if (use_gpu_memory_buffers_) {
124 pool_resource->AllocateWithGpuMemoryBuffer(size, format, usage_); 127 pool_resource->AllocateWithGpuMemoryBuffer(size, format, usage_,
128 color_space);
125 } else { 129 } else {
126 pool_resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, 130 pool_resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE,
127 format); 131 format, color_space);
128 } 132 }
129 133
130 DCHECK(ResourceUtil::VerifySizeInBytes<size_t>(pool_resource->size(), 134 DCHECK(ResourceUtil::VerifySizeInBytes<size_t>(pool_resource->size(),
131 pool_resource->format())); 135 pool_resource->format()));
132 total_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( 136 total_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
133 pool_resource->size(), pool_resource->format()); 137 pool_resource->size(), pool_resource->format());
134 ++total_resource_count_; 138 ++total_resource_count_;
135 139
136 // Clear the invalidated rect and content ID, as we are about to raster new 140 // Clear the invalidated rect and content ID, as we are about to raster new
137 // content. These will be re-set when rasterization completes successfully. 141 // content. These will be re-set when rasterization completes successfully.
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 for (const auto& resource : busy_resources_) { 436 for (const auto& resource : busy_resources_) {
433 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 437 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
434 } 438 }
435 for (const auto& entry : in_use_resources_) { 439 for (const auto& entry : in_use_resources_) {
436 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 440 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
437 } 441 }
438 return true; 442 return true;
439 } 443 }
440 444
441 } // namespace cc 445 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_pool.h ('k') | cc/resources/resource_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698