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_
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"
21 // Program cache that stores binaries completely in-memory
22 class GPU_EXPORT MemoryProgramCache
: public ProgramCache
{
25 explicit MemoryProgramCache(const size_t max_cache_size_bytes
);
26 ~MemoryProgramCache() override
;
28 ProgramLoadResult
LoadLinkedProgram(
32 const LocationMap
* bind_attrib_location_map
,
33 const std::vector
<std::string
>& transform_feedback_varyings
,
34 GLenum transform_feedback_buffer_mode
,
35 const ShaderCacheCallback
& shader_callback
) override
;
36 void SaveLinkedProgram(
38 const Shader
* shader_a
,
39 const Shader
* shader_b
,
40 const LocationMap
* bind_attrib_location_map
,
41 const std::vector
<std::string
>& transform_feedback_varyings
,
42 GLenum transform_feedback_buffer_mode
,
43 const ShaderCacheCallback
& shader_callback
) override
;
45 void LoadProgram(const std::string
& program
) override
;
48 void ClearBackend() override
;
50 class ProgramCacheValue
: public base::RefCounted
<ProgramCacheValue
> {
52 ProgramCacheValue(GLsizei length
,
55 const std::string
& program_hash
,
56 const char* shader_0_hash
,
57 const AttributeMap
& attrib_map_0
,
58 const UniformMap
& uniform_map_0
,
59 const VaryingMap
& varying_map_0
,
60 const char* shader_1_hash
,
61 const AttributeMap
& attrib_map_1
,
62 const UniformMap
& uniform_map_1
,
63 const VaryingMap
& varying_map_1
,
64 MemoryProgramCache
* program_cache
);
66 GLsizei
length() const {
70 GLenum
format() const {
74 const char* data() const {
78 const std::string
& shader_0_hash() const {
79 return shader_0_hash_
;
82 const AttributeMap
& attrib_map_0() const {
86 const UniformMap
& uniform_map_0() const {
87 return uniform_map_0_
;
90 const VaryingMap
& varying_map_0() const {
91 return varying_map_0_
;
94 const std::string
& shader_1_hash() const {
95 return shader_1_hash_
;
98 const AttributeMap
& attrib_map_1() const {
102 const UniformMap
& uniform_map_1() const {
103 return uniform_map_1_
;
106 const VaryingMap
& varying_map_1() const {
107 return varying_map_1_
;
111 friend class base::RefCounted
<ProgramCacheValue
>;
113 ~ProgramCacheValue();
115 const GLsizei length_
;
116 const GLenum format_
;
117 const scoped_ptr
<const char[]> data_
;
118 const std::string program_hash_
;
119 const std::string shader_0_hash_
;
120 const AttributeMap attrib_map_0_
;
121 const UniformMap uniform_map_0_
;
122 const VaryingMap varying_map_0_
;
123 const std::string shader_1_hash_
;
124 const AttributeMap attrib_map_1_
;
125 const UniformMap uniform_map_1_
;
126 const VaryingMap varying_map_1_
;
127 MemoryProgramCache
* const program_cache_
;
129 DISALLOW_COPY_AND_ASSIGN(ProgramCacheValue
);
132 friend class ProgramCacheValue
;
134 typedef base::MRUCache
<std::string
,
135 scoped_refptr
<ProgramCacheValue
> > ProgramMRUCache
;
137 const size_t max_size_bytes_
;
138 size_t curr_size_bytes_
;
139 ProgramMRUCache store_
;
141 DISALLOW_COPY_AND_ASSIGN(MemoryProgramCache
);
147 #endif // GPU_COMMAND_BUFFER_SERVICE_MEMORY_PROGRAM_CACHE_H_