screencopy: use wlr_buffer api for shm copies

This commit is contained in:
vaxerski 2023-07-19 12:24:41 +02:00
parent 81f4a4f471
commit b8a7b09092

View file

@ -421,40 +421,16 @@ bool CScreencopyProtocolManager::copyFrameShm(SScreencopyFrame* frame, timespec*
// render the client // render the client
const auto PMONITOR = frame->pMonitor; const auto PMONITOR = frame->pMonitor;
if (!wlr_output_attach_render(PMONITOR->output, nullptr)) { if (!wlr_renderer_begin_with_buffer(g_pCompositor->m_sWLRRenderer, m_pLastMonitorBackBuffer)) {
Debug::log(ERR, "[screencopy] Couldn't attach render");
wlr_buffer_end_data_ptr_access(frame->buffer); wlr_buffer_end_data_ptr_access(frame->buffer);
return false; return false;
} }
const auto PFORMAT = get_gles2_format_from_drm(format); bool success = wlr_renderer_read_pixels(g_pCompositor->m_sWLRRenderer, format, stride, frame->box.width, frame->box.height, frame->box.x, frame->box.y, 0, 0, data);
if (!PFORMAT) { wlr_renderer_end(g_pCompositor->m_sWLRRenderer);
Debug::log(ERR, "[screencopy] Cannot read pixels, unsupported format %lx", PFORMAT);
wlr_output_rollback(PMONITOR->output);
wlr_buffer_end_data_ptr_access(frame->buffer);
return false;
}
g_pHyprOpenGL->begin(PMONITOR, &PMONITOR->lastFrameDamage, true);
// we should still have the last frame by this point in the original fb
glBindFramebuffer(GL_FRAMEBUFFER, g_pHyprOpenGL->m_RenderData.pCurrentMonData->primaryFB.m_iFb);
glFinish(); // flush
glReadPixels(frame->box.x, frame->box.y, frame->box.width, frame->box.height, PFORMAT->gl_format, PFORMAT->gl_type, data);
glBindFramebuffer(GL_FRAMEBUFFER, g_pHyprOpenGL->m_iWLROutputFb);
g_pHyprOpenGL->end();
wlr_output_rollback(PMONITOR->output);
pixman_region32_fini(&PMONITOR->lastFrameDamage);
wlr_buffer_end_data_ptr_access(frame->buffer); wlr_buffer_end_data_ptr_access(frame->buffer);
return true; return success;
} }
bool CScreencopyProtocolManager::copyFrameDmabuf(SScreencopyFrame* frame) { bool CScreencopyProtocolManager::copyFrameDmabuf(SScreencopyFrame* frame) {