VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo_dri.c@ 19495

Last change on this file since 19495 was 17451, checked in by vboxsync, 16 years ago

Additions/x11/vboxvideo: fixes to the DRI code, and activate it

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.0 KB
Line 
1/** @file $Id: vboxvideo_dri.c 17451 2009-03-06 10:28:41Z 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
58static Bool
59VBOXCreateContext(ScreenPtr pScreen, VisualPtr visual,
60 drm_context_t hwContext, void *pVisualConfigPriv,
61 DRIContextType contextStore);
62static void
63VBOXDestroyContext(ScreenPtr pScreen, drm_context_t hwContext,
64 DRIContextType contextStore);
65static void
66VBOXDRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
67 DRIContextType oldContextType, void *oldContext,
68 DRIContextType newContextType, void *newContext);
69static void
70VBOXDRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index);
71static void
72VBOXDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
73 RegionPtr prgnSrc, CARD32 index);
74static Bool
75VBOXDRIOpenFullScreen(ScreenPtr pScreen);
76static Bool
77VBOXDRICloseFullScreen(ScreenPtr pScreen);
78static void
79VBOXDRITransitionTo2d(ScreenPtr pScreen);
80static void
81VBOXDRITransitionTo3d(ScreenPtr pScreen);
82
83static Bool
84VBOXInitVisualConfigs(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
145static void
146VBOXDoWakeupHandler(int screenNum, pointer wakeupData, unsigned long result,
147 pointer pReadmask)
148{
149
150}
151#endif
152
153#if 0
154static void
155VBOXDoBlockHandler(int screenNum, pointer blockData, pointer pTimeout,
156 pointer pReadmask)
157{
158
159}
160#endif
161
162Bool 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 /* Check that the GLX, DRI, and DRM modules have been loaded by testing for
178 * canonical symbols in each module, the way all existing _dri drivers do.
179 */
180 if (rc)
181 {
182 TRACE_LOG("Checking symbols\n");
183 if ( !xf86LoaderCheckSymbol("GlxSetVisualConfigs")
184 || !xf86LoaderCheckSymbol("drmAvailable")
185 || !xf86LoaderCheckSymbol("DRIQueryVersion"))
186 {
187 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
188 "Disabling DRI due to missing server functionality.\n");
189 rc = FALSE;
190 }
191 }
192 /* Check the DRI version */
193 if (rc)
194 {
195 int major, minor, patch;
196 TRACE_LOG("Checking DRI version\n");
197 DRIQueryVersion(&major, &minor, &patch);
198 if (major != DRIINFO_MAJOR_VERSION || minor < DRIINFO_MINOR_VERSION)
199 {
200 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
201 "Disabling DRI due to a version mismatch between server and driver. Server version: %d.%d. Driver version: %d.%d\n",
202 major, minor, DRIINFO_MAJOR_VERSION, DRIINFO_MINOR_VERSION);
203 rc = FALSE;
204 }
205 }
206 if (rc)
207 {
208 TRACE_LOG("Creating DRIInfoRec\n");
209 pDRIInfo = DRICreateInfoRec();
210 if (!pDRIInfo)
211 {
212 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
213 "Disabling DRI: out of memory.\n");
214 rc = FALSE;
215 }
216 else
217 pVBox->pDRIInfo = pDRIInfo;
218 }
219 if (rc)
220 {
221 pDRIInfo->CreateContext = VBOXCreateContext;
222 pDRIInfo->DestroyContext = VBOXDestroyContext;
223 pDRIInfo->SwapContext = VBOXDRISwapContext;
224 pDRIInfo->InitBuffers = VBOXDRIInitBuffers;
225 pDRIInfo->MoveBuffers = VBOXDRIMoveBuffers;
226 pDRIInfo->OpenFullScreen = VBOXDRIOpenFullScreen;
227 pDRIInfo->CloseFullScreen = VBOXDRICloseFullScreen;
228 pDRIInfo->TransitionTo2d = VBOXDRITransitionTo2d;
229 pDRIInfo->TransitionTo3d = VBOXDRITransitionTo3d;
230
231 /* These two are set in DRICreateInfoRec(). */
232 pDRIInfo->wrap.ValidateTree = NULL;
233 pDRIInfo->wrap.PostValidateTree = NULL;
234
235 pDRIInfo->drmDriverName = VBOX_DRM_DRIVER_NAME;
236 pDRIInfo->clientDriverName = VBOX_DRI_DRIVER_NAME;
237#ifdef PCIACCESS
238 pDRIInfo->busIdString = DRICreatePCIBusID(pVBox->pciInfo);
239#else
240 pDRIInfo->busIdString = xalloc(64);
241 sprintf(pDRIInfo->busIdString, "PCI:%d:%d:%d",
242 ((pciConfigPtr)pVBox->pciInfo->thisCard)->busnum,
243 ((pciConfigPtr)pVBox->pciInfo->thisCard)->devnum,
244 ((pciConfigPtr)pVBox->pciInfo->thisCard)->funcnum);
245#endif
246 pDRIInfo->ddxDriverMajorVersion = VBOX_VIDEO_MAJOR;
247 pDRIInfo->ddxDriverMinorVersion = VBOX_VIDEO_MINOR;
248 pDRIInfo->ddxDriverPatchVersion = 0;
249 pDRIInfo->ddxDrawableTableEntry = VBOX_MAX_DRAWABLES;
250 pDRIInfo->maxDrawableTableEntry = VBOX_MAX_DRAWABLES;
251 pDRIInfo->frameBufferPhysicalAddress = pVBox->base;
252 pDRIInfo->frameBufferSize = pVBox->mapSize;
253 pDRIInfo->frameBufferStride = pScrn->displayWidth;
254 pDRIInfo->SAREASize = SAREA_MAX; /* we have no private bits yet. */
255 /* This can't be zero, as the server callocs this size and checks for
256 * non-NULL... */
257 pDRIInfo->contextSize = 4;
258 pDRIInfo->driverSwapMethod = DRI_HIDE_X_CONTEXT;
259 pDRIInfo->bufferRequests = DRI_ALL_WINDOWS;
260 TRACE_LOG("Calling DRIScreenInit\n");
261 if (!DRIScreenInit(pScreen, pDRIInfo, &pVBox->drmFD))
262 rc = FALSE;
263 if (!rc)
264 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
265 "DRIScreenInit failed, disabling DRI.\n");
266 }
267 if (rc && !VBOXInitVisualConfigs(pScrn, pVBox))
268 {
269 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
270 "VBOXInitVisualConfigs failed, disabling DRI.\n");
271 rc = FALSE;
272 }
273 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "visual configurations initialized\n");
274
275 /* Check the DRM version */
276 if (rc)
277 {
278 drmVersionPtr version = drmGetVersion(pVBox->drmFD);
279 TRACE_LOG("Checking DRM version\n");
280 if (version)
281 {
282 if (version->version_major != 1 || version->version_minor < 0)
283 {
284 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
285 "Bad DRM driver version %d.%d, expected version 1.0. Disabling DRI.\n",
286 version->version_major, version->version_minor);
287 rc = FALSE;
288 }
289 drmFreeVersion(version);
290 }
291 }
292
293 /* Clean up on failure. */
294 if (!rc)
295 {
296 if (pVBox->pDRIInfo)
297 DRIDestroyInfoRec(pVBox->pDRIInfo);
298 pVBox->pDRIInfo = NULL;
299 if (pVBox->drmFD >= 0)
300 VBOXDRICloseScreen(pScreen, pVBox);
301 pVBox->drmFD = -1;
302 }
303 TRACE_LOG("returning %s\n", BOOL_STR(rc));
304 return rc;
305}
306
307void
308VBOXDRICloseScreen(ScreenPtr pScreen, VBOXPtr pVBox)
309{
310 DRICloseScreen(pScreen);
311 DRIDestroyInfoRec(pVBox->pDRIInfo);
312 pVBox->pDRIInfo=0;
313 if (pVBox->pVisualConfigs)
314 xfree(pVBox->pVisualConfigs);
315 pVBox->cVisualConfigs = 0;
316 pVBox->pVisualConfigs = NULL;
317}
318
319static Bool
320VBOXCreateContext(ScreenPtr pScreen, VisualPtr visual,
321 drm_context_t hwContext, void *pVisualConfigPriv,
322 DRIContextType contextStore)
323{
324 return TRUE;
325}
326
327static void
328VBOXDestroyContext(ScreenPtr pScreen, drm_context_t hwContext,
329 DRIContextType contextStore)
330{
331}
332
333Bool
334VBOXDRIFinishScreenInit(ScreenPtr pScreen)
335{
336 return DRIFinishScreenInit(pScreen);
337}
338
339static void
340VBOXDRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
341 DRIContextType oldContextType, void *oldContext,
342 DRIContextType newContextType, void *newContext)
343{
344}
345
346static void
347VBOXDRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index)
348{
349}
350
351static void
352VBOXDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
353 RegionPtr prgnSrc, CARD32 index)
354{
355}
356
357/* Apparently the next two are just legacy. */
358static Bool
359VBOXDRIOpenFullScreen(ScreenPtr pScreen)
360{
361 return TRUE;
362}
363
364static Bool
365VBOXDRICloseFullScreen(ScreenPtr pScreen)
366{
367 return TRUE;
368}
369
370static void
371VBOXDRITransitionTo2d(ScreenPtr pScreen)
372{
373}
374
375static void
376VBOXDRITransitionTo3d(ScreenPtr pScreen)
377{
378}
379
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette