VirtualBox

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

Last change on this file since 68632 was 68632, checked in by vboxsync, 7 years ago

Additions/x11: eliminating unnecessary VMMDev.h includes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 8.3 KB
Line 
1/* $Id: vbva.c 68632 2017-09-05 11:43:45Z vboxsync $ */
2/** @file
3 * VirtualBox X11 Additions graphics driver 2D acceleration functions
4 */
5
6/*
7 * Copyright (C) 2006-2016 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#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 pScrn 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 DECLCALLBACK(int) vboxFillViewInfo(void *pvVBox, struct VBVAINFOVIEW *pViews, uint32_t cViews)
132{
133 VBOXPtr pVBox = (VBOXPtr)pvVBox;
134 unsigned i;
135 for (i = 0; i < cViews; ++i)
136 {
137 pViews[i].u32ViewIndex = i;
138 pViews[i].u32ViewOffset = 0;
139 pViews[i].u32ViewSize = pVBox->cbView;
140 pViews[i].u32MaxScreenSize = pVBox->cbFBMax;
141 }
142 return VINF_SUCCESS;
143}
144
145/**
146 * Initialise VirtualBox's accelerated video extensions.
147 *
148 * @returns TRUE on success, FALSE on failure
149 */
150static Bool vboxSetupVRAMVbva(VBOXPtr pVBox)
151{
152 int rc = VINF_SUCCESS;
153 unsigned i;
154
155 pVBox->cbFBMax = pVBox->cbView;
156 for (i = 0; i < pVBox->cScreens; ++i)
157 {
158 pVBox->cbFBMax -= VBVA_MIN_BUFFER_SIZE;
159 pVBox->pScreens[i].aoffVBVABuffer = pVBox->cbFBMax;
160 TRACE_LOG("VBVA buffer offset for screen %u: 0x%lx\n", i,
161 (unsigned long) pVBox->cbFBMax);
162 VBoxVBVASetupBufferContext(&pVBox->pScreens[i].aVbvaCtx,
163 pVBox->pScreens[i].aoffVBVABuffer,
164 VBVA_MIN_BUFFER_SIZE);
165 }
166 TRACE_LOG("Maximum framebuffer size: %lu (0x%lx)\n",
167 (unsigned long) pVBox->cbFBMax,
168 (unsigned long) pVBox->cbFBMax);
169 rc = VBoxHGSMISendViewInfo(&pVBox->guestCtx, pVBox->cScreens,
170 vboxFillViewInfo, (void *)pVBox);
171 VBVXASSERT(RT_SUCCESS(rc), ("Failed to send the view information to the host, rc=%d\n", rc));
172 return TRUE;
173}
174
175static bool haveHGSMIModeHintAndCursorReportingInterface(VBOXPtr pVBox)
176{
177 uint32_t fModeHintReporting, fCursorReporting;
178
179 return RT_SUCCESS(VBoxQueryConfHGSMI(&pVBox->guestCtx, VBOX_VBVA_CONF32_MODE_HINT_REPORTING, &fModeHintReporting))
180 && RT_SUCCESS(VBoxQueryConfHGSMI(&pVBox->guestCtx, VBOX_VBVA_CONF32_GUEST_CURSOR_REPORTING, &fCursorReporting))
181 && fModeHintReporting == VINF_SUCCESS
182 && fCursorReporting == VINF_SUCCESS;
183}
184
185static bool hostHasScreenBlankingFlag(VBOXPtr pVBox)
186{
187 uint32_t fScreenFlags;
188
189 return RT_SUCCESS(VBoxQueryConfHGSMI(&pVBox->guestCtx, VBOX_VBVA_CONF32_SCREEN_FLAGS, &fScreenFlags))
190 && fScreenFlags & VBVA_SCREEN_F_BLANK;
191}
192
193/**
194 * Inform VBox that we will supply it with dirty rectangle information
195 * and install the dirty rectangle handler.
196 *
197 * @returns TRUE for success, FALSE for failure
198 * @param pScrn Pointer to a structure describing the X screen in use
199 */
200Bool
201vboxEnableVbva(ScrnInfoPtr pScrn)
202{
203 bool rc = TRUE;
204 unsigned i;
205 VBOXPtr pVBox = pScrn->driverPrivate;
206
207 TRACE_ENTRY();
208 if (!vboxSetupVRAMVbva(pVBox))
209 return FALSE;
210 for (i = 0; i < pVBox->cScreens; ++i)
211 {
212 struct VBVABUFFER *pVBVA;
213
214 pVBVA = (struct VBVABUFFER *) ( ((uint8_t *)pVBox->base)
215 + pVBox->pScreens[i].aoffVBVABuffer);
216 if (!VBoxVBVAEnable(&pVBox->pScreens[i].aVbvaCtx, &pVBox->guestCtx,
217 pVBVA, i))
218 rc = FALSE;
219 }
220 VBVXASSERT(rc, ("Failed to enable screen update reporting for at least one virtual monitor.\n"));
221 pVBox->fHaveHGSMIModeHints = haveHGSMIModeHintAndCursorReportingInterface(pVBox);
222 pVBox->fHostHasScreenBlankingFlag = hostHasScreenBlankingFlag(pVBox);
223 return rc;
224}
225
226/**
227 * Inform VBox that we will stop supplying it with dirty rectangle
228 * information. This function is intended to be called when an X
229 * virtual terminal is disabled, or the X server is terminated.
230 *
231 * @returns TRUE for success, FALSE for failure
232 * @param pScrn Pointer to a structure describing the X screen in use
233 */
234void
235vboxDisableVbva(ScrnInfoPtr pScrn)
236{
237 unsigned i;
238 VBOXPtr pVBox = pScrn->driverPrivate;
239
240 TRACE_ENTRY();
241 for (i = 0; i < pVBox->cScreens; ++i)
242 VBoxVBVADisable(&pVBox->pScreens[i].aVbvaCtx, &pVBox->guestCtx, i);
243}
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