wined3d: Factor out acquire_graphics_pipeline_resources().
[wine.git] / dlls / d2d1 / stroke.c
blobc5a1d503ffa8d8a772e4eca9b10c71f596621444
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 static inline struct d2d_stroke_style *impl_from_ID2D1StrokeStyle(ID2D1StrokeStyle *iface)
28 return CONTAINING_RECORD(iface, struct d2d_stroke_style, ID2D1StrokeStyle_iface);
31 static HRESULT STDMETHODCALLTYPE d2d_stroke_style_QueryInterface(ID2D1StrokeStyle *iface, REFIID iid, void **out)
33 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
35 if (IsEqualGUID(iid, &IID_ID2D1StrokeStyle)
36 || IsEqualGUID(iid, &IID_ID2D1Resource)
37 || IsEqualGUID(iid, &IID_IUnknown))
39 ID2D1StrokeStyle_AddRef(iface);
40 *out = iface;
41 return S_OK;
44 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
46 *out = NULL;
47 return E_NOINTERFACE;
50 static ULONG STDMETHODCALLTYPE d2d_stroke_style_AddRef(ID2D1StrokeStyle *iface)
52 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
53 ULONG refcount = InterlockedIncrement(&style->refcount);
55 TRACE("%p increasing refcount to %u.\n", iface, refcount);
57 return refcount;
60 static ULONG STDMETHODCALLTYPE d2d_stroke_style_Release(ID2D1StrokeStyle *iface)
62 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
63 ULONG refcount = InterlockedDecrement(&style->refcount);
65 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
67 if (!refcount)
69 ID2D1Factory_Release(style->factory);
70 if (style->desc.dashStyle == D2D1_DASH_STYLE_CUSTOM)
71 HeapFree(GetProcessHeap(), 0, style->dashes);
72 HeapFree(GetProcessHeap(), 0, style);
75 return refcount;
78 static void STDMETHODCALLTYPE d2d_stroke_style_GetFactory(ID2D1StrokeStyle *iface, ID2D1Factory **factory)
80 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
82 TRACE("iface %p, factory %p.\n", iface, factory);
84 ID2D1Factory_AddRef(*factory = style->factory);
87 static D2D1_CAP_STYLE STDMETHODCALLTYPE d2d_stroke_style_GetStartCap(ID2D1StrokeStyle *iface)
89 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
91 TRACE("iface %p.\n", iface);
93 return style->desc.startCap;
96 static D2D1_CAP_STYLE STDMETHODCALLTYPE d2d_stroke_style_GetEndCap(ID2D1StrokeStyle *iface)
98 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
100 TRACE("iface %p.\n", iface);
102 return style->desc.endCap;
105 static D2D1_CAP_STYLE STDMETHODCALLTYPE d2d_stroke_style_GetDashCap(ID2D1StrokeStyle *iface)
107 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
109 TRACE("iface %p.\n", iface);
111 return style->desc.dashCap;
114 static float STDMETHODCALLTYPE d2d_stroke_style_GetMiterLimit(ID2D1StrokeStyle *iface)
116 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
118 TRACE("iface %p.\n", iface);
120 return style->desc.miterLimit;
123 static D2D1_LINE_JOIN STDMETHODCALLTYPE d2d_stroke_style_GetLineJoin(ID2D1StrokeStyle *iface)
125 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
127 TRACE("iface %p.\n", iface);
129 return style->desc.lineJoin;
132 static float STDMETHODCALLTYPE d2d_stroke_style_GetDashOffset(ID2D1StrokeStyle *iface)
134 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
136 TRACE("iface %p.\n", iface);
138 return style->desc.dashOffset;
141 static D2D1_DASH_STYLE STDMETHODCALLTYPE d2d_stroke_style_GetDashStyle(ID2D1StrokeStyle *iface)
143 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
145 TRACE("iface %p.\n", iface);
147 return style->desc.dashStyle;
150 static UINT32 STDMETHODCALLTYPE d2d_stroke_style_GetDashesCount(ID2D1StrokeStyle *iface)
152 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
154 TRACE("iface %p.\n", iface);
156 return style->dash_count;
159 static void STDMETHODCALLTYPE d2d_stroke_style_GetDashes(ID2D1StrokeStyle *iface, float *dashes, UINT32 dash_count)
161 struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle(iface);
163 TRACE("iface %p, dashes %p, count %u.\n", iface, dashes, dash_count);
165 memcpy(dashes, style->dashes, min(style->dash_count, dash_count) * sizeof(*dashes));
166 if (dash_count > style->dash_count)
167 memset(dashes + style->dash_count, 0, (dash_count - style->dash_count) * sizeof(*dashes));
170 static const struct ID2D1StrokeStyleVtbl d2d_stroke_style_vtbl =
172 d2d_stroke_style_QueryInterface,
173 d2d_stroke_style_AddRef,
174 d2d_stroke_style_Release,
175 d2d_stroke_style_GetFactory,
176 d2d_stroke_style_GetStartCap,
177 d2d_stroke_style_GetEndCap,
178 d2d_stroke_style_GetDashCap,
179 d2d_stroke_style_GetMiterLimit,
180 d2d_stroke_style_GetLineJoin,
181 d2d_stroke_style_GetDashOffset,
182 d2d_stroke_style_GetDashStyle,
183 d2d_stroke_style_GetDashesCount,
184 d2d_stroke_style_GetDashes,
187 HRESULT d2d_stroke_style_init(struct d2d_stroke_style *style, ID2D1Factory *factory,
188 const D2D1_STROKE_STYLE_PROPERTIES *desc, const float *dashes, UINT32 dash_count)
190 static const struct
192 UINT32 dash_count;
193 float dashes[6];
195 builtin_dash_styles[] =
197 /* D2D1_DASH_STYLE_SOLID */ { 0 },
198 /* D2D1_DASH_STYLE_DASH */ { 2, {2.0f, 2.0f}},
199 /* D2D1_DASH_STYLE_DOT */ { 2, {0.0f, 2.0f}},
200 /* D2D1_DASH_STYLE_DASH_DOT */ { 4, {2.0f, 2.0f, 0.0f, 2.0f}},
201 /* D2D1_DASH_STYLE_DASH_DOT_DOT */ { 6, {2.0f, 2.0f, 0.0f, 2.0f, 0.0f, 2.0f}},
204 if (desc->dashStyle > D2D1_DASH_STYLE_CUSTOM)
205 return E_INVALIDARG;
207 style->ID2D1StrokeStyle_iface.lpVtbl = &d2d_stroke_style_vtbl;
208 style->refcount = 1;
210 if (desc->dashStyle == D2D1_DASH_STYLE_CUSTOM)
212 if (!dashes || !dash_count)
213 return E_INVALIDARG;
215 if (!(style->dashes = HeapAlloc(GetProcessHeap(), 0, dash_count * sizeof(*style->dashes))))
216 return E_OUTOFMEMORY;
217 memcpy(style->dashes, dashes, dash_count * sizeof(*style->dashes));
218 style->dash_count = dash_count;
220 else
222 if (dashes)
223 return E_INVALIDARG;
225 style->dashes = (float *)builtin_dash_styles[desc->dashStyle].dashes;
226 style->dash_count = builtin_dash_styles[desc->dashStyle].dash_count;
229 ID2D1Factory_AddRef(style->factory = factory);
230 style->desc = *desc;
232 return S_OK;