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 FIXME("iface %p, geometry %p stub!\n", iface
, geometry
);
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
;
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 struct d2d_state_block
*object
;
170 TRACE("iface %p, desc %p, text_rendering_params %p, state_block %p.\n",
171 iface
, desc
, text_rendering_params
, state_block
);
173 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
174 return E_OUTOFMEMORY
;
176 d2d_state_block_init(object
, desc
, text_rendering_params
);
178 TRACE("Created state block %p.\n", object
);
179 *state_block
= &object
->ID2D1DrawingStateBlock_iface
;
184 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateWicBitmapRenderTarget(ID2D1Factory
*iface
,
185 IWICBitmap
*target
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
, ID2D1RenderTarget
**render_target
)
187 struct d2d_wic_render_target
*object
;
190 TRACE("iface %p, target %p, desc %p, render_target %p.\n", iface
, target
, desc
, render_target
);
192 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
193 return E_OUTOFMEMORY
;
195 if (FAILED(hr
= d2d_wic_render_target_init(object
, iface
, target
, desc
)))
197 WARN("Failed to initialize render target, hr %#x.\n", hr
);
198 HeapFree(GetProcessHeap(), 0, object
);
202 TRACE("Created render target %p.\n", object
);
203 *render_target
= &object
->ID2D1RenderTarget_iface
;
208 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateHwndRenderTarget(ID2D1Factory
*iface
,
209 const D2D1_RENDER_TARGET_PROPERTIES
*desc
, const D2D1_HWND_RENDER_TARGET_PROPERTIES
*hwnd_rt_desc
,
210 ID2D1HwndRenderTarget
**render_target
)
212 FIXME("iface %p, desc %p, hwnd_rt_desc %p, render_target %p stub!\n", iface
, desc
, hwnd_rt_desc
, render_target
);
217 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateDxgiSurfaceRenderTarget(ID2D1Factory
*iface
,
218 IDXGISurface
*surface
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
, ID2D1RenderTarget
**render_target
)
220 struct d2d_d3d_render_target
*object
;
223 TRACE("iface %p, surface %p, desc %p, render_target %p.\n", iface
, surface
, desc
, render_target
);
225 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
226 return E_OUTOFMEMORY
;
228 if (FAILED(hr
= d2d_d3d_render_target_init(object
, iface
, surface
, desc
)))
230 WARN("Failed to initialize render target, hr %#x.\n", hr
);
231 HeapFree(GetProcessHeap(), 0, object
);
235 TRACE("Created render target %p.\n", object
);
236 *render_target
= &object
->ID2D1RenderTarget_iface
;
241 static HRESULT STDMETHODCALLTYPE
d2d_factory_CreateDCRenderTarget(ID2D1Factory
*iface
,
242 const D2D1_RENDER_TARGET_PROPERTIES
*desc
, ID2D1DCRenderTarget
**render_target
)
244 FIXME("iface %p, desc %p, render_target %p stub!\n", iface
, desc
, render_target
);
249 static const struct ID2D1FactoryVtbl d2d_factory_vtbl
=
251 d2d_factory_QueryInterface
,
254 d2d_factory_ReloadSystemMetrics
,
255 d2d_factory_GetDesktopDpi
,
256 d2d_factory_CreateRectangleGeometry
,
257 d2d_factory_CreateRoundedRectangleGeometry
,
258 d2d_factory_CreateEllipseGeometry
,
259 d2d_factory_CreateGeometryGroup
,
260 d2d_factory_CreateTransformedGeometry
,
261 d2d_factory_CreatePathGeometry
,
262 d2d_factory_CreateStrokeStyle
,
263 d2d_factory_CreateDrawingStateBlock
,
264 d2d_factory_CreateWicBitmapRenderTarget
,
265 d2d_factory_CreateHwndRenderTarget
,
266 d2d_factory_CreateDxgiSurfaceRenderTarget
,
267 d2d_factory_CreateDCRenderTarget
,
270 static void d2d_factory_init(struct d2d_factory
*factory
, D2D1_FACTORY_TYPE factory_type
,
271 const D2D1_FACTORY_OPTIONS
*factory_options
)
273 FIXME("Ignoring factory type and options.\n");
275 factory
->ID2D1Factory_iface
.lpVtbl
= &d2d_factory_vtbl
;
276 factory
->refcount
= 1;
279 HRESULT WINAPI
D2D1CreateFactory(D2D1_FACTORY_TYPE factory_type
, REFIID iid
,
280 const D2D1_FACTORY_OPTIONS
*factory_options
, void **factory
)
282 struct d2d_factory
*object
;
285 TRACE("factory_type %#x, iid %s, factory_options %p, factory %p.\n",
286 factory_type
, debugstr_guid(iid
), factory_options
, factory
);
288 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
289 return E_OUTOFMEMORY
;
291 d2d_factory_init(object
, factory_type
, factory_options
);
293 TRACE("Created factory %p.\n", object
);
295 hr
= ID2D1Factory_QueryInterface(&object
->ID2D1Factory_iface
, iid
, factory
);
296 ID2D1Factory_Release(&object
->ID2D1Factory_iface
);
301 void WINAPI
D2D1MakeRotateMatrix(float angle
, D2D1_POINT_2F center
, D2D1_MATRIX_3X2_F
*matrix
)
303 float theta
, sin_theta
, cos_theta
;
305 TRACE("angle %.8e, center {%.8e, %.8e}, matrix %p.\n", angle
, center
.x
, center
.y
, matrix
);
307 theta
= angle
* (M_PI
/ 180.0f
);
308 sin_theta
= sinf(theta
);
309 cos_theta
= cosf(theta
);
311 /* translate(center) * rotate(theta) * translate(-center) */
312 matrix
->_11
= cos_theta
;
313 matrix
->_12
= sin_theta
;
314 matrix
->_21
= -sin_theta
;
315 matrix
->_22
= cos_theta
;
316 matrix
->_31
= center
.x
- center
.x
* cos_theta
+ center
.y
* sin_theta
;
317 matrix
->_32
= center
.y
- center
.x
* sin_theta
- center
.y
* cos_theta
;