1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Bismarck, ND., USA
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
27 **************************************************************************/
31 * Get a hardware accelerated Gallium screen/context from the OpenGL driver.
35 #include "pipe/p_compiler.h"
37 #ifdef PIPE_OS_WINDOWS
42 #include <X11/Xutil.h>
47 #include "st_winsys.h"
50 typedef struct pipe_screen
* (GLAPIENTRY
*PFNGETGALLIUMSCREENMESAPROC
) (void);
51 typedef struct pipe_context
* (GLAPIENTRY
* PFNCREATEGALLIUMCONTEXTMESAPROC
) (void);
53 static PFNGETGALLIUMSCREENMESAPROC pfnGetGalliumScreenMESA
= NULL
;
54 static PFNCREATEGALLIUMCONTEXTMESAPROC pfnCreateGalliumContextMESA
= NULL
;
57 /* XXX: Force init_gallium symbol to be linked */
58 extern void init_gallium(void);
59 void (*force_init_gallium_linkage
)(void) = &init_gallium
;
62 #ifdef PIPE_OS_WINDOWS
65 st_hardpipe_load(void)
71 PIXELFORMATDESCRIPTOR pfd
;
74 if(pfnGetGalliumScreenMESA
&& pfnCreateGalliumContextMESA
)
77 memset(&wc
, 0, sizeof wc
);
78 wc
.lpfnWndProc
= DefWindowProc
;
79 wc
.lpszClassName
= "gallium";
80 wc
.style
= CS_OWNDC
| CS_HREDRAW
| CS_VREDRAW
;
83 hwnd
= CreateWindow(wc
.lpszClassName
, "gallium", 0, 0, 0, 0, 0, NULL
, 0, wc
.hInstance
, NULL
);
95 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
96 pfd
.iLayerType
= PFD_MAIN_PLANE
;
97 pfd
.iPixelType
= PFD_TYPE_RGBA
;
98 pfd
.nSize
= sizeof(pfd
);
101 iPixelFormat
= ChoosePixelFormat(hdc
, &pfd
);
103 pfd
.dwFlags
|= PFD_DOUBLEBUFFER
;
104 iPixelFormat
= ChoosePixelFormat(hdc
, &pfd
);
109 SetPixelFormat(hdc
, iPixelFormat
, &pfd
);
110 hglrc
= wglCreateContext(hdc
);
114 if (!wglMakeCurrent(hdc
, hglrc
))
117 pfnGetGalliumScreenMESA
= (PFNGETGALLIUMSCREENMESAPROC
)wglGetProcAddress("wglGetGalliumScreenMESA");
118 if(!pfnGetGalliumScreenMESA
)
121 pfnCreateGalliumContextMESA
= (PFNCREATEGALLIUMCONTEXTMESAPROC
)wglGetProcAddress("wglCreateGalliumContextMESA");
122 if(!pfnCreateGalliumContextMESA
)
132 static INLINE boolean
133 st_hardpipe_load(void)
138 int attribSingle
[] = {
144 int attribDouble
[] = {
151 XVisualInfo
*visinfo
;
152 GLXContext ctx
= NULL
;
153 XSetWindowAttributes attr
;
155 int width
= 100, height
= 100;
158 dpy
= XOpenDisplay(NULL
);
164 root
= RootWindow(dpy
, scrnum
);
166 visinfo
= glXChooseVisual(dpy
, scrnum
, attribSingle
);
168 visinfo
= glXChooseVisual(dpy
, scrnum
, attribDouble
);
172 ctx
= glXCreateContext( dpy
, visinfo
, NULL
, True
);
177 attr
.background_pixel
= 0;
178 attr
.border_pixel
= 0;
179 attr
.colormap
= XCreateColormap(dpy
, root
, visinfo
->visual
, AllocNone
);
180 attr
.event_mask
= StructureNotifyMask
| ExposureMask
;
182 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
184 win
= XCreateWindow(dpy
, root
, 0, 0, width
, height
,
185 0, visinfo
->depth
, InputOutput
,
186 visinfo
->visual
, mask
, &attr
);
188 if (!glXMakeCurrent(dpy
, win
, ctx
))
191 pfnGetGalliumScreenMESA
= (PFNGETGALLIUMSCREENMESAPROC
)glXGetProcAddressARB((const GLubyte
*)"glXGetGalliumScreenMESA");
192 if(!pfnGetGalliumScreenMESA
)
195 pfnCreateGalliumContextMESA
= (PFNCREATEGALLIUMCONTEXTMESAPROC
)glXGetProcAddressARB((const GLubyte
*)"glXCreateGalliumContextMESA");
196 if(!pfnCreateGalliumContextMESA
)
199 glXDestroyContext(dpy
, ctx
);
201 XDestroyWindow(dpy
, win
);
210 static struct pipe_screen
*
211 st_hardpipe_screen_create(void)
213 if(st_hardpipe_load())
214 return pfnGetGalliumScreenMESA();
216 return st_softpipe_winsys
.screen_create();
220 static struct pipe_context
*
221 st_hardpipe_context_create(struct pipe_screen
*screen
)
223 if(st_hardpipe_load()) {
224 if(screen
== pfnGetGalliumScreenMESA())
225 return pfnCreateGalliumContextMESA();
230 return st_softpipe_winsys
.context_create(screen
);
234 const struct st_winsys st_hardpipe_winsys
= {
235 &st_hardpipe_screen_create
,
236 &st_hardpipe_context_create