Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDR Support #112

Merged
merged 12 commits into from
Jan 5, 2025
Prev Previous commit
Next Next commit
edid debug
UjinT34 committed Dec 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit ec0b4f9897f68b0f6f52a533447324a69564da00
27 changes: 27 additions & 0 deletions src/backend/drm/DRM.cpp
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@
#include <aquamarine/backend/drm/Atomic.hpp>
#include <aquamarine/allocator/GBM.hpp>
#include <aquamarine/allocator/DRMDumb.hpp>
#include <cstdint>
#include <format>
#include <hyprutils/string/VarList.hpp>
#include <chrono>
#include <thread>
@@ -1168,7 +1170,17 @@ drmModeModeInfo* Aquamarine::SDRMConnector::getCurrentMode() {
return modeInfo;
}

std::string vectorTostring(const std::vector<uint8_t>& vec) {
std::stringstream result;
for (const auto& v : vec) {
result << std::setfill('0') << std::setw(sizeof(v) * 2) << std::hex << +v;
result << " ";
}
return result.str();
}

IOutput::SParsedEDID Aquamarine::SDRMConnector::parseEDID(std::vector<uint8_t> data) {
TRACE(backend->backend->log(AQ_LOG_TRACE, std::format("EDID: parsing {} bytes: {}", data.size(), vectorTostring(data))));
auto info = di_info_parse_edid(data.data(), data.size());
IOutput::SParsedEDID parsed = {};
if (!info) {
@@ -1202,17 +1214,29 @@ IOutput::SParsedEDID Aquamarine::SDRMConnector::parseEDID(std::vector<uint8_t> d
IOutput::xy{chromaticity->blue_x, chromaticity->blue_y},
IOutput::xy{chromaticity->white_x, chromaticity->white_y},
};
TRACE(backend->backend->log(AQ_LOG_TRACE,
std::format("EDID: chromaticity coords {},{} {},{} {},{} {},{}", parsed.chromaticityCoords->red.x, parsed.chromaticityCoords->red.y,
parsed.chromaticityCoords->green.x, parsed.chromaticityCoords->green.y, parsed.chromaticityCoords->blue.x,
parsed.chromaticityCoords->blue.y, parsed.chromaticityCoords->white.y, parsed.chromaticityCoords->white.y)));
}

auto exts = di_edid_get_extensions(edid);

for (; *exts != nullptr; exts++) {
auto tag = di_edid_ext_get_tag(*exts);
TRACE(backend->backend->log(AQ_LOG_TRACE, std::format("EDID: checking ext {}", (uint32_t)tag)));
if (tag == DI_EDID_EXT_DISPLAYID)
backend->backend->log(AQ_LOG_WARNING, "FIXME: support displayid blocks");

const auto cta = di_edid_ext_get_cta(*exts);
if (cta) {
TRACE(backend->backend->log(AQ_LOG_TRACE, "EDID: found CTA"));
const di_cta_hdr_static_metadata_block* hdr_static_metadata = nullptr;
const di_cta_colorimetry_block* colorimetry = nullptr;
auto blocks = di_edid_cta_get_data_blocks(cta);
for (; *blocks != nullptr; blocks++) {
if (!hdr_static_metadata && (hdr_static_metadata = di_cta_data_block_get_hdr_static_metadata(*blocks))) {
TRACE(backend->backend->log(AQ_LOG_TRACE, std::format("EDID: found HDR {}", hdr_static_metadata->eotfs->pq)));
parsed.hdrMetadata = IOutput::SHDRMetadata{
.desiredContentMaxLuminance = hdr_static_metadata->desired_content_max_luminance,
.desiredMaxFrameAverageLuminance = hdr_static_metadata->desired_content_max_frame_avg_luminance,
@@ -1222,6 +1246,7 @@ IOutput::SParsedEDID Aquamarine::SDRMConnector::parseEDID(std::vector<uint8_t> d
continue;
}
if (!colorimetry && (colorimetry = di_cta_data_block_get_colorimetry(*blocks))) {
TRACE(backend->backend->log(AQ_LOG_TRACE, std::format("EDID: found colorimetry {}", colorimetry->bt2020_rgb)));
parsed.supportsBT2020 = colorimetry->bt2020_rgb;
continue;
}
@@ -1232,6 +1257,8 @@ IOutput::SParsedEDID Aquamarine::SDRMConnector::parseEDID(std::vector<uint8_t> d

di_info_destroy(info);

TRACE(backend->backend->log(AQ_LOG_TRACE, "EDID: parsed"));

return parsed;
}