1 | /** @file $Id: vboxvideo_dri.c 20877 2009-06-24 06:23:48Z vboxsync $
|
---|
2 | *
|
---|
3 | * VirtualBox X11 Additions graphics driver, DRI support
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | * --------------------------------------------------------------------
|
---|
21 | *
|
---|
22 | * This code is based on:
|
---|
23 | *
|
---|
24 | * X11 TDFX driver, src/tdfx_dri.c
|
---|
25 | *
|
---|
26 | * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
|
---|
27 | * All Rights Reserved.
|
---|
28 | *
|
---|
29 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
30 | * copy of this software and associated documentation files (the
|
---|
31 | * "Software"), to deal in the Software without restriction, including
|
---|
32 | * without limitation the rights to use, copy, modify, merge, publish,
|
---|
33 | * distribute, sub license, and/or sell copies of the Software, and to
|
---|
34 | * permit persons to whom the Software is furnished to do so, subject to
|
---|
35 | * the following conditions:
|
---|
36 | *
|
---|
37 | * The above copyright notice and this permission notice (including the
|
---|
38 | * next paragraph) shall be included in all copies or substantial portions
|
---|
39 | * of the Software.
|
---|
40 | *
|
---|
41 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
---|
42 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
---|
43 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
---|
44 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
---|
45 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
---|
46 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
---|
47 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
---|
48 | *
|
---|
49 | * Authors:
|
---|
50 | * Daryll Strauss <[email protected]>
|
---|
51 | */
|
---|
52 |
|
---|
53 | #include "vboxvideo.h"
|
---|
54 | #ifndef PCIACCESS
|
---|
55 | # include "xf86Pci.h"
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | static Bool
|
---|
59 | VBOXCreateContext(ScreenPtr pScreen, VisualPtr visual,
|
---|
60 | drm_context_t hwContext, void *pVisualConfigPriv,
|
---|
61 | DRIContextType contextStore);
|
---|
62 | static void
|
---|
63 | VBOXDestroyContext(ScreenPtr pScreen, drm_context_t hwContext,
|
---|
64 | DRIContextType contextStore);
|
---|
65 | static void
|
---|
66 | VBOXDRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
|
---|
67 | DRIContextType oldContextType, void *oldContext,
|
---|
68 | DRIContextType newContextType, void *newContext);
|
---|
69 | static void
|
---|
70 | VBOXDRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index);
|
---|
71 | static void
|
---|
72 | VBOXDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
|
---|
73 | RegionPtr prgnSrc, CARD32 index);
|
---|
74 | static Bool
|
---|
75 | VBOXDRIOpenFullScreen(ScreenPtr pScreen);
|
---|
76 | static Bool
|
---|
77 | VBOXDRICloseFullScreen(ScreenPtr pScreen);
|
---|
78 | static void
|
---|
79 | VBOXDRITransitionTo2d(ScreenPtr pScreen);
|
---|
80 | static void
|
---|
81 | VBOXDRITransitionTo3d(ScreenPtr pScreen);
|
---|
82 |
|
---|
83 | static Bool
|
---|
84 | VBOXInitVisualConfigs(ScrnInfoPtr pScrn, VBOXPtr pVBox)
|
---|
85 | {
|
---|
86 | Bool rc = TRUE;
|
---|
87 | TRACE_ENTRY();
|
---|
88 | int cConfigs = 2; /* With and without double buffering */
|
---|
89 | __GLXvisualConfig *pConfigs = NULL;
|
---|
90 | pConfigs = (__GLXvisualConfig*) xcalloc(sizeof(__GLXvisualConfig),
|
---|
91 | cConfigs);
|
---|
92 | if (!pConfigs)
|
---|
93 | {
|
---|
94 | rc = FALSE;
|
---|
95 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
96 | "Disabling DRI: out of memory.\n");
|
---|
97 | }
|
---|
98 | for (int i = 0; rc && i < cConfigs; ++i)
|
---|
99 | {
|
---|
100 | pConfigs[i].vid = -1;
|
---|
101 | pConfigs[i].class = -1;
|
---|
102 | pConfigs[i].rgba = TRUE;
|
---|
103 | if (pScrn->bitsPerPixel == 16)
|
---|
104 | {
|
---|
105 | pConfigs[i].redSize = 5;
|
---|
106 | pConfigs[i].greenSize = 6;
|
---|
107 | pConfigs[i].blueSize = 5;
|
---|
108 | pConfigs[i].redMask = 0x0000F800;
|
---|
109 | pConfigs[i].greenMask = 0x000007E0;
|
---|
110 | pConfigs[i].blueMask = 0x0000001F;
|
---|
111 | }
|
---|
112 | else if (pScrn->bitsPerPixel == 32)
|
---|
113 | {
|
---|
114 | pConfigs[i].redSize = 8;
|
---|
115 | pConfigs[i].greenSize = 8;
|
---|
116 | pConfigs[i].blueSize = 8;
|
---|
117 | pConfigs[i].alphaSize = 8;
|
---|
118 | pConfigs[i].redMask = 0x00ff0000;
|
---|
119 | pConfigs[i].greenMask = 0x0000ff00;
|
---|
120 | pConfigs[i].blueMask = 0x000000ff;
|
---|
121 | pConfigs[i].alphaMask = 0xff000000;
|
---|
122 | }
|
---|
123 | else
|
---|
124 | rc = FALSE;
|
---|
125 | pConfigs[i].bufferSize = pScrn->bitsPerPixel;
|
---|
126 | pConfigs[i].visualRating = GLX_NONE;
|
---|
127 | pConfigs[i].transparentPixel = GLX_NONE;
|
---|
128 | }
|
---|
129 | if (rc)
|
---|
130 | {
|
---|
131 | pConfigs[0].doubleBuffer = FALSE;
|
---|
132 | pConfigs[1].doubleBuffer = TRUE;
|
---|
133 | pVBox->cVisualConfigs = cConfigs;
|
---|
134 | pVBox->pVisualConfigs = pConfigs;
|
---|
135 | TRACE_LOG("Calling GlxSetVisualConfigs\n");
|
---|
136 | GlxSetVisualConfigs(cConfigs, pConfigs, NULL);
|
---|
137 | }
|
---|
138 | if (!rc && pConfigs)
|
---|
139 | xfree(pConfigs);
|
---|
140 | TRACE_LOG("returning %s\n", BOOL_STR(rc));
|
---|
141 | return rc;
|
---|
142 | }
|
---|
143 |
|
---|
144 | #if 0
|
---|
145 | static void
|
---|
146 | VBOXDoWakeupHandler(int screenNum, pointer wakeupData, unsigned long result,
|
---|
147 | pointer pReadmask)
|
---|
148 | {
|
---|
149 |
|
---|
150 | }
|
---|
151 | #endif
|
---|
152 |
|
---|
153 | #if 0
|
---|
154 | static void
|
---|
155 | VBOXDoBlockHandler(int screenNum, pointer blockData, pointer pTimeout,
|
---|
156 | pointer pReadmask)
|
---|
157 | {
|
---|
158 |
|
---|
159 | }
|
---|
160 | #endif
|
---|
161 |
|
---|
162 | Bool VBOXDRIScreenInit(int scrnIndex, ScreenPtr pScreen, VBOXPtr pVBox)
|
---|
163 | {
|
---|
164 | DRIInfoPtr pDRIInfo = NULL;
|
---|
165 | Bool rc = TRUE;
|
---|
166 | ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
|
---|
167 |
|
---|
168 | TRACE_ENTRY();
|
---|
169 | pVBox->drmFD = -1;
|
---|
170 | if ( pScrn->bitsPerPixel != 16
|
---|
171 | && pScrn->bitsPerPixel != 32)
|
---|
172 | {
|
---|
173 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
174 | "DRI is only available in 16bpp or 32bpp graphics modes.\n");
|
---|
175 | rc = FALSE;
|
---|
176 | }
|
---|
177 | /* Assertion */
|
---|
178 | if ( (pScrn->displayWidth == 0)
|
---|
179 | || (pVBox->pciInfo == NULL)
|
---|
180 | || (pVBox->base == NULL)
|
---|
181 | || (pVBox->mapSize == 0))
|
---|
182 | {
|
---|
183 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "%s: preconditions failed\n",
|
---|
184 | __PRETTY_FUNCTION__);
|
---|
185 | rc = FALSE;
|
---|
186 | }
|
---|
187 | /* Check that the GLX, DRI, and DRM modules have been loaded by testing for
|
---|
188 | * canonical symbols in each module, the way all existing _dri drivers do.
|
---|
189 | */
|
---|
190 | if (rc)
|
---|
191 | {
|
---|
192 | TRACE_LOG("Checking symbols\n");
|
---|
193 | if ( !xf86LoaderCheckSymbol("GlxSetVisualConfigs")
|
---|
194 | || !xf86LoaderCheckSymbol("drmAvailable")
|
---|
195 | || !xf86LoaderCheckSymbol("DRIQueryVersion"))
|
---|
196 | {
|
---|
197 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
198 | "Disabling DRI due to missing server functionality.\n");
|
---|
199 | rc = FALSE;
|
---|
200 | }
|
---|
201 | }
|
---|
202 | /* Check the DRI version */
|
---|
203 | if (rc)
|
---|
204 | {
|
---|
205 | int major, minor, patch;
|
---|
206 | TRACE_LOG("Checking DRI version\n");
|
---|
207 | DRIQueryVersion(&major, &minor, &patch);
|
---|
208 | if (major != DRIINFO_MAJOR_VERSION || minor < DRIINFO_MINOR_VERSION)
|
---|
209 | {
|
---|
210 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
211 | "Disabling DRI due to a version mismatch between server and driver. Server version: %d.%d. Driver version: %d.%d\n",
|
---|
212 | major, minor, DRIINFO_MAJOR_VERSION, DRIINFO_MINOR_VERSION);
|
---|
213 | rc = FALSE;
|
---|
214 | }
|
---|
215 | }
|
---|
216 | if (rc)
|
---|
217 | {
|
---|
218 | TRACE_LOG("Creating DRIInfoRec\n");
|
---|
219 | pDRIInfo = DRICreateInfoRec();
|
---|
220 | if (!pDRIInfo)
|
---|
221 | {
|
---|
222 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
223 | "Disabling DRI: out of memory.\n");
|
---|
224 | rc = FALSE;
|
---|
225 | }
|
---|
226 | else
|
---|
227 | pVBox->pDRIInfo = pDRIInfo;
|
---|
228 | }
|
---|
229 | if (rc)
|
---|
230 | {
|
---|
231 | pDRIInfo->CreateContext = VBOXCreateContext;
|
---|
232 | pDRIInfo->DestroyContext = VBOXDestroyContext;
|
---|
233 | pDRIInfo->SwapContext = VBOXDRISwapContext;
|
---|
234 | pDRIInfo->InitBuffers = VBOXDRIInitBuffers;
|
---|
235 | pDRIInfo->MoveBuffers = VBOXDRIMoveBuffers;
|
---|
236 | pDRIInfo->OpenFullScreen = VBOXDRIOpenFullScreen;
|
---|
237 | pDRIInfo->CloseFullScreen = VBOXDRICloseFullScreen;
|
---|
238 | pDRIInfo->TransitionTo2d = VBOXDRITransitionTo2d;
|
---|
239 | pDRIInfo->TransitionTo3d = VBOXDRITransitionTo3d;
|
---|
240 |
|
---|
241 | /* These two are set in DRICreateInfoRec(). */
|
---|
242 | pDRIInfo->wrap.ValidateTree = NULL;
|
---|
243 | pDRIInfo->wrap.PostValidateTree = NULL;
|
---|
244 |
|
---|
245 | pDRIInfo->drmDriverName = VBOX_DRM_DRIVER_NAME;
|
---|
246 | pDRIInfo->clientDriverName = VBOX_DRI_DRIVER_NAME;
|
---|
247 | #ifdef PCIACCESS
|
---|
248 | pDRIInfo->busIdString = DRICreatePCIBusID(pVBox->pciInfo);
|
---|
249 | #else
|
---|
250 | pDRIInfo->busIdString = xalloc(64);
|
---|
251 | sprintf(pDRIInfo->busIdString, "PCI:%d:%d:%d",
|
---|
252 | ((pciConfigPtr)pVBox->pciInfo->thisCard)->busnum,
|
---|
253 | ((pciConfigPtr)pVBox->pciInfo->thisCard)->devnum,
|
---|
254 | ((pciConfigPtr)pVBox->pciInfo->thisCard)->funcnum);
|
---|
255 | #endif
|
---|
256 | pDRIInfo->ddxDriverMajorVersion = VBOX_VIDEO_MAJOR;
|
---|
257 | pDRIInfo->ddxDriverMinorVersion = VBOX_VIDEO_MINOR;
|
---|
258 | pDRIInfo->ddxDriverPatchVersion = 0;
|
---|
259 | pDRIInfo->ddxDrawableTableEntry = VBOX_MAX_DRAWABLES;
|
---|
260 | pDRIInfo->maxDrawableTableEntry = VBOX_MAX_DRAWABLES;
|
---|
261 | pDRIInfo->frameBufferPhysicalAddress = (pointer)pVBox->mapPhys;
|
---|
262 | pDRIInfo->frameBufferSize = pVBox->mapSize;
|
---|
263 | pDRIInfo->frameBufferStride = pScrn->displayWidth
|
---|
264 | * pScrn->bitsPerPixel / 8;
|
---|
265 | pDRIInfo->SAREASize = SAREA_MAX; /* we have no private bits yet. */
|
---|
266 | /* This can't be zero, as the server callocs this size and checks for
|
---|
267 | * non-NULL... */
|
---|
268 | pDRIInfo->contextSize = 4;
|
---|
269 | pDRIInfo->driverSwapMethod = DRI_HIDE_X_CONTEXT;
|
---|
270 | pDRIInfo->bufferRequests = DRI_ALL_WINDOWS;
|
---|
271 | TRACE_LOG("Calling DRIScreenInit\n");
|
---|
272 | if (!DRIScreenInit(pScreen, pDRIInfo, &pVBox->drmFD))
|
---|
273 | rc = FALSE;
|
---|
274 | if (!rc)
|
---|
275 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
276 | "DRIScreenInit failed, disabling DRI.\n");
|
---|
277 | }
|
---|
278 | if (rc && !VBOXInitVisualConfigs(pScrn, pVBox))
|
---|
279 | {
|
---|
280 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
281 | "VBOXInitVisualConfigs failed, disabling DRI.\n");
|
---|
282 | rc = FALSE;
|
---|
283 | }
|
---|
284 | xf86DrvMsg(pScrn->scrnIndex, X_INFO, "visual configurations initialized\n");
|
---|
285 |
|
---|
286 | /* Check the DRM version */
|
---|
287 | if (rc)
|
---|
288 | {
|
---|
289 | drmVersionPtr version = drmGetVersion(pVBox->drmFD);
|
---|
290 | TRACE_LOG("Checking DRM version\n");
|
---|
291 | if (version)
|
---|
292 | {
|
---|
293 | if (version->version_major != 1 || version->version_minor < 0)
|
---|
294 | {
|
---|
295 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
296 | "Bad DRM driver version %d.%d, expected version 1.0. Disabling DRI.\n",
|
---|
297 | version->version_major, version->version_minor);
|
---|
298 | rc = FALSE;
|
---|
299 | }
|
---|
300 | drmFreeVersion(version);
|
---|
301 | }
|
---|
302 | }
|
---|
303 |
|
---|
304 | /* Clean up on failure. */
|
---|
305 | if (!rc)
|
---|
306 | {
|
---|
307 | if (pVBox->pDRIInfo)
|
---|
308 | DRIDestroyInfoRec(pVBox->pDRIInfo);
|
---|
309 | pVBox->pDRIInfo = NULL;
|
---|
310 | if (pVBox->drmFD >= 0)
|
---|
311 | VBOXDRICloseScreen(pScreen, pVBox);
|
---|
312 | pVBox->drmFD = -1;
|
---|
313 | }
|
---|
314 | TRACE_LOG("returning %s\n", BOOL_STR(rc));
|
---|
315 | return rc;
|
---|
316 | }
|
---|
317 |
|
---|
318 | void VBOXDRIUpdateStride(ScrnInfoPtr pScrn, VBOXPtr pVBox)
|
---|
319 | {
|
---|
320 | DRIInfoPtr pDRIInfo = pVBox->pDRIInfo;
|
---|
321 | pDRIInfo->frameBufferStride = pScrn->displayWidth
|
---|
322 | * pScrn->bitsPerPixel / 8;
|
---|
323 | }
|
---|
324 |
|
---|
325 | void
|
---|
326 | VBOXDRICloseScreen(ScreenPtr pScreen, VBOXPtr pVBox)
|
---|
327 | {
|
---|
328 | DRICloseScreen(pScreen);
|
---|
329 | DRIDestroyInfoRec(pVBox->pDRIInfo);
|
---|
330 | pVBox->pDRIInfo=0;
|
---|
331 | if (pVBox->pVisualConfigs)
|
---|
332 | xfree(pVBox->pVisualConfigs);
|
---|
333 | pVBox->cVisualConfigs = 0;
|
---|
334 | pVBox->pVisualConfigs = NULL;
|
---|
335 | }
|
---|
336 |
|
---|
337 | static Bool
|
---|
338 | VBOXCreateContext(ScreenPtr pScreen, VisualPtr visual,
|
---|
339 | drm_context_t hwContext, void *pVisualConfigPriv,
|
---|
340 | DRIContextType contextStore)
|
---|
341 | {
|
---|
342 | return TRUE;
|
---|
343 | }
|
---|
344 |
|
---|
345 | static void
|
---|
346 | VBOXDestroyContext(ScreenPtr pScreen, drm_context_t hwContext,
|
---|
347 | DRIContextType contextStore)
|
---|
348 | {
|
---|
349 | }
|
---|
350 |
|
---|
351 | Bool
|
---|
352 | VBOXDRIFinishScreenInit(ScreenPtr pScreen)
|
---|
353 | {
|
---|
354 | return DRIFinishScreenInit(pScreen);
|
---|
355 | }
|
---|
356 |
|
---|
357 | static void
|
---|
358 | VBOXDRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
|
---|
359 | DRIContextType oldContextType, void *oldContext,
|
---|
360 | DRIContextType newContextType, void *newContext)
|
---|
361 | {
|
---|
362 | }
|
---|
363 |
|
---|
364 | static void
|
---|
365 | VBOXDRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index)
|
---|
366 | {
|
---|
367 | }
|
---|
368 |
|
---|
369 | static void
|
---|
370 | VBOXDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
|
---|
371 | RegionPtr prgnSrc, CARD32 index)
|
---|
372 | {
|
---|
373 | }
|
---|
374 |
|
---|
375 | /* Apparently the next two are just legacy. */
|
---|
376 | static Bool
|
---|
377 | VBOXDRIOpenFullScreen(ScreenPtr pScreen)
|
---|
378 | {
|
---|
379 | return TRUE;
|
---|
380 | }
|
---|
381 |
|
---|
382 | static Bool
|
---|
383 | VBOXDRICloseFullScreen(ScreenPtr pScreen)
|
---|
384 | {
|
---|
385 | return TRUE;
|
---|
386 | }
|
---|
387 |
|
---|
388 | static void
|
---|
389 | VBOXDRITransitionTo2d(ScreenPtr pScreen)
|
---|
390 | {
|
---|
391 | }
|
---|
392 |
|
---|
393 | static void
|
---|
394 | VBOXDRITransitionTo3d(ScreenPtr pScreen)
|
---|
395 | {
|
---|
396 | }
|
---|
397 |
|
---|