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