applegl_glx.c revision e903cc17bbf7152b3f7d64fe7fbb5ceebcc7452e
1d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi/* 2d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * Copyright © 2010 Intel Corporation 3d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * Copyright © 2011 Apple Inc. 4d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * 5d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * Permission is hereby granted, free of charge, to any person obtaining a 6d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * copy of this software and associated documentation files (the "Soft- 7d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * ware"), to deal in the Software without restriction, including without 8d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * limitation the rights to use, copy, modify, merge, publish, distribute, 9d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * and/or sell copies of the Software, and to permit persons to whom the 10d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * Software is furnished to do so, provided that the above copyright 11d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * notice(s) and this permission notice appear in all copies of the Soft- 12d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * ware and that both the above copyright notice(s) and this permission 13d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * notice appear in supporting documentation. 14d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * 15d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- 17d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY 18d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN 19d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE- 20d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 21d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 22d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR- 23d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * MANCE OF THIS SOFTWARE. 24d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * 25d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * Except as contained in this notice, the name of a copyright holder shall 26d685894212e6dbeac1fda4996903c1da115d49a6Ying Wang * not be used in advertising or otherwise to promote the sale, use or 27d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * other dealings in this Software without prior written authorization of 28d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * the copyright holder. 29d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * 30bd882b1c8708686d373c56e07e6bb8b1cb6ffd9eJeff Brown * Authors: 31bd882b1c8708686d373c56e07e6bb8b1cb6ffd9eJeff Brown * Kristian Høgsberg (krh@bitplanet.net) 32d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi */ 33d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 34d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#if defined(GLX_USE_APPLEGL) 35d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 36d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#include <stdbool.h> 37ba4d0433319393d626d2169683209e4956a087e2James Dong 38ba4d0433319393d626d2169683209e4956a087e2James Dong#include "glxclient.h" 39057b086e0e054247840060cbd1e14295a214221bHenrik B Andersson#include "apple_glx_context.h" 40057b086e0e054247840060cbd1e14295a214221bHenrik B Andersson#include "apple_glx.h" 41d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#include "glx_error.h" 423070af08821ee86f06a9cc6b58dbb79c82946b94Iliyan Malchev 43d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshistatic void 443802949f5cfe500b8bc41371ff99c82c9ed5d9c3Jean-Baptiste Queruapplegl_destroy_context(struct glx_context *gc) 453802949f5cfe500b8bc41371ff99c82c9ed5d9c3Jean-Baptiste Queru{ 46d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 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 120 /* TODO: darwin: Integrate with above to do indirect */ 121 if(apple_glx_create_context(&gc->driContext, dpy, screen, config, 122 shareList ? shareList->driContext : NULL, 123 &errorcode, &x11error)) { 124 __glXSendError(dpy, errorcode, 0, X_GLXCreateContext, x11error); 125 gc->vtable->destroy(gc); 126 return NULL; 127 } 128 129 gc->currentContextTag = -1; 130 gc->config = config; 131 gc->isDirect = GL_TRUE; 132 gc->xid = 1; /* Just something not None, so we know when to destroy 133 * it in MakeContextCurrent. */ 134 135 return gc; 136} 137 138struct glx_screen_vtable applegl_screen_vtable = { 139 applegl_create_context 140}; 141 142_X_HIDDEN struct glx_screen * 143applegl_create_screen(int screen, struct glx_display * priv) 144{ 145 struct glx_screen *psc; 146 147 psc = Xmalloc(sizeof *psc); 148 if (psc == NULL) 149 return NULL; 150 151 memset(psc, 0, sizeof *psc); 152 glx_screen_init(psc, screen, priv); 153 psc->vtable = &applegl_screen_vtable; 154 155 return psc; 156} 157 158_X_HIDDEN int 159applegl_create_display(struct glx_display *glx_dpy) 160{ 161 if(!apple_init_glx(glx_dpy->dpy)) 162 return 1; 163 164 return GLXBadContext; 165} 166 167#endif 168