VirtualBox

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

Last change on this file since 43105 was 43081, checked in by vboxsync, 12 years ago

Additions/x11/vboxvideo: some header file inclusion clean-up.

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