2 * Copyright © 2010 Intel Corporation
3 * Copyright © 2011 Apple Inc.
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.
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.
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.
31 * Kristian Høgsberg (krh@bitplanet.net)
34 #if defined(GLX_USE_APPLEGL)
39 #include "glxclient.h"
40 #include "apple_glx_context.h"
41 #include "apple_glx.h"
42 #include "apple_cgl.h"
43 #include "glx_error.h"
46 applegl_destroy_context(struct glx_context
*gc
)
48 apple_glx_destroy_context(&gc
->driContext
, gc
->psc
->dpy
);
52 applegl_bind_context(struct glx_context
*gc
, struct glx_context
*old
,
53 GLXDrawable draw
, GLXDrawable read
)
55 Display
*dpy
= gc
->psc
->dpy
;
56 bool error
= apple_glx_make_current_context(dpy
,
57 (old
&& old
!= &dummyContext
) ? old
->driContext
: NULL
,
58 gc
? gc
->driContext
: NULL
, draw
);
60 apple_glx_diagnostic("%s: error %s\n", __func__
, error
? "YES" : "NO");
62 return 1; /* GLXBadContext is the same as Success (0) */
64 apple_glapi_set_dispatch();
70 applegl_unbind_context(struct glx_context
*gc
, struct glx_context
*new)
75 applegl_wait_gl(struct glx_context
*gc
)
81 applegl_wait_x(struct glx_context
*gc
)
83 Display
*dpy
= gc
->psc
->dpy
;
84 apple_glx_waitx(dpy
, gc
->driContext
);
88 applegl_get_proc_address(const char *symbol
)
90 return dlsym(apple_cgl_get_dl_handle(), symbol
);
93 static const struct glx_context_vtable applegl_context_vtable
= {
94 applegl_destroy_context
,
96 applegl_unbind_context
,
100 NULL
, /* bind_tex_image, */
101 NULL
, /* release_tex_image, */
102 applegl_get_proc_address
,
106 applegl_create_context(struct glx_screen
*psc
,
107 struct glx_config
*config
,
108 struct glx_context
*shareList
, int renderType
)
110 struct glx_context
*gc
;
113 Display
*dpy
= psc
->dpy
;
114 int screen
= psc
->scr
;
116 /* TODO: Integrate this with apple_glx_create_context and make
117 * struct apple_glx_context inherit from struct glx_context. */
119 gc
= Xcalloc(1, sizeof (*gc
));
123 if (!glx_context_init(gc
, psc
, config
)) {
128 gc
->vtable
= &applegl_context_vtable
;
129 gc
->driContext
= NULL
;
131 /* TODO: darwin: Integrate with above to do indirect */
132 if(apple_glx_create_context(&gc
->driContext
, dpy
, screen
, config
,
133 shareList
? shareList
->driContext
: NULL
,
134 &errorcode
, &x11error
)) {
135 __glXSendError(dpy
, errorcode
, 0, X_GLXCreateContext
, x11error
);
136 gc
->vtable
->destroy(gc
);
140 gc
->currentContextTag
= -1;
142 gc
->isDirect
= GL_TRUE
;
143 gc
->xid
= 1; /* Just something not None, so we know when to destroy
144 * it in MakeContextCurrent. */
149 struct glx_screen_vtable applegl_screen_vtable
= {
150 applegl_create_context
153 _X_HIDDEN
struct glx_screen
*
154 applegl_create_screen(int screen
, struct glx_display
* priv
)
156 struct glx_screen
*psc
;
158 psc
= Xmalloc(sizeof *psc
);
162 memset(psc
, 0, sizeof *psc
);
163 glx_screen_init(psc
, screen
, priv
);
164 psc
->vtable
= &applegl_screen_vtable
;
170 applegl_create_display(struct glx_display
*glx_dpy
)
172 if(!apple_init_glx(glx_dpy
->dpy
))
175 return GLXBadContext
;