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 #ifdef PIPE_OS_WINDOWS
60 st_hardpipe_load(void)
66 PIXELFORMATDESCRIPTOR pfd
;
69 if(pfnGetGalliumScreenMESA
&& pfnCreateGalliumContextMESA
)
72 memset(&wc
, 0, sizeof wc
);
73 wc
.lpfnWndProc
= DefWindowProc
;
74 wc
.lpszClassName
= "gallium";
75 wc
.style
= CS_OWNDC
| CS_HREDRAW
| CS_VREDRAW
;
78 hwnd
= CreateWindow(wc
.lpszClassName
, "gallium", 0, 0, 0, 0, 0, NULL
, 0, wc
.hInstance
, NULL
);
90 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
91 pfd
.iLayerType
= PFD_MAIN_PLANE
;
92 pfd
.iPixelType
= PFD_TYPE_RGBA
;
93 pfd
.nSize
= sizeof(pfd
);
96 iPixelFormat
= ChoosePixelFormat(hdc
, &pfd
);
98 pfd
.dwFlags
|= PFD_DOUBLEBUFFER
;
99 iPixelFormat
= ChoosePixelFormat(hdc
, &pfd
);
104 SetPixelFormat(hdc
, iPixelFormat
, &pfd
);
105 hglrc
= wglCreateContext(hdc
);
109 if (!wglMakeCurrent(hdc
, hglrc
))
112 pfnGetGalliumScreenMESA
= (PFNGETGALLIUMSCREENMESAPROC
)wglGetProcAddress("wglGetGalliumScreenMESA");
113 if(!pfnGetGalliumScreenMESA
)
116 pfnCreateGalliumContextMESA
= (PFNCREATEGALLIUMCONTEXTMESAPROC
)wglGetProcAddress("wglCreateGalliumContextMESA");
117 if(!pfnCreateGalliumContextMESA
)
127 static INLINE boolean
128 st_hardpipe_load(void)
133 int attribSingle
[] = {
139 int attribDouble
[] = {
146 XVisualInfo
*visinfo
;
147 GLXContext ctx
= NULL
;
148 XSetWindowAttributes attr
;
150 int width
= 100, height
= 100;
153 dpy
= XOpenDisplay(NULL
);
159 root
= RootWindow(dpy
, scrnum
);
161 visinfo
= glXChooseVisual(dpy
, scrnum
, attribSingle
);
163 visinfo
= glXChooseVisual(dpy
, scrnum
, attribDouble
);
167 ctx
= glXCreateContext( dpy
, visinfo
, NULL
, True
);
172 attr
.background_pixel
= 0;
173 attr
.border_pixel
= 0;
174 attr
.colormap
= XCreateColormap(dpy
, root
, visinfo
->visual
, AllocNone
);
175 attr
.event_mask
= StructureNotifyMask
| ExposureMask
;
177 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
179 win
= XCreateWindow(dpy
, root
, 0, 0, width
, height
,
180 0, visinfo
->depth
, InputOutput
,
181 visinfo
->visual
, mask
, &attr
);
183 if (!glXMakeCurrent(dpy
, win
, ctx
))
186 pfnGetGalliumScreenMESA
= (PFNGETGALLIUMSCREENMESAPROC
)glXGetProcAddressARB((const GLubyte
*)"glXGetGalliumScreenMESA");
187 if(!pfnGetGalliumScreenMESA
)
190 pfnCreateGalliumContextMESA
= (PFNCREATEGALLIUMCONTEXTMESAPROC
)glXGetProcAddressARB((const GLubyte
*)"glXCreateGalliumContextMESA");
191 if(!pfnCreateGalliumContextMESA
)
194 glXDestroyContext(dpy
, ctx
);
196 XDestroyWindow(dpy
, win
);
206 st_hardware_screen_create(void)
208 if(st_hardpipe_load())
209 return pfnGetGalliumScreenMESA();
211 return st_software_screen_create(NULL
);