VirtualBox

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

Last change on this file since 52235 was 52199, checked in by vboxsync, 10 years ago

Additions/x11/vboxvideo: remove hard-coded maximum number of screens.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1/* $Id: setmode.c 52199 2014-07-25 19:47:39Z 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 uint16_t fFlags;
103
104 TRACE_LOG("cDisplay=%u, cWidth=%u, cHeight=%u, x=%d, y=%d, displayWidth=%d\n",
105 cDisplay, cWidth, cHeight, x, y, pScrn->displayWidth);
106 offStart = y * pVBox->cbLine + x * vboxBPP(pScrn) / 8;
107 /* Deactivate the screen if the mode - specifically the virtual width - is
108 * too large for VRAM as we sometimes have to do this - see comments in
109 * VBOXPreInit. */
110 if ( offStart + pVBox->cbLine * cHeight > pVBox->cbFBMax
111 || pVBox->cbLine * pScrn->virtualY > pVBox->cbFBMax)
112 return FALSE;
113 /* Deactivate the screen if it is outside of the virtual framebuffer and
114 * clamp it to lie inside if it is partly outside. */
115 if (x >= pScrn->displayWidth || x + (int) cWidth <= 0)
116 return FALSE;
117 else
118 cwReal = RT_MIN((int) cWidth, pScrn->displayWidth - x);
119 TRACE_LOG("pVBox->pScreens[%u].afDisabled=%d\n",
120 cDisplay, (int)pVBox->pScreens[cDisplay].afDisabled);
121 if (cDisplay == 0)
122 VBoxVideoSetModeRegisters(cwReal, cHeight, pScrn->displayWidth,
123 vboxBPP(pScrn), 0, x, y);
124 fFlags = VBVA_SCREEN_F_ACTIVE;
125 fFlags |= (pVBox->pScreens[cDisplay].afDisabled ? VBVA_SCREEN_F_DISABLED : 0);
126 VBoxHGSMIProcessDisplayInfo(&pVBox->guestCtx, cDisplay, x, y,
127 offStart, pVBox->cbLine, cwReal, cHeight,
128 vboxBPP(pScrn), fFlags);
129 return TRUE;
130}
131
132/** Resize the virtual framebuffer. After resizing we reset all modes
133 * (X.Org 1.3+) to adjust them to the new framebuffer.
134 */
135Bool VBOXAdjustScreenPixmap(ScrnInfoPtr pScrn, int width, int height)
136{
137 ScreenPtr pScreen = pScrn->pScreen;
138 PixmapPtr pPixmap = pScreen->GetScreenPixmap(pScreen);
139 VBOXPtr pVBox = VBOXGetRec(pScrn);
140 uint64_t cbLine = vboxLineLength(pScrn, width);
141 int displayWidth = vboxDisplayPitch(pScrn, cbLine);
142
143 TRACE_LOG("width=%d, height=%d\n", width, height);
144 if ( width == pScrn->virtualX
145 && height == pScrn->virtualY
146 && displayWidth == pScrn->displayWidth)
147 return TRUE;
148 if (!pPixmap) {
149 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
150 "Failed to get the screen pixmap.\n");
151 return FALSE;
152 }
153 if (cbLine > UINT32_MAX || cbLine * height >= pVBox->cbFBMax)
154 {
155 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
156 "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",
157 width, height, pVBox->cbFBMax / 1024, pScrn->videoRam);
158 return FALSE;
159 }
160 pScreen->ModifyPixmapHeader(pPixmap, width, height,
161 pScrn->depth, vboxBPP(pScrn), cbLine,
162 pVBox->base);
163 vboxClearVRAM(pScrn, width, height);
164 pScrn->virtualX = width;
165 pScrn->virtualY = height;
166 pScrn->displayWidth = displayWidth;
167 pVBox->cbLine = cbLine;
168#ifdef VBOX_DRI_OLD
169 if (pVBox->useDRI)
170 VBOXDRIUpdateStride(pScrn, pVBox);
171#endif
172#ifdef VBOXVIDEO_13
173 /* Write the new values to the hardware */
174 {
175 unsigned i;
176 for (i = 0; i < pVBox->cScreens; ++i)
177 VBOXSetMode(pScrn, i, pVBox->pScreens[i].aScreenLocation.cx,
178 pVBox->pScreens[i].aScreenLocation.cy,
179 pVBox->pScreens[i].aScreenLocation.x,
180 pVBox->pScreens[i].aScreenLocation.y);
181 }
182#endif
183#ifdef RT_OS_SOLARIS
184 /* Tell the virtual mouse device about the new virtual desktop size. */
185 {
186 int rc;
187 int hMouse = open("/dev/mouse", O_RDWR);
188 if (hMouse >= 0)
189 {
190 do {
191 Ms_screen_resolution Res = { height, width };
192 rc = ioctl(hMouse, MSIOSRESOLUTION, &Res);
193 } while ((rc != 0) && (errno == EINTR));
194 close(hMouse);
195 }
196 }
197#endif
198 return TRUE;
199}
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