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

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

Issue 2110083004: Partial raster for GPU (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@partialuma2
Patch Set: hi Created 4 years, 5 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
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 pool_resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, 126 pool_resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE,
127 format); 127 format);
128 } 128 }
129 129
130 DCHECK(ResourceUtil::VerifySizeInBytes<size_t>(pool_resource->size(), 130 DCHECK(ResourceUtil::VerifySizeInBytes<size_t>(pool_resource->size(),
131 pool_resource->format())); 131 pool_resource->format()));
132 total_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( 132 total_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
133 pool_resource->size(), pool_resource->format()); 133 pool_resource->size(), pool_resource->format());
134 ++total_resource_count_; 134 ++total_resource_count_;
135 135
136 // 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.
138 pool_resource->set_invalidated_rect(gfx::Rect());
139 pool_resource->set_content_id(0);
140
136 Resource* resource = pool_resource.get(); 141 Resource* resource = pool_resource.get();
137 in_use_resources_[resource->id()] = std::move(pool_resource); 142 in_use_resources_[resource->id()] = std::move(pool_resource);
138 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( 143 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
139 resource->size(), resource->format()); 144 resource->size(), resource->format());
145
140 return resource; 146 return resource;
141 } 147 }
142 148
143 Resource* ResourcePool::TryAcquireResourceWithContentId(uint64_t content_id) { 149 Resource* ResourcePool::TryAcquireResourceForPartialRaster(
144 DCHECK(content_id); 150 uint64_t new_content_id,
151 const gfx::Rect& new_invalidated_rect,
152 uint64_t previous_content_id,
153 gfx::Rect* total_invalidated_rect) {
154 DCHECK(new_content_id);
155 DCHECK(previous_content_id);
156 *total_invalidated_rect = gfx::Rect();
145 157
146 auto it = std::find_if( 158 // Try to find |previous_content_id| in |unused_resources_|.
159 auto found_unused = std::find_if(
147 unused_resources_.begin(), unused_resources_.end(), 160 unused_resources_.begin(), unused_resources_.end(),
148 [content_id](const std::unique_ptr<PoolResource>& pool_resource) { 161 [previous_content_id](const ResourceDeque::value_type& pool_resource) {
149 return pool_resource->content_id() == content_id; 162 return pool_resource->content_id() == previous_content_id;
150 }); 163 });
151 if (it == unused_resources_.end()) 164 if (found_unused != unused_resources_.end()) {
152 return nullptr; 165 PoolResource* found_resource = found_unused->get();
166 DCHECK(resource_provider_->CanLockForWrite(found_resource->id()));
153 167
154 Resource* resource = it->get(); 168 // Transfer resource to |in_use_resources_|.
155 DCHECK(resource_provider_->CanLockForWrite(resource->id())); 169 in_use_resources_[found_resource->id()] = std::move(*found_unused);
170 unused_resources_.erase(found_unused);
171 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>(
172 found_resource->size(), found_resource->format());
156 173
157 // Transfer resource to |in_use_resources_|. 174 *total_invalidated_rect = new_invalidated_rect;
158 in_use_resources_[resource->id()] = std::move(*it); 175 if (!found_resource->invalidated_rect().IsEmpty())
159 unused_resources_.erase(it); 176 total_invalidated_rect->Union(found_resource->invalidated_rect());
160 in_use_memory_usage_bytes_ += ResourceUtil::UncheckedSizeInBytes<size_t>( 177
161 resource->size(), resource->format()); 178 // Clear the invalidated rect and content ID on the resource being retunred.
162 return resource; 179 // These will be updated when raster completes successfully.
180 found_resource->set_invalidated_rect(gfx::Rect());
181 found_resource->set_content_id(0);
182
183 return found_resource;
184 }
185
186 // Couldn't find an unused previous resource. If possible, update the
187 // invalidation on the in-use resource to allow for future partial raster.
188 auto found_in_use = std::find_if(
189 in_use_resources_.begin(), in_use_resources_.end(),
190 [previous_content_id](const InUseResourceMap::value_type& in_use_entry) {
191 return in_use_entry.second->content_id() == previous_content_id;
192 });
193 if (found_in_use != in_use_resources_.end()) {
194 PoolResource* found_resource = found_in_use->second.get();
195 gfx::Rect updated_invalidated_rect = new_invalidated_rect;
196 if (!found_resource->invalidated_rect().IsEmpty())
197 updated_invalidated_rect.Union(found_resource->invalidated_rect());
198
199 found_resource->set_content_id(new_content_id);
enne (OOO) 2016/07/11 21:16:24 I guess this could mean that potentially there are
ericrk 2016/07/12 17:31:56 Per our offline discussion, added a comment to exp
200 found_resource->set_invalidated_rect(updated_invalidated_rect);
201 }
202
203 return nullptr;
163 } 204 }
164 205
165 void ResourcePool::ReleaseResource(Resource* resource, uint64_t content_id) { 206 void ResourcePool::ReleaseResource(Resource* resource) {
166 // Ensure that the provided resource is valid. 207 // Ensure that the provided resource is valid.
167 // TODO(ericrk): Remove this once we've investigated further. 208 // TODO(ericrk): Remove this once we've investigated further.
168 // crbug.com/598286. 209 // crbug.com/598286.
169 CHECK(resource); 210 CHECK(resource);
170 CHECK(resource->id()); 211 CHECK(resource->id());
171 212
172 auto it = in_use_resources_.find(resource->id()); 213 auto it = in_use_resources_.find(resource->id());
173 if (it == in_use_resources_.end()) { 214 if (it == in_use_resources_.end()) {
174 // We should never hit this. Do some digging to try to determine the cause. 215 // We should never hit this. Do some digging to try to determine the cause.
175 // TODO(ericrk): Remove this once we've investigated further. 216 // TODO(ericrk): Remove this once we've investigated further.
(...skipping 19 matching lines...) Expand all
195 // Resource doesn't exist in any of our lists. CHECK. 236 // Resource doesn't exist in any of our lists. CHECK.
196 CHECK(false); 237 CHECK(false);
197 } 238 }
198 239
199 // Also ensure that the resource wasn't null in our list. 240 // Also ensure that the resource wasn't null in our list.
200 // TODO(ericrk): Remove this once we've investigated further. 241 // TODO(ericrk): Remove this once we've investigated further.
201 // crbug.com/598286. 242 // crbug.com/598286.
202 CHECK(it->second.get()); 243 CHECK(it->second.get());
203 244
204 PoolResource* pool_resource = it->second.get(); 245 PoolResource* pool_resource = it->second.get();
205 pool_resource->set_content_id(content_id);
206 pool_resource->set_last_usage(base::TimeTicks::Now()); 246 pool_resource->set_last_usage(base::TimeTicks::Now());
207 247
208 // Transfer resource to |busy_resources_|. 248 // Transfer resource to |busy_resources_|.
209 busy_resources_.push_front(std::move(it->second)); 249 busy_resources_.push_front(std::move(it->second));
210 in_use_resources_.erase(it); 250 in_use_resources_.erase(it);
211 in_use_memory_usage_bytes_ -= ResourceUtil::UncheckedSizeInBytes<size_t>( 251 in_use_memory_usage_bytes_ -= ResourceUtil::UncheckedSizeInBytes<size_t>(
212 pool_resource->size(), pool_resource->format()); 252 pool_resource->size(), pool_resource->format());
213 253
214 // Now that we have evictable resources, schedule an eviction call for this 254 // Now that we have evictable resources, schedule an eviction call for this
215 // resource if necessary. 255 // resource if necessary.
216 ScheduleEvictExpiredResourcesIn(resource_expiration_delay_); 256 ScheduleEvictExpiredResourcesIn(resource_expiration_delay_);
217 } 257 }
218 258
259 void ResourcePool::OnContentReplaced(ResourceId resource_id,
260 uint64_t content_id) {
261 auto found = in_use_resources_.find(resource_id);
262 DCHECK(found != in_use_resources_.end());
263 found->second->set_content_id(content_id);
264 found->second->set_invalidated_rect(gfx::Rect());
265 }
266
219 void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes, 267 void ResourcePool::SetResourceUsageLimits(size_t max_memory_usage_bytes,
220 size_t max_resource_count) { 268 size_t max_resource_count) {
221 max_memory_usage_bytes_ = max_memory_usage_bytes; 269 max_memory_usage_bytes_ = max_memory_usage_bytes;
222 max_resource_count_ = max_resource_count; 270 max_resource_count_ = max_resource_count;
223 271
224 ReduceResourceUsage(); 272 ReduceResourceUsage();
225 } 273 }
226 274
227 void ResourcePool::ReduceResourceUsage() { 275 void ResourcePool::ReduceResourceUsage() {
228 while (!unused_resources_.empty()) { 276 while (!unused_resources_.empty()) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 for (const auto& resource : busy_resources_) { 398 for (const auto& resource : busy_resources_) {
351 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 399 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
352 } 400 }
353 for (const auto& entry : in_use_resources_) { 401 for (const auto& entry : in_use_resources_) {
354 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); 402 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */);
355 } 403 }
356 return true; 404 return true;
357 } 405 }
358 406
359 } // namespace cc 407 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698