2014-07-18 10:37:56 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Henri Verbeet for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "d2d1_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d2d);
|
|
|
|
|
2021-12-06 14:29:00 +01:00
|
|
|
static inline struct d2d_stroke_style *impl_from_ID2D1StrokeStyle1(ID2D1StrokeStyle1 *iface)
|
2014-07-18 10:37:56 +02:00
|
|
|
{
|
2021-12-06 14:29:00 +01:00
|
|
|
return CONTAINING_RECORD(iface, struct d2d_stroke_style, ID2D1StrokeStyle1_iface);
|
2014-07-18 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:29:00 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE d2d_stroke_style_QueryInterface(ID2D1StrokeStyle1 *iface, REFIID iid, void **out)
|
2014-07-18 10:37:56 +02:00
|
|
|
{
|
|
|
|
TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
|
|
|
|
|
|
|
|
if (IsEqualGUID(iid, &IID_ID2D1StrokeStyle)
|
|
|
|
|| IsEqualGUID(iid, &IID_ID2D1Resource)
|
|
|
|
|| IsEqualGUID(iid, &IID_IUnknown))
|
|
|
|
{
|
2021-12-06 14:29:00 +01:00
|
|
|
ID2D1StrokeStyle1_AddRef(iface);
|
2014-07-18 10:37:56 +02:00
|
|
|
*out = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
|
|
|
|
|
|
|
|
*out = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2021-12-06 14:29:00 +01:00
|
|
|
static ULONG STDMETHODCALLTYPE d2d_stroke_style_AddRef(ID2D1StrokeStyle1 *iface)
|
2014-07-18 10:37:56 +02:00
|
|
|
{
|
2021-12-06 14:29:00 +01:00
|
|
|
struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
|
2014-07-18 10:37:56 +02:00
|
|
|
ULONG refcount = InterlockedIncrement(&style->refcount);
|
|
|
|
|
|
|
|
TRACE("%p increasing refcount to %u.\n", iface, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2021-12-06 14:29:00 +01:00
|
|
|
static ULONG STDMETHODCALLTYPE d2d_stroke_style_Release(ID2D1StrokeStyle1 *iface)
|
2014-07-18 10:37:56 +02:00
|
|
|
{
|
2021-12-06 14:29:00 +01:00
|
|
|
struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
|
2014-07-18 10:37:56 +02:00
|
|
|
ULONG refcount = InterlockedDecrement(&style->refcount);
|
|
|
|
|
|
|
|
TRACE("%p decreasing refcount to %u.\n", iface, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
2015-07-30 11:10:59 +02:00
|
|
|
{
|
|
|
|
ID2D1Factory_Release(style->factory);
|
2016-11-24 12:29:37 +01:00
|
|
|
if (style->desc.dashStyle == D2D1_DASH_STYLE_CUSTOM)
|
2018-01-30 13:24:39 +01:00
|
|
|
heap_free(style->dashes);
|
|
|
|
heap_free(style);
|
2015-07-30 11:10:59 +02:00
|
|
|
}
|
2014-07-18 10:37:56 +02:00
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2021-12-06 14:29:00 +01:00
|
|
|
static void STDMETHODCALLTYPE d2d_stroke_style_GetFactory(ID2D1StrokeStyle1 *iface, ID2D1Factory **factory)
|
2014-07-18 10:37:56 +02:00
|
|
|
{
|
2021-12-06 14:29:00 +01:00
|
|
|
struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
|
2015-07-30 11:10:59 +02:00
|
|
|
|
|
|
|
TRACE("iface %p, factory %p.\n", iface, factory);
|
2014-07-18 10:37:56 +02:00
|
|
|
|
2015-07-30 11:10:59 +02:00
|
|
|
ID2D1Factory_AddRef(*factory = style->factory);
|
2014-07-18 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:29:00 +01:00
|
|
|
static D2D1_CAP_STYLE STDMETHODCALLTYPE d2d_stroke_style_GetStartCap(ID2D1StrokeStyle1 *iface)
|
2014-07-18 10:37:56 +02:00
|
|
|
{
|
2021-12-06 14:29:00 +01:00
|
|
|
struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
|
2016-11-21 14:38:36 +01:00
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
2014-07-18 10:37:56 +02:00
|
|
|
|
2016-11-21 14:38:36 +01:00
|
|
|
return style->desc.startCap;
|
2014-07-18 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:29:00 +01:00
|
|
|
static D2D1_CAP_STYLE STDMETHODCALLTYPE d2d_stroke_style_GetEndCap(ID2D1StrokeStyle1 *iface)
|
2014-07-18 10:37:56 +02:00
|
|
|
{
|
2021-12-06 14:29:00 +01:00
|
|
|
struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
|
2016-11-21 14:38:36 +01:00
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
2014-07-18 10:37:56 +02:00
|
|
|
|
2016-11-21 14:38:36 +01:00
|
|
|
return style->desc.endCap;
|
2014-07-18 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:29:00 +01:00
|
|
|
static D2D1_CAP_STYLE STDMETHODCALLTYPE d2d_stroke_style_GetDashCap(ID2D1StrokeStyle1 *iface)
|
2014-07-18 10:37:56 +02:00
|
|
|
{
|
2021-12-06 14:29:00 +01:00
|
|
|
struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
|
2016-11-21 14:38:36 +01:00
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
2014-07-18 10:37:56 +02:00
|
|
|
|
2016-11-21 14:38:36 +01:00
|
|
|
return style->desc.dashCap;
|
2014-07-18 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:29:00 +01:00
|
|
|
static float STDMETHODCALLTYPE d2d_stroke_style_GetMiterLimit(ID2D1StrokeStyle1 *iface)
|
2014-07-18 10:37:56 +02:00
|
|
|
{
|
2021-12-06 14:29:00 +01:00
|
|
|
struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
|
2014-07-18 10:37:56 +02:00
|
|
|
|
2016-11-21 14:38:36 +01:00
|
|
|
TRACE("iface %p.\n", iface);
|
|
|
|
|
|
|
|
return style->desc.miterLimit;
|
2014-07-18 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:29:00 +01:00
|
|
|
static D2D1_LINE_JOIN STDMETHODCALLTYPE d2d_stroke_style_GetLineJoin(ID2D1StrokeStyle1 *iface)
|
2014-07-18 10:37:56 +02:00
|
|
|
{
|
2021-12-06 14:29:00 +01:00
|
|
|
struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
|
2014-07-18 10:37:56 +02:00
|
|
|
|
2016-11-21 14:38:36 +01:00
|
|
|
TRACE("iface %p.\n", iface);
|
|
|
|
|
|
|
|
return style->desc.lineJoin;
|
2014-07-18 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:29:00 +01:00
|
|
|
static float STDMETHODCALLTYPE d2d_stroke_style_GetDashOffset(ID2D1StrokeStyle1 *iface)
|
2014-07-18 10:37:56 +02:00
|
|
|
{
|
2021-12-06 14:29:00 +01:00
|
|
|
struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
|
2016-11-21 14:38:36 +01:00
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
2014-07-18 10:37:56 +02:00
|
|
|
|
2016-11-21 14:38:36 +01:00
|
|
|
return style->desc.dashOffset;
|
2014-07-18 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:29:00 +01:00
|
|
|
static D2D1_DASH_STYLE STDMETHODCALLTYPE d2d_stroke_style_GetDashStyle(ID2D1StrokeStyle1 *iface)
|
2014-07-18 10:37:56 +02:00
|
|
|
{
|
2021-12-06 14:29:00 +01:00
|
|
|
struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
|
2016-11-21 14:38:36 +01:00
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
2014-07-18 10:37:56 +02:00
|
|
|
|
2016-11-21 14:38:36 +01:00
|
|
|
return style->desc.dashStyle;
|
2014-07-18 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:29:00 +01:00
|
|
|
static UINT32 STDMETHODCALLTYPE d2d_stroke_style_GetDashesCount(ID2D1StrokeStyle1 *iface)
|
2014-07-18 10:37:56 +02:00
|
|
|
{
|
2021-12-06 14:29:00 +01:00
|
|
|
struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
|
2016-11-24 12:29:37 +01:00
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
2014-07-18 10:37:56 +02:00
|
|
|
|
2016-11-24 12:29:37 +01:00
|
|
|
return style->dash_count;
|
2014-07-18 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:29:00 +01:00
|
|
|
static void STDMETHODCALLTYPE d2d_stroke_style_GetDashes(ID2D1StrokeStyle1 *iface, float *dashes, UINT32 dash_count)
|
2014-07-18 10:37:56 +02:00
|
|
|
{
|
2021-12-06 14:29:00 +01:00
|
|
|
struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
|
2016-11-24 12:29:37 +01:00
|
|
|
|
|
|
|
TRACE("iface %p, dashes %p, count %u.\n", iface, dashes, dash_count);
|
|
|
|
|
|
|
|
memcpy(dashes, style->dashes, min(style->dash_count, dash_count) * sizeof(*dashes));
|
|
|
|
if (dash_count > style->dash_count)
|
|
|
|
memset(dashes + style->dash_count, 0, (dash_count - style->dash_count) * sizeof(*dashes));
|
2014-07-18 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:29:00 +01:00
|
|
|
static D2D1_STROKE_TRANSFORM_TYPE STDMETHODCALLTYPE d2d_stroke_style_GetStrokeTransformType(ID2D1StrokeStyle1 *iface)
|
|
|
|
{
|
|
|
|
struct d2d_stroke_style *style = impl_from_ID2D1StrokeStyle1(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
|
|
|
|
|
|
|
return style->desc.transformType;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ID2D1StrokeStyle1Vtbl d2d_stroke_style_vtbl =
|
2014-07-18 10:37:56 +02:00
|
|
|
{
|
|
|
|
d2d_stroke_style_QueryInterface,
|
|
|
|
d2d_stroke_style_AddRef,
|
|
|
|
d2d_stroke_style_Release,
|
|
|
|
d2d_stroke_style_GetFactory,
|
|
|
|
d2d_stroke_style_GetStartCap,
|
|
|
|
d2d_stroke_style_GetEndCap,
|
|
|
|
d2d_stroke_style_GetDashCap,
|
|
|
|
d2d_stroke_style_GetMiterLimit,
|
|
|
|
d2d_stroke_style_GetLineJoin,
|
|
|
|
d2d_stroke_style_GetDashOffset,
|
|
|
|
d2d_stroke_style_GetDashStyle,
|
|
|
|
d2d_stroke_style_GetDashesCount,
|
|
|
|
d2d_stroke_style_GetDashes,
|
2021-12-06 14:29:00 +01:00
|
|
|
d2d_stroke_style_GetStrokeTransformType
|
2014-07-18 10:37:56 +02:00
|
|
|
};
|
|
|
|
|
2016-11-24 12:29:37 +01:00
|
|
|
HRESULT d2d_stroke_style_init(struct d2d_stroke_style *style, ID2D1Factory *factory,
|
2021-12-06 14:29:00 +01:00
|
|
|
const D2D1_STROKE_STYLE_PROPERTIES1 *desc, const float *dashes, UINT32 dash_count)
|
2014-07-18 10:37:56 +02:00
|
|
|
{
|
2016-11-24 12:29:37 +01:00
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
UINT32 dash_count;
|
|
|
|
float dashes[6];
|
|
|
|
}
|
|
|
|
builtin_dash_styles[] =
|
|
|
|
{
|
|
|
|
/* D2D1_DASH_STYLE_SOLID */ { 0 },
|
|
|
|
/* D2D1_DASH_STYLE_DASH */ { 2, {2.0f, 2.0f}},
|
|
|
|
/* D2D1_DASH_STYLE_DOT */ { 2, {0.0f, 2.0f}},
|
|
|
|
/* D2D1_DASH_STYLE_DASH_DOT */ { 4, {2.0f, 2.0f, 0.0f, 2.0f}},
|
|
|
|
/* D2D1_DASH_STYLE_DASH_DOT_DOT */ { 6, {2.0f, 2.0f, 0.0f, 2.0f, 0.0f, 2.0f}},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (desc->dashStyle > D2D1_DASH_STYLE_CUSTOM)
|
|
|
|
return E_INVALIDARG;
|
2014-07-18 10:37:56 +02:00
|
|
|
|
2021-12-06 14:29:00 +01:00
|
|
|
if (desc->transformType != D2D1_STROKE_TRANSFORM_TYPE_NORMAL)
|
|
|
|
FIXME("transformType %d is not supported\n", desc->transformType);
|
|
|
|
|
|
|
|
style->ID2D1StrokeStyle1_iface.lpVtbl = &d2d_stroke_style_vtbl;
|
2014-07-18 10:37:56 +02:00
|
|
|
style->refcount = 1;
|
2016-11-24 12:29:37 +01:00
|
|
|
|
|
|
|
if (desc->dashStyle == D2D1_DASH_STYLE_CUSTOM)
|
|
|
|
{
|
|
|
|
if (!dashes || !dash_count)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2018-02-01 00:37:35 +01:00
|
|
|
if (!(style->dashes = heap_calloc(dash_count, sizeof(*style->dashes))))
|
2016-11-24 12:29:37 +01:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
memcpy(style->dashes, dashes, dash_count * sizeof(*style->dashes));
|
|
|
|
style->dash_count = dash_count;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (dashes)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
style->dashes = (float *)builtin_dash_styles[desc->dashStyle].dashes;
|
|
|
|
style->dash_count = builtin_dash_styles[desc->dashStyle].dash_count;
|
|
|
|
}
|
|
|
|
|
2015-07-30 11:10:59 +02:00
|
|
|
ID2D1Factory_AddRef(style->factory = factory);
|
2016-11-21 14:38:36 +01:00
|
|
|
style->desc = *desc;
|
2016-11-24 12:29:37 +01:00
|
|
|
|
|
|
|
return S_OK;
|
2014-07-18 10:37:56 +02:00
|
|
|
}
|