1 /**************************************************************************
3 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
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 above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
27 /* $XFree86: xc/lib/GL/mesa/src/drv/i810/i810screen.c,v 1.2 2002/10/30 12:51:33 alanh Exp $ */
31 * Keith Whitwell <keith@tungstengraphics.com>
39 #include "simple_list.h"
41 #include "i810screen.h"
44 #include "i810state.h"
48 #include "i810ioctl.h"
52 /* static int i810_malloc_proxy_buf(drmBufMapPtr buffers) */
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; */
67 static drmBufMapPtr
i810_create_empty_buffers(void)
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
) {
79 memset(retval
->list
, 0, sizeof(drmBuf
) * I810_DMA_BUF_NR
);
85 i810InitDriver(__DRIscreenPrivate
*sPriv
)
87 i810ScreenPrivate
*i810Screen
;
88 I810DRIPtr gDRIPriv
= (I810DRIPtr
)sPriv
->pDevPriv
;
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
);
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
);
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
);
112 /* Allocate the private area */
113 i810Screen
= (i810ScreenPrivate
*)CALLOC(sizeof(i810ScreenPrivate
));
115 __driUtilMessage("i810InitDriver: alloc i810ScreenPrivate struct failed");
119 i810Screen
->driScrnPriv
= sPriv
;
120 sPriv
->private = (void *)i810Screen
;
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
;
130 if (gDRIPriv
->bitsPerPixel
== 15)
131 i810Screen
->fbFormat
= DV_PF_555
;
133 i810Screen
->fbFormat
= DV_PF_565
;
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
;
143 i810Screen
->bufs
= i810_create_empty_buffers();
144 if (i810Screen
->bufs
== NULL
) {
145 __driUtilMessage("i810InitDriver: i810_create_empty_buffers() failed");
150 i810Screen
->back
.handle
= gDRIPriv
->backbuffer
;
151 i810Screen
->back
.size
= gDRIPriv
->backbufferSize
;
153 if (drmMap(sPriv
->fd
,
154 i810Screen
->back
.handle
,
155 i810Screen
->back
.size
,
156 (drmAddress
*)&i810Screen
->back
.map
) != 0) {
158 sPriv
->private = NULL
;
159 __driUtilMessage("i810InitDriver: drmMap failed");
163 i810Screen
->depth
.handle
= gDRIPriv
->depthbuffer
;
164 i810Screen
->depth
.size
= gDRIPriv
->depthbufferSize
;
166 if (drmMap(sPriv
->fd
,
167 i810Screen
->depth
.handle
,
168 i810Screen
->depth
.size
,
169 (drmAddress
*)&i810Screen
->depth
.map
) != 0) {
171 drmUnmap(i810Screen
->back
.map
, i810Screen
->back
.size
);
172 sPriv
->private = NULL
;
173 __driUtilMessage("i810InitDriver: drmMap (2) failed");
177 i810Screen
->tex
.handle
= gDRIPriv
->textures
;
178 i810Screen
->tex
.size
= gDRIPriv
->textureSize
;
180 if (drmMap(sPriv
->fd
,
181 i810Screen
->tex
.handle
,
182 i810Screen
->tex
.size
,
183 (drmAddress
*)&i810Screen
->tex
.map
) != 0) {
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");
192 i810Screen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
198 i810DestroyScreen(__DRIscreenPrivate
*sPriv
)
200 i810ScreenPrivate
*i810Screen
= (i810ScreenPrivate
*)sPriv
->private;
202 /* Need to unmap all the bufs and maps here:
204 drmUnmap(i810Screen
->back
.map
, i810Screen
->back
.size
);
205 drmUnmap(i810Screen
->depth
.map
, i810Screen
->depth
.size
);
206 drmUnmap(i810Screen
->tex
.map
, i810Screen
->tex
.size
);
209 sPriv
->private = NULL
;
214 i810CreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
215 __DRIdrawablePrivate
*driDrawPriv
,
216 const __GLcontextModes
*mesaVis
,
220 return GL_FALSE
; /* not implemented */
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
);
235 i810DestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
237 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
242 i810OpenCloseFullScreen(__DRIcontextPrivate
*driContextPriv
)
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
,
263 .SwapBuffersMSC
= NULL
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.
273 void *__driCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
274 int numConfigs
, __GLXvisualConfig
*config
)
276 __DRIscreenPrivate
*psp
;
277 psp
= __driUtilCreateScreen(dpy
, scrn
, psc
, numConfigs
, config
, &i810API
);
281 void *__driCreateScreen(struct DRIDriverRec
*driver
,
282 struct DRIDriverContextRec
*driverContext
)
284 __DRIscreenPrivate
*psp
;
285 psp
= __driUtilCreateScreen(driver
, driverContext
, &i810API
);