wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / d3drm / viewport.c
blob8d9c4fde822d6597eef4066a6057aec89e1460ce
1 /*
2 * Implementation of IDirect3DRMViewport Interface
4 * Copyright 2012 André Hentschel
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 "d3drm_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(d3drm);
25 static inline struct d3drm_viewport *impl_from_IDirect3DRMViewport(IDirect3DRMViewport *iface)
27 return CONTAINING_RECORD(iface, struct d3drm_viewport, IDirect3DRMViewport_iface);
30 static inline struct d3drm_viewport *impl_from_IDirect3DRMViewport2(IDirect3DRMViewport2 *iface)
32 return CONTAINING_RECORD(iface, struct d3drm_viewport, IDirect3DRMViewport2_iface);
35 static inline void d3drm_normalize_d3d_color(D3DCOLORVALUE *color_value, D3DCOLOR color)
37 color_value->u1.r = RGBA_GETRED(color) / 255.0f;
38 color_value->u2.g = RGBA_GETGREEN(color) / 255.0f;
39 color_value->u3.b = RGBA_GETBLUE(color) / 255.0f;
40 color_value->u4.a = RGBA_GETALPHA(color) / 255.0f;
43 static HRESULT d3drm_update_background_material(struct d3drm_viewport *viewport)
45 IDirect3DRMFrame *root_frame;
46 D3DCOLOR color;
47 D3DMATERIAL mat;
48 HRESULT hr;
50 if (FAILED(hr = IDirect3DRMFrame_GetScene(viewport->camera, &root_frame)))
51 return hr;
52 color = IDirect3DRMFrame_GetSceneBackground(root_frame);
53 IDirect3DRMFrame_Release(root_frame);
55 memset(&mat, 0, sizeof(mat));
56 mat.dwSize = sizeof(mat);
57 d3drm_normalize_d3d_color(&mat.u.diffuse, color);
59 return IDirect3DMaterial_SetMaterial(viewport->material, &mat);
62 static void d3drm_viewport_destroy(struct d3drm_viewport *viewport)
64 TRACE("viewport %p releasing attached interfaces.\n", viewport);
66 d3drm_object_cleanup((IDirect3DRMObject *)&viewport->IDirect3DRMViewport_iface, &viewport->obj);
68 if (viewport->d3d_viewport)
70 IDirect3DViewport_Release(viewport->d3d_viewport);
71 IDirect3DMaterial_Release(viewport->material);
72 IDirect3DRMFrame_Release(viewport->camera);
73 IDirect3DRM_Release(viewport->d3drm);
76 heap_free(viewport);
79 static HRESULT WINAPI d3drm_viewport2_QueryInterface(IDirect3DRMViewport2 *iface, REFIID riid, void **out)
81 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
83 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
85 if (IsEqualGUID(riid, &IID_IDirect3DRMViewport)
86 || IsEqualGUID(riid, &IID_IDirect3DRMObject)
87 || IsEqualGUID(riid, &IID_IUnknown))
89 *out = &viewport->IDirect3DRMViewport_iface;
91 else if (IsEqualGUID(riid, &IID_IDirect3DRMViewport2))
93 *out = &viewport->IDirect3DRMViewport2_iface;
95 else
97 *out = NULL;
98 WARN("%s not implemented, returning CLASS_E_CLASSNOTAVAILABLE.\n", debugstr_guid(riid));
99 return CLASS_E_CLASSNOTAVAILABLE;
102 IUnknown_AddRef((IUnknown *)*out);
103 return S_OK;
106 static HRESULT WINAPI d3drm_viewport1_QueryInterface(IDirect3DRMViewport *iface, REFIID riid, void **out)
108 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
110 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
112 return d3drm_viewport2_QueryInterface(&viewport->IDirect3DRMViewport2_iface, riid, out);
115 static ULONG WINAPI d3drm_viewport2_AddRef(IDirect3DRMViewport2 *iface)
117 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
118 ULONG refcount = InterlockedIncrement(&viewport->obj.ref);
120 TRACE("%p increasing refcount to %u.\n", iface, refcount);
122 return refcount;
125 static ULONG WINAPI d3drm_viewport1_AddRef(IDirect3DRMViewport *iface)
127 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
129 TRACE("iface %p.\n", iface);
131 return d3drm_viewport2_AddRef(&viewport->IDirect3DRMViewport2_iface);
134 static ULONG WINAPI d3drm_viewport2_Release(IDirect3DRMViewport2 *iface)
136 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
137 ULONG refcount = InterlockedDecrement(&viewport->obj.ref);
139 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
141 if (!refcount)
142 d3drm_viewport_destroy(viewport);
144 return refcount;
147 static ULONG WINAPI d3drm_viewport1_Release(IDirect3DRMViewport *iface)
149 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
151 TRACE("iface %p.\n", iface);
153 return d3drm_viewport2_Release(&viewport->IDirect3DRMViewport2_iface);
156 static HRESULT WINAPI d3drm_viewport2_Clone(IDirect3DRMViewport2 *iface,
157 IUnknown *outer, REFIID iid, void **out)
159 FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface, outer, debugstr_guid(iid), out);
161 return E_NOTIMPL;
164 static HRESULT WINAPI d3drm_viewport1_Clone(IDirect3DRMViewport *iface,
165 IUnknown *outer, REFIID iid, void **out)
167 FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface, outer, debugstr_guid(iid), out);
169 return E_NOTIMPL;
172 static HRESULT WINAPI d3drm_viewport2_AddDestroyCallback(IDirect3DRMViewport2 *iface,
173 D3DRMOBJECTCALLBACK cb, void *ctx)
175 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
177 TRACE("iface %p, cb %p, ctx %p\n", iface, cb, ctx);
179 return d3drm_object_add_destroy_callback(&viewport->obj, cb, ctx);
182 static HRESULT WINAPI d3drm_viewport1_AddDestroyCallback(IDirect3DRMViewport *iface,
183 D3DRMOBJECTCALLBACK cb, void *ctx)
185 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
187 TRACE("iface %p, cb %p, ctx %p\n", iface, cb, ctx);
189 return d3drm_viewport2_AddDestroyCallback(&viewport->IDirect3DRMViewport2_iface, cb, ctx);
192 static HRESULT WINAPI d3drm_viewport2_DeleteDestroyCallback(IDirect3DRMViewport2 *iface,
193 D3DRMOBJECTCALLBACK cb, void *ctx)
195 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
197 TRACE("iface %p, cb %p, ctx %p\n", iface, cb, ctx);
199 return d3drm_object_delete_destroy_callback(&viewport->obj, cb, ctx);
202 static HRESULT WINAPI d3drm_viewport1_DeleteDestroyCallback(IDirect3DRMViewport *iface,
203 D3DRMOBJECTCALLBACK cb, void *ctx)
205 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
207 TRACE("iface %p, cb %p, ctx %p\n", iface, cb, ctx);
209 return d3drm_viewport2_DeleteDestroyCallback(&viewport->IDirect3DRMViewport2_iface, cb, ctx);
212 static HRESULT WINAPI d3drm_viewport2_SetAppData(IDirect3DRMViewport2 *iface, DWORD data)
214 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
216 TRACE("iface %p, data %#x\n", iface, data);
218 viewport->obj.appdata = data;
219 return S_OK;
222 static HRESULT WINAPI d3drm_viewport1_SetAppData(IDirect3DRMViewport *iface, DWORD data)
224 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
226 TRACE("iface %p, data %#x\n", iface, data);
228 return d3drm_viewport2_SetAppData(&viewport->IDirect3DRMViewport2_iface, data);
231 static DWORD WINAPI d3drm_viewport2_GetAppData(IDirect3DRMViewport2 *iface)
233 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
235 TRACE("iface %p\n", iface);
237 return viewport->obj.appdata;
240 static DWORD WINAPI d3drm_viewport1_GetAppData(IDirect3DRMViewport *iface)
242 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
244 TRACE("iface %p.\n", iface);
246 return d3drm_viewport2_GetAppData(&viewport->IDirect3DRMViewport2_iface);
249 static HRESULT WINAPI d3drm_viewport2_SetName(IDirect3DRMViewport2 *iface, const char *name)
251 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
253 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
255 return d3drm_object_set_name(&viewport->obj, name);
258 static HRESULT WINAPI d3drm_viewport1_SetName(IDirect3DRMViewport *iface, const char *name)
260 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
262 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
264 return d3drm_viewport2_SetName(&viewport->IDirect3DRMViewport2_iface, name);
267 static HRESULT WINAPI d3drm_viewport2_GetName(IDirect3DRMViewport2 *iface, DWORD *size, char *name)
269 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
271 TRACE("iface %p, size %p, name %p.\n", iface, size, name);
273 return d3drm_object_get_name(&viewport->obj, size, name);
276 static HRESULT WINAPI d3drm_viewport1_GetName(IDirect3DRMViewport *iface, DWORD *size, char *name)
278 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
280 TRACE("iface %p, size %p, name %p.\n", iface, size, name);
282 return d3drm_viewport2_GetName(&viewport->IDirect3DRMViewport2_iface, size, name);
285 static HRESULT WINAPI d3drm_viewport2_GetClassName(IDirect3DRMViewport2 *iface, DWORD *size, char *name)
287 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
289 TRACE("iface %p, size %p, name %p.\n", iface, size, name);
291 return d3drm_object_get_class_name(&viewport->obj, size, name);
294 static HRESULT WINAPI d3drm_viewport1_GetClassName(IDirect3DRMViewport *iface, DWORD *size, char *name)
296 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
298 TRACE("iface %p, size %p, name %p.\n", iface, size, name);
300 return d3drm_viewport2_GetClassName(&viewport->IDirect3DRMViewport2_iface, size, name);
303 static HRESULT WINAPI d3drm_viewport2_Init(IDirect3DRMViewport2 *iface, IDirect3DRMDevice3 *device,
304 IDirect3DRMFrame3 *camera, DWORD x, DWORD y, DWORD width, DWORD height)
306 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
307 struct d3drm_device *device_obj = unsafe_impl_from_IDirect3DRMDevice3(device);
308 D3DVIEWPORT vp;
309 D3DVALUE scale;
310 IDirect3D *d3d1 = NULL;
311 IDirect3DDevice *d3d_device = NULL;
312 IDirect3DMaterial *material = NULL;
313 D3DMATERIALHANDLE hmat;
314 HRESULT hr = D3DRM_OK;
316 TRACE("iface %p, device %p, camera %p, x %u, y %u, width %u, height %u.\n",
317 iface, device, camera, x, y, width, height);
319 if (!device_obj || !camera
320 || width > device_obj->width
321 || height > device_obj->height)
323 return D3DRMERR_BADOBJECT;
326 if (viewport->d3d_viewport)
327 return D3DRMERR_BADOBJECT;
329 IDirect3DRM_AddRef(viewport->d3drm);
331 if (FAILED(hr = IDirect3DRMDevice3_GetDirect3DDevice(device, &d3d_device)))
332 goto cleanup;
334 if (FAILED(hr = IDirect3DDevice_GetDirect3D(d3d_device, &d3d1)))
335 goto cleanup;
337 if (FAILED(hr = IDirect3D_CreateViewport(d3d1, &viewport->d3d_viewport, NULL)))
338 goto cleanup;
340 if (FAILED(hr = IDirect3DDevice_AddViewport(d3d_device, viewport->d3d_viewport)))
341 goto cleanup;
343 vp.dwSize = sizeof(vp);
344 vp.dwWidth = width;
345 vp.dwHeight = height;
346 vp.dwX = x;
347 vp.dwY = y;
348 scale = width > height ? (float)width / 2.0f : (float)height / 2.0f;
349 vp.dvScaleX = scale;
350 vp.dvScaleY = scale;
351 vp.dvMaxX = vp.dwWidth / (2.0f * vp.dvScaleX);
352 vp.dvMaxY = vp.dwHeight / (2.0f * vp.dvScaleY);
353 vp.dvMinZ = 0.0f;
354 vp.dvMaxZ = 1.0f;
356 if (FAILED(hr = IDirect3DViewport_SetViewport(viewport->d3d_viewport, &vp)))
357 goto cleanup;
359 if (FAILED(hr = IDirect3DRMFrame3_QueryInterface(camera, &IID_IDirect3DRMFrame, (void **)&viewport->camera)))
360 goto cleanup;
362 if (FAILED(hr = IDirect3D_CreateMaterial(d3d1, &material, NULL)))
363 goto cleanup;
365 if (FAILED(hr = IDirect3DMaterial_GetHandle(material, d3d_device, &hmat)))
366 goto cleanup;
368 hr = IDirect3DViewport_SetBackground(viewport->d3d_viewport, hmat);
369 viewport->material = material;
370 viewport->device = device_obj;
372 viewport->clip.left = -0.5f;
373 viewport->clip.top = 0.5f;
374 viewport->clip.right = 0.5f;
375 viewport->clip.bottom = -0.5f;
376 viewport->clip.front = 1.0f;
377 viewport->clip.back = 100.0f;
379 cleanup:
381 if (FAILED(hr))
383 if (viewport->d3d_viewport)
385 IDirect3DViewport_Release(viewport->d3d_viewport);
386 viewport->d3d_viewport = NULL;
388 if (viewport->camera)
389 IDirect3DRMFrame_Release(viewport->camera);
390 if (material)
391 IDirect3DMaterial_Release(material);
392 IDirect3DRM_Release(viewport->d3drm);
394 if (d3d_device)
395 IDirect3DDevice_Release(d3d_device);
396 if (d3d1)
397 IDirect3D_Release(d3d1);
399 return hr;
402 static HRESULT WINAPI d3drm_viewport1_Init(IDirect3DRMViewport *iface, IDirect3DRMDevice *device,
403 IDirect3DRMFrame *camera, DWORD x, DWORD y, DWORD width, DWORD height)
405 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
406 struct d3drm_frame *frame = unsafe_impl_from_IDirect3DRMFrame(camera);
407 IDirect3DRMDevice3 *device3;
408 HRESULT hr;
410 TRACE("iface %p, device %p, camera %p, x %u, y %u, width %u, height %u.\n",
411 iface, device, camera, x, y, width, height);
413 if (!device || !frame)
414 return D3DRMERR_BADOBJECT;
416 if (FAILED(hr = IDirect3DRMDevice_QueryInterface(device, &IID_IDirect3DRMDevice3, (void **)&device3)))
417 return hr;
419 hr = d3drm_viewport2_Init(&viewport->IDirect3DRMViewport2_iface, device3, &frame->IDirect3DRMFrame3_iface,
420 x, y, width, height);
421 IDirect3DRMDevice3_Release(device3);
423 return hr;
426 static HRESULT WINAPI d3drm_viewport2_Clear(IDirect3DRMViewport2 *iface, DWORD flags)
428 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
429 DDSCAPS caps = { DDSCAPS_ZBUFFER };
430 HRESULT hr;
431 D3DRECT clear_rect;
432 IDirectDrawSurface *ds;
433 DWORD clear_flags = 0;
435 TRACE("iface %p, flags %#x.\n", iface, flags);
437 clear_rect.u1.x1 = clear_rect.u2.y1 = 0;
438 clear_rect.u3.x2 = viewport->device->width;
439 clear_rect.u4.y2 = viewport->device->height;
441 if (flags & D3DRMCLEAR_TARGET)
443 clear_flags |= D3DCLEAR_TARGET;
444 d3drm_update_background_material(viewport);
446 if (flags & D3DRMCLEAR_ZBUFFER)
448 hr = IDirectDrawSurface_GetAttachedSurface(viewport->device->render_target, &caps, &ds);
449 if (SUCCEEDED(hr))
451 clear_flags |= D3DCLEAR_ZBUFFER;
452 IDirectDrawSurface_Release(ds);
455 if (flags & D3DRMCLEAR_DIRTYRECTS)
456 FIXME("Flag D3DRMCLEAR_DIRTYRECT not implemented yet.\n");
458 if (FAILED(hr = IDirect3DViewport_Clear(viewport->d3d_viewport, 1, &clear_rect, clear_flags)))
459 return hr;
461 return D3DRM_OK;
464 static HRESULT WINAPI d3drm_viewport1_Clear(IDirect3DRMViewport *iface)
466 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
468 TRACE("iface %p.\n", iface);
470 return d3drm_viewport2_Clear(&viewport->IDirect3DRMViewport2_iface, D3DRMCLEAR_ALL);
473 static HRESULT WINAPI d3drm_viewport2_Render(IDirect3DRMViewport2 *iface, IDirect3DRMFrame3 *frame)
475 FIXME("iface %p, frame %p stub!\n", iface, frame);
477 return D3DRM_OK;
480 static HRESULT WINAPI d3drm_viewport1_Render(IDirect3DRMViewport *iface, IDirect3DRMFrame *frame)
482 FIXME("iface %p, frame %p stub!\n", iface, frame);
484 return D3DRM_OK;
487 static HRESULT WINAPI d3drm_viewport2_SetFront(IDirect3DRMViewport2 *iface, D3DVALUE front)
489 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
491 TRACE("iface %p, front %.8e.\n", iface, front);
493 if (!viewport->d3d_viewport)
494 return D3DRMERR_BADOBJECT;
496 if (front <= 0.0f)
497 return D3DRMERR_BADVALUE;
499 viewport->clip.front = front;
501 return D3DRM_OK;
504 static HRESULT WINAPI d3drm_viewport1_SetFront(IDirect3DRMViewport *iface, D3DVALUE front)
506 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
508 TRACE("iface %p, front %.8e.\n", iface, front);
510 return d3drm_viewport2_SetFront(&viewport->IDirect3DRMViewport2_iface, front);
513 static HRESULT WINAPI d3drm_viewport2_SetBack(IDirect3DRMViewport2 *iface, D3DVALUE back)
515 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
517 TRACE("iface %p, back %.8e.\n", iface, back);
519 if (!viewport->d3d_viewport)
520 return D3DRMERR_BADOBJECT;
522 if (back <= viewport->clip.front)
523 return D3DRMERR_BADVALUE;
525 viewport->clip.back = back;
527 return D3DRM_OK;
530 static HRESULT WINAPI d3drm_viewport1_SetBack(IDirect3DRMViewport *iface, D3DVALUE back)
532 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
534 TRACE("iface %p, back %.8e.\n", iface, back);
536 return d3drm_viewport2_SetBack(&viewport->IDirect3DRMViewport2_iface, back);
539 static HRESULT WINAPI d3drm_viewport2_SetField(IDirect3DRMViewport2 *iface, D3DVALUE field)
541 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
543 TRACE("iface %p, field %.8e.\n", iface, field);
545 if (!viewport->d3d_viewport)
546 return D3DRMERR_BADOBJECT;
548 if (field <= 0.0f)
549 return D3DRMERR_BADVALUE;
551 viewport->clip.left = -field;
552 viewport->clip.right = field;
553 viewport->clip.bottom = -field;
554 viewport->clip.top = field;
556 return D3DRM_OK;
559 static HRESULT WINAPI d3drm_viewport1_SetField(IDirect3DRMViewport *iface, D3DVALUE field)
561 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
563 TRACE("iface %p, field %.8e.\n", iface, field);
565 return d3drm_viewport2_SetField(&viewport->IDirect3DRMViewport2_iface, field);
568 static HRESULT WINAPI d3drm_viewport2_SetUniformScaling(IDirect3DRMViewport2 *iface, BOOL b)
570 FIXME("iface %p, b %#x stub!\n", iface, b);
572 return E_NOTIMPL;
575 static HRESULT WINAPI d3drm_viewport1_SetUniformScaling(IDirect3DRMViewport *iface, BOOL b)
577 FIXME("iface %p, b %#x stub!\n", iface, b);
579 return E_NOTIMPL;
582 static HRESULT WINAPI d3drm_viewport2_SetCamera(IDirect3DRMViewport2 *iface, IDirect3DRMFrame3 *camera)
584 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
585 struct d3drm_frame *frame = unsafe_impl_from_IDirect3DRMFrame3(camera);
587 TRACE("iface %p, camera %p.\n", iface, camera);
589 if (!camera || !viewport->camera)
590 return D3DRMERR_BADOBJECT;
592 IDirect3DRMFrame_AddRef(&frame->IDirect3DRMFrame_iface);
593 IDirect3DRMFrame_Release(viewport->camera);
594 viewport->camera = &frame->IDirect3DRMFrame_iface;
596 return D3DRM_OK;
599 static HRESULT WINAPI d3drm_viewport1_SetCamera(IDirect3DRMViewport *iface, IDirect3DRMFrame *camera)
601 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
602 struct d3drm_frame *frame = unsafe_impl_from_IDirect3DRMFrame(camera);
604 TRACE("iface %p, camera %p.\n", iface, camera);
606 return d3drm_viewport2_SetCamera(&viewport->IDirect3DRMViewport2_iface,
607 frame ? &frame->IDirect3DRMFrame3_iface : NULL);
610 static HRESULT WINAPI d3drm_viewport2_SetProjection(IDirect3DRMViewport2 *iface, D3DRMPROJECTIONTYPE type)
612 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
614 TRACE("iface %p, type %#x.\n", iface, type);
616 if (!viewport->d3d_viewport)
617 return D3DRMERR_BADOBJECT;
619 viewport->projection = type;
621 return D3DRM_OK;
624 static HRESULT WINAPI d3drm_viewport1_SetProjection(IDirect3DRMViewport *iface, D3DRMPROJECTIONTYPE type)
626 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
628 TRACE("iface %p, type %#x.\n", iface, type);
630 return d3drm_viewport2_SetProjection(&viewport->IDirect3DRMViewport2_iface, type);
633 static HRESULT WINAPI d3drm_viewport2_Transform(IDirect3DRMViewport2 *iface, D3DRMVECTOR4D *d, D3DVECTOR *s)
635 FIXME("iface %p, d %p, s %p stub!\n", iface, d, s);
637 return E_NOTIMPL;
640 static HRESULT WINAPI d3drm_viewport1_Transform(IDirect3DRMViewport *iface, D3DRMVECTOR4D *d, D3DVECTOR *s)
642 FIXME("iface %p, d %p, s %p stub!\n", iface, d, s);
644 return E_NOTIMPL;
647 static HRESULT WINAPI d3drm_viewport2_InverseTransform(IDirect3DRMViewport2 *iface, D3DVECTOR *d, D3DRMVECTOR4D *s)
649 FIXME("iface %p, d %p, s %p stub!\n", iface, d, s);
651 return E_NOTIMPL;
654 static HRESULT WINAPI d3drm_viewport1_InverseTransform(IDirect3DRMViewport *iface, D3DVECTOR *d, D3DRMVECTOR4D *s)
656 FIXME("iface %p, d %p, s %p stub!\n", iface, d, s);
658 return E_NOTIMPL;
661 static HRESULT WINAPI d3drm_viewport2_Configure(IDirect3DRMViewport2 *iface,
662 LONG x, LONG y, DWORD width, DWORD height)
664 FIXME("iface %p, x %d, y %d, width %u, height %u stub!\n", iface, x, y, width, height);
666 return E_NOTIMPL;
669 static HRESULT WINAPI d3drm_viewport1_Configure(IDirect3DRMViewport *iface,
670 LONG x, LONG y, DWORD width, DWORD height)
672 FIXME("iface %p, x %d, y %d, width %u, height %u stub!\n", iface, x, y, width, height);
674 return E_NOTIMPL;
677 static HRESULT WINAPI d3drm_viewport2_ForceUpdate(IDirect3DRMViewport2* iface,
678 DWORD x1, DWORD y1, DWORD x2, DWORD y2)
680 FIXME("iface %p, x1 %u, y1 %u, x2 %u, y2 %u stub!\n", iface, x1, y1, x2, y2);
682 return E_NOTIMPL;
685 static HRESULT WINAPI d3drm_viewport1_ForceUpdate(IDirect3DRMViewport *iface,
686 DWORD x1, DWORD y1, DWORD x2, DWORD y2)
688 FIXME("iface %p, x1 %u, y1 %u, x2 %u, y2 %u stub!\n", iface, x1, y1, x2, y2);
690 return E_NOTIMPL;
693 static HRESULT WINAPI d3drm_viewport2_SetPlane(IDirect3DRMViewport2 *iface,
694 D3DVALUE left, D3DVALUE right, D3DVALUE bottom, D3DVALUE top)
696 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
698 TRACE("iface %p, left %.8e, right %.8e, bottom %.8e, top %.8e.\n",
699 iface, left, right, bottom, top);
701 if (!viewport->d3d_viewport)
702 return D3DRMERR_BADOBJECT;
704 viewport->clip.left = left;
705 viewport->clip.right = right;
706 viewport->clip.bottom = bottom;
707 viewport->clip.top = top;
709 return D3DRM_OK;
712 static HRESULT WINAPI d3drm_viewport1_SetPlane(IDirect3DRMViewport *iface,
713 D3DVALUE left, D3DVALUE right, D3DVALUE bottom, D3DVALUE top)
715 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
717 TRACE("iface %p, left %.8e, right %.8e, bottom %.8e, top %.8e.\n",
718 iface, left, right, bottom, top);
720 return d3drm_viewport2_SetPlane(&viewport->IDirect3DRMViewport2_iface, left, right, bottom, top);
723 static HRESULT WINAPI d3drm_viewport2_GetCamera(IDirect3DRMViewport2 *iface, IDirect3DRMFrame3 **camera)
725 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
727 TRACE("iface %p, camera %p.\n", iface, camera);
729 if (!camera)
730 return D3DRMERR_BADVALUE;
732 if (!viewport->camera)
733 return D3DRMERR_BADOBJECT;
735 return IDirect3DRMFrame_QueryInterface(viewport->camera, &IID_IDirect3DRMFrame3, (void **)camera);
738 static HRESULT WINAPI d3drm_viewport1_GetCamera(IDirect3DRMViewport *iface, IDirect3DRMFrame **camera)
740 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
741 struct d3drm_frame *camera_impl;
742 IDirect3DRMFrame3 *camera3;
743 HRESULT hr;
745 TRACE("iface %p, camera %p.\n", iface, camera);
747 if (!camera)
748 return D3DRMERR_BADVALUE;
750 if (FAILED(hr = d3drm_viewport2_GetCamera(&viewport->IDirect3DRMViewport2_iface, &camera3)))
751 return hr;
753 camera_impl = unsafe_impl_from_IDirect3DRMFrame3(camera3);
754 *camera = &camera_impl->IDirect3DRMFrame_iface;
756 return D3DRM_OK;
759 static HRESULT WINAPI d3drm_viewport2_GetDevice(IDirect3DRMViewport2 *iface, IDirect3DRMDevice3 **device)
761 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
763 TRACE("iface %p, device %p.\n", iface, device);
765 if (!device)
766 return D3DRMERR_BADVALUE;
768 if (!viewport->device)
769 return D3DRMERR_BADOBJECT;
771 *device = &viewport->device->IDirect3DRMDevice3_iface;
772 IDirect3DRMDevice3_AddRef(*device);
774 return D3DRM_OK;
777 static HRESULT WINAPI d3drm_viewport1_GetDevice(IDirect3DRMViewport *iface, IDirect3DRMDevice **device)
779 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
781 TRACE("iface %p, device %p.\n\n", iface, device);
783 if (!device)
784 return D3DRMERR_BADVALUE;
786 if (!viewport->device)
787 return D3DRMERR_BADOBJECT;
789 *device = &viewport->device->IDirect3DRMDevice_iface;
790 IDirect3DRMDevice_AddRef(*device);
792 return D3DRM_OK;
795 static HRESULT WINAPI d3drm_viewport2_GetPlane(IDirect3DRMViewport2 *iface,
796 D3DVALUE *left, D3DVALUE *right, D3DVALUE *bottom, D3DVALUE *top)
798 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
800 TRACE("iface %p, left %p, right %p, bottom %p, top %p.\n",
801 iface, left, right, bottom, top);
803 if (!viewport->d3d_viewport)
804 return D3DRMERR_BADOBJECT;
806 *left = viewport->clip.left;
807 *right = viewport->clip.right;
808 *bottom = viewport->clip.bottom;
809 *top = viewport->clip.top;
811 return D3DRM_OK;
814 static HRESULT WINAPI d3drm_viewport1_GetPlane(IDirect3DRMViewport *iface,
815 D3DVALUE *left, D3DVALUE *right, D3DVALUE *bottom, D3DVALUE *top)
817 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
819 TRACE("iface %p, left %p, right %p, bottom %p, top %p.\n",
820 iface, left, right, bottom, top);
822 return d3drm_viewport2_GetPlane(&viewport->IDirect3DRMViewport2_iface, left, right, bottom, top);
825 static HRESULT WINAPI d3drm_viewport2_Pick(IDirect3DRMViewport2 *iface,
826 LONG x, LONG y, IDirect3DRMPickedArray **visuals)
828 FIXME("iface %p, x %d, y %d, visuals %p stub!\n", iface, x, y, visuals);
830 return E_NOTIMPL;
833 static HRESULT WINAPI d3drm_viewport1_Pick(IDirect3DRMViewport *iface,
834 LONG x, LONG y, IDirect3DRMPickedArray **visuals)
836 FIXME("iface %p, x %d, y %d, visuals %p stub!\n", iface, x, y, visuals);
838 return E_NOTIMPL;
841 static BOOL WINAPI d3drm_viewport2_GetUniformScaling(IDirect3DRMViewport2 *iface)
843 FIXME("iface %p stub!\n", iface);
845 return FALSE;
848 static BOOL WINAPI d3drm_viewport1_GetUniformScaling(IDirect3DRMViewport *iface)
850 FIXME("iface %p stub!\n", iface);
852 return FALSE;
855 static LONG WINAPI d3drm_viewport2_GetX(IDirect3DRMViewport2 *iface)
857 FIXME("iface %p stub!\n", iface);
859 return E_NOTIMPL;
862 static LONG WINAPI d3drm_viewport1_GetX(IDirect3DRMViewport *iface)
864 FIXME("iface %p stub!\n", iface);
866 return E_NOTIMPL;
869 static LONG WINAPI d3drm_viewport2_GetY(IDirect3DRMViewport2 *iface)
871 FIXME("iface %p stub!\n", iface);
873 return E_NOTIMPL;
876 static LONG WINAPI d3drm_viewport1_GetY(IDirect3DRMViewport *iface)
878 FIXME("iface %p stub!\n", iface);
880 return E_NOTIMPL;
883 static DWORD WINAPI d3drm_viewport2_GetWidth(IDirect3DRMViewport2 *iface)
885 FIXME("iface %p stub!\n", iface);
887 return E_NOTIMPL;
890 static DWORD WINAPI d3drm_viewport1_GetWidth(IDirect3DRMViewport *iface)
892 FIXME("iface %p stub!\n", iface);
894 return E_NOTIMPL;
897 static DWORD WINAPI d3drm_viewport2_GetHeight(IDirect3DRMViewport2 *iface)
899 FIXME("iface %p stub!\n", iface);
901 return E_NOTIMPL;
904 static DWORD WINAPI d3drm_viewport1_GetHeight(IDirect3DRMViewport *iface)
906 FIXME("iface %p stub!\n", iface);
908 return E_NOTIMPL;
911 static D3DVALUE WINAPI d3drm_viewport2_GetField(IDirect3DRMViewport2 *iface)
913 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
915 TRACE("iface %p.\n", iface);
917 if (!viewport->d3d_viewport)
918 return -1.0f;
920 return (viewport->clip.right - viewport->clip.left
921 + viewport->clip.top - viewport->clip.bottom) / 4.0f;
924 static D3DVALUE WINAPI d3drm_viewport1_GetField(IDirect3DRMViewport *iface)
926 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
928 TRACE("iface %p.\n", iface);
930 return d3drm_viewport2_GetField(&viewport->IDirect3DRMViewport2_iface);
933 static D3DVALUE WINAPI d3drm_viewport2_GetBack(IDirect3DRMViewport2 *iface)
935 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
937 TRACE("iface %p.\n", iface);
939 if (!viewport->d3d_viewport)
940 return -1.0f;
942 return viewport->clip.back;
945 static D3DVALUE WINAPI d3drm_viewport1_GetBack(IDirect3DRMViewport *iface)
947 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
949 TRACE("iface %p.\n", iface);
951 return d3drm_viewport2_GetBack(&viewport->IDirect3DRMViewport2_iface);
954 static D3DVALUE WINAPI d3drm_viewport2_GetFront(IDirect3DRMViewport2 *iface)
956 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
958 TRACE("iface %p.\n", iface);
960 if (!viewport->d3d_viewport)
961 return -1.0f;
963 return viewport->clip.front;
966 static D3DVALUE WINAPI d3drm_viewport1_GetFront(IDirect3DRMViewport *iface)
968 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
970 TRACE("iface %p.\n", iface);
972 return d3drm_viewport2_GetFront(&viewport->IDirect3DRMViewport2_iface);
975 static D3DRMPROJECTIONTYPE WINAPI d3drm_viewport2_GetProjection(IDirect3DRMViewport2 *iface)
977 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
979 TRACE("iface %p.\n", iface);
981 if (!viewport->d3d_viewport)
982 return ~0u;
984 return viewport->projection;
987 static D3DRMPROJECTIONTYPE WINAPI d3drm_viewport1_GetProjection(IDirect3DRMViewport *iface)
989 struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
991 TRACE("iface %p.\n", iface);
993 return d3drm_viewport2_GetProjection(&viewport->IDirect3DRMViewport2_iface);
996 static HRESULT WINAPI d3drm_viewport2_GetDirect3DViewport(IDirect3DRMViewport2 *iface,
997 IDirect3DViewport **viewport)
999 struct d3drm_viewport *viewport_object = impl_from_IDirect3DRMViewport2(iface);
1001 TRACE("iface %p, viewport %p.\n", iface, viewport);
1003 if (!viewport)
1004 return D3DRMERR_BADVALUE;
1006 if (!viewport_object->d3d_viewport)
1007 return D3DRMERR_BADOBJECT;
1009 *viewport = viewport_object->d3d_viewport;
1010 IDirect3DViewport_AddRef(*viewport);
1012 return D3DRM_OK;
1015 static HRESULT WINAPI d3drm_viewport1_GetDirect3DViewport(IDirect3DRMViewport *iface,
1016 IDirect3DViewport **viewport)
1018 struct d3drm_viewport *viewport_object = impl_from_IDirect3DRMViewport(iface);
1020 TRACE("iface %p, viewport %p.\n", iface, viewport);
1022 return d3drm_viewport2_GetDirect3DViewport(&viewport_object->IDirect3DRMViewport2_iface, viewport);
1025 static HRESULT WINAPI d3drm_viewport2_TransformVectors(IDirect3DRMViewport2 *iface,
1026 DWORD vector_count, D3DRMVECTOR4D *dst, D3DVECTOR *src)
1028 FIXME("iface %p, vector_count %u, dst %p, src %p stub!\n", iface, vector_count, dst, src);
1030 return E_NOTIMPL;
1033 static HRESULT WINAPI d3drm_viewport2_InverseTransformVectors(IDirect3DRMViewport2 *iface,
1034 DWORD vector_count, D3DVECTOR *dst, D3DRMVECTOR4D *src)
1036 FIXME("iface %p, vector_count %u, dst %p, src %p stub!\n", iface, vector_count, dst, src);
1038 return E_NOTIMPL;
1041 static const struct IDirect3DRMViewport2Vtbl d3drm_viewport2_vtbl =
1043 d3drm_viewport2_QueryInterface,
1044 d3drm_viewport2_AddRef,
1045 d3drm_viewport2_Release,
1046 d3drm_viewport2_Clone,
1047 d3drm_viewport2_AddDestroyCallback,
1048 d3drm_viewport2_DeleteDestroyCallback,
1049 d3drm_viewport2_SetAppData,
1050 d3drm_viewport2_GetAppData,
1051 d3drm_viewport2_SetName,
1052 d3drm_viewport2_GetName,
1053 d3drm_viewport2_GetClassName,
1054 d3drm_viewport2_Init,
1055 d3drm_viewport2_Clear,
1056 d3drm_viewport2_Render,
1057 d3drm_viewport2_SetFront,
1058 d3drm_viewport2_SetBack,
1059 d3drm_viewport2_SetField,
1060 d3drm_viewport2_SetUniformScaling,
1061 d3drm_viewport2_SetCamera,
1062 d3drm_viewport2_SetProjection,
1063 d3drm_viewport2_Transform,
1064 d3drm_viewport2_InverseTransform,
1065 d3drm_viewport2_Configure,
1066 d3drm_viewport2_ForceUpdate,
1067 d3drm_viewport2_SetPlane,
1068 d3drm_viewport2_GetCamera,
1069 d3drm_viewport2_GetDevice,
1070 d3drm_viewport2_GetPlane,
1071 d3drm_viewport2_Pick,
1072 d3drm_viewport2_GetUniformScaling,
1073 d3drm_viewport2_GetX,
1074 d3drm_viewport2_GetY,
1075 d3drm_viewport2_GetWidth,
1076 d3drm_viewport2_GetHeight,
1077 d3drm_viewport2_GetField,
1078 d3drm_viewport2_GetBack,
1079 d3drm_viewport2_GetFront,
1080 d3drm_viewport2_GetProjection,
1081 d3drm_viewport2_GetDirect3DViewport,
1082 d3drm_viewport2_TransformVectors,
1083 d3drm_viewport2_InverseTransformVectors,
1086 static const struct IDirect3DRMViewportVtbl d3drm_viewport1_vtbl =
1088 d3drm_viewport1_QueryInterface,
1089 d3drm_viewport1_AddRef,
1090 d3drm_viewport1_Release,
1091 d3drm_viewport1_Clone,
1092 d3drm_viewport1_AddDestroyCallback,
1093 d3drm_viewport1_DeleteDestroyCallback,
1094 d3drm_viewport1_SetAppData,
1095 d3drm_viewport1_GetAppData,
1096 d3drm_viewport1_SetName,
1097 d3drm_viewport1_GetName,
1098 d3drm_viewport1_GetClassName,
1099 d3drm_viewport1_Init,
1100 d3drm_viewport1_Clear,
1101 d3drm_viewport1_Render,
1102 d3drm_viewport1_SetFront,
1103 d3drm_viewport1_SetBack,
1104 d3drm_viewport1_SetField,
1105 d3drm_viewport1_SetUniformScaling,
1106 d3drm_viewport1_SetCamera,
1107 d3drm_viewport1_SetProjection,
1108 d3drm_viewport1_Transform,
1109 d3drm_viewport1_InverseTransform,
1110 d3drm_viewport1_Configure,
1111 d3drm_viewport1_ForceUpdate,
1112 d3drm_viewport1_SetPlane,
1113 d3drm_viewport1_GetCamera,
1114 d3drm_viewport1_GetDevice,
1115 d3drm_viewport1_GetPlane,
1116 d3drm_viewport1_Pick,
1117 d3drm_viewport1_GetUniformScaling,
1118 d3drm_viewport1_GetX,
1119 d3drm_viewport1_GetY,
1120 d3drm_viewport1_GetWidth,
1121 d3drm_viewport1_GetHeight,
1122 d3drm_viewport1_GetField,
1123 d3drm_viewport1_GetBack,
1124 d3drm_viewport1_GetFront,
1125 d3drm_viewport1_GetProjection,
1126 d3drm_viewport1_GetDirect3DViewport,
1129 HRESULT d3drm_viewport_create(struct d3drm_viewport **viewport, IDirect3DRM *d3drm)
1131 static const char classname[] = "Viewport";
1132 struct d3drm_viewport *object;
1134 TRACE("viewport %p, d3drm %p.\n", viewport, d3drm);
1136 if (!(object = heap_alloc_zero(sizeof(*object))))
1137 return E_OUTOFMEMORY;
1139 object->IDirect3DRMViewport_iface.lpVtbl = &d3drm_viewport1_vtbl;
1140 object->IDirect3DRMViewport2_iface.lpVtbl = &d3drm_viewport2_vtbl;
1141 object->d3drm = d3drm;
1142 d3drm_object_init(&object->obj, classname);
1144 *viewport = object;
1146 return S_OK;