d3d8: Get rid of the format switching code in d3d8_device_CopyRects().
[wine.git] / dlls / d2d1 / factory.c
blob7919210e804a362d350f7ac792a434e4d301629b
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 #include "d2d1_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d2d);
26 struct d2d_factory
28 ID2D1Factory ID2D1Factory_iface;
29 LONG refcount;
32 static inline struct d2d_factory *impl_from_ID2D1Factory(ID2D1Factory *iface)
34 return CONTAINING_RECORD(iface, struct d2d_factory, ID2D1Factory_iface);
37 static HRESULT STDMETHODCALLTYPE d2d_factory_QueryInterface(ID2D1Factory *iface, REFIID iid, void **out)
39 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
41 if (IsEqualGUID(iid, &IID_ID2D1Factory)
42 || IsEqualGUID(iid, &IID_IUnknown))
44 ID2D1Factory_AddRef(iface);
45 *out = iface;
46 return S_OK;
49 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
51 *out = NULL;
52 return E_NOINTERFACE;
55 static ULONG STDMETHODCALLTYPE d2d_factory_AddRef(ID2D1Factory *iface)
57 struct d2d_factory *factory = impl_from_ID2D1Factory(iface);
58 ULONG refcount = InterlockedIncrement(&factory->refcount);
60 TRACE("%p increasing refcount to %u.\n", iface, refcount);
62 return refcount;
65 static ULONG STDMETHODCALLTYPE d2d_factory_Release(ID2D1Factory *iface)
67 struct d2d_factory *factory = impl_from_ID2D1Factory(iface);
68 ULONG refcount = InterlockedDecrement(&factory->refcount);
70 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
72 if (!refcount)
73 HeapFree(GetProcessHeap(), 0, factory);
75 return refcount;
78 static HRESULT STDMETHODCALLTYPE d2d_factory_ReloadSystemMetrics(ID2D1Factory *iface)
80 FIXME("iface %p stub!\n", iface);
82 return E_NOTIMPL;
85 static void STDMETHODCALLTYPE d2d_factory_GetDesktopDpi(ID2D1Factory *iface, float *dpi_x, float *dpi_y)
87 FIXME("iface %p, dpi_x %p, dpi_y %p stub!\n", iface, dpi_x, dpi_y);
89 *dpi_x = 96.0f;
90 *dpi_y = 96.0f;
93 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateRectangleGeometry(ID2D1Factory *iface,
94 const D2D1_RECT_F *rect, ID2D1RectangleGeometry **geometry)
96 FIXME("iface %p, rect %p, geometry %p stub!\n", iface, rect, geometry);
98 return E_NOTIMPL;
101 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateRoundedRectangleGeometry(ID2D1Factory *iface,
102 const D2D1_ROUNDED_RECT *rect, ID2D1RoundedRectangleGeometry **geometry)
104 FIXME("iface %p, rect %p, geometry %p stub!\n", iface, rect, geometry);
106 return E_NOTIMPL;
109 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateEllipseGeometry(ID2D1Factory *iface,
110 const D2D1_ELLIPSE *ellipse, ID2D1EllipseGeometry **geometry)
112 FIXME("iface %p, ellipse %p, geometry %p stub!\n", iface, ellipse, geometry);
114 return E_NOTIMPL;
117 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateGeometryGroup(ID2D1Factory *iface,
118 D2D1_FILL_MODE fill_mode, ID2D1Geometry *geometry, UINT32 geometry_count, ID2D1GeometryGroup **group)
120 FIXME("iface %p, fill_mode %#x, geometry %p, geometry_count %u, group %p stub!\n",
121 iface, fill_mode, geometry, geometry_count, group);
123 return E_NOTIMPL;
126 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateTransformedGeometry(ID2D1Factory *iface,
127 ID2D1Geometry *src_geometry, const D2D1_MATRIX_3X2_F *transform,
128 ID2D1TransformedGeometry **transformed_geometry)
130 FIXME("iface %p, src_geometry %p, transform %p, transformed_geometry %p stub!\n",
131 iface, src_geometry, transform, transformed_geometry);
133 return E_NOTIMPL;
136 static HRESULT STDMETHODCALLTYPE d2d_factory_CreatePathGeometry(ID2D1Factory *iface, ID2D1PathGeometry *geometry)
138 FIXME("iface %p, geometry %p stub!\n", iface, geometry);
140 return E_NOTIMPL;
143 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateStrokeStyle(ID2D1Factory *iface,
144 const D2D1_STROKE_STYLE_PROPERTIES *desc, const float *dashes, UINT32 dash_count,
145 ID2D1StrokeStyle **stroke_style)
147 struct d2d_stroke_style *object;
149 TRACE("iface %p, desc %p, dashes %p, dash_count %u, stroke_style %p.\n",
150 iface, desc, dashes, dash_count, stroke_style);
152 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
153 return E_OUTOFMEMORY;
155 d2d_stroke_style_init(object, iface, desc, dashes, dash_count);
157 TRACE("Created stroke style %p.\n", object);
158 *stroke_style = &object->ID2D1StrokeStyle_iface;
160 return S_OK;
163 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDrawingStateBlock(ID2D1Factory *iface,
164 const D2D1_DRAWING_STATE_DESCRIPTION *desc, IDWriteRenderingParams *text_rendering_params,
165 ID2D1DrawingStateBlock **state_block)
167 FIXME("iface %p, desc %p, text_rendering_params %p, state_block %p stub!\n",
168 iface, desc, text_rendering_params, state_block);
170 return E_NOTIMPL;
173 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateWicBitmapRenderTarget(ID2D1Factory *iface,
174 IWICBitmap *target, const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1RenderTarget **render_target)
176 struct d2d_wic_render_target *object;
177 HRESULT hr;
179 TRACE("iface %p, target %p, desc %p, render_target %p.\n", iface, target, desc, render_target);
181 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
182 return E_OUTOFMEMORY;
184 if (FAILED(hr = d2d_wic_render_target_init(object, iface, target, desc)))
186 WARN("Failed to initialize render target, hr %#x.\n", hr);
187 HeapFree(GetProcessHeap(), 0, object);
188 return hr;
191 TRACE("Created render target %p.\n", object);
192 *render_target = &object->ID2D1RenderTarget_iface;
194 return S_OK;
197 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateHwndRenderTarget(ID2D1Factory *iface,
198 const D2D1_RENDER_TARGET_PROPERTIES *desc, const D2D1_HWND_RENDER_TARGET_PROPERTIES *hwnd_rt_desc,
199 ID2D1HwndRenderTarget **render_target)
201 FIXME("iface %p, desc %p, hwnd_rt_desc %p, render_target %p stub!\n", iface, desc, hwnd_rt_desc, render_target);
203 return E_NOTIMPL;
206 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDxgiSurfaceRenderTarget(ID2D1Factory *iface,
207 IDXGISurface *surface, const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1RenderTarget **render_target)
209 struct d2d_d3d_render_target *object;
210 HRESULT hr;
212 TRACE("iface %p, surface %p, desc %p, render_target %p.\n", iface, surface, desc, render_target);
214 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
215 return E_OUTOFMEMORY;
217 if (FAILED(hr = d2d_d3d_render_target_init(object, iface, surface, desc)))
219 WARN("Failed to initialize render target, hr %#x.\n", hr);
220 HeapFree(GetProcessHeap(), 0, object);
221 return hr;
224 TRACE("Created render target %p.\n", object);
225 *render_target = &object->ID2D1RenderTarget_iface;
227 return S_OK;
230 static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDCRenderTarget(ID2D1Factory *iface,
231 const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1DCRenderTarget **render_target)
233 FIXME("iface %p, desc %p, render_target %p stub!\n", iface, desc, render_target);
235 return E_NOTIMPL;
238 static const struct ID2D1FactoryVtbl d2d_factory_vtbl =
240 d2d_factory_QueryInterface,
241 d2d_factory_AddRef,
242 d2d_factory_Release,
243 d2d_factory_ReloadSystemMetrics,
244 d2d_factory_GetDesktopDpi,
245 d2d_factory_CreateRectangleGeometry,
246 d2d_factory_CreateRoundedRectangleGeometry,
247 d2d_factory_CreateEllipseGeometry,
248 d2d_factory_CreateGeometryGroup,
249 d2d_factory_CreateTransformedGeometry,
250 d2d_factory_CreatePathGeometry,
251 d2d_factory_CreateStrokeStyle,
252 d2d_factory_CreateDrawingStateBlock,
253 d2d_factory_CreateWicBitmapRenderTarget,
254 d2d_factory_CreateHwndRenderTarget,
255 d2d_factory_CreateDxgiSurfaceRenderTarget,
256 d2d_factory_CreateDCRenderTarget,
259 static void d2d_factory_init(struct d2d_factory *factory, D2D1_FACTORY_TYPE factory_type,
260 const D2D1_FACTORY_OPTIONS *factory_options)
262 FIXME("Ignoring factory type and options.\n");
264 factory->ID2D1Factory_iface.lpVtbl = &d2d_factory_vtbl;
265 factory->refcount = 1;
268 HRESULT WINAPI D2D1CreateFactory(D2D1_FACTORY_TYPE factory_type, REFIID iid,
269 const D2D1_FACTORY_OPTIONS *factory_options, void **factory)
271 struct d2d_factory *object;
272 HRESULT hr;
274 TRACE("factory_type %#x, iid %s, factory_options %p, factory %p.\n",
275 factory_type, debugstr_guid(iid), factory_options, factory);
277 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
278 return E_OUTOFMEMORY;
280 d2d_factory_init(object, factory_type, factory_options);
282 TRACE("Created factory %p.\n", object);
284 hr = ID2D1Factory_QueryInterface(&object->ID2D1Factory_iface, iid, factory);
285 ID2D1Factory_Release(&object->ID2D1Factory_iface);
287 return hr;
290 void WINAPI D2D1MakeRotateMatrix(float angle, D2D1_POINT_2F center, D2D1_MATRIX_3X2_F *matrix)
292 float theta, sin_theta, cos_theta;
294 TRACE("angle %.8e, center {%.8e, %.8e}, matrix %p.\n", angle, center.x, center.y, matrix);
296 theta = angle * (M_PI / 180.0f);
297 sin_theta = sinf(theta);
298 cos_theta = cosf(theta);
300 /* translate(center) * rotate(theta) * translate(-center) */
301 matrix->_11 = cos_theta;
302 matrix->_12 = sin_theta;
303 matrix->_21 = -sin_theta;
304 matrix->_22 = cos_theta;
305 matrix->_31 = center.x - center.x * cos_theta + center.y * sin_theta;
306 matrix->_32 = center.y - center.x * sin_theta - center.y * cos_theta;