// Copyright (c) Microsoft Corporation.  All Rights Reserved

import "dxgi.idl";

cpp_quote("#include <winapifamily.h>")

#pragma region Desktop Family
cpp_quote("#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)")

[
    object,
    uuid( ea9dbf1a-c88e-4486-854a-98aa0138f30c ),
    local,
    pointer_default(unique)
]
interface IDXGIDisplayControl :
    IUnknown
{
    BOOL IsStereoEnabled();
    void SetStereoEnabled(BOOL enabled);
};

    //--------------------------------------------------------------------------------------------------------
// IDXGIOutputDuplication structures
//--------------------------------------------------------------------------------------------------------
typedef struct DXGI_OUTDUPL_MOVE_RECT
{
    POINT   SourcePoint;
    RECT    DestinationRect;
} DXGI_OUTDUPL_MOVE_RECT;

typedef struct DXGI_OUTDUPL_DESC
{
    DXGI_MODE_DESC        ModeDesc;
    DXGI_MODE_ROTATION    Rotation;
    BOOL                  DesktopImageInSystemMemory;
} DXGI_OUTDUPL_DESC;

typedef struct DXGI_OUTDUPL_POINTER_POSITION
{
    POINT   Position;
    BOOL    Visible;
} DXGI_OUTDUPL_POINTER_POSITION;

typedef enum DXGI_OUTDUPL_POINTER_SHAPE_TYPE
{
    DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MONOCHROME     = 0x00000001,
    DXGI_OUTDUPL_POINTER_SHAPE_TYPE_COLOR          = 0x00000002,
    DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MASKED_COLOR   = 0x00000004
} DXGI_OUTDUPL_POINTER_SHAPE_TYPE;

typedef struct DXGI_OUTDUPL_POINTER_SHAPE_INFO
{
    UINT    Type;
    UINT    Width;
    UINT    Height;
    UINT    Pitch;
    POINT   HotSpot;
} DXGI_OUTDUPL_POINTER_SHAPE_INFO;

typedef struct DXGI_OUTDUPL_FRAME_INFO
{
    LARGE_INTEGER                       LastPresentTime;
    LARGE_INTEGER                       LastMouseUpdateTime;
    UINT                                AccumulatedFrames;
    BOOL                                RectsCoalesced;
    BOOL                                ProtectedContentMaskedOut;
    DXGI_OUTDUPL_POINTER_POSITION       PointerPosition;
    UINT                                TotalMetadataBufferSize;
    UINT                                PointerShapeBufferSize;
} DXGI_OUTDUPL_FRAME_INFO;

//--------------------------------------------------------------------------------------------------------
// IDXGIOutputDuplication interface
//--------------------------------------------------------------------------------------------------------
[
    object,
    uuid(191cfac3-a341-470d-b26e-a864f428319c),
    local,
    pointer_default(unique)
]
interface IDXGIOutputDuplication :
    IDXGIObject
{
    void GetDesc([out, annotation ("_Out_")] DXGI_OUTDUPL_DESC* pDesc);
    HRESULT AcquireNextFrame([in, annotation ("_In_")] UINT TimeoutInMilliseconds,
                             [out, annotation("_Out_")] DXGI_OUTDUPL_FRAME_INFO* pFrameInfo,
                             [out, annotation("_COM_Outptr_")] IDXGIResource** ppDesktopResource);
    HRESULT GetFrameDirtyRects([in, annotation("_In_")] UINT DirtyRectsBufferSize,
                               [out, annotation("_Out_writes_bytes_to_(DirtyRectsBufferSize, *pDirtyRectsBufferSizeRequired)")] RECT* pDirtyRectsBuffer,
                               [out, annotation("_Out_")] UINT* pDirtyRectsBufferSizeRequired);
    HRESULT GetFrameMoveRects([in, annotation("_In_")] UINT MoveRectsBufferSize,
                              [out, annotation("_Out_writes_bytes_to_(MoveRectsBufferSize, *pMoveRectsBufferSizeRequired)")] DXGI_OUTDUPL_MOVE_RECT* pMoveRectBuffer,
                              [out, annotation("_Out_")] UINT* pMoveRectsBufferSizeRequired);
    HRESULT GetFramePointerShape([in, annotation("_In_")] UINT PointerShapeBufferSize,
                                 [out, annotation("_Out_writes_bytes_to_(PointerShapeBufferSize, *pPointerShapeBufferSizeRequired)")] void* pPointerShapeBuffer,
                                 [out, annotation("_Out_")] UINT* pPointerShapeBufferSizeRequired,
                                 [out, annotation("_Out_")] DXGI_OUTDUPL_POINTER_SHAPE_INFO* pPointerShapeInfo);
    HRESULT MapDesktopSurface([out, annotation("_Out_")] DXGI_MAPPED_RECT* pLockedRect);
    HRESULT UnMapDesktopSurface();
    HRESULT ReleaseFrame();
};
cpp_quote("#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */")
#pragma endregion

