From 9824f1e2c714d20a3cc37b7481edf14cd21e85d6 Mon Sep 17 00:00:00 2001 From: UjinT34 Date: Thu, 5 Dec 2024 20:52:15 +0300 Subject: [PATCH] expose edid hdr info --- include/aquamarine/backend/DRM.hpp | 17 +------------- include/aquamarine/output/Output.hpp | 28 +++++++++++++++++++++++ src/backend/drm/DRM.cpp | 34 +++++++++++++++------------- 3 files changed, 47 insertions(+), 32 deletions(-) diff --git a/include/aquamarine/backend/DRM.hpp b/include/aquamarine/backend/DRM.hpp index e942463..e3e72e7 100644 --- a/include/aquamarine/backend/DRM.hpp +++ b/include/aquamarine/backend/DRM.hpp @@ -265,20 +265,6 @@ namespace Aquamarine { void calculateMode(Hyprutils::Memory::CSharedPointer connector); }; - struct HDRMetadata { - bool supported = false; - double desiredContentMinLuminance; - std::optional desiredContentMaxLuminance; - std::optional desiredMaxFrameAverageLuminance; - bool supportsPQ; - bool supportsBT2020; - }; - - struct ParsedEDID { - std::string make, serial, model; - HDRMetadata hdrMetadata = {}; - }; - struct SDRMConnector { ~SDRMConnector(); @@ -287,7 +273,7 @@ namespace Aquamarine { void disconnect(); Hyprutils::Memory::CSharedPointer getCurrentCRTC(const drmModeConnector* connector); drmModeModeInfo* getCurrentMode(); - ParsedEDID parseEDID(std::vector data); + IOutput::ParsedEDID parseEDID(std::vector data); bool commitState(SDRMConnectorCommitData& data); void applyCommit(const SDRMConnectorCommitData& data); void rollbackCommit(const SDRMConnectorCommitData& data); @@ -305,7 +291,6 @@ namespace Aquamarine { int32_t refresh = 0; uint32_t possibleCrtcs = 0; std::string make, serial, model; - HDRMetadata hdrMetadata; bool canDoVrr = false; bool cursorEnabled = false; diff --git a/include/aquamarine/output/Output.hpp b/include/aquamarine/output/Output.hpp index 5895758..9ba10a1 100644 --- a/include/aquamarine/output/Output.hpp +++ b/include/aquamarine/output/Output.hpp @@ -124,6 +124,33 @@ namespace Aquamarine { AQ_SCHEDULE_ANIMATION_DAMAGE, }; + struct HDRMetadata { + bool supported = false; + double desiredContentMinLuminance; + std::optional desiredContentMaxLuminance; + std::optional desiredMaxFrameAverageLuminance; + bool supportsPQ; + bool supportsBT2020; + }; + + struct xy { + double x = 0; + double y = 0; + }; + + struct ChromaticityCoords { + xy red; + xy green; + xy blue; + xy white; + }; + + struct ParsedEDID { + std::string make, serial, model; + std::optional hdrMetadata; + std::optional chromaticityCoords; + }; + virtual bool commit() = 0; virtual bool test() = 0; virtual Hyprutils::Memory::CSharedPointer getBackend() = 0; @@ -138,6 +165,7 @@ namespace Aquamarine { virtual bool destroy(); // not all backends allow this!!! std::string name, description, make, model, serial; + ParsedEDID parsedEDID; Hyprutils::Math::Vector2D physicalSize; bool enabled = false; bool nonDesktop = false; diff --git a/src/backend/drm/DRM.cpp b/src/backend/drm/DRM.cpp index 5b77723..c482461 100644 --- a/src/backend/drm/DRM.cpp +++ b/src/backend/drm/DRM.cpp @@ -1150,9 +1150,9 @@ drmModeModeInfo* Aquamarine::SDRMConnector::getCurrentMode() { return modeInfo; } -ParsedEDID Aquamarine::SDRMConnector::parseEDID(std::vector data) { - auto info = di_info_parse_edid(data.data(), data.size()); - ParsedEDID parsed = {}; +IOutput::ParsedEDID Aquamarine::SDRMConnector::parseEDID(std::vector data) { + auto info = di_info_parse_edid(data.data(), data.size()); + IOutput::ParsedEDID parsed = {}; if (!info) { backend->backend->log(AQ_LOG_ERROR, "drm: failed to parse edid"); return parsed; @@ -1177,17 +1177,17 @@ ParsedEDID Aquamarine::SDRMConnector::parseEDID(std::vector data) { parsed.serial = serial; // copied from kwin - // const auto chromaticity = di_edid_get_chromaticity_coords(edid); - // if (chromaticity) { - // m_colorimetry = Colorimetry{ - // xy{chromaticity->red_x, chromaticity->red_y}, - // xy{chromaticity->green_x, chromaticity->green_y}, - // xy{chromaticity->blue_x, chromaticity->blue_y}, - // xy{chromaticity->white_x, chromaticity->white_y}, - // }; - // } else { - // m_colorimetry.reset(); - // } + const auto chromaticity = di_edid_get_chromaticity_coords(edid); + if (chromaticity) { + parsed.chromaticityCoords = IOutput::ChromaticityCoords{ + IOutput::xy{chromaticity->red_x, chromaticity->red_y}, + IOutput::xy{chromaticity->green_x, chromaticity->green_y}, + IOutput::xy{chromaticity->blue_x, chromaticity->blue_y}, + IOutput::xy{chromaticity->white_x, chromaticity->white_y}, + }; + } else { + parsed.chromaticityCoords.reset(); + } const di_edid_cta* cta = nullptr; const di_edid_ext* const* exts = di_edid_get_extensions(edid); const di_cta_hdr_static_metadata_block* hdr_static_metadata = nullptr; @@ -1208,8 +1208,7 @@ ParsedEDID Aquamarine::SDRMConnector::parseEDID(std::vector data) { } } if (hdr_static_metadata) { - hdrMetadata = parsed.hdrMetadata = HDRMetadata{ - .supported = true, + parsed.hdrMetadata = IOutput::HDRMetadata{ .desiredContentMinLuminance = hdr_static_metadata->desired_content_min_luminance, .desiredContentMaxLuminance = hdr_static_metadata->desired_content_max_luminance > 0 ? std::make_optional(hdr_static_metadata->desired_content_max_luminance) : std::nullopt, @@ -1219,6 +1218,8 @@ ParsedEDID Aquamarine::SDRMConnector::parseEDID(std::vector data) { .supportsPQ = hdr_static_metadata->eotfs->pq, .supportsBT2020 = colorimetry && colorimetry->bt2020_rgb, }; + } else { + parsed.hdrMetadata.reset(); } } @@ -1341,6 +1342,7 @@ void Aquamarine::SDRMConnector::connect(drmModeConnector* connector) { output->make = parsedEDID.make; output->model = parsedEDID.model; output->serial = parsedEDID.serial; + output->parsedEDID = parsedEDID; output->description = std::format("{} {} {} ({})", make, model, serial, szName); output->needsFrame = true;