1 /* DirectDrawGammaControl implementation
3 * Copyright 2001 TransGaming Technologies Inc.
4 * Copyright 2006 Stefan Dösinger
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
23 #include "wine/debug.h"
36 #include "wine/exception.h"
41 #include "ddraw_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
44 WINE_DECLARE_DEBUG_CHANNEL(ddraw_thunk);
46 static inline IDirectDrawSurfaceImpl *surface_from_gamma_control(IDirectDrawGammaControl *iface)
48 return (IDirectDrawSurfaceImpl *)((char*)iface
49 - FIELD_OFFSET(IDirectDrawSurfaceImpl, IDirectDrawGammaControl_vtbl));
52 /**********************************************************
53 * IUnknown parts follow
54 **********************************************************/
56 /**********************************************************
57 * IDirectDrawGammaControl::QueryInterface
59 * QueryInterface, thunks to IDirectDrawSurface
62 * riid: Interface id queried for
63 * obj: Returns the interface pointer
66 * S_OK or E_NOINTERFACE: See IDirectDrawSurface7::QueryInterface
68 **********************************************************/
70 IDirectDrawGammaControlImpl_QueryInterface(IDirectDrawGammaControl *iface, REFIID riid,
73 IDirectDrawSurfaceImpl *This = surface_from_gamma_control(iface);
74 TRACE_(ddraw_thunk)("(%p)->(%s,%p): Thunking to IDirectDrawSurface7\n", This, debugstr_guid(riid), obj);
76 return IDirectDrawSurface7_QueryInterface((IDirectDrawSurface7 *)This, riid, obj);
79 /**********************************************************
80 * IDirectDrawGammaControl::AddRef
82 * Addref, thunks to IDirectDrawSurface
87 **********************************************************/
89 IDirectDrawGammaControlImpl_AddRef(IDirectDrawGammaControl *iface)
91 IDirectDrawSurfaceImpl *This = surface_from_gamma_control(iface);
92 TRACE_(ddraw_thunk)("(%p)->() Thunking to IDirectDrawSurface7\n", This);
94 return IDirectDrawSurface7_AddRef((IDirectDrawSurface7 *)This);
97 /**********************************************************
98 * IDirectDrawGammaControl::Release
100 * Release, thunks to IDirectDrawSurface
105 **********************************************************/
107 IDirectDrawGammaControlImpl_Release(IDirectDrawGammaControl *iface)
109 IDirectDrawSurfaceImpl *This = surface_from_gamma_control(iface);
110 TRACE_(ddraw_thunk)("(%p)->() Thunking to IDirectDrawSurface7\n", This);
112 return IDirectDrawSurface7_Release((IDirectDrawSurface7 *)This);
115 /**********************************************************
116 * IDirectDrawGammaControl
117 **********************************************************/
119 /**********************************************************
120 * IDirectDrawGammaControl::GetGammaRamp
122 * Returns the current gamma ramp for a surface
126 * GammaRamp: Address to write the ramp to
130 * DDERR_INVALIDPARAMS if GammaRamp is NULL
132 **********************************************************/
133 static HRESULT WINAPI
134 IDirectDrawGammaControlImpl_GetGammaRamp(IDirectDrawGammaControl *iface,
136 DDGAMMARAMP *GammaRamp)
138 IDirectDrawSurfaceImpl *This = surface_from_gamma_control(iface);
139 TRACE("(%p)->(%08x,%p)\n", This,Flags,GammaRamp);
141 /* This looks sane */
144 ERR("(%p) GammaRamp is NULL, returning DDERR_INVALIDPARAMS\n", This);
145 return DDERR_INVALIDPARAMS;
148 EnterCriticalSection(&ddraw_cs);
149 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
151 /* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP */
152 IWineD3DDevice_GetGammaRamp(This->ddraw->wineD3DDevice,
154 (WINED3DGAMMARAMP *) GammaRamp);
158 ERR("(%p) Unimplemented for non-primary surfaces\n", This);
160 LeaveCriticalSection(&ddraw_cs);
165 /**********************************************************
166 * IDirectDrawGammaControl::SetGammaRamp
168 * Sets the red, green and blue gamma ramps for
171 * Flags: Can be DDSGR_CALIBRATE to request calibration
172 * GammaRamp: Structure containing the new gamma ramp
176 * DDERR_INVALIDPARAMS if GammaRamp is NULL
178 **********************************************************/
179 static HRESULT WINAPI
180 IDirectDrawGammaControlImpl_SetGammaRamp(IDirectDrawGammaControl *iface,
182 DDGAMMARAMP *GammaRamp)
184 IDirectDrawSurfaceImpl *This = surface_from_gamma_control(iface);
185 TRACE("(%p)->(%08x,%p)\n", This,Flags,GammaRamp);
187 /* This looks sane */
190 ERR("(%p) GammaRamp is NULL, returning DDERR_INVALIDPARAMS\n", This);
191 return DDERR_INVALIDPARAMS;
194 EnterCriticalSection(&ddraw_cs);
195 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
198 /* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP */
199 IWineD3DDevice_SetGammaRamp(This->ddraw->wineD3DDevice,
202 (WINED3DGAMMARAMP *) GammaRamp);
206 ERR("(%p) Unimplemented for non-primary surfaces\n", This);
208 LeaveCriticalSection(&ddraw_cs);
213 const IDirectDrawGammaControlVtbl IDirectDrawGammaControl_Vtbl =
215 IDirectDrawGammaControlImpl_QueryInterface,
216 IDirectDrawGammaControlImpl_AddRef,
217 IDirectDrawGammaControlImpl_Release,
218 IDirectDrawGammaControlImpl_GetGammaRamp,
219 IDirectDrawGammaControlImpl_SetGammaRamp