Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | List of all members
impeller::ProcTableGLES Class Reference

#include <proc_table_gles.h>

Public Types

using Resolver = std::function< void *(const char *function_name)>
 

Public Member Functions

 ProcTableGLES (Resolver resolver)
 
 ProcTableGLES (ProcTableGLES &&other)=default
 
 ~ProcTableGLES ()
 
 FOR_EACH_IMPELLER_PROC (IMPELLER_PROC)
 
 FOR_EACH_IMPELLER_ES_ONLY_PROC (IMPELLER_PROC)
 
 FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC (IMPELLER_PROC)
 
 FOR_EACH_IMPELLER_GLES3_PROC (IMPELLER_PROC)
 
 FOR_EACH_IMPELLER_EXT_PROC (IMPELLER_PROC)
 
bool IsValid () const
 
void ShaderSourceMapping (GLuint shader, const fml::Mapping &mapping, const std::vector< Scalar > &defines={}) const
 Set the source for the attached [shader]. More...
 
const DescriptionGLESGetDescription () const
 
const std::shared_ptr< const CapabilitiesGLES > & GetCapabilities () const
 
std::string DescribeCurrentFramebuffer () const
 
std::string GetProgramInfoLogString (GLuint program) const
 
bool IsCurrentFramebufferComplete () const
 
bool SetDebugLabel (DebugResourceType type, GLint name, const std::string &label) const
 
void PushDebugGroup (const std::string &string) const
 
void PopDebugGroup () const
 
std::optional< std::string > ComputeShaderWithDefines (const fml::Mapping &mapping, const std::vector< Scalar > &defines) const
 

Detailed Description

Definition at line 228 of file proc_table_gles.h.

Member Typedef Documentation

◆ Resolver

using impeller::ProcTableGLES::Resolver = std::function<void*(const char* function_name)>

Definition at line 230 of file proc_table_gles.h.

Constructor & Destructor Documentation

◆ ProcTableGLES() [1/2]

impeller::ProcTableGLES::ProcTableGLES ( Resolver  resolver)
explicit

Definition at line 74 of file proc_table_gles.cc.

75 {
76 // The reason this constructor has anywhere near enough code to tip off
77 // `google-readability-function-size` is the proc macros, so ignore the lint.
78
79 if (!resolver) {
80 return;
81 }
82
83 resolver = WrappedResolver(resolver);
84
85 auto error_fn = reinterpret_cast<PFNGLGETERRORPROC>(resolver("glGetError"));
86 if (!error_fn) {
87 VALIDATION_LOG << "Could not resolve " << "glGetError";
88 return;
89 }
90
91#define IMPELLER_PROC(proc_ivar) \
92 if (auto fn_ptr = resolver(proc_ivar.name)) { \
93 proc_ivar.function = \
94 reinterpret_cast<decltype(proc_ivar.function)>(fn_ptr); \
95 proc_ivar.error_fn = error_fn; \
96 } else { \
97 VALIDATION_LOG << "Could not resolve " << proc_ivar.name; \
98 return; \
99 }
100
102
103 description_ = std::make_unique<DescriptionGLES>(*this);
104
105 if (!description_->IsValid()) {
106 return;
107 }
108
109 if (description_->IsES()) {
111 } else {
113 }
114
115#undef IMPELLER_PROC
116
117#define IMPELLER_PROC(proc_ivar) \
118 if (auto fn_ptr = resolver(proc_ivar.name)) { \
119 proc_ivar.function = \
120 reinterpret_cast<decltype(proc_ivar.function)>(fn_ptr); \
121 proc_ivar.error_fn = error_fn; \
122 }
125
126#undef IMPELLER_PROC
127
128 if (!description_->HasDebugExtension()) {
129 PushDebugGroupKHR.Reset();
130 PopDebugGroupKHR.Reset();
131 ObjectLabelKHR.Reset();
132 } else {
133 GetIntegerv(GL_MAX_LABEL_LENGTH_KHR, &debug_label_max_length_);
134 }
135
136 if (!description_->HasExtension("GL_EXT_discard_framebuffer")) {
137 DiscardFramebufferEXT.Reset();
138 }
139
140 capabilities_ = std::make_shared<CapabilitiesGLES>(*this);
141
142 is_valid_ = true;
143}
FOR_EACH_IMPELLER_ES_ONLY_PROC(IMPELLER_PROC)
FOR_EACH_IMPELLER_GLES3_PROC(IMPELLER_PROC)
FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC(IMPELLER_PROC)
FOR_EACH_IMPELLER_PROC(IMPELLER_PROC)
FOR_EACH_IMPELLER_EXT_PROC(IMPELLER_PROC)
ProcTableGLES::Resolver WrappedResolver(const ProcTableGLES::Resolver &resolver)
#define IMPELLER_PROC(proc_ivar)
#define VALIDATION_LOG
Definition: validation.h:73

