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

Side by Side Diff: cc/resource_pool.cc

Issue 12197004: cc: Enforce correct recycling in resource pool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use fence interface. Created 7 years, 10 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/resource_pool.h" 5 #include "cc/resource_pool.h"
6 6
7 #include "cc/resource_provider.h" 7 #include "cc/resource_provider.h"
8 8
9 namespace cc { 9 namespace cc {
10 10
(...skipping 25 matching lines...) Expand all
36 ResourcePool::~ResourcePool() { 36 ResourcePool::~ResourcePool() {
37 SetMaxMemoryUsageBytes(0); 37 SetMaxMemoryUsageBytes(0);
38 } 38 }
39 39
40 scoped_ptr<ResourcePool::Resource> ResourcePool::AcquireResource( 40 scoped_ptr<ResourcePool::Resource> ResourcePool::AcquireResource(
41 const gfx::Size& size, GLenum format) { 41 const gfx::Size& size, GLenum format) {
42 for (ResourceList::iterator it = resources_.begin(); 42 for (ResourceList::iterator it = resources_.begin();
43 it != resources_.end(); ++it) { 43 it != resources_.end(); ++it) {
44 Resource* resource = *it; 44 Resource* resource = *it;
45 45
46 // TODO(epenner): It would nice to DCHECK that this
47 // doesn't happen two frames in a row for any resource
48 // in this pool.
49 if (!resource_provider_->canLockForWrite(resource->id()))
50 continue;
51
46 if (resource->size() != size) 52 if (resource->size() != size)
47 continue; 53 continue;
48 if (resource->format() != format) 54 if (resource->format() != format)
49 continue; 55 continue;
50 56
51 resources_.erase(it); 57 resources_.erase(it);
52 return make_scoped_ptr(resource); 58 return make_scoped_ptr(resource);
53 } 59 }
54 60
55 // Create new resource. 61 // Create new resource.
56 Resource* resource = new Resource( 62 Resource* resource = new Resource(
57 resource_provider_, size, format); 63 resource_provider_, size, format);
64
65 // Extend all read locks on all resources until the resource is
nduca 2013/02/05 22:39:05 Can we restrict this to only resources that are as
66 // finished being used, such that we know when resources are
67 // truly safe to recycle.
68 resource_provider_->enableReadLockFences(resource->id(), true);
69
58 memory_usage_bytes_ += resource->bytes(); 70 memory_usage_bytes_ += resource->bytes();
59 return make_scoped_ptr(resource); 71 return make_scoped_ptr(resource);
60 } 72 }
61 73
62 void ResourcePool::ReleaseResource( 74 void ResourcePool::ReleaseResource(
63 scoped_ptr<ResourcePool::Resource> resource) { 75 scoped_ptr<ResourcePool::Resource> resource) {
64 if (memory_usage_bytes_ > max_memory_usage_bytes_) { 76 if (memory_usage_bytes_ > max_memory_usage_bytes_) {
65 memory_usage_bytes_ -= resource->bytes(); 77 memory_usage_bytes_ -= resource->bytes();
66 return; 78 return;
67 } 79 }
68 80
69 resources_.push_back(resource.release()); 81 resources_.push_back(resource.release());
70 } 82 }
71 83
72 void ResourcePool::SetMaxMemoryUsageBytes(size_t max_memory_usage_bytes) { 84 void ResourcePool::SetMaxMemoryUsageBytes(size_t max_memory_usage_bytes) {
73 max_memory_usage_bytes_ = max_memory_usage_bytes; 85 max_memory_usage_bytes_ = max_memory_usage_bytes;
74 86
75 while (!resources_.empty()) { 87 while (!resources_.empty()) {
76 if (memory_usage_bytes_ <= max_memory_usage_bytes_) 88 if (memory_usage_bytes_ <= max_memory_usage_bytes_)
77 break; 89 break;
78 Resource* resource = resources_.front(); 90 Resource* resource = resources_.front();
79 resources_.pop_front(); 91 resources_.pop_front();
80 memory_usage_bytes_ -= resource->bytes(); 92 memory_usage_bytes_ -= resource->bytes();
81 delete resource; 93 delete resource;
82 } 94 }
83 } 95 }
84 96
85 } // namespace cc 97 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698