VirtualBox

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

Last change on this file since 54530 was 54530, checked in by vboxsync, 10 years ago

Additions/x11/vboxvideo: temporary check-in of local state: dynamic resizing and cursor integration toggling without kernel drivers.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 8.1 KB
Line 
1/** @file
2 * VirtualBox X11 Additions graphics driver 2D acceleration functions
3 */
4
5/*
6 * Copyright (C) 2006-2012 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#include <iprt/string.h>
21#include "compiler.h"
22
23#include "vboxvideo.h"
24
25#ifdef XORG_7X
26# include <stdlib.h>
27#endif
28
29/**************************************************************************
30* Main functions *
31**************************************************************************/
32
33/**
34 * Callback function called by the X server to tell us about dirty
35 * rectangles in the video buffer.
36 *
37 * @param pScreen pointer to the information structure for the current
38 * screen
39 * @param iRects Number of dirty rectangles to update
40 * @param aRects Array of structures containing the coordinates of the
41 * rectangles
42 */
43void vbvxHandleDirtyRect(ScrnInfoPtr pScrn, int iRects, BoxPtr aRects)
44{
45 VBVACMDHDR cmdHdr;
46 VBOXPtr pVBox;
47 int i;
48 unsigned j;
49
50 pVBox = pScrn->driverPrivate;
51 if (!pScrn->vtSema)
52 return;
53
54 for (j = 0; j < pVBox->cScreens; ++j)
55 {
56 /* Just continue quietly if VBVA is not currently active. */
57 struct VBVABUFFER *pVBVA = pVBox->pScreens[j].aVbvaCtx.pVBVA;
58 if ( !pVBVA
59 || !(pVBVA->hostFlags.u32HostEvents & VBVA_F_MODE_ENABLED))
60 continue;
61 for (i = 0; i < iRects; ++i)
62 {
63 if ( aRects[i].x1 > pVBox->pScreens[j].aScreenLocation.x
64 + pVBox->pScreens[j].aScreenLocation.cx
65 || aRects[i].y1 > pVBox->pScreens[j].aScreenLocation.y
66 + pVBox->pScreens[j].aScreenLocation.cy
67 || aRects[i].x2 < pVBox->pScreens[j].aScreenLocation.x
68 || aRects[i].y2 < pVBox->pScreens[j].aScreenLocation.y)
69 continue;
70 cmdHdr.x = (int16_t)aRects[i].x1 - pVBox->pScreens[0].aScreenLocation.x;
71 cmdHdr.y = (int16_t)aRects[i].y1 - pVBox->pScreens[0].aScreenLocation.y;
72 cmdHdr.w = (uint16_t)(aRects[i].x2 - aRects[i].x1);
73 cmdHdr.h = (uint16_t)(aRects[i].y2 - aRects[i].y1);
74
75#if 0
76 TRACE_LOG("display=%u, x=%d, y=%d, w=%d, h=%d\n",
77 j, cmdHdr.x, cmdHdr.y, cmdHdr.w, cmdHdr.h);
78#endif
79
80 if (VBoxVBVABufferBeginUpdate(&pVBox->pScreens[j].aVbvaCtx,
81 &pVBox->guestCtx))
82 {
83 VBoxVBVAWrite(&pVBox->pScreens[j].aVbvaCtx, &pVBox->guestCtx, &cmdHdr,
84 sizeof(cmdHdr));
85 VBoxVBVABufferEndUpdate(&pVBox->pScreens[j].aVbvaCtx);
86 }
87 }
88 }
89}
90
91static DECLCALLBACK(void *) hgsmiEnvAlloc(void *pvEnv, HGSMISIZE cb)
92{
93 NOREF(pvEnv);
94 return calloc(1, cb);
95}
96
97static DECLCALLBACK(void) hgsmiEnvFree(void *pvEnv, void *pv)
98{
99 NOREF(pvEnv);
100 free(pv);
101}
102
103static HGSMIENV g_hgsmiEnv =
104{
105 NULL,
106 hgsmiEnvAlloc,
107 hgsmiEnvFree
108};
109
110/**
111 * Calculate the location in video RAM of and initialise the heap for guest to
112 * host messages. In the VirtualBox 4.3 and earlier Guest Additions this
113 * function creates the heap structures directly in guest video RAM, so it
114 * needs to be called whenever video RAM is (re-)set-up.
115 */
116void vbvxSetUpHGSMIHeapInGuest(VBOXPtr pVBox, uint32_t cbVRAM)
117{
118 int rc;
119 uint32_t offVRAMBaseMapping, offGuestHeapMemory, cbGuestHeapMemory;
120 void *pvGuestHeapMemory;
121
122 VBoxHGSMIGetBaseMappingInfo(cbVRAM, &offVRAMBaseMapping, NULL, &offGuestHeapMemory, &cbGuestHeapMemory, NULL);
123 pvGuestHeapMemory = ((uint8_t *)pVBox->base) + offVRAMBaseMapping + offGuestHeapMemory;
124 rc = VBoxHGSMISetupGuestContext(&pVBox->guestCtx, pvGuestHeapMemory, cbGuestHeapMemory,
125 offVRAMBaseMapping + offGuestHeapMemory, &g_hgsmiEnv);
126 VBVXASSERT(RT_SUCCESS(rc), ("Failed to set up the guest-to-host message buffer heap, rc=%d\n", rc));
127 pVBox->cbView = offVRAMBaseMapping;
128}
129
130/** Callback to fill in the view structures */
131static int
132vboxFillViewInfo(void *pvVBox, struct VBVAINFOVIEW *pViews, uint32_t cViews)
133{
134 VBOXPtr pVBox = (VBOXPtr)pvVBox;
135 unsigned i;
136 for (i = 0; i < cViews; ++i)
137 {
138 pViews[i].u32ViewIndex = i;
139 pViews[i].u32ViewOffset = 0;
140 pViews[i].u32ViewSize = pVBox->cbView;
141 pViews[i].u32MaxScreenSize = pVBox->cbFBMax;
142 }
143 return VINF_SUCCESS;
144}
145
146/**
147 * Initialise VirtualBox's accelerated video extensions.
148 *
149 * @returns TRUE on success, FALSE on failure
150 */
151static Bool vboxSetupVRAMVbva(VBOXPtr pVBox)
152{
153 int rc = VINF_SUCCESS;
154 unsigned i;
155
156 pVBox->cbFBMax = pVBox->cbView;
157 for (i = 0; i < pVBox->cScreens; ++i)
158 {
159 pVBox->cbFBMax -= VBVA_MIN_BUFFER_SIZE;
160 pVBox->pScreens[i].aoffVBVABuffer = pVBox->cbFBMax;
161 TRACE_LOG("VBVA buffer offset for screen %u: 0x%lx\n", i,
162 (unsigned long) pVBox->cbFBMax);
163 VBoxVBVASetupBufferContext(&pVBox->pScreens[i].aVbvaCtx,
164 pVBox->pScreens[i].aoffVBVABuffer,
165 VBVA_MIN_BUFFER_SIZE);
166 }
167 TRACE_LOG("Maximum framebuffer size: %lu (0x%lx)\n",
168 (unsigned long) pVBox->cbFBMax,
169 (unsigned long) pVBox->cbFBMax);
170 rc = VBoxHGSMISendViewInfo(&pVBox->guestCtx, pVBox->cScreens,
171 vboxFillViewInfo, (void *)pVBox);
172 VBVXASSERT(RT_SUCCESS(rc), ("Failed to send the view information to the host, rc=%d\n", rc));
173 return TRUE;
174}
175
176static bool haveHGSMIModeHintAndCursorReportingInterface(VBOXPtr pVBox)
177{
178 uint32_t fModeHintReporting, fCursorReporting;
179
180 return RT_SUCCESS(VBoxQueryConfHGSMI(&pVBox->guestCtx, VBOX_VBVA_CONF32_MODE_HINT_REPORTING, &fModeHintReporting))
181 && RT_SUCCESS(VBoxQueryConfHGSMI(&pVBox->guestCtx, VBOX_VBVA_CONF32_GUEST_CURSOR_REPORTING, &fCursorReporting))
182 && fModeHintReporting == VINF_SUCCESS
183 && fCursorReporting == VINF_SUCCESS;
184}
185
186/**
187 * Inform VBox that we will supply it with dirty rectangle information
188 * and install the dirty rectangle handler.
189 *
190 * @returns TRUE for success, FALSE for failure
191 * @param pScrn Pointer to a structure describing the X screen in use
192 */
193Bool
194vboxEnableVbva(ScrnInfoPtr pScrn)
195{
196 bool rc = TRUE;
197 unsigned i;
198 VBOXPtr pVBox = pScrn->driverPrivate;
199
200 TRACE_ENTRY();
201 if (!vboxSetupVRAMVbva(pVBox))
202 return FALSE;
203 for (i = 0; i < pVBox->cScreens; ++i)
204 {
205 struct VBVABUFFER *pVBVA;
206
207 pVBVA = (struct VBVABUFFER *) ( ((uint8_t *)pVBox->base)
208 + pVBox->pScreens[i].aoffVBVABuffer);
209 if (!VBoxVBVAEnable(&pVBox->pScreens[i].aVbvaCtx, &pVBox->guestCtx,
210 pVBVA, i))
211 rc = FALSE;
212 }
213 VBVXASSERT(rc, ("Failed to enable screen update reporting for at least one virtual monitor.\n"));
214#ifdef VBOXVIDEO_13
215 VBoxHGSMISendCapsInfo(&pVBox->guestCtx, VBVACAPS_VIDEO_MODE_HINTS | VBVACAPS_DISABLE_CURSOR_INTEGRATION);
216 pVBox->fHaveHGSMIModeHints = haveHGSMIModeHintAndCursorReportingInterface(pVBox);
217#endif
218 return rc;
219}
220
221/**
222 * Inform VBox that we will stop supplying it with dirty rectangle
223 * information. This function is intended to be called when an X
224 * virtual terminal is disabled, or the X server is terminated.
225 *
226 * @returns TRUE for success, FALSE for failure
227 * @param pScrn Pointer to a structure describing the X screen in use
228 */
229void
230vboxDisableVbva(ScrnInfoPtr pScrn)
231{
232 int rc;
233 unsigned i;
234 VBOXPtr pVBox = pScrn->driverPrivate;
235
236 TRACE_ENTRY();
237 for (i = 0; i < pVBox->cScreens; ++i)
238 VBoxVBVADisable(&pVBox->pScreens[i].aVbvaCtx, &pVBox->guestCtx, i);
239}
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