use utility function to check versions
[mesa.git] / src / mesa / drivers / dri / i810 / i810screen.c
1 /**************************************************************************
2
3 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
4 All Rights Reserved.
5
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:
13
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial portions
16 of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
22 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **************************************************************************/
27 /* $XFree86: xc/lib/GL/mesa/src/drv/i810/i810screen.c,v 1.2 2002/10/30 12:51:33 alanh Exp $ */
28
29 /*
30 * Authors:
31 * Keith Whitwell <keith@tungstengraphics.com>
32 *
33 */
34
35
36 #include "glheader.h"
37 #include "imports.h"
38 #include "context.h"
39 #include "matrix.h"
40 #include "simple_list.h"
41 #include "utils.h"
42
43 #include "i810screen.h"
44 #include "i810_dri.h"
45
46 #include "i810state.h"
47 #include "i810tex.h"
48 #include "i810span.h"
49 #include "i810tris.h"
50 #include "i810ioctl.h"
51
52
53
54 /* static int i810_malloc_proxy_buf(drmBufMapPtr buffers) */
55 /* { */
56 /* char *buffer; */
57 /* drmBufPtr buf; */
58 /* int i; */
59
60 /* buffer = CALLOC(I810_DMA_BUF_SZ); */
61 /* if(buffer == NULL) return -1; */
62 /* for(i = 0; i < I810_DMA_BUF_NR; i++) { */
63 /* buf = &(buffers->list[i]); */
64 /* buf->address = (drmAddress)buffer; */
65 /* } */
66 /* return 0; */
67 /* } */
68
69 static drmBufMapPtr i810_create_empty_buffers(void)
70 {
71 drmBufMapPtr retval;
72
73 retval = (drmBufMapPtr)ALIGN_MALLOC(sizeof(drmBufMap), 32);
74 if(retval == NULL) return NULL;
75 memset(retval, 0, sizeof(drmBufMap));
76 retval->list = (drmBufPtr)ALIGN_MALLOC(sizeof(drmBuf) * I810_DMA_BUF_NR, 32);
77 if(retval->list == NULL) {
78 ALIGN_FREE(retval);
79 return NULL;
80 }
81 memset(retval->list, 0, sizeof(drmBuf) * I810_DMA_BUF_NR);
82 return retval;
83 }
84
85
86 static GLboolean
87 i810InitDriver(__DRIscreenPrivate *sPriv)
88 {
89 i810ScreenPrivate *i810Screen;
90 I810DRIPtr gDRIPriv = (I810DRIPtr)sPriv->pDevPriv;
91
92 if ( ! driCheckDriDdxDrmVersions( sPriv, "i810", 4, 0, 1, 0, 1, 2 ) )
93 return GL_FALSE;
94
95 /* Allocate the private area */
96 i810Screen = (i810ScreenPrivate *)CALLOC(sizeof(i810ScreenPrivate));
97 if (!i810Screen) {
98 __driUtilMessage("i810InitDriver: alloc i810ScreenPrivate struct failed");
99 return GL_FALSE;
100 }
101
102 i810Screen->driScrnPriv = sPriv;
103 sPriv->private = (void *)i810Screen;
104
105 i810Screen->deviceID=gDRIPriv->deviceID;
106 i810Screen->width=gDRIPriv->width;
107 i810Screen->height=gDRIPriv->height;
108 i810Screen->mem=gDRIPriv->mem;
109 i810Screen->cpp=gDRIPriv->cpp;
110 i810Screen->fbStride=gDRIPriv->fbStride;
111 i810Screen->fbOffset=gDRIPriv->fbOffset;
112
113 if (gDRIPriv->bitsPerPixel == 15)
114 i810Screen->fbFormat = DV_PF_555;
115 else
116 i810Screen->fbFormat = DV_PF_565;
117
118 i810Screen->backOffset=gDRIPriv->backOffset;
119 i810Screen->depthOffset=gDRIPriv->depthOffset;
120 i810Screen->backPitch = gDRIPriv->auxPitch;
121 i810Screen->backPitchBits = gDRIPriv->auxPitchBits;
122 i810Screen->textureOffset=gDRIPriv->textureOffset;
123 i810Screen->textureSize=gDRIPriv->textureSize;
124 i810Screen->logTextureGranularity = gDRIPriv->logTextureGranularity;
125
126 i810Screen->bufs = i810_create_empty_buffers();
127 if (i810Screen->bufs == NULL) {
128 __driUtilMessage("i810InitDriver: i810_create_empty_buffers() failed");
129 FREE(i810Screen);
130 return GL_FALSE;
131 }
132
133 i810Screen->back.handle = gDRIPriv->backbuffer;
134 i810Screen->back.size = gDRIPriv->backbufferSize;
135
136 if (drmMap(sPriv->fd,
137 i810Screen->back.handle,
138 i810Screen->back.size,
139 (drmAddress *)&i810Screen->back.map) != 0) {
140 FREE(i810Screen);
141 sPriv->private = NULL;
142 __driUtilMessage("i810InitDriver: drmMap failed");
143 return GL_FALSE;
144 }
145
146 i810Screen->depth.handle = gDRIPriv->depthbuffer;
147 i810Screen->depth.size = gDRIPriv->depthbufferSize;
148
149 if (drmMap(sPriv->fd,
150 i810Screen->depth.handle,
151 i810Screen->depth.size,
152 (drmAddress *)&i810Screen->depth.map) != 0) {
153 FREE(i810Screen);
154 drmUnmap(i810Screen->back.map, i810Screen->back.size);
155 sPriv->private = NULL;
156 __driUtilMessage("i810InitDriver: drmMap (2) failed");
157 return GL_FALSE;
158 }
159
160 i810Screen->tex.handle = gDRIPriv->textures;
161 i810Screen->tex.size = gDRIPriv->textureSize;
162
163 if (drmMap(sPriv->fd,
164 i810Screen->tex.handle,
165 i810Screen->tex.size,
166 (drmAddress *)&i810Screen->tex.map) != 0) {
167 FREE(i810Screen);
168 drmUnmap(i810Screen->back.map, i810Screen->back.size);
169 drmUnmap(i810Screen->depth.map, i810Screen->depth.size);
170 sPriv->private = NULL;
171 __driUtilMessage("i810InitDriver: drmMap (3) failed");
172 return GL_FALSE;
173 }
174
175 i810Screen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
176
177 return GL_TRUE;
178 }
179
180 static void
181 i810DestroyScreen(__DRIscreenPrivate *sPriv)
182 {
183 i810ScreenPrivate *i810Screen = (i810ScreenPrivate *)sPriv->private;
184
185 /* Need to unmap all the bufs and maps here:
186 */
187 drmUnmap(i810Screen->back.map, i810Screen->back.size);
188 drmUnmap(i810Screen->depth.map, i810Screen->depth.size);
189 drmUnmap(i810Screen->tex.map, i810Screen->tex.size);
190
191 FREE(i810Screen);
192 sPriv->private = NULL;
193 }
194
195
196 static GLboolean
197 i810CreateBuffer( __DRIscreenPrivate *driScrnPriv,
198 __DRIdrawablePrivate *driDrawPriv,
199 const __GLcontextModes *mesaVis,
200 GLboolean isPixmap )
201 {
202 if (isPixmap) {
203 return GL_FALSE; /* not implemented */
204 }
205 else {
206 driDrawPriv->driverPrivate = (void *)
207 _mesa_create_framebuffer(mesaVis,
208 GL_FALSE, /* software depth buffer? */
209 mesaVis->stencilBits > 0,
210 mesaVis->accumRedBits > 0,
211 GL_FALSE /* s/w alpha planes */);
212 return (driDrawPriv->driverPrivate != NULL);
213 }
214 }
215
216
217 static void
218 i810DestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
219 {
220 _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
221 }
222
223
224 static GLboolean
225 i810OpenCloseFullScreen(__DRIcontextPrivate *driContextPriv)
226 {
227 return GL_TRUE;
228 }
229
230 static const struct __DriverAPIRec i810API = {
231 .InitDriver = i810InitDriver,
232 .DestroyScreen = i810DestroyScreen,
233 .CreateContext = i810CreateContext,
234 .DestroyContext = i810DestroyContext,
235 .CreateBuffer = i810CreateBuffer,
236 .DestroyBuffer = i810DestroyBuffer,
237 .SwapBuffers = i810SwapBuffers,
238 .MakeCurrent = i810MakeCurrent,
239 .UnbindContext = i810UnbindContext,
240 .OpenFullScreen = i810OpenCloseFullScreen,
241 .CloseFullScreen = i810OpenCloseFullScreen,
242 .GetSwapInfo = NULL,
243 .GetMSC = NULL,
244 .WaitForMSC = NULL,
245 .WaitForSBC = NULL,
246 .SwapBuffersMSC = NULL
247 };
248
249
250 /*
251 * This is the bootstrap function for the driver.
252 * The __driCreateScreen name is the symbol that libGL.so fetches.
253 * Return: pointer to a __DRIscreenPrivate.
254 */
255 #ifndef _SOLO
256 void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc,
257 int numConfigs, __GLXvisualConfig *config)
258 {
259 __DRIscreenPrivate *psp;
260 psp = __driUtilCreateScreen(dpy, scrn, psc, numConfigs, config, &i810API);
261 return (void *) psp;
262 }
263 #else
264 void *__driCreateScreen(struct DRIDriverRec *driver,
265 struct DRIDriverContextRec *driverContext)
266 {
267 __DRIscreenPrivate *psp;
268 psp = __driUtilCreateScreen(driver, driverContext, &i810API);
269 return (void *) psp;
270 }
271 #endif