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_compare_config(const _EGLConfig
*conf1
, const _EGLConfig
*conf2
,
104 const _EGLConfig
*criteria
= (const _EGLConfig
*) priv_data
;
106 /* EGL_NATIVE_VISUAL_TYPE ignored? */
107 return _eglCompareConfigs(conf1
, conf2
, criteria
, EGL_TRUE
);
111 egl_g3d_match_config(const _EGLConfig
*conf
, const _EGLConfig
*criteria
)
113 if (!_eglMatchConfig(conf
, criteria
))
116 if (criteria
->MatchNativePixmap
!= EGL_NONE
&&
117 criteria
->MatchNativePixmap
!= EGL_DONT_CARE
) {
118 struct egl_g3d_display
*gdpy
= egl_g3d_display(conf
->Display
);
119 struct egl_g3d_config
*gconf
= egl_g3d_config(conf
);
120 EGLNativePixmapType pix
=
121 (EGLNativePixmapType
) criteria
->MatchNativePixmap
;
123 if (!gdpy
->native
->is_pixmap_supported(gdpy
->native
, pix
, gconf
->native
))
131 egl_g3d_choose_config(_EGLDriver
*drv
, _EGLDisplay
*dpy
, const EGLint
*attribs
,
132 EGLConfig
*configs
, EGLint size
, EGLint
*num_configs
)
134 _EGLConfig
**tmp_configs
, criteria
;
138 return _eglError(EGL_BAD_PARAMETER
, "eglChooseConfigs");
140 if (!_eglParseConfigAttribList(&criteria
, dpy
, attribs
))
141 return _eglError(EGL_BAD_ATTRIBUTE
, "eglChooseConfig");
143 tmp_configs
= (_EGLConfig
**) _eglFilterArray(dpy
->Configs
, &tmp_size
,
144 (_EGLArrayForEach
) egl_g3d_match_config
, (void *) &criteria
);
146 return _eglError(EGL_BAD_ALLOC
, "eglChooseConfig(out of memory)");
148 /* perform sorting of configs */
149 if (tmp_configs
&& tmp_size
) {
150 _eglSortConfigs((const _EGLConfig
**) tmp_configs
, tmp_size
,
151 egl_g3d_compare_config
, (void *) &criteria
);
152 size
= MIN2(tmp_size
, size
);
153 for (i
= 0; i
< size
; i
++)
154 configs
[i
] = _eglGetConfigHandle(tmp_configs
[i
]);
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 gsurf
->stvis
.render_buffer
= ST_ATTACHMENT_FRONT_LEFT
;
318 gsurf
->stfbi
= egl_g3d_create_st_framebuffer(&gsurf
->base
);
320 nsurf
->destroy(nsurf
);
325 nsurf
->user_data
= &gsurf
->base
;
326 gsurf
->native
= nsurf
;
332 egl_g3d_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
333 _EGLConfig
*conf
, EGLNativeWindowType win
,
334 const EGLint
*attribs
)
336 struct egl_g3d_create_surface_arg arg
;
338 memset(&arg
, 0, sizeof(arg
));
339 arg
.type
= EGL_WINDOW_BIT
;
342 return egl_g3d_create_surface(drv
, dpy
, conf
, &arg
, attribs
);
346 egl_g3d_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
347 _EGLConfig
*conf
, EGLNativePixmapType pix
,
348 const EGLint
*attribs
)
350 struct egl_g3d_create_surface_arg arg
;
352 memset(&arg
, 0, sizeof(arg
));
353 arg
.type
= EGL_PIXMAP_BIT
;
356 return egl_g3d_create_surface(drv
, dpy
, conf
, &arg
, attribs
);
359 static struct egl_g3d_surface
*
360 create_pbuffer_surface(_EGLDisplay
*dpy
, _EGLConfig
*conf
,
361 const EGLint
*attribs
, const char *func
)
363 struct egl_g3d_config
*gconf
= egl_g3d_config(conf
);
364 struct egl_g3d_surface
*gsurf
;
366 gsurf
= CALLOC_STRUCT(egl_g3d_surface
);
368 _eglError(EGL_BAD_ALLOC
, func
);
372 if (!_eglInitSurface(&gsurf
->base
, dpy
, EGL_PBUFFER_BIT
, conf
, attribs
)) {
377 gsurf
->stvis
= gconf
->stvis
;
379 gsurf
->stfbi
= egl_g3d_create_st_framebuffer(&gsurf
->base
);
389 egl_g3d_create_pbuffer_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
390 _EGLConfig
*conf
, const EGLint
*attribs
)
392 struct egl_g3d_surface
*gsurf
;
393 struct pipe_resource
*ptex
= NULL
;
395 gsurf
= create_pbuffer_surface(dpy
, conf
, attribs
,
396 "eglCreatePbufferSurface");
400 gsurf
->client_buffer_type
= EGL_NONE
;
402 if (!gsurf
->stfbi
->validate(gsurf
->stfbi
,
403 &gsurf
->stvis
.render_buffer
, 1, &ptex
)) {
404 egl_g3d_destroy_st_framebuffer(gsurf
->stfbi
);
413 egl_g3d_create_pbuffer_from_client_buffer(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
415 EGLClientBuffer buffer
,
417 const EGLint
*attribs
)
419 struct egl_g3d_surface
*gsurf
;
420 struct pipe_resource
*ptex
= NULL
;
421 EGLint pbuffer_attribs
[32];
425 case EGL_OPENVG_IMAGE
:
428 _eglError(EGL_BAD_PARAMETER
, "eglCreatePbufferFromClientBuffer");
433 /* parse the attributes first */
435 for (i
= 0; attribs
&& attribs
[i
] != EGL_NONE
; i
++) {
436 EGLint attr
= attribs
[i
++];
437 EGLint val
= attribs
[i
];
438 EGLint err
= EGL_SUCCESS
;
441 case EGL_TEXTURE_FORMAT
:
442 case EGL_TEXTURE_TARGET
:
443 case EGL_MIPMAP_TEXTURE
:
444 pbuffer_attribs
[count
++] = attr
;
445 pbuffer_attribs
[count
++] = val
;
448 err
= EGL_BAD_ATTRIBUTE
;
452 if (err
!= EGL_SUCCESS
) {
453 _eglError(err
, "eglCreatePbufferFromClientBuffer");
458 pbuffer_attribs
[count
++] = EGL_NONE
;
460 gsurf
= create_pbuffer_surface(dpy
, conf
, pbuffer_attribs
,
461 "eglCreatePbufferFromClientBuffer");
465 gsurf
->client_buffer_type
= buftype
;
466 gsurf
->client_buffer
= buffer
;
468 if (!gsurf
->stfbi
->validate(gsurf
->stfbi
,
469 &gsurf
->stvis
.render_buffer
, 1, &ptex
)) {
470 egl_g3d_destroy_st_framebuffer(gsurf
->stfbi
);
482 destroy_surface(_EGLDisplay
*dpy
, _EGLSurface
*surf
)
484 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
486 /* FIXME a surface might live longer than its display */
487 if (!dpy
->Initialized
)
488 _eglLog(_EGL_FATAL
, "destroy a surface with an unitialized display");
490 pipe_resource_reference(&gsurf
->render_texture
, NULL
);
491 egl_g3d_destroy_st_framebuffer(gsurf
->stfbi
);
493 gsurf
->native
->destroy(gsurf
->native
);
498 egl_g3d_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
500 if (_eglPutSurface(surf
))
501 destroy_surface(dpy
, surf
);
506 egl_g3d_make_current(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
507 _EGLSurface
*draw
, _EGLSurface
*read
, _EGLContext
*ctx
)
509 struct egl_g3d_context
*gctx
= egl_g3d_context(ctx
);
510 struct egl_g3d_surface
*gdraw
= egl_g3d_surface(draw
);
511 struct egl_g3d_surface
*gread
= egl_g3d_surface(read
);
512 struct egl_g3d_context
*old_gctx
;
513 _EGLContext
*old_ctx
;
514 _EGLSurface
*old_draw
, *old_read
;
515 EGLBoolean ok
= EGL_TRUE
;
517 /* make new bindings */
518 if (!_eglBindContext(ctx
, draw
, read
, &old_ctx
, &old_draw
, &old_read
))
521 old_gctx
= egl_g3d_context(old_ctx
);
523 /* flush old context */
524 old_gctx
->stctxi
->flush(old_gctx
->stctxi
,
525 PIPE_FLUSH_RENDER_CACHE
| PIPE_FLUSH_FRAME
, NULL
);
529 ok
= gctx
->stapi
->make_current(gctx
->stapi
, gctx
->stctxi
,
530 (gdraw
) ? gdraw
->stfbi
: NULL
, (gread
) ? gread
->stfbi
: NULL
);
533 gctx
->stctxi
->notify_invalid_framebuffer(gctx
->stctxi
,
536 if (gdraw
->base
.Type
== EGL_WINDOW_BIT
) {
537 gctx
->base
.WindowRenderBuffer
=
538 (gdraw
->stvis
.render_buffer
== ST_ATTACHMENT_FRONT_LEFT
) ?
539 EGL_SINGLE_BUFFER
: EGL_BACK_BUFFER
;
542 if (gread
&& gread
!= gdraw
) {
543 gctx
->stctxi
->notify_invalid_framebuffer(gctx
->stctxi
,
549 ok
= old_gctx
->stapi
->make_current(old_gctx
->stapi
, NULL
, NULL
, NULL
);
551 old_gctx
->base
.WindowRenderBuffer
= EGL_NONE
;
555 if (_eglPutContext(old_ctx
))
556 destroy_context(dpy
, old_ctx
);
557 if (_eglPutSurface(old_draw
))
558 destroy_surface(dpy
, old_draw
);
559 if (_eglPutSurface(old_read
))
560 destroy_surface(dpy
, old_read
);
563 /* undo the previous _eglBindContext */
564 _eglBindContext(old_ctx
, old_draw
, old_read
, &ctx
, &draw
, &read
);
565 assert(&gctx
->base
== ctx
&&
566 &gdraw
->base
== draw
&&
567 &gread
->base
== read
);
569 _eglPutSurface(draw
);
570 _eglPutSurface(read
);
573 _eglPutSurface(old_draw
);
574 _eglPutSurface(old_read
);
575 _eglPutContext(old_ctx
);
582 egl_g3d_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
584 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
585 _EGLContext
*ctx
= _eglGetCurrentContext();
586 struct egl_g3d_context
*gctx
= NULL
;
588 /* no-op for pixmap or pbuffer surface */
589 if (gsurf
->base
.Type
== EGL_PIXMAP_BIT
||
590 gsurf
->base
.Type
== EGL_PBUFFER_BIT
)
593 /* or when the surface is single-buffered */
594 if (gsurf
->stvis
.render_buffer
== ST_ATTACHMENT_FRONT_LEFT
)
597 if (ctx
&& ctx
->DrawSurface
== surf
)
598 gctx
= egl_g3d_context(ctx
);
600 /* flush if the surface is current */
602 gctx
->stctxi
->flush(gctx
->stctxi
,
603 PIPE_FLUSH_RENDER_CACHE
| PIPE_FLUSH_FRAME
, NULL
);
606 return gsurf
->native
->present(gsurf
->native
,
607 NATIVE_ATTACHMENT_BACK_LEFT
,
608 gsurf
->base
.SwapBehavior
== EGL_BUFFER_PRESERVED
,
609 gsurf
->base
.SwapInterval
);
613 * Get the pipe surface of the given attachment of the native surface.
615 static struct pipe_resource
*
616 get_pipe_resource(struct native_display
*ndpy
, struct native_surface
*nsurf
,
617 enum native_attachment natt
)
619 struct pipe_resource
*textures
[NUM_NATIVE_ATTACHMENTS
];
621 textures
[natt
] = NULL
;
622 nsurf
->validate(nsurf
, 1 << natt
, NULL
, textures
, NULL
, NULL
);
624 return textures
[natt
];
628 egl_g3d_copy_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
629 EGLNativePixmapType target
)
631 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
632 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
633 _EGLContext
*ctx
= _eglGetCurrentContext();
634 struct egl_g3d_config
*gconf
;
635 struct native_surface
*nsurf
;
636 struct pipe_resource
*ptex
;
638 if (!gsurf
->render_texture
)
641 gconf
= egl_g3d_config(egl_g3d_find_pixmap_config(dpy
, target
));
643 return _eglError(EGL_BAD_NATIVE_PIXMAP
, "eglCopyBuffers");
645 nsurf
= gdpy
->native
->create_pixmap_surface(gdpy
->native
,
646 target
, gconf
->native
);
648 return _eglError(EGL_BAD_NATIVE_PIXMAP
, "eglCopyBuffers");
650 /* flush if the surface is current */
651 if (ctx
&& ctx
->DrawSurface
== &gsurf
->base
) {
652 struct egl_g3d_context
*gctx
= egl_g3d_context(ctx
);
653 gctx
->stctxi
->flush(gctx
->stctxi
,
654 PIPE_FLUSH_RENDER_CACHE
| PIPE_FLUSH_FRAME
, NULL
);
657 /* create a pipe context to copy surfaces */
660 gdpy
->native
->screen
->context_create(gdpy
->native
->screen
, NULL
);
665 ptex
= get_pipe_resource(gdpy
->native
, nsurf
, NATIVE_ATTACHMENT_FRONT_LEFT
);
667 struct pipe_resource
*psrc
= gsurf
->render_texture
;
668 struct pipe_subresource subsrc
, subdst
;
675 gdpy
->pipe
->resource_copy_region(gdpy
->pipe
, ptex
, subdst
, 0, 0, 0,
676 gsurf
->render_texture
, subsrc
, 0, 0, 0, ptex
->width0
, ptex
->height0
);
677 nsurf
->present(nsurf
, NATIVE_ATTACHMENT_FRONT_LEFT
, FALSE
, 0);
680 pipe_resource_reference(&ptex
, NULL
);
683 nsurf
->destroy(nsurf
);
689 egl_g3d_wait_client(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*ctx
)
691 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
692 struct egl_g3d_context
*gctx
= egl_g3d_context(ctx
);
693 struct pipe_screen
*screen
= gdpy
->native
->screen
;
694 struct pipe_fence_handle
*fence
= NULL
;
696 gctx
->stctxi
->flush(gctx
->stctxi
,
697 PIPE_FLUSH_RENDER_CACHE
| PIPE_FLUSH_FRAME
, &fence
);
699 screen
->fence_finish(screen
, fence
, 0);
700 screen
->fence_reference(screen
, &fence
, NULL
);
707 egl_g3d_wait_native(_EGLDriver
*drv
, _EGLDisplay
*dpy
, EGLint engine
)
709 _EGLContext
*ctx
= _eglGetCurrentContext();
711 if (engine
!= EGL_CORE_NATIVE_ENGINE
)
712 return _eglError(EGL_BAD_PARAMETER
, "eglWaitNative");
714 if (ctx
&& ctx
->DrawSurface
) {
715 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(ctx
->DrawSurface
);
718 gsurf
->native
->wait(gsurf
->native
);
725 egl_g3d_bind_tex_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
726 _EGLSurface
*surf
, EGLint buffer
)
728 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
729 _EGLContext
*es1
= _eglGetAPIContext(EGL_OPENGL_ES_API
);
730 struct egl_g3d_context
*gctx
;
731 enum pipe_format internal_format
;
732 enum st_texture_type target
;
734 if (!gsurf
|| gsurf
->base
.Type
!= EGL_PBUFFER_BIT
)
735 return _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
736 if (buffer
!= EGL_BACK_BUFFER
)
737 return _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
738 if (gsurf
->base
.BoundToTexture
)
739 return _eglError(EGL_BAD_ACCESS
, "eglBindTexImage");
741 switch (gsurf
->base
.TextureFormat
) {
742 case EGL_TEXTURE_RGB
:
743 internal_format
= PIPE_FORMAT_R8G8B8_UNORM
;
745 case EGL_TEXTURE_RGBA
:
746 internal_format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
749 return _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
752 switch (gsurf
->base
.TextureTarget
) {
754 target
= ST_TEXTURE_2D
;
757 return _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
762 if (!gsurf
->render_texture
)
765 /* flush properly if the surface is bound */
766 if (gsurf
->base
.CurrentContext
) {
767 gctx
= egl_g3d_context(gsurf
->base
.CurrentContext
);
768 gctx
->stctxi
->flush(gctx
->stctxi
,
769 PIPE_FLUSH_RENDER_CACHE
| PIPE_FLUSH_FRAME
, NULL
);
772 gctx
= egl_g3d_context(es1
);
773 if (gctx
->stctxi
->teximage
) {
774 if (!gctx
->stctxi
->teximage(gctx
->stctxi
, target
,
775 gsurf
->base
.MipmapLevel
, internal_format
,
776 gsurf
->render_texture
, gsurf
->base
.MipmapTexture
))
778 gsurf
->base
.BoundToTexture
= EGL_TRUE
;
785 egl_g3d_release_tex_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
786 _EGLSurface
*surf
, EGLint buffer
)
788 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
790 if (!gsurf
|| gsurf
->base
.Type
!= EGL_PBUFFER_BIT
||
791 !gsurf
->base
.BoundToTexture
)
792 return _eglError(EGL_BAD_SURFACE
, "eglReleaseTexImage");
793 if (buffer
!= EGL_BACK_BUFFER
)
794 return _eglError(EGL_BAD_PARAMETER
, "eglReleaseTexImage");
796 if (gsurf
->render_texture
) {
797 _EGLContext
*ctx
= _eglGetAPIContext(EGL_OPENGL_ES_API
);
798 struct egl_g3d_context
*gctx
= egl_g3d_context(ctx
);
800 /* what if the context the surface binds to is no longer current? */
802 gctx
->stctxi
->teximage(gctx
->stctxi
, ST_TEXTURE_2D
,
803 gsurf
->base
.MipmapLevel
, PIPE_FORMAT_NONE
, NULL
, FALSE
);
807 gsurf
->base
.BoundToTexture
= EGL_FALSE
;
812 #ifdef EGL_MESA_screen_surface
815 egl_g3d_create_screen_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
816 _EGLConfig
*conf
, const EGLint
*attribs
)
818 struct egl_g3d_create_surface_arg arg
;
820 memset(&arg
, 0, sizeof(arg
));
821 arg
.type
= EGL_SCREEN_BIT_MESA
;
823 return egl_g3d_create_surface(drv
, dpy
, conf
, &arg
, attribs
);
827 egl_g3d_show_screen_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
828 _EGLScreen
*scr
, _EGLSurface
*surf
,
831 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
832 struct egl_g3d_screen
*gscr
= egl_g3d_screen(scr
);
833 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
834 struct native_surface
*nsurf
;
835 const struct native_mode
*nmode
;
842 return _eglError(EGL_BAD_MATCH
, "eglShowSurfaceMESA");
843 if (gsurf
->base
.Type
!= EGL_SCREEN_BIT_MESA
)
844 return _eglError(EGL_BAD_SURFACE
, "eglShowScreenSurfaceMESA");
845 if (gsurf
->base
.Width
< mode
->Width
|| gsurf
->base
.Height
< mode
->Height
)
846 return _eglError(EGL_BAD_MATCH
,
847 "eglShowSurfaceMESA(surface smaller than mode size)");
849 /* find the index of the mode */
850 for (idx
= 0; idx
< gscr
->base
.NumModes
; idx
++)
851 if (mode
== &gscr
->base
.Modes
[idx
])
853 if (idx
>= gscr
->base
.NumModes
) {
854 return _eglError(EGL_BAD_MODE_MESA
,
855 "eglShowSurfaceMESA(unknown mode)");
858 nsurf
= gsurf
->native
;
859 nmode
= gscr
->native_modes
[idx
];
863 return _eglError(EGL_BAD_MATCH
, "eglShowSurfaceMESA");
865 /* disable the screen */
870 /* TODO surface panning by CRTC choosing */
871 changed
= gdpy
->native
->modeset
->program(gdpy
->native
, 0, nsurf
,
872 gscr
->base
.OriginX
, gscr
->base
.OriginY
, &gscr
->native
, 1, nmode
);
874 gscr
->base
.CurrentSurface
= &gsurf
->base
;
875 gscr
->base
.CurrentMode
= mode
;
881 #endif /* EGL_MESA_screen_surface */
884 * Find a config that supports the pixmap.
887 egl_g3d_find_pixmap_config(_EGLDisplay
*dpy
, EGLNativePixmapType pix
)
889 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
890 struct egl_g3d_config
*gconf
;
893 for (i
= 0; i
< dpy
->Configs
->Size
; i
++) {
894 gconf
= egl_g3d_config((_EGLConfig
*) dpy
->Configs
->Elements
[i
]);
895 if (gdpy
->native
->is_pixmap_supported(gdpy
->native
, pix
, gconf
->native
))
899 return (i
< dpy
->Configs
->Size
) ? &gconf
->base
: NULL
;
903 egl_g3d_init_driver_api(_EGLDriver
*drv
)
905 _eglInitDriverFallbacks(drv
);
907 drv
->API
.ChooseConfig
= egl_g3d_choose_config
;
909 drv
->API
.CreateContext
= egl_g3d_create_context
;
910 drv
->API
.DestroyContext
= egl_g3d_destroy_context
;
911 drv
->API
.CreateWindowSurface
= egl_g3d_create_window_surface
;
912 drv
->API
.CreatePixmapSurface
= egl_g3d_create_pixmap_surface
;
913 drv
->API
.CreatePbufferSurface
= egl_g3d_create_pbuffer_surface
;
914 drv
->API
.CreatePbufferFromClientBuffer
= egl_g3d_create_pbuffer_from_client_buffer
;
915 drv
->API
.DestroySurface
= egl_g3d_destroy_surface
;
916 drv
->API
.MakeCurrent
= egl_g3d_make_current
;
917 drv
->API
.SwapBuffers
= egl_g3d_swap_buffers
;
918 drv
->API
.CopyBuffers
= egl_g3d_copy_buffers
;
919 drv
->API
.WaitClient
= egl_g3d_wait_client
;
920 drv
->API
.WaitNative
= egl_g3d_wait_native
;
922 drv
->API
.BindTexImage
= egl_g3d_bind_tex_image
;
923 drv
->API
.ReleaseTexImage
= egl_g3d_release_tex_image
;
925 drv
->API
.CreateImageKHR
= egl_g3d_create_image
;
926 drv
->API
.DestroyImageKHR
= egl_g3d_destroy_image
;
927 #ifdef EGL_MESA_drm_image
928 drv
->API
.CreateDRMImageMESA
= egl_g3d_create_drm_image
;
929 drv
->API
.ExportDRMImageMESA
= egl_g3d_export_drm_image
;
932 #ifdef EGL_KHR_reusable_sync
933 drv
->API
.CreateSyncKHR
= egl_g3d_create_sync
;
934 drv
->API
.DestroySyncKHR
= egl_g3d_destroy_sync
;
935 drv
->API
.ClientWaitSyncKHR
= egl_g3d_client_wait_sync
;
936 drv
->API
.SignalSyncKHR
= egl_g3d_signal_sync
;
939 #ifdef EGL_MESA_screen_surface
940 drv
->API
.CreateScreenSurfaceMESA
= egl_g3d_create_screen_surface
;
941 drv
->API
.ShowScreenSurfaceMESA
= egl_g3d_show_screen_surface
;