add gamma driver - no kernel driver yet
[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 "context.h"
38 #include "matrix.h"
39 #include "simple_list.h"
40
41 #include "i810screen.h"
42 #include "i810_dri.h"
43
44 #include "i810state.h"
45 #include "i810tex.h"
46 #include "i810span.h"
47 #include "i810tris.h"
48 #include "i810ioctl.h"
49
50
51
52 /* static int i810_malloc_proxy_buf(drmBufMapPtr buffers) */
53 /* { */
54 /* char *buffer; */
55 /* drmBufPtr buf; */
56 /* int i; */
57
58 /* buffer = CALLOC(I810_DMA_BUF_SZ); */
59 /* if(buffer == NULL) return -1; */
60 /* for(i = 0; i < I810_DMA_BUF_NR; i++) { */
61 /* buf = &(buffers->list[i]); */
62 /* buf->address = (drmAddress)buffer; */
63 /* } */
64 /* return 0; */
65 /* } */
66
67 static drmBufMapPtr i810_create_empty_buffers(void)
68 {
69 drmBufMapPtr retval;
70
71 retval = (drmBufMapPtr)ALIGN_MALLOC(sizeof(drmBufMap));
72 if(retval == NULL) return NULL;
73 memset(retval, 0, sizeof(drmBufMap));
74 retval->list = (drmBufPtr)ALIGN_MALLOC(sizeof(drmBuf) * I810_DMA_BUF_NR);
75 if(retval->list == NULL) {
76 Xfree(retval);
77 return NULL;
78 }
79 memset(retval->list, 0, sizeof(drmBuf) * I810_DMA_BUF_NR);
80 return retval;
81 }
82
83
84 static GLboolean
85 i810InitDriver(__DRIscreenPrivate *sPriv)
86 {
87 i810ScreenPrivate *i810Screen;
88 I810DRIPtr gDRIPriv = (I810DRIPtr)sPriv->pDevPriv;
89
90 /* Check the DRI externsion version */
91 if ( sPriv->driMajor != 4 || sPriv->driMinor < 0 ) {
92 __driUtilMessage( "i810 DRI driver expected DRI version 4.0.x "
93 "but got version %d.%d.%d",
94 sPriv->driMajor, sPriv->driMinor, sPriv->driPatch );
95 return GL_FALSE;
96 }
97
98 /* Check that the DDX driver version is compatible */
99 if (sPriv->ddxMajor != 1 ||
100 sPriv->ddxMinor < 0) {
101 __driUtilMessage("i810 DRI driver expected DDX driver version 1.0.x but got version %d.%d.%d", sPriv->ddxMajor, sPriv->ddxMinor, sPriv->ddxPatch);
102 return GL_FALSE;
103 }
104
105 /* Check that the DRM driver version is compatible */
106 if (sPriv->drmMajor != 1 ||
107 sPriv->drmMinor < 2) {
108 __driUtilMessage("i810 DRI driver expected DRM driver version 1.2.x but got version %d.%d.%d", sPriv->drmMajor, sPriv->drmMinor, sPriv->drmPatch);
109 return GL_FALSE;
110 }
111
112 /* Allocate the private area */
113 i810Screen = (i810ScreenPrivate *)CALLOC(sizeof(i810ScreenPrivate));
114 if (!i810Screen) {
115 __driUtilMessage("i810InitDriver: alloc i810ScreenPrivate struct failed");
116 return GL_FALSE;
117 }
118
119 i810Screen->driScrnPriv = sPriv;
120 sPriv->private = (void *)i810Screen;
121
122 i810Screen->deviceID=gDRIPriv->deviceID;
123 i810Screen->width=gDRIPriv->width;
124 i810Screen->height=gDRIPriv->height;
125 i810Screen->mem=gDRIPriv->mem;
126 i810Screen->cpp=gDRIPriv->cpp;
127 i810Screen->fbStride=gDRIPriv->fbStride;
128 i810Screen->fbOffset=gDRIPriv->fbOffset;
129
130 if (gDRIPriv->bitsPerPixel == 15)
131 i810Screen->fbFormat = DV_PF_555;
132 else
133 i810Screen->fbFormat = DV_PF_565;
134
135 i810Screen->backOffset=gDRIPriv->backOffset;
136 i810Screen->depthOffset=gDRIPriv->depthOffset;
137 i810Screen->backPitch = gDRIPriv->auxPitch;
138 i810Screen->backPitchBits = gDRIPriv->auxPitchBits;
139 i810Screen->textureOffset=gDRIPriv->textureOffset;
140 i810Screen->textureSize=gDRIPriv->textureSize;
141 i810Screen->logTextureGranularity = gDRIPriv->logTextureGranularity;
142
143 i810Screen->bufs = i810_create_empty_buffers();
144 if (i810Screen->bufs == NULL) {
145 __driUtilMessage("i810InitDriver: i810_create_empty_buffers() failed");
146 Xfree(i810Screen);
147 return GL_FALSE;
148 }
149
150 i810Screen->back.handle = gDRIPriv->backbuffer;
151 i810Screen->back.size = gDRIPriv->backbufferSize;
152
153 if (drmMap(sPriv->fd,
154 i810Screen->back.handle,
155 i810Screen->back.size,
156 (drmAddress *)&i810Screen->back.map) != 0) {
157 Xfree(i810Screen);
158 sPriv->private = NULL;
159 __driUtilMessage("i810InitDriver: drmMap failed");
160 return GL_FALSE;
161 }
162
163 i810Screen->depth.handle = gDRIPriv->depthbuffer;
164 i810Screen->depth.size = gDRIPriv->depthbufferSize;
165
166 if (drmMap(sPriv->fd,
167 i810Screen->depth.handle,
168 i810Screen->depth.size,
169 (drmAddress *)&i810Screen->depth.map) != 0) {
170 Xfree(i810Screen);
171 drmUnmap(i810Screen->back.map, i810Screen->back.size);
172 sPriv->private = NULL;
173 __driUtilMessage("i810InitDriver: drmMap (2) failed");
174 return GL_FALSE;
175 }
176
177 i810Screen->tex.handle = gDRIPriv->textures;
178 i810Screen->tex.size = gDRIPriv->textureSize;
179
180 if (drmMap(sPriv->fd,
181 i810Screen->tex.handle,
182 i810Screen->tex.size,
183 (drmAddress *)&i810Screen->tex.map) != 0) {
184 Xfree(i810Screen);
185 drmUnmap(i810Screen->back.map, i810Screen->back.size);
186 drmUnmap(i810Screen->depth.map, i810Screen->depth.size);
187 sPriv->private = NULL;
188 __driUtilMessage("i810InitDriver: drmMap (3) failed");
189 return GL_FALSE;
190 }
191
192 i810Screen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
193
194 return GL_TRUE;
195 }
196
197 static void
198 i810DestroyScreen(__DRIscreenPrivate *sPriv)
199 {
200 i810ScreenPrivate *i810Screen = (i810ScreenPrivate *)sPriv->private;
201
202 /* Need to unmap all the bufs and maps here:
203 */
204 drmUnmap(i810Screen->back.map, i810Screen->back.size);
205 drmUnmap(i810Screen->depth.map, i810Screen->depth.size);
206 drmUnmap(i810Screen->tex.map, i810Screen->tex.size);
207
208 Xfree(i810Screen);
209 sPriv->private = NULL;
210 }
211
212
213 static GLboolean
214 i810CreateBuffer( __DRIscreenPrivate *driScrnPriv,
215 __DRIdrawablePrivate *driDrawPriv,
216 const __GLcontextModes *mesaVis,
217 GLboolean isPixmap )
218 {
219 if (isPixmap) {
220 return GL_FALSE; /* not implemented */
221 }
222 else {
223 driDrawPriv->driverPrivate = (void *)
224 _mesa_create_framebuffer(mesaVis,
225 GL_FALSE, /* software depth buffer? */
226 mesaVis->stencilBits > 0,
227 mesaVis->accumRedBits > 0,
228 GL_FALSE /* s/w alpha planes */);
229 return (driDrawPriv->driverPrivate != NULL);
230 }
231 }
232
233
234 static void
235 i810DestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
236 {
237 _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
238 }
239
240
241 static GLboolean
242 i810OpenCloseFullScreen(__DRIcontextPrivate *driContextPriv)
243 {
244 return GL_TRUE;
245 }
246
247 static const struct __DriverAPIRec i810API = {
248 .InitDriver = i810InitDriver,
249 .DestroyScreen = i810DestroyScreen,
250 .CreateContext = i810CreateContext,
251 .DestroyContext = i810DestroyContext,
252 .CreateBuffer = i810CreateBuffer,
253 .DestroyBuffer = i810DestroyBuffer,
254 .SwapBuffers = i810SwapBuffers,
255 .MakeCurrent = i810MakeCurrent,
256 .UnbindContext = i810UnbindContext,
257 .OpenFullScreen = i810OpenCloseFullScreen,
258 .CloseFullScreen = i810OpenCloseFullScreen,
259 .GetSwapInfo = NULL,
260 .GetMSC = NULL,
261 .WaitForMSC = NULL,
262 .WaitForSBC = NULL,
263 .SwapBuffersMSC = NULL
264 };
265
266
267 /*
268 * This is the bootstrap function for the driver.
269 * The __driCreateScreen name is the symbol that libGL.so fetches.
270 * Return: pointer to a __DRIscreenPrivate.
271 */
272 #ifndef _SOLO
273 void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc,
274 int numConfigs, __GLXvisualConfig *config)
275 {
276 __DRIscreenPrivate *psp;
277 psp = __driUtilCreateScreen(dpy, scrn, psc, numConfigs, config, &i810API);
278 return (void *) psp;
279 }
280 #else
281 void *__driCreateScreen(struct DRIDriverRec *driver,
282 struct DRIDriverContextRec *driverContext)
283 {
284 __DRIscreenPrivate *psp;
285 psp = __driUtilCreateScreen(driver, driverContext, &i810API);
286 return (void *) psp;
287 }
288 #endif