wbemdisp: Implement GetObjectText_().
[wine/zf.git] / dlls / d2d1 / factory.c
blob6b6eab766c7b200a2cb290cca6d56db6fa62b634
1 /*
2 * Copyright 2014 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define D2D1_INIT_GUID
20 #include "d2d1_private.h"
22 WINE_DECLARE_DEBUG_CHANNEL(winediag);
23 WINE_DEFAULT_DEBUG_CHANNEL(d2d);
25 struct d2d_settings d2d_settings =
27 ~0u, /* No ID2D1Factory version limit by default. */
30 struct d2d_factory
32 ID2D1Factory2 ID2D1Factory2_iface;
33 LONG refcount;
35 ID3D10Device1 *device;
37 float dpi_x;
38 float dpi_y;
41 static inline struct d2d_factory *impl_from_ID2D1Factory2(ID2D1Factory2 *iface)
43 return CONTAINING_RECORD(iface, struct d2d_factory, ID2D1Factory2_iface);
46 static HRESULT d2d_factory_reload_sysmetrics(struct d2d_factory *factory)
48 HDC hdc;
50 if (!(hdc = GetDC(NULL)))
52 factory->dpi_x = factory->dpi_y = 96.0f;
53 return E_FAIL;
56 factory->dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
57 factory->dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
59 ReleaseDC(NULL, hdc);
61 return S_OK;
64 static HRESULT STDMETHODCALLTYPE d2d_factory_QueryInterface(ID2D1Factory2 *iface, REFIID iid, void **out)
66 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
68 if ((IsEqualGUID(iid, &IID_ID2D1Factory2) && d2d_settings.max_version_factory >= 2)
69 || (IsEqualGUID(iid, &IID_ID2D1Factory1) && d2d_settings.max_version_factory >= 1)
70 || IsEqualGUID(iid, &IID_ID2D1Factory)
71 || IsEqualGUID(iid, &IID_IUnknown))
73 ID2D1Factory2_AddRef(iface);
74 *out = iface;
75 return S_OK;
78 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
80 *out = NULL;
81 return E_NOINTERFACE;
84 static ULONG STDMETHODCALLTYPE d2d_factory_AddRef(ID2D1Factory2 *iface)
86 struct d2d_factory *factory = impl_from_ID2D1Factory2(iface);
87 ULONG refcount = InterlockedIncrement(&factory->refcount);
89 TRACE("%p increasing refcount to %u.\n", iface, refcount);
91 return refcount;
94 static ULONG STDMETHODCALLTYPE d2d_factory_Release(ID2D1Factory2 *iface)
96 struct d2d_factory *factory = impl_from_ID2D1Factory2(iface);
97 ULONG refcount = InterlockedDecrement(&factory->refcount);
99 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
101 if (!refcount)
103 if (factory->device)
104 ID3D10Device1_Release(factory->device);
105 heap_free(factory);
108 return refcount;
111 static HRESULT STDMETHODCALLTYPE d2d_factory_ReloadSystemMetrics(ID2D1Factory2 *iface)
113 struct d2d_factory *factory = impl_from_ID2D1Factory2(iface);
115 TRACE("iface %p.\n", iface);
117 return d2d_factory_reload_sysmetrics(factory);
120 static void STDMETHODCALLTYPE d2d_factory_GetDesktopDpi(ID2D1Factory2 *iface, float *dpi_x, float *dpi_y)
122 struct d2d_factory *factory = impl_from_ID2D1Factory2(iface);
124 TRACE("iface %p, dpi_x %p, dpi_y %p.\n", iface, dpi_x, dpi_y);
126 *dpi_x = factory->dpi_x;
127 *dpi_y = factory->dpi_y;
130 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateRectangleGeometry(ID2D1Factory2 *iface,
131 const D2D1_RECT_F *rect, ID2D1RectangleGeometry **geometry)
133 struct d2d_geometry *object;
134 HRESULT hr;
136 TRACE("iface %p, rect %s, geometry %p.\n", iface, debug_d2d_rect_f(rect), geometry);
138 if (!(object = heap_alloc_zero(sizeof(*object))))
139 return E_OUTOFMEMORY;
141 if (FAILED(hr = d2d_rectangle_geometry_init(object, (ID2D1Factory *)iface, rect)))
143 WARN("Failed to initialize rectangle geometry, hr %#x.\n", hr);
144 heap_free(object);
145 return hr;
148 TRACE("Created rectangle geometry %p.\n", object);
149 *geometry = (ID2D1RectangleGeometry *)&object->ID2D1Geometry_iface;
151 return S_OK;
154 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateRoundedRectangleGeometry(ID2D1Factory2 *iface,
155 const D2D1_ROUNDED_RECT *rounded_rect, ID2D1RoundedRectangleGeometry **geometry)
157 struct d2d_geometry *object;
158 HRESULT hr;
160 TRACE("iface %p, rounded_rect %s, geometry %p.\n", iface, debug_d2d_rounded_rect(rounded_rect), geometry);
162 if (!(object = heap_alloc_zero(sizeof(*object))))
163 return E_OUTOFMEMORY;
165 if (FAILED(hr = d2d_rounded_rectangle_geometry_init(object, (ID2D1Factory *)iface, rounded_rect)))
167 WARN("Failed to initialize rounded rectangle geometry, hr %#x.\n", hr);
168 heap_free(object);
169 return hr;
172 TRACE("Created rounded rectangle geometry %p.\n", object);
173 *geometry = (ID2D1RoundedRectangleGeometry *)&object->ID2D1Geometry_iface;
175 return S_OK;
178 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateEllipseGeometry(ID2D1Factory2 *iface,
179 const D2D1_ELLIPSE *ellipse, ID2D1EllipseGeometry **geometry)
181 struct d2d_geometry *object;
182 HRESULT hr;
184 TRACE("iface %p, ellipse %s, geometry %p.\n", iface, debug_d2d_ellipse(ellipse), geometry);
186 if (!(object = heap_alloc_zero(sizeof(*object))))
187 return E_OUTOFMEMORY;
189 if (FAILED(hr = d2d_ellipse_geometry_init(object, (ID2D1Factory *)iface, ellipse)))
191 WARN("Failed to initialize ellipse geometry, hr %#x.\n", hr);
192 heap_free(object);
193 return hr;
196 TRACE("Created ellipse geometry %p.\n", object);
197 *geometry = (ID2D1EllipseGeometry *)&object->ID2D1Geometry_iface;
199 return S_OK;
202 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateGeometryGroup(ID2D1Factory2 *iface,
203 D2D1_FILL_MODE fill_mode, ID2D1Geometry **geometries, UINT32 geometry_count, ID2D1GeometryGroup **group)
205 struct d2d_geometry *object;
206 HRESULT hr;
208 TRACE("iface %p, fill_mode %#x, geometries %p, geometry_count %u, group %p.\n",
209 iface, fill_mode, geometries, geometry_count, group);
211 if (!(object = heap_alloc_zero(sizeof(*object))))
212 return E_OUTOFMEMORY;
214 if (FAILED(hr = d2d_geometry_group_init(object, (ID2D1Factory *)iface, fill_mode, geometries, geometry_count)))
216 WARN("Failed to initialize geometry group, hr %#x.\n", hr);
217 heap_free(object);
218 return hr;
221 TRACE("Created geometry group %p.\n", object);
222 *group = (ID2D1GeometryGroup *)&object->ID2D1Geometry_iface;
224 return S_OK;
227 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateTransformedGeometry(ID2D1Factory2 *iface,
228 ID2D1Geometry *src_geometry, const D2D1_MATRIX_3X2_F *transform,
229 ID2D1TransformedGeometry **transformed_geometry)
231 struct d2d_geometry *object;
233 TRACE("iface %p, src_geometry %p, transform %p, transformed_geometry %p.\n",
234 iface, src_geometry, transform, transformed_geometry);
236 if (!(object = heap_alloc_zero(sizeof(*object))))
237 return E_OUTOFMEMORY;
239 d2d_transformed_geometry_init(object, (ID2D1Factory *)iface, src_geometry, transform);
241 TRACE("Created transformed geometry %p.\n", object);
242 *transformed_geometry = (ID2D1TransformedGeometry *)&object->ID2D1Geometry_iface;
244 return S_OK;
247 static HRESULT STDMETHODCALLTYPE d2d_factory_CreatePathGeometry(ID2D1Factory2 *iface, ID2D1PathGeometry **geometry)
249 struct d2d_geometry *object;
251 TRACE("iface %p, geometry %p.\n", iface, geometry);
253 if (!(object = heap_alloc_zero(sizeof(*object))))
254 return E_OUTOFMEMORY;
256 d2d_path_geometry_init(object, (ID2D1Factory *)iface);
258 TRACE("Created path geometry %p.\n", object);
259 *geometry = (ID2D1PathGeometry *)&object->ID2D1Geometry_iface;
261 return S_OK;
264 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateStrokeStyle(ID2D1Factory2 *iface,
265 const D2D1_STROKE_STYLE_PROPERTIES *desc, const float *dashes, UINT32 dash_count,
266 ID2D1StrokeStyle **stroke_style)
268 struct d2d_stroke_style *object;
269 HRESULT hr;
271 TRACE("iface %p, desc %p, dashes %p, dash_count %u, stroke_style %p.\n",
272 iface, desc, dashes, dash_count, stroke_style);
274 if (!(object = heap_alloc_zero(sizeof(*object))))
275 return E_OUTOFMEMORY;
277 if (FAILED(hr = d2d_stroke_style_init(object, (ID2D1Factory *)iface, desc, dashes, dash_count)))
279 WARN("Failed to initialize stroke style, hr %#x.\n", hr);
280 heap_free(object);
281 return hr;
284 TRACE("Created stroke style %p.\n", object);
285 *stroke_style = &object->ID2D1StrokeStyle_iface;
287 return S_OK;
290 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDrawingStateBlock(ID2D1Factory2 *iface,
291 const D2D1_DRAWING_STATE_DESCRIPTION *desc, IDWriteRenderingParams *text_rendering_params,
292 ID2D1DrawingStateBlock **state_block)
294 D2D1_DRAWING_STATE_DESCRIPTION1 state_desc;
295 struct d2d_state_block *object;
297 TRACE("iface %p, desc %p, text_rendering_params %p, state_block %p.\n",
298 iface, desc, text_rendering_params, state_block);
300 if (!(object = heap_alloc_zero(sizeof(*object))))
301 return E_OUTOFMEMORY;
303 if (desc)
305 memcpy(&state_desc, desc, sizeof(*desc));
306 state_desc.primitiveBlend = D2D1_PRIMITIVE_BLEND_SOURCE_OVER;
307 state_desc.unitMode = D2D1_UNIT_MODE_DIPS;
310 d2d_state_block_init(object, (ID2D1Factory *)iface, desc ? &state_desc : NULL, text_rendering_params);
312 TRACE("Created state block %p.\n", object);
313 *state_block = (ID2D1DrawingStateBlock *)&object->ID2D1DrawingStateBlock1_iface;
315 return S_OK;
318 static HRESULT d2d_factory_get_device(struct d2d_factory *factory, ID3D10Device1 **device)
320 HRESULT hr = S_OK;
322 if (!factory->device && FAILED(hr = D3D10CreateDevice1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, D3D10_CREATE_DEVICE_BGRA_SUPPORT,
323 D3D10_FEATURE_LEVEL_10_0, D3D10_1_SDK_VERSION, &factory->device)))
324 WARN("Failed to create device, hr %#x.\n", hr);
326 *device = factory->device;
327 return hr;
330 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateWicBitmapRenderTarget(ID2D1Factory2 *iface,
331 IWICBitmap *target, const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1RenderTarget **render_target)
333 struct d2d_factory *factory = impl_from_ID2D1Factory2(iface);
334 struct d2d_wic_render_target *object;
335 ID3D10Device1 *device;
336 HRESULT hr;
338 TRACE("iface %p, target %p, desc %p, render_target %p.\n", iface, target, desc, render_target);
340 if (!(object = heap_alloc_zero(sizeof(*object))))
341 return E_OUTOFMEMORY;
343 if (FAILED(hr = d2d_factory_get_device(factory, &device)))
345 heap_free(object);
346 return hr;
349 if (FAILED(hr = d2d_wic_render_target_init(object, (ID2D1Factory1 *)iface, device, target, desc)))
351 WARN("Failed to initialize render target, hr %#x.\n", hr);
352 heap_free(object);
353 return hr;
356 TRACE("Created render target %p.\n", object);
357 *render_target = object->dxgi_target;
359 return S_OK;
362 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateHwndRenderTarget(ID2D1Factory2 *iface,
363 const D2D1_RENDER_TARGET_PROPERTIES *desc, const D2D1_HWND_RENDER_TARGET_PROPERTIES *hwnd_rt_desc,
364 ID2D1HwndRenderTarget **render_target)
366 struct d2d_factory *factory = impl_from_ID2D1Factory2(iface);
367 struct d2d_hwnd_render_target *object;
368 ID3D10Device1 *device;
369 HRESULT hr;
371 TRACE("iface %p, desc %p, hwnd_rt_desc %p, render_target %p.\n", iface, desc, hwnd_rt_desc, render_target);
373 if (FAILED(hr = d2d_factory_get_device(factory, &device)))
374 return hr;
376 if (!(object = heap_alloc_zero(sizeof(*object))))
377 return E_OUTOFMEMORY;
379 if (FAILED(hr = d2d_hwnd_render_target_init(object, (ID2D1Factory1 *)iface, device, desc, hwnd_rt_desc)))
381 WARN("Failed to initialize render target, hr %#x.\n", hr);
382 heap_free(object);
383 return hr;
386 TRACE("Created render target %p.\n", object);
387 *render_target = &object->ID2D1HwndRenderTarget_iface;
389 return S_OK;
392 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDxgiSurfaceRenderTarget(ID2D1Factory2 *iface,
393 IDXGISurface *surface, const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1RenderTarget **render_target)
395 IDXGIDevice *dxgi_device;
396 ID2D1Device *device;
397 HRESULT hr;
399 TRACE("iface %p, surface %p, desc %p, render_target %p.\n", iface, surface, desc, render_target);
401 if (FAILED(hr = IDXGISurface_GetDevice(surface, &IID_IDXGIDevice, (void **)&dxgi_device)))
403 WARN("Failed to get DXGI device, hr %#x.\n", hr);
404 return hr;
407 hr = ID2D1Factory1_CreateDevice((ID2D1Factory1 *)iface, dxgi_device, &device);
408 IDXGIDevice_Release(dxgi_device);
409 if (FAILED(hr))
411 WARN("Failed to create D2D device, hr %#x.\n", hr);
412 return hr;
415 hr = d2d_d3d_create_render_target(device, surface, NULL, NULL, desc, (void **)render_target);
416 ID2D1Device_Release(device);
417 return hr;
420 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDCRenderTarget(ID2D1Factory2 *iface,
421 const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1DCRenderTarget **render_target)
423 struct d2d_factory *factory = impl_from_ID2D1Factory2(iface);
424 struct d2d_dc_render_target *object;
425 ID3D10Device1 *device;
426 HRESULT hr;
428 TRACE("iface %p, desc %p, render_target %p.\n", iface, desc, render_target);
430 if (FAILED(hr = d2d_factory_get_device(factory, &device)))
431 return hr;
433 if (!(object = heap_alloc_zero(sizeof(*object))))
434 return E_OUTOFMEMORY;
436 if (FAILED(hr = d2d_dc_render_target_init(object, (ID2D1Factory1 *)iface, device, desc)))
438 WARN("Failed to initialize render target, hr %#x.\n", hr);
439 heap_free(object);
440 return hr;
443 TRACE("Created render target %p.\n", object);
444 *render_target = &object->ID2D1DCRenderTarget_iface;
446 return S_OK;
449 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDevice(ID2D1Factory2 *iface,
450 IDXGIDevice *dxgi_device, ID2D1Device **device)
452 struct d2d_device *object;
454 TRACE("iface %p, dxgi_device %p, device %p.\n", iface, dxgi_device, device);
456 if (!(object = heap_alloc_zero(sizeof(*object))))
457 return E_OUTOFMEMORY;
459 d2d_device_init(object, (ID2D1Factory1 *)iface, dxgi_device);
461 TRACE("Create device %p.\n", object);
462 *device = &object->ID2D1Device_iface;
464 return S_OK;
467 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateStrokeStyle1(ID2D1Factory2 *iface,
468 const D2D1_STROKE_STYLE_PROPERTIES1 *desc, const float *dashes, UINT32 dash_count,
469 ID2D1StrokeStyle1 **stroke_style)
471 FIXME("iface %p, desc %p, dashes %p, dash_count %u, stroke_style %p stub!\n",
472 iface, desc, dashes, dash_count, stroke_style);
474 return E_NOTIMPL;
477 static HRESULT STDMETHODCALLTYPE d2d_factory_CreatePathGeometry1(ID2D1Factory2 *iface, ID2D1PathGeometry1 **geometry)
479 FIXME("iface %p, geometry %p stub!\n", iface, geometry);
481 return E_NOTIMPL;
484 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDrawingStateBlock1(ID2D1Factory2 *iface,
485 const D2D1_DRAWING_STATE_DESCRIPTION1 *desc, IDWriteRenderingParams *text_rendering_params,
486 ID2D1DrawingStateBlock1 **state_block)
488 struct d2d_state_block *object;
490 TRACE("iface %p, desc %p, text_rendering_params %p, state_block %p.\n",
491 iface, desc, text_rendering_params, state_block);
493 if (!(object = heap_alloc_zero(sizeof(*object))))
494 return E_OUTOFMEMORY;
496 d2d_state_block_init(object, (ID2D1Factory *)iface, desc, text_rendering_params);
498 TRACE("Created state block %p.\n", object);
499 *state_block = &object->ID2D1DrawingStateBlock1_iface;
501 return S_OK;
504 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateGdiMetafile(ID2D1Factory2 *iface,
505 IStream *stream, ID2D1GdiMetafile **metafile)
507 FIXME("iface %p, stream %p, metafile %p stub!\n", iface, stream, metafile);
509 return E_NOTIMPL;
512 static HRESULT STDMETHODCALLTYPE d2d_factory_RegisterEffectFromStream(ID2D1Factory2 *iface,
513 REFCLSID effect_id, IStream *property_xml, const D2D1_PROPERTY_BINDING *bindings,
514 UINT32 binding_count, PD2D1_EFFECT_FACTORY effect_factory)
516 FIXME("iface %p, effect_id %s, property_xml %p, bindings %p, binding_count %u, effect_factory %p stub!\n",
517 iface, debugstr_guid(effect_id), property_xml, bindings, binding_count, effect_factory);
519 return E_NOTIMPL;
522 static HRESULT STDMETHODCALLTYPE d2d_factory_RegisterEffectFromString(ID2D1Factory2 *iface,
523 REFCLSID effect_id, const WCHAR *property_xml, const D2D1_PROPERTY_BINDING *bindings,
524 UINT32 binding_count, PD2D1_EFFECT_FACTORY effect_factory)
526 FIXME("iface %p, effect_id %s, property_xml %s, bindings %p, binding_count %u, effect_factory %p stub!\n",
527 iface, debugstr_guid(effect_id), debugstr_w(property_xml), bindings, binding_count, effect_factory);
529 return S_OK;
532 static HRESULT STDMETHODCALLTYPE d2d_factory_UnregisterEffect(ID2D1Factory2 *iface, REFCLSID effect_id)
534 FIXME("iface %p, effect_id %s stub!\n", iface, debugstr_guid(effect_id));
536 return E_NOTIMPL;
539 static HRESULT STDMETHODCALLTYPE d2d_factory_GetRegisteredEffects(ID2D1Factory2 *iface,
540 CLSID *effects, UINT32 effect_count, UINT32 *returned, UINT32 *registered)
542 FIXME("iface %p, effects %p, effect_count %u, returned %p, registered %p stub!\n",
543 iface, effects, effect_count, returned, registered);
545 return E_NOTIMPL;
548 static HRESULT STDMETHODCALLTYPE d2d_factory_GetEffectProperties(ID2D1Factory2 *iface,
549 REFCLSID effect_id, ID2D1Properties **props)
551 FIXME("iface %p, effect_id %s, props %p stub!\n", iface, debugstr_guid(effect_id), props);
553 return E_NOTIMPL;
556 static HRESULT STDMETHODCALLTYPE d2d_factory_ID2D1Factory1_CreateDevice(ID2D1Factory2 *iface, IDXGIDevice *dxgi_device,
557 ID2D1Device1 **device)
559 FIXME("iface %p, dxgi_device %p, device %p stub!\n", iface, dxgi_device, device);
561 return E_NOTIMPL;
564 static const struct ID2D1Factory2Vtbl d2d_factory_vtbl =
566 d2d_factory_QueryInterface,
567 d2d_factory_AddRef,
568 d2d_factory_Release,
569 d2d_factory_ReloadSystemMetrics,
570 d2d_factory_GetDesktopDpi,
571 d2d_factory_CreateRectangleGeometry,
572 d2d_factory_CreateRoundedRectangleGeometry,
573 d2d_factory_CreateEllipseGeometry,
574 d2d_factory_CreateGeometryGroup,
575 d2d_factory_CreateTransformedGeometry,
576 d2d_factory_CreatePathGeometry,
577 d2d_factory_CreateStrokeStyle,
578 d2d_factory_CreateDrawingStateBlock,
579 d2d_factory_CreateWicBitmapRenderTarget,
580 d2d_factory_CreateHwndRenderTarget,
581 d2d_factory_CreateDxgiSurfaceRenderTarget,
582 d2d_factory_CreateDCRenderTarget,
583 d2d_factory_CreateDevice,
584 d2d_factory_CreateStrokeStyle1,
585 d2d_factory_CreatePathGeometry1,
586 d2d_factory_CreateDrawingStateBlock1,
587 d2d_factory_CreateGdiMetafile,
588 d2d_factory_RegisterEffectFromStream,
589 d2d_factory_RegisterEffectFromString,
590 d2d_factory_UnregisterEffect,
591 d2d_factory_GetRegisteredEffects,
592 d2d_factory_GetEffectProperties,
593 d2d_factory_ID2D1Factory1_CreateDevice,
596 static void d2d_factory_init(struct d2d_factory *factory, D2D1_FACTORY_TYPE factory_type,
597 const D2D1_FACTORY_OPTIONS *factory_options)
599 if (factory_type != D2D1_FACTORY_TYPE_SINGLE_THREADED)
600 FIXME("Ignoring factory type %#x.\n", factory_type);
601 if (factory_options && factory_options->debugLevel != D2D1_DEBUG_LEVEL_NONE)
602 WARN("Ignoring debug level %#x.\n", factory_options->debugLevel);
604 factory->ID2D1Factory2_iface.lpVtbl = &d2d_factory_vtbl;
605 factory->refcount = 1;
606 d2d_factory_reload_sysmetrics(factory);
609 HRESULT WINAPI D2D1CreateFactory(D2D1_FACTORY_TYPE factory_type, REFIID iid,
610 const D2D1_FACTORY_OPTIONS *factory_options, void **factory)
612 struct d2d_factory *object;
613 HRESULT hr;
615 TRACE("factory_type %#x, iid %s, factory_options %p, factory %p.\n",
616 factory_type, debugstr_guid(iid), factory_options, factory);
618 if (!(object = heap_alloc_zero(sizeof(*object))))
619 return E_OUTOFMEMORY;
621 d2d_factory_init(object, factory_type, factory_options);
623 TRACE("Created factory %p.\n", object);
625 hr = ID2D1Factory2_QueryInterface(&object->ID2D1Factory2_iface, iid, factory);
626 ID2D1Factory2_Release(&object->ID2D1Factory2_iface);
628 return hr;
631 void WINAPI D2D1MakeRotateMatrix(float angle, D2D1_POINT_2F center, D2D1_MATRIX_3X2_F *matrix)
633 float theta, sin_theta, cos_theta;
635 TRACE("angle %.8e, center %s, matrix %p.\n", angle, debug_d2d_point_2f(&center), matrix);
637 theta = angle * (M_PI / 180.0f);
638 sin_theta = sinf(theta);
639 cos_theta = cosf(theta);
641 /* translate(center) * rotate(theta) * translate(-center) */
642 matrix->_11 = cos_theta;
643 matrix->_12 = sin_theta;
644 matrix->_21 = -sin_theta;
645 matrix->_22 = cos_theta;
646 matrix->_31 = center.x - center.x * cos_theta + center.y * sin_theta;
647 matrix->_32 = center.y - center.x * sin_theta - center.y * cos_theta;
650 void WINAPI D2D1MakeSkewMatrix(float angle_x, float angle_y, D2D1_POINT_2F center, D2D1_MATRIX_3X2_F *matrix)
652 float tan_x, tan_y;
654 TRACE("angle_x %.8e, angle_y %.8e, center %s, matrix %p.\n", angle_x, angle_y, debug_d2d_point_2f(&center), matrix);
656 tan_x = tan(angle_x * (M_PI / 180.0f));
657 tan_y = tan(angle_y * (M_PI / 180.0f));
659 /* translate(-center) * skew() * translate(center) */
660 matrix->_11 = 1.0f;
661 matrix->_12 = tan_y;
662 matrix->_21 = tan_x;
663 matrix->_22 = 1.0f;
664 matrix->_31 = -tan_x * center.y;
665 matrix->_32 = -tan_y * center.x;
668 BOOL WINAPI D2D1IsMatrixInvertible(const D2D1_MATRIX_3X2_F *matrix)
670 TRACE("matrix %p.\n", matrix);
672 return (matrix->_11 * matrix->_22 - matrix->_21 * matrix->_12) != 0.0f;
675 BOOL WINAPI D2D1InvertMatrix(D2D1_MATRIX_3X2_F *matrix)
677 D2D1_MATRIX_3X2_F m = *matrix;
679 TRACE("matrix %p.\n", matrix);
681 return d2d_matrix_invert(matrix, &m);
684 HRESULT WINAPI D2D1CreateDevice(IDXGIDevice *dxgi_device,
685 const D2D1_CREATION_PROPERTIES *properties, ID2D1Device **device)
687 D2D1_CREATION_PROPERTIES default_properties = {0};
688 D2D1_FACTORY_OPTIONS factory_options;
689 ID3D11Device *d3d_device;
690 ID2D1Factory1 *factory;
691 HRESULT hr;
693 TRACE("dxgi_device %p, properties %p, device %p.\n", dxgi_device, properties, device);
695 if (!properties)
697 if (SUCCEEDED(IDXGIDevice_QueryInterface(dxgi_device, &IID_ID3D11Device, (void **)&d3d_device)))
699 if (!(ID3D11Device_GetCreationFlags(d3d_device) & D3D11_CREATE_DEVICE_SINGLETHREADED))
700 default_properties.threadingMode = D2D1_THREADING_MODE_MULTI_THREADED;
701 ID3D11Device_Release(d3d_device);
703 properties = &default_properties;
706 factory_options.debugLevel = properties->debugLevel;
707 if (FAILED(hr = D2D1CreateFactory(properties->threadingMode,
708 &IID_ID2D1Factory1, &factory_options, (void **)&factory)))
709 return hr;
711 hr = ID2D1Factory1_CreateDevice(factory, dxgi_device, device);
712 ID2D1Factory1_Release(factory);
713 return hr;
716 void WINAPI D2D1SinCos(float angle, float *s, float *c)
718 TRACE("angle %.8e, s %p, c %p.\n", angle, s, c);
720 *s = sinf(angle);
721 *c = cosf(angle);
724 float WINAPI D2D1Tan(float angle)
726 TRACE("angle %.8e.\n", angle);
728 return tanf(angle);
731 float WINAPI D2D1Vec3Length(float x, float y, float z)
733 TRACE("x %.8e, y %.8e, z %.8e.\n", x, y, z);
735 return sqrtf(x * x + y * y + z * z);
738 static BOOL get_config_key_dword(HKEY default_key, HKEY application_key, const char *name, DWORD *value)
740 DWORD type, data, size;
742 size = sizeof(data);
743 if (application_key && !RegQueryValueExA(application_key,
744 name, 0, &type, (BYTE *)&data, &size) && type == REG_DWORD)
745 goto success;
747 size = sizeof(data);
748 if (default_key && !RegQueryValueExA(default_key,
749 name, 0, &type, (BYTE *)&data, &size) && type == REG_DWORD)
750 goto success;
752 return FALSE;
754 success:
755 *value = data;
756 return TRUE;
759 static void d2d_settings_init(void)
761 HKEY default_key, tmp_key, application_key = NULL;
762 char buffer[MAX_PATH + 10];
763 DWORD len;
765 if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Direct2D", &default_key))
766 default_key = NULL;
768 len = GetModuleFileNameA(0, buffer, MAX_PATH);
769 if (len && len < MAX_PATH)
771 char *p, *appname = buffer;
773 if ((p = strrchr(appname, '/')))
774 appname = p + 1;
775 if ((p = strrchr(appname, '\\')))
776 appname = p + 1;
777 strcat(appname, "\\Direct2D");
779 if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmp_key))
781 if (RegOpenKeyA(tmp_key, appname, &application_key))
782 application_key = NULL;
783 RegCloseKey(tmp_key);
787 if (!default_key && !application_key)
788 return;
790 if (get_config_key_dword(default_key, application_key, "max_version_factory", &d2d_settings.max_version_factory))
791 ERR_(winediag)("Limiting maximum Direct2D factory version to %#x.\n", d2d_settings.max_version_factory);
793 if (application_key)
794 RegCloseKey(application_key);
795 if (default_key)
796 RegCloseKey(default_key);
799 BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, void *reserved)
801 if (reason == DLL_PROCESS_ATTACH)
802 d2d_settings_init();
803 return TRUE;