Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / gpu / command_buffer / service / shader_translator_cache.h
blobe5f1ae03575f176ac4068f3622fc199a892283fd
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.
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_
8 #include <string.h>
10 #include <map>
12 #include "base/memory/ref_counted.h"
13 #include "gpu/command_buffer/service/shader_translator.h"
14 #include "third_party/angle/include/GLSLANG/ShaderLang.h"
16 namespace gpu {
17 namespace gles2 {
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
21 // threads without synchronization.
23 // TODO(backer): Investigate using glReleaseShaderCompiler as an alternative to
24 // to this cache.
25 class GPU_EXPORT ShaderTranslatorCache
26 : public base::RefCounted<ShaderTranslatorCache>,
27 public NON_EXPORTED_BASE(ShaderTranslator::DestructionObserver) {
28 public:
29 ShaderTranslatorCache();
31 // ShaderTranslator::DestructionObserver implementation
32 virtual void OnDestruct(ShaderTranslator* translator) OVERRIDE;
34 scoped_refptr<ShaderTranslator> GetTranslator(
35 #if (ANGLE_SH_VERSION >= 126)
36 sh::GLenum shader_type,
37 #else
38 ShShaderType shader_type,
39 #endif
40 ShShaderSpec shader_spec,
41 const ShBuiltInResources* resources,
42 ShaderTranslatorInterface::GlslImplementationType
43 glsl_implementation_type,
44 ShCompileOptions driver_bug_workarounds);
46 private:
47 friend class base::RefCounted<ShaderTranslatorCache>;
48 virtual ~ShaderTranslatorCache();
50 // Parameters passed into ShaderTranslator::Init
51 struct ShaderTranslatorInitParams {
52 #if (ANGLE_SH_VERSION >= 126)
53 sh::GLenum shader_type;
54 #else
55 ShShaderType shader_type;
56 #endif
57 ShShaderSpec shader_spec;
58 ShBuiltInResources resources;
59 ShaderTranslatorInterface::GlslImplementationType
60 glsl_implementation_type;
61 ShCompileOptions driver_bug_workarounds;
63 ShaderTranslatorInitParams(
64 #if (ANGLE_SH_VERSION >= 126)
65 sh::GLenum shader_type,
66 #else
67 ShShaderType shader_type,
68 #endif
69 ShShaderSpec shader_spec,
70 const ShBuiltInResources& resources,
71 ShaderTranslatorInterface::GlslImplementationType
72 glsl_implementation_type,
73 ShCompileOptions driver_bug_workarounds)
74 : shader_type(shader_type),
75 shader_spec(shader_spec),
76 resources(resources),
77 glsl_implementation_type(glsl_implementation_type),
78 driver_bug_workarounds(driver_bug_workarounds) {
81 ShaderTranslatorInitParams(const ShaderTranslatorInitParams& params) {
82 memcpy(this, &params, sizeof(*this));
85 bool operator== (const ShaderTranslatorInitParams& params) const {
86 return memcmp(&params, this, sizeof(*this)) == 0;
89 bool operator< (const ShaderTranslatorInitParams& params) const {
90 return memcmp(&params, this, sizeof(*this)) < 0;
94 typedef std::map<ShaderTranslatorInitParams, ShaderTranslator* > Cache;
95 Cache cache_;
97 DISALLOW_COPY_AND_ASSIGN(ShaderTranslatorCache);
100 } // namespace gles2
101 } // namespace gpu
103 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_