applegl_glx.c 5.08 KB
Newer Older
1
2
/*
 * Copyright © 2010 Intel Corporation
3
 * Copyright © 2011 Apple Inc.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Soft-
 * ware"), to deal in the Software without restriction, including without
 * limitation the rights to use, copy, modify, merge, publish, distribute,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, provided that the above copyright
 * notice(s) and this permission notice appear in all copies of the Soft-
 * ware and that both the above copyright notice(s) and this permission
 * notice appear in supporting documentation.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
 * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
 * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
 * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
 * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
 * MANCE OF THIS SOFTWARE.
 *
 * Except as contained in this notice, the name of a copyright holder shall
 * not be used in advertising or otherwise to promote the sale, use or
 * other dealings in this Software without prior written authorization of
 * the copyright holder.
 *
 * Authors:
 *   Kristian Høgsberg (krh@bitplanet.net)
 */

#if defined(GLX_USE_APPLEGL)

36
37
38
39
40
41
42
#include <stdbool.h>

#include "glxclient.h"
#include "apple_glx_context.h"
#include "apple_glx.h"
#include "glx_error.h"

43
44
45
static void
applegl_destroy_context(struct glx_context *gc)
{
46
   apple_glx_destroy_context(&gc->driContext, gc->psc->dpy);
47
48
49
50
51
52
}

static int
applegl_bind_context(struct glx_context *gc, struct glx_context *old,
		     GLXDrawable draw, GLXDrawable read)
{
53
   Display *dpy = gc->psc->dpy;
54
   bool error = apple_glx_make_current_context(dpy,
55
					       (old && old != &dummyContext) ? old->driContext : NULL,
56
57
58
59
					       gc ? gc->driContext : NULL, draw);

   apple_glx_diagnostic("%s: error %s\n", __func__, error ? "YES" : "NO");
   if (error)
60
      return 1; /* GLXBadContext is the same as Success (0) */
61
62
63
64
65
66
67

   return Success;
}

static void
applegl_unbind_context(struct glx_context *gc, struct glx_context *new)
{
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
   Display *dpy;
   bool error;

   /* If we don't have a context, then we have nothing to unbind */
   if (!gc)
      return;

   /* If we have a new context, keep this one around and remove it during bind. */
   if (new)
      return;

   dpy = gc->psc->dpy;

   error = apple_glx_make_current_context(dpy,
					  (gc != &dummyContext) ? gc->driContext : NULL,
					  NULL, None);

   apple_glx_diagnostic("%s: error %s\n", __func__, error ? "YES" : "NO");
86
87
88
89
90
91
92
93
94
95
96
}

static void
applegl_wait_gl(struct glx_context *gc)
{
   glFinish();
}

static void
applegl_wait_x(struct glx_context *gc)
{
97
98
   Display *dpy = gc->psc->dpy;
   apple_glx_waitx(dpy, gc->driContext);
99
100
101
102
103
104
105
106
107
108
109
110
111
}

static const struct glx_context_vtable applegl_context_vtable = {
   applegl_destroy_context,
   applegl_bind_context,
   applegl_unbind_context,
   applegl_wait_gl,
   applegl_wait_x,
   DRI_glXUseXFont,
   NULL, /* bind_tex_image, */
   NULL, /* release_tex_image, */
};

112
struct glx_context *
113
applegl_create_context(struct glx_screen *psc,
114
		       struct glx_config *config,
115
116
117
118
119
		       struct glx_context *shareList, int renderType)
{
   struct glx_context *gc;
   int errorcode;
   bool x11error;
120
121
   Display *dpy = psc->dpy;
   int screen = psc->scr;
122
123
124
125

   /* TODO: Integrate this with apple_glx_create_context and make
    * struct apple_glx_context inherit from struct glx_context. */

126
127
   gc = Xcalloc(1, sizeof (*gc));
   if (gc == NULL)
128
129
      return NULL;

130
   if (!glx_context_init(gc, psc, config)) {
131
132
133
134
135
136
137
138
      Xfree(gc);
      return NULL;
   }

   gc->vtable = &applegl_context_vtable;
   gc->driContext = NULL;

   /* TODO: darwin: Integrate with above to do indirect */
139
   if(apple_glx_create_context(&gc->driContext, dpy, screen, config, 
140
141
142
143
144
145
146
147
			       shareList ? shareList->driContext : NULL,
			       &errorcode, &x11error)) {
      __glXSendError(dpy, errorcode, 0, X_GLXCreateContext, x11error);
      gc->vtable->destroy(gc);
      return NULL;
   }

   gc->currentContextTag = -1;
148
149
   gc->config = config;
   gc->isDirect = GL_TRUE;
150
151
152
153
154
155
   gc->xid = 1; /* Just something not None, so we know when to destroy
		 * it in MakeContextCurrent. */

   return gc;
}

156
struct glx_screen_vtable applegl_screen_vtable = {
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
   applegl_create_context
};

_X_HIDDEN struct glx_screen *
applegl_create_screen(int screen, struct glx_display * priv)
{
   struct glx_screen *psc;

   psc = Xmalloc(sizeof *psc);
   if (psc == NULL)
      return NULL;

   memset(psc, 0, sizeof *psc);
   glx_screen_init(psc, screen, priv);
   psc->vtable = &applegl_screen_vtable;

   return psc;
}

_X_HIDDEN int
177
applegl_create_display(struct glx_display *glx_dpy)
178
{
179
180
181
182
   if(!apple_init_glx(glx_dpy->dpy))
      return 1;

   return GLXBadContext;
183
184
185
}

#endif