/*
 * Copyright 2024 Elizabeth Figura for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

import "unknwn.idl";

cpp_quote("#if 0")
typedef DWORD IDirect3DDevice9Ex, IDirect3DSurface9, D3DFORMAT, D3DPOOL;
cpp_quote("#endif")

typedef enum _DXVAHD_BLT_STATE
{
    DXVAHD_BLT_STATE_TARGET_RECT = 0,
    DXVAHD_BLT_STATE_BACKGROUND_COLOR = 1,
    DXVAHD_BLT_STATE_OUTPUT_COLOR_SPACE = 2,
    DXVAHD_BLT_STATE_ALPHA_FILL = 3,
    DXVAHD_BLT_STATE_CONSTRICTION = 4,
    DXVAHD_BLT_STATE_PRIVATE = 1000,
} DXVAHD_BLT_STATE;

typedef enum _DXVAHD_DEVICE_TYPE
{
    DXVAHD_DEVICE_TYPE_HARDWARE = 0,
    DXVAHD_DEVICE_TYPE_SOFTWARE = 1,
    DXVAHD_DEVICE_TYPE_REFERENCE = 2,
    DXVAHD_DEVICE_TYPE_OTHER = 3,
} DXVAHD_DEVICE_TYPE;

typedef enum _DXVAHD_DEVICE_USAGE
{
    DXVAHD_DEVICE_USAGE_PLAYBACK_NORMAL = 0,
    DXVAHD_DEVICE_USAGE_OPTIMAL_SPEED = 1,
    DXVAHD_DEVICE_USAGE_OPTIMAL_QUALITY = 2,
} DXVAHD_DEVICE_USAGE;

typedef enum _DXVAHD_FILTER
{
    DXVAHD_FILTER_BRIGHTNESS = 0,
    DXVAHD_FILTER_CONTRAST = 1,
    DXVAHD_FILTER_HUE = 2,
    DXVAHD_FILTER_SATURATION = 3,
    DXVAHD_FILTER_NOISE_REDUCTION = 4,
    DXVAHD_FILTER_EDGE_ENHANCEMENT = 5,
    DXVAHD_FILTER_ANAMORPHIC_SCALING = 6,
} DXVAHD_FILTER;

typedef enum _DXVAHD_FRAME_FORMAT
{
    DXVAHD_FRAME_FORMAT_PROGRESSIVE = 0,
    DXVAHD_FRAME_FORMAT_INTERLACED_TOP_FIELD_FIRST = 1,
    DXVAHD_FRAME_FORMAT_INTERLACED_BOTTOM_FIELD_FIRST = 2,
} DXVAHD_FRAME_FORMAT;

typedef enum _DXVAHD_STREAM_STATE
{
    DXVAHD_STREAM_STATE_D3DFORMAT = 0,
    DXVAHD_STREAM_STATE_FRAME_FORMAT = 1,
    DXVAHD_STREAM_STATE_INPUT_COLOR_SPACE = 2,
    DXVAHD_STREAM_STATE_OUTPUT_RATE = 3,
    DXVAHD_STREAM_STATE_SOURCE_RECT = 4,
    DXVAHD_STREAM_STATE_DESTINATION_RECT = 5,
    DXVAHD_STREAM_STATE_ALPHA = 6,
    DXVAHD_STREAM_STATE_PALETTE = 7,
    DXVAHD_STREAM_STATE_LUMA_KEY = 8,
    DXVAHD_STREAM_STATE_ASPECT_RATIO = 9,
    DXVAHD_STREAM_STATE_FILTER_BRIGHTNESS = 100,
    DXVAHD_STREAM_STATE_FILTER_CONTRAST = 101,
    DXVAHD_STREAM_STATE_FILTER_HUE = 102,
    DXVAHD_STREAM_STATE_FILTER_SATURATION = 103,
    DXVAHD_STREAM_STATE_FILTER_NOISE_REDUCTION = 104,
    DXVAHD_STREAM_STATE_FILTER_EDGE_ENHANCEMENT = 105,
    DXVAHD_STREAM_STATE_FILTER_ANAMORPHIC_SCALING = 106,
    DXVAHD_STREAM_STATE_PRIVATE = 1000,
} DXVAHD_STREAM_STATE;

typedef enum _DXVAHD_SURFACE_TYPE
{
    DXVAHD_SURFACE_TYPE_VIDEO_INPUT = 0,
    DXVAHD_SURFACE_TYPE_VIDEO_INPUT_PRIVATE = 1,
    DXVAHD_SURFACE_TYPE_VIDEO_OUTPUT = 2,
} DXVAHD_SURFACE_TYPE;

typedef struct _DXVAHD_RATIONAL
{
    UINT Numerator;
    UINT Denominator;
} DXVAHD_RATIONAL;

typedef struct _DXVAHD_CONTENT_DESC
{
    DXVAHD_FRAME_FORMAT InputFrameFormat;
    DXVAHD_RATIONAL InputFrameRate;
    UINT InputWidth;
    UINT InputHeight;
    DXVAHD_RATIONAL OutputFrameRate;
    UINT OutputWidth;
    UINT OutputHeight;
} DXVAHD_CONTENT_DESC;

typedef struct _DXVAHD_CUSTOM_RATE_DATA
{
    DXVAHD_RATIONAL CustomRate;
    UINT OutputFrames;
    BOOL InputInterlaced;
    UINT InputFramesOrFields;
} DXVAHD_CUSTOM_RATE_DATA;

typedef struct _DXVAHD_FILTER_RANGE_DATA
{
    INT Minimum;
    INT Maximum;
    INT Default;
    FLOAT Multiplier;
} DXVAHD_FILTER_RANGE_DATA;

typedef struct _DXVAHD_STREAM_DATA
{
    BOOL Enable;
    UINT OutputIndex;
    UINT InputFrameOrField;
    UINT PastFrames;
    UINT FutureFrames;
    IDirect3DSurface9 **ppPastSurfaces;
    IDirect3DSurface9 *pInputSurface;
    IDirect3DSurface9 **ppFutureSurfaces;
} DXVAHD_STREAM_DATA;

typedef struct _DXVAHD_VPDEVCAPS
{
    DXVAHD_DEVICE_TYPE DeviceType;
    UINT DeviceCaps;
    UINT FeatureCaps;
    UINT FilterCaps;
    UINT InputFormatCaps;
    D3DPOOL InputPool;
    UINT OutputFormatCount;
    UINT InputFormatCount;
    UINT VideoProcessorCount;
    UINT MaxInputStreams;
    UINT MaxStreamStates;
} DXVAHD_VPDEVCAPS;

typedef struct _DXVAHD_VPCAPS
{
    GUID VPGuid;
    UINT PastFrames;
    UINT FutureFrames;
    UINT ProcessorCaps;
    UINT ITelecineCaps;
    UINT CustomRateCount;
} DXVAHD_VPCAPS;

typedef HRESULT (__stdcall *PDXVAHDSW_Plugin)(UINT size, void *callbacks);

[
    object,
    local,
    uuid(95f4edf4-6e03-4cd7-be1b-3075d665aa52),
]
interface IDXVAHD_VideoProcessor : IUnknown
{
    HRESULT SetVideoProcessBltState(DXVAHD_BLT_STATE state, UINT size, const void *data);
    HRESULT GetVideoProcessBltState(DXVAHD_BLT_STATE state, UINT size, void *data);
    HRESULT SetVideoProcessStreamState(UINT stream_idx, DXVAHD_STREAM_STATE state, UINT size, const void *data);
    HRESULT GetVideoProcessStreamState(UINT stream_idx, DXVAHD_STREAM_STATE state, UINT size, void *data);
    HRESULT VideoProcessBltHD(IDirect3DSurface9 *surface, UINT frame_idx,
            UINT stream_count, const DXVAHD_STREAM_DATA *streams);
}

[
    object,
    local,
    uuid(95f12dfd-d77e-49be-815f-57d579634d6d),
]
interface IDXVAHD_Device : IUnknown
{
    HRESULT CreateVideoSurface(UINT width, UINT height, D3DFORMAT format, D3DPOOL pool, DWORD usage,
            DXVAHD_SURFACE_TYPE type, UINT count, IDirect3DSurface9 **surfaces, HANDLE *shared_handle);
    HRESULT GetVideoProcessorDeviceCaps(DXVAHD_VPDEVCAPS *caps);
    HRESULT GetVideoProcessorOutputFormats(UINT count, D3DFORMAT *formats);
    HRESULT GetVideoProcessorInputFormats(UINT count, D3DFORMAT *formats);
    HRESULT GetVideoProcessorCaps(UINT count, DXVAHD_VPCAPS *caps);
    HRESULT GetVideoProcessorCustomRates(const GUID *guid, UINT count, DXVAHD_CUSTOM_RATE_DATA *rates);
    HRESULT GetVideoProcessorFilterRange(DXVAHD_FILTER filter, DXVAHD_FILTER_RANGE_DATA *range);
    HRESULT CreateVideoProcessor(const GUID *guid, IDXVAHD_VideoProcessor **processor);
}

HRESULT __stdcall DXVAHD_CreateDevice(IDirect3DDevice9Ex *d3d9_device, const DXVAHD_CONTENT_DESC *desc,
        DXVAHD_DEVICE_USAGE usage, PDXVAHDSW_Plugin plugin, IDXVAHD_Device **device);
