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>
40 #include "simple_list.h"
43 #include "i810screen.h"
46 #include "i810state.h"
50 #include "i810ioctl.h"
54 /* static int i810_malloc_proxy_buf(drmBufMapPtr buffers) */
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; */
69 static drmBufMapPtr
i810_create_empty_buffers(void)
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
) {
81 memset(retval
->list
, 0, sizeof(drmBuf
) * I810_DMA_BUF_NR
);
87 i810InitDriver(__DRIscreenPrivate
*sPriv
)
89 i810ScreenPrivate
*i810Screen
;
90 I810DRIPtr gDRIPriv
= (I810DRIPtr
)sPriv
->pDevPriv
;
92 if ( ! driCheckDriDdxDrmVersions( sPriv
, "i810", 4, 0, 1, 0, 1, 2 ) )
95 /* Allocate the private area */
96 i810Screen
= (i810ScreenPrivate
*)CALLOC(sizeof(i810ScreenPrivate
));
98 __driUtilMessage("i810InitDriver: alloc i810ScreenPrivate struct failed");
102 i810Screen
->driScrnPriv
= sPriv
;
103 sPriv
->private = (void *)i810Screen
;
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
;
113 if (gDRIPriv
->bitsPerPixel
== 15)
114 i810Screen
->fbFormat
= DV_PF_555
;
116 i810Screen
->fbFormat
= DV_PF_565
;
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
;
126 i810Screen
->bufs
= i810_create_empty_buffers();
127 if (i810Screen
->bufs
== NULL
) {
128 __driUtilMessage("i810InitDriver: i810_create_empty_buffers() failed");
133 i810Screen
->back
.handle
= gDRIPriv
->backbuffer
;
134 i810Screen
->back
.size
= gDRIPriv
->backbufferSize
;
136 if (drmMap(sPriv
->fd
,
137 i810Screen
->back
.handle
,
138 i810Screen
->back
.size
,
139 (drmAddress
*)&i810Screen
->back
.map
) != 0) {
141 sPriv
->private = NULL
;
142 __driUtilMessage("i810InitDriver: drmMap failed");
146 i810Screen
->depth
.handle
= gDRIPriv
->depthbuffer
;
147 i810Screen
->depth
.size
= gDRIPriv
->depthbufferSize
;
149 if (drmMap(sPriv
->fd
,
150 i810Screen
->depth
.handle
,
151 i810Screen
->depth
.size
,
152 (drmAddress
*)&i810Screen
->depth
.map
) != 0) {
154 drmUnmap(i810Screen
->back
.map
, i810Screen
->back
.size
);
155 sPriv
->private = NULL
;
156 __driUtilMessage("i810InitDriver: drmMap (2) failed");
160 i810Screen
->tex
.handle
= gDRIPriv
->textures
;
161 i810Screen
->tex
.size
= gDRIPriv
->textureSize
;
163 if (drmMap(sPriv
->fd
,
164 i810Screen
->tex
.handle
,
165 i810Screen
->tex
.size
,
166 (drmAddress
*)&i810Screen
->tex
.map
) != 0) {
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");
175 i810Screen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
181 i810DestroyScreen(__DRIscreenPrivate
*sPriv
)
183 i810ScreenPrivate
*i810Screen
= (i810ScreenPrivate
*)sPriv
->private;
185 /* Need to unmap all the bufs and maps here:
187 drmUnmap(i810Screen
->back
.map
, i810Screen
->back
.size
);
188 drmUnmap(i810Screen
->depth
.map
, i810Screen
->depth
.size
);
189 drmUnmap(i810Screen
->tex
.map
, i810Screen
->tex
.size
);
192 sPriv
->private = NULL
;
197 i810CreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
198 __DRIdrawablePrivate
*driDrawPriv
,
199 const __GLcontextModes
*mesaVis
,
203 return GL_FALSE
; /* not implemented */
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
);
218 i810DestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
220 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
225 i810OpenCloseFullScreen(__DRIcontextPrivate
*driContextPriv
)
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
,
246 .SwapBuffersMSC
= NULL
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.
256 void *__driCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
257 int numConfigs
, __GLXvisualConfig
*config
)
259 __DRIscreenPrivate
*psp
;
260 psp
= __driUtilCreateScreen(dpy
, scrn
, psc
, numConfigs
, config
, &i810API
);
264 void *__driCreateScreen(struct DRIDriverRec
*driver
,
265 struct DRIDriverContextRec
*driverContext
)
267 __DRIscreenPrivate
*psp
;
268 psp
= __driUtilCreateScreen(driver
, driverContext
, &i810API
);