forked from vesa-org/DisplayHDRTest
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBandedGradientEffect.h
110 lines (91 loc) · 3.8 KB
/
BandedGradientEffect.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
DEFINE_GUID(GUID_BandedGradientPixelShader, 0xfddf597e, 0x98d4, 0x4aac, 0x83, 0x49, 0x6f, 0xb8, 0x76, 0x67, 0xdc, 0xb5);
DEFINE_GUID(CLSID_CustomBandedGradientEffect, 0x376c22b8, 0xe6c3, 0x41e7, 0xb1, 0xc1, 0xfb, 0x5f, 0x7e, 0xc9, 0xee, 0x49);
// Our effect contains one transform, which is simply a wrapper around a pixel shader. As such,
// we can simply make the effect itself act as the transform.
class BandedGradientEffect : public ID2D1EffectImpl, public ID2D1DrawTransform
{
public:
// Declare effect registration methods.
static HRESULT Register(_In_ ID2D1Factory1* pFactory);
static HRESULT __stdcall CreateBandedGradientImpl(_Outptr_ IUnknown** ppEffectImpl);
// Declare ID2D1EffectImpl implementation methods.
IFACEMETHODIMP Initialize(
_In_ ID2D1EffectContext* pContextInternal,
_In_ ID2D1TransformGraph* pTransformGraph
);
IFACEMETHODIMP PrepareForRender(D2D1_CHANGE_TYPE changeType);
IFACEMETHODIMP SetGraph(_In_ ID2D1TransformGraph* pGraph);
// Declare ID2D1DrawTransform implementation methods.
IFACEMETHODIMP SetDrawInfo(_In_ ID2D1DrawInfo* pRenderInfo);
// Declare ID2D1Transform implementation methods.
IFACEMETHODIMP MapOutputRectToInputRects(
_In_ const D2D1_RECT_L* pOutputRect,
_Out_writes_(inputRectCount) D2D1_RECT_L* pInputRects,
UINT32 inputRectCount
) const;
IFACEMETHODIMP MapInputRectsToOutputRect(
_In_reads_(inputRectCount) CONST D2D1_RECT_L* pInputRects,
_In_reads_(inputRectCount) CONST D2D1_RECT_L* pInputOpaqueSubRects,
UINT32 inputRectCount,
_Out_ D2D1_RECT_L* pOutputRect,
_Out_ D2D1_RECT_L* pOutputOpaqueSubRect
);
IFACEMETHODIMP MapInvalidRect(
UINT32 inputIndex,
D2D1_RECT_L invalidInputRect,
_Out_ D2D1_RECT_L* pInvalidOutputRect
) const;
// Declare ID2D1TransformNode implementation methods.
IFACEMETHODIMP_(UINT32) GetInputCount() const;
// Declare IUnknown implementation methods.
IFACEMETHODIMP_(ULONG) AddRef();
IFACEMETHODIMP_(ULONG) Release();
IFACEMETHODIMP QueryInterface(_In_ REFIID riid, _Outptr_ void** ppOutput);
// Declare property getter/setter methods.
HRESULT SetOutputSize(D2D1_POINT_2F size);
D2D1_POINT_2F GetOutputSize() const;
private:
BandedGradientEffect();
HRESULT UpdateConstants();
inline static float Clamp(float v, float low, float high)
{
return (v < low) ? low : (v > high) ? high : v;
}
inline static float Round(float v)
{
return floor(v + 0.5f);
}
// Prevents over/underflows when adding longs.
inline static long SafeAdd(long base, long valueToAdd)
{
if (valueToAdd >= 0)
{
return ((base + valueToAdd) >= base) ? (base + valueToAdd) : LONG_MAX;
}
else
{
return ((base + valueToAdd) <= base) ? (base + valueToAdd) : LONG_MIN;
}
}
// This struct defines the constant buffer of our pixel shader.
struct
{
float dpi;
D2D1_POINT_2F outputSize;
} m_constants;
Microsoft::WRL::ComPtr<ID2D1DrawInfo> m_drawInfo;
Microsoft::WRL::ComPtr<ID2D1EffectContext> m_effectContext;
LONG m_refCount;
D2D1_RECT_L m_inputRect;
float m_dpi;
};