msvcp110: Add tr2_sys__File_size_wchar implementation and test.
[wine/multimedia.git] / dlls / d2d1 / factory.c
blob0d15548e12d67ef6e49944965989069ce9cee8c1
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 FIXME("iface %p, src_geometry %p, transform %p, transformed_geometry %p stub!\n",
154 iface, src_geometry, transform, transformed_geometry);
156 return E_NOTIMPL;
159 static HRESULT STDMETHODCALLTYPE d2d_factory_CreatePathGeometry(ID2D1Factory *iface, ID2D1PathGeometry **geometry)
161 struct d2d_geometry *object;
163 TRACE("iface %p, geometry %p.\n", iface, geometry);
165 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
166 return E_OUTOFMEMORY;
168 d2d_path_geometry_init(object, iface);
170 TRACE("Created path geometry %p.\n", object);
171 *geometry = (ID2D1PathGeometry *)&object->ID2D1Geometry_iface;
173 return S_OK;
176 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateStrokeStyle(ID2D1Factory *iface,
177 const D2D1_STROKE_STYLE_PROPERTIES *desc, const float *dashes, UINT32 dash_count,
178 ID2D1StrokeStyle **stroke_style)
180 struct d2d_stroke_style *object;
182 TRACE("iface %p, desc %p, dashes %p, dash_count %u, stroke_style %p.\n",
183 iface, desc, dashes, dash_count, stroke_style);
185 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
186 return E_OUTOFMEMORY;
188 d2d_stroke_style_init(object, iface, desc, dashes, dash_count);
190 TRACE("Created stroke style %p.\n", object);
191 *stroke_style = &object->ID2D1StrokeStyle_iface;
193 return S_OK;
196 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDrawingStateBlock(ID2D1Factory *iface,
197 const D2D1_DRAWING_STATE_DESCRIPTION *desc, IDWriteRenderingParams *text_rendering_params,
198 ID2D1DrawingStateBlock **state_block)
200 struct d2d_state_block *object;
202 TRACE("iface %p, desc %p, text_rendering_params %p, state_block %p.\n",
203 iface, desc, text_rendering_params, state_block);
205 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
206 return E_OUTOFMEMORY;
208 d2d_state_block_init(object, iface, desc, text_rendering_params);
210 TRACE("Created state block %p.\n", object);
211 *state_block = &object->ID2D1DrawingStateBlock_iface;
213 return S_OK;
216 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateWicBitmapRenderTarget(ID2D1Factory *iface,
217 IWICBitmap *target, const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1RenderTarget **render_target)
219 struct d2d_factory *factory = impl_from_ID2D1Factory(iface);
220 struct d2d_wic_render_target *object;
221 HRESULT hr;
223 TRACE("iface %p, target %p, desc %p, render_target %p.\n", iface, target, desc, render_target);
225 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
226 return E_OUTOFMEMORY;
228 if (!factory->wic_device && FAILED(hr = D3D10CreateDevice1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL,
229 D3D10_CREATE_DEVICE_BGRA_SUPPORT, D3D10_FEATURE_LEVEL_10_0, D3D10_1_SDK_VERSION, &factory->wic_device)))
231 WARN("Failed to create device, hr %#x.\n", hr);
232 return hr;
235 if (FAILED(hr = d2d_wic_render_target_init(object, iface, factory->wic_device, target, desc)))
237 WARN("Failed to initialize render target, hr %#x.\n", hr);
238 HeapFree(GetProcessHeap(), 0, object);
239 return hr;
242 TRACE("Created render target %p.\n", object);
243 *render_target = &object->ID2D1RenderTarget_iface;
245 return S_OK;
248 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateHwndRenderTarget(ID2D1Factory *iface,
249 const D2D1_RENDER_TARGET_PROPERTIES *desc, const D2D1_HWND_RENDER_TARGET_PROPERTIES *hwnd_rt_desc,
250 ID2D1HwndRenderTarget **render_target)
252 FIXME("iface %p, desc %p, hwnd_rt_desc %p, render_target %p stub!\n", iface, desc, hwnd_rt_desc, render_target);
254 return E_NOTIMPL;
257 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDxgiSurfaceRenderTarget(ID2D1Factory *iface,
258 IDXGISurface *surface, const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1RenderTarget **render_target)
260 struct d2d_d3d_render_target *object;
261 HRESULT hr;
263 TRACE("iface %p, surface %p, desc %p, render_target %p.\n", iface, surface, desc, render_target);
265 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
266 return E_OUTOFMEMORY;
268 if (FAILED(hr = d2d_d3d_render_target_init(object, iface, surface, desc)))
270 WARN("Failed to initialize render target, hr %#x.\n", hr);
271 HeapFree(GetProcessHeap(), 0, object);
272 return hr;
275 TRACE("Created render target %p.\n", object);
276 *render_target = &object->ID2D1RenderTarget_iface;
278 return S_OK;
281 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDCRenderTarget(ID2D1Factory *iface,
282 const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1DCRenderTarget **render_target)
284 FIXME("iface %p, desc %p, render_target %p stub!\n", iface, desc, render_target);
286 return E_NOTIMPL;
289 static const struct ID2D1FactoryVtbl d2d_factory_vtbl =
291 d2d_factory_QueryInterface,
292 d2d_factory_AddRef,
293 d2d_factory_Release,
294 d2d_factory_ReloadSystemMetrics,
295 d2d_factory_GetDesktopDpi,
296 d2d_factory_CreateRectangleGeometry,
297 d2d_factory_CreateRoundedRectangleGeometry,
298 d2d_factory_CreateEllipseGeometry,
299 d2d_factory_CreateGeometryGroup,
300 d2d_factory_CreateTransformedGeometry,
301 d2d_factory_CreatePathGeometry,
302 d2d_factory_CreateStrokeStyle,
303 d2d_factory_CreateDrawingStateBlock,
304 d2d_factory_CreateWicBitmapRenderTarget,
305 d2d_factory_CreateHwndRenderTarget,
306 d2d_factory_CreateDxgiSurfaceRenderTarget,
307 d2d_factory_CreateDCRenderTarget,
310 static void d2d_factory_init(struct d2d_factory *factory, D2D1_FACTORY_TYPE factory_type,
311 const D2D1_FACTORY_OPTIONS *factory_options)
313 FIXME("Ignoring factory type and options.\n");
315 factory->ID2D1Factory_iface.lpVtbl = &d2d_factory_vtbl;
316 factory->refcount = 1;
319 HRESULT WINAPI D2D1CreateFactory(D2D1_FACTORY_TYPE factory_type, REFIID iid,
320 const D2D1_FACTORY_OPTIONS *factory_options, void **factory)
322 struct d2d_factory *object;
323 HRESULT hr;
325 TRACE("factory_type %#x, iid %s, factory_options %p, factory %p.\n",
326 factory_type, debugstr_guid(iid), factory_options, factory);
328 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
329 return E_OUTOFMEMORY;
331 d2d_factory_init(object, factory_type, factory_options);
333 TRACE("Created factory %p.\n", object);
335 hr = ID2D1Factory_QueryInterface(&object->ID2D1Factory_iface, iid, factory);
336 ID2D1Factory_Release(&object->ID2D1Factory_iface);
338 return hr;
341 void WINAPI D2D1MakeRotateMatrix(float angle, D2D1_POINT_2F center, D2D1_MATRIX_3X2_F *matrix)
343 float theta, sin_theta, cos_theta;
345 TRACE("angle %.8e, center {%.8e, %.8e}, matrix %p.\n", angle, center.x, center.y, matrix);
347 theta = angle * (M_PI / 180.0f);
348 sin_theta = sinf(theta);
349 cos_theta = cosf(theta);
351 /* translate(center) * rotate(theta) * translate(-center) */
352 matrix->_11 = cos_theta;
353 matrix->_12 = sin_theta;
354 matrix->_21 = -sin_theta;
355 matrix->_22 = cos_theta;
356 matrix->_31 = center.x - center.x * cos_theta + center.y * sin_theta;
357 matrix->_32 = center.y - center.x * sin_theta - center.y * cos_theta;