st/egl: add android backend
[mesa.git] / src / gallium / state_trackers / egl / common / egl_g3d.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.8
4 *
5 * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26 #include "egldriver.h"
27 #include "eglcurrent.h"
28 #include "egllog.h"
29
30 #include "pipe/p_screen.h"
31 #include "util/u_memory.h"
32 #include "util/u_format.h"
33 #include "util/u_string.h"
34 #include "util/u_atomic.h"
35
36 #include "egl_g3d.h"
37 #include "egl_g3d_api.h"
38 #include "egl_g3d_st.h"
39 #include "egl_g3d_loader.h"
40 #include "native.h"
41
42 static void
43 egl_g3d_invalid_surface(struct native_display *ndpy,
44 struct native_surface *nsurf,
45 unsigned int seq_num)
46 {
47 /* XXX not thread safe? */
48 struct egl_g3d_surface *gsurf = egl_g3d_surface(nsurf->user_data);
49
50 if (gsurf && gsurf->stfbi)
51 p_atomic_inc(&gsurf->stfbi->stamp);
52 }
53
54 static struct pipe_screen *
55 egl_g3d_new_drm_screen(struct native_display *ndpy, const char *name, int fd)
56 {
57 _EGLDisplay *dpy = (_EGLDisplay *) ndpy->user_data;
58 struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
59 return gdpy->loader->create_drm_screen(name, fd);
60 }
61
62 static struct pipe_screen *
63 egl_g3d_new_sw_screen(struct native_display *ndpy, struct sw_winsys *ws)
64 {
65 _EGLDisplay *dpy = (_EGLDisplay *) ndpy->user_data;
66 struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
67 return gdpy->loader->create_sw_screen(ws);
68 }
69
70 static struct pipe_resource *
71 egl_g3d_lookup_egl_image(struct native_display *ndpy, void *egl_image)
72 {
73 _EGLDisplay *dpy = (_EGLDisplay *) ndpy->user_data;
74 struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
75 struct st_egl_image img;
76 struct pipe_resource *resource = NULL;
77
78 memset(&img, 0, sizeof(img));
79 if (gdpy->smapi->get_egl_image(gdpy->smapi, egl_image, &img))
80 resource = img.texture;
81
82 return resource;
83 }
84
85 static const struct native_event_handler egl_g3d_native_event_handler = {
86 egl_g3d_invalid_surface,
87 egl_g3d_new_drm_screen,
88 egl_g3d_new_sw_screen,
89 egl_g3d_lookup_egl_image
90 };
91
92 /**
93 * Get the native platform.
94 */
95 static const struct native_platform *
96 egl_g3d_get_platform(_EGLDriver *drv, _EGLPlatformType plat)
97 {
98 struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
99
100 if (!gdrv->platforms[plat]) {
101 const char *plat_name = NULL;
102 const struct native_platform *nplat = NULL;
103
104 switch (plat) {
105 case _EGL_PLATFORM_WINDOWS:
106 plat_name = "Windows";
107 #ifdef HAVE_GDI_BACKEND
108 nplat = native_get_gdi_platform(&egl_g3d_native_event_handler);
109 #endif
110 break;
111 case _EGL_PLATFORM_X11:
112 plat_name = "X11";
113 #ifdef HAVE_X11_BACKEND
114 nplat = native_get_x11_platform(&egl_g3d_native_event_handler);
115 #endif
116 break;
117 case _EGL_PLATFORM_WAYLAND:
118 plat_name = "wayland";
119 #ifdef HAVE_WAYLAND_BACKEND
120 nplat = native_get_wayland_platform(&egl_g3d_native_event_handler);
121 #endif
122 break;
123 case _EGL_PLATFORM_DRM:
124 plat_name = "DRM";
125 #ifdef HAVE_DRM_BACKEND
126 nplat = native_get_drm_platform(&egl_g3d_native_event_handler);
127 #endif
128 break;
129 case _EGL_PLATFORM_FBDEV:
130 plat_name = "FBDEV";
131 #ifdef HAVE_FBDEV_BACKEND
132 nplat = native_get_fbdev_platform(&egl_g3d_native_event_handler);
133 #endif
134 break;
135 case _EGL_PLATFORM_ANDROID:
136 plat_name = "Android";
137 #ifdef HAVE_ANDROID_BACKEND
138 nplat = native_get_android_platform(&egl_g3d_native_event_handler);
139 #endif
140 break;
141 default:
142 break;
143 }
144
145 if (!nplat)
146 _eglLog(_EGL_WARNING, "unsupported platform %s", plat_name);
147
148 gdrv->platforms[plat] = nplat;
149 }
150
151 return gdrv->platforms[plat];
152 }
153
154 #ifdef EGL_MESA_screen_surface
155
156 static void
157 egl_g3d_add_screens(_EGLDriver *drv, _EGLDisplay *dpy)
158 {
159 struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
160 const struct native_connector **native_connectors;
161 EGLint num_connectors, i;
162
163 native_connectors =
164 gdpy->native->modeset->get_connectors(gdpy->native, &num_connectors, NULL);
165 if (!num_connectors) {
166 if (native_connectors)
167 FREE(native_connectors);
168 return;
169 }
170
171 for (i = 0; i < num_connectors; i++) {
172 const struct native_connector *nconn = native_connectors[i];
173 struct egl_g3d_screen *gscr;
174 const struct native_mode **native_modes;
175 EGLint num_modes, j;
176
177 /* TODO support for hotplug */
178 native_modes =
179 gdpy->native->modeset->get_modes(gdpy->native, nconn, &num_modes);
180 if (!num_modes) {
181 if (native_modes)
182 FREE(native_modes);
183 continue;
184 }
185
186 gscr = CALLOC_STRUCT(egl_g3d_screen);
187 if (!gscr) {
188 FREE(native_modes);
189 continue;
190 }
191
192 _eglInitScreen(&gscr->base, dpy, num_modes);
193 for (j = 0; j < gscr->base.NumModes; j++) {
194 const struct native_mode *nmode = native_modes[j];
195 _EGLMode *mode = &gscr->base.Modes[j];
196
197 mode->Width = nmode->width;
198 mode->Height = nmode->height;
199 mode->RefreshRate = nmode->refresh_rate;
200 mode->Optimal = EGL_FALSE;
201 mode->Interlaced = EGL_FALSE;
202 /* no need to strdup() */
203 mode->Name = nmode->desc;
204 }
205
206 gscr->native = nconn;
207 gscr->native_modes = native_modes;
208
209 _eglLinkScreen(&gscr->base);
210 }
211
212 FREE(native_connectors);
213 }
214
215 #endif /* EGL_MESA_screen_surface */
216
217 /**
218 * Initialize and validate the EGL config attributes.
219 */
220 static EGLBoolean
221 init_config_attributes(_EGLConfig *conf, const struct native_config *nconf,
222 EGLint api_mask, enum pipe_format depth_stencil_format,
223 EGLBoolean preserve_buffer, EGLint max_swap_interval)
224 {
225 uint rgba[4], depth_stencil[2], buffer_size;
226 EGLint surface_type;
227 EGLint i;
228
229 /* get the color and depth/stencil component sizes */
230 assert(nconf->color_format != PIPE_FORMAT_NONE);
231 buffer_size = 0;
232 for (i = 0; i < 4; i++) {
233 rgba[i] = util_format_get_component_bits(nconf->color_format,
234 UTIL_FORMAT_COLORSPACE_RGB, i);
235 buffer_size += rgba[i];
236 }
237 for (i = 0; i < 2; i++) {
238 if (depth_stencil_format != PIPE_FORMAT_NONE) {
239 depth_stencil[i] =
240 util_format_get_component_bits(depth_stencil_format,
241 UTIL_FORMAT_COLORSPACE_ZS, i);
242 }
243 else {
244 depth_stencil[i] = 0;
245 }
246 }
247
248 surface_type = 0x0;
249 /* pixmap surfaces should be EGL_SINGLE_BUFFER */
250 if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_FRONT_LEFT)) {
251 if (nconf->pixmap_bit)
252 surface_type |= EGL_PIXMAP_BIT;
253 }
254 /* the others surfaces should be EGL_BACK_BUFFER (or settable) */
255 if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_BACK_LEFT)) {
256 if (nconf->window_bit)
257 surface_type |= EGL_WINDOW_BIT;
258 #ifdef EGL_MESA_screen_surface
259 if (nconf->scanout_bit)
260 surface_type |= EGL_SCREEN_BIT_MESA;
261 #endif
262 surface_type |= EGL_PBUFFER_BIT;
263 }
264
265 conf->Conformant = api_mask;
266 conf->RenderableType = api_mask;
267
268 conf->RedSize = rgba[0];
269 conf->GreenSize = rgba[1];
270 conf->BlueSize = rgba[2];
271 conf->AlphaSize = rgba[3];
272 conf->BufferSize = buffer_size;
273
274 conf->DepthSize = depth_stencil[0];
275 conf->StencilSize = depth_stencil[1];
276
277 /* st/vega will allocate the mask on demand */
278 if (api_mask & EGL_OPENVG_BIT)
279 conf->AlphaMaskSize = 8;
280
281 conf->SurfaceType = surface_type;
282
283 conf->NativeRenderable = EGL_TRUE;
284 if (surface_type & EGL_WINDOW_BIT) {
285 conf->NativeVisualID = nconf->native_visual_id;
286 conf->NativeVisualType = nconf->native_visual_type;
287 }
288
289 if (surface_type & EGL_PBUFFER_BIT) {
290 conf->BindToTextureRGB = EGL_TRUE;
291 if (rgba[3])
292 conf->BindToTextureRGBA = EGL_TRUE;
293
294 conf->MaxPbufferWidth = 4096;
295 conf->MaxPbufferHeight = 4096;
296 conf->MaxPbufferPixels = 4096 * 4096;
297 }
298
299 conf->Level = nconf->level;
300
301 if (nconf->transparent_rgb) {
302 conf->TransparentType = EGL_TRANSPARENT_RGB;
303 conf->TransparentRedValue = nconf->transparent_rgb_values[0];
304 conf->TransparentGreenValue = nconf->transparent_rgb_values[1];
305 conf->TransparentBlueValue = nconf->transparent_rgb_values[2];
306 }
307
308 conf->MinSwapInterval = 0;
309 conf->MaxSwapInterval = max_swap_interval;
310 if (preserve_buffer)
311 conf->SurfaceType |= EGL_SWAP_BEHAVIOR_PRESERVED_BIT;
312
313 return _eglValidateConfig(conf, EGL_FALSE);
314 }
315
316 /**
317 * Initialize an EGL config from the native config.
318 */
319 static EGLBoolean
320 egl_g3d_init_config(_EGLDriver *drv, _EGLDisplay *dpy,
321 _EGLConfig *conf, const struct native_config *nconf,
322 enum pipe_format depth_stencil_format,
323 int preserve_buffer, int max_swap_interval)
324 {
325 struct egl_g3d_config *gconf = egl_g3d_config(conf);
326 EGLint buffer_mask;
327 EGLBoolean valid;
328
329 buffer_mask = 0x0;
330 if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_FRONT_LEFT))
331 buffer_mask |= ST_ATTACHMENT_FRONT_LEFT_MASK;
332 if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_BACK_LEFT))
333 buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK;
334 if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_FRONT_RIGHT))
335 buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK;
336 if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_BACK_RIGHT))
337 buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK;
338
339 gconf->stvis.buffer_mask = buffer_mask;
340 gconf->stvis.color_format = nconf->color_format;
341 gconf->stvis.depth_stencil_format = depth_stencil_format;
342 gconf->stvis.accum_format = PIPE_FORMAT_NONE;
343 gconf->stvis.samples = 0;
344
345 /* will be overridden per surface */
346 gconf->stvis.render_buffer = (buffer_mask & ST_ATTACHMENT_BACK_LEFT_MASK) ?
347 ST_ATTACHMENT_BACK_LEFT : ST_ATTACHMENT_FRONT_LEFT;
348
349 valid = init_config_attributes(&gconf->base,
350 nconf, dpy->ClientAPIs, depth_stencil_format,
351 preserve_buffer, max_swap_interval);
352 if (!valid) {
353 _eglLog(_EGL_DEBUG, "skip invalid config 0x%x", nconf->native_visual_id);
354 return EGL_FALSE;
355 }
356
357 gconf->native = nconf;
358
359 return EGL_TRUE;
360 }
361
362 /**
363 * Get all interested depth/stencil formats of a display.
364 */
365 static EGLint
366 egl_g3d_fill_depth_stencil_formats(_EGLDisplay *dpy,
367 enum pipe_format formats[8])
368 {
369 struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
370 struct pipe_screen *screen = gdpy->native->screen;
371 const EGLint candidates[] = {
372 1, PIPE_FORMAT_Z16_UNORM,
373 1, PIPE_FORMAT_Z32_UNORM,
374 2, PIPE_FORMAT_Z24_UNORM_S8_USCALED, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
375 2, PIPE_FORMAT_Z24X8_UNORM, PIPE_FORMAT_X8Z24_UNORM,
376 0
377 };
378 const EGLint *fmt = candidates;
379 EGLint count;
380
381 count = 0;
382 formats[count++] = PIPE_FORMAT_NONE;
383
384 while (*fmt) {
385 EGLint i, n = *fmt++;
386
387 /* pick the first supported format */
388 for (i = 0; i < n; i++) {
389 if (screen->is_format_supported(screen, fmt[i],
390 PIPE_TEXTURE_2D, 0, PIPE_BIND_DEPTH_STENCIL)) {
391 formats[count++] = fmt[i];
392 break;
393 }
394 }
395
396 fmt += n;
397 }
398
399 return count;
400 }
401
402 /**
403 * Add configs to display and return the next config ID.
404 */
405 static EGLint
406 egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint id)
407 {
408 struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
409 const struct native_config **native_configs;
410 enum pipe_format depth_stencil_formats[8];
411 int num_formats, num_configs, i, j;
412 int preserve_buffer, max_swap_interval;
413
414 native_configs = gdpy->native->get_configs(gdpy->native, &num_configs);
415 if (!num_configs) {
416 if (native_configs)
417 FREE(native_configs);
418 return id;
419 }
420
421 preserve_buffer =
422 gdpy->native->get_param(gdpy->native, NATIVE_PARAM_PRESERVE_BUFFER);
423 max_swap_interval =
424 gdpy->native->get_param(gdpy->native, NATIVE_PARAM_MAX_SWAP_INTERVAL);
425
426 num_formats = egl_g3d_fill_depth_stencil_formats(dpy,
427 depth_stencil_formats);
428
429 for (i = 0; i < num_configs; i++) {
430 for (j = 0; j < num_formats; j++) {
431 struct egl_g3d_config *gconf;
432
433 gconf = CALLOC_STRUCT(egl_g3d_config);
434 if (gconf) {
435 _eglInitConfig(&gconf->base, dpy, id);
436 if (!egl_g3d_init_config(drv, dpy, &gconf->base,
437 native_configs[i], depth_stencil_formats[j],
438 preserve_buffer, max_swap_interval)) {
439 FREE(gconf);
440 break;
441 }
442
443 _eglLinkConfig(&gconf->base);
444 id++;
445 }
446 }
447 }
448
449 FREE(native_configs);
450 return id;
451 }
452
453 static void
454 egl_g3d_free_config(void *conf)
455 {
456 struct egl_g3d_config *gconf = egl_g3d_config((_EGLConfig *) conf);
457 FREE(gconf);
458 }
459
460 static void
461 egl_g3d_free_screen(void *scr)
462 {
463 #ifdef EGL_MESA_screen_surface
464 struct egl_g3d_screen *gscr = egl_g3d_screen((_EGLScreen *) scr);
465 FREE(gscr->native_modes);
466 FREE(gscr);
467 #endif
468 }
469
470 static EGLBoolean
471 egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy)
472 {
473 struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
474
475 _eglReleaseDisplayResources(drv, dpy);
476
477 if (dpy->Configs) {
478 _eglDestroyArray(dpy->Configs, egl_g3d_free_config);
479 dpy->Configs = NULL;
480 }
481 if (dpy->Screens) {
482 _eglDestroyArray(dpy->Screens, egl_g3d_free_screen);
483 dpy->Screens = NULL;
484 }
485
486 _eglCleanupDisplay(dpy);
487
488 if (gdpy->smapi)
489 egl_g3d_destroy_st_manager(gdpy->smapi);
490
491 if (gdpy->native)
492 gdpy->native->destroy(gdpy->native);
493
494 FREE(gdpy);
495 dpy->DriverData = NULL;
496
497 return EGL_TRUE;
498 }
499
500 static EGLBoolean
501 egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy)
502 {
503 struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
504 struct egl_g3d_display *gdpy;
505 const struct native_platform *nplat;
506
507 nplat = egl_g3d_get_platform(drv, dpy->Platform);
508 if (!nplat)
509 return EGL_FALSE;
510
511 if (dpy->Options.TestOnly)
512 return EGL_TRUE;
513
514 gdpy = CALLOC_STRUCT(egl_g3d_display);
515 if (!gdpy) {
516 _eglError(EGL_BAD_ALLOC, "eglInitialize");
517 goto fail;
518 }
519 gdpy->loader = gdrv->loader;
520 dpy->DriverData = gdpy;
521
522 _eglLog(_EGL_INFO, "use %s for display %p",
523 nplat->name, dpy->PlatformDisplay);
524 gdpy->native =
525 nplat->create_display(dpy->PlatformDisplay, dpy->Options.UseFallback);
526 if (!gdpy->native) {
527 _eglError(EGL_NOT_INITIALIZED, "eglInitialize(no usable display)");
528 goto fail;
529 }
530 gdpy->native->user_data = (void *) dpy;
531 if (!gdpy->native->init_screen(gdpy->native)) {
532 _eglError(EGL_NOT_INITIALIZED,
533 "eglInitialize(failed to initialize screen)");
534 goto fail;
535 }
536
537 if (gdpy->loader->profile_masks[ST_API_OPENGL] & ST_PROFILE_DEFAULT_MASK)
538 dpy->ClientAPIs |= EGL_OPENGL_BIT;
539 if (gdpy->loader->profile_masks[ST_API_OPENGL] & ST_PROFILE_OPENGL_ES1_MASK)
540 dpy->ClientAPIs |= EGL_OPENGL_ES_BIT;
541 if (gdpy->loader->profile_masks[ST_API_OPENGL] & ST_PROFILE_OPENGL_ES2_MASK)
542 dpy->ClientAPIs |= EGL_OPENGL_ES2_BIT;
543 if (gdpy->loader->profile_masks[ST_API_OPENVG] & ST_PROFILE_DEFAULT_MASK)
544 dpy->ClientAPIs |= EGL_OPENVG_BIT;
545
546 gdpy->smapi = egl_g3d_create_st_manager(dpy);
547 if (!gdpy->smapi) {
548 _eglError(EGL_NOT_INITIALIZED,
549 "eglInitialize(failed to create st manager)");
550 goto fail;
551 }
552
553 #ifdef EGL_MESA_screen_surface
554 /* enable MESA_screen_surface before adding (and validating) configs */
555 if (gdpy->native->modeset) {
556 dpy->Extensions.MESA_screen_surface = EGL_TRUE;
557 egl_g3d_add_screens(drv, dpy);
558 }
559 #endif
560
561 dpy->Extensions.KHR_image_base = EGL_TRUE;
562 if (gdpy->native->get_param(gdpy->native, NATIVE_PARAM_USE_NATIVE_BUFFER))
563 dpy->Extensions.KHR_image_pixmap = EGL_TRUE;
564
565 dpy->Extensions.KHR_reusable_sync = EGL_TRUE;
566 dpy->Extensions.KHR_fence_sync = EGL_TRUE;
567
568 dpy->Extensions.KHR_surfaceless_gles1 = EGL_TRUE;
569 dpy->Extensions.KHR_surfaceless_gles2 = EGL_TRUE;
570 dpy->Extensions.KHR_surfaceless_opengl = EGL_TRUE;
571
572 if (dpy->Platform == _EGL_PLATFORM_DRM) {
573 dpy->Extensions.MESA_drm_display = EGL_TRUE;
574 if (gdpy->native->buffer)
575 dpy->Extensions.MESA_drm_image = EGL_TRUE;
576 }
577
578 if (dpy->Platform == _EGL_PLATFORM_WAYLAND && gdpy->native->buffer)
579 dpy->Extensions.MESA_drm_image = EGL_TRUE;
580
581 #ifdef EGL_ANDROID_image_native_buffer
582 if (dpy->Platform == _EGL_PLATFORM_ANDROID && gdpy->native->buffer)
583 dpy->Extensions.ANDROID_image_native_buffer = EGL_TRUE;
584 #endif
585
586 #ifdef EGL_WL_bind_wayland_display
587 if (gdpy->native->wayland_bufmgr)
588 dpy->Extensions.WL_bind_wayland_display = EGL_TRUE;
589 #endif
590
591 if (egl_g3d_add_configs(drv, dpy, 1) == 1) {
592 _eglError(EGL_NOT_INITIALIZED, "eglInitialize(unable to add configs)");
593 goto fail;
594 }
595
596 dpy->VersionMajor = 1;
597 dpy->VersionMinor = 4;
598
599 return EGL_TRUE;
600
601 fail:
602 if (gdpy)
603 egl_g3d_terminate(drv, dpy);
604 return EGL_FALSE;
605 }
606
607 static _EGLProc
608 egl_g3d_get_proc_address(_EGLDriver *drv, const char *procname)
609 {
610 struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
611 struct st_api *stapi = NULL;
612
613 if (procname && procname[0] == 'v' && procname[1] == 'g')
614 stapi = gdrv->loader->get_st_api(ST_API_OPENVG);
615 else if (procname && procname[0] == 'g' && procname[1] == 'l')
616 stapi = gdrv->loader->get_st_api(ST_API_OPENGL);
617
618 return (_EGLProc) ((stapi) ?
619 stapi->get_proc_address(stapi, procname) : NULL);
620 }
621
622 _EGLDriver *
623 egl_g3d_create_driver(const struct egl_g3d_loader *loader)
624 {
625 struct egl_g3d_driver *gdrv;
626
627 gdrv = CALLOC_STRUCT(egl_g3d_driver);
628 if (!gdrv)
629 return NULL;
630
631 gdrv->loader = loader;
632
633 egl_g3d_init_driver_api(&gdrv->base);
634 gdrv->base.API.Initialize = egl_g3d_initialize;
635 gdrv->base.API.Terminate = egl_g3d_terminate;
636 gdrv->base.API.GetProcAddress = egl_g3d_get_proc_address;
637
638 /* to be filled by the caller */
639 gdrv->base.Name = NULL;
640 gdrv->base.Unload = NULL;
641
642 return &gdrv->base;
643 }
644
645 void
646 egl_g3d_destroy_driver(_EGLDriver *drv)
647 {
648 struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
649 FREE(gdrv);
650 }