diff options
| author | davc0n <dconti.dev@gmail.com> | 2025-05-04 19:21:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-04 19:21:36 +0200 |
| commit | 2626f89ea6fe0df585df28052bf1fcca2c50fe8e (patch) | |
| tree | 6dd030f42e065e1a927ab907222e1efaf21b0bc1 /src/protocols/Screencopy.cpp | |
| parent | adbae0f74d951e06c575bad3c81a944027dfe413 (diff) | |
protocols: refactor class member vars (n-t) (#10273)
Diffstat (limited to 'src/protocols/Screencopy.cpp')
| -rw-r--r-- | src/protocols/Screencopy.cpp | 264 |
1 files changed, 132 insertions, 132 deletions
diff --git a/src/protocols/Screencopy.cpp b/src/protocols/Screencopy.cpp index 391d13e7..2c84fe93 100644 --- a/src/protocols/Screencopy.cpp +++ b/src/protocols/Screencopy.cpp @@ -17,66 +17,66 @@ #include <algorithm> #include <functional> -CScreencopyFrame::CScreencopyFrame(SP<CZwlrScreencopyFrameV1> resource_, int32_t overlay_cursor, wl_resource* output, CBox box_) : resource(resource_) { +CScreencopyFrame::CScreencopyFrame(SP<CZwlrScreencopyFrameV1> resource_, int32_t overlay_cursor, wl_resource* output, CBox box_) : m_resource(resource_) { if UNLIKELY (!good()) return; - overlayCursor = !!overlay_cursor; - pMonitor = CWLOutputResource::fromResource(output)->m_monitor; + m_overlayCursor = !!overlay_cursor; + m_monitor = CWLOutputResource::fromResource(output)->m_monitor; - if (!pMonitor) { + if (!m_monitor) { LOGM(ERR, "Client requested sharing of a monitor that doesnt exist"); - resource->sendFailed(); + m_resource->sendFailed(); return; } - resource->setOnDestroy([this](CZwlrScreencopyFrameV1* pMgr) { PROTO::screencopy->destroyResource(this); }); - resource->setDestroy([this](CZwlrScreencopyFrameV1* pFrame) { PROTO::screencopy->destroyResource(this); }); - resource->setCopy([this](CZwlrScreencopyFrameV1* pFrame, wl_resource* res) { this->copy(pFrame, res); }); - resource->setCopyWithDamage([this](CZwlrScreencopyFrameV1* pFrame, wl_resource* res) { - withDamage = true; + m_resource->setOnDestroy([this](CZwlrScreencopyFrameV1* pMgr) { PROTO::screencopy->destroyResource(this); }); + m_resource->setDestroy([this](CZwlrScreencopyFrameV1* pFrame) { PROTO::screencopy->destroyResource(this); }); + m_resource->setCopy([this](CZwlrScreencopyFrameV1* pFrame, wl_resource* res) { this->copy(pFrame, res); }); + m_resource->setCopyWithDamage([this](CZwlrScreencopyFrameV1* pFrame, wl_resource* res) { + m_withDamage = true; this->copy(pFrame, res); }); g_pHyprRenderer->makeEGLCurrent(); - shmFormat = g_pHyprOpenGL->getPreferredReadFormat(pMonitor.lock()); - if (shmFormat == DRM_FORMAT_INVALID) { + m_shmFormat = g_pHyprOpenGL->getPreferredReadFormat(m_monitor.lock()); + if (m_shmFormat == DRM_FORMAT_INVALID) { LOGM(ERR, "No format supported by renderer in capture output"); - resource->sendFailed(); + m_resource->sendFailed(); return; } // TODO: hack, we can't bit flip so we'll format flip heh, GL_BGRA_EXT wont work here - if (shmFormat == DRM_FORMAT_XRGB2101010 || shmFormat == DRM_FORMAT_ARGB2101010) - shmFormat = DRM_FORMAT_XBGR2101010; + if (m_shmFormat == DRM_FORMAT_XRGB2101010 || m_shmFormat == DRM_FORMAT_ARGB2101010) + m_shmFormat = DRM_FORMAT_XBGR2101010; - const auto PSHMINFO = NFormatUtils::getPixelFormatFromDRM(shmFormat); + const auto PSHMINFO = NFormatUtils::getPixelFormatFromDRM(m_shmFormat); if (!PSHMINFO) { LOGM(ERR, "No pixel format supported by renderer in capture output"); - resource->sendFailed(); + m_resource->sendFailed(); return; } - dmabufFormat = pMonitor->m_output->state->state().drmFormat; + m_dmabufFormat = m_monitor->m_output->state->state().drmFormat; if (box_.width == 0 && box_.height == 0) - box = {0, 0, (int)(pMonitor->m_size.x), (int)(pMonitor->m_size.y)}; + m_box = {0, 0, (int)(m_monitor->m_size.x), (int)(m_monitor->m_size.y)}; else { - box = box_; + m_box = box_; } - box.transform(wlTransformToHyprutils(pMonitor->m_transform), pMonitor->m_transformedSize.x, pMonitor->m_transformedSize.y).scale(pMonitor->m_scale).round(); + m_box.transform(wlTransformToHyprutils(m_monitor->m_transform), m_monitor->m_transformedSize.x, m_monitor->m_transformedSize.y).scale(m_monitor->m_scale).round(); - shmStride = NFormatUtils::minStride(PSHMINFO, box.w); + m_shmStride = NFormatUtils::minStride(PSHMINFO, m_box.w); - resource->sendBuffer(NFormatUtils::drmToShm(shmFormat), box.width, box.height, shmStride); + m_resource->sendBuffer(NFormatUtils::drmToShm(m_shmFormat), m_box.width, m_box.height, m_shmStride); - if (resource->version() >= 3) { - if LIKELY (dmabufFormat != DRM_FORMAT_INVALID) - resource->sendLinuxDmabuf(dmabufFormat, box.width, box.height); + if (m_resource->version() >= 3) { + if LIKELY (m_dmabufFormat != DRM_FORMAT_INVALID) + m_resource->sendLinuxDmabuf(m_dmabufFormat, m_box.width, m_box.height); - resource->sendBufferDone(); + m_resource->sendBufferDone(); } } @@ -86,137 +86,137 @@ void CScreencopyFrame::copy(CZwlrScreencopyFrameV1* pFrame, wl_resource* buffer_ return; } - if UNLIKELY (!g_pCompositor->monitorExists(pMonitor.lock())) { + if UNLIKELY (!g_pCompositor->monitorExists(m_monitor.lock())) { LOGM(ERR, "Client requested sharing of a monitor that is gone"); - resource->sendFailed(); + m_resource->sendFailed(); return; } const auto PBUFFER = CWLBufferResource::fromResource(buffer_); if UNLIKELY (!PBUFFER) { LOGM(ERR, "Invalid buffer in {:x}", (uintptr_t)this); - resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer"); + m_resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer"); PROTO::screencopy->destroyResource(this); return; } - if UNLIKELY (PBUFFER->m_buffer->size != box.size()) { + if UNLIKELY (PBUFFER->m_buffer->size != m_box.size()) { LOGM(ERR, "Invalid dimensions in {:x}", (uintptr_t)this); - resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer dimensions"); + m_resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer dimensions"); PROTO::screencopy->destroyResource(this); return; } - if UNLIKELY (buffer) { + if UNLIKELY (m_buffer) { LOGM(ERR, "Buffer used in {:x}", (uintptr_t)this); - resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_ALREADY_USED, "frame already used"); + m_resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_ALREADY_USED, "frame already used"); PROTO::screencopy->destroyResource(this); return; } if (auto attrs = PBUFFER->m_buffer->dmabuf(); attrs.success) { - bufferDMA = true; + m_bufferDMA = true; - if (attrs.format != dmabufFormat) { + if (attrs.format != m_dmabufFormat) { LOGM(ERR, "Invalid buffer dma format in {:x}", (uintptr_t)pFrame); - resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer format"); + m_resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer format"); PROTO::screencopy->destroyResource(this); return; } } else if (auto attrs = PBUFFER->m_buffer->shm(); attrs.success) { - if (attrs.format != shmFormat) { + if (attrs.format != m_shmFormat) { LOGM(ERR, "Invalid buffer shm format in {:x}", (uintptr_t)pFrame); - resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer format"); + m_resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer format"); PROTO::screencopy->destroyResource(this); return; - } else if ((int)attrs.stride != shmStride) { + } else if ((int)attrs.stride != m_shmStride) { LOGM(ERR, "Invalid buffer shm stride in {:x}", (uintptr_t)pFrame); - resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer stride"); + m_resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer stride"); PROTO::screencopy->destroyResource(this); return; } } else { LOGM(ERR, "Invalid buffer type in {:x}", (uintptr_t)pFrame); - resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer type"); + m_resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer type"); PROTO::screencopy->destroyResource(this); return; } - buffer = CHLBufferReference(PBUFFER->m_buffer.lock()); + m_buffer = CHLBufferReference(PBUFFER->m_buffer.lock()); - PROTO::screencopy->m_vFramesAwaitingWrite.emplace_back(self); + PROTO::screencopy->m_framesAwaitingWrite.emplace_back(m_self); g_pHyprRenderer->m_bDirectScanoutBlocked = true; - if (!withDamage) - g_pHyprRenderer->damageMonitor(pMonitor.lock()); + if (!m_withDamage) + g_pHyprRenderer->damageMonitor(m_monitor.lock()); } void CScreencopyFrame::share() { - if (!buffer || !pMonitor) + if (!m_buffer || !m_monitor) return; const auto NOW = Time::steadyNow(); - auto callback = [this, NOW, weak = self](bool success) { + auto callback = [this, NOW, weak = m_self](bool success) { if (weak.expired()) return; if (!success) { - LOGM(ERR, "{} copy failed in {:x}", bufferDMA ? "Dmabuf" : "Shm", (uintptr_t)this); - resource->sendFailed(); + LOGM(ERR, "{} copy failed in {:x}", m_bufferDMA ? "Dmabuf" : "Shm", (uintptr_t)this); + m_resource->sendFailed(); return; } - resource->sendFlags((zwlrScreencopyFrameV1Flags)0); - if (withDamage) { + m_resource->sendFlags((zwlrScreencopyFrameV1Flags)0); + if (m_withDamage) { // TODO: add a damage ring for this. - resource->sendDamage(0, 0, buffer->size.x, buffer->size.y); + m_resource->sendDamage(0, 0, m_buffer->size.x, m_buffer->size.y); } const auto [sec, nsec] = Time::secNsec(NOW); uint32_t tvSecHi = (sizeof(sec) > 4) ? sec >> 32 : 0; uint32_t tvSecLo = sec & 0xFFFFFFFF; - resource->sendReady(tvSecHi, tvSecLo, nsec); + m_resource->sendReady(tvSecHi, tvSecLo, nsec); }; - if (bufferDMA) + if (m_bufferDMA) copyDmabuf(callback); else callback(copyShm()); } void CScreencopyFrame::copyDmabuf(std::function<void(bool)> callback) { - const auto PERM = g_pDynamicPermissionManager->clientPermissionMode(resource->client(), PERMISSION_TYPE_SCREENCOPY); - auto TEXTURE = makeShared<CTexture>(pMonitor->m_output->state->state().buffer); + const auto PERM = g_pDynamicPermissionManager->clientPermissionMode(m_resource->client(), PERMISSION_TYPE_SCREENCOPY); + auto TEXTURE = makeShared<CTexture>(m_monitor->m_output->state->state().buffer); CRegion fakeDamage = {0, 0, INT16_MAX, INT16_MAX}; - if (!g_pHyprRenderer->beginRender(pMonitor.lock(), fakeDamage, RENDER_MODE_TO_BUFFER, buffer.m_buffer, nullptr, true)) { + if (!g_pHyprRenderer->beginRender(m_monitor.lock(), fakeDamage, RENDER_MODE_TO_BUFFER, m_buffer.m_buffer, nullptr, true)) { LOGM(ERR, "Can't copy: failed to begin rendering to dma frame"); callback(false); return; } if (PERM == PERMISSION_RULE_ALLOW_MODE_ALLOW) { - CBox monbox = CBox{0, 0, pMonitor->m_pixelSize.x, pMonitor->m_pixelSize.y} - .translate({-box.x, -box.y}) // vvvv kinda ass-backwards but that's how I designed the renderer... sigh. - .transform(wlTransformToHyprutils(invertTransform(pMonitor->m_transform)), pMonitor->m_pixelSize.x, pMonitor->m_pixelSize.y); + CBox monbox = CBox{0, 0, m_monitor->m_pixelSize.x, m_monitor->m_pixelSize.y} + .translate({-m_box.x, -m_box.y}) // vvvv kinda ass-backwards but that's how I designed the renderer... sigh. + .transform(wlTransformToHyprutils(invertTransform(m_monitor->m_transform)), m_monitor->m_pixelSize.x, m_monitor->m_pixelSize.y); g_pHyprOpenGL->setMonitorTransformEnabled(true); g_pHyprOpenGL->setRenderModifEnabled(false); g_pHyprOpenGL->renderTexture(TEXTURE, monbox, 1); g_pHyprOpenGL->setRenderModifEnabled(true); g_pHyprOpenGL->setMonitorTransformEnabled(false); - if (overlayCursor) - g_pPointerManager->renderSoftwareCursorsFor(pMonitor.lock(), Time::steadyNow(), fakeDamage, - g_pInputManager->getMouseCoordsInternal() - pMonitor->m_position - box.pos(), true); + if (m_overlayCursor) + g_pPointerManager->renderSoftwareCursorsFor(m_monitor.lock(), Time::steadyNow(), fakeDamage, + g_pInputManager->getMouseCoordsInternal() - m_monitor->m_position - m_box.pos(), true); } else if (PERM == PERMISSION_RULE_ALLOW_MODE_PENDING) g_pHyprOpenGL->clear(Colors::BLACK); else { g_pHyprOpenGL->clear(Colors::BLACK); CBox texbox = - CBox{pMonitor->m_transformedSize / 2.F, g_pHyprOpenGL->m_pScreencopyDeniedTexture->m_vSize}.translate(-g_pHyprOpenGL->m_pScreencopyDeniedTexture->m_vSize / 2.F); + CBox{m_monitor->m_transformedSize / 2.F, g_pHyprOpenGL->m_pScreencopyDeniedTexture->m_vSize}.translate(-g_pHyprOpenGL->m_pScreencopyDeniedTexture->m_vSize / 2.F); g_pHyprOpenGL->renderTexture(g_pHyprOpenGL->m_pScreencopyDeniedTexture, texbox, 1); } @@ -229,40 +229,40 @@ void CScreencopyFrame::copyDmabuf(std::function<void(bool)> callback) { } bool CScreencopyFrame::copyShm() { - const auto PERM = g_pDynamicPermissionManager->clientPermissionMode(resource->client(), PERMISSION_TYPE_SCREENCOPY); - auto TEXTURE = makeShared<CTexture>(pMonitor->m_output->state->state().buffer); + const auto PERM = g_pDynamicPermissionManager->clientPermissionMode(m_resource->client(), PERMISSION_TYPE_SCREENCOPY); + auto TEXTURE = makeShared<CTexture>(m_monitor->m_output->state->state().buffer); - auto shm = buffer->shm(); - auto [pixelData, fmt, bufLen] = buffer->beginDataPtr(0); // no need for end, cuz it's shm + auto shm = m_buffer->shm(); + auto [pixelData, fmt, bufLen] = m_buffer->beginDataPtr(0); // no need for end, cuz it's shm CRegion fakeDamage = {0, 0, INT16_MAX, INT16_MAX}; g_pHyprRenderer->makeEGLCurrent(); CFramebuffer fb; - fb.alloc(box.w, box.h, pMonitor->m_output->state->state().drmFormat); + fb.alloc(m_box.w, m_box.h, m_monitor->m_output->state->state().drmFormat); - if (!g_pHyprRenderer->beginRender(pMonitor.lock(), fakeDamage, RENDER_MODE_FULL_FAKE, nullptr, &fb, true)) { + if (!g_pHyprRenderer->beginRender(m_monitor.lock(), fakeDamage, RENDER_MODE_FULL_FAKE, nullptr, &fb, true)) { LOGM(ERR, "Can't copy: failed to begin rendering"); return false; } if (PERM == PERMISSION_RULE_ALLOW_MODE_ALLOW) { - CBox monbox = CBox{0, 0, pMonitor->m_transformedSize.x, pMonitor->m_transformedSize.y}.translate({-box.x, -box.y}); + CBox monbox = CBox{0, 0, m_monitor->m_transformedSize.x, m_monitor->m_transformedSize.y}.translate({-m_box.x, -m_box.y}); g_pHyprOpenGL->setMonitorTransformEnabled(true); g_pHyprOpenGL->setRenderModifEnabled(false); g_pHyprOpenGL->renderTexture(TEXTURE, monbox, 1); g_pHyprOpenGL->setRenderModifEnabled(true); g_pHyprOpenGL->setMonitorTransformEnabled(false); - if (overlayCursor) - g_pPointerManager->renderSoftwareCursorsFor(pMonitor.lock(), Time::steadyNow(), fakeDamage, - g_pInputManager->getMouseCoordsInternal() - pMonitor->m_position - box.pos(), true); + if (m_overlayCursor) + g_pPointerManager->renderSoftwareCursorsFor(m_monitor.lock(), Time::steadyNow(), fakeDamage, + g_pInputManager->getMouseCoordsInternal() - m_monitor->m_position - m_box.pos(), true); } else if (PERM == PERMISSION_RULE_ALLOW_MODE_PENDING) g_pHyprOpenGL->clear(Colors::BLACK); else { g_pHyprOpenGL->clear(Colors::BLACK); CBox texbox = - CBox{pMonitor->m_transformedSize / 2.F, g_pHyprOpenGL->m_pScreencopyDeniedTexture->m_vSize}.translate(-g_pHyprOpenGL->m_pScreencopyDeniedTexture->m_vSize / 2.F); + CBox{m_monitor->m_transformedSize / 2.F, g_pHyprOpenGL->m_pScreencopyDeniedTexture->m_vSize}.translate(-g_pHyprOpenGL->m_pScreencopyDeniedTexture->m_vSize / 2.F); g_pHyprOpenGL->renderTexture(g_pHyprOpenGL->m_pScreencopyDeniedTexture, texbox, 1); } @@ -285,22 +285,22 @@ bool CScreencopyFrame::copyShm() { g_pHyprRenderer->endRender(); g_pHyprRenderer->makeEGLCurrent(); - g_pHyprOpenGL->m_RenderData.pMonitor = pMonitor; + g_pHyprOpenGL->m_RenderData.pMonitor = m_monitor; fb.bind(); glPixelStorei(GL_PACK_ALIGNMENT, 1); const auto drmFmt = NFormatUtils::getPixelFormatFromDRM(shm.format); - uint32_t packStride = NFormatUtils::minStride(drmFmt, box.w); + uint32_t packStride = NFormatUtils::minStride(drmFmt, m_box.w); // This could be optimized by using a pixel buffer object to make this async, // but really clients should just use a dma buffer anyways. if (packStride == (uint32_t)shm.stride) { - glReadPixels(0, 0, box.w, box.h, glFormat, PFORMAT->glType, pixelData); + glReadPixels(0, 0, m_box.w, m_box.h, glFormat, PFORMAT->glType, pixelData); } else { - for (size_t i = 0; i < box.h; ++i) { + for (size_t i = 0; i < m_box.h; ++i) { uint32_t y = i; - glReadPixels(0, y, box.w, 1, glFormat, PFORMAT->glType, ((unsigned char*)pixelData) + i * shm.stride); + glReadPixels(0, y, m_box.w, 1, glFormat, PFORMAT->glType, ((unsigned char*)pixelData) + i * shm.stride); } } @@ -318,68 +318,68 @@ bool CScreencopyFrame::copyShm() { } bool CScreencopyFrame::good() { - return resource->resource(); + return m_resource->resource(); } CScreencopyClient::~CScreencopyClient() { - g_pHookSystem->unhook(tickCallback); + g_pHookSystem->unhook(m_tickCallback); } -CScreencopyClient::CScreencopyClient(SP<CZwlrScreencopyManagerV1> resource_) : resource(resource_) { +CScreencopyClient::CScreencopyClient(SP<CZwlrScreencopyManagerV1> resource_) : m_resource(resource_) { if UNLIKELY (!good()) return; - resource->setDestroy([this](CZwlrScreencopyManagerV1* pMgr) { PROTO::screencopy->destroyResource(this); }); - resource->setOnDestroy([this](CZwlrScreencopyManagerV1* pMgr) { PROTO::screencopy->destroyResource(this); }); - resource->setCaptureOutput( + m_resource->setDestroy([this](CZwlrScreencopyManagerV1* pMgr) { PROTO::screencopy->destroyResource(this); }); + m_resource->setOnDestroy([this](CZwlrScreencopyManagerV1* pMgr) { PROTO::screencopy->destroyResource(this); }); + m_resource->setCaptureOutput( [this](CZwlrScreencopyManagerV1* pMgr, uint32_t frame, int32_t overlayCursor, wl_resource* output) { this->captureOutput(frame, overlayCursor, output, {}); }); - resource->setCaptureOutputRegion([this](CZwlrScreencopyManagerV1* pMgr, uint32_t frame, int32_t overlayCursor, wl_resource* output, int32_t x, int32_t y, int32_t w, - int32_t h) { this->captureOutput(frame, overlayCursor, output, {x, y, w, h}); }); + m_resource->setCaptureOutputRegion([this](CZwlrScreencopyManagerV1* pMgr, uint32_t frame, int32_t overlayCursor, wl_resource* output, int32_t x, int32_t y, int32_t w, + int32_t h) { this->captureOutput(frame, overlayCursor, output, {x, y, w, h}); }); - lastMeasure.reset(); - lastFrame.reset(); - tickCallback = g_pHookSystem->hookDynamic("tick", [&](void* self, SCallbackInfo& info, std::any data) { onTick(); }); + m_lastMeasure.reset(); + m_lastFrame.reset(); + m_tickCallback = g_pHookSystem->hookDynamic("tick", [&](void* self, SCallbackInfo& info, std::any data) { onTick(); }); } void CScreencopyClient::captureOutput(uint32_t frame, int32_t overlayCursor_, wl_resource* output, CBox box) { - const auto FRAME = PROTO::screencopy->m_vFrames.emplace_back( - makeShared<CScreencopyFrame>(makeShared<CZwlrScreencopyFrameV1>(resource->client(), resource->version(), frame), overlayCursor_, output, box)); + const auto FRAME = PROTO::screencopy->m_frames.emplace_back( + makeShared<CScreencopyFrame>(makeShared<CZwlrScreencopyFrameV1>(m_resource->client(), m_resource->version(), frame), overlayCursor_, output, box)); if (!FRAME->good()) { LOGM(ERR, "Couldn't alloc frame for sharing! (no memory)"); - resource->noMemory(); + m_resource->noMemory(); PROTO::screencopy->destroyResource(FRAME.get()); return; } - FRAME->self = FRAME; - FRAME->client = self; + FRAME->m_self = FRAME; + FRAME->m_client = m_self; } void CScreencopyClient::onTick() { - if (lastMeasure.getMillis() < 500) + if (m_lastMeasure.getMillis() < 500) return; - framesInLastHalfSecond = frameCounter; - frameCounter = 0; - lastMeasure.reset(); - - const auto LASTFRAMEDELTA = lastFrame.getMillis() / 1000.0; - const bool FRAMEAWAITING = std::ranges::any_of(PROTO::screencopy->m_vFrames, [&](const auto& frame) { return frame->client.get() == this; }); - - if (framesInLastHalfSecond > 3 && !sentScreencast) { - EMIT_HOOK_EVENT("screencast", (std::vector<uint64_t>{1, (uint64_t)framesInLastHalfSecond, (uint64_t)clientOwner})); - g_pEventManager->postEvent(SHyprIPCEvent{"screencast", "1," + std::to_string(clientOwner)}); - sentScreencast = true; - } else if (framesInLastHalfSecond < 4 && sentScreencast && LASTFRAMEDELTA > 1.0 && !FRAMEAWAITING) { - EMIT_HOOK_EVENT("screencast", (std::vector<uint64_t>{0, (uint64_t)framesInLastHalfSecond, (uint64_t)clientOwner})); - g_pEventManager->postEvent(SHyprIPCEvent{"screencast", "0," + std::to_string(clientOwner)}); - sentScreencast = false; + m_framesInLastHalfSecond = m_frameCounter; + m_frameCounter = 0; + m_lastMeasure.reset(); + + const auto LASTFRAMEDELTA = m_lastFrame.getMillis() / 1000.0; + const bool FRAMEAWAITING = std::ranges::any_of(PROTO::screencopy->m_frames, [&](const auto& frame) { return frame->m_client.get() == this; }); + + if (m_framesInLastHalfSecond > 3 && !m_sentScreencast) { + EMIT_HOOK_EVENT("screencast", (std::vector<uint64_t>{1, (uint64_t)m_framesInLastHalfSecond, (uint64_t)m_clientOwner})); + g_pEventManager->postEvent(SHyprIPCEvent{"screencast", "1," + std::to_string(m_clientOwner)}); + m_sentScreencast = true; + } else if (m_framesInLastHalfSecond < 4 && m_sentScreencast && LASTFRAMEDELTA > 1.0 && !FRAMEAWAITING) { + EMIT_HOOK_EVENT("screencast", (std::vector<uint64_t>{0, (uint64_t)m_framesInLastHalfSecond, (uint64_t)m_clientOwner})); + g_pEventManager->postEvent(SHyprIPCEvent{"screencast", "0," + std::to_string(m_clientOwner)}); + m_sentScreencast = false; } } bool CScreencopyClient::good() { - return resource->resource(); + return m_resource->resource(); } CScreencopyProtocol::CScreencopyProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { @@ -387,71 +387,71 @@ CScreencopyProtocol::CScreencopyProtocol(const wl_interface* iface, const int& v } void CScreencopyProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { - const auto CLIENT = m_vClients.emplace_back(makeShared<CScreencopyClient>(makeShared<CZwlrScreencopyManagerV1>(client, ver, id))); + const auto CLIENT = m_clients.emplace_back(makeShared<CScreencopyClient>(makeShared<CZwlrScreencopyManagerV1>(client, ver, id))); if (!CLIENT->good()) { LOGM(LOG, "Failed to bind client! (out of memory)"); - CLIENT->resource->noMemory(); - m_vClients.pop_back(); + CLIENT->m_resource->noMemory(); + m_clients.pop_back(); return; } - CLIENT->self = CLIENT; + CLIENT->m_self = CLIENT; LOGM(LOG, "Bound client successfully!"); } void CScreencopyProtocol::destroyResource(CScreencopyClient* client) { - std::erase_if(m_vClients, [&](const auto& other) { return other.get() == client; }); - std::erase_if(m_vFrames, [&](const auto& other) { return other->client.get() == client; }); - std::erase_if(m_vFramesAwaitingWrite, [&](const auto& other) { return !other || other->client.get() == client; }); + std::erase_if(m_clients, [&](const auto& other) { return other.get() == client; }); + std::erase_if(m_frames, [&](const auto& other) { return other->m_client.get() == client; }); + std::erase_if(m_framesAwaitingWrite, [&](const auto& other) { return !other || other->m_client.get() == client; }); } void CScreencopyProtocol::destroyResource(CScreencopyFrame* frame) { - std::erase_if(m_vFrames, [&](const auto& other) { return other.get() == frame; }); - std::erase_if(m_vFramesAwaitingWrite, [&](const auto& other) { return !other || other.get() == frame; }); + std::erase_if(m_frames, [&](const auto& other) { return other.get() == frame; }); + std::erase_if(m_framesAwaitingWrite, [&](const auto& other) { return !other || other.get() == frame; }); } void CScreencopyProtocol::onOutputCommit(PHLMONITOR pMonitor) { - if (m_vFramesAwaitingWrite.empty()) { + if (m_framesAwaitingWrite.empty()) { g_pHyprRenderer->m_bDirectScanoutBlocked = false; return; // nothing to share } std::vector<WP<CScreencopyFrame>> framesToRemove; // reserve number of elements to avoid reallocations - framesToRemove.reserve(m_vFramesAwaitingWrite.size()); + framesToRemove.reserve(m_framesAwaitingWrite.size()); // share frame if correct output - for (auto const& f : m_vFramesAwaitingWrite) { + for (auto const& f : m_framesAwaitingWrite) { if (!f) continue; // check permissions - const auto PERM = g_pDynamicPermissionManager->clientPermissionMode(f->resource->client(), PERMISSION_TYPE_SCREENCOPY); + const auto PERM = g_pDynamicPermissionManager->clientPermissionMode(f->m_resource->client(), PERMISSION_TYPE_SCREENCOPY); if (PERM == PERMISSION_RULE_ALLOW_MODE_PENDING) continue; // pending an answer, don't do anything yet. // otherwise share. If it's denied, it will be black. - if (!f->pMonitor || !f->buffer) { + if (!f->m_monitor || !f->m_buffer) { framesToRemove.emplace_back(f); continue; } - if (f->pMonitor != pMonitor) + if (f->m_monitor != pMonitor) continue; f->share(); - f->client->lastFrame.reset(); - ++f->client->frameCounter; + f->m_client->m_lastFrame.reset(); + ++f->m_client->m_frameCounter; framesToRemove.emplace_back(f); } for (auto const& f : framesToRemove) { - std::erase(m_vFramesAwaitingWrite, f); + std::erase(m_framesAwaitingWrite, f); } } |
