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"
23 #include "wine/list.h"
25 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
26 WINE_DEFAULT_DEBUG_CHANNEL(d2d
);
28 struct d2d_settings d2d_settings
=
30 ~0u, /* No ID2D1Factory version limit by default. */
33 static void d2d_effect_registration_cleanup(struct d2d_effect_registration
*reg
)
35 d2d_effect_properties_cleanup(®
->properties
);
41 ID2D1Factory3 ID2D1Factory3_iface
;
42 ID2D1Multithread ID2D1Multithread_iface
;
45 ID3D10Device1
*device
;
51 INIT_ONCE init_builtins
;
56 static inline struct d2d_factory
*impl_from_ID2D1Factory3(ID2D1Factory3
*iface
)
58 return CONTAINING_RECORD(iface
, struct d2d_factory
, ID2D1Factory3_iface
);
61 static inline struct d2d_factory
*unsafe_impl_from_ID2D1Factory(ID2D1Factory
*iface
)
63 return CONTAINING_RECORD(iface
, struct d2d_factory
, ID2D1Factory3_iface
);
66 static inline struct d2d_factory
*impl_from_ID2D1Multithread(ID2D1Multithread
*iface
)
68 return CONTAINING_RECORD(iface
, struct d2d_factory
, ID2D1Multithread_iface
);
71 static BOOL WINAPI
d2d_factory_builtins_initonce(INIT_ONCE
*once
, void *param
, void **context
)
73 d2d_effects_init_builtins(param
);
78 static void d2d_factory_init_builtin_effects(struct d2d_factory
*factory
)
80 InitOnceExecuteOnce(&factory
->init_builtins
, d2d_factory_builtins_initonce
, factory
, NULL
);
83 void d2d_factory_register_effect(struct d2d_factory
*factory
, struct d2d_effect_registration
*effect
)
85 list_add_tail(&factory
->effects
, &effect
->entry
);
88 struct d2d_effect_registration
* d2d_factory_get_registered_effect(ID2D1Factory
*iface
,
91 struct d2d_factory
*factory
= unsafe_impl_from_ID2D1Factory(iface
);
92 struct d2d_effect_registration
*reg
;
94 d2d_effects_init_builtins(factory
);
96 LIST_FOR_EACH_ENTRY(reg
, &factory
->effects
, struct d2d_effect_registration
, entry
)
98 if (IsEqualGUID(id
, ®
->id
)) return reg
;
104 static HRESULT
d2d_factory_reload_sysmetrics(struct d2d_factory
*factory
)
108 if (!(hdc
= GetDC(NULL
)))
110 factory
->dpi_x
= factory
->dpi_y
= 96.0f
;
114 factory
->dpi_x
= GetDeviceCaps(hdc
, LOGPIXELSX
);
115 factory
->dpi_y
= GetDeviceCaps(hdc
, LOGPIXELSY
);
117 ReleaseDC(NULL
, hdc
);
122 static HRESULT STDMETHODCALLTYPE
d2d_factory_QueryInterface(ID2D1Factory3
*iface
, REFIID iid
, void **out
)
124 struct d2d_factory
*factory
= impl_from_ID2D1Factory3(iface
);
126 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
128 if ((IsEqualGUID(iid
, &IID_ID2D1Factory3
) && d2d_settings
.max_version_factory
>= 3)
129 || (IsEqualGUID(iid
, &IID_ID2D1Factory2
) && d2d_settings
.max_version_factory
>= 2)
130 || (IsEqualGUID(iid
, &IID_ID2D1Factory1
) && d2d_settings
.max_version_factory
>= 1)
131 || IsEqualGUID(iid
, &IID_ID2D1Factory
)
132 || IsEqualGUID(iid
, &IID_IUnknown
))
134 ID2D1Factory3_AddRef(iface
);
138 else if (IsEqualGUID(iid
, &IID_ID2D1Multithread
))
140 ID2D1Factory3_AddRef(iface
);
141 *out
= &factory
->ID2D1Multithread_iface
;
145 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
148 return E_NOINTERFACE
;
151 static ULONG STDMETHODCALLTYPE
d2d_factory_AddRef(ID2D1Factory3
*iface
)
153 struct d2d_factory
*factory
= impl_from_ID2D1Factory3(iface
);
154 ULONG refcount
= InterlockedIncrement(&factory
->refcount
);
156 TRACE("%p increasing refcount to %lu.\n", iface
, refcount
);
161 static ULONG STDMETHODCALLTYPE
d2d_factory_Release(ID2D1Factory3
*iface
)
163 struct d2d_factory
*factory
= impl_from_ID2D1Factory3(iface
);
164 ULONG refcount
= InterlockedDecrement(&factory
->refcount
);
165 struct d2d_effect_registration
*reg
, *reg2
;
167 TRACE("%p decreasing refcount to %lu.\n", iface
, refcount
);
172 ID3D10Device1_Release(factory
->device
);
173 LIST_FOR_EACH_ENTRY_SAFE(reg
, reg2
, &factory
->effects
, struct d2d_effect_registration
, entry
)
175 d2d_effect_registration_cleanup(reg
);
177 DeleteCriticalSection(&factory
->cs
);
184 static HRESULT STDMETHODCALLTYPE
d2d_factory_ReloadSystemMetrics(ID2D1Factory3
*iface
)
186 struct d2d_factory
*factory
= impl_from_ID2D1Factory3(iface
);
188 TRACE("iface %p.\n", iface
);
190 return d2d_factory_reload_sysmetrics(factory
);
193 static void STDMETHODCALLTYPE
d2d_factory_GetDesktopDpi(ID2D1Factory3
*iface
, float *dpi_x
, float *dpi_y
)
195 struct d2d_factory
*factory
= impl_from_ID2D1Factory3(iface
);
197 TRACE("iface %p, dpi_x %p, dpi_y %p.\n", iface
, dpi_x
, dpi_y
);
199 *dpi_x
= factory
->dpi_x
;
200 *dpi_y
= factory
->dpi_y
;
203 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateRectangleGeometry(ID2D1Factory3
*iface
,
204 const D2D1_RECT_F
*rect
, ID2D1RectangleGeometry
**geometry
)
206 struct d2d_geometry
*object
;
209 TRACE("iface %p, rect %s, geometry %p.\n", iface
, debug_d2d_rect_f(rect
), geometry
);
211 if (!(object
= calloc(1, sizeof(*object
))))
212 return E_OUTOFMEMORY
;
214 if (FAILED(hr
= d2d_rectangle_geometry_init(object
, (ID2D1Factory
*)iface
, rect
)))
216 WARN("Failed to initialise rectangle geometry, hr %#lx.\n", hr
);
221 TRACE("Created rectangle geometry %p.\n", object
);
222 *geometry
= (ID2D1RectangleGeometry
*)&object
->ID2D1Geometry_iface
;
227 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateRoundedRectangleGeometry(ID2D1Factory3
*iface
,
228 const D2D1_ROUNDED_RECT
*rounded_rect
, ID2D1RoundedRectangleGeometry
**geometry
)
230 struct d2d_geometry
*object
;
233 TRACE("iface %p, rounded_rect %s, geometry %p.\n", iface
, debug_d2d_rounded_rect(rounded_rect
), geometry
);
235 if (!(object
= calloc(1, sizeof(*object
))))
236 return E_OUTOFMEMORY
;
238 if (FAILED(hr
= d2d_rounded_rectangle_geometry_init(object
, (ID2D1Factory
*)iface
, rounded_rect
)))
240 WARN("Failed to initialise rounded rectangle geometry, hr %#lx.\n", hr
);
245 TRACE("Created rounded rectangle geometry %p.\n", object
);
246 *geometry
= (ID2D1RoundedRectangleGeometry
*)&object
->ID2D1Geometry_iface
;
251 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateEllipseGeometry(ID2D1Factory3
*iface
,
252 const D2D1_ELLIPSE
*ellipse
, ID2D1EllipseGeometry
**geometry
)
254 struct d2d_geometry
*object
;
257 TRACE("iface %p, ellipse %s, geometry %p.\n", iface
, debug_d2d_ellipse(ellipse
), geometry
);
259 if (!(object
= calloc(1, sizeof(*object
))))
260 return E_OUTOFMEMORY
;
262 if (FAILED(hr
= d2d_ellipse_geometry_init(object
, (ID2D1Factory
*)iface
, ellipse
)))
264 WARN("Failed to initialise ellipse geometry, hr %#lx.\n", hr
);
269 TRACE("Created ellipse geometry %p.\n", object
);
270 *geometry
= (ID2D1EllipseGeometry
*)&object
->ID2D1Geometry_iface
;
275 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateGeometryGroup(ID2D1Factory3
*iface
,
276 D2D1_FILL_MODE fill_mode
, ID2D1Geometry
**geometries
, UINT32 geometry_count
, ID2D1GeometryGroup
**group
)
278 struct d2d_geometry
*object
;
281 TRACE("iface %p, fill_mode %#x, geometries %p, geometry_count %u, group %p.\n",
282 iface
, fill_mode
, geometries
, geometry_count
, group
);
284 if (!(object
= calloc(1, sizeof(*object
))))
285 return E_OUTOFMEMORY
;
287 if (FAILED(hr
= d2d_geometry_group_init(object
, (ID2D1Factory
*)iface
, fill_mode
, geometries
, geometry_count
)))
289 WARN("Failed to initialise geometry group, hr %#lx.\n", hr
);
294 TRACE("Created geometry group %p.\n", object
);
295 *group
= (ID2D1GeometryGroup
*)&object
->ID2D1Geometry_iface
;
300 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateTransformedGeometry(ID2D1Factory3
*iface
,
301 ID2D1Geometry
*src_geometry
, const D2D1_MATRIX_3X2_F
*transform
,
302 ID2D1TransformedGeometry
**transformed_geometry
)
304 struct d2d_geometry
*object
;
306 TRACE("iface %p, src_geometry %p, transform %p, transformed_geometry %p.\n",
307 iface
, src_geometry
, transform
, transformed_geometry
);
309 if (!(object
= calloc(1, sizeof(*object
))))
310 return E_OUTOFMEMORY
;
312 d2d_transformed_geometry_init(object
, (ID2D1Factory
*)iface
, src_geometry
, transform
);
314 TRACE("Created transformed geometry %p.\n", object
);
315 *transformed_geometry
= (ID2D1TransformedGeometry
*)&object
->ID2D1Geometry_iface
;
320 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreatePathGeometry(ID2D1Factory3
*iface
, ID2D1PathGeometry
**geometry
)
322 struct d2d_geometry
*object
;
324 TRACE("iface %p, geometry %p.\n", iface
, geometry
);
326 if (!(object
= calloc(1, sizeof(*object
))))
327 return E_OUTOFMEMORY
;
329 d2d_path_geometry_init(object
, (ID2D1Factory
*)iface
);
331 TRACE("Created path geometry %p.\n", object
);
332 *geometry
= (ID2D1PathGeometry
*)&object
->ID2D1Geometry_iface
;
337 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateStrokeStyle(ID2D1Factory3
*iface
,
338 const D2D1_STROKE_STYLE_PROPERTIES
*desc
, const float *dashes
, UINT32 dash_count
,
339 ID2D1StrokeStyle
**stroke_style
)
341 struct d2d_stroke_style
*object
;
342 D2D1_STROKE_STYLE_PROPERTIES1 desc1
;
345 TRACE("iface %p, desc %p, dashes %p, dash_count %u, stroke_style %p.\n",
346 iface
, desc
, dashes
, dash_count
, stroke_style
);
348 if (!(object
= calloc(1, sizeof(*object
))))
349 return E_OUTOFMEMORY
;
351 desc1
.startCap
= desc
->startCap
;
352 desc1
.endCap
= desc
->endCap
;
353 desc1
.dashCap
= desc
->dashCap
;
354 desc1
.lineJoin
= desc
->lineJoin
;
355 desc1
.miterLimit
= desc
->miterLimit
;
356 desc1
.dashStyle
= desc
->dashStyle
;
357 desc1
.dashOffset
= desc
->dashOffset
;
358 desc1
.transformType
= D2D1_STROKE_TRANSFORM_TYPE_NORMAL
;
360 if (FAILED(hr
= d2d_stroke_style_init(object
, (ID2D1Factory
*)iface
, &desc1
, dashes
, dash_count
)))
362 WARN("Failed to initialise stroke style, hr %#lx.\n", hr
);
367 TRACE("Created stroke style %p.\n", object
);
368 *stroke_style
= (ID2D1StrokeStyle
*)&object
->ID2D1StrokeStyle1_iface
;
373 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateDrawingStateBlock(ID2D1Factory3
*iface
,
374 const D2D1_DRAWING_STATE_DESCRIPTION
*desc
, IDWriteRenderingParams
*text_rendering_params
,
375 ID2D1DrawingStateBlock
**state_block
)
377 D2D1_DRAWING_STATE_DESCRIPTION1 state_desc
;
378 struct d2d_state_block
*object
;
380 TRACE("iface %p, desc %p, text_rendering_params %p, state_block %p.\n",
381 iface
, desc
, text_rendering_params
, state_block
);
383 if (!(object
= calloc(1, sizeof(*object
))))
384 return E_OUTOFMEMORY
;
388 memcpy(&state_desc
, desc
, sizeof(*desc
));
389 state_desc
.primitiveBlend
= D2D1_PRIMITIVE_BLEND_SOURCE_OVER
;
390 state_desc
.unitMode
= D2D1_UNIT_MODE_DIPS
;
393 d2d_state_block_init(object
, (ID2D1Factory
*)iface
, desc
? &state_desc
: NULL
, text_rendering_params
);
395 TRACE("Created state block %p.\n", object
);
396 *state_block
= (ID2D1DrawingStateBlock
*)&object
->ID2D1DrawingStateBlock1_iface
;
401 static HRESULT
d2d_factory_get_device(struct d2d_factory
*factory
, ID3D10Device1
**device
)
405 if (!factory
->device
&& FAILED(hr
= D3D10CreateDevice1(NULL
, D3D10_DRIVER_TYPE_HARDWARE
, NULL
, D3D10_CREATE_DEVICE_BGRA_SUPPORT
,
406 D3D10_FEATURE_LEVEL_10_0
, D3D10_1_SDK_VERSION
, &factory
->device
)))
407 WARN("Failed to create device, hr %#lx.\n", hr
);
409 *device
= factory
->device
;
413 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateWicBitmapRenderTarget(ID2D1Factory3
*iface
,
414 IWICBitmap
*target
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
, ID2D1RenderTarget
**render_target
)
416 struct d2d_factory
*factory
= impl_from_ID2D1Factory3(iface
);
417 struct d2d_wic_render_target
*object
;
418 ID3D10Device1
*device
;
421 TRACE("iface %p, target %p, desc %p, render_target %p.\n", iface
, target
, desc
, render_target
);
423 if (!(object
= calloc(1, sizeof(*object
))))
424 return E_OUTOFMEMORY
;
426 if (FAILED(hr
= d2d_factory_get_device(factory
, &device
)))
432 if (FAILED(hr
= d2d_wic_render_target_init(object
, (ID2D1Factory1
*)iface
, device
, target
, desc
)))
434 WARN("Failed to initialise render target, hr %#lx.\n", hr
);
439 TRACE("Created render target %p.\n", object
);
440 *render_target
= object
->dxgi_target
;
445 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateHwndRenderTarget(ID2D1Factory3
*iface
,
446 const D2D1_RENDER_TARGET_PROPERTIES
*desc
, const D2D1_HWND_RENDER_TARGET_PROPERTIES
*hwnd_rt_desc
,
447 ID2D1HwndRenderTarget
**render_target
)
449 struct d2d_factory
*factory
= impl_from_ID2D1Factory3(iface
);
450 struct d2d_hwnd_render_target
*object
;
451 ID3D10Device1
*device
;
454 TRACE("iface %p, desc %p, hwnd_rt_desc %p, render_target %p.\n", iface
, desc
, hwnd_rt_desc
, render_target
);
456 if (FAILED(hr
= d2d_factory_get_device(factory
, &device
)))
459 if (!(object
= calloc(1, sizeof(*object
))))
460 return E_OUTOFMEMORY
;
462 if (FAILED(hr
= d2d_hwnd_render_target_init(object
, (ID2D1Factory1
*)iface
, device
, desc
, hwnd_rt_desc
)))
464 WARN("Failed to initialise render target, hr %#lx.\n", hr
);
469 TRACE("Created render target %p.\n", object
);
470 *render_target
= &object
->ID2D1HwndRenderTarget_iface
;
475 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateDxgiSurfaceRenderTarget(ID2D1Factory3
*iface
,
476 IDXGISurface
*surface
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
, ID2D1RenderTarget
**render_target
)
478 IDXGIDevice
*dxgi_device
;
482 TRACE("iface %p, surface %p, desc %p, render_target %p.\n", iface
, surface
, desc
, render_target
);
484 if (FAILED(hr
= IDXGISurface_GetDevice(surface
, &IID_IDXGIDevice
, (void **)&dxgi_device
)))
486 WARN("Failed to get DXGI device, hr %#lx.\n", hr
);
490 hr
= ID2D1Factory1_CreateDevice((ID2D1Factory1
*)iface
, dxgi_device
, &device
);
491 IDXGIDevice_Release(dxgi_device
);
494 WARN("Failed to create D2D device, hr %#lx.\n", hr
);
498 hr
= d2d_d3d_create_render_target(device
, surface
, NULL
, NULL
, desc
, (void **)render_target
);
499 ID2D1Device_Release(device
);
503 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateDCRenderTarget(ID2D1Factory3
*iface
,
504 const D2D1_RENDER_TARGET_PROPERTIES
*desc
, ID2D1DCRenderTarget
**render_target
)
506 struct d2d_factory
*factory
= impl_from_ID2D1Factory3(iface
);
507 struct d2d_dc_render_target
*object
;
508 ID3D10Device1
*device
;
511 TRACE("iface %p, desc %p, render_target %p.\n", iface
, desc
, render_target
);
513 if (FAILED(hr
= d2d_factory_get_device(factory
, &device
)))
516 if (!(object
= calloc(1, sizeof(*object
))))
517 return E_OUTOFMEMORY
;
519 if (FAILED(hr
= d2d_dc_render_target_init(object
, (ID2D1Factory1
*)iface
, device
, desc
)))
521 WARN("Failed to initialise render target, hr %#lx.\n", hr
);
526 TRACE("Created render target %p.\n", object
);
527 *render_target
= &object
->ID2D1DCRenderTarget_iface
;
532 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateDevice(ID2D1Factory3
*iface
,
533 IDXGIDevice
*dxgi_device
, ID2D1Device
**device
)
535 struct d2d_device
*object
;
537 TRACE("iface %p, dxgi_device %p, device %p.\n", iface
, dxgi_device
, device
);
539 if (!(object
= calloc(1, sizeof(*object
))))
540 return E_OUTOFMEMORY
;
542 d2d_device_init(object
, (ID2D1Factory1
*)iface
, dxgi_device
);
544 TRACE("Create device %p.\n", object
);
545 *device
= &object
->ID2D1Device_iface
;
550 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateStrokeStyle1(ID2D1Factory3
*iface
,
551 const D2D1_STROKE_STYLE_PROPERTIES1
*desc
, const float *dashes
, UINT32 dash_count
,
552 ID2D1StrokeStyle1
**stroke_style
)
554 struct d2d_stroke_style
*object
;
557 TRACE("iface %p, desc %p, dashes %p, dash_count %u, stroke_style %p.\n",
558 iface
, desc
, dashes
, dash_count
, stroke_style
);
560 if (!(object
= calloc(1, sizeof(*object
))))
561 return E_OUTOFMEMORY
;
563 if (FAILED(hr
= d2d_stroke_style_init(object
, (ID2D1Factory
*)iface
,
564 desc
, dashes
, dash_count
)))
566 WARN("Failed to initialise stroke style, hr %#lx.\n", hr
);
571 TRACE("Created stroke style %p.\n", object
);
572 *stroke_style
= &object
->ID2D1StrokeStyle1_iface
;
577 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreatePathGeometry1(ID2D1Factory3
*iface
, ID2D1PathGeometry1
**geometry
)
579 struct d2d_geometry
*object
;
581 TRACE("iface %p, geometry %p.\n", iface
, geometry
);
583 if (!(object
= calloc(1, sizeof(*object
))))
584 return E_OUTOFMEMORY
;
586 d2d_path_geometry_init(object
, (ID2D1Factory
*)iface
);
588 TRACE("Created path geometry %p.\n", object
);
589 *geometry
= (ID2D1PathGeometry1
*)&object
->ID2D1Geometry_iface
;
594 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateDrawingStateBlock1(ID2D1Factory3
*iface
,
595 const D2D1_DRAWING_STATE_DESCRIPTION1
*desc
, IDWriteRenderingParams
*text_rendering_params
,
596 ID2D1DrawingStateBlock1
**state_block
)
598 struct d2d_state_block
*object
;
600 TRACE("iface %p, desc %p, text_rendering_params %p, state_block %p.\n",
601 iface
, desc
, text_rendering_params
, state_block
);
603 if (!(object
= calloc(1, sizeof(*object
))))
604 return E_OUTOFMEMORY
;
606 d2d_state_block_init(object
, (ID2D1Factory
*)iface
, desc
, text_rendering_params
);
608 TRACE("Created state block %p.\n", object
);
609 *state_block
= &object
->ID2D1DrawingStateBlock1_iface
;
614 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateGdiMetafile(ID2D1Factory3
*iface
,
615 IStream
*stream
, ID2D1GdiMetafile
**metafile
)
617 FIXME("iface %p, stream %p, metafile %p stub!\n", iface
, stream
, metafile
);
622 static HRESULT
parse_effect_get_next_xml_node(IXmlReader
*reader
, XmlNodeType expected_type
,
623 const WCHAR
*expected_name
, unsigned int *depth
)
625 const WCHAR
*node_name
;
626 XmlNodeType node_type
;
629 assert(expected_type
!= XmlNodeType_Whitespace
);
631 while ((hr
= IXmlReader_Read(reader
, &node_type
)) == S_OK
)
633 if (node_type
== XmlNodeType_Whitespace
)
636 if (expected_type
!= XmlNodeType_None
&& node_type
!= expected_type
)
637 return HRESULT_FROM_WIN32(ERROR_NOT_FOUND
);
641 if (FAILED(hr
= IXmlReader_GetLocalName(reader
, &node_name
, NULL
)))
644 if (wcscmp(node_name
, expected_name
))
645 return HRESULT_FROM_WIN32(ERROR_NOT_FOUND
);
649 IXmlReader_GetDepth(reader
, depth
);
656 static HRESULT
parse_effect_skip_element(IXmlReader
*reader
, unsigned int element_depth
)
658 XmlNodeType node_type
;
662 if (IXmlReader_IsEmptyElement(reader
)) return S_OK
;
664 while ((hr
= IXmlReader_Read(reader
, &node_type
)) == S_OK
)
666 IXmlReader_GetDepth(reader
, &depth
);
667 if (node_type
== XmlNodeType_EndElement
&& depth
== element_depth
+ 1)
676 static HRESULT
parse_effect_get_attribute(IXmlReader
*reader
, const WCHAR
*name
, WCHAR
**ret
)
682 if (IXmlReader_MoveToAttributeByName(reader
, name
, NULL
) != S_OK
)
684 if (IXmlReader_GetValue(reader
, &value
, NULL
) != S_OK
)
686 if (!(*ret
= wcsdup(value
)))
687 return E_OUTOFMEMORY
;
692 static HRESULT
parse_effect_get_property_type(IXmlReader
*reader
, D2D1_PROPERTY_TYPE
*type
)
694 static const WCHAR
*types
[] =
696 L
"", /* D2D1_PROPERTY_TYPE_UNKNOWN */
697 L
"string", /* D2D1_PROPERTY_TYPE_STRING */
698 L
"bool", /* D2D1_PROPERTY_TYPE_BOOL */
699 L
"uint32", /* D2D1_PROPERTY_TYPE_UINT32 */
700 L
"int32", /* D2D1_PROPERTY_TYPE_INT32 */
701 L
"float", /* D2D1_PROPERTY_TYPE_FLOAT */
702 L
"vector2", /* D2D1_PROPERTY_TYPE_VECTOR2 */
703 L
"vector3", /* D2D1_PROPERTY_TYPE_VECTOR3 */
704 L
"vector4", /* D2D1_PROPERTY_TYPE_VECTOR4 */
705 L
"blob", /* D2D1_PROPERTY_TYPE_BLOB */
706 L
"iunknown", /* D2D1_PROPERTY_TYPE_IUNKNOWN */
707 L
"enum", /* D2D1_PROPERTY_TYPE_ENUM */
708 L
"array", /* D2D1_PROPERTY_TYPE_ARRAY */
709 L
"clsid", /* D2D1_PROPERTY_TYPE_CLSID */
710 L
"matrix3x2", /* D2D1_PROPERTY_TYPE_MATRIX_3X2 */
711 L
"matrix4x3", /* D2D1_PROPERTY_TYPE_MATRIX_4X3 */
712 L
"matrix4x4", /* D2D1_PROPERTY_TYPE_MATRIX_4X4 */
713 L
"matrix5x4", /* D2D1_PROPERTY_TYPE_MATRIX_5X4 */
714 L
"colorcontext", /* D2D1_PROPERTY_TYPE_COLOR_CONTEXT */
720 if (FAILED(hr
= parse_effect_get_attribute(reader
, L
"type", &value
))) return hr
;
722 *type
= D2D1_PROPERTY_TYPE_UNKNOWN
;
724 for (i
= 0; i
< ARRAY_SIZE(types
); ++i
)
726 if (!wcscmp(value
, types
[i
]))
735 return *type
== D2D1_PROPERTY_TYPE_UNKNOWN
? E_INVALIDARG
: S_OK
;
738 static struct d2d_effect_property
* parse_effect_get_property(const struct d2d_effect_registration
*effect
,
743 for (i
= 0; i
< effect
->properties
.count
; ++i
)
745 if (!wcscmp(name
, effect
->properties
.properties
[i
].name
))
746 return &effect
->properties
.properties
[i
];
752 static UINT32
parse_effect_get_property_index(struct d2d_effect_properties
*props
,
755 if (!wcscmp(name
, L
"DisplayName")) return D2D1_PROPERTY_DISPLAYNAME
;
756 if (!wcscmp(name
, L
"Author")) return D2D1_PROPERTY_AUTHOR
;
757 if (!wcscmp(name
, L
"Category")) return D2D1_PROPERTY_CATEGORY
;
758 if (!wcscmp(name
, L
"Description")) return D2D1_PROPERTY_DESCRIPTION
;
759 return props
->custom_count
;
762 static HRESULT
parse_effect_property(IXmlReader
*reader
, struct d2d_effect_registration
*effect
)
764 WCHAR
*name
= NULL
, *value
= NULL
;
765 D2D1_PROPERTY_TYPE type
;
770 if (FAILED(hr
= parse_effect_get_attribute(reader
, L
"name", &name
)))
773 if (FAILED(hr
= parse_effect_get_property_type(reader
, &type
)))
779 /* Check for duplicates. */
780 if (parse_effect_get_property(effect
, name
))
783 parse_effect_get_attribute(reader
, L
"value", &value
);
787 /* FIXME: sub properties are ignored */
788 IXmlReader_MoveToElement(reader
);
789 IXmlReader_GetDepth(reader
, &depth
);
790 hr
= parse_effect_skip_element(reader
, depth
);
795 index
= parse_effect_get_property_index(&effect
->properties
, name
);
796 hr
= d2d_effect_properties_add(&effect
->properties
, name
, index
, type
, value
);
805 static HRESULT
parse_effect_inputs(IXmlReader
*reader
, struct d2d_effect_registration
*effect
)
807 struct d2d_effect_properties
*subproperties
;
808 unsigned int depth
, input_count
= 0;
809 struct d2d_effect_property
*inputs
;
810 XmlNodeType node_type
;
815 if (FAILED(hr
= d2d_effect_properties_add(&effect
->properties
, L
"Inputs",
816 D2D1_PROPERTY_INPUTS
, D2D1_PROPERTY_TYPE_ARRAY
, NULL
)))
819 if (!(inputs
= d2d_effect_properties_get_property_by_name(&effect
->properties
, L
"Inputs")))
821 if (!(inputs
->subproperties
= calloc(1, sizeof(*inputs
->subproperties
))))
822 return E_OUTOFMEMORY
;
823 subproperties
= inputs
->subproperties
;
825 d2d_effect_subproperties_add(subproperties
, L
"IsReadOnly", D2D1_SUBPROPERTY_ISREADONLY
,
826 D2D1_PROPERTY_TYPE_BOOL
, L
"true");
827 d2d_effect_subproperties_add(subproperties
, L
"DisplayName", D2D1_SUBPROPERTY_DISPLAYNAME
,
828 D2D1_PROPERTY_TYPE_STRING
, L
"Inputs");
830 if (IXmlReader_IsEmptyElement(reader
)) return S_OK
;
832 while (parse_effect_get_next_xml_node(reader
, XmlNodeType_None
, L
"Input", &depth
) == S_OK
)
834 if (FAILED(hr
= IXmlReader_GetNodeType(reader
, &node_type
))) return hr
;
835 if (node_type
== XmlNodeType_EndElement
) continue;
836 if (node_type
!= XmlNodeType_Element
) return HRESULT_FROM_WIN32(ERROR_NOT_FOUND
);
838 if (FAILED(hr
= parse_effect_get_attribute(reader
, L
"name", &name
))) return hr
;
840 swprintf(nameW
, ARRAY_SIZE(nameW
), L
"%lu", input_count
);
841 d2d_effect_subproperties_add(subproperties
, nameW
, input_count
, D2D1_PROPERTY_TYPE_STRING
, name
);
846 *(UINT32
*)(effect
->properties
.data
.ptr
+ inputs
->data
.offset
) = input_count
;
848 if (FAILED(hr
= IXmlReader_GetNodeType(reader
, &node_type
))) return hr
;
849 if (node_type
!= XmlNodeType_EndElement
) return HRESULT_FROM_WIN32(ERROR_NOT_FOUND
);
854 static HRESULT
parse_effect_xml(IXmlReader
*reader
, struct d2d_effect_registration
*effect
)
856 const WCHAR
*node_name
;
857 XmlNodeType node_type
;
861 /* Xml declaration node is mandatory. */
862 if ((hr
= parse_effect_get_next_xml_node(reader
, XmlNodeType_XmlDeclaration
, L
"xml", NULL
)) != S_OK
)
865 /* Top level "Effect" element. */
866 if ((hr
= parse_effect_get_next_xml_node(reader
, XmlNodeType_Element
, L
"Effect", NULL
)) != S_OK
)
869 /* Loop inside effect node */
870 while ((hr
= parse_effect_get_next_xml_node(reader
, XmlNodeType_None
, NULL
, &depth
)) == S_OK
)
872 if (FAILED(hr
= IXmlReader_GetNodeType(reader
, &node_type
))) return hr
;
873 if (node_type
!= XmlNodeType_Element
&& node_type
!= XmlNodeType_EndElement
) continue;
874 if (FAILED(hr
= IXmlReader_GetLocalName(reader
, &node_name
, NULL
))) return hr
;
875 if (node_type
== XmlNodeType_EndElement
) break;
877 if (!wcscmp(node_name
, L
"Property"))
878 hr
= parse_effect_property(reader
, effect
);
879 else if (!wcscmp(node_name
, L
"Inputs"))
880 hr
= parse_effect_inputs(reader
, effect
);
883 WARN("Unexpected element %s.\n", debugstr_w(node_name
));
884 hr
= parse_effect_skip_element(reader
, depth
);
894 static HRESULT STDMETHODCALLTYPE
d2d_factory_RegisterEffectFromStream(ID2D1Factory3
*iface
,
895 REFCLSID effect_id
, IStream
*property_xml
, const D2D1_PROPERTY_BINDING
*bindings
,
896 UINT32 binding_count
, PD2D1_EFFECT_FACTORY effect_factory
)
898 struct d2d_factory
*factory
= impl_from_ID2D1Factory3(iface
);
899 struct d2d_effect_registration
*effect
;
904 TRACE("iface %p, effect_id %s, property_xml %p, bindings %p, binding_count %u, effect_factory %p.\n",
905 iface
, debugstr_guid(effect_id
), property_xml
, bindings
, binding_count
, effect_factory
);
907 d2d_factory_init_builtin_effects(factory
);
909 LIST_FOR_EACH_ENTRY_REV(effect
, &factory
->effects
, struct d2d_effect_registration
, entry
)
911 if (IsEqualGUID(effect_id
, &effect
->id
))
913 if (effect
->builtin
) return E_INVALIDARG
;
914 ++effect
->registration_count
;
919 if (FAILED(hr
= CreateXmlReader(&IID_IXmlReader
, (void **)&reader
, NULL
)))
922 if (FAILED(hr
= IXmlReader_SetInput(reader
, (IUnknown
*)property_xml
)))
924 IXmlReader_Release(reader
);
928 if (!(effect
= calloc(1, sizeof(*effect
))))
930 IXmlReader_Release(reader
);
931 return E_OUTOFMEMORY
;
934 hr
= parse_effect_xml(reader
, effect
);
935 IXmlReader_Release(reader
);
938 WARN("Failed to parse effect xml, hr %#lx.\n", hr
);
939 d2d_effect_registration_cleanup(effect
);
943 /* Check required properties. */
944 if (!parse_effect_get_property(effect
, L
"DisplayName")
945 || !parse_effect_get_property(effect
, L
"Author")
946 || !parse_effect_get_property(effect
, L
"Category")
947 || !parse_effect_get_property(effect
, L
"Description")
948 || !parse_effect_get_property(effect
, L
"Inputs"))
950 WARN("Missing required properties.\n");
951 d2d_effect_registration_cleanup(effect
);
955 /* Bind getter and setter. */
956 for (i
= 0; i
< binding_count
; ++i
)
958 struct d2d_effect_property
*property
;
960 if (!(property
= parse_effect_get_property(effect
, bindings
[i
].propertyName
)))
962 WARN("Failed to bind to missing property.\n");
963 d2d_effect_registration_cleanup(effect
);
964 return D2DERR_INVALID_PROPERTY
;
967 property
->get_function
= bindings
[i
].getFunction
;
968 property
->set_function
= bindings
[i
].setFunction
;
971 effect
->registration_count
= 1;
972 effect
->id
= *effect_id
;
973 effect
->factory
= effect_factory
;
974 d2d_effect_properties_add(&effect
->properties
, L
"MinInputs", D2D1_PROPERTY_MIN_INPUTS
,
975 D2D1_PROPERTY_TYPE_UINT32
, L
"1");
976 d2d_effect_properties_add(&effect
->properties
, L
"MaxInputs", D2D1_PROPERTY_MAX_INPUTS
,
977 D2D1_PROPERTY_TYPE_UINT32
, L
"1" /* FIXME */);
978 effect
->default_input_count
= 1;
979 d2d_factory_register_effect(factory
, effect
);
984 static HRESULT STDMETHODCALLTYPE
d2d_factory_RegisterEffectFromString(ID2D1Factory3
*iface
,
985 REFCLSID effect_id
, const WCHAR
*property_xml
, const D2D1_PROPERTY_BINDING
*bindings
,
986 UINT32 binding_count
, PD2D1_EFFECT_FACTORY effect_factory
)
988 static const LARGE_INTEGER zero
;
993 TRACE("iface %p, effect_id %s, property_xml %s, bindings %p, binding_count %u, effect_factory %p.\n",
994 iface
, debugstr_guid(effect_id
), debugstr_w(property_xml
), bindings
, binding_count
, effect_factory
);
996 if (FAILED(hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
)))
999 size
= sizeof(*property_xml
) * (wcslen(property_xml
) + 1);
1000 if (SUCCEEDED(hr
= IStream_Write(stream
, property_xml
, size
, NULL
)))
1001 hr
= IStream_Seek(stream
, zero
, SEEK_SET
, NULL
);
1004 hr
= ID2D1Factory3_RegisterEffectFromStream(iface
, effect_id
, stream
, bindings
,
1005 binding_count
, effect_factory
);
1007 IStream_Release(stream
);
1011 static HRESULT STDMETHODCALLTYPE
d2d_factory_UnregisterEffect(ID2D1Factory3
*iface
, REFCLSID effect_id
)
1013 struct d2d_factory
*factory
= impl_from_ID2D1Factory3(iface
);
1014 struct d2d_effect_registration
*effect
;
1016 TRACE("iface %p, effect_id %s.\n", iface
, debugstr_guid(effect_id
));
1018 d2d_factory_init_builtin_effects(factory
);
1020 LIST_FOR_EACH_ENTRY_REV(effect
, &factory
->effects
, struct d2d_effect_registration
, entry
)
1022 if (IsEqualGUID(effect_id
, &effect
->id
))
1024 if (effect
->builtin
) break;
1025 if (!--effect
->registration_count
)
1027 list_remove(&effect
->entry
);
1028 d2d_effect_registration_cleanup(effect
);
1034 return D2DERR_EFFECT_IS_NOT_REGISTERED
;
1037 static HRESULT STDMETHODCALLTYPE
d2d_factory_GetRegisteredEffects(ID2D1Factory3
*iface
,
1038 CLSID
*effects
, UINT32 effect_count
, UINT32
*returned
, UINT32
*registered
)
1040 struct d2d_factory
*factory
= impl_from_ID2D1Factory3(iface
);
1041 struct d2d_effect_registration
*effect
;
1044 TRACE("iface %p, effects %p, effect_count %u, returned %p, registered %p.\n",
1045 iface
, effects
, effect_count
, returned
, registered
);
1047 if (!returned
) returned
= &ret
;
1048 if (!registered
) registered
= ®
;
1053 d2d_factory_init_builtin_effects(factory
);
1055 LIST_FOR_EACH_ENTRY(effect
, &factory
->effects
, struct d2d_effect_registration
, entry
)
1057 if (effects
&& effect_count
)
1059 *effects
= effect
->id
;
1068 if (!effects
) return S_OK
;
1069 return *returned
== *registered
? S_OK
: D2DERR_INSUFFICIENT_BUFFER
;
1072 static HRESULT STDMETHODCALLTYPE
d2d_factory_GetEffectProperties(ID2D1Factory3
*iface
,
1073 REFCLSID effect_id
, ID2D1Properties
**props
)
1075 FIXME("iface %p, effect_id %s, props %p stub!\n", iface
, debugstr_guid(effect_id
), props
);
1080 static HRESULT STDMETHODCALLTYPE
d2d_factory_ID2D1Factory2_CreateDevice(ID2D1Factory3
*iface
, IDXGIDevice
*dxgi_device
,
1081 ID2D1Device1
**device
)
1083 FIXME("iface %p, dxgi_device %p, device %p stub!\n", iface
, dxgi_device
, device
);
1088 static HRESULT STDMETHODCALLTYPE
d2d_factory_ID2D1Factory3_CreateDevice(ID2D1Factory3
*iface
, IDXGIDevice
*dxgi_device
,
1089 ID2D1Device2
**device
)
1091 FIXME("iface %p, dxgi_device %p, device %p stub!\n", iface
, dxgi_device
, device
);
1096 static const struct ID2D1Factory3Vtbl d2d_factory_vtbl
=
1098 d2d_factory_QueryInterface
,
1100 d2d_factory_Release
,
1101 d2d_factory_ReloadSystemMetrics
,
1102 d2d_factory_GetDesktopDpi
,
1103 d2d_factory_CreateRectangleGeometry
,
1104 d2d_factory_CreateRoundedRectangleGeometry
,
1105 d2d_factory_CreateEllipseGeometry
,
1106 d2d_factory_CreateGeometryGroup
,
1107 d2d_factory_CreateTransformedGeometry
,
1108 d2d_factory_CreatePathGeometry
,
1109 d2d_factory_CreateStrokeStyle
,
1110 d2d_factory_CreateDrawingStateBlock
,
1111 d2d_factory_CreateWicBitmapRenderTarget
,
1112 d2d_factory_CreateHwndRenderTarget
,
1113 d2d_factory_CreateDxgiSurfaceRenderTarget
,
1114 d2d_factory_CreateDCRenderTarget
,
1115 d2d_factory_CreateDevice
,
1116 d2d_factory_CreateStrokeStyle1
,
1117 d2d_factory_CreatePathGeometry1
,
1118 d2d_factory_CreateDrawingStateBlock1
,
1119 d2d_factory_CreateGdiMetafile
,
1120 d2d_factory_RegisterEffectFromStream
,
1121 d2d_factory_RegisterEffectFromString
,
1122 d2d_factory_UnregisterEffect
,
1123 d2d_factory_GetRegisteredEffects
,
1124 d2d_factory_GetEffectProperties
,
1125 d2d_factory_ID2D1Factory2_CreateDevice
,
1126 d2d_factory_ID2D1Factory3_CreateDevice
,
1129 static HRESULT STDMETHODCALLTYPE
d2d_factory_mt_QueryInterface(ID2D1Multithread
*iface
, REFIID iid
, void **out
)
1131 struct d2d_factory
*factory
= impl_from_ID2D1Multithread(iface
);
1132 return d2d_factory_QueryInterface(&factory
->ID2D1Factory3_iface
, iid
, out
);
1135 static ULONG STDMETHODCALLTYPE
d2d_factory_mt_AddRef(ID2D1Multithread
*iface
)
1137 struct d2d_factory
*factory
= impl_from_ID2D1Multithread(iface
);
1138 return d2d_factory_AddRef(&factory
->ID2D1Factory3_iface
);
1141 static ULONG STDMETHODCALLTYPE
d2d_factory_mt_Release(ID2D1Multithread
*iface
)
1143 struct d2d_factory
*factory
= impl_from_ID2D1Multithread(iface
);
1144 return d2d_factory_Release(&factory
->ID2D1Factory3_iface
);
1147 static BOOL STDMETHODCALLTYPE
d2d_factory_mt_GetMultithreadProtected(ID2D1Multithread
*iface
)
1152 static void STDMETHODCALLTYPE
d2d_factory_mt_Enter(ID2D1Multithread
*iface
)
1154 struct d2d_factory
*factory
= impl_from_ID2D1Multithread(iface
);
1156 TRACE("%p.\n", iface
);
1158 EnterCriticalSection(&factory
->cs
);
1161 static void STDMETHODCALLTYPE
d2d_factory_mt_Leave(ID2D1Multithread
*iface
)
1163 struct d2d_factory
*factory
= impl_from_ID2D1Multithread(iface
);
1165 TRACE("%p.\n", iface
);
1167 LeaveCriticalSection(&factory
->cs
);
1170 static BOOL STDMETHODCALLTYPE
d2d_factory_st_GetMultithreadProtected(ID2D1Multithread
*iface
)
1175 static void STDMETHODCALLTYPE
d2d_factory_st_Enter(ID2D1Multithread
*iface
)
1179 static void STDMETHODCALLTYPE
d2d_factory_st_Leave(ID2D1Multithread
*iface
)
1183 static const struct ID2D1MultithreadVtbl d2d_factory_multithread_vtbl
=
1185 d2d_factory_mt_QueryInterface
,
1186 d2d_factory_mt_AddRef
,
1187 d2d_factory_mt_Release
,
1188 d2d_factory_mt_GetMultithreadProtected
,
1189 d2d_factory_mt_Enter
,
1190 d2d_factory_mt_Leave
,
1193 static const struct ID2D1MultithreadVtbl d2d_factory_multithread_noop_vtbl
=
1195 d2d_factory_mt_QueryInterface
,
1196 d2d_factory_mt_AddRef
,
1197 d2d_factory_mt_Release
,
1198 d2d_factory_st_GetMultithreadProtected
,
1199 d2d_factory_st_Enter
,
1200 d2d_factory_st_Leave
,
1203 static void d2d_factory_init(struct d2d_factory
*factory
, D2D1_FACTORY_TYPE factory_type
,
1204 const D2D1_FACTORY_OPTIONS
*factory_options
)
1206 if (factory_options
&& factory_options
->debugLevel
!= D2D1_DEBUG_LEVEL_NONE
)
1207 WARN("Ignoring debug level %#x.\n", factory_options
->debugLevel
);
1209 factory
->ID2D1Factory3_iface
.lpVtbl
= &d2d_factory_vtbl
;
1210 factory
->ID2D1Multithread_iface
.lpVtbl
= factory_type
== D2D1_FACTORY_TYPE_SINGLE_THREADED
?
1211 &d2d_factory_multithread_noop_vtbl
: &d2d_factory_multithread_vtbl
;
1212 factory
->refcount
= 1;
1213 d2d_factory_reload_sysmetrics(factory
);
1214 list_init(&factory
->effects
);
1215 InitializeCriticalSection(&factory
->cs
);
1216 InitOnceInitialize(&factory
->init_builtins
);
1219 HRESULT WINAPI
D2D1CreateFactory(D2D1_FACTORY_TYPE factory_type
, REFIID iid
,
1220 const D2D1_FACTORY_OPTIONS
*factory_options
, void **factory
)
1222 struct d2d_factory
*object
;
1225 TRACE("factory_type %#x, iid %s, factory_options %p, factory %p.\n",
1226 factory_type
, debugstr_guid(iid
), factory_options
, factory
);
1228 if (factory_type
!= D2D1_FACTORY_TYPE_SINGLE_THREADED
&&
1229 factory_type
!= D2D1_FACTORY_TYPE_MULTI_THREADED
)
1231 return E_INVALIDARG
;
1234 if (!(object
= calloc(1, sizeof(*object
))))
1235 return E_OUTOFMEMORY
;
1237 d2d_factory_init(object
, factory_type
, factory_options
);
1239 TRACE("Created factory %p.\n", object
);
1241 hr
= ID2D1Factory3_QueryInterface(&object
->ID2D1Factory3_iface
, iid
, factory
);
1242 ID2D1Factory3_Release(&object
->ID2D1Factory3_iface
);
1247 void WINAPI
D2D1MakeRotateMatrix(float angle
, D2D1_POINT_2F center
, D2D1_MATRIX_3X2_F
*matrix
)
1249 float theta
, sin_theta
, cos_theta
;
1251 TRACE("angle %.8e, center %s, matrix %p.\n", angle
, debug_d2d_point_2f(¢er
), matrix
);
1253 theta
= angle
* (M_PI
/ 180.0f
);
1254 sin_theta
= sinf(theta
);
1255 cos_theta
= cosf(theta
);
1257 /* translate(center) * rotate(theta) * translate(-center) */
1258 matrix
->_11
= cos_theta
;
1259 matrix
->_12
= sin_theta
;
1260 matrix
->_21
= -sin_theta
;
1261 matrix
->_22
= cos_theta
;
1262 matrix
->_31
= center
.x
- center
.x
* cos_theta
+ center
.y
* sin_theta
;
1263 matrix
->_32
= center
.y
- center
.x
* sin_theta
- center
.y
* cos_theta
;
1266 void WINAPI
D2D1MakeSkewMatrix(float angle_x
, float angle_y
, D2D1_POINT_2F center
, D2D1_MATRIX_3X2_F
*matrix
)
1270 TRACE("angle_x %.8e, angle_y %.8e, center %s, matrix %p.\n", angle_x
, angle_y
, debug_d2d_point_2f(¢er
), matrix
);
1272 tan_x
= tan(angle_x
* (M_PI
/ 180.0f
));
1273 tan_y
= tan(angle_y
* (M_PI
/ 180.0f
));
1275 /* translate(-center) * skew() * translate(center) */
1277 matrix
->_12
= tan_y
;
1278 matrix
->_21
= tan_x
;
1280 matrix
->_31
= -tan_x
* center
.y
;
1281 matrix
->_32
= -tan_y
* center
.x
;
1284 BOOL WINAPI
D2D1IsMatrixInvertible(const D2D1_MATRIX_3X2_F
*matrix
)
1286 TRACE("matrix %p.\n", matrix
);
1288 return (matrix
->_11
* matrix
->_22
- matrix
->_21
* matrix
->_12
) != 0.0f
;
1291 BOOL WINAPI
D2D1InvertMatrix(D2D1_MATRIX_3X2_F
*matrix
)
1293 D2D1_MATRIX_3X2_F m
= *matrix
;
1295 TRACE("matrix %p.\n", matrix
);
1297 return d2d_matrix_invert(matrix
, &m
);
1300 HRESULT WINAPI
D2D1CreateDevice(IDXGIDevice
*dxgi_device
,
1301 const D2D1_CREATION_PROPERTIES
*properties
, ID2D1Device
**device
)
1303 D2D1_CREATION_PROPERTIES default_properties
= {0};
1304 D2D1_FACTORY_OPTIONS factory_options
;
1305 ID3D11Device
*d3d_device
;
1306 ID2D1Factory1
*factory
;
1309 TRACE("dxgi_device %p, properties %p, device %p.\n", dxgi_device
, properties
, device
);
1313 if (SUCCEEDED(IDXGIDevice_QueryInterface(dxgi_device
, &IID_ID3D11Device
, (void **)&d3d_device
)))
1315 if (!(ID3D11Device_GetCreationFlags(d3d_device
) & D3D11_CREATE_DEVICE_SINGLETHREADED
))
1316 default_properties
.threadingMode
= D2D1_THREADING_MODE_MULTI_THREADED
;
1317 ID3D11Device_Release(d3d_device
);
1319 properties
= &default_properties
;
1322 factory_options
.debugLevel
= properties
->debugLevel
;
1323 if (FAILED(hr
= D2D1CreateFactory(properties
->threadingMode
,
1324 &IID_ID2D1Factory1
, &factory_options
, (void **)&factory
)))
1327 hr
= ID2D1Factory1_CreateDevice(factory
, dxgi_device
, device
);
1328 ID2D1Factory1_Release(factory
);
1332 void WINAPI
D2D1SinCos(float angle
, float *s
, float *c
)
1334 TRACE("angle %.8e, s %p, c %p.\n", angle
, s
, c
);
1340 float WINAPI
D2D1Tan(float angle
)
1342 TRACE("angle %.8e.\n", angle
);
1347 float WINAPI
D2D1Vec3Length(float x
, float y
, float z
)
1349 TRACE("x %.8e, y %.8e, z %.8e.\n", x
, y
, z
);
1351 return sqrtf(x
* x
+ y
* y
+ z
* z
);
1354 /* See IEC 61966-2-1:1999; also described in the EXT_texture_sRGB OpenGL
1355 * extension, among others. */
1356 static float srgb_transfer_function(float x
)
1362 else if (x
<= 0.0031308f
)
1365 return 1.055f
* powf(x
, 1.0f
/ 2.4f
) - 0.055f
;
1368 static float srgb_inverse_transfer_function(float x
)
1374 else if (x
<= 0.04045f
)
1377 return powf((x
+ 0.055f
) / 1.055f
, 2.4f
);
1380 D2D1_COLOR_F WINAPI
D2D1ConvertColorSpace(D2D1_COLOR_SPACE src_colour_space
,
1381 D2D1_COLOR_SPACE dst_colour_space
, const D2D1_COLOR_F
*colour
)
1385 TRACE("src_colour_space %#x, dst_colour_space %#x, colour %s.\n",
1386 src_colour_space
, dst_colour_space
, debug_d2d_color_f(colour
));
1388 if (src_colour_space
== D2D1_COLOR_SPACE_CUSTOM
|| dst_colour_space
== D2D1_COLOR_SPACE_CUSTOM
)
1398 if (src_colour_space
== dst_colour_space
)
1401 if (src_colour_space
== D2D1_COLOR_SPACE_SRGB
&& dst_colour_space
== D2D1_COLOR_SPACE_SCRGB
)
1403 ret
.r
= srgb_inverse_transfer_function(colour
->r
);
1404 ret
.g
= srgb_inverse_transfer_function(colour
->g
);
1405 ret
.b
= srgb_inverse_transfer_function(colour
->b
);
1411 if (src_colour_space
== D2D1_COLOR_SPACE_SCRGB
&& dst_colour_space
== D2D1_COLOR_SPACE_SRGB
)
1413 ret
.r
= srgb_transfer_function(colour
->r
);
1414 ret
.g
= srgb_transfer_function(colour
->g
);
1415 ret
.b
= srgb_transfer_function(colour
->b
);
1421 FIXME("Unhandled conversion from source colour space %#x to destination colour space %#x.\n",
1422 src_colour_space
, dst_colour_space
);
1431 static bool get_config_key_u32(HKEY default_key
, HKEY application_key
, const char *name
, uint32_t *value
)
1436 size
= sizeof(data
);
1437 if (application_key
&& !RegQueryValueExA(application_key
,
1438 name
, 0, &type
, (BYTE
*)&data
, &size
) && type
== REG_DWORD
)
1441 size
= sizeof(data
);
1442 if (default_key
&& !RegQueryValueExA(default_key
,
1443 name
, 0, &type
, (BYTE
*)&data
, &size
) && type
== REG_DWORD
)
1453 static void d2d_settings_init(void)
1455 HKEY default_key
, tmp_key
, application_key
= NULL
;
1456 char buffer
[MAX_PATH
+ 10];
1459 if (RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Direct2D", &default_key
))
1462 len
= GetModuleFileNameA(0, buffer
, MAX_PATH
);
1463 if (len
&& len
< MAX_PATH
)
1465 char *p
, *appname
= buffer
;
1467 if ((p
= strrchr(appname
, '/')))
1469 if ((p
= strrchr(appname
, '\\')))
1471 strcat(appname
, "\\Direct2D");
1473 if (!RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\AppDefaults", &tmp_key
))
1475 if (RegOpenKeyA(tmp_key
, appname
, &application_key
))
1476 application_key
= NULL
;
1477 RegCloseKey(tmp_key
);
1481 if (!default_key
&& !application_key
)
1484 if (get_config_key_u32(default_key
, application_key
, "max_version_factory", &d2d_settings
.max_version_factory
))
1485 ERR_(winediag
)("Limiting maximum Direct2D factory version to %#x.\n", d2d_settings
.max_version_factory
);
1487 if (application_key
)
1488 RegCloseKey(application_key
);
1490 RegCloseKey(default_key
);
1493 BOOL WINAPI
DllMain(HINSTANCE inst
, DWORD reason
, void *reserved
)
1495 if (reason
== DLL_PROCESS_ATTACH
)
1496 d2d_settings_init();