source: Daodan/MSYS2/mingw32/i686-w64-mingw32/include/d2d1effecthelpers.h@ 1181

Last change on this file since 1181 was 1166, checked in by rossy, 3 years ago

Daodan: Replace MinGW build env with an up-to-date MSYS2 env

File size: 2.0 KB
RevLine 
[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
16template<typename T>
17T GetType(T t) {
18 return t;
19};
20
21template<class C, typename P, typename I>
22HRESULT 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
28template<typename T, T P, typename I>
29HRESULT CALLBACK ValueSetter(IUnknown *effect, const BYTE *data, UINT32 dataSize) {
30 return DeducingValueSetter(P, static_cast<I*>(effect), data, dataSize);
31}
32
33template<class C, typename P, typename I>
34HRESULT 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
48template<typename T, T P, typename I>
49HRESULT 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_ */
Note: See TracBrowser for help on using the repository browser.