◆ ProcTableGLES() [2/2]

impeller::ProcTableGLES::ProcTableGLES ( ProcTableGLES &&  other)
default

◆ ~ProcTableGLES()

impeller::ProcTableGLES::~ProcTableGLES ( )
default

Member Function Documentation

◆ ComputeShaderWithDefines()

std::optional< std::string > impeller::ProcTableGLES::ComputeShaderWithDefines ( const fml::Mapping mapping,
const std::vector< Scalar > &  defines 
) const

Definition at line 175 of file proc_table_gles.cc.

177 {
178 auto shader_source = std::string{
179 reinterpret_cast<const char*>(mapping.GetMapping()), mapping.GetSize()};
180
181 // Look for the first newline after the '#version' header, which impellerc
182 // will always emit as the first line of a compiled shader.
183 auto index = shader_source.find('\n');
184 if (index == std::string::npos) {
185 VALIDATION_LOG << "Failed to append constant data to shader";
186 return std::nullopt;
187 }
188
189 std::stringstream ss;
190 ss << std::fixed;
191 for (auto i = 0u; i < defines.size(); i++) {
192 ss << "#define SPIRV_CROSS_CONSTANT_ID_" << i << " " << defines[i] << '\n';
193 }
194 auto define_string = ss.str();
195 shader_source.insert(index + 1, define_string);
196 return shader_source;
197}
virtual const uint8_t * GetMapping() const =0
virtual size_t GetSize() const =0

◆ DescribeCurrentFramebuffer()

std::string impeller::ProcTableGLES::DescribeCurrentFramebuffer ( ) const

Definition at line 268 of file proc_table_gles.cc.

268 {
269 GLint framebuffer = GL_NONE;
270 GetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer);
271 if (IsFramebuffer(framebuffer) == GL_FALSE) {
272 return "No framebuffer or the default window framebuffer is bound.";
273 }
274
275 GLenum status = CheckFramebufferStatus(framebuffer);
276 std::stringstream stream;
277 stream << "FBO "
278 << ((framebuffer == GL_NONE) ? "(Default)"
279 : std::to_string(framebuffer))
280 << ": " << FramebufferStatusToString(status) << std::endl;
282 stream << "Framebuffer is complete." << std::endl;
283 } else {
284 stream << "Framebuffer is incomplete." << std::endl;
285 }
286 stream << "Description: " << std::endl;
287 stream << "Color Attachment: "
288 << DescribeFramebufferAttachment(*this, GL_COLOR_ATTACHMENT0)
289 << std::endl;
290 stream << "Color Attachment: "
291 << DescribeFramebufferAttachment(*this, GL_DEPTH_ATTACHMENT)
292 << std::endl;
293 stream << "Color Attachment: "
294 << DescribeFramebufferAttachment(*this, GL_STENCIL_ATTACHMENT)
295 << std::endl;
296 return stream.str();
297}
bool IsCurrentFramebufferComplete() const
static const char * FramebufferStatusToString(GLenum status)
static std::string DescribeFramebufferAttachment(const ProcTableGLES &gl, GLenum attachment)
static SkString to_string(int n)
Definition: nanobench.cpp:119

◆ FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_DESKTOP_ONLY_PROC ( IMPELLER_PROC  )

◆ FOR_EACH_IMPELLER_ES_ONLY_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_ES_ONLY_PROC ( IMPELLER_PROC  )

◆ FOR_EACH_IMPELLER_EXT_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_EXT_PROC ( IMPELLER_PROC  )

◆ FOR_EACH_IMPELLER_GLES3_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_GLES3_PROC ( IMPELLER_PROC  )

◆ FOR_EACH_IMPELLER_PROC()

impeller::ProcTableGLES::FOR_EACH_IMPELLER_PROC ( IMPELLER_PROC  )

◆ GetCapabilities()

const std::shared_ptr< const CapabilitiesGLES > & impeller::ProcTableGLES::GetCapabilities ( ) const

Definition at line 203 of file proc_table_gles.cc.

204 {
205 return capabilities_;
206}

◆ GetDescription()

const DescriptionGLES * impeller::ProcTableGLES::GetDescription ( ) const

Definition at line 199 of file proc_table_gles.cc.

199 {
200 return description_.get();
201}

◆ GetProgramInfoLogString()

std::string impeller::ProcTableGLES::GetProgramInfoLogString ( GLuint  program) const

Definition at line 401 of file proc_table_gles.cc.

