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

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

Issue 10694111: RefCounted types should not have public destructors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android & Win compiles Created 8 years, 5 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_H_ 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ 6 #define GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 14 matching lines...) Expand all
25 enum GlslImplementationType { 25 enum GlslImplementationType {
26 kGlsl, 26 kGlsl,
27 kGlslES 27 kGlslES
28 }; 28 };
29 29
30 enum GlslBuiltInFunctionBehavior { 30 enum GlslBuiltInFunctionBehavior {
31 kGlslBuiltInFunctionOriginal, 31 kGlslBuiltInFunctionOriginal,
32 kGlslBuiltInFunctionEmulated 32 kGlslBuiltInFunctionEmulated
33 }; 33 };
34 34
35 virtual ~ShaderTranslatorInterface() { } 35 struct VariableInfo {
36 VariableInfo()
37 : type(0),
38 size(0) {
39 }
40
41 VariableInfo(int _type, int _size, std::string _name)
42 : type(_type),
43 size(_size),
44 name(_name) {
45 }
46
47 int type;
48 int size;
49 std::string name; // name in the original shader source.
50 };
51
52 // Mapping between variable name and info.
53 typedef base::hash_map<std::string, VariableInfo> VariableMap;
36 54
37 // Initializes the translator. 55 // Initializes the translator.
38 // Must be called once before using the translator object. 56 // Must be called once before using the translator object.
39 virtual bool Init( 57 virtual bool Init(
40 ShShaderType shader_type, 58 ShShaderType shader_type,
41 ShShaderSpec shader_spec, 59 ShShaderSpec shader_spec,
42 const ShBuiltInResources* resources, 60 const ShBuiltInResources* resources,
43 GlslImplementationType glsl_implementation_type, 61 GlslImplementationType glsl_implementation_type,
44 GlslBuiltInFunctionBehavior glsl_built_in_function_behavior) = 0; 62 GlslBuiltInFunctionBehavior glsl_built_in_function_behavior) = 0;
45 63
46 // Translates the given shader source. 64 // Translates the given shader source.
47 // Returns true if translation is successful, false otherwise. 65 // Returns true if translation is successful, false otherwise.
48 virtual bool Translate(const char* shader) = 0; 66 virtual bool Translate(const char* shader) = 0;
49 67
50 // The following functions return results from the last translation. 68 // The following functions return results from the last translation.
51 // The results are NULL/empty if the translation was unsuccessful. 69 // The results are NULL/empty if the translation was unsuccessful.
52 // A valid info-log is always returned irrespective of whether translation 70 // A valid info-log is always returned irrespective of whether translation
53 // was successful or not. 71 // was successful or not.
54 virtual const char* translated_shader() const = 0; 72 virtual const char* translated_shader() const = 0;
55 virtual const char* info_log() const = 0; 73 virtual const char* info_log() const = 0;
56 74
57 struct VariableInfo {
58 VariableInfo()
59 : type(0),
60 size(0) {
61 }
62 VariableInfo(int _type, int _size, std::string _name)
63 : type(_type),
64 size(_size),
65 name(_name) {
66 }
67 int type;
68 int size;
69 std::string name; // name in the original shader source.
70 };
71 // Mapping between variable name and info.
72 typedef base::hash_map<std::string, VariableInfo> VariableMap;
73 virtual const VariableMap& attrib_map() const = 0; 75 virtual const VariableMap& attrib_map() const = 0;
74 virtual const VariableMap& uniform_map() const = 0; 76 virtual const VariableMap& uniform_map() const = 0;
77
78 protected:
79 virtual ~ShaderTranslatorInterface() {}
75 }; 80 };
76 81
77 // Implementation of ShaderTranslatorInterface 82 // Implementation of ShaderTranslatorInterface
78 class GPU_EXPORT ShaderTranslator 83 class GPU_EXPORT ShaderTranslator
79 : public base::RefCounted<ShaderTranslator>, 84 : public base::RefCounted<ShaderTranslator>,
80 NON_EXPORTED_BASE(public ShaderTranslatorInterface) { 85 NON_EXPORTED_BASE(public ShaderTranslatorInterface) {
81 public: 86 public:
82 class DestructionObserver { 87 class DestructionObserver {
83 public: 88 public:
84 DestructionObserver(); 89 DestructionObserver();
85 virtual ~DestructionObserver(); 90 virtual ~DestructionObserver();
86 91
87 virtual void OnDestruct(ShaderTranslator* translator) = 0; 92 virtual void OnDestruct(ShaderTranslator* translator) = 0;
93
88 private: 94 private:
89 DISALLOW_COPY_AND_ASSIGN(DestructionObserver); 95 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
90 }; 96 };
91 97
92 ShaderTranslator(); 98 ShaderTranslator();
93 99
94 // Overridden from ShaderTranslatorInterface. 100 // Overridden from ShaderTranslatorInterface.
95 virtual bool Init( 101 virtual bool Init(
96 ShShaderType shader_type, 102 ShShaderType shader_type,
97 ShShaderSpec shader_spec, 103 ShShaderSpec shader_spec,
98 const ShBuiltInResources* resources, 104 const ShBuiltInResources* resources,
99 GlslImplementationType glsl_implementation_type, 105 GlslImplementationType glsl_implementation_type,
100 GlslBuiltInFunctionBehavior glsl_built_in_function_behavior) OVERRIDE; 106 GlslBuiltInFunctionBehavior glsl_built_in_function_behavior) OVERRIDE;
101 107
102 // Overridden from ShaderTranslatorInterface. 108 // Overridden from ShaderTranslatorInterface.
103 virtual bool Translate(const char* shader) OVERRIDE; 109 virtual bool Translate(const char* shader) OVERRIDE;
104 110
105 // Overridden from ShaderTranslatorInterface. 111 // Overridden from ShaderTranslatorInterface.
106 virtual const char* translated_shader() const OVERRIDE; 112 virtual const char* translated_shader() const OVERRIDE;
107 virtual const char* info_log() const OVERRIDE; 113 virtual const char* info_log() const OVERRIDE;
108 114
109 // Overridden from ShaderTranslatorInterface. 115 // Overridden from ShaderTranslatorInterface.
110 virtual const VariableMap& attrib_map() const OVERRIDE; 116 virtual const VariableMap& attrib_map() const OVERRIDE;
111 virtual const VariableMap& uniform_map() const OVERRIDE; 117 virtual const VariableMap& uniform_map() const OVERRIDE;
112 118
113 void AddDestructionObserver(DestructionObserver* observer); 119 void AddDestructionObserver(DestructionObserver* observer);
114 void RemoveDestructionObserver(DestructionObserver* observer); 120 void RemoveDestructionObserver(DestructionObserver* observer);
115 121
116 private: 122 private:
123 friend class base::RefCounted<ShaderTranslator>;
124
117 virtual ~ShaderTranslator(); 125 virtual ~ShaderTranslator();
118
119 void ClearResults(); 126 void ClearResults();
120 127
121 ShHandle compiler_; 128 ShHandle compiler_;
122 scoped_array<char> translated_shader_; 129 scoped_array<char> translated_shader_;
123 scoped_array<char> info_log_; 130 scoped_array<char> info_log_;
124 VariableMap attrib_map_; 131 VariableMap attrib_map_;
125 VariableMap uniform_map_; 132 VariableMap uniform_map_;
126 bool implementation_is_glsl_es_; 133 bool implementation_is_glsl_es_;
127 bool needs_built_in_function_emulation_; 134 bool needs_built_in_function_emulation_;
128 ObserverList<DestructionObserver> destruction_observers_; 135 ObserverList<DestructionObserver> destruction_observers_;
129 136
130 friend class base::RefCounted<ShaderTranslator>;
131
132 DISALLOW_COPY_AND_ASSIGN(ShaderTranslator); 137 DISALLOW_COPY_AND_ASSIGN(ShaderTranslator);
133 }; 138 };
134 139
135 } // namespace gles2 140 } // namespace gles2
136 } // namespace gpu 141 } // namespace gpu
137 142
138 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ 143 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_
139 144
OLDNEW
« no previous file with comments | « content/common/gpu/sync_point_manager.cc ('k') | gpu/command_buffer/service/shader_translator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698