ntdll: Add stub for RtlSetHeapInformation.
[wine.git] / dlls / d2d1 / factory.c
blob27370c11c537909990282268b23f72570be9948e
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;
33 static inline struct d2d_factory *impl_from_ID2D1Factory(ID2D1Factory *iface)
35 return CONTAINING_RECORD(iface, struct d2d_factory, ID2D1Factory_iface);
38 static HRESULT STDMETHODCALLTYPE d2d_factory_QueryInterface(ID2D1Factory *iface, REFIID iid, void **out)
40 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
42 if (IsEqualGUID(iid, &IID_ID2D1Factory)
43 || IsEqualGUID(iid, &IID_IUnknown))
45 ID2D1Factory_AddRef(iface);
46 *out = iface;
47 return S_OK;
50 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
52 *out = NULL;
53 return E_NOINTERFACE;
56 static ULONG STDMETHODCALLTYPE d2d_factory_AddRef(ID2D1Factory *iface)
58 struct d2d_factory *factory = impl_from_ID2D1Factory(iface);
59 ULONG refcount = InterlockedIncrement(&factory->refcount);
61 TRACE("%p increasing refcount to %u.\n", iface, refcount);
63 return refcount;
66 static ULONG STDMETHODCALLTYPE d2d_factory_Release(ID2D1Factory *iface)
68 struct d2d_factory *factory = impl_from_ID2D1Factory(iface);
69 ULONG refcount = InterlockedDecrement(&factory->refcount);
71 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
73 if (!refcount)
74 HeapFree(GetProcessHeap(), 0, factory);
76 return refcount;
79 static HRESULT STDMETHODCALLTYPE d2d_factory_ReloadSystemMetrics(ID2D1Factory *iface)
81 FIXME("iface %p stub!\n", iface);
83 return E_NOTIMPL;
86 static void STDMETHODCALLTYPE d2d_factory_GetDesktopDpi(ID2D1Factory *iface, float *dpi_x, float *dpi_y)
88 FIXME("iface %p, dpi_x %p, dpi_y %p stub!\n", iface, dpi_x, dpi_y);
90 *dpi_x = 96.0f;
91 *dpi_y = 96.0f;
94 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateRectangleGeometry(ID2D1Factory *iface,
95 const D2D1_RECT_F *rect, ID2D1RectangleGeometry **geometry)
97 FIXME("iface %p, rect %p, geometry %p stub!\n", iface, rect, geometry);
99 return E_NOTIMPL;
102 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateRoundedRectangleGeometry(ID2D1Factory *iface,
103 const D2D1_ROUNDED_RECT *rect, ID2D1RoundedRectangleGeometry **geometry)
105 FIXME("iface %p, rect %p, geometry %p stub!\n", iface, rect, geometry);
107 return E_NOTIMPL;
110 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateEllipseGeometry(ID2D1Factory *iface,
111 const D2D1_ELLIPSE *ellipse, ID2D1EllipseGeometry **geometry)
113 FIXME("iface %p, ellipse %p, geometry %p stub!\n", iface, ellipse, geometry);
115 return E_NOTIMPL;
118 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateGeometryGroup(ID2D1Factory *iface,
119 D2D1_FILL_MODE fill_mode, ID2D1Geometry *geometry, UINT32 geometry_count, ID2D1GeometryGroup **group)
121 FIXME("iface %p, fill_mode %#x, geometry %p, geometry_count %u, group %p stub!\n",
122 iface, fill_mode, geometry, geometry_count, group);
124 return E_NOTIMPL;
127 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateTransformedGeometry(ID2D1Factory *iface,
128 ID2D1Geometry *src_geometry, const D2D1_MATRIX_3X2_F *transform,
129 ID2D1TransformedGeometry **transformed_geometry)
131 FIXME("iface %p, src_geometry %p, transform %p, transformed_geometry %p stub!\n",
132 iface, src_geometry, transform, transformed_geometry);
134 return E_NOTIMPL;
137 static HRESULT STDMETHODCALLTYPE d2d_factory_CreatePathGeometry(ID2D1Factory *iface, ID2D1PathGeometry *geometry)
139 FIXME("iface %p, geometry %p stub!\n", iface, geometry);
141 return E_NOTIMPL;
144 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateStrokeStyle(ID2D1Factory *iface,
145 const D2D1_STROKE_STYLE_PROPERTIES *desc, const float *dashes, UINT32 dash_count,
146 ID2D1StrokeStyle **stroke_style)
148 struct d2d_stroke_style *object;
150 TRACE("iface %p, desc %p, dashes %p, dash_count %u, stroke_style %p.\n",
151 iface, desc, dashes, dash_count, stroke_style);
153 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
154 return E_OUTOFMEMORY;
156 d2d_stroke_style_init(object, iface, desc, dashes, dash_count);
158 TRACE("Created stroke style %p.\n", object);
159 *stroke_style = &object->ID2D1StrokeStyle_iface;
161 return S_OK;
164 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDrawingStateBlock(ID2D1Factory *iface,
165 const D2D1_DRAWING_STATE_DESCRIPTION *desc, IDWriteRenderingParams *text_rendering_params,
166 ID2D1DrawingStateBlock **state_block)
168 FIXME("iface %p, desc %p, text_rendering_params %p, state_block %p stub!\n",
169 iface, desc, text_rendering_params, state_block);
171 return E_NOTIMPL;
174 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateWicBitmapRenderTarget(ID2D1Factory *iface,
175 IWICBitmap *target, const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1RenderTarget **render_target)
177 struct d2d_wic_render_target *object;
178 HRESULT hr;
180 TRACE("iface %p, target %p, desc %p, render_target %p.\n", iface, target, desc, render_target);
182 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
183 return E_OUTOFMEMORY;
185 if (FAILED(hr = d2d_wic_render_target_init(object, iface, target, desc)))
187 WARN("Failed to initialize render target, hr %#x.\n", hr);
188 HeapFree(GetProcessHeap(), 0, object);
189 return hr;
192 TRACE("Created render target %p.\n", object);
193 *render_target = &object->ID2D1RenderTarget_iface;
195 return S_OK;
198 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateHwndRenderTarget(ID2D1Factory *iface,
199 const D2D1_RENDER_TARGET_PROPERTIES *desc, const D2D1_HWND_RENDER_TARGET_PROPERTIES *hwnd_rt_desc,
200 ID2D1HwndRenderTarget **render_target)
202 FIXME("iface %p, desc %p, hwnd_rt_desc %p, render_target %p stub!\n", iface, desc, hwnd_rt_desc, render_target);
204 return E_NOTIMPL;
207 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDxgiSurfaceRenderTarget(ID2D1Factory *iface,
208 IDXGISurface *surface, const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1RenderTarget **render_target)
210 struct d2d_d3d_render_target *object;
211 HRESULT hr;
213 TRACE("iface %p, surface %p, desc %p, render_target %p.\n", iface, surface, desc, render_target);
215 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
216 return E_OUTOFMEMORY;
218 if (FAILED(hr = d2d_d3d_render_target_init(object, iface, surface, desc)))
220 WARN("Failed to initialize render target, hr %#x.\n", hr);
221 HeapFree(GetProcessHeap(), 0, object);
222 return hr;
225 TRACE("Created render target %p.\n", object);
226 *render_target = &object->ID2D1RenderTarget_iface;
228 return S_OK;
231 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDCRenderTarget(ID2D1Factory *iface,
232 const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1DCRenderTarget **render_target)
234 FIXME("iface %p, desc %p, render_target %p stub!\n", iface, desc, render_target);
236 return E_NOTIMPL;
239 static const struct ID2D1FactoryVtbl d2d_factory_vtbl =
241 d2d_factory_QueryInterface,
242 d2d_factory_AddRef,
243 d2d_factory_Release,
244 d2d_factory_ReloadSystemMetrics,
245 d2d_factory_GetDesktopDpi,
246 d2d_factory_CreateRectangleGeometry,
247 d2d_factory_CreateRoundedRectangleGeometry,
248 d2d_factory_CreateEllipseGeometry,
249 d2d_factory_CreateGeometryGroup,
250 d2d_factory_CreateTransformedGeometry,
251 d2d_factory_CreatePathGeometry,
252 d2d_factory_CreateStrokeStyle,
253 d2d_factory_CreateDrawingStateBlock,
254 d2d_factory_CreateWicBitmapRenderTarget,
255 d2d_factory_CreateHwndRenderTarget,
256 d2d_factory_CreateDxgiSurfaceRenderTarget,
257 d2d_factory_CreateDCRenderTarget,
260 static void d2d_factory_init(struct d2d_factory *factory, D2D1_FACTORY_TYPE factory_type,
261 const D2D1_FACTORY_OPTIONS *factory_options)
263 FIXME("Ignoring factory type and options.\n");
265 factory->ID2D1Factory_iface.lpVtbl = &d2d_factory_vtbl;
266 factory->refcount = 1;
269 HRESULT WINAPI D2D1CreateFactory(D2D1_FACTORY_TYPE factory_type, REFIID iid,
270 const D2D1_FACTORY_OPTIONS *factory_options, void **factory)
272 struct d2d_factory *object;
273 HRESULT hr;
275 TRACE("factory_type %#x, iid %s, factory_options %p, factory %p.\n",
276 factory_type, debugstr_guid(iid), factory_options, factory);
278 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
279 return E_OUTOFMEMORY;
281 d2d_factory_init(object, factory_type, factory_options);
283 TRACE("Created factory %p.\n", object);
285 hr = ID2D1Factory_QueryInterface(&object->ID2D1Factory_iface, iid, factory);
286 ID2D1Factory_Release(&object->ID2D1Factory_iface);
288 return hr;
291 void WINAPI D2D1MakeRotateMatrix(float angle, D2D1_POINT_2F center, D2D1_MATRIX_3X2_F *matrix)
293 float theta, sin_theta, cos_theta;
295 TRACE("angle %.8e, center {%.8e, %.8e}, matrix %p.\n", angle, center.x, center.y, matrix);
297 theta = angle * (M_PI / 180.0f);
298 sin_theta = sinf(theta);
299 cos_theta = cosf(theta);
301 /* translate(center) * rotate(theta) * translate(-center) */
302 matrix->_11 = cos_theta;
303 matrix->_12 = sin_theta;
304 matrix->_21 = -sin_theta;
305 matrix->_22 = cos_theta;
306 matrix->_31 = center.x - center.x * cos_theta + center.y * sin_theta;
307 matrix->_32 = center.y - center.x * sin_theta - center.y * cos_theta;