VirtualBox

Changeset 24714 in vbox for trunk


Ignore:
Timestamp:
Nov 17, 2009 10:45:20 AM (15 years ago)
Author:
vboxsync
Message:

DevVGA_VBVA: save and restore mouse pointer.

Location:
trunk/src/VBox/Devices/Graphics
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Graphics/DevVGA.cpp

    r24495 r24714  
    54535453
    54545454    if (    uVersion != VGA_SAVEDSTATE_VERSION
     5455        &&  uVersion != VGA_SAVEDSTATE_VERSION_WITH_CONFIG
    54555456        &&  uVersion != VGA_SAVEDSTATE_VERSION_HGSMI
    54565457        &&  uVersion != VGA_SAVEDSTATE_VERSION_PRE_HGSMI
  • trunk/src/VBox/Devices/Graphics/DevVGA.h

    r24495 r24714  
    4949#endif /* VBOX_WITH_HGSMI */
    5050
    51 #define VGA_SAVEDSTATE_VERSION              4
     51#define VGA_SAVEDSTATE_VERSION              5
     52#define VGA_SAVEDSTATE_VERSION_WITH_CONFIG  4
    5253#define VGA_SAVEDSTATE_VERSION_HGSMI        3
    5354#define VGA_SAVEDSTATE_VERSION_PRE_HGSMI    2
  • trunk/src/VBox/Devices/Graphics/DevVGA_VBVA.cpp

    r24166 r24714  
    6666} VBVAVIEW;
    6767
     68typedef struct VBVAMOUSESHAPEINFO
     69{
     70    bool fSet;
     71    bool fVisible;
     72    bool fAlpha;
     73    uint32_t u32HotX;
     74    uint32_t u32HotY;
     75    uint32_t u32Width;
     76    uint32_t u32Height;
     77    uint32_t cbShape;
     78    uint32_t cbAllocated;
     79    uint8_t *pu8Shape;
     80} VBVAMOUSESHAPEINFO;
     81
    6882/* @todo saved state: save and restore VBVACONTEXT */
    6983typedef struct _VBVACONTEXT
     
    7185    uint32_t cViews;
    7286    VBVAVIEW aViews[64 /* @todo SchemaDefs::MaxGuestMonitors*/];
     87    VBVAMOUSESHAPEINFO mouseShapeInfo;
    7388} VBVACONTEXT;
    7489
     
    519534}
    520535
    521 static int vbvaMousePointerShape (PVGASTATE pVGAState, VBVACONTEXT *pCtx, const VBVAMOUSEPOINTERSHAPE *pShape, HGSMISIZE cbShape)
    522 {
    523     bool fVisible = (pShape->fu32Flags & VBOX_MOUSE_POINTER_VISIBLE) != 0;
    524     bool fAlpha =   (pShape->fu32Flags & VBOX_MOUSE_POINTER_ALPHA) != 0;
    525     bool fShape =   (pShape->fu32Flags & VBOX_MOUSE_POINTER_SHAPE) != 0;
    526 
    527     HGSMISIZE cbPointerData = 0;
    528 
    529     if (fShape)
    530     {
    531          cbPointerData = ((((pShape->u32Width + 7) / 8) * pShape->u32Height + 3) & ~3)
    532                          + pShape->u32Width * 4 * pShape->u32Height;
    533     }
    534 
    535     if (cbPointerData > cbShape - RT_OFFSETOF(VBVAMOUSEPOINTERSHAPE, au8Data))
    536     {
    537         Log(("vbvaMousePointerShape: calculated pointer data size is too big (%d bytes, limit %d)\n",
    538               cbPointerData, cbShape - RT_OFFSETOF(VBVAMOUSEPOINTERSHAPE, au8Data)));
    539         return VERR_INVALID_PARAMETER;
    540     }
    541 
    542     if (pVGAState->pDrv->pfnVBVAMousePointerShape == NULL)
    543     {
    544         return VERR_NOT_SUPPORTED;
    545     }
    546 
     536#ifdef DEBUG_sunlover
     537void dumpMouseShapeInfo(const VBVAMOUSESHAPEINFO *pMouseShapeInfo)
     538{
     539    LogFlow(("fSet = %d, fVisible %d, fAlpha %d, @%d,%d %dx%d (%p, %d/%d)\n",
     540             pMouseShapeInfo->fSet,
     541             pMouseShapeInfo->fVisible,
     542             pMouseShapeInfo->fAlpha,
     543             pMouseShapeInfo->u32HotX,
     544             pMouseShapeInfo->u32HotY,
     545             pMouseShapeInfo->u32Width,
     546             pMouseShapeInfo->u32Height,
     547             pMouseShapeInfo->pu8Shape,
     548             pMouseShapeInfo->cbShape,
     549             pMouseShapeInfo->cbAllocated
     550             ));
     551}
     552#endif
     553
     554static int vbvaUpdateMousePointerShape(PVGASTATE pVGAState, VBVAMOUSESHAPEINFO *pMouseShapeInfo, bool fShape, const uint8_t *pu8Shape)
     555{
    547556    int rc;
    548 
    549     if (fShape)
     557    LogFlowFunc(("pVGAState %p, pMouseShapeInfo %p, fShape %d, pu8Shape %p\n",
     558                  pVGAState, pMouseShapeInfo, fShape, pu8Shape));
     559#ifdef DEBUG_sunlover
     560    dumpMouseShapeInfo(pMouseShapeInfo);
     561#endif
     562
     563    if (fShape && pu8Shape != NULL)
    550564    {
    551565        rc = pVGAState->pDrv->pfnVBVAMousePointerShape (pVGAState->pDrv,
    552                                                         fVisible,
    553                                                         fAlpha,
    554                                                         pShape->u32HotX, pShape->u32HotY,
    555                                                         pShape->u32Width, pShape->u32Height,
    556                                                         &pShape->au8Data[0]);
     566                                                        pMouseShapeInfo->fVisible,
     567                                                        pMouseShapeInfo->fAlpha,
     568                                                        pMouseShapeInfo->u32HotX,
     569                                                        pMouseShapeInfo->u32HotY,
     570                                                        pMouseShapeInfo->u32Width,
     571                                                        pMouseShapeInfo->u32Height,
     572                                                        pu8Shape);
    557573    }
    558574    else
    559575    {
    560576        rc = pVGAState->pDrv->pfnVBVAMousePointerShape (pVGAState->pDrv,
    561                                                         fVisible,
     577                                                        pMouseShapeInfo->fVisible,
    562578                                                        false,
    563579                                                        0, 0,
     
    565581                                                        NULL);
    566582    }
     583
     584    return rc;
     585}
     586
     587static int vbvaMousePointerShape (PVGASTATE pVGAState, VBVACONTEXT *pCtx, const VBVAMOUSEPOINTERSHAPE *pShape, HGSMISIZE cbShape)
     588{
     589    bool fVisible = (pShape->fu32Flags & VBOX_MOUSE_POINTER_VISIBLE) != 0;
     590    bool fAlpha =   (pShape->fu32Flags & VBOX_MOUSE_POINTER_ALPHA) != 0;
     591    bool fShape =   (pShape->fu32Flags & VBOX_MOUSE_POINTER_SHAPE) != 0;
     592
     593    HGSMISIZE cbPointerData = 0;
     594
     595    if (fShape)
     596    {
     597         cbPointerData = ((((pShape->u32Width + 7) / 8) * pShape->u32Height + 3) & ~3)
     598                         + pShape->u32Width * 4 * pShape->u32Height;
     599    }
     600
     601    if (cbPointerData > cbShape - RT_OFFSETOF(VBVAMOUSEPOINTERSHAPE, au8Data))
     602    {
     603        Log(("vbvaMousePointerShape: calculated pointer data size is too big (%d bytes, limit %d)\n",
     604              cbPointerData, cbShape - RT_OFFSETOF(VBVAMOUSEPOINTERSHAPE, au8Data)));
     605        return VERR_INVALID_PARAMETER;
     606    }
     607
     608    /* Save mouse info it will be used to restore mouse pointer after restoring saved state. */
     609    pCtx->mouseShapeInfo.fSet = true;
     610    pCtx->mouseShapeInfo.fVisible = fVisible;
     611    pCtx->mouseShapeInfo.fAlpha = fAlpha;
     612    pCtx->mouseShapeInfo.u32HotX = pShape->u32HotX;
     613    pCtx->mouseShapeInfo.u32HotY = pShape->u32HotY;
     614    pCtx->mouseShapeInfo.u32Width = pShape->u32Width;
     615    pCtx->mouseShapeInfo.u32Height = pShape->u32Height;
     616    if (fShape)
     617    {
     618        /* Reallocate memory buffer if necessary. */
     619        if (cbPointerData > pCtx->mouseShapeInfo.cbAllocated)
     620        {
     621            RTMemFree (pCtx->mouseShapeInfo.pu8Shape);
     622            pCtx->mouseShapeInfo.pu8Shape = NULL;
     623            pCtx->mouseShapeInfo.cbShape = 0;
     624
     625            uint8_t *pu8Shape = (uint8_t *)RTMemAlloc (cbPointerData);
     626            if (pu8Shape)
     627            {
     628                pCtx->mouseShapeInfo.pu8Shape = pu8Shape;
     629                pCtx->mouseShapeInfo.cbAllocated = cbPointerData;
     630            }
     631        }
     632
     633        /* Copy shape bitmaps. */
     634        if (pCtx->mouseShapeInfo.pu8Shape)
     635        {
     636            memcpy (pCtx->mouseShapeInfo.pu8Shape, &pShape->au8Data[0], cbPointerData);
     637            pCtx->mouseShapeInfo.cbShape = cbPointerData;
     638        }
     639    }
     640
     641    if (pVGAState->pDrv->pfnVBVAMousePointerShape == NULL)
     642    {
     643        return VERR_NOT_SUPPORTED;
     644    }
     645
     646    int rc = vbvaUpdateMousePointerShape(pVGAState, &pCtx->mouseShapeInfo, fShape, &pShape->au8Data[0]);
    567647
    568648    return rc;
     
    629709              pView->partialRecord.pu8));
    630710    }
     711
     712    dumpMouseShapeInfo(&pCtx->mouseShapeInfo);
    631713}
    632714#endif /* DEBUG_sunlover */
     
    705787                }
    706788            }
     789
     790            /* Save mouse pointer shape information. */
     791            rc = SSMR3PutBool (pSSM, pCtx->mouseShapeInfo.fSet);
     792            AssertRCReturn(rc, rc);
     793            rc = SSMR3PutBool (pSSM, pCtx->mouseShapeInfo.fVisible);
     794            AssertRCReturn(rc, rc);
     795            rc = SSMR3PutBool (pSSM, pCtx->mouseShapeInfo.fAlpha);
     796            AssertRCReturn(rc, rc);
     797            rc = SSMR3PutU32 (pSSM, pCtx->mouseShapeInfo.u32HotX);
     798            AssertRCReturn(rc, rc);
     799            rc = SSMR3PutU32 (pSSM, pCtx->mouseShapeInfo.u32HotY);
     800            AssertRCReturn(rc, rc);
     801            rc = SSMR3PutU32 (pSSM, pCtx->mouseShapeInfo.u32Width);
     802            AssertRCReturn(rc, rc);
     803            rc = SSMR3PutU32 (pSSM, pCtx->mouseShapeInfo.u32Height);
     804            AssertRCReturn(rc, rc);
     805            rc = SSMR3PutU32 (pSSM, pCtx->mouseShapeInfo.cbShape);
     806            AssertRCReturn(rc, rc);
     807            if (pCtx->mouseShapeInfo.cbShape)
     808            {
     809                rc = SSMR3PutMem (pSSM, pCtx->mouseShapeInfo.pu8Shape, pCtx->mouseShapeInfo.cbShape);
     810                AssertRCReturn(rc, rc);
     811            }
     812
     813            /* Size of some additional data. For future extensions. */
     814            rc = SSMR3PutU32 (pSSM, 0);
     815            AssertRCReturn(rc, rc);
    707816        }
    708817    }
     
    713822int vboxVBVALoadStateExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t u32Version)
    714823{
    715     if (u32Version < 3)
     824    if (u32Version < VGA_SAVEDSTATE_VERSION_HGSMI)
    716825    {
    717826        /* Nothing was saved. */
     
    810919            }
    811920
     921            if (u32Version > VGA_SAVEDSTATE_VERSION_WITH_CONFIG)
     922            {
     923                /* Read mouse pointer shape information. */
     924                rc = SSMR3GetBool (pSSM, &pCtx->mouseShapeInfo.fSet);
     925                AssertRCReturn(rc, rc);
     926                rc = SSMR3GetBool (pSSM, &pCtx->mouseShapeInfo.fVisible);
     927                AssertRCReturn(rc, rc);
     928                rc = SSMR3GetBool (pSSM, &pCtx->mouseShapeInfo.fAlpha);
     929                AssertRCReturn(rc, rc);
     930                rc = SSMR3GetU32 (pSSM, &pCtx->mouseShapeInfo.u32HotX);
     931                AssertRCReturn(rc, rc);
     932                rc = SSMR3GetU32 (pSSM, &pCtx->mouseShapeInfo.u32HotY);
     933                AssertRCReturn(rc, rc);
     934                rc = SSMR3GetU32 (pSSM, &pCtx->mouseShapeInfo.u32Width);
     935                AssertRCReturn(rc, rc);
     936                rc = SSMR3GetU32 (pSSM, &pCtx->mouseShapeInfo.u32Height);
     937                AssertRCReturn(rc, rc);
     938                rc = SSMR3GetU32 (pSSM, &pCtx->mouseShapeInfo.cbShape);
     939                AssertRCReturn(rc, rc);
     940                if (pCtx->mouseShapeInfo.cbShape)
     941                {
     942                    pCtx->mouseShapeInfo.pu8Shape = (uint8_t *)RTMemAlloc(pCtx->mouseShapeInfo.cbShape);
     943                    if (pCtx->mouseShapeInfo.pu8Shape == NULL)
     944                    {
     945                        return VERR_NO_MEMORY;
     946                    }
     947                    pCtx->mouseShapeInfo.cbAllocated = pCtx->mouseShapeInfo.cbShape;
     948                    rc = SSMR3GetMem (pSSM, pCtx->mouseShapeInfo.pu8Shape, pCtx->mouseShapeInfo.cbShape);
     949                    AssertRCReturn(rc, rc);
     950                }
     951                else
     952                {
     953                    pCtx->mouseShapeInfo.pu8Shape = NULL;
     954                }
     955
     956                /* Size of some additional data. For future extensions. */
     957                uint32_t cbExtra = 0;
     958                rc = SSMR3GetU32 (pSSM, &cbExtra);
     959                AssertRCReturn(rc, rc);
     960                if (cbExtra > 0)
     961                {
     962                    rc = SSMR3Skip(pSSM, cbExtra);
     963                    AssertRCReturn(rc, rc);
     964                }
     965            }
     966
    812967            pCtx->cViews = iView;
    813968            LogFlowFunc(("%d views loaded\n", pCtx->cViews));
     
    839994                vbvaResize (pVGAState, pView, &pView->screen);
    840995            }
     996        }
     997
     998        if (pCtx->mouseShapeInfo.fSet)
     999        {
     1000            vbvaUpdateMousePointerShape(pVGAState, &pCtx->mouseShapeInfo, true, pCtx->mouseShapeInfo.pu8Shape);
    8411001        }
    8421002    }
     
    14021562            vbvaDisable (uScreenId, pVGAState, pCtx);
    14031563        }
     1564
     1565        pCtx->mouseShapeInfo.fSet = false;
     1566        RTMemFree(pCtx->mouseShapeInfo.pu8Shape);
     1567        pCtx->mouseShapeInfo.pu8Shape = NULL;
     1568        pCtx->mouseShapeInfo.cbAllocated = 0;
     1569        pCtx->mouseShapeInfo.cbShape = 0;
    14041570    }
    14051571
     
    14671633void VBVADestroy (PVGASTATE pVGAState)
    14681634{
     1635    VBVACONTEXT *pCtx = (VBVACONTEXT *)HGSMIContext (pVGAState->pHGSMI);
     1636
     1637    if (pCtx)
     1638    {
     1639        pCtx->mouseShapeInfo.fSet = false;
     1640        RTMemFree(pCtx->mouseShapeInfo.pu8Shape);
     1641        pCtx->mouseShapeInfo.pu8Shape = NULL;
     1642        pCtx->mouseShapeInfo.cbAllocated = 0;
     1643        pCtx->mouseShapeInfo.cbShape = 0;
     1644    }
     1645
    14691646    HGSMIDestroy (pVGAState->pHGSMI);
    14701647    pVGAState->pHGSMI = NULL;
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