summaryrefslogtreecommitdiffstats
path: root/src/gui/rhi/qdxgihdrinfo_p.h
blob: d19f87bc55a32bac146cf87fed0b944aca5892ad (plain)
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
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QDXGIHDRINFO_P_H
#define QDXGIHDRINFO_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include <QtGui/qwindow.h>
#include <rhi/qrhi.h>

#include <dxgi1_6.h>

QT_BEGIN_NAMESPACE

class Q_GUI_EXPORT QDxgiHdrInfo
{
public:
    // When already having an adapter, i.e. in a D3D11/12 backend of QRhi; this
    // is very cheap to construct.
    QDxgiHdrInfo(IDXGIAdapter1 *adapter);

    // When having the adapter LUID from somewhere (e.g.
    // VkPhysicalDeviceIDProperties::deviceLUID); This has to create a DXGI
    // factory and enumarate to find the matching IDXGIAdapter, so less cheap.
    QDxgiHdrInfo(LUID luid);

    // All functions below will enumerate all adapters and all their outputs
    // every time they are called. Probably not nice. Use when there is no
    // knowledge which GPUs will be used with QRhi.
    QDxgiHdrInfo();

    ~QDxgiHdrInfo();

    // True if the window belongs to an output where HDR is enabled. Moving a
    // window to another screen may make this function return a different value.
    //
    // If/how DXGI outputs map to screens, is out of our hands, but they will
    // typically match. However, this will not be functional when WARP is used
    // since the WARP adapter never has any outputs associated (even though
    // there are certainly screens still).
    //
    bool isHdrCapable(QWindow *w);

    // HDR info and white level. Or default, dummy values when the window is not
    // on a HDR-enabled output.
    QRhiSwapChainHdrInfo queryHdrInfo(QWindow *w);

private:
    static bool output6ForWindow(QWindow *w, IDXGIAdapter1 *adapter, IDXGIOutput6 **result);
    static bool outputDesc1ForWindow(QWindow *w, IDXGIAdapter1 *adapter, DXGI_OUTPUT_DESC1 *result);
    static float sdrWhiteLevelInNits(const DXGI_OUTPUT_DESC1 &outputDesc);

    IDXGIFactory2 *m_factory = nullptr;
    IDXGIAdapter1 *m_adapter = nullptr;
};

QT_END_NAMESPACE

#endif