mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-22 21:25:58 +01:00
parent
8440a30231
commit
9c09f2a847
7 changed files with 37 additions and 30 deletions
|
@ -781,4 +781,14 @@ uint32_t drmFormatToGL(uint32_t drm) {
|
|||
}
|
||||
UNREACHABLE();
|
||||
return GL_RGBA;
|
||||
}
|
||||
|
||||
uint32_t glFormatToType(uint32_t gl) {
|
||||
return gl != GL_RGBA ?
|
||||
#ifdef GLES2
|
||||
GL_UNSIGNED_INT_2_10_10_10_REV_EXT :
|
||||
#else
|
||||
GL_UNSIGNED_INT_2_10_10_10_REV :
|
||||
#endif
|
||||
GL_UNSIGNED_BYTE;
|
||||
}
|
|
@ -34,6 +34,7 @@ std::string replaceInString(std::string subject, const std:
|
|||
std::vector<SCallstackFrameInfo> getBacktrace();
|
||||
void throwError(const std::string& err);
|
||||
uint32_t drmFormatToGL(uint32_t drm);
|
||||
uint32_t glFormatToType(uint32_t gl);
|
||||
|
||||
template <typename... Args>
|
||||
[[deprecated("use std::format instead")]] std::string getFormat(std::format_string<Args...> fmt, Args&&... args) {
|
||||
|
|
|
@ -210,7 +210,7 @@ void CScreencopyProtocolManager::captureOutput(wl_client* client, wl_resource* r
|
|||
PFRAME->client = PCLIENT;
|
||||
PCLIENT->ref++;
|
||||
|
||||
PFRAME->shmFormat = g_pHyprRenderer->isNvidia() ? DRM_FORMAT_XRGB8888 : PFRAME->pMonitor->drmFormat;
|
||||
PFRAME->shmFormat = g_pHyprOpenGL->getPreferredReadFormat(PFRAME->pMonitor);
|
||||
if (PFRAME->shmFormat == DRM_FORMAT_INVALID) {
|
||||
Debug::log(ERR, "No format supported by renderer in capture output");
|
||||
zwlr_screencopy_frame_v1_send_failed(PFRAME->resource);
|
||||
|
@ -441,7 +441,7 @@ bool CScreencopyProtocolManager::copyFrameShm(SScreencopyFrame* frame, timespec*
|
|||
g_pHyprRenderer->makeEGLCurrent();
|
||||
|
||||
CFramebuffer fb;
|
||||
fb.alloc(frame->box.w, frame->box.h); // 8bit only
|
||||
fb.alloc(frame->box.w, frame->box.h, frame->pMonitor->drmFormat);
|
||||
|
||||
if (!g_pHyprRenderer->beginRender(frame->pMonitor, fakeDamage, RENDER_MODE_FULL_FAKE, nullptr, &fb)) {
|
||||
wlr_texture_destroy(sourceTex);
|
||||
|
@ -456,13 +456,8 @@ bool CScreencopyProtocolManager::copyFrameShm(SScreencopyFrame* frame, timespec*
|
|||
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, fb.m_iFb);
|
||||
|
||||
const auto PFORMAT = gles2FromDRM(format);
|
||||
if (!PFORMAT) {
|
||||
Debug::log(ERR, "[sc] Cannot read pixels, unsupported format {:x}", (uintptr_t)PFORMAT);
|
||||
wlr_texture_destroy(sourceTex);
|
||||
wlr_buffer_end_data_ptr_access(frame->buffer);
|
||||
return false;
|
||||
}
|
||||
const auto GLFORMAT = drmFormatToGL(frame->pMonitor->drmFormat);
|
||||
const auto GLTYPE = glFormatToType(GLFORMAT);
|
||||
|
||||
g_pHyprRenderer->endRender();
|
||||
|
||||
|
@ -470,7 +465,7 @@ bool CScreencopyProtocolManager::copyFrameShm(SScreencopyFrame* frame, timespec*
|
|||
g_pHyprOpenGL->m_RenderData.pMonitor = frame->pMonitor;
|
||||
fb.bind();
|
||||
|
||||
glReadPixels(0, 0, frame->box.w, frame->box.h, PFORMAT->gl_format, PFORMAT->gl_type, data);
|
||||
glReadPixels(0, 0, frame->box.w, frame->box.h, GL_RGBA, GLTYPE, data);
|
||||
|
||||
g_pHyprOpenGL->m_RenderData.pMonitor = nullptr;
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ void CToplevelExportProtocolManager::captureToplevel(wl_client* client, wl_resou
|
|||
|
||||
const auto PMONITOR = g_pCompositor->getMonitorFromID(PFRAME->pWindow->m_iMonitorID);
|
||||
|
||||
PFRAME->shmFormat = g_pHyprRenderer->isNvidia() ? DRM_FORMAT_XRGB8888 : PMONITOR->drmFormat;
|
||||
PFRAME->shmFormat = g_pHyprOpenGL->getPreferredReadFormat(PFRAME->pMonitor);
|
||||
if (PFRAME->shmFormat == DRM_FORMAT_INVALID) {
|
||||
Debug::log(ERR, "No format supported by renderer in capture toplevel");
|
||||
hyprland_toplevel_export_frame_v1_send_failed(resource);
|
||||
|
@ -366,7 +366,7 @@ bool CToplevelExportProtocolManager::copyFrameShm(SScreencopyFrame* frame, times
|
|||
g_pHyprRenderer->makeEGLCurrent();
|
||||
|
||||
CFramebuffer outFB;
|
||||
outFB.alloc(PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y);
|
||||
outFB.alloc(PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y, PMONITOR->drmFormat);
|
||||
|
||||
if (!g_pHyprRenderer->beginRender(PMONITOR, fakeDamage, RENDER_MODE_FULL_FAKE, nullptr, &outFB)) {
|
||||
wlr_buffer_end_data_ptr_access(frame->buffer);
|
||||
|
@ -386,20 +386,12 @@ bool CToplevelExportProtocolManager::copyFrameShm(SScreencopyFrame* frame, times
|
|||
if (frame->overlayCursor)
|
||||
g_pHyprRenderer->renderSoftwareCursors(PMONITOR, fakeDamage, g_pInputManager->getMouseCoordsInternal() - frame->pWindow->m_vRealPosition.vec());
|
||||
|
||||
// copy pixels
|
||||
const auto PFORMAT = gles2FromDRM(format);
|
||||
if (!PFORMAT) {
|
||||
Debug::log(ERR, "[toplevel_export] Cannot read pixels, unsupported format {:x}", (uintptr_t)PFORMAT);
|
||||
g_pHyprRenderer->endRender();
|
||||
wlr_buffer_end_data_ptr_access(frame->buffer);
|
||||
if (frame->overlayCursor)
|
||||
wlr_output_lock_software_cursors(PMONITOR->output, false);
|
||||
return false;
|
||||
}
|
||||
const auto GLFORMAT = drmFormatToGL(frame->pMonitor->drmFormat);
|
||||
const auto GLTYPE = glFormatToType(GLFORMAT);
|
||||
|
||||
g_pHyprOpenGL->m_RenderData.mainFB->bind();
|
||||
|
||||
glReadPixels(0, 0, frame->box.width, frame->box.height, PFORMAT->gl_format, PFORMAT->gl_type, data);
|
||||
glReadPixels(0, 0, frame->box.width, frame->box.height, GL_RGBA, GLTYPE, data);
|
||||
|
||||
g_pHyprRenderer->endRender();
|
||||
|
||||
|
|
|
@ -6,13 +6,7 @@ bool CFramebuffer::alloc(int w, int h, uint32_t drmFormat) {
|
|||
RASSERT((w > 1 && h > 1), "cannot alloc a FB with negative / zero size! (attempted {}x{})", w, h);
|
||||
|
||||
uint32_t glFormat = drmFormatToGL(drmFormat);
|
||||
uint32_t glType = glFormat != GL_RGBA ?
|
||||
#ifdef GLES2
|
||||
GL_UNSIGNED_INT_2_10_10_10_REV_EXT :
|
||||
#else
|
||||
GL_UNSIGNED_INT_2_10_10_10_REV :
|
||||
#endif
|
||||
GL_UNSIGNED_BYTE;
|
||||
uint32_t glType = glFormatToType(glFormat);
|
||||
|
||||
if (m_iFb == (uint32_t)-1) {
|
||||
firstAlloc = true;
|
||||
|
|
|
@ -2064,3 +2064,16 @@ void CHyprOpenGLImpl::bindBackOnMain() {
|
|||
void CHyprOpenGLImpl::setMonitorTransformEnabled(bool enabled) {
|
||||
m_bEndFrame = !enabled;
|
||||
}
|
||||
|
||||
uint32_t CHyprOpenGLImpl::getPreferredReadFormat(CMonitor* pMonitor) {
|
||||
if (g_pHyprRenderer->isNvidia())
|
||||
return DRM_FORMAT_XRGB8888;
|
||||
|
||||
if (pMonitor->drmFormat == DRM_FORMAT_XRGB8888)
|
||||
return DRM_FORMAT_XRGB8888;
|
||||
if (pMonitor->drmFormat == DRM_FORMAT_XBGR8888)
|
||||
return DRM_FORMAT_XBGR8888;
|
||||
if (pMonitor->drmFormat == DRM_FORMAT_XRGB2101010 || pMonitor->drmFormat == DRM_FORMAT_XBGR2101010)
|
||||
return DRM_FORMAT_XBGR2101010;
|
||||
return DRM_FORMAT_INVALID;
|
||||
}
|
||||
|
|
|
@ -158,6 +158,8 @@ class CHyprOpenGLImpl {
|
|||
void renderOffToMain(CFramebuffer* off);
|
||||
void bindBackOnMain();
|
||||
|
||||
uint32_t getPreferredReadFormat(CMonitor* pMonitor);
|
||||
|
||||
SCurrentRenderData m_RenderData;
|
||||
|
||||
GLint m_iCurrentOutputFb = 0;
|
||||
|
|
Loading…
Reference in a new issue