Flutter Engine
egl_utils.cc File Reference
#include "egl_utils.h"
#include <EGL/egl.h>

Go to the source code of this file.

Functions

static gchar * egl_decimal_to_string (EGLint value)
 
static gchar * egl_hexadecimal_to_string (EGLint value)
 
static gchar * egl_enum_to_string (EGLint value)
 
static gboolean clear_bit (EGLint *field, EGLint bit)
 
static gchar * egl_renderable_type_to_string (EGLint value)
 
static gchar * egl_surface_type_to_string (EGLint value)
 
const gchar * egl_error_to_string (EGLint error)
 
gchar * egl_config_to_string (EGLDisplay display, EGLConfig config)
 

Function Documentation

◆ clear_bit()

static gboolean clear_bit ( EGLint *  field,
EGLint  bit 
)
static

Definition at line 43 of file egl_utils.cc.

References TRUE.

Referenced by egl_renderable_type_to_string(), and egl_surface_type_to_string().

43  {
44  if ((*field & bit) == 0)
45  return FALSE;
46 
47  *field ^= bit;
48  return TRUE;
49 }
return TRUE
Definition: fl_view.cc:107

◆ egl_config_to_string()

gchar* egl_config_to_string ( EGLDisplay  display,
EGLConfig  config 
)

egl_config_to_string: : an EGL display. : an EGL configuration.

Converts an EGL configuration to a human readable string. e.g. "EGL_CONFIG_ID=1 EGL_RED_SIZE=8...".

Returns: a configuration description.

Definition at line 126 of file egl_utils.cc.

References egl_decimal_to_string(), egl_enum_to_string(), egl_hexadecimal_to_string(), egl_renderable_type_to_string(), egl_surface_type_to_string(), eglGetConfigAttrib(), name, and value.

Referenced by fl_renderer_wayland_create_surfaces(), setup_egl_display(), setup_egl_surfaces(), and TEST().

126  {
127  struct {
128  EGLint attribute;
129  const gchar* name;
130  gchar* (*to_string)(EGLint value);
131  } config_items[] = {{
132  EGL_CONFIG_ID,
133  "EGL_CONFIG_ID",
135  },
136  {
137  EGL_BUFFER_SIZE,
138  "EGL_BUFFER_SIZE",
140  },
141  {
142  EGL_COLOR_BUFFER_TYPE,
143  "EGL_COLOR_BUFFER_TYPE",
145  },
146  {
147  EGL_TRANSPARENT_TYPE,
148  "EGL_TRANSPARENT_TYPE",
150  },
151  {
152  EGL_LEVEL,
153  "EGL_LEVEL",
155  },
156  {
157  EGL_RED_SIZE,
158  "EGL_RED_SIZE",
160  },
161  {
162  EGL_GREEN_SIZE,
163  "EGL_GREEN_SIZE",
165  },
166  {
167  EGL_BLUE_SIZE,
168  "EGL_BLUE_SIZE",
170  },
171  {
172  EGL_ALPHA_SIZE,
173  "EGL_ALPHA_SIZE",
175  },
176  {
177  EGL_DEPTH_SIZE,
178  "EGL_DEPTH_SIZE",
180  },
181  {
182  EGL_STENCIL_SIZE,
183  "EGL_STENCIL_SIZE",
185  },
186  {
187  EGL_SAMPLES,
188  "EGL_SAMPLES",
190  },
191  {
192  EGL_SAMPLE_BUFFERS,
193  "EGL_SAMPLE_BUFFERS",
195  },
196  {
197  EGL_NATIVE_VISUAL_ID,
198  "EGL_NATIVE_VISUAL_ID",
200  },
201  {
202  EGL_NATIVE_VISUAL_TYPE,
203  "EGL_NATIVE_VISUAL_TYPE",
205  },
206  {
207  EGL_NATIVE_RENDERABLE,
208  "EGL_NATIVE_RENDERABLE",
210  },
211  {
212  EGL_CONFIG_CAVEAT,
213  "EGL_CONFIG_CAVEAT",
215  },
216  {
217  EGL_BIND_TO_TEXTURE_RGB,
218  "EGL_BIND_TO_TEXTURE_RGB",
220  },
221  {
222  EGL_BIND_TO_TEXTURE_RGBA,
223  "EGL_BIND_TO_TEXTURE_RGBA",
225  },
226  {
227  EGL_RENDERABLE_TYPE,
228  "EGL_RENDERABLE_TYPE",
230  },
231  {
232  EGL_CONFORMANT,
233  "EGL_CONFORMANT",
235  },
236  {
237  EGL_SURFACE_TYPE,
238  "EGL_SURFACE_TYPE",
240  },
241  {
242  EGL_MAX_PBUFFER_WIDTH,
243  "EGL_MAX_PBUFFER_WIDTH",
245  },
246  {
247  EGL_MAX_PBUFFER_HEIGHT,
248  "EGL_MAX_PBUFFER_HEIGHT",
250  },
251  {
252  EGL_MAX_PBUFFER_PIXELS,
253  "EGL_MAX_PBUFFER_PIXELS",
255  },
256  {
257  EGL_MIN_SWAP_INTERVAL,
258  "EGL_MIN_SWAP_INTERVAL",
260  },
261  {
262  EGL_MAX_SWAP_INTERVAL,
263  "EGL_MAX_SWAP_INTERVAL",
265  },
266  {EGL_NONE, nullptr, nullptr}};
267 
268  g_autoptr(GPtrArray) strings = g_ptr_array_new_with_free_func(g_free);
269  for (int i = 0; config_items[i].attribute != EGL_NONE; i++) {
270  EGLint value;
271  if (!eglGetConfigAttrib(display, config, config_items[i].attribute, &value))
272  continue;
273  g_autofree gchar* value_string = config_items[i].to_string(value);
274  if (value_string == nullptr)
275  value_string = egl_hexadecimal_to_string(value);
276  g_ptr_array_add(
277  strings, g_strdup_printf("%s=%s", config_items[i].name, value_string));
278  }
279  g_ptr_array_add(strings, nullptr);
280 
281  return g_strjoinv(" ", reinterpret_cast<gchar**>(strings->pdata));
282 }
static gchar * egl_enum_to_string(EGLint value)
Definition: egl_utils.cc:20
EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
Definition: mock_egl.cc:153
static gchar * egl_decimal_to_string(EGLint value)
Definition: egl_utils.cc:10
uint8_t value
static gchar * egl_hexadecimal_to_string(EGLint value)
Definition: egl_utils.cc:15
static gchar * egl_renderable_type_to_string(EGLint value)
Definition: egl_utils.cc:52
const char * name
Definition: fuchsia.cc:50
static gchar * egl_surface_type_to_string(EGLint value)
Definition: egl_utils.cc:73

