VirtualBox

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

Last change on this file since 34079 was 32495, checked in by vboxsync, 14 years ago

Additions/x11/vboxvideo: removed some unneeded structure members

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.4 KB
Line 
1/** @file $Id: vboxvideo_dri.c 32495 2010-09-14 22:14:42Z 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 "vboxvideo.h"
50#ifndef PCIACCESS
51# include "xf86Pci.h"
52#endif
53
54static Bool
55VBOXCreateContext(ScreenPtr pScreen, VisualPtr visual,
56 drm_context_t hwContext, void *pVisualConfigPriv,
57 DRIContextType contextStore);
58static void
59VBOXDestroyContext(ScreenPtr pScreen, drm_context_t hwContext,
60 DRIContextType contextStore);
61static void
62VBOXDRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
63 DRIContextType oldContextType, void *oldContext,
64 DRIContextType newContextType, void *newContext);
65static void
66VBOXDRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index);
67static void
68VBOXDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
69 RegionPtr prgnSrc, CARD32 index);
70static Bool
71VBOXDRIOpenFullScreen(ScreenPtr pScreen);
72static Bool
73VBOXDRICloseFullScreen(ScreenPtr pScreen);
74static void
75VBOXDRITransitionTo2d(ScreenPtr pScreen);
76static void
77VBOXDRITransitionTo3d(ScreenPtr pScreen);
78
79static Bool
80VBOXInitVisualConfigs(ScrnInfoPtr pScrn, VBOXPtr pVBox)
81{
82 Bool rc = TRUE;
83 TRACE_ENTRY();
84 int cConfigs = 2; /* With and without double buffering */
85 __GLXvisualConfig *pConfigs = NULL;
86 pConfigs = (__GLXvisualConfig*) calloc(sizeof(__GLXvisualConfig),
87 cConfigs);
88 if (!pConfigs)
89 {
90 rc = FALSE;
91 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
92 "Disabling DRI: out of memory.\n");
93 }
94 for (int i = 0; rc && i < cConfigs; ++i)
95 {
96 pConfigs[i].vid = -1;
97 pConfigs[i].class = -1;
98 pConfigs[i].rgba = TRUE;
99 if (pScrn->bitsPerPixel == 16)
100 {
101 pConfigs[i].redSize = 5;
102 pConfigs[i].greenSize = 6;
103 pConfigs[i].blueSize = 5;
104 pConfigs[i].redMask = 0x0000F800;
105 pConfigs[i].greenMask = 0x000007E0;
106 pConfigs[i].blueMask = 0x0000001F;
107 }
108 else if (pScrn->bitsPerPixel == 32)
109 {
110 pConfigs[i].redSize = 8;
111 pConfigs[i].greenSize = 8;
112 pConfigs[i].blueSize = 8;
113 pConfigs[i].alphaSize = 8;
114 pConfigs[i].redMask = 0x00ff0000;
115 pConfigs[i].greenMask = 0x0000ff00;
116 pConfigs[i].blueMask = 0x000000ff;
117 pConfigs[i].alphaMask = 0xff000000;
118 }
119 else
120 rc = FALSE;
121 pConfigs[i].bufferSize = pScrn->bitsPerPixel;
122 pConfigs[i].visualRating = GLX_NONE;
123 pConfigs[i].transparentPixel = GLX_NONE;
124 }
125 if (rc)
126 {
127 pConfigs[0].doubleBuffer = FALSE;
128 pConfigs[1].doubleBuffer = TRUE;
129 pVBox->cVisualConfigs = cConfigs;
130 pVBox->pVisualConfigs = pConfigs;
131 TRACE_LOG("Calling GlxSetVisualConfigs\n");
132 GlxSetVisualConfigs(cConfigs, pConfigs, NULL);
133 }
134 if (!rc && pConfigs)
135 free(pConfigs);
136 TRACE_LOG("returning %s\n", BOOL_STR(rc));
137 return rc;
138}
139
140#if 0
141static void
142VBOXDoWakeupHandler(int screenNum, pointer wakeupData, unsigned long result,
143 pointer pReadmask)
144{
145
146}
147#endif
148
149#if 0
150static void
151VBOXDoBlockHandler(int screenNum, pointer blockData, pointer pTimeout,
152 pointer pReadmask)
153{
154
155}
156#endif
157
158Bool VBOXDRIScreenInit(int scrnIndex, ScreenPtr pScreen, VBOXPtr pVBox)
159{
160 DRIInfoPtr pDRIInfo = NULL;
161 Bool rc = TRUE;
162 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
163
164 TRACE_ENTRY();
165 pVBox->drmFD = -1;
166 if ( pScrn->bitsPerPixel != 16
167 && pScrn->bitsPerPixel != 32)
168 {
169 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
170 "DRI is only available in 16bpp or 32bpp graphics modes.\n");
171 rc = FALSE;
172 }
173 /* Assertion */
174 if ( (pScrn->displayWidth == 0)
175 || (pVBox->pciInfo == NULL)
176 || (pVBox->base == NULL)
177 || (pVBox->mapSize == 0))
178 {
179 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "%s: preconditions failed\n",
180 __PRETTY_FUNCTION__);
181 rc = FALSE;
182 }
183 /* Check that the GLX, DRI, and DRM modules have been loaded by testing for
184 * canonical symbols in each module, the way all existing _dri drivers do.
185 */
186 if (rc)
187 {
188 TRACE_LOG("Checking symbols\n");
189 if ( !xf86LoaderCheckSymbol("GlxSetVisualConfigs")
190 || !xf86LoaderCheckSymbol("drmAvailable")
191 || !xf86LoaderCheckSymbol("DRIQueryVersion"))
192 {
193 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
194 "Disabling DRI due to missing server functionality.\n");
195 rc = FALSE;
196 }
197 }
198 /* Check the DRI version */
199 if (rc)
200 {
201 int major, minor, patch;
202 TRACE_LOG("Checking DRI version\n");
203 DRIQueryVersion(&major, &minor, &patch);
204 if (major != DRIINFO_MAJOR_VERSION || minor < DRIINFO_MINOR_VERSION)
205 {
206 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
207 "Disabling DRI due to a version mismatch between server and driver. Server version: %d.%d. Driver version: %d.%d\n",
208 major, minor, DRIINFO_MAJOR_VERSION, DRIINFO_MINOR_VERSION);
209 rc = FALSE;
210 }
211 }
212 if (rc)
213 {
214 TRACE_LOG("Creating DRIInfoRec\n");
215 pDRIInfo = DRICreateInfoRec();
216 if (!pDRIInfo)
217 {
218 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
219 "Disabling DRI: out of memory.\n");
220 rc = FALSE;
221 }
222 else
223 pVBox->pDRIInfo = pDRIInfo;
224 }
225 if (rc)
226 {
227 pDRIInfo->CreateContext = VBOXCreateContext;
228 pDRIInfo->DestroyContext = VBOXDestroyContext;
229 pDRIInfo->SwapContext = VBOXDRISwapContext;
230 pDRIInfo->InitBuffers = VBOXDRIInitBuffers;
231 pDRIInfo->MoveBuffers = VBOXDRIMoveBuffers;
232 pDRIInfo->OpenFullScreen = VBOXDRIOpenFullScreen;
233 pDRIInfo->CloseFullScreen = VBOXDRICloseFullScreen;
234 pDRIInfo->TransitionTo2d = VBOXDRITransitionTo2d;
235 pDRIInfo->TransitionTo3d = VBOXDRITransitionTo3d;
236
237 /* These two are set in DRICreateInfoRec(). */
238 pDRIInfo->wrap.ValidateTree = NULL;
239 pDRIInfo->wrap.PostValidateTree = NULL;
240
241 pDRIInfo->drmDriverName = VBOX_DRM_DRIVER_NAME;
242 pDRIInfo->clientDriverName = VBOX_DRI_DRIVER_NAME;
243#ifdef PCIACCESS
244 pDRIInfo->busIdString = DRICreatePCIBusID(pVBox->pciInfo);
245#else
246 pDRIInfo->busIdString = alloc(64);
247 sprintf(pDRIInfo->busIdString, "PCI:%d:%d:%d",
248 ((pciConfigPtr)pVBox->pciInfo->thisCard)->busnum,
249 ((pciConfigPtr)pVBox->pciInfo->thisCard)->devnum,
250 ((pciConfigPtr)pVBox->pciInfo->thisCard)->funcnum);
251#endif
252 pDRIInfo->ddxDriverMajorVersion = VBOX_VIDEO_MAJOR;
253 pDRIInfo->ddxDriverMinorVersion = VBOX_VIDEO_MINOR;
254 pDRIInfo->ddxDriverPatchVersion = 0;
255 pDRIInfo->ddxDrawableTableEntry = VBOX_MAX_DRAWABLES;
256 pDRIInfo->maxDrawableTableEntry = VBOX_MAX_DRAWABLES;
257 pDRIInfo->frameBufferPhysicalAddress = (pointer)pScrn->memPhysBase;
258 pDRIInfo->frameBufferSize = pVBox->mapSize;
259 pDRIInfo->frameBufferStride = pScrn->displayWidth
260 * pScrn->bitsPerPixel / 8;
261 pDRIInfo->SAREASize = SAREA_MAX; /* we have no private bits yet. */
262 /* This can't be zero, as the server callocs this size and checks for
263 * non-NULL... */
264 pDRIInfo->contextSize = 4;
265 pDRIInfo->driverSwapMethod = DRI_HIDE_X_CONTEXT;
266 pDRIInfo->bufferRequests = DRI_ALL_WINDOWS;
267 TRACE_LOG("Calling DRIScreenInit\n");
268 if (!DRIScreenInit(pScreen, pDRIInfo, &pVBox->drmFD))
269 rc = FALSE;
270 if (!rc)
271 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
272 "DRIScreenInit failed, disabling DRI.\n");
273 }
274 if (rc && !VBOXInitVisualConfigs(pScrn, pVBox))
275 {
276 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
277 "VBOXInitVisualConfigs failed, disabling DRI.\n");
278 rc = FALSE;
279 }
280 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "visual configurations initialized\n");
281
282 /* Check the DRM version */
283 if (rc)
284 {
285 drmVersionPtr version = drmGetVersion(pVBox->drmFD);
286 TRACE_LOG("Checking DRM version\n");
287 if (version)
288 {
289 if (version->version_major != 1 || version->version_minor < 0)
290 {
291 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
292 "Bad DRM driver version %d.%d, expected version 1.0. Disabling DRI.\n",
293 version->version_major, version->version_minor);
294 rc = FALSE;
295 }
296 drmFreeVersion(version);
297 }
298 }
299
300 /* Clean up on failure. */
301 if (!rc)
302 {
303 if (pVBox->pDRIInfo)
304 DRIDestroyInfoRec(pVBox->pDRIInfo);
305 pVBox->pDRIInfo = NULL;
306 if (pVBox->drmFD >= 0)
307 VBOXDRICloseScreen(pScreen, pVBox);
308 pVBox->drmFD = -1;
309 }
310 TRACE_LOG("returning %s\n", BOOL_STR(rc));
311 return rc;
312}
313
314void VBOXDRIUpdateStride(ScrnInfoPtr pScrn, VBOXPtr pVBox)
315{
316 DRIInfoPtr pDRIInfo = pVBox->pDRIInfo;
317 pDRIInfo->frameBufferStride = pScrn->displayWidth
318 * pScrn->bitsPerPixel / 8;
319}
320
321void
322VBOXDRICloseScreen(ScreenPtr pScreen, VBOXPtr pVBox)
323{
324 DRICloseScreen(pScreen);
325 DRIDestroyInfoRec(pVBox->pDRIInfo);
326 pVBox->pDRIInfo=0;
327 if (pVBox->pVisualConfigs)
328 free(pVBox->pVisualConfigs);
329 pVBox->cVisualConfigs = 0;
330 pVBox->pVisualConfigs = NULL;
331}
332
333static Bool
334VBOXCreateContext(ScreenPtr pScreen, VisualPtr visual,
335 drm_context_t hwContext, void *pVisualConfigPriv,
336 DRIContextType contextStore)
337{
338 return TRUE;
339}
340
341static void
342VBOXDestroyContext(ScreenPtr pScreen, drm_context_t hwContext,
343 DRIContextType contextStore)
344{
345}
346
347Bool
348VBOXDRIFinishScreenInit(ScreenPtr pScreen)
349{
350 return DRIFinishScreenInit(pScreen);
351}
352
353static void
354VBOXDRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
355 DRIContextType oldContextType, void *oldContext,
356 DRIContextType newContextType, void *newContext)
357{
358}
359
360static void
361VBOXDRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index)
362{
363}
364
365static void
366VBOXDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
367 RegionPtr prgnSrc, CARD32 index)
368{
369}
370
371/* Apparently the next two are just legacy. */
372static Bool
373VBOXDRIOpenFullScreen(ScreenPtr pScreen)
374{
375 return TRUE;
376}
377
378static Bool
379VBOXDRICloseFullScreen(ScreenPtr pScreen)
380{
381 return TRUE;
382}
383
384static void
385VBOXDRITransitionTo2d(ScreenPtr pScreen)
386{
387}
388
389static void
390VBOXDRITransitionTo3d(ScreenPtr pScreen)
391{
392}
393
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