VBoxGuestR3LibVideo.cpp revision 5b5f34343f19663d77572b58d4cc70bf57e64b51
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Video.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Copyright (C) 2007 Sun Microsystems, Inc.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * available from http://www.virtualbox.org. This file is free software;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * you can redistribute it and/or modify it under the terms of the GNU
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * General Public License (GPL) as published by the Free Software
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * additional information or have any questions.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync/*******************************************************************************
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync* Header Files *
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync*******************************************************************************/
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync#include <VBox/HostServices/VBoxInfoSvc.h> /* For Save and RetrieveVideoMode */
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * Enable or disable video acceleration.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * @returns VBox status code.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * @param fEnable Pass zero to disable, any other value to enable.
50f0e2e83362e100d306a411980d555d46aa00a8vboxsyncVBGLR3DECL(int) VbglR3VideoAccelEnable(bool fEnable)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelEnable);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * Flush the video buffer.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * @returns VBox status code.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelFlush);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * Send mouse pointer shape information to the host.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * @returns VBox status code.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * @param fFlags Mouse pointer flags.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * @param xHot X coordinate of hot spot.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * @param yHot Y coordinate of hot spot.
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync * @param cx Pointer width.
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync * @param cy Pointer height.
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync * @param pvImg Pointer to the image data (can be NULL).
54828795a553ed0731f308ebda81675ad2c39d58vboxsync * @param cbImg Size of the image data pointed to by pvImg.
54828795a553ed0731f308ebda81675ad2c39d58vboxsyncVBGLR3DECL(int) VbglR3SetPointerShape(uint32_t fFlags, uint32_t xHot, uint32_t yHot, uint32_t cx, uint32_t cy, const void *pvImg, size_t cbImg)
54828795a553ed0731f308ebda81675ad2c39d58vboxsync int rc = vbglR3GRAlloc((VMMDevRequestHeader **)&pReq, RT_OFFSETOF(VMMDevReqMousePointer, pointerData) + cbImg, VMMDevReq_SetPointerShape);
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync * Send mouse pointer shape information to the host.
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync * This version of the function accepts a request for clients that
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync * already allocate and manipulate the request structure directly.
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync * @returns VBox status code.
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync * @param pReq Pointer to the VMMDevReqMousePointer structure.
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsyncVBGLR3DECL(int) VbglR3SetPointerShapeReq(VMMDevReqMousePointer *pReq)
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync * Query the last display change request.
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync * @returns iprt status value
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync * @param pcx Where to store the horizontal pixel resolution (0 = do not change).
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync * @param pcy Where to store the vertical pixel resolution (0 = do not change).
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync * @param pcBits Where to store the bits per pixel (0 = do not change).
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync * @param iDisplay Where to store the display number the request was for - 0 for the
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync * primary display, 1 for the first secondary, etc.
052deaa01d8fcd5cec4dff857833538940b751c3vboxsyncVBGLR3DECL(int) VbglR3GetLastDisplayChangeRequest(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits, uint32_t *piDisplay)
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsyncvmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync * Wait for a display change request event from the host. These events must have been
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync * activated previously using VbglR3CtlFilterMask.
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync * @returns IPRT status value
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync * @param pcx On success, where to return the requested display width.
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync * 0 means no change.
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync * @param pcy On success, where to return the requested display height.
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync * 0 means no change.
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync * @param pcBits On success, where to return the requested bits per pixel.
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync * 0 means no change.
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync * @param piDisplay On success, where to return the index of the display to be changed.
052deaa01d8fcd5cec4dff857833538940b751c3vboxsyncVBGLR3DECL(int) VbglR3DisplayChangeWaitEvent(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits, uint32_t *piDisplay)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync waitEvent.u32EventMaskIn = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_WAITEVENT, &waitEvent, sizeof(waitEvent));
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync /* did we get the right event? */
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync Req.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync * Query the host as to whether it likes a specific video mode.
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync * @returns the result of the query
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync * @param cx the width of the mode being queried
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync * @param cy the height of the mode being queried
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync * @param cBits the bpp of the mode being queried
052deaa01d8fcd5cec4dff857833538940b751c3vboxsyncVBGLR3DECL(bool) VbglR3HostLikesVideoMode(uint32_t cx, uint32_t cy, uint32_t cBits)
d308e8fdb9e4d827ed10d26d1581d265602f6f46vboxsync bool fRc = false;
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync vmmdevInitRequest(&req.header, VMMDevReq_VideoModeSupported);
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync LogRelFunc(("error querying video mode supported status from VMMDev."
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync "rc = %Vrc, VMMDev rc = %Vrc\n", rc, req.header.rc));
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync * Save video mode parameters to the registry.
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync * @returns iprt status value
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync * @param pszName the name to save the mode parameters under
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync * @param cx mode width
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync * @param cy mode height
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync * @param cBits bits per pixel for the mode
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsyncVBGLR3DECL(int) VbglR3SaveVideoMode(const char *pszName, uint32_t cx, uint32_t cy, uint32_t cBits)
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync using namespace svcInfo;
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync RTStrPrintf(szModeName, sizeof(szModeName), "VideoMode/%s", pszName);
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync RTStrPrintf(szModeParms, sizeof(szModeParms), "%dx%dx%d", cx, cy, cBits);
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync rc = VbglR3InfoSvcWriteKey(u32ClientId, szModeName, szModeParms);
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync VbglR3InfoSvcDisconnect(u32ClientId); /* Return value ignored, because what can we do anyway? */
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync * Retrieve video mode parameters from the registry.
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync * @returns iprt status value
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync * @param pszName the name under which the mode parameters are saved
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync * @param pcx where to store the mode width
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync * @param pcy where to store the mode height
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync * @param pcBits where to store the bits per pixel for the mode
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsyncVBGLR3DECL(int) VbglR3RetrieveVideoMode(const char *pszName, uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits)
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync using namespace svcInfo;
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync RTStrPrintf(szModeName, sizeof(szModeName), "VideoMode/%s", pszName);
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync rc = VbglR3InfoSvcReadKey(u32ClientId, szModeName, szModeParms,
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync sizeof(szModeParms), NULL); /** @todo add a VbglR3InfoSvcReadKeyF/FV that does the RTStrPrintf for you. */
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync /* Extract the width from the string */
7dbde0174637fbfd00c50b383f654e46878eaa8evboxsync rc = RTStrToUInt32Ex(szModeParms, &pszNext, 10, &cx);
846739bf4fe90231599e8de3a8c792ae2851b1d1vboxsync if ((rc != VWRN_TRAILING_CHARS) || (*pszNext != 'x'))
846739bf4fe90231599e8de3a8c792ae2851b1d1vboxsync if ((rc != VWRN_TRAILING_CHARS) || (*pszNext != 'x'))
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync VbglR3InfoSvcDisconnect(u32ClientId); /* Return value ignored, because what can we do anyway? */