Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: gpu/command_buffer/service/shader_translator_cache.h

Issue 217813004: Make ShaderTranslatorCache thread safe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/memory/singleton.h"
14 #include "gpu/command_buffer/service/shader_translator.h" 13 #include "gpu/command_buffer/service/shader_translator.h"
15 #include "third_party/angle/include/GLSLANG/ShaderLang.h" 14 #include "third_party/angle/include/GLSLANG/ShaderLang.h"
16 15
17 namespace gpu { 16 namespace gpu {
18 namespace gles2 { 17 namespace gles2 {
19 18
20 // This singleton and the cache that it implements is NOT thread safe. 19 // This class is not thread safe and can only be created and destroyed
21 // We're relying on the fact that the all GLES2DecoderImpl's are used 20 // on a single thread. But it is safe to use two independent instances on two
22 // on one thread. 21 // threads without synchronization.
23 // 22 //
24 // TODO(backer): Investigate using glReleaseShaderCompiler as an alternative to 23 // TODO(backer): Investigate using glReleaseShaderCompiler as an alternative to
25 // to this cache. 24 // to this cache.
26 class ShaderTranslatorCache : public ShaderTranslator::DestructionObserver { 25 class GPU_EXPORT ShaderTranslatorCache
26 : public base::RefCounted<ShaderTranslatorCache>,
27 public NON_EXPORTED_BASE(ShaderTranslator::DestructionObserver) {
27 public: 28 public:
28 static ShaderTranslatorCache* GetInstance(); 29 ShaderTranslatorCache();
29 30
30 // ShaderTranslator::DestructionObserver implementation 31 // ShaderTranslator::DestructionObserver implementation
31 virtual void OnDestruct(ShaderTranslator* translator) OVERRIDE; 32 virtual void OnDestruct(ShaderTranslator* translator) OVERRIDE;
32 33
33 scoped_refptr<ShaderTranslator> GetTranslator( 34 scoped_refptr<ShaderTranslator> GetTranslator(
34 ShShaderType shader_type, 35 ShShaderType shader_type,
35 ShShaderSpec shader_spec, 36 ShShaderSpec shader_spec,
36 const ShBuiltInResources* resources, 37 const ShBuiltInResources* resources,
37 ShaderTranslatorInterface::GlslImplementationType 38 ShaderTranslatorInterface::GlslImplementationType
38 glsl_implementation_type, 39 glsl_implementation_type,
39 ShCompileOptions driver_bug_workarounds); 40 ShCompileOptions driver_bug_workarounds);
40 41
41 private: 42 private:
42 ShaderTranslatorCache(); 43 friend class base::RefCounted<ShaderTranslatorCache>;
43 virtual ~ShaderTranslatorCache(); 44 virtual ~ShaderTranslatorCache();
44 45
45 friend struct DefaultSingletonTraits<ShaderTranslatorCache>;
46
47 // Parameters passed into ShaderTranslator::Init 46 // Parameters passed into ShaderTranslator::Init
48 struct ShaderTranslatorInitParams { 47 struct ShaderTranslatorInitParams {
49 ShShaderType shader_type; 48 ShShaderType shader_type;
50 ShShaderSpec shader_spec; 49 ShShaderSpec shader_spec;
51 ShBuiltInResources resources; 50 ShBuiltInResources resources;
52 ShaderTranslatorInterface::GlslImplementationType 51 ShaderTranslatorInterface::GlslImplementationType
53 glsl_implementation_type; 52 glsl_implementation_type;
54 ShCompileOptions driver_bug_workarounds; 53 ShCompileOptions driver_bug_workarounds;
55 54
56 ShaderTranslatorInitParams( 55 ShaderTranslatorInitParams(
(...skipping 26 matching lines...) Expand all
83 typedef std::map<ShaderTranslatorInitParams, ShaderTranslator* > Cache; 82 typedef std::map<ShaderTranslatorInitParams, ShaderTranslator* > Cache;
84 Cache cache_; 83 Cache cache_;
85 84
86 DISALLOW_COPY_AND_ASSIGN(ShaderTranslatorCache); 85 DISALLOW_COPY_AND_ASSIGN(ShaderTranslatorCache);
87 }; 86 };
88 87
89 } // namespace gles2 88 } // namespace gles2
90 } // namespace gpu 89 } // namespace gpu
91 90
92 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_ 91 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/shader_translator.cc ('k') | gpu/command_buffer/service/shader_translator_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698