Open/Close FullScreen die. unichrome and savage implemented, code is ifdef'd out
[mesa.git] / src / mesa / drivers / dri / unichrome / via_screen.c
1 /*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25 #include <stdio.h>
26
27 #include "utils.h"
28 #include "dri_util.h"
29 #include "glheader.h"
30 #include "context.h"
31 #include "matrix.h"
32 #include "simple_list.h"
33
34 #include "via_state.h"
35 #include "via_tex.h"
36 #include "via_span.h"
37 #include "via_tris.h"
38 #include "via_ioctl.h"
39 #include "via_screen.h"
40 #include "via_fb.h"
41
42 #include "via_dri.h"
43 extern viaContextPtr current_mesa;
44
45 static drmBufMapPtr via_create_empty_buffers(void)
46 {
47 drmBufMapPtr retval;
48
49 retval = (drmBufMapPtr)MALLOC(sizeof(drmBufMap));
50 if (retval == NULL) return NULL;
51 memset(retval, 0, sizeof(drmBufMap));
52
53 retval->list = (drmBufPtr)MALLOC(sizeof(drmBuf) * VIA_DMA_BUF_NR);
54 if (retval->list == NULL) {
55 FREE(retval);
56 return NULL;
57 }
58 memset(retval->list, 0, sizeof(drmBuf) * VIA_DMA_BUF_NR);
59 return retval;
60 }
61
62 static GLboolean
63 viaInitDriver(__DRIscreenPrivate *sPriv)
64 {
65 viaScreenPrivate *viaScreen;
66 VIADRIPtr gDRIPriv = (VIADRIPtr)sPriv->pDevPriv;
67 #ifdef DEBUG
68 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
69 #endif
70 if (!driCheckDriDdxDrmVersions(sPriv, "Via", 4, 0, 4, 0, 1, 1))
71 return GL_FALSE;
72
73 /* Allocate the private area */
74 viaScreen = (viaScreenPrivate *) CALLOC(sizeof(viaScreenPrivate));
75 if (!viaScreen) {
76 __driUtilMessage("viaInitDriver: alloc viaScreenPrivate struct failed");
77 return GL_FALSE;
78 }
79
80 viaScreen->driScrnPriv = sPriv;
81 sPriv->private = (void *)viaScreen;
82
83 viaScreen->deviceID = gDRIPriv->deviceID;
84 viaScreen->width = gDRIPriv->width;
85 viaScreen->height = gDRIPriv->height;
86 viaScreen->mem = gDRIPriv->mem;
87 viaScreen->bitsPerPixel = gDRIPriv->bytesPerPixel << 3;
88 viaScreen->bytesPerPixel = gDRIPriv->bytesPerPixel;
89 viaScreen->fbOffset = 0;
90 viaScreen->fbSize = gDRIPriv->fbSize;
91 #ifdef USE_XINERAMA
92 viaScreen->drixinerama = gDRIPriv->drixinerama;
93 #endif
94 /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
95 viaScreen->VQEnable = gDRIPriv->VQEnable;
96 #ifdef DEBUG
97 if (VIA_DEBUG) {
98 fprintf(stderr, "deviceID = %08x\n", viaScreen->deviceID);
99 fprintf(stderr, "width = %08x\n", viaScreen->width);
100 fprintf(stderr, "height = %08x\n", viaScreen->height);
101 fprintf(stderr, "cpp = %08x\n", viaScreen->cpp);
102 fprintf(stderr, "fbOffset = %08x\n", viaScreen->fbOffset);
103 }
104 #endif
105 /* DBG */
106 /*
107 if (gDRIPriv->bitsPerPixel == 15)
108 viaScreen->fbFormat = DV_PF_555;
109 else
110 viaScreen->fbFormat = DV_PF_565;
111 */
112
113 viaScreen->bufs = via_create_empty_buffers();
114 if (viaScreen->bufs == NULL) {
115 __driUtilMessage("viaInitDriver: via_create_empty_buffers() failed");
116 FREE(viaScreen);
117 return GL_FALSE;
118 }
119
120 if (drmMap(sPriv->fd,
121 gDRIPriv->regs.handle,
122 gDRIPriv->regs.size,
123 (drmAddress *)&viaScreen->reg) != 0) {
124 FREE(viaScreen);
125 sPriv->private = NULL;
126 __driUtilMessage("viaInitDriver: drmMap regs failed");
127 return GL_FALSE;
128 }
129
130 if (gDRIPriv->agp.size) {
131 if (drmMap(sPriv->fd,
132 gDRIPriv->agp.handle,
133 gDRIPriv->agp.size,
134 (drmAddress *)&viaScreen->agpLinearStart) != 0) {
135 FREE(viaScreen);
136 drmUnmap(viaScreen->reg, gDRIPriv->agp.size);
137 sPriv->private = NULL;
138 __driUtilMessage("viaInitDriver: drmMap agp failed");
139 return GL_FALSE;
140 }
141 viaScreen->agpBase = (GLuint *)gDRIPriv->agp.handle;
142 } else
143 viaScreen->agpLinearStart = 0;
144
145 viaScreen->sareaPrivOffset = gDRIPriv->sarea_priv_offset;
146 #ifdef DEBUG
147 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
148 #endif
149 return GL_TRUE;
150 }
151
152 static void
153 viaDestroyScreen(__DRIscreenPrivate *sPriv)
154 {
155 viaScreenPrivate *viaScreen = (viaScreenPrivate *)sPriv->private;
156 VIADRIPtr gDRIPriv = (VIADRIPtr)sPriv->pDevPriv;
157 #ifdef DEBUG
158 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
159 #endif
160 drmUnmap(viaScreen->reg, gDRIPriv->regs.size);
161 if (gDRIPriv->agp.size)
162 drmUnmap(viaScreen->agpLinearStart, gDRIPriv->agp.size);
163 #ifdef DEBUG
164 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
165 #endif
166 FREE(viaScreen);
167 sPriv->private = NULL;
168 }
169
170 static GLboolean
171 viaCreateBuffer(__DRIscreenPrivate *driScrnPriv,
172 __DRIdrawablePrivate *driDrawPriv,
173 const __GLcontextModes *mesaVis,
174 GLboolean isPixmap)
175 {
176 viaContextPtr vmesa = current_mesa;
177 #ifdef DEBUG
178 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
179 #endif
180 /*=* John Sheng [2003.7.2] for visual config & patch viewperf *=*/
181 if (mesaVis->depthBits == 32 && vmesa->depthBits == 16) {
182 vmesa->depthBits = mesaVis->depthBits;
183 vmesa->depth.size *= 2;
184 vmesa->depth.pitch *= 2;
185 vmesa->depth.bpp *= 2;
186 if (vmesa->depth.map)
187 via_free_depth_buffer(vmesa);
188 if (!via_alloc_depth_buffer(vmesa)) {
189 via_free_depth_buffer(vmesa);
190 return GL_FALSE;
191 }
192
193 ((__GLcontextModes*)mesaVis)->depthBits = 16; /* XXX : sure you want to change read-only data? */
194 }
195
196 if (isPixmap) {
197 driDrawPriv->driverPrivate = (void *)
198 _mesa_create_framebuffer(mesaVis,
199 GL_FALSE, /* software depth buffer? */
200 mesaVis->stencilBits > 0,
201 mesaVis->accumRedBits > 0,
202 GL_FALSE /* s/w alpha planes */);
203
204 if (vmesa) vmesa->drawType = GLX_PBUFFER_BIT;
205 #ifdef DEBUG
206 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
207 #endif
208 return (driDrawPriv->driverPrivate != NULL);
209 }
210 else {
211 driDrawPriv->driverPrivate = (void *)
212 _mesa_create_framebuffer(mesaVis,
213 GL_FALSE, /* software depth buffer? */
214 mesaVis->stencilBits > 0,
215 mesaVis->accumRedBits > 0,
216 GL_FALSE /* s/w alpha planes */);
217
218 if (vmesa) vmesa->drawType = GLX_WINDOW_BIT;
219 #ifdef DEBUG
220 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
221 #endif
222 return (driDrawPriv->driverPrivate != NULL);
223 }
224 }
225
226
227 static void
228 viaDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
229 {
230 #ifdef DEBUG
231 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
232 #endif
233 _mesa_destroy_framebuffer((GLframebuffer *)(driDrawPriv->driverPrivate));
234 #ifdef DEBUG
235 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
236 #endif
237 }
238
239
240 #if 0
241 /* Initialize the fullscreen mode.
242 */
243 GLboolean
244 XMesaOpenFullScreen(__DRIcontextPrivate *driContextPriv)
245 {
246 viaContextPtr vmesa = (viaContextPtr)driContextPriv->driverPrivate;
247 vmesa->doPageFlip = 1;
248 vmesa->currentPage = 0;
249 return GL_TRUE;
250 }
251
252 /* Shut down the fullscreen mode.
253 */
254 GLboolean
255 XMesaCloseFullScreen(__DRIcontextPrivate *driContextPriv)
256 {
257 viaContextPtr vmesa = (viaContextPtr)driContextPriv->driverPrivate;
258
259 if (vmesa->currentPage == 1) {
260 viaPageFlip(vmesa);
261 vmesa->currentPage = 0;
262 }
263
264 vmesa->doPageFlip = GL_FALSE;
265 vmesa->Setup[VIA_DESTREG_DI0] = vmesa->driScreen->front_offset;
266 return GL_TRUE;
267 }
268 #endif
269
270
271 static struct __DriverAPIRec viaAPI = {
272 viaInitDriver,
273 viaDestroyScreen,
274 viaCreateContext,
275 viaDestroyContext,
276 viaCreateBuffer,
277 viaDestroyBuffer,
278 viaSwapBuffers,
279 viaMakeCurrent,
280 viaUnbindContext
281 };
282
283
284 /*
285 * This is the bootstrap function for the driver.
286 * The __driCreateScreen name is the symbol that libGL.so fetches.
287 * Return: pointer to a __DRIscreenPrivate.
288 */
289 #ifndef _SOLO
290 void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc,
291 int numConfigs, __GLXvisualConfig *config)
292 {
293 __DRIscreenPrivate *psp;
294 psp = __driUtilCreateScreen(dpy, scrn, psc, numConfigs, config, &viaAPI);
295 return (void *)psp;
296 }
297 #else
298 void *__driCreateScreen(struct DRIDriverRec *driver,
299 struct DRIDriverContextRec *driverContext)
300 {
301 __DRIscreenPrivate *psp;
302 psp = __driUtilCreateScreen(driver, driverContext, &viaAPI);
303 return (void *) psp;
304 }
305 #endif