◆ egl_decimal_to_string()

static gchar* egl_decimal_to_string ( EGLint  value)
static

Definition at line 10 of file egl_utils.cc.

Referenced by egl_config_to_string().

10  {
11  return g_strdup_printf("%d", value);
12 }
uint8_t value

◆ egl_enum_to_string()

static gchar* egl_enum_to_string ( EGLint  value)
static

Definition at line 20 of file egl_utils.cc.

Referenced by egl_config_to_string().

20  {
21  if (value == EGL_FALSE)
22  return g_strdup("EGL_FALSE");
23  else if (value == EGL_LUMINANCE_BUFFER)
24  return g_strdup("EGL_LUMINANCE_BUFFER");
25  else if (value == EGL_NONE)
26  return g_strdup("EGL_NONE");
27  else if (value == EGL_NON_CONFORMANT_CONFIG)
28  return g_strdup("EGL_NON_CONFORMANT_CONFIG");
29  else if (value == EGL_RGB_BUFFER)
30  return g_strdup("EGL_RGB_BUFFER");
31  else if (value == EGL_SLOW_CONFIG)
32  return g_strdup("EGL_SLOW_CONFIG");
33  else if (value == EGL_TRANSPARENT_RGB)
34  return g_strdup("EGL_TRANSPARENT_RGB");
35  else if (value == EGL_TRUE)
36  return g_strdup("EGL_TRUE");
37  else
38  return nullptr;
39 }
uint8_t value

◆ egl_error_to_string()

const gchar* egl_error_to_string ( EGLint  error)

egl_error_to_string: : an EGL error code.

Converts an egl error code to a human readable string. e.g. "Bad Match".

Returns: an error description.

Definition at line 89 of file egl_utils.cc.

Referenced by fl_renderer_clear_current(), fl_renderer_make_current(), fl_renderer_make_resource_current(), fl_renderer_present(), fl_renderer_wayland_create_surfaces(), setup_egl_display(), setup_egl_surfaces(), and TEST().

