mciqtz32: Use opened state to avoid device to be closed several times.
[wine.git] / dlls / ddraw / gamma.c
blobdf631a4d6bfed52798ccedc9323a2ebe84149a5e
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
21 #include "config.h"
22 #include "wine/port.h"
23 #include "wine/debug.h"
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <string.h>
28 #include <stdlib.h>
30 #define COBJMACROS
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winerror.h"
35 #include "wingdi.h"
36 #include "wine/exception.h"
38 #include "ddraw.h"
39 #include "d3d.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
61 * Params:
62 * riid: Interface id queried for
63 * obj: Returns the interface pointer
65 * Returns:
66 * S_OK or E_NOINTERFACE: See IDirectDrawSurface7::QueryInterface
68 **********************************************************/
69 static HRESULT WINAPI
70 IDirectDrawGammaControlImpl_QueryInterface(IDirectDrawGammaControl *iface, REFIID riid,
71 void **obj)
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
84 * Returns:
85 * The new refcount
87 **********************************************************/
88 static ULONG WINAPI
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
102 * Returns:
103 * The new refcount
105 **********************************************************/
106 static ULONG WINAPI
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
124 * Params:
125 * Flags: Ignored
126 * GammaRamp: Address to write the ramp to
128 * Returns:
129 * DD_OK on success
130 * DDERR_INVALIDPARAMS if GammaRamp is NULL
132 **********************************************************/
133 static HRESULT WINAPI
134 IDirectDrawGammaControlImpl_GetGammaRamp(IDirectDrawGammaControl *iface,
135 DWORD Flags,
136 DDGAMMARAMP *GammaRamp)
138 IDirectDrawSurfaceImpl *This = surface_from_gamma_control(iface);
139 TRACE("(%p)->(%08x,%p)\n", This,Flags,GammaRamp);
141 /* This looks sane */
142 if(!GammaRamp)
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,
153 0 /* Swapchain */,
154 (WINED3DGAMMARAMP *) GammaRamp);
156 else
158 ERR("(%p) Unimplemented for non-primary surfaces\n", This);
160 LeaveCriticalSection(&ddraw_cs);
162 return DD_OK;
165 /**********************************************************
166 * IDirectDrawGammaControl::SetGammaRamp
168 * Sets the red, green and blue gamma ramps for
170 * Params:
171 * Flags: Can be DDSGR_CALIBRATE to request calibration
172 * GammaRamp: Structure containing the new gamma ramp
174 * Returns:
175 * DD_OK on success
176 * DDERR_INVALIDPARAMS if GammaRamp is NULL
178 **********************************************************/
179 static HRESULT WINAPI
180 IDirectDrawGammaControlImpl_SetGammaRamp(IDirectDrawGammaControl *iface,
181 DWORD Flags,
182 DDGAMMARAMP *GammaRamp)
184 IDirectDrawSurfaceImpl *This = surface_from_gamma_control(iface);
185 TRACE("(%p)->(%08x,%p)\n", This,Flags,GammaRamp);
187 /* This looks sane */
188 if(!GammaRamp)
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,
200 0 /* Swapchain */,
201 Flags,
202 (WINED3DGAMMARAMP *) GammaRamp);
204 else
206 ERR("(%p) Unimplemented for non-primary surfaces\n", This);
208 LeaveCriticalSection(&ddraw_cs);
210 return DD_OK;
213 const IDirectDrawGammaControlVtbl IDirectDrawGammaControl_Vtbl =
215 IDirectDrawGammaControlImpl_QueryInterface,
216 IDirectDrawGammaControlImpl_AddRef,
217 IDirectDrawGammaControlImpl_Release,
218 IDirectDrawGammaControlImpl_GetGammaRamp,
219 IDirectDrawGammaControlImpl_SetGammaRamp