d3d10/effect: Use case-insensitive comparison in GetMemberTypeBySemantic().
[wine.git] / dlls / d2d1 / stroke.c
blob0ba44e0b1d007f2bab01b38c948e9463f06248cd
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_ID2D1StrokeStyle(ID2D1StrokeStyle *iface)
25 return CONTAINING_RECORD(iface, struct d2d_stroke_style, ID2D1StrokeStyle_iface);
28 static HRESULT STDMETHODCALLTYPE d2d_stroke_style_QueryInterface(ID2D1StrokeStyle *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 ID2D1StrokeStyle_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(ID2D1StrokeStyle *iface)
49 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
50 ULONG refcount = InterlockedIncrement(&style->refcount);
52 TRACE("%p increasing refcount to %u.\n", iface, refcount);
54 return refcount;
57 static ULONG STDMETHODCALLTYPE d2d_stroke_style_Release(ID2D1StrokeStyle *iface)
59 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
60 ULONG refcount = InterlockedDecrement(&style->refcount);
62 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
64 if (!refcount)
66 ID2D1Factory_Release(style->factory);
67 if (style->desc.dashStyle == D2D1_DASH_STYLE_CUSTOM)
68 heap_free(style->dashes);
69 heap_free(style);
72 return refcount;
75 static void STDMETHODCALLTYPE d2d_stroke_style_GetFactory(ID2D1StrokeStyle *iface, ID2D1Factory **factory)
77 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(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(ID2D1StrokeStyle *iface)
86 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
88 TRACE("iface %p.\n", iface);
90 return style->desc.startCap;
93 static D2D1_CAP_STYLE STDMETHODCALLTYPE d2d_stroke_style_GetEndCap(ID2D1StrokeStyle *iface)
95 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
97 TRACE("iface %p.\n", iface);
99 return style->desc.endCap;
102 static D2D1_CAP_STYLE STDMETHODCALLTYPE d2d_stroke_style_GetDashCap(ID2D1StrokeStyle *iface)
104 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
106 TRACE("iface %p.\n", iface);
108 return style->desc.dashCap;
111 static float STDMETHODCALLTYPE d2d_stroke_style_GetMiterLimit(ID2D1StrokeStyle *iface)
113 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
115 TRACE("iface %p.\n", iface);
117 return style->desc.miterLimit;
120 static D2D1_LINE_JOIN STDMETHODCALLTYPE d2d_stroke_style_GetLineJoin(ID2D1StrokeStyle *iface)
122 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
124 TRACE("iface %p.\n", iface);
126 return style->desc.lineJoin;
129 static float STDMETHODCALLTYPE d2d_stroke_style_GetDashOffset(ID2D1StrokeStyle *iface)
131 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
133 TRACE("iface %p.\n", iface);
135 return style->desc.dashOffset;
138 static D2D1_DASH_STYLE STDMETHODCALLTYPE d2d_stroke_style_GetDashStyle(ID2D1StrokeStyle *iface)
140 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
142 TRACE("iface %p.\n", iface);
144 return style->desc.dashStyle;
147 static UINT32 STDMETHODCALLTYPE d2d_stroke_style_GetDashesCount(ID2D1StrokeStyle *iface)
149 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
151 TRACE("iface %p.\n", iface);
153 return style->dash_count;
156 static void STDMETHODCALLTYPE d2d_stroke_style_GetDashes(ID2D1StrokeStyle *iface, float *dashes, UINT32 dash_count)
158 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(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 const struct ID2D1StrokeStyleVtbl d2d_stroke_style_vtbl =
169 d2d_stroke_style_QueryInterface,
170 d2d_stroke_style_AddRef,
171 d2d_stroke_style_Release,
172 d2d_stroke_style_GetFactory,
173 d2d_stroke_style_GetStartCap,
174 d2d_stroke_style_GetEndCap,
175 d2d_stroke_style_GetDashCap,
176 d2d_stroke_style_GetMiterLimit,
177 d2d_stroke_style_GetLineJoin,
178 d2d_stroke_style_GetDashOffset,
179 d2d_stroke_style_GetDashStyle,
180 d2d_stroke_style_GetDashesCount,
181 d2d_stroke_style_GetDashes,
184 HRESULT d2d_stroke_style_init(struct d2d_stroke_style *style, ID2D1Factory *factory,
185 const D2D1_STROKE_STYLE_PROPERTIES *desc, const float *dashes, UINT32 dash_count)
187 static const struct
189 UINT32 dash_count;
190 float dashes[6];
192 builtin_dash_styles[] =
194 /* D2D1_DASH_STYLE_SOLID */ { 0 },
195 /* D2D1_DASH_STYLE_DASH */ { 2, {2.0f, 2.0f}},
196 /* D2D1_DASH_STYLE_DOT */ { 2, {0.0f, 2.0f}},
197 /* D2D1_DASH_STYLE_DASH_DOT */ { 4, {2.0f, 2.0f, 0.0f, 2.0f}},
198 /* D2D1_DASH_STYLE_DASH_DOT_DOT */ { 6, {2.0f, 2.0f, 0.0f, 2.0f, 0.0f, 2.0f}},
201 if (desc->dashStyle > D2D1_DASH_STYLE_CUSTOM)
202 return E_INVALIDARG;
204 style->ID2D1StrokeStyle_iface.lpVtbl = &d2d_stroke_style_vtbl;
205 style->refcount = 1;
207 if (desc->dashStyle == D2D1_DASH_STYLE_CUSTOM)
209 if (!dashes || !dash_count)
210 return E_INVALIDARG;
212 if (!(style->dashes = heap_calloc(dash_count, sizeof(*style->dashes))))
213 return E_OUTOFMEMORY;
214 memcpy(style->dashes, dashes, dash_count * sizeof(*style->dashes));
215 style->dash_count = dash_count;
217 else
219 if (dashes)
220 return E_INVALIDARG;
222 style->dashes = (float *)builtin_dash_styles[desc->dashStyle].dashes;
223 style->dash_count = builtin_dash_styles[desc->dashStyle].dash_count;
226 ID2D1Factory_AddRef(style->factory = factory);
227 style->desc = *desc;
229 return S_OK;