@@ -16,6 +16,45 @@ typedef struct {
1616
1717G_DEFINE_TYPE_WITH_PRIVATE (FlRenderer, fl_renderer, G_TYPE_OBJECT)
1818
19+ // Gets a string representation of the last EGL error.
20+ static const gchar* get_egl_error() {
21+ EGLint error = eglGetError ();
22+ switch (error) {
23+ case EGL_SUCCESS:
24+ return " Success" ;
25+ case EGL_NOT_INITIALIZED:
26+ return " Not Initialized" ;
27+ case EGL_BAD_ACCESS:
28+ return " Bad Access" ;
29+ case EGL_BAD_ALLOC:
30+ return " Bad Allocation" ;
31+ case EGL_BAD_ATTRIBUTE:
32+ return " Bad Attribute" ;
33+ case EGL_BAD_CONTEXT:
34+ return " Bad Context" ;
35+ case EGL_BAD_CONFIG:
36+ return " Bad Configuration" ;
37+ case EGL_BAD_CURRENT_SURFACE:
38+ return " Bad Current Surface" ;
39+ case EGL_BAD_DISPLAY:
40+ return " Bad Display" ;
41+ case EGL_BAD_SURFACE:
42+ return " Bad Surface" ;
43+ case EGL_BAD_MATCH:
44+ return " Bad Match" ;
45+ case EGL_BAD_PARAMETER:
46+ return " Bad Parameter" ;
47+ case EGL_BAD_NATIVE_PIXMAP:
48+ return " Bad Native Pixmap" ;
49+ case EGL_BAD_NATIVE_WINDOW:
50+ return " Bad Native Window" ;
51+ case EGL_CONTEXT_LOST:
52+ return " Context Lost" ;
53+ default :
54+ return " Unknown Error" ;
55+ }
56+ }
57+
1958// Default implementation for the start virtual method.
2059// Provided so subclasses can chain up to here.
2160static gboolean fl_renderer_real_start (FlRenderer* self, GError** error) {
@@ -52,25 +91,35 @@ static gboolean fl_renderer_real_start(FlRenderer* self, GError** error) {
5291 if (!eglChooseConfig (priv->egl_display , attributes, &egl_config, 1 ,
5392 &n_config)) {
5493 g_set_error (error, fl_renderer_error_quark (), FL_RENDERER_ERROR_FAILED,
55- " Failed to choose EGL config" );
94+ " Failed to choose EGL config: %s " , get_egl_error () );
5695 return FALSE ;
5796 }
5897 if (n_config == 0 ) {
5998 g_set_error (error, fl_renderer_error_quark (), FL_RENDERER_ERROR_FAILED,
60- " Failed to find appropriate EGL config" );
99+ " Failed to find appropriate EGL config: %s " , get_egl_error () );
61100 return FALSE ;
62101 }
63102 if (!eglBindAPI (EGL_OPENGL_ES_API)) {
64103 g_set_error (error, fl_renderer_error_quark (), FL_RENDERER_ERROR_FAILED,
65- " Failed to bind EGL OpenGL ES API" );
104+ " Failed to bind EGL OpenGL ES API: %s " , get_egl_error () );
66105 return FALSE ;
67106 }
68107
69108 priv->egl_surface = FL_RENDERER_GET_CLASS (self)->create_surface (
70109 self, priv->egl_display , egl_config);
110+ if (priv->egl_surface == nullptr ) {
111+ g_set_error (error, fl_renderer_error_quark (), FL_RENDERER_ERROR_FAILED,
112+ " Failed to create EGL surface: %s" , get_egl_error ());
113+ return FALSE ;
114+ }
71115 EGLint context_attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2 , EGL_NONE};
72116 priv->egl_context = eglCreateContext (priv->egl_display , egl_config,
73117 EGL_NO_CONTEXT, context_attributes);
118+ if (priv->egl_context == nullptr ) {
119+ g_set_error (error, fl_renderer_error_quark (), FL_RENDERER_ERROR_FAILED,
120+ " Failed to create EGL context: %s" , get_egl_error ());
121+ return FALSE ;
122+ }
74123 EGLint value;
75124 eglQueryContext (priv->egl_display , priv->egl_context ,
76125 EGL_CONTEXT_CLIENT_VERSION, &value);
@@ -99,7 +148,7 @@ gboolean fl_renderer_make_current(FlRenderer* self, GError** error) {
99148 if (!eglMakeCurrent (priv->egl_display , priv->egl_surface , priv->egl_surface ,
100149 priv->egl_context )) {
101150 g_set_error (error, fl_renderer_error_quark (), FL_RENDERER_ERROR_FAILED,
102- " Failed to make EGL context current" );
151+ " Failed to make EGL context current: %s " , get_egl_error () );
103152 return FALSE ;
104153 }
105154
@@ -113,7 +162,7 @@ gboolean fl_renderer_clear_current(FlRenderer* self, GError** error) {
113162 if (!eglMakeCurrent (priv->egl_display , EGL_NO_SURFACE, EGL_NO_SURFACE,
114163 EGL_NO_CONTEXT)) {
115164 g_set_error (error, fl_renderer_error_quark (), FL_RENDERER_ERROR_FAILED,
116- " Failed to clear EGL context" );
165+ " Failed to clear EGL context: %s " , get_egl_error () );
117166 return FALSE ;
118167 }
119168
@@ -131,7 +180,7 @@ gboolean fl_renderer_present(FlRenderer* self, GError** error) {
131180
132181 if (!eglSwapBuffers (priv->egl_display , priv->egl_surface )) {
133182 g_set_error (error, fl_renderer_error_quark (), FL_RENDERER_ERROR_FAILED,
134- " Failed to swap EGL buffers" );
183+ " Failed to swap EGL buffers: %s " , get_egl_error () );
135184 return FALSE ;
136185 }
137186
0 commit comments