From c81c12df8477daeb958e8f08d92100cc91c392f8 Mon Sep 17 00:00:00 2001 From: narzoul Date: Sat, 27 May 2017 23:53:25 +0200 Subject: [PATCH] Redirect gamma controls to the real primary surface --- DDrawCompat/DDraw/DirectDrawGammaControl.cpp | 36 ++++++++++++++++++- DDrawCompat/DDraw/DirectDrawSurface.cpp | 1 - DDrawCompat/DDraw/RealPrimarySurface.cpp | 22 ++++++++++++ DDrawCompat/DDraw/RealPrimarySurface.h | 2 ++ .../DDraw/Surfaces/PrimarySurfaceImpl.cpp | 11 ------ .../DDraw/Surfaces/PrimarySurfaceImpl.h | 1 - DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp | 6 ---- DDrawCompat/DDraw/Surfaces/SurfaceImpl.h | 1 - 8 files changed, 59 insertions(+), 21 deletions(-) diff --git a/DDrawCompat/DDraw/DirectDrawGammaControl.cpp b/DDrawCompat/DDraw/DirectDrawGammaControl.cpp index 09f8762..e4f1b7a 100644 --- a/DDrawCompat/DDraw/DirectDrawGammaControl.cpp +++ b/DDrawCompat/DDraw/DirectDrawGammaControl.cpp @@ -1,8 +1,42 @@ #include "DDraw/DirectDrawGammaControl.h" +#include "DDraw/RealPrimarySurface.h" +#include "DDraw/Surfaces/PrimarySurface.h" + +namespace +{ + bool isPrimaryGamma(IDirectDrawGammaControl* gamma) + { + return CompatPtr::from(gamma) == DDraw::PrimarySurface::getPrimary(); + } + + HRESULT STDMETHODCALLTYPE getGammaRamp( + IDirectDrawGammaControl* This, DWORD dwFlags, LPDDGAMMARAMP lpRampData) + { + if (0 != dwFlags || !lpRampData || !isPrimaryGamma(This)) + { + return DDraw::DirectDrawGammaControl::s_origVtable.GetGammaRamp(This, dwFlags, lpRampData); + } + + return DDraw::RealPrimarySurface::getGammaRamp(lpRampData); + } + + HRESULT STDMETHODCALLTYPE setGammaRamp( + IDirectDrawGammaControl* This, DWORD dwFlags, LPDDGAMMARAMP lpRampData) + { + if ((0 != dwFlags && DDSGR_CALIBRATE != dwFlags) || !isPrimaryGamma(This)) + { + return DDraw::DirectDrawGammaControl::s_origVtable.SetGammaRamp(This, dwFlags, lpRampData); + } + + return DDraw::RealPrimarySurface::setGammaRamp(lpRampData); + } +} namespace DDraw { - void DirectDrawGammaControl::setCompatVtable(IDirectDrawGammaControlVtbl& /*vtable*/) + void DirectDrawGammaControl::setCompatVtable(IDirectDrawGammaControlVtbl& vtable) { + vtable.GetGammaRamp = &getGammaRamp; + vtable.SetGammaRamp = &setGammaRamp; } } diff --git a/DDrawCompat/DDraw/DirectDrawSurface.cpp b/DDrawCompat/DDraw/DirectDrawSurface.cpp index 9e3a28b..c059f50 100644 --- a/DDrawCompat/DDraw/DirectDrawSurface.cpp +++ b/DDrawCompat/DDraw/DirectDrawSurface.cpp @@ -43,7 +43,6 @@ namespace DDraw SET_COMPAT_METHOD(GetSurfaceDesc); SET_COMPAT_METHOD(IsLost); SET_COMPAT_METHOD(Lock); - SET_COMPAT_METHOD(QueryInterface); SET_COMPAT_METHOD(ReleaseDC); SET_COMPAT_METHOD(Restore); SET_COMPAT_METHOD(SetClipper); diff --git a/DDrawCompat/DDraw/RealPrimarySurface.cpp b/DDrawCompat/DDraw/RealPrimarySurface.cpp index 5644609..baae367 100644 --- a/DDrawCompat/DDraw/RealPrimarySurface.cpp +++ b/DDrawCompat/DDraw/RealPrimarySurface.cpp @@ -320,6 +320,17 @@ namespace DDraw return result; } + HRESULT RealPrimarySurface::getGammaRamp(DDGAMMARAMP* rampData) + { + auto gammaControl(CompatPtr::from(g_frontBuffer.get())); + if (!gammaControl) + { + return DDERR_INVALIDPARAMS; + } + + return gammaControl->GetGammaRamp(gammaControl, 0, rampData); + } + CompatWeakPtr RealPrimarySurface::getSurface() { return g_frontBuffer; @@ -380,6 +391,17 @@ namespace DDraw g_clipper = clipper; } + HRESULT RealPrimarySurface::setGammaRamp(DDGAMMARAMP* rampData) + { + auto gammaControl(CompatPtr::from(g_frontBuffer.get())); + if (!gammaControl) + { + return DDERR_INVALIDPARAMS; + } + + return gammaControl->SetGammaRamp(gammaControl, 0, rampData); + } + void RealPrimarySurface::setPalette() { if (g_surfaceDesc.ddpfPixelFormat.dwRGBBitCount <= 8) diff --git a/DDrawCompat/DDraw/RealPrimarySurface.h b/DDrawCompat/DDraw/RealPrimarySurface.h index 7aa0666..03d6be2 100644 --- a/DDrawCompat/DDraw/RealPrimarySurface.h +++ b/DDrawCompat/DDraw/RealPrimarySurface.h @@ -18,6 +18,7 @@ namespace DDraw static void disableUpdates(); static void enableUpdates(); static HRESULT flip(DWORD flags); + static HRESULT getGammaRamp(DDGAMMARAMP* rampData); static CompatWeakPtr getSurface(); static bool isFullScreen(); static bool isLost(); @@ -25,6 +26,7 @@ namespace DDraw static void removeUpdateThread(); static HRESULT restore(); static void setClipper(CompatWeakPtr clipper); + static HRESULT setGammaRamp(DDGAMMARAMP* rampData); static void setPalette(); static void update(); static void updatePalette(DWORD startingEntry, DWORD count); diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp b/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp index 247f2f8..c0b7542 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp @@ -147,17 +147,6 @@ namespace DDraw return result; } - template - HRESULT PrimarySurfaceImpl::QueryInterface(TSurface* This, REFIID riid, LPVOID* obp) - { - if (riid == IID_IDirectDrawGammaControl) - { - auto realPrimary(RealPrimarySurface::getSurface()); - return realPrimary->QueryInterface(realPrimary, riid, obp); - } - return m_impl.QueryInterface(This, riid, obp); - } - template HRESULT PrimarySurfaceImpl::ReleaseDC(TSurface* This, HDC hDC) { diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.h b/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.h index 2cac65e..41f8a9c 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.h +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.h @@ -27,7 +27,6 @@ namespace DDraw virtual HRESULT IsLost(TSurface* This) override; virtual HRESULT Lock(TSurface* This, LPRECT lpDestRect, TSurfaceDesc* lpDDSurfaceDesc, DWORD dwFlags, HANDLE hEvent) override; - virtual HRESULT QueryInterface(TSurface* This, REFIID riid, LPVOID* obp) override; virtual HRESULT ReleaseDC(TSurface* This, HDC hDC) override; virtual HRESULT Restore(TSurface* This) override; virtual HRESULT SetClipper(TSurface* This, LPDIRECTDRAWCLIPPER lpDDClipper) override; diff --git a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp index ee226f6..265972b 100644 --- a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp +++ b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp @@ -261,12 +261,6 @@ namespace DDraw return result; } - template - HRESULT SurfaceImpl::QueryInterface(TSurface* This, REFIID riid, LPVOID* obp) - { - return s_origVtable.QueryInterface(This, riid, obp); - } - template HRESULT SurfaceImpl::ReleaseDC(TSurface* This, HDC hDC) { diff --git a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.h b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.h index 4a7b4f4..fa35f19 100644 --- a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.h +++ b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.h @@ -47,7 +47,6 @@ namespace DDraw virtual HRESULT IsLost(TSurface* This); virtual HRESULT Lock(TSurface* This, LPRECT lpDestRect, TSurfaceDesc* lpDDSurfaceDesc, DWORD dwFlags, HANDLE hEvent); - virtual HRESULT QueryInterface(TSurface* This, REFIID riid, LPVOID* obp); virtual HRESULT ReleaseDC(TSurface* This, HDC hDC); virtual HRESULT Restore(TSurface* This); virtual HRESULT SetClipper(TSurface* This, LPDIRECTDRAWCLIPPER lpDDClipper);