#pragma region App Family
cpp_quote("#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)")

typedef enum DXGI_ALPHA_MODE
{
    DXGI_ALPHA_MODE_UNSPECIFIED = 0,
    DXGI_ALPHA_MODE_PREMULTIPLIED = 1,
    DXGI_ALPHA_MODE_STRAIGHT = 2,
    DXGI_ALPHA_MODE_IGNORE = 3,
    DXGI_ALPHA_MODE_FORCE_DWORD = 0xffffffff
} DXGI_ALPHA_MODE;

[
    object,
    uuid(aba496dd-b617-4cb8-a866-bc44d7eb1fa2),
    local,
    pointer_default(unique)
]
interface IDXGISurface2 :
    IDXGISurface1
{
    HRESULT GetResource([in, annotation("_In_")] REFIID riid,
                        [out, annotation("_COM_Outptr_")] void **ppParentResource,
                        [out, annotation("_Out_")] UINT *pSubresourceIndex);
};

[
    object,
    uuid(30961379-4609-4a41-998e-54fe567ee0c1),
    local,
    pointer_default(unique)
]
interface IDXGIResource1 :
    IDXGIResource
{
    HRESULT CreateSubresourceSurface(
        UINT index,
        [out, annotation("_COM_Outptr_")] IDXGISurface2 **ppSurface );

    HRESULT CreateSharedHandle(
        [in, annotation("_In_opt_")] const SECURITY_ATTRIBUTES *pAttributes,
        [in, annotation("_In_")] DWORD dwAccess,
        [in, annotation("_In_opt_")] LPCWSTR lpName,
        [out, annotation("_Out_")] HANDLE *pHandle);
};

typedef enum _DXGI_OFFER_RESOURCE_PRIORITY
{
    DXGI_OFFER_RESOURCE_PRIORITY_LOW=1,
    DXGI_OFFER_RESOURCE_PRIORITY_NORMAL,
    DXGI_OFFER_RESOURCE_PRIORITY_HIGH,
} DXGI_OFFER_RESOURCE_PRIORITY;

[
    object,
    uuid( 05008617-fbfd-4051-a790-144884b4f6a9 ),
    local,
    pointer_default(unique)
]
interface IDXGIDevice2 :
    IDXGIDevice1
{
    HRESULT OfferResources(
        [in, annotation("_In_")] UINT NumResources,
        [in, size_is(NumResources), annotation("_In_reads_(NumResources)")] IDXGIResource *const *ppResources,
        [in, annotation("_In_")] DXGI_OFFER_RESOURCE_PRIORITY Priority);
    HRESULT ReclaimResources(
        [in, annotation("_In_")] UINT NumResources,
        [in, size_is(NumResources), annotation("_In_reads_(NumResources)")] IDXGIResource *const *ppResources,
        [out, size_is(NumResources), annotation("_Out_writes_all_opt_(NumResources)")] BOOL *pDiscarded);
    HRESULT EnqueueSetEvent( [in, annotation("_In_")] HANDLE hEvent );
};

const UINT DXGI_ENUM_MODES_STEREO = 4UL;
const UINT DXGI_ENUM_MODES_DISABLED_STEREO = 8UL;

const DWORD DXGI_SHARED_RESOURCE_READ = 0x80000000L;
const DWORD DXGI_SHARED_RESOURCE_WRITE = 1;

typedef struct DXGI_MODE_DESC1
{
    UINT Width;
    UINT Height;
    DXGI_RATIONAL RefreshRate;
    DXGI_FORMAT Format;
    DXGI_MODE_SCANLINE_ORDER ScanlineOrdering;
    DXGI_MODE_SCALING Scaling;
    BOOL Stereo;
} DXGI_MODE_DESC1;

