VBoxGuestR3LibVideo.cpp revision 5d05aa26ae1949e6f0bbc149d8b8e39495710ac7
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync/* $Id$ */
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync/** @file
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Video.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync */
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync/*
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * Copyright (C) 2007 innotek GmbH
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync *
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.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync */
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync/*******************************************************************************
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync* Header Files *
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync*******************************************************************************/
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync#include <iprt/string.h>
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync#include <iprt/mem.h>
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync#include <iprt/assert.h>
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
c312e1b81dffe42e0fb766020fb8defaeade05d6vboxsync#include "VBGLR3Internal.h"
c312e1b81dffe42e0fb766020fb8defaeade05d6vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync/**
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * Enable or disable video acceleration.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync *
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * @returns VBox status code.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync *
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * @param fEnable Pass zero to disable, any other value to enable.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync */
50f0e2e83362e100d306a411980d555d46aa00a8vboxsyncVBGLR3DECL(int) VbglR3VideoAccelEnable(bool fEnable)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync{
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync VMMDevVideoAccelEnable Req;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelEnable);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Req.u32Enable = fEnable;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Req.cbRingBuffer = VBVA_RING_BUFFER_SIZE;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Req.fu32Status = 0;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync return vbglR3GRPerform(&Req.header);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync}
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync/**
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * Flush the video buffer.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync *
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * @returns VBox status code.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync */
b0dfb334954c0552bb583967a3077ec88fd00471vboxsyncVBGLR3DECL(int) VbglR3VideoAccelFlush(void)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync{
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync VMMDevVideoAccelFlush Req;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelFlush);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync return vbglR3GRPerform(&Req.header);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync}
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync/**
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * Send mouse pointer shape information to the host.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync *
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync * @returns VBox status code.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync *
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.
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync */
54828795a553ed0731f308ebda81675ad2c39d58vboxsyncVBGLR3DECL(int) VbglR3SetPointerShape(uint32_t fFlags, uint32_t xHot, uint32_t yHot, uint32_t cx, uint32_t cy, const void *pvImg, size_t cbImg)
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync{
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync VMMDevReqMousePointer *pReq;
54828795a553ed0731f308ebda81675ad2c39d58vboxsync int rc = vbglR3GRAlloc((VMMDevRequestHeader **)&pReq, RT_OFFSETOF(VMMDevReqMousePointer, pointerData) + cbImg, VMMDevReq_SetPointerShape);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync if (RT_SUCCESS(rc))
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync {
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync pReq->fFlags = fFlags;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync pReq->xHot = xHot;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync pReq->yHot = yHot;
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync pReq->width = cx;
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync pReq->height = cy;
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync if (pvImg)
54828795a553ed0731f308ebda81675ad2c39d58vboxsync memcpy(pReq->pointerData, pvImg, cbImg);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync rc = vbglR3GRPerform(&pReq->header);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync vbglR3GRFree(&pReq->header);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync if (RT_SUCCESS(rc))
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync rc = pReq->header.rc;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync }
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync return rc;
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync}
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync/**
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 *
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync * @returns VBox status code.
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync *
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync * @param pReq Pointer to the VMMDevReqMousePointer structure.
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync */
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsyncVBGLR3DECL(int) VbglR3SetPointerShapeReq(VMMDevReqMousePointer *pReq)
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync{
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync int rc = vbglR3GRPerform(&pReq->header);
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync if (RT_SUCCESS(rc))
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync rc = pReq->header.rc;
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync return rc;
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync}
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync/**
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync * Query the last display change request.
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync *
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.
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync */
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsyncVBGLR3DECL(int) VbglR3GetLastDisplayChangeRequest(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits,
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync uint32_t *piDisplay)
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync{
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync VMMDevDisplayChangeRequest2 Req = { { 0 } };
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync#ifndef VBOX_VBGLR3_XFREE86
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync AssertPtrReturn(pcBits, VERR_INVALID_PARAMETER);
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync#endif
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsyncvmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync int rc = vbglR3GRPerform(&Req.header);
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync if (RT_SUCCESS(rc))
b60e4b0625949fd68ed97f1353e2174c5b3192e5vboxsync rc = Req.header.rc;
b60e4b0625949fd68ed97f1353e2174c5b3192e5vboxsync if (RT_SUCCESS(rc))
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync {
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync *pcx = Req.xres;
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync *pcy = Req.yres;
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync *pcBits = Req.bpp;
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync *piDisplay = Req.display;
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync }
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync return rc;
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync}
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync/**
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync * Wait for a display change request event from the host. These events must have been
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync * activated previously using VbglR3CtlFilterMask.
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync *
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync * @returns IPRT status value
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync * @param pcx on success, where to return the requested display width. 0 means no
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync * change.
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync * @param pcy on success, where to return the requested display height. 0 means no
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync * change.
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync * @param pcBits on success, where to return the requested bits per pixel. 0 means no
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync * change.
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync * @param piDisplay on success, where to return the index of the display to be changed.
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync */
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsyncVBGLR3DECL(int) VbglR3DisplayChangeWaitEvent(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits,
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync uint32_t *piDisplay)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync{
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync VBoxGuestWaitEventInfo waitEvent;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync int rc;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync#ifndef VBOX_VBGLR3_XFREE86
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync AssertPtrReturn(pcBits, VERR_INVALID_PARAMETER);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync#endif
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync waitEvent.u32TimeoutIn = RT_INDEFINITE_WAIT;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync waitEvent.u32EventMaskIn = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_WAITEVENT, &waitEvent, sizeof(waitEvent));
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync if (RT_SUCCESS(rc))
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync {
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync /* did we get the right event? */
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync {
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync VMMDevDisplayChangeRequest2 Req = { { 0 } };
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync Req.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync int rc = vbglR3GRPerform(&Req.header);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync if (RT_SUCCESS(rc))
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync rc = Req.header.rc;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync if (RT_SUCCESS(rc))
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync {
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync *pcx = Req.xres;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync *pcy = Req.yres;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync *pcBits = Req.bpp;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync *piDisplay = Req.display;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync }
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync }
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync else
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync rc = VERR_TRY_AGAIN;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync }
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync return rc;
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync}