Monado OpenXR Runtime
Loading...
Searching...
No Matches
d3d_convertible_luid.hpp
Go to the documentation of this file.
1// Copyright 2019-2024, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Helper for converting LUIDs between different data types
6 *
7 * @author Rylie Pavlik <rylie.pavlik@collabora.com>
8 * @ingroup aux_d3d
9 */
10
11#pragma once
12
13#include "xrt/xrt_defines.h"
14#include "xrt/xrt_windows.h"
15#include "xrt/xrt_compiler.h"
16
17#include <cstring>
18#include <winrt/Windows.Graphics.h>
19
20#include <stdint.h>
21#include <utility>
22#include <tuple>
23
24namespace xrt::auxiliary::d3d {
25
26//! Wrapper/interchange type for LUIDs, which identify display adapters on Windows.
28{
29 //! Construct from a Windows LUID
30 explicit ConvertibleLuid(LUID const &luid) : t(luid.LowPart, luid.HighPart) {}
31
32 //! Construct from a WinRT LUID (Windows.Graphics.DisplayAdapterId)
33 explicit ConvertibleLuid(::winrt::Windows::Graphics::DisplayAdapterId const &id) : t(id.LowPart, id.HighPart) {}
34
35 //! Construct from a Monado LUID
36 explicit ConvertibleLuid(const xrt_luid_t &luid) : ConvertibleLuid(fromMonadoLuid(luid)) {}
37
38 //! Implicit conversion to a Windows LUID
39 operator LUID() const
40 {
41 LUID ret;
42 std::tie(ret.LowPart, ret.HighPart) = t;
43 return ret;
44 }
45
46 //! Implicit conversion to a WinRT LUID (Windows.Graphics.DisplayAdapterId)
47 operator ::winrt::Windows::Graphics::DisplayAdapterId() const
48 {
49 return ::winrt::Windows::Graphics::DisplayAdapterId{std::get<0>(t), std::get<1>(t)};
50 }
51
52 //! Implicit conversion to a Monado LUID
53 operator xrt_luid_t() const
54 {
55 return toMonadoLuid(*this);
56 }
57
58
59 friend XRT_CHECK_RESULT bool
60 operator==(ConvertibleLuid const &lhs, ConvertibleLuid const &rhs)
61 {
62 return lhs.t == rhs.t;
63 }
64 friend XRT_CHECK_RESULT bool
65 operator!=(ConvertibleLuid const &lhs, ConvertibleLuid const &rhs)
66 {
67 return !(lhs == rhs);
68 }
69 friend XRT_CHECK_RESULT bool
70 operator<(ConvertibleLuid const &lhs, ConvertibleLuid const &rhs)
71 {
72 return lhs.t < rhs.t;
73 }
74
75 //! The actual high, low pair describing the LUID.
76 std::pair<DWORD, LONG> t;
77
78 static xrt_luid_t
79 toMonadoLuid(LUID luid)
80 {
81 xrt_luid_t ret{};
82 std::memcpy(&ret, &luid, sizeof(xrt_luid_t));
83 return ret;
84 }
85 static LUID
86 fromMonadoLuid(xrt_luid_t luid)
87 {
88 LUID ret{};
89 std::memcpy(&ret, &luid, sizeof(xrt_luid_t));
90 return ret;
91 }
92};
93
94} // namespace xrt::auxiliary::d3d
struct xrt_luid xrt_luid_t
Typedef for xrt_luid.
Definition xrt_defines.h:72
Wrapper/interchange type for LUIDs, which identify display adapters on Windows.
Definition d3d_convertible_luid.hpp:28
ConvertibleLuid(::winrt::Windows::Graphics::DisplayAdapterId const &id)
Construct from a WinRT LUID (Windows.Graphics.DisplayAdapterId)
Definition d3d_convertible_luid.hpp:33
std::pair< DWORD, LONG > t
The actual high, low pair describing the LUID.
Definition d3d_convertible_luid.hpp:76
ConvertibleLuid(LUID const &luid)
Construct from a Windows LUID.
Definition d3d_convertible_luid.hpp:30
ConvertibleLuid(const xrt_luid_t &luid)
Construct from a Monado LUID.
Definition d3d_convertible_luid.hpp:36
To transport LUIDs between different APIs.
Definition xrt_defines.h:63
Header holding common defines.
Common defines and enums for XRT.
A minimal way to include Windows.h.