Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / gpu / command_buffer / service / shader_translator.h
blobac431e3e61562858060a670a2e0b47d36087822f
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 int* shader_version,
57 AttributeMap* attrib_map,
58 UniformMap* uniform_map,
59 VaryingMap* varying_map,
60 NameMap* name_map) const = 0;
62 // Return a string that is unique for a specfic set of options that would
63 // possibly affect compilation.
64 virtual std::string GetStringForOptionsThatWouldAffectCompilation() const = 0;
66 protected:
67 virtual ~ShaderTranslatorInterface() {}
69 private:
70 friend class base::RefCounted<ShaderTranslatorInterface>;
71 DISALLOW_COPY_AND_ASSIGN(ShaderTranslatorInterface);
74 // Implementation of ShaderTranslatorInterface
75 class GPU_EXPORT ShaderTranslator
76 : NON_EXPORTED_BASE(public ShaderTranslatorInterface) {
77 public:
78 class DestructionObserver {
79 public:
80 DestructionObserver();
81 virtual ~DestructionObserver();
83 virtual void OnDestruct(ShaderTranslator* translator) = 0;
85 private:
86 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
89 ShaderTranslator();
91 // Overridden from ShaderTranslatorInterface.
92 bool Init(sh::GLenum shader_type,
93 ShShaderSpec shader_spec,
94 const ShBuiltInResources* resources,
95 GlslImplementationType glsl_implementation_type,
96 ShCompileOptions driver_bug_workarounds) override;
98 // Overridden from ShaderTranslatorInterface.
99 bool Translate(const std::string& shader_source,
100 std::string* info_log,
101 std::string* translated_source,
102 int* shader_version,
103 AttributeMap* attrib_map,
104 UniformMap* uniform_map,
105 VaryingMap* varying_map,
106 NameMap* name_map) const override;
108 std::string GetStringForOptionsThatWouldAffectCompilation() const override;
110 void AddDestructionObserver(DestructionObserver* observer);
111 void RemoveDestructionObserver(DestructionObserver* observer);
113 private:
114 ~ShaderTranslator() override;
116 int GetCompileOptions() const;
118 ShHandle compiler_;
119 bool implementation_is_glsl_es_;
120 ShCompileOptions driver_bug_workarounds_;
121 ObserverList<DestructionObserver> destruction_observers_;
124 } // namespace gles2
125 } // namespace gpu
127 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_