VirtualBox

Ignore:
Timestamp:
Nov 15, 2010 5:17:53 PM (14 years ago)
Author:
vboxsync
Message:

Additions/WINNT/Graphics: more refactoring

Location:
trunk/src/VBox/Additions/WINNT/Graphics/Miniport
Files:
14 edited
1 copied

Legend:

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

    r33540 r34079  
    2222}
    2323#else
    24 # include "VBoxVideo.h"
     24# include "VBoxVideo-win.h"
    2525#endif
    2626
     
    6565#pragma alloc_text(PAGE, vboxQueryWinVersion)
    6666
    67 BOOLEAN vboxQueryDisplayRequest(uint32_t *xres, uint32_t *yres, uint32_t *bpp, uint32_t *pDisplayId)
    68 {
    69     BOOLEAN bRC = FALSE;
     67bool vboxQueryDisplayRequest(uint32_t *xres, uint32_t *yres, uint32_t *bpp, uint32_t *pDisplayId)
     68{
     69    bool bRC = FALSE;
    7070
    7171    dprintf(("VBoxVideo::vboxQueryDisplayRequest: xres = 0x%p, yres = 0x%p bpp = 0x%p\n", xres, yres, bpp));
     
    111111}
    112112
    113 BOOLEAN vboxLikesVideoMode(uint32_t display, uint32_t width, uint32_t height, uint32_t bpp)
    114 {
    115     BOOLEAN bRC = FALSE;
     113bool vboxLikesVideoMode(uint32_t display, uint32_t width, uint32_t height, uint32_t bpp)
     114{
     115    bool bRC = FALSE;
    116116
    117117    VMMDevVideoModeSupportedRequest2 *req2 = NULL;
     
    171171}
    172172
    173 ULONG vboxGetHeightReduction()
    174 {
    175     ULONG retHeight = 0;
     173uint32_t vboxGetHeightReduction()
     174{
     175    uint32_t retHeight = 0;
    176176
    177177    dprintf(("VBoxVideo::vboxGetHeightReduction\n"));
     
    189189        if (RT_SUCCESS(rc))
    190190        {
    191             retHeight = (ULONG)req->heightReduction;
     191            retHeight = req->heightReduction;
    192192        }
    193193        else
     
    203203}
    204204
    205 static BOOLEAN vboxQueryPointerPosInternal (uint16_t *pointerXPos, uint16_t *pointerYPos)
    206 {
    207     BOOLEAN bRC = FALSE;
     205static bool vboxQueryPointerPosInternal (uint16_t *pointerXPos, uint16_t *pointerYPos)
     206{
     207    bool bRC = FALSE;
    208208
    209209    /* Activate next line only when really needed; floods the log very quickly! */
     
    255255 * (between 0 and 0xFFFF).
    256256 *
    257  * @returns BOOLEAN     success indicator
     257 * @returns bool        success indicator
    258258 * @param   pointerXPos address of result variable for x pos
    259259 * @param   pointerYPos address of result variable for y pos
    260260 */
    261 BOOLEAN vboxQueryPointerPos(uint16_t *pointerXPos, uint16_t *pointerYPos)
     261bool vboxQueryPointerPos(uint16_t *pointerXPos, uint16_t *pointerYPos)
    262262{
    263263    if (!pointerXPos || !pointerYPos)
     
    272272 * Returns whether the host wants us to take absolute coordinates.
    273273 *
    274  * @returns BOOLEAN TRUE if the host wants to send absolute coordinates.
     274 * @returns bool TRUE if the host wants to send absolute coordinates.
    275275 */
    276 BOOLEAN vboxQueryHostWantsAbsolute (void)
     276bool vboxQueryHostWantsAbsolute (void)
    277277{
    278278    return vboxQueryPointerPosInternal (NULL, NULL);
     
    320320    return winVersion;
    321321}
    322 
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/Helper.h

    r33980 r34079  
    3131extern "C"
    3232{
    33 BOOLEAN vboxQueryDisplayRequest(uint32_t *xres, uint32_t *yres, uint32_t *bpp, uint32_t *pDisplayId);
    34 BOOLEAN vboxLikesVideoMode(uint32_t display, uint32_t width, uint32_t height, uint32_t bpp);
    35 ULONG vboxGetHeightReduction();
    36 BOOLEAN vboxQueryPointerPos(uint16_t *pointerXPos, uint16_t *pointerYPos);
    37 BOOLEAN vboxQueryHostWantsAbsolute();
     33bool vboxQueryDisplayRequest(uint32_t *xres, uint32_t *yres, uint32_t *bpp, uint32_t *pDisplayId);
     34bool vboxLikesVideoMode(uint32_t display, uint32_t width, uint32_t height, uint32_t bpp);
     35uint32_t vboxGetHeightReduction();
     36bool vboxQueryPointerPos(uint16_t *pointerXPos, uint16_t *pointerYPos);
     37bool vboxQueryHostWantsAbsolute();
    3838winVersion_t vboxQueryWinVersion();
    3939
    40 #include "vboxioctl.h"
     40// #include "vboxioctl.h"
    4141
    42 int vboxVbvaEnable (ULONG ulEnable, VBVAENABLERESULT *pVbvaResult);
     42// int vboxVbvaEnable (ULONG ulEnable, VBVAENABLERESULT *pVbvaResult);
    4343}
    4444
    4545
    4646/* debug printf */
    47 #define OSDBGPRINT(a) DbgPrint a
     47/** @todo replace this with normal IPRT guest logging */
     48#ifdef RT_OS_WINDOWS
     49# define OSDBGPRINT(a) DbgPrint a
     50#else
     51# define OSDBGPRINT(a) do { } while(0)
     52#endif
    4853
    4954#ifdef LOG_TO_BACKDOOR
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/Makefile.kmk

    r33676 r34079  
    9191  VBoxVideoWddm_DEFS       += LOG_ENABLED
    9292 endif
     93 VBoxVideoWddm_DEFS       += LOG_DISABLED
    9394 #VBoxVideoWddm_DEFS       += VBOX_WITH_MULTIMONITOR_FIX
    9495 #VBoxVideoWddm_DEFS       += LOG_TO_BACKDOOR
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo-win.h

    r33997 r34079  
    11/** @file
    2  * VirtualBox Video miniport driver
     2 * VirtualBox Video miniport driver, Windows-specific header
    33 *
    44 * Copyright (C) 2006-2007 Oracle Corporation
     
    1313 */
    1414
    15 #ifndef VBOXVIDEO_H
    16 #define VBOXVIDEO_H
    17 
    18 #include <VBox/cdefs.h>
    19 #include <VBox/types.h>
    20 #include <iprt/assert.h>
    21 
    22 //#include <iprt/thread.h>
    23 
    24 #include <VBox/HGSMI/HGSMI.h>
    25 #include <VBox/HGSMI/HGSMIChSetup.h>
    26 #include <VBox/VBoxVideo.h>
    27 #include "VBoxHGSMI.h"
     15#ifndef VBOXVIDEO_WIN_H
     16#define VBOXVIDEO_WIN_H
     17
     18#include "VBoxVideo.h"
    2819
    2920RT_C_DECLS_BEGIN
     
    7869RT_C_DECLS_END
    7970
    80 #define VBE_DISPI_IOPORT_INDEX          0x01CE
    81 #define VBE_DISPI_IOPORT_DATA           0x01CF
    82 #define VBE_DISPI_INDEX_ID              0x0
    83 #define VBE_DISPI_INDEX_XRES            0x1
    84 #define VBE_DISPI_INDEX_YRES            0x2
    85 #define VBE_DISPI_INDEX_BPP             0x3
    86 #define VBE_DISPI_INDEX_ENABLE          0x4
    87 #define VBE_DISPI_INDEX_VIRT_WIDTH      0x6
    88 #define VBE_DISPI_INDEX_VIRT_HEIGHT     0x7
    89 #define VBE_DISPI_INDEX_X_OFFSET        0x8
    90 #define VBE_DISPI_INDEX_Y_OFFSET        0x9
    91 #define VBE_DISPI_INDEX_VBOX_VIDEO      0xa
    92 
    93 #define VBE_DISPI_ID2                   0xB0C2
    94 /* The VBOX interface id. Indicates support for VBE_DISPI_INDEX_VBOX_VIDEO. */
    95 #define VBE_DISPI_ID_VBOX_VIDEO         0xBE00
    96 #define VBE_DISPI_ID_HGSMI              0xBE01
    97 #define VBE_DISPI_ID_ANYX               0xBE02
    98 #define VBE_DISPI_DISABLED              0x00
    99 #define VBE_DISPI_ENABLED               0x01
    100 #define VBE_DISPI_LFB_ENABLED           0x40
    101 #define VBE_DISPI_LFB_PHYSICAL_ADDRESS  0xE0000000
    102 #define VBE_DISPI_TOTAL_VIDEO_MEMORY_MB 4
    103 #define VBE_DISPI_TOTAL_VIDEO_MEMORY_KB         (VBE_DISPI_TOTAL_VIDEO_MEMORY_MB * 1024)
    104 #define VBE_DISPI_TOTAL_VIDEO_MEMORY_BYTES      (VBE_DISPI_TOTAL_VIDEO_MEMORY_KB * 1024)
    105 
    106 #define VGA_PORT_HGSMI_HOST  0x3b0
    107 #define VGA_PORT_HGSMI_GUEST 0x3d0
    108 
    10971/* common API types */
    11072#ifdef VBOX_WITH_WDDM
     
    186148#endif
    187149
    188 typedef struct VBOXVIDEO_COMMON
    189 {
    190     int cDisplays;                      /* Number of displays. */
    191 
    192     ULONG cbVRAM;                       /* The VRAM size. */
    193 
    194     ULONG cbMiniportHeap;               /* The size of reserved VRAM for miniport driver heap.
    195                                          * It is at offset:
    196                                          *   cbAdapterMemorySize - VBOX_VIDEO_ADAPTER_INFORMATION_SIZE - cbMiniportHeap
    197                                          */
    198     PVOID pvMiniportHeap;               /* The pointer to the miniport heap VRAM.
    199                                          * This is mapped by miniport separately.
    200                                          */
    201     volatile HGSMIHOSTFLAGS * pHostFlags; /* HGSMI host flags */
    202     volatile bool bHostCmdProcessing;
    203 
    204     PVOID pvAdapterInformation;         /* The pointer to the last 4K of VRAM.
    205                                          * This is mapped by miniport separately.
    206                                          */
    207 
    208     /** Host HGSMI capabilities the guest can handle */
    209     uint32_t fCaps;
    210 
    211     BOOLEAN bHGSMI;                     /* Whether HGSMI is enabled. */
    212 
    213     HGSMIAREA areaHostHeap;             /* Host heap VRAM area. */
    214 
    215     HGSMICHANNELINFO channels;
    216 
    217     HGSMIHEAP hgsmiAdapterHeap;
    218 
    219     /* The IO Port Number for host commands. */
    220     RTIOPORT IOPortHost;
    221 
    222     /* The IO Port Number for guest commands. */
    223     RTIOPORT IOPortGuest;
    224 } VBOXVIDEO_COMMON, *PVBOXVIDEO_COMMON;
    225 
    226150typedef struct _DEVICE_EXTENSION
    227151{
     
    333257}
    334258
     259static inline bool vboxUpdatePointerShapeWrap(PVBOXVIDEO_COMMON pCommon,
     260                                              PVIDEO_POINTER_ATTRIBUTES pointerAttr,
     261                                              uint32_t cbLength)
     262{
     263    return vboxUpdatePointerShape(pCommon,
     264                                  pointerAttr->Enable & 0x0000FFFF,
     265                                  (pointerAttr->Enable >> 16) & 0xFF,
     266                                  (pointerAttr->Enable >> 24) & 0xFF,
     267                                  pointerAttr->Width,
     268                                  pointerAttr->Height,
     269                                  pointerAttr->Pixels,
     270                                  cbLength - sizeof(VIDEO_POINTER_ATTRIBUTES));
     271}
     272
    335273#ifndef VBOX_WITH_WDDM
    336274#define DEV_MOUSE_HIDDEN(dev) ((dev)->pPrimary->u.primary.fMouseHidden)
     
    354292} while (0)
    355293#endif
     294
    356295extern "C"
    357296{
    358 /** Signal an event in a guest-OS-specific way.  pvEvent will be re-cast to
    359  * something OS-specific. */
    360 void VBoxVideoCmnSignalEvent(PVBOXVIDEO_COMMON pCommon, uint64_t pvEvent);
    361 
    362 /** Allocate memory to be used in normal driver operation (dispatch level in
    363  * Windows) but not necessarily in IRQ context. */
    364 void *VBoxVideoCmnMemAllocDriver(PVBOXVIDEO_COMMON pCommon, size_t cb);
    365 
    366 /** Free memory allocated by @a VBoxVideoCmnMemAllocDriver */
    367 void VBoxVideoCmnMemFreeDriver(PVBOXVIDEO_COMMON pCommon, void *pv);
    368 
    369 /** Write an 8-bit value to an I/O port. */
    370 void VBoxVideoCmnPortWriteUchar(RTIOPORT Port, uint8_t Value);
    371 
    372 /** Write a 16-bit value to an I/O port. */
    373 void VBoxVideoCmnPortWriteUshort(RTIOPORT Port, uint16_t Value);
    374 
    375 /** Write a 32-bit value to an I/O port. */
    376 void VBoxVideoCmnPortWriteUlong(RTIOPORT Port, uint32_t Value);
    377 
    378 /** Read an 8-bit value from an I/O port. */
    379 uint8_t VBoxVideoCmnPortReadUchar(RTIOPORT Port);
    380 
    381 /** Read a 16-bit value from an I/O port. */
    382 uint16_t VBoxVideoCmnPortReadUshort(RTIOPORT Port);
    383 
    384 /** Read a 32-bit value from an I/O port. */
    385 uint32_t VBoxVideoCmnPortReadUlong(RTIOPORT Port);
    386 
    387297#ifndef VBOX_WITH_WDDM
    388298
     
    409319
    410320/* @return STATUS_BUFFER_TOO_SMALL - if buffer is too small, STATUS_SUCCESS - on success */
    411 NTSTATUS vboxWddmGetModesForResolution(PDEVICE_EXTENSION DeviceExtension, PVBOXWDDM_VIDEOMODES_INFO pModeInfos,
    412         D3DKMDT_2DREGION *pResolution, VIDEO_MODE_INFORMATION * pModes, uint32_t cModes, uint32_t *pcModes, int32_t *piPreferrableMode);
    413 
    414 D3DDDIFORMAT vboxWddmCalcPixelFormat(VIDEO_MODE_INFORMATION *pInfo);
     321NTSTATUS vboxWddmGetModesForResolution(VIDEO_MODE_INFORMATION *pAllModes, uint32_t cAllModes, int iSearchPreferredMode,
     322        const D3DKMDT_2DREGION *pResolution, VIDEO_MODE_INFORMATION * pModes, uint32_t cModes, uint32_t *pcModes, int32_t *piPreferrableMode);
     323
     324int vboxWddmVideoModeFind(const VIDEO_MODE_INFORMATION *pModes, int cModes, const VIDEO_MODE_INFORMATION *pM);
     325int vboxWddmVideoResolutionFind(const D3DKMDT_2DREGION *pResolutions, int cResolutions, const D3DKMDT_2DREGION *pRes);
     326bool vboxWddmVideoResolutionsMatch(const D3DKMDT_2DREGION *pResolutions1, const D3DKMDT_2DREGION *pResolutions2, int cResolutions);
     327bool vboxWddmVideoModesMatch(const VIDEO_MODE_INFORMATION *pModes1, const VIDEO_MODE_INFORMATION *pModes2, int cModes);
     328
     329D3DDDIFORMAT vboxWddmCalcPixelFormat(const VIDEO_MODE_INFORMATION *pInfo);
     330bool vboxWddmFillMode(VIDEO_MODE_INFORMATION *pInfo, D3DDDIFORMAT enmFormat, ULONG w, ULONG h);
    415331
    416332DECLINLINE(ULONG) vboxWddmVramCpuVisibleSize(PDEVICE_EXTENSION pDevExt)
     
    524440#endif
    525441
    526 void* vboxHGSMIBufferAlloc(PVBOXVIDEO_COMMON pCommon,
    527                          HGSMISIZE cbData,
    528                          uint8_t u8Ch,
    529                          uint16_t u16Op);
    530 void vboxHGSMIBufferFree (PVBOXVIDEO_COMMON pCommon, void *pvBuffer);
    531 int vboxHGSMIBufferSubmit (PVBOXVIDEO_COMMON pCommon, void *pvBuffer);
    532 
    533442BOOLEAN FASTCALL VBoxVideoSetCurrentModePerform(PDEVICE_EXTENSION DeviceExtension,
    534443        USHORT width, USHORT height, USHORT bpp
     
    578487   PSTATUS_BLOCK StatusBlock);
    579488
    580 int VBoxMapAdapterMemory (PVBOXVIDEO_COMMON pCommon,
    581                           void **ppv,
    582                           ULONG ulOffset,
    583                           ULONG ulSize);
    584 
    585 void VBoxUnmapAdapterMemory (PVBOXVIDEO_COMMON pCommon, void **ppv);
    586 
    587 typedef bool(*PFNVIDEOIRQSYNC)(void *);
    588 bool VBoxSyncToVideoIRQ(PVBOXVIDEO_COMMON pCommon, PFNVIDEOIRQSYNC pfnSync,
    589                         void *pvUser);
    590 
    591489void VBoxComputeFrameBufferSizes (PDEVICE_EXTENSION PrimaryExtension);
    592 
    593 
    594 /*
    595  * Host and Guest port IO helpers.
    596  */
    597 DECLINLINE(void) VBoxHGSMIHostWrite(PVBOXVIDEO_COMMON pCommon, ULONG data)
    598 {
    599     VBoxVideoCmnPortWriteUlong(pCommon->IOPortHost, data);
    600 }
    601 
    602 DECLINLINE(ULONG) VBoxHGSMIHostRead(PVBOXVIDEO_COMMON pCommon)
    603 {
    604     return VBoxVideoCmnPortReadUlong(pCommon->IOPortHost);
    605 }
    606 
    607 DECLINLINE(void) VBoxHGSMIGuestWrite(PVBOXVIDEO_COMMON pCommon, ULONG data)
    608 {
    609     VBoxVideoCmnPortWriteUlong(pCommon->IOPortGuest, data);
    610 }
    611 
    612 DECLINLINE(ULONG) VBoxHGSMIGuestRead(PVBOXVIDEO_COMMON pCommon)
    613 {
    614     return VBoxVideoCmnPortReadUlong(pCommon->IOPortGuest);
    615 }
    616 
    617 
    618 BOOLEAN VBoxHGSMIIsSupported (void);
    619 
    620 typedef int FNHGSMIFILLVIEWINFO (void *pvData, VBVAINFOVIEW *pInfo);
    621 typedef FNHGSMIFILLVIEWINFO *PFNHGSMIFILLVIEWINFO;
    622 
    623 int VBoxHGSMISendViewInfo(PVBOXVIDEO_COMMON pCommon, uint32_t u32Count, PFNHGSMIFILLVIEWINFO pfnFill, void *pvData);
    624 
    625 VOID VBoxSetupDisplaysHGSMI (PVBOXVIDEO_COMMON pCommon,
    626                              ULONG AdapterMemorySize, uint32_t fCaps);
    627 BOOLEAN vboxUpdatePointerShape (PVBOXVIDEO_COMMON pCommon,
    628                                 PVIDEO_POINTER_ATTRIBUTES pointerAttr,
    629                                 uint32_t cbLength);
    630 
    631 void VBoxFreeDisplaysHGSMI(PVBOXVIDEO_COMMON pCommon);
    632 #ifndef VBOX_WITH_WDDM
    633 DECLCALLBACK(void) hgsmiHostCmdComplete (HVBOXVIDEOHGSMI hHGSMI, struct _VBVAHOSTCMD * pCmd);
    634 DECLCALLBACK(int) hgsmiHostCmdRequest (HVBOXVIDEOHGSMI hHGSMI, uint8_t u8Channel, uint32_t iDisplay, struct _VBVAHOSTCMD ** ppCmd);
    635 #endif
    636 
    637 
    638 int vboxVBVAChannelDisplayEnable(PVBOXVIDEO_COMMON pCommon,
    639         int iDisplay, /* negative would mean this is a miniport handler */
    640         uint8_t u8Channel);
    641 
    642 void hgsmiProcessHostCommandQueue(PVBOXVIDEO_COMMON pCommon);
    643 
    644 void HGSMIClearIrq (PVBOXVIDEO_COMMON pCommon);
    645 
    646490} /* extern "C" */
    647491
    648 #endif /* VBOXVIDEO_H */
     492#endif /* VBOXVIDEO_WIN_H */
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp

    r34018 r34079  
    1515 */
    1616
    17 #include "VBoxVideo.h"
     17#include "VBoxVideo-win.h"
    1818#include "Helper.h"
    1919#ifdef VBOX_WITH_WDDM
     
    26672667}
    26682668
    2669 int VBoxMapAdapterMemory (PVBOXVIDEO_COMMON pCommon, void **ppv, ULONG ulOffset, ULONG ulSize)
     2669int VBoxMapAdapterMemory (PVBOXVIDEO_COMMON pCommon, void **ppv, uint32_t ulOffset, uint32_t ulSize)
    26702670{
    26712671    PDEVICE_EXTENSION PrimaryExtension = commonToPrimaryExt(pCommon);
     
    32093209        PointerAttributes.Enable = VBOX_MOUSE_POINTER_VISIBLE;
    32103210
    3211         Result = vboxUpdatePointerShape(commonFromDeviceExt(PrimaryExtension), &PointerAttributes, sizeof (PointerAttributes));
     3211        Result = vboxUpdatePointerShapeWrap(commonFromDeviceExt(PrimaryExtension), &PointerAttributes, sizeof (PointerAttributes));
    32123212
    32133213        if (Result)
     
    34573457                PointerAttributes.Enable = 0;
    34583458
    3459                 Result = vboxUpdatePointerShape(commonFromDeviceExt((PDEVICE_EXTENSION)HwDeviceExtension), &PointerAttributes, sizeof (PointerAttributes));
     3459                Result = vboxUpdatePointerShapeWrap(commonFromDeviceExt((PDEVICE_EXTENSION)HwDeviceExtension), &PointerAttributes, sizeof (PointerAttributes));
    34603460
    34613461                if (Result)
     
    35023502                dprintf(("\tBytes attached: %d\n", RequestPacket->InputBufferLength - sizeof(VIDEO_POINTER_ATTRIBUTES)));
    35033503#endif
    3504                 Result = vboxUpdatePointerShape(commonFromDeviceExt((PDEVICE_EXTENSION)HwDeviceExtension), pPointerAttributes, RequestPacket->InputBufferLength);
     3504                Result = vboxUpdatePointerShapeWrap(commonFromDeviceExt((PDEVICE_EXTENSION)HwDeviceExtension), pPointerAttributes, RequestPacket->InputBufferLength);
    35053505                if (!Result)
    35063506                    dprintf(("VBoxVideo::VBoxVideoStartIO: Could not set hardware pointer -> fallback\n"));
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.h

    r34018 r34079  
    2727#include "VBoxHGSMI.h"
    2828
    29 RT_C_DECLS_BEGIN
    30 #ifndef VBOX_WITH_WDDM
    31 #include "dderror.h"
    32 #include "devioctl.h"
    33 #include "miniport.h"
    34 #include "ntddvdeo.h"
    35 #include "video.h"
    36 #else
    37 #   ifdef PAGE_SIZE
    38 #    undef PAGE_SIZE
    39 #   endif
    40 #   ifdef PAGE_SHIFT
    41 #    undef PAGE_SHIFT
    42 #   endif
    43 #   define VBOX_WITH_WORKAROUND_MISSING_PACK
    44 #   if (_MSC_VER >= 1400) && !defined(VBOX_WITH_PATCHED_DDK)
    45 #       define _InterlockedExchange           _InterlockedExchange_StupidDDKVsCompilerCrap
    46 #       define _InterlockedExchangeAdd        _InterlockedExchangeAdd_StupidDDKVsCompilerCrap
    47 #       define _InterlockedCompareExchange    _InterlockedCompareExchange_StupidDDKVsCompilerCrap
    48 #       define _InterlockedAddLargeStatistic  _InterlockedAddLargeStatistic_StupidDDKVsCompilerCrap
    49 #       define _interlockedbittestandset      _interlockedbittestandset_StupidDDKVsCompilerCrap
    50 #       define _interlockedbittestandreset    _interlockedbittestandreset_StupidDDKVsCompilerCrap
    51 #       define _interlockedbittestandset64    _interlockedbittestandset64_StupidDDKVsCompilerCrap
    52 #       define _interlockedbittestandreset64  _interlockedbittestandreset64_StupidDDKVsCompilerCrap
    53 #       pragma warning(disable : 4163)
    54 #       ifdef VBOX_WITH_WORKAROUND_MISSING_PACK
    55 #          pragma warning(disable : 4103)
    56 #       endif
    57 #       include <ntddk.h>
    58 #       pragma warning(default : 4163)
    59 #       ifdef VBOX_WITH_WORKAROUND_MISSING_PACK
    60 #         pragma pack()
    61 #         pragma warning(default : 4103)
    62 #       endif
    63 #       undef  _InterlockedExchange
    64 #       undef  _InterlockedExchangeAdd
    65 #       undef  _InterlockedCompareExchange
    66 #       undef  _InterlockedAddLargeStatistic
    67 #       undef  _interlockedbittestandset
    68 #       undef  _interlockedbittestandreset
    69 #       undef  _interlockedbittestandset64
    70 #       undef  _interlockedbittestandreset64
    71 #   else
    72 #       include <ntddk.h>
    73 #   endif
    74 #include "dispmprt.h"
    75 #include "ntddvdeo.h"
    76 #include "dderror.h"
    77 #endif
    78 RT_C_DECLS_END
    79 
    8029#define VBE_DISPI_IOPORT_INDEX          0x01CE
    8130#define VBE_DISPI_IOPORT_DATA           0x01CF
     
    10756#define VGA_PORT_HGSMI_GUEST 0x3d0
    10857
    109 /* common API types */
    110 #ifdef VBOX_WITH_WDDM
    111 #define VBOX_WITH_GENERIC_MULTIMONITOR
    112 typedef struct _DEVICE_EXTENSION *PDEVICE_EXTENSION;
    113 #include <VBox/VBoxVideo.h>
    114 #include "wddm/VBoxVideoIf.h"
    115 #include "wddm/VBoxVideoMisc.h"
    116 #include "wddm/VBoxVideoShgsmi.h"
    117 #include "wddm/VBoxVideoCm.h"
    118 #include "wddm/VBoxVideoVdma.h"
    119 #include "wddm/VBoxVideoWddm.h"
    120 #include "wddm/VBoxVideoVidPn.h"
    121 #ifdef VBOXWDDM_WITH_VBVA
    122 # include "wddm/VBoxVideoVbva.h"
    123 #endif
    124 #ifdef VBOX_WITH_VIDEOHWACCEL
    125 # include "wddm/VBoxVideoVhwa.h"
    126 #endif
    127 
    128 #define VBOXWDDM_POINTER_ATTRIBUTES_SIZE VBOXWDDM_ROUNDBOUND( \
    129         VBOXWDDM_ROUNDBOUND( sizeof (VIDEO_POINTER_ATTRIBUTES), 4 ) + \
    130         VBOXWDDM_ROUNDBOUND(VBOXWDDM_C_POINTER_MAX_WIDTH * VBOXWDDM_C_POINTER_MAX_HEIGHT * 4, 4) + \
    131         VBOXWDDM_ROUNDBOUND((VBOXWDDM_C_POINTER_MAX_WIDTH * VBOXWDDM_C_POINTER_MAX_HEIGHT + 7) >> 3, 4) \
    132          , 8)
    133 
    134 typedef struct VBOXWDDM_POINTER_INFO
    135 {
    136     uint32_t xPos;
    137     uint32_t yPos;
    138     union
    139     {
    140         VIDEO_POINTER_ATTRIBUTES data;
    141         char buffer[VBOXWDDM_POINTER_ATTRIBUTES_SIZE];
    142     } Attributes;
    143 } VBOXWDDM_POINTER_INFO, *PVBOXWDDM_POINTER_INFO;
    144 
    145 typedef struct VBOXWDDM_GLOBAL_POINTER_INFO
    146 {
    147     uint32_t cVisible;
    148 } VBOXWDDM_GLOBAL_POINTER_INFO, *PVBOXWDDM_GLOBAL_POINTER_INFO;
    149 
    150 #ifdef VBOX_WITH_VIDEOHWACCEL
    151 typedef struct VBOXWDDM_VHWA
    152 {
    153     VBOXVHWA_INFO Settings;
    154     volatile uint32_t cOverlaysCreated;
    155 } VBOXWDDM_VHWA;
    156 #endif
    157 
    158 typedef struct VBOXWDDM_SOURCE
    159 {
    160     struct VBOXWDDM_ALLOCATION * pPrimaryAllocation;
    161 #ifdef VBOXWDDM_RENDER_FROM_SHADOW
    162     struct VBOXWDDM_ALLOCATION * pShadowAllocation;
    163     VBOXVIDEOOFFSET offVram;
    164     VBOXWDDM_SURFACE_DESC SurfDesc;
    165     VBOXVBVAINFO Vbva;
    166 #endif
    167 #ifdef VBOX_WITH_VIDEOHWACCEL
    168     /* @todo: in our case this seems more like a target property,
    169      * but keep it here for now */
    170     VBOXWDDM_VHWA Vhwa;
    171     volatile uint32_t cOverlays;
    172     LIST_ENTRY OverlayList;
    173     KSPIN_LOCK OverlayListLock;
    174 #endif
    175     POINT VScreenPos;
    176     VBOXWDDM_POINTER_INFO PointerInfo;
    177 } VBOXWDDM_SOURCE, *PVBOXWDDM_SOURCE;
    178 
    179 typedef struct VBOXWDDM_TARGET
    180 {
    181     uint32_t ScanLineState;
    182     uint32_t HeightVisible;
    183     uint32_t HeightTotal;
    184 } VBOXWDDM_TARGET, *PVBOXWDDM_TARGET;
    185 
    186 #endif
    187 
    18858typedef struct VBOXVIDEO_COMMON
    18959{
    19060    int cDisplays;                      /* Number of displays. */
    19161
    192     ULONG cbVRAM;                       /* The VRAM size. */
    193 
    194     ULONG cbMiniportHeap;               /* The size of reserved VRAM for miniport driver heap.
     62    uint32_t cbVRAM;                    /* The VRAM size. */
     63
     64    uint32_t cbMiniportHeap;            /* The size of reserved VRAM for miniport driver heap.
    19565                                         * It is at offset:
    19666                                         *   cbAdapterMemorySize - VBOX_VIDEO_ADAPTER_INFORMATION_SIZE - cbMiniportHeap
    19767                                         */
    198     PVOID pvMiniportHeap;               /* The pointer to the miniport heap VRAM.
     68    void *pvMiniportHeap;               /* The pointer to the miniport heap VRAM.
    19969                                         * This is mapped by miniport separately.
    20070                                         */
     
    20272    volatile bool bHostCmdProcessing;
    20373
    204     PVOID pvAdapterInformation;         /* The pointer to the last 4K of VRAM.
     74    void *pvAdapterInformation;         /* The pointer to the last 4K of VRAM.
    20575                                         * This is mapped by miniport separately.
    20676                                         */
     
    20979    uint32_t fCaps;
    21080
    211     BOOLEAN bHGSMI;                     /* Whether HGSMI is enabled. */
     81    bool bHGSMI;                        /* Whether HGSMI is enabled. */
    21282
    21383    HGSMIAREA areaHostHeap;             /* Host heap VRAM area. */
     
    22494} VBOXVIDEO_COMMON, *PVBOXVIDEO_COMMON;
    22595
    226 typedef struct _DEVICE_EXTENSION
    227 {
    228    struct _DEVICE_EXTENSION *pNext;            /* Next extension in the DualView extension list.
    229                                                 * The primary extension is the first one.
    230                                                 */
    231 #ifndef VBOX_WITH_WDDM
    232    struct _DEVICE_EXTENSION *pPrimary;         /* Pointer to the primary device extension. */
    233 
    234    ULONG iDevice;                              /* Device index: 0 for primary, otherwise a secondary device. */
    235 
    236    ULONG CurrentMode;                          /* Saved information about video modes */
    237    ULONG CurrentModeWidth;
    238    ULONG CurrentModeHeight;
    239    ULONG CurrentModeBPP;
    240 
    241    ULONG ulFrameBufferOffset;                  /* The framebuffer position in the VRAM. */
    242    ULONG ulFrameBufferSize;                    /* The size of the current framebuffer. */
    243 #endif
    244    union {
    245        /* Information that is only relevant to the primary device or is the same for all devices. */
    246        struct {
    247 
    248            void *pvReqFlush;                   /* Pointer to preallocated generic request structure for
    249                                                 * VMMDevReq_VideoAccelFlush. Allocated when VBVA status
    250                                                 * is changed. Deallocated on HwReset.
    251                                                 */
    252 
    253 
    254            ULONG ulVbvaEnabled;                /* Indicates that VBVA mode is enabled. */
    255 
    256 #ifdef VBOX_WITH_WDDM
    257            VBOXVDMAINFO Vdma;
    258 # ifdef VBOXVDMA_WITH_VBVA
    259            VBOXVBVAINFO Vbva;
    260 # endif
    261 #endif
    262            ULONG ulMaxFrameBufferSize;         /* The size of the VRAM allocated for the a single framebuffer. */
    263 
    264            BOOLEAN fMouseHidden;               /* Has the mouse cursor been hidden by the guest? */
    265 
    266 
    267            VBOXVIDEO_COMMON commonInfo;
    268 #ifndef VBOX_WITH_WDDM
    269            /* Video Port API dynamically picked up at runtime for binary backwards compatibility with older NT versions */
    270            VBOXVIDEOPORTPROCS VideoPortProcs;
    271 #else
    272            /* committed VidPn handle */
    273            D3DKMDT_HVIDPN hCommittedVidPn;
    274            /* Display Port handle and callbacks */
    275            DXGKRNL_INTERFACE DxgkInterface;
    276 #endif
    277        } primary;
    278 
    279        /* Secondary device information. */
    280        struct {
    281            BOOLEAN bEnabled;                   /* Device enabled flag */
    282        } secondary;
    283    } u;
    284 
    285    HGSMIAREA areaDisplay;                      /* Entire VRAM chunk for this display device. */
    286 
    287 #ifdef VBOX_WITH_WDDM
    288    PDEVICE_OBJECT pPDO;
    289    UNICODE_STRING RegKeyName;
    290    UNICODE_STRING VideoGuid;
    291 
    292    uint8_t * pvVisibleVram;
    293 
    294    VBOXVIDEOCM_MGR CmMgr;
    295    /* hgsmi allocation manager */
    296    VBOXVIDEOCM_ALLOC_MGR AllocMgr;
    297    VBOXVDMADDI_CMD_QUEUE DdiCmdQueue;
    298    LIST_ENTRY SwapchainList3D;
    299    /* mutex for context list operations */
    300    FAST_MUTEX ContextMutex;
    301    KSPIN_LOCK SynchLock;
    302    volatile uint32_t cContexts3D;
    303    volatile uint32_t cUnlockedVBVADisabled;
    304 
    305    VBOXWDDM_GLOBAL_POINTER_INFO PointerInfo;
    306 
    307    VBOXSHGSMILIST CtlList;
    308    VBOXSHGSMILIST DmaCmdList;
    309 #ifdef VBOX_WITH_VIDEOHWACCEL
    310    VBOXSHGSMILIST VhwaCmdList;
    311 #endif
    312 //   BOOL bSetNotifyDxDpc;
    313    BOOL bNotifyDxDpc;
    314 
    315    VBOXWDDM_SOURCE aSources[VBOX_VIDEO_MAX_SCREENS];
    316    VBOXWDDM_TARGET aTargets[VBOX_VIDEO_MAX_SCREENS];
    317 #endif
    318    BOOLEAN fAnyX;   /* Unrestricted horizontal resolution flag. */
    319 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
    320 
    321 static inline PVBOXVIDEO_COMMON commonFromDeviceExt(PDEVICE_EXTENSION pExt)
    322 {
    323 #ifndef VBOX_WITH_WDDM
    324     return &pExt->pPrimary->u.primary.commonInfo;
    325 #else
    326     return &pExt->u.primary.commonInfo;
    327 #endif
    328 }
    329 
    330 static inline PDEVICE_EXTENSION commonToPrimaryExt(PVBOXVIDEO_COMMON pCommon)
    331 {
    332     return RT_FROM_MEMBER(pCommon, DEVICE_EXTENSION, u.primary.commonInfo);
    333 }
    334 
    335 #ifndef VBOX_WITH_WDDM
    336 #define DEV_MOUSE_HIDDEN(dev) ((dev)->pPrimary->u.primary.fMouseHidden)
    337 #define DEV_SET_MOUSE_HIDDEN(dev)   \
    338 do { \
    339     (dev)->pPrimary->u.primary.fMouseHidden = TRUE; \
    340 } while (0)
    341 #define DEV_SET_MOUSE_SHOWN(dev)   \
    342 do { \
    343     (dev)->pPrimary->u.primary.fMouseHidden = FALSE; \
    344 } while (0)
    345 #else
    346 #define DEV_MOUSE_HIDDEN(dev) ((dev)->u.primary.fMouseHidden)
    347 #define DEV_SET_MOUSE_HIDDEN(dev)   \
    348 do { \
    349     (dev)->u.primary.fMouseHidden = TRUE; \
    350 } while (0)
    351 #define DEV_SET_MOUSE_SHOWN(dev)   \
    352 do { \
    353     (dev)->u.primary.fMouseHidden = FALSE; \
    354 } while (0)
    355 #endif
    35696extern "C"
    35797{
     
    384124/** Read a 32-bit value from an I/O port. */
    385125uint32_t VBoxVideoCmnPortReadUlong(RTIOPORT Port);
    386 
    387 #ifndef VBOX_WITH_WDDM
    388 
    389 RT_C_DECLS_BEGIN
    390 ULONG DriverEntry(IN PVOID Context1, IN PVOID Context2);
    391 RT_C_DECLS_END
    392 
    393 #else
    394 
    395 RT_C_DECLS_BEGIN
    396 NTSTATUS
    397 DriverEntry(
    398     IN PDRIVER_OBJECT DriverObject,
    399     IN PUNICODE_STRING RegistryPath
    400     );
    401 RT_C_DECLS_END
    402 
    403 PVBOXWDDM_VIDEOMODES_INFO vboxWddmGetVideoModesInfo(PDEVICE_EXTENSION DeviceExtension, D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId);
    404 PVBOXWDDM_VIDEOMODES_INFO vboxWddmGetAllVideoModesInfos(PDEVICE_EXTENSION DeviceExtension);
    405 
    406 void vboxVideoInitCustomVideoModes(PDEVICE_EXTENSION pDevExt);
    407 
    408 VOID vboxWddmInvalidateVideoModesInfo(PDEVICE_EXTENSION DeviceExtension);
    409 
    410 /* @return STATUS_BUFFER_TOO_SMALL - if buffer is too small, STATUS_SUCCESS - on success */
    411 NTSTATUS vboxWddmGetModesForResolution(VIDEO_MODE_INFORMATION *pAllModes, uint32_t cAllModes, int iSearchPreferredMode,
    412         const D3DKMDT_2DREGION *pResolution, VIDEO_MODE_INFORMATION * pModes, uint32_t cModes, uint32_t *pcModes, int32_t *piPreferrableMode);
    413 
    414 int vboxWddmVideoModeFind(const VIDEO_MODE_INFORMATION *pModes, int cModes, const VIDEO_MODE_INFORMATION *pM);
    415 int vboxWddmVideoResolutionFind(const D3DKMDT_2DREGION *pResolutions, int cResolutions, const D3DKMDT_2DREGION *pRes);
    416 bool vboxWddmVideoResolutionsMatch(const D3DKMDT_2DREGION *pResolutions1, const D3DKMDT_2DREGION *pResolutions2, int cResolutions);
    417 bool vboxWddmVideoModesMatch(const VIDEO_MODE_INFORMATION *pModes1, const VIDEO_MODE_INFORMATION *pModes2, int cModes);
    418 
    419 D3DDDIFORMAT vboxWddmCalcPixelFormat(const VIDEO_MODE_INFORMATION *pInfo);
    420 bool vboxWddmFillMode(VIDEO_MODE_INFORMATION *pInfo, D3DDDIFORMAT enmFormat, ULONG w, ULONG h);
    421 
    422 DECLINLINE(ULONG) vboxWddmVramCpuVisibleSize(PDEVICE_EXTENSION pDevExt)
    423 {
    424 #ifdef VBOXWDDM_RENDER_FROM_SHADOW
    425     /* all memory layout info should be initialized */
    426     Assert(pDevExt->aSources[0].Vbva.offVBVA);
    427     /* page aligned */
    428     Assert(!(pDevExt->aSources[0].Vbva.offVBVA & 0xfff));
    429 
    430     return (ULONG)(pDevExt->aSources[0].Vbva.offVBVA & ~0xfffULL);
    431 #else
    432     /* all memory layout info should be initialized */
    433     Assert(pDevExt->u.primary.Vdma.CmdHeap.area.offBase);
    434     /* page aligned */
    435     Assert(!(pDevExt->u.primary.Vdma.CmdHeap.area.offBase & 0xfff));
    436 
    437     return pDevExt->u.primary.Vdma.CmdHeap.area.offBase & ~0xfffUL;
    438 #endif
    439 }
    440 
    441 DECLINLINE(ULONG) vboxWddmVramCpuVisibleSegmentSize(PDEVICE_EXTENSION pDevExt)
    442 {
    443     return vboxWddmVramCpuVisibleSize(pDevExt);
    444 }
    445 
    446 #ifdef VBOXWDDM_RENDER_FROM_SHADOW
    447 DECLINLINE(ULONG) vboxWddmVramCpuInvisibleSegmentSize(PDEVICE_EXTENSION pDevExt)
    448 {
    449     return vboxWddmVramCpuVisibleSegmentSize(pDevExt);
    450 }
    451 
    452 DECLINLINE(bool) vboxWddmCmpSurfDescsBase(VBOXWDDM_SURFACE_DESC *pDesc1, VBOXWDDM_SURFACE_DESC *pDesc2)
    453 {
    454     if (pDesc1->width != pDesc2->width)
    455         return false;
    456     if (pDesc1->height != pDesc2->height)
    457         return false;
    458     if (pDesc1->format != pDesc2->format)
    459         return false;
    460     if (pDesc1->bpp != pDesc2->bpp)
    461         return false;
    462     if (pDesc1->pitch != pDesc2->pitch)
    463         return false;
    464     return true;
    465 }
    466 
    467 DECLINLINE(void) vboxWddmAssignShadow(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_SOURCE pSource, PVBOXWDDM_ALLOCATION pAllocation, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
    468 {
    469     if (pSource->pShadowAllocation == pAllocation)
    470     {
    471         Assert(pAllocation->bAssigned);
    472         return;
    473     }
    474 
    475     if (pSource->pShadowAllocation)
    476     {
    477         PVBOXWDDM_ALLOCATION pOldAlloc = pSource->pShadowAllocation;
    478         /* clear the visibility info fo the current primary */
    479         pOldAlloc->bVisible = FALSE;
    480         pOldAlloc->bAssigned = FALSE;
    481         Assert(pOldAlloc->SurfDesc.VidPnSourceId == srcId);
    482         /* release the shadow surface */
    483         pOldAlloc->SurfDesc.VidPnSourceId = D3DDDI_ID_UNINITIALIZED;
    484     }
    485 
    486     if (pAllocation)
    487     {
    488         Assert(!pAllocation->bAssigned);
    489         Assert(!pAllocation->bVisible);
    490         pAllocation->bVisible = FALSE;
    491         /* this check ensures the shadow is not used for other source simultaneously */
    492         Assert(pAllocation->SurfDesc.VidPnSourceId == D3DDDI_ID_UNINITIALIZED);
    493         pAllocation->SurfDesc.VidPnSourceId = srcId;
    494         pAllocation->bAssigned = TRUE;
    495         if (!vboxWddmCmpSurfDescsBase(&pSource->SurfDesc, &pAllocation->SurfDesc))
    496             pSource->offVram = VBOXVIDEOOFFSET_VOID; /* force guest->host notification */
    497         pSource->SurfDesc = pAllocation->SurfDesc;
    498     }
    499 
    500     pSource->pShadowAllocation = pAllocation;
    501 }
    502 #endif
    503 
    504 DECLINLINE(VOID) vboxWddmAssignPrimary(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_SOURCE pSource, PVBOXWDDM_ALLOCATION pAllocation, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
    505 {
    506     if (pSource->pPrimaryAllocation == pAllocation)
    507         return;
    508 
    509     if (pSource->pPrimaryAllocation)
    510     {
    511         PVBOXWDDM_ALLOCATION pOldAlloc = pSource->pPrimaryAllocation;
    512         /* clear the visibility info fo the current primary */
    513         pOldAlloc->bVisible = FALSE;
    514         pOldAlloc->bAssigned = FALSE;
    515         Assert(pOldAlloc->SurfDesc.VidPnSourceId == srcId);
    516     }
    517 
    518     if (pAllocation)
    519     {
    520         pAllocation->bVisible = FALSE;
    521         Assert(pAllocation->SurfDesc.VidPnSourceId == srcId);
    522         pAllocation->SurfDesc.VidPnSourceId = srcId;
    523         pAllocation->bAssigned = TRUE;
    524     }
    525 
    526     pSource->pPrimaryAllocation = pAllocation;
    527 }
    528 
    529 
    530 #endif
    531126
    532127void* vboxHGSMIBufferAlloc(PVBOXVIDEO_COMMON pCommon,
     
    537132int vboxHGSMIBufferSubmit (PVBOXVIDEO_COMMON pCommon, void *pvBuffer);
    538133
    539 BOOLEAN FASTCALL VBoxVideoSetCurrentModePerform(PDEVICE_EXTENSION DeviceExtension,
    540         USHORT width, USHORT height, USHORT bpp
    541 #ifdef VBOX_WITH_WDDM
    542         , ULONG offDisplay
    543 #endif
    544         );
    545 
    546 BOOLEAN FASTCALL VBoxVideoSetCurrentMode(
    547    PDEVICE_EXTENSION DeviceExtension,
    548    PVIDEO_MODE RequestedMode,
    549    PSTATUS_BLOCK StatusBlock);
    550 
    551 BOOLEAN FASTCALL VBoxVideoResetDevice(
    552    PDEVICE_EXTENSION DeviceExtension,
    553    PSTATUS_BLOCK StatusBlock);
    554 
    555 BOOLEAN FASTCALL VBoxVideoMapVideoMemory(
    556    PDEVICE_EXTENSION DeviceExtension,
    557    PVIDEO_MEMORY RequestedAddress,
    558    PVIDEO_MEMORY_INFORMATION MapInformation,
    559    PSTATUS_BLOCK StatusBlock);
    560 
    561 BOOLEAN FASTCALL VBoxVideoUnmapVideoMemory(
    562    PDEVICE_EXTENSION DeviceExtension,
    563    PVIDEO_MEMORY VideoMemory,
    564    PSTATUS_BLOCK StatusBlock);
    565 
    566 BOOLEAN FASTCALL VBoxVideoQueryNumAvailModes(
    567    PDEVICE_EXTENSION DeviceExtension,
    568    PVIDEO_NUM_MODES Modes,
    569    PSTATUS_BLOCK StatusBlock);
    570 
    571 BOOLEAN FASTCALL VBoxVideoQueryAvailModes(
    572    PDEVICE_EXTENSION DeviceExtension,
    573    PVIDEO_MODE_INFORMATION ReturnedModes,
    574    PSTATUS_BLOCK StatusBlock);
    575 
    576 BOOLEAN FASTCALL VBoxVideoQueryCurrentMode(
    577    PDEVICE_EXTENSION DeviceExtension,
    578    PVIDEO_MODE_INFORMATION VideoModeInfo,
    579    PSTATUS_BLOCK StatusBlock);
    580 
    581 BOOLEAN FASTCALL VBoxVideoSetColorRegisters(
    582    PDEVICE_EXTENSION DeviceExtension,
    583    PVIDEO_CLUT ColorLookUpTable,
    584    PSTATUS_BLOCK StatusBlock);
    585 
    586134int VBoxMapAdapterMemory (PVBOXVIDEO_COMMON pCommon,
    587135                          void **ppv,
    588                           ULONG ulOffset,
    589                           ULONG ulSize);
     136                          uint32_t ulOffset,
     137                          uint32_t ulSize);
    590138
    591139void VBoxUnmapAdapterMemory (PVBOXVIDEO_COMMON pCommon, void **ppv);
     
    595143                        void *pvUser);
    596144
    597 void VBoxComputeFrameBufferSizes (PDEVICE_EXTENSION PrimaryExtension);
    598 
    599 
    600145/*
    601146 * Host and Guest port IO helpers.
    602147 */
    603 DECLINLINE(void) VBoxHGSMIHostWrite(PVBOXVIDEO_COMMON pCommon, ULONG data)
     148DECLINLINE(void) VBoxHGSMIHostWrite(PVBOXVIDEO_COMMON pCommon, uint32_t data)
    604149{
    605150    VBoxVideoCmnPortWriteUlong(pCommon->IOPortHost, data);
    606151}
    607152
    608 DECLINLINE(ULONG) VBoxHGSMIHostRead(PVBOXVIDEO_COMMON pCommon)
     153DECLINLINE(uint32_t) VBoxHGSMIHostRead(PVBOXVIDEO_COMMON pCommon)
    609154{
    610155    return VBoxVideoCmnPortReadUlong(pCommon->IOPortHost);
    611156}
    612157
    613 DECLINLINE(void) VBoxHGSMIGuestWrite(PVBOXVIDEO_COMMON pCommon, ULONG data)
     158DECLINLINE(void) VBoxHGSMIGuestWrite(PVBOXVIDEO_COMMON pCommon, uint32_t data)
    614159{
    615160    VBoxVideoCmnPortWriteUlong(pCommon->IOPortGuest, data);
    616161}
    617162
    618 DECLINLINE(ULONG) VBoxHGSMIGuestRead(PVBOXVIDEO_COMMON pCommon)
     163DECLINLINE(uint32_t) VBoxHGSMIGuestRead(PVBOXVIDEO_COMMON pCommon)
    619164{
    620165    return VBoxVideoCmnPortReadUlong(pCommon->IOPortGuest);
    621166}
    622167
    623 
    624 BOOLEAN VBoxHGSMIIsSupported (void);
     168bool VBoxHGSMIIsSupported (void);
    625169
    626170typedef int FNHGSMIFILLVIEWINFO (void *pvData, VBVAINFOVIEW *pInfo);
     
    629173int VBoxHGSMISendViewInfo(PVBOXVIDEO_COMMON pCommon, uint32_t u32Count, PFNHGSMIFILLVIEWINFO pfnFill, void *pvData);
    630174
    631 VOID VBoxSetupDisplaysHGSMI (PVBOXVIDEO_COMMON pCommon,
    632                              ULONG AdapterMemorySize, uint32_t fCaps);
    633 BOOLEAN vboxUpdatePointerShape (PVBOXVIDEO_COMMON pCommon,
    634                                 PVIDEO_POINTER_ATTRIBUTES pointerAttr,
    635                                 uint32_t cbLength);
     175void VBoxSetupDisplaysHGSMI (PVBOXVIDEO_COMMON pCommon,
     176                             uint32_t AdapterMemorySize, uint32_t fCaps);
     177
     178bool vboxUpdatePointerShape (PVBOXVIDEO_COMMON pCommon,
     179                             uint32_t fFlags,
     180                             uint32_t cHotX,
     181                             uint32_t cHotY,
     182                             uint32_t cWidth,
     183                             uint32_t cHeight,
     184                             uint8_t *pPixels,
     185                             uint32_t cbLength);
    636186
    637187void VBoxFreeDisplaysHGSMI(PVBOXVIDEO_COMMON pCommon);
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideoHGSMI.cpp

    r33997 r34079  
    1616 */
    1717
     18#include <string.h>
    1819
    1920#include "VBoxVideo.h"
     
    2728#include <VBox/VBoxVideo.h>
    2829
    29 #include <VBoxDisplay.h>
    30 
    31 #include "vboxioctl.h"
     30// #include <VBoxDisplay.h>
     31
     32// #include "vboxioctl.h"
    3233
    3334void HGSMINotifyHostCmdComplete (PVBOXVIDEO_COMMON pCommon, HGSMIOFFSET offt)
     
    9394
    9495/* Detect whether HGSMI is supported by the host. */
    95 BOOLEAN VBoxHGSMIIsSupported (void)
    96 {
    97     USHORT DispiId;
     96bool VBoxHGSMIIsSupported (void)
     97{
     98    uint16_t DispiId;
    9899
    99100    VBoxVideoCmnPortWriteUshort(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_ID);
     
    216217typedef struct _QUERYCONFCTX
    217218{
    218     uint32_t u32Index;
    219     ULONG *pulValue;
     219    uint32_t  u32Index;
     220    uint32_t *pulValue;
    220221} QUERYCONFCTX;
    221222
     
    245246}
    246247
    247 static int vboxQueryConfHGSMI (PVBOXVIDEO_COMMON pCommon, uint32_t u32Index, ULONG *pulValue)
     248static int vboxQueryConfHGSMI (PVBOXVIDEO_COMMON pCommon, uint32_t u32Index, uint32_t *pulValue)
    248249{
    249250    Log(("VBoxVideo::vboxQueryConf: u32Index = %d\n", u32Index));
     
    379380 * to talk to the host.
    380381 */
    381 VOID VBoxSetupDisplaysHGSMI(PVBOXVIDEO_COMMON pCommon,
    382                             ULONG AdapterMemorySize, uint32_t fCaps)
    383 {
    384     VP_STATUS rc = NO_ERROR;
     382void VBoxSetupDisplaysHGSMI(PVBOXVIDEO_COMMON pCommon,
     383                            uint32_t AdapterMemorySize, uint32_t fCaps)
     384{
     385    /** @todo I simply converted this from Windows error codes.  That is wrong,
     386     * but we currently freely mix and match those (failure == rc > 0) and iprt
     387     * ones (failure == rc < 0) anyway.  This needs to be fully reviewed and
     388     * fixed. */
     389    int rc = VINF_SUCCESS;
    385390
    386391    Log(("VBoxVideo::VBoxSetupDisplays: pCommon = %p\n", pCommon));
     
    402407
    403408        /* Map the adapter information. It will be needed for HGSMI IO. */
     409        /** @todo all callers of VBoxMapAdapterMemory expect it to use iprt
     410         * error codes, but it doesn't. */
    404411        rc = VBoxMapAdapterMemory (pCommon, &pCommon->pvAdapterInformation,
    405412                                   AdapterMemorySize - VBVA_ADAPTER_INFORMATION_SIZE,
    406413                                   VBVA_ADAPTER_INFORMATION_SIZE
    407414                                  );
    408         if (rc != NO_ERROR)
     415        if (RT_FAILURE(rc))
    409416        {
    410417            Log(("VBoxVideo::VBoxSetupDisplays: VBoxMapAdapterMemory pvAdapterInfoirrmation failed rc = %d\n",
    411418                     rc));
    412419
    413             pCommon->bHGSMI = FALSE;
     420            pCommon->bHGSMI = false;
    414421        }
    415422        else
     
    422429                                 false /*fOffsetBased*/);
    423430
    424             if (RT_FAILURE (rc))
     431            if (RT_FAILURE(rc))
    425432            {
    426433                Log(("VBoxVideo::VBoxSetupDisplays: HGSMIHeapSetup failed rc = %d\n",
    427434                         rc));
    428435
    429                 pCommon->bHGSMI = FALSE;
     436                pCommon->bHGSMI = false;
    430437            }
    431438            else
     
    441448    {
    442449        /* The miniport heap is used for the host buffers. */
    443         ULONG cbMiniportHeap = 0;
     450        uint32_t cbMiniportHeap = 0;
    444451        vboxQueryConfHGSMI (pCommon, VBOX_VBVA_CONF32_HOST_HEAP_SIZE, &cbMiniportHeap);
    445452
     
    447454        {
    448455            /* Do not allow too big heap. No more than 25% of VRAM is allowed. */
    449             ULONG cbMiniportHeapMaxSize = AdapterMemorySize / 4;
     456            uint32_t cbMiniportHeapMaxSize = AdapterMemorySize / 4;
    450457
    451458            if (cbMiniportHeapMaxSize >= VBVA_ADAPTER_INFORMATION_SIZE)
     
    477484                                       pCommon->cbMiniportHeap
    478485                                      );
    479             if (rc != NO_ERROR)
     486            if (RT_FAILURE(rc))
    480487            {
    481488                pCommon->pvMiniportHeap = NULL;
    482489                pCommon->cbMiniportHeap = 0;
    483                 pCommon->bHGSMI = FALSE;
     490                pCommon->bHGSMI = false;
    484491            }
    485492            else
     
    508515    {
    509516        /* Query the configured number of displays. */
    510         ULONG cDisplays = 0;
     517        uint32_t cDisplays = 0;
    511518        vboxQueryConfHGSMI (pCommon, VBOX_VBVA_CONF32_MONITOR_COUNT, &cDisplays);
    512519
     
    527534        rc = vboxSetupAdapterInfoHGSMI (pCommon);
    528535
    529         if (RT_FAILURE (rc))
    530         {
    531             pCommon->bHGSMI = FALSE;
     536        if (RT_FAILURE(rc))
     537        {
     538            pCommon->bHGSMI = false;
    532539        }
    533540    }
     
    539546}
    540547
    541 static bool VBoxUnmapAdpInfoCallback(PVOID pvCommon)
     548static bool VBoxUnmapAdpInfoCallback(void *pvCommon)
    542549{
    543550    PVBOXVIDEO_COMMON pCommon = (PVBOXVIDEO_COMMON)pvCommon;
    544551
    545552    pCommon->pHostFlags = NULL;
    546     return TRUE;
     553    return true;
    547554}
    548555
     
    562569typedef struct _MOUSEPOINTERSHAPECTX
    563570{
    564     VIDEO_POINTER_ATTRIBUTES *pPointerAttr;
     571    uint32_t fFlags;
     572    uint32_t cHotX;
     573    uint32_t cHotY;
     574    uint32_t cWidth;
     575    uint32_t cHeight;
    565576    uint32_t cbData;
    566     int32_t i32Result;
     577    uint8_t *pPixels;
     578    int32_t  i32Result;
    567579} MOUSEPOINTERSHAPECTX;
    568580
     
    576588
    577589    /* We have our custom flags in the field */
    578     p->fu32Flags = pCtx->pPointerAttr->Enable & 0x0000FFFF;
    579 
    580     p->u32HotX   = (pCtx->pPointerAttr->Enable >> 16) & 0xFF;
    581     p->u32HotY   = (pCtx->pPointerAttr->Enable >> 24) & 0xFF;
    582     p->u32Width  = pCtx->pPointerAttr->Width;
    583     p->u32Height = pCtx->pPointerAttr->Height;
     590    p->fu32Flags = pCtx->fFlags;
     591
     592    p->u32HotX   = pCtx->cHotX;
     593    p->u32HotY   = pCtx->cHotY;
     594    p->u32Width  = pCtx->cWidth;
     595    p->u32Height = pCtx->cHeight;
    584596
    585597    if (p->fu32Flags & VBOX_MOUSE_POINTER_SHAPE)
     
    591603
    592604        /* Copy the actual pointer data. */
    593         memcpy (p->au8Data, pCtx->pPointerAttr->Pixels, pCtx->cbData);
     605        memcpy (p->au8Data, pCtx->pPixels, pCtx->cbData);
    594606    }
    595607
     
    607619}
    608620
    609 BOOLEAN vboxUpdatePointerShape (PVBOXVIDEO_COMMON pCommon,
    610                                 PVIDEO_POINTER_ATTRIBUTES pointerAttr,
    611                                 uint32_t cbLength)
     621bool vboxUpdatePointerShape (PVBOXVIDEO_COMMON pCommon,
     622                             uint32_t fFlags,
     623                             uint32_t cHotX,
     624                             uint32_t cHotY,
     625                             uint32_t cWidth,
     626                             uint32_t cHeight,
     627                             uint8_t *pPixels,
     628                             uint32_t cbLength)
    612629{
    613630    uint32_t cbData = 0;
    614631
    615     if (pointerAttr->Enable & VBOX_MOUSE_POINTER_SHAPE)
     632    if (fFlags & VBOX_MOUSE_POINTER_SHAPE)
    616633    {
    617634        /* Size of the pointer data: sizeof (AND mask) + sizeof (XOR_MASK) */
    618         cbData = ((((pointerAttr->Width + 7) / 8) * pointerAttr->Height + 3) & ~3)
    619                  + pointerAttr->Width * 4 * pointerAttr->Height;
     635        cbData = ((((cWidth + 7) / 8) * cHeight + 3) & ~3)
     636                 + cWidth * 4 * cHeight;
    620637    }
    621638
    622639#ifndef DEBUG_misha
    623640    Log(("vboxUpdatePointerShape: cbData %d, %dx%d\n",
    624              cbData, pointerAttr->Width, pointerAttr->Height));
     641             cbData, cWidth, cHeight));
    625642#endif
    626643
    627     if (cbData > cbLength - sizeof(VIDEO_POINTER_ATTRIBUTES))
     644    if (cbData > cbLength)
    628645    {
    629646        Log(("vboxUpdatePointerShape: calculated pointer data size is too big (%d bytes, limit %d)\n",
    630                  cbData, cbLength - sizeof(VIDEO_POINTER_ATTRIBUTES)));
    631         return FALSE;
     647                 cbData, cbLength));
     648        return false;
    632649    }
    633650
    634651    MOUSEPOINTERSHAPECTX ctx;
    635652
    636     ctx.pPointerAttr = pointerAttr;
    637     ctx.cbData = cbData;
     653    ctx.fFlags    = fFlags;
     654    ctx.cHotX     = cHotX;
     655    ctx.cHotY     = cHotY;
     656    ctx.cWidth    = cWidth;
     657    ctx.cHeight   = cHeight;
     658    ctx.pPixels   = pPixels;
     659    ctx.cbData    = cbData;
    638660    ctx.i32Result = VERR_NOT_SUPPORTED;
    639661
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoCm.cpp

    r33540 r34079  
    1010 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    1111 */
    12 #include "../VBoxVideo.h"
     12#include "../VBoxVideo-win.h"
    1313#include "../Helper.h"
    1414
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoMisc.cpp

    r33531 r34079  
    1111 */
    1212
    13 #include "../VBoxVideo.h"
     13#include "../VBoxVideo-win.h"
    1414#include "../Helper.h"
    1515
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoShgsmi.cpp

    r33216 r34079  
    1111 */
    1212
    13 #include "../VBoxVideo.h"
     13#include "../VBoxVideo-win.h"
    1414#include "../Helper.h"
    1515
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVbva.cpp

    r33711 r34079  
    1616 */
    1717
    18 #include "../VBoxVideo.h"
     18#include "../VBoxVideo-win.h"
    1919#include "../Helper.h"
    2020
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVdma.cpp

    r33711 r34079  
    1111 */
    1212
    13 #include "../VBoxVideo.h"
     13#include "../VBoxVideo-win.h"
    1414#include "../Helper.h"
    1515
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVhwa.cpp

    r33714 r34079  
    1010 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    1111 */
    12 #include "../VBoxVideo.h"
     12#include "../VBoxVideo-win.h"
    1313#include "../Helper.h"
    1414
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVidPn.cpp

    r34018 r34079  
    1010 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    1111 */
    12 #include "../VBoxVideo.h"
     12#include "../VBoxVideo-win.h"
    1313#include "../Helper.h"
    1414
  • trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp

    r34018 r34079  
    1111 */
    1212
    13 #include "../VBoxVideo.h"
     13#include "../VBoxVideo-win.h"
    1414#include "../Helper.h"
    1515
     
    31813181        PointerAttributes.Enable = pSetPointerPosition->Flags.Visible ? VBOX_MOUSE_POINTER_VISIBLE : 0;
    31823182
    3183         BOOLEAN bResult = vboxUpdatePointerShape(commonFromDeviceExt(pDevExt), &PointerAttributes, sizeof (PointerAttributes));
     3183        BOOLEAN bResult = vboxUpdatePointerShapeWrap(commonFromDeviceExt(pDevExt), &PointerAttributes, sizeof (PointerAttributes));
    31843184        Assert(bResult);
    31853185    }
     
    32113211        if (vboxVddmPointerShapeToAttributes(pSetPointerShape, pPointerInfo))
    32123212        {
    3213             if (vboxUpdatePointerShape (commonFromDeviceExt(pDevExt), &pPointerInfo->Attributes.data, VBOXWDDM_POINTER_ATTRIBUTES_SIZE))
     3213            if (vboxUpdatePointerShapeWrap (commonFromDeviceExt(pDevExt), &pPointerInfo->Attributes.data, VBOXWDDM_POINTER_ATTRIBUTES_SIZE))
    32143214                Status = STATUS_SUCCESS;
    32153215            else
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