From af4a13452bc4046e2ad64abbc9ae3447192dbbf2 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 13 Jul 2024 12:30:16 +0200 Subject: [PATCH] thanks ikalco --- src/protocols/LinuxDMABUF.cpp | 20 ++--------- src/render/OpenGL.cpp | 18 +--------- src/render/Renderer.cpp | 66 +++++++++++++++++------------------ 3 files changed, 36 insertions(+), 68 deletions(-) diff --git a/src/protocols/LinuxDMABUF.cpp b/src/protocols/LinuxDMABUF.cpp index 862fb4d7..1b4391a6 100644 --- a/src/protocols/LinuxDMABUF.cpp +++ b/src/protocols/LinuxDMABUF.cpp @@ -393,25 +393,9 @@ CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const mainDevice = *dev; // FIXME: this will break on multi-gpu - std::vector aqFormats; - for (auto& impl : g_pCompositor->m_pAqBackend->getImplementations()) { - if (impl->type() != Aquamarine::AQ_BACKEND_DRM) - continue; - aqFormats = impl->getRenderFormats(); - if (!aqFormats.empty()) - break; - } - - if (aqFormats.empty()) { - // fallback: use EGL formats - for (auto& fmt : g_pHyprOpenGL->getDRMFormats()) { - aqFormats.emplace_back(Aquamarine::SDRMFormat{ - .drmFormat = fmt.drmFormat, - .modifiers = fmt.modifiers, - }); - } - } + std::vector aqFormats = g_pHyprOpenGL->getDRMFormats(); + // SDMABufTranche tranche = { .device = *dev, .formats = aqFormats, diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 5326442d..be449dfe 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -2721,23 +2721,7 @@ void CHyprOpenGLImpl::setRenderModifEnabled(bool enabled) { } uint32_t CHyprOpenGLImpl::getPreferredReadFormat(CMonitor* pMonitor) { - GLint glf = -1, glt = -1, as = 0; - /*glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &glf); - glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &glt); - glGetIntegerv(GL_ALPHA_BITS, &as);*/ - - if (glf == 0 || glt == 0) { - glf = FormatUtils::drmFormatToGL(pMonitor->drmFormat); - glt = FormatUtils::glFormatToType(glf); - } - - if (const auto FMT = FormatUtils::getPixelFormatFromGL(glf, glt, as > 0); FMT) - return FMT->drmFormat; - - if (m_sExts.EXT_read_format_bgra) - return DRM_FORMAT_XRGB8888; - - return DRM_FORMAT_XBGR8888; + return pMonitor->output->state->state().drmFormat; } std::vector CHyprOpenGLImpl::getDRMFormats() { diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 00c488e3..274813d6 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1943,7 +1943,39 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR // Needed in case we are switching from a custom modeline to a standard mode pMonitor->customDrmMode = {}; pMonitor->currentMode = nullptr; - bool autoScale = false; + + // clang-format off + static const std::array>, 2> formats{ + std::vector>{ /* 10-bit */ + {"DRM_FORMAT_XRGB2101010", DRM_FORMAT_XRGB2101010}, {"DRM_FORMAT_XBGR2101010", DRM_FORMAT_XBGR2101010}, {"DRM_FORMAT_XRGB8888", DRM_FORMAT_XRGB8888}, {"DRM_FORMAT_XBGR8888", DRM_FORMAT_XBGR8888}, {"DRM_FORMAT_INVALID", DRM_FORMAT_INVALID} + }, + std::vector>{ /* 8-bit */ + {"DRM_FORMAT_XRGB8888", DRM_FORMAT_XRGB8888}, {"DRM_FORMAT_XBGR8888", DRM_FORMAT_XBGR8888}, {"DRM_FORMAT_INVALID", DRM_FORMAT_INVALID} + } + }; + // clang-format on + + bool set10bit = false; + pMonitor->drmFormat = DRM_FORMAT_INVALID; + + for (auto& fmt : formats[(int)!RULE->enable10bit]) { + pMonitor->output->state->setFormat(fmt.second); + + if (!pMonitor->state.test()) { + Debug::log(ERR, "output {} failed basic test on format {}", pMonitor->szName, fmt.first); + } else { + Debug::log(LOG, "output {} succeeded basic test on format {}", pMonitor->szName, fmt.first); + if (RULE->enable10bit && fmt.first.contains("101010")) + set10bit = true; + + pMonitor->drmFormat = fmt.second; + break; + } + } + + pMonitor->enabled10bit = set10bit; + + bool autoScale = false; if (RULE->scale > 0.1) { pMonitor->scale = RULE->scale; @@ -1955,7 +1987,6 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR pMonitor->setScale = pMonitor->scale; pMonitor->transform = RULE->transform; - pMonitor->output->state->setFormat(DRM_FORMAT_XBGR8888); const auto WLRREFRESHRATE = pMonitor->output->getBackend()->type() == Aquamarine::eBackendType::AQ_BACKEND_DRM ? RULE->refreshRate * 1000 : 0; @@ -2228,37 +2259,6 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR } } - // clang-format off - static const std::array>, 2> formats{ - std::vector>{ /* 10-bit */ - {"DRM_FORMAT_XRGB2101010", DRM_FORMAT_XRGB2101010}, {"DRM_FORMAT_XBGR2101010", DRM_FORMAT_XBGR2101010}, {"DRM_FORMAT_XRGB8888", DRM_FORMAT_XRGB8888}, {"DRM_FORMAT_XBGR8888", DRM_FORMAT_XBGR8888}, {"DRM_FORMAT_INVALID", DRM_FORMAT_INVALID} - }, - std::vector>{ /* 8-bit */ - {"DRM_FORMAT_XRGB8888", DRM_FORMAT_XRGB8888}, {"DRM_FORMAT_XBGR8888", DRM_FORMAT_XBGR8888}, {"DRM_FORMAT_INVALID", DRM_FORMAT_INVALID} - } - }; - // clang-format on - - bool set10bit = false; - pMonitor->drmFormat = DRM_FORMAT_INVALID; - - for (auto& fmt : formats[(int)!RULE->enable10bit]) { - pMonitor->output->state->setFormat(fmt.second); - - if (!pMonitor->state.test()) { - Debug::log(ERR, "output {} failed basic test on format {}", pMonitor->szName, fmt.first); - } else { - Debug::log(LOG, "output {} succeeded basic test on format {}", pMonitor->szName, fmt.first); - if (RULE->enable10bit && fmt.first.contains("101010")) - set10bit = true; - - pMonitor->drmFormat = fmt.second; - break; - } - } - - pMonitor->enabled10bit = set10bit; - pMonitor->output->scheduleFrame(); if (!pMonitor->state.commit())