Add ICU message format support
[chromium-blink-merge.git] / cc / resources / resource_pool.h
blobefd1e015c9406dd7e9798ba13dcc3bf7eea4f19f
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_
8 #include <deque>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/trace_event/memory_dump_provider.h"
12 #include "cc/base/cc_export.h"
13 #include "cc/output/renderer.h"
14 #include "cc/resources/resource.h"
15 #include "cc/resources/resource_format.h"
17 namespace cc {
18 class ScopedResource;
20 class CC_EXPORT ResourcePool : public base::trace_event::MemoryDumpProvider {
21 public:
22 static scoped_ptr<ResourcePool> Create(ResourceProvider* resource_provider,
23 GLenum target) {
24 return make_scoped_ptr(new ResourcePool(resource_provider, target));
27 ~ResourcePool() override;
29 scoped_ptr<ScopedResource> AcquireResource(const gfx::Size& size,
30 ResourceFormat format);
31 scoped_ptr<ScopedResource> TryAcquireResourceWithContentId(uint64 content_id);
32 void ReleaseResource(scoped_ptr<ScopedResource> resource,
33 uint64_t content_id);
35 void SetResourceUsageLimits(size_t max_memory_usage_bytes,
36 size_t max_unused_memory_usage_bytes,
37 size_t max_resource_count);
39 void ReduceResourceUsage();
40 // This might block if |wait_if_needed| is true and one of the currently
41 // busy resources has a read lock fence that needs to be waited upon before
42 // it can be locked for write again.
43 void CheckBusyResources(bool wait_if_needed);
45 size_t total_memory_usage_bytes() const { return memory_usage_bytes_; }
46 size_t acquired_memory_usage_bytes() const {
47 return memory_usage_bytes_ - unused_memory_usage_bytes_;
49 size_t total_resource_count() const { return resource_count_; }
50 size_t acquired_resource_count() const {
51 return resource_count_ - unused_resources_.size();
53 size_t busy_resource_count() const { return busy_resources_.size(); }
55 // Overridden from base::trace_event::MemoryDumpProvider:
56 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
57 base::trace_event::ProcessMemoryDump* pmd) override;
59 protected:
60 ResourcePool(ResourceProvider* resource_provider, GLenum target);
62 bool ResourceUsageTooHigh();
64 private:
65 void DidFinishUsingResource(ScopedResource* resource, uint64_t content_id);
66 void DeleteResource(ScopedResource* resource);
68 ResourceProvider* resource_provider_;
69 const GLenum target_;
70 size_t max_memory_usage_bytes_;
71 size_t max_unused_memory_usage_bytes_;
72 size_t max_resource_count_;
73 size_t memory_usage_bytes_;
74 size_t unused_memory_usage_bytes_;
75 size_t resource_count_;
77 struct PoolResource {
78 PoolResource(ScopedResource* resource, uint64_t content_id)
79 : resource(resource), content_id(content_id) {}
80 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
81 bool is_free) const;
83 ScopedResource* resource;
84 uint64_t content_id;
86 typedef std::deque<PoolResource> ResourceList;
87 ResourceList unused_resources_;
88 ResourceList busy_resources_;
90 DISALLOW_COPY_AND_ASSIGN(ResourcePool);
93 } // namespace cc
95 #endif // CC_RESOURCES_RESOURCE_POOL_H_