• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CC_RESOURCES_RESOURCE_POOL_H_
6 #define CC_RESOURCES_RESOURCE_POOL_H_
7 
8 #include <list>
9 
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"
15 
16 namespace cc {
17 class ScopedResource;
18 
19 class CC_EXPORT ResourcePool {
20  public:
Create(ResourceProvider * resource_provider,GLenum target,ResourceFormat format)21   static scoped_ptr<ResourcePool> Create(ResourceProvider* resource_provider,
22                                          GLenum target,
23                                          ResourceFormat format) {
24     return make_scoped_ptr(new ResourcePool(resource_provider,
25                                             target,
26                                             format));
27   }
28 
29   virtual ~ResourcePool();
30 
31   scoped_ptr<ScopedResource> AcquireResource(gfx::Size size);
32   void ReleaseResource(scoped_ptr<ScopedResource>);
33 
34   void SetResourceUsageLimits(size_t max_memory_usage_bytes,
35                               size_t max_unused_memory_usage_bytes,
36                               size_t max_resource_count);
37 
38   void ReduceResourceUsage();
39   void CheckBusyResources();
40 
total_memory_usage_bytes()41   size_t total_memory_usage_bytes() const {
42     return memory_usage_bytes_;
43   }
acquired_memory_usage_bytes()44   size_t acquired_memory_usage_bytes() const {
45     return memory_usage_bytes_ - unused_memory_usage_bytes_;
46   }
acquired_resource_count()47   size_t acquired_resource_count() const {
48     return resource_count_ - unused_resources_.size();
49   }
50 
51  protected:
52   ResourcePool(ResourceProvider* resource_provider,
53                GLenum target,
54                ResourceFormat format);
55 
56   bool ResourceUsageTooHigh();
57 
58  private:
59   void DidFinishUsingResource(ScopedResource* resource);
60 
61   ResourceProvider* resource_provider_;
62   const GLenum target_;
63   const ResourceFormat format_;
64   size_t max_memory_usage_bytes_;
65   size_t max_unused_memory_usage_bytes_;
66   size_t max_resource_count_;
67   size_t memory_usage_bytes_;
68   size_t unused_memory_usage_bytes_;
69   size_t resource_count_;
70 
71   typedef std::list<ScopedResource*> ResourceList;
72   ResourceList unused_resources_;
73   ResourceList busy_resources_;
74 
75   DISALLOW_COPY_AND_ASSIGN(ResourcePool);
76 };
77 
78 }  // namespace cc
79 
80 #endif  // CC_RESOURCES_RESOURCE_POOL_H_
81