89  {
90  switch (error) {
91  case EGL_SUCCESS:
92  return "Success";
93  case EGL_NOT_INITIALIZED:
94  return "Not Initialized";
95  case EGL_BAD_ACCESS:
96  return "Bad Access";
97  case EGL_BAD_ALLOC:
98  return "Bad Allocation";
99  case EGL_BAD_ATTRIBUTE:
100  return "Bad Attribute";
101  case EGL_BAD_CONTEXT:
102  return "Bad Context";
103  case EGL_BAD_CONFIG:
104  return "Bad Configuration";
105  case EGL_BAD_CURRENT_SURFACE:
106  return "Bad Current Surface";
107  case EGL_BAD_DISPLAY:
108  return "Bad Display";
109  case EGL_BAD_SURFACE:
110  return "Bad Surface";
111  case EGL_BAD_MATCH:
112  return "Bad Match";
113  case EGL_BAD_PARAMETER:
114  return "Bad Parameter";
115  case EGL_BAD_NATIVE_PIXMAP:
116  return "Bad Native Pixmap";
117  case EGL_BAD_NATIVE_WINDOW:
118  return "Bad Native Window";
119  case EGL_CONTEXT_LOST:
120  return "Context Lost";
121  default:
122  return "Unknown Error";
123  }
124 }
FlMethodResponse GError ** error

◆ egl_hexadecimal_to_string()

static gchar* egl_hexadecimal_to_string ( EGLint  value)
static

Definition at line 15 of file egl_utils.cc.

Referenced by egl_config_to_string(), egl_renderable_type_to_string(), and egl_surface_type_to_string().

15  {
16  return g_strdup_printf("0x%x", value);
17 }
uint8_t value

◆ egl_renderable_type_to_string()

static gchar* egl_renderable_type_to_string ( EGLint  value)
static

Definition at line 52 of file egl_utils.cc.

References clear_bit(), egl_hexadecimal_to_string(), and value.

Referenced by egl_config_to_string().

52  {
53  EGLint v = value;
54  g_autoptr(GPtrArray) strings = g_ptr_array_new_with_free_func(g_free);
55  if (clear_bit(&v, EGL_OPENGL_ES_BIT))
56  g_ptr_array_add(strings, g_strdup("EGL_OPENGL_ES_BIT"));
57  if (clear_bit(&v, EGL_OPENVG_BIT))
58  g_ptr_array_add(strings, g_strdup("EGL_OPENVG_BIT"));
59  if (clear_bit(&v, EGL_OPENGL_ES2_BIT))
60  g_ptr_array_add(strings, g_strdup("EGL_OPENGL_ES2_BIT"));
61  if (clear_bit(&v, EGL_OPENGL_BIT))
62  g_ptr_array_add(strings, g_strdup("EGL_OPENGL_BIT"));
63  if (clear_bit(&v, EGL_OPENGL_ES3_BIT))
64  g_ptr_array_add(strings, g_strdup("EGL_OPENGL_ES3_BIT"));
65  if (v != 0)
66  g_ptr_array_add(strings, egl_hexadecimal_to_string(v));
67  g_ptr_array_add(strings, nullptr);
68 
69  return g_strjoinv("|", reinterpret_cast<gchar**>(strings->pdata));
70 }
uint8_t value
static gchar * egl_hexadecimal_to_string(EGLint value)
Definition: egl_utils.cc:15
static gboolean clear_bit(EGLint *field, EGLint bit)
Definition: egl_utils.cc:43

◆ egl_surface_type_to_string()

static gchar* egl_surface_type_to_string ( EGLint  value)
static

Definition at line 73 of file egl_utils.cc.

References clear_bit(), egl_hexadecimal_to_string(), and value.

Referenced by egl_config_to_string().

73  {
74  EGLint v = value;
75  g_autoptr(GPtrArray) strings = g_ptr_array_new_with_free_func(g_free);
76  if (clear_bit(&v, EGL_PBUFFER_BIT))
77  g_ptr_array_add(strings, g_strdup("EGL_PBUFFER_BIT"));
78  if (clear_bit(&v, EGL_PIXMAP_BIT))
79  g_ptr_array_add(strings, g_strdup("EGL_PIXMAP_BIT"));
80  if (clear_bit(&v, EGL_WINDOW_BIT))
81  g_ptr_array_add(strings, g_strdup("EGL_WINDOW_BIT"));
82  if (v != 0)
83  g_ptr_array_add(strings, egl_hexadecimal_to_string(v));
84  g_ptr_array_add(strings, nullptr);
85 
86  return g_strjoinv("|", reinterpret_cast<gchar**>(strings->pdata));
87 }
uint8_t value
static gchar * egl_hexadecimal_to_string(EGLint value)
Definition: egl_utils.cc:15
static gboolean clear_bit(EGLint *field, EGLint bit)
Definition: egl_utils.cc:43