VirtualBox

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

Last change on this file since 50485 was 49877, checked in by vboxsync, 11 years ago

Additions/x11: make vboxvideo dynamic resizing compatible with what the KMS/modesetting drivers can do.

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