Don't add an aura tooltip to bubble close buttons on Windows.
[chromium-blink-merge.git] / gpu / command_buffer / service / shader_translator.h
blob818be5d22241c4550979c99f6770039f3015aa19
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_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/containers/hash_tables.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h"
15 #include "gpu/gpu_export.h"
16 #include "third_party/angle/include/GLSLANG/ShaderLang.h"
18 namespace gpu {
19 namespace gles2 {
21 // Mapping between variable name and info.
22 typedef base::hash_map<std::string, sh::Attribute> AttributeMap;
23 typedef base::hash_map<std::string, sh::Uniform> UniformMap;
24 typedef base::hash_map<std::string, sh::Varying> VaryingMap;
25 // Mapping between hashed name and original name.
26 typedef base::hash_map<std::string, std::string> NameMap;
28 // Translates a GLSL ES 2.0 shader to desktop GLSL shader, or just
29 // validates GLSL ES 2.0 shaders on a true GLSL ES implementation.
30 class ShaderTranslatorInterface
31 : public base::RefCounted<ShaderTranslatorInterface> {
32 public:
33 ShaderTranslatorInterface() {}
34 enum GlslImplementationType {
35 kGlsl,
36 kGlslES
39 // Initializes the translator.
40 // Must be called once before using the translator object.
41 virtual bool Init(
42 sh::GLenum shader_type,
43 ShShaderSpec shader_spec,
44 const ShBuiltInResources* resources,
45 GlslImplementationType glsl_implementation_type,
46 ShCompileOptions driver_bug_workarounds) = 0;
48 // Translates the given shader source.
49 // Returns true if translation is successful, false otherwise.
50 // Always fill |info_log| if it's non-null.
51 // Upon success, fill |translated_shader|, |attrib_map|, |uniform_map|,
52 // |varying_map|, and |name_map| if they are non-null.
53 virtual bool Translate(const std::string& shader_source,
54 std::string* info_log,
55 std::string* translated_shader,
56 AttributeMap* attrib_map,
57 UniformMap* uniform_map,
58 VaryingMap* varying_map,
59 NameMap* name_map) const = 0;
61 // Return a string that is unique for a specfic set of options that would
62 // possibly affect compilation.
63 virtual std::string GetStringForOptionsThatWouldAffectCompilation() const = 0;
65 protected:
66 virtual ~ShaderTranslatorInterface() {}
68 private:
69 friend class base::RefCounted<ShaderTranslatorInterface>;
70 DISALLOW_COPY_AND_ASSIGN(ShaderTranslatorInterface);
73 // Implementation of ShaderTranslatorInterface
74 class GPU_EXPORT ShaderTranslator
75 : NON_EXPORTED_BASE(public ShaderTranslatorInterface) {
76 public:
77 class DestructionObserver {
78 public:
79 DestructionObserver();
80 virtual ~DestructionObserver();
82 virtual void OnDestruct(ShaderTranslator* translator) = 0;
84 private:
85 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
88 ShaderTranslator();
90 // Overridden from ShaderTranslatorInterface.
91 bool Init(sh::GLenum shader_type,
92 ShShaderSpec shader_spec,
93 const ShBuiltInResources* resources,
94 GlslImplementationType glsl_implementation_type,
95 ShCompileOptions driver_bug_workarounds) override;
97 // Overridden from ShaderTranslatorInterface.
98 bool Translate(const std::string& shader_source,
99 std::string* info_log,
100 std::string* translated_source,
101 AttributeMap* attrib_map,
102 UniformMap* uniform_map,
103 VaryingMap* varying_map,
104 NameMap* name_map) const override;
106 std::string GetStringForOptionsThatWouldAffectCompilation() const override;
108 void AddDestructionObserver(DestructionObserver* observer);
109 void RemoveDestructionObserver(DestructionObserver* observer);
111 private:
112 ~ShaderTranslator() override;
114 int GetCompileOptions() const;
116 ShHandle compiler_;
117 bool implementation_is_glsl_es_;
118 ShCompileOptions driver_bug_workarounds_;
119 ObserverList<DestructionObserver> destruction_observers_;
122 } // namespace gles2
123 } // namespace gpu
125 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_