Flutter Engine
The Flutter Engine
proc_table_gles.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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.
4
5#ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_PROC_TABLE_GLES_H_
6#define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_PROC_TABLE_GLES_H_
7
8#include <functional>
9#include <string>
10
11#include "flutter/fml/logging.h"
12#include "flutter/fml/mapping.h"
16
17namespace impeller {
18
19const char* GLErrorToString(GLenum value);
20bool GLErrorIsFatal(GLenum value);
21
23 const PFNGLGETERRORPROC error_fn;
24
25 // TODO(matanlurey) Change to string_view.
26 // https://github.com/flutter/flutter/issues/135922
27 const char* name;
28
29 AutoErrorCheck(PFNGLGETERRORPROC error, const char* name)
30 : error_fn(error), name(name) {}
31
33 if (error_fn) {
34 auto error = error_fn();
35 if (error == GL_NO_ERROR) {
36 return;
37 }
38 if (GLErrorIsFatal(error)) {
39 FML_LOG(FATAL) << "Fatal GL Error " << GLErrorToString(error) << "("
40 << error << ")" << " encountered on call to " << name;
41 } else {
42 FML_LOG(ERROR) << "GL Error " << GLErrorToString(error) << "(" << error
43 << ")" << " encountered on call to " << name;
44 }
45 }
46 }
47};
48
49template <class T>
50struct GLProc {
52
53 // TODO(matanlurey) Change to string_view.
54 // https://github.com/flutter/flutter/issues/135922
55
56 //----------------------------------------------------------------------------
57 /// The name of the GL function.
58 ///
59 const char* name = nullptr;
60
61 //----------------------------------------------------------------------------
62 /// The pointer to the GL function.
63 ///
65
66 //----------------------------------------------------------------------------
67 /// An optional error function. If present, all calls will be followed by an
68 /// error check.
69 ///
70 PFNGLGETERRORPROC error_fn = nullptr;
71
72 //----------------------------------------------------------------------------
73 /// @brief Call the GL function with the appropriate parameters. Lookup
74 /// the documentation for the GL function being called to
75 /// understand the arguments and return types. The arguments
76 /// types must match and will be type checked.
77 ///
78 template <class... Args>
79 auto operator()(Args&&... args) const {
80#ifdef IMPELLER_DEBUG
82 // We check for the existence of extensions, and reset the function pointer
83 // but it's still called unconditionally below, and will segfault. This
84 // validation log will at least give us a hint as to what's going on.
85 FML_CHECK(IsAvailable()) << "GL function " << name << " is not available. "
86 << "This is likely due to a missing extension.";
87#endif // IMPELLER_DEBUG
88 return function(std::forward<Args>(args)...);
89 }
90
91 constexpr bool IsAvailable() const { return function != nullptr; }
92
93 void Reset() {
94 function = nullptr;
95 error_fn = nullptr;
96 }
97};
98
99#define FOR_EACH_IMPELLER_PROC(PROC) \
100 PROC(ActiveTexture); \
101 PROC(AttachShader); \
102 PROC(BindAttribLocation); \
103 PROC(BindBuffer); \
104 PROC(BindFramebuffer); \
105 PROC(BindRenderbuffer); \
106 PROC(BindTexture); \
107 PROC(BlendEquationSeparate); \
108 PROC(BlendFuncSeparate); \
109 PROC(BufferData); \
110 PROC(CheckFramebufferStatus); \
111 PROC(Clear); \
112 PROC(ClearColor); \
113 PROC(ClearStencil); \
114 PROC(ColorMask); \
115 PROC(CompileShader); \
116 PROC(CreateProgram); \
117 PROC(CreateShader); \
118 PROC(CullFace); \
119 PROC(DeleteBuffers); \
120 PROC(DeleteFramebuffers); \
121 PROC(DeleteProgram); \
122 PROC(DeleteRenderbuffers); \
123 PROC(DeleteShader); \
124 PROC(DeleteTextures); \
125 PROC(DepthFunc); \
126 PROC(DepthMask); \
127 PROC(DetachShader); \
128 PROC(Disable); \
129 PROC(DisableVertexAttribArray); \
130 PROC(DrawArrays); \
131 PROC(DrawElements); \
132 PROC(Enable); \
133 PROC(EnableVertexAttribArray); \
134 PROC(Flush); \
135 PROC(FramebufferRenderbuffer); \
136 PROC(FramebufferTexture2D); \
137 PROC(FrontFace); \
138 PROC(GenBuffers); \
139 PROC(GenerateMipmap); \
140 PROC(GenFramebuffers); \
141 PROC(GenRenderbuffers); \
142 PROC(GenTextures); \
143 PROC(GetActiveUniform); \
144 PROC(GetBooleanv); \
145 PROC(GetFloatv); \
146 PROC(GetFramebufferAttachmentParameteriv); \
147 PROC(GetIntegerv); \
148 PROC(GetProgramInfoLog); \
149 PROC(GetProgramiv); \
150 PROC(GetShaderInfoLog); \
151 PROC(GetShaderiv); \
152 PROC(GetString); \
153 PROC(GetStringi); \
154 PROC(GetUniformLocation); \
155 PROC(IsBuffer); \
156 PROC(IsFramebuffer); \
157 PROC(IsProgram); \
158 PROC(IsRenderbuffer); \
159 PROC(IsShader); \
160 PROC(IsTexture); \
161 PROC(LinkProgram); \
162 PROC(PixelStorei); \
163 PROC(RenderbufferStorage); \
164 PROC(Scissor); \
165 PROC(ShaderBinary); \
166 PROC(ShaderSource); \
167 PROC(StencilFuncSeparate); \
168 PROC(StencilMaskSeparate); \
169 PROC(StencilOpSeparate); \
170 PROC(TexImage2D); \
171 PROC(TexSubImage2D); \
172 PROC(TexParameteri); \
173 PROC(TexParameterfv); \
174 PROC(Uniform1fv); \
175 PROC(Uniform1i); \
176 PROC(Uniform2fv); \
177 PROC(Uniform3fv); \
178 PROC(Uniform4fv); \
179 PROC(UniformMatrix4fv); \
180 PROC(UseProgram); \
181 PROC(VertexAttribPointer); \
182 PROC(Viewport); \
183 PROC(GetShaderSource); \
184 PROC(ReadPixels);
185
186// Calls specific to OpenGLES.
187void(glClearDepthf)(GLfloat depth);
188void(glDepthRangef)(GLfloat n, GLfloat f);
189
190#define FOR_EACH_IMPELLER_ES_ONLY_PROC(PROC) \
191 PROC(ClearDepthf); \
192 PROC(DepthRangef);
193
194// Calls specific to desktop GL.
195void(glClearDepth)(GLdouble depth);
196void(glDepthRange)(GLdouble n, GLdouble f);
197
198#define FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC(PROC) \
199 PROC(ClearDepth); \
200 PROC(DepthRange);
201
202#define FOR_EACH_IMPELLER_GLES3_PROC(PROC) PROC(BlitFramebuffer);
203
204#define FOR_EACH_IMPELLER_EXT_PROC(PROC) \
205 PROC(DebugMessageControlKHR); \
206 PROC(DiscardFramebufferEXT); \
207 PROC(FramebufferTexture2DMultisampleEXT); \
208 PROC(PushDebugGroupKHR); \
209 PROC(PopDebugGroupKHR); \
210 PROC(ObjectLabelKHR); \
211 PROC(RenderbufferStorageMultisampleEXT); \
212 PROC(GenQueriesEXT); \
213 PROC(DeleteQueriesEXT); \
214 PROC(GetQueryObjectui64vEXT); \
215 PROC(BeginQueryEXT); \
216 PROC(EndQueryEXT); \
217 PROC(GetQueryObjectuivEXT);
218
220 kTexture,
221 kBuffer,
222 kProgram,
223 kShader,
226};
227
229 public:
230 using Resolver = std::function<void*(const char* function_name)>;
231 explicit ProcTableGLES(Resolver resolver);
232 ProcTableGLES(ProcTableGLES&& other) = default;
233
235
236#define IMPELLER_PROC(name) \
237 GLProc<decltype(gl##name)> name = {"gl" #name, nullptr};
238
244
245#undef IMPELLER_PROC
246
247 bool IsValid() const;
248
249 /// @brief Set the source for the attached [shader].
250 ///
251 /// Optionally, [defines] may contain a string value that will be
252 /// append to the shader source after the version marker. This can be used to
253 /// support static specialization. For example, setting "#define Foo 1".
254 void ShaderSourceMapping(GLuint shader,
255 const fml::Mapping& mapping,
256 const std::vector<Scalar>& defines = {}) const;
257
258 const DescriptionGLES* GetDescription() const;
259
260 const std::shared_ptr<const CapabilitiesGLES>& GetCapabilities() const;
261
262 std::string DescribeCurrentFramebuffer() const;
263
264 std::string GetProgramInfoLogString(GLuint program) const;
265
266 bool IsCurrentFramebufferComplete() const;
267
269 GLint name,
270 const std::string& label) const;
271
272 void PushDebugGroup(const std::string& string) const;
273
274 void PopDebugGroup() const;
275
276 // Visible For testing.
277 std::optional<std::string> ComputeShaderWithDefines(
278 const fml::Mapping& mapping,
279 const std::vector<Scalar>& defines) const;
280
281 private:
282 bool is_valid_ = false;
283 std::unique_ptr<DescriptionGLES> description_;
284 std::shared_ptr<const CapabilitiesGLES> capabilities_;
285 GLint debug_label_max_length_ = 0;
286
287 ProcTableGLES(const ProcTableGLES&) = delete;
288
289 ProcTableGLES& operator=(const ProcTableGLES&) = delete;
290};
291
292} // namespace impeller
293
294#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_PROC_TABLE_GLES_H_
GLenum type
FOR_EACH_IMPELLER_ES_ONLY_PROC(IMPELLER_PROC)
ProcTableGLES(ProcTableGLES &&other)=default
std::optional< std::string > ComputeShaderWithDefines(const fml::Mapping &mapping, const std::vector< Scalar > &defines) const
FOR_EACH_IMPELLER_GLES3_PROC(IMPELLER_PROC)
std::function< void *(const char *function_name)> Resolver
void ShaderSourceMapping(GLuint shader, const fml::Mapping &mapping, const std::vector< Scalar > &defines={}) const
Set the source for the attached [shader].
FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC(IMPELLER_PROC)
std::string GetProgramInfoLogString(GLuint program) const
bool SetDebugLabel(DebugResourceType type, GLint name, const std::string &label) const
std::string DescribeCurrentFramebuffer() const
const std::shared_ptr< const CapabilitiesGLES > & GetCapabilities() const
bool IsCurrentFramebufferComplete() const
ProcTableGLES(Resolver resolver)
FOR_EACH_IMPELLER_PROC(IMPELLER_PROC)
FOR_EACH_IMPELLER_EXT_PROC(IMPELLER_PROC)
void PushDebugGroup(const std::string &string) const
const DescriptionGLES * GetDescription() const
#define FATAL(error)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const uint8_t uint32_t uint32_t GError ** error
uint8_t value
#define FML_LOG(severity)
Definition: logging.h:82
#define FML_CHECK(condition)
Definition: logging.h:85
Dart_NativeFunction function
Definition: fuchsia.cc:51
const char *const function_name
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
void() glClearDepth(GLdouble depth)
bool GLErrorIsFatal(GLenum value)
void() glDepthRangef(GLfloat n, GLfloat f)
const char * GLErrorToString(GLenum value)
void() glDepthRange(GLdouble n, GLdouble f)
void() glClearDepthf(GLfloat depth)
#define T
Definition: precompiler.cc:65
#define IMPELLER_PROC(name)
AutoErrorCheck(PFNGLGETERRORPROC error, const char *name)
const PFNGLGETERRORPROC error_fn
auto operator()(Args &&... args) const
Call the GL function with the appropriate parameters. Lookup the documentation for the GL function be...
const char * name
constexpr bool IsAvailable() const
GLFunctionType * function
PFNGLGETERRORPROC error_fn
#define ERROR(message)
Definition: elf_loader.cc:260