@@ -89,24 +89,6 @@ static void(*findProcAddress(const char* name,
8989
9090// ----------------------------------------------------------------------------
9191
92- template <typename T>
93- static __attribute__ ((noinline))
94- int binarySearch(T const sortedArray[], int first, int last, T key) {
95- while (first <= last) {
96- int mid = (first + last) / 2 ;
97- if (sortedArray[mid] < key) {
98- first = mid + 1 ;
99- } else if (key < sortedArray[mid]) {
100- last = mid - 1 ;
101- } else {
102- return mid;
103- }
104- }
105- return -1 ;
106- }
107-
108- // ----------------------------------------------------------------------------
109-
11092namespace android {
11193extern void setGLHooksThreadSpecific (gl_hooks_t const *value);
11294extern EGLBoolean egl_init_drivers ();
@@ -184,21 +166,20 @@ EGLBoolean eglGetConfigs( EGLDisplay dpy,
184166 egl_display_t const * const dp = validate_display (dpy);
185167 if (!dp) return EGL_FALSE;
186168
187- GLint numConfigs = dp->numTotalConfigs ;
188- if (!configs) {
189- *num_config = numConfigs;
190- return EGL_TRUE;
169+ if (num_config==0 ) {
170+ return setError (EGL_BAD_PARAMETER, EGL_FALSE);
191171 }
192172
193- GLint n = 0 ;
194- for (intptr_t i=0 ; i<dp->numTotalConfigs && config_size ; i++) {
195- *configs++ = EGLConfig (i);
196- config_size--;
197- n++;
173+ EGLBoolean res = EGL_FALSE;
174+ *num_config = 0 ;
175+
176+ egl_connection_t * const cnx = &gEGLImpl ;
177+ if (cnx->dso ) {
178+ res = cnx->egl .eglGetConfigs (
179+ dp->disp .dpy , configs, config_size, num_config);
198180 }
199-
200- *num_config = n;
201- return EGL_TRUE;
181+
182+ return res;
202183}
203184
204185EGLBoolean eglChooseConfig ( EGLDisplay dpy, const EGLint *attrib_list,
@@ -214,105 +195,14 @@ EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list,
214195 return setError (EGL_BAD_PARAMETER, EGL_FALSE);
215196 }
216197
217- EGLint n;
218198 EGLBoolean res = EGL_FALSE;
219199 *num_config = 0 ;
220200
221-
222- // It is unfortunate, but we need to remap the EGL_CONFIG_IDs,
223- // to do this, we have to go through the attrib_list array once
224- // to figure out both its size and if it contains an EGL_CONFIG_ID
225- // key. If so, the full array is copied and patched.
226- // NOTE: we assume that there can be only one occurrence
227- // of EGL_CONFIG_ID.
228-
229- EGLint patch_index = -1 ;
230- GLint attr;
231- size_t size = 0 ;
232- if (attrib_list) {
233- while ((attr=attrib_list[size]) != EGL_NONE) {
234- if (attr == EGL_CONFIG_ID)
235- patch_index = size;
236- size += 2 ;
237- }
238- }
239- if (patch_index >= 0 ) {
240- size += 2 ; // we need copy the sentinel as well
241- EGLint* new_list = (EGLint*)malloc (size*sizeof (EGLint));
242- if (new_list == 0 )
243- return setError (EGL_BAD_ALLOC, EGL_FALSE);
244- memcpy (new_list, attrib_list, size*sizeof (EGLint));
245-
246- // patch the requested EGL_CONFIG_ID
247- bool found = false ;
248- EGLConfig ourConfig (0 );
249- EGLint& configId (new_list[patch_index+1 ]);
250- for (intptr_t i=0 ; i<dp->numTotalConfigs ; i++) {
251- if (dp->configs [i].configId == configId) {
252- ourConfig = EGLConfig (i);
253- configId = dp->configs [i].implConfigId ;
254- found = true ;
255- break ;
256- }
257- }
258-
259- egl_connection_t * const cnx = &gEGLImpl ;
260- if (found && cnx->dso ) {
261- // and switch to the new list
262- attrib_list = const_cast <const EGLint *>(new_list);
263-
264- // At this point, the only configuration that can match is
265- // dp->configs[i][index], however, we don't know if it would be
266- // rejected because of the other attributes, so we do have to call
267- // cnx->egl.eglChooseConfig() -- but we don't have to loop
268- // through all the EGLimpl[].
269- // We also know we can only get a single config back, and we know
270- // which one.
271-
272- res = cnx->egl .eglChooseConfig (
273- dp->disp .dpy ,
274- attrib_list, configs, config_size, &n);
275- if (res && n>0 ) {
276- // n has to be 0 or 1, by construction, and we already know
277- // which config it will return (since there can be only one).
278- if (configs) {
279- configs[0 ] = ourConfig;
280- }
281- *num_config = 1 ;
282- }
283- }
284-
285- free (const_cast <EGLint *>(attrib_list));
286- return res;
287- }
288-
289-
290201 egl_connection_t * const cnx = &gEGLImpl ;
291202 if (cnx->dso ) {
292- if (cnx->egl .eglChooseConfig (
293- dp->disp .dpy , attrib_list, configs, config_size, &n)) {
294- if (configs) {
295- // now we need to convert these client EGLConfig to our
296- // internal EGLConfig format.
297- // This is done in O(n Log(n)) time.
298- for (int j=0 ; j<n ; j++) {
299- egl_config_t key (configs[j]);
300- intptr_t index = binarySearch<egl_config_t >(
301- dp->configs , 0 , dp->numTotalConfigs , key);
302- if (index >= 0 ) {
303- configs[j] = EGLConfig (index);
304- } else {
305- return setError (EGL_BAD_CONFIG, EGL_FALSE);
306- }
307- }
308- configs += n;
309- config_size -= n;
310- }
311- *num_config += n;
312- res = EGL_TRUE;
313- }
203+ res = cnx->egl .eglChooseConfig (
204+ dp->disp .dpy , attrib_list, configs, config_size, num_config);
314205 }
315-
316206 return res;
317207}
318208
@@ -325,13 +215,8 @@ EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
325215 egl_connection_t * cnx = validate_display_config (dpy, config, dp);
326216 if (!cnx) return EGL_FALSE;
327217
328- if (attribute == EGL_CONFIG_ID) {
329- *value = dp->configs [intptr_t (config)].configId ;
330- return EGL_TRUE;
331- }
332218 return cnx->egl .eglGetConfigAttrib (
333- dp->disp .dpy ,
334- dp->configs [intptr_t (config)].config , attribute, value);
219+ dp->disp .dpy , config, attribute, value);
335220}
336221
337222// ----------------------------------------------------------------------------
@@ -348,7 +233,6 @@ EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config,
348233 egl_connection_t * cnx = validate_display_config (dpy, config, dp);
349234 if (cnx) {
350235 EGLDisplay iDpy = dp->disp .dpy ;
351- EGLConfig iConfig = dp->configs [intptr_t (config)].config ;
352236 EGLint format;
353237
354238 if (native_window_api_connect (window, NATIVE_WINDOW_API_EGL) != OK) {
@@ -359,7 +243,7 @@ EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config,
359243
360244 // set the native window's buffers format to match this config
361245 if (cnx->egl .eglGetConfigAttrib (iDpy,
362- iConfig , EGL_NATIVE_VISUAL_ID, &format)) {
246+ config , EGL_NATIVE_VISUAL_ID, &format)) {
363247 if (format != 0 ) {
364248 int err = native_window_set_buffers_format (window, format);
365249 if (err != 0 ) {
@@ -377,7 +261,7 @@ EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config,
377261 anw->setSwapInterval (anw, 1 );
378262
379263 EGLSurface surface = cnx->egl .eglCreateWindowSurface (
380- iDpy, iConfig , window, attrib_list);
264+ iDpy, config , window, attrib_list);
381265 if (surface != EGL_NO_SURFACE) {
382266 egl_surface_t * s = new egl_surface_t (dpy, config, window, surface, cnx);
383267 return s;
@@ -400,8 +284,7 @@ EGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config,
400284 egl_connection_t * cnx = validate_display_config (dpy, config, dp);
401285 if (cnx) {
402286 EGLSurface surface = cnx->egl .eglCreatePixmapSurface (
403- dp->disp .dpy ,
404- dp->configs [intptr_t (config)].config , pixmap, attrib_list);
287+ dp->disp .dpy , config, pixmap, attrib_list);
405288 if (surface != EGL_NO_SURFACE) {
406289 egl_surface_t * s = new egl_surface_t (dpy, config, NULL , surface, cnx);
407290 return s;
@@ -419,8 +302,7 @@ EGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config,
419302 egl_connection_t * cnx = validate_display_config (dpy, config, dp);
420303 if (cnx) {
421304 EGLSurface surface = cnx->egl .eglCreatePbufferSurface (
422- dp->disp .dpy ,
423- dp->configs [intptr_t (config)].config , attrib_list);
305+ dp->disp .dpy , config, attrib_list);
424306 if (surface != EGL_NO_SURFACE) {
425307 egl_surface_t * s = new egl_surface_t (dpy, config, NULL , surface, cnx);
426308 return s;
@@ -461,16 +343,8 @@ EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface,
461343 return setError (EGL_BAD_SURFACE, EGL_FALSE);
462344
463345 egl_surface_t const * const s = get_surface (surface);
464- EGLBoolean result (EGL_TRUE);
465- if (attribute == EGL_CONFIG_ID) {
466- // We need to remap EGL_CONFIG_IDs
467- *value = dp->configs [intptr_t (s->config )].configId ;
468- } else {
469- result = s->cnx ->egl .eglQuerySurface (
470- dp->disp .dpy , s->surface , attribute, value);
471- }
472-
473- return result;
346+ return s->cnx ->egl .eglQuerySurface (
347+ dp->disp .dpy , s->surface , attribute, value);
474348}
475349
476350void EGLAPI eglBeginFrame (EGLDisplay dpy, EGLSurface surface) {
@@ -510,9 +384,7 @@ EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config,
510384 share_list = c->context ;
511385 }
512386 EGLContext context = cnx->egl .eglCreateContext (
513- dp->disp .dpy ,
514- dp->configs [intptr_t (config)].config ,
515- share_list, attrib_list);
387+ dp->disp .dpy , config, share_list, attrib_list);
516388 if (context != EGL_NO_CONTEXT) {
517389 // figure out if it's a GLESv1 or GLESv2
518390 int version = 0 ;
@@ -522,9 +394,9 @@ EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config,
522394 GLint value = *attrib_list++;
523395 if (attr == EGL_CONTEXT_CLIENT_VERSION) {
524396 if (value == 1 ) {
525- version = GLESv1_INDEX;
397+ version = egl_connection_t :: GLESv1_INDEX;
526398 } else if (value == 2 ) {
527- version = GLESv2_INDEX;
399+ version = egl_connection_t :: GLESv2_INDEX;
528400 }
529401 }
530402 };
@@ -668,17 +540,9 @@ EGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx,
668540 if (!_c.get ()) return setError (EGL_BAD_CONTEXT, EGL_FALSE);
669541
670542 egl_context_t * const c = get_context (ctx);
543+ return c->cnx ->egl .eglQueryContext (
544+ dp->disp .dpy , c->context , attribute, value);
671545
672- EGLBoolean result (EGL_TRUE);
673- if (attribute == EGL_CONFIG_ID) {
674- *value = dp->configs [intptr_t (c->config )].configId ;
675- } else {
676- // We need to remap EGL_CONFIG_IDs
677- result = c->cnx ->egl .eglQueryContext (
678- dp->disp .dpy , c->context , attribute, value);
679- }
680-
681- return result;
682546}
683547
684548EGLContext eglGetCurrentContext (void )
@@ -849,8 +713,8 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname)
849713 if (cnx->dso && cnx->egl .eglGetProcAddress ) {
850714 found = true ;
851715 // Extensions are independent of the bound context
852- cnx->hooks [GLESv1_INDEX]->ext .extensions [slot] =
853- cnx->hooks [GLESv2_INDEX]->ext .extensions [slot] =
716+ cnx->hooks [egl_connection_t :: GLESv1_INDEX]->ext .extensions [slot] =
717+ cnx->hooks [egl_connection_t :: GLESv2_INDEX]->ext .extensions [slot] =
854718#if EGL_TRACE
855719 debugHooks->ext .extensions [slot] =
856720 gHooksTrace .ext .extensions [slot] =
@@ -1105,9 +969,7 @@ EGLSurface eglCreatePbufferFromClientBuffer(
1105969 if (!cnx) return EGL_FALSE;
1106970 if (cnx->egl .eglCreatePbufferFromClientBuffer ) {
1107971 return cnx->egl .eglCreatePbufferFromClientBuffer (
1108- dp->disp .dpy ,
1109- buftype, buffer,
1110- dp->configs [intptr_t (config)].config , attrib_list);
972+ dp->disp .dpy , buftype, buffer, config, attrib_list);
1111973 }
1112974 return setError (EGL_BAD_CONFIG, EGL_NO_SURFACE);
1113975}
0 commit comments