VirtualBox

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

Last change on this file since 96588 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1/* $Id: setmode.c 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * Linux Additions X11 graphics driver, mode setting
4 */
5
6/*
7 * Copyright (C) 2006-2022 Oracle and/or its affiliates.
8 * This file is based on X11 VESA driver (hardly any traces left here):
9 *
10 * Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com)
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
25 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
26 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
27 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
28 * USE OR OTHER DEALINGS IN THE SOFTWARE.
29 *
30 * Except as contained in this notice, the name of Conectiva Linux shall
31 * not be used in advertising or otherwise to promote the sale, use or other
32 * dealings in this Software without prior written authorization from
33 * Conectiva Linux.
34 *
35 * Authors: Paulo César Pereira de Andrade <pcpa@conectiva.com.br>
36 * Michael Thayer <michael.thayer@oracle.com>
37 */
38
39#ifdef XORG_7X
40/* We include <unistd.h> for Solaris below, and the ANSI C emulation layer
41 * interferes with that. */
42# define _XF86_ANSIC_H
43# define XF86_LIBC_H
44# include <string.h>
45#endif
46#include "vboxvideo.h"
47#include "xf86.h"
48
49/* VGA hardware functions for setting and restoring text mode */
50#include "vgaHW.h"
51
52#ifdef RT_OS_SOLARIS
53# include <sys/vuid_event.h>
54# include <sys/msio.h>
55# include <errno.h>
56# include <fcntl.h>
57# include <unistd.h>
58#endif
59
60/** Clear the virtual framebuffer in VRAM. Optionally also clear up to the
61 * size of a new framebuffer. Framebuffer sizes larger than available VRAM
62 * be treated as zero and passed over. */
63void vbvxClearVRAM(ScrnInfoPtr pScrn, size_t cbOldSize, size_t cbNewSize)
64{
65 VBOXPtr pVBox = VBOXGetRec(pScrn);
66
67 /* Assume 32BPP - this is just a sanity test. */
68 AssertMsg( cbOldSize / 4 <= VBOX_VIDEO_MAX_VIRTUAL * VBOX_VIDEO_MAX_VIRTUAL
69 && cbNewSize / 4 <= VBOX_VIDEO_MAX_VIRTUAL * VBOX_VIDEO_MAX_VIRTUAL,
70 ("cbOldSize=%llu cbNewSize=%llu, max=%u.\n", (unsigned long long)cbOldSize, (unsigned long long)cbNewSize,
71 VBOX_VIDEO_MAX_VIRTUAL * VBOX_VIDEO_MAX_VIRTUAL));
72 if (cbOldSize > (size_t)pVBox->cbFBMax)
73 cbOldSize = pVBox->cbFBMax;
74 if (cbNewSize > (size_t)pVBox->cbFBMax)
75 cbNewSize = pVBox->cbFBMax;
76 memset(pVBox->base, 0, max(cbOldSize, cbNewSize));
77}
78
79/** Set a graphics mode. Poke any required values into registers, do an HGSMI
80 * mode set and tell the host we support advanced graphics functions.
81 */
82void vbvxSetMode(ScrnInfoPtr pScrn, unsigned cDisplay, unsigned cWidth, unsigned cHeight, int x, int y, Bool fEnabled,
83 Bool fConnected, struct vbvxFrameBuffer *pFrameBuffer)
84{
85 VBOXPtr pVBox = VBOXGetRec(pScrn);
86 uint32_t offStart;
87 uint16_t fFlags;
88 int rc;
89 Bool fEnabledAndVisible = fEnabled && x + cWidth <= pFrameBuffer->cWidth && y + cHeight <= pFrameBuffer->cHeight;
90 /* Recent host code has a flag to blank the screen; older code needs BPP set to zero. */
91 uint32_t cBPP = fEnabledAndVisible || pVBox->fHostHasScreenBlankingFlag ? pFrameBuffer->cBPP : 0;
92
93 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",
94 cDisplay, cWidth, cHeight, x, y, fEnabled, fConnected, pFrameBuffer->x0, pFrameBuffer->y0, pFrameBuffer->cWidth,
95 pFrameBuffer->cHeight, pFrameBuffer->cBPP);
96 AssertMsg(cWidth != 0 && cHeight != 0, ("cWidth = 0 or cHeight = 0\n"));
97 offStart = (y * pFrameBuffer->cWidth + x) * pFrameBuffer->cBPP / 8;
98 if (cDisplay == 0 && fEnabled)
99 VBoxVideoSetModeRegisters(cWidth, cHeight, pFrameBuffer->cWidth, pFrameBuffer->cBPP, 0, x, y);
100 fFlags = VBVA_SCREEN_F_ACTIVE;
101 fFlags |= (fConnected ? 0 : VBVA_SCREEN_F_DISABLED);
102 fFlags |= (!fEnabledAndVisible && pVBox->fHostHasScreenBlankingFlag ? VBVA_SCREEN_F_BLANK : 0);
103 VBoxHGSMIProcessDisplayInfo(&pVBox->guestCtx, cDisplay, x - pFrameBuffer->x0, y - pFrameBuffer->y0, offStart,
104 pFrameBuffer->cWidth * pFrameBuffer->cBPP / 8, cWidth, cHeight, cBPP, fFlags);
105 rc = VBoxHGSMIUpdateInputMapping(&pVBox->guestCtx, 0 - pFrameBuffer->x0, 0 - pFrameBuffer->y0, pFrameBuffer->cWidth,
106 pFrameBuffer->cHeight);
107 if (RT_FAILURE(rc))
108 FatalError("Failed to update the input mapping.\n");
109}
110
111/** Tell the virtual mouse device about the new virtual desktop size. */
112void vbvxSetSolarisMouseRange(int width, int height)
113{
114#ifdef RT_OS_SOLARIS
115 int rc;
116 int hMouse = open("/dev/mouse", O_RDWR);
117
118 if (hMouse >= 0)
119 {
120 do {
121 Ms_screen_resolution Res = { height, width };
122 rc = ioctl(hMouse, MSIOSRESOLUTION, &Res);
123 } while ((rc != 0) && (errno == EINTR));
124 close(hMouse);
125 }
126#else
127 (void)width; (void)height;
128#endif
129}
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