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
3 // found in the LICENSE file.
5 #ifndef CC_RESOURCES_RESOURCE_POOL_H_
6 #define CC_RESOURCES_RESOURCE_POOL_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "cc/base/cc_export.h"
12 #include "cc/output/renderer.h"
13 #include "cc/resources/resource.h"
14 #include "cc/resources/resource_format.h"
19 class CC_EXPORT ResourcePool
{
21 static scoped_ptr
<ResourcePool
> Create(ResourceProvider
* resource_provider
,
23 ResourceFormat format
) {
24 return make_scoped_ptr(new ResourcePool(resource_provider
, target
, format
));
27 virtual ~ResourcePool();
29 scoped_ptr
<ScopedResource
> AcquireResource(const gfx::Size
& size
);
30 void ReleaseResource(scoped_ptr
<ScopedResource
>);
32 void SetResourceUsageLimits(size_t max_memory_usage_bytes
,
33 size_t max_unused_memory_usage_bytes
,
34 size_t max_resource_count
);
36 void ReduceResourceUsage();
37 // This might block if |wait_if_needed| is true and one of the currently
38 // busy resources has a read lock fence that needs to be waited upon before
39 // it can be locked for write again.
40 void CheckBusyResources(bool wait_if_needed
);
42 size_t total_memory_usage_bytes() const { return memory_usage_bytes_
; }
43 size_t acquired_memory_usage_bytes() const {
44 return memory_usage_bytes_
- unused_memory_usage_bytes_
;
46 size_t total_resource_count() const { return resource_count_
; }
47 size_t acquired_resource_count() const {
48 return resource_count_
- unused_resources_
.size();
50 size_t busy_resource_count() const { return busy_resources_
.size(); }
52 ResourceFormat
resource_format() const { return format_
; }
55 ResourcePool(ResourceProvider
* resource_provider
,
57 ResourceFormat format
);
59 bool ResourceUsageTooHigh();
62 void DidFinishUsingResource(ScopedResource
* resource
);
64 ResourceProvider
* resource_provider_
;
66 const ResourceFormat format_
;
67 size_t max_memory_usage_bytes_
;
68 size_t max_unused_memory_usage_bytes_
;
69 size_t max_resource_count_
;
70 size_t memory_usage_bytes_
;
71 size_t unused_memory_usage_bytes_
;
72 size_t resource_count_
;
74 typedef std::list
<ScopedResource
*> ResourceList
;
75 ResourceList unused_resources_
;
76 ResourceList busy_resources_
;
78 DISALLOW_COPY_AND_ASSIGN(ResourcePool
);
83 #endif // CC_RESOURCES_RESOURCE_POOL_H_