Revision: 178 http://trac.macosforge.org/projects/xquartz/changeset/178 Author: gstaplin@apple.com Date: 2009-02-19 15:54:05 -0800 (Thu, 19 Feb 2009) Log Message: ----------- Add support for glXMakeContextCurrent's readable drawable. This basically involves swapping the CGL drawable if the gc->currentReadable drawable doesn't match the gc->currentDrawable. The thread safety for these routines will come in a commit after this. Modified Paths: -------------- AppleSGLX/trunk/Makefile AppleSGLX/trunk/apple_xgl_api.c Added Paths: ----------- AppleSGLX/trunk/apple_xgl_api_read.c AppleSGLX/trunk/apple_xgl_api_read.h Modified: AppleSGLX/trunk/Makefile =================================================================== --- AppleSGLX/trunk/Makefile 2009-02-19 23:09:20 UTC (rev 177) +++ AppleSGLX/trunk/Makefile 2009-02-19 23:54:05 UTC (rev 178) @@ -23,7 +23,7 @@ appledri.o apple_glx_context.o apple_glx.o pixel.o \ compsize.o apple_visual.o apple_cgl.o glxreply.o glcontextmodes.o \ apple_xgl_api.o apple_glx_drawable.o xfont.o apple_glx_pbuffer.o \ - apple_glx_pixmap.o + apple_glx_pixmap.o apple_xgl_api_read.o #This target is used for the tests. @@ -42,6 +42,9 @@ apple_xgl_api.o: apple_xgl_api.h apple_xgl_api.c $(COMPILE) apple_xgl_api.c +apple_xgl_api_read.o: apple_xgl_api_read.h apple_xgl_api_read.c apple_xgl_api.h + $(COMPILE) apple_xgl_api_read.c + glcontextmodes.o: glcontextmodes.c glcontextmodes.h $(COMPILE) glcontextmodes.c Modified: AppleSGLX/trunk/apple_xgl_api.c =================================================================== --- AppleSGLX/trunk/apple_xgl_api.c 2009-02-19 23:09:20 UTC (rev 177) +++ AppleSGLX/trunk/apple_xgl_api.c 2009-02-19 23:54:05 UTC (rev 178) @@ -408,9 +408,6 @@ void glCopyColorSubTable(GLenum target, GLsizei start, GLint x, GLint y, GLsizei width) { __gl_api.CopyColorSubTable(target, start, x, y, width); } -void glCopyColorTable(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width) { - __gl_api.CopyColorTable(target, internalformat, x, y, width); -} void glCopyColorTableSGI(GLenum internalformat, GLint x, GLint y, GLsizei width) { /*noop*/ } @@ -426,9 +423,6 @@ void glCopyConvolutionFilter2DEXT(GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height) { /*noop*/ } -void glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type) { - __gl_api.CopyPixels(x, y, width, height, type); -} void glCopyTexImage1D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border) { __gl_api.CopyTexImage1D(target, level, internalformat, x, y, width, border); } @@ -1923,9 +1917,6 @@ void glReadInstrumentsSGIX(GLint marker) { /*noop*/ } -void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void * pixels) { - __gl_api.ReadPixels(x, y, width, height, format, type, pixels); -} void glRectd(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2) { __gl_api.Rectd(x1, y1, x2, y2); } Added: AppleSGLX/trunk/apple_xgl_api_read.c =================================================================== --- AppleSGLX/trunk/apple_xgl_api_read.c (rev 0) +++ AppleSGLX/trunk/apple_xgl_api_read.c 2009-02-19 23:54:05 UTC (rev 178) @@ -0,0 +1,120 @@ +/* + Copyright (c) 2008, 2009 Apple Inc. + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT + HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + + Except as contained in this notice, the name(s) of the above + copyright holders shall not be used in advertising or otherwise to + promote the sale, use or other dealings in this Software without + prior written authorization. +*/ + +/* + * This file works with the glXMakeContextCurrent readable drawable. + * + * The way it works is by swapping the currentDrawable for the currentReadable + * drawable if they are different. + */ +#include <stdbool.h> +#include "apple_xgl_api_read.h" +#include "apple_xgl_api.h" +#include "apple_cgl.h" +#include "apple_glx_context.h" + +extern struct apple_xgl_api __gl_api; + +struct apple_xgl_saved_state { + bool swapped; +}; + +static void SetRead(struct apple_xgl_saved_state *saved) { + GLXContext gc = __glXGetCurrentContext(); + + /* + * By default indicate that the state was not swapped, so that UnsetRead + * functions correctly. + */ + saved->swapped = false; + + /* + * If the readable drawable isn't the same as the drawable then + * the user has requested a readable drawable with glXMakeContextCurrent(). + * We emulate this behavior by switching the current drawable. + */ + if(gc->currentReadable != gc->currentDrawable) { + Display *dpy = glXGetCurrentDisplay(); + + saved->swapped = true; + + if(apple_glx_make_current_context(dpy, gc, gc, gc->currentReadable)) { + /* An error occurred, so try to restore the old context state. */ + (void)apple_glx_make_current_context(dpy, gc, gc, gc->currentDrawable); + saved->swapped = false; + } + } +} + +static void UnsetRead(struct apple_xgl_saved_state *saved) { + if(saved->swapped) { + GLXContext gc = __glXGetCurrentContext(); + Display *dpy = glXGetCurrentDisplay(); + + if(apple_glx_make_current_context(dpy, gc, gc, gc->currentDrawable)) { + /* + * An error occurred restoring the drawable. + * It's unclear what to do about that. + */ + } + } +} + +void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, + GLenum format, GLenum type, void * pixels) { + struct apple_xgl_saved_state saved; + + SetRead(&saved); + + __gl_api.ReadPixels(x, y, width, height, format, type, pixels); + + UnsetRead(&saved); +} + +void glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, + GLenum type) { + struct apple_xgl_saved_state saved; + + SetRead(&saved); + + __gl_api.CopyPixels(x, y, width, height, type); + + UnsetRead(&saved); +} + +void glCopyColorTable(GLenum target, GLenum internalformat, GLint x, GLint y, + GLsizei width) { + struct apple_xgl_saved_state saved; + + SetRead(&saved); + + __gl_api.CopyColorTable(target, internalformat, x, y, width); + + UnsetRead(&saved); +} Added: AppleSGLX/trunk/apple_xgl_api_read.h =================================================================== --- AppleSGLX/trunk/apple_xgl_api_read.h (rev 0) +++ AppleSGLX/trunk/apple_xgl_api_read.h 2009-02-19 23:54:05 UTC (rev 178) @@ -0,0 +1,46 @@ +/* + Copyright (c) 2008, 2009 Apple Inc. + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT + HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + + Except as contained in this notice, the name(s) of the above + copyright holders shall not be used in advertising or otherwise to + promote the sale, use or other dealings in this Software without + prior written authorization. +*/ + +/* + * This file works with the glXMakeContextCurrent readable drawable. + */ +#ifndef APPLE_XGL_API_READ_H +#define APPLE_XGL_API_READ_H + +#include "glxclient.h" + +extern void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, + GLenum type, void * pixels); + +extern void glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type); + +extern void glCopyColorTable(GLenum target, GLenum internalformat, GLint x, GLint y, + GLsizei width); + +#endif
participants (1)
-
source_changes@macosforge.org