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
20 #include "wine/port.h"
22 #define D2D1_INIT_GUID
23 #include "d2d1_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d2d
);
29 ID2D1Factory ID2D1Factory_iface
;
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
);
50 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
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
);
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
);
74 HeapFree(GetProcessHeap(), 0, factory
);
79 static HRESULT STDMETHODCALLTYPE
d2d_factory_ReloadSystemMetrics(ID2D1Factory
*iface
)
81 FIXME("iface %p stub!\n", iface
);
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
);
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
);
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
);
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
);
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
);
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
);
137 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreatePathGeometry(ID2D1Factory
*iface
, ID2D1PathGeometry
**geometry
)
139 struct d2d_geometry
*object
;
141 TRACE("iface %p, geometry %p.\n", iface
, geometry
);
143 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
144 return E_OUTOFMEMORY
;
146 d2d_path_geometry_init(object
);
148 TRACE("Created path geometry %p.\n", object
);
149 *geometry
= (ID2D1PathGeometry
*)&object
->ID2D1Geometry_iface
;
154 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateStrokeStyle(ID2D1Factory
*iface
,
155 const D2D1_STROKE_STYLE_PROPERTIES
*desc
, const float *dashes
, UINT32 dash_count
,
156 ID2D1StrokeStyle
**stroke_style
)
158 struct d2d_stroke_style
*object
;
160 TRACE("iface %p, desc %p, dashes %p, dash_count %u, stroke_style %p.\n",
161 iface
, desc
, dashes
, dash_count
, stroke_style
);
163 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
164 return E_OUTOFMEMORY
;
166 d2d_stroke_style_init(object
, iface
, desc
, dashes
, dash_count
);
168 TRACE("Created stroke style %p.\n", object
);
169 *stroke_style
= &object
->ID2D1StrokeStyle_iface
;
174 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateDrawingStateBlock(ID2D1Factory
*iface
,
175 const D2D1_DRAWING_STATE_DESCRIPTION
*desc
, IDWriteRenderingParams
*text_rendering_params
,
176 ID2D1DrawingStateBlock
**state_block
)
178 struct d2d_state_block
*object
;
180 TRACE("iface %p, desc %p, text_rendering_params %p, state_block %p.\n",
181 iface
, desc
, text_rendering_params
, state_block
);
183 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
184 return E_OUTOFMEMORY
;
186 d2d_state_block_init(object
, desc
, text_rendering_params
);
188 TRACE("Created state block %p.\n", object
);
189 *state_block
= &object
->ID2D1DrawingStateBlock_iface
;
194 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateWicBitmapRenderTarget(ID2D1Factory
*iface
,
195 IWICBitmap
*target
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
, ID2D1RenderTarget
**render_target
)
197 struct d2d_wic_render_target
*object
;
200 TRACE("iface %p, target %p, desc %p, render_target %p.\n", iface
, target
, desc
, render_target
);
202 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
203 return E_OUTOFMEMORY
;
205 if (FAILED(hr
= d2d_wic_render_target_init(object
, iface
, target
, desc
)))
207 WARN("Failed to initialize render target, hr %#x.\n", hr
);
208 HeapFree(GetProcessHeap(), 0, object
);
212 TRACE("Created render target %p.\n", object
);
213 *render_target
= &object
->ID2D1RenderTarget_iface
;
218 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateHwndRenderTarget(ID2D1Factory
*iface
,
219 const D2D1_RENDER_TARGET_PROPERTIES
*desc
, const D2D1_HWND_RENDER_TARGET_PROPERTIES
*hwnd_rt_desc
,
220 ID2D1HwndRenderTarget
**render_target
)
222 FIXME("iface %p, desc %p, hwnd_rt_desc %p, render_target %p stub!\n", iface
, desc
, hwnd_rt_desc
, render_target
);
227 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateDxgiSurfaceRenderTarget(ID2D1Factory
*iface
,
228 IDXGISurface
*surface
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
, ID2D1RenderTarget
**render_target
)
230 struct d2d_d3d_render_target
*object
;
233 TRACE("iface %p, surface %p, desc %p, render_target %p.\n", iface
, surface
, desc
, render_target
);
235 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
236 return E_OUTOFMEMORY
;
238 if (FAILED(hr
= d2d_d3d_render_target_init(object
, iface
, surface
, desc
)))
240 WARN("Failed to initialize render target, hr %#x.\n", hr
);
241 HeapFree(GetProcessHeap(), 0, object
);
245 TRACE("Created render target %p.\n", object
);
246 *render_target
= &object
->ID2D1RenderTarget_iface
;
251 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateDCRenderTarget(ID2D1Factory
*iface
,
252 const D2D1_RENDER_TARGET_PROPERTIES
*desc
, ID2D1DCRenderTarget
**render_target
)
254 FIXME("iface %p, desc %p, render_target %p stub!\n", iface
, desc
, render_target
);
259 static const struct ID2D1FactoryVtbl d2d_factory_vtbl
=
261 d2d_factory_QueryInterface
,
264 d2d_factory_ReloadSystemMetrics
,
265 d2d_factory_GetDesktopDpi
,
266 d2d_factory_CreateRectangleGeometry
,
267 d2d_factory_CreateRoundedRectangleGeometry
,
268 d2d_factory_CreateEllipseGeometry
,
269 d2d_factory_CreateGeometryGroup
,
270 d2d_factory_CreateTransformedGeometry
,
271 d2d_factory_CreatePathGeometry
,
272 d2d_factory_CreateStrokeStyle
,
273 d2d_factory_CreateDrawingStateBlock
,
274 d2d_factory_CreateWicBitmapRenderTarget
,
275 d2d_factory_CreateHwndRenderTarget
,
276 d2d_factory_CreateDxgiSurfaceRenderTarget
,
277 d2d_factory_CreateDCRenderTarget
,
280 static void d2d_factory_init(struct d2d_factory
*factory
, D2D1_FACTORY_TYPE factory_type
,
281 const D2D1_FACTORY_OPTIONS
*factory_options
)
283 FIXME("Ignoring factory type and options.\n");
285 factory
->ID2D1Factory_iface
.lpVtbl
= &d2d_factory_vtbl
;
286 factory
->refcount
= 1;
289 HRESULT WINAPI
D2D1CreateFactory(D2D1_FACTORY_TYPE factory_type
, REFIID iid
,
290 const D2D1_FACTORY_OPTIONS
*factory_options
, void **factory
)
292 struct d2d_factory
*object
;
295 TRACE("factory_type %#x, iid %s, factory_options %p, factory %p.\n",
296 factory_type
, debugstr_guid(iid
), factory_options
, factory
);
298 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
299 return E_OUTOFMEMORY
;
301 d2d_factory_init(object
, factory_type
, factory_options
);
303 TRACE("Created factory %p.\n", object
);
305 hr
= ID2D1Factory_QueryInterface(&object
->ID2D1Factory_iface
, iid
, factory
);
306 ID2D1Factory_Release(&object
->ID2D1Factory_iface
);
311 void WINAPI
D2D1MakeRotateMatrix(float angle
, D2D1_POINT_2F center
, D2D1_MATRIX_3X2_F
*matrix
)
313 float theta
, sin_theta
, cos_theta
;
315 TRACE("angle %.8e, center {%.8e, %.8e}, matrix %p.\n", angle
, center
.x
, center
.y
, matrix
);
317 theta
= angle
* (M_PI
/ 180.0f
);
318 sin_theta
= sinf(theta
);
319 cos_theta
= cosf(theta
);
321 /* translate(center) * rotate(theta) * translate(-center) */
322 matrix
->_11
= cos_theta
;
323 matrix
->_12
= sin_theta
;
324 matrix
->_21
= -sin_theta
;
325 matrix
->_22
= cos_theta
;
326 matrix
->_31
= center
.x
- center
.x
* cos_theta
+ center
.y
* sin_theta
;
327 matrix
->_32
= center
.y
- center
.x
* sin_theta
- center
.y
* cos_theta
;