401 {
402 GLint length = 0;
403 GetProgramiv(program, GL_INFO_LOG_LENGTH, &length);
404 if (length <= 0) {
405 return "";
406 }
407
408 length = std::min<GLint>(length, 1024);
409 Allocation allocation;
410 if (!allocation.Truncate(length, false)) {
411 return "";
412 }
413 GetProgramInfoLog(program, // program
414 length, // max length
415 &length, // length written (excluding NULL terminator)
416 reinterpret_cast<GLchar*>(allocation.GetBuffer()) // buffer
417 );
418 if (length <= 0) {
419 return "";
420 }
421 return std::string{reinterpret_cast<const char*>(allocation.GetBuffer()),
422 static_cast<size_t>(length)};
423}
size_t length

◆ IsCurrentFramebufferComplete()

bool impeller::ProcTableGLES::IsCurrentFramebufferComplete ( ) const

Definition at line 299 of file proc_table_gles.cc.

299 {
300 GLint framebuffer = GL_NONE;
301 GetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer);
302 if (IsFramebuffer(framebuffer) == GL_FALSE) {
303 // The default framebuffer is always complete.
304 return true;
305 }
306 GLenum status = CheckFramebufferStatus(framebuffer);
307 return status == GL_FRAMEBUFFER_COMPLETE;
308}

◆ IsValid()

bool impeller::ProcTableGLES::IsValid ( ) const

Definition at line 147 of file proc_table_gles.cc.

147 {
148 return is_valid_;
149}

◆ PopDebugGroup()

void impeller::ProcTableGLES::PopDebugGroup ( ) const

Definition at line 391 of file proc_table_gles.cc.

391 {
392#ifdef IMPELLER_DEBUG
393 if (debug_label_max_length_ <= 0) {
394 return;
395 }
396
397 PopDebugGroupKHR();
398#endif // IMPELLER_DEBUG
399}

◆ PushDebugGroup()

void impeller::ProcTableGLES::PushDebugGroup ( const std::string &  string) const

Definition at line 374 of file proc_table_gles.cc.

374 {
375#ifdef IMPELLER_DEBUG
376 if (debug_label_max_length_ <= 0) {
377 return;
378 }
379
380 UniqueID id;
381 const auto label_length =
382 std::min<GLsizei>(debug_label_max_length_ - 1, label.size());
383 PushDebugGroupKHR(GL_DEBUG_SOURCE_APPLICATION_KHR, // source
384 static_cast<GLuint>(id.id), // id
385 label_length, // length
386 label.data() // message
387 );
388#endif // IMPELLER_DEBUG
389}
const uintptr_t id

◆ SetDebugLabel()

bool impeller::ProcTableGLES::SetDebugLabel ( DebugResourceType  type,
GLint  name,
const std::string &  label 
) const

Definition at line 348 of file proc_table_gles.cc.

350 {
351 if (debug_label_max_length_ <= 0) {
352 return true;
353 }
354 if (!ObjectLabelKHR.IsAvailable()) {
355 return true;
356 }
357 if (!ResourceIsLive(*this, type, name)) {
358 return false;
359 }
360 const auto identifier = ToDebugIdentifier(type);
361 const auto label_length =
362 std::min<GLsizei>(debug_label_max_length_ - 1, label.size());
363 if (!identifier.has_value()) {
364 return true;
365 }
366 ObjectLabelKHR(identifier.value(), // identifier
367 name, // name
368 label_length, // length
369 label.data() // label
370 );
371 return true;
372}
GLenum type
static SkString identifier(const FontFamilyDesc &family, const FontDesc &font)
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
static std::optional< GLenum > ToDebugIdentifier(DebugResourceType type)
static bool ResourceIsLive(const ProcTableGLES &gl, DebugResourceType type, GLint name)

◆ ShaderSourceMapping()

void impeller::ProcTableGLES::ShaderSourceMapping ( GLuint  shader,
const fml::Mapping mapping,
const std::vector< Scalar > &  defines = {} 
) const

Set the source for the attached [shader].

Optionally, [defines] may contain a string value that will be append to the shader source after the version marker. This can be used to support static specialization. For example, setting "#define Foo 1".

Definition at line 151 of file proc_table_gles.cc.

154 {
155 if (defines.empty()) {
156 const GLchar* sources[] = {
157 reinterpret_cast<const GLchar*>(mapping.GetMapping())};
158 const GLint lengths[] = {static_cast<GLint>(mapping.GetSize())};
159 ShaderSource(shader, 1u, sources, lengths);
160 return;
161 }
162 const auto& shader_source = ComputeShaderWithDefines(mapping, defines);
163 if (!shader_source.has_value()) {
164 VALIDATION_LOG << "Failed to append constant data to shader";
165 return;
166 }
167
168 const GLchar* sources[] = {
169 reinterpret_cast<const GLchar*>(shader_source->c_str())};
170 const GLint lengths[] = {static_cast<GLint>(shader_source->size())};
171 ShaderSource(shader, 1u, sources, lengths);
172}
std::optional< std::string > ComputeShaderWithDefines(const fml::Mapping &mapping, const std::vector< Scalar > &defines) const

The documentation for this class was generated from the following files: