VirtualBox

Ignore:
Timestamp:
Oct 29, 2010 11:17:01 PM (14 years ago)
Author:
vboxsync
Message:

Additions/WINNT/Graphics: more refactoring

Location:
trunk/src/VBox/Additions/WINNT/Graphics/Miniport
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp

    r33532 r33628  
    15141514}
    15151515
    1516 void VBoxUnmapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension, void **ppv, ULONG ulSize)
     1516void VBoxUnmapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension, void **ppv)
    15171517{
    15181518    dprintf(("VBoxVideo::VBoxUnmapAdapterMemory\n"));
     
    16381638
    16391639#ifndef VBOX_WITH_WDDM
     1640static int vbvaInitInfoDisplay (void *pvData, VBVAINFOVIEW *p)
     1641{
     1642    PDEVICE_EXTENSION PrimaryExtension = (PDEVICE_EXTENSION) pvData;
     1643
     1644    int i;
     1645    PDEVICE_EXTENSION Extension;
     1646
     1647    for (i = 0, Extension = PrimaryExtension;
     1648         i < commonFromDeviceExt(PrimaryExtension)->cDisplays && Extension;
     1649         i++, Extension = Extension->pNext)
     1650    {
     1651        p[i].u32ViewIndex     = Extension->iDevice;
     1652        p[i].u32ViewOffset    = Extension->ulFrameBufferOffset;
     1653        p[i].u32ViewSize      = PrimaryExtension->u.primary.ulMaxFrameBufferSize;
     1654
     1655        /* How much VRAM should be reserved for the guest drivers to use VBVA. */
     1656        const uint32_t cbReservedVRAM = VBVA_DISPLAY_INFORMATION_SIZE + VBVA_MIN_BUFFER_SIZE;
     1657
     1658        p[i].u32MaxScreenSize = p[i].u32ViewSize > cbReservedVRAM?
     1659                                    p[i].u32ViewSize - cbReservedVRAM:
     1660                                    0;
     1661    }
     1662
     1663    if (i == commonFromDeviceExt(PrimaryExtension)->cDisplays && Extension == NULL)
     1664    {
     1665        return VINF_SUCCESS;
     1666    }
     1667
     1668    AssertFailed ();
     1669    return VERR_INTERNAL_ERROR;
     1670}
     1671
     1672
     1673static VOID VBoxCreateDisplaysXPDM(PDEVICE_EXTENSION PrimaryExtension,
     1674                                   PVIDEO_PORT_CONFIG_INFO pConfigInfo)
     1675{
     1676    VP_STATUS rc;
     1677
     1678    if (commonFromDeviceExt(PrimaryExtension)->bHGSMI)
     1679    {
     1680        typedef VP_STATUS (*PFNCREATESECONDARYDISPLAY)(PVOID, PVOID *, ULONG);
     1681        PFNCREATESECONDARYDISPLAY pfnCreateSecondaryDisplay = NULL;
     1682
     1683        /* Dynamically query the VideoPort import to be binary compatible across Windows versions */
     1684        if (vboxQueryWinVersion() > WINNT4)
     1685        {
     1686            /* This bluescreens on NT4, hence the above version check */
     1687            pfnCreateSecondaryDisplay = (PFNCREATESECONDARYDISPLAY)(pConfigInfo->VideoPortGetProcAddress)
     1688                                                                       (PrimaryExtension,
     1689                                                                        (PUCHAR)"VideoPortCreateSecondaryDisplay");
     1690        }
     1691
     1692        if (!pfnCreateSecondaryDisplay)
     1693            commonFromDeviceExt(PrimaryExtension)->cDisplays = 1;
     1694        else
     1695        {
     1696            PDEVICE_EXTENSION pPrev = PrimaryExtension;
     1697
     1698            ULONG iDisplay;
     1699            ULONG cDisplays = commonFromDeviceExt(PrimaryExtension)->cDisplays;
     1700            commonFromDeviceExt(PrimaryExtension)->cDisplays = 1;
     1701            for (iDisplay = 1; iDisplay < cDisplays; iDisplay++)
     1702            {
     1703               PDEVICE_EXTENSION SecondaryExtension = NULL;
     1704               rc = pfnCreateSecondaryDisplay (PrimaryExtension, (PVOID*)&SecondaryExtension, VIDEO_DUALVIEW_REMOVABLE);
     1705
     1706               dprintf(("VBoxVideo::VBoxSetupDisplays: VideoPortCreateSecondaryDisplay returned %#x, SecondaryExtension = %p\n",
     1707                        rc, SecondaryExtension));
     1708
     1709               if (rc != NO_ERROR)
     1710               {
     1711                   break;
     1712               }
     1713
     1714               SecondaryExtension->pNext                = NULL;
     1715               SecondaryExtension->pPrimary             = PrimaryExtension;
     1716               SecondaryExtension->iDevice              = iDisplay;
     1717               SecondaryExtension->ulFrameBufferOffset  = 0;
     1718               SecondaryExtension->ulFrameBufferSize    = 0;
     1719               SecondaryExtension->u.secondary.bEnabled = FALSE;
     1720
     1721               /* Update the list pointers. */
     1722               pPrev->pNext = SecondaryExtension;
     1723               pPrev = SecondaryExtension;
     1724
     1725               /* Take the successfully created display into account. */
     1726               commonFromDeviceExt(PrimaryExtension)->cDisplays++;
     1727            }
     1728        }
     1729
     1730        /* Failure to create secondary displays is not fatal */
     1731        rc = NO_ERROR;
     1732    }
     1733
     1734    /* Now when the number of monitors is known and extensions are created,
     1735     * calculate the layout of framebuffers.
     1736     */
     1737    VBoxComputeFrameBufferSizes (PrimaryExtension);
     1738    /* in case of WDDM we do not control the framebuffer location,
     1739     * i.e. it is assigned by Video Memory Manager,
     1740     * The FB information should be passed to guest from our
     1741     * DxgkDdiSetVidPnSourceAddress callback */
     1742
     1743    if (commonFromDeviceExt(PrimaryExtension)->bHGSMI)
     1744    {
     1745        if (RT_SUCCESS(rc))
     1746        {
     1747            rc = VBoxHGSMISendViewInfo (commonFromDeviceExt(PrimaryExtension),
     1748                                   commonFromDeviceExt(PrimaryExtension)->cDisplays,
     1749                                   vbvaInitInfoDisplay,
     1750                                   (void *) PrimaryExtension);
     1751            AssertRC(rc);
     1752        }
     1753
     1754        if (RT_FAILURE (rc))
     1755        {
     1756            commonFromDeviceExt(PrimaryExtension)->bHGSMI = FALSE;
     1757        }
     1758    }
     1759}
    16401760
    16411761VP_STATUS VBoxVideoFindAdapter(IN PVOID HwDeviceExtension,
     
    17541874       * with old guest additions.
    17551875       */
    1756       VBoxSetupDisplaysHGSMI((PDEVICE_EXTENSION)HwDeviceExtension, ConfigInfo, AdapterMemorySize, 0);
     1876      VBoxSetupDisplaysHGSMI((PDEVICE_EXTENSION)HwDeviceExtension, AdapterMemorySize, 0);
    17571877
    17581878      if (commonFromDeviceExt((PDEVICE_EXTENSION)HwDeviceExtension)->bHGSMI)
    17591879      {
    17601880          LogRel(("VBoxVideo: using HGSMI\n"));
     1881          VBoxCreateDisplaysXPDM((PDEVICE_EXTENSION)HwDeviceExtension, ConfigInfo);
    17611882      }
    17621883
     
    25702691    VbglTerminate ();
    25712692
    2572     VBoxUnmapAdapterMemory (pDevExt, &commonFromDeviceExt(pDevExt)->pvMiniportHeap, commonFromDeviceExt(pDevExt)->cbMiniportHeap);
    2573     VBoxUnmapAdapterInformation (pDevExt);
     2693    VBoxFreeDisplaysHGSMI(pDevExt);
     2694    /** @note using this callback instead of doing things manually adds an
     2695     *        additional call to HGSMIHeapDestroy().  I assume that call was
     2696     *        merely forgotton in the first place. */
    25742697
    25752698    return TRUE;
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.h

    r33532 r33628  
    808808
    809809void VBoxUnmapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension,
    810                              void **ppv, ULONG ulSize);
     810                             void **ppv);
    811811void VBoxUnmapAdapterInformation (PDEVICE_EXTENSION PrimaryExtension);
    812812
     
    845845
    846846VOID VBoxSetupDisplaysHGSMI (PDEVICE_EXTENSION PrimaryExtension,
    847 #ifndef VBOX_WITH_WDDM
    848                              PVIDEO_PORT_CONFIG_INFO pConfigInfo,
    849 #endif
    850847                             ULONG AdapterMemorySize, uint32_t fCaps);
    851848BOOLEAN vboxUpdatePointerShape (PDEVICE_EXTENSION DeviceExtension,
     
    853850                                uint32_t cbLength);
    854851
    855 #ifdef VBOX_WITH_WDDM
    856 int VBoxFreeDisplaysHGSMI(PDEVICE_EXTENSION PrimaryExtension);
    857 #else
     852void VBoxFreeDisplaysHGSMI(PDEVICE_EXTENSION PrimaryExtension);
     853#ifndef VBOX_WITH_WDDM
    858854DECLCALLBACK(void) hgsmiHostCmdComplete (HVBOXVIDEOHGSMI hHGSMI, struct _VBVAHOSTCMD * pCmd);
    859855DECLCALLBACK(int) hgsmiHostCmdRequest (HVBOXVIDEOHGSMI hHGSMI, uint8_t u8Channel, struct _VBVAHOSTCMD ** ppCmd);
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideoHGSMI.cpp

    r33540 r33628  
    288288}
    289289
    290 #ifndef VBOX_WITH_WDDM
    291 static int vbvaInitInfoDisplay (void *pvData, VBVAINFOVIEW *p)
    292 {
    293     PDEVICE_EXTENSION PrimaryExtension = (PDEVICE_EXTENSION) pvData;
    294 
    295     int i;
    296     PDEVICE_EXTENSION Extension;
    297 
    298     for (i = 0, Extension = PrimaryExtension;
    299          i < commonFromDeviceExt(PrimaryExtension)->cDisplays && Extension;
    300          i++, Extension = Extension->pNext)
    301     {
    302         p[i].u32ViewIndex     = Extension->iDevice;
    303         p[i].u32ViewOffset    = Extension->ulFrameBufferOffset;
    304         p[i].u32ViewSize      = PrimaryExtension->u.primary.ulMaxFrameBufferSize;
    305 
    306         /* How much VRAM should be reserved for the guest drivers to use VBVA. */
    307         const uint32_t cbReservedVRAM = VBVA_DISPLAY_INFORMATION_SIZE + VBVA_MIN_BUFFER_SIZE;
    308 
    309         p[i].u32MaxScreenSize = p[i].u32ViewSize > cbReservedVRAM?
    310                                     p[i].u32ViewSize - cbReservedVRAM:
    311                                     0;
    312     }
    313 
    314     if (i == commonFromDeviceExt(PrimaryExtension)->cDisplays && Extension == NULL)
    315     {
    316         return VINF_SUCCESS;
    317     }
    318 
    319     AssertFailed ();
    320     return VERR_INTERNAL_ERROR;
    321 }
    322 #endif
     290
    323291int vbvaInitInfoCaps (PVBOXVIDEO_COMMON pCommon, void *pvContext, void *pvData)
    324292{
     
    414382 */
    415383VOID VBoxSetupDisplaysHGSMI(PDEVICE_EXTENSION PrimaryExtension,
    416 #ifndef VBOX_WITH_WDDM
    417         PVIDEO_PORT_CONFIG_INFO pConfigInfo,
    418 #endif
    419         ULONG AdapterMemorySize, uint32_t fCaps)
     384                            ULONG AdapterMemorySize, uint32_t fCaps)
    420385{
    421386    VP_STATUS rc = NO_ERROR;
     
    574539    }
    575540
    576 #ifndef VBOX_WITH_WDDM
     541#ifdef VBOX_WITH_WDDM
    577542    /* For WDDM, we simply store the number of monitors as we will deal with
    578543     * VidPN stuff later */
    579     if (commonFromDeviceExt(PrimaryExtension)->bHGSMI)
    580     {
    581         typedef VP_STATUS (*PFNCREATESECONDARYDISPLAY)(PVOID, PVOID *, ULONG);
    582         PFNCREATESECONDARYDISPLAY pfnCreateSecondaryDisplay = NULL;
    583 
    584         /* Dynamically query the VideoPort import to be binary compatible across Windows versions */
    585         if (vboxQueryWinVersion() > WINNT4)
    586         {
    587             /* This bluescreens on NT4, hence the above version check */
    588             pfnCreateSecondaryDisplay = (PFNCREATESECONDARYDISPLAY)(pConfigInfo->VideoPortGetProcAddress)
    589                                                                        (PrimaryExtension,
    590                                                                         (PUCHAR)"VideoPortCreateSecondaryDisplay");
    591         }
    592 
    593         if (!pfnCreateSecondaryDisplay)
    594             commonFromDeviceExt(PrimaryExtension)->cDisplays = 1;
    595         else
    596         {
    597             PDEVICE_EXTENSION pPrev = PrimaryExtension;
    598 
    599             ULONG iDisplay;
    600             ULONG cDisplays = commonFromDeviceExt(PrimaryExtension)->cDisplays;
    601             commonFromDeviceExt(PrimaryExtension)->cDisplays = 1;
    602             for (iDisplay = 1; iDisplay < cDisplays; iDisplay++)
    603             {
    604                PDEVICE_EXTENSION SecondaryExtension = NULL;
    605                rc = pfnCreateSecondaryDisplay (PrimaryExtension, (PVOID*)&SecondaryExtension, VIDEO_DUALVIEW_REMOVABLE);
    606 
    607                dprintf(("VBoxVideo::VBoxSetupDisplays: VideoPortCreateSecondaryDisplay returned %#x, SecondaryExtension = %p\n",
    608                         rc, SecondaryExtension));
    609 
    610                if (rc != NO_ERROR)
    611                {
    612                    break;
    613                }
    614 
    615                SecondaryExtension->pNext                = NULL;
    616                SecondaryExtension->pPrimary             = PrimaryExtension;
    617                SecondaryExtension->iDevice              = iDisplay;
    618                SecondaryExtension->ulFrameBufferOffset  = 0;
    619                SecondaryExtension->ulFrameBufferSize    = 0;
    620                SecondaryExtension->u.secondary.bEnabled = FALSE;
    621 
    622                /* Update the list pointers. */
    623                pPrev->pNext = SecondaryExtension;
    624                pPrev = SecondaryExtension;
    625 
    626                /* Take the successfully created display into account. */
    627                commonFromDeviceExt(PrimaryExtension)->cDisplays++;
    628             }
    629         }
    630 
    631         /* Failure to create secondary displays is not fatal */
    632         rc = NO_ERROR;
    633     }
    634 
    635     /* Now when the number of monitors is known and extensions are created,
    636      * calculate the layout of framebuffers.
    637      */
    638     VBoxComputeFrameBufferSizes (PrimaryExtension);
    639     /* in case of WDDM we do not control the framebuffer location,
    640      * i.e. it is assigned by Video Memory Manager,
    641      * The FB information should be passed to guest from our
    642      * DxgkDdiSetVidPnSourceAddress callback */
    643 
    644     if (commonFromDeviceExt(PrimaryExtension)->bHGSMI)
    645     {
    646         if (RT_SUCCESS(rc))
    647         {
    648             rc = VBoxHGSMISendViewInfo (commonFromDeviceExt(PrimaryExtension),
    649                                    commonFromDeviceExt(PrimaryExtension)->cDisplays,
    650                                    vbvaInitInfoDisplay,
    651                                    (void *) PrimaryExtension);
    652             AssertRC(rc);
    653         }
    654 
    655         if (RT_FAILURE (rc))
    656         {
    657             commonFromDeviceExt(PrimaryExtension)->bHGSMI = FALSE;
    658         }
    659     }
    660 #endif
    661 
    662 #ifdef VBOX_WITH_WDDM
    663544    if (commonFromDeviceExt(PrimaryExtension)->bHGSMI)
    664545    {
     
    766647
    767648    if (!commonFromDeviceExt(PrimaryExtension)->bHGSMI)
    768     {
    769         /* Unmap the memory if VBoxVideo is not supported. */
    770         VBoxUnmapAdapterMemory (PrimaryExtension, &commonFromDeviceExt(PrimaryExtension)->pvMiniportHeap, commonFromDeviceExt(PrimaryExtension)->cbMiniportHeap);
    771         VBoxUnmapAdapterInformation (PrimaryExtension);
    772 
    773         HGSMIHeapDestroy (&commonFromDeviceExt(PrimaryExtension)->hgsmiAdapterHeap);
    774     }
     649        VBoxFreeDisplaysHGSMI(PrimaryExtension);
    775650
    776651    dprintf(("VBoxVideo::VBoxSetupDisplays: finished\n"));
    777652}
    778653
    779 #ifdef VBOX_WITH_WDDM
    780 int VBoxFreeDisplaysHGSMI(PDEVICE_EXTENSION PrimaryExtension)
    781 {
    782     int rc = VINF_SUCCESS;
    783 
    784     Assert(PrimaryExtension->pvVisibleVram);
    785     if (PrimaryExtension->pvVisibleVram)
    786         VBoxUnmapAdapterMemory(PrimaryExtension, (void**)&PrimaryExtension->pvVisibleVram, vboxWddmVramCpuVisibleSize(PrimaryExtension));
    787 
    788     for (int i = commonFromDeviceExt(PrimaryExtension)->cDisplays-1; i >= 0; --i)
    789     {
    790         rc = vboxVbvaDisable(PrimaryExtension, &PrimaryExtension->aSources[i].Vbva);
    791         AssertRC(rc);
    792         if (RT_SUCCESS(rc))
    793         {
    794             rc = vboxVbvaDestroy(PrimaryExtension, &PrimaryExtension->aSources[i].Vbva);
    795             AssertRC(rc);
    796             if (RT_FAILURE(rc))
    797             {
    798                 /* @todo: */
    799             }
    800         }
    801     }
    802 
    803     vboxVideoAMgrDestroy(PrimaryExtension, &PrimaryExtension->AllocMgr);
    804 
    805     rc = vboxVdmaDisable(PrimaryExtension, &PrimaryExtension->u.primary.Vdma);
    806     AssertRC(rc);
    807     if (RT_SUCCESS(rc))
    808     {
    809         rc = vboxVdmaDestroy(PrimaryExtension, &PrimaryExtension->u.primary.Vdma);
    810         AssertRC(rc);
    811         if (RT_SUCCESS(rc))
    812         {
    813             /*rc = */VBoxUnmapAdapterMemory(PrimaryExtension, &commonFromDeviceExt(PrimaryExtension)->pvMiniportHeap, commonFromDeviceExt(PrimaryExtension)->cbMiniportHeap);
    814 /*
    815             AssertRC(rc);
    816             if (RT_SUCCESS(rc))
    817 */
    818             {
    819                 HGSMIHeapDestroy(&commonFromDeviceExt(PrimaryExtension)->hgsmiAdapterHeap);
    820 
    821                 /* Map the adapter information. It will be needed for HGSMI IO. */
    822                 /*rc = */VBoxUnmapAdapterInformation(PrimaryExtension);
    823 /*
    824                 AssertRC(rc);
    825                 if (RT_FAILURE(rc))
    826                     drprintf((__FUNCTION__"VBoxUnmapAdapterMemory PrimaryExtension->u.primary.pvAdapterInformation failed, rc(%d)\n", rc));
    827 */
    828 
    829             }
    830         }
    831     }
    832 
    833     return rc;
    834 }
    835 #endif
     654void VBoxFreeDisplaysHGSMI(PDEVICE_EXTENSION PrimaryExtension)
     655{
     656    VBoxUnmapAdapterMemory(PrimaryExtension, &commonFromDeviceExt(PrimaryExtension)->pvMiniportHeap);
     657    HGSMIHeapDestroy(&commonFromDeviceExt(PrimaryExtension)->hgsmiAdapterHeap);
     658
     659    /* Unmap the adapter information needed for HGSMI IO. */
     660    VBoxUnmapAdapterInformation(PrimaryExtension);
     661}
    836662
    837663/*
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVbva.cpp

    r33226 r33628  
    125125{
    126126    int rc = VINF_SUCCESS;
    127     /*rc = */VBoxUnmapAdapterMemory(pDevExt, (void**)&pVbva->pVBVA, pVbva->cbVBVA);
    128 /*
    129     AssertRC(rc);
    130     if (RT_SUCCESS(rc))
    131 */
    132         memset(pVbva, 0, sizeof(VBOXVBVAINFO));
    133 /*
    134     else
    135         drprintf((__FUNCTION__": VBoxUnmapAdapterMemory failed, rc (%d)\n", rc));
    136 */
     127    VBoxUnmapAdapterMemory(pDevExt, (void**)&pVbva->pVBVA);
     128    memset(pVbva, 0, sizeof(VBOXVBVAINFO));
    137129    return rc;
    138130}
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVdma.cpp

    r33530 r33628  
    11161116            drprintf((__FUNCTION__": HGSMIHeapSetup failed rc = 0x%x\n", rc));
    11171117
    1118         VBoxUnmapAdapterMemory(pDevExt, &pvBuffer, cbBuffer);
     1118        VBoxUnmapAdapterMemory(pDevExt, &pvBuffer);
    11191119    }
    11201120    else
     
    11891189            rc = vboxVdmaDisable (pDevExt, pInfo);
    11901190#ifdef VBOX_WITH_VDMA
    1191         VBoxUnmapAdapterMemory (pDevExt, (void**)&pInfo->CmdHeap.area.pu8Base, pInfo->CmdHeap.area.cbArea);
     1191        VBoxUnmapAdapterMemory (pDevExt, (void**)&pInfo->CmdHeap.area.pu8Base);
    11921192#endif
    11931193    }
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp

    r33540 r33628  
    493493}
    494494
     495static void vboxWddmSetupDisplays(PDEVICE_EXTENSION pDevExt)
     496{
     497    /* For WDDM, we simply store the number of monitors as we will deal with
     498     * VidPN stuff later */
     499    int rc = STATUS_SUCCESS;
     500
     501    if (commonFromDeviceExt(pDevExt)->bHGSMI)
     502    {
     503        ULONG ulAvailable = commonFromDeviceExt(pDevExt)->cbVRAM
     504                            - commonFromDeviceExt(pDevExt)->cbMiniportHeap
     505                            - VBVA_ADAPTER_INFORMATION_SIZE;
     506
     507        ULONG ulSize;
     508        ULONG offset;
     509#ifdef VBOX_WITH_VDMA
     510        ulSize = ulAvailable / 2;
     511        if (ulSize > VBOXWDDM_C_VDMA_BUFFER_SIZE)
     512            ulSize = VBOXWDDM_C_VDMA_BUFFER_SIZE;
     513
     514        /* Align down to 4096 bytes. */
     515        ulSize &= ~0xFFF;
     516        offset = ulAvailable - ulSize;
     517
     518        Assert(!(offset & 0xFFF));
     519#else
     520        offset = ulAvailable;
     521#endif
     522        rc = vboxVdmaCreate (pDevExt, &pDevExt->u.primary.Vdma
     523#ifdef VBOX_WITH_VDMA
     524                , offset, ulSize
     525#endif
     526                );
     527        AssertRC(rc);
     528        if (RT_SUCCESS(rc))
     529        {
     530            /* can enable it right away since the host does not need any screen/FB info
     531             * for basic DMA functionality */
     532            rc = vboxVdmaEnable(pDevExt, &pDevExt->u.primary.Vdma);
     533            AssertRC(rc);
     534            if (RT_FAILURE(rc))
     535                vboxVdmaDestroy(pDevExt, &pDevExt->u.primary.Vdma);
     536        }
     537
     538        ulAvailable = offset;
     539        ulSize = ulAvailable/2;
     540        offset = ulAvailable - ulSize;
     541
     542        NTSTATUS Status = vboxVideoAMgrCreate(pDevExt, &pDevExt->AllocMgr, offset, ulSize);
     543        Assert(Status == STATUS_SUCCESS);
     544        if (Status != STATUS_SUCCESS)
     545        {
     546            offset = ulAvailable;
     547        }
     548
     549#ifdef VBOXWDDM_RENDER_FROM_SHADOW
     550        if (RT_SUCCESS(rc))
     551        {
     552            ulAvailable = offset;
     553            ulSize = ulAvailable / 2;
     554            ulSize /= commonFromDeviceExt(pDevExt)->cDisplays;
     555            Assert(ulSize > VBVA_MIN_BUFFER_SIZE);
     556            if (ulSize > VBVA_MIN_BUFFER_SIZE)
     557            {
     558                ULONG ulRatio = ulSize/VBVA_MIN_BUFFER_SIZE;
     559                ulRatio >>= 4; /* /= 16; */
     560                if (ulRatio)
     561                    ulSize = VBVA_MIN_BUFFER_SIZE * ulRatio;
     562                else
     563                    ulSize = VBVA_MIN_BUFFER_SIZE;
     564            }
     565            else
     566            {
     567                /* todo: ?? */
     568            }
     569
     570            ulSize &= ~0xFFF;
     571            Assert(ulSize);
     572
     573            Assert(ulSize * commonFromDeviceExt(pDevExt)->cDisplays < ulAvailable);
     574
     575            for (int i = commonFromDeviceExt(pDevExt)->cDisplays-1; i >= 0; --i)
     576            {
     577                offset -= ulSize;
     578                rc = vboxVbvaCreate(pDevExt, &pDevExt->aSources[i].Vbva, offset, ulSize, i);
     579                AssertRC(rc);
     580                if (RT_SUCCESS(rc))
     581                {
     582                    rc = vboxVbvaEnable(pDevExt, &pDevExt->aSources[i].Vbva);
     583                    AssertRC(rc);
     584                    if (RT_FAILURE(rc))
     585                    {
     586                        /* @todo: de-initialize */
     587                    }
     588                }
     589            }
     590        }
     591#endif
     592
     593        rc = VBoxMapAdapterMemory(commonFromDeviceExt(pDevExt), (void**)&pDevExt->pvVisibleVram,
     594                                       0,
     595                                       vboxWddmVramCpuVisibleSize(pDevExt));
     596        Assert(rc == VINF_SUCCESS);
     597        if (rc != VINF_SUCCESS)
     598            pDevExt->pvVisibleVram = NULL;
     599
     600        if (RT_FAILURE(rc))
     601            commonFromDeviceExt(pDevExt)->bHGSMI = FALSE;
     602    }
     603}
     604
     605static int vboxWddmFreeDisplays(PDEVICE_EXTENSION pDevExt)
     606{
     607    int rc = VINF_SUCCESS;
     608
     609    Assert(pDevExt->pvVisibleVram);
     610    if (pDevExt->pvVisibleVram)
     611        VBoxUnmapAdapterMemory(pDevExt, (void**)&pDevExt->pvVisibleVram);
     612
     613    for (int i = commonFromDeviceExt(pDevExt)->cDisplays-1; i >= 0; --i)
     614    {
     615        rc = vboxVbvaDisable(pDevExt, &pDevExt->aSources[i].Vbva);
     616        AssertRC(rc);
     617        if (RT_SUCCESS(rc))
     618        {
     619            rc = vboxVbvaDestroy(pDevExt, &pDevExt->aSources[i].Vbva);
     620            AssertRC(rc);
     621            if (RT_FAILURE(rc))
     622            {
     623                /* @todo: */
     624            }
     625        }
     626    }
     627
     628    vboxVideoAMgrDestroy(pDevExt, &pDevExt->AllocMgr);
     629
     630    rc = vboxVdmaDisable(pDevExt, &pDevExt->u.primary.Vdma);
     631    AssertRC(rc);
     632    if (RT_SUCCESS(rc))
     633    {
     634        rc = vboxVdmaDestroy(pDevExt, &pDevExt->u.primary.Vdma);
     635        AssertRC(rc);
     636    }
     637    return rc;
     638}
     639
    495640/* driver callbacks */
    496641NTSTATUS DxgkDdiAddDevice(
     
    584729                VbglInit ();
    585730
    586                 /* Guest supports only HGSMI, the old VBVA via VMMDev is not supported. Old
    587                  * code will be ifdef'ed and later removed.
     731                /* Guest supports only HGSMI, the old VBVA via VMMDev is not supported.
    588732                 * The host will however support both old and new interface to keep compatibility
    589733                 * with old guest additions.
     
    593737                if (commonFromDeviceExt(pContext)->bHGSMI)
    594738                {
     739                    vboxWddmSetupDisplays(pContext);
     740                    if (!commonFromDeviceExt(pContext)->bHGSMI)
     741                        VBoxFreeDisplaysHGSMI(pContext);
     742                }
     743                if (commonFromDeviceExt(pContext)->bHGSMI)
     744                {
    595745                    drprintf(("VBoxVideoWddm: using HGSMI\n"));
    596746                    *NumberOfVideoPresentSources = commonFromDeviceExt(pContext)->cDisplays;
     
    661811#endif
    662812
    663     int rc = VBoxFreeDisplaysHGSMI(pDevExt);
     813    int rc = vboxWddmFreeDisplays(pDevExt);
     814    if (RT_SUCCESS(rc))
     815        VBoxFreeDisplaysHGSMI(pDevExt);
    664816    AssertRC(rc);
    665817    if (RT_SUCCESS(rc))
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