Merge lp:~afrantzis/glproxy/fix-dummy-surface into lp:~jammy-zhou/glproxy/glproxy

Proposed by Alexandros Frantzis
Status: Merged
Merged at revision: 29
Proposed branch: lp:~afrantzis/glproxy/fix-dummy-surface
Merge into: lp:~jammy-zhou/glproxy/glproxy
Diff against target: 180 lines (+34/-28)
2 files modified
src/egldef.h (+8/-2)
src/gl_proxy.c (+26/-26)
To merge this branch: bzr merge lp:~afrantzis/glproxy/fix-dummy-surface
Reviewer Review Type Date Requested Status
Jammy Zhou Approve
Review via email: mp+59537@code.launchpad.net
To post a comment you must log in.
29. By Alexandros Frantzis

Ensure that we always get a valid dummy surface to use for configuration.

Using eglGetConfig and eglCreateWindowSurface does not guarantee that
the returned EGLConfig supports ES2, nor that it is suitable for window
surfaces, nor that it is compatible with the used X window visual. We can
use eglChooseConfig with explicit attributes and eglCreatePbufferSurface
to make the process both simpler and more robust.

Revision history for this message
Jammy Zhou (jammy-zhou) wrote :

eglChooseConfig/eglCreatePbufferSurface pair seems more robust ^_^

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/egldef.h'
2--- src/egldef.h 2011-02-24 04:52:03 +0000
3+++ src/egldef.h 2011-04-29 22:03:27 +0000
4@@ -42,15 +42,21 @@
5 #define EGL_OPENGL_ES_API 0x30A0
6 #define EGL_OPENGL_API 0x30A2
7
8+#define EGL_RENDERABLE_TYPE 0x3040
9+#define EGL_SURFACE_TYPE 0x3033
10+#define EGL_PBUFFER_BIT 0x0001 /* EGL_SURFACE_TYPE mask bits */
11+#define EGL_OPENGL_ES2_BIT 0x0004 /* EGL_RENDERABLE_TYPE mask bits */
12 #define EGL_CONTEXT_CLIENT_VERSION 0x3098
13 #define EGL_NONE 0x3038
14+#define EGL_HEIGHT 0x3056
15+#define EGL_WIDTH 0x3057
16
17 typedef void * (*PFNPROXYEGLGETPROCADDRESSPROC)( char const *procName);
18 typedef EGLDisplay (*PFNPROXYEGLGETDISPLAYPROC)(EGLNativeDisplayType display_id);
19 typedef EGLBoolean (*PFNPROXYEGLINITIALIZEPROC)(EGLDisplay dpy, EGLint *major, EGLint *minor);
20 typedef EGLBoolean (*PFNPROXYEGLTERMINATEPROC)(EGLDisplay dpy);
21-typedef EGLBoolean (*PFNPROXYEGLGETCONFIGSPROC)(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
22-typedef EGLSurface (*PFNPROXYEGLCREATEWINDOWSURFACEPROC)(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list);
23+typedef EGLBoolean (*PFNPROXYEGLCHOOSECONFIGPROC)(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
24+typedef EGLSurface (*PFNPROXYEGLCREATEPBUFFERSURFACEPROC)(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
25 typedef EGLBoolean (*PFNPROXYEGLDESTROYSURFACEPROC)(EGLDisplay dpy, EGLSurface surface);
26 typedef EGLContext (*PFNPROXYEGLCREATECONTEXTPROC)(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);
27 typedef EGLBoolean (*PFNPROXYEGLDESTROYCONTEXTPROC)(EGLDisplay dpy, EGLContext ctx);
28
29=== modified file 'src/gl_proxy.c'
30--- src/gl_proxy.c 2011-03-10 14:13:00 +0000
31+++ src/gl_proxy.c 2011-04-29 22:03:27 +0000
32@@ -199,10 +199,10 @@
33 PFNPROXYEGLGETDISPLAYPROC pfnProxyEGLGetDisplay = NULL;
34 PFNPROXYEGLINITIALIZEPROC pfnProxyEGLInitialize = NULL;
35 PFNPROXYEGLTERMINATEPROC pfnProxyEGLTerminate = NULL;
36-PFNPROXYEGLGETCONFIGSPROC pfnProxyEGLGetConfigs = NULL;
37+PFNPROXYEGLCHOOSECONFIGPROC pfnProxyEGLChooseConfig = NULL;
38 PFNPROXYEGLCREATECONTEXTPROC pfnProxyEGLCreateContext = NULL;
39 PFNPROXYEGLDESTROYCONTEXTPROC pfnProxyEGLDestroyContext = NULL;
40-PFNPROXYEGLCREATEWINDOWSURFACEPROC pfnProxyEGLCreateWindowSurface = NULL;
41+PFNPROXYEGLCREATEPBUFFERSURFACEPROC pfnProxyEGLCreatePbufferSurface = NULL;
42 PFNPROXYEGLDESTROYSURFACEPROC pfnProxyEGLDestroySurface = NULL;
43 PFNPROXYEGLMAKECURRENTPROC pfnProxyEGLMakeCurrent = NULL;
44
45@@ -220,16 +220,26 @@
46 * - call glGetString to get renderer information
47 * - call eglGetProcAddress to get symbol address for functions of GLES2 extenstions
48 */
49-static int CreateEGLRenderingContext(Display *dpy, Window win, PROXY_CONTEXT *proxy_context)
50+static int CreateEGLRenderingContext(Display *dpy, PROXY_CONTEXT *proxy_context)
51 {
52 EGLDisplay egl_dpy;
53 EGLConfig config;
54 EGLint num_configs = 1;
55
56+ static const EGLint config_attribs[] = {
57+ EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
58+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
59+ EGL_NONE
60+ };
61 static const EGLint ctx_attribs[] = {
62 EGL_CONTEXT_CLIENT_VERSION, 2,
63 EGL_NONE
64 };
65+ static const EGLint surface_attribs[] = {
66+ EGL_WIDTH, 1,
67+ EGL_HEIGHT, 1,
68+ EGL_NONE
69+ };
70
71 if (proxy_context->egl_dpy && proxy_context->egl_ctx && proxy_context->egl_surf)
72 return 0;
73@@ -241,7 +251,7 @@
74 return -1;
75 }
76
77- if (!(*pfnProxyEGLGetConfigs)(egl_dpy, &config, num_configs, &num_configs) || num_configs < 1) {
78+ if (!(*pfnProxyEGLChooseConfig)(egl_dpy, config_attribs, &config, num_configs, &num_configs) || num_configs < 1) {
79 printf("failed to get egl config\n");
80 return -1;
81 }
82@@ -252,9 +262,9 @@
83 return -1;
84 }
85
86- proxy_context->egl_surf = (*pfnProxyEGLCreateWindowSurface)(egl_dpy, config, win, NULL);
87+ proxy_context->egl_surf = (*pfnProxyEGLCreatePbufferSurface)(egl_dpy, config, surface_attribs);
88 if (EGL_NO_SURFACE == proxy_context->egl_surf) {
89- printf("eglCreateWindowSurface failed\n");
90+ printf("eglCreatePbufferSurface failed\n");
91 return -1;
92 }
93
94@@ -291,31 +301,26 @@
95 }
96 else if (OPENGL_ES20_BACKEND == proxy_context->current_backend) {
97 Display *dpy = XOpenDisplay(NULL);
98- int scrnum;
99- Window root;
100
101 if (NULL == dpy) {
102 printf("failed to open display\n");
103 return -1;
104 }
105
106- scrnum = DefaultScreen(dpy);
107- root = RootWindow(dpy, scrnum);
108-
109 if (NULL == proxy_context->egl_handle) {
110 proxy_context->egl_handle = glProxyOpenLibrary(LIBEGL_PATH);
111 pfnProxyEGLGetDisplay = dlsym(proxy_context->egl_handle, "eglGetDisplay");
112 pfnProxyEGLInitialize = dlsym(proxy_context->egl_handle, "eglInitialize");
113- pfnProxyEGLGetConfigs = dlsym(proxy_context->egl_handle, "eglGetConfigs");
114+ pfnProxyEGLChooseConfig = dlsym(proxy_context->egl_handle, "eglChooseConfig");
115 pfnProxyEGLCreateContext = dlsym(proxy_context->egl_handle, "eglCreateContext");
116- pfnProxyEGLCreateWindowSurface = dlsym(proxy_context->egl_handle, "eglCreateWindowSurface");
117+ pfnProxyEGLCreatePbufferSurface = dlsym(proxy_context->egl_handle, "eglCreatePbufferSurface");
118 pfnProxyEGLMakeCurrent = dlsym(proxy_context->egl_handle, "eglMakeCurrent");
119 pfnProxyEGLDestroyContext = dlsym(proxy_context->egl_handle, "eglDestroyContext");
120 pfnProxyEGLDestroySurface = dlsym(proxy_context->egl_handle, "eglDestroySurface");
121 pfnProxyEGLTerminate = dlsym(proxy_context->egl_handle, "eglTerminate");
122 }
123
124- if (CreateEGLRenderingContext(dpy, root, proxy_context) < 0)
125+ if (CreateEGLRenderingContext(dpy, proxy_context) < 0)
126 return -1;
127
128 pfnProxyEGLGetProcAddress = dlsym(proxy_context->egl_handle, "eglGetProcAddress");
129@@ -443,18 +448,12 @@
130
131 /* Try to get the gles2 renderer info */
132 if (proxy_context->egl_handle && proxy_context->gles2_handle) {
133- int scrnum;
134- Window root;
135-
136- scrnum = DefaultScreen(dpy);
137- root = RootWindow(dpy, scrnum);
138-
139 /* Resolve EGL APIs for create rendering context to get GL_RENDERER */
140 pfnProxyEGLGetDisplay = dlsym(proxy_context->egl_handle, "eglGetDisplay");
141 pfnProxyEGLInitialize = dlsym(proxy_context->egl_handle, "eglInitialize");
142- pfnProxyEGLGetConfigs = dlsym(proxy_context->egl_handle, "eglGetConfigs");
143+ pfnProxyEGLChooseConfig = dlsym(proxy_context->egl_handle, "eglChooseConfig");
144 pfnProxyEGLCreateContext = dlsym(proxy_context->egl_handle, "eglCreateContext");
145- pfnProxyEGLCreateWindowSurface = dlsym(proxy_context->egl_handle, "eglCreateWindowSurface");
146+ pfnProxyEGLCreatePbufferSurface = dlsym(proxy_context->egl_handle, "eglCreatePbufferSurface");
147 pfnProxyEGLMakeCurrent = dlsym(proxy_context->egl_handle, "eglMakeCurrent");
148 pfnProxyEGLDestroyContext = dlsym(proxy_context->egl_handle, "eglDestroyContext");
149 pfnProxyEGLDestroySurface = dlsym(proxy_context->egl_handle, "eglDestroySurface");
150@@ -463,7 +462,7 @@
151 /* Resolve glGetString */
152 pfnProxyGetString = dlsym(proxy_context->gles2_handle, "glGetString");
153
154- CreateEGLRenderingContext(dpy, root, proxy_context);
155+ CreateEGLRenderingContext(dpy, proxy_context);
156
157 gles2_renderer = pfnProxyGetString(GL_RENDERER);
158
159@@ -544,9 +543,9 @@
160 DestroyEGLRenderingContext(proxy_context);
161 pfnProxyEGLGetDisplay = NULL;
162 pfnProxyEGLInitialize = NULL;
163- pfnProxyEGLGetConfigs = NULL;
164+ pfnProxyEGLChooseConfig = NULL;
165 pfnProxyEGLCreateContext = NULL;
166- pfnProxyEGLCreateWindowSurface = NULL;
167+ pfnProxyEGLCreatePbufferSurface = NULL;
168 pfnProxyEGLMakeCurrent = NULL;
169 pfnProxyEGLDestroyContext = NULL;
170 pfnProxyEGLDestroySurface = NULL;
171@@ -738,7 +737,8 @@
172 printf("%s backend is selected for rendering\n", (global_proxy_context.current_backend == OPENGL_BACKEND) ? "OpenGL" : "OpenGL ES2.0");
173
174 /* Load selected backend, and resolve glXGetProcAddress/eglGetProcAddress */
175- glProxyEarlyResolve(&global_proxy_context);
176+ if (glProxyEarlyResolve(&global_proxy_context) < 0)
177+ return -1;
178
179 /* Resolve symbols */
180 if (OPENGL_BACKEND == global_proxy_context.current_backend) {

Subscribers

People subscribed via source and target branches