[LWIP]
[reactos.git] / dll / directx / wine / ddraw / gamma.c
1 /* DirectDrawGammaControl implementation
2 *
3 * Copyright 2001 TransGaming Technologies Inc.
4 * Copyright 2006 Stefan Dösinger
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include "config.h"
22 #include "wine/port.h"
23 #include "wine/debug.h"
24
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <string.h>
28 #include <stdlib.h>
29
30 #define COBJMACROS
31
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winerror.h"
35 #include "wingdi.h"
36 #include "wine/exception.h"
37
38 #include "ddraw.h"
39 #include "d3d.h"
40
41 #include "ddraw_private.h"
42
43 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
44 WINE_DECLARE_DEBUG_CHANNEL(ddraw_thunk);
45
46 static inline IDirectDrawSurfaceImpl *surface_from_gamma_control(IDirectDrawGammaControl *iface)
47 {
48 return (IDirectDrawSurfaceImpl *)((char*)iface
49 - FIELD_OFFSET(IDirectDrawSurfaceImpl, IDirectDrawGammaControl_vtbl));
50 }
51
52 /**********************************************************
53 * IUnknown parts follow
54 **********************************************************/
55
56 /**********************************************************
57 * IDirectDrawGammaControl::QueryInterface
58 *
59 * QueryInterface, thunks to IDirectDrawSurface
60 *
61 * Params:
62 * riid: Interface id queried for
63 * obj: Returns the interface pointer
64 *
65 * Returns:
66 * S_OK or E_NOINTERFACE: See IDirectDrawSurface7::QueryInterface
67 *
68 **********************************************************/
69 static HRESULT WINAPI
70 IDirectDrawGammaControlImpl_QueryInterface(IDirectDrawGammaControl *iface, REFIID riid,
71 void **obj)
72 {
73 IDirectDrawSurfaceImpl *This = surface_from_gamma_control(iface);
74 TRACE_(ddraw_thunk)("(%p)->(%s,%p): Thunking to IDirectDrawSurface7\n", This, debugstr_guid(riid), obj);
75
76 return IDirectDrawSurface7_QueryInterface((IDirectDrawSurface7 *)This, riid, obj);
77 }
78
79 /**********************************************************
80 * IDirectDrawGammaControl::AddRef
81 *
82 * Addref, thunks to IDirectDrawSurface
83 *
84 * Returns:
85 * The new refcount
86 *
87 **********************************************************/
88 static ULONG WINAPI
89 IDirectDrawGammaControlImpl_AddRef(IDirectDrawGammaControl *iface)
90 {
91 IDirectDrawSurfaceImpl *This = surface_from_gamma_control(iface);
92 TRACE_(ddraw_thunk)("(%p)->() Thunking to IDirectDrawSurface7\n", This);
93
94 return IDirectDrawSurface7_AddRef((IDirectDrawSurface7 *)This);
95 }
96
97 /**********************************************************
98 * IDirectDrawGammaControl::Release
99 *
100 * Release, thunks to IDirectDrawSurface
101 *
102 * Returns:
103 * The new refcount
104 *
105 **********************************************************/
106 static ULONG WINAPI
107 IDirectDrawGammaControlImpl_Release(IDirectDrawGammaControl *iface)
108 {
109 IDirectDrawSurfaceImpl *This = surface_from_gamma_control(iface);
110 TRACE_(ddraw_thunk)("(%p)->() Thunking to IDirectDrawSurface7\n", This);
111
112 return IDirectDrawSurface7_Release((IDirectDrawSurface7 *)This);
113 }
114
115 /**********************************************************
116 * IDirectDrawGammaControl
117 **********************************************************/
118
119 /**********************************************************
120 * IDirectDrawGammaControl::GetGammaRamp
121 *
122 * Returns the current gamma ramp for a surface
123 *
124 * Params:
125 * Flags: Ignored
126 * GammaRamp: Address to write the ramp to
127 *
128 * Returns:
129 * DD_OK on success
130 * DDERR_INVALIDPARAMS if GammaRamp is NULL
131 *
132 **********************************************************/
133 static HRESULT WINAPI
134 IDirectDrawGammaControlImpl_GetGammaRamp(IDirectDrawGammaControl *iface,
135 DWORD Flags,
136 DDGAMMARAMP *GammaRamp)
137 {
138 IDirectDrawSurfaceImpl *This = surface_from_gamma_control(iface);
139 TRACE("(%p)->(%08x,%p)\n", This,Flags,GammaRamp);
140
141 /* This looks sane */
142 if(!GammaRamp)
143 {
144 ERR("(%p) GammaRamp is NULL, returning DDERR_INVALIDPARAMS\n", This);
145 return DDERR_INVALIDPARAMS;
146 }
147
148 EnterCriticalSection(&ddraw_cs);
149 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
150 {
151 /* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP */
152 IWineD3DDevice_GetGammaRamp(This->ddraw->wineD3DDevice,
153 0 /* Swapchain */,
154 (WINED3DGAMMARAMP *) GammaRamp);
155 }
156 else
157 {
158 ERR("(%p) Unimplemented for non-primary surfaces\n", This);
159 }
160 LeaveCriticalSection(&ddraw_cs);
161
162 return DD_OK;
163 }
164
165 /**********************************************************
166 * IDirectDrawGammaControl::SetGammaRamp
167 *
168 * Sets the red, green and blue gamma ramps for
169 *
170 * Params:
171 * Flags: Can be DDSGR_CALIBRATE to request calibration
172 * GammaRamp: Structure containing the new gamma ramp
173 *
174 * Returns:
175 * DD_OK on success
176 * DDERR_INVALIDPARAMS if GammaRamp is NULL
177 *
178 **********************************************************/
179 static HRESULT WINAPI
180 IDirectDrawGammaControlImpl_SetGammaRamp(IDirectDrawGammaControl *iface,
181 DWORD Flags,
182 DDGAMMARAMP *GammaRamp)
183 {
184 IDirectDrawSurfaceImpl *This = surface_from_gamma_control(iface);
185 TRACE("(%p)->(%08x,%p)\n", This,Flags,GammaRamp);
186
187 /* This looks sane */
188 if(!GammaRamp)
189 {
190 ERR("(%p) GammaRamp is NULL, returning DDERR_INVALIDPARAMS\n", This);
191 return DDERR_INVALIDPARAMS;
192 }
193
194 EnterCriticalSection(&ddraw_cs);
195 if(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
196 {
197
198 /* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP */
199 IWineD3DDevice_SetGammaRamp(This->ddraw->wineD3DDevice,
200 0 /* Swapchain */,
201 Flags,
202 (WINED3DGAMMARAMP *) GammaRamp);
203 }
204 else
205 {
206 ERR("(%p) Unimplemented for non-primary surfaces\n", This);
207 }
208 LeaveCriticalSection(&ddraw_cs);
209
210 return DD_OK;
211 }
212
213 const IDirectDrawGammaControlVtbl IDirectDrawGammaControl_Vtbl =
214 {
215 IDirectDrawGammaControlImpl_QueryInterface,
216 IDirectDrawGammaControlImpl_AddRef,
217 IDirectDrawGammaControlImpl_Release,
218 IDirectDrawGammaControlImpl_GetGammaRamp,
219 IDirectDrawGammaControlImpl_SetGammaRamp
220 };