1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright © 2008 George Sapountzis <gsap7@yahoo.gr>
3*4882a593Smuzhiyun * Copyright © 2008 Red Hat, Inc
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Permission to use, copy, modify, distribute, and sell this software
6*4882a593Smuzhiyun * and its documentation for any purpose is hereby granted without
7*4882a593Smuzhiyun * fee, provided that the above copyright notice appear in all copies
8*4882a593Smuzhiyun * and that both that copyright notice and this permission notice
9*4882a593Smuzhiyun * appear in supporting documentation, and that the name of the
10*4882a593Smuzhiyun * copyright holders not be used in advertising or publicity
11*4882a593Smuzhiyun * pertaining to distribution of the software without specific,
12*4882a593Smuzhiyun * written prior permission. The copyright holders make no
13*4882a593Smuzhiyun * representations about the suitability of this software for any
14*4882a593Smuzhiyun * purpose. It is provided "as is" without express or implied
15*4882a593Smuzhiyun * warranty.
16*4882a593Smuzhiyun *
17*4882a593Smuzhiyun * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
18*4882a593Smuzhiyun * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19*4882a593Smuzhiyun * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
20*4882a593Smuzhiyun * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21*4882a593Smuzhiyun * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
22*4882a593Smuzhiyun * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
23*4882a593Smuzhiyun * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
24*4882a593Smuzhiyun * SOFTWARE.
25*4882a593Smuzhiyun */
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
28*4882a593Smuzhiyun #include <dix-config.h>
29*4882a593Smuzhiyun #endif
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun #include <stdint.h>
32*4882a593Smuzhiyun #include <stdio.h>
33*4882a593Smuzhiyun #include <string.h>
34*4882a593Smuzhiyun #include <errno.h>
35*4882a593Smuzhiyun #include <sys/time.h>
36*4882a593Smuzhiyun #include <dlfcn.h>
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun #include <GL/gl.h>
39*4882a593Smuzhiyun #include <GL/internal/dri_interface.h>
40*4882a593Smuzhiyun #include <GL/glxtokens.h>
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun #include "scrnintstr.h"
43*4882a593Smuzhiyun #include "pixmapstr.h"
44*4882a593Smuzhiyun #include "gcstruct.h"
45*4882a593Smuzhiyun #include "os.h"
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun #include "glxserver.h"
48*4882a593Smuzhiyun #include "glxutil.h"
49*4882a593Smuzhiyun #include "glxdricommon.h"
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun #include "extension_string.h"
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun /* RTLD_LOCAL is not defined on Cygwin */
54*4882a593Smuzhiyun #ifdef __CYGWIN__
55*4882a593Smuzhiyun #ifndef RTLD_LOCAL
56*4882a593Smuzhiyun #define RTLD_LOCAL 0
57*4882a593Smuzhiyun #endif
58*4882a593Smuzhiyun #endif
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun typedef struct __GLXDRIscreen __GLXDRIscreen;
61*4882a593Smuzhiyun typedef struct __GLXDRIcontext __GLXDRIcontext;
62*4882a593Smuzhiyun typedef struct __GLXDRIdrawable __GLXDRIdrawable;
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun struct __GLXDRIscreen {
65*4882a593Smuzhiyun __GLXscreen base;
66*4882a593Smuzhiyun __DRIscreen *driScreen;
67*4882a593Smuzhiyun void *driver;
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun const __DRIcoreExtension *core;
70*4882a593Smuzhiyun const __DRIswrastExtension *swrast;
71*4882a593Smuzhiyun const __DRIcopySubBufferExtension *copySubBuffer;
72*4882a593Smuzhiyun const __DRItexBufferExtension *texBuffer;
73*4882a593Smuzhiyun const __DRIconfig **driConfigs;
74*4882a593Smuzhiyun };
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun struct __GLXDRIcontext {
77*4882a593Smuzhiyun __GLXcontext base;
78*4882a593Smuzhiyun __DRIcontext *driContext;
79*4882a593Smuzhiyun };
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun struct __GLXDRIdrawable {
82*4882a593Smuzhiyun __GLXdrawable base;
83*4882a593Smuzhiyun __DRIdrawable *driDrawable;
84*4882a593Smuzhiyun __GLXDRIscreen *screen;
85*4882a593Smuzhiyun };
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun /* white lie */
88*4882a593Smuzhiyun extern glx_func_ptr glXGetProcAddressARB(const char *);
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun static void
__glXDRIdrawableDestroy(__GLXdrawable * drawable)91*4882a593Smuzhiyun __glXDRIdrawableDestroy(__GLXdrawable * drawable)
92*4882a593Smuzhiyun {
93*4882a593Smuzhiyun __GLXDRIdrawable *private = (__GLXDRIdrawable *) drawable;
94*4882a593Smuzhiyun const __DRIcoreExtension *core = private->screen->core;
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun (*core->destroyDrawable) (private->driDrawable);
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun __glXDrawableRelease(drawable);
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun free(private);
101*4882a593Smuzhiyun }
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun static GLboolean
__glXDRIdrawableSwapBuffers(ClientPtr client,__GLXdrawable * drawable)104*4882a593Smuzhiyun __glXDRIdrawableSwapBuffers(ClientPtr client, __GLXdrawable * drawable)
105*4882a593Smuzhiyun {
106*4882a593Smuzhiyun __GLXDRIdrawable *private = (__GLXDRIdrawable *) drawable;
107*4882a593Smuzhiyun const __DRIcoreExtension *core = private->screen->core;
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun (*core->swapBuffers) (private->driDrawable);
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun return TRUE;
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun static void
__glXDRIdrawableCopySubBuffer(__GLXdrawable * basePrivate,int x,int y,int w,int h)115*4882a593Smuzhiyun __glXDRIdrawableCopySubBuffer(__GLXdrawable * basePrivate,
116*4882a593Smuzhiyun int x, int y, int w, int h)
117*4882a593Smuzhiyun {
118*4882a593Smuzhiyun __GLXDRIdrawable *private = (__GLXDRIdrawable *) basePrivate;
119*4882a593Smuzhiyun const __DRIcopySubBufferExtension *copySubBuffer =
120*4882a593Smuzhiyun private->screen->copySubBuffer;
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun if (copySubBuffer)
123*4882a593Smuzhiyun (*copySubBuffer->copySubBuffer) (private->driDrawable, x, y, w, h);
124*4882a593Smuzhiyun }
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun static void
__glXDRIcontextDestroy(__GLXcontext * baseContext)127*4882a593Smuzhiyun __glXDRIcontextDestroy(__GLXcontext * baseContext)
128*4882a593Smuzhiyun {
129*4882a593Smuzhiyun __GLXDRIcontext *context = (__GLXDRIcontext *) baseContext;
130*4882a593Smuzhiyun __GLXDRIscreen *screen = (__GLXDRIscreen *) context->base.pGlxScreen;
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun (*screen->core->destroyContext) (context->driContext);
133*4882a593Smuzhiyun __glXContextDestroy(&context->base);
134*4882a593Smuzhiyun free(context);
135*4882a593Smuzhiyun }
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun static int
__glXDRIcontextMakeCurrent(__GLXcontext * baseContext)138*4882a593Smuzhiyun __glXDRIcontextMakeCurrent(__GLXcontext * baseContext)
139*4882a593Smuzhiyun {
140*4882a593Smuzhiyun __GLXDRIcontext *context = (__GLXDRIcontext *) baseContext;
141*4882a593Smuzhiyun __GLXDRIdrawable *draw = (__GLXDRIdrawable *) baseContext->drawPriv;
142*4882a593Smuzhiyun __GLXDRIdrawable *read = (__GLXDRIdrawable *) baseContext->readPriv;
143*4882a593Smuzhiyun __GLXDRIscreen *screen = (__GLXDRIscreen *) context->base.pGlxScreen;
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun return (*screen->core->bindContext) (context->driContext,
146*4882a593Smuzhiyun draw->driDrawable, read->driDrawable);
147*4882a593Smuzhiyun }
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun static int
__glXDRIcontextLoseCurrent(__GLXcontext * baseContext)150*4882a593Smuzhiyun __glXDRIcontextLoseCurrent(__GLXcontext * baseContext)
151*4882a593Smuzhiyun {
152*4882a593Smuzhiyun __GLXDRIcontext *context = (__GLXDRIcontext *) baseContext;
153*4882a593Smuzhiyun __GLXDRIscreen *screen = (__GLXDRIscreen *) context->base.pGlxScreen;
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun return (*screen->core->unbindContext) (context->driContext);
156*4882a593Smuzhiyun }
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun static int
__glXDRIcontextCopy(__GLXcontext * baseDst,__GLXcontext * baseSrc,unsigned long mask)159*4882a593Smuzhiyun __glXDRIcontextCopy(__GLXcontext * baseDst, __GLXcontext * baseSrc,
160*4882a593Smuzhiyun unsigned long mask)
161*4882a593Smuzhiyun {
162*4882a593Smuzhiyun __GLXDRIcontext *dst = (__GLXDRIcontext *) baseDst;
163*4882a593Smuzhiyun __GLXDRIcontext *src = (__GLXDRIcontext *) baseSrc;
164*4882a593Smuzhiyun __GLXDRIscreen *screen = (__GLXDRIscreen *) dst->base.pGlxScreen;
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun return (*screen->core->copyContext) (dst->driContext,
167*4882a593Smuzhiyun src->driContext, mask);
168*4882a593Smuzhiyun }
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun static int
__glXDRIbindTexImage(__GLXcontext * baseContext,int buffer,__GLXdrawable * glxPixmap)171*4882a593Smuzhiyun __glXDRIbindTexImage(__GLXcontext * baseContext,
172*4882a593Smuzhiyun int buffer, __GLXdrawable * glxPixmap)
173*4882a593Smuzhiyun {
174*4882a593Smuzhiyun __GLXDRIdrawable *drawable = (__GLXDRIdrawable *) glxPixmap;
175*4882a593Smuzhiyun const __DRItexBufferExtension *texBuffer = drawable->screen->texBuffer;
176*4882a593Smuzhiyun __GLXDRIcontext *context = (__GLXDRIcontext *) baseContext;
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun if (texBuffer == NULL)
179*4882a593Smuzhiyun return Success;
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun #if __DRI_TEX_BUFFER_VERSION >= 2
182*4882a593Smuzhiyun if (texBuffer->base.version >= 2 && texBuffer->setTexBuffer2 != NULL) {
183*4882a593Smuzhiyun (*texBuffer->setTexBuffer2) (context->driContext,
184*4882a593Smuzhiyun glxPixmap->target,
185*4882a593Smuzhiyun glxPixmap->format, drawable->driDrawable);
186*4882a593Smuzhiyun }
187*4882a593Smuzhiyun else
188*4882a593Smuzhiyun #endif
189*4882a593Smuzhiyun texBuffer->setTexBuffer(context->driContext,
190*4882a593Smuzhiyun glxPixmap->target, drawable->driDrawable);
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun return Success;
193*4882a593Smuzhiyun }
194*4882a593Smuzhiyun
195*4882a593Smuzhiyun static int
__glXDRIreleaseTexImage(__GLXcontext * baseContext,int buffer,__GLXdrawable * pixmap)196*4882a593Smuzhiyun __glXDRIreleaseTexImage(__GLXcontext * baseContext,
197*4882a593Smuzhiyun int buffer, __GLXdrawable * pixmap)
198*4882a593Smuzhiyun {
199*4882a593Smuzhiyun /* FIXME: Just unbind the texture? */
200*4882a593Smuzhiyun return Success;
201*4882a593Smuzhiyun }
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun static __GLXcontext *
__glXDRIscreenCreateContext(__GLXscreen * baseScreen,__GLXconfig * glxConfig,__GLXcontext * baseShareContext,unsigned num_attribs,const uint32_t * attribs,int * error)204*4882a593Smuzhiyun __glXDRIscreenCreateContext(__GLXscreen * baseScreen,
205*4882a593Smuzhiyun __GLXconfig * glxConfig,
206*4882a593Smuzhiyun __GLXcontext * baseShareContext,
207*4882a593Smuzhiyun unsigned num_attribs,
208*4882a593Smuzhiyun const uint32_t *attribs,
209*4882a593Smuzhiyun int *error)
210*4882a593Smuzhiyun {
211*4882a593Smuzhiyun __GLXDRIscreen *screen = (__GLXDRIscreen *) baseScreen;
212*4882a593Smuzhiyun __GLXDRIcontext *context, *shareContext;
213*4882a593Smuzhiyun __GLXDRIconfig *config = (__GLXDRIconfig *) glxConfig;
214*4882a593Smuzhiyun const __DRIconfig *driConfig = config ? config->driConfig : NULL;
215*4882a593Smuzhiyun const __DRIcoreExtension *core = screen->core;
216*4882a593Smuzhiyun __DRIcontext *driShare;
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun /* DRISWRAST won't support createContextAttribs, so these parameters will
219*4882a593Smuzhiyun * never be used.
220*4882a593Smuzhiyun */
221*4882a593Smuzhiyun (void) num_attribs;
222*4882a593Smuzhiyun (void) attribs;
223*4882a593Smuzhiyun (void) error;
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun shareContext = (__GLXDRIcontext *) baseShareContext;
226*4882a593Smuzhiyun if (shareContext)
227*4882a593Smuzhiyun driShare = shareContext->driContext;
228*4882a593Smuzhiyun else
229*4882a593Smuzhiyun driShare = NULL;
230*4882a593Smuzhiyun
231*4882a593Smuzhiyun context = calloc(1, sizeof *context);
232*4882a593Smuzhiyun if (context == NULL)
233*4882a593Smuzhiyun return NULL;
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun context->base.config = glxConfig;
236*4882a593Smuzhiyun context->base.destroy = __glXDRIcontextDestroy;
237*4882a593Smuzhiyun context->base.makeCurrent = __glXDRIcontextMakeCurrent;
238*4882a593Smuzhiyun context->base.loseCurrent = __glXDRIcontextLoseCurrent;
239*4882a593Smuzhiyun context->base.copy = __glXDRIcontextCopy;
240*4882a593Smuzhiyun context->base.bindTexImage = __glXDRIbindTexImage;
241*4882a593Smuzhiyun context->base.releaseTexImage = __glXDRIreleaseTexImage;
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun context->driContext =
244*4882a593Smuzhiyun (*core->createNewContext) (screen->driScreen, driConfig, driShare,
245*4882a593Smuzhiyun context);
246*4882a593Smuzhiyun
247*4882a593Smuzhiyun return &context->base;
248*4882a593Smuzhiyun }
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun static __GLXdrawable *
__glXDRIscreenCreateDrawable(ClientPtr client,__GLXscreen * screen,DrawablePtr pDraw,XID drawId,int type,XID glxDrawId,__GLXconfig * glxConfig)251*4882a593Smuzhiyun __glXDRIscreenCreateDrawable(ClientPtr client,
252*4882a593Smuzhiyun __GLXscreen * screen,
253*4882a593Smuzhiyun DrawablePtr pDraw,
254*4882a593Smuzhiyun XID drawId,
255*4882a593Smuzhiyun int type, XID glxDrawId, __GLXconfig * glxConfig)
256*4882a593Smuzhiyun {
257*4882a593Smuzhiyun __GLXDRIscreen *driScreen = (__GLXDRIscreen *) screen;
258*4882a593Smuzhiyun __GLXDRIconfig *config = (__GLXDRIconfig *) glxConfig;
259*4882a593Smuzhiyun __GLXDRIdrawable *private;
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun private = calloc(1, sizeof *private);
262*4882a593Smuzhiyun if (private == NULL)
263*4882a593Smuzhiyun return NULL;
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun private->screen = driScreen;
266*4882a593Smuzhiyun if (!__glXDrawableInit(&private->base, screen,
267*4882a593Smuzhiyun pDraw, type, glxDrawId, glxConfig)) {
268*4882a593Smuzhiyun free(private);
269*4882a593Smuzhiyun return NULL;
270*4882a593Smuzhiyun }
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun private->base.destroy = __glXDRIdrawableDestroy;
273*4882a593Smuzhiyun private->base.swapBuffers = __glXDRIdrawableSwapBuffers;
274*4882a593Smuzhiyun private->base.copySubBuffer = __glXDRIdrawableCopySubBuffer;
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun private->driDrawable =
277*4882a593Smuzhiyun (*driScreen->swrast->createNewDrawable) (driScreen->driScreen,
278*4882a593Smuzhiyun config->driConfig, private);
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun return &private->base;
281*4882a593Smuzhiyun }
282*4882a593Smuzhiyun
283*4882a593Smuzhiyun static void
swrastGetDrawableInfo(__DRIdrawable * draw,int * x,int * y,int * w,int * h,void * loaderPrivate)284*4882a593Smuzhiyun swrastGetDrawableInfo(__DRIdrawable * draw,
285*4882a593Smuzhiyun int *x, int *y, int *w, int *h, void *loaderPrivate)
286*4882a593Smuzhiyun {
287*4882a593Smuzhiyun __GLXDRIdrawable *drawable = loaderPrivate;
288*4882a593Smuzhiyun DrawablePtr pDraw = drawable->base.pDraw;
289*4882a593Smuzhiyun
290*4882a593Smuzhiyun *x = pDraw->x;
291*4882a593Smuzhiyun *y = pDraw->y;
292*4882a593Smuzhiyun *w = pDraw->width;
293*4882a593Smuzhiyun *h = pDraw->height;
294*4882a593Smuzhiyun }
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun static void
swrastPutImage(__DRIdrawable * draw,int op,int x,int y,int w,int h,char * data,void * loaderPrivate)297*4882a593Smuzhiyun swrastPutImage(__DRIdrawable * draw, int op,
298*4882a593Smuzhiyun int x, int y, int w, int h, char *data, void *loaderPrivate)
299*4882a593Smuzhiyun {
300*4882a593Smuzhiyun __GLXDRIdrawable *drawable = loaderPrivate;
301*4882a593Smuzhiyun DrawablePtr pDraw = drawable->base.pDraw;
302*4882a593Smuzhiyun GCPtr gc;
303*4882a593Smuzhiyun __GLXcontext *cx = lastGLContext;
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun if ((gc = GetScratchGC(pDraw->depth, pDraw->pScreen))) {
306*4882a593Smuzhiyun ValidateGC(pDraw, gc);
307*4882a593Smuzhiyun gc->ops->PutImage(pDraw, gc, pDraw->depth, x, y, w, h, 0, ZPixmap,
308*4882a593Smuzhiyun data);
309*4882a593Smuzhiyun FreeScratchGC(gc);
310*4882a593Smuzhiyun }
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun if (cx != lastGLContext) {
313*4882a593Smuzhiyun lastGLContext = cx;
314*4882a593Smuzhiyun cx->makeCurrent(cx);
315*4882a593Smuzhiyun }
316*4882a593Smuzhiyun }
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun static void
swrastGetImage(__DRIdrawable * draw,int x,int y,int w,int h,char * data,void * loaderPrivate)319*4882a593Smuzhiyun swrastGetImage(__DRIdrawable * draw,
320*4882a593Smuzhiyun int x, int y, int w, int h, char *data, void *loaderPrivate)
321*4882a593Smuzhiyun {
322*4882a593Smuzhiyun __GLXDRIdrawable *drawable = loaderPrivate;
323*4882a593Smuzhiyun DrawablePtr pDraw = drawable->base.pDraw;
324*4882a593Smuzhiyun ScreenPtr pScreen = pDraw->pScreen;
325*4882a593Smuzhiyun __GLXcontext *cx = lastGLContext;
326*4882a593Smuzhiyun
327*4882a593Smuzhiyun pScreen->SourceValidate(pDraw, x, y, w, h, IncludeInferiors);
328*4882a593Smuzhiyun pScreen->GetImage(pDraw, x, y, w, h, ZPixmap, ~0L, data);
329*4882a593Smuzhiyun if (cx != lastGLContext) {
330*4882a593Smuzhiyun lastGLContext = cx;
331*4882a593Smuzhiyun cx->makeCurrent(cx);
332*4882a593Smuzhiyun }
333*4882a593Smuzhiyun }
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun static const __DRIswrastLoaderExtension swrastLoaderExtension = {
336*4882a593Smuzhiyun {__DRI_SWRAST_LOADER, 1},
337*4882a593Smuzhiyun swrastGetDrawableInfo,
338*4882a593Smuzhiyun swrastPutImage,
339*4882a593Smuzhiyun swrastGetImage
340*4882a593Smuzhiyun };
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun static const __DRIextension *loader_extensions[] = {
343*4882a593Smuzhiyun &swrastLoaderExtension.base,
344*4882a593Smuzhiyun NULL
345*4882a593Smuzhiyun };
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun static void
initializeExtensions(__GLXscreen * screen)348*4882a593Smuzhiyun initializeExtensions(__GLXscreen * screen)
349*4882a593Smuzhiyun {
350*4882a593Smuzhiyun const __DRIextension **extensions;
351*4882a593Smuzhiyun __GLXDRIscreen *dri = (__GLXDRIscreen *)screen;
352*4882a593Smuzhiyun int i;
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun __glXEnableExtension(screen->glx_enable_bits, "GLX_MESA_copy_sub_buffer");
355*4882a593Smuzhiyun __glXEnableExtension(screen->glx_enable_bits, "GLX_EXT_no_config_context");
356*4882a593Smuzhiyun
357*4882a593Smuzhiyun if (dri->swrast->base.version >= 3) {
358*4882a593Smuzhiyun __glXEnableExtension(screen->glx_enable_bits,
359*4882a593Smuzhiyun "GLX_ARB_create_context");
360*4882a593Smuzhiyun __glXEnableExtension(screen->glx_enable_bits,
361*4882a593Smuzhiyun "GLX_ARB_create_context_no_error");
362*4882a593Smuzhiyun __glXEnableExtension(screen->glx_enable_bits,
363*4882a593Smuzhiyun "GLX_ARB_create_context_profile");
364*4882a593Smuzhiyun __glXEnableExtension(screen->glx_enable_bits,
365*4882a593Smuzhiyun "GLX_EXT_create_context_es_profile");
366*4882a593Smuzhiyun __glXEnableExtension(screen->glx_enable_bits,
367*4882a593Smuzhiyun "GLX_EXT_create_context_es2_profile");
368*4882a593Smuzhiyun }
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun /* these are harmless to enable unconditionally */
371*4882a593Smuzhiyun __glXEnableExtension(screen->glx_enable_bits, "GLX_EXT_framebuffer_sRGB");
372*4882a593Smuzhiyun __glXEnableExtension(screen->glx_enable_bits, "GLX_ARB_fbconfig_float");
373*4882a593Smuzhiyun __glXEnableExtension(screen->glx_enable_bits, "GLX_EXT_fbconfig_packed_float");
374*4882a593Smuzhiyun __glXEnableExtension(screen->glx_enable_bits, "GLX_EXT_texture_from_pixmap");
375*4882a593Smuzhiyun
376*4882a593Smuzhiyun extensions = dri->core->getExtensions(dri->driScreen);
377*4882a593Smuzhiyun
378*4882a593Smuzhiyun for (i = 0; extensions[i]; i++) {
379*4882a593Smuzhiyun if (strcmp(extensions[i]->name, __DRI_COPY_SUB_BUFFER) == 0) {
380*4882a593Smuzhiyun dri->copySubBuffer =
381*4882a593Smuzhiyun (const __DRIcopySubBufferExtension *) extensions[i];
382*4882a593Smuzhiyun }
383*4882a593Smuzhiyun
384*4882a593Smuzhiyun if (strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0) {
385*4882a593Smuzhiyun dri->texBuffer = (const __DRItexBufferExtension *) extensions[i];
386*4882a593Smuzhiyun }
387*4882a593Smuzhiyun
388*4882a593Smuzhiyun #ifdef __DRI2_FLUSH_CONTROL
389*4882a593Smuzhiyun if (strcmp(extensions[i]->name, __DRI2_FLUSH_CONTROL) == 0) {
390*4882a593Smuzhiyun __glXEnableExtension(screen->glx_enable_bits,
391*4882a593Smuzhiyun "GLX_ARB_context_flush_control");
392*4882a593Smuzhiyun }
393*4882a593Smuzhiyun #endif
394*4882a593Smuzhiyun
395*4882a593Smuzhiyun }
396*4882a593Smuzhiyun }
397*4882a593Smuzhiyun
398*4882a593Smuzhiyun static void
__glXDRIscreenDestroy(__GLXscreen * baseScreen)399*4882a593Smuzhiyun __glXDRIscreenDestroy(__GLXscreen * baseScreen)
400*4882a593Smuzhiyun {
401*4882a593Smuzhiyun int i;
402*4882a593Smuzhiyun
403*4882a593Smuzhiyun __GLXDRIscreen *screen = (__GLXDRIscreen *) baseScreen;
404*4882a593Smuzhiyun
405*4882a593Smuzhiyun (*screen->core->destroyScreen) (screen->driScreen);
406*4882a593Smuzhiyun
407*4882a593Smuzhiyun dlclose(screen->driver);
408*4882a593Smuzhiyun
409*4882a593Smuzhiyun __glXScreenDestroy(baseScreen);
410*4882a593Smuzhiyun
411*4882a593Smuzhiyun if (screen->driConfigs) {
412*4882a593Smuzhiyun for (i = 0; screen->driConfigs[i] != NULL; i++)
413*4882a593Smuzhiyun free((__DRIconfig **) screen->driConfigs[i]);
414*4882a593Smuzhiyun free(screen->driConfigs);
415*4882a593Smuzhiyun }
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun free(screen);
418*4882a593Smuzhiyun }
419*4882a593Smuzhiyun
420*4882a593Smuzhiyun static __GLXscreen *
__glXDRIscreenProbe(ScreenPtr pScreen)421*4882a593Smuzhiyun __glXDRIscreenProbe(ScreenPtr pScreen)
422*4882a593Smuzhiyun {
423*4882a593Smuzhiyun const char *driverName = "swrast";
424*4882a593Smuzhiyun __GLXDRIscreen *screen;
425*4882a593Smuzhiyun
426*4882a593Smuzhiyun screen = calloc(1, sizeof *screen);
427*4882a593Smuzhiyun if (screen == NULL)
428*4882a593Smuzhiyun return NULL;
429*4882a593Smuzhiyun
430*4882a593Smuzhiyun screen->base.destroy = __glXDRIscreenDestroy;
431*4882a593Smuzhiyun screen->base.createContext = __glXDRIscreenCreateContext;
432*4882a593Smuzhiyun screen->base.createDrawable = __glXDRIscreenCreateDrawable;
433*4882a593Smuzhiyun screen->base.swapInterval = NULL;
434*4882a593Smuzhiyun screen->base.pScreen = pScreen;
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun __glXInitExtensionEnableBits(screen->base.glx_enable_bits);
437*4882a593Smuzhiyun
438*4882a593Smuzhiyun screen->driver = glxProbeDriver(driverName,
439*4882a593Smuzhiyun (void **) &screen->core,
440*4882a593Smuzhiyun __DRI_CORE, 1,
441*4882a593Smuzhiyun (void **) &screen->swrast,
442*4882a593Smuzhiyun __DRI_SWRAST, 1);
443*4882a593Smuzhiyun if (screen->driver == NULL) {
444*4882a593Smuzhiyun goto handle_error;
445*4882a593Smuzhiyun }
446*4882a593Smuzhiyun
447*4882a593Smuzhiyun screen->driScreen =
448*4882a593Smuzhiyun (*screen->swrast->createNewScreen) (pScreen->myNum,
449*4882a593Smuzhiyun loader_extensions,
450*4882a593Smuzhiyun &screen->driConfigs, screen);
451*4882a593Smuzhiyun
452*4882a593Smuzhiyun if (screen->driScreen == NULL) {
453*4882a593Smuzhiyun LogMessage(X_ERROR, "IGLX error: Calling driver entry point failed\n");
454*4882a593Smuzhiyun goto handle_error;
455*4882a593Smuzhiyun }
456*4882a593Smuzhiyun
457*4882a593Smuzhiyun initializeExtensions(&screen->base);
458*4882a593Smuzhiyun
459*4882a593Smuzhiyun screen->base.fbconfigs = glxConvertConfigs(screen->core,
460*4882a593Smuzhiyun screen->driConfigs);
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun #if !defined(XQUARTZ) && !defined(WIN32)
463*4882a593Smuzhiyun screen->base.glvnd = strdup("mesa");
464*4882a593Smuzhiyun #endif
465*4882a593Smuzhiyun __glXScreenInit(&screen->base, pScreen);
466*4882a593Smuzhiyun
467*4882a593Smuzhiyun __glXsetGetProcAddress(glXGetProcAddressARB);
468*4882a593Smuzhiyun
469*4882a593Smuzhiyun LogMessage(X_INFO, "IGLX: Loaded and initialized %s\n", driverName);
470*4882a593Smuzhiyun
471*4882a593Smuzhiyun return &screen->base;
472*4882a593Smuzhiyun
473*4882a593Smuzhiyun handle_error:
474*4882a593Smuzhiyun if (screen->driver)
475*4882a593Smuzhiyun dlclose(screen->driver);
476*4882a593Smuzhiyun
477*4882a593Smuzhiyun free(screen);
478*4882a593Smuzhiyun
479*4882a593Smuzhiyun LogMessage(X_ERROR, "GLX: could not load software renderer\n");
480*4882a593Smuzhiyun
481*4882a593Smuzhiyun return NULL;
482*4882a593Smuzhiyun }
483*4882a593Smuzhiyun
484*4882a593Smuzhiyun __GLXprovider __glXDRISWRastProvider = {
485*4882a593Smuzhiyun __glXDRIscreenProbe,
486*4882a593Smuzhiyun "DRISWRAST",
487*4882a593Smuzhiyun NULL
488*4882a593Smuzhiyun };
489