Skip to content

Commit

Permalink
expose edid hdr info
Browse files Browse the repository at this point in the history
  • Loading branch information
UjinT34 committed Dec 5, 2024
1 parent d39cdfe commit 9824f1e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 32 deletions.
17 changes: 1 addition & 16 deletions include/aquamarine/backend/DRM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,6 @@ namespace Aquamarine {
void calculateMode(Hyprutils::Memory::CSharedPointer<SDRMConnector> connector);
};

struct HDRMetadata {
bool supported = false;
double desiredContentMinLuminance;
std::optional<double> desiredContentMaxLuminance;
std::optional<double> desiredMaxFrameAverageLuminance;
bool supportsPQ;
bool supportsBT2020;
};

struct ParsedEDID {
std::string make, serial, model;
HDRMetadata hdrMetadata = {};
};

struct SDRMConnector {
~SDRMConnector();

Expand All @@ -287,7 +273,7 @@ namespace Aquamarine {
void disconnect();
Hyprutils::Memory::CSharedPointer<SDRMCRTC> getCurrentCRTC(const drmModeConnector* connector);
drmModeModeInfo* getCurrentMode();
ParsedEDID parseEDID(std::vector<uint8_t> data);
IOutput::ParsedEDID parseEDID(std::vector<uint8_t> data);
bool commitState(SDRMConnectorCommitData& data);
void applyCommit(const SDRMConnectorCommitData& data);
void rollbackCommit(const SDRMConnectorCommitData& data);
Expand All @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions include/aquamarine/output/Output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,33 @@ namespace Aquamarine {
AQ_SCHEDULE_ANIMATION_DAMAGE,
};

struct HDRMetadata {
bool supported = false;
double desiredContentMinLuminance;
std::optional<double> desiredContentMaxLuminance;
std::optional<double> 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> hdrMetadata;
std::optional<ChromaticityCoords> chromaticityCoords;
};

virtual bool commit() = 0;
virtual bool test() = 0;
virtual Hyprutils::Memory::CSharedPointer<IBackendImplementation> getBackend() = 0;
Expand All @@ -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;
Expand Down
34 changes: 18 additions & 16 deletions src/backend/drm/DRM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1150,9 +1150,9 @@ drmModeModeInfo* Aquamarine::SDRMConnector::getCurrentMode() {
return modeInfo;
}

ParsedEDID Aquamarine::SDRMConnector::parseEDID(std::vector<uint8_t> data) {
auto info = di_info_parse_edid(data.data(), data.size());
ParsedEDID parsed = {};
IOutput::ParsedEDID Aquamarine::SDRMConnector::parseEDID(std::vector<uint8_t> 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;
Expand All @@ -1177,17 +1177,17 @@ ParsedEDID Aquamarine::SDRMConnector::parseEDID(std::vector<uint8_t> 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;
Expand All @@ -1208,8 +1208,7 @@ ParsedEDID Aquamarine::SDRMConnector::parseEDID(std::vector<uint8_t> 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,
Expand All @@ -1219,6 +1218,8 @@ ParsedEDID Aquamarine::SDRMConnector::parseEDID(std::vector<uint8_t> data) {
.supportsPQ = hdr_static_metadata->eotfs->pq,
.supportsBT2020 = colorimetry && colorimetry->bt2020_rgb,
};
} else {
parsed.hdrMetadata.reset();
}
}

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 9824f1e

Please sign in to comment.