Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / gpu / command_buffer / service / memory_program_cache.h
blobb5862d269345cd42aa9e62c51d02dd9af6310e1d
1 // Copyright (c) 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 GPU_COMMAND_BUFFER_SERVICE_MEMORY_PROGRAM_CACHE_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_MEMORY_PROGRAM_CACHE_H_
8 #include <map>
9 #include <string>
11 #include "base/containers/hash_tables.h"
12 #include "base/containers/mru_cache.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
16 #include "gpu/command_buffer/service/program_cache.h"
18 namespace gpu {
19 namespace gles2 {
21 // Program cache that stores binaries completely in-memory
22 class GPU_EXPORT MemoryProgramCache : public ProgramCache {
23 public:
24 MemoryProgramCache();
25 explicit MemoryProgramCache(const size_t max_cache_size_bytes);
26 ~MemoryProgramCache() override;
28 ProgramLoadResult LoadLinkedProgram(
29 GLuint program,
30 Shader* shader_a,
31 Shader* shader_b,
32 const LocationMap* bind_attrib_location_map,
33 const ShaderCacheCallback& shader_callback) override;
34 void SaveLinkedProgram(GLuint program,
35 const Shader* shader_a,
36 const Shader* shader_b,
37 const LocationMap* bind_attrib_location_map,
38 const ShaderCacheCallback& shader_callback) override;
40 void LoadProgram(const std::string& program) override;
42 private:
43 void ClearBackend() override;
45 class ProgramCacheValue : public base::RefCounted<ProgramCacheValue> {
46 public:
47 ProgramCacheValue(GLsizei length,
48 GLenum format,
49 const char* data,
50 const std::string& program_hash,
51 const char* shader_0_hash,
52 const AttributeMap& attrib_map_0,
53 const UniformMap& uniform_map_0,
54 const VaryingMap& varying_map_0,
55 const char* shader_1_hash,
56 const AttributeMap& attrib_map_1,
57 const UniformMap& uniform_map_1,
58 const VaryingMap& varying_map_1,
59 MemoryProgramCache* program_cache);
61 GLsizei length() const {
62 return length_;
65 GLenum format() const {
66 return format_;
69 const char* data() const {
70 return data_.get();
73 const std::string& shader_0_hash() const {
74 return shader_0_hash_;
77 const AttributeMap& attrib_map_0() const {
78 return attrib_map_0_;
81 const UniformMap& uniform_map_0() const {
82 return uniform_map_0_;
85 const VaryingMap& varying_map_0() const {
86 return varying_map_0_;
89 const std::string& shader_1_hash() const {
90 return shader_1_hash_;
93 const AttributeMap& attrib_map_1() const {
94 return attrib_map_1_;
97 const UniformMap& uniform_map_1() const {
98 return uniform_map_1_;
101 const VaryingMap& varying_map_1() const {
102 return varying_map_1_;
105 private:
106 friend class base::RefCounted<ProgramCacheValue>;
108 ~ProgramCacheValue();
110 const GLsizei length_;
111 const GLenum format_;
112 const scoped_ptr<const char[]> data_;
113 const std::string program_hash_;
114 const std::string shader_0_hash_;
115 const AttributeMap attrib_map_0_;
116 const UniformMap uniform_map_0_;
117 const VaryingMap varying_map_0_;
118 const std::string shader_1_hash_;
119 const AttributeMap attrib_map_1_;
120 const UniformMap uniform_map_1_;
121 const VaryingMap varying_map_1_;
122 MemoryProgramCache* const program_cache_;
124 DISALLOW_COPY_AND_ASSIGN(ProgramCacheValue);
127 friend class ProgramCacheValue;
129 typedef base::MRUCache<std::string,
130 scoped_refptr<ProgramCacheValue> > ProgramMRUCache;
132 const size_t max_size_bytes_;
133 size_t curr_size_bytes_;
134 ProgramMRUCache store_;
136 DISALLOW_COPY_AND_ASSIGN(MemoryProgramCache);
139 } // namespace gles2
140 } // namespace gpu
142 #endif // GPU_COMMAND_BUFFER_SERVICE_MEMORY_PROGRAM_CACHE_H_