VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/vboxvideo/vbva.c@ 43245

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

Additions/x11/vboxvideo: clean up sanity handling for mode switches when we do not own the virtual terminal.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 8.8 KB
Line 
1/** @file
2 * VirtualBox X11 Additions graphics driver 2D acceleration functions
3 */
4
5/*
6 * Copyright (C) 2006-2007 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#include <VBox/VMMDev.h>
18#include <VBox/VBoxGuestLib.h>
19
20#ifndef PCIACCESS
21# include <xf86Pci.h>
22# include <Pci.h>
23#endif
24
25#include "xf86.h"
26#define NEED_XF86_TYPES
27#include <iprt/string.h>
28#include "compiler.h"
29
30/* ShadowFB support */
31#include "shadowfb.h"
32
33#include "vboxvideo.h"
34
35/**************************************************************************
36* Main functions *
37**************************************************************************/
38
39/**
40 * Callback function called by the X server to tell us about dirty
41 * rectangles in the video buffer.
42 *
43 * @param pScreen pointer to the information structure for the current
44 * screen
45 * @param iRects Number of dirty rectangles to update
46 * @param aRects Array of structures containing the coordinates of the
47 * rectangles
48 */
49static void
50vboxHandleDirtyRect(ScrnInfoPtr pScrn, int iRects, BoxPtr aRects)
51{
52 VBVACMDHDR cmdHdr;
53 VBOXPtr pVBox;
54 int i;
55 unsigned j;
56
57 pVBox = pScrn->driverPrivate;
58 if (pVBox->fHaveHGSMI == FALSE || !pScrn->vtSema)
59 return;
60
61 for (i = 0; i < iRects; ++i)
62 for (j = 0; j < pVBox->cScreens; ++j)
63 {
64 /* Just continue quietly if VBVA is not currently active. */
65 struct VBVABUFFER *pVBVA = pVBox->aVbvaCtx[j].pVBVA;
66 if ( !pVBVA
67 || !(pVBVA->hostFlags.u32HostEvents & VBVA_F_MODE_ENABLED))
68 continue;
69 if ( aRects[i].x1 > pVBox->aScreenLocation[j].x
70 + pVBox->aScreenLocation[j].cx
71 || aRects[i].y1 > pVBox->aScreenLocation[j].y
72 + pVBox->aScreenLocation[j].cy
73 || aRects[i].x2 < pVBox->aScreenLocation[j].x
74 || aRects[i].y2 < pVBox->aScreenLocation[j].y)
75 continue;
76 cmdHdr.x = (int16_t)aRects[i].x1;
77 cmdHdr.y = (int16_t)aRects[i].y1;
78 cmdHdr.w = (uint16_t)(aRects[i].x2 - aRects[i].x1);
79 cmdHdr.h = (uint16_t)(aRects[i].y2 - aRects[i].y1);
80
81#if 0
82 TRACE_LOG("display=%u, x=%d, y=%d, w=%d, h=%d\n",
83 j, cmdHdr.x, cmdHdr.y, cmdHdr.w, cmdHdr.h);
84#endif
85
86 if (VBoxVBVABufferBeginUpdate(&pVBox->aVbvaCtx[j],
87 &pVBox->guestCtx))
88 {
89 VBoxVBVAWrite(&pVBox->aVbvaCtx[j], &pVBox->guestCtx, &cmdHdr,
90 sizeof(cmdHdr));
91 VBoxVBVABufferEndUpdate(&pVBox->aVbvaCtx[j]);
92 }
93 }
94}
95
96/** Callback to fill in the view structures */
97static int
98vboxFillViewInfo(void *pvVBox, struct VBVAINFOVIEW *pViews, uint32_t cViews)
99{
100 VBOXPtr pVBox = (VBOXPtr)pvVBox;
101 unsigned i;
102 for (i = 0; i < cViews; ++i)
103 {
104 pViews[i].u32ViewIndex = i;
105 pViews[i].u32ViewOffset = 0;
106 pViews[i].u32ViewSize = pVBox->cbView;
107 pViews[i].u32MaxScreenSize = pVBox->cbFBMax;
108 }
109 return VINF_SUCCESS;
110}
111
112/**
113 * Initialise VirtualBox's accelerated video extensions.
114 *
115 * @returns TRUE on success, FALSE on failure
116 */
117static Bool
118vboxInitVbva(int scrnIndex, ScreenPtr pScreen, VBOXPtr pVBox)
119{
120 ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
121 int rc = VINF_SUCCESS;
122
123 pVBox->cScreens = 1;
124 if (!VBoxHGSMIIsSupported())
125 {
126 xf86DrvMsg(scrnIndex, X_ERROR, "The graphics device does not seem to support HGSMI. Disableing video acceleration.\n");
127 return FALSE;
128 }
129
130 /* Set up the dirty rectangle handler. It will be added into a function
131 * chain and gets removed when the screen is cleaned up. */
132 if (ShadowFBInit2(pScreen, NULL, vboxHandleDirtyRect) != TRUE)
133 {
134 xf86DrvMsg(scrnIndex, X_ERROR,
135 "Unable to install dirty rectangle handler for VirtualBox graphics acceleration.\n");
136 return FALSE;
137 }
138 return TRUE;
139}
140
141/**
142 * Initialise VirtualBox's accelerated video extensions.
143 *
144 * @returns TRUE on success, FALSE on failure
145 */
146static Bool
147vboxSetupVRAMVbva(ScrnInfoPtr pScrn, VBOXPtr pVBox)
148{
149 int rc = VINF_SUCCESS;
150 unsigned i;
151 uint32_t offVRAMBaseMapping, offGuestHeapMemory, cbGuestHeapMemory;
152 void *pvGuestHeapMemory;
153
154 if (!pVBox->fHaveHGSMI)
155 return FALSE;
156 VBoxHGSMIGetBaseMappingInfo(pScrn->videoRam * 1024, &offVRAMBaseMapping,
157 NULL, &offGuestHeapMemory, &cbGuestHeapMemory,
158 NULL);
159 pvGuestHeapMemory = ((uint8_t *)pVBox->base) + offVRAMBaseMapping
160 + offGuestHeapMemory;
161 TRACE_LOG("video RAM: %u KB, guest heap offset: 0x%x, cbGuestHeapMemory: %u\n",
162 pScrn->videoRam, offVRAMBaseMapping + offGuestHeapMemory,
163 cbGuestHeapMemory);
164 rc = VBoxHGSMISetupGuestContext(&pVBox->guestCtx, pvGuestHeapMemory,
165 cbGuestHeapMemory,
166 offVRAMBaseMapping + offGuestHeapMemory);
167 if (RT_FAILURE(rc))
168 {
169 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed to set up the guest-to-host communication context, rc=%d\n", rc);
170 return FALSE;
171 }
172 pVBox->cbView = pVBox->cbFBMax = offVRAMBaseMapping;
173 pVBox->cScreens = VBoxHGSMIGetMonitorCount(&pVBox->guestCtx);
174 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Requested monitor count: %u\n",
175 pVBox->cScreens);
176 for (i = 0; i < pVBox->cScreens; ++i)
177 {
178 pVBox->cbFBMax -= VBVA_MIN_BUFFER_SIZE;
179 pVBox->aoffVBVABuffer[i] = pVBox->cbFBMax;
180 TRACE_LOG("VBVA buffer offset for screen %u: 0x%lx\n", i,
181 (unsigned long) pVBox->cbFBMax);
182 VBoxVBVASetupBufferContext(&pVBox->aVbvaCtx[i],
183 pVBox->aoffVBVABuffer[i],
184 VBVA_MIN_BUFFER_SIZE);
185 }
186 TRACE_LOG("Maximum framebuffer size: %lu (0x%lx)\n",
187 (unsigned long) pVBox->cbFBMax,
188 (unsigned long) pVBox->cbFBMax);
189 rc = VBoxHGSMISendViewInfo(&pVBox->guestCtx, pVBox->cScreens,
190 vboxFillViewInfo, (void *)pVBox);
191 if (RT_FAILURE(rc))
192 {
193 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed to send the view information to the host, rc=%d\n", rc);
194 return FALSE;
195 }
196 return TRUE;
197}
198
199Bool
200vbox_open(ScrnInfoPtr pScrn, ScreenPtr pScreen, VBOXPtr pVBox)
201{
202 TRACE_ENTRY();
203
204 pVBox->fHaveHGSMI = vboxInitVbva(pScrn->scrnIndex, pScreen, pVBox);
205 return pVBox->fHaveHGSMI;
206}
207
208Bool
209vbox_device_available(VBOXPtr pVBox)
210{
211 return pVBox->useDevice;
212}
213
214/**
215 * Inform VBox that we will supply it with dirty rectangle information
216 * and install the dirty rectangle handler.
217 *
218 * @returns TRUE for success, FALSE for failure
219 * @param pScrn Pointer to a structure describing the X screen in use
220 */
221Bool
222vboxEnableVbva(ScrnInfoPtr pScrn)
223{
224 bool rc = TRUE;
225 int scrnIndex = pScrn->scrnIndex;
226 unsigned i;
227 VBOXPtr pVBox = pScrn->driverPrivate;
228
229 TRACE_ENTRY();
230 if (!vboxSetupVRAMVbva(pScrn, pVBox))
231 return FALSE;
232 for (i = 0; i < pVBox->cScreens; ++i)
233 {
234 struct VBVABUFFER *pVBVA;
235
236 pVBVA = (struct VBVABUFFER *) ( ((uint8_t *)pVBox->base)
237 + pVBox->aoffVBVABuffer[i]);
238 if (!VBoxVBVAEnable(&pVBox->aVbvaCtx[i], &pVBox->guestCtx, pVBVA, i))
239 rc = FALSE;
240 }
241 if (!rc)
242 {
243 /* Request not accepted - disable for old hosts. */
244 xf86DrvMsg(scrnIndex, X_ERROR,
245 "Failed to enable screen update reporting for at least one virtual monitor.\n");
246 vboxDisableVbva(pScrn);
247 }
248 return rc;
249}
250
251/**
252 * Inform VBox that we will stop supplying it with dirty rectangle
253 * information. This function is intended to be called when an X
254 * virtual terminal is disabled, or the X server is terminated.
255 *
256 * @returns TRUE for success, FALSE for failure
257 * @param pScrn Pointer to a structure describing the X screen in use
258 */
259void
260vboxDisableVbva(ScrnInfoPtr pScrn)
261{
262 int rc;
263 int scrnIndex = pScrn->scrnIndex;
264 unsigned i;
265 VBOXPtr pVBox = pScrn->driverPrivate;
266
267 TRACE_ENTRY();
268 if (!pVBox->fHaveHGSMI) /* Ths function should not have been called */
269 return;
270 for (i = 0; i < pVBox->cScreens; ++i)
271 VBoxVBVADisable(&pVBox->aVbvaCtx[i], &pVBox->guestCtx, i);
272}
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