//--------------------------------------------------------------------------------------------------------
// IDXGISwapchain1 structures
//--------------------------------------------------------------------------------------------------------
typedef enum DXGI_SCALING
{
    DXGI_SCALING_STRETCH = 0,
    DXGI_SCALING_NONE = 1,
    DXGI_SCALING_ASPECT_RATIO_STRETCH = 2,
} DXGI_SCALING;

typedef struct DXGI_SWAP_CHAIN_DESC1
{
    UINT              Width;
    UINT              Height;
    DXGI_FORMAT       Format;
    BOOL              Stereo;
    DXGI_SAMPLE_DESC  SampleDesc;
    DXGI_USAGE        BufferUsage;
    UINT              BufferCount;
    DXGI_SCALING      Scaling;
    DXGI_SWAP_EFFECT  SwapEffect;
    DXGI_ALPHA_MODE   AlphaMode;
    UINT              Flags; // DXGI_SWAP_CHAIN_FLAG
} DXGI_SWAP_CHAIN_DESC1;

typedef struct DXGI_SWAP_CHAIN_FULLSCREEN_DESC
{
    DXGI_RATIONAL RefreshRate;
    DXGI_MODE_SCANLINE_ORDER ScanlineOrdering;
    DXGI_MODE_SCALING Scaling;
    BOOL Windowed;
} DXGI_SWAP_CHAIN_FULLSCREEN_DESC;

typedef struct DXGI_PRESENT_PARAMETERS
{
    UINT DirtyRectsCount;
    [annotation("_Field_size_full_opt_(DirtyRectsCount)")] RECT* pDirtyRects;
    RECT* pScrollRect;
    POINT* pScrollOffset;
} DXGI_PRESENT_PARAMETERS;

//--------------------------------------------------------------------------------------------------------
// IDXGISwapchain1 interface
//--------------------------------------------------------------------------------------------------------
[
    object,
    uuid( 790a45f7-0d42-4876-983a-0a55cfe6f4aa ),
    local,
    pointer_default(unique)
]
interface IDXGISwapChain1 :
    IDXGISwapChain
{
    HRESULT GetDesc1( [out, annotation("_Out_")] DXGI_SWAP_CHAIN_DESC1 *pDesc );
    HRESULT GetFullscreenDesc( [out, annotation("_Out_")] DXGI_SWAP_CHAIN_FULLSCREEN_DESC *pDesc );

    HRESULT GetHwnd( [out, annotation("_Out_")] HWND *pHwnd);
    HRESULT GetCoreWindow (
            [in, annotation("_In_")] REFIID refiid,
            [out, annotation("_COM_Outptr_")] void **ppUnk);

    HRESULT Present1(
        [in] UINT SyncInterval,
        [in] UINT PresentFlags,
        [in, annotation("_In_")] const DXGI_PRESENT_PARAMETERS* pPresentParameters );
    BOOL IsTemporaryMonoSupported();
    HRESULT GetRestrictToOutput( [out, annotation("_Out_")] IDXGIOutput** ppRestrictToOutput );
    HRESULT SetBackgroundColor( [in, annotation("_In_")] const DXGI_RGBA* pColor );
    HRESULT GetBackgroundColor( [out, annotation("_Out_")] DXGI_RGBA* pColor );
    HRESULT SetRotation( [in, annotation("_In_")] DXGI_MODE_ROTATION Rotation );
    HRESULT GetRotation( [out, annotation("_Out_")] DXGI_MODE_ROTATION* pRotation );
};

