VBoxGuestR3LibVideo.cpp revision a34996f4849a881e4112ba993984dcd2388b8bf2
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Video.
c58f1213e628a545081c70e26c6b67a841cff880vboxsync * Copyright (C) 2007-2009 Oracle Corporation
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.
aba0e602e244ae7c4f11b50fc6d2440f5a762038vboxsync * The contents of this file may alternatively be used under the terms
aba0e602e244ae7c4f11b50fc6d2440f5a762038vboxsync * of the Common Development and Distribution License Version 1.0
aba0e602e244ae7c4f11b50fc6d2440f5a762038vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
aba0e602e244ae7c4f11b50fc6d2440f5a762038vboxsync * VirtualBox OSE distribution, in which case the provisions of the
aba0e602e244ae7c4f11b50fc6d2440f5a762038vboxsync * CDDL are applicable instead of those of the GPL.
aba0e602e244ae7c4f11b50fc6d2440f5a762038vboxsync * You may elect to license modified versions of this file under the
aba0e602e244ae7c4f11b50fc6d2440f5a762038vboxsync * terms and conditions of either the GPL or the CDDL or both.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync/*******************************************************************************
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync* Header Files *
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync*******************************************************************************/
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync#include <VBox/HostServices/GuestPropertySvc.h> /* For Save and RetrieveVideoMode */
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync/* Rather than try to resolve all the header file conflicts, I will just
ab0fa8b1fefba60f43cfd2104a7939944da28b86vboxsync prototype what we need here. */
c312e1b81dffe42e0fb766020fb8defaeade05d6vboxsyncextern "C" void* xf86memcpy(void*,const void*,xf86size_t);
a34996f4849a881e4112ba993984dcd2388b8bf2vboxsync#endif /* VBOX_VBGLR3_XFREE86 */
a34996f4849a881e4112ba993984dcd2388b8bf2vboxsync#define VIDEO_PROP_PREFIX "/VirtualBox/GuestAdd/Vbgl/Video/"
64241796dca8fa36d3fca205e01b4320193a36b7vboxsync * Enable or disable video acceleration.
a34996f4849a881e4112ba993984dcd2388b8bf2vboxsync * @returns VBox status code.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * @param fEnable Pass zero to disable, any other value to enable.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsyncVBGLR3DECL(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.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * @param cx Pointer width.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * @param cy Pointer height.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * @param pvImg Pointer to the image data (can be NULL).
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * @param cbImg Size of the image data pointed to by pvImg.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsyncVBGLR3DECL(int) VbglR3SetPointerShape(uint32_t fFlags, uint32_t xHot, uint32_t yHot, uint32_t cx, uint32_t cy, const void *pvImg, size_t cbImg)
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync int rc = vbglR3GRAlloc((VMMDevRequestHeader **)&pReq, RT_OFFSETOF(VMMDevReqMousePointer, pointerData) + cbImg, VMMDevReq_SetPointerShape);
54828795a553ed0731f308ebda81675ad2c39d58vboxsync * Send mouse pointer shape information to the host.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * This version of the function accepts a request for clients that
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * already allocate and manipulate the request structure directly.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * @returns VBox status code.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * @param pReq Pointer to the VMMDevReqMousePointer structure.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsyncVBGLR3DECL(int) VbglR3SetPointerShapeReq(VMMDevReqMousePointer *pReq)
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync * Query the last display change request sent from the host to the guest.
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync * @returns iprt status value
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync * @param pcx Where to store the horizontal pixel resolution
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync * requested (a value of zero means do not change).
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync * @param pcy Where to store the vertical pixel resolution
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync * requested (a value of zero means do not change).
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync * @param pcBits Where to store the bits per pixel requested (a value
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync * of zero means do not change).
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync * @param iDisplay Where to store the display number the request was for
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync * - 0 for the primary display, 1 for the first
0defe73e08f591e32e92dfeb3de18ee84a180d2avboxsync * secondary display, etc.
0defe73e08f591e32e92dfeb3de18ee84a180d2avboxsync * @param fAck whether or not to acknowlege the newest request sent by
0defe73e08f591e32e92dfeb3de18ee84a180d2avboxsync * the host. If this is set, the function will return the
0defe73e08f591e32e92dfeb3de18ee84a180d2avboxsync * most recent host request, otherwise it will return the
0defe73e08f591e32e92dfeb3de18ee84a180d2avboxsync * last request to be acknowleged.
0defe73e08f591e32e92dfeb3de18ee84a180d2avboxsyncVBGLR3DECL(int) VbglR3GetDisplayChangeRequest(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits, uint32_t *piDisplay, bool fAck)
0defe73e08f591e32e92dfeb3de18ee84a180d2avboxsync AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
0defe73e08f591e32e92dfeb3de18ee84a180d2avboxsync vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync Req.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
0defe73e08f591e32e92dfeb3de18ee84a180d2avboxsync * Query the host as to whether it likes a specific video mode.
0defe73e08f591e32e92dfeb3de18ee84a180d2avboxsync * @returns the result of the query
0defe73e08f591e32e92dfeb3de18ee84a180d2avboxsync * @param cx the width of the mode being queried
0defe73e08f591e32e92dfeb3de18ee84a180d2avboxsync * @param cy the height of the mode being queried
0defe73e08f591e32e92dfeb3de18ee84a180d2avboxsync * @param cBits the bpp of the mode being queried
0defe73e08f591e32e92dfeb3de18ee84a180d2avboxsyncVBGLR3DECL(bool) VbglR3HostLikesVideoMode(uint32_t cx, uint32_t cy, uint32_t cBits)
0defe73e08f591e32e92dfeb3de18ee84a180d2avboxsync bool fRc = true; /* If for some reason we can't contact the host then
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync * we like everything. */
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync vmmdevInitRequest(&req.header, VMMDevReq_VideoModeSupported);
b3d4b85739cf74a503b1f8bbb7c7f4de26c1c09fvboxsync * Save video mode parameters to the registry.
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * @returns iprt status value
2084a447d1acb619df7c393fac41b79d517e4b3dvboxsync * @param pszName the name to save the mode parameters under
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync * @param cx mode width
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync * @param cy mode height
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync * @param cBits bits per pixel for the mode
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsyncVBGLR3DECL(int) VbglR3SaveVideoMode(const char *pszName, uint32_t cx, uint32_t cy, uint32_t cBits)
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync using namespace guestProp;
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX"%s", pszName);
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync RTStrPrintf(szModeParms, sizeof(szModeParms), "%dx%dx%d", cx, cy, cBits);
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync rc = VbglR3GuestPropWriteValue(u32ClientId, szModeName, szModeParms);
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync VbglR3GuestPropDisconnect(u32ClientId); /* Return value ignored, because what can we do anyway? */
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync#else /* !VBOX_WITH_GUEST_PROPS */
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync#endif /* !VBOX_WITH_GUEST_PROPS */
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync * Retrieve video mode parameters from the guest property store.
5c320d1b52e5e4ae280cd680c2c64de5f5f13d22vboxsync * @returns iprt status value
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync * @param pszName the name under which the mode parameters are saved
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync * @param pcx where to store the mode width
b3d4b85739cf74a503b1f8bbb7c7f4de26c1c09fvboxsync * @param pcy where to store the mode height
b3d4b85739cf74a503b1f8bbb7c7f4de26c1c09fvboxsync * @param pcBits where to store the bits per pixel for the mode
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsyncVBGLR3DECL(int) VbglR3RetrieveVideoMode(const char *pszName, uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits)
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync using namespace guestProp;
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync * First we retreive the video mode which is saved as a string in the
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync * guest property store.
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync /* The buffer for VbglR3GuestPropReadValue. If this is too small then
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync * something is wrong with the data stored in the property. */
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX"%s", pszName);
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync /** @todo add a VbglR3GuestPropReadValueF/FV that does the RTStrPrintf for you. */
9fc58edfe4464fca24d4a064b9d3fe2ed173a71avboxsync rc = VbglR3GuestPropReadValue(u32ClientId, szModeName, szModeParms,
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync * Now we convert the string returned to numeric values.
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync /* Extract the width from the string */
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync rc = RTStrToUInt32Ex(szModeParms, &pszNext, 10, &cx);
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync if ((rc != VWRN_TRAILING_CHARS) || (*pszNext != 'x'))
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync /* Extract the height from the string */
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync if ((rc != VWRN_TRAILING_CHARS) || (*pszNext != 'x'))
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync /* Extract the bpp from the string */
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync * And clean up and return the values if we successfully obtained them.
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync VbglR3GuestPropDisconnect(u32ClientId); /* Return value ignored, because what can we do anyway? */
dd6994667c4e2ebd8f1f01a1d29f5c0491f82603vboxsync#else /* !VBOX_WITH_GUEST_PROPS */
dd6994667c4e2ebd8f1f01a1d29f5c0491f82603vboxsync#endif /* !VBOX_WITH_GUEST_PROPS */