VirtualBox

Changeset 21912 in vbox for trunk/src/VBox/Additions


Ignore:
Timestamp:
Jul 31, 2009 11:33:06 AM (15 years ago)
Author:
vboxsync
Message:

Additions/x11 and common: simplify requests for getting video mode hints and introduce a generic wait event request

Location:
trunk/src/VBox/Additions
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibMisc.cpp

    r21211 r21912  
    2828
    2929#include "VBGLR3Internal.h"
     30
     31
     32/**
     33 * Wait for the host to signal one or several of a set of events and return the
     34 * events signalled.  The events will only be delivered by the host if they
     35 * have been enabled previously using @a VbglR3CtlFilterMask.  If one or
     36 * several of the events have already been signalled but not yet waited for,
     37 * this function will return immediately and return those events.
     38 *
     39 * @returns iprt status code
     40 * @param   fMask       the events we want to wait for, or-ed together
     41 * @param   u32Timeout  how long to wait before giving up and returning.  Use
     42 *                      RT_INDEFINITE_WAIT to wait until we are interrupted or
     43 *                      one of the events is signalled.
     44 * @param   pfEvents    where to store the events signalled
     45 */
     46VBGLR3DECL(int) VbglR3WaitEvent(uint32_t fMask, uint32_t u32Timeout,
     47                                uint32_t *pfEvents)
     48{
     49    LogFlowFunc(("fMask=0x%x, u32Timeout=%u, pfEvents=%p\n", fMask, u32Timeout,
     50                 pfEvents));
     51    AssertReturn((fMask & ~VMMDEV_EVENT_VALID_EVENT_MASK) == 0,
     52                 VERR_INVALID_PARAMETER);
     53    /* Does pfEvents == NULL make sense? */
     54    AssertReturn(VALID_PTR(pfEvents) || pfEvents == NULL,
     55                 VERR_INVALID_POINTER);
     56
     57    VBoxGuestWaitEventInfo waitEvent;
     58    int rc;
     59
     60    waitEvent.u32TimeoutIn = u32Timeout;
     61    waitEvent.u32EventMaskIn = fMask;
     62    waitEvent.u32Result = VBOXGUEST_WAITEVENT_ERROR;
     63    waitEvent.u32EventFlagsOut = 0;
     64    rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_WAITEVENT, &waitEvent, sizeof(waitEvent));
     65    if (RT_SUCCESS(rc) && (pfEvents) != NULL)
     66        *pfEvents = waitEvent.u32EventFlagsOut;
     67    LogFlowFunc(("rc=%Rrc, waitEvent.u32EventFlagsOut=0x%x\n", rc,
     68                 waitEvent.u32EventFlagsOut));
     69    return rc;
     70}
    3071
    3172
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibVideo.cpp

    r21211 r21912  
    120120
    121121/**
    122  * Query the last display change request.
     122 * Query the last display change request sent from the host to the guest.
    123123 *
    124124 * @returns iprt status value
    125  * @param   pcx         Where to store the horizontal pixel resolution (0 = do not change).
    126  * @param   pcy         Where to store the vertical pixel resolution (0 = do not change).
    127  * @param   pcBits      Where to store the bits per pixel (0 = do not change).
    128  * @param   iDisplay    Where to store the display number the request was for - 0 for the
    129  *                      primary display, 1 for the first secondary, etc.
    130  */
    131 VBGLR3DECL(int) VbglR3GetLastDisplayChangeRequest(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits, uint32_t *piDisplay)
     125 * @param   pcx         Where to store the horizontal pixel resolution
     126 *                      requested (a value of zero means do not change).
     127 * @param   pcy         Where to store the vertical pixel resolution
     128 *                      requested (a value of zero means do not change).
     129 * @param   pcBits      Where to store the bits per pixel requested (a value
     130 *                      of zero means do not change).
     131 * @param   iDisplay    Where to store the display number the request was for
     132 *                      - 0 for the primary display, 1 for the first
     133 *                      secondary display, etc.
     134 * @param   fAck        whether or not to acknowlege the newest request sent by
     135 *                      the host.  If this is set, the function will return the
     136 *                      most recent host request, otherwise it will return the
     137 *                      last request to be acknowleged.
     138 *                     
     139 */
     140VBGLR3DECL(int) VbglR3GetDisplayChangeRequest(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits, uint32_t *piDisplay, bool fAck)
    132141{
    133142    VMMDevDisplayChangeRequest2 Req = { { 0 } };
     
    139148    AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
    140149#endif
    141 vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
     150    vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
     151    if (fAck)
     152        Req.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
    142153    int rc = vbglR3GRPerform(&Req.header);
    143154    if (RT_SUCCESS(rc))
     
    153164}
    154165
    155 /**
    156  * Wait for a display change request event from the host.  These events must have been
    157  * activated previously using VbglR3CtlFilterMask.
    158  *
    159  * @returns IPRT status value
    160  * @param   pcx       On success, where to return the requested display width.
    161  *                    0 means no change.
    162  * @param   pcy       On success, where to return the requested display height.
    163  *                    0 means no change.
    164  * @param   pcBits    On success, where to return the requested bits per pixel.
    165  *                    0 means no change.
    166  * @param   piDisplay On success, where to return the index of the display to be changed.
    167  */
    168 VBGLR3DECL(int) VbglR3DisplayChangeWaitEvent(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits, uint32_t *piDisplay)
    169 {
    170     VBoxGuestWaitEventInfo waitEvent;
    171     int rc;
    172 
    173 #ifndef VBOX_VBGLR3_XFREE86
    174     AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
    175     AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
    176     AssertPtrReturn(pcBits, VERR_INVALID_PARAMETER);
    177     AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
    178 #endif
    179     waitEvent.u32TimeoutIn = RT_INDEFINITE_WAIT;
    180     waitEvent.u32EventMaskIn = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
    181     waitEvent.u32Result = VBOXGUEST_WAITEVENT_ERROR;
    182     waitEvent.u32EventFlagsOut = 0;
    183     rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_WAITEVENT, &waitEvent, sizeof(waitEvent));
    184     if (RT_SUCCESS(rc))
    185     {
    186         /* did we get the right event? */
    187         if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
    188         {
    189             VMMDevDisplayChangeRequest2 Req = { { 0 } };
    190             vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
    191             Req.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
    192             int rc = vbglR3GRPerform(&Req.header);
    193             if (RT_SUCCESS(rc))
    194                 rc = Req.header.rc;
    195             if (RT_SUCCESS(rc))
    196             {
    197                 *pcx = Req.xres;
    198                 *pcy = Req.yres;
    199                 *pcBits = Req.bpp;
    200                 *piDisplay = Req.display;
    201             }
    202         }
    203         else
    204             rc = VERR_TRY_AGAIN;
    205     }
    206     return rc;
    207 }
    208166
    209167/**
  • trunk/src/VBox/Additions/x11/VBoxClient/autoresize.cpp

    r21227 r21912  
    5656    }
    5757    if (RT_SUCCESS(rc))
    58         rc = VbglR3CtlFilterMask(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, 0);
     58        rc = VbglR3CtlFilterMask(  VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST
     59                                 | VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED, 0);
    5960    LogFlowFunc(("returning %Rrc\n", rc));
    6061    return rc;
     
    6465{
    6566    LogFlowFunc(("\n"));
    66     VbglR3CtlFilterMask(0, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
     67    VbglR3CtlFilterMask(0,   VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST
     68                           | VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED);
    6769    LogFlowFunc(("returning\n"));
    6870}
     
    9395    if (RT_FAILURE(rc))
    9496        return rc;
    95     VbglR3GetLastDisplayChangeRequest(&cx0, &cy0, &cBits0, &iDisplay0);
     97    VbglR3GetDisplayChangeRequest(&cx0, &cy0, &cBits0, &iDisplay0, false);
    9698    while (true)
    9799    {
    98         uint32_t cx = 0, cy = 0, cBits = 0, iDisplay = 0;
    99         rc = VbglR3DisplayChangeWaitEvent(&cx, &cy, &cBits, &iDisplay);
    100         /* Ignore the request if it is stale */
    101         if ((cx != cx0) || (cy != cy0) || RT_FAILURE(rc))
     100        uint32_t fEvents = 0, cx = 0, cy = 0, cBits = 0, iDisplay = 0;
     101        rc = VbglR3WaitEvent(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST,
     102                             RT_INDEFINITE_WAIT, &fEvents);
     103        if (RT_SUCCESS(rc) && (fEvents & VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST))
    102104        {
    103                 /* If we are not stopping, sleep for a bit to avoid using up too
    104                     much CPU while retrying. */
    105                 if (RT_FAILURE(rc))
    106                     RTThreadYield();
    107                 else
    108                     system("VBoxRandR");
     105            rc = VbglR3GetDisplayChangeRequest(&cx, &cy, &cBits, &iDisplay,
     106                                               true);
     107            /* Ignore the request if it is stale */
     108            if ((cx != cx0) || (cy != cy0) || RT_FAILURE(rc))
     109            {
     110                    /* If we are not stopping, sleep for a bit to avoid using up
     111                        too much CPU while retrying. */
     112                    if (RT_FAILURE(rc))
     113                        RTThreadYield();
     114                    else
     115                    {
     116                        system("VBoxRandR");
     117                    cx0 = cx;
     118                    cy0 = cy;
     119                    }
     120            }
    109121        }
    110         /* We do not want to ignore any further requests. */
    111         cx0 = 0;
    112         cy0 = 0;
    113122    }
    114123    LogFlowFunc(("returning VINF_SUCCESS\n"));
  • trunk/src/VBox/Additions/x11/vboxvideo/vboxutils.c

    r21867 r21912  
    998998    if (!pVBox->useDevice)
    999999        return FALSE;
    1000     int rc = VbglR3GetLastDisplayChangeRequest(pcx, pcy, pcBits, piDisplay);
     1000    int rc = VbglR3GetDisplayChangeRequest(pcx, pcy, pcBits, piDisplay, false);
    10011001    if (RT_SUCCESS(rc))
    10021002        return TRUE;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette