RetroArch
d2d1effecthelpers.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //
4 // D2D helper functions for effect authors.
5 //
6 // File name: D2D1EffectHelpers.h
7 //---------------------------------------------------------------------------
8 #pragma once
9 
10 #ifndef _D2D1_EFFECT_HELPERS_H_
11 #define _D2D1_EFFECT_HELPERS_H_
12 
13 /*#include <winapifamily.h>*/
14 
15 /*#pragma region Application Family*/
16 /*#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)*/
17 
18 #include <d2d1effectauthor.h>
19 
20 //+-----------------------------------------------------------------------------
21 //
22 // Function:
23 // DeducingValueSetter
24 //
25 // Synopsis:
26 // Deduces the class and arguments and then calls a member-function property
27 // setter callback for a value-type property.
28 //
29 // This should not be called directly.
30 //
31 //--------------------------------------------------------------------------------
32 template<class C, typename P, typename I>
34  _In_ HRESULT (C::*callback)(P),
35  _In_ I *effect,
36  _In_reads_(dataSize) const BYTE *data,
38  )
39 {
40  // We must exactly match the value-type's size.
41  if (dataSize != sizeof(P))
42  {
43  return E_INVALIDARG;
44  }
45 
46  return (static_cast<C *>(effect)->*callback)(*reinterpret_cast<const P *>(data));
47 }
48 
49 //+-----------------------------------------------------------------------------
50 //
51 // Function:
52 // ValueSetter
53 //
54 // Synopsis:
55 // Calls a member-function property setter callback for a value-type property.
56 //
57 //--------------------------------------------------------------------------------
58 template<typename T, T P, typename I>
60  _In_ IUnknown *effect,
61  _In_reads_(dataSize) const BYTE *data,
63  )
64 {
65  // Cast through I to resolve multiple-inheritance ambiguities.
66  return DeducingValueSetter(P, static_cast<I *>(effect), data, dataSize);
67 }
68 
69 //+-----------------------------------------------------------------------------
70 //
71 // Function:
72 // DeducingValueGetter
73 //
74 // Synopsis:
75 // Deduces the class and arguments and then calls a member-function property
76 // getter callback for a value-type property.
77 //
78 // This should not be called directly.
79 //
80 //--------------------------------------------------------------------------------
81 template<class C, typename P, typename I>
83  _In_ P (C::*callback)() const,
84  _In_ const I *effect,
85  _Out_writes_opt_(dataSize) BYTE *data,
87  _Out_opt_ UINT32 *actualSize
88  )
89 {
90  if (actualSize)
91  {
92  *actualSize = sizeof(P);
93  }
94 
95  if (dataSize > 0 && data)
96  {
97  if (dataSize < sizeof(P))
98  {
99  return E_NOT_SUFFICIENT_BUFFER;
100  }
101 
102  *reinterpret_cast<P *>(data) = (static_cast<const C *>(effect)->*callback)();
103  }
104 
105  return S_OK;
106 }
107 
108 //+-----------------------------------------------------------------------------
109 //
110 // Function:
111 // ValueGetter
112 //
113 // Synopsis:
114 // Calls a member-function property setter callback for a value-type property.
115 //
116 //--------------------------------------------------------------------------------
117 template<typename T, T P, typename I>
119  _In_ const IUnknown *effect,
120  _Out_writes_opt_(dataSize) BYTE *data,
122  _Out_opt_ UINT32 *actualSize
123  )
124 {
125  // Cast through I to resolve multiple-inheritance ambiguities.
126  return DeducingValueGetter(P, static_cast<const I *>(effect), data, dataSize, actualSize);
127 }
128 
129 //+-----------------------------------------------------------------------------
130 //
131 // Function:
132 // DeducingBlobSetter
133 //
134 // Synopsis:
135 // Deduces the class and arguments and then calls a member-function property
136 // setter callback for a blob-type property.
137 //
138 // This should not be called directly.
139 //
140 //--------------------------------------------------------------------------------
141 template<class C, typename I>
143  _In_ HRESULT (C::*callback)(const BYTE *, UINT32),
144  _In_ I *effect,
145  _In_reads_(dataSize) const BYTE *data,
147  )
148 {
149  return (static_cast<C *>(effect)->*callback)(data, dataSize);
150 }
151 
152 //+-----------------------------------------------------------------------------
153 //
154 // Function:
155 // BlobSetter
156 //
157 // Synopsis:
158 // Calls a member-function property setter callback for a blob-type property.
159 //
160 //--------------------------------------------------------------------------------
161 template<typename T, T P, typename I>
163  _In_ IUnknown *effect,
164  _In_reads_(dataSize) const BYTE *data,
166  )
167 {
168  // Cast through I to resolve multiple-inheritance ambiguities.
169  return DeducingBlobSetter(P, static_cast<I *>(effect), data, dataSize);
170 }
171 
172 //+-----------------------------------------------------------------------------
173 //
174 // Function:
175 // DeducingBlobGetter
176 //
177 // Synopsis:
178 // Deduces the class and arguments and then calls a member-function property
179 // getter callback for a blob-type property.
180 //
181 // This should not be called directly.
182 //
183 //--------------------------------------------------------------------------------
184 template<class C, typename I>
186  _In_ HRESULT (C::*callback)(BYTE *, UINT32, UINT32*) const,
187  _In_ const I *effect,
188  _Out_writes_opt_(dataSize) BYTE *data,
190  _Out_opt_ UINT32 *actualSize
191  )
192 {
193  return (static_cast<const C *>(effect)->*callback)(data, dataSize, actualSize);
194 }
195 
196 //+-----------------------------------------------------------------------------
197 //
198 // Function:
199 // BlobGetter
200 //
201 // Synopsis:
202 // Calls a member-function property getter callback for a blob-type property.
203 //
204 //--------------------------------------------------------------------------------
205 template<typename T, T P, typename I>
207  _In_ const IUnknown *effect,
208  _Out_writes_opt_(dataSize) BYTE *data,
210  _Out_opt_ UINT32 *actualSize
211  )
212 {
213  // Cast through I to resolve multiple-inheritance ambiguities.
214  return DeducingBlobGetter(P, static_cast<const I *>(effect), data, dataSize, actualSize);
215 }
216 
217 //+-----------------------------------------------------------------------------
218 //
219 // Function:
220 // DeducingStringSetter
221 //
222 // Synopsis:
223 // Deduces the class and arguments and then calls a member-function property
224 // setter callback for a string-type property.
225 //
226 // This should not be called directly.
227 //
228 //--------------------------------------------------------------------------------
229 template<class C, typename I>
231  _In_ HRESULT (C::*callback)(PCWSTR string),
232  _In_ I *effect,
233  _In_reads_(dataSize) const BYTE *data,
235  )
236 {
237  dataSize;
238 
239  return (static_cast<C *>(effect)->*callback)(reinterpret_cast<PCWSTR>(data));
240 }
241 
242 //+-----------------------------------------------------------------------------
243 //
244 // Function:
245 // StringSetter
246 //
247 // Synopsis:
248 // Calls a member-function property setter callback for a string-type property.
249 //
250 //--------------------------------------------------------------------------------
251 template<typename T, T P, typename I>
253  _In_ IUnknown *effect,
254  _In_reads_(dataSize) const BYTE *data,
256  )
257 {
258  // Cast through I to resolve multiple-inheritance ambiguities.
259  return DeducingStringSetter(P, static_cast<I *>(effect), data, dataSize);
260 }
261 
262 //+-----------------------------------------------------------------------------
263 //
264 // Function:
265 // DeducingStringGetter
266 //
267 // Synopsis:
268 // Deduces the class and arguments and then calls a member-function property
269 // getter callback for a string-type property.
270 //
271 // This should not be called directly.
272 //
273 //--------------------------------------------------------------------------------
274 template<class C, typename I>
276  _In_ HRESULT (C::*callback)(PWSTR, UINT32, UINT32*) const,
277  _In_ const I *effect,
278  _Out_writes_opt_(dataSize) BYTE *data,
280  _Out_opt_ UINT32 *actualSize
281  )
282 {
283  UINT32 cchString = 0;
284 
285  HRESULT hr = (static_cast<const C *>(effect)->*callback)(reinterpret_cast<PWSTR>(data), dataSize / sizeof(WCHAR), &cchString);
286 
287  if ((SUCCEEDED(hr) || hr == E_NOT_SUFFICIENT_BUFFER) && actualSize)
288  {
289  *actualSize = cchString * sizeof(WCHAR);
290  }
291 
292  return hr;
293 }
294 
295 //+-----------------------------------------------------------------------------
296 //
297 // Function:
298 // StringGetter
299 //
300 // Synopsis:
301 // Calls a member-function property getter callback for a string-type property.
302 //
303 //--------------------------------------------------------------------------------
304 template<typename T, T P, typename I>
306  _In_ const IUnknown *effect,
307  _Out_writes_opt_(dataSize) BYTE *data,
309  _Out_opt_ UINT32 *actualSize
310  )
311 {
312  // Cast through I to resolve multiple-inheritance ambiguities.
313  return DeducingStringGetter(P, static_cast<const I *>(effect), data, dataSize, actualSize);
314 }
315 
316 //
317 // Simpler versions of the helpers can be declared if decltype is available:
318 //
319 #if _MSC_VER >= 1600
320 #define D2D1_SIMPLE_BINDING_MACROS
321 #endif
322 
323 #ifdef D2D1_SIMPLE_BINDING_MACROS
324 
325 //
326 // Helper to work around decltype issues:
327 //
328 template<typename T>
329 T GetType(T t) { return t; };
330 
331 //
332 // Helper macros for declaring a D2D1_PROPERTY_BINDING for value, blob, or string callbacks.
333 //
334 #define D2D1_VALUE_TYPE_BINDING(NAME, SETTER, GETTER) \
335  { NAME, &ValueSetter<decltype(GetType(SETTER)), SETTER, ID2D1EffectImpl>, &ValueGetter<decltype(GetType(GETTER)), GETTER, ID2D1EffectImpl> }
336 
337 #define D2D1_BLOB_TYPE_BINDING(NAME, SETTER, GETTER) \
338  { NAME, &BlobSetter<decltype(GetType(SETTER)), SETTER, ID2D1EffectImpl>, &BlobGetter<decltype(GetType(GETTER)), GETTER, ID2D1EffectImpl> }
339 
340 #define D2D1_STRING_TYPE_BINDING(NAME, SETTER, GETTER) \
341  { NAME, &StringSetter<decltype(GetType(SETTER)), SETTER, ID2D1EffectImpl>, &StringGetter<decltype(GetType(GETTER)), GETTER, ID2D1EffectImpl> }
342 
343 //
344 // Read-only variants:
345 //
346 #define D2D1_READONLY_VALUE_TYPE_BINDING(NAME, GETTER) \
347  { NAME, NULL, &ValueGetter<decltype(GetType(GETTER)), GETTER, ID2D1EffectImpl> }
348 
349 #define D2D1_READONLY_BLOB_TYPE_BINDING(NAME, GETTER) \
350  { NAME, NULL, &BlobGetter<decltype(GetType(GETTER)), GETTER, ID2D1EffectImpl> }
351 
352 #define D2D1_READONLY_STRING_TYPE_BINDING(NAME, GETTER) \
353  { NAME, NULL, &StringGetter<decltype(GetType(GETTER)), GETTER, ID2D1EffectImpl> }
354 
355 #else // #ifdef D2D1_SIMPLE_BINDING_MACROS
356 
357 //
358 // Helper macros for declaring a D2D1_PROPERTY_BINDING for value, blob, or string callbacks.
359 //
360 #define D2D1_VALUE_TYPE_BINDING(NAME, TYPE, CLASS, SETTER, GETTER) \
361  { \
362  NAME, \
363  &ValueSetter<HRESULT (CLASS::*)(TYPE), SETTER, ID2D1EffectImpl>, \
364  &ValueGetter<TYPE (CLASS::*)() const, GETTER, ID2D1EffectImpl> \
365  }
366 
367 #define D2D1_BLOB_TYPE_BINDING(NAME, CLASS, SETTER, GETTER) \
368  { \
369  NAME, \
370  &BlobSetter<HRESULT (CLASS::*)(const BYTE *, UINT32), SETTER, ID2D1EffectImpl>, \
371  &BlobGetter<HRESULT (CLASS::*)(BYTE *, UINT32, UINT32*) const, GETTER, ID2D1EffectImpl> \
372  }
373 
374 #define D2D1_STRING_TYPE_BINDING(NAME, CLASS, SETTER, GETTER) \
375  { \
376  NAME, \
377  &StringSetter<HRESULT (CLASS::*)(PCWSTR string), SETTER, ID2D1EffectImpl>, \
378  &StringGetter<HRESULT (CLASS::*)(PWSTR, UINT32, UINT32*) const, GETTER, ID2D1EffectImpl> \
379  }
380 
381 //
382 // Read-only variants:
383 //
384 #define D2D1_READONLY_VALUE_TYPE_BINDING(NAME, TYPE, CLASS, GETTER) \
385  { \
386  NAME, \
387  NULL, \
388  &ValueGetter<TYPE (CLASS::*)() const, GETTER, ID2D1EffectImpl> \
389  }
390 
391 #define D2D1_READONLY_BLOB_TYPE_BINDING(NAME, CLASS, GETTER) \
392  { \
393  NAME, \
394  NULL, \
395  &BlobGetter<HRESULT (CLASS::*)(BYTE *, UINT32, UINT32*) const, GETTER, ID2D1EffectImpl> \
396  }
397 
398 #define D2D1_READONLY_STRING_TYPE_BINDING(NAME, CLASS, GETTER) \
399  { \
400  NAME, \
401  NULL, \
402  &StringGetter<HRESULT (CLASS::*)(PWSTR, UINT32, UINT32*) const, GETTER, ID2D1EffectImpl> \
403  }
404 
405 #endif // #ifdef D2D1_SIMPLE_BINDING_MACROS
406 
407 /*#endif*/ /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) */
408 /*#pragma endregion*/
409 
410 #endif // #ifndef _D2D1_AUTHOR_H_
HRESULT CALLBACK ValueGetter(_In_ const IUnknown *effect, _Out_writes_opt_(dataSize) BYTE *data, UINT32 dataSize, _Out_opt_ UINT32 *actualSize)
Definition: d2d1effecthelpers.h:118
#define T(x)
GLdouble GLdouble t
Definition: glext.h:6398
#define P(a, b, c, d, k, s, t)
typedef HRESULT(WINAPI *PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)(_In_ const D3D12_ROOT_SIGNATURE_DESC *pRootSignature
HRESULT DeducingValueGetter(_In_ P(C::*callback)() const, _In_ const I *effect, _Out_writes_opt_(dataSize) BYTE *data, UINT32 dataSize, _Out_opt_ UINT32 *actualSize)
Definition: d2d1effecthelpers.h:82
Definition: ibxm.h:9
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:6303
void callback(s32 result, dvdcmdblk *block)
Definition: dvd.c:2293
HRESULT CALLBACK BlobSetter(_In_ IUnknown *effect, _In_reads_(dataSize) const BYTE *data, UINT32 dataSize)
Definition: d2d1effecthelpers.h:162
HRESULT DeducingBlobSetter(_In_ HRESULT(C::*callback)(const BYTE *, UINT32), _In_ I *effect, _In_reads_(dataSize) const BYTE *data, UINT32 dataSize)
Definition: d2d1effecthelpers.h:142
HRESULT DeducingValueSetter(_In_ HRESULT(C::*callback)(P), _In_ I *effect, _In_reads_(dataSize) const BYTE *data, UINT32 dataSize)
Definition: d2d1effecthelpers.h:33
GLenum GLsizei dataSize
Definition: glext.h:12030
HRESULT CALLBACK BlobGetter(_In_ const IUnknown *effect, _Out_writes_opt_(dataSize) BYTE *data, UINT32 dataSize, _Out_opt_ UINT32 *actualSize)
Definition: d2d1effecthelpers.h:206
uint32_t UINT32
Definition: coretypes.h:10
HRESULT CALLBACK ValueSetter(_In_ IUnknown *effect, _In_reads_(dataSize) const BYTE *data, UINT32 dataSize)
Definition: d2d1effecthelpers.h:59
HRESULT CALLBACK StringSetter(_In_ IUnknown *effect, _In_reads_(dataSize) const BYTE *data, UINT32 dataSize)
Definition: d2d1effecthelpers.h:252
HRESULT CALLBACK StringGetter(_In_ const IUnknown *effect, _Out_writes_opt_(dataSize) BYTE *data, UINT32 dataSize, _Out_opt_ UINT32 *actualSize)
Definition: d2d1effecthelpers.h:305
HRESULT DeducingStringSetter(_In_ HRESULT(C::*callback)(PCWSTR string), _In_ I *effect, _In_reads_(dataSize) const BYTE *data, UINT32 dataSize)
Definition: d2d1effecthelpers.h:230
HRESULT DeducingStringGetter(_In_ HRESULT(C::*callback)(PWSTR, UINT32, UINT32 *) const, _In_ const I *effect, _Out_writes_opt_(dataSize) BYTE *data, UINT32 dataSize, _Out_opt_ UINT32 *actualSize)
Definition: d2d1effecthelpers.h:275
HRESULT DeducingBlobGetter(_In_ HRESULT(C::*callback)(BYTE *, UINT32, UINT32 *) const, _In_ const I *effect, _Out_writes_opt_(dataSize) BYTE *data, UINT32 dataSize, _Out_opt_ UINT32 *actualSize)
Definition: d2d1effecthelpers.h:185