@@ -16,6 +16,45 @@ typedef struct {
16
16
17
17
G_DEFINE_TYPE_WITH_PRIVATE (FlRenderer, fl_renderer, G_TYPE_OBJECT)
18
18
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
+
19
58
// Default implementation for the start virtual method.
20
59
// Provided so subclasses can chain up to here.
21
60
static gboolean fl_renderer_real_start (FlRenderer* self, GError** error) {
@@ -52,25 +91,35 @@ static gboolean fl_renderer_real_start(FlRenderer* self, GError** error) {
52
91
if (!eglChooseConfig (priv->egl_display , attributes, &egl_config, 1 ,
53
92
&n_config)) {
54
93
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 () );
56
95
return FALSE ;
57
96
}
58
97
if (n_config == 0 ) {
59
98
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 () );
61
100
return FALSE ;
62
101
}
63
102
if (!eglBindAPI (EGL_OPENGL_ES_API)) {
64
103
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 () );
66
105
return FALSE ;
67
106
}
68
107
69
108
priv->egl_surface = FL_RENDERER_GET_CLASS (self)->create_surface (
70
109
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
+ }
71
115
EGLint context_attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2 , EGL_NONE};
72
116
priv->egl_context = eglCreateContext (priv->egl_display , egl_config,
73
117
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
+ }
74
123
EGLint value;
75
124
eglQueryContext (priv->egl_display , priv->egl_context ,
76
125
EGL_CONTEXT_CLIENT_VERSION, &value);
@@ -99,7 +148,7 @@ gboolean fl_renderer_make_current(FlRenderer* self, GError** error) {
99
148
if (!eglMakeCurrent (priv->egl_display , priv->egl_surface , priv->egl_surface ,
100
149
priv->egl_context )) {
101
150
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 () );
103
152
return FALSE ;
104
153
}
105
154
@@ -113,7 +162,7 @@ gboolean fl_renderer_clear_current(FlRenderer* self, GError** error) {
113
162
if (!eglMakeCurrent (priv->egl_display , EGL_NO_SURFACE, EGL_NO_SURFACE,
114
163
EGL_NO_CONTEXT)) {
115
164
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 () );
117
166
return FALSE ;
118
167
}
119
168
@@ -131,7 +180,7 @@ gboolean fl_renderer_present(FlRenderer* self, GError** error) {
131
180
132
181
if (!eglSwapBuffers (priv->egl_display , priv->egl_surface )) {
133
182
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 () );
135
184
return FALSE ;
136
185
}
137
186
0 commit comments