//--------------------------------------------------------------------------------------------------------
// IDXGIFactory2 interface
//--------------------------------------------------------------------------------------------------------
[
    object,
    uuid( 50c83a1c-e072-4c48-87b0-3630fa36a6d0 ),
    local,
    pointer_default(unique)
]
interface IDXGIFactory2 :
    IDXGIFactory1
{
    BOOL IsWindowedStereoEnabled();

    HRESULT CreateSwapChainForHwnd(
        [in, annotation("_In_")] IUnknown *pDevice,
        [in, annotation("_In_")] HWND hWnd,
        [in, annotation("_In_")] const DXGI_SWAP_CHAIN_DESC1 *pDesc,
        [in, annotation("_In_opt_")] const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *pFullscreenDesc,
        [in, annotation("_In_opt_")] IDXGIOutput *pRestrictToOutput,
        [out, annotation("_COM_Outptr_")] IDXGISwapChain1 **ppSwapChain );

    HRESULT CreateSwapChainForCoreWindow(
        [in, annotation("_In_")] IUnknown *pDevice,
        [in, annotation("_In_")] IUnknown *pWindow,
        [in, annotation("_In_")] const DXGI_SWAP_CHAIN_DESC1 *pDesc,
        [in, annotation("_In_opt_")] IDXGIOutput *pRestrictToOutput,
        [out, annotation("_COM_Outptr_")] IDXGISwapChain1 **ppSwapChain );

    HRESULT GetSharedResourceAdapterLuid(
        [annotation("_In_")] HANDLE hResource,
        [annotation("_Out_")] LUID* pLuid);

    HRESULT RegisterStereoStatusWindow(
        [in, annotation("_In_")] HWND WindowHandle,
        [in, annotation("_In_")] UINT wMsg,
        [out, annotation("_Out_")] DWORD *pdwCookie );

    HRESULT RegisterStereoStatusEvent(
        [in, annotation("_In_")] HANDLE hEvent,
        [out, annotation("_Out_")] DWORD *pdwCookie );

    void UnregisterStereoStatus(
        [in, annotation("_In_")] DWORD dwCookie );

    HRESULT RegisterOcclusionStatusWindow(
        [in, annotation("_In_")] HWND WindowHandle,
        [in, annotation("_In_")] UINT wMsg,
        [out, annotation("_Out_")] DWORD *pdwCookie );

    HRESULT RegisterOcclusionStatusEvent(
        [in, annotation("_In_")] HANDLE hEvent,
        [out, annotation("_Out_")] DWORD *pdwCookie );

    void UnregisterOcclusionStatus(
        [in, annotation("_In_")] DWORD dwCookie );

    HRESULT CreateSwapChainForComposition(
        [in, annotation("_In_")] IUnknown *pDevice,
        [in, annotation("_In_")] const DXGI_SWAP_CHAIN_DESC1 *pDesc,
        [in, annotation("_In_opt_")] IDXGIOutput *pRestrictToOutput,
        [out, annotation("_COM_Outptr_")] IDXGISwapChain1 **ppSwapChain );
};

//--------------------------------------------------------------------------------------------------------
// IDXGIAdapter2 structures
//--------------------------------------------------------------------------------------------------------
typedef enum DXGI_GRAPHICS_PREEMPTION_GRANULARITY
{
    DXGI_GRAPHICS_PREEMPTION_DMA_BUFFER_BOUNDARY    = 0,
    DXGI_GRAPHICS_PREEMPTION_PRIMITIVE_BOUNDARY     = 1,
    DXGI_GRAPHICS_PREEMPTION_TRIANGLE_BOUNDARY      = 2,
    DXGI_GRAPHICS_PREEMPTION_PIXEL_BOUNDARY         = 3,
    DXGI_GRAPHICS_PREEMPTION_INSTRUCTION_BOUNDARY   = 4,
} DXGI_GRAPHICS_PREEMPTION_GRANULARITY;

typedef enum DXGI_COMPUTE_PREEMPTION_GRANULARITY
{
    DXGI_COMPUTE_PREEMPTION_DMA_BUFFER_BOUNDARY      = 0,
    DXGI_COMPUTE_PREEMPTION_DISPATCH_BOUNDARY        = 1,
    DXGI_COMPUTE_PREEMPTION_THREAD_GROUP_BOUNDARY    = 2,
    DXGI_COMPUTE_PREEMPTION_THREAD_BOUNDARY          = 3,
    DXGI_COMPUTE_PREEMPTION_INSTRUCTION_BOUNDARY     = 4,
} DXGI_COMPUTE_PREEMPTION_GRANULARITY;

