[1166] | 1 | /**
|
---|
| 2 | * This file has no copyright assigned and is placed in the Public Domain.
|
---|
| 3 | * This file is part of the mingw-w64 runtime package.
|
---|
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
---|
| 5 | */
|
---|
| 6 |
|
---|
| 7 | #ifndef _D2D1_EFFECT_HELPERS_H_
|
---|
| 8 | #define _D2D1_EFFECT_HELPERS_H_
|
---|
| 9 |
|
---|
| 10 | #include <winapifamily.h>
|
---|
| 11 |
|
---|
| 12 | #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
|
---|
| 13 |
|
---|
| 14 | #include <d2d1effectauthor.h>
|
---|
| 15 |
|
---|
| 16 | template<typename T>
|
---|
| 17 | T GetType(T t) {
|
---|
| 18 | return t;
|
---|
| 19 | };
|
---|
| 20 |
|
---|
| 21 | template<class C, typename P, typename I>
|
---|
| 22 | HRESULT DeducingValueSetter(HRESULT (C::*callback)(P), I *effect, const BYTE *data, UINT32 dataSize) {
|
---|
| 23 | return dataSize == sizeof(P)
|
---|
| 24 | ? (static_cast<C*>(effect)->*callback)(*reinterpret_cast<const P*>(data))
|
---|
| 25 | : E_INVALIDARG;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | template<typename T, T P, typename I>
|
---|
| 29 | HRESULT CALLBACK ValueSetter(IUnknown *effect, const BYTE *data, UINT32 dataSize) {
|
---|
| 30 | return DeducingValueSetter(P, static_cast<I*>(effect), data, dataSize);
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | template<class C, typename P, typename I>
|
---|
| 34 | HRESULT DeducingValueGetter(P (C::*callback)() const, const I *effect, BYTE *data, UINT32 dataSize, UINT32 *actualSize) {
|
---|
| 35 | if (actualSize)
|
---|
| 36 | *actualSize = sizeof(P);
|
---|
| 37 |
|
---|
| 38 | if(!dataSize || !data)
|
---|
| 39 | return S_OK;
|
---|
| 40 |
|
---|
| 41 | if (dataSize < sizeof(P))
|
---|
| 42 | return E_NOT_SUFFICIENT_BUFFER;
|
---|
| 43 |
|
---|
| 44 | *reinterpret_cast<P*>(data) = (static_cast<const C*>(effect)->*callback)();
|
---|
| 45 | return S_OK;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | template<typename T, T P, typename I>
|
---|
| 49 | HRESULT CALLBACK ValueGetter(const IUnknown *effect, BYTE *data, UINT32 dataSize, UINT32 *actualSize) {
|
---|
| 50 | return DeducingValueGetter(P, static_cast<const I*>(effect), data, dataSize, actualSize);
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | #define D2D1_VALUE_TYPE_BINDING(name, setter, getter) \
|
---|
| 54 | { \
|
---|
| 55 | name, \
|
---|
| 56 | &ValueSetter<decltype(GetType(setter)), setter, ID2D1EffectImpl>, \
|
---|
| 57 | &ValueGetter<decltype(GetType(getter)), getter, ID2D1EffectImpl> \
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | #endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) */
|
---|
| 61 |
|
---|
| 62 | #endif /* _D2D1_EFFECT_HELPERS_H_ */
|
---|