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(unsafe_impl_from_ID2D1Device((ID2D1Device1
*)device
), surface
,
499 NULL
, NULL
, desc
, (void **)render_target
);
500 ID2D1Device_Release(device
);
504 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateDCRenderTarget(ID2D1Factory3
*iface
,
505 const D2D1_RENDER_TARGET_PROPERTIES
*desc
, ID2D1DCRenderTarget
**render_target
)
507 struct d2d_factory
*factory
= impl_from_ID2D1Factory3(iface
);
508 struct d2d_dc_render_target
*object
;
509 ID3D10Device1
*device
;
512 TRACE("iface %p, desc %p, render_target %p.\n", iface
, desc
, render_target
);
514 if (FAILED(hr
= d2d_factory_get_device(factory
, &device
)))
517 if (!(object
= calloc(1, sizeof(*object
))))
518 return E_OUTOFMEMORY
;
520 if (FAILED(hr
= d2d_dc_render_target_init(object
, (ID2D1Factory1
*)iface
, device
, desc
)))
522 WARN("Failed to initialise render target, hr %#lx.\n", hr
);
527 TRACE("Created render target %p.\n", object
);
528 *render_target
= &object
->ID2D1DCRenderTarget_iface
;
533 static HRESULT
d2d_factory_create_device(ID2D1Factory3
*iface
, IDXGIDevice
*dxgi_device
,
534 ID2D1Device1
**device
) {
535 struct d2d_device
*object
;
537 if (!(object
= calloc(1, sizeof(*object
))))
538 return E_OUTOFMEMORY
;
540 d2d_device_init(object
, (ID2D1Factory1
*)iface
, dxgi_device
);
542 TRACE("Create device %p.\n", object
);
543 *device
= &object
->ID2D1Device1_iface
;
548 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateDevice(ID2D1Factory3
*iface
,
549 IDXGIDevice
*dxgi_device
, ID2D1Device
**device
)
551 TRACE("iface %p, dxgi_device %p, device %p.\n", iface
, dxgi_device
, device
);
553 return d2d_factory_create_device(iface
, dxgi_device
, (ID2D1Device1
**)device
);
556 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateStrokeStyle1(ID2D1Factory3
*iface
,
557 const D2D1_STROKE_STYLE_PROPERTIES1
*desc
, const float *dashes
, UINT32 dash_count
,
558 ID2D1StrokeStyle1
**stroke_style
)
560 struct d2d_stroke_style
*object
;
563 TRACE("iface %p, desc %p, dashes %p, dash_count %u, stroke_style %p.\n",
564 iface
, desc
, dashes
, dash_count
, stroke_style
);
566 if (!(object
= calloc(1, sizeof(*object
))))
567 return E_OUTOFMEMORY
;
569 if (FAILED(hr
= d2d_stroke_style_init(object
, (ID2D1Factory
*)iface
,
570 desc
, dashes
, dash_count
)))
572 WARN("Failed to initialise stroke style, hr %#lx.\n", hr
);
577 TRACE("Created stroke style %p.\n", object
);
578 *stroke_style
= &object
->ID2D1StrokeStyle1_iface
;
583 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreatePathGeometry1(ID2D1Factory3
*iface
, ID2D1PathGeometry1
**geometry
)
585 struct d2d_geometry
*object
;
587 TRACE("iface %p, geometry %p.\n", iface
, geometry
);
589 if (!(object
= calloc(1, sizeof(*object
))))
590 return E_OUTOFMEMORY
;
592 d2d_path_geometry_init(object
, (ID2D1Factory
*)iface
);
594 TRACE("Created path geometry %p.\n", object
);
595 *geometry
= (ID2D1PathGeometry1
*)&object
->ID2D1Geometry_iface
;
600 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateDrawingStateBlock1(ID2D1Factory3
*iface
,
601 const D2D1_DRAWING_STATE_DESCRIPTION1
*desc
, IDWriteRenderingParams
*text_rendering_params
,
602 ID2D1DrawingStateBlock1
**state_block
)
604 struct d2d_state_block
*object
;
606 TRACE("iface %p, desc %p, text_rendering_params %p, state_block %p.\n",
607 iface
, desc
, text_rendering_params
, state_block
);
609 if (!(object
= calloc(1, sizeof(*object
))))
610 return E_OUTOFMEMORY
;
612 d2d_state_block_init(object
, (ID2D1Factory
*)iface
, desc
, text_rendering_params
);
614 TRACE("Created state block %p.\n", object
);
615 *state_block
= &object
->ID2D1DrawingStateBlock1_iface
;
620 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateGdiMetafile(ID2D1Factory3
*iface
,
621 IStream
*stream
, ID2D1GdiMetafile
**metafile
)
623 FIXME("iface %p, stream %p, metafile %p stub!\n", iface
, stream
, metafile
);
628 static HRESULT
parse_effect_get_next_xml_node(IXmlReader
*reader
, XmlNodeType expected_type
,
629 const WCHAR
*expected_name
, unsigned int *depth
)
631 const WCHAR
*node_name
;
632 XmlNodeType node_type
;
635 assert(expected_type
!= XmlNodeType_Whitespace
);
637 while ((hr
= IXmlReader_Read(reader
, &node_type
)) == S_OK
)
639 if (node_type
== XmlNodeType_Whitespace
)
642 if (expected_type
!= XmlNodeType_None
&& node_type
!= expected_type
)
643 return HRESULT_FROM_WIN32(ERROR_NOT_FOUND
);
647 if (FAILED(hr
= IXmlReader_GetLocalName(reader
, &node_name
, NULL
)))
650 if (wcscmp(node_name
, expected_name
))
651 return HRESULT_FROM_WIN32(ERROR_NOT_FOUND
);
655 IXmlReader_GetDepth(reader
, depth
);
662 static HRESULT
parse_effect_skip_element(IXmlReader
*reader
, unsigned int element_depth
)
664 XmlNodeType node_type
;
668 if (IXmlReader_IsEmptyElement(reader
)) return S_OK
;
670 while ((hr
= IXmlReader_Read(reader
, &node_type
)) == S_OK
)
672 IXmlReader_GetDepth(reader
, &depth
);
673 if (node_type
== XmlNodeType_EndElement
&& depth
== element_depth
+ 1)
682 static HRESULT
parse_effect_get_attribute(IXmlReader
*reader
, const WCHAR
*name
, WCHAR
**ret
)
688 if (IXmlReader_MoveToAttributeByName(reader
, name
, NULL
) != S_OK
)
690 if (IXmlReader_GetValue(reader
, &value
, NULL
) != S_OK
)
692 if (!(*ret
= wcsdup(value
)))
693 return E_OUTOFMEMORY
;
698 static HRESULT
parse_effect_get_property_type(IXmlReader
*reader
, D2D1_PROPERTY_TYPE
*type
)
700 static const WCHAR
*types
[] =
702 L
"", /* D2D1_PROPERTY_TYPE_UNKNOWN */
703 L
"string", /* D2D1_PROPERTY_TYPE_STRING */
704 L
"bool", /* D2D1_PROPERTY_TYPE_BOOL */
705 L
"uint32", /* D2D1_PROPERTY_TYPE_UINT32 */
706 L
"int32", /* D2D1_PROPERTY_TYPE_INT32 */
707 L
"float", /* D2D1_PROPERTY_TYPE_FLOAT */
708 L
"vector2", /* D2D1_PROPERTY_TYPE_VECTOR2 */
709 L
"vector3", /* D2D1_PROPERTY_TYPE_VECTOR3 */
710 L
"vector4", /* D2D1_PROPERTY_TYPE_VECTOR4 */
711 L
"blob", /* D2D1_PROPERTY_TYPE_BLOB */
712 L
"iunknown", /* D2D1_PROPERTY_TYPE_IUNKNOWN */
713 L
"enum", /* D2D1_PROPERTY_TYPE_ENUM */
714 L
"array", /* D2D1_PROPERTY_TYPE_ARRAY */
715 L
"clsid", /* D2D1_PROPERTY_TYPE_CLSID */
716 L
"matrix3x2", /* D2D1_PROPERTY_TYPE_MATRIX_3X2 */
717 L
"matrix4x3", /* D2D1_PROPERTY_TYPE_MATRIX_4X3 */
718 L
"matrix4x4", /* D2D1_PROPERTY_TYPE_MATRIX_4X4 */
719 L
"matrix5x4", /* D2D1_PROPERTY_TYPE_MATRIX_5X4 */
720 L
"colorcontext", /* D2D1_PROPERTY_TYPE_COLOR_CONTEXT */
726 if (FAILED(hr
= parse_effect_get_attribute(reader
, L
"type", &value
))) return hr
;
728 *type
= D2D1_PROPERTY_TYPE_UNKNOWN
;
730 for (i
= 0; i
< ARRAY_SIZE(types
); ++i
)
732 if (!wcscmp(value
, types
[i
]))
741 return *type
== D2D1_PROPERTY_TYPE_UNKNOWN
? E_INVALIDARG
: S_OK
;
744 static struct d2d_effect_property
* parse_effect_get_property(const struct d2d_effect_registration
*effect
,
749 for (i
= 0; i
< effect
->properties
.count
; ++i
)
751 if (!wcscmp(name
, effect
->properties
.properties
[i
].name
))
752 return &effect
->properties
.properties
[i
];
758 static UINT32
parse_effect_get_property_index(struct d2d_effect_properties
*props
,
761 if (!wcscmp(name
, L
"DisplayName")) return D2D1_PROPERTY_DISPLAYNAME
;
762 if (!wcscmp(name
, L
"Author")) return D2D1_PROPERTY_AUTHOR
;
763 if (!wcscmp(name
, L
"Category")) return D2D1_PROPERTY_CATEGORY
;
764 if (!wcscmp(name
, L
"Description")) return D2D1_PROPERTY_DESCRIPTION
;
765 return props
->custom_count
;
768 static HRESULT
parse_effect_property(IXmlReader
*reader
, struct d2d_effect_registration
*effect
)
770 WCHAR
*name
= NULL
, *value
= NULL
;
771 D2D1_PROPERTY_TYPE type
;
776 if (FAILED(hr
= parse_effect_get_attribute(reader
, L
"name", &name
)))
779 if (FAILED(hr
= parse_effect_get_property_type(reader
, &type
)))
785 /* Check for duplicates. */
786 if (parse_effect_get_property(effect
, name
))
789 parse_effect_get_attribute(reader
, L
"value", &value
);
793 /* FIXME: sub properties are ignored */
794 IXmlReader_MoveToElement(reader
);
795 IXmlReader_GetDepth(reader
, &depth
);
796 hr
= parse_effect_skip_element(reader
, depth
);
801 index
= parse_effect_get_property_index(&effect
->properties
, name
);
802 hr
= d2d_effect_properties_add(&effect
->properties
, name
, index
, type
, value
);
811 static HRESULT
parse_effect_inputs(IXmlReader
*reader
, struct d2d_effect_registration
*effect
)
813 struct d2d_effect_properties
*subproperties
;
814 unsigned int depth
, input_count
= 0;
815 struct d2d_effect_property
*inputs
;
816 XmlNodeType node_type
;
821 if (FAILED(hr
= d2d_effect_properties_add(&effect
->properties
, L
"Inputs",
822 D2D1_PROPERTY_INPUTS
, D2D1_PROPERTY_TYPE_ARRAY
, NULL
)))
825 if (!(inputs
= d2d_effect_properties_get_property_by_name(&effect
->properties
, L
"Inputs")))
827 if (!(inputs
->subproperties
= calloc(1, sizeof(*inputs
->subproperties
))))
828 return E_OUTOFMEMORY
;
829 subproperties
= inputs
->subproperties
;
831 d2d_effect_subproperties_add(subproperties
, L
"IsReadOnly", D2D1_SUBPROPERTY_ISREADONLY
,
832 D2D1_PROPERTY_TYPE_BOOL
, L
"true");
833 d2d_effect_subproperties_add(subproperties
, L
"DisplayName", D2D1_SUBPROPERTY_DISPLAYNAME
,
834 D2D1_PROPERTY_TYPE_STRING
, L
"Inputs");
836 if (IXmlReader_IsEmptyElement(reader
)) return S_OK
;
838 while (parse_effect_get_next_xml_node(reader
, XmlNodeType_None
, L
"Input", &depth
) == S_OK
)
840 if (FAILED(hr
= IXmlReader_GetNodeType(reader
, &node_type
))) return hr
;
841 if (node_type
== XmlNodeType_EndElement
) continue;
842 if (node_type
!= XmlNodeType_Element
) return HRESULT_FROM_WIN32(ERROR_NOT_FOUND
);
844 if (FAILED(hr
= parse_effect_get_attribute(reader
, L
"name", &name
))) return hr
;
846 swprintf(nameW
, ARRAY_SIZE(nameW
), L
"%lu", input_count
);
847 d2d_effect_subproperties_add(subproperties
, nameW
, input_count
, D2D1_PROPERTY_TYPE_STRING
, name
);
852 *(UINT32
*)(effect
->properties
.data
.ptr
+ inputs
->data
.offset
) = input_count
;
854 if (FAILED(hr
= IXmlReader_GetNodeType(reader
, &node_type
))) return hr
;
855 if (node_type
!= XmlNodeType_EndElement
) return HRESULT_FROM_WIN32(ERROR_NOT_FOUND
);
860 static HRESULT
parse_effect_xml(IXmlReader
*reader
, struct d2d_effect_registration
*effect
)
862 const WCHAR
*node_name
;
863 XmlNodeType node_type
;
867 /* Xml declaration node is mandatory. */
868 if ((hr
= parse_effect_get_next_xml_node(reader
, XmlNodeType_XmlDeclaration
, L
"xml", NULL
)) != S_OK
)
871 /* Top level "Effect" element. */
872 if ((hr
= parse_effect_get_next_xml_node(reader
, XmlNodeType_Element
, L
"Effect", NULL
)) != S_OK
)
875 /* Loop inside effect node */
876 while ((hr
= parse_effect_get_next_xml_node(reader
, XmlNodeType_None
, NULL
, &depth
)) == S_OK
)
878 if (FAILED(hr
= IXmlReader_GetNodeType(reader
, &node_type
))) return hr
;
879 if (node_type
!= XmlNodeType_Element
&& node_type
!= XmlNodeType_EndElement
) continue;
880 if (FAILED(hr
= IXmlReader_GetLocalName(reader
, &node_name
, NULL
))) return hr
;
881 if (node_type
== XmlNodeType_EndElement
) break;
883 if (!wcscmp(node_name
, L
"Property"))
884 hr
= parse_effect_property(reader
, effect
);
885 else if (!wcscmp(node_name
, L
"Inputs"))
886 hr
= parse_effect_inputs(reader
, effect
);
889 WARN("Unexpected element %s.\n", debugstr_w(node_name
));
890 hr
= parse_effect_skip_element(reader
, depth
);
900 static HRESULT STDMETHODCALLTYPE
d2d_factory_RegisterEffectFromStream(ID2D1Factory3
*iface
,
901 REFCLSID effect_id
, IStream
*property_xml
, const D2D1_PROPERTY_BINDING
*bindings
,
902 UINT32 binding_count
, PD2D1_EFFECT_FACTORY effect_factory
)
904 struct d2d_factory
*factory
= impl_from_ID2D1Factory3(iface
);
905 struct d2d_effect_registration
*effect
;
910 TRACE("iface %p, effect_id %s, property_xml %p, bindings %p, binding_count %u, effect_factory %p.\n",
911 iface
, debugstr_guid(effect_id
), property_xml
, bindings
, binding_count
, effect_factory
);
913 d2d_factory_init_builtin_effects(factory
);
915 LIST_FOR_EACH_ENTRY_REV(effect
, &factory
->effects
, struct d2d_effect_registration
, entry
)
917 if (IsEqualGUID(effect_id
, &effect
->id
))
919 if (effect
->builtin
) return E_INVALIDARG
;
920 ++effect
->registration_count
;
925 if (FAILED(hr
= CreateXmlReader(&IID_IXmlReader
, (void **)&reader
, NULL
)))
928 if (FAILED(hr
= IXmlReader_SetInput(reader
, (IUnknown
*)property_xml
)))
930 IXmlReader_Release(reader
);
934 if (!(effect
= calloc(1, sizeof(*effect
))))
936 IXmlReader_Release(reader
);
937 return E_OUTOFMEMORY
;
940 hr
= parse_effect_xml(reader
, effect
);
941 IXmlReader_Release(reader
);
944 WARN("Failed to parse effect xml, hr %#lx.\n", hr
);
945 d2d_effect_registration_cleanup(effect
);
949 /* Check required properties. */
950 if (!parse_effect_get_property(effect
, L
"DisplayName")
951 || !parse_effect_get_property(effect
, L
"Author")
952 || !parse_effect_get_property(effect
, L
"Category")
953 || !parse_effect_get_property(effect
, L
"Description")
954 || !parse_effect_get_property(effect
, L
"Inputs"))
956 WARN("Missing required properties.\n");
957 d2d_effect_registration_cleanup(effect
);
961 /* Bind getter and setter. */
962 for (i
= 0; i
< binding_count
; ++i
)
964 struct d2d_effect_property
*property
;
966 if (!(property
= parse_effect_get_property(effect
, bindings
[i
].propertyName
)))
968 WARN("Failed to bind to missing property.\n");
969 d2d_effect_registration_cleanup(effect
);
970 return D2DERR_INVALID_PROPERTY
;
973 property
->get_function
= bindings
[i
].getFunction
;
974 property
->set_function
= bindings
[i
].setFunction
;
977 effect
->registration_count
= 1;
978 effect
->id
= *effect_id
;
979 effect
->factory
= effect_factory
;
980 d2d_effect_properties_add(&effect
->properties
, L
"MinInputs", D2D1_PROPERTY_MIN_INPUTS
,
981 D2D1_PROPERTY_TYPE_UINT32
, L
"1");
982 d2d_effect_properties_add(&effect
->properties
, L
"MaxInputs", D2D1_PROPERTY_MAX_INPUTS
,
983 D2D1_PROPERTY_TYPE_UINT32
, L
"1" /* FIXME */);
984 effect
->default_input_count
= 1;
985 d2d_factory_register_effect(factory
, effect
);
990 static HRESULT STDMETHODCALLTYPE
d2d_factory_RegisterEffectFromString(ID2D1Factory3
*iface
,
991 REFCLSID effect_id
, const WCHAR
*property_xml
, const D2D1_PROPERTY_BINDING
*bindings
,
992 UINT32 binding_count
, PD2D1_EFFECT_FACTORY effect_factory
)
994 static const LARGE_INTEGER zero
;
999 TRACE("iface %p, effect_id %s, property_xml %s, bindings %p, binding_count %u, effect_factory %p.\n",
1000 iface
, debugstr_guid(effect_id
), debugstr_w(property_xml
), bindings
, binding_count
, effect_factory
);
1002 if (FAILED(hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
)))
1005 size
= sizeof(*property_xml
) * (wcslen(property_xml
) + 1);
1006 if (SUCCEEDED(hr
= IStream_Write(stream
, property_xml
, size
, NULL
)))
1007 hr
= IStream_Seek(stream
, zero
, SEEK_SET
, NULL
);
1010 hr
= ID2D1Factory3_RegisterEffectFromStream(iface
, effect_id
, stream
, bindings
,
1011 binding_count
, effect_factory
);
1013 IStream_Release(stream
);
1017 static HRESULT STDMETHODCALLTYPE
d2d_factory_UnregisterEffect(ID2D1Factory3
*iface
, REFCLSID effect_id
)
1019 struct d2d_factory
*factory
= impl_from_ID2D1Factory3(iface
);
1020 struct d2d_effect_registration
*effect
;
1022 TRACE("iface %p, effect_id %s.\n", iface
, debugstr_guid(effect_id
));
1024 d2d_factory_init_builtin_effects(factory
);
1026 LIST_FOR_EACH_ENTRY_REV(effect
, &factory
->effects
, struct d2d_effect_registration
, entry
)
1028 if (IsEqualGUID(effect_id
, &effect
->id
))
1030 if (effect
->builtin
) break;
1031 if (!--effect
->registration_count
)
1033 list_remove(&effect
->entry
);
1034 d2d_effect_registration_cleanup(effect
);
1040 return D2DERR_EFFECT_IS_NOT_REGISTERED
;
1043 static HRESULT STDMETHODCALLTYPE
d2d_factory_GetRegisteredEffects(ID2D1Factory3
*iface
,
1044 CLSID
*effects
, UINT32 effect_count
, UINT32
*returned
, UINT32
*registered
)
1046 struct d2d_factory
*factory
= impl_from_ID2D1Factory3(iface
);
1047 struct d2d_effect_registration
*effect
;
1050 TRACE("iface %p, effects %p, effect_count %u, returned %p, registered %p.\n",
1051 iface
, effects
, effect_count
, returned
, registered
);
1053 if (!returned
) returned
= &ret
;
1054 if (!registered
) registered
= ®
;
1059 d2d_factory_init_builtin_effects(factory
);
1061 LIST_FOR_EACH_ENTRY(effect
, &factory
->effects
, struct d2d_effect_registration
, entry
)
1063 if (effects
&& effect_count
)
1065 *effects
= effect
->id
;
1074 if (!effects
) return S_OK
;
1075 return *returned
== *registered
? S_OK
: D2DERR_INSUFFICIENT_BUFFER
;
1078 static HRESULT STDMETHODCALLTYPE
d2d_factory_GetEffectProperties(ID2D1Factory3
*iface
,
1079 REFCLSID effect_id
, ID2D1Properties
**props
)
1081 FIXME("iface %p, effect_id %s, props %p stub!\n", iface
, debugstr_guid(effect_id
), props
);
1086 static HRESULT STDMETHODCALLTYPE
d2d_factory_ID2D1Factory2_CreateDevice(ID2D1Factory3
*iface
, IDXGIDevice
*dxgi_device
,
1087 ID2D1Device1
**device
)
1089 TRACE("iface %p, dxgi_device %p, device %p.\n", iface
, dxgi_device
, device
);
1091 return d2d_factory_create_device(iface
, dxgi_device
, device
);
1094 static HRESULT STDMETHODCALLTYPE
d2d_factory_ID2D1Factory3_CreateDevice(ID2D1Factory3
*iface
, IDXGIDevice
*dxgi_device
,
1095 ID2D1Device2
**device
)
1097 FIXME("iface %p, dxgi_device %p, device %p stub!\n", iface
, dxgi_device
, device
);
1102 static const struct ID2D1Factory3Vtbl d2d_factory_vtbl
=
1104 d2d_factory_QueryInterface
,
1106 d2d_factory_Release
,
1107 d2d_factory_ReloadSystemMetrics
,
1108 d2d_factory_GetDesktopDpi
,
1109 d2d_factory_CreateRectangleGeometry
,
1110 d2d_factory_CreateRoundedRectangleGeometry
,
1111 d2d_factory_CreateEllipseGeometry
,
1112 d2d_factory_CreateGeometryGroup
,
1113 d2d_factory_CreateTransformedGeometry
,
1114 d2d_factory_CreatePathGeometry
,
1115 d2d_factory_CreateStrokeStyle
,
1116 d2d_factory_CreateDrawingStateBlock
,
1117 d2d_factory_CreateWicBitmapRenderTarget
,
1118 d2d_factory_CreateHwndRenderTarget
,
1119 d2d_factory_CreateDxgiSurfaceRenderTarget
,
1120 d2d_factory_CreateDCRenderTarget
,
1121 d2d_factory_CreateDevice
,
1122 d2d_factory_CreateStrokeStyle1
,
1123 d2d_factory_CreatePathGeometry1
,
1124 d2d_factory_CreateDrawingStateBlock1
,
1125 d2d_factory_CreateGdiMetafile
,
1126 d2d_factory_RegisterEffectFromStream
,
1127 d2d_factory_RegisterEffectFromString
,
1128 d2d_factory_UnregisterEffect
,
1129 d2d_factory_GetRegisteredEffects
,
1130 d2d_factory_GetEffectProperties
,
1131 d2d_factory_ID2D1Factory2_CreateDevice
,
1132 d2d_factory_ID2D1Factory3_CreateDevice
,
1135 static HRESULT STDMETHODCALLTYPE
d2d_factory_mt_QueryInterface(ID2D1Multithread
*iface
, REFIID iid
, void **out
)
1137 struct d2d_factory
*factory
= impl_from_ID2D1Multithread(iface
);
1138 return d2d_factory_QueryInterface(&factory
->ID2D1Factory3_iface
, iid
, out
);
1141 static ULONG STDMETHODCALLTYPE
d2d_factory_mt_AddRef(ID2D1Multithread
*iface
)
1143 struct d2d_factory
*factory
= impl_from_ID2D1Multithread(iface
);
1144 return d2d_factory_AddRef(&factory
->ID2D1Factory3_iface
);
1147 static ULONG STDMETHODCALLTYPE
d2d_factory_mt_Release(ID2D1Multithread
*iface
)
1149 struct d2d_factory
*factory
= impl_from_ID2D1Multithread(iface
);
1150 return d2d_factory_Release(&factory
->ID2D1Factory3_iface
);
1153 static BOOL STDMETHODCALLTYPE
d2d_factory_mt_GetMultithreadProtected(ID2D1Multithread
*iface
)
1158 static void STDMETHODCALLTYPE
d2d_factory_mt_Enter(ID2D1Multithread
*iface
)
1160 struct d2d_factory
*factory
= impl_from_ID2D1Multithread(iface
);
1162 TRACE("%p.\n", iface
);
1164 EnterCriticalSection(&factory
->cs
);
1167 static void STDMETHODCALLTYPE
d2d_factory_mt_Leave(ID2D1Multithread
*iface
)
1169 struct d2d_factory
*factory
= impl_from_ID2D1Multithread(iface
);
1171 TRACE("%p.\n", iface
);
1173 LeaveCriticalSection(&factory
->cs
);
1176 static BOOL STDMETHODCALLTYPE
d2d_factory_st_GetMultithreadProtected(ID2D1Multithread
*iface
)
1181 static void STDMETHODCALLTYPE
d2d_factory_st_Enter(ID2D1Multithread
*iface
)
1185 static void STDMETHODCALLTYPE
d2d_factory_st_Leave(ID2D1Multithread
*iface
)
1189 static const struct ID2D1MultithreadVtbl d2d_factory_multithread_vtbl
=
1191 d2d_factory_mt_QueryInterface
,
1192 d2d_factory_mt_AddRef
,
1193 d2d_factory_mt_Release
,
1194 d2d_factory_mt_GetMultithreadProtected
,
1195 d2d_factory_mt_Enter
,
1196 d2d_factory_mt_Leave
,
1199 static const struct ID2D1MultithreadVtbl d2d_factory_multithread_noop_vtbl
=
1201 d2d_factory_mt_QueryInterface
,
1202 d2d_factory_mt_AddRef
,
1203 d2d_factory_mt_Release
,
1204 d2d_factory_st_GetMultithreadProtected
,
1205 d2d_factory_st_Enter
,
1206 d2d_factory_st_Leave
,
1209 static void d2d_factory_init(struct d2d_factory
*factory
, D2D1_FACTORY_TYPE factory_type
,
1210 const D2D1_FACTORY_OPTIONS
*factory_options
)
1212 if (factory_options
&& factory_options
->debugLevel
!= D2D1_DEBUG_LEVEL_NONE
)
1213 WARN("Ignoring debug level %#x.\n", factory_options
->debugLevel
);
1215 factory
->ID2D1Factory3_iface
.lpVtbl
= &d2d_factory_vtbl
;
1216 factory
->ID2D1Multithread_iface
.lpVtbl
= factory_type
== D2D1_FACTORY_TYPE_SINGLE_THREADED
?
1217 &d2d_factory_multithread_noop_vtbl
: &d2d_factory_multithread_vtbl
;
1218 factory
->refcount
= 1;
1219 d2d_factory_reload_sysmetrics(factory
);
1220 list_init(&factory
->effects
);
1221 InitializeCriticalSection(&factory
->cs
);
1222 InitOnceInitialize(&factory
->init_builtins
);
1225 HRESULT WINAPI
D2D1CreateFactory(D2D1_FACTORY_TYPE factory_type
, REFIID iid
,
1226 const D2D1_FACTORY_OPTIONS
*factory_options
, void **factory
)
1228 struct d2d_factory
*object
;
1231 TRACE("factory_type %#x, iid %s, factory_options %p, factory %p.\n",
1232 factory_type
, debugstr_guid(iid
), factory_options
, factory
);
1234 if (factory_type
!= D2D1_FACTORY_TYPE_SINGLE_THREADED
&&
1235 factory_type
!= D2D1_FACTORY_TYPE_MULTI_THREADED
)
1237 return E_INVALIDARG
;
1240 if (!(object
= calloc(1, sizeof(*object
))))
1241 return E_OUTOFMEMORY
;
1243 d2d_factory_init(object
, factory_type
, factory_options
);
1245 TRACE("Created factory %p.\n", object
);
1247 hr
= ID2D1Factory3_QueryInterface(&object
->ID2D1Factory3_iface
, iid
, factory
);
1248 ID2D1Factory3_Release(&object
->ID2D1Factory3_iface
);
1253 void WINAPI
D2D1MakeRotateMatrix(float angle
, D2D1_POINT_2F center
, D2D1_MATRIX_3X2_F
*matrix
)
1255 float theta
, sin_theta
, cos_theta
;
1257 TRACE("angle %.8e, center %s, matrix %p.\n", angle
, debug_d2d_point_2f(¢er
), matrix
);
1259 theta
= angle
* (M_PI
/ 180.0f
);
1260 sin_theta
= sinf(theta
);
1261 cos_theta
= cosf(theta
);
1263 /* translate(center) * rotate(theta) * translate(-center) */
1264 matrix
->_11
= cos_theta
;
1265 matrix
->_12
= sin_theta
;
1266 matrix
->_21
= -sin_theta
;
1267 matrix
->_22
= cos_theta
;
1268 matrix
->_31
= center
.x
- center
.x
* cos_theta
+ center
.y
* sin_theta
;
1269 matrix
->_32
= center
.y
- center
.x
* sin_theta
- center
.y
* cos_theta
;
1272 void WINAPI
D2D1MakeSkewMatrix(float angle_x
, float angle_y
, D2D1_POINT_2F center
, D2D1_MATRIX_3X2_F
*matrix
)
1276 TRACE("angle_x %.8e, angle_y %.8e, center %s, matrix %p.\n", angle_x
, angle_y
, debug_d2d_point_2f(¢er
), matrix
);
1278 tan_x
= tan(angle_x
* (M_PI
/ 180.0f
));
1279 tan_y
= tan(angle_y
* (M_PI
/ 180.0f
));
1281 /* translate(-center) * skew() * translate(center) */
1283 matrix
->_12
= tan_y
;
1284 matrix
->_21
= tan_x
;
1286 matrix
->_31
= -tan_x
* center
.y
;
1287 matrix
->_32
= -tan_y
* center
.x
;
1290 BOOL WINAPI
D2D1IsMatrixInvertible(const D2D1_MATRIX_3X2_F
*matrix
)
1292 TRACE("matrix %p.\n", matrix
);
1294 return (matrix
->_11
* matrix
->_22
- matrix
->_21
* matrix
->_12
) != 0.0f
;
1297 BOOL WINAPI
D2D1InvertMatrix(D2D1_MATRIX_3X2_F
*matrix
)
1299 D2D1_MATRIX_3X2_F m
= *matrix
;
1301 TRACE("matrix %p.\n", matrix
);
1303 return d2d_matrix_invert(matrix
, &m
);
1306 HRESULT WINAPI
D2D1CreateDevice(IDXGIDevice
*dxgi_device
,
1307 const D2D1_CREATION_PROPERTIES
*properties
, ID2D1Device
**device
)
1309 D2D1_CREATION_PROPERTIES default_properties
= {0};
1310 D2D1_FACTORY_OPTIONS factory_options
;
1311 ID3D11Device
*d3d_device
;
1312 ID2D1Factory1
*factory
;
1315 TRACE("dxgi_device %p, properties %p, device %p.\n", dxgi_device
, properties
, device
);
1319 if (SUCCEEDED(IDXGIDevice_QueryInterface(dxgi_device
, &IID_ID3D11Device
, (void **)&d3d_device
)))
1321 if (!(ID3D11Device_GetCreationFlags(d3d_device
) & D3D11_CREATE_DEVICE_SINGLETHREADED
))
1322 default_properties
.threadingMode
= D2D1_THREADING_MODE_MULTI_THREADED
;
1323 ID3D11Device_Release(d3d_device
);
1325 properties
= &default_properties
;
1328 factory_options
.debugLevel
= properties
->debugLevel
;
1329 if (FAILED(hr
= D2D1CreateFactory(properties
->threadingMode
,
1330 &IID_ID2D1Factory1
, &factory_options
, (void **)&factory
)))
1333 hr
= ID2D1Factory1_CreateDevice(factory
, dxgi_device
, device
);
1334 ID2D1Factory1_Release(factory
);
1338 void WINAPI
D2D1SinCos(float angle
, float *s
, float *c
)
1340 TRACE("angle %.8e, s %p, c %p.\n", angle
, s
, c
);
1346 float WINAPI
D2D1Tan(float angle
)
1348 TRACE("angle %.8e.\n", angle
);
1353 float WINAPI
D2D1Vec3Length(float x
, float y
, float z
)
1355 TRACE("x %.8e, y %.8e, z %.8e.\n", x
, y
, z
);
1357 return sqrtf(x
* x
+ y
* y
+ z
* z
);
1360 /* See IEC 61966-2-1:1999; also described in the EXT_texture_sRGB OpenGL
1361 * extension, among others. */
1362 static float srgb_transfer_function(float x
)
1368 else if (x
<= 0.0031308f
)
1371 return 1.055f
* powf(x
, 1.0f
/ 2.4f
) - 0.055f
;
1374 static float srgb_inverse_transfer_function(float x
)
1380 else if (x
<= 0.04045f
)
1383 return powf((x
+ 0.055f
) / 1.055f
, 2.4f
);
1386 D2D1_COLOR_F WINAPI
D2D1ConvertColorSpace(D2D1_COLOR_SPACE src_colour_space
,
1387 D2D1_COLOR_SPACE dst_colour_space
, const D2D1_COLOR_F
*colour
)
1391 TRACE("src_colour_space %#x, dst_colour_space %#x, colour %s.\n",
1392 src_colour_space
, dst_colour_space
, debug_d2d_color_f(colour
));
1394 if (src_colour_space
== D2D1_COLOR_SPACE_CUSTOM
|| dst_colour_space
== D2D1_COLOR_SPACE_CUSTOM
)
1404 if (src_colour_space
== dst_colour_space
)
1407 if (src_colour_space
== D2D1_COLOR_SPACE_SRGB
&& dst_colour_space
== D2D1_COLOR_SPACE_SCRGB
)
1409 ret
.r
= srgb_inverse_transfer_function(colour
->r
);
1410 ret
.g
= srgb_inverse_transfer_function(colour
->g
);
1411 ret
.b
= srgb_inverse_transfer_function(colour
->b
);
1417 if (src_colour_space
== D2D1_COLOR_SPACE_SCRGB
&& dst_colour_space
== D2D1_COLOR_SPACE_SRGB
)
1419 ret
.r
= srgb_transfer_function(colour
->r
);
1420 ret
.g
= srgb_transfer_function(colour
->g
);
1421 ret
.b
= srgb_transfer_function(colour
->b
);
1427 FIXME("Unhandled conversion from source colour space %#x to destination colour space %#x.\n",
1428 src_colour_space
, dst_colour_space
);
1437 static bool get_config_key_u32(HKEY default_key
, HKEY application_key
, const char *name
, uint32_t *value
)
1442 size
= sizeof(data
);
1443 if (application_key
&& !RegQueryValueExA(application_key
,
1444 name
, 0, &type
, (BYTE
*)&data
, &size
) && type
== REG_DWORD
)
1447 size
= sizeof(data
);
1448 if (default_key
&& !RegQueryValueExA(default_key
,
1449 name
, 0, &type
, (BYTE
*)&data
, &size
) && type
== REG_DWORD
)
1459 static void d2d_settings_init(void)
1461 HKEY default_key
, tmp_key
, application_key
= NULL
;
1462 char buffer
[MAX_PATH
+ 10];
1465 if (RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Direct2D", &default_key
))
1468 len
= GetModuleFileNameA(0, buffer
, MAX_PATH
);
1469 if (len
&& len
< MAX_PATH
)
1471 char *p
, *appname
= buffer
;
1473 if ((p
= strrchr(appname
, '/')))
1475 if ((p
= strrchr(appname
, '\\')))
1477 strcat(appname
, "\\Direct2D");
1479 if (!RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\AppDefaults", &tmp_key
))
1481 if (RegOpenKeyA(tmp_key
, appname
, &application_key
))
1482 application_key
= NULL
;
1483 RegCloseKey(tmp_key
);
1487 if (!default_key
&& !application_key
)
1490 if (get_config_key_u32(default_key
, application_key
, "max_version_factory", &d2d_settings
.max_version_factory
))
1491 ERR_(winediag
)("Limiting maximum Direct2D factory version to %#x.\n", d2d_settings
.max_version_factory
);
1493 if (application_key
)
1494 RegCloseKey(application_key
);
1496 RegCloseKey(default_key
);
1499 BOOL WINAPI
DllMain(HINSTANCE inst
, DWORD reason
, void *reserved
)
1501 if (reason
== DLL_PROCESS_ATTACH
)
1502 d2d_settings_init();