wined3d: Move the wined3d_gl.h include to individual files.
[wine.git] / dlls / d2d1 / stroke.c
blob16fa1f6077122aaa89dd20c6f9f9d2c6fa617c4f
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 "d2d1_private.h"
21 WINE_DEFAULT_DEBUG_CHANNEL(d2d);
23 static inline struct d2d_stroke_style *impl_from_ID2D1StrokeStyle1(ID2D1StrokeStyle1 *iface)
25 return CONTAINING_RECORD(iface, struct d2d_stroke_style, ID2D1StrokeStyle1_iface);
28 static HRESULT STDMETHODCALLTYPE d2d_stroke_style_QueryInterface(ID2D1StrokeStyle1 *iface, REFIID iid, void **out)
30 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
32 if (IsEqualGUID(iid, &IID_ID2D1StrokeStyle)
33 || IsEqualGUID(iid, &IID_ID2D1Resource)
34 || IsEqualGUID(iid, &IID_IUnknown))
36 ID2D1StrokeStyle1_AddRef(iface);
37 *out = iface;
38 return S_OK;
41 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
43 *out = NULL;
44 return E_NOINTERFACE;
47 static ULONG STDMETHODCALLTYPE d2d_stroke_style_AddRef(ID2D1StrokeStyle1 *iface)
49 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
50 ULONG refcount = InterlockedIncrement(&style->refcount);
52 TRACE("%p increasing refcount to %lu.\n", iface, refcount);
54 return refcount;
57 static ULONG STDMETHODCALLTYPE d2d_stroke_style_Release(ID2D1StrokeStyle1 *iface)
59 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
60 ULONG refcount = InterlockedDecrement(&style->refcount);
62 TRACE("%p decreasing refcount to %lu.\n", iface, refcount);
64 if (!refcount)
66 ID2D1Factory_Release(style->factory);
67 if (style->desc.dashStyle == D2D1_DASH_STYLE_CUSTOM)
68 free(style->dashes);
69 free(style);
72 return refcount;
75 static void STDMETHODCALLTYPE d2d_stroke_style_GetFactory(ID2D1StrokeStyle1 *iface, ID2D1Factory **factory)
77 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
79 TRACE("iface %p, factory %p.\n", iface, factory);
81 ID2D1Factory_AddRef(*factory = style->factory);
84 static D2D1_CAP_STYLE STDMETHODCALLTYPE d2d_stroke_style_GetStartCap(ID2D1StrokeStyle1 *iface)
86 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
88 TRACE("iface %p.\n", iface);
90 return style->desc.startCap;
93 static D2D1_CAP_STYLE STDMETHODCALLTYPE d2d_stroke_style_GetEndCap(ID2D1StrokeStyle1 *iface)
95 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
97 TRACE("iface %p.\n", iface);
99 return style->desc.endCap;
102 static D2D1_CAP_STYLE STDMETHODCALLTYPE d2d_stroke_style_GetDashCap(ID2D1StrokeStyle1 *iface)
104 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
106 TRACE("iface %p.\n", iface);
108 return style->desc.dashCap;
111 static float STDMETHODCALLTYPE d2d_stroke_style_GetMiterLimit(ID2D1StrokeStyle1 *iface)
113 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
115 TRACE("iface %p.\n", iface);
117 return style->desc.miterLimit;
120 static D2D1_LINE_JOIN STDMETHODCALLTYPE d2d_stroke_style_GetLineJoin(ID2D1StrokeStyle1 *iface)
122 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
124 TRACE("iface %p.\n", iface);
126 return style->desc.lineJoin;
129 static float STDMETHODCALLTYPE d2d_stroke_style_GetDashOffset(ID2D1StrokeStyle1 *iface)
131 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
133 TRACE("iface %p.\n", iface);
135 return style->desc.dashOffset;
138 static D2D1_DASH_STYLE STDMETHODCALLTYPE d2d_stroke_style_GetDashStyle(ID2D1StrokeStyle1 *iface)
140 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
142 TRACE("iface %p.\n", iface);
144 return style->desc.dashStyle;
147 static UINT32 STDMETHODCALLTYPE d2d_stroke_style_GetDashesCount(ID2D1StrokeStyle1 *iface)
149 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
151 TRACE("iface %p.\n", iface);
153 return style->dash_count;
156 static void STDMETHODCALLTYPE d2d_stroke_style_GetDashes(ID2D1StrokeStyle1 *iface, float *dashes, UINT32 dash_count)
158 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
160 TRACE("iface %p, dashes %p, count %u.\n", iface, dashes, dash_count);
162 memcpy(dashes, style->dashes, min(style->dash_count, dash_count) * sizeof(*dashes));
163 if (dash_count > style->dash_count)
164 memset(dashes + style->dash_count, 0, (dash_count - style->dash_count) * sizeof(*dashes));
167 static D2D1_STROKE_TRANSFORM_TYPE STDMETHODCALLTYPE d2d_stroke_style_GetStrokeTransformType(ID2D1StrokeStyle1 *iface)
169 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
171 TRACE("iface %p.\n", iface);
173 return style->desc.transformType;
176 static const struct ID2D1StrokeStyle1Vtbl d2d_stroke_style_vtbl =
178 d2d_stroke_style_QueryInterface,
179 d2d_stroke_style_AddRef,
180 d2d_stroke_style_Release,
181 d2d_stroke_style_GetFactory,
182 d2d_stroke_style_GetStartCap,
183 d2d_stroke_style_GetEndCap,
184 d2d_stroke_style_GetDashCap,
185 d2d_stroke_style_GetMiterLimit,
186 d2d_stroke_style_GetLineJoin,
187 d2d_stroke_style_GetDashOffset,
188 d2d_stroke_style_GetDashStyle,
189 d2d_stroke_style_GetDashesCount,
190 d2d_stroke_style_GetDashes,
191 d2d_stroke_style_GetStrokeTransformType
194 HRESULT d2d_stroke_style_init(struct d2d_stroke_style *style, ID2D1Factory *factory,
195 const D2D1_STROKE_STYLE_PROPERTIES1 *desc, const float *dashes, UINT32 dash_count)
197 static const struct
199 UINT32 dash_count;
200 float dashes[6];
202 builtin_dash_styles[] =
204 /* D2D1_DASH_STYLE_SOLID */ { 0 },
205 /* D2D1_DASH_STYLE_DASH */ { 2, {2.0f, 2.0f}},
206 /* D2D1_DASH_STYLE_DOT */ { 2, {0.0f, 2.0f}},
207 /* D2D1_DASH_STYLE_DASH_DOT */ { 4, {2.0f, 2.0f, 0.0f, 2.0f}},
208 /* D2D1_DASH_STYLE_DASH_DOT_DOT */ { 6, {2.0f, 2.0f, 0.0f, 2.0f, 0.0f, 2.0f}},
211 if (desc->dashStyle > D2D1_DASH_STYLE_CUSTOM)
212 return E_INVALIDARG;
214 if (desc->transformType != D2D1_STROKE_TRANSFORM_TYPE_NORMAL)
215 FIXME("transformType %d is not supported\n", desc->transformType);
217 style->ID2D1StrokeStyle1_iface.lpVtbl = &d2d_stroke_style_vtbl;
218 style->refcount = 1;
220 if (desc->dashStyle == D2D1_DASH_STYLE_CUSTOM)
222 if (!dashes || !dash_count)
223 return E_INVALIDARG;
225 if (!(style->dashes = calloc(dash_count, sizeof(*style->dashes))))
226 return E_OUTOFMEMORY;
227 memcpy(style->dashes, dashes, dash_count * sizeof(*style->dashes));
228 style->dash_count = dash_count;
230 else
232 if (dashes)
233 return E_INVALIDARG;
235 style->dashes = (float *)builtin_dash_styles[desc->dashStyle].dashes;
236 style->dash_count = builtin_dash_styles[desc->dashStyle].dash_count;
239 ID2D1Factory_AddRef(style->factory = factory);
240 style->desc = *desc;
242 return S_OK;