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"
33 #include "util/u_box.h"
36 #include "egl_g3d_api.h"
37 #include "egl_g3d_image.h"
38 #include "egl_g3d_sync.h"
39 #include "egl_g3d_st.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
)
52 *profile
= ST_PROFILE_DEFAULT
;
54 switch (ctx
->ClientAPI
) {
55 case EGL_OPENGL_ES_API
:
56 switch (ctx
->ClientVersion
) {
59 *profile
= ST_PROFILE_OPENGL_ES1
;
63 *profile
= ST_PROFILE_OPENGL_ES2
;
66 _eglLog(_EGL_WARNING
, "unknown client version %d",
78 _eglLog(_EGL_WARNING
, "unknown client API 0x%04x", ctx
->ClientAPI
);
82 stapi
= egl_g3d_get_st_api(drv
, api
);
83 if (stapi
&& !(stapi
->profile_mask
& (1 << *profile
)))
90 egl_g3d_compare_config(const _EGLConfig
*conf1
, const _EGLConfig
*conf2
,
93 const _EGLConfig
*criteria
= (const _EGLConfig
*) priv_data
;
95 /* EGL_NATIVE_VISUAL_TYPE ignored? */
96 return _eglCompareConfigs(conf1
, conf2
, criteria
, EGL_TRUE
);
100 egl_g3d_match_config(const _EGLConfig
*conf
, const _EGLConfig
*criteria
)
102 if (!_eglMatchConfig(conf
, criteria
))
105 if (criteria
->MatchNativePixmap
!= EGL_NONE
&&
106 criteria
->MatchNativePixmap
!= EGL_DONT_CARE
) {
107 struct egl_g3d_display
*gdpy
= egl_g3d_display(conf
->Display
);
108 struct egl_g3d_config
*gconf
= egl_g3d_config(conf
);
109 EGLNativePixmapType pix
=
110 (EGLNativePixmapType
) criteria
->MatchNativePixmap
;
112 if (!gdpy
->native
->is_pixmap_supported(gdpy
->native
, pix
, gconf
->native
))
120 egl_g3d_choose_config(_EGLDriver
*drv
, _EGLDisplay
*dpy
, const EGLint
*attribs
,
121 EGLConfig
*configs
, EGLint size
, EGLint
*num_configs
)
123 _EGLConfig
**tmp_configs
, criteria
;
127 return _eglError(EGL_BAD_PARAMETER
, "eglChooseConfigs");
129 if (!_eglParseConfigAttribList(&criteria
, dpy
, attribs
))
130 return _eglError(EGL_BAD_ATTRIBUTE
, "eglChooseConfig");
132 /* get the number of matched configs */
133 tmp_size
= _eglFilterArray(dpy
->Configs
, NULL
, 0,
134 (_EGLArrayForEach
) egl_g3d_match_config
, (void *) &criteria
);
136 *num_configs
= tmp_size
;
140 tmp_configs
= MALLOC(sizeof(tmp_configs
[0]) * tmp_size
);
142 return _eglError(EGL_BAD_ALLOC
, "eglChooseConfig(out of memory)");
144 /* get the matched configs */
145 _eglFilterArray(dpy
->Configs
, (void **) tmp_configs
, tmp_size
,
146 (_EGLArrayForEach
) egl_g3d_match_config
, (void *) &criteria
);
148 /* perform sorting of configs */
149 if (configs
&& tmp_size
) {
150 _eglSortConfigs((const _EGLConfig
**) tmp_configs
, tmp_size
,
151 egl_g3d_compare_config
, (void *) &criteria
);
152 tmp_size
= MIN2(tmp_size
, size
);
153 for (i
= 0; i
< tmp_size
; i
++)
154 configs
[i
] = _eglGetConfigHandle(tmp_configs
[i
]);
159 *num_configs
= tmp_size
;
165 egl_g3d_create_context(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
166 _EGLContext
*share
, const EGLint
*attribs
)
168 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
169 struct egl_g3d_context
*gshare
= egl_g3d_context(share
);
170 struct egl_g3d_config
*gconf
= egl_g3d_config(conf
);
171 struct egl_g3d_context
*gctx
;
172 struct st_context_attribs stattribs
;
174 gctx
= CALLOC_STRUCT(egl_g3d_context
);
176 _eglError(EGL_BAD_ALLOC
, "eglCreateContext");
180 if (!_eglInitContext(&gctx
->base
, dpy
, conf
, attribs
)) {
185 memset(&stattribs
, 0, sizeof(stattribs
));
187 stattribs
.visual
= gconf
->stvis
;
189 gctx
->stapi
= egl_g3d_choose_st(drv
, &gctx
->base
, &stattribs
.profile
);
195 gctx
->stctxi
= gctx
->stapi
->create_context(gctx
->stapi
, gdpy
->smapi
,
196 &stattribs
, (gshare
) ? gshare
->stctxi
: NULL
);
202 gctx
->stctxi
->st_manager_private
= (void *) &gctx
->base
;
211 destroy_context(_EGLDisplay
*dpy
, _EGLContext
*ctx
)
213 struct egl_g3d_context
*gctx
= egl_g3d_context(ctx
);
215 /* FIXME a context might live longer than its display */
216 if (!dpy
->Initialized
)
217 _eglLog(_EGL_FATAL
, "destroy a context with an unitialized display");
219 gctx
->stctxi
->destroy(gctx
->stctxi
);
225 egl_g3d_destroy_context(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*ctx
)
227 if (_eglPutContext(ctx
))
228 destroy_context(dpy
, ctx
);
232 struct egl_g3d_create_surface_arg
{
235 EGLNativeWindowType win
;
236 EGLNativePixmapType pix
;
241 egl_g3d_create_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
242 struct egl_g3d_create_surface_arg
*arg
,
243 const EGLint
*attribs
)
245 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
246 struct egl_g3d_config
*gconf
= egl_g3d_config(conf
);
247 struct egl_g3d_surface
*gsurf
;
248 struct native_surface
*nsurf
;
253 err
= "eglCreateWindowSurface";
256 err
= "eglCreatePixmapSurface";
258 #ifdef EGL_MESA_screen_surface
259 case EGL_SCREEN_BIT_MESA
:
260 err
= "eglCreateScreenSurface";
264 err
= "eglCreateUnknownSurface";
268 gsurf
= CALLOC_STRUCT(egl_g3d_surface
);
270 _eglError(EGL_BAD_ALLOC
, err
);
274 if (!_eglInitSurface(&gsurf
->base
, dpy
, arg
->type
, conf
, attribs
)) {
279 /* create the native surface */
282 nsurf
= gdpy
->native
->create_window_surface(gdpy
->native
,
283 arg
->u
.win
, gconf
->native
);
286 nsurf
= gdpy
->native
->create_pixmap_surface(gdpy
->native
,
287 arg
->u
.pix
, gconf
->native
);
289 #ifdef EGL_MESA_screen_surface
290 case EGL_SCREEN_BIT_MESA
:
291 /* prefer back buffer (move to _eglInitSurface?) */
292 gsurf
->base
.RenderBuffer
= EGL_BACK_BUFFER
;
293 nsurf
= gdpy
->native
->modeset
->create_scanout_surface(gdpy
->native
,
294 gconf
->native
, gsurf
->base
.Width
, gsurf
->base
.Height
);
306 /* initialize the geometry */
307 if (!nsurf
->validate(nsurf
, 0x0, &gsurf
->sequence_number
, NULL
,
308 &gsurf
->base
.Width
, &gsurf
->base
.Height
)) {
309 nsurf
->destroy(nsurf
);
314 gsurf
->stvis
= gconf
->stvis
;
315 if (gsurf
->base
.RenderBuffer
== EGL_SINGLE_BUFFER
&&
316 gconf
->stvis
.buffer_mask
& ST_ATTACHMENT_FRONT_LEFT_MASK
)
317 gsurf
->stvis
.render_buffer
= ST_ATTACHMENT_FRONT_LEFT
;
319 gsurf
->stfbi
= egl_g3d_create_st_framebuffer(&gsurf
->base
);
321 nsurf
->destroy(nsurf
);
326 nsurf
->user_data
= &gsurf
->base
;
327 gsurf
->native
= nsurf
;
333 egl_g3d_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
334 _EGLConfig
*conf
, EGLNativeWindowType win
,
335 const EGLint
*attribs
)
337 struct egl_g3d_create_surface_arg arg
;
339 memset(&arg
, 0, sizeof(arg
));
340 arg
.type
= EGL_WINDOW_BIT
;
343 return egl_g3d_create_surface(drv
, dpy
, conf
, &arg
, attribs
);
347 egl_g3d_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
348 _EGLConfig
*conf
, EGLNativePixmapType pix
,
349 const EGLint
*attribs
)
351 struct egl_g3d_create_surface_arg arg
;
353 memset(&arg
, 0, sizeof(arg
));
354 arg
.type
= EGL_PIXMAP_BIT
;
357 return egl_g3d_create_surface(drv
, dpy
, conf
, &arg
, attribs
);
360 static struct egl_g3d_surface
*
361 create_pbuffer_surface(_EGLDisplay
*dpy
, _EGLConfig
*conf
,
362 const EGLint
*attribs
, const char *func
)
364 struct egl_g3d_config
*gconf
= egl_g3d_config(conf
);
365 struct egl_g3d_surface
*gsurf
;
367 gsurf
= CALLOC_STRUCT(egl_g3d_surface
);
369 _eglError(EGL_BAD_ALLOC
, func
);
373 if (!_eglInitSurface(&gsurf
->base
, dpy
, EGL_PBUFFER_BIT
, conf
, attribs
)) {
378 gsurf
->stvis
= gconf
->stvis
;
380 gsurf
->stfbi
= egl_g3d_create_st_framebuffer(&gsurf
->base
);
390 egl_g3d_create_pbuffer_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
391 _EGLConfig
*conf
, const EGLint
*attribs
)
393 struct egl_g3d_surface
*gsurf
;
395 gsurf
= create_pbuffer_surface(dpy
, conf
, attribs
,
396 "eglCreatePbufferSurface");
400 gsurf
->client_buffer_type
= EGL_NONE
;
406 egl_g3d_create_pbuffer_from_client_buffer(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
408 EGLClientBuffer buffer
,
410 const EGLint
*attribs
)
412 struct egl_g3d_surface
*gsurf
;
413 struct pipe_resource
*ptex
= NULL
;
414 EGLint pbuffer_attribs
[32];
418 case EGL_OPENVG_IMAGE
:
421 _eglError(EGL_BAD_PARAMETER
, "eglCreatePbufferFromClientBuffer");
426 /* parse the attributes first */
428 for (i
= 0; attribs
&& attribs
[i
] != EGL_NONE
; i
++) {
429 EGLint attr
= attribs
[i
++];
430 EGLint val
= attribs
[i
];
431 EGLint err
= EGL_SUCCESS
;
434 case EGL_TEXTURE_FORMAT
:
435 case EGL_TEXTURE_TARGET
:
436 case EGL_MIPMAP_TEXTURE
:
437 pbuffer_attribs
[count
++] = attr
;
438 pbuffer_attribs
[count
++] = val
;
441 err
= EGL_BAD_ATTRIBUTE
;
445 if (err
!= EGL_SUCCESS
) {
446 _eglError(err
, "eglCreatePbufferFromClientBuffer");
451 pbuffer_attribs
[count
++] = EGL_NONE
;
453 gsurf
= create_pbuffer_surface(dpy
, conf
, pbuffer_attribs
,
454 "eglCreatePbufferFromClientBuffer");
458 gsurf
->client_buffer_type
= buftype
;
459 gsurf
->client_buffer
= buffer
;
461 /* validate now so that it fails if the client buffer is invalid */
462 if (!gsurf
->stfbi
->validate(gsurf
->stfbi
,
463 &gsurf
->stvis
.render_buffer
, 1, &ptex
)) {
464 egl_g3d_destroy_st_framebuffer(gsurf
->stfbi
);
468 pipe_resource_reference(&ptex
, NULL
);
477 destroy_surface(_EGLDisplay
*dpy
, _EGLSurface
*surf
)
479 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
481 /* FIXME a surface might live longer than its display */
482 if (!dpy
->Initialized
)
483 _eglLog(_EGL_FATAL
, "destroy a surface with an unitialized display");
485 pipe_resource_reference(&gsurf
->render_texture
, NULL
);
486 egl_g3d_destroy_st_framebuffer(gsurf
->stfbi
);
488 gsurf
->native
->destroy(gsurf
->native
);
493 egl_g3d_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
495 if (_eglPutSurface(surf
))
496 destroy_surface(dpy
, surf
);
501 egl_g3d_make_current(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
502 _EGLSurface
*draw
, _EGLSurface
*read
, _EGLContext
*ctx
)
504 struct egl_g3d_context
*gctx
= egl_g3d_context(ctx
);
505 struct egl_g3d_surface
*gdraw
= egl_g3d_surface(draw
);
506 struct egl_g3d_surface
*gread
= egl_g3d_surface(read
);
507 struct egl_g3d_context
*old_gctx
;
508 _EGLContext
*old_ctx
;
509 _EGLSurface
*old_draw
, *old_read
;
510 EGLBoolean ok
= EGL_TRUE
;
512 /* make new bindings */
513 if (!_eglBindContext(ctx
, draw
, read
, &old_ctx
, &old_draw
, &old_read
))
516 old_gctx
= egl_g3d_context(old_ctx
);
518 /* flush old context */
519 old_gctx
->stctxi
->flush(old_gctx
->stctxi
, ST_FLUSH_FRONT
, NULL
);
523 ok
= gctx
->stapi
->make_current(gctx
->stapi
, gctx
->stctxi
,
524 (gdraw
) ? gdraw
->stfbi
: NULL
, (gread
) ? gread
->stfbi
: NULL
);
527 gctx
->stctxi
->notify_invalid_framebuffer(gctx
->stctxi
,
530 if (gdraw
->base
.Type
== EGL_WINDOW_BIT
) {
531 gctx
->base
.WindowRenderBuffer
=
532 (gdraw
->stvis
.render_buffer
== ST_ATTACHMENT_FRONT_LEFT
) ?
533 EGL_SINGLE_BUFFER
: EGL_BACK_BUFFER
;
536 if (gread
&& gread
!= gdraw
) {
537 gctx
->stctxi
->notify_invalid_framebuffer(gctx
->stctxi
,
543 ok
= old_gctx
->stapi
->make_current(old_gctx
->stapi
, NULL
, NULL
, NULL
);
545 old_gctx
->base
.WindowRenderBuffer
= EGL_NONE
;
549 if (_eglPutContext(old_ctx
))
550 destroy_context(dpy
, old_ctx
);
551 if (_eglPutSurface(old_draw
))
552 destroy_surface(dpy
, old_draw
);
553 if (_eglPutSurface(old_read
))
554 destroy_surface(dpy
, old_read
);
557 /* undo the previous _eglBindContext */
558 _eglBindContext(old_ctx
, old_draw
, old_read
, &ctx
, &draw
, &read
);
559 assert(&gctx
->base
== ctx
&&
560 &gdraw
->base
== draw
&&
561 &gread
->base
== read
);
563 _eglPutSurface(draw
);
564 _eglPutSurface(read
);
567 _eglPutSurface(old_draw
);
568 _eglPutSurface(old_read
);
569 _eglPutContext(old_ctx
);
576 egl_g3d_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
578 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
579 _EGLContext
*ctx
= _eglGetCurrentContext();
580 struct egl_g3d_context
*gctx
= NULL
;
582 /* no-op for pixmap or pbuffer surface */
583 if (gsurf
->base
.Type
== EGL_PIXMAP_BIT
||
584 gsurf
->base
.Type
== EGL_PBUFFER_BIT
)
587 /* or when the surface is single-buffered */
588 if (gsurf
->stvis
.render_buffer
== ST_ATTACHMENT_FRONT_LEFT
)
591 if (ctx
&& ctx
->DrawSurface
== surf
)
592 gctx
= egl_g3d_context(ctx
);
594 /* flush if the surface is current */
596 gctx
->stctxi
->flush(gctx
->stctxi
, ST_FLUSH_FRONT
, NULL
);
599 return gsurf
->native
->present(gsurf
->native
,
600 NATIVE_ATTACHMENT_BACK_LEFT
,
601 gsurf
->base
.SwapBehavior
== EGL_BUFFER_PRESERVED
,
602 gsurf
->base
.SwapInterval
);
606 egl_g3d_copy_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
607 EGLNativePixmapType target
)
609 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
610 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
611 _EGLContext
*ctx
= _eglGetCurrentContext();
613 if (!gsurf
->render_texture
)
616 /* flush if the surface is current */
617 if (ctx
&& ctx
->DrawSurface
== &gsurf
->base
) {
618 struct egl_g3d_context
*gctx
= egl_g3d_context(ctx
);
619 gctx
->stctxi
->flush(gctx
->stctxi
, ST_FLUSH_FRONT
, NULL
);
622 return gdpy
->native
->copy_to_pixmap(gdpy
->native
,
623 target
, gsurf
->render_texture
);
627 egl_g3d_wait_client(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*ctx
)
629 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
630 struct egl_g3d_context
*gctx
= egl_g3d_context(ctx
);
631 struct pipe_screen
*screen
= gdpy
->native
->screen
;
632 struct pipe_fence_handle
*fence
= NULL
;
634 gctx
->stctxi
->flush(gctx
->stctxi
, ST_FLUSH_FRONT
, &fence
);
636 screen
->fence_finish(screen
, fence
, PIPE_TIMEOUT_INFINITE
);
637 screen
->fence_reference(screen
, &fence
, NULL
);
644 egl_g3d_wait_native(_EGLDriver
*drv
, _EGLDisplay
*dpy
, EGLint engine
)
646 _EGLContext
*ctx
= _eglGetCurrentContext();
648 if (engine
!= EGL_CORE_NATIVE_ENGINE
)
649 return _eglError(EGL_BAD_PARAMETER
, "eglWaitNative");
651 if (ctx
&& ctx
->DrawSurface
) {
652 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(ctx
->DrawSurface
);
655 gsurf
->native
->wait(gsurf
->native
);
662 egl_g3d_bind_tex_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
663 _EGLSurface
*surf
, EGLint buffer
)
665 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
666 _EGLContext
*es1
= _eglGetAPIContext(EGL_OPENGL_ES_API
);
667 struct egl_g3d_context
*gctx
;
668 enum pipe_format internal_format
;
669 enum st_texture_type target
;
671 if (!gsurf
|| gsurf
->base
.Type
!= EGL_PBUFFER_BIT
)
672 return _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
673 if (buffer
!= EGL_BACK_BUFFER
)
674 return _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
675 if (gsurf
->base
.BoundToTexture
)
676 return _eglError(EGL_BAD_ACCESS
, "eglBindTexImage");
678 switch (gsurf
->base
.TextureFormat
) {
679 case EGL_TEXTURE_RGB
:
680 internal_format
= PIPE_FORMAT_R8G8B8_UNORM
;
682 case EGL_TEXTURE_RGBA
:
683 internal_format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
686 return _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
689 switch (gsurf
->base
.TextureTarget
) {
691 target
= ST_TEXTURE_2D
;
694 return _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
699 if (!gsurf
->render_texture
)
702 /* flush properly if the surface is bound */
703 if (gsurf
->base
.CurrentContext
) {
704 gctx
= egl_g3d_context(gsurf
->base
.CurrentContext
);
705 gctx
->stctxi
->flush(gctx
->stctxi
, ST_FLUSH_FRONT
, NULL
);
708 gctx
= egl_g3d_context(es1
);
709 if (gctx
->stctxi
->teximage
) {
710 if (!gctx
->stctxi
->teximage(gctx
->stctxi
, target
,
711 gsurf
->base
.MipmapLevel
, internal_format
,
712 gsurf
->render_texture
, gsurf
->base
.MipmapTexture
))
714 gsurf
->base
.BoundToTexture
= EGL_TRUE
;
721 egl_g3d_release_tex_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
722 _EGLSurface
*surf
, EGLint buffer
)
724 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
726 if (!gsurf
|| gsurf
->base
.Type
!= EGL_PBUFFER_BIT
||
727 !gsurf
->base
.BoundToTexture
)
728 return _eglError(EGL_BAD_SURFACE
, "eglReleaseTexImage");
729 if (buffer
!= EGL_BACK_BUFFER
)
730 return _eglError(EGL_BAD_PARAMETER
, "eglReleaseTexImage");
732 if (gsurf
->render_texture
) {
733 _EGLContext
*ctx
= _eglGetAPIContext(EGL_OPENGL_ES_API
);
734 struct egl_g3d_context
*gctx
= egl_g3d_context(ctx
);
736 /* what if the context the surface binds to is no longer current? */
738 gctx
->stctxi
->teximage(gctx
->stctxi
, ST_TEXTURE_2D
,
739 gsurf
->base
.MipmapLevel
, PIPE_FORMAT_NONE
, NULL
, FALSE
);
743 gsurf
->base
.BoundToTexture
= EGL_FALSE
;
748 #ifdef EGL_MESA_screen_surface
751 egl_g3d_create_screen_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
752 _EGLConfig
*conf
, const EGLint
*attribs
)
754 struct egl_g3d_create_surface_arg arg
;
756 memset(&arg
, 0, sizeof(arg
));
757 arg
.type
= EGL_SCREEN_BIT_MESA
;
759 return egl_g3d_create_surface(drv
, dpy
, conf
, &arg
, attribs
);
763 egl_g3d_show_screen_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
764 _EGLScreen
*scr
, _EGLSurface
*surf
,
767 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
768 struct egl_g3d_screen
*gscr
= egl_g3d_screen(scr
);
769 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
770 struct native_surface
*nsurf
;
771 const struct native_mode
*nmode
;
778 return _eglError(EGL_BAD_MATCH
, "eglShowSurfaceMESA");
779 if (gsurf
->base
.Type
!= EGL_SCREEN_BIT_MESA
)
780 return _eglError(EGL_BAD_SURFACE
, "eglShowScreenSurfaceMESA");
781 if (gsurf
->base
.Width
< mode
->Width
|| gsurf
->base
.Height
< mode
->Height
)
782 return _eglError(EGL_BAD_MATCH
,
783 "eglShowSurfaceMESA(surface smaller than mode size)");
785 /* find the index of the mode */
786 for (idx
= 0; idx
< gscr
->base
.NumModes
; idx
++)
787 if (mode
== &gscr
->base
.Modes
[idx
])
789 if (idx
>= gscr
->base
.NumModes
) {
790 return _eglError(EGL_BAD_MODE_MESA
,
791 "eglShowSurfaceMESA(unknown mode)");
794 nsurf
= gsurf
->native
;
795 nmode
= gscr
->native_modes
[idx
];
799 return _eglError(EGL_BAD_MATCH
, "eglShowSurfaceMESA");
801 /* disable the screen */
806 /* TODO surface panning by CRTC choosing */
807 changed
= gdpy
->native
->modeset
->program(gdpy
->native
, 0, nsurf
,
808 gscr
->base
.OriginX
, gscr
->base
.OriginY
, &gscr
->native
, 1, nmode
);
810 gscr
->base
.CurrentSurface
= &gsurf
->base
;
811 gscr
->base
.CurrentMode
= mode
;
817 #endif /* EGL_MESA_screen_surface */
819 #ifdef EGL_WL_bind_wayland_display
822 egl_g3d_bind_wayland_display_wl(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
823 struct wl_display
*wl_dpy
)
825 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
827 if (!gdpy
->native
->wayland_bufmgr
)
830 return gdpy
->native
->wayland_bufmgr
->bind_display(gdpy
->native
, wl_dpy
);
834 egl_g3d_unbind_wayland_display_wl(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
835 struct wl_display
*wl_dpy
)
837 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
839 if (!gdpy
->native
->wayland_bufmgr
)
842 return gdpy
->native
->wayland_bufmgr
->unbind_display(gdpy
->native
, wl_dpy
);
845 #endif /* EGL_WL_bind_wayland_display */
848 egl_g3d_init_driver_api(_EGLDriver
*drv
)
850 _eglInitDriverFallbacks(drv
);
852 drv
->API
.ChooseConfig
= egl_g3d_choose_config
;
854 drv
->API
.CreateContext
= egl_g3d_create_context
;
855 drv
->API
.DestroyContext
= egl_g3d_destroy_context
;
856 drv
->API
.CreateWindowSurface
= egl_g3d_create_window_surface
;
857 drv
->API
.CreatePixmapSurface
= egl_g3d_create_pixmap_surface
;
858 drv
->API
.CreatePbufferSurface
= egl_g3d_create_pbuffer_surface
;
859 drv
->API
.CreatePbufferFromClientBuffer
= egl_g3d_create_pbuffer_from_client_buffer
;
860 drv
->API
.DestroySurface
= egl_g3d_destroy_surface
;
861 drv
->API
.MakeCurrent
= egl_g3d_make_current
;
862 drv
->API
.SwapBuffers
= egl_g3d_swap_buffers
;
863 drv
->API
.CopyBuffers
= egl_g3d_copy_buffers
;
864 drv
->API
.WaitClient
= egl_g3d_wait_client
;
865 drv
->API
.WaitNative
= egl_g3d_wait_native
;
867 drv
->API
.BindTexImage
= egl_g3d_bind_tex_image
;
868 drv
->API
.ReleaseTexImage
= egl_g3d_release_tex_image
;
870 drv
->API
.CreateImageKHR
= egl_g3d_create_image
;
871 drv
->API
.DestroyImageKHR
= egl_g3d_destroy_image
;
872 #ifdef EGL_MESA_drm_image
873 drv
->API
.CreateDRMImageMESA
= egl_g3d_create_drm_image
;
874 drv
->API
.ExportDRMImageMESA
= egl_g3d_export_drm_image
;
876 #ifdef EGL_WL_bind_wayland_display
877 drv
->API
.BindWaylandDisplayWL
= egl_g3d_bind_wayland_display_wl
;
878 drv
->API
.UnbindWaylandDisplayWL
= egl_g3d_unbind_wayland_display_wl
;
882 #ifdef EGL_KHR_reusable_sync
883 drv
->API
.CreateSyncKHR
= egl_g3d_create_sync
;
884 drv
->API
.DestroySyncKHR
= egl_g3d_destroy_sync
;
885 drv
->API
.ClientWaitSyncKHR
= egl_g3d_client_wait_sync
;
886 drv
->API
.SignalSyncKHR
= egl_g3d_signal_sync
;
889 #ifdef EGL_MESA_screen_surface
890 drv
->API
.CreateScreenSurfaceMESA
= egl_g3d_create_screen_surface
;
891 drv
->API
.ShowScreenSurfaceMESA
= egl_g3d_show_screen_surface
;