applegl_glx.c revision 2ee5272e1671aff8c8d9e0c12bf37ed006717283
1/* 2 * Copyright © 2010 Intel Corporation 3 * Copyright © 2011 Apple Inc. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Soft- 7 * ware"), to deal in the Software without restriction, including without 8 * limitation the rights to use, copy, modify, merge, publish, distribute, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, provided that the above copyright 11 * notice(s) and this permission notice appear in all copies of the Soft- 12 * ware and that both the above copyright notice(s) and this permission 13 * notice appear in supporting documentation. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- 17 * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY 18 * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN 19 * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE- 20 * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 22 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR- 23 * MANCE OF THIS SOFTWARE. 24 * 25 * Except as contained in this notice, the name of a copyright holder shall 26 * not be used in advertising or otherwise to promote the sale, use or 27 * other dealings in this Software without prior written authorization of 28 * the copyright holder. 29 * 30 * Authors: 31 * Kristian Høgsberg (krh@bitplanet.net) 32 */ 33 34#if defined(GLX_USE_APPLEGL) 35 36#include <stdbool.h> 37 38#include "glxclient.h" 39#include "apple_glx_context.h" 40#include "apple_glx.h" 41#include "glx_error.h" 42 43static void 44applegl_destroy_context(struct glx_context *gc) 45{ 46 apple_glx_destroy_context(&gc->driContext, gc->currentDpy); 47} 48 49static int 50applegl_bind_context(struct glx_context *gc, struct glx_context *old, 51 GLXDrawable draw, GLXDrawable read) 52{ 53 Display *dpy = gc->psc->dpy; 54 bool error = apple_glx_make_current_context(dpy, 55 (old && old != &dummyContext) ? old->driContext : NULL, 56 gc ? gc->driContext : NULL, draw); 57 58 apple_glx_diagnostic("%s: error %s\n", __func__, error ? "YES" : "NO"); 59 if (error) 60 return 1; /* GLXBadContext is the same as Success (0) */ 61 62 return Success; 63} 64 65static void 66applegl_unbind_context(struct glx_context *gc, struct glx_context *new) 67{ 68} 69 70static void 71applegl_wait_gl(struct glx_context *gc) 72{ 73 glFinish(); 74} 75 76static void 77applegl_wait_x(struct glx_context *gc) 78{ 79 Display *dpy = gc->psc->dpy; 80 apple_glx_waitx(dpy, gc->driContext); 81} 82 83static const struct glx_context_vtable applegl_context_vtable = { 84 applegl_destroy_context, 85 applegl_bind_context, 86 applegl_unbind_context, 87 applegl_wait_gl, 88 applegl_wait_x, 89 DRI_glXUseXFont, 90 NULL, /* bind_tex_image, */ 91 NULL, /* release_tex_image, */ 92}; 93 94struct glx_context * 95applegl_create_context(struct glx_screen *psc, 96 struct glx_config *config, 97 struct glx_context *shareList, int renderType) 98{ 99 struct glx_context *gc; 100 int errorcode; 101 bool x11error; 102 Display *dpy = psc->dpy; 103 int screen = psc->scr; 104 105 /* TODO: Integrate this with apple_glx_create_context and make 106 * struct apple_glx_context inherit from struct glx_context. */ 107 108 gc = Xcalloc(1, sizeof (*gc)); 109 if (gc == NULL) 110 return NULL; 111 112 if (!glx_context_init(gc, psc, config)) { 113 Xfree(gc); 114 return NULL; 115 } 116 117 gc->vtable = &applegl_context_vtable; 118 gc->driContext = NULL; 119 gc->do_destroy = False; 120 121 /* TODO: darwin: Integrate with above to do indirect */ 122 if(apple_glx_create_context(&gc->driContext, dpy, screen, config, 123 shareList ? shareList->driContext : NULL, 124 &errorcode, &x11error)) { 125 __glXSendError(dpy, errorcode, 0, X_GLXCreateContext, x11error); 126 gc->vtable->destroy(gc); 127 return NULL; 128 } 129 130 gc->currentContextTag = -1; 131 gc->config = config; 132 gc->isDirect = GL_TRUE; 133 gc->xid = 1; /* Just something not None, so we know when to destroy 134 * it in MakeContextCurrent. */ 135 136 return gc; 137} 138 139struct glx_screen_vtable applegl_screen_vtable = { 140 applegl_create_context 141}; 142 143_X_HIDDEN struct glx_screen * 144applegl_create_screen(int screen, struct glx_display * priv) 145{ 146 struct glx_screen *psc; 147 148 psc = Xmalloc(sizeof *psc); 149 if (psc == NULL) 150 return NULL; 151 152 memset(psc, 0, sizeof *psc); 153 glx_screen_init(psc, screen, priv); 154 psc->vtable = &applegl_screen_vtable; 155 156 return psc; 157} 158 159_X_HIDDEN int 160applegl_create_display(struct glx_display *glx_dpy) 161{ 162 if(!apple_init_glx(glx_dpy->dpy)) 163 return 1; 164 165 return GLXBadContext; 166} 167 168#endif 169