1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-26 10:29:23 +01:00
cnc-ddraw/src/IDirectDraw/IDirectDraw.c

401 lines
14 KiB
C
Raw Normal View History

2020-10-13 09:20:52 +02:00
#include <initguid.h>
#include "IDirectDraw.h"
2020-10-14 00:42:42 +02:00
#include "IDirect3D.h"
2020-10-13 09:20:52 +02:00
#include "dd.h"
#include "ddclipper.h"
#include "ddpalette.h"
#include "ddsurface.h"
#include "debug.h"
HRESULT __stdcall IDirectDraw__QueryInterface(IDirectDrawImpl* This, REFIID riid, void** obj)
{
dprintf("-> %s(This=%p, riid=%08X, obj=%p)\n", __FUNCTION__, This, (unsigned int)riid, obj);
HRESULT ret = DDERR_UNSUPPORTED;
if (riid)
{
if (IsEqualGUID(&IID_IDirectDraw2, riid) ||
IsEqualGUID(&IID_IDirectDraw4, riid) ||
IsEqualGUID(&IID_IDirectDraw7, riid))
{
dprintf(" GUID = %08X (IID_IDirectDrawX)\n", ((GUID*)riid)->Data1);
IDirectDrawImpl* dd = (IDirectDrawImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawImpl));
dd->lpVtbl = &g_dd_vtblx;
*obj = dd;
IDirectDraw_AddRef(dd);
2020-10-13 21:58:04 +02:00
2020-10-13 09:20:52 +02:00
ret = S_OK;
}
2020-10-14 00:42:42 +02:00
else if (IsEqualGUID(&IID_IDirectDraw, riid))
{
dprintf(" GUID = %08X (IID_IDirectDraw)\n", ((GUID*)riid)->Data1);
IDirectDrawImpl* dd = (IDirectDrawImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawImpl));
dd->lpVtbl = &g_dd_vtbl1;
*obj = dd;
IDirectDraw_AddRef(dd);
ret = S_OK;
}
else if (IsEqualGUID(&IID_IDirect3D, riid))
{
dprintf(" GUID = %08X (IID_IDirect3D)\n", ((GUID*)riid)->Data1);
IDirect3DImpl* d3d = (IDirect3DImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawImpl));
d3d->lpVtbl = &g_d3d_vtbl1;
*obj = d3d;
d3d->lpVtbl->AddRef(d3d);
ret = S_OK;
}
else if (IsEqualGUID(&IID_IDirect3D2, riid) || IsEqualGUID(&IID_IDirect3D3, riid) || IsEqualGUID(&IID_IDirect3D7, riid))
{
dprintf(" GUID = %08X (IID_IDirect3DX)\n", ((GUID*)riid)->Data1);
}
2020-10-13 09:20:52 +02:00
else
{
dprintf(" GUID = %08X\n", ((GUID*)riid)->Data1);
}
ret = S_OK;
}
dprintf("<- %s\n", __FUNCTION__);
return ret;
}
ULONG __stdcall IDirectDraw__AddRef(IDirectDrawImpl* This)
{
dprintf("-> %s(This=%p)\n", __FUNCTION__, This);
ULONG ret = ++This->ref;
ULONG glob_ref = dd_AddRef();
dprintf("<- %s(This ref=%u, global ref=%u)\n", __FUNCTION__, ret, glob_ref);
return ret;
}
ULONG __stdcall IDirectDraw__Release(IDirectDrawImpl* This)
{
dprintf("-> %s(This=%p)\n", __FUNCTION__, This);
ULONG ret = --This->ref;
if (This->ref == 0)
{
dprintf(" Released (%p)\n", This);
2020-10-13 21:58:04 +02:00
2020-10-13 09:20:52 +02:00
HeapFree(GetProcessHeap(), 0, This);
}
ULONG glob_ref = dd_Release();
dprintf("<- %s(This ref=%u, global ref=%u)\n", __FUNCTION__, ret, glob_ref);
return ret;
}
HRESULT __stdcall IDirectDraw__Compact(IDirectDrawImpl* This)
{
dprintf("NOT_IMPLEMENTED -> %s(This=%p)\n", __FUNCTION__, This);
HRESULT ret = DD_OK;
dprintf("NOT_IMPLEMENTED <- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__CreateClipper(IDirectDrawImpl* This, DWORD dwFlags, LPDIRECTDRAWCLIPPER FAR* lplpDDClipper, IUnknown FAR* pUnkOuter)
{
dprintf("-> %s(This=%p, dwFlags=%08X, DDClipper=%p, unkOuter=%p)\n", __FUNCTION__, This, (int)dwFlags, lplpDDClipper, pUnkOuter);
HRESULT ret = dd_CreateClipper(dwFlags, lplpDDClipper, pUnkOuter);
dprintf("<- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__CreatePalette(IDirectDrawImpl* This, DWORD dwFlags, LPPALETTEENTRY lpDDColorArray, LPDIRECTDRAWPALETTE FAR* lpDDPalette, IUnknown FAR* unkOuter)
{
dprintf("-> %s(This=%p, dwFlags=%08X, DDColorArray=%p, DDPalette=%p, unkOuter=%p)\n", __FUNCTION__, This, (int)dwFlags, lpDDColorArray, lpDDPalette, unkOuter);
HRESULT ret = dd_CreatePalette(dwFlags, lpDDColorArray, lpDDPalette, unkOuter);
dprintf("<- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__CreateSurface(IDirectDrawImpl* This, LPDDSURFACEDESC lpDDSurfaceDesc, LPDIRECTDRAWSURFACE FAR* lpDDSurface, IUnknown FAR* unkOuter)
{
dprintf("-> %s(This=%p, lpDDSurfaceDesc=%p, lpDDSurface=%p, unkOuter=%p)\n", __FUNCTION__, This, lpDDSurfaceDesc, lpDDSurface, unkOuter);
HRESULT ret = dd_CreateSurface(lpDDSurfaceDesc, lpDDSurface, unkOuter);
dprintf("<- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__DuplicateSurface(IDirectDrawImpl* This, LPDIRECTDRAWSURFACE src, LPDIRECTDRAWSURFACE* dest)
{
dprintf("NOT_IMPLEMENTED -> %s(This=%p)\n", __FUNCTION__, This);
HRESULT ret = DD_OK;
dprintf("NOT_IMPLEMENTED <- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__EnumDisplayModes(IDirectDrawImpl* This, DWORD dwFlags, LPDDSURFACEDESC lpDDSurfaceDesc, LPVOID lpContext, LPDDENUMMODESCALLBACK lpEnumModesCallback)
{
dprintf("-> %s(This=%p, dwFlags=%08X, lpDDSurfaceDesc=%p, lpContext=%p, lpEnumModesCallback=%p)\n", __FUNCTION__, This, (unsigned int)dwFlags, lpDDSurfaceDesc, lpContext, lpEnumModesCallback);
HRESULT ret = dd_EnumDisplayModes(dwFlags, lpDDSurfaceDesc, lpContext, lpEnumModesCallback);
dprintf("<- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__EnumSurfaces(IDirectDrawImpl* This, DWORD a, LPDDSURFACEDESC b, LPVOID c, LPDDENUMSURFACESCALLBACK d)
{
dprintf("NOT_IMPLEMENTED -> %s(This=%p)\n", __FUNCTION__, This);
HRESULT ret = DD_OK;
dprintf("NOT_IMPLEMENTED <- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__FlipToGDISurface(IDirectDrawImpl* This)
{
dprintf("NOT_IMPLEMENTED -> %s(This=%p)\n", __FUNCTION__, This);
HRESULT ret = DD_OK;
dprintf("NOT_IMPLEMENTED <- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__GetCaps(IDirectDrawImpl* This, LPDDCAPS lpDDDriverCaps, LPDDCAPS lpDDEmulCaps)
{
dprintf("-> %s(This=%p, lpDDDriverCaps=%p, lpDDEmulCaps=%p)\n", __FUNCTION__, This, lpDDDriverCaps, lpDDEmulCaps);
HRESULT ret = dd_GetCaps(lpDDDriverCaps, lpDDEmulCaps);
dprintf("<- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__GetDisplayMode(IDirectDrawImpl* This, LPDDSURFACEDESC a)
{
dprintf("NOT_IMPLEMENTED -> %s(This=%p)\n", __FUNCTION__, This);
HRESULT ret = DDERR_UNSUPPORTEDMODE;
dprintf("NOT_IMPLEMENTED <- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__GetFourCCCodes(IDirectDrawImpl* This, LPDWORD a, LPDWORD b)
{
dprintf("NOT_IMPLEMENTED -> %s(This=%p)\n", __FUNCTION__, This);
HRESULT ret = DD_OK;
dprintf("NOT_IMPLEMENTED <- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__GetGDISurface(IDirectDrawImpl* This, LPDIRECTDRAWSURFACE* a)
{
dprintf("NOT_IMPLEMENTED -> %s(This=%p)\n", __FUNCTION__, This);
HRESULT ret = DD_OK;
dprintf("NOT_IMPLEMENTED <- %s\n", __FUNCTION__);
return ret;
}
2020-10-13 22:55:49 +02:00
HRESULT __stdcall IDirectDraw__GetMonitorFrequency(IDirectDrawImpl* This, LPDWORD lpdwFreq)
2020-10-13 09:20:52 +02:00
{
2020-10-13 22:55:49 +02:00
dprintf("-> %s(This=%p)\n", __FUNCTION__, This);
HRESULT ret = dd_GetMonitorFrequency(lpdwFreq);
dprintf("<- %s\n", __FUNCTION__);
2020-10-13 09:20:52 +02:00
return ret;
}
HRESULT __stdcall IDirectDraw__GetScanLine(IDirectDrawImpl* This, LPDWORD a)
{
dprintf("NOT_IMPLEMENTED -> %s(This=%p)\n", __FUNCTION__, This);
HRESULT ret = DD_OK;
dprintf("NOT_IMPLEMENTED <- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__GetVerticalBlankStatus(IDirectDrawImpl* This, LPBOOL lpbIsInVB)
{
dprintf("-> %s(This=%p, lpbIsInVB=%p)\n", __FUNCTION__, This, lpbIsInVB);
HRESULT ret = dd_GetVerticalBlankStatus(lpbIsInVB);
dprintf("<- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__Initialize(IDirectDrawImpl* This, GUID* a)
{
dprintf("NOT_IMPLEMENTED -> %s(This=%p)\n", __FUNCTION__, This);
HRESULT ret = DD_OK;
dprintf("NOT_IMPLEMENTED <- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__RestoreDisplayMode(IDirectDrawImpl* This)
{
dprintf("-> %s(This=%p)\n", __FUNCTION__, This);
HRESULT ret = dd_RestoreDisplayMode();
dprintf("<- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__SetCooperativeLevel(IDirectDrawImpl* This, HWND hwnd, DWORD dwFlags)
{
dprintf("-> %s(This=%p, hwnd=0x%08X, dwFlags=0x%08X)\n", __FUNCTION__, This, (unsigned int)hwnd, (unsigned int)dwFlags);
HRESULT ret = dd_SetCooperativeLevel(hwnd, dwFlags);
dprintf("<- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__SetDisplayMode(IDirectDrawImpl* This, DWORD width, DWORD height, DWORD bpp)
{
dprintf("-> %s(This=%p, width=%d, height=%d, bpp=%d)\n", __FUNCTION__, This, (unsigned int)width, (unsigned int)height, (unsigned int)bpp);
HRESULT ret = dd_SetDisplayMode(width, height, bpp);
dprintf("<- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__SetDisplayModeX(IDirectDrawImpl* This, DWORD width, DWORD height, DWORD bpp, DWORD refreshRate, DWORD flags)
{
dprintf("-> %s(This=%p, width=%d, height=%d, bpp=%d, refreshRate=%d, flags=%d)\n", __FUNCTION__, This, (unsigned int)width, (unsigned int)height, (unsigned int)bpp, (unsigned int)refreshRate, (unsigned int)flags);
HRESULT ret = dd_SetDisplayMode(width, height, bpp);
dprintf("<- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__WaitForVerticalBlank(IDirectDrawImpl* This, DWORD dwFlags, HANDLE h)
{
dprintfex("-> %s(This=%p, flags=%08X, handle=%p)\n", __FUNCTION__, This, dwFlags, h);
HRESULT ret = dd_WaitForVerticalBlank(dwFlags, h);
dprintfex("<- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__GetAvailableVidMem(IDirectDrawImpl* This, void* lpDDCaps, LPDWORD lpdwTotal, LPDWORD lpdwFree)
{
dprintf("-> %s(This=%p, lpDDCaps=%p, lpdwTotal=%p, lpdwFree=%p)\n", __FUNCTION__, This, lpDDCaps, lpdwTotal, lpdwFree);
HRESULT ret = dd_GetAvailableVidMem(lpDDCaps, lpdwTotal, lpdwFree);
dprintf("<- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__GetSurfaceFromDC(IDirectDrawImpl* This, HDC hdc, void* lplpDDSurface)
{
dprintf("NOT_IMPLEMENTED -> %s(This=%p)\n", __FUNCTION__, This);
HRESULT ret = DDERR_GENERIC;
dprintf("NOT_IMPLEMENTED <- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__RestoreAllSurfaces(IDirectDrawImpl* This)
{
dprintf("NOT_IMPLEMENTED -> %s(This=%p)\n", __FUNCTION__, This);
HRESULT ret = DDERR_INVALIDOBJECT;
dprintf("NOT_IMPLEMENTED <- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__TestCooperativeLevel(IDirectDrawImpl* This)
{
dprintf("NOT_IMPLEMENTED -> %s(This=%p)\n", __FUNCTION__, This);
HRESULT ret = DDERR_INVALIDOBJECT;
dprintf("NOT_IMPLEMENTED <- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__GetDeviceIdentifier(IDirectDrawImpl* This, void* pDDDI, DWORD dwFlags)
{
dprintf("NOT_IMPLEMENTED -> %s(This=%p)\n", __FUNCTION__, This);
HRESULT ret = DDERR_INVALIDPARAMS;
dprintf("NOT_IMPLEMENTED <- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__StartModeTest(IDirectDrawImpl* This, LPSIZE pModes, DWORD dwNumModes, DWORD dwFlags)
{
dprintf("NOT_IMPLEMENTED -> %s(This=%p)\n", __FUNCTION__, This);
HRESULT ret = DDERR_CURRENTLYNOTAVAIL;
dprintf("NOT_IMPLEMENTED <- %s\n", __FUNCTION__);
return ret;
}
HRESULT __stdcall IDirectDraw__EvaluateMode(IDirectDrawImpl* This, DWORD dwFlags, DWORD* pTimeout)
{
dprintf("NOT_IMPLEMENTED -> %s(This=%p)\n", __FUNCTION__, This);
HRESULT ret = DDERR_INVALIDOBJECT;
dprintf("NOT_IMPLEMENTED <- %s\n", __FUNCTION__);
return ret;
}
struct IDirectDrawImplVtbl g_dd_vtbl1 =
{
/* IUnknown */
IDirectDraw__QueryInterface,
IDirectDraw__AddRef,
IDirectDraw__Release,
/* IDirectDrawImpl */
IDirectDraw__Compact,
IDirectDraw__CreateClipper,
IDirectDraw__CreatePalette,
IDirectDraw__CreateSurface,
IDirectDraw__DuplicateSurface,
IDirectDraw__EnumDisplayModes,
IDirectDraw__EnumSurfaces,
IDirectDraw__FlipToGDISurface,
IDirectDraw__GetCaps,
IDirectDraw__GetDisplayMode,
IDirectDraw__GetFourCCCodes,
IDirectDraw__GetGDISurface,
IDirectDraw__GetMonitorFrequency,
IDirectDraw__GetScanLine,
IDirectDraw__GetVerticalBlankStatus,
IDirectDraw__Initialize,
IDirectDraw__RestoreDisplayMode,
IDirectDraw__SetCooperativeLevel,
{IDirectDraw__SetDisplayMode},
IDirectDraw__WaitForVerticalBlank,
// v2
IDirectDraw__GetAvailableVidMem,
// v4
IDirectDraw__GetSurfaceFromDC,
IDirectDraw__RestoreAllSurfaces,
IDirectDraw__TestCooperativeLevel,
IDirectDraw__GetDeviceIdentifier,
// v7
IDirectDraw__StartModeTest,
IDirectDraw__EvaluateMode,
};
struct IDirectDrawImplVtbl g_dd_vtblx =
{
/* IUnknown */
IDirectDraw__QueryInterface,
IDirectDraw__AddRef,
IDirectDraw__Release,
/* IDirectDrawImpl */
IDirectDraw__Compact,
IDirectDraw__CreateClipper,
IDirectDraw__CreatePalette,
IDirectDraw__CreateSurface,
IDirectDraw__DuplicateSurface,
IDirectDraw__EnumDisplayModes,
IDirectDraw__EnumSurfaces,
IDirectDraw__FlipToGDISurface,
IDirectDraw__GetCaps,
IDirectDraw__GetDisplayMode,
IDirectDraw__GetFourCCCodes,
IDirectDraw__GetGDISurface,
IDirectDraw__GetMonitorFrequency,
IDirectDraw__GetScanLine,
IDirectDraw__GetVerticalBlankStatus,
IDirectDraw__Initialize,
IDirectDraw__RestoreDisplayMode,
IDirectDraw__SetCooperativeLevel,
{IDirectDraw__SetDisplayModeX},
IDirectDraw__WaitForVerticalBlank,
// v2
IDirectDraw__GetAvailableVidMem,
// v4
IDirectDraw__GetSurfaceFromDC,
IDirectDraw__RestoreAllSurfaces,
IDirectDraw__TestCooperativeLevel,
IDirectDraw__GetDeviceIdentifier,
// v7
IDirectDraw__StartModeTest,
IDirectDraw__EvaluateMode,
};