summaryrefslogtreecommitdiff
path: root/src/protocols/Screencopy.cpp
diff options
context:
space:
mode:
authorvaxerski <vaxry@vaxry.net>2025-01-17 18:21:34 +0100
committervaxerski <vaxry@vaxry.net>2025-01-17 18:56:39 +0100
commitb7a3c4526990d6601ff2cac748ff860cda6bc16d (patch)
tree425c6afa0bc35f7f370a666bd7a81214a6e9475a /src/protocols/Screencopy.cpp
parent2bad73354a5dbb9be8ba9a39b6238017a216a25b (diff)
core: add LIKELY and UNLIKELY macros
helps the compiler optimize
Diffstat (limited to 'src/protocols/Screencopy.cpp')
-rw-r--r--src/protocols/Screencopy.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/protocols/Screencopy.cpp b/src/protocols/Screencopy.cpp
index da0a9412..8bdaf8f9 100644
--- a/src/protocols/Screencopy.cpp
+++ b/src/protocols/Screencopy.cpp
@@ -19,7 +19,7 @@ CScreencopyFrame::~CScreencopyFrame() {
}
CScreencopyFrame::CScreencopyFrame(SP<CZwlrScreencopyFrameV1> resource_, int32_t overlay_cursor, wl_resource* output, CBox box_) : resource(resource_) {
- if (!good())
+ if UNLIKELY (!good())
return;
overlayCursor = !!overlay_cursor;
@@ -77,21 +77,20 @@ CScreencopyFrame::CScreencopyFrame(SP<CZwlrScreencopyFrameV1> resource_, int32_t
resource->sendBuffer(NFormatUtils::drmToShm(shmFormat), box.width, box.height, shmStride);
if (resource->version() >= 3) {
- if (dmabufFormat != DRM_FORMAT_INVALID) {
+ if LIKELY (dmabufFormat != DRM_FORMAT_INVALID)
resource->sendLinuxDmabuf(dmabufFormat, box.width, box.height);
- }
resource->sendBufferDone();
}
}
void CScreencopyFrame::copy(CZwlrScreencopyFrameV1* pFrame, wl_resource* buffer_) {
- if (!good()) {
+ if UNLIKELY (!good()) {
LOGM(ERR, "No frame in copyFrame??");
return;
}
- if (!g_pCompositor->monitorExists(pMonitor.lock())) {
+ if UNLIKELY (!g_pCompositor->monitorExists(pMonitor.lock())) {
LOGM(ERR, "Client requested sharing of a monitor that is gone");
resource->sendFailed();
PROTO::screencopy->destroyResource(this);
@@ -99,7 +98,7 @@ void CScreencopyFrame::copy(CZwlrScreencopyFrameV1* pFrame, wl_resource* buffer_
}
const auto PBUFFER = CWLBufferResource::fromResource(buffer_);
- if (!PBUFFER) {
+ if UNLIKELY (!PBUFFER) {
LOGM(ERR, "Invalid buffer in {:x}", (uintptr_t)this);
resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer");
PROTO::screencopy->destroyResource(this);
@@ -108,14 +107,14 @@ void CScreencopyFrame::copy(CZwlrScreencopyFrameV1* pFrame, wl_resource* buffer_
PBUFFER->buffer->lock();
- if (PBUFFER->buffer->size != box.size()) {
+ if UNLIKELY (PBUFFER->buffer->size != box.size()) {
LOGM(ERR, "Invalid dimensions in {:x}", (uintptr_t)this);
resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer dimensions");
PROTO::screencopy->destroyResource(this);
return;
}
- if (buffer) {
+ if UNLIKELY (buffer) {
LOGM(ERR, "Buffer used in {:x}", (uintptr_t)this);
resource->error(ZWLR_SCREENCOPY_FRAME_V1_ERROR_ALREADY_USED, "frame already used");
PROTO::screencopy->destroyResource(this);
@@ -308,7 +307,7 @@ CScreencopyClient::~CScreencopyClient() {
}
CScreencopyClient::CScreencopyClient(SP<CZwlrScreencopyManagerV1> resource_) : resource(resource_) {
- if (!good())
+ if UNLIKELY (!good())
return;
resource->setDestroy([this](CZwlrScreencopyManagerV1* pMgr) { PROTO::screencopy->destroyResource(this); });