VirtualBox

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

Last change on this file since 69064 was 69064, checked in by vboxsync, 7 years ago

Additions/x11/vboxvideo: use X.Org Bool rather than C++ bool.
bugref:9017: Additions/x11: put vboxvideo into upstream X.Org

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