Skip to content

Commit

Permalink
thanks ikalco
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski authored and DawfukFR committed Jul 14, 2024
1 parent 9f2822c commit d8ecf69
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 68 deletions.
20 changes: 2 additions & 18 deletions src/protocols/LinuxDMABUF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,25 +393,9 @@ CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const
mainDevice = *dev;

// FIXME: this will break on multi-gpu
std::vector<Aquamarine::SDRMFormat> 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<Aquamarine::SDRMFormat> aqFormats = g_pHyprOpenGL->getDRMFormats();

//
SDMABufTranche tranche = {
.device = *dev,
.formats = aqFormats,
Expand Down
18 changes: 1 addition & 17 deletions src/render/OpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2719,23 +2719,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<SDRMFormat> CHyprOpenGLImpl::getDRMFormats() {
Expand Down
66 changes: 33 additions & 33 deletions src/render/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::vector<std::pair<std::string, uint32_t>>, 2> formats{
std::vector<std::pair<std::string, uint32_t>>{ /* 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<std::pair<std::string, uint32_t>>{ /* 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;
Expand All @@ -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;

Expand Down Expand Up @@ -2228,37 +2259,6 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR
}
}

// clang-format off
static const std::array<std::vector<std::pair<std::string, uint32_t>>, 2> formats{
std::vector<std::pair<std::string, uint32_t>>{ /* 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<std::pair<std::string, uint32_t>>{ /* 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())
Expand Down

0 comments on commit d8ecf69

Please sign in to comment.