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 (!_eglIsContextBound(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 (!_eglIsSurfaceBound(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 EGLBoolean ok
= EGL_TRUE
;
451 /* bind the new context and return the "orphaned" one */
452 if (!_eglBindContext(&ctx
, &draw
, &read
))
454 old_gctx
= egl_g3d_context(ctx
);
457 /* flush old context */
458 old_gctx
->stctxi
->flush(old_gctx
->stctxi
,
459 PIPE_FLUSH_RENDER_CACHE
| PIPE_FLUSH_FRAME
, NULL
);
463 ok
= gctx
->stapi
->make_current(gctx
->stapi
, gctx
->stctxi
,
464 (gdraw
) ? gdraw
->stfbi
: NULL
, (gread
) ? gread
->stfbi
: NULL
);
467 gctx
->stctxi
->notify_invalid_framebuffer(gctx
->stctxi
,
470 if (gdraw
->base
.Type
== EGL_WINDOW_BIT
) {
471 gctx
->base
.WindowRenderBuffer
=
472 (gdraw
->stvis
.render_buffer
== ST_ATTACHMENT_FRONT_LEFT
) ?
473 EGL_SINGLE_BUFFER
: EGL_BACK_BUFFER
;
476 if (gread
&& gread
!= gdraw
) {
477 gctx
->stctxi
->notify_invalid_framebuffer(gctx
->stctxi
,
483 ok
= old_gctx
->stapi
->make_current(old_gctx
->stapi
, NULL
, NULL
, NULL
);
484 old_gctx
->base
.WindowRenderBuffer
= EGL_NONE
;
487 if (ctx
&& !_eglIsContextLinked(ctx
))
488 destroy_context(dpy
, ctx
);
489 if (draw
&& !_eglIsSurfaceLinked(draw
))
490 destroy_surface(dpy
, draw
);
491 if (read
&& read
!= draw
&& !_eglIsSurfaceLinked(read
))
492 destroy_surface(dpy
, read
);
498 egl_g3d_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
500 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
501 _EGLContext
*ctx
= _eglGetCurrentContext();
502 struct egl_g3d_context
*gctx
= NULL
;
504 /* no-op for pixmap or pbuffer surface */
505 if (gsurf
->base
.Type
== EGL_PIXMAP_BIT
||
506 gsurf
->base
.Type
== EGL_PBUFFER_BIT
)
509 /* or when the surface is single-buffered */
510 if (gsurf
->stvis
.render_buffer
== ST_ATTACHMENT_FRONT_LEFT
)
513 if (ctx
&& ctx
->DrawSurface
== surf
)
514 gctx
= egl_g3d_context(ctx
);
516 /* flush if the surface is current */
518 gctx
->stctxi
->flush(gctx
->stctxi
,
519 PIPE_FLUSH_RENDER_CACHE
| PIPE_FLUSH_FRAME
, NULL
);
522 return gsurf
->native
->swap_buffers(gsurf
->native
);
526 * Get the pipe surface of the given attachment of the native surface.
528 static struct pipe_resource
*
529 get_pipe_resource(struct native_display
*ndpy
, struct native_surface
*nsurf
,
530 enum native_attachment natt
)
532 struct pipe_resource
*textures
[NUM_NATIVE_ATTACHMENTS
];
534 textures
[natt
] = NULL
;
535 nsurf
->validate(nsurf
, 1 << natt
, NULL
, textures
, NULL
, NULL
);
537 return textures
[natt
];
541 egl_g3d_copy_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
542 EGLNativePixmapType target
)
544 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
545 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
546 _EGLContext
*ctx
= _eglGetCurrentContext();
547 struct egl_g3d_config
*gconf
;
548 struct native_surface
*nsurf
;
549 struct pipe_resource
*ptex
;
551 if (!gsurf
->render_texture
)
554 gconf
= egl_g3d_config(egl_g3d_find_pixmap_config(dpy
, target
));
556 return _eglError(EGL_BAD_NATIVE_PIXMAP
, "eglCopyBuffers");
558 nsurf
= gdpy
->native
->create_pixmap_surface(gdpy
->native
,
559 target
, gconf
->native
);
561 return _eglError(EGL_BAD_NATIVE_PIXMAP
, "eglCopyBuffers");
563 /* flush if the surface is current */
564 if (ctx
&& ctx
->DrawSurface
== &gsurf
->base
) {
565 struct egl_g3d_context
*gctx
= egl_g3d_context(ctx
);
566 gctx
->stctxi
->flush(gctx
->stctxi
,
567 PIPE_FLUSH_RENDER_CACHE
| PIPE_FLUSH_FRAME
, NULL
);
570 /* create a pipe context to copy surfaces */
573 gdpy
->native
->screen
->context_create(gdpy
->native
->screen
, NULL
);
578 ptex
= get_pipe_resource(gdpy
->native
, nsurf
, NATIVE_ATTACHMENT_FRONT_LEFT
);
580 struct pipe_resource
*psrc
= gsurf
->render_texture
;
581 struct pipe_subresource subsrc
, subdst
;
588 gdpy
->pipe
->resource_copy_region(gdpy
->pipe
, ptex
, subdst
, 0, 0, 0,
589 gsurf
->render_texture
, subsrc
, 0, 0, 0, ptex
->width0
, ptex
->height0
);
591 nsurf
->flush_frontbuffer(nsurf
);
594 pipe_resource_reference(&ptex
, NULL
);
597 nsurf
->destroy(nsurf
);
603 egl_g3d_wait_client(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*ctx
)
605 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
606 struct egl_g3d_context
*gctx
= egl_g3d_context(ctx
);
607 struct pipe_screen
*screen
= gdpy
->native
->screen
;
608 struct pipe_fence_handle
*fence
= NULL
;
610 gctx
->stctxi
->flush(gctx
->stctxi
,
611 PIPE_FLUSH_RENDER_CACHE
| PIPE_FLUSH_FRAME
, &fence
);
613 screen
->fence_finish(screen
, fence
, 0);
614 screen
->fence_reference(screen
, &fence
, NULL
);
621 egl_g3d_wait_native(_EGLDriver
*drv
, _EGLDisplay
*dpy
, EGLint engine
)
623 _EGLContext
*ctx
= _eglGetCurrentContext();
625 if (engine
!= EGL_CORE_NATIVE_ENGINE
)
626 return _eglError(EGL_BAD_PARAMETER
, "eglWaitNative");
628 if (ctx
&& ctx
->DrawSurface
) {
629 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(ctx
->DrawSurface
);
632 gsurf
->native
->wait(gsurf
->native
);
639 egl_g3d_bind_tex_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
640 _EGLSurface
*surf
, EGLint buffer
)
642 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
643 _EGLContext
*es1
= _eglGetAPIContext(EGL_OPENGL_ES_API
);
644 struct egl_g3d_context
*gctx
;
645 enum pipe_format internal_format
;
646 enum st_texture_type target
;
648 if (!gsurf
|| gsurf
->base
.Type
!= EGL_PBUFFER_BIT
)
649 return _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
650 if (buffer
!= EGL_BACK_BUFFER
)
651 return _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
652 if (gsurf
->base
.BoundToTexture
)
653 return _eglError(EGL_BAD_ACCESS
, "eglBindTexImage");
655 switch (gsurf
->base
.TextureFormat
) {
656 case EGL_TEXTURE_RGB
:
657 internal_format
= PIPE_FORMAT_R8G8B8_UNORM
;
659 case EGL_TEXTURE_RGBA
:
660 internal_format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
663 return _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
666 switch (gsurf
->base
.TextureTarget
) {
668 target
= ST_TEXTURE_2D
;
671 return _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
676 if (!gsurf
->render_texture
)
679 /* flush properly if the surface is bound */
680 if (gsurf
->base
.CurrentContext
) {
681 gctx
= egl_g3d_context(gsurf
->base
.CurrentContext
);
682 gctx
->stctxi
->flush(gctx
->stctxi
,
683 PIPE_FLUSH_RENDER_CACHE
| PIPE_FLUSH_FRAME
, NULL
);
686 gctx
= egl_g3d_context(es1
);
687 if (gctx
->stctxi
->teximage
) {
688 if (!gctx
->stctxi
->teximage(gctx
->stctxi
, target
,
689 gsurf
->base
.MipmapLevel
, internal_format
,
690 gsurf
->render_texture
, gsurf
->base
.MipmapTexture
))
692 gsurf
->base
.BoundToTexture
= EGL_TRUE
;
699 egl_g3d_release_tex_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
700 _EGLSurface
*surf
, EGLint buffer
)
702 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
704 if (!gsurf
|| gsurf
->base
.Type
!= EGL_PBUFFER_BIT
||
705 !gsurf
->base
.BoundToTexture
)
706 return _eglError(EGL_BAD_SURFACE
, "eglReleaseTexImage");
707 if (buffer
!= EGL_BACK_BUFFER
)
708 return _eglError(EGL_BAD_PARAMETER
, "eglReleaseTexImage");
710 if (gsurf
->render_texture
) {
711 _EGLContext
*ctx
= _eglGetAPIContext(EGL_OPENGL_ES_API
);
712 struct egl_g3d_context
*gctx
= egl_g3d_context(ctx
);
714 /* what if the context the surface binds to is no longer current? */
716 gctx
->stctxi
->teximage(gctx
->stctxi
, ST_TEXTURE_2D
,
717 gsurf
->base
.MipmapLevel
, PIPE_FORMAT_NONE
, NULL
, FALSE
);
721 gsurf
->base
.BoundToTexture
= EGL_FALSE
;
726 #ifdef EGL_MESA_screen_surface
729 egl_g3d_create_screen_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
730 _EGLConfig
*conf
, const EGLint
*attribs
)
732 struct egl_g3d_create_surface_arg arg
;
734 memset(&arg
, 0, sizeof(arg
));
735 arg
.type
= EGL_SCREEN_BIT_MESA
;
737 return egl_g3d_create_surface(drv
, dpy
, conf
, &arg
, attribs
);
741 egl_g3d_show_screen_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
742 _EGLScreen
*scr
, _EGLSurface
*surf
,
745 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
746 struct egl_g3d_screen
*gscr
= egl_g3d_screen(scr
);
747 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
748 struct native_surface
*nsurf
;
749 const struct native_mode
*nmode
;
756 return _eglError(EGL_BAD_MATCH
, "eglShowSurfaceMESA");
757 if (gsurf
->base
.Type
!= EGL_SCREEN_BIT_MESA
)
758 return _eglError(EGL_BAD_SURFACE
, "eglShowScreenSurfaceMESA");
759 if (gsurf
->base
.Width
< mode
->Width
|| gsurf
->base
.Height
< mode
->Height
)
760 return _eglError(EGL_BAD_MATCH
,
761 "eglShowSurfaceMESA(surface smaller than mode size)");
763 /* find the index of the mode */
764 for (idx
= 0; idx
< gscr
->base
.NumModes
; idx
++)
765 if (mode
== &gscr
->base
.Modes
[idx
])
767 if (idx
>= gscr
->base
.NumModes
) {
768 return _eglError(EGL_BAD_MODE_MESA
,
769 "eglShowSurfaceMESA(unknown mode)");
772 nsurf
= gsurf
->native
;
773 nmode
= gscr
->native_modes
[idx
];
777 return _eglError(EGL_BAD_MATCH
, "eglShowSurfaceMESA");
779 /* disable the screen */
784 /* TODO surface panning by CRTC choosing */
785 changed
= gdpy
->native
->modeset
->program(gdpy
->native
, 0, nsurf
,
786 gscr
->base
.OriginX
, gscr
->base
.OriginY
, &gscr
->native
, 1, nmode
);
788 gscr
->base
.CurrentSurface
= &gsurf
->base
;
789 gscr
->base
.CurrentMode
= mode
;
795 #endif /* EGL_MESA_screen_surface */
798 * Find a config that supports the pixmap.
801 egl_g3d_find_pixmap_config(_EGLDisplay
*dpy
, EGLNativePixmapType pix
)
803 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
804 struct egl_g3d_config
*gconf
;
807 for (i
= 0; i
< dpy
->Configs
->Size
; i
++) {
808 gconf
= egl_g3d_config((_EGLConfig
*) dpy
->Configs
->Elements
[i
]);
809 if (gdpy
->native
->is_pixmap_supported(gdpy
->native
, pix
, gconf
->native
))
813 return (i
< dpy
->Configs
->Size
) ? &gconf
->base
: NULL
;
817 egl_g3d_init_driver_api(_EGLDriver
*drv
)
819 _eglInitDriverFallbacks(drv
);
821 drv
->API
.CreateContext
= egl_g3d_create_context
;
822 drv
->API
.DestroyContext
= egl_g3d_destroy_context
;
823 drv
->API
.CreateWindowSurface
= egl_g3d_create_window_surface
;
824 drv
->API
.CreatePixmapSurface
= egl_g3d_create_pixmap_surface
;
825 drv
->API
.CreatePbufferSurface
= egl_g3d_create_pbuffer_surface
;
826 drv
->API
.CreatePbufferFromClientBuffer
= egl_g3d_create_pbuffer_from_client_buffer
;
827 drv
->API
.DestroySurface
= egl_g3d_destroy_surface
;
828 drv
->API
.MakeCurrent
= egl_g3d_make_current
;
829 drv
->API
.SwapBuffers
= egl_g3d_swap_buffers
;
830 drv
->API
.CopyBuffers
= egl_g3d_copy_buffers
;
831 drv
->API
.WaitClient
= egl_g3d_wait_client
;
832 drv
->API
.WaitNative
= egl_g3d_wait_native
;
834 drv
->API
.BindTexImage
= egl_g3d_bind_tex_image
;
835 drv
->API
.ReleaseTexImage
= egl_g3d_release_tex_image
;
837 drv
->API
.CreateImageKHR
= egl_g3d_create_image
;
838 drv
->API
.DestroyImageKHR
= egl_g3d_destroy_image
;
839 #ifdef EGL_MESA_drm_image
840 drv
->API
.CreateDRMImageMESA
= egl_g3d_create_drm_image
;
841 drv
->API
.ExportDRMImageMESA
= egl_g3d_export_drm_image
;
844 #ifdef EGL_KHR_reusable_sync
845 drv
->API
.CreateSyncKHR
= egl_g3d_create_sync
;
846 drv
->API
.DestroySyncKHR
= egl_g3d_destroy_sync
;
847 drv
->API
.ClientWaitSyncKHR
= egl_g3d_client_wait_sync
;
848 drv
->API
.SignalSyncKHR
= egl_g3d_signal_sync
;
851 #ifdef EGL_MESA_screen_surface
852 drv
->API
.CreateScreenSurfaceMESA
= egl_g3d_create_screen_surface
;
853 drv
->API
.ShowScreenSurfaceMESA
= egl_g3d_show_screen_surface
;