2 * Mesa 3-D graphics library
5 * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
26 #include "egldriver.h"
27 #include "eglcurrent.h"
30 #include "pipe/p_screen.h"
31 #include "util/u_memory.h"
32 #include "util/u_inlines.h"
35 #include "egl_g3d_api.h"
36 #include "egl_g3d_image.h"
37 #include "egl_g3d_sync.h"
38 #include "egl_g3d_st.h"
39 #include "egl_g3d_loader.h"
43 * Return the state tracker for the given context.
45 static struct st_api
*
46 egl_g3d_choose_st(_EGLDriver
*drv
, _EGLContext
*ctx
,
47 enum st_profile_type
*profile
)
49 struct egl_g3d_driver
*gdrv
= egl_g3d_driver(drv
);
53 *profile
= ST_PROFILE_DEFAULT
;
55 switch (ctx
->ClientAPI
) {
56 case EGL_OPENGL_ES_API
:
57 switch (ctx
->ClientVersion
) {
60 *profile
= ST_PROFILE_OPENGL_ES1
;
64 *profile
= ST_PROFILE_OPENGL_ES2
;
67 _eglLog(_EGL_WARNING
, "unknown client version %d",
79 _eglLog(_EGL_WARNING
, "unknown client API 0x%04x", ctx
->ClientAPI
);
85 stapi
= gdrv
->loader
->guess_gl_api(*profile
);
88 stapi
= gdrv
->loader
->get_st_api(api
);
94 if (stapi
&& !(stapi
->profile_mask
& (1 << *profile
)))
101 egl_g3d_create_context(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
102 _EGLContext
*share
, const EGLint
*attribs
)
104 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
105 struct egl_g3d_context
*gshare
= egl_g3d_context(share
);
106 struct egl_g3d_config
*gconf
= egl_g3d_config(conf
);
107 struct egl_g3d_context
*gctx
;
108 struct st_context_attribs stattribs
;
110 gctx
= CALLOC_STRUCT(egl_g3d_context
);
112 _eglError(EGL_BAD_ALLOC
, "eglCreateContext");
116 if (!_eglInitContext(&gctx
->base
, dpy
, conf
, attribs
)) {
121 memset(&stattribs
, 0, sizeof(stattribs
));
123 stattribs
.visual
= gconf
->stvis
;
125 gctx
->stapi
= egl_g3d_choose_st(drv
, &gctx
->base
, &stattribs
.profile
);
131 gctx
->stctxi
= gctx
->stapi
->create_context(gctx
->stapi
, gdpy
->smapi
,
132 &stattribs
, (gshare
) ? gshare
->stctxi
: NULL
);
138 gctx
->stctxi
->st_manager_private
= (void *) &gctx
->base
;
147 destroy_context(_EGLDisplay
*dpy
, _EGLContext
*ctx
)
149 struct egl_g3d_context
*gctx
= egl_g3d_context(ctx
);
151 /* FIXME a context might live longer than its display */
152 if (!dpy
->Initialized
)
153 _eglLog(_EGL_FATAL
, "destroy a context with an unitialized display");
155 gctx
->stctxi
->destroy(gctx
->stctxi
);
161 egl_g3d_destroy_context(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*ctx
)
163 if (_eglPutContext(ctx
))
164 destroy_context(dpy
, ctx
);
168 struct egl_g3d_create_surface_arg
{
171 EGLNativeWindowType win
;
172 EGLNativePixmapType pix
;
177 egl_g3d_create_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
178 struct egl_g3d_create_surface_arg
*arg
,
179 const EGLint
*attribs
)
181 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
182 struct egl_g3d_config
*gconf
= egl_g3d_config(conf
);
183 struct egl_g3d_surface
*gsurf
;
184 struct native_surface
*nsurf
;
189 err
= "eglCreateWindowSurface";
192 err
= "eglCreatePixmapSurface";
194 #ifdef EGL_MESA_screen_surface
195 case EGL_SCREEN_BIT_MESA
:
196 err
= "eglCreateScreenSurface";
200 err
= "eglCreateUnknownSurface";
204 gsurf
= CALLOC_STRUCT(egl_g3d_surface
);
206 _eglError(EGL_BAD_ALLOC
, err
);
210 if (!_eglInitSurface(&gsurf
->base
, dpy
, arg
->type
, conf
, attribs
)) {
215 /* create the native surface */
218 nsurf
= gdpy
->native
->create_window_surface(gdpy
->native
,
219 arg
->u
.win
, gconf
->native
);
222 nsurf
= gdpy
->native
->create_pixmap_surface(gdpy
->native
,
223 arg
->u
.pix
, gconf
->native
);
225 #ifdef EGL_MESA_screen_surface
226 case EGL_SCREEN_BIT_MESA
:
227 /* prefer back buffer (move to _eglInitSurface?) */
228 gsurf
->base
.RenderBuffer
= EGL_BACK_BUFFER
;
229 nsurf
= gdpy
->native
->modeset
->create_scanout_surface(gdpy
->native
,
230 gconf
->native
, gsurf
->base
.Width
, gsurf
->base
.Height
);
242 /* initialize the geometry */
243 if (!nsurf
->validate(nsurf
, 0x0, &gsurf
->sequence_number
, NULL
,
244 &gsurf
->base
.Width
, &gsurf
->base
.Height
)) {
245 nsurf
->destroy(nsurf
);
250 gsurf
->stvis
= gconf
->stvis
;
251 if (gsurf
->base
.RenderBuffer
== EGL_SINGLE_BUFFER
)
252 gsurf
->stvis
.render_buffer
= ST_ATTACHMENT_FRONT_LEFT
;
254 gsurf
->stfbi
= egl_g3d_create_st_framebuffer(&gsurf
->base
);
256 nsurf
->destroy(nsurf
);
261 nsurf
->user_data
= &gsurf
->base
;
262 gsurf
->native
= nsurf
;
268 egl_g3d_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
269 _EGLConfig
*conf
, EGLNativeWindowType win
,
270 const EGLint
*attribs
)
272 struct egl_g3d_create_surface_arg arg
;
274 memset(&arg
, 0, sizeof(arg
));
275 arg
.type
= EGL_WINDOW_BIT
;
278 return egl_g3d_create_surface(drv
, dpy
, conf
, &arg
, attribs
);
282 egl_g3d_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
283 _EGLConfig
*conf
, EGLNativePixmapType pix
,
284 const EGLint
*attribs
)
286 struct egl_g3d_create_surface_arg arg
;
288 memset(&arg
, 0, sizeof(arg
));
289 arg
.type
= EGL_PIXMAP_BIT
;
292 return egl_g3d_create_surface(drv
, dpy
, conf
, &arg
, attribs
);
295 static struct egl_g3d_surface
*
296 create_pbuffer_surface(_EGLDisplay
*dpy
, _EGLConfig
*conf
,
297 const EGLint
*attribs
, const char *func
)
299 struct egl_g3d_config
*gconf
= egl_g3d_config(conf
);
300 struct egl_g3d_surface
*gsurf
;
302 gsurf
= CALLOC_STRUCT(egl_g3d_surface
);
304 _eglError(EGL_BAD_ALLOC
, func
);
308 if (!_eglInitSurface(&gsurf
->base
, dpy
, EGL_PBUFFER_BIT
, conf
, attribs
)) {
313 gsurf
->stvis
= gconf
->stvis
;
315 gsurf
->stfbi
= egl_g3d_create_st_framebuffer(&gsurf
->base
);
325 egl_g3d_create_pbuffer_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
326 _EGLConfig
*conf
, const EGLint
*attribs
)
328 struct egl_g3d_surface
*gsurf
;
329 struct pipe_resource
*ptex
= NULL
;
331 gsurf
= create_pbuffer_surface(dpy
, conf
, attribs
,
332 "eglCreatePbufferSurface");
336 gsurf
->client_buffer_type
= EGL_NONE
;
338 if (!gsurf
->stfbi
->validate(gsurf
->stfbi
,
339 &gsurf
->stvis
.render_buffer
, 1, &ptex
)) {
340 egl_g3d_destroy_st_framebuffer(gsurf
->stfbi
);
349 egl_g3d_create_pbuffer_from_client_buffer(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
351 EGLClientBuffer buffer
,
353 const EGLint
*attribs
)
355 struct egl_g3d_surface
*gsurf
;
356 struct pipe_resource
*ptex
= NULL
;
357 EGLint pbuffer_attribs
[32];
361 case EGL_OPENVG_IMAGE
:
364 _eglError(EGL_BAD_PARAMETER
, "eglCreatePbufferFromClientBuffer");
369 /* parse the attributes first */
371 for (i
= 0; attribs
&& attribs
[i
] != EGL_NONE
; i
++) {
372 EGLint attr
= attribs
[i
++];
373 EGLint val
= attribs
[i
];
374 EGLint err
= EGL_SUCCESS
;
377 case EGL_TEXTURE_FORMAT
:
378 case EGL_TEXTURE_TARGET
:
379 case EGL_MIPMAP_TEXTURE
:
380 pbuffer_attribs
[count
++] = attr
;
381 pbuffer_attribs
[count
++] = val
;
384 err
= EGL_BAD_ATTRIBUTE
;
388 if (err
!= EGL_SUCCESS
) {
389 _eglError(err
, "eglCreatePbufferFromClientBuffer");
394 pbuffer_attribs
[count
++] = EGL_NONE
;
396 gsurf
= create_pbuffer_surface(dpy
, conf
, pbuffer_attribs
,
397 "eglCreatePbufferFromClientBuffer");
401 gsurf
->client_buffer_type
= buftype
;
402 gsurf
->client_buffer
= buffer
;
404 if (!gsurf
->stfbi
->validate(gsurf
->stfbi
,
405 &gsurf
->stvis
.render_buffer
, 1, &ptex
)) {
406 egl_g3d_destroy_st_framebuffer(gsurf
->stfbi
);
418 destroy_surface(_EGLDisplay
*dpy
, _EGLSurface
*surf
)
420 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
422 /* FIXME a surface might live longer than its display */
423 if (!dpy
->Initialized
)
424 _eglLog(_EGL_FATAL
, "destroy a surface with an unitialized display");
426 pipe_resource_reference(&gsurf
->render_texture
, NULL
);
427 egl_g3d_destroy_st_framebuffer(gsurf
->stfbi
);
429 gsurf
->native
->destroy(gsurf
->native
);
434 egl_g3d_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
436 if (_eglPutSurface(surf
))
437 destroy_surface(dpy
, surf
);
442 egl_g3d_make_current(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
443 _EGLSurface
*draw
, _EGLSurface
*read
, _EGLContext
*ctx
)
445 struct egl_g3d_context
*gctx
= egl_g3d_context(ctx
);
446 struct egl_g3d_surface
*gdraw
= egl_g3d_surface(draw
);
447 struct egl_g3d_surface
*gread
= egl_g3d_surface(read
);
448 struct egl_g3d_context
*old_gctx
;
449 _EGLContext
*old_ctx
;
450 _EGLSurface
*old_draw
, *old_read
;
451 EGLBoolean ok
= EGL_TRUE
;
453 /* make new bindings */
454 if (!_eglBindContext(ctx
, draw
, read
, &old_ctx
, &old_draw
, &old_read
))
457 old_gctx
= egl_g3d_context(old_ctx
);
459 /* flush old context */
460 old_gctx
->stctxi
->flush(old_gctx
->stctxi
,
461 PIPE_FLUSH_RENDER_CACHE
| PIPE_FLUSH_FRAME
, NULL
);
465 ok
= gctx
->stapi
->make_current(gctx
->stapi
, gctx
->stctxi
,
466 (gdraw
) ? gdraw
->stfbi
: NULL
, (gread
) ? gread
->stfbi
: NULL
);
469 gctx
->stctxi
->notify_invalid_framebuffer(gctx
->stctxi
,
472 if (gdraw
->base
.Type
== EGL_WINDOW_BIT
) {
473 gctx
->base
.WindowRenderBuffer
=
474 (gdraw
->stvis
.render_buffer
== ST_ATTACHMENT_FRONT_LEFT
) ?
475 EGL_SINGLE_BUFFER
: EGL_BACK_BUFFER
;
478 if (gread
&& gread
!= gdraw
) {
479 gctx
->stctxi
->notify_invalid_framebuffer(gctx
->stctxi
,
485 ok
= old_gctx
->stapi
->make_current(old_gctx
->stapi
, NULL
, NULL
, NULL
);
487 old_gctx
->base
.WindowRenderBuffer
= EGL_NONE
;
491 if (_eglPutContext(old_ctx
))
492 destroy_context(dpy
, old_ctx
);
493 if (_eglPutSurface(old_draw
))
494 destroy_surface(dpy
, old_draw
);
495 if (_eglPutSurface(old_read
))
496 destroy_surface(dpy
, old_read
);
499 /* undo the previous _eglBindContext */
500 _eglBindContext(old_ctx
, old_draw
, old_read
, &ctx
, &draw
, &read
);
501 assert(&gctx
->base
== ctx
&&
502 &gdraw
->base
== draw
&&
503 &gread
->base
== read
);
505 _eglPutSurface(draw
);
506 _eglPutSurface(read
);
509 _eglPutSurface(old_draw
);
510 _eglPutSurface(old_read
);
511 _eglPutContext(old_ctx
);
518 egl_g3d_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
520 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
521 _EGLContext
*ctx
= _eglGetCurrentContext();
522 struct egl_g3d_context
*gctx
= NULL
;
524 /* no-op for pixmap or pbuffer surface */
525 if (gsurf
->base
.Type
== EGL_PIXMAP_BIT
||
526 gsurf
->base
.Type
== EGL_PBUFFER_BIT
)
529 /* or when the surface is single-buffered */
530 if (gsurf
->stvis
.render_buffer
== ST_ATTACHMENT_FRONT_LEFT
)
533 if (ctx
&& ctx
->DrawSurface
== surf
)
534 gctx
= egl_g3d_context(ctx
);
536 /* flush if the surface is current */
538 gctx
->stctxi
->flush(gctx
->stctxi
,
539 PIPE_FLUSH_RENDER_CACHE
| PIPE_FLUSH_FRAME
, NULL
);
542 return gsurf
->native
->swap_buffers(gsurf
->native
);
546 * Get the pipe surface of the given attachment of the native surface.
548 static struct pipe_resource
*
549 get_pipe_resource(struct native_display
*ndpy
, struct native_surface
*nsurf
,
550 enum native_attachment natt
)
552 struct pipe_resource
*textures
[NUM_NATIVE_ATTACHMENTS
];
554 textures
[natt
] = NULL
;
555 nsurf
->validate(nsurf
, 1 << natt
, NULL
, textures
, NULL
, NULL
);
557 return textures
[natt
];
561 egl_g3d_copy_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
562 EGLNativePixmapType target
)
564 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
565 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
566 _EGLContext
*ctx
= _eglGetCurrentContext();
567 struct egl_g3d_config
*gconf
;
568 struct native_surface
*nsurf
;
569 struct pipe_resource
*ptex
;
571 if (!gsurf
->render_texture
)
574 gconf
= egl_g3d_config(egl_g3d_find_pixmap_config(dpy
, target
));
576 return _eglError(EGL_BAD_NATIVE_PIXMAP
, "eglCopyBuffers");
578 nsurf
= gdpy
->native
->create_pixmap_surface(gdpy
->native
,
579 target
, gconf
->native
);
581 return _eglError(EGL_BAD_NATIVE_PIXMAP
, "eglCopyBuffers");
583 /* flush if the surface is current */
584 if (ctx
&& ctx
->DrawSurface
== &gsurf
->base
) {
585 struct egl_g3d_context
*gctx
= egl_g3d_context(ctx
);
586 gctx
->stctxi
->flush(gctx
->stctxi
,
587 PIPE_FLUSH_RENDER_CACHE
| PIPE_FLUSH_FRAME
, NULL
);
590 /* create a pipe context to copy surfaces */
593 gdpy
->native
->screen
->context_create(gdpy
->native
->screen
, NULL
);
598 ptex
= get_pipe_resource(gdpy
->native
, nsurf
, NATIVE_ATTACHMENT_FRONT_LEFT
);
600 struct pipe_resource
*psrc
= gsurf
->render_texture
;
601 struct pipe_subresource subsrc
, subdst
;
608 gdpy
->pipe
->resource_copy_region(gdpy
->pipe
, ptex
, subdst
, 0, 0, 0,
609 gsurf
->render_texture
, subsrc
, 0, 0, 0, ptex
->width0
, ptex
->height0
);
611 nsurf
->flush_frontbuffer(nsurf
);
614 pipe_resource_reference(&ptex
, NULL
);
617 nsurf
->destroy(nsurf
);
623 egl_g3d_wait_client(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*ctx
)
625 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
626 struct egl_g3d_context
*gctx
= egl_g3d_context(ctx
);
627 struct pipe_screen
*screen
= gdpy
->native
->screen
;
628 struct pipe_fence_handle
*fence
= NULL
;
630 gctx
->stctxi
->flush(gctx
->stctxi
,
631 PIPE_FLUSH_RENDER_CACHE
| PIPE_FLUSH_FRAME
, &fence
);
633 screen
->fence_finish(screen
, fence
, 0);
634 screen
->fence_reference(screen
, &fence
, NULL
);
641 egl_g3d_wait_native(_EGLDriver
*drv
, _EGLDisplay
*dpy
, EGLint engine
)
643 _EGLContext
*ctx
= _eglGetCurrentContext();
645 if (engine
!= EGL_CORE_NATIVE_ENGINE
)
646 return _eglError(EGL_BAD_PARAMETER
, "eglWaitNative");
648 if (ctx
&& ctx
->DrawSurface
) {
649 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(ctx
->DrawSurface
);
652 gsurf
->native
->wait(gsurf
->native
);
659 egl_g3d_bind_tex_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
660 _EGLSurface
*surf
, EGLint buffer
)
662 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
663 _EGLContext
*es1
= _eglGetAPIContext(EGL_OPENGL_ES_API
);
664 struct egl_g3d_context
*gctx
;
665 enum pipe_format internal_format
;
666 enum st_texture_type target
;
668 if (!gsurf
|| gsurf
->base
.Type
!= EGL_PBUFFER_BIT
)
669 return _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
670 if (buffer
!= EGL_BACK_BUFFER
)
671 return _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
672 if (gsurf
->base
.BoundToTexture
)
673 return _eglError(EGL_BAD_ACCESS
, "eglBindTexImage");
675 switch (gsurf
->base
.TextureFormat
) {
676 case EGL_TEXTURE_RGB
:
677 internal_format
= PIPE_FORMAT_R8G8B8_UNORM
;
679 case EGL_TEXTURE_RGBA
:
680 internal_format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
683 return _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
686 switch (gsurf
->base
.TextureTarget
) {
688 target
= ST_TEXTURE_2D
;
691 return _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
696 if (!gsurf
->render_texture
)
699 /* flush properly if the surface is bound */
700 if (gsurf
->base
.CurrentContext
) {
701 gctx
= egl_g3d_context(gsurf
->base
.CurrentContext
);
702 gctx
->stctxi
->flush(gctx
->stctxi
,
703 PIPE_FLUSH_RENDER_CACHE
| PIPE_FLUSH_FRAME
, NULL
);
706 gctx
= egl_g3d_context(es1
);
707 if (gctx
->stctxi
->teximage
) {
708 if (!gctx
->stctxi
->teximage(gctx
->stctxi
, target
,
709 gsurf
->base
.MipmapLevel
, internal_format
,
710 gsurf
->render_texture
, gsurf
->base
.MipmapTexture
))
712 gsurf
->base
.BoundToTexture
= EGL_TRUE
;
719 egl_g3d_release_tex_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
720 _EGLSurface
*surf
, EGLint buffer
)
722 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
724 if (!gsurf
|| gsurf
->base
.Type
!= EGL_PBUFFER_BIT
||
725 !gsurf
->base
.BoundToTexture
)
726 return _eglError(EGL_BAD_SURFACE
, "eglReleaseTexImage");
727 if (buffer
!= EGL_BACK_BUFFER
)
728 return _eglError(EGL_BAD_PARAMETER
, "eglReleaseTexImage");
730 if (gsurf
->render_texture
) {
731 _EGLContext
*ctx
= _eglGetAPIContext(EGL_OPENGL_ES_API
);
732 struct egl_g3d_context
*gctx
= egl_g3d_context(ctx
);
734 /* what if the context the surface binds to is no longer current? */
736 gctx
->stctxi
->teximage(gctx
->stctxi
, ST_TEXTURE_2D
,
737 gsurf
->base
.MipmapLevel
, PIPE_FORMAT_NONE
, NULL
, FALSE
);
741 gsurf
->base
.BoundToTexture
= EGL_FALSE
;
746 #ifdef EGL_MESA_screen_surface
749 egl_g3d_create_screen_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
750 _EGLConfig
*conf
, const EGLint
*attribs
)
752 struct egl_g3d_create_surface_arg arg
;
754 memset(&arg
, 0, sizeof(arg
));
755 arg
.type
= EGL_SCREEN_BIT_MESA
;
757 return egl_g3d_create_surface(drv
, dpy
, conf
, &arg
, attribs
);
761 egl_g3d_show_screen_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
762 _EGLScreen
*scr
, _EGLSurface
*surf
,
765 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
766 struct egl_g3d_screen
*gscr
= egl_g3d_screen(scr
);
767 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
768 struct native_surface
*nsurf
;
769 const struct native_mode
*nmode
;
776 return _eglError(EGL_BAD_MATCH
, "eglShowSurfaceMESA");
777 if (gsurf
->base
.Type
!= EGL_SCREEN_BIT_MESA
)
778 return _eglError(EGL_BAD_SURFACE
, "eglShowScreenSurfaceMESA");
779 if (gsurf
->base
.Width
< mode
->Width
|| gsurf
->base
.Height
< mode
->Height
)
780 return _eglError(EGL_BAD_MATCH
,
781 "eglShowSurfaceMESA(surface smaller than mode size)");
783 /* find the index of the mode */
784 for (idx
= 0; idx
< gscr
->base
.NumModes
; idx
++)
785 if (mode
== &gscr
->base
.Modes
[idx
])
787 if (idx
>= gscr
->base
.NumModes
) {
788 return _eglError(EGL_BAD_MODE_MESA
,
789 "eglShowSurfaceMESA(unknown mode)");
792 nsurf
= gsurf
->native
;
793 nmode
= gscr
->native_modes
[idx
];
797 return _eglError(EGL_BAD_MATCH
, "eglShowSurfaceMESA");
799 /* disable the screen */
804 /* TODO surface panning by CRTC choosing */
805 changed
= gdpy
->native
->modeset
->program(gdpy
->native
, 0, nsurf
,
806 gscr
->base
.OriginX
, gscr
->base
.OriginY
, &gscr
->native
, 1, nmode
);
808 gscr
->base
.CurrentSurface
= &gsurf
->base
;
809 gscr
->base
.CurrentMode
= mode
;
815 #endif /* EGL_MESA_screen_surface */
818 * Find a config that supports the pixmap.
821 egl_g3d_find_pixmap_config(_EGLDisplay
*dpy
, EGLNativePixmapType pix
)
823 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
824 struct egl_g3d_config
*gconf
;
827 for (i
= 0; i
< dpy
->Configs
->Size
; i
++) {
828 gconf
= egl_g3d_config((_EGLConfig
*) dpy
->Configs
->Elements
[i
]);
829 if (gdpy
->native
->is_pixmap_supported(gdpy
->native
, pix
, gconf
->native
))
833 return (i
< dpy
->Configs
->Size
) ? &gconf
->base
: NULL
;
837 egl_g3d_init_driver_api(_EGLDriver
*drv
)
839 _eglInitDriverFallbacks(drv
);
841 drv
->API
.CreateContext
= egl_g3d_create_context
;
842 drv
->API
.DestroyContext
= egl_g3d_destroy_context
;
843 drv
->API
.CreateWindowSurface
= egl_g3d_create_window_surface
;
844 drv
->API
.CreatePixmapSurface
= egl_g3d_create_pixmap_surface
;
845 drv
->API
.CreatePbufferSurface
= egl_g3d_create_pbuffer_surface
;
846 drv
->API
.CreatePbufferFromClientBuffer
= egl_g3d_create_pbuffer_from_client_buffer
;
847 drv
->API
.DestroySurface
= egl_g3d_destroy_surface
;
848 drv
->API
.MakeCurrent
= egl_g3d_make_current
;
849 drv
->API
.SwapBuffers
= egl_g3d_swap_buffers
;
850 drv
->API
.CopyBuffers
= egl_g3d_copy_buffers
;
851 drv
->API
.WaitClient
= egl_g3d_wait_client
;
852 drv
->API
.WaitNative
= egl_g3d_wait_native
;
854 drv
->API
.BindTexImage
= egl_g3d_bind_tex_image
;
855 drv
->API
.ReleaseTexImage
= egl_g3d_release_tex_image
;
857 drv
->API
.CreateImageKHR
= egl_g3d_create_image
;
858 drv
->API
.DestroyImageKHR
= egl_g3d_destroy_image
;
859 #ifdef EGL_MESA_drm_image
860 drv
->API
.CreateDRMImageMESA
= egl_g3d_create_drm_image
;
861 drv
->API
.ExportDRMImageMESA
= egl_g3d_export_drm_image
;
864 #ifdef EGL_KHR_reusable_sync
865 drv
->API
.CreateSyncKHR
= egl_g3d_create_sync
;
866 drv
->API
.DestroySyncKHR
= egl_g3d_destroy_sync
;
867 drv
->API
.ClientWaitSyncKHR
= egl_g3d_client_wait_sync
;
868 drv
->API
.SignalSyncKHR
= egl_g3d_signal_sync
;
871 #ifdef EGL_MESA_screen_surface
872 drv
->API
.CreateScreenSurfaceMESA
= egl_g3d_create_screen_surface
;
873 drv
->API
.ShowScreenSurfaceMESA
= egl_g3d_show_screen_surface
;