1 | /* $Id: setmode.c 55237 2015-04-14 10:16:43Z 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. */
|
---|
77 | void 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. */
|
---|
96 | void 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. This
|
---|
112 | * procedure is complicated by the fact that X.Org can implicitly disable a
|
---|
113 | * screen by resizing the virtual framebuffer so that the screen is no longer
|
---|
114 | * inside it. We have to spot and handle this.
|
---|
115 | */
|
---|
116 | Bool VBOXSetMode(ScrnInfoPtr pScrn, unsigned cDisplay, unsigned cWidth,
|
---|
117 | unsigned cHeight, int x, int y)
|
---|
118 | {
|
---|
119 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
120 | uint32_t offStart, cwReal = cWidth;
|
---|
121 | bool fEnabled;
|
---|
122 | uint16_t fFlags;
|
---|
123 | int rc;
|
---|
124 |
|
---|
125 | TRACE_LOG("cDisplay=%u, cWidth=%u, cHeight=%u, x=%d, y=%d, displayWidth=%d\n",
|
---|
126 | cDisplay, cWidth, cHeight, x, y, pScrn->displayWidth);
|
---|
127 | offStart = y * pVBox->cbLine + x * vboxBPP(pScrn) / 8;
|
---|
128 | /* Deactivate the screen if the mode - specifically the virtual width - is
|
---|
129 | * too large for VRAM as we sometimes have to do this - see comments in
|
---|
130 | * VBOXPreInit. */
|
---|
131 | if ( offStart + pVBox->cbLine * cHeight > pVBox->cbFBMax
|
---|
132 | || pVBox->cbLine * pScrn->virtualY > pVBox->cbFBMax)
|
---|
133 | return FALSE;
|
---|
134 | /* Deactivate the screen if it is outside of the virtual framebuffer and
|
---|
135 | * clamp it to lie inside if it is partly outside. */
|
---|
136 | if (x >= pScrn->displayWidth || x + (int) cWidth <= 0)
|
---|
137 | return FALSE;
|
---|
138 | else
|
---|
139 | cwReal = RT_MIN((int) cWidth, pScrn->displayWidth - x);
|
---|
140 | TRACE_LOG("pVBox->pScreens[%u].fCrtcEnabled=%d, fOutputEnabled=%d\n",
|
---|
141 | cDisplay, (int)pVBox->pScreens[cDisplay].fCrtcEnabled,
|
---|
142 | (int)pVBox->pScreens[cDisplay].fOutputEnabled);
|
---|
143 | if (cDisplay == 0)
|
---|
144 | VBoxVideoSetModeRegisters(cwReal, cHeight, pScrn->displayWidth,
|
---|
145 | vboxBPP(pScrn), 0, x, y);
|
---|
146 | fEnabled = pVBox->pScreens[cDisplay].fCrtcEnabled
|
---|
147 | && pVBox->pScreens[cDisplay].fOutputEnabled;
|
---|
148 | fFlags = VBVA_SCREEN_F_ACTIVE;
|
---|
149 | fFlags |= (pVBox->pScreens[cDisplay].afConnected ? 0
|
---|
150 | : VBVA_SCREEN_F_DISABLED);
|
---|
151 | VBoxHGSMIProcessDisplayInfo(&pVBox->guestCtx, cDisplay, x, y,
|
---|
152 | offStart, pVBox->cbLine, cwReal, cHeight,
|
---|
153 | fEnabled ? vboxBPP(pScrn) : 0, fFlags);
|
---|
154 | if (cDisplay == 0)
|
---|
155 | {
|
---|
156 | rc = VBoxHGSMIUpdateInputMapping(&pVBox->guestCtx, 0 - pVBox->pScreens[0].aScreenLocation.x,
|
---|
157 | 0 - pVBox->pScreens[0].aScreenLocation.y, pScrn->virtualX, pScrn->virtualY);
|
---|
158 | if (RT_FAILURE(rc))
|
---|
159 | FatalError("Failed to update the input mapping.\n");
|
---|
160 | }
|
---|
161 | return TRUE;
|
---|
162 | }
|
---|
163 |
|
---|
164 | /** Resize the virtual framebuffer. After resizing we reset all modes
|
---|
165 | * (X.Org 1.3+) to adjust them to the new framebuffer.
|
---|
166 | */
|
---|
167 | Bool VBOXAdjustScreenPixmap(ScrnInfoPtr pScrn, int width, int height)
|
---|
168 | {
|
---|
169 | ScreenPtr pScreen = pScrn->pScreen;
|
---|
170 | PixmapPtr pPixmap = pScreen->GetScreenPixmap(pScreen);
|
---|
171 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
172 | uint64_t cbLine = vboxLineLength(pScrn, width);
|
---|
173 | int displayWidth = vboxDisplayPitch(pScrn, cbLine);
|
---|
174 | int rc;
|
---|
175 |
|
---|
176 | TRACE_LOG("width=%d, height=%d\n", width, height);
|
---|
177 | if ( width == pScrn->virtualX
|
---|
178 | && height == pScrn->virtualY
|
---|
179 | && displayWidth == pScrn->displayWidth)
|
---|
180 | return TRUE;
|
---|
181 | if (!pPixmap) {
|
---|
182 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
183 | "Failed to get the screen pixmap.\n");
|
---|
184 | return FALSE;
|
---|
185 | }
|
---|
186 | if (cbLine > UINT32_MAX || cbLine * height >= pVBox->cbFBMax)
|
---|
187 | {
|
---|
188 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
189 | "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",
|
---|
190 | width, height, pVBox->cbFBMax / 1024, pScrn->videoRam);
|
---|
191 | return FALSE;
|
---|
192 | }
|
---|
193 | pScreen->ModifyPixmapHeader(pPixmap, width, height,
|
---|
194 | pScrn->depth, vboxBPP(pScrn), cbLine,
|
---|
195 | pVBox->base);
|
---|
196 | vboxClearVRAM(pScrn, width, height);
|
---|
197 | pScrn->virtualX = width;
|
---|
198 | pScrn->virtualY = height;
|
---|
199 | pScrn->displayWidth = displayWidth;
|
---|
200 | pVBox->cbLine = cbLine;
|
---|
201 | #ifdef VBOX_DRI_OLD
|
---|
202 | if (pVBox->useDRI)
|
---|
203 | VBOXDRIUpdateStride(pScrn, pVBox);
|
---|
204 | #endif
|
---|
205 | #ifdef VBOXVIDEO_13
|
---|
206 | /* Write the new values to the hardware */
|
---|
207 | /** @todo why is this only for VBOXVIDEO_13? */
|
---|
208 | {
|
---|
209 | unsigned i;
|
---|
210 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
211 | VBOXSetMode(pScrn, i, pVBox->pScreens[i].aScreenLocation.cx,
|
---|
212 | pVBox->pScreens[i].aScreenLocation.cy,
|
---|
213 | pVBox->pScreens[i].aScreenLocation.x,
|
---|
214 | pVBox->pScreens[i].aScreenLocation.y);
|
---|
215 | }
|
---|
216 | #else
|
---|
217 | rc = VBoxHGSMIUpdateInputMapping(&pVBox->guestCtx, 0 - pVBox->pScreens[0].aScreenLocation.x,
|
---|
218 | 0 - pVBox->pScreens[0].aScreenLocation.y, pScrn->virtualX, pScrn->virtualY);
|
---|
219 | if (RT_FAILURE(rc))
|
---|
220 | FatalError("Failed to update the input mapping.\n");
|
---|
221 | #endif
|
---|
222 | vbvxSetSolarisMouseRange(width, height);
|
---|
223 | return TRUE;
|
---|
224 | }
|
---|
225 |
|
---|
226 | /** Tell the virtual mouse device about the new virtual desktop size. */
|
---|
227 | void vbvxSetSolarisMouseRange(int width, int height)
|
---|
228 | {
|
---|
229 | #ifdef RT_OS_SOLARIS
|
---|
230 | int rc;
|
---|
231 | int hMouse = open("/dev/mouse", O_RDWR);
|
---|
232 |
|
---|
233 | if (hMouse >= 0)
|
---|
234 | {
|
---|
235 | do {
|
---|
236 | Ms_screen_resolution Res = { height, width };
|
---|
237 | rc = ioctl(hMouse, MSIOSRESOLUTION, &Res);
|
---|
238 | } while ((rc != 0) && (errno == EINTR));
|
---|
239 | close(hMouse);
|
---|
240 | }
|
---|
241 | #else
|
---|
242 | (void)width; (void)height;
|
---|
243 | #endif
|
---|
244 | }
|
---|