dri: Add DRI entrypoints to create a context for a given API
authorKristian Høgsberg <krh@bitplanet.net>
Tue, 27 Apr 2010 15:04:51 +0000 (11:04 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Wed, 28 Apr 2010 18:05:21 +0000 (14:05 -0400)
27 files changed:
include/GL/internal/dri_interface.h
src/mesa/drivers/dri/common/dri_util.c
src/mesa/drivers/dri/common/dri_util.h
src/mesa/drivers/dri/i810/i810context.c
src/mesa/drivers/dri/i810/i810screen.h
src/mesa/drivers/dri/intel/intel_screen.c
src/mesa/drivers/dri/mach64/mach64_context.c
src/mesa/drivers/dri/mach64/mach64_context.h
src/mesa/drivers/dri/mga/mga_xmesa.c
src/mesa/drivers/dri/nouveau/nouveau_context.c
src/mesa/drivers/dri/r128/r128_context.c
src/mesa/drivers/dri/r128/r128_context.h
src/mesa/drivers/dri/r200/r200_context.c
src/mesa/drivers/dri/r200/r200_context.h
src/mesa/drivers/dri/r300/r300_context.c
src/mesa/drivers/dri/r300/r300_context.h
src/mesa/drivers/dri/r600/r600_context.c
src/mesa/drivers/dri/r600/r600_context.h
src/mesa/drivers/dri/radeon/radeon_context.c
src/mesa/drivers/dri/radeon/radeon_context.h
src/mesa/drivers/dri/savage/savage_xmesa.c
src/mesa/drivers/dri/sis/sis_context.c
src/mesa/drivers/dri/sis/sis_context.h
src/mesa/drivers/dri/tdfx/tdfx_context.c
src/mesa/drivers/dri/tdfx/tdfx_context.h
src/mesa/drivers/dri/unichrome/via_context.c
src/mesa/drivers/dri/unichrome/via_screen.h

index fa9b7c4bf2197ad09e6bbfd6c292e1cc8d1bcd0f..4b9264166f9b331b0d365468c25f70f86fe6d895 100644 (file)
@@ -736,7 +736,11 @@ struct __DRIdri2LoaderExtensionRec {
  * constructors for DRI2.
  */
 #define __DRI_DRI2 "DRI_DRI2"
-#define __DRI_DRI2_VERSION 1
+#define __DRI_DRI2_VERSION 2
+
+#define __DRI_API_OPENGL       0
+#define __DRI_API_GLES         1
+#define __DRI_API_GLES2                2
 
 struct __DRIdri2ExtensionRec {
     __DRIextension base;
@@ -755,6 +759,14 @@ struct __DRIdri2ExtensionRec {
                                      __DRIcontext *shared,
                                      void *loaderPrivate);
 
+   /* Since version 2 */
+   unsigned int (*getAPIMask)(__DRIscreen *screen);
+
+   __DRIcontext *(*createNewContextForAPI)(__DRIscreen *screen,
+                                          int api,
+                                          const __DRIconfig *config,
+                                          __DRIcontext *shared,
+                                          void *data);
 };
 
 
index f1bbd38612868381b49ba75dfdbaa547cc111ed8..e08005f90b9a198c5d6b950fe57db9a07bc27fac 100644 (file)
@@ -564,7 +564,8 @@ driCreateNewContext(__DRIscreen *psp, const __DRIconfig *config,
 
     pcp->hHWContext = hwContext;
 
-    if ( !(*psp->DriverAPI.CreateContext)(&config->modes, pcp, shareCtx) ) {
+    if ( !(*psp->DriverAPI.CreateContext)(API_OPENGL,
+                                         &config->modes, pcp, shareCtx) ) {
         free(pcp);
         return NULL;
     }
@@ -572,15 +573,62 @@ driCreateNewContext(__DRIscreen *psp, const __DRIconfig *config,
     return pcp;
 }
 
+static unsigned int
+dri2GetAPIMask(__DRIscreen *screen)
+{
+    return screen->api_mask;
+}
+
+static __DRIcontext *
+dri2CreateNewContextForAPI(__DRIscreen *screen, int api,
+                          const __DRIconfig *config,
+                          __DRIcontext *shared, void *data)
+{
+    __DRIcontext *context;
+    void *shareCtx = (shared != NULL) ? shared->driverPrivate : NULL;
+    gl_api mesa_api;
+
+    if (!(screen->api_mask & (1 << api)))
+       return NULL;
+
+    switch (api) {
+    case __DRI_API_OPENGL:
+           mesa_api = API_OPENGL;
+           break;
+    case __DRI_API_GLES:
+           mesa_api = API_OPENGLES;
+           break;
+    case __DRI_API_GLES2:
+           mesa_api = API_OPENGLES2;
+           break;
+    }
+
+    context = malloc(sizeof *context);
+    if (!context)
+       return NULL;
+
+    context->driScreenPriv = screen;
+    context->driDrawablePriv = NULL;
+    context->loaderPrivate = data;
+    
+    if (!(*screen->DriverAPI.CreateContext)(api, &config->modes,
+                                           context, shareCtx) ) {
+        free(context);
+        return NULL;
+    }
+
+    return context;
+}
+
 
 static __DRIcontext *
 dri2CreateNewContext(__DRIscreen *screen, const __DRIconfig *config,
                      __DRIcontext *shared, void *data)
 {
-    return driCreateNewContext(screen, config, 0, shared, 0, data);
+   return dri2CreateNewContextForAPI(screen, __DRI_API_OPENGL,
+                                    config, shared, data);
 }
 
-
 static int
 driCopyContext(__DRIcontext *dest, __DRIcontext *src, unsigned long mask)
 {
@@ -718,6 +766,7 @@ driCreateNewScreen(int scrn,
     psp->dri2.enabled = GL_FALSE;
 
     psp->DriverAPI = driDriverAPI;
+    psp->api_mask = (1 << __DRI_API_OPENGL);
 
     *driver_modes = driDriverAPI.InitScreen(psp);
     if (*driver_modes == NULL) {
@@ -763,6 +812,7 @@ dri2CreateNewScreen(int scrn, int fd,
     psp->dri2.enabled = GL_TRUE;
 
     psp->DriverAPI = driDriverAPI;
+    psp->api_mask = (1 << __DRI_API_OPENGL);
     *driver_configs = driDriverAPI.InitScreen2(psp);
     if (*driver_configs == NULL) {
        free(psp);
@@ -811,6 +861,8 @@ const __DRIdri2Extension driDRI2Extension = {
     dri2CreateNewScreen,
     dri2CreateNewDrawable,
     dri2CreateNewContext,
+    dri2GetAPIMask,
+    dri2CreateNewContextForAPI
 };
 
 static int
index 038a81604fc3c3e675ebb0a68785bf98db212b45..4b7cd414b8f7896e451d60e41d6a02b2f4c0e63e 100644 (file)
@@ -52,6 +52,7 @@
 #include <drm_sarea.h>
 #include <xf86drm.h>
 #include "main/glheader.h"
+#include "main/mtypes.h"
 #include "GL/internal/glcore.h"
 #include "GL/internal/dri_interface.h"
 
@@ -146,8 +147,9 @@ struct __DriverAPIRec {
     /**
      * Context creation callback
      */                    
-    GLboolean (*CreateContext)(const __GLcontextModes *glVis,
-                               __DRIcontext *driContextPriv,
+    GLboolean (*CreateContext)(gl_api api,
+                              const __GLcontextModes *glVis,
+                              __DRIcontext *driContextPriv,
                                void *sharedContextPrivate);
 
     /**
@@ -527,6 +529,8 @@ struct __DRIscreenRec {
 
     /* The lock actually in use, old sarea or DRI2 */
     drmLock *lock;
+
+   unsigned int api_mask;
 };
 
 extern void
index 34e34606b4b34e4d15d2cdc9c3a9066349e67726..49f3ee88a61dedd1bcfe4a662b931429768a26fa 100644 (file)
@@ -166,7 +166,8 @@ static const struct dri_debug_control debug_control[] =
 };
 
 GLboolean
-i810CreateContext( const __GLcontextModes *mesaVis,
+i810CreateContext( gl_api api,
+                  const __GLcontextModes *mesaVis,
                    __DRIcontext *driContextPriv,
                    void *sharedContextPrivate )
 {
index 734e2fb002d965b401dd63dd8d59055ba55c7fa5..fe6db7e6e1ccfceccad4fcb5b84708a4f1026141 100644 (file)
@@ -78,7 +78,8 @@ typedef struct {
 
 
 extern GLboolean
-i810CreateContext( const __GLcontextModes *mesaVis,
+i810CreateContext( gl_api api,
+                  const __GLcontextModes *mesaVis,
                    __DRIcontext *driContextPriv,
                    void *sharedContextPrivate );
 
index 5e3f40836d04625c56642d2b5c484e779e46a413..b27e7a34a76d525eb97d85f000fc18bfa355b004 100644 (file)
@@ -364,7 +364,8 @@ extern GLboolean brwCreateContext(const __GLcontextModes * mesaVis,
                                  void *sharedContextPrivate);
 
 static GLboolean
-intelCreateContext(const __GLcontextModes * mesaVis,
+intelCreateContext(gl_api api,
+                  const __GLcontextModes * mesaVis,
                    __DRIcontext * driContextPriv,
                    void *sharedContextPrivate)
 {
index 77e7e53ce044edd21aed9ae40a4393986cec10e3..72a44d96424c6cd28fbdebe8d5519ba2afe738ea 100644 (file)
@@ -86,7 +86,8 @@ static const struct dri_extension card_extensions[] =
 
 /* Create the device specific context.
   */
-GLboolean mach64CreateContext( const __GLcontextModes *glVisual,
+GLboolean mach64CreateContext( gl_api api,
+                              const __GLcontextModes *glVisual,
                               __DRIcontext *driContextPriv,
                                void *sharedContextPrivate )
 {
index 18fc859d0132f10a9aae333c0c45617d2a782875..893fc8daee93571361d84b00f5ce22d9898e563d 100644 (file)
@@ -273,7 +273,8 @@ struct mach64_context {
 #define MACH64_CONTEXT(ctx)            ((mach64ContextPtr)(ctx->DriverCtx))
 
 
-extern GLboolean mach64CreateContext( const __GLcontextModes *glVisual,
+extern GLboolean mach64CreateContext( gl_api api,
+                                     const __GLcontextModes *glVisual,
                                      __DRIcontext *driContextPriv,
                                       void *sharedContextPrivate );
 
index 687412bca55674938683f2fee8fa29f7e8d5887e..31007ccb1dacf14e40bd628ed6e13add00e9696d 100644 (file)
@@ -423,7 +423,8 @@ static const struct dri_debug_control debug_control[] =
 
 
 static GLboolean
-mgaCreateContext( const __GLcontextModes *mesaVis,
+mgaCreateContext( gl_api api,
+                 const __GLcontextModes *mesaVis,
                   __DRIcontext *driContextPriv,
                   void *sharedContextPrivate )
 {
index 42bec659d73e1d8dd36daadc09c7f075b42b5894..f481161d468e221b74af0cd2482faf16fd7a71a8 100644 (file)
@@ -75,7 +75,8 @@ nouveau_channel_flush_notify(struct nouveau_channel *chan)
 }
 
 GLboolean
-nouveau_context_create(const __GLcontextModes *visual, __DRIcontext *dri_ctx,
+nouveau_context_create(gl_api api,
+                      const __GLcontextModes *visual, __DRIcontext *dri_ctx,
                       void *share_ctx)
 {
        __DRIscreen *dri_screen = dri_ctx->driScreenPriv;
index 67e92405057697c014b0c922fd0491b64c63cd43..78607083830f0a373933154b4b1f8bd04f4e4dd2 100644 (file)
@@ -99,7 +99,8 @@ static const struct dri_debug_control debug_control[] =
 
 /* Create the device specific context.
  */
-GLboolean r128CreateContext( const __GLcontextModes *glVisual,
+GLboolean r128CreateContext( gl_api api,
+                            const __GLcontextModes *glVisual,
                             __DRIcontext *driContextPriv,
                              void *sharedContextPrivate )
 {
index 65f845c115955f61c26ae5d9411d9494c532de5f..65ddb3bd23bcff540afb4a68c966f1d0d43d02bb 100644 (file)
@@ -224,7 +224,8 @@ struct r128_context {
                (rmesa->r128Screen->chipset == R128_CARD_TYPE_R128_MOBILITY)
 
 
-extern GLboolean r128CreateContext( const __GLcontextModes *glVisual,
+extern GLboolean r128CreateContext( gl_api api,
+                                   const __GLcontextModes *glVisual,
                                    __DRIcontext *driContextPriv,
                                     void *sharedContextPrivate );
 
index 36a29350ccc3f1f7035898ec54875f2472e82d82..5896296021f250618212acfc4afb721eec63e8c5 100644 (file)
@@ -271,7 +271,8 @@ static void r200_init_vtbl(radeonContextPtr radeon)
 
 /* Create the device specific rendering context.
  */
-GLboolean r200CreateContext( const __GLcontextModes *glVisual,
+GLboolean r200CreateContext( gl_api api,
+                            const __GLcontextModes *glVisual,
                             __DRIcontext *driContextPriv,
                             void *sharedContextPrivate)
 {
index a9dce310ae134f369043a5feb2d639d971efdf9a..305958f5d7667a7ac13f63a7a9ecb416a463d578 100644 (file)
@@ -637,7 +637,8 @@ struct r200_context {
 
 
 extern void r200DestroyContext( __DRIcontext *driContextPriv );
-extern GLboolean r200CreateContext( const __GLcontextModes *glVisual,
+extern GLboolean r200CreateContext( gl_api api,
+                                   const __GLcontextModes *glVisual,
                                    __DRIcontext *driContextPriv,
                                    void *sharedContextPrivate);
 extern GLboolean r200MakeCurrent( __DRIcontext *driContextPriv,
index 4dce454c3a757aab7b511ec2d0a4904a2004b662..6992ca59dbf29d9152b3e2131eb83c096f05f740 100644 (file)
@@ -478,7 +478,8 @@ static void r300InitIoctlFuncs(struct dd_function_table *functions)
 
 /* Create the device specific rendering context.
  */
-GLboolean r300CreateContext(const __GLcontextModes * glVisual,
+GLboolean r300CreateContext(gl_api api,
+                           const __GLcontextModes * glVisual,
                            __DRIcontext * driContextPriv,
                            void *sharedContextPrivate)
 {
index df7115e7daef31c2a90e23e5befe61a9a02f1c72..fbb609b9f618a401956e94fd938b1204f95f5b21 100644 (file)
@@ -543,7 +543,8 @@ struct r300_context {
 #define R300_CONTEXT(ctx)              ((r300ContextPtr)(ctx->DriverCtx))
 
 extern void r300DestroyContext(__DRIcontext * driContextPriv);
-extern GLboolean r300CreateContext(const __GLcontextModes * glVisual,
+extern GLboolean r300CreateContext(gl_api api,
+                                  const __GLcontextModes * glVisual,
                                   __DRIcontext * driContextPriv,
                                   void *sharedContextPrivate);
 
index fddac2f9bdc8011c887c954acb254e8308ca0ab5..9f8923f09dcd4cb3a764441ce1bc81840cd2142d 100644 (file)
@@ -353,7 +353,8 @@ static void r600InitGLExtensions(GLcontext *ctx)
 
 /* Create the device specific rendering context.
  */
-GLboolean r600CreateContext(const __GLcontextModes * glVisual,
+GLboolean r600CreateContext(gl_api api,
+                           const __GLcontextModes * glVisual,
                            __DRIcontext * driContextPriv,
                            void *sharedContextPrivate)
 {
index 72c8c869b702eab92b4dcbbd7a3c8a2d2208b405..063dd7c49a1a702f45aa8f00a25e8f0a2a23902c 100644 (file)
@@ -155,7 +155,8 @@ struct r600_context {
 #define R700_CONTEXT(ctx)              ((context_t *)(ctx->DriverCtx))
 #define GL_CONTEXT(context)     ((GLcontext *)(context->radeon.glCtx))
 
-extern GLboolean r600CreateContext(const __GLcontextModes * glVisual,
+extern GLboolean r600CreateContext(gl_api api,
+                                  const __GLcontextModes * glVisual,
                                   __DRIcontext * driContextPriv,
                                   void *sharedContextPrivate);
 
index 56aba16e9e097f10ed2c146f7d1cc446dc9be3b1..ee65d7ff3d06ca364886fd39d149b60b3aba61a5 100644 (file)
@@ -206,9 +206,10 @@ static void r100_init_vtbl(radeonContextPtr radeon)
 /* Create the device specific context.
  */
 GLboolean
-r100CreateContext( const __GLcontextModes *glVisual,
-                     __DRIcontext *driContextPriv,
-                     void *sharedContextPrivate)
+r100CreateContext( gl_api api,
+                  const __GLcontextModes *glVisual,
+                  __DRIcontext *driContextPriv,
+                  void *sharedContextPrivate)
 {
    __DRIscreen *sPriv = driContextPriv->driScreenPriv;
    radeonScreenPtr screen = (radeonScreenPtr)(sPriv->private);
index d84760bf74fce146032a120e75dda70b75a82a9a..c4bfbfdaeb3f9022b11dd158f1da96f38ec34fe1 100644 (file)
@@ -450,7 +450,8 @@ struct r100_context {
 
 #define RADEON_OLD_PACKETS 1
 
-extern GLboolean r100CreateContext( const __GLcontextModes *glVisual,
+extern GLboolean r100CreateContext( gl_api api,
+                                   const __GLcontextModes *glVisual,
                                    __DRIcontext *driContextPriv,
                                    void *sharedContextPrivate);
 
index c3a53ea5e258d815e2fee9fb087bdc79fa2f8d4d..cbdc9c87eebb720d91df9fb6bee3f54efd49abb8 100644 (file)
@@ -288,7 +288,8 @@ savageDestroyScreen(__DRIscreen *sPriv)
 }
 
 static GLboolean
-savageCreateContext( const __GLcontextModes *mesaVis,
+savageCreateContext( gl_api api,
+                    const __GLcontextModes *mesaVis,
                     __DRIcontext *driContextPriv,
                     void *sharedContextPrivate )
 {
index 400681a04ab8a6fadae54ea6d80f3501a640b0b9..85f26a08b7f458e1a4b6b5d913a3e6bc472bb5c1 100644 (file)
@@ -158,7 +158,8 @@ void sisReAllocateBuffers(GLcontext *ctx, GLframebuffer *drawbuffer,
 }
 
 GLboolean
-sisCreateContext( const __GLcontextModes *glVisual,
+sisCreateContext( gl_api api,
+                 const __GLcontextModes *glVisual,
                  __DRIcontext *driContextPriv,
                   void *sharedContextPrivate )
 {
index 4179ee081a7572d3ce79d783fc204c44c6bb98a6..132cee33ee3df4542b9bff6e236d3e0d395d8caa 100644 (file)
@@ -438,7 +438,8 @@ enum _sis_verbose {
        VERBOSE_SIS_MEMORY  = 0x2
 };
 
-extern GLboolean sisCreateContext( const __GLcontextModes *glVisual,
+extern GLboolean sisCreateContext( gl_api api,
+                                  const __GLcontextModes *glVisual,
                                   __DRIcontext *driContextPriv,
                                    void *sharedContextPrivate );
 extern void sisDestroyContext( __DRIcontext * );
index edb1875f767f9f5a5e6eb21eb60b91725f5c3d9d..c30fcf3a6f703dfe5c64c9a2f6f953044eb697ea 100644 (file)
@@ -164,7 +164,8 @@ static const struct dri_debug_control debug_control[] =
     { NULL,    0 }
 };
 
-GLboolean tdfxCreateContext( const __GLcontextModes *mesaVis,
+GLboolean tdfxCreateContext( gl_api api,
+                            const __GLcontextModes *mesaVis,
                             __DRIcontext *driContextPriv,
                              void *sharedContextPrivate )
 {
index 6e25cac30159c419eec0a56ef7d3e0f8b2ef3720..29b0876f9f93f383826415c346a07be3c92aaf82 100644 (file)
@@ -937,7 +937,8 @@ struct tdfx_context {
 
 
 extern GLboolean
-tdfxCreateContext( const __GLcontextModes *mesaVis,
+tdfxCreateContext( gl_api api,
+                  const __GLcontextModes *mesaVis,
                    __DRIcontext *driContextPriv,
                    void *sharedContextPrivate );
 
index 9da96bdd45a836bf1d80210a13d49f14635527c7..4298c9485512410b712d29ce9147d03b118b6dec 100644 (file)
@@ -456,7 +456,8 @@ FreeBuffer(struct via_context *vmesa)
 
 
 GLboolean
-viaCreateContext(const __GLcontextModes *visual,
+viaCreateContext(gl_api api,
+                const __GLcontextModes *visual,
                  __DRIcontext *driContextPriv,
                  void *sharedContextPrivate)
 {
index aa662e01c04512fb43ef8ddab38b39f302017d78..51df0ce4eb4a4a589aa1b298b07ca06c5636b108 100644 (file)
@@ -76,7 +76,8 @@ typedef struct {
 
 
 extern GLboolean
-viaCreateContext(const __GLcontextModes *mesaVis,
+viaCreateContext(gl_api api,
+                const __GLcontextModes *mesaVis,
                  __DRIcontext *driContextPriv,
                  void *sharedContextPrivate);