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