typedef struct DXGI_ADAPTER_DESC2
{
    WCHAR Description[128];

    UINT VendorId;
    UINT DeviceId;
    UINT SubSysId;
    UINT Revision;

    SIZE_T DedicatedVideoMemory;
    SIZE_T DedicatedSystemMemory;
    SIZE_T SharedSystemMemory;

    LUID AdapterLuid;

    UINT Flags;

    DXGI_GRAPHICS_PREEMPTION_GRANULARITY GraphicsPreemptionGranularity;
    DXGI_COMPUTE_PREEMPTION_GRANULARITY ComputePreemptionGranularity;
} DXGI_ADAPTER_DESC2;

//--------------------------------------------------------------------------------------------------------
// IDXGIAdapter2 interface
//--------------------------------------------------------------------------------------------------------
[
    object,
    uuid(0AA1AE0A-FA0E-4B84-8644-E05FF8E5ACB5),
    local,
    pointer_default(unique)
]
interface IDXGIAdapter2 :
    IDXGIAdapter1
{
    HRESULT GetDesc2( [out, annotation("_Out_")] DXGI_ADAPTER_DESC2 *pDesc);
};

//--------------------------------------------------------------------------------------------------------
// IDXGIOutput1
//--------------------------------------------------------------------------------------------------------
[
    object,
    uuid(00cddea8-939b-4b83-a340-a685226666cc),
    local,
    pointer_default(unique)
]
interface IDXGIOutput1 :
    IDXGIOutput
{
    HRESULT GetDisplayModeList1(
        [in] DXGI_FORMAT EnumFormat,
        [in] UINT Flags,
        [in, out, annotation("_Inout_")] UINT * pNumModes,
        [out, annotation("_Out_writes_to_opt_(*pNumModes,*pNumModes)")] DXGI_MODE_DESC1 *pDesc);
    HRESULT FindClosestMatchingMode1(
        [in, annotation("_In_")] const DXGI_MODE_DESC1 *pModeToMatch,
        [out, annotation("_Out_")] DXGI_MODE_DESC1 *pClosestMatch,
        [in, annotation("_In_opt_")] IUnknown * pConcernedDevice );
    HRESULT GetDisplaySurfaceData1( [in, annotation("_In_")] IDXGIResource *pDestination );
    HRESULT DuplicateOutput([in, annotation("_In_")] IUnknown    *pDevice,
                            [out, annotation("_COM_Outptr_")] IDXGIOutputDuplication **ppOutputDuplication);
};

cpp_quote("#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */")
#pragma endregion

cpp_quote( "DEFINE_GUID(IID_IDXGIDisplayControl,0xea9dbf1a,0xc88e,0x4486,0x85,0x4a,0x98,0xaa,0x01,0x38,0xf3,0x0c);" )
cpp_quote( "DEFINE_GUID(IID_IDXGIOutputDuplication,0x191cfac3,0xa341,0x470d,0xb2,0x6e,0xa8,0x64,0xf4,0x28,0x31,0x9c);" )
cpp_quote( "DEFINE_GUID(IID_IDXGISurface2,0xaba496dd,0xb617,0x4cb8,0xa8,0x66,0xbc,0x44,0xd7,0xeb,0x1f,0xa2);" )
cpp_quote( "DEFINE_GUID(IID_IDXGIResource1,0x30961379,0x4609,0x4a41,0x99,0x8e,0x54,0xfe,0x56,0x7e,0xe0,0xc1);" )
cpp_quote( "DEFINE_GUID(IID_IDXGIDevice2,0x05008617,0xfbfd,0x4051,0xa7,0x90,0x14,0x48,0x84,0xb4,0xf6,0xa9);" )
cpp_quote( "DEFINE_GUID(IID_IDXGISwapChain1,0x790a45f7,0x0d42,0x4876,0x98,0x3a,0x0a,0x55,0xcf,0xe6,0xf4,0xaa);" )
cpp_quote( "DEFINE_GUID(IID_IDXGIFactory2,0x50c83a1c,0xe072,0x4c48,0x87,0xb0,0x36,0x30,0xfa,0x36,0xa6,0xd0);" )
cpp_quote( "DEFINE_GUID(IID_IDXGIAdapter2,0x0AA1AE0A,0xFA0E,0x4B84,0x86,0x44,0xE0,0x5F,0xF8,0xE5,0xAC,0xB5);" )
cpp_quote( "DEFINE_GUID(IID_IDXGIOutput1,0x00cddea8,0x939b,0x4b83,0xa3,0x40,0xa6,0x85,0x22,0x66,0x66,0xcc);" )
