From c46c55e2cd341eda3f1b5a5b972e0385a46d4c18 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 7 Oct 2024 19:34:12 +0100 Subject: [PATCH] better fns --- src/backend/drm/impl/Atomic.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/backend/drm/impl/Atomic.cpp b/src/backend/drm/impl/Atomic.cpp index da5ec55..b031076 100644 --- a/src/backend/drm/impl/Atomic.cpp +++ b/src/backend/drm/impl/Atomic.cpp @@ -272,10 +272,16 @@ bool Aquamarine::CDRMAtomicImpl::prepareConnector(Hyprutils::Memory::CSharedPoin if (!connector->crtc->props.ctm) connector->backend->backend->log(AQ_LOG_ERROR, "atomic drm: failed to commit ctm: no ctm prop support"); else { + static auto doubleToS3132Fixed = [](const double val) -> uint64_t { + const uint64_t result = std::abs(val) * (1ULL << 32); + if (val < 0) + return result | 1ULL << 63; + return result; + }; + drm_color_ctm ctm = {0}; for (size_t i = 0; i < 9; ++i) { - const double val = data.ctm->getMatrix()[i]; - ctm.matrix[i] = static_cast(val * std::pow(2, 32)); + ctm.matrix[i] = doubleToS3132Fixed(data.ctm->getMatrix()[i]); } if (drmModeCreatePropertyBlob(connector->backend->gpu->fd, &ctm, sizeof(drm_color_ctm), &data.atomic.ctmBlob)) {