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/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "gpu/command_buffer/service/shader_translator.h" | 13 #include "gpu/command_buffer/service/shader_translator.h" |
14 #include "third_party/angle/include/GLSLANG/ShaderLang.h" | 14 #include "third_party/angle/include/GLSLANG/ShaderLang.h" |
15 | 15 |
16 namespace gpu { | 16 namespace gpu { |
17 namespace gles2 { | 17 namespace gles2 { |
18 | 18 |
19 // This class is not thread safe and can only be created and destroyed | 19 // This class is not thread safe and can only be created and destroyed |
20 // on a single thread. But it is safe to use two independent instances on two | 20 // on a single thread. But it is safe to use two independent instances on two |
21 // threads without synchronization. | 21 // threads without synchronization. |
22 // | 22 // |
23 // TODO(backer): Investigate using glReleaseShaderCompiler as an alternative to | 23 // TODO(backer): Investigate using glReleaseShaderCompiler as an alternative to |
24 // to this cache. | 24 // to this cache. |
| 25 // TODO(mgiuca): Avoid using UnsafeRefCounted. http://crbug.com/469952. |
25 class GPU_EXPORT ShaderTranslatorCache | 26 class GPU_EXPORT ShaderTranslatorCache |
26 : public base::RefCounted<ShaderTranslatorCache>, | 27 : public base::UnsafeRefCounted<ShaderTranslatorCache>, |
27 public NON_EXPORTED_BASE(ShaderTranslator::DestructionObserver) { | 28 public NON_EXPORTED_BASE(ShaderTranslator::DestructionObserver) { |
28 public: | 29 public: |
29 ShaderTranslatorCache(); | 30 ShaderTranslatorCache(); |
30 | 31 |
31 // ShaderTranslator::DestructionObserver implementation | 32 // ShaderTranslator::DestructionObserver implementation |
32 void OnDestruct(ShaderTranslator* translator) override; | 33 void OnDestruct(ShaderTranslator* translator) override; |
33 | 34 |
34 scoped_refptr<ShaderTranslator> GetTranslator( | 35 scoped_refptr<ShaderTranslator> GetTranslator( |
35 sh::GLenum shader_type, | 36 sh::GLenum shader_type, |
36 ShShaderSpec shader_spec, | 37 ShShaderSpec shader_spec, |
37 const ShBuiltInResources* resources, | 38 const ShBuiltInResources* resources, |
38 ShaderTranslatorInterface::GlslImplementationType | 39 ShaderTranslatorInterface::GlslImplementationType |
39 glsl_implementation_type, | 40 glsl_implementation_type, |
40 ShCompileOptions driver_bug_workarounds); | 41 ShCompileOptions driver_bug_workarounds); |
41 | 42 |
42 private: | 43 private: |
43 friend class base::RefCounted<ShaderTranslatorCache>; | 44 friend class base::UnsafeRefCounted<ShaderTranslatorCache>; |
44 friend class ShaderTranslatorCacheTest_InitParamComparable_Test; | 45 friend class ShaderTranslatorCacheTest_InitParamComparable_Test; |
45 ~ShaderTranslatorCache() override; | 46 ~ShaderTranslatorCache() override; |
46 | 47 |
47 // Parameters passed into ShaderTranslator::Init | 48 // Parameters passed into ShaderTranslator::Init |
48 struct ShaderTranslatorInitParams { | 49 struct ShaderTranslatorInitParams { |
49 sh::GLenum shader_type; | 50 sh::GLenum shader_type; |
50 ShShaderSpec shader_spec; | 51 ShShaderSpec shader_spec; |
51 ShBuiltInResources resources; | 52 ShBuiltInResources resources; |
52 ShaderTranslatorInterface::GlslImplementationType | 53 ShaderTranslatorInterface::GlslImplementationType |
53 glsl_implementation_type; | 54 glsl_implementation_type; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 typedef std::map<ShaderTranslatorInitParams, ShaderTranslator* > Cache; | 88 typedef std::map<ShaderTranslatorInitParams, ShaderTranslator* > Cache; |
88 Cache cache_; | 89 Cache cache_; |
89 | 90 |
90 DISALLOW_COPY_AND_ASSIGN(ShaderTranslatorCache); | 91 DISALLOW_COPY_AND_ASSIGN(ShaderTranslatorCache); |
91 }; | 92 }; |
92 | 93 |
93 } // namespace gles2 | 94 } // namespace gles2 |
94 } // namespace gpu | 95 } // namespace gpu |
95 | 96 |
96 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_ | 97 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_ |
OLD | NEW |