VirtualBox

Changeset 55367 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Apr 22, 2015 10:21:01 AM (10 years ago)
Author:
vboxsync
Message:

Additions/x11/vboxvideo: clean up vbva code.

Location:
trunk/src/VBox/Additions/x11/vboxvideo
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.c

    r55358 r55367  
    12721272#endif
    12731273
    1274     vbox_open (pScrn, pScreen, pVBox);
     1274    if (!VBoxHGSMIIsSupported())
     1275    {
     1276        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Graphics device too old to support.\n");
     1277        return FALSE;
     1278    }
     1279    vbvxSetUpHGSMIHeapInGuest(pVBox, pScrn->videoRam * 1024);
     1280    pVBox->cScreens = VBoxHGSMIGetMonitorCount(&pVBox->guestCtx);
     1281    pVBox->pScreens = xnfcalloc(pVBox->cScreens, sizeof(*pVBox->pScreens));
     1282    pVBox->paVBVAModeHints = xnfcalloc(pVBox->cScreens, sizeof(*pVBox->paVBVAModeHints));
     1283    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Requested monitor count: %u\n", pVBox->cScreens);
    12751284    vboxEnableVbva(pScrn);
    12761285    /* Set up the dirty rectangle handler.  It will be added into a function
  • trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.h

    r55358 r55367  
    283283
    284284extern Bool vbox_cursor_init (ScreenPtr pScreen);
    285 extern void vbox_open (ScrnInfoPtr pScrn, ScreenPtr pScreen, VBOXPtr pVBox);
    286285extern void vbox_close (ScrnInfoPtr pScrn, VBOXPtr pVBox);
    287286
    288287/* vbva.c */
    289288extern void vbvxHandleDirtyRect(ScrnInfoPtr pScrn, int iRects, BoxPtr aRects);
     289extern void vbvxSetUpHGSMIHeapInGuest(VBOXPtr pVBox, uint32_t cbVRAM);
    290290extern Bool vboxEnableVbva(ScrnInfoPtr pScrn);
    291291extern void vboxDisableVbva(ScrnInfoPtr pScrn);
  • trunk/src/VBox/Additions/x11/vboxvideo/vbva.c

    r55358 r55367  
    9999}
    100100
     101static DECLCALLBACK(void *) hgsmiEnvAlloc(void *pvEnv, HGSMISIZE cb)
     102{
     103    NOREF(pvEnv);
     104    return calloc(1, cb);
     105}
     106
     107static DECLCALLBACK(void) hgsmiEnvFree(void *pvEnv, void *pv)
     108{
     109    NOREF(pvEnv);
     110    free(pv);
     111}
     112
     113static HGSMIENV g_hgsmiEnv =
     114{
     115    NULL,
     116    hgsmiEnvAlloc,
     117    hgsmiEnvFree
     118};
     119
     120/**
     121 * Calculate the location in video RAM of and initialise the heap for guest to
     122 * host messages.  In the VirtualBox 4.3 and earlier Guest Additions this
     123 * function creates the heap structures directly in guest video RAM, so it
     124 * needs to be called whenever video RAM is (re-)set-up.
     125 */
     126void vbvxSetUpHGSMIHeapInGuest(VBOXPtr pVBox, uint32_t cbVRAM)
     127{
     128    int rc;
     129    uint32_t offVRAMBaseMapping, offGuestHeapMemory, cbGuestHeapMemory;
     130    void *pvGuestHeapMemory;
     131
     132    VBoxHGSMIGetBaseMappingInfo(cbVRAM, &offVRAMBaseMapping, NULL, &offGuestHeapMemory, &cbGuestHeapMemory, NULL);
     133    pvGuestHeapMemory = ((uint8_t *)pVBox->base) + offVRAMBaseMapping + offGuestHeapMemory;
     134    rc = VBoxHGSMISetupGuestContext(&pVBox->guestCtx, pvGuestHeapMemory, cbGuestHeapMemory,
     135                                    offVRAMBaseMapping + offGuestHeapMemory, &g_hgsmiEnv);
     136    VBVXASSERT(RT_SUCCESS(rc), ("Failed to set up the guest-to-host message buffer heap, rc=%d\n", rc));
     137    pVBox->cbView = offVRAMBaseMapping;
     138}
     139
    101140/** Callback to fill in the view structures */
    102141static int
     
    120159 * @returns TRUE on success, FALSE on failure
    121160 */
    122 static Bool
    123 vboxInitVbva(int scrnIndex, ScreenPtr pScreen, VBOXPtr pVBox)
    124 {
    125     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     161static Bool vboxSetupVRAMVbva(VBOXPtr pVBox)
     162{
    126163    int rc = VINF_SUCCESS;
    127 
    128     /* Why is this here?  In case things break before we have found the real
    129      * count? */
    130     pVBox->cScreens = 1;
    131     if (!VBoxHGSMIIsSupported())
    132     {
    133         xf86DrvMsg(scrnIndex, X_ERROR, "The graphics device does not seem to support HGSMI.  Disableing video acceleration.\n");
    134         return FALSE;
    135     }
    136     return TRUE;
    137 }
    138 
    139 static DECLCALLBACK(void *) hgsmiEnvAlloc(void *pvEnv, HGSMISIZE cb)
    140 {
    141     NOREF(pvEnv);
    142     return calloc(1, cb);
    143 }
    144 
    145 static DECLCALLBACK(void) hgsmiEnvFree(void *pvEnv, void *pv)
    146 {
    147     NOREF(pvEnv);
    148     free(pv);
    149 }
    150 
    151 static HGSMIENV g_hgsmiEnv =
    152 {
    153     NULL,
    154     hgsmiEnvAlloc,
    155     hgsmiEnvFree
    156 };
    157 
    158 /**
    159  * Initialise VirtualBox's accelerated video extensions.
    160  *
    161  * @returns TRUE on success, FALSE on failure
    162  */
    163 static Bool
    164 vboxSetupVRAMVbva(ScrnInfoPtr pScrn, VBOXPtr pVBox)
    165 {
    166     int rc = VINF_SUCCESS;
    167     unsigned i;
    168     uint32_t offVRAMBaseMapping, offGuestHeapMemory, cbGuestHeapMemory;
    169     void *pvGuestHeapMemory;
    170 
    171     VBoxHGSMIGetBaseMappingInfo(pScrn->videoRam * 1024, &offVRAMBaseMapping,
    172                                 NULL, &offGuestHeapMemory, &cbGuestHeapMemory,
    173                                 NULL);
    174     pvGuestHeapMemory =   ((uint8_t *)pVBox->base) + offVRAMBaseMapping
    175                         + offGuestHeapMemory;
    176     TRACE_LOG("video RAM: %u KB, guest heap offset: 0x%x, cbGuestHeapMemory: %u\n",
    177               pScrn->videoRam, offVRAMBaseMapping + offGuestHeapMemory,
    178               cbGuestHeapMemory);
    179     rc = VBoxHGSMISetupGuestContext(&pVBox->guestCtx, pvGuestHeapMemory,
    180                                     cbGuestHeapMemory,
    181                                     offVRAMBaseMapping + offGuestHeapMemory,
    182                                     &g_hgsmiEnv);
    183     if (RT_FAILURE(rc))
    184     {
    185         xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed to set up the guest-to-host communication context, rc=%d\n", rc);
    186         return FALSE;
    187     }
    188     pVBox->cbView = pVBox->cbFBMax = offVRAMBaseMapping;
    189     pVBox->cScreens = VBoxHGSMIGetMonitorCount(&pVBox->guestCtx);
    190     pVBox->pScreens = calloc(pVBox->cScreens, sizeof(*pVBox->pScreens));
    191     if (pVBox->pScreens == NULL)
    192         FatalError("Failed to allocate memory for screens array.\n");
    193 #ifdef VBOXVIDEO_13
    194     pVBox->paVBVAModeHints = calloc(pVBox->cScreens,
    195                                     sizeof(*pVBox->paVBVAModeHints));
    196     if (pVBox->paVBVAModeHints == NULL)
    197         FatalError("Failed to allocate memory for mode hints array.\n");
    198 #endif
    199     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Requested monitor count: %u\n",
    200                pVBox->cScreens);
     164    unsigned i;
     165
     166    pVBox->cbFBMax = pVBox->cbView;
    201167    for (i = 0; i < pVBox->cScreens; ++i)
    202168    {
     
    214180    rc = VBoxHGSMISendViewInfo(&pVBox->guestCtx, pVBox->cScreens,
    215181                               vboxFillViewInfo, (void *)pVBox);
    216     if (RT_FAILURE(rc))
    217     {
    218         xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed to send the view information to the host, rc=%d\n", rc);
    219         return FALSE;
    220     }
     182    VBVXASSERT(RT_SUCCESS(rc), ("Failed to send the view information to the host, rc=%d\n", rc));
    221183    return TRUE;
    222 }
    223 
    224 void
    225 vbox_open(ScrnInfoPtr pScrn, ScreenPtr pScreen, VBOXPtr pVBox)
    226 {
    227     TRACE_ENTRY();
    228 
    229     if (!vboxInitVbva(pScrn->scrnIndex, pScreen, pVBox))
    230         FatalError("failed to initialise vboxvideo graphics acceleration.\n");
    231184}
    232185
     
    242195{
    243196    bool rc = TRUE;
    244     int scrnIndex = pScrn->scrnIndex;
    245197    unsigned i;
    246198    VBOXPtr pVBox = pScrn->driverPrivate;
    247199
    248200    TRACE_ENTRY();
    249     if (!vboxSetupVRAMVbva(pScrn, pVBox))
     201    if (!vboxSetupVRAMVbva(pVBox))
    250202        return FALSE;
    251203    for (i = 0; i < pVBox->cScreens; ++i)
     
    259211            rc = FALSE;
    260212    }
    261     if (!rc)
    262     {
    263         /* Request not accepted - disable for old hosts. */
    264         xf86DrvMsg(scrnIndex, X_ERROR,
    265                    "Failed to enable screen update reporting for at least one virtual monitor.\n");
    266          vboxDisableVbva(pScrn);
    267     }
     213    VBVXASSERT(rc, ("Failed to enable screen update reporting for at least one virtual monitor.\n"));
    268214#ifdef VBOXVIDEO_13
    269215# ifdef RT_OS_LINUX
     
    289235{
    290236    int rc;
    291     int scrnIndex = pScrn->scrnIndex;
    292237    unsigned i;
    293238    VBOXPtr pVBox = pScrn->driverPrivate;
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