st/egl: Use xlib_sw_winsys in ximage 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
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #include <assert.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include "pipe/p_screen.h"
29 #include "util/u_memory.h"
30 #include "util/u_rect.h"
31 #include "util/u_inlines.h"
32 #include "egldriver.h"
33 #include "eglcurrent.h"
34 #include "eglconfigutil.h"
35 #include "egllog.h"
36
37 #include "native.h"
38 #include "egl_g3d.h"
39 #include "egl_st.h"
40
41 /**
42 * Validate the draw/read surfaces of the context.
43 */
44 static void
45 egl_g3d_validate_context(_EGLDisplay *dpy, _EGLContext *ctx)
46 {
47 struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
48 struct pipe_screen *screen = gdpy->native->screen;
49 struct egl_g3d_context *gctx = egl_g3d_context(ctx);
50 const uint st_att_map[NUM_NATIVE_ATTACHMENTS] = {
51 ST_SURFACE_FRONT_LEFT,
52 ST_SURFACE_BACK_LEFT,
53 ST_SURFACE_FRONT_RIGHT,
54 ST_SURFACE_BACK_RIGHT,
55 };
56 EGLint num_surfaces, s;
57
58 /* validate draw and/or read buffers */
59 num_surfaces = (gctx->base.ReadSurface == gctx->base.DrawSurface) ? 1 : 2;
60 for (s = 0; s < num_surfaces; s++) {
61 struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
62 struct egl_g3d_surface *gsurf;
63 struct egl_g3d_buffer *gbuf;
64 EGLint att;
65
66 if (s == 0) {
67 gsurf = egl_g3d_surface(gctx->base.DrawSurface);
68 gbuf = &gctx->draw;
69 }
70 else {
71 gsurf = egl_g3d_surface(gctx->base.ReadSurface);
72 gbuf = &gctx->read;
73 }
74
75 if (!gctx->force_validate) {
76 unsigned int seq_num;
77
78 gsurf->native->validate(gsurf->native, gbuf->attachment_mask,
79 &seq_num, NULL, NULL, NULL);
80 /* skip validation */
81 if (gsurf->sequence_number == seq_num)
82 continue;
83 }
84
85 pipe_surface_reference(&gsurf->render_surface, NULL);
86 memset(textures, 0, sizeof(textures));
87
88 gsurf->native->validate(gsurf->native, gbuf->attachment_mask,
89 &gsurf->sequence_number, textures,
90 &gsurf->base.Width, &gsurf->base.Height);
91 for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
92 struct pipe_texture *pt = textures[att];
93 struct pipe_surface *ps;
94
95 if (native_attachment_mask_test(gbuf->attachment_mask, att) && pt) {
96 ps = screen->get_tex_surface(screen, pt, 0, 0, 0,
97 PIPE_BUFFER_USAGE_GPU_READ |
98 PIPE_BUFFER_USAGE_GPU_WRITE);
99 gctx->stapi->st_set_framebuffer_surface(gbuf->st_fb,
100 st_att_map[att], ps);
101
102 if (gsurf->render_att == att)
103 pipe_surface_reference(&gsurf->render_surface, ps);
104
105 pipe_surface_reference(&ps, NULL);
106 pipe_texture_reference(&pt, NULL);
107 }
108 }
109
110 gctx->stapi->st_resize_framebuffer(gbuf->st_fb,
111 gsurf->base.Width, gsurf->base.Height);
112 }
113
114 gctx->force_validate = EGL_FALSE;
115
116 }
117
118 /**
119 * Create a st_framebuffer.
120 */
121 static struct st_framebuffer *
122 create_framebuffer(_EGLContext *ctx, _EGLSurface *surf)
123 {
124 struct egl_g3d_context *gctx = egl_g3d_context(ctx);
125 struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
126 struct egl_g3d_config *gconf = egl_g3d_config(gsurf->base.Config);
127
128 return gctx->stapi->st_create_framebuffer(&gconf->native->mode,
129 gconf->native->color_format, gconf->native->depth_format,
130 gconf->native->stencil_format,
131 gsurf->base.Width, gsurf->base.Height, &gsurf->base);
132 }
133
134 /**
135 * Update the attachments of draw/read surfaces.
136 */
137 static void
138 egl_g3d_route_context(_EGLDisplay *dpy, _EGLContext *ctx)
139 {
140 struct egl_g3d_context *gctx = egl_g3d_context(ctx);
141 EGLint s;
142
143 /* route draw and read buffers' attachments */
144 for (s = 0; s < 2; s++) {
145 struct egl_g3d_surface *gsurf;
146 struct egl_g3d_buffer *gbuf;
147
148 if (s == 0) {
149 gsurf = egl_g3d_surface(gctx->base.DrawSurface);
150 gbuf = &gctx->draw;
151 }
152 else {
153 gsurf = egl_g3d_surface(gctx->base.ReadSurface);
154 gbuf = &gctx->read;
155 }
156
157 gbuf->attachment_mask = (1 << gsurf->render_att);
158
159 /* FIXME OpenGL defaults to draw the front or back buffer when the
160 * context is single-buffered or double-buffered respectively. In EGL,
161 * however, the buffer to be drawn is determined by the surface, instead
162 * of the context. As a result, rendering to a pixmap surface with a
163 * double-buffered context does not work as expected.
164 *
165 * gctx->stapi->st_draw_front_buffer(gctx->st_ctx, natt ==
166 * NATIVE_ATTACHMENT_FRONT_LEFT);
167 */
168
169 /*
170 * FIXME If the back buffer is asked for here, and the front buffer is
171 * later needed by the client API (e.g. glDrawBuffer is called to draw
172 * the front buffer), it will create a new pipe texture and draw there.
173 * One fix is to ask for both buffers here, but it would be a waste if
174 * the front buffer is never used. A better fix is to add a callback to
175 * the pipe screen with context private (just like flush_frontbuffer).
176 */
177 }
178 }
179
180 /**
181 * Reallocate the context's framebuffers after draw/read surfaces change.
182 */
183 static EGLBoolean
184 egl_g3d_realloc_context(_EGLDisplay *dpy, _EGLContext *ctx)
185 {
186 struct egl_g3d_context *gctx = egl_g3d_context(ctx);
187 struct egl_g3d_surface *gdraw = egl_g3d_surface(gctx->base.DrawSurface);
188 struct egl_g3d_surface *gread = egl_g3d_surface(gctx->base.ReadSurface);
189
190 /* unreference the old framebuffers */
191 if (gctx->draw.st_fb) {
192 EGLBoolean is_equal = (gctx->draw.st_fb == gctx->read.st_fb);
193 void *priv;
194
195 priv = gctx->stapi->st_framebuffer_private(gctx->draw.st_fb);
196 if (!gdraw || priv != (void *) &gdraw->base) {
197 gctx->stapi->st_unreference_framebuffer(gctx->draw.st_fb);
198 gctx->draw.st_fb = NULL;
199 gctx->draw.attachment_mask = 0x0;
200 }
201
202 if (is_equal) {
203 gctx->read.st_fb = NULL;
204 gctx->draw.attachment_mask = 0x0;
205 }
206 else {
207 priv = gctx->stapi->st_framebuffer_private(gctx->read.st_fb);
208 if (!gread || priv != (void *) &gread->base) {
209 gctx->stapi->st_unreference_framebuffer(gctx->read.st_fb);
210 gctx->read.st_fb = NULL;
211 gctx->draw.attachment_mask = 0x0;
212 }
213 }
214 }
215
216 if (!gdraw)
217 return EGL_TRUE;
218
219 /* create the draw fb */
220 if (!gctx->draw.st_fb) {
221 gctx->draw.st_fb = create_framebuffer(&gctx->base, &gdraw->base);
222 if (!gctx->draw.st_fb)
223 return EGL_FALSE;
224 }
225
226 /* create the read fb */
227 if (!gctx->read.st_fb) {
228 if (gread != gdraw) {
229 gctx->read.st_fb = create_framebuffer(&gctx->base, &gread->base);
230 if (!gctx->read.st_fb) {
231 gctx->stapi->st_unreference_framebuffer(gctx->draw.st_fb);
232 gctx->draw.st_fb = NULL;
233 return EGL_FALSE;
234 }
235 }
236 else {
237 /* there is no st_reference_framebuffer... */
238 gctx->read.st_fb = gctx->draw.st_fb;
239 }
240 }
241
242 egl_g3d_route_context(dpy, &gctx->base);
243 gctx->force_validate = EGL_TRUE;
244
245 return EGL_TRUE;
246 }
247
248 /**
249 * Return the state tracker for the given context.
250 */
251 static const struct egl_g3d_st *
252 egl_g3d_choose_st(_EGLDriver *drv, _EGLContext *ctx)
253 {
254 struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
255 const struct egl_g3d_st *stapi;
256 EGLint idx = -1;
257
258 switch (ctx->ClientAPI) {
259 case EGL_OPENGL_ES_API:
260 switch (ctx->ClientVersion) {
261 case 1:
262 idx = EGL_G3D_ST_OPENGL_ES;
263 break;
264 case 2:
265 idx = EGL_G3D_ST_OPENGL_ES2;
266 break;
267 default:
268 _eglLog(_EGL_WARNING, "unknown client version %d",
269 ctx->ClientVersion);
270 break;
271 }
272 break;
273 case EGL_OPENVG_API:
274 idx = EGL_G3D_ST_OPENVG;
275 break;
276 case EGL_OPENGL_API:
277 idx = EGL_G3D_ST_OPENGL;
278 break;
279 default:
280 _eglLog(_EGL_WARNING, "unknown client API 0x%04x", ctx->ClientAPI);
281 break;
282 }
283
284 stapi = (idx >= 0) ? gdrv->stapis[idx] : NULL;
285 return stapi;
286 }
287
288 /**
289 * Initialize the state trackers.
290 */
291 static void
292 egl_g3d_init_st(_EGLDriver *drv)
293 {
294 struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
295 EGLint i;
296
297 /* already initialized */
298 if (gdrv->api_mask)
299 return;
300
301 for (i = 0; i < NUM_EGL_G3D_STS; i++) {
302 gdrv->stapis[i] = egl_g3d_get_st(i);
303 if (gdrv->stapis[i])
304 gdrv->api_mask |= gdrv->stapis[i]->api_bit;
305 }
306
307 if (gdrv->api_mask)
308 _eglLog(_EGL_DEBUG, "Driver API mask: 0x%x", gdrv->api_mask);
309 else
310 _eglLog(_EGL_WARNING, "No supported client API");
311 }
312
313 /**
314 * Get the probe object of the display.
315 *
316 * Note that this function may be called before the display is initialized.
317 */
318 static struct native_probe *
319 egl_g3d_get_probe(_EGLDriver *drv, _EGLDisplay *dpy)
320 {
321 struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
322 struct native_probe *nprobe;
323
324 nprobe = (struct native_probe *) _eglGetProbeCache(gdrv->probe_key);
325 if (!nprobe || nprobe->display != dpy->NativeDisplay) {
326 if (nprobe)
327 nprobe->destroy(nprobe);
328 nprobe = native_create_probe(dpy->NativeDisplay);
329 _eglSetProbeCache(gdrv->probe_key, (void *) nprobe);
330 }
331
332 return nprobe;
333 }
334
335 /**
336 * Destroy the probe object of the display. The display may be NULL.
337 *
338 * Note that this function may be called before the display is initialized.
339 */
340 static void
341 egl_g3d_destroy_probe(_EGLDriver *drv, _EGLDisplay *dpy)
342 {
343 struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
344 struct native_probe *nprobe;
345
346 nprobe = (struct native_probe *) _eglGetProbeCache(gdrv->probe_key);
347 if (nprobe && (!dpy || nprobe->display == dpy->NativeDisplay)) {
348 nprobe->destroy(nprobe);
349 _eglSetProbeCache(gdrv->probe_key, NULL);
350 }
351 }
352
353 /**
354 * Return an API mask that consists of the state trackers that supports the
355 * given mode.
356 *
357 * FIXME add st_is_mode_supported()?
358 */
359 static EGLint
360 get_mode_api_mask(const __GLcontextModes *mode, EGLint api_mask)
361 {
362 EGLint check;
363
364 /* OpenGL ES 1.x and 2.x are checked together */
365 check = EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT;
366 if (api_mask & check) {
367 /* this is required by EGL, not by OpenGL ES */
368 if (mode->drawableType & GLX_WINDOW_BIT && !mode->doubleBufferMode)
369 api_mask &= ~check;
370 }
371
372 check = EGL_OPENVG_BIT;
373 if (api_mask & check) {
374 /* vega st needs the depth/stencil rb */
375 if (!mode->depthBits && !mode->stencilBits)
376 api_mask &= ~check;
377 }
378
379 return api_mask;
380 }
381
382 #ifdef EGL_MESA_screen_surface
383
384 static void
385 egl_g3d_add_screens(_EGLDriver *drv, _EGLDisplay *dpy)
386 {
387 struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
388 const struct native_connector **native_connectors;
389 EGLint num_connectors, i;
390
391 native_connectors =
392 gdpy->native->modeset->get_connectors(gdpy->native, &num_connectors, NULL);
393 if (!num_connectors) {
394 if (native_connectors)
395 free(native_connectors);
396 return;
397 }
398
399 for (i = 0; i < num_connectors; i++) {
400 const struct native_connector *nconn = native_connectors[i];
401 struct egl_g3d_screen *gscr;
402 const struct native_mode **native_modes;
403 EGLint num_modes, j;
404
405 /* TODO support for hotplug */
406 native_modes =
407 gdpy->native->modeset->get_modes(gdpy->native, nconn, &num_modes);
408 if (!num_modes) {
409 if (native_modes)
410 free(native_modes);
411 continue;
412 }
413
414 gscr = CALLOC_STRUCT(egl_g3d_screen);
415 if (!gscr) {
416 free(native_modes);
417 continue;
418 }
419
420 _eglInitScreen(&gscr->base);
421
422 for (j = 0; j < num_modes; j++) {
423 const struct native_mode *nmode = native_modes[j];
424 _EGLMode *mode;
425
426 mode = _eglAddNewMode(&gscr->base, nmode->width, nmode->height,
427 nmode->refresh_rate, nmode->desc);
428 if (!mode)
429 break;
430 /* gscr->native_modes and gscr->base.Modes should be consistent */
431 assert(mode == &gscr->base.Modes[j]);
432 }
433
434 gscr->native = nconn;
435 gscr->native_modes = native_modes;
436
437 _eglAddScreen(dpy, &gscr->base);
438 }
439
440 free(native_connectors);
441 }
442
443 #endif /* EGL_MESA_screen_surface */
444
445 /**
446 * Add configs to display and return the next config ID.
447 */
448 static EGLint
449 egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint id)
450 {
451 struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
452 struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
453 const struct native_config **native_configs;
454 int num_configs, i;
455
456 native_configs = gdpy->native->get_configs(gdpy->native,
457 &num_configs);
458 if (!num_configs) {
459 if (native_configs)
460 free(native_configs);
461 return id;
462 }
463
464 for (i = 0; i < num_configs; i++) {
465 EGLint api_mask;
466 struct egl_g3d_config *gconf;
467 EGLBoolean valid;
468
469 gconf = CALLOC_STRUCT(egl_g3d_config);
470 if (!gconf)
471 continue;
472
473 _eglInitConfig(&gconf->base, dpy, id);
474
475 api_mask = get_mode_api_mask(&native_configs[i]->mode, gdrv->api_mask);
476 if (!api_mask) {
477 _eglLog(_EGL_DEBUG, "no state tracker supports config 0x%x",
478 native_configs[i]->mode.visualID);
479 }
480
481 valid = _eglConfigFromContextModesRec(&gconf->base,
482 &native_configs[i]->mode, api_mask, api_mask);
483 if (valid) {
484 #ifdef EGL_MESA_screen_surface
485 /* check if scanout surface bit is set */
486 if (native_configs[i]->scanout_bit) {
487 EGLint val = GET_CONFIG_ATTRIB(&gconf->base, EGL_SURFACE_TYPE);
488 val |= EGL_SCREEN_BIT_MESA;
489 SET_CONFIG_ATTRIB(&gconf->base, EGL_SURFACE_TYPE, val);
490 }
491 #endif
492 valid = _eglValidateConfig(&gconf->base, EGL_FALSE);
493 }
494 if (!valid) {
495 _eglLog(_EGL_DEBUG, "skip invalid config 0x%x",
496 native_configs[i]->mode.visualID);
497 free(gconf);
498 continue;
499 }
500
501 gconf->native = native_configs[i];
502 _eglAddConfig(dpy, &gconf->base);
503 id++;
504 }
505
506 free(native_configs);
507 return id;
508 }
509
510 /**
511 * Re-validate the context.
512 */
513 static void
514 egl_g3d_update_buffer(struct pipe_screen *screen, void *context_private)
515 {
516 struct egl_g3d_context *gctx = egl_g3d_context(context_private);
517 egl_g3d_validate_context(gctx->base.Resource.Display, &gctx->base);
518 }
519
520 static EGLBoolean
521 egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy)
522 {
523 struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
524 EGLint i;
525
526 _eglReleaseDisplayResources(drv, dpy);
527 _eglCleanupDisplay(dpy);
528
529 if (dpy->Screens) {
530 for (i = 0; i < dpy->NumScreens; i++) {
531 struct egl_g3d_screen *gscr = egl_g3d_screen(dpy->Screens[i]);
532 free(gscr->native_modes);
533 free(gscr);
534 }
535 free(dpy->Screens);
536 }
537
538 if (gdpy->native)
539 gdpy->native->destroy(gdpy->native);
540
541 free(gdpy);
542 dpy->DriverData = NULL;
543
544 return EGL_TRUE;
545 }
546
547 static EGLBoolean
548 egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy,
549 EGLint *major, EGLint *minor)
550 {
551 struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
552 struct egl_g3d_display *gdpy;
553
554 /* the probe object is unlikely to be needed again */
555 egl_g3d_destroy_probe(drv, dpy);
556
557 gdpy = CALLOC_STRUCT(egl_g3d_display);
558 if (!gdpy) {
559 _eglError(EGL_BAD_ALLOC, "eglInitialize");
560 goto fail;
561 }
562 dpy->DriverData = gdpy;
563
564 gdpy->native = native_create_display(dpy->NativeDisplay);
565 if (!gdpy->native) {
566 _eglError(EGL_NOT_INITIALIZED, "eglInitialize(no usable display)");
567 goto fail;
568 }
569
570 gdpy->native->screen->update_buffer = egl_g3d_update_buffer;
571
572 egl_g3d_init_st(&gdrv->base);
573 dpy->ClientAPIsMask = gdrv->api_mask;
574
575 #ifdef EGL_MESA_screen_surface
576 /* enable MESA_screen_surface before adding (and validating) configs */
577 if (gdpy->native->modeset) {
578 dpy->Extensions.MESA_screen_surface = EGL_TRUE;
579 egl_g3d_add_screens(drv, dpy);
580 }
581 #endif
582
583 if (egl_g3d_add_configs(drv, dpy, 1) == 1) {
584 _eglError(EGL_NOT_INITIALIZED, "eglInitialize(unable to add configs)");
585 goto fail;
586 }
587
588 *major = 1;
589 *minor = 4;
590
591 return EGL_TRUE;
592
593 fail:
594 if (gdpy)
595 egl_g3d_terminate(drv, dpy);
596 return EGL_FALSE;
597 }
598
599 static _EGLContext *
600 egl_g3d_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
601 _EGLContext *share, const EGLint *attribs)
602 {
603 struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
604 struct egl_g3d_context *gshare = egl_g3d_context(share);
605 struct egl_g3d_config *gconf = egl_g3d_config(conf);
606 struct egl_g3d_context *gctx;
607 const __GLcontextModes *mode;
608
609 gctx = CALLOC_STRUCT(egl_g3d_context);
610 if (!gctx) {
611 _eglError(EGL_BAD_ALLOC, "eglCreateContext");
612 return NULL;
613 }
614
615 if (!_eglInitContext(&gctx->base, dpy, conf, attribs)) {
616 free(gctx);
617 return NULL;
618 }
619
620 gctx->stapi = egl_g3d_choose_st(drv, &gctx->base);
621 if (!gctx->stapi) {
622 free(gctx);
623 return NULL;
624 }
625
626 mode = &gconf->native->mode;
627
628 gctx->pipe = gdpy->native->screen->context_create(
629 gdpy->native->screen,
630 (void *) &gctx->base);
631
632 if (!gctx->pipe) {
633 free(gctx);
634 return NULL;
635 }
636
637 gctx->st_ctx = gctx->stapi->st_create_context(gctx->pipe, mode,
638 (gshare) ? gshare->st_ctx : NULL);
639 if (!gctx->st_ctx) {
640 gctx->pipe->destroy(gctx->pipe);
641 free(gctx);
642 return NULL;
643 }
644
645 return &gctx->base;
646 }
647
648 /**
649 * Destroy a context.
650 */
651 static void
652 destroy_context(_EGLDisplay *dpy, _EGLContext *ctx)
653 {
654 struct egl_g3d_context *gctx = egl_g3d_context(ctx);
655
656 /* FIXME a context might live longer than its display */
657 if (!dpy->Initialized)
658 _eglLog(_EGL_FATAL, "destroy a context with an unitialized display");
659
660 egl_g3d_realloc_context(dpy, &gctx->base);
661 /* it will destroy the associated pipe context */
662 gctx->stapi->st_destroy_context(gctx->st_ctx);
663
664 free(gctx);
665 }
666
667 static EGLBoolean
668 egl_g3d_destroy_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx)
669 {
670 if (!_eglIsContextBound(ctx))
671 destroy_context(dpy, ctx);
672 return EGL_TRUE;
673 }
674
675 struct egl_g3d_create_surface_arg {
676 EGLint type;
677 union {
678 EGLNativeWindowType win;
679 EGLNativePixmapType pix;
680 } u;
681 };
682
683 static _EGLSurface *
684 egl_g3d_create_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
685 struct egl_g3d_create_surface_arg *arg,
686 const EGLint *attribs)
687 {
688 struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
689 struct egl_g3d_config *gconf = egl_g3d_config(conf);
690 struct egl_g3d_surface *gsurf;
691 struct native_surface *nsurf;
692 const char *err;
693
694 switch (arg->type) {
695 case EGL_WINDOW_BIT:
696 err = "eglCreateWindowSurface";
697 break;
698 case EGL_PIXMAP_BIT:
699 err = "eglCreatePixmapSurface";
700 break;
701 case EGL_PBUFFER_BIT:
702 err = "eglCreatePBufferSurface";
703 break;
704 #ifdef EGL_MESA_screen_surface
705 case EGL_SCREEN_BIT_MESA:
706 err = "eglCreateScreenSurface";
707 break;
708 #endif
709 default:
710 err = "eglCreateUnknownSurface";
711 break;
712 }
713
714 gsurf = CALLOC_STRUCT(egl_g3d_surface);
715 if (!gsurf) {
716 _eglError(EGL_BAD_ALLOC, err);
717 return NULL;
718 }
719
720 if (!_eglInitSurface(&gsurf->base, dpy, arg->type, conf, attribs)) {
721 free(gsurf);
722 return NULL;
723 }
724
725 /* create the native surface */
726 switch (arg->type) {
727 case EGL_WINDOW_BIT:
728 nsurf = gdpy->native->create_window_surface(gdpy->native,
729 arg->u.win, gconf->native);
730 break;
731 case EGL_PIXMAP_BIT:
732 nsurf = gdpy->native->create_pixmap_surface(gdpy->native,
733 arg->u.pix, gconf->native);
734 break;
735 case EGL_PBUFFER_BIT:
736 nsurf = gdpy->native->create_pbuffer_surface(gdpy->native,
737 gconf->native, gsurf->base.Width, gsurf->base.Height);
738 break;
739 #ifdef EGL_MESA_screen_surface
740 case EGL_SCREEN_BIT_MESA:
741 /* prefer back buffer (move to _eglInitSurface?) */
742 gsurf->base.RenderBuffer = EGL_BACK_BUFFER;
743 nsurf = gdpy->native->modeset->create_scanout_surface(gdpy->native,
744 gconf->native, gsurf->base.Width, gsurf->base.Height);
745 break;
746 #endif
747 default:
748 nsurf = NULL;
749 break;
750 }
751
752 if (!nsurf) {
753 free(gsurf);
754 return NULL;
755 }
756 /* initialize the geometry */
757 if (!nsurf->validate(nsurf, 0x0, &gsurf->sequence_number, NULL,
758 &gsurf->base.Width, &gsurf->base.Height)) {
759 nsurf->destroy(nsurf);
760 free(gsurf);
761 return NULL;
762 }
763
764 gsurf->native = nsurf;
765
766 gsurf->render_att = (gsurf->base.RenderBuffer == EGL_SINGLE_BUFFER) ?
767 NATIVE_ATTACHMENT_FRONT_LEFT : NATIVE_ATTACHMENT_BACK_LEFT;
768 if (!gconf->native->mode.doubleBufferMode)
769 gsurf->render_att = NATIVE_ATTACHMENT_FRONT_LEFT;
770
771 return &gsurf->base;
772 }
773
774 static _EGLSurface *
775 egl_g3d_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy,
776 _EGLConfig *conf, EGLNativeWindowType win,
777 const EGLint *attribs)
778 {
779 struct egl_g3d_create_surface_arg arg;
780
781 memset(&arg, 0, sizeof(arg));
782 arg.type = EGL_WINDOW_BIT;
783 arg.u.win = win;
784
785 return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs);
786 }
787
788 static _EGLSurface *
789 egl_g3d_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy,
790 _EGLConfig *conf, EGLNativePixmapType pix,
791 const EGLint *attribs)
792 {
793 struct egl_g3d_create_surface_arg arg;
794
795 memset(&arg, 0, sizeof(arg));
796 arg.type = EGL_PIXMAP_BIT;
797 arg.u.pix = pix;
798
799 return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs);
800 }
801
802 static _EGLSurface *
803 egl_g3d_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy,
804 _EGLConfig *conf, const EGLint *attribs)
805 {
806 struct egl_g3d_create_surface_arg arg;
807
808 memset(&arg, 0, sizeof(arg));
809 arg.type = EGL_PBUFFER_BIT;
810
811 return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs);
812 }
813
814 /**
815 * Destroy a surface.
816 */
817 static void
818 destroy_surface(_EGLDisplay *dpy, _EGLSurface *surf)
819 {
820 struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
821
822 /* FIXME a surface might live longer than its display */
823 if (!dpy->Initialized)
824 _eglLog(_EGL_FATAL, "destroy a surface with an unitialized display");
825
826 pipe_surface_reference(&gsurf->render_surface, NULL);
827 gsurf->native->destroy(gsurf->native);
828 free(gsurf);
829 }
830
831 static EGLBoolean
832 egl_g3d_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
833 {
834 if (!_eglIsSurfaceBound(surf))
835 destroy_surface(dpy, surf);
836 return EGL_TRUE;
837 }
838
839 static EGLBoolean
840 egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy,
841 _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx)
842 {
843 struct egl_g3d_context *gctx = egl_g3d_context(ctx);
844 struct egl_g3d_surface *gdraw = egl_g3d_surface(draw);
845 struct egl_g3d_context *old_gctx;
846 EGLBoolean ok = EGL_TRUE;
847
848 /* bind the new context and return the "orphaned" one */
849 if (!_eglBindContext(&ctx, &draw, &read))
850 return EGL_FALSE;
851 old_gctx = egl_g3d_context(ctx);
852
853 if (old_gctx) {
854 /* flush old context */
855 old_gctx->stapi->st_flush(old_gctx->st_ctx,
856 PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
857
858 /*
859 * The old context is no longer current, and egl_g3d_realloc_context()
860 * should be called to destroy the framebuffers. However, it is possible
861 * that it will be made current again with the same draw/read surfaces.
862 * It might be better to keep it around.
863 */
864 }
865
866 if (gctx) {
867 ok = egl_g3d_realloc_context(dpy, &gctx->base);
868 if (ok) {
869 ok = gctx->stapi->st_make_current(gctx->st_ctx,
870 gctx->draw.st_fb, gctx->read.st_fb);
871 if (ok) {
872 egl_g3d_validate_context(dpy, &gctx->base);
873 if (gdraw->base.Type == EGL_WINDOW_BIT) {
874 gctx->base.WindowRenderBuffer =
875 (gdraw->render_att == NATIVE_ATTACHMENT_FRONT_LEFT) ?
876 EGL_SINGLE_BUFFER : EGL_BACK_BUFFER;
877 }
878 }
879 }
880 }
881 else if (old_gctx) {
882 ok = old_gctx->stapi->st_make_current(NULL, NULL, NULL);
883 old_gctx->base.WindowRenderBuffer = EGL_NONE;
884 }
885
886 if (ctx && !_eglIsContextLinked(ctx))
887 destroy_context(dpy, ctx);
888 if (draw && !_eglIsSurfaceLinked(draw))
889 destroy_surface(dpy, draw);
890 if (read && read != draw && !_eglIsSurfaceLinked(read))
891 destroy_surface(dpy, read);
892
893 return ok;
894 }
895
896 static EGLBoolean
897 egl_g3d_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
898 {
899 struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
900 _EGLContext *ctx = _eglGetCurrentContext();
901 struct egl_g3d_context *gctx = NULL;
902
903 /* no-op for pixmap or pbuffer surface */
904 if (gsurf->base.Type == EGL_PIXMAP_BIT ||
905 gsurf->base.Type == EGL_PBUFFER_BIT)
906 return EGL_TRUE;
907
908 /* or when the surface is single-buffered */
909 if (gsurf->render_att == NATIVE_ATTACHMENT_FRONT_LEFT)
910 return EGL_TRUE;
911
912 if (ctx && ctx->DrawSurface == surf)
913 gctx = egl_g3d_context(ctx);
914
915 /* flush if the surface is current */
916 if (gctx)
917 gctx->stapi->st_notify_swapbuffers(gctx->draw.st_fb);
918
919 return gsurf->native->swap_buffers(gsurf->native);
920 }
921
922 /**
923 * Find a config that supports the pixmap.
924 */
925 static _EGLConfig *
926 find_pixmap_config(_EGLDisplay *dpy, EGLNativePixmapType pix)
927 {
928 struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
929 struct egl_g3d_config *gconf;
930 EGLint i;
931
932 for (i = 0; i < dpy->NumConfigs; i++) {
933 gconf = egl_g3d_config(dpy->Configs[i]);
934 if (gdpy->native->is_pixmap_supported(gdpy->native, pix, gconf->native))
935 break;
936 }
937
938 return (i < dpy->NumConfigs) ? &gconf->base : NULL;
939 }
940
941 /**
942 * Get the pipe surface of the given attachment of the native surface.
943 */
944 static struct pipe_surface *
945 get_pipe_surface(struct native_display *ndpy, struct native_surface *nsurf,
946 enum native_attachment natt)
947 {
948 struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
949 struct pipe_surface *psurf;
950
951 textures[natt] = NULL;
952 nsurf->validate(nsurf, 1 << natt, NULL, textures, NULL, NULL);
953 if (!textures[natt])
954 return NULL;
955
956 psurf = ndpy->screen->get_tex_surface(ndpy->screen, textures[natt],
957 0, 0, 0, PIPE_BUFFER_USAGE_CPU_WRITE);
958 pipe_texture_reference(&textures[natt], NULL);
959
960 return psurf;
961 }
962
963 static EGLBoolean
964 egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
965 EGLNativePixmapType target)
966 {
967 struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
968 struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
969 _EGLContext *ctx = _eglGetCurrentContext();
970 struct egl_g3d_config *gconf;
971 struct native_surface *nsurf;
972 struct pipe_screen *screen = gdpy->native->screen;
973 struct pipe_surface *psurf;
974
975 if (!gsurf->render_surface)
976 return EGL_TRUE;
977
978 gconf = egl_g3d_config(find_pixmap_config(dpy, target));
979 if (!gconf)
980 return _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCopyBuffers");
981
982 nsurf = gdpy->native->create_pixmap_surface(gdpy->native,
983 target, gconf->native);
984 if (!nsurf)
985 return _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCopyBuffers");
986
987 /* flush if the surface is current */
988 if (ctx && ctx->DrawSurface == &gsurf->base) {
989 struct egl_g3d_context *gctx = egl_g3d_context(ctx);
990 gctx->stapi->st_flush(gctx->st_ctx,
991 PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
992 }
993
994 psurf = get_pipe_surface(gdpy->native, nsurf, NATIVE_ATTACHMENT_FRONT_LEFT);
995 if (psurf) {
996 struct pipe_context pipe;
997
998 /**
999 * XXX This is hacky. If we might allow the EGLDisplay to create a pipe
1000 * context of its own and use the blitter context for this.
1001 */
1002 memset(&pipe, 0, sizeof(pipe));
1003 pipe.screen = screen;
1004
1005 util_surface_copy(&pipe, FALSE, psurf, 0, 0,
1006 gsurf->render_surface, 0, 0, psurf->width, psurf->height);
1007
1008 pipe_surface_reference(&psurf, NULL);
1009 nsurf->flush_frontbuffer(nsurf);
1010 }
1011
1012 nsurf->destroy(nsurf);
1013
1014 return EGL_TRUE;
1015 }
1016
1017 static EGLBoolean
1018 egl_g3d_wait_client(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx)
1019 {
1020 struct egl_g3d_context *gctx = egl_g3d_context(ctx);
1021 gctx->stapi->st_finish(gctx->st_ctx);
1022 return EGL_TRUE;
1023 }
1024
1025 static EGLBoolean
1026 egl_g3d_wait_native(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine)
1027 {
1028 _EGLContext *ctx = _eglGetCurrentContext();
1029
1030 if (engine != EGL_CORE_NATIVE_ENGINE)
1031 return _eglError(EGL_BAD_PARAMETER, "eglWaitNative");
1032
1033 if (ctx && ctx->DrawSurface) {
1034 struct egl_g3d_surface *gsurf = egl_g3d_surface(ctx->DrawSurface);
1035 gsurf->native->wait(gsurf->native);
1036 }
1037
1038 return EGL_TRUE;
1039 }
1040
1041 static _EGLProc
1042 egl_g3d_get_proc_address(_EGLDriver *drv, const char *procname)
1043 {
1044 struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
1045 _EGLProc proc;
1046 EGLint i;
1047
1048 /* in case this is called before a display is initialized */
1049 egl_g3d_init_st(&gdrv->base);
1050
1051 for (i = 0; i < NUM_EGL_G3D_STS; i++) {
1052 const struct egl_g3d_st *stapi = gdrv->stapis[i];
1053 if (stapi) {
1054 proc = (_EGLProc) stapi->st_get_proc_address(procname);
1055 if (proc)
1056 return proc;
1057 }
1058 }
1059
1060 return (_EGLProc) NULL;
1061 }
1062
1063 static EGLBoolean
1064 egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy,
1065 _EGLSurface *surf, EGLint buffer)
1066 {
1067 struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
1068 _EGLContext *es1 = _eglGetAPIContext(EGL_OPENGL_ES_API);
1069 struct egl_g3d_context *gctx;
1070 enum pipe_format target_format;
1071 int target;
1072
1073 if (!gsurf || gsurf->base.Type != EGL_PBUFFER_BIT)
1074 return _eglError(EGL_BAD_SURFACE, "eglBindTexImage");
1075 if (buffer != EGL_BACK_BUFFER)
1076 return _eglError(EGL_BAD_PARAMETER, "eglBindTexImage");
1077 if (gsurf->base.BoundToTexture)
1078 return _eglError(EGL_BAD_ACCESS, "eglBindTexImage");
1079
1080 switch (gsurf->base.TextureFormat) {
1081 case EGL_TEXTURE_RGB:
1082 target_format = PIPE_FORMAT_R8G8B8_UNORM;
1083 break;
1084 case EGL_TEXTURE_RGBA:
1085 target_format = PIPE_FORMAT_B8G8R8A8_UNORM;
1086 break;
1087 default:
1088 return _eglError(EGL_BAD_MATCH, "eglBindTexImage");
1089 }
1090
1091 switch (gsurf->base.TextureTarget) {
1092 case EGL_TEXTURE_2D:
1093 target = ST_TEXTURE_2D;
1094 break;
1095 default:
1096 return _eglError(EGL_BAD_MATCH, "eglBindTexImage");
1097 }
1098
1099 if (!es1)
1100 return EGL_TRUE;
1101 if (!gsurf->render_surface)
1102 return EGL_FALSE;
1103
1104 /* flush properly if the surface is bound */
1105 if (gsurf->base.CurrentContext) {
1106 gctx = egl_g3d_context(gsurf->base.CurrentContext);
1107 gctx->stapi->st_flush(gctx->st_ctx,
1108 PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
1109 }
1110
1111 gctx = egl_g3d_context(es1);
1112 gctx->stapi->st_bind_texture_surface(gsurf->render_surface,
1113 target, gsurf->base.MipmapLevel, target_format);
1114
1115 gsurf->base.BoundToTexture = EGL_TRUE;
1116
1117 return EGL_TRUE;
1118 }
1119
1120 static EGLBoolean
1121 egl_g3d_release_tex_image(_EGLDriver *drv, _EGLDisplay *dpy,
1122 _EGLSurface *surf, EGLint buffer)
1123 {
1124 struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
1125
1126 if (!gsurf || gsurf->base.Type != EGL_PBUFFER_BIT ||
1127 !gsurf->base.BoundToTexture)
1128 return _eglError(EGL_BAD_SURFACE, "eglReleaseTexImage");
1129 if (buffer != EGL_BACK_BUFFER)
1130 return _eglError(EGL_BAD_PARAMETER, "eglReleaseTexImage");
1131
1132 if (gsurf->render_surface) {
1133 _EGLContext *ctx = _eglGetAPIContext(EGL_OPENGL_ES_API);
1134 struct egl_g3d_context *gctx = egl_g3d_context(ctx);
1135
1136 /* what if the context the surface binds to is no longer current? */
1137 if (gctx)
1138 gctx->stapi->st_unbind_texture_surface(gsurf->render_surface,
1139 ST_TEXTURE_2D, gsurf->base.MipmapLevel);
1140 }
1141
1142 gsurf->base.BoundToTexture = EGL_FALSE;
1143
1144 return EGL_TRUE;
1145 }
1146
1147 #ifdef EGL_MESA_screen_surface
1148
1149 static _EGLSurface *
1150 egl_g3d_create_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy,
1151 _EGLConfig *conf, const EGLint *attribs)
1152 {
1153 struct egl_g3d_create_surface_arg arg;
1154
1155 memset(&arg, 0, sizeof(arg));
1156 arg.type = EGL_SCREEN_BIT_MESA;
1157
1158 return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs);
1159 }
1160
1161 static EGLBoolean
1162 egl_g3d_show_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy,
1163 _EGLScreen *scr, _EGLSurface *surf,
1164 _EGLMode *mode)
1165 {
1166 struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
1167 struct egl_g3d_screen *gscr = egl_g3d_screen(scr);
1168 struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
1169 struct native_surface *nsurf;
1170 const struct native_mode *nmode;
1171 EGLBoolean changed;
1172
1173 if (gsurf) {
1174 EGLint idx;
1175
1176 if (!mode)
1177 return _eglError(EGL_BAD_MATCH, "eglShowSurfaceMESA");
1178 if (gsurf->base.Type != EGL_SCREEN_BIT_MESA)
1179 return _eglError(EGL_BAD_SURFACE, "eglShowScreenSurfaceMESA");
1180 if (gsurf->base.Width < mode->Width || gsurf->base.Height < mode->Height)
1181 return _eglError(EGL_BAD_MATCH,
1182 "eglShowSurfaceMESA(surface smaller than mode size)");
1183
1184 /* find the index of the mode */
1185 for (idx = 0; idx < gscr->base.NumModes; idx++)
1186 if (mode == &gscr->base.Modes[idx])
1187 break;
1188 if (idx >= gscr->base.NumModes) {
1189 return _eglError(EGL_BAD_MODE_MESA,
1190 "eglShowSurfaceMESA(unknown mode)");
1191 }
1192
1193 nsurf = gsurf->native;
1194 nmode = gscr->native_modes[idx];
1195 }
1196 else {
1197 if (mode)
1198 return _eglError(EGL_BAD_MATCH, "eglShowSurfaceMESA");
1199
1200 /* disable the screen */
1201 nsurf = NULL;
1202 nmode = NULL;
1203 }
1204
1205 /* TODO surface panning by CRTC choosing */
1206 changed = gdpy->native->modeset->program(gdpy->native, 0, nsurf,
1207 gscr->base.OriginX, gscr->base.OriginY, &gscr->native, 1, nmode);
1208 if (changed) {
1209 gscr->base.CurrentSurface = &gsurf->base;
1210 gscr->base.CurrentMode = mode;
1211 }
1212
1213 return changed;
1214 }
1215
1216 #endif /* EGL_MESA_screen_surface */
1217
1218 static EGLint
1219 egl_g3d_probe(_EGLDriver *drv, _EGLDisplay *dpy)
1220 {
1221 struct native_probe *nprobe;
1222 enum native_probe_result res;
1223 EGLint score;
1224
1225 nprobe = egl_g3d_get_probe(drv, dpy);
1226 res = native_get_probe_result(nprobe);
1227
1228 switch (res) {
1229 case NATIVE_PROBE_UNKNOWN:
1230 default:
1231 score = 0;
1232 break;
1233 case NATIVE_PROBE_FALLBACK:
1234 score = 40;
1235 break;
1236 case NATIVE_PROBE_SUPPORTED:
1237 score = 50;
1238 break;
1239 case NATIVE_PROBE_EXACT:
1240 score = 100;
1241 break;
1242 }
1243
1244 return score;
1245 }
1246
1247 static void
1248 egl_g3d_unload(_EGLDriver *drv)
1249 {
1250 struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
1251
1252 egl_g3d_destroy_probe(drv, NULL);
1253 free(gdrv);
1254 }
1255
1256 _EGLDriver *
1257 _eglMain(const char *args)
1258 {
1259 static char driver_name[64];
1260 struct egl_g3d_driver *gdrv;
1261
1262 snprintf(driver_name, sizeof(driver_name),
1263 "Gallium/%s", native_get_name());
1264
1265 gdrv = CALLOC_STRUCT(egl_g3d_driver);
1266 if (!gdrv)
1267 return NULL;
1268
1269 _eglInitDriverFallbacks(&gdrv->base);
1270
1271 gdrv->base.API.Initialize = egl_g3d_initialize;
1272 gdrv->base.API.Terminate = egl_g3d_terminate;
1273 gdrv->base.API.CreateContext = egl_g3d_create_context;
1274 gdrv->base.API.DestroyContext = egl_g3d_destroy_context;
1275 gdrv->base.API.CreateWindowSurface = egl_g3d_create_window_surface;
1276 gdrv->base.API.CreatePixmapSurface = egl_g3d_create_pixmap_surface;
1277 gdrv->base.API.CreatePbufferSurface = egl_g3d_create_pbuffer_surface;
1278 gdrv->base.API.DestroySurface = egl_g3d_destroy_surface;
1279 gdrv->base.API.MakeCurrent = egl_g3d_make_current;
1280 gdrv->base.API.SwapBuffers = egl_g3d_swap_buffers;
1281 gdrv->base.API.CopyBuffers = egl_g3d_copy_buffers;
1282 gdrv->base.API.WaitClient = egl_g3d_wait_client;
1283 gdrv->base.API.WaitNative = egl_g3d_wait_native;
1284 gdrv->base.API.GetProcAddress = egl_g3d_get_proc_address;
1285
1286 gdrv->base.API.BindTexImage = egl_g3d_bind_tex_image;
1287 gdrv->base.API.ReleaseTexImage = egl_g3d_release_tex_image;
1288
1289 #ifdef EGL_MESA_screen_surface
1290 gdrv->base.API.CreateScreenSurfaceMESA = egl_g3d_create_screen_surface;
1291 gdrv->base.API.ShowScreenSurfaceMESA = egl_g3d_show_screen_surface;
1292 #endif
1293
1294 gdrv->base.Name = driver_name;
1295 gdrv->base.Probe = egl_g3d_probe;
1296 gdrv->base.Unload = egl_g3d_unload;
1297
1298 /* the key is " EGL G3D" */
1299 gdrv->probe_key = 0x0E61063D;
1300
1301 return &gdrv->base;
1302 }