advapi32/tests: Improve RegDeleteTree tests.
[wine.git] / dlls / d2d1 / factory.c
blobd63add5ff9dafca4aaa8431902009b0d7148d2bd
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 #include "config.h"
20 #include "wine/port.h"
22 #define D2D1_INIT_GUID
23 #include "d2d1_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d2d);
27 struct d2d_factory
29 ID2D1Factory ID2D1Factory_iface;
30 LONG refcount;
32 ID3D10Device1 *wic_device;
35 static inline struct d2d_factory *impl_from_ID2D1Factory(ID2D1Factory *iface)
37 return CONTAINING_RECORD(iface, struct d2d_factory, ID2D1Factory_iface);
40 static HRESULT STDMETHODCALLTYPE d2d_factory_QueryInterface(ID2D1Factory *iface, REFIID iid, void **out)
42 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
44 if (IsEqualGUID(iid, &IID_ID2D1Factory)
45 || IsEqualGUID(iid, &IID_IUnknown))
47 ID2D1Factory_AddRef(iface);
48 *out = iface;
49 return S_OK;
52 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
54 *out = NULL;
55 return E_NOINTERFACE;
58 static ULONG STDMETHODCALLTYPE d2d_factory_AddRef(ID2D1Factory *iface)
60 struct d2d_factory *factory = impl_from_ID2D1Factory(iface);
61 ULONG refcount = InterlockedIncrement(&factory->refcount);
63 TRACE("%p increasing refcount to %u.\n", iface, refcount);
65 return refcount;
68 static ULONG STDMETHODCALLTYPE d2d_factory_Release(ID2D1Factory *iface)
70 struct d2d_factory *factory = impl_from_ID2D1Factory(iface);
71 ULONG refcount = InterlockedDecrement(&factory->refcount);
73 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
75 if (!refcount)
77 if (factory->wic_device)
78 ID3D10Device1_Release(factory->wic_device);
79 HeapFree(GetProcessHeap(), 0, factory);
82 return refcount;
85 static HRESULT STDMETHODCALLTYPE d2d_factory_ReloadSystemMetrics(ID2D1Factory *iface)
87 FIXME("iface %p stub!\n", iface);
89 return E_NOTIMPL;
92 static void STDMETHODCALLTYPE d2d_factory_GetDesktopDpi(ID2D1Factory *iface, float *dpi_x, float *dpi_y)
94 FIXME("iface %p, dpi_x %p, dpi_y %p stub!\n", iface, dpi_x, dpi_y);
96 *dpi_x = 96.0f;
97 *dpi_y = 96.0f;
100 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateRectangleGeometry(ID2D1Factory *iface,
101 const D2D1_RECT_F *rect, ID2D1RectangleGeometry **geometry)
103 struct d2d_geometry *object;
104 HRESULT hr;
106 TRACE("iface %p, rect %p, geometry %p.\n", iface, rect, geometry);
108 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
109 return E_OUTOFMEMORY;
111 if (FAILED(hr = d2d_rectangle_geometry_init(object, iface, rect)))
113 WARN("Failed to initialize rectangle geometry, hr %#x.\n", hr);
114 HeapFree(GetProcessHeap(), 0, object);
115 return hr;
118 TRACE("Created rectangle geometry %p.\n", object);
119 *geometry = (ID2D1RectangleGeometry *)&object->ID2D1Geometry_iface;
121 return S_OK;
124 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateRoundedRectangleGeometry(ID2D1Factory *iface,
125 const D2D1_ROUNDED_RECT *rect, ID2D1RoundedRectangleGeometry **geometry)
127 FIXME("iface %p, rect %p, geometry %p stub!\n", iface, rect, geometry);
129 return E_NOTIMPL;
132 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateEllipseGeometry(ID2D1Factory *iface,
133 const D2D1_ELLIPSE *ellipse, ID2D1EllipseGeometry **geometry)
135 FIXME("iface %p, ellipse %p, geometry %p stub!\n", iface, ellipse, geometry);
137 return E_NOTIMPL;
140 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateGeometryGroup(ID2D1Factory *iface,
141 D2D1_FILL_MODE fill_mode, ID2D1Geometry *geometry, UINT32 geometry_count, ID2D1GeometryGroup **group)
143 FIXME("iface %p, fill_mode %#x, geometry %p, geometry_count %u, group %p stub!\n",
144 iface, fill_mode, geometry, geometry_count, group);
146 return E_NOTIMPL;
149 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateTransformedGeometry(ID2D1Factory *iface,
150 ID2D1Geometry *src_geometry, const D2D1_MATRIX_3X2_F *transform,
151 ID2D1TransformedGeometry **transformed_geometry)
153 struct d2d_geometry *object;
155 TRACE("iface %p, src_geometry %p, transform %p, transformed_geometry %p.\n",
156 iface, src_geometry, transform, transformed_geometry);
158 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
159 return E_OUTOFMEMORY;
161 d2d_transformed_geometry_init(object, iface, src_geometry, transform);
163 TRACE("Created transformed geometry %p.\n", object);
164 *transformed_geometry = (ID2D1TransformedGeometry *)&object->ID2D1Geometry_iface;
166 return S_OK;
169 static HRESULT STDMETHODCALLTYPE d2d_factory_CreatePathGeometry(ID2D1Factory *iface, ID2D1PathGeometry **geometry)
171 struct d2d_geometry *object;
173 TRACE("iface %p, geometry %p.\n", iface, geometry);
175 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
176 return E_OUTOFMEMORY;
178 d2d_path_geometry_init(object, iface);
180 TRACE("Created path geometry %p.\n", object);
181 *geometry = (ID2D1PathGeometry *)&object->ID2D1Geometry_iface;
183 return S_OK;
186 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateStrokeStyle(ID2D1Factory *iface,
187 const D2D1_STROKE_STYLE_PROPERTIES *desc, const float *dashes, UINT32 dash_count,
188 ID2D1StrokeStyle **stroke_style)
190 struct d2d_stroke_style *object;
192 TRACE("iface %p, desc %p, dashes %p, dash_count %u, stroke_style %p.\n",
193 iface, desc, dashes, dash_count, stroke_style);
195 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
196 return E_OUTOFMEMORY;
198 d2d_stroke_style_init(object, iface, desc, dashes, dash_count);
200 TRACE("Created stroke style %p.\n", object);
201 *stroke_style = &object->ID2D1StrokeStyle_iface;
203 return S_OK;
206 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDrawingStateBlock(ID2D1Factory *iface,
207 const D2D1_DRAWING_STATE_DESCRIPTION *desc, IDWriteRenderingParams *text_rendering_params,
208 ID2D1DrawingStateBlock **state_block)
210 struct d2d_state_block *object;
212 TRACE("iface %p, desc %p, text_rendering_params %p, state_block %p.\n",
213 iface, desc, text_rendering_params, state_block);
215 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
216 return E_OUTOFMEMORY;
218 d2d_state_block_init(object, iface, desc, text_rendering_params);
220 TRACE("Created state block %p.\n", object);
221 *state_block = &object->ID2D1DrawingStateBlock_iface;
223 return S_OK;
226 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateWicBitmapRenderTarget(ID2D1Factory *iface,
227 IWICBitmap *target, const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1RenderTarget **render_target)
229 struct d2d_factory *factory = impl_from_ID2D1Factory(iface);
230 struct d2d_wic_render_target *object;
231 HRESULT hr;
233 TRACE("iface %p, target %p, desc %p, render_target %p.\n", iface, target, desc, render_target);
235 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
236 return E_OUTOFMEMORY;
238 if (!factory->wic_device && FAILED(hr = D3D10CreateDevice1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL,
239 D3D10_CREATE_DEVICE_BGRA_SUPPORT, D3D10_FEATURE_LEVEL_10_0, D3D10_1_SDK_VERSION, &factory->wic_device)))
241 WARN("Failed to create device, hr %#x.\n", hr);
242 HeapFree(GetProcessHeap(), 0, object);
243 return hr;
246 if (FAILED(hr = d2d_wic_render_target_init(object, iface, factory->wic_device, target, desc)))
248 WARN("Failed to initialize render target, hr %#x.\n", hr);
249 HeapFree(GetProcessHeap(), 0, object);
250 return hr;
253 TRACE("Created render target %p.\n", object);
254 *render_target = &object->ID2D1RenderTarget_iface;
256 return S_OK;
259 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateHwndRenderTarget(ID2D1Factory *iface,
260 const D2D1_RENDER_TARGET_PROPERTIES *desc, const D2D1_HWND_RENDER_TARGET_PROPERTIES *hwnd_rt_desc,
261 ID2D1HwndRenderTarget **render_target)
263 FIXME("iface %p, desc %p, hwnd_rt_desc %p, render_target %p stub!\n", iface, desc, hwnd_rt_desc, render_target);
265 return E_NOTIMPL;
268 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDxgiSurfaceRenderTarget(ID2D1Factory *iface,
269 IDXGISurface *surface, const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1RenderTarget **render_target)
271 struct d2d_d3d_render_target *object;
272 HRESULT hr;
274 TRACE("iface %p, surface %p, desc %p, render_target %p.\n", iface, surface, desc, render_target);
276 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
277 return E_OUTOFMEMORY;
279 if (FAILED(hr = d2d_d3d_render_target_init(object, iface, surface, desc)))
281 WARN("Failed to initialize render target, hr %#x.\n", hr);
282 HeapFree(GetProcessHeap(), 0, object);
283 return hr;
286 TRACE("Created render target %p.\n", object);
287 *render_target = &object->ID2D1RenderTarget_iface;
289 return S_OK;
292 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDCRenderTarget(ID2D1Factory *iface,
293 const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1DCRenderTarget **render_target)
295 FIXME("iface %p, desc %p, render_target %p stub!\n", iface, desc, render_target);
297 return E_NOTIMPL;
300 static const struct ID2D1FactoryVtbl d2d_factory_vtbl =
302 d2d_factory_QueryInterface,
303 d2d_factory_AddRef,
304 d2d_factory_Release,
305 d2d_factory_ReloadSystemMetrics,
306 d2d_factory_GetDesktopDpi,
307 d2d_factory_CreateRectangleGeometry,
308 d2d_factory_CreateRoundedRectangleGeometry,
309 d2d_factory_CreateEllipseGeometry,
310 d2d_factory_CreateGeometryGroup,
311 d2d_factory_CreateTransformedGeometry,
312 d2d_factory_CreatePathGeometry,
313 d2d_factory_CreateStrokeStyle,
314 d2d_factory_CreateDrawingStateBlock,
315 d2d_factory_CreateWicBitmapRenderTarget,
316 d2d_factory_CreateHwndRenderTarget,
317 d2d_factory_CreateDxgiSurfaceRenderTarget,
318 d2d_factory_CreateDCRenderTarget,
321 static void d2d_factory_init(struct d2d_factory *factory, D2D1_FACTORY_TYPE factory_type,
322 const D2D1_FACTORY_OPTIONS *factory_options)
324 if (factory_type != D2D1_FACTORY_TYPE_SINGLE_THREADED)
325 FIXME("Ignoring factory type %#x.\n", factory_type);
326 if (factory_options && factory_options->debugLevel != D2D1_DEBUG_LEVEL_NONE)
327 WARN("Ignoring debug level %#x.\n", factory_options->debugLevel);
329 factory->ID2D1Factory_iface.lpVtbl = &d2d_factory_vtbl;
330 factory->refcount = 1;
333 HRESULT WINAPI D2D1CreateFactory(D2D1_FACTORY_TYPE factory_type, REFIID iid,
334 const D2D1_FACTORY_OPTIONS *factory_options, void **factory)
336 struct d2d_factory *object;
337 HRESULT hr;
339 TRACE("factory_type %#x, iid %s, factory_options %p, factory %p.\n",
340 factory_type, debugstr_guid(iid), factory_options, factory);
342 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
343 return E_OUTOFMEMORY;
345 d2d_factory_init(object, factory_type, factory_options);
347 TRACE("Created factory %p.\n", object);
349 hr = ID2D1Factory_QueryInterface(&object->ID2D1Factory_iface, iid, factory);
350 ID2D1Factory_Release(&object->ID2D1Factory_iface);
352 return hr;
355 void WINAPI D2D1MakeRotateMatrix(float angle, D2D1_POINT_2F center, D2D1_MATRIX_3X2_F *matrix)
357 float theta, sin_theta, cos_theta;
359 TRACE("angle %.8e, center {%.8e, %.8e}, matrix %p.\n", angle, center.x, center.y, matrix);
361 theta = angle * (M_PI / 180.0f);
362 sin_theta = sinf(theta);
363 cos_theta = cosf(theta);
365 /* translate(center) * rotate(theta) * translate(-center) */
366 matrix->_11 = cos_theta;
367 matrix->_12 = sin_theta;
368 matrix->_21 = -sin_theta;
369 matrix->_22 = cos_theta;
370 matrix->_31 = center.x - center.x * cos_theta + center.y * sin_theta;
371 matrix->_32 = center.y - center.x * sin_theta - center.y * cos_theta;