summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon TURNEY <jon.turney@dronecode.org.uk>2014-04-23 11:15:59 +0100
committerJon TURNEY <jon.turney@dronecode.org.uk>2014-04-23 11:15:59 +0100
commit458a9185f13c96505928eb10d84a25f5ef61c5d1 (patch)
tree2d6ba6968742764ac80246e3cb527248bfa22875
parent12e83108029a2fe694579b9e64458f1c47e26b26 (diff)
Introduce platform_vtable and push applegl code into itapplegl-vtable
-rw-r--r--src/glx/apple/apple_glx_pbuffer.c90
-rw-r--r--src/glx/apple/apple_glx_pixmap.c33
-rw-r--r--src/glx/applegl_glx.c18
-rw-r--r--src/glx/create_context.c12
-rw-r--r--src/glx/glx_pbuffer.c187
-rw-r--r--src/glx/glxclient.h17
-rw-r--r--src/glx/glxcmds.c9
-rw-r--r--src/glx/glxcurrent.c7
-rw-r--r--src/glx/glxext.c72
9 files changed, 196 insertions, 249 deletions
diff --git a/src/glx/apple/apple_glx_pbuffer.c b/src/glx/apple/apple_glx_pbuffer.c
index 142f4cce99..b5bcc4ecab 100644
--- a/src/glx/apple/apple_glx_pbuffer.c
+++ b/src/glx/apple/apple_glx_pbuffer.c
@@ -107,19 +107,18 @@ pbuffer_destroy(Display * dpy, struct apple_glx_drawable *d)
XFreePixmap(dpy, pbuf->xid);
}
-/* Return true if an error occurred. */
-bool
+void
apple_glx_pbuffer_destroy(Display * dpy, GLXPbuffer pbuf)
{
- return !apple_glx_drawable_destroy_by_type(dpy, pbuf,
- APPLE_GLX_DRAWABLE_PBUFFER);
+ if (!apple_glx_drawable_destroy_by_type(dpy, pbuf,
+ APPLE_GLX_DRAWABLE_PBUFFER))
+ __glXSendError(dpy, GLXBadPbuffer, pbuf, X_GLXDestroyPbuffer, false);
}
-/* Return true if an error occurred. */
-bool
-apple_glx_pbuffer_create(Display * dpy, GLXFBConfig config,
- int width, int height, int *errorcode,
- GLXPbuffer * result)
+GLXDrawable
+apple_glx_pbuffer_create(Display * dpy, struct glx_config *config,
+ unsigned int width, unsigned int height,
+ const int *attrib_list, GLboolean size_in_attribs)
{
struct apple_glx_drawable *d;
struct apple_glx_pbuffer *pbuf = NULL;
@@ -172,11 +171,17 @@ apple_glx_pbuffer_create(Display * dpy, GLXFBConfig config,
pbuf->event_mask = 0;
- *result = pbuf->xid;
-
d->unlock(d);
- return false;
+ return pbuf->xid;
+
+ err:
+ /*
+ * apple_glx_pbuffer_create only sets the errorcode to core X11
+ * errors.
+ */
+ __glXSendError(dpy, errorcode, 0, X_GLXCreatePbuffer, true);
+ return NULL;
}
@@ -303,6 +308,10 @@ apple_glx_pbuffer_query(GLXPbuffer p, int attr, unsigned int *value)
*value = pbuf->fbconfigID;
result = true;
break;
+
+ case GLX_EVENT_MASK_SGIX:
+ result = apple_glx_pbuffer_get_event_mask(drawable, value);
+ break;
}
d->unlock(d);
@@ -311,6 +320,63 @@ apple_glx_pbuffer_query(GLXPbuffer p, int attr, unsigned int *value)
return result;
}
+int
+apple_get_drawable_attribute(Display * dpy, GLXDrawable drawable,
+ int attribute, unsigned int *value)
+{
+ Window root;
+ int x, y;
+ unsigned int width, height, bd, depth;
+
+ if (apple_glx_pixmap_query(drawable, attribute, value))
+ return 0; /*done */
+
+ if (apple_glx_pbuffer_query(drawable, attribute, value))
+ return 0; /*done */
+
+ /*
+ * The OpenGL spec states that we should report GLXBadDrawable if
+ * the drawable is invalid, however doing so would require that we
+ * use XSetErrorHandler(), which is known to not be thread safe.
+ * If we use a round-trip call to validate the drawable, there could
+ * be a race, so instead we just opt in favor of letting the
+ * XGetGeometry request fail with a GetGeometry request X error
+ * rather than GLXBadDrawable, in what is hoped to be a rare
+ * case of an invalid drawable. In practice most and possibly all
+ * X11 apps using GLX shouldn't notice a difference.
+ */
+ if (XGetGeometry
+ (dpy, drawable, &root, &x, &y, &width, &height, &bd, &depth)) {
+ switch (attribute) {
+ case GLX_WIDTH:
+ *value = width;
+ break;
+
+ case GLX_HEIGHT:
+ *value = height;
+ break;
+
+ case GLX_EVENT_MASK_SGIX:
+ *value = 0;
+ }
+ }
+
+ return 0;
+}
+
+void
+apple_change_drawable_attribute(Display * dpy, GLXDrawable drawable,
+ const CARD32 * attribs, size_t num_attribs)
+{
+ for (i = 0; i < num_attribs; i++) {
+ switch(attribs[i * 2]) {
+ case GLX_EVENT_MASK:
+ apple_glx_pbuffer_set_event_mask(drawable, value);
+ break;
+ }
+ }
+}
+
bool
apple_glx_pbuffer_set_event_mask(GLXDrawable drawable, unsigned long mask)
{
diff --git a/src/glx/apple/apple_glx_pixmap.c b/src/glx/apple/apple_glx_pixmap.c
index bee0ec98be..19fc88b78f 100644
--- a/src/glx/apple/apple_glx_pixmap.c
+++ b/src/glx/apple/apple_glx_pixmap.c
@@ -114,20 +114,21 @@ pixmap_destroy(Display * dpy, struct apple_glx_drawable *d)
apple_glx_diagnostic("destroyed pixmap buffer for: 0x%lx\n", d->drawable);
}
-/* Return true if an error occurred. */
-bool
-apple_glx_pixmap_create(Display * dpy, int screen, Pixmap pixmap,
- const void *mode)
+GLXDrawable
+apple_glx_pixmap_create(Display *dpy, struct glx_config *config,
+ Drawable drawable, const int *attrib_list, CARD8 glxCode)
{
struct apple_glx_drawable *d;
struct apple_glx_pixmap *p;
bool double_buffered;
bool uses_stereo;
CGLError error;
- const struct glx_config *cmodes = mode;
+
+ const struct glx_config *cmodes = config;
+ int screen = config->screen;
if (apple_glx_drawable_create(dpy, screen, pixmap, &d, &callbacks))
- return true;
+ return None;
/* d is locked and referenced at this point. */
@@ -141,7 +142,7 @@ apple_glx_pixmap_create(Display * dpy, int screen, Pixmap pixmap,
&p->size, p->path, PATH_MAX)) {
d->unlock(d);
d->destroy(d);
- return true;
+ return None;
}
p->fd = shm_open(p->path, O_RDWR, 0);
@@ -150,7 +151,7 @@ apple_glx_pixmap_create(Display * dpy, int screen, Pixmap pixmap,
perror("shm_open");
d->unlock(d);
d->destroy(d);
- return true;
+ return None;
}
p->buffer = mmap(NULL, p->size, PROT_READ | PROT_WRITE,
@@ -160,7 +161,7 @@ apple_glx_pixmap_create(Display * dpy, int screen, Pixmap pixmap,
perror("mmap");
d->unlock(d);
d->destroy(d);
- return true;
+ return None;
}
apple_visual_create_pfobj(&p->pixel_format_obj, mode, &double_buffered,
@@ -172,7 +173,7 @@ apple_glx_pixmap_create(Display * dpy, int screen, Pixmap pixmap,
if (kCGLNoError != error) {
d->unlock(d);
d->destroy(d);
- return true;
+ return None;
}
p->fbconfigID = cmodes->fbconfigID;
@@ -181,7 +182,7 @@ apple_glx_pixmap_create(Display * dpy, int screen, Pixmap pixmap,
apple_glx_diagnostic("created: pixmap buffer for 0x%lx\n", d->drawable);
- return false;
+ return drawable;
}
bool
@@ -220,10 +221,10 @@ apple_glx_pixmap_query(GLXPixmap pixmap, int attr, unsigned int *value)
return result;
}
-/* Return true if the type is valid for pixmap. */
-bool
-apple_glx_pixmap_destroy(Display * dpy, GLXPixmap pixmap)
+void
+apple_glx_pixmap_destroy(Display * dpy, GLXDrawable drawable, CARD32 glxCode)
{
- return !apple_glx_drawable_destroy_by_type(dpy, pixmap,
- APPLE_GLX_DRAWABLE_PIXMAP);
+ if (!apple_glx_drawable_destroy_by_type(dpy, pixmap,
+ APPLE_GLX_DRAWABLE_PIXMAP))
+ __glXSendError(dpy, GLXBadPixmap, pixmap, glxCode, false);
}
diff --git a/src/glx/applegl_glx.c b/src/glx/applegl_glx.c
index 72fd985178..d14adcb0e2 100644
--- a/src/glx/applegl_glx.c
+++ b/src/glx/applegl_glx.c
@@ -181,12 +181,20 @@ applegl_create_screen(int screen, struct glx_display * priv)
return psc;
}
-_X_HIDDEN int
+_X_HIDDEN __GLXDRIdisplay *
applegl_create_display(struct glx_display *glx_dpy)
{
- if(!apple_init_glx(glx_dpy->dpy))
- return 1;
+ struct __GLXDRIdisplay *pdpyp;
- return GLXBadContext;
-}
+ if (!apple_init_glx(glx_dpy->dpy))
+ return NULL;
+
+ pdpyp = malloc(sizeof *pdpyp);
+ if (pdpyp == NULL)
+ return NULL;
+
+ pdpyp->destroyDisplay = apple_destroy_display;
+ pdpyp->createScreen = applegl_create_screen;
+ return &pdpyp->base;
+}
diff --git a/src/glx/create_context.c b/src/glx/create_context.c
index 38e949ab4c..f62ff3ad7d 100644
--- a/src/glx/create_context.c
+++ b/src/glx/create_context.c
@@ -78,16 +78,20 @@ glXCreateContextAttribsARB(Display *dpy, GLXFBConfig config,
gc = psc->vtable->create_context_attribs(psc, cfg, share, num_attribs,
(const uint32_t *) attrib_list,
&dummy_err);
+
+ }
+
+ /* ??? fallback if create_context_attribs not supported ??? or just fail ??? */
+ if (gc == NULL) {
+ if (direct && psc->vtable->create_context) {
+ gc = psc->vtable->create_context(psc, cfg, share, 0);
+ }
}
if (gc == NULL) {
-#ifdef GLX_USE_APPLEGL
- gc = applegl_create_context(psc, cfg, share, 0);
-#else
gc = indirect_create_context_attribs(psc, cfg, share, num_attribs,
(const uint32_t *) attrib_list,
&dummy_err);
-#endif
}
gc->xid = xcb_generate_id(c);
diff --git a/src/glx/glx_pbuffer.c b/src/glx/glx_pbuffer.c
index 0cd0554578..fab6989420 100644
--- a/src/glx/glx_pbuffer.c
+++ b/src/glx/glx_pbuffer.c
@@ -672,6 +672,8 @@ DestroyPbuffer(Display * dpy, GLXDrawable drawable)
return;
}
+#endif /* GLX_USE_APPLEGL */
+
/**
* Create a new pbuffer.
*/
@@ -685,8 +687,6 @@ glXCreateGLXPbufferSGIX(Display * dpy, GLXFBConfigSGIX config,
attrib_list, GL_FALSE);
}
-#endif /* GLX_USE_APPLEGL */
-
/**
* Create a new pbuffer.
*/
@@ -694,17 +694,12 @@ _X_EXPORT GLXPbuffer
glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int *attrib_list)
{
int i, width, height;
-#ifdef GLX_USE_APPLEGL
- GLXPbuffer result;
- int errorcode;
-#endif
width = 0;
height = 0;
WARN_ONCE_GLX_1_3(dpy, __func__);
-#ifdef GLX_USE_APPLEGL
for (i = 0; attrib_list[i]; ++i) {
switch (attrib_list[i]) {
case GLX_PBUFFER_WIDTH:
@@ -723,7 +718,7 @@ glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int *attrib_list)
break;
case GLX_PRESERVED_CONTENTS:
- /* The contents are always preserved with AppleSGLX with CGL. */
+ /* This is a hint we should probably handle, but how? */
++i;
break;
@@ -732,33 +727,8 @@ glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int *attrib_list)
}
}
- if (apple_glx_pbuffer_create(dpy, config, width, height, &errorcode,
- &result)) {
- /*
- * apple_glx_pbuffer_create only sets the errorcode to core X11
- * errors.
- */
- __glXSendError(dpy, errorcode, 0, X_GLXCreatePbuffer, true);
-
- return None;
- }
-
- return result;
-#else
- for (i = 0; attrib_list[i * 2]; i++) {
- switch (attrib_list[i * 2]) {
- case GLX_PBUFFER_WIDTH:
- width = attrib_list[i * 2 + 1];
- break;
- case GLX_PBUFFER_HEIGHT:
- height = attrib_list[i * 2 + 1];
- break;
- }
- }
-
- return (GLXPbuffer) CreatePbuffer(dpy, (struct glx_config *) config,
- width, height, attrib_list, GL_TRUE);
-#endif
+ return dpy->platform->CreatePbuffer(dpy, (struct glx_config *) config,
+ width, height, attrib_list, GL_TRUE);
}
@@ -768,13 +738,7 @@ glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int *attrib_list)
_X_EXPORT void
glXDestroyPbuffer(Display * dpy, GLXPbuffer pbuf)
{
-#ifdef GLX_USE_APPLEGL
- if (apple_glx_pbuffer_destroy(dpy, pbuf)) {
- __glXSendError(dpy, GLXBadPbuffer, pbuf, X_GLXDestroyPbuffer, false);
- }
-#else
- DestroyPbuffer(dpy, pbuf);
-#endif
+ dpy->platform->DestroyPbuffer(dpy, pbuf);
}
@@ -786,47 +750,9 @@ glXQueryDrawable(Display * dpy, GLXDrawable drawable,
int attribute, unsigned int *value)
{
WARN_ONCE_GLX_1_3(dpy, __func__);
-#ifdef GLX_USE_APPLEGL
- Window root;
- int x, y;
- unsigned int width, height, bd, depth;
-
- if (apple_glx_pixmap_query(drawable, attribute, value))
- return; /*done */
-
- if (apple_glx_pbuffer_query(drawable, attribute, value))
- return; /*done */
-
- /*
- * The OpenGL spec states that we should report GLXBadDrawable if
- * the drawable is invalid, however doing so would require that we
- * use XSetErrorHandler(), which is known to not be thread safe.
- * If we use a round-trip call to validate the drawable, there could
- * be a race, so instead we just opt in favor of letting the
- * XGetGeometry request fail with a GetGeometry request X error
- * rather than GLXBadDrawable, in what is hoped to be a rare
- * case of an invalid drawable. In practice most and possibly all
- * X11 apps using GLX shouldn't notice a difference.
- */
- if (XGetGeometry
- (dpy, drawable, &root, &x, &y, &width, &height, &bd, &depth)) {
- switch (attribute) {
- case GLX_WIDTH:
- *value = width;
- break;
-
- case GLX_HEIGHT:
- *value = height;
- break;
- }
- }
-#else
- GetDrawableAttribute(dpy, drawable, attribute, value);
-#endif
+ dpy->platform->GetDrawableAttribute(dpy, drawable, attribute, value);
}
-
-#ifndef GLX_USE_APPLEGL
/**
* Query an attribute of a pbuffer.
*/
@@ -834,9 +760,8 @@ _X_EXPORT int
glXQueryGLXPbufferSGIX(Display * dpy, GLXPbufferSGIX drawable,
int attribute, unsigned int *value)
{
- return GetDrawableAttribute(dpy, drawable, attribute, value);
+ return dpy->platform->GetDrawableAttribute(dpy, drawable, attribute, value);
}
-#endif
/**
* Select the event mask for a drawable.
@@ -844,30 +769,12 @@ glXQueryGLXPbufferSGIX(Display * dpy, GLXPbufferSGIX drawable,
_X_EXPORT void
glXSelectEvent(Display * dpy, GLXDrawable drawable, unsigned long mask)
{
-#ifdef GLX_USE_APPLEGL
- XWindowAttributes xwattr;
-
- if (apple_glx_pbuffer_set_event_mask(drawable, mask))
- return; /*done */
-
- /*
- * The spec allows a window, but currently there are no valid
- * events for a window, so do nothing.
- */
- if (XGetWindowAttributes(dpy, drawable, &xwattr))
- return; /*done */
- /* The drawable seems to be invalid. Report an error. */
-
- __glXSendError(dpy, GLXBadDrawable, drawable,
- X_GLXChangeDrawableAttributes, false);
-#else
CARD32 attribs[2];
attribs[0] = (CARD32) GLX_EVENT_MASK;
attribs[1] = (CARD32) mask;
- ChangeDrawableAttribute(dpy, drawable, attribs, 1);
-#endif
+ dpy->platform->changeDrawableAttribute(dpy, drawable, attribs, 1);
}
@@ -877,26 +784,6 @@ glXSelectEvent(Display * dpy, GLXDrawable drawable, unsigned long mask)
_X_EXPORT void
glXGetSelectedEvent(Display * dpy, GLXDrawable drawable, unsigned long *mask)
{
-#ifdef GLX_USE_APPLEGL
- XWindowAttributes xwattr;
-
- if (apple_glx_pbuffer_get_event_mask(drawable, mask))
- return; /*done */
-
- /*
- * The spec allows a window, but currently there are no valid
- * events for a window, so do nothing, but set the mask to 0.
- */
- if (XGetWindowAttributes(dpy, drawable, &xwattr)) {
- /* The window is valid, so set the mask to 0. */
- *mask = 0;
- return; /*done */
- }
- /* The drawable seems to be invalid. Report an error. */
-
- __glXSendError(dpy, GLXBadDrawable, drawable, X_GLXGetDrawableAttributes,
- true);
-#else
unsigned int value;
@@ -905,9 +792,8 @@ glXGetSelectedEvent(Display * dpy, GLXDrawable drawable, unsigned long *mask)
* we could just type-cast the pointer, but why?
*/
- GetDrawableAttribute(dpy, drawable, GLX_EVENT_MASK_SGIX, &value);
+ dpy->platform->getDrawableAttribute(dpy, drawable, GLX_EVENT_MASK_SGIX, &value);
*mask = value;
-#endif
}
@@ -917,17 +803,8 @@ glXCreatePixmap(Display * dpy, GLXFBConfig config, Pixmap pixmap,
{
WARN_ONCE_GLX_1_3(dpy, __func__);
-#ifdef GLX_USE_APPLEGL
- const struct glx_config *modes = (const struct glx_config *) config;
-
- if (apple_glx_pixmap_create(dpy, modes->screen, pixmap, modes))
- return None;
-
- return pixmap;
-#else
- return CreateDrawable(dpy, (struct glx_config *) config,
+ return dpy->platform->CreateDrawable(dpy, (struct glx_config *) config,
(Drawable) pixmap, attrib_list, X_GLXCreatePixmap);
-#endif
}
@@ -936,33 +813,8 @@ glXCreateWindow(Display * dpy, GLXFBConfig config, Window win,
const int *attrib_list)
{
WARN_ONCE_GLX_1_3(dpy, __func__);
-#ifdef GLX_USE_APPLEGL
- XWindowAttributes xwattr;
- XVisualInfo *visinfo;
-
- (void) attrib_list; /*unused according to GLX 1.4 */
-
- XGetWindowAttributes(dpy, win, &xwattr);
-
- visinfo = glXGetVisualFromFBConfig(dpy, config);
-
- if (NULL == visinfo) {
- __glXSendError(dpy, GLXBadFBConfig, 0, X_GLXCreateWindow, false);
- return None;
- }
-
- if (visinfo->visualid != XVisualIDFromVisual(xwattr.visual)) {
- __glXSendError(dpy, BadMatch, 0, X_GLXCreateWindow, true);
- return None;
- }
-
- free(visinfo);
-
- return win;
-#else
- return CreateDrawable(dpy, (struct glx_config *) config,
- (Drawable) win, attrib_list, X_GLXCreateWindow);
-#endif
+ return dpy->platform->CreateDrawable(dpy, (struct glx_config *) config,
+ (Drawable) win, attrib_list, X_GLXCreateWindow);
}
@@ -970,12 +822,7 @@ _X_EXPORT void
glXDestroyPixmap(Display * dpy, GLXPixmap pixmap)
{
WARN_ONCE_GLX_1_3(dpy, __func__);
-#ifdef GLX_USE_APPLEGL
- if (apple_glx_pixmap_destroy(dpy, pixmap))
- __glXSendError(dpy, GLXBadPixmap, pixmap, X_GLXDestroyPixmap, false);
-#else
- DestroyDrawable(dpy, (GLXDrawable) pixmap, X_GLXDestroyPixmap);
-#endif
+ dpy->platform->DestroyDrawable(dpy, (GLXDrawable) pixmap, X_GLXDestroyPixmap);
}
@@ -983,12 +830,9 @@ _X_EXPORT void
glXDestroyWindow(Display * dpy, GLXWindow win)
{
WARN_ONCE_GLX_1_3(dpy, __func__);
-#ifndef GLX_USE_APPLEGL
- DestroyDrawable(dpy, (GLXDrawable) win, X_GLXDestroyWindow);
-#endif
+ dpy->platform->DestroyDrawable(dpy, (GLXDrawable) win, X_GLXDestroyWindow);
}
-#ifndef GLX_USE_APPLEGL
_X_EXPORT
GLX_ALIAS_VOID(glXDestroyGLXPbufferSGIX,
(Display * dpy, GLXPbufferSGIX pbuf),
@@ -1004,4 +848,3 @@ GLX_ALIAS_VOID(glXGetSelectedEventSGIX,
(Display * dpy, GLXDrawable drawable,
unsigned long *mask), (dpy, drawable, mask),
glXGetSelectedEvent)
-#endif
diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h
index 74c19c4856..734472c414 100644
--- a/src/glx/glxclient.h
+++ b/src/glx/glxclient.h
@@ -76,10 +76,6 @@ struct glx_context;
extern void DRI_glXUseXFont(struct glx_context *ctx,
Font font, int first, int count, int listbase);
-#endif
-
-#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
-
/**
* Display dependent methods. This structure is initialized during the
* \c driCreateDisplay call.
@@ -88,6 +84,19 @@ typedef struct __GLXDRIdisplayRec __GLXDRIdisplay;
typedef struct __GLXDRIscreenRec __GLXDRIscreen;
typedef struct __GLXDRIdrawableRec __GLXDRIdrawable;
+/*
+ platform vtable
+ */
+struct glx_platform_vtable {
+ void (*platformInit) (void);
+ GLXDrawable (*createPBuffer) (Display * dpy, struct glx_config * config,
+ unsigned int width, unsigned int height,
+ const int *attrib_list, GLboolean size_in_attribs);
+};
+
+/*
+ display vtable
+ */
struct __GLXDRIdisplayRec
{
/**
diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c
index 7984715036..2427ed35bd 100644
--- a/src/glx/glxcmds.c
+++ b/src/glx/glxcmds.c
@@ -292,14 +292,10 @@ CreateContext(Display *dpy, int generic_id, struct glx_config *config,
return NULL;
gc = NULL;
-#ifdef GLX_USE_APPLEGL
- gc = applegl_create_context(psc, config, shareList, renderType);
-#else
if (allowDirect && psc->vtable->create_context)
gc = psc->vtable->create_context(psc, config, shareList, renderType);
if (!gc)
gc = indirect_create_context(psc, config, shareList, renderType);
-#endif
if (!gc)
return NULL;
@@ -667,11 +663,8 @@ glXIsDirect(Display * dpy, GLXContext gc_user)
else if (gc->isDirect) {
return True;
}
-#ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
- return False;
-#else
+
return __glXIsDirect(dpy, gc->xid);
-#endif
}
_X_EXPORT GLXPixmap
diff --git a/src/glx/glxcurrent.c b/src/glx/glxcurrent.c
index 2e5111b8cf..33baf18104 100644
--- a/src/glx/glxcurrent.c
+++ b/src/glx/glxcurrent.c
@@ -38,13 +38,6 @@
#endif
#include "glxclient.h"
-#ifdef GLX_USE_APPLEGL
-#include <stdlib.h>
-
-#include "apple_glx.h"
-#include "apple_glx_context.h"
-#endif
-
#include "glapi.h"
/*
diff --git a/src/glx/glxext.c b/src/glx/glxext.c
index 29317906d5..97c6aba780 100644
--- a/src/glx/glxext.c
+++ b/src/glx/glxext.c
@@ -43,7 +43,7 @@
#include <X11/extensions/extutil.h>
#ifdef GLX_USE_APPLEGL
#include "apple_glx.h"
-#include "apple_visual.h"
+//#include "apple_visual.h"
#endif
#include "glxextensions.h"
@@ -84,10 +84,8 @@ static /* const */ char *error_list[] = {
"GLXBadProfileARB",
};
-#ifdef GLX_USE_APPLEGL
static char *__glXErrorString(Display *dpy, int code, XExtCodes *codes,
char *buf, int n);
-#endif
static
XEXT_GENERATE_ERROR_STRING(__glXErrorString, __glXExtensionName,
@@ -203,15 +201,11 @@ FreeScreenConfigs(struct glx_display * priv)
psc = priv->screens[i];
glx_screen_cleanup(psc);
-#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
if (psc->driScreen) {
psc->driScreen->destroyScreen(psc);
} else {
free(psc);
}
-#else
- free(psc);
-#endif
}
free((char *) priv->screens);
priv->screens = NULL;
@@ -234,7 +228,8 @@ glx_display_free(struct glx_display *priv)
__glxHashDestroy(priv->glXDrawHash);
-#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
+#if defined(GLX_DIRECT_RENDERING)
+#if !defined(GLX_USE_APPLEGL)
__glxHashDestroy(priv->drawHash);
/* Free the direct rendering per display data */
@@ -249,6 +244,12 @@ glx_display_free(struct glx_display *priv)
if (priv->dri2Display)
(*priv->dri2Display->destroyDisplay) (priv->dri2Display);
priv->dri2Display = NULL;
+
+ /* No DRI3 ??? */
+#else
+ if (priv->appledriDisplay)
+ (*priv->appledriDisplay->destroyDisplay) (priv->appledriDisplay);
+ priv->appledriDisplay = NULL;
#endif
free((char *) priv);
@@ -774,7 +775,9 @@ AllocAndFetchScreenConfigs(Display * dpy, struct glx_display * priv)
for (i = 0; i < screens; i++, psc++) {
psc = NULL;
-#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
+#if defined(GLX_DIRECT_RENDERING)
+ /* This expresses a platform-specific preference order of direct renderers */
+#if !defined(__APPLE__)
#if defined(HAVE_DRI3)
if (priv->dri3Display)
psc = (*priv->dri3Display->createScreen) (i, priv);
@@ -783,12 +786,13 @@ AllocAndFetchScreenConfigs(Display * dpy, struct glx_display * priv)
psc = (*priv->dri2Display->createScreen) (i, priv);
if (psc == NULL && priv->driDisplay)
psc = (*priv->driDisplay->createScreen) (i, priv);
- if (psc == NULL && priv->driswDisplay)
- psc = (*priv->driswDisplay->createScreen) (i, priv);
#endif
-#if defined(GLX_USE_APPLEGL)
+#else
if (psc == NULL)
- psc = applegl_create_screen(i, priv);
+ psc = (*priv->appledriDisplay->createScreen)(i, priv);
+#endif
+ if (psc == NULL && priv->driswDisplay)
+ psc = (*priv->driswDisplay->createScreen) (i, priv);
#else
if (psc == NULL)
psc = indirect_create_screen(i, priv);
@@ -806,7 +810,7 @@ AllocAndFetchScreenConfigs(Display * dpy, struct glx_display * priv)
__glXInitialize(Display * dpy)
{
struct glx_display *dpyPriv, *d;
-#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
+#if defined(GLX_DIRECT_RENDERING)
Bool glx_direct, glx_accel;
#endif
int i;
@@ -858,10 +862,38 @@ __glXInitialize(Display * dpy)
dpyPriv->glXDrawHash = __glxHashCreate();
-#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
+#ifdef __linux__
+ glx_platform_vtable driPlatform = {
+ .createPBuffer = CreatePBuffer;
+ .destroyPBuffer = DestroyPbuffer;
+ .getDrawableAttribute = GetDrawableAttribute;
+ .changeDrawableAttribute = ChangeDrawableAttribute;
+ .createDrawable = CreateDrawable;
+ .destroyDrawable = DestroyDrawable;
+ };
+ dpyPriv->platform = driPlatform;
+#endif
+#ifdef __APPLE__
+ glx_platform_vtable applePlatform = {
+ .createPBuffer = apple_glx_pbuffer_create;
+ .destroyPBuffer = apple_glx_pbuffer_destroy;
+ .getDrawableAttribute = apple_get_drawable_attribute;
+ .changeDrawableAttribute = apple_change_drawable_attribute;
+ .createDrawable = apple_glx_pixmap_create;
+ .destroyDrawable = apple_glx_pixmap_destroy;
+#else
+ };
+ dpyPriv->platform = applePlatform;
+#endif
+#if defined(_WIN32) || defined(__CYGWIN__)
+ dpyPriv->platform = windowsPlatform;
+#endif
+
+#if defined(GLX_DIRECT_RENDERING)
glx_direct = (getenv("LIBGL_ALWAYS_INDIRECT") == NULL);
glx_accel = (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL);
+#if !defined(GLX_USE_APPLEGL)
dpyPriv->drawHash = __glxHashCreate();
/*
@@ -877,16 +909,14 @@ __glXInitialize(Display * dpy)
dpyPriv->dri2Display = dri2CreateDisplay(dpy);
dpyPriv->driDisplay = driCreateDisplay(dpy);
}
+#else
+ if (glx_direct && glx_accel) {
+ dpyPriv->appledriDisplay = applegl_create_display(dpyPriv);
+#endif
if (glx_direct)
dpyPriv->driswDisplay = driswCreateDisplay(dpy);
#endif
-#ifdef GLX_USE_APPLEGL
- if (!applegl_create_display(dpyPriv)) {
- free(dpyPriv);
- return NULL;
- }
-#endif
if (!AllocAndFetchScreenConfigs(dpy, dpyPriv)) {
free(dpyPriv);
return NULL;