VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/vboxvideo/setmode.c@ 55319

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

Additions/x11/vboxvideo: reverted temporary commit r99563.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 KB
Line 
1/* $Id: setmode.c 55262 2015-04-15 05:34:05Z vboxsync $ */
2/** @file
3 *
4 * Linux Additions X11 graphics driver, mode setting
5 */
6
7/*
8 * Copyright (C) 2006-2013 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 * --------------------------------------------------------------------
18 *
19 * This code is based on:
20 *
21 * X11 VESA driver
22 *
23 * Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com)
24 *
25 * Permission is hereby granted, free of charge, to any person obtaining a
26 * copy of this software and associated documentation files (the "Software"),
27 * to deal in the Software without restriction, including without limitation
28 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
29 * and/or sell copies of the Software, and to permit persons to whom the
30 * Software is furnished to do so, subject to the following conditions:
31 *
32 * The above copyright notice and this permission notice shall be included in
33 * all copies or substantial portions of the Software.
34 *
35 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
38 * CONECTIVA LINUX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
39 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
40 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41 * SOFTWARE.
42 *
43 * Except as contained in this notice, the name of Conectiva Linux shall
44 * not be used in advertising or otherwise to promote the sale, use or other
45 * dealings in this Software without prior written authorization from
46 * Conectiva Linux.
47 *
48 * Authors: Paulo César Pereira de Andrade <[email protected]>
49 */
50
51#ifdef XORG_7X
52/* We include <unistd.h> for Solaris below, and the ANSI C emulation layer
53 * interferes with that. */
54# define _XF86_ANSIC_H
55# define XF86_LIBC_H
56# include <string.h>
57#endif
58#include "vboxvideo.h"
59#include "version-generated.h"
60#include "product-generated.h"
61#include "xf86.h"
62
63/* VGA hardware functions for setting and restoring text mode */
64#include "vgaHW.h"
65
66#ifdef RT_OS_SOLARIS
67# include <sys/vuid_event.h>
68# include <sys/msio.h>
69# include <errno.h>
70# include <fcntl.h>
71# include <unistd.h>
72#endif
73
74/** Clear the virtual framebuffer in VRAM. Optionally also clear up to the
75 * size of a new framebuffer. Framebuffer sizes larger than available VRAM
76 * be treated as zero and passed over. */
77void vbvxClearVRAM(ScrnInfoPtr pScrn, size_t cbOldSize, size_t cbNewSize)
78{
79 VBOXPtr pVBox = VBOXGetRec(pScrn);
80
81 /* Assume 32BPP - this is just a sanity test. */
82 VBVXASSERT( cbOldSize / 4 <= VBOX_VIDEO_MAX_VIRTUAL * VBOX_VIDEO_MAX_VIRTUAL
83 && cbNewSize / 4 <= VBOX_VIDEO_MAX_VIRTUAL * VBOX_VIDEO_MAX_VIRTUAL,
84 ("cbOldSize=%llu cbNewSize=%llu, max=%u.\n", (unsigned long long)cbOldSize, (unsigned long long)cbNewSize,
85 VBOX_VIDEO_MAX_VIRTUAL * VBOX_VIDEO_MAX_VIRTUAL));
86 if (cbOldSize > (size_t)pVBox->cbFBMax)
87 cbOldSize = pVBox->cbFBMax;
88 if (cbNewSize > (size_t)pVBox->cbFBMax)
89 cbNewSize = pVBox->cbFBMax;
90 memset(pVBox->base, 0, max(cbOldSize, cbNewSize));
91}
92
93/** Clear the virtual framebuffer in VRAM. Optionally also clear up to the
94 * size of a new framebuffer. Framebuffer sizes larger than available VRAM
95 * be treated as zero and passed over. */
96void vboxClearVRAM(ScrnInfoPtr pScrn, int32_t cNewX, int32_t cNewY)
97{
98 VBOXPtr pVBox = VBOXGetRec(pScrn);
99 uint64_t cbOldFB, cbNewFB;
100
101 cbOldFB = pVBox->cbLine * pScrn->virtualX;
102 cbNewFB = vboxLineLength(pScrn, cNewX) * cNewY;
103 if (cbOldFB > (uint64_t)pVBox->cbFBMax)
104 cbOldFB = 0;
105 if (cbNewFB > (uint64_t)pVBox->cbFBMax)
106 cbNewFB = 0;
107 memset(pVBox->base, 0, max(cbOldFB, cbNewFB));
108}
109
110/** Set a graphics mode. Poke any required values into registers, do an HGSMI
111 * mode set and tell the host we support advanced graphics functions.
112 */
113void vbvxSetMode(ScrnInfoPtr pScrn, unsigned cDisplay, unsigned cWidth, unsigned cHeight, int x, int y, bool fEnabled,
114 bool fConnected, struct vbvxFrameBuffer *pFrameBuffer)
115{
116 VBOXPtr pVBox = VBOXGetRec(pScrn);
117 uint32_t offStart;
118 uint16_t fFlags;
119 int rc;
120 bool fEnabledAndVisible = fEnabled && x + cWidth <= pFrameBuffer->cWidth && y + cHeight <= pFrameBuffer->cHeight;
121 /* Recent host code has a flag to blank the screen; older code needs BPP set to zero. */
122 uint32_t cBPP = fEnabledAndVisible || pVBox->fHostHasScreenBlankingFlag ? pFrameBuffer->cBPP : 0;
123
124 TRACE_LOG("cDisplay=%u, cWidth=%u, cHeight=%u, x=%d, y=%d, fEnabled=%d, fConnected=%d, pFrameBuffer: { x0=%d, y0=%d, cWidth=%u, cHeight=%u, cBPP=%u }\n",
125 cDisplay, cWidth, cHeight, x, y, fEnabled, fConnected, pFrameBuffer->x0, pFrameBuffer->y0, pFrameBuffer->cWidth,
126 pFrameBuffer->cHeight, pFrameBuffer->cBPP);
127 VBVXASSERT(cWidth != 0 && cHeight != 0, ("cWidth = 0 or cHeight = 0\n"));
128 offStart = (y * pFrameBuffer->cWidth + x) * pFrameBuffer->cBPP / 8;
129 if (cDisplay == 0 && fEnabled)
130 VBoxVideoSetModeRegisters(cWidth, cHeight, pFrameBuffer->cWidth, pFrameBuffer->cBPP, 0, x, y);
131 fFlags = VBVA_SCREEN_F_ACTIVE;
132 fFlags |= (fConnected ? 0 : VBVA_SCREEN_F_DISABLED);
133 fFlags |= (!fEnabledAndVisible && pVBox->fHostHasScreenBlankingFlag ? VBVA_SCREEN_F_BLANK : 0);
134 VBoxHGSMIProcessDisplayInfo(&pVBox->guestCtx, cDisplay, x - pFrameBuffer->x0, y - pFrameBuffer->y0, offStart,
135 pFrameBuffer->cWidth * pFrameBuffer->cBPP / 8, cWidth, cHeight, cBPP, fFlags);
136 rc = VBoxHGSMIUpdateInputMapping(&pVBox->guestCtx, 0 - pFrameBuffer->x0, 0 - pFrameBuffer->y0, pFrameBuffer->cWidth,
137 pFrameBuffer->cHeight);
138 if (RT_FAILURE(rc))
139 FatalError("Failed to update the input mapping.\n");
140}
141
142/** Set a graphics mode. Poke any required values into registers, do an HGSMI
143 * mode set and tell the host we support advanced graphics functions. This
144 * procedure is complicated by the fact that X.Org can implicitly disable a
145 * screen by resizing the virtual framebuffer so that the screen is no longer
146 * inside it. We have to spot and handle this.
147 */
148Bool VBOXSetMode(ScrnInfoPtr pScrn, unsigned cDisplay, unsigned cWidth,
149 unsigned cHeight, int x, int y)
150{
151 VBOXPtr pVBox = VBOXGetRec(pScrn);
152 uint32_t offStart, cwReal = cWidth;
153 bool fEnabled;
154 uint16_t fFlags;
155 int rc;
156
157 TRACE_LOG("cDisplay=%u, cWidth=%u, cHeight=%u, x=%d, y=%d, displayWidth=%d\n",
158 cDisplay, cWidth, cHeight, x, y, pScrn->displayWidth);
159 offStart = y * pVBox->cbLine + x * vboxBPP(pScrn) / 8;
160 /* Deactivate the screen if the mode - specifically the virtual width - is
161 * too large for VRAM as we sometimes have to do this - see comments in
162 * VBOXPreInit. */
163 if ( offStart + pVBox->cbLine * cHeight > pVBox->cbFBMax
164 || pVBox->cbLine * pScrn->virtualY > pVBox->cbFBMax)
165 return FALSE;
166 /* Deactivate the screen if it is outside of the virtual framebuffer and
167 * clamp it to lie inside if it is partly outside. */
168 if (x >= pScrn->displayWidth || x + (int) cWidth <= 0)
169 return FALSE;
170 else
171 cwReal = RT_MIN((int) cWidth, pScrn->displayWidth - x);
172 TRACE_LOG("pVBox->pScreens[%u].fCrtcEnabled=%d, fOutputEnabled=%d\n",
173 cDisplay, (int)pVBox->pScreens[cDisplay].fCrtcEnabled,
174 (int)pVBox->pScreens[cDisplay].fOutputEnabled);
175 if (cDisplay == 0)
176 VBoxVideoSetModeRegisters(cwReal, cHeight, pScrn->displayWidth,
177 vboxBPP(pScrn), 0, x, y);
178 fEnabled = pVBox->pScreens[cDisplay].fCrtcEnabled
179 && pVBox->pScreens[cDisplay].fOutputEnabled;
180 fFlags = VBVA_SCREEN_F_ACTIVE;
181 fFlags |= (pVBox->pScreens[cDisplay].afConnected ? 0
182 : VBVA_SCREEN_F_DISABLED);
183 VBoxHGSMIProcessDisplayInfo(&pVBox->guestCtx, cDisplay, x, y,
184 offStart, pVBox->cbLine, cwReal, cHeight,
185 fEnabled ? vboxBPP(pScrn) : 0, fFlags);
186 if (cDisplay == 0)
187 {
188 rc = VBoxHGSMIUpdateInputMapping(&pVBox->guestCtx, 0 - pVBox->pScreens[0].aScreenLocation.x,
189 0 - pVBox->pScreens[0].aScreenLocation.y, pScrn->virtualX, pScrn->virtualY);
190 if (RT_FAILURE(rc))
191 FatalError("Failed to update the input mapping.\n");
192 }
193 return TRUE;
194}
195
196/** Resize the virtual framebuffer. After resizing we reset all modes
197 * (X.Org 1.3+) to adjust them to the new framebuffer.
198 */
199Bool VBOXAdjustScreenPixmap(ScrnInfoPtr pScrn, int width, int height)
200{
201 ScreenPtr pScreen = pScrn->pScreen;
202 PixmapPtr pPixmap = pScreen->GetScreenPixmap(pScreen);
203 VBOXPtr pVBox = VBOXGetRec(pScrn);
204 uint64_t cbLine = vboxLineLength(pScrn, width);
205 int displayWidth = vboxDisplayPitch(pScrn, cbLine);
206 int rc;
207
208 TRACE_LOG("width=%d, height=%d\n", width, height);
209 if ( width == pScrn->virtualX
210 && height == pScrn->virtualY
211 && displayWidth == pScrn->displayWidth)
212 return TRUE;
213 if (!pPixmap) {
214 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
215 "Failed to get the screen pixmap.\n");
216 return FALSE;
217 }
218 if (cbLine > UINT32_MAX || cbLine * height >= pVBox->cbFBMax)
219 {
220 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
221 "Unable to set up a virtual screen size of %dx%d with %lu of %d Kb of video memory available. Please increase the video memory size.\n",
222 width, height, pVBox->cbFBMax / 1024, pScrn->videoRam);
223 return FALSE;
224 }
225 pScreen->ModifyPixmapHeader(pPixmap, width, height,
226 pScrn->depth, vboxBPP(pScrn), cbLine,
227 pVBox->base);
228 vboxClearVRAM(pScrn, width, height);
229 pScrn->virtualX = width;
230 pScrn->virtualY = height;
231 pScrn->displayWidth = displayWidth;
232 pVBox->cbLine = cbLine;
233#ifdef VBOX_DRI_OLD
234 if (pVBox->useDRI)
235 VBOXDRIUpdateStride(pScrn, pVBox);
236#endif
237#ifdef VBOXVIDEO_13
238 /* Write the new values to the hardware */
239 /** @todo why is this only for VBOXVIDEO_13? */
240 {
241 unsigned i;
242 for (i = 0; i < pVBox->cScreens; ++i)
243 VBOXSetMode(pScrn, i, pVBox->pScreens[i].aScreenLocation.cx,
244 pVBox->pScreens[i].aScreenLocation.cy,
245 pVBox->pScreens[i].aScreenLocation.x,
246 pVBox->pScreens[i].aScreenLocation.y);
247 }
248#else
249 rc = VBoxHGSMIUpdateInputMapping(&pVBox->guestCtx, 0 - pVBox->pScreens[0].aScreenLocation.x,
250 0 - pVBox->pScreens[0].aScreenLocation.y, pScrn->virtualX, pScrn->virtualY);
251 if (RT_FAILURE(rc))
252 FatalError("Failed to update the input mapping.\n");
253#endif
254 vbvxSetSolarisMouseRange(width, height);
255 return TRUE;
256}
257
258/** Tell the virtual mouse device about the new virtual desktop size. */
259void vbvxSetSolarisMouseRange(int width, int height)
260{
261#ifdef RT_OS_SOLARIS
262 int rc;
263 int hMouse = open("/dev/mouse", O_RDWR);
264
265 if (hMouse >= 0)
266 {
267 do {
268 Ms_screen_resolution Res = { height, width };
269 rc = ioctl(hMouse, MSIOSRESOLUTION, &Res);
270 } while ((rc != 0) && (errno == EINTR));
271 close(hMouse);
272 }
273#else
274 (void)width; (void)height;
275#endif
276}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette