xref: /reactos/dll/directx/wine/d3drm/device.c (revision 321bcc05)
1 /*
2  * Implementation of IDirect3DRMDevice Interface
3  *
4  * Copyright 2011, 2012 André Hentschel
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 "d3drm_private.h"
22 
23 #include <d3drmwin.h>
24 
25 struct d3drm_device
26 {
27     IDirect3DRMDevice IDirect3DRMDevice_iface;
28     IDirect3DRMDevice2 IDirect3DRMDevice2_iface;
29     IDirect3DRMDevice3 IDirect3DRMDevice3_iface;
30     IDirect3DRMWinDevice IDirect3DRMWinDevice_iface;
31     IDirect3DRM *d3drm;
32     IDirectDraw *ddraw;
33     IDirectDrawSurface *primary_surface, *render_target;
34     IDirectDrawClipper *clipper;
35     IDirect3DDevice *device;
36     LONG ref;
37     BOOL dither;
38     D3DRMRENDERQUALITY quality;
39     DWORD rendermode;
40     DWORD height;
41     DWORD width;
42 };
43 
44 static inline struct d3drm_device *impl_from_IDirect3DRMDevice(IDirect3DRMDevice *iface)
45 {
46     return CONTAINING_RECORD(iface, struct d3drm_device, IDirect3DRMDevice_iface);
47 }
48 
49 static inline struct d3drm_device *impl_from_IDirect3DRMDevice2(IDirect3DRMDevice2 *iface)
50 {
51     return CONTAINING_RECORD(iface, struct d3drm_device, IDirect3DRMDevice2_iface);
52 }
53 
54 static inline struct d3drm_device *impl_from_IDirect3DRMDevice3(IDirect3DRMDevice3 *iface)
55 {
56     return CONTAINING_RECORD(iface, struct d3drm_device, IDirect3DRMDevice3_iface);
57 }
58 
59 IDirect3DRMDevice *IDirect3DRMDevice_from_impl(struct d3drm_device *device)
60 {
61     return &device->IDirect3DRMDevice_iface;
62 }
63 
64 IDirect3DRMDevice2 *IDirect3DRMDevice2_from_impl(struct d3drm_device *device)
65 {
66     return &device->IDirect3DRMDevice2_iface;
67 }
68 
69 IDirect3DRMDevice3 *IDirect3DRMDevice3_from_impl(struct d3drm_device *device)
70 {
71     return &device->IDirect3DRMDevice3_iface;
72 }
73 
74 void d3drm_device_destroy(struct d3drm_device *device)
75 {
76     if (device->device)
77     {
78         TRACE("Releasing attached ddraw interfaces.\n");
79         IDirect3DDevice_Release(device->device);
80     }
81     if (device->render_target)
82         IDirectDrawSurface_Release(device->render_target);
83     if (device->primary_surface)
84     {
85         TRACE("Releasing primary surface and attached clipper.\n");
86         IDirectDrawSurface_Release(device->primary_surface);
87         IDirectDrawClipper_Release(device->clipper);
88     }
89     if (device->ddraw)
90     {
91         IDirectDraw_Release(device->ddraw);
92         IDirect3DRM_Release(device->d3drm);
93     }
94     HeapFree(GetProcessHeap(), 0, device);
95 }
96 
97 static inline struct d3drm_device *impl_from_IDirect3DRMWinDevice(IDirect3DRMWinDevice *iface)
98 {
99     return CONTAINING_RECORD(iface, struct d3drm_device, IDirect3DRMWinDevice_iface);
100 }
101 
102 HRESULT d3drm_device_create_surfaces_from_clipper(struct d3drm_device *object, IDirectDraw *ddraw, IDirectDrawClipper *clipper, int width, int height, IDirectDrawSurface **surface)
103 {
104     DDSURFACEDESC surface_desc;
105     IDirectDrawSurface *primary_surface, *render_target;
106     HWND window;
107     HRESULT hr;
108 
109     hr = IDirectDrawClipper_GetHWnd(clipper, &window);
110     if (FAILED(hr))
111         return hr;
112 
113     hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
114     if (FAILED(hr))
115         return hr;
116 
117     memset(&surface_desc, 0, sizeof(surface_desc));
118     surface_desc.dwSize = sizeof(surface_desc);
119     surface_desc.dwFlags = DDSD_CAPS;
120     surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
121     hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &primary_surface, NULL);
122     if (FAILED(hr))
123         return hr;
124     hr = IDirectDrawSurface_SetClipper(primary_surface, clipper);
125     if (FAILED(hr))
126     {
127         IDirectDrawSurface_Release(primary_surface);
128         return hr;
129     }
130 
131     memset(&surface_desc, 0, sizeof(surface_desc));
132     surface_desc.dwSize = sizeof(surface_desc);
133     surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
134     surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
135     surface_desc.dwWidth = width;
136     surface_desc.dwHeight = height;
137 
138     hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &render_target, NULL);
139     if (FAILED(hr))
140     {
141         IDirectDrawSurface_Release(primary_surface);
142         return hr;
143     }
144 
145     object->primary_surface = primary_surface;
146     object->clipper = clipper;
147     IDirectDrawClipper_AddRef(clipper);
148     *surface = render_target;
149 
150     return D3DRM_OK;
151 }
152 
153 HRESULT d3drm_device_init(struct d3drm_device *device, UINT version, IDirect3DRM *d3drm, IDirectDraw *ddraw, IDirectDrawSurface *surface,
154             BOOL create_z_surface)
155 {
156     DDSCAPS caps = { DDSCAPS_ZBUFFER };
157     IDirectDrawSurface *ds = NULL;
158     IDirect3DDevice *device1 = NULL;
159     IDirect3DDevice2 *device2 = NULL;
160     IDirect3D2 *d3d2 = NULL;
161     DDSURFACEDESC desc, surface_desc;
162     HRESULT hr;
163 
164     device->ddraw = ddraw;
165     IDirectDraw_AddRef(ddraw);
166     device->d3drm = d3drm;
167     IDirect3DRM_AddRef(d3drm);
168     device->render_target = surface;
169     IDirectDrawSurface_AddRef(surface);
170 
171     desc.dwSize = sizeof(desc);
172     hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
173     if (FAILED(hr))
174         return hr;
175 
176     if (!(desc.ddsCaps.dwCaps & DDSCAPS_3DDEVICE))
177         return DDERR_INVALIDCAPS;
178 
179     hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
180     if (SUCCEEDED(hr))
181     {
182         create_z_surface = FALSE;
183         IDirectDrawSurface_Release(ds);
184         ds = NULL;
185     }
186 
187     if (create_z_surface)
188     {
189         memset(&surface_desc, 0, sizeof(surface_desc));
190         surface_desc.dwSize = sizeof(surface_desc);
191         surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
192         surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
193         surface_desc.u2.dwZBufferBitDepth = 16;
194         surface_desc.dwWidth = desc.dwWidth;
195         surface_desc.dwHeight = desc.dwHeight;
196         hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &ds, NULL);
197         if (FAILED(hr))
198             return hr;
199 
200         hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
201         IDirectDrawSurface_Release(ds);
202         if (FAILED(hr))
203             return hr;
204     }
205 
206     if (version == 1)
207         hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DRGBDevice, (void **)&device1);
208     else
209     {
210         IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D2, (void**)&d3d2);
211         hr = IDirect3D2_CreateDevice(d3d2, &IID_IDirect3DRGBDevice, surface, &device2);
212         IDirect3D2_Release(d3d2);
213     }
214     if (FAILED(hr))
215     {
216         IDirectDrawSurface_DeleteAttachedSurface(surface, 0, ds);
217         return hr;
218     }
219 
220     if (version != 1)
221     {
222         hr = IDirect3DDevice2_QueryInterface(device2, &IID_IDirect3DDevice, (void**)&device1);
223         IDirect3DDevice2_Release(device2);
224         if (FAILED(hr))
225         {
226             IDirectDrawSurface_DeleteAttachedSurface(surface, 0, ds);
227             return hr;
228         }
229     }
230     device->device = device1;
231 
232     return hr;
233 }
234 
235 HRESULT d3drm_device_set_ddraw_device_d3d(struct d3drm_device *device, IDirect3DRM *d3drm, IDirect3D *d3d, IDirect3DDevice *d3d_device)
236 {
237     device->d3drm = d3drm;
238     IDirect3DRM_AddRef(d3drm);
239     device->device = d3d_device;
240     IDirect3DDevice_AddRef(d3d_device);
241 
242     return IDirect3D_QueryInterface(d3d, &IID_IDirectDraw, (void **)&device->ddraw);
243 }
244 
245 static HRESULT WINAPI d3drm_device1_QueryInterface(IDirect3DRMDevice *iface, REFIID riid, void **out)
246 {
247     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
248 
249     TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
250 
251     return IDirect3DRMDevice3_QueryInterface(&device->IDirect3DRMDevice3_iface, riid, out);
252 }
253 
254 static ULONG WINAPI d3drm_device1_AddRef(IDirect3DRMDevice *iface)
255 {
256     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
257 
258     TRACE("iface %p.\n", iface);
259 
260     return IDirect3DRMDevice3_AddRef(&device->IDirect3DRMDevice3_iface);
261 }
262 
263 static ULONG WINAPI d3drm_device1_Release(IDirect3DRMDevice *iface)
264 {
265     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
266 
267     TRACE("iface %p.\n", iface);
268 
269     return IDirect3DRMDevice3_Release(&device->IDirect3DRMDevice3_iface);
270 }
271 
272 static HRESULT WINAPI d3drm_device1_Clone(IDirect3DRMDevice *iface,
273     IUnknown *outer, REFIID iid, void **out)
274 {
275     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
276 
277     TRACE("iface %p, outer %p, iid %s, out %p.\n", iface, outer, debugstr_guid(iid), out);
278 
279     return IDirect3DRMDevice3_Clone(&device->IDirect3DRMDevice3_iface, outer, iid, out);
280 }
281 
282 static HRESULT WINAPI d3drm_device1_AddDestroyCallback(IDirect3DRMDevice *iface,
283     D3DRMOBJECTCALLBACK cb, void *ctx)
284 {
285     FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
286 
287     return E_NOTIMPL;
288 }
289 
290 static HRESULT WINAPI d3drm_device1_DeleteDestroyCallback(IDirect3DRMDevice *iface,
291     D3DRMOBJECTCALLBACK cb, void *ctx)
292 {
293     FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
294 
295     return E_NOTIMPL;
296 }
297 
298 static HRESULT WINAPI d3drm_device1_SetAppData(IDirect3DRMDevice *iface, DWORD data)
299 {
300     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
301 
302     TRACE("iface %p, data %#x.\n", iface, data);
303 
304     return IDirect3DRMDevice3_SetAppData(&device->IDirect3DRMDevice3_iface, data);
305 }
306 
307 static DWORD WINAPI d3drm_device1_GetAppData(IDirect3DRMDevice *iface)
308 {
309     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
310 
311     TRACE("iface %p.\n", iface);
312 
313     return IDirect3DRMDevice3_GetAppData(&device->IDirect3DRMDevice3_iface);
314 }
315 
316 static HRESULT WINAPI d3drm_device1_SetName(IDirect3DRMDevice *iface, const char *name)
317 {
318     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
319 
320     TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
321 
322     return IDirect3DRMDevice3_SetName(&device->IDirect3DRMDevice3_iface, name);
323 }
324 
325 static HRESULT WINAPI d3drm_device1_GetName(IDirect3DRMDevice *iface, DWORD *size, char *name)
326 {
327     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
328 
329     TRACE("iface %p, size %p, name %p.\n", iface, size, name);
330 
331     return IDirect3DRMDevice3_GetName(&device->IDirect3DRMDevice3_iface, size, name);
332 }
333 
334 static HRESULT WINAPI d3drm_device1_GetClassName(IDirect3DRMDevice *iface, DWORD *size, char *name)
335 {
336     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
337 
338     TRACE("iface %p, size %p, name %p.\n", iface, size, name);
339 
340     return IDirect3DRMDevice3_GetClassName(&device->IDirect3DRMDevice3_iface, size, name);
341 }
342 
343 static HRESULT WINAPI d3drm_device1_Init(IDirect3DRMDevice *iface, ULONG width, ULONG height)
344 {
345     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
346 
347     TRACE("iface %p, width %u, height %u.\n", iface, width, height);
348 
349     return IDirect3DRMDevice3_Init(&device->IDirect3DRMDevice3_iface, width, height);
350 }
351 
352 static HRESULT WINAPI d3drm_device1_InitFromD3D(IDirect3DRMDevice *iface,
353     IDirect3D *d3d, IDirect3DDevice *d3d_device)
354 {
355     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
356 
357     TRACE("iface %p, d3d %p, d3d_device %p.\n", iface, d3d, d3d_device);
358 
359     return IDirect3DRMDevice3_InitFromD3D(&device->IDirect3DRMDevice3_iface, d3d, d3d_device);
360 }
361 
362 static HRESULT WINAPI d3drm_device1_InitFromClipper(IDirect3DRMDevice *iface,
363     IDirectDrawClipper *clipper, GUID *guid, int width, int height)
364 {
365     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
366 
367     TRACE("iface %p, clipper %p, guid %s, width %d, height %d.\n",
368         iface, clipper, debugstr_guid(guid), width, height);
369 
370     return IDirect3DRMDevice3_InitFromClipper(&device->IDirect3DRMDevice3_iface,
371         clipper, guid, width, height);
372 }
373 
374 static HRESULT WINAPI d3drm_device1_Update(IDirect3DRMDevice *iface)
375 {
376     FIXME("iface %p stub!\n", iface);
377 
378     return D3DRM_OK;
379 }
380 
381 static HRESULT WINAPI d3drm_device1_AddUpdateCallback(IDirect3DRMDevice *iface,
382     D3DRMUPDATECALLBACK cb, void *ctx)
383 {
384     FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
385 
386     return E_NOTIMPL;
387 }
388 
389 static HRESULT WINAPI d3drm_device1_DeleteUpdateCallback(IDirect3DRMDevice *iface,
390     D3DRMUPDATECALLBACK cb, void *ctx)
391 {
392     FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
393 
394     return E_NOTIMPL;
395 }
396 
397 static HRESULT WINAPI d3drm_device1_SetBufferCount(IDirect3DRMDevice *iface, DWORD count)
398 {
399     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
400 
401     TRACE("iface %p, count %u.\n", iface, count);
402 
403     return IDirect3DRMDevice3_SetBufferCount(&device->IDirect3DRMDevice3_iface, count);
404 }
405 
406 static DWORD WINAPI d3drm_device1_GetBufferCount(IDirect3DRMDevice *iface)
407 {
408     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
409 
410     TRACE("iface %p.\n", iface);
411 
412     return IDirect3DRMDevice3_GetBufferCount(&device->IDirect3DRMDevice3_iface);
413 }
414 
415 static HRESULT WINAPI d3drm_device1_SetDither(IDirect3DRMDevice *iface, BOOL enable)
416 {
417     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
418 
419     TRACE("iface %p, enabled %#x.\n", iface, enable);
420 
421     return IDirect3DRMDevice3_SetDither(&device->IDirect3DRMDevice3_iface, enable);
422 }
423 
424 static HRESULT WINAPI d3drm_device1_SetShades(IDirect3DRMDevice *iface, DWORD count)
425 {
426     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
427 
428     TRACE("iface %p, count %u.\n", iface, count);
429 
430     return IDirect3DRMDevice3_SetShades(&device->IDirect3DRMDevice3_iface, count);
431 }
432 
433 static HRESULT WINAPI d3drm_device1_SetQuality(IDirect3DRMDevice *iface, D3DRMRENDERQUALITY quality)
434 {
435     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
436 
437     TRACE("iface %p, quality %u.\n", iface, quality);
438 
439     return IDirect3DRMDevice3_SetQuality(&device->IDirect3DRMDevice3_iface, quality);
440 }
441 
442 static HRESULT WINAPI d3drm_device1_SetTextureQuality(IDirect3DRMDevice *iface, D3DRMTEXTUREQUALITY quality)
443 {
444     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
445 
446     TRACE("iface %p, quality %u.\n", iface, quality);
447 
448     return IDirect3DRMDevice3_SetTextureQuality(&device->IDirect3DRMDevice3_iface, quality);
449 }
450 
451 static HRESULT WINAPI d3drm_device1_GetViewports(IDirect3DRMDevice *iface, IDirect3DRMViewportArray **array)
452 {
453     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
454 
455     TRACE("iface %p, array %p.\n", iface, array);
456 
457     return IDirect3DRMDevice3_GetViewports(&device->IDirect3DRMDevice3_iface, array);
458 }
459 
460 static BOOL WINAPI d3drm_device1_GetDither(IDirect3DRMDevice *iface)
461 {
462     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
463 
464     TRACE("iface %p.\n", iface);
465 
466     return IDirect3DRMDevice3_GetDither(&device->IDirect3DRMDevice3_iface);
467 }
468 
469 static DWORD WINAPI d3drm_device1_GetShades(IDirect3DRMDevice *iface)
470 {
471     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
472 
473     TRACE("iface %p.\n", iface);
474 
475     return IDirect3DRMDevice3_GetShades(&device->IDirect3DRMDevice3_iface);
476 }
477 
478 static DWORD WINAPI d3drm_device1_GetHeight(IDirect3DRMDevice *iface)
479 {
480     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
481 
482     TRACE("iface %p.\n", iface);
483 
484     return IDirect3DRMDevice3_GetHeight(&device->IDirect3DRMDevice3_iface);
485 }
486 
487 static DWORD WINAPI d3drm_device1_GetWidth(IDirect3DRMDevice *iface)
488 {
489     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
490 
491     TRACE("iface %p.\n", iface);
492 
493     return IDirect3DRMDevice3_GetWidth(&device->IDirect3DRMDevice3_iface);
494 }
495 
496 static DWORD WINAPI d3drm_device1_GetTrianglesDrawn(IDirect3DRMDevice *iface)
497 {
498     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
499 
500     TRACE("iface %p.\n", iface);
501 
502     return IDirect3DRMDevice3_GetTrianglesDrawn(&device->IDirect3DRMDevice3_iface);
503 }
504 
505 static DWORD WINAPI d3drm_device1_GetWireframeOptions(IDirect3DRMDevice *iface)
506 {
507     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
508 
509     TRACE("iface %p.\n", iface);
510 
511     return IDirect3DRMDevice3_GetWireframeOptions(&device->IDirect3DRMDevice3_iface);
512 }
513 
514 static D3DRMRENDERQUALITY WINAPI d3drm_device1_GetQuality(IDirect3DRMDevice *iface)
515 {
516     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
517 
518     TRACE("iface %p.\n", iface);
519 
520     return IDirect3DRMDevice3_GetQuality(&device->IDirect3DRMDevice3_iface);
521 }
522 
523 static D3DCOLORMODEL WINAPI d3drm_device1_GetColorModel(IDirect3DRMDevice *iface)
524 {
525     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
526 
527     TRACE("iface %p stub!\n", iface);
528 
529     return IDirect3DRMDevice3_GetColorModel(&device->IDirect3DRMDevice3_iface);
530 }
531 
532 static D3DRMTEXTUREQUALITY WINAPI d3drm_device1_GetTextureQuality(IDirect3DRMDevice *iface)
533 {
534     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
535 
536     TRACE("iface %p.\n", iface);
537 
538     return IDirect3DRMDevice3_GetTextureQuality(&device->IDirect3DRMDevice3_iface);
539 }
540 
541 static HRESULT WINAPI d3drm_device1_GetDirect3DDevice(IDirect3DRMDevice *iface, IDirect3DDevice **d3d_device)
542 {
543     struct d3drm_device *device = impl_from_IDirect3DRMDevice(iface);
544 
545     TRACE("iface %p, d3d_device %p.\n", iface, d3d_device);
546 
547     return IDirect3DRMDevice3_GetDirect3DDevice(&device->IDirect3DRMDevice3_iface, d3d_device);
548 }
549 
550 static const struct IDirect3DRMDeviceVtbl d3drm_device1_vtbl =
551 {
552     d3drm_device1_QueryInterface,
553     d3drm_device1_AddRef,
554     d3drm_device1_Release,
555     d3drm_device1_Clone,
556     d3drm_device1_AddDestroyCallback,
557     d3drm_device1_DeleteDestroyCallback,
558     d3drm_device1_SetAppData,
559     d3drm_device1_GetAppData,
560     d3drm_device1_SetName,
561     d3drm_device1_GetName,
562     d3drm_device1_GetClassName,
563     d3drm_device1_Init,
564     d3drm_device1_InitFromD3D,
565     d3drm_device1_InitFromClipper,
566     d3drm_device1_Update,
567     d3drm_device1_AddUpdateCallback,
568     d3drm_device1_DeleteUpdateCallback,
569     d3drm_device1_SetBufferCount,
570     d3drm_device1_GetBufferCount,
571     d3drm_device1_SetDither,
572     d3drm_device1_SetShades,
573     d3drm_device1_SetQuality,
574     d3drm_device1_SetTextureQuality,
575     d3drm_device1_GetViewports,
576     d3drm_device1_GetDither,
577     d3drm_device1_GetShades,
578     d3drm_device1_GetHeight,
579     d3drm_device1_GetWidth,
580     d3drm_device1_GetTrianglesDrawn,
581     d3drm_device1_GetWireframeOptions,
582     d3drm_device1_GetQuality,
583     d3drm_device1_GetColorModel,
584     d3drm_device1_GetTextureQuality,
585     d3drm_device1_GetDirect3DDevice,
586 };
587 
588 static HRESULT WINAPI d3drm_device2_QueryInterface(IDirect3DRMDevice2 *iface, REFIID riid, void **out)
589 {
590     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
591 
592     TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
593 
594     return IDirect3DRMDevice3_QueryInterface(&device->IDirect3DRMDevice3_iface, riid, out);
595 }
596 
597 static ULONG WINAPI d3drm_device2_AddRef(IDirect3DRMDevice2 *iface)
598 {
599     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
600 
601     TRACE("iface %p.\n", iface);
602 
603     return IDirect3DRMDevice3_AddRef(&device->IDirect3DRMDevice3_iface);
604 }
605 
606 static ULONG WINAPI d3drm_device2_Release(IDirect3DRMDevice2 *iface)
607 {
608     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
609 
610     TRACE("iface %p.\n", iface);
611 
612     return IDirect3DRMDevice3_Release(&device->IDirect3DRMDevice3_iface);
613 }
614 
615 static HRESULT WINAPI d3drm_device2_Clone(IDirect3DRMDevice2 *iface,
616         IUnknown *outer, REFIID iid, void **out)
617 {
618     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
619 
620     TRACE("iface %p, outer %p, iid %s, out %p\n", iface, outer, debugstr_guid(iid), out);
621 
622     return IDirect3DRMDevice3_Clone(&device->IDirect3DRMDevice3_iface, outer, iid, out);
623 }
624 
625 static HRESULT WINAPI d3drm_device2_AddDestroyCallback(IDirect3DRMDevice2 *iface,
626         D3DRMOBJECTCALLBACK cb, void *ctx)
627 {
628     FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
629 
630     return E_NOTIMPL;
631 }
632 
633 static HRESULT WINAPI d3drm_device2_DeleteDestroyCallback(IDirect3DRMDevice2 *iface,
634         D3DRMOBJECTCALLBACK cb, void *ctx)
635 {
636     FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
637 
638     return E_NOTIMPL;
639 }
640 
641 static HRESULT WINAPI d3drm_device2_SetAppData(IDirect3DRMDevice2 *iface, DWORD data)
642 {
643     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
644 
645     TRACE("iface %p, data %#x.\n", iface, data);
646 
647     return IDirect3DRMDevice3_SetAppData(&device->IDirect3DRMDevice3_iface, data);
648 }
649 
650 static DWORD WINAPI d3drm_device2_GetAppData(IDirect3DRMDevice2 *iface)
651 {
652     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
653 
654     TRACE("iface %p.\n", iface);
655 
656     return IDirect3DRMDevice3_GetAppData(&device->IDirect3DRMDevice3_iface);
657 }
658 
659 static HRESULT WINAPI d3drm_device2_SetName(IDirect3DRMDevice2 *iface, const char *name)
660 {
661     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
662 
663     TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
664 
665     return IDirect3DRMDevice3_SetName(&device->IDirect3DRMDevice3_iface, name);
666 }
667 
668 static HRESULT WINAPI d3drm_device2_GetName(IDirect3DRMDevice2 *iface, DWORD *size, char *name)
669 {
670     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
671 
672     TRACE("iface %p, size %p, name %p.\n", iface, size, name);
673 
674     return IDirect3DRMDevice3_GetName(&device->IDirect3DRMDevice3_iface, size, name);
675 }
676 
677 static HRESULT WINAPI d3drm_device2_GetClassName(IDirect3DRMDevice2 *iface, DWORD *size, char *name)
678 {
679     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
680 
681     TRACE("iface %p, size %p, name %p.\n", iface, size, name);
682 
683     return IDirect3DRMDevice3_GetClassName(&device->IDirect3DRMDevice3_iface, size, name);
684 }
685 
686 static HRESULT WINAPI d3drm_device2_Init(IDirect3DRMDevice2 *iface, ULONG width, ULONG height)
687 {
688     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
689 
690     TRACE("iface %p, width %u, height %u.\n", iface, width, height);
691 
692     return IDirect3DRMDevice3_Init(&device->IDirect3DRMDevice3_iface, width, height);
693 }
694 
695 static HRESULT WINAPI d3drm_device2_InitFromD3D(IDirect3DRMDevice2 *iface,
696         IDirect3D *d3d, IDirect3DDevice *d3d_device)
697 {
698     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
699 
700     TRACE("iface %p, d3d %p, d3d_device %p.\n", iface, d3d, d3d_device);
701 
702     return IDirect3DRMDevice3_InitFromD3D(&device->IDirect3DRMDevice3_iface, d3d, d3d_device);
703 }
704 
705 static HRESULT WINAPI d3drm_device2_InitFromClipper(IDirect3DRMDevice2 *iface,
706         IDirectDrawClipper *clipper, GUID *guid, int width, int height)
707 {
708     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
709 
710     TRACE("iface %p, clipper %p, guid %s, width %d, height %d.\n",
711             iface, clipper, debugstr_guid(guid), width, height);
712 
713     return IDirect3DRMDevice3_InitFromClipper(&device->IDirect3DRMDevice3_iface,
714             clipper, guid, width, height);
715 }
716 
717 static HRESULT WINAPI d3drm_device2_Update(IDirect3DRMDevice2 *iface)
718 {
719     FIXME("iface %p stub!\n", iface);
720 
721     return D3DRM_OK;
722 }
723 
724 static HRESULT WINAPI d3drm_device2_AddUpdateCallback(IDirect3DRMDevice2 *iface,
725         D3DRMUPDATECALLBACK cb, void *ctx)
726 {
727     FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
728 
729     return E_NOTIMPL;
730 }
731 
732 static HRESULT WINAPI d3drm_device2_DeleteUpdateCallback(IDirect3DRMDevice2 *iface,
733         D3DRMUPDATECALLBACK cb, void *ctx)
734 {
735     FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
736 
737     return E_NOTIMPL;
738 }
739 
740 static HRESULT WINAPI d3drm_device2_SetBufferCount(IDirect3DRMDevice2 *iface, DWORD count)
741 {
742     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
743 
744     TRACE("iface %p, count %u.\n", iface, count);
745 
746     return IDirect3DRMDevice3_SetBufferCount(&device->IDirect3DRMDevice3_iface, count);
747 }
748 
749 static DWORD WINAPI d3drm_device2_GetBufferCount(IDirect3DRMDevice2 *iface)
750 {
751     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
752 
753     TRACE("iface %p.\n", iface);
754 
755     return IDirect3DRMDevice3_GetBufferCount(&device->IDirect3DRMDevice3_iface);
756 }
757 
758 static HRESULT WINAPI d3drm_device2_SetDither(IDirect3DRMDevice2 *iface, BOOL enable)
759 {
760     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
761 
762     TRACE("iface %p, enabled %#x.\n", iface, enable);
763 
764     return IDirect3DRMDevice3_SetDither(&device->IDirect3DRMDevice3_iface, enable);
765 }
766 
767 static HRESULT WINAPI d3drm_device2_SetShades(IDirect3DRMDevice2 *iface, DWORD count)
768 {
769     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
770 
771     TRACE("iface %p, count %u.\n", iface, count);
772 
773     return IDirect3DRMDevice3_SetShades(&device->IDirect3DRMDevice3_iface, count);
774 }
775 
776 static HRESULT WINAPI d3drm_device2_SetQuality(IDirect3DRMDevice2 *iface, D3DRMRENDERQUALITY quality)
777 {
778     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
779 
780     TRACE("iface %p, quality %u.\n", iface, quality);
781 
782     return IDirect3DRMDevice3_SetQuality(&device->IDirect3DRMDevice3_iface, quality);
783 }
784 
785 static HRESULT WINAPI d3drm_device2_SetTextureQuality(IDirect3DRMDevice2 *iface, D3DRMTEXTUREQUALITY quality)
786 {
787     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
788 
789     TRACE("iface %p, quality %u.\n", iface, quality);
790 
791     return IDirect3DRMDevice3_SetTextureQuality(&device->IDirect3DRMDevice3_iface, quality);
792 }
793 
794 static HRESULT WINAPI d3drm_device2_GetViewports(IDirect3DRMDevice2 *iface, IDirect3DRMViewportArray **array)
795 {
796     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
797 
798     TRACE("iface %p, array %p.\n", iface, array);
799 
800     return IDirect3DRMDevice3_GetViewports(&device->IDirect3DRMDevice3_iface, array);
801 }
802 
803 static BOOL WINAPI d3drm_device2_GetDither(IDirect3DRMDevice2 *iface)
804 {
805     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
806 
807     TRACE("iface %p.\n", iface);
808 
809     return IDirect3DRMDevice3_GetDither(&device->IDirect3DRMDevice3_iface);
810 }
811 
812 static DWORD WINAPI d3drm_device2_GetShades(IDirect3DRMDevice2 *iface)
813 {
814     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
815 
816     TRACE("iface %p.\n", iface);
817 
818     return IDirect3DRMDevice3_GetShades(&device->IDirect3DRMDevice3_iface);
819 }
820 
821 static DWORD WINAPI d3drm_device2_GetHeight(IDirect3DRMDevice2 *iface)
822 {
823     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
824 
825     TRACE("iface %p.\n", iface);
826 
827     return IDirect3DRMDevice3_GetHeight(&device->IDirect3DRMDevice3_iface);
828 }
829 
830 static DWORD WINAPI d3drm_device2_GetWidth(IDirect3DRMDevice2 *iface)
831 {
832     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
833 
834     TRACE("iface %p.\n", iface);
835 
836     return IDirect3DRMDevice3_GetWidth(&device->IDirect3DRMDevice3_iface);
837 }
838 
839 static DWORD WINAPI d3drm_device2_GetTrianglesDrawn(IDirect3DRMDevice2 *iface)
840 {
841     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
842 
843     TRACE("iface %p.\n", iface);
844 
845     return IDirect3DRMDevice3_GetTrianglesDrawn(&device->IDirect3DRMDevice3_iface);
846 }
847 
848 static DWORD WINAPI d3drm_device2_GetWireframeOptions(IDirect3DRMDevice2 *iface)
849 {
850     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
851 
852     TRACE("iface %p.\n", iface);
853 
854     return IDirect3DRMDevice3_GetWireframeOptions(&device->IDirect3DRMDevice3_iface);
855 }
856 
857 static D3DRMRENDERQUALITY WINAPI d3drm_device2_GetQuality(IDirect3DRMDevice2 *iface)
858 {
859     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
860 
861     TRACE("iface %p.\n", iface);
862 
863     return IDirect3DRMDevice3_GetQuality(&device->IDirect3DRMDevice3_iface);
864 }
865 
866 static D3DCOLORMODEL WINAPI d3drm_device2_GetColorModel(IDirect3DRMDevice2 *iface)
867 {
868     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
869 
870     TRACE("iface %p.\n", iface);
871 
872     return IDirect3DRMDevice3_GetColorModel(&device->IDirect3DRMDevice3_iface);
873 }
874 
875 static D3DRMTEXTUREQUALITY WINAPI d3drm_device2_GetTextureQuality(IDirect3DRMDevice2 *iface)
876 {
877     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
878 
879     TRACE("iface %p.\n", iface);
880 
881     return IDirect3DRMDevice3_GetTextureQuality(&device->IDirect3DRMDevice3_iface);
882 }
883 
884 static HRESULT WINAPI d3drm_device2_GetDirect3DDevice(IDirect3DRMDevice2 *iface, IDirect3DDevice **d3d_device)
885 {
886     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
887 
888     TRACE("iface %p, d3d_device %p.\n", iface, d3d_device);
889 
890     return IDirect3DRMDevice3_GetDirect3DDevice(&device->IDirect3DRMDevice3_iface, d3d_device);
891 }
892 
893 static HRESULT WINAPI d3drm_device2_InitFromD3D2(IDirect3DRMDevice2 *iface,
894         IDirect3D2 *d3d, IDirect3DDevice2 *d3d_device)
895 {
896     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
897 
898     TRACE("iface %p, d3d %p, d3d_device %p.\n", iface, d3d, d3d_device);
899 
900     return IDirect3DRMDevice3_InitFromD3D2(&device->IDirect3DRMDevice3_iface, d3d, d3d_device);
901 }
902 
903 static HRESULT WINAPI d3drm_device2_InitFromSurface(IDirect3DRMDevice2 *iface,
904         GUID *guid, IDirectDraw *ddraw, IDirectDrawSurface *backbuffer)
905 {
906     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
907 
908     TRACE("iface %p, guid %s, ddraw %p, backbuffer %p.\n",
909             iface, debugstr_guid(guid), ddraw, backbuffer);
910 
911     return IDirect3DRMDevice3_InitFromSurface(&device->IDirect3DRMDevice3_iface, guid, ddraw, backbuffer);
912 }
913 
914 static HRESULT WINAPI d3drm_device2_SetRenderMode(IDirect3DRMDevice2 *iface, DWORD flags)
915 {
916     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
917 
918     TRACE("iface %p, flags %#x.\n", iface, flags);
919 
920     return IDirect3DRMDevice3_SetRenderMode(&device->IDirect3DRMDevice3_iface, flags);
921 }
922 
923 static DWORD WINAPI d3drm_device2_GetRenderMode(IDirect3DRMDevice2 *iface)
924 {
925     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
926 
927     TRACE("iface %p.\n", iface);
928 
929     return IDirect3DRMDevice3_GetRenderMode(&device->IDirect3DRMDevice3_iface);
930 }
931 
932 static HRESULT WINAPI d3drm_device2_GetDirect3DDevice2(IDirect3DRMDevice2 *iface, IDirect3DDevice2 **d3d_device)
933 {
934     struct d3drm_device *device = impl_from_IDirect3DRMDevice2(iface);
935 
936     TRACE("iface %p, d3d_device %p.\n", iface, d3d_device);
937 
938     return IDirect3DRMDevice3_GetDirect3DDevice2(&device->IDirect3DRMDevice3_iface, d3d_device);
939 }
940 
941 static const struct IDirect3DRMDevice2Vtbl d3drm_device2_vtbl =
942 {
943     d3drm_device2_QueryInterface,
944     d3drm_device2_AddRef,
945     d3drm_device2_Release,
946     d3drm_device2_Clone,
947     d3drm_device2_AddDestroyCallback,
948     d3drm_device2_DeleteDestroyCallback,
949     d3drm_device2_SetAppData,
950     d3drm_device2_GetAppData,
951     d3drm_device2_SetName,
952     d3drm_device2_GetName,
953     d3drm_device2_GetClassName,
954     d3drm_device2_Init,
955     d3drm_device2_InitFromD3D,
956     d3drm_device2_InitFromClipper,
957     d3drm_device2_Update,
958     d3drm_device2_AddUpdateCallback,
959     d3drm_device2_DeleteUpdateCallback,
960     d3drm_device2_SetBufferCount,
961     d3drm_device2_GetBufferCount,
962     d3drm_device2_SetDither,
963     d3drm_device2_SetShades,
964     d3drm_device2_SetQuality,
965     d3drm_device2_SetTextureQuality,
966     d3drm_device2_GetViewports,
967     d3drm_device2_GetDither,
968     d3drm_device2_GetShades,
969     d3drm_device2_GetHeight,
970     d3drm_device2_GetWidth,
971     d3drm_device2_GetTrianglesDrawn,
972     d3drm_device2_GetWireframeOptions,
973     d3drm_device2_GetQuality,
974     d3drm_device2_GetColorModel,
975     d3drm_device2_GetTextureQuality,
976     d3drm_device2_GetDirect3DDevice,
977     d3drm_device2_InitFromD3D2,
978     d3drm_device2_InitFromSurface,
979     d3drm_device2_SetRenderMode,
980     d3drm_device2_GetRenderMode,
981     d3drm_device2_GetDirect3DDevice2,
982 };
983 
984 static HRESULT WINAPI d3drm_device3_QueryInterface(IDirect3DRMDevice3 *iface, REFIID riid, void **out)
985 {
986     struct d3drm_device *device = impl_from_IDirect3DRMDevice3(iface);
987 
988     TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
989 
990     if (IsEqualGUID(riid, &IID_IDirect3DRMDevice3)
991             || IsEqualGUID(riid, &IID_IDirect3DRMObject)
992             || IsEqualGUID(riid, &IID_IUnknown))
993     {
994         *out = &device->IDirect3DRMDevice3_iface;
995     }
996     else if (IsEqualGUID(riid, &IID_IDirect3DRMDevice2))
997     {
998         *out = &device->IDirect3DRMDevice2_iface;
999     }
1000     else if (IsEqualGUID(riid, &IID_IDirect3DRMDevice))
1001     {
1002         *out = &device->IDirect3DRMDevice_iface;
1003     }
1004     else if (IsEqualGUID(riid, &IID_IDirect3DRMWinDevice))
1005     {
1006         *out = &device->IDirect3DRMWinDevice_iface;
1007     }
1008     else
1009     {
1010         *out = NULL;
1011         WARN("%s not implemented, returning CLASS_E_CLASSNOTAVAILABLE.\n", debugstr_guid(riid));
1012         return CLASS_E_CLASSNOTAVAILABLE;
1013     }
1014 
1015     IUnknown_AddRef((IUnknown *)*out);
1016     return S_OK;
1017 }
1018 
1019 static ULONG WINAPI d3drm_device3_AddRef(IDirect3DRMDevice3 *iface)
1020 {
1021     struct d3drm_device *device = impl_from_IDirect3DRMDevice3(iface);
1022     ULONG refcount = InterlockedIncrement(&device->ref);
1023 
1024     TRACE("%p increasing refcount to %u.\n", iface, refcount);
1025 
1026     return refcount;
1027 }
1028 
1029 static ULONG WINAPI d3drm_device3_Release(IDirect3DRMDevice3 *iface)
1030 {
1031     struct d3drm_device *device = impl_from_IDirect3DRMDevice3(iface);
1032     ULONG refcount = InterlockedDecrement(&device->ref);
1033 
1034     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
1035 
1036     if (!refcount)
1037         d3drm_device_destroy(device);
1038 
1039     return refcount;
1040 }
1041 
1042 static HRESULT WINAPI d3drm_device3_Clone(IDirect3DRMDevice3 *iface,
1043         IUnknown *outer, REFIID iid, void **out)
1044 {
1045     FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface, outer, debugstr_guid(iid), out);
1046 
1047     return E_NOTIMPL;
1048 }
1049 
1050 static HRESULT WINAPI d3drm_device3_AddDestroyCallback(IDirect3DRMDevice3 *iface,
1051         D3DRMOBJECTCALLBACK cb, void *ctx)
1052 {
1053     FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
1054 
1055     return E_NOTIMPL;
1056 }
1057 
1058 static HRESULT WINAPI d3drm_device3_DeleteDestroyCallback(IDirect3DRMDevice3 *iface,
1059         D3DRMOBJECTCALLBACK cb, void *ctx)
1060 {
1061     FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
1062 
1063     return E_NOTIMPL;
1064 }
1065 
1066 static HRESULT WINAPI d3drm_device3_SetAppData(IDirect3DRMDevice3 *iface, DWORD data)
1067 {
1068     FIXME("iface %p, data %#x stub!\n", iface, data);
1069 
1070     return E_NOTIMPL;
1071 }
1072 
1073 static DWORD WINAPI d3drm_device3_GetAppData(IDirect3DRMDevice3 *iface)
1074 {
1075     FIXME("iface %p stub!\n", iface);
1076 
1077     return 0;
1078 }
1079 
1080 static HRESULT WINAPI d3drm_device3_SetName(IDirect3DRMDevice3 *iface, const char *name)
1081 {
1082     FIXME("iface %p, name %s stub!\n", iface, debugstr_a(name));
1083 
1084     return E_NOTIMPL;
1085 }
1086 
1087 static HRESULT WINAPI d3drm_device3_GetName(IDirect3DRMDevice3 *iface, DWORD *size, char *name)
1088 {
1089     FIXME("iface %p, size %p, name %p stub!\n", iface, size, name);
1090 
1091     return E_NOTIMPL;
1092 }
1093 
1094 static HRESULT WINAPI d3drm_device3_GetClassName(IDirect3DRMDevice3 *iface, DWORD *size, char *name)
1095 {
1096     TRACE("iface %p, size %p, name %p.\n", iface, size, name);
1097 
1098     if (!size || *size < strlen("Device") || !name)
1099         return E_INVALIDARG;
1100 
1101     strcpy(name, "Device");
1102     *size = sizeof("Device");
1103 
1104     return D3DRM_OK;
1105 }
1106 
1107 static HRESULT WINAPI d3drm_device3_Init(IDirect3DRMDevice3 *iface, ULONG width, ULONG height)
1108 {
1109     struct d3drm_device *device = impl_from_IDirect3DRMDevice3(iface);
1110 
1111     FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
1112 
1113     device->height = height;
1114     device->width = width;
1115 
1116     return D3DRM_OK;
1117 }
1118 
1119 static HRESULT WINAPI d3drm_device3_InitFromD3D(IDirect3DRMDevice3 *iface,
1120         IDirect3D *d3d, IDirect3DDevice *d3d_device)
1121 {
1122     FIXME("iface %p, d3d %p, d3d_device %p stub!\n", iface, d3d, d3d_device);
1123 
1124     return E_NOTIMPL;
1125 }
1126 
1127 static HRESULT WINAPI d3drm_device3_InitFromClipper(IDirect3DRMDevice3 *iface,
1128         IDirectDrawClipper *clipper, GUID *guid, int width, int height)
1129 {
1130     struct d3drm_device *device = impl_from_IDirect3DRMDevice3(iface);
1131 
1132     FIXME("iface %p, clipper %p, guid %s, width %d, height %d stub!\n",
1133             iface, clipper, debugstr_guid(guid), width, height);
1134 
1135     device->height = height;
1136     device->width = width;
1137 
1138     return D3DRM_OK;
1139 }
1140 
1141 static HRESULT WINAPI d3drm_device3_Update(IDirect3DRMDevice3 *iface)
1142 {
1143     FIXME("iface %p stub!\n", iface);
1144 
1145     return D3DRM_OK;
1146 }
1147 
1148 static HRESULT WINAPI d3drm_device3_AddUpdateCallback(IDirect3DRMDevice3 *iface,
1149         D3DRMUPDATECALLBACK cb, void *ctx)
1150 {
1151     FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
1152 
1153     return E_NOTIMPL;
1154 }
1155 
1156 static HRESULT WINAPI d3drm_device3_DeleteUpdateCallback(IDirect3DRMDevice3 *iface,
1157         D3DRMUPDATECALLBACK cb, void *ctx)
1158 {
1159     FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
1160 
1161     return E_NOTIMPL;
1162 }
1163 
1164 static HRESULT WINAPI d3drm_device3_SetBufferCount(IDirect3DRMDevice3 *iface, DWORD count)
1165 {
1166     FIXME("iface %p, count %u stub!\n", iface, count);
1167 
1168     return E_NOTIMPL;
1169 }
1170 
1171 static DWORD WINAPI d3drm_device3_GetBufferCount(IDirect3DRMDevice3 *iface)
1172 {
1173     FIXME("iface %p stub!\n", iface);
1174 
1175     return E_NOTIMPL;
1176 }
1177 
1178 static HRESULT WINAPI d3drm_device3_SetDither(IDirect3DRMDevice3 *iface, BOOL enable)
1179 {
1180     struct d3drm_device *device = impl_from_IDirect3DRMDevice3(iface);
1181 
1182     TRACE("iface %p, enable %#x.\n", iface, enable);
1183 
1184     device->dither = enable;
1185 
1186     return D3DRM_OK;
1187 }
1188 
1189 static HRESULT WINAPI d3drm_device3_SetShades(IDirect3DRMDevice3 *iface, DWORD count)
1190 {
1191     FIXME("iface %p, count %u stub!\n", iface, count);
1192 
1193     return E_NOTIMPL;
1194 }
1195 
1196 static HRESULT WINAPI d3drm_device3_SetQuality(IDirect3DRMDevice3 *iface, D3DRMRENDERQUALITY quality)
1197 {
1198     struct d3drm_device *device = impl_from_IDirect3DRMDevice3(iface);
1199 
1200     TRACE("iface %p, quality %u.\n", iface, quality);
1201 
1202     device->quality = quality;
1203 
1204     return D3DRM_OK;
1205 }
1206 
1207 static HRESULT WINAPI d3drm_device3_SetTextureQuality(IDirect3DRMDevice3 *iface, D3DRMTEXTUREQUALITY quality)
1208 {
1209     FIXME("iface %p, quality %u stub!\n", iface, quality);
1210 
1211     return E_NOTIMPL;
1212 }
1213 
1214 static HRESULT WINAPI d3drm_device3_GetViewports(IDirect3DRMDevice3 *iface, IDirect3DRMViewportArray **array)
1215 {
1216     FIXME("iface %p, array %p stub!\n", iface, array);
1217 
1218     return E_NOTIMPL;
1219 }
1220 
1221 static BOOL WINAPI d3drm_device3_GetDither(IDirect3DRMDevice3 *iface)
1222 {
1223     struct d3drm_device *device = impl_from_IDirect3DRMDevice3(iface);
1224 
1225     TRACE("iface %p.\n", iface);
1226 
1227     return device->dither;
1228 }
1229 
1230 static DWORD WINAPI d3drm_device3_GetShades(IDirect3DRMDevice3 *iface)
1231 {
1232     FIXME("iface %p stub!\n", iface);
1233 
1234     return E_NOTIMPL;
1235 }
1236 
1237 static DWORD WINAPI d3drm_device3_GetHeight(IDirect3DRMDevice3 *iface)
1238 {
1239     struct d3drm_device *device = impl_from_IDirect3DRMDevice3(iface);
1240 
1241     TRACE("iface %p.\n", iface);
1242 
1243     return device->height;
1244 }
1245 
1246 static DWORD WINAPI d3drm_device3_GetWidth(IDirect3DRMDevice3 *iface)
1247 {
1248     struct d3drm_device *device = impl_from_IDirect3DRMDevice3(iface);
1249 
1250     TRACE("iface %p.\n", iface);
1251 
1252     return device->width;
1253 }
1254 
1255 static DWORD WINAPI d3drm_device3_GetTrianglesDrawn(IDirect3DRMDevice3 *iface)
1256 {
1257     FIXME("iface %p stub!\n", iface);
1258 
1259     return E_NOTIMPL;
1260 }
1261 
1262 static DWORD WINAPI d3drm_device3_GetWireframeOptions(IDirect3DRMDevice3 *iface)
1263 {
1264     FIXME("iface %p stub!\n", iface);
1265 
1266     return E_NOTIMPL;
1267 }
1268 
1269 static D3DRMRENDERQUALITY WINAPI d3drm_device3_GetQuality(IDirect3DRMDevice3 *iface)
1270 {
1271     struct d3drm_device *device = impl_from_IDirect3DRMDevice3(iface);
1272 
1273     TRACE("iface %p.\n", iface);
1274 
1275     return device->quality;
1276 }
1277 
1278 static D3DCOLORMODEL WINAPI d3drm_device3_GetColorModel(IDirect3DRMDevice3 *iface)
1279 {
1280     FIXME("iface %p stub!\n", iface);
1281 
1282     return E_NOTIMPL;
1283 }
1284 
1285 static D3DRMTEXTUREQUALITY WINAPI d3drm_device3_GetTextureQuality(IDirect3DRMDevice3 *iface)
1286 {
1287     FIXME("iface %p stub!\n", iface);
1288 
1289     return E_NOTIMPL;
1290 }
1291 
1292 static HRESULT WINAPI d3drm_device3_GetDirect3DDevice(IDirect3DRMDevice3 *iface, IDirect3DDevice **d3d_device)
1293 {
1294     struct d3drm_device *device = impl_from_IDirect3DRMDevice3(iface);
1295     TRACE("iface %p, d3d_device %p!\n", iface, d3d_device);
1296 
1297     *d3d_device = device->device;
1298     IDirect3DDevice_AddRef(*d3d_device);
1299 
1300     return D3DRM_OK;
1301 }
1302 
1303 static HRESULT WINAPI d3drm_device3_InitFromD3D2(IDirect3DRMDevice3 *iface,
1304         IDirect3D2 *d3d, IDirect3DDevice2 *d3d_device)
1305 {
1306     FIXME("iface %p, d3d %p, d3d_device %p stub!\n", iface, d3d, d3d_device);
1307 
1308     return E_NOTIMPL;
1309 }
1310 
1311 static HRESULT WINAPI d3drm_device3_InitFromSurface(IDirect3DRMDevice3 *iface,
1312         GUID *guid, IDirectDraw *ddraw, IDirectDrawSurface *backbuffer)
1313 {
1314     FIXME("iface %p, guid %s, ddraw %p, backbuffer %p stub!\n",
1315             iface, debugstr_guid(guid), ddraw, backbuffer);
1316 
1317     return E_NOTIMPL;
1318 }
1319 
1320 static HRESULT WINAPI d3drm_device3_SetRenderMode(IDirect3DRMDevice3 *iface, DWORD flags)
1321 {
1322     struct d3drm_device *device = impl_from_IDirect3DRMDevice3(iface);
1323 
1324     TRACE("iface %p, flags %#x.\n", iface, flags);
1325 
1326     device->rendermode = flags;
1327 
1328     return D3DRM_OK;
1329 }
1330 
1331 static DWORD WINAPI d3drm_device3_GetRenderMode(IDirect3DRMDevice3 *iface)
1332 {
1333     struct d3drm_device *device = impl_from_IDirect3DRMDevice3(iface);
1334 
1335     TRACE("iface %p.\n", iface);
1336 
1337     return device->rendermode;
1338 }
1339 
1340 static HRESULT WINAPI d3drm_device3_GetDirect3DDevice2(IDirect3DRMDevice3 *iface, IDirect3DDevice2 **d3d_device)
1341 {
1342     struct d3drm_device *device = impl_from_IDirect3DRMDevice3(iface);
1343 
1344     TRACE("iface %p, d3d_device %p.\n", iface, d3d_device);
1345 
1346     IDirect3DDevice_QueryInterface(device->device, &IID_IDirect3DDevice2, (void**)d3d_device);
1347 
1348     return D3DRM_OK;
1349 }
1350 
1351 static HRESULT WINAPI d3drm_device3_FindPreferredTextureFormat(IDirect3DRMDevice3 *iface,
1352         DWORD bitdepths, DWORD flags, DDPIXELFORMAT *pf)
1353 {
1354     FIXME("iface %p, bitdepths %u, flags %#x, pf %p stub!\n", iface, bitdepths, flags, pf);
1355 
1356     return E_NOTIMPL;
1357 }
1358 
1359 static HRESULT WINAPI d3drm_device3_RenderStateChange(IDirect3DRMDevice3 *iface,
1360         D3DRENDERSTATETYPE state, DWORD value, DWORD flags)
1361 {
1362     FIXME("iface %p, state %#x, value %#x, flags %#x stub!\n", iface, state, value, flags);
1363 
1364     return E_NOTIMPL;
1365 }
1366 
1367 static HRESULT WINAPI d3drm_device3_LightStateChange(IDirect3DRMDevice3 *iface,
1368         D3DLIGHTSTATETYPE state, DWORD value, DWORD flags)
1369 {
1370     FIXME("iface %p, state %#x, value %#x, flags %#x stub!\n", iface, state, value, flags);
1371 
1372     return E_NOTIMPL;
1373 }
1374 
1375 static HRESULT WINAPI d3drm_device3_GetStateChangeOptions(IDirect3DRMDevice3 *iface,
1376         DWORD state_class, DWORD state_idx, DWORD *flags)
1377 {
1378     FIXME("iface %p, state_class %#x, state_idx %#x, flags %p stub!\n",
1379             iface, state_class, state_idx, flags);
1380 
1381     return E_NOTIMPL;
1382 }
1383 
1384 static HRESULT WINAPI d3drm_device3_SetStateChangeOptions(IDirect3DRMDevice3 *iface,
1385         DWORD state_class, DWORD state_idx, DWORD flags)
1386 {
1387     FIXME("iface %p, state_class %#x, state_idx %#x, flags %#x stub!\n",
1388             iface, state_class, state_idx, flags);
1389 
1390     return E_NOTIMPL;
1391 }
1392 
1393 static const struct IDirect3DRMDevice3Vtbl d3drm_device3_vtbl =
1394 {
1395     d3drm_device3_QueryInterface,
1396     d3drm_device3_AddRef,
1397     d3drm_device3_Release,
1398     d3drm_device3_Clone,
1399     d3drm_device3_AddDestroyCallback,
1400     d3drm_device3_DeleteDestroyCallback,
1401     d3drm_device3_SetAppData,
1402     d3drm_device3_GetAppData,
1403     d3drm_device3_SetName,
1404     d3drm_device3_GetName,
1405     d3drm_device3_GetClassName,
1406     d3drm_device3_Init,
1407     d3drm_device3_InitFromD3D,
1408     d3drm_device3_InitFromClipper,
1409     d3drm_device3_Update,
1410     d3drm_device3_AddUpdateCallback,
1411     d3drm_device3_DeleteUpdateCallback,
1412     d3drm_device3_SetBufferCount,
1413     d3drm_device3_GetBufferCount,
1414     d3drm_device3_SetDither,
1415     d3drm_device3_SetShades,
1416     d3drm_device3_SetQuality,
1417     d3drm_device3_SetTextureQuality,
1418     d3drm_device3_GetViewports,
1419     d3drm_device3_GetDither,
1420     d3drm_device3_GetShades,
1421     d3drm_device3_GetHeight,
1422     d3drm_device3_GetWidth,
1423     d3drm_device3_GetTrianglesDrawn,
1424     d3drm_device3_GetWireframeOptions,
1425     d3drm_device3_GetQuality,
1426     d3drm_device3_GetColorModel,
1427     d3drm_device3_GetTextureQuality,
1428     d3drm_device3_GetDirect3DDevice,
1429     d3drm_device3_InitFromD3D2,
1430     d3drm_device3_InitFromSurface,
1431     d3drm_device3_SetRenderMode,
1432     d3drm_device3_GetRenderMode,
1433     d3drm_device3_GetDirect3DDevice2,
1434     d3drm_device3_FindPreferredTextureFormat,
1435     d3drm_device3_RenderStateChange,
1436     d3drm_device3_LightStateChange,
1437     d3drm_device3_GetStateChangeOptions,
1438     d3drm_device3_SetStateChangeOptions,
1439 };
1440 
1441 static HRESULT WINAPI d3drm_device_win_QueryInterface(IDirect3DRMWinDevice *iface, REFIID riid, void **out)
1442 {
1443     struct d3drm_device *device = impl_from_IDirect3DRMWinDevice(iface);
1444 
1445     TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
1446 
1447     return d3drm_device3_QueryInterface(&device->IDirect3DRMDevice3_iface, riid, out);
1448 }
1449 
1450 static ULONG WINAPI d3drm_device_win_AddRef(IDirect3DRMWinDevice *iface)
1451 {
1452     struct d3drm_device *device = impl_from_IDirect3DRMWinDevice(iface);
1453 
1454     TRACE("iface %p.\n", iface);
1455 
1456     return d3drm_device3_AddRef(&device->IDirect3DRMDevice3_iface);
1457 }
1458 
1459 static ULONG WINAPI d3drm_device_win_Release(IDirect3DRMWinDevice *iface)
1460 {
1461     struct d3drm_device *device = impl_from_IDirect3DRMWinDevice(iface);
1462 
1463     TRACE("iface %p.\n", iface);
1464 
1465     return d3drm_device3_Release(&device->IDirect3DRMDevice3_iface);
1466 }
1467 
1468 static HRESULT WINAPI d3drm_device_win_Clone(IDirect3DRMWinDevice *iface,
1469         IUnknown *outer, REFIID iid, void **out)
1470 {
1471     struct d3drm_device *device = impl_from_IDirect3DRMWinDevice(iface);
1472 
1473     TRACE("iface %p, outer %p, iid %s, out %p\n", iface, outer, debugstr_guid(iid), out);
1474 
1475     return IDirect3DRMDevice3_Clone(&device->IDirect3DRMDevice3_iface, outer, iid, out);
1476 }
1477 
1478 static HRESULT WINAPI d3drm_device_win_AddDestroyCallback(IDirect3DRMWinDevice *iface,
1479         D3DRMOBJECTCALLBACK cb, void *ctx)
1480 {
1481     FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
1482 
1483     return E_NOTIMPL;
1484 }
1485 
1486 static HRESULT WINAPI d3drm_device_win_DeleteDestroyCallback(IDirect3DRMWinDevice *iface,
1487         D3DRMOBJECTCALLBACK cb, void *ctx)
1488 {
1489     FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
1490 
1491     return E_NOTIMPL;
1492 }
1493 
1494 static HRESULT WINAPI d3drm_device_win_SetAppData(IDirect3DRMWinDevice *iface, DWORD data)
1495 {
1496     struct d3drm_device *device = impl_from_IDirect3DRMWinDevice(iface);
1497 
1498     TRACE("iface %p, data %#x.\n", iface, data);
1499 
1500     return IDirect3DRMDevice3_SetAppData(&device->IDirect3DRMDevice3_iface, data);
1501 }
1502 
1503 static DWORD WINAPI d3drm_device_win_GetAppData(IDirect3DRMWinDevice *iface)
1504 {
1505     struct d3drm_device *device = impl_from_IDirect3DRMWinDevice(iface);
1506 
1507     TRACE("iface %p.\n", iface);
1508 
1509     return IDirect3DRMDevice3_GetAppData(&device->IDirect3DRMDevice3_iface);
1510 }
1511 
1512 static HRESULT WINAPI d3drm_device_win_SetName(IDirect3DRMWinDevice *iface, const char *name)
1513 {
1514     struct d3drm_device *device = impl_from_IDirect3DRMWinDevice(iface);
1515 
1516     TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
1517 
1518     return IDirect3DRMDevice3_SetName(&device->IDirect3DRMDevice3_iface, name);
1519 }
1520 
1521 static HRESULT WINAPI d3drm_device_win_GetName(IDirect3DRMWinDevice *iface, DWORD *size, char *name)
1522 {
1523     struct d3drm_device *device = impl_from_IDirect3DRMWinDevice(iface);
1524 
1525     TRACE("iface %p, size %p, name %p stub!\n", iface, size, name);
1526 
1527     return IDirect3DRMDevice3_GetName(&device->IDirect3DRMDevice3_iface, size, name);
1528 }
1529 
1530 static HRESULT WINAPI d3drm_device_win_GetClassName(IDirect3DRMWinDevice *iface, DWORD *size, char *name)
1531 {
1532     struct d3drm_device *device = impl_from_IDirect3DRMWinDevice(iface);
1533 
1534     TRACE("iface %p, size %p, name %p.\n", iface, size, name);
1535 
1536     return IDirect3DRMDevice3_GetClassName(&device->IDirect3DRMDevice3_iface, size, name);
1537 }
1538 
1539 static HRESULT WINAPI d3drm_device_win_HandlePaint(IDirect3DRMWinDevice *iface, HDC dc)
1540 {
1541     FIXME("iface %p, dc %p stub!\n", iface, dc);
1542 
1543     return D3DRM_OK;
1544 }
1545 
1546 static HRESULT WINAPI d3drm_device_win_HandleActivate(IDirect3DRMWinDevice *iface, WORD wparam)
1547 {
1548     FIXME("iface %p, wparam %#x stub!\n", iface, wparam);
1549 
1550     return D3DRM_OK;
1551 }
1552 
1553 static const struct IDirect3DRMWinDeviceVtbl d3drm_device_win_vtbl =
1554 {
1555     d3drm_device_win_QueryInterface,
1556     d3drm_device_win_AddRef,
1557     d3drm_device_win_Release,
1558     d3drm_device_win_Clone,
1559     d3drm_device_win_AddDestroyCallback,
1560     d3drm_device_win_DeleteDestroyCallback,
1561     d3drm_device_win_SetAppData,
1562     d3drm_device_win_GetAppData,
1563     d3drm_device_win_SetName,
1564     d3drm_device_win_GetName,
1565     d3drm_device_win_GetClassName,
1566     d3drm_device_win_HandlePaint,
1567     d3drm_device_win_HandleActivate,
1568 };
1569 
1570 HRESULT d3drm_device_create(struct d3drm_device **out)
1571 {
1572     struct d3drm_device *object;
1573 
1574     TRACE("out %p.\n", out);
1575 
1576     if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1577         return E_OUTOFMEMORY;
1578 
1579     object->IDirect3DRMDevice_iface.lpVtbl = &d3drm_device1_vtbl;
1580     object->IDirect3DRMDevice2_iface.lpVtbl = &d3drm_device2_vtbl;
1581     object->IDirect3DRMDevice3_iface.lpVtbl = &d3drm_device3_vtbl;
1582     object->IDirect3DRMWinDevice_iface.lpVtbl = &d3drm_device_win_vtbl;
1583     object->ref = 1;
1584 
1585     *out = object;
1586 
1587     return D3DRM_OK;
1588 }
1589