VirtualBox

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

Last change on this file since 55393 was 55390, checked in by vboxsync, 9 years ago

Additions/x11/vboxvideo: remove old code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 8.4 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
186static bool hostHasScreenBlankingFlag(VBOXPtr pVBox)
187{
188 uint32_t fScreenFlags;
189
190 return RT_SUCCESS(VBoxQueryConfHGSMI(&pVBox->guestCtx, VBOX_VBVA_CONF32_SCREEN_FLAGS, &fScreenFlags))
191 && fScreenFlags & VBVA_SCREEN_F_BLANK;
192}
193
194/**
195 * Inform VBox that we will supply it with dirty rectangle information
196 * and install the dirty rectangle handler.
197 *
198 * @returns TRUE for success, FALSE for failure
199 * @param pScrn Pointer to a structure describing the X screen in use
200 */
201Bool
202vboxEnableVbva(ScrnInfoPtr pScrn)
203{
204 bool rc = TRUE;
205 unsigned i;
206 VBOXPtr pVBox = pScrn->driverPrivate;
207
208 TRACE_ENTRY();
209 if (!vboxSetupVRAMVbva(pVBox))
210 return FALSE;
211 for (i = 0; i < pVBox->cScreens; ++i)
212 {
213 struct VBVABUFFER *pVBVA;
214
215 pVBVA = (struct VBVABUFFER *) ( ((uint8_t *)pVBox->base)
216 + pVBox->pScreens[i].aoffVBVABuffer);
217 if (!VBoxVBVAEnable(&pVBox->pScreens[i].aVbvaCtx, &pVBox->guestCtx,
218 pVBVA, i))
219 rc = FALSE;
220 }
221 VBVXASSERT(rc, ("Failed to enable screen update reporting for at least one virtual monitor.\n"));
222#ifdef VBOXVIDEO_13
223 VBoxHGSMISendCapsInfo(&pVBox->guestCtx, VBVACAPS_VIDEO_MODE_HINTS | VBVACAPS_DISABLE_CURSOR_INTEGRATION);
224 pVBox->fHaveHGSMIModeHints = haveHGSMIModeHintAndCursorReportingInterface(pVBox);
225 pVBox->fHostHasScreenBlankingFlag = hostHasScreenBlankingFlag(pVBox);
226#endif
227 return rc;
228}
229
230/**
231 * Inform VBox that we will stop supplying it with dirty rectangle
232 * information. This function is intended to be called when an X
233 * virtual terminal is disabled, or the X server is terminated.
234 *
235 * @returns TRUE for success, FALSE for failure
236 * @param pScrn Pointer to a structure describing the X screen in use
237 */
238void
239vboxDisableVbva(ScrnInfoPtr pScrn)
240{
241 int rc;
242 unsigned i;
243 VBOXPtr pVBox = pScrn->driverPrivate;
244
245 TRACE_ENTRY();
246 for (i = 0; i < pVBox->cScreens; ++i)
247 VBoxVBVADisable(&pVBox->pScreens[i].aVbvaCtx, &pVBox->guestCtx, i);
248}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use