d2d1effecthelpers.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #ifndef _D2D1_EFFECT_HELPERS_H_
  7. #define _D2D1_EFFECT_HELPERS_H_
  8. #include <winapifamily.h>
  9. #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
  10. #include <d2d1effectauthor.h>
  11. template<typename T>
  12. T GetType(T t) {
  13. return t;
  14. };
  15. template<class C, typename P, typename I>
  16. HRESULT DeducingValueSetter(HRESULT (C::*callback)(P), I *effect, const BYTE *data, UINT32 dataSize) {
  17. return dataSize == sizeof(P)
  18. ? (static_cast<C*>(effect)->*callback)(*reinterpret_cast<const P*>(data))
  19. : E_INVALIDARG;
  20. }
  21. template<typename T, T P, typename I>
  22. HRESULT CALLBACK ValueSetter(IUnknown *effect, const BYTE *data, UINT32 dataSize) {
  23. return DeducingValueSetter(P, static_cast<I*>(effect), data, dataSize);
  24. }
  25. template<class C, typename P, typename I>
  26. HRESULT DeducingValueGetter(P (C::*callback)() const, const I *effect, BYTE *data, UINT32 dataSize, UINT32 *actualSize) {
  27. if (actualSize)
  28. *actualSize = sizeof(P);
  29. if(!dataSize || !data)
  30. return S_OK;
  31. if (dataSize < sizeof(P))
  32. return E_NOT_SUFFICIENT_BUFFER;
  33. *reinterpret_cast<P*>(data) = (static_cast<const C*>(effect)->*callback)();
  34. return S_OK;
  35. }
  36. template<typename T, T P, typename I>
  37. HRESULT CALLBACK ValueGetter(const IUnknown *effect, BYTE *data, UINT32 dataSize, UINT32 *actualSize) {
  38. return DeducingValueGetter(P, static_cast<const I*>(effect), data, dataSize, actualSize);
  39. }
  40. #define D2D1_VALUE_TYPE_BINDING(name, setter, getter) \
  41. { \
  42. name, \
  43. &ValueSetter<decltype(GetType(setter)), setter, ID2D1EffectImpl>, \
  44. &ValueGetter<decltype(GetType(getter)), getter, ID2D1EffectImpl> \
  45. }
  46. #endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) */
  47. #endif /* _D2D1_EFFECT_HELPERS_H_ */