Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
hermes_kms_color.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <cstddef>
8#include <cstdint>
9#include <cstring>
10
11namespace VDISPLAY::hermes_kms {
12 constexpr std::uint64_t cap_frame_color = 1ULL << 18;
13 constexpr std::uint32_t color_valid = 1U << 0;
14 constexpr std::uint32_t color_hdr_valid = 1U << 1;
15 constexpr std::uint32_t color_rgb_full_range = 1U << 2;
16 constexpr std::uint32_t colorspace_default = 0;
17 constexpr std::uint32_t colorspace_bt2020_rgb = 9;
18
19 // Fixed-width mirror of drm_hermes_kms_frame_color. Explicit padding keeps
20 // the native/compat ABI identical without depending on installed KMS headers.
21 struct color_t {
22 std::uint32_t flags {};
23 std::uint32_t colorspace {};
24 std::uint32_t metadata_type {};
25 std::uint8_t eotf {};
26 std::uint8_t descriptor_type {};
27
28 struct xy_t {
29 std::uint16_t x {}, y {};
30 } primaries[3], white_point;
31
32 std::uint16_t max_luminance {};
33 std::uint16_t min_luminance {};
34 std::uint16_t max_cll {};
35 std::uint16_t max_fall {};
36 std::uint16_t padding {};
37 std::uint32_t reserved[2] {};
38
39 bool known() const {
40 return flags & color_valid;
41 }
42
43 bool pq() const {
44 return known() && (flags & color_hdr_valid) && eotf == 2 &&
45 colorspace == colorspace_bt2020_rgb;
46 }
47
48 bool supported() const {
49 if (!known() || (flags & ~(color_valid | color_hdr_valid | color_rgb_full_range)) || !(flags & color_rgb_full_range) || padding || reserved[0] || reserved[1]) {
50 return false;
51 }
52 if (colorspace != colorspace_default && colorspace != colorspace_bt2020_rgb) {
53 return false;
54 }
55 if (!(flags & color_hdr_valid)) {
56 const color_t zero {};
57 return std::memcmp(&metadata_type, &zero.metadata_type, offsetof(color_t, reserved) - offsetof(color_t, metadata_type)) == 0;
58 }
59 return metadata_type == 0 && descriptor_type == 0 &&
60 (eotf == 0 || (eotf == 2 && colorspace == colorspace_bt2020_rgb));
61 }
62
63 bool operator==(const color_t &other) const {
64 return std::memcmp(this, &other, sizeof(*this)) == 0;
65 }
66
67 template<class Metadata>
68 bool copy_hdr_metadata(Metadata &out) const {
69 out = {};
70 if (!supported() || !pq()) {
71 return false;
72 }
73 for (int i = 0; i < 3; ++i) {
74 out.displayPrimaries[i].x = primaries[i].x;
75 out.displayPrimaries[i].y = primaries[i].y;
76 }
77 out.whitePoint.x = white_point.x;
78 out.whitePoint.y = white_point.y;
79 out.maxDisplayLuminance = max_luminance;
80 out.minDisplayLuminance = min_luminance;
81 out.maxContentLightLevel = max_cll;
82 out.maxFrameAverageLightLevel = max_fall;
83 return true;
84 }
85 };
86
87 static_assert(sizeof(color_t) == 48);
88 static_assert(offsetof(color_t, metadata_type) == 8);
89 static_assert(offsetof(color_t, reserved) == 40);
90} // namespace VDISPLAY::hermes_kms