| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_MEMORY_program_cache_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_MEMORY_program_cache_H_ |
| 7 |
| 8 #include "base/hash_tables.h" |
| 9 #include "gpu/command_buffer/service/program_cache.h" |
| 10 #include "gpu/command_buffer/service/program_cache_lru_helper.h" |
| 11 #include "gpu/command_buffer/service/shader_translator.h" |
| 12 #include "net/disk_cache/disk_cache.h" |
| 13 |
| 14 namespace { |
| 15 static const size_t kMaxMemoryCacheSizeBytes = 6*1024*1024; |
| 16 typedef std::map<std::string, GLint> BindAttribMap; |
| 17 } // anonymous namespace |
| 18 |
| 19 namespace gpu { |
| 20 namespace gles2 { |
| 21 |
| 22 // Program cache that stores binaries completely in-memory |
| 23 class GPU_EXPORT MemoryProgramCache : public ProgramCache { |
| 24 public: |
| 25 MemoryProgramCache() |
| 26 : max_size_bytes_(kMaxMemoryCacheSizeBytes), |
| 27 curr_size_bytes_(0) {} |
| 28 virtual ~MemoryProgramCache(); |
| 29 |
| 30 bool LoadLinkedProgram( |
| 31 const GLuint program, |
| 32 ShaderManager::ShaderInfo* shader_a, |
| 33 ShaderManager::ShaderInfo* shader_b, |
| 34 const BindAttribMap* bind_attrib_location_map) const; |
| 35 void SaveLinkedProgram( |
| 36 const GLuint program, |
| 37 const ShaderManager::ShaderInfo* shader_a, |
| 38 const ShaderManager::ShaderInfo* shader_b, |
| 39 const BindAttribMap* bind_attrib_location_map); |
| 40 |
| 41 private: |
| 42 void ClearBackend(); |
| 43 |
| 44 struct StoreValue { |
| 45 StoreValue() : length(0), format(0), data(NULL) { } |
| 46 StoreValue(GLsizei _length, |
| 47 GLenum _format, |
| 48 const GLvoid* _data, |
| 49 const char* _shader_0_hash, |
| 50 const ShaderTranslator::VariableMap& _attrib_map_0, |
| 51 const ShaderTranslator::VariableMap& _uniform_map_0, |
| 52 const char* _shader_1_hash, |
| 53 const ShaderTranslator::VariableMap& _attrib_map_1, |
| 54 const ShaderTranslator::VariableMap& _uniform_map_1) |
| 55 : length(_length), |
| 56 format(_format), |
| 57 data(_data), |
| 58 shader_0_hash(_shader_0_hash, kHashLength), |
| 59 attrib_map_0(_attrib_map_0), |
| 60 uniform_map_0(_uniform_map_0), |
| 61 shader_1_hash(_shader_1_hash, kHashLength), |
| 62 attrib_map_1(_attrib_map_1), |
| 63 uniform_map_1(_uniform_map_1) { } |
| 64 GLsizei length; |
| 65 GLenum format; |
| 66 const GLvoid* data; |
| 67 std::string shader_0_hash; |
| 68 ShaderTranslator::VariableMap attrib_map_0; |
| 69 ShaderTranslator::VariableMap uniform_map_0; |
| 70 std::string shader_1_hash; |
| 71 ShaderTranslator::VariableMap attrib_map_1; |
| 72 ShaderTranslator::VariableMap uniform_map_1; |
| 73 }; |
| 74 |
| 75 typedef base::hash_map<std::string, |
| 76 StoreValue> StoreMap; |
| 77 |
| 78 const size_t max_size_bytes_; |
| 79 size_t curr_size_bytes_; |
| 80 StoreMap store_; |
| 81 ProgramCacheLruHelper lru_helper_; |
| 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(MemoryProgramCache); |
| 84 }; |
| 85 |
| 86 } // namespace gles2 |
| 87 } // namespace gpu |
| 88 |
| 89 #endif /* GPU_COMMAND_BUFFER_SERVICE_MEMORY_program_cache_H_ */ |
| OLD | NEW |