VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxVideo/Modesetting.cpp@ 35398

Last change on this file since 35398 was 35150, checked in by vboxsync, 14 years ago

Additions/VBoxVideo: support disabling the screen via VBVA_SCREEN_F_DISABLE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/* $Id: Modesetting.cpp 35150 2010-12-15 16:33:59Z vboxsync $ */
2/** @file
3 * VirtualBox Video driver, common code - HGSMI initialisation and helper
4 * functions.
5 */
6
7/*
8 * Copyright (C) 2006-2010 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#include <VBox/VBoxVideoGuest.h>
20#include <VBox/VBoxVideo.h>
21#include <VBox/VBoxGuest.h>
22#include <VBox/Hardware/VBoxVideoVBE.h>
23#include <VBox/VMMDev.h>
24
25#include <iprt/asm.h>
26#include <iprt/log.h>
27
28/**
29 * Gets the count of virtual monitors attached to the guest via an HGSMI
30 * command
31 *
32 * @returns the right count on success or 1 on failure.
33 * @param pCtx the context containing the heap to use
34 */
35RTDECL(uint32_t) VBoxHGSMIGetMonitorCount(PHGSMIGUESTCOMMANDCONTEXT pCtx)
36{
37 /* Query the configured number of displays. */
38 uint32_t cDisplays = 0;
39 VBoxQueryConfHGSMI(pCtx, VBOX_VBVA_CONF32_MONITOR_COUNT, &cDisplays);
40 LogFunc(("cDisplays = %d\n", cDisplays));
41 if (cDisplays == 0 || cDisplays > VBOX_VIDEO_MAX_SCREENS)
42 /* Host reported some bad value. Continue in the 1 screen mode. */
43 cDisplays = 1;
44 return cDisplays;
45}
46
47
48/**
49 * Tell the host about how VRAM is divided up between each screen via an HGSMI
50 * command. It is acceptable to specifiy identical data for each screen if
51 * they share a single framebuffer.
52 *
53 * @returns iprt status code, either VERR_NO_MEMORY or the status returned by
54 * @a pfnFill
55 * @param pCtx the context containing the heap to use
56 * @param u32Count the number of screens we are activating
57 * @param pfnFill a callback which initialises the VBVAINFOVIEW structures
58 * for all screens
59 * @param pvData context data for @a pfnFill
60 */
61RTDECL(int) VBoxHGSMISendViewInfo(PHGSMIGUESTCOMMANDCONTEXT pCtx,
62 uint32_t u32Count,
63 PFNHGSMIFILLVIEWINFO pfnFill,
64 void *pvData)
65{
66 int rc;
67 /* Issue the screen info command. */
68 void *p = VBoxHGSMIBufferAlloc(pCtx, sizeof(VBVAINFOVIEW) * u32Count,
69 HGSMI_CH_VBVA, VBVA_INFO_VIEW);
70 if (p)
71 {
72 VBVAINFOVIEW *pInfo = (VBVAINFOVIEW *)p;
73 rc = pfnFill(pvData, pInfo, u32Count);
74 if (RT_SUCCESS(rc))
75 VBoxHGSMIBufferSubmit (pCtx, p);
76 VBoxHGSMIBufferFree(pCtx, p);
77 }
78 else
79 rc = VERR_NO_MEMORY;
80 return rc;
81}
82
83
84/**
85 * Set a video mode using port registers. This must be done for the first
86 * screen before every HGSMI modeset and also works when HGSM is not enabled.
87 * @param cWidth the mode width
88 * @param cHeight the mode height
89 * @param cBPP the colour depth of the mode
90 * @param cx the horizontal panning offset
91 * @param cy the vertical panning offset
92 */
93RTDECL(void) VBoxVideoSetModeRegisters(uint16_t cWidth, uint16_t cHeight,
94 uint16_t cVirtWidth, uint16_t cBPP,
95 uint16_t cx, uint16_t cy)
96{
97 /* set the mode characteristics */
98 VBoxVideoCmnPortWriteUshort(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_XRES);
99 VBoxVideoCmnPortWriteUshort(VBE_DISPI_IOPORT_DATA, cWidth);
100 VBoxVideoCmnPortWriteUshort(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_YRES);
101 VBoxVideoCmnPortWriteUshort(VBE_DISPI_IOPORT_DATA, cHeight);
102 VBoxVideoCmnPortWriteUshort(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_VIRT_WIDTH);
103 VBoxVideoCmnPortWriteUshort(VBE_DISPI_IOPORT_DATA, cVirtWidth);
104 VBoxVideoCmnPortWriteUshort(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_BPP);
105 VBoxVideoCmnPortWriteUshort(VBE_DISPI_IOPORT_DATA, cBPP);
106 /* enable the mode */
107 VBoxVideoCmnPortWriteUshort(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_ENABLE);
108 VBoxVideoCmnPortWriteUshort(VBE_DISPI_IOPORT_DATA, VBE_DISPI_ENABLED | VBE_DISPI_LFB_ENABLED);
109 /* Panning registers */
110 VBoxVideoCmnPortWriteUshort(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_X_OFFSET);
111 VBoxVideoCmnPortWriteUshort(VBE_DISPI_IOPORT_DATA, cx);
112 VBoxVideoCmnPortWriteUshort(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_Y_OFFSET);
113 VBoxVideoCmnPortWriteUshort(VBE_DISPI_IOPORT_DATA, cy);
114 /** @todo read from the port to see if the mode switch was successful */
115}
116
117
118/**
119 * Set a video mode via an HGSMI request. The views must have been
120 * initialised first using @a VBoxHGSMISendViewInfo and if the mode is being
121 * set on the first display then it must be set first using registers.
122 * @param cDisplay the screen number
123 * @param cOriginX the horizontal displacement relative to the first screen
124 * @param cOriginY the vertical displacement relative to the first screen
125 * @param offStart the offset of the visible area of the framebuffer
126 * relative to the framebuffer start
127 * @param cbPitch the offset in bytes between the starts of two adjecent
128 * scan lines in video RAM
129 * @param cWidth the mode width
130 * @param cHeight the mode height
131 * @param cBPP the colour depth of the mode
132 */
133RTDECL(void) VBoxHGSMIProcessDisplayInfo(PHGSMIGUESTCOMMANDCONTEXT pCtx,
134 uint32_t cDisplay,
135 int32_t cOriginX,
136 int32_t cOriginY,
137 uint32_t offStart,
138 uint32_t cbPitch,
139 uint32_t cWidth,
140 uint32_t cHeight,
141 uint16_t cBPP,
142 uint16_t fFlags)
143{
144 /* Issue the screen info command. */
145 void *p = VBoxHGSMIBufferAlloc(pCtx,
146 sizeof (VBVAINFOSCREEN),
147 HGSMI_CH_VBVA,
148 VBVA_INFO_SCREEN);
149 if (!p)
150 {
151 LogFunc(("HGSMIHeapAlloc failed\n"));
152 }
153 else
154 {
155 VBVAINFOSCREEN *pScreen = (VBVAINFOSCREEN *)p;
156
157 pScreen->u32ViewIndex = cDisplay;
158 pScreen->i32OriginX = cOriginX;
159 pScreen->i32OriginY = cOriginY;
160 pScreen->u32StartOffset = offStart;
161 pScreen->u32LineSize = cbPitch;
162 pScreen->u32Width = cWidth;
163 pScreen->u32Height = cHeight;
164 pScreen->u16BitsPerPixel = cBPP;
165 pScreen->u16Flags = fFlags;
166
167 VBoxHGSMIBufferSubmit(pCtx, p);
168
169 VBoxHGSMIBufferFree(pCtx, p);
170 }
171}
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