Revision: 147 http://trac.macosforge.org/projects/xquartz/changeset/147 Author: gstaplin@apple.com Date: 2009-02-16 14:45:56 -0800 (Mon, 16 Feb 2009) Log Message: ----------- Add support for GLXPixmaps and restructure the struct apple_glx_drawable a bit. Add appropriate branching in the apple_glx_context.c code for GLXPixmaps, and cleanup some of the Pbuffer code. Modified Paths: -------------- AppleSGLX/trunk/apple_glx_context.c AppleSGLX/trunk/apple_glx_drawable.c AppleSGLX/trunk/apple_glx_drawable.h Modified: AppleSGLX/trunk/apple_glx_context.c =================================================================== --- AppleSGLX/trunk/apple_glx_context.c 2009-02-16 22:44:20 UTC (rev 146) +++ AppleSGLX/trunk/apple_glx_context.c 2009-02-16 22:45:56 UTC (rev 147) @@ -351,15 +351,7 @@ } if(NULL == newagd) { - CGLPBufferObj pbufobj; - bool is_pbuffer = false; - - /* First check if it's a pbuffer. */ - if(apple_glx_pbuffer_get(drawable, &pbufobj)) - is_pbuffer = true; - - if(apple_glx_create_drawable(dpy, ac, drawable, - is_pbuffer ? pbufobj : NULL, &newagd)) + if(apple_glx_create_drawable(dpy, ac, drawable, &newagd)) return true; /* Save the new drawable with the context structure. */ @@ -388,23 +380,31 @@ ac->is_current = true; assert(NULL != ac->context_obj); - assert(NULL != ac->drawable); - if(ac->drawable->is_pbuffer(ac->drawable)) { - - assert(NULL != ac->drawable->pbuffer_obj); + switch(ac->drawable->type) { + case APPLE_GLX_DRAWABLE_PBUFFER: { + CGLPBufferObj pbufobj; + if(false == apple_glx_pbuffer_get(ac->drawable->drawable, &pbufobj)) { + fprintf(stderr, "internal error: drawable is a pbuffer, " + "but the pbuffer layer was unable to retrieve " + "the CGLPBufferObj!\n"); + return true; + } + cglerr = apple_cgl.set_pbuffer(ac->context_obj, - ac->drawable->pbuffer_obj, + pbufobj, 0, 0, 0); - + if(kCGLNoError != cglerr) { fprintf(stderr, "set_pbuffer: %s\n", apple_cgl.error_string(cglerr)); return true; } - - } else { + } + break; + + case APPLE_GLX_DRAWABLE_SURFACE: error = xp_attach_gl_context(ac->context_obj, ac->drawable->surface_id); if(error) { @@ -419,10 +419,42 @@ * The first time a new context is made current the glViewport * and glScissor should be updated. */ - update_viewport_and_scissor(dpy, drawable); + update_viewport_and_scissor(dpy, ac->drawable->drawable); ac->made_current = true; } + break; + + case APPLE_GLX_DRAWABLE_PIXMAP: { + int width, height; + void *ptr; + + + apple_cgl.clear_drawable(ac->context_obj); + + if(false == apple_glx_pixmap_data(dpy, ac->drawable->drawable, + &width, &height, + &ptr)) { + + + fprintf(stderr, "invalid GLXPixmap: 0x%lx\n", ac->drawable->drawable); + return true; + } + + printf("%s ptr %p\n", __func__, ptr); + + cglerr = apple_cgl.set_off_screen(ac->context_obj, width, height, + width * /*FIXME?*/ 4, ptr); + + if(kCGLNoError != cglerr) { + fprintf(stderr, "set off screen: %s\n", + apple_cgl.error_string(cglerr)); + + return true; + } } + break; + } + ac->thread_id = pthread_self(); Modified: AppleSGLX/trunk/apple_glx_drawable.c =================================================================== --- AppleSGLX/trunk/apple_glx_drawable.c 2009-02-16 22:44:20 UTC (rev 146) +++ AppleSGLX/trunk/apple_glx_drawable.c 2009-02-16 22:45:56 UTC (rev 147) @@ -180,12 +180,8 @@ if(agd->next) agd->next->previous = agd->previous; - /* - * Only destroy the surface if it wasn't a pbuffer. - * - * The pbuffer should be cleaned up explicitly with glXDestroyPbuffer. - */ - if(!agd->pbuffer_obj) { + + if(APPLE_GLX_DRAWABLE_SURFACE == agd->type) { error = xp_destroy_surface(agd->surface_id); if(error) { @@ -216,15 +212,19 @@ } static bool is_pbuffer(struct apple_glx_drawable *agd) { - return agd->pbuffer_obj ? true : false; + return APPLE_GLX_DRAWABLE_PBUFFER == agd->type; } +static bool is_pixmap(struct apple_glx_drawable *agd) { + return APPLE_GLX_DRAWABLE_PIXMAP == agd->type; +} + bool apple_glx_create_drawable(Display *dpy, struct apple_glx_context *ac, GLXDrawable drawable, - CGLPBufferObj pbuf, struct apple_glx_drawable **agdResult) { struct apple_glx_drawable *agd; + CGLPBufferObj pbufobj; int err; *agdResult = NULL; @@ -241,8 +241,15 @@ agd->drawable = drawable; agd->surface_id = 0; agd->uid = 0; - agd->pbuffer_obj = pbuf; + agd->type = APPLE_GLX_DRAWABLE_SURFACE; + + if(apple_glx_pbuffer_get(drawable, &pbufobj)) + agd->type = APPLE_GLX_DRAWABLE_PBUFFER; + + if(apple_glx_is_pixmap(dpy, drawable)) + agd->type = APPLE_GLX_DRAWABLE_PIXMAP; + err = pthread_mutex_init(&agd->mutex, NULL); if(err) { @@ -259,6 +266,7 @@ agd->destroy = destroy_drawable_callback; agd->is_pbuffer = is_pbuffer; + agd->is_pixmap = is_pixmap; agd->width = -1; agd->height = -1; @@ -270,7 +278,8 @@ agd->previous = NULL; - if(!agd->pbuffer_obj && create_surface(dpy, ac, agd)) { + if(APPLE_GLX_DRAWABLE_SURFACE == agd->type + && create_surface(dpy, ac, agd)) { free(agd); return true; } Modified: AppleSGLX/trunk/apple_glx_drawable.h =================================================================== --- AppleSGLX/trunk/apple_glx_drawable.h 2009-02-16 22:44:20 UTC (rev 146) +++ AppleSGLX/trunk/apple_glx_drawable.h 2009-02-16 22:45:56 UTC (rev 147) @@ -37,14 +37,21 @@ #define XP_NO_X_HEADERS #include <Xplugin.h> #undef XP_NO_X_HEADERS +#include "apple_glx_pixmap.h" +enum { + APPLE_GLX_DRAWABLE_SURFACE = 1, + APPLE_GLX_DRAWABLE_PBUFFER, + APPLE_GLX_DRAWABLE_PIXMAP +}; + struct apple_glx_drawable { Display *display; int reference_count; GLXDrawable drawable; xp_surface_id surface_id; unsigned int uid; - CGLPBufferObj pbuffer_obj; + int type; /* APPLE_GLX_DRAWABLE_* */ /* * This mutex protects the reference count and any other drawable data. @@ -61,6 +68,8 @@ bool (*is_pbuffer)(struct apple_glx_drawable *agd); + bool (*is_pixmap)(struct apple_glx_drawable *agd); + /*BEGIN These are used for the mixed mode drawing... */ int width, height; int row_bytes; @@ -83,7 +92,6 @@ bool apple_glx_create_drawable(Display *dpy, struct apple_glx_context *ac, GLXDrawable drawable, - CGLPBufferObj pbuf, struct apple_glx_drawable **agd); void apple_glx_garbage_collect_drawables(Display *dpy);
participants (1)
-
source_changes@macosforge.org