VirtualBox

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

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

Additions/x11/vboxvideo: revert temporary check-in.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.7 KB
Line 
1/* $Id: setmode.c 54531 2015-02-26 14:05:57Z 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 vboxClearVRAM(ScrnInfoPtr pScrn, int32_t cNewX, int32_t cNewY)
78{
79 VBOXPtr pVBox = VBOXGetRec(pScrn);
80 uint64_t cbOldFB, cbNewFB;
81
82 cbOldFB = pVBox->cbLine * pScrn->virtualX;
83 cbNewFB = vboxLineLength(pScrn, cNewX) * cNewY;
84 if (cbOldFB > (uint64_t)pVBox->cbFBMax)
85 cbOldFB = 0;
86 if (cbNewFB > (uint64_t)pVBox->cbFBMax)
87 cbNewFB = 0;
88 memset(pVBox->base, 0, max(cbOldFB, cbNewFB));
89}
90
91/** Set a graphics mode. Poke any required values into registers, do an HGSMI
92 * mode set and tell the host we support advanced graphics functions. This
93 * procedure is complicated by the fact that X.Org can implicitly disable a
94 * screen by resizing the virtual framebuffer so that the screen is no longer
95 * inside it. We have to spot and handle this.
96 */
97Bool VBOXSetMode(ScrnInfoPtr pScrn, unsigned cDisplay, unsigned cWidth,
98 unsigned cHeight, int x, int y)
99{
100 VBOXPtr pVBox = VBOXGetRec(pScrn);
101 uint32_t offStart, cwReal = cWidth;
102 bool fEnabled;
103 uint16_t fFlags;
104 int rc;
105
106 TRACE_LOG("cDisplay=%u, cWidth=%u, cHeight=%u, x=%d, y=%d, displayWidth=%d\n",
107 cDisplay, cWidth, cHeight, x, y, pScrn->displayWidth);
108 offStart = y * pVBox->cbLine + x * vboxBPP(pScrn) / 8;
109 /* Deactivate the screen if the mode - specifically the virtual width - is
110 * too large for VRAM as we sometimes have to do this - see comments in
111 * VBOXPreInit. */
112 if ( offStart + pVBox->cbLine * cHeight > pVBox->cbFBMax
113 || pVBox->cbLine * pScrn->virtualY > pVBox->cbFBMax)
114 return FALSE;
115 /* Deactivate the screen if it is outside of the virtual framebuffer and
116 * clamp it to lie inside if it is partly outside. */
117 if (x >= pScrn->displayWidth || x + (int) cWidth <= 0)
118 return FALSE;
119 else
120 cwReal = RT_MIN((int) cWidth, pScrn->displayWidth - x);
121 TRACE_LOG("pVBox->pScreens[%u].fCrtcEnabled=%d, fOutputEnabled=%d\n",
122 cDisplay, (int)pVBox->pScreens[cDisplay].fCrtcEnabled,
123 (int)pVBox->pScreens[cDisplay].fOutputEnabled);
124 if (cDisplay == 0)
125 VBoxVideoSetModeRegisters(cwReal, cHeight, pScrn->displayWidth,
126 vboxBPP(pScrn), 0, x, y);
127 fEnabled = pVBox->pScreens[cDisplay].fCrtcEnabled
128 && pVBox->pScreens[cDisplay].fOutputEnabled;
129 fFlags = VBVA_SCREEN_F_ACTIVE;
130 fFlags |= (pVBox->pScreens[cDisplay].afConnected ? 0
131 : VBVA_SCREEN_F_DISABLED);
132 VBoxHGSMIProcessDisplayInfo(&pVBox->guestCtx, cDisplay, x, y,
133 offStart, pVBox->cbLine, cwReal, cHeight,
134 fEnabled ? vboxBPP(pScrn) : 0, fFlags);
135 if (cDisplay == 0)
136 {
137 rc = VBoxHGSMIUpdateInputMapping(&pVBox->guestCtx, 0 - pVBox->pScreens[0].aScreenLocation.x,
138 0 - pVBox->pScreens[0].aScreenLocation.y, pScrn->virtualX, pScrn->virtualY);
139 if (RT_FAILURE(rc))
140 FatalError("Failed to update the input mapping.\n");
141 }
142 return TRUE;
143}
144
145/** Resize the virtual framebuffer. After resizing we reset all modes
146 * (X.Org 1.3+) to adjust them to the new framebuffer.
147 */
148Bool VBOXAdjustScreenPixmap(ScrnInfoPtr pScrn, int width, int height)
149{
150 ScreenPtr pScreen = pScrn->pScreen;
151 PixmapPtr pPixmap = pScreen->GetScreenPixmap(pScreen);
152 VBOXPtr pVBox = VBOXGetRec(pScrn);
153 uint64_t cbLine = vboxLineLength(pScrn, width);
154 int displayWidth = vboxDisplayPitch(pScrn, cbLine);
155 int rc;
156
157 TRACE_LOG("width=%d, height=%d\n", width, height);
158 if ( width == pScrn->virtualX
159 && height == pScrn->virtualY
160 && displayWidth == pScrn->displayWidth)
161 return TRUE;
162 if (!pPixmap) {
163 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
164 "Failed to get the screen pixmap.\n");
165 return FALSE;
166 }
167 if (cbLine > UINT32_MAX || cbLine * height >= pVBox->cbFBMax)
168 {
169 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
170 "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",
171 width, height, pVBox->cbFBMax / 1024, pScrn->videoRam);
172 return FALSE;
173 }
174 pScreen->ModifyPixmapHeader(pPixmap, width, height,
175 pScrn->depth, vboxBPP(pScrn), cbLine,
176 pVBox->base);
177 vboxClearVRAM(pScrn, width, height);
178 pScrn->virtualX = width;
179 pScrn->virtualY = height;
180 pScrn->displayWidth = displayWidth;
181 pVBox->cbLine = cbLine;
182#ifdef VBOX_DRI_OLD
183 if (pVBox->useDRI)
184 VBOXDRIUpdateStride(pScrn, pVBox);
185#endif
186#ifdef VBOXVIDEO_13
187 /* Write the new values to the hardware */
188 /** @todo why is this only for VBOXVIDEO_13? */
189 {
190 unsigned i;
191 for (i = 0; i < pVBox->cScreens; ++i)
192 VBOXSetMode(pScrn, i, pVBox->pScreens[i].aScreenLocation.cx,
193 pVBox->pScreens[i].aScreenLocation.cy,
194 pVBox->pScreens[i].aScreenLocation.x,
195 pVBox->pScreens[i].aScreenLocation.y);
196 }
197#else
198 rc = VBoxHGSMIUpdateInputMapping(&pVBox->guestCtx, 0 - pVBox->pScreens[0].aScreenLocation.x,
199 0 - pVBox->pScreens[0].aScreenLocation.y, pScrn->virtualX, pScrn->virtualY);
200 if (RT_FAILURE(rc))
201 FatalError("Failed to update the input mapping.\n");
202#endif
203#ifdef RT_OS_SOLARIS
204 /* Tell the virtual mouse device about the new virtual desktop size. */
205 {
206 int rc;
207 int hMouse = open("/dev/mouse", O_RDWR);
208 if (hMouse >= 0)
209 {
210 do {
211 Ms_screen_resolution Res = { height, width };
212 rc = ioctl(hMouse, MSIOSRESOLUTION, &Res);
213 } while ((rc != 0) && (errno == EINTR));
214 close(hMouse);
215 }
216 }
217#endif
218 return TRUE;
219}
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