OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_ |
6 #define GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_ |
7 | 7 |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "gpu/command_buffer/service/shader_translator.h" | 14 #include "gpu/command_buffer/service/shader_translator.h" |
15 #include "third_party/angle/include/GLSLANG/ShaderLang.h" | 15 #include "third_party/angle/include/GLSLANG/ShaderLang.h" |
16 | 16 |
17 namespace gpu { | 17 namespace gpu { |
| 18 |
| 19 struct GpuPreferences; |
| 20 |
18 namespace gles2 { | 21 namespace gles2 { |
19 | 22 |
20 // This class is not thread safe and can only be created and destroyed | 23 // This class is not thread safe and can only be created and destroyed |
21 // on a single thread. But it is safe to use two independent instances on two | 24 // on a single thread. But it is safe to use two independent instances on two |
22 // threads without synchronization. | 25 // threads without synchronization. |
23 // | 26 // |
24 // TODO(backer): Investigate using glReleaseShaderCompiler as an alternative to | 27 // TODO(backer): Investigate using glReleaseShaderCompiler as an alternative to |
25 // to this cache. | 28 // to this cache. |
26 class GPU_EXPORT ShaderTranslatorCache | 29 class GPU_EXPORT ShaderTranslatorCache |
27 : public base::RefCounted<ShaderTranslatorCache>, | 30 : public base::RefCounted<ShaderTranslatorCache>, |
28 public NON_EXPORTED_BASE(ShaderTranslator::DestructionObserver) { | 31 public NON_EXPORTED_BASE(ShaderTranslator::DestructionObserver) { |
29 public: | 32 public: |
30 ShaderTranslatorCache(); | 33 explicit ShaderTranslatorCache(const GpuPreferences& gpu_preferences); |
31 | 34 |
32 // ShaderTranslator::DestructionObserver implementation | 35 // ShaderTranslator::DestructionObserver implementation |
33 void OnDestruct(ShaderTranslator* translator) override; | 36 void OnDestruct(ShaderTranslator* translator) override; |
34 | 37 |
35 scoped_refptr<ShaderTranslator> GetTranslator( | 38 scoped_refptr<ShaderTranslator> GetTranslator( |
36 sh::GLenum shader_type, | 39 sh::GLenum shader_type, |
37 ShShaderSpec shader_spec, | 40 ShShaderSpec shader_spec, |
38 const ShBuiltInResources* resources, | 41 const ShBuiltInResources* resources, |
39 ShShaderOutput shader_output_language, | 42 ShShaderOutput shader_output_language, |
40 ShCompileOptions driver_bug_workarounds); | 43 ShCompileOptions driver_bug_workarounds); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 78 |
76 bool operator< (const ShaderTranslatorInitParams& params) const { | 79 bool operator< (const ShaderTranslatorInitParams& params) const { |
77 return memcmp(¶ms, this, sizeof(*this)) < 0; | 80 return memcmp(¶ms, this, sizeof(*this)) < 0; |
78 } | 81 } |
79 | 82 |
80 private: | 83 private: |
81 ShaderTranslatorInitParams(); | 84 ShaderTranslatorInitParams(); |
82 ShaderTranslatorInitParams& operator=(const ShaderTranslatorInitParams&); | 85 ShaderTranslatorInitParams& operator=(const ShaderTranslatorInitParams&); |
83 }; | 86 }; |
84 | 87 |
| 88 const GpuPreferences& gpu_preferences_; |
| 89 |
85 typedef std::map<ShaderTranslatorInitParams, ShaderTranslator* > Cache; | 90 typedef std::map<ShaderTranslatorInitParams, ShaderTranslator* > Cache; |
86 Cache cache_; | 91 Cache cache_; |
87 | 92 |
88 DISALLOW_COPY_AND_ASSIGN(ShaderTranslatorCache); | 93 DISALLOW_COPY_AND_ASSIGN(ShaderTranslatorCache); |
89 }; | 94 }; |
90 | 95 |
91 } // namespace gles2 | 96 } // namespace gles2 |
92 } // namespace gpu | 97 } // namespace gpu |
93 | 98 |
94 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_ | 99 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_ |
OLD | NEW |