This is a reimplementation of the EGL_MESA_gallium extension over egl_g3d.
It is much simpler and cleaner than the older patch I posted to the list, which 
should be disregarded.
GLX support is not implemented. It may be added later to an eventual GLX API 
implementation over the egl_g3d core.

The API is changed and eglGetGalliumSurfacesMESA is replaced with 
eglGetGalliumTexturesMESA.

Each of the three API functions directly maps to egl_g3d functionality, and the 
functions are each implemented with two lines of code:
eglGetGalliumScreenMESA -> gdpy->native->screen
eglCreateGalliumScreenMESA -> gdpy->native->create_context(...)
eglGetGalliumTexturesMESA -> gsurf->native->validate(...)

Note that the two egl_g3d validation patches are necessary to make 
eglGetGalliumTexturesMESA work properly.

I think the simplicity of the implementation shows that this is the right 
approach as opposed to inventing a Gallium "state tracker".
Of course, once Gallium makes a new stable release, the API could be versioned 
with a "compatibility identity" module on top.

This patch removes the egl_g3d code that discards configs not supported by any 
API since they can still be used with direct Gallium access.
---
 include/EGL/eglext.h                               |   26 +++++++++++++
 src/egl/main/eglapi.c                              |   40 +++++++++++++++++++-
 src/egl/main/eglapi.h                              |   11 +++++
 src/egl/main/egldisplay.h                          |    1 +
 src/egl/main/eglmisc.c                             |    2 +
 .../state_trackers/egl_g3d/common/egl_g3d.c        |   37 ++++++++++++++++--
 6 files changed, 111 insertions(+), 6 deletions(-)

diff --git a/include/EGL/eglext.h b/include/EGL/eglext.h
index b65f7f2..68f732f 100644
--- a/include/EGL/eglext.h
+++ b/include/EGL/eglext.h
@@ -179,6 +179,32 @@ typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOPYCONTEXTMESA) 
(EGLDisplay dpy, EGLCont
 
 #endif /* EGL_MESA_copy_context */
 
+/* EGL_MESA_gallium  >>> PRELIMINARY <<< */
+#ifndef EGL_MESA_gallium
+#define EGL_MESA_gallium 1
+
+struct pipe_screen;
+struct pipe_context;
+struct pipe_texture;
+
+#define EGL_GALLIUM_FRONT_LEFT_MESA 0
+#define EGL_GALLIUM_BACK_LEFT_MESA 1
+#define EGL_GALLIUM_FRONT_RIGHT_MESA 2
+#define EGL_GALLIUM_BACK_RIGHT_MESA 3
+#define EGL_GALLIUM_DEPTH_STENCIL_MESA 4
+
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI struct pipe_screen* EGLAPIENTRY eglGetGalliumScreenMESA(EGLDisplay dpy);
+EGLAPI struct pipe_context* EGLAPIENTRY eglCreateGalliumContextMESA(EGLDisplay 
dpy);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetGalliumTexturesMESA(EGLDisplay* dpy, 
EGLSurface surface, EGLint count, EGLint* attachments, struct pipe_texture** 
textures, EGLint* width, EGLint* height, EGLint* seq_num);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+
+typedef struct pipe_screen* (EGLAPIENTRYP 
PFNEGLGETGALLIUMSCREENMESA)(EGLDisplay dpy);
+typedef struct pipe_context* (EGLAPIENTRYP 
PFNEGLCREATEGALLIUMCONTEXTMESA)(EGLDisplay dpy);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETGALLIUMTEXTURESMESA)(EGLDisplay* 
dpy, EGLSurface surface, EGLint count, EGLint* attachments, struct 
pipe_texture** textures, EGLint* width, EGLint* height, EGLint* seq_num);
+
+#endif /* EGL_MESA_gallium */
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 14cc5fa..6ae123c 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -538,12 +538,15 @@ eglSwapInterval(EGLDisplay dpy, EGLint interval)
 EGLBoolean EGLAPIENTRY
 eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
 {
-   _EGLContext *ctx = _eglGetCurrentContext();
+   /* remove binding requirement for EGL_MESA_gallium */
+   /* _EGLContext *ctx = _eglGetCurrentContext(); */
    _EGL_DECLARE_DD_AND_SURFACE(dpy, surface);
 
    /* surface must be bound to current context in EGL 1.4 */
+   /*
    if (!ctx || !_eglIsContextLinked(ctx) || surf != ctx->DrawSurface)
       return _eglError(EGL_BAD_SURFACE, __FUNCTION__);
+   */
 
    return drv->API.SwapBuffers(drv, disp, surf);
 }
@@ -991,5 +994,40 @@ eglReleaseThread(void)
    return EGL_TRUE;
 }
 
+struct pipe_screen* eglGetGalliumScreenMESA(EGLDisplay dpy)
+{
+   _EGLDisplay *disp = _eglLookupDisplay(dpy);
+   _EGLDriver *drv = _eglCheckDisplay(disp, __FUNCTION__);
+   if (!drv)
+      return 0;
+
+   return drv->API.GetGalliumScreenMESA ? drv->API.GetGalliumScreenMESA(drv, 
disp) : 0;
+}
+
+struct pipe_context* eglCreateGalliumContextMESA(EGLDisplay dpy)
+{
+   _EGLDisplay *disp = _eglLookupDisplay(dpy);
+   _EGLDriver *drv = _eglCheckDisplay(disp, __FUNCTION__);
+   if (!drv)
+      return 0;
+
+   return drv->API.CreateGalliumContextMESA ? 
drv->API.CreateGalliumContextMESA(drv, disp) : 0;
+}
+
+EGLBoolean eglGetGalliumTexturesMESA(EGLDisplay* dpy, EGLSurface surface, 
EGLint count, EGLint* attachments, struct pipe_texture** textures, EGLint* 
width, EGLint* height, EGLint* seq_num)
+{
+   _EGLDisplay *disp = _eglLookupDisplay(dpy);
+   _EGLDriver *drv = _eglCheckDisplay(disp, __FUNCTION__);
+   _EGLSurface* surf;
+
+   if (!drv || !drv->API.GetGalliumTexturesMESA)
+      return EGL_FALSE;
+
+   surf = _eglLookupSurface(surface, disp);
+   if(!surf)
+      return EGL_FALSE;
+
+   return drv->API.GetGalliumTexturesMESA(drv, disp, surf, count, attachments, 
textures, width, height, seq_num);
+}
 
 #endif /* EGL_VERSION_1_2 */
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index aa0abe3..13e8f13 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -69,6 +69,13 @@ typedef _EGLSurface 
*(*CreatePbufferFromClientBuffer_t)(_EGLDriver *drv, _EGLDis
 #endif /* EGL_VERSION_1_2 */
 
 
+struct pipe_screen;
+struct pipe_context;
+struct pipe_surface;
+typedef struct pipe_screen* (*GetGalliumScreenMESA_t)(_EGLDriver *drv, 
_EGLDisplay *dpy);
+typedef struct pipe_context* (*CreateGalliumContextMESA_t)(_EGLDriver *drv, 
_EGLDisplay *dpy);
+typedef EGLBoolean (*GetGalliumTexturesMESA_t)(_EGLDriver *drv, _EGLDisplay* 
dpy, _EGLSurface* surf, EGLint count, EGLint* attachments, struct 
pipe_texture** textures, EGLint* width, EGLint* height, EGLint* seq_num);
+
 
 /**
  * The API dispatcher jumps through these functions
@@ -120,6 +127,10 @@ struct _egl_api
 
 #ifdef EGL_VERSION_1_2
    CreatePbufferFromClientBuffer_t CreatePbufferFromClientBuffer;
+
+   GetGalliumScreenMESA_t GetGalliumScreenMESA;
+   CreateGalliumContextMESA_t CreateGalliumContextMESA;
+   GetGalliumTexturesMESA_t GetGalliumTexturesMESA;
 #endif
 };
 
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index ea4e35a..c711ca3 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -14,6 +14,7 @@ struct _egl_extensions
 {
    EGLBoolean MESA_screen_surface;
    EGLBoolean MESA_copy_context;
+   EGLBoolean MESA_gallium;
 
    char String[_EGL_MAX_EXTENSIONS_LEN];
 };
diff --git a/src/egl/main/eglmisc.c b/src/egl/main/eglmisc.c
index e669133..e2ca56d 100644
--- a/src/egl/main/eglmisc.c
+++ b/src/egl/main/eglmisc.c
@@ -54,6 +54,8 @@ _eglUpdateExtensionsString(_EGLDisplay *dpy)
       strcat(exts, "EGL_MESA_screen_surface ");
    if (dpy->Extensions.MESA_copy_context)
       strcat(exts, "EGL_MESA_copy_context ");
+   if (dpy->Extensions.MESA_gallium)
+         strcat(exts, "EGL_MESA_gallium");
    assert(strlen(exts) < _EGL_MAX_EXTENSIONS_LEN);
 }
 
diff --git a/src/gallium/state_trackers/egl_g3d/common/egl_g3d.c 
b/src/gallium/state_trackers/egl_g3d/common/egl_g3d.c
index 480f5a7..2eae4e9 100644
--- a/src/gallium/state_trackers/egl_g3d/common/egl_g3d.c
+++ b/src/gallium/state_trackers/egl_g3d/common/egl_g3d.c
@@ -349,11 +349,6 @@ egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, 
EGLint id)
       EGLBoolean valid;
 
       api_mask = get_mode_api_mask(&native_configs[i]->mode, gdrv->api_mask);
-      if (!api_mask) {
-         _eglLog(_EGL_DEBUG, "no state tracker supports config 0x%x",
-               native_configs[i]->mode.visualID);
-         continue;
-      }
 
       gconf = CALLOC_STRUCT(egl_g3d_config);
       if (!gconf)
@@ -444,6 +439,8 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy,
    *major = 1;
    *minor = 4;
 
+   dpy->Extensions.MESA_gallium = EGL_TRUE;
+
    return EGL_TRUE;
 
 fail:
@@ -856,6 +853,32 @@ egl_g3d_unload(_EGLDriver *drv)
    free(gdrv);
 }
 
+
+static struct pipe_screen*
+egl_g3d_get_gallium_screen(_EGLDriver *drv, _EGLDisplay *dpy)
+{
+       struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+       return gdpy->native->screen;
+}
+
+static struct pipe_context*
+egl_g3d_create_gallium_context(_EGLDriver *drv, _EGLDisplay *dpy)
+{
+       struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+       return gdpy->native->create_context(gdpy->native, 0);
+}
+
+static EGLBoolean
+egl_g3d_get_gallium_textures(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface* 
surf, EGLint count, EGLint* attachments, struct pipe_texture** textures, 
EGLint* width, EGLint* height, EGLint* seq_num)
+{
+       struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
+       gsurf->native->validate(gsurf->native,
+                   (enum native_attachment*)attachments, count,
+                   textures,
+                   width, height, seq_num);
+       return EGL_TRUE;
+}
+
 _EGLDriver *
 _eglMain(const char *args)
 {
@@ -889,6 +912,10 @@ _eglMain(const char *args)
    gdrv->base.API.BindTexImage = egl_g3d_bind_tex_image;
    gdrv->base.API.ReleaseTexImage = egl_g3d_release_tex_image;
 
+   gdrv->base.API.GetGalliumScreenMESA = egl_g3d_get_gallium_screen;
+   gdrv->base.API.CreateGalliumContextMESA = egl_g3d_create_gallium_context;
+   gdrv->base.API.GetGalliumTexturesMESA = egl_g3d_get_gallium_textures;
+
    gdrv->base.Name = driver_name;
    gdrv->base.Unload = egl_g3d_unload;
 
-- 
1.6.3.3


------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Mesa3d-dev mailing list
Mesa3d-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to