forked from vesa-org/DisplayHDRTest
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBackgroundNoiseEffect.h
More file actions
119 lines (98 loc) · 4.24 KB
/
BackgroundNoiseEffect.h
File metadata and controls
119 lines (98 loc) · 4.24 KB
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
111
112
113
114
115
116
117
118
119
//*********************************************************
//
// 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_BackgroundNoisePixelShader, 0x882aea52, 0x4067, 0x11ee, 0xbe, 0x56, 0x02, 0x42, 0xac, 0x12, 0x00, 0x02); // 882aea52 - 4067 - 11ee - be56 - 0242ac120002
DEFINE_GUID(CLSID_CustomBackgroundNoiseEffect, 0x882af0d8, 0x4067, 0x11ee, 0xbe, 0x56, 0x02, 0x42, 0xac, 0x12, 0x00, 0x02); // 882af0d8 - 4067 - 11ee - be56 - 0242ac120002
// 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 BackgroundNoiseEffect : public ID2D1EffectImpl, public ID2D1DrawTransform
{
public:
// Declare effect registration methods.
static HRESULT Register(_In_ ID2D1Factory1* pFactory);
static HRESULT __stdcall CreateBackgroundNoiseImpl(_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 SetAPL(float apl );
float GetAPL() const;
HRESULT SetClamp(float lim );
float GetClamp() const;
HRESULT SetiTime(float t );
float GetiTime() const;
private:
BackgroundNoiseEffect();
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.
// All distances are in pixels, we ignore DPI.
struct
{
float dpi; // screen property
float APL; // Average Picture Level in Nits
float Clamp; // No pixel values above this limit (nits)
float iTime; // time since app start in seconds
} 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;
};