ole32: Fix wrap-around bug in tick count comparison.
[wine] / dlls / d3drm / material.c
1 /*
2  * Implementation of IDirect3DRMMaterial2 interface
3  *
4  * Copyright 2012 Christian Costa
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 "wine/debug.h"
22
23 #define COBJMACROS
24
25 #include "winbase.h"
26 #include "wingdi.h"
27
28 #include "d3drm_private.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(d3drm);
31
32 typedef struct
33 {
34     D3DVALUE r;
35     D3DVALUE g;
36     D3DVALUE b;
37 } color_rgb;
38
39 typedef struct {
40     IDirect3DRMMaterial2 IDirect3DRMMaterial2_iface;
41     LONG ref;
42     color_rgb emissive;
43     color_rgb specular;
44     D3DVALUE power;
45     color_rgb ambient;
46 } IDirect3DRMMaterialImpl;
47
48 static inline IDirect3DRMMaterialImpl *impl_from_IDirect3DRMMaterial2(IDirect3DRMMaterial2 *iface)
49 {
50     return CONTAINING_RECORD(iface, IDirect3DRMMaterialImpl, IDirect3DRMMaterial2_iface);
51 }
52
53 /*** IUnknown methods ***/
54 static HRESULT WINAPI IDirect3DRMMaterial2Impl_QueryInterface(IDirect3DRMMaterial2* iface,
55                                                            REFIID riid, void** ret_iface)
56 {
57     IDirect3DRMMaterialImpl *This = impl_from_IDirect3DRMMaterial2(iface);
58
59     TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ret_iface);
60
61     if (IsEqualGUID(riid, &IID_IUnknown) ||
62         IsEqualGUID(riid, &IID_IDirect3DRMMaterial) ||
63         IsEqualGUID(riid, &IID_IDirect3DRMMaterial2))
64     {
65         *ret_iface = &This->IDirect3DRMMaterial2_iface;
66     }
67     else
68     {
69         *ret_iface = NULL;
70         FIXME("Interface %s not implemented\n", debugstr_guid(riid));
71         return E_NOINTERFACE;
72     }
73
74     IDirect3DRMMaterial_AddRef(iface);
75
76     return S_OK;
77 }
78
79 static ULONG WINAPI IDirect3DRMMaterial2Impl_AddRef(IDirect3DRMMaterial2* iface)
80 {
81     IDirect3DRMMaterialImpl *This = impl_from_IDirect3DRMMaterial2(iface);
82     ULONG ref = InterlockedIncrement(&This->ref);
83
84     TRACE("(%p)->(): new ref = %d\n", iface, ref);
85
86     return ref;
87 }
88
89 static ULONG WINAPI IDirect3DRMMaterial2Impl_Release(IDirect3DRMMaterial2* iface)
90 {
91     IDirect3DRMMaterialImpl *This = impl_from_IDirect3DRMMaterial2(iface);
92     ULONG ref = InterlockedDecrement(&This->ref);
93
94     TRACE("(%p)->(): new ref = %d\n", iface, ref);
95
96     if (!ref)
97         HeapFree(GetProcessHeap(), 0, This);
98
99     return ref;
100 }
101
102 /*** IDirect3DRMObject methods ***/
103 static HRESULT WINAPI IDirect3DRMMaterial2Impl_Clone(IDirect3DRMMaterial2* iface,
104                                                      LPUNKNOWN unknown, REFIID riid,
105                                                      LPVOID* object)
106 {
107     FIXME("(%p)->(%p, %s, %p): stub\n", iface, unknown, debugstr_guid(riid), object);
108
109     return E_NOTIMPL;
110 }
111
112 static HRESULT WINAPI IDirect3DRMMaterial2Impl_AddDestroyCallback(IDirect3DRMMaterial2* iface,
113                                                                   D3DRMOBJECTCALLBACK cb,
114                                                                   LPVOID argument)
115 {
116     FIXME("(%p)->(%p, %p): stub\n", iface, cb, argument);
117
118     return E_NOTIMPL;
119 }
120
121 static HRESULT WINAPI IDirect3DRMMaterial2Impl_DeleteDestroyCallback(IDirect3DRMMaterial2* iface,
122                                                                      D3DRMOBJECTCALLBACK cb,
123                                                                      LPVOID argument)
124 {
125     FIXME("(%p)->(%p, %p): stub\n", iface, cb, argument);
126
127     return E_NOTIMPL;
128 }
129
130 static HRESULT WINAPI IDirect3DRMMaterial2Impl_SetAppData(IDirect3DRMMaterial2* iface,
131                                                           DWORD data)
132 {
133     FIXME("(%p)->(%u): stub\n", iface, data);
134
135     return E_NOTIMPL;
136 }
137
138 static DWORD WINAPI IDirect3DRMMaterial2Impl_GetAppData(IDirect3DRMMaterial2* iface)
139 {
140     FIXME("(%p)->(): stub\n", iface);
141
142     return 0;
143 }
144
145 static HRESULT WINAPI IDirect3DRMMaterial2Impl_SetName(IDirect3DRMMaterial2* iface, LPCSTR name)
146 {
147     FIXME("(%p)->(%s): stub\n", iface, name);
148
149     return E_NOTIMPL;
150 }
151
152 static HRESULT WINAPI IDirect3DRMMaterial2Impl_GetName(IDirect3DRMMaterial2* iface,
153                                                        LPDWORD size, LPSTR name)
154 {
155     FIXME("(%p)->(%p, %p): stub\n", iface, size, name);
156
157     return E_NOTIMPL;
158 }
159
160 static HRESULT WINAPI IDirect3DRMMaterial2Impl_GetClassName(IDirect3DRMMaterial2* iface,
161                                                            LPDWORD size, LPSTR name)
162 {
163     TRACE("(%p)->(%p, %p)\n", iface, size, name);
164
165     if (!size || *size < strlen("Material") || !name)
166         return E_INVALIDARG;
167
168     strcpy(name, "Material");
169     *size = sizeof("Material");
170
171     return D3DRM_OK;
172 }
173
174 /*** IDirect3DRMMaterial methods ***/
175 static HRESULT WINAPI IDirect3DRMMaterial2Impl_SetPower(IDirect3DRMMaterial2* iface, D3DVALUE power)
176 {
177     IDirect3DRMMaterialImpl *This = impl_from_IDirect3DRMMaterial2(iface);
178
179     TRACE("(%p)->(%f)\n", iface, power);
180
181     This->power = power;
182
183     return D3DRM_OK;
184 }
185
186 static HRESULT WINAPI IDirect3DRMMaterial2Impl_SetSpecular(IDirect3DRMMaterial2* iface,
187                                                            D3DVALUE r, D3DVALUE g, D3DVALUE b)
188 {
189     IDirect3DRMMaterialImpl *This = impl_from_IDirect3DRMMaterial2(iface);
190
191     TRACE("(%p)->(%f, %f, %f)\n", iface, r, g, b);
192
193     This->specular.r = r;
194     This->specular.g = g;
195     This->specular.b = b;
196
197     return D3DRM_OK;
198 }
199
200 static HRESULT WINAPI IDirect3DRMMaterial2Impl_SetEmissive(IDirect3DRMMaterial2* iface,
201                                                            D3DVALUE r, D3DVALUE g, D3DVALUE b)
202 {
203     IDirect3DRMMaterialImpl *This = impl_from_IDirect3DRMMaterial2(iface);
204
205     TRACE("(%p)->(%f, %f, %f)\n", iface, r, g, b);
206
207     This->emissive.r = r;
208     This->emissive.g = g;
209     This->emissive.b = b;
210
211     return D3DRM_OK;
212 }
213
214 static D3DVALUE WINAPI IDirect3DRMMaterial2Impl_GetPower(IDirect3DRMMaterial2* iface)
215 {
216     IDirect3DRMMaterialImpl *This = impl_from_IDirect3DRMMaterial2(iface);
217
218     TRACE("(%p)->()\n", iface);
219
220     return This->power;
221 }
222
223 static HRESULT WINAPI IDirect3DRMMaterial2Impl_GetSpecular(IDirect3DRMMaterial2* iface,
224                                                            D3DVALUE* r, D3DVALUE* g, D3DVALUE* b)
225 {
226     IDirect3DRMMaterialImpl *This = impl_from_IDirect3DRMMaterial2(iface);
227
228     TRACE("(%p)->(%p, %p, %p)\n", iface, r, g, b);
229
230     *r = This->specular.r;
231     *g = This->specular.g;
232     *b = This->specular.b;
233
234     return D3DRM_OK;
235 }
236
237 static HRESULT WINAPI IDirect3DRMMaterial2Impl_GetEmissive(IDirect3DRMMaterial2* iface,
238                                                            D3DVALUE* r, D3DVALUE* g, D3DVALUE* b)
239 {
240     IDirect3DRMMaterialImpl *This = impl_from_IDirect3DRMMaterial2(iface);
241
242     TRACE("(%p)->(%p, %p, %p)\n", iface, r, g, b);
243
244     *r = This->emissive.r;
245     *g = This->emissive.g;
246     *b = This->emissive.b;
247
248     return D3DRM_OK;
249 }
250
251 /*** IDirect3DRMMaterial2 methods ***/
252 static HRESULT WINAPI IDirect3DRMMaterial2Impl_GetAmbient(IDirect3DRMMaterial2* iface,
253                                                           D3DVALUE* r, D3DVALUE* g, D3DVALUE* b)
254 {
255     IDirect3DRMMaterialImpl *This = impl_from_IDirect3DRMMaterial2(iface);
256
257     TRACE("(%p)->(%p, %p, %p)\n", iface, r, g, b);
258
259     *r = This->ambient.r;
260     *g = This->ambient.g;
261     *b = This->ambient.b;
262
263     return D3DRM_OK;
264 }
265
266 static HRESULT WINAPI IDirect3DRMMaterial2Impl_SetAmbient(IDirect3DRMMaterial2* iface,
267                                                           D3DVALUE r, D3DVALUE g, D3DVALUE b)
268 {
269     IDirect3DRMMaterialImpl *This = impl_from_IDirect3DRMMaterial2(iface);
270
271     TRACE("(%p)->(%f, %f, %f)\n", iface, r, g, b);
272
273     This->ambient.r = r;
274     This->ambient.g = g;
275     This->ambient.b = b;
276
277     return D3DRM_OK;
278 }
279
280 static const struct IDirect3DRMMaterial2Vtbl Direct3DRMMaterial2_Vtbl =
281 {
282     /*** IUnknown methods ***/
283     IDirect3DRMMaterial2Impl_QueryInterface,
284     IDirect3DRMMaterial2Impl_AddRef,
285     IDirect3DRMMaterial2Impl_Release,
286     /*** IDirect3DRMObject methods ***/
287     IDirect3DRMMaterial2Impl_Clone,
288     IDirect3DRMMaterial2Impl_AddDestroyCallback,
289     IDirect3DRMMaterial2Impl_DeleteDestroyCallback,
290     IDirect3DRMMaterial2Impl_SetAppData,
291     IDirect3DRMMaterial2Impl_GetAppData,
292     IDirect3DRMMaterial2Impl_SetName,
293     IDirect3DRMMaterial2Impl_GetName,
294     IDirect3DRMMaterial2Impl_GetClassName,
295     /*** IDirect3DRMMaterial methods ***/
296     IDirect3DRMMaterial2Impl_SetPower,
297     IDirect3DRMMaterial2Impl_SetSpecular,
298     IDirect3DRMMaterial2Impl_SetEmissive,
299     IDirect3DRMMaterial2Impl_GetPower,
300     IDirect3DRMMaterial2Impl_GetSpecular,
301     IDirect3DRMMaterial2Impl_GetEmissive,
302     /*** IDirect3DRMMaterial2 methods ***/
303     IDirect3DRMMaterial2Impl_GetAmbient,
304     IDirect3DRMMaterial2Impl_SetAmbient
305 };
306
307 HRESULT Direct3DRMMaterial_create(IDirect3DRMMaterial2** ret_iface)
308 {
309     IDirect3DRMMaterialImpl* object;
310
311     TRACE("(%p)\n", ret_iface);
312
313     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DRMMaterialImpl));
314     if (!object)
315     {
316         ERR("Out of memory\n");
317         return E_OUTOFMEMORY;
318     }
319
320     object->IDirect3DRMMaterial2_iface.lpVtbl = &Direct3DRMMaterial2_Vtbl;
321     object->ref = 1;
322
323     object->specular.r = 1.0f;
324     object->specular.g = 1.0f;
325     object->specular.b = 1.0f;
326
327     *ret_iface = &object->IDirect3DRMMaterial2_iface;
328
329     return S_OK;
330 }