screencopy: improve shm handling

This commit is contained in:
vaxerski 2023-07-19 00:51:38 +02:00
parent 2623364dbd
commit 81f4a4f471
3 changed files with 8 additions and 17 deletions

View file

@ -326,15 +326,11 @@ void CScreencopyProtocolManager::copyFrame(wl_client* client, wl_resource* resou
void CScreencopyProtocolManager::onOutputCommit(CMonitor* pMonitor, wlr_output_event_commit* e) { void CScreencopyProtocolManager::onOutputCommit(CMonitor* pMonitor, wlr_output_event_commit* e) {
m_pLastMonitorBackBuffer = e->buffer; m_pLastMonitorBackBuffer = e->buffer;
shareAllFrames(pMonitor, true); shareAllFrames(pMonitor);
m_pLastMonitorBackBuffer = nullptr; m_pLastMonitorBackBuffer = nullptr;
} }
void CScreencopyProtocolManager::onRenderEnd(CMonitor* pMonitor) { void CScreencopyProtocolManager::shareAllFrames(CMonitor* pMonitor) {
shareAllFrames(pMonitor, false);
}
void CScreencopyProtocolManager::shareAllFrames(CMonitor* pMonitor, bool dmabuf) {
if (m_vFramesAwaitingWrite.empty()) if (m_vFramesAwaitingWrite.empty())
return; // nothing to share return; // nothing to share
@ -347,7 +343,7 @@ void CScreencopyProtocolManager::shareAllFrames(CMonitor* pMonitor, bool dmabuf)
continue; continue;
} }
if (f->pMonitor != pMonitor || dmabuf != (f->bufferCap == WLR_BUFFER_CAP_DMABUF)) if (f->pMonitor != pMonitor)
continue; continue;
shareFrame(f); shareFrame(f);
@ -424,12 +420,9 @@ bool CScreencopyProtocolManager::copyFrameShm(SScreencopyFrame* frame, timespec*
// render the client // render the client
const auto PMONITOR = frame->pMonitor; const auto PMONITOR = frame->pMonitor;
pixman_region32_t fakeDamage;
pixman_region32_init_rect(&fakeDamage, 0, 0, PMONITOR->vecPixelSize.x * 10, PMONITOR->vecPixelSize.y * 10);
if (!wlr_output_attach_render(PMONITOR->output, nullptr)) { if (!wlr_output_attach_render(PMONITOR->output, nullptr)) {
Debug::log(ERR, "[screencopy] Couldn't attach render"); Debug::log(ERR, "[screencopy] Couldn't attach render");
pixman_region32_fini(&fakeDamage);
wlr_buffer_end_data_ptr_access(frame->buffer); wlr_buffer_end_data_ptr_access(frame->buffer);
return false; return false;
} }
@ -438,12 +431,11 @@ bool CScreencopyProtocolManager::copyFrameShm(SScreencopyFrame* frame, timespec*
if (!PFORMAT) { if (!PFORMAT) {
Debug::log(ERR, "[screencopy] Cannot read pixels, unsupported format %lx", PFORMAT); Debug::log(ERR, "[screencopy] Cannot read pixels, unsupported format %lx", PFORMAT);
wlr_output_rollback(PMONITOR->output); wlr_output_rollback(PMONITOR->output);
pixman_region32_fini(&fakeDamage);
wlr_buffer_end_data_ptr_access(frame->buffer); wlr_buffer_end_data_ptr_access(frame->buffer);
return false; return false;
} }
g_pHyprOpenGL->begin(PMONITOR, &fakeDamage, true); g_pHyprOpenGL->begin(PMONITOR, &PMONITOR->lastFrameDamage, true);
// we should still have the last frame by this point in the original fb // 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); glBindFramebuffer(GL_FRAMEBUFFER, g_pHyprOpenGL->m_RenderData.pCurrentMonData->primaryFB.m_iFb);
@ -458,7 +450,7 @@ bool CScreencopyProtocolManager::copyFrameShm(SScreencopyFrame* frame, timespec*
wlr_output_rollback(PMONITOR->output); wlr_output_rollback(PMONITOR->output);
pixman_region32_fini(&fakeDamage); pixman_region32_fini(&PMONITOR->lastFrameDamage);
wlr_buffer_end_data_ptr_access(frame->buffer); wlr_buffer_end_data_ptr_access(frame->buffer);
@ -482,6 +474,7 @@ bool CScreencopyProtocolManager::copyFrameDmabuf(SScreencopyFrame* frame) {
float color[] = {0, 0, 0, 0}; float color[] = {0, 0, 0, 0};
wlr_renderer_clear(g_pCompositor->m_sWLRRenderer, color); wlr_renderer_clear(g_pCompositor->m_sWLRRenderer, color);
// TODO: use hl render methods to use damage
wlr_render_texture_with_matrix(g_pCompositor->m_sWLRRenderer, sourceTex, glMatrix, 1.0f); wlr_render_texture_with_matrix(g_pCompositor->m_sWLRRenderer, sourceTex, glMatrix, 1.0f);
wlr_texture_destroy(sourceTex); wlr_texture_destroy(sourceTex);

View file

@ -77,7 +77,6 @@ class CScreencopyProtocolManager {
void copyFrame(wl_client* client, wl_resource* resource, wl_resource* buffer); void copyFrame(wl_client* client, wl_resource* resource, wl_resource* buffer);
void onRenderEnd(CMonitor* pMonitor);
void onOutputCommit(CMonitor* pMonitor, wlr_output_event_commit* e); void onOutputCommit(CMonitor* pMonitor, wlr_output_event_commit* e);
private: private:
@ -91,7 +90,7 @@ class CScreencopyProtocolManager {
wlr_buffer* m_pLastMonitorBackBuffer = nullptr; wlr_buffer* m_pLastMonitorBackBuffer = nullptr;
void shareAllFrames(CMonitor* pMonitor, bool dmabuf); void shareAllFrames(CMonitor* pMonitor);
void shareFrame(SScreencopyFrame* frame); void shareFrame(SScreencopyFrame* frame);
void sendFrameDamage(SScreencopyFrame* frame); void sendFrameDamage(SScreencopyFrame* frame);
bool copyFrameDmabuf(SScreencopyFrame* frame); bool copyFrameDmabuf(SScreencopyFrame* frame);

View file

@ -1073,7 +1073,6 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) {
return; return;
} }
g_pProtocolManager->m_pScreencopyProtocolManager->onRenderEnd(pMonitor);
pixman_region32_fini(&damage); pixman_region32_fini(&damage);
if (UNLOCK_SC) if (UNLOCK_SC)