VirtualBox

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

Last change on this file since 78293 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 8.7 KB
Line 
1/* $Id: vbva.c 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * VirtualBox X11 Additions graphics driver 2D acceleration functions
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
8 *
9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without
12 * restriction, including without limitation the rights to use,
13 * copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following
16 * conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31#if defined(IN_XF86_MODULE) && !defined(NO_ANSIC)
32# include "xf86_ansic.h"
33#endif
34#include "compiler.h"
35
36#include "vboxvideo.h"
37
38#ifdef XORG_7X
39# include <stdlib.h>
40# include <string.h>
41#endif
42
43/**************************************************************************
44* Main functions *
45**************************************************************************/
46
47/**
48 * Callback function called by the X server to tell us about dirty
49 * rectangles in the video buffer.
50 *
51 * @param pScrn pointer to the information structure for the current
52 * screen
53 * @param iRects Number of dirty rectangles to update
54 * @param aRects Array of structures containing the coordinates of the
55 * rectangles
56 */
57void vbvxHandleDirtyRect(ScrnInfoPtr pScrn, int iRects, BoxPtr aRects)
58{
59 VBVACMDHDR cmdHdr;
60 VBOXPtr pVBox;
61 int i;
62 unsigned j;
63
64 pVBox = pScrn->driverPrivate;
65 if (!pScrn->vtSema)
66 return;
67
68 for (j = 0; j < pVBox->cScreens; ++j)
69 {
70 /* Just continue quietly if VBVA is not currently active. */
71 struct VBVABUFFER *pVBVA = pVBox->pScreens[j].aVbvaCtx.pVBVA;
72 if ( !pVBVA
73 || !(pVBVA->hostFlags.u32HostEvents & VBVA_F_MODE_ENABLED))
74 continue;
75 for (i = 0; i < iRects; ++i)
76 {
77 if ( aRects[i].x1 > pVBox->pScreens[j].aScreenLocation.x
78 + pVBox->pScreens[j].aScreenLocation.cx
79 || aRects[i].y1 > pVBox->pScreens[j].aScreenLocation.y
80 + pVBox->pScreens[j].aScreenLocation.cy
81 || aRects[i].x2 < pVBox->pScreens[j].aScreenLocation.x
82 || aRects[i].y2 < pVBox->pScreens[j].aScreenLocation.y)
83 continue;
84 cmdHdr.x = (int16_t)aRects[i].x1 - pVBox->pScreens[0].aScreenLocation.x;
85 cmdHdr.y = (int16_t)aRects[i].y1 - pVBox->pScreens[0].aScreenLocation.y;
86 cmdHdr.w = (uint16_t)(aRects[i].x2 - aRects[i].x1);
87 cmdHdr.h = (uint16_t)(aRects[i].y2 - aRects[i].y1);
88
89#if 0
90 TRACE_LOG("display=%u, x=%d, y=%d, w=%d, h=%d\n",
91 j, cmdHdr.x, cmdHdr.y, cmdHdr.w, cmdHdr.h);
92#endif
93
94 if (VBoxVBVABufferBeginUpdate(&pVBox->pScreens[j].aVbvaCtx,
95 &pVBox->guestCtx))
96 {
97 VBoxVBVAWrite(&pVBox->pScreens[j].aVbvaCtx, &pVBox->guestCtx, &cmdHdr,
98 sizeof(cmdHdr));
99 VBoxVBVABufferEndUpdate(&pVBox->pScreens[j].aVbvaCtx);
100 }
101 }
102 }
103}
104
105static DECLCALLBACK(void *) hgsmiEnvAlloc(void *pvEnv, HGSMISIZE cb)
106{
107 RT_NOREF(pvEnv);
108 return calloc(1, cb);
109}
110
111static DECLCALLBACK(void) hgsmiEnvFree(void *pvEnv, void *pv)
112{
113 RT_NOREF(pvEnv);
114 free(pv);
115}
116
117static HGSMIENV g_hgsmiEnv =
118{
119 NULL,
120 hgsmiEnvAlloc,
121 hgsmiEnvFree
122};
123
124/**
125 * Calculate the location in video RAM of and initialise the heap for guest to
126 * host messages.
127 */
128void vbvxSetUpHGSMIHeapInGuest(VBOXPtr pVBox, uint32_t cbVRAM)
129{
130 int rc;
131 uint32_t offVRAMBaseMapping, offGuestHeapMemory, cbGuestHeapMemory;
132 void *pvGuestHeapMemory;
133
134 VBoxHGSMIGetBaseMappingInfo(cbVRAM, &offVRAMBaseMapping, NULL, &offGuestHeapMemory, &cbGuestHeapMemory, NULL);
135 pvGuestHeapMemory = ((uint8_t *)pVBox->base) + offVRAMBaseMapping + offGuestHeapMemory;
136 rc = VBoxHGSMISetupGuestContext(&pVBox->guestCtx, pvGuestHeapMemory, cbGuestHeapMemory,
137 offVRAMBaseMapping + offGuestHeapMemory, &g_hgsmiEnv);
138 AssertMsg(RT_SUCCESS(rc), ("Failed to set up the guest-to-host message buffer heap, rc=%d\n", rc));
139 pVBox->cbView = offVRAMBaseMapping;
140}
141
142/** Callback to fill in the view structures */
143static DECLCALLBACK(int) vboxFillViewInfo(void *pvVBox, struct VBVAINFOVIEW *pViews, uint32_t cViews)
144{
145 VBOXPtr pVBox = (VBOXPtr)pvVBox;
146 unsigned i;
147 for (i = 0; i < cViews; ++i)
148 {
149 pViews[i].u32ViewIndex = i;
150 pViews[i].u32ViewOffset = 0;
151 pViews[i].u32ViewSize = pVBox->cbView;
152 pViews[i].u32MaxScreenSize = pVBox->cbFBMax;
153 }
154 return VINF_SUCCESS;
155}
156
157/**
158 * Initialise VirtualBox's accelerated video extensions.
159 *
160 * @returns TRUE on success, FALSE on failure
161 */
162static Bool vboxSetupVRAMVbva(VBOXPtr pVBox)
163{
164 int rc = VINF_SUCCESS;
165 unsigned i;
166
167 pVBox->cbFBMax = pVBox->cbView;
168 for (i = 0; i < pVBox->cScreens; ++i)
169 {
170 pVBox->cbFBMax -= VBVA_MIN_BUFFER_SIZE;
171 pVBox->pScreens[i].aoffVBVABuffer = pVBox->cbFBMax;
172 TRACE_LOG("VBVA buffer offset for screen %u: 0x%lx\n", i,
173 (unsigned long) pVBox->cbFBMax);
174 VBoxVBVASetupBufferContext(&pVBox->pScreens[i].aVbvaCtx,
175 pVBox->pScreens[i].aoffVBVABuffer,
176 VBVA_MIN_BUFFER_SIZE);
177 }
178 TRACE_LOG("Maximum framebuffer size: %lu (0x%lx)\n",
179 (unsigned long) pVBox->cbFBMax,
180 (unsigned long) pVBox->cbFBMax);
181 rc = VBoxHGSMISendViewInfo(&pVBox->guestCtx, pVBox->cScreens,
182 vboxFillViewInfo, (void *)pVBox);
183 AssertMsg(RT_SUCCESS(rc), ("Failed to send the view information to the host, rc=%d\n", rc));
184 return TRUE;
185}
186
187static Bool haveHGSMIModeHintAndCursorReportingInterface(VBOXPtr pVBox)
188{
189 uint32_t fModeHintReporting, fCursorReporting;
190
191 return RT_SUCCESS(VBoxQueryConfHGSMI(&pVBox->guestCtx, VBOX_VBVA_CONF32_MODE_HINT_REPORTING, &fModeHintReporting))
192 && RT_SUCCESS(VBoxQueryConfHGSMI(&pVBox->guestCtx, VBOX_VBVA_CONF32_GUEST_CURSOR_REPORTING, &fCursorReporting))
193 && fModeHintReporting == VINF_SUCCESS
194 && fCursorReporting == VINF_SUCCESS;
195}
196
197static Bool hostHasScreenBlankingFlag(VBOXPtr pVBox)
198{
199 uint32_t fScreenFlags;
200
201 return RT_SUCCESS(VBoxQueryConfHGSMI(&pVBox->guestCtx, VBOX_VBVA_CONF32_SCREEN_FLAGS, &fScreenFlags))
202 && fScreenFlags & VBVA_SCREEN_F_BLANK;
203}
204
205/**
206 * Inform VBox that we will supply it with dirty rectangle information
207 * and install the dirty rectangle handler.
208 *
209 * @returns TRUE for success, FALSE for failure
210 * @param pScrn Pointer to a structure describing the X screen in use
211 */
212Bool
213vboxEnableVbva(ScrnInfoPtr pScrn)
214{
215 Bool rc = TRUE;
216 unsigned i;
217 VBOXPtr pVBox = pScrn->driverPrivate;
218
219 TRACE_ENTRY();
220 if (!vboxSetupVRAMVbva(pVBox))
221 return FALSE;
222 for (i = 0; i < pVBox->cScreens; ++i)
223 {
224 struct VBVABUFFER *pVBVA;
225
226 pVBVA = (struct VBVABUFFER *) ( ((uint8_t *)pVBox->base)
227 + pVBox->pScreens[i].aoffVBVABuffer);
228 if (!VBoxVBVAEnable(&pVBox->pScreens[i].aVbvaCtx, &pVBox->guestCtx,
229 pVBVA, i))
230 rc = FALSE;
231 }
232 AssertMsg(rc, ("Failed to enable screen update reporting for at least one virtual monitor.\n"));
233 pVBox->fHaveHGSMIModeHints = haveHGSMIModeHintAndCursorReportingInterface(pVBox);
234 pVBox->fHostHasScreenBlankingFlag = hostHasScreenBlankingFlag(pVBox);
235 return rc;
236}
237
238/**
239 * Inform VBox that we will stop supplying it with dirty rectangle
240 * information. This function is intended to be called when an X
241 * virtual terminal is disabled, or the X server is terminated.
242 *
243 * @returns TRUE for success, FALSE for failure
244 * @param pScrn Pointer to a structure describing the X screen in use
245 */
246void
247vboxDisableVbva(ScrnInfoPtr pScrn)
248{
249 unsigned i;
250 VBOXPtr pVBox = pScrn->driverPrivate;
251
252 TRACE_ENTRY();
253 for (i = 0; i < pVBox->cScreens; ++i)
254 VBoxVBVADisable(&pVBox->pScreens[i].aVbvaCtx, &pVBox->guestCtx, i);
255}
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