core: add LIKELY and UNLIKELY macros

helps the compiler optimize
This commit is contained in:
Vaxry 2025-01-17 18:21:34 +01:00
parent 2bad73354a
commit b7a3c45269
58 changed files with 395 additions and 396 deletions

View file

@ -11,7 +11,7 @@ SP<CVirtualPointer> CVirtualPointer::create(SP<CVirtualPointerV1Resource> resour
}
CVirtualPointer::CVirtualPointer(SP<CVirtualPointerV1Resource> resource) : pointer(resource) {
if (!resource->good())
if UNLIKELY (!resource->good())
return;
listeners.destroy = pointer->events.destroy.registerListener([this](std::any d) {

View file

@ -114,3 +114,6 @@
namespace Aquamarine { \
class name; \
}
#define UNLIKELY(expr) (expr) [[unlikely]]
#define LIKELY(expr) (expr) [[likely]]

View file

@ -15,7 +15,7 @@ bool CAlphaModifier::good() {
void CAlphaModifier::setResource(SP<CWpAlphaModifierSurfaceV1> resource) {
m_pResource = std::move(resource);
if (!m_pResource->resource())
if UNLIKELY (!m_pResource->resource())
return;
m_pResource->setDestroy([this](CWpAlphaModifierSurfaceV1* resource) { destroy(); });
@ -98,7 +98,7 @@ void CAlphaModifierProtocol::getSurface(CWpAlphaModifierV1* manager, uint32_t id
.first->second.get();
}
if (!alphaModifier->good()) {
if UNLIKELY (!alphaModifier->good()) {
manager->noMemory();
m_mAlphaModifiers.erase(surface);
}

View file

@ -7,7 +7,7 @@
#include "../helpers/Monitor.hpp"
CHyprlandCTMControlResource::CHyprlandCTMControlResource(SP<CHyprlandCtmControlManagerV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CHyprlandCtmControlManagerV1* pMgr) { PROTO::ctm->destroyResource(this); });
@ -17,12 +17,12 @@ CHyprlandCTMControlResource::CHyprlandCTMControlResource(SP<CHyprlandCtmControlM
wl_fixed_t mat5, wl_fixed_t mat6, wl_fixed_t mat7, wl_fixed_t mat8) {
const auto OUTPUTRESOURCE = CWLOutputResource::fromResource(output);
if (!OUTPUTRESOURCE)
if UNLIKELY (!OUTPUTRESOURCE)
return; // ?!
const auto PMONITOR = OUTPUTRESOURCE->monitor.lock();
if (!PMONITOR)
if UNLIKELY (!PMONITOR)
return; // ?!?!
const std::array<float, 9> MAT = {wl_fixed_to_double(mat0), wl_fixed_to_double(mat1), wl_fixed_to_double(mat2), wl_fixed_to_double(mat3), wl_fixed_to_double(mat4),
@ -72,7 +72,7 @@ void CHyprlandCTMControlProtocol::bindManager(wl_client* client, void* data, uin
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CHyprlandCTMControlResource>(makeShared<CHyprlandCtmControlManagerV1>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;

View file

@ -2,7 +2,7 @@
#include "Compositor.hpp"
CColorManager::CColorManager(SP<CXxColorManagerV4> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->sendSupportedFeature(XX_COLOR_MANAGER_V4_FEATURE_PARAMETRIC);
@ -38,7 +38,7 @@ CColorManager::CColorManager(SP<CXxColorManagerV4> resource_) : resource(resourc
const auto RESOURCE =
PROTO::colorManagement->m_vOutputs.emplace_back(makeShared<CColorManagementOutput>(makeShared<CXxColorManagementOutputV4>(r->client(), r->version(), id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vOutputs.pop_back();
return;
@ -63,7 +63,7 @@ CColorManager::CColorManager(SP<CXxColorManagerV4> resource_) : resource(resourc
const auto RESOURCE =
PROTO::colorManagement->m_vSurfaces.emplace_back(makeShared<CColorManagementSurface>(makeShared<CXxColorManagementSurfaceV4>(r->client(), r->version(), id), SURF));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vSurfaces.pop_back();
return;
@ -86,7 +86,7 @@ CColorManager::CColorManager(SP<CXxColorManagerV4> resource_) : resource(resourc
const auto RESOURCE = PROTO::colorManagement->m_vFeedbackSurfaces.emplace_back(
makeShared<CColorManagementFeedbackSurface>(makeShared<CXxColorManagementFeedbackSurfaceV4>(r->client(), r->version(), id), SURF));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vFeedbackSurfaces.pop_back();
return;
@ -104,7 +104,7 @@ CColorManager::CColorManager(SP<CXxColorManagerV4> resource_) : resource(resourc
const auto RESOURCE = PROTO::colorManagement->m_vParametricCreators.emplace_back(
makeShared<CColorManagementParametricCreator>(makeShared<CXxImageDescriptionCreatorParamsV4>(r->client(), r->version(), id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vParametricCreators.pop_back();
return;
@ -121,7 +121,7 @@ bool CColorManager::good() {
}
CColorManagementOutput::CColorManagementOutput(SP<CXxColorManagementOutputV4> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
pClient = resource->client();
@ -137,7 +137,7 @@ CColorManagementOutput::CColorManagementOutput(SP<CXxColorManagementOutputV4> re
const auto RESOURCE = PROTO::colorManagement->m_vImageDescriptions.emplace_back(
makeShared<CColorManagementImageDescription>(makeShared<CXxImageDescriptionV4>(r->client(), r->version(), id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vImageDescriptions.pop_back();
return;
@ -160,7 +160,7 @@ CColorManagementSurface::CColorManagementSurface(SP<CWLSurfaceResource> surface_
}
CColorManagementSurface::CColorManagementSurface(SP<CXxColorManagementSurfaceV4> resource_, SP<CWLSurfaceResource> surface_) : surface(surface_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
pClient = resource->client();
@ -242,7 +242,7 @@ bool CColorManagementSurface::needsHdrMetadataUpdate() {
CColorManagementFeedbackSurface::CColorManagementFeedbackSurface(SP<CXxColorManagementFeedbackSurfaceV4> resource_, SP<CWLSurfaceResource> surface_) :
surface(surface_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
pClient = resource->client();
@ -269,7 +269,7 @@ CColorManagementFeedbackSurface::CColorManagementFeedbackSurface(SP<CXxColorMana
const auto RESOURCE = PROTO::colorManagement->m_vImageDescriptions.emplace_back(
makeShared<CColorManagementImageDescription>(makeShared<CXxImageDescriptionV4>(r->client(), r->version(), id), true));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vImageDescriptions.pop_back();
return;
@ -293,7 +293,7 @@ wl_client* CColorManagementFeedbackSurface::client() {
}
CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CXxImageDescriptionCreatorParamsV4> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
//
pClient = resource->client();
@ -318,7 +318,7 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CXxImage
const auto RESOURCE = PROTO::colorManagement->m_vImageDescriptions.emplace_back(
makeShared<CColorManagementImageDescription>(makeShared<CXxImageDescriptionV4>(r->client(), r->version(), id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vImageDescriptions.pop_back();
return;
@ -465,7 +465,7 @@ wl_client* CColorManagementParametricCreator::client() {
CColorManagementImageDescription::CColorManagementImageDescription(SP<CXxImageDescriptionV4> resource_, bool allowGetInformation) :
m_resource(resource_), m_allowGetInformation(allowGetInformation) {
if (!good())
if UNLIKELY (!good())
return;
pClient = m_resource->client();
@ -482,7 +482,7 @@ CColorManagementImageDescription::CColorManagementImageDescription(SP<CXxImageDe
auto RESOURCE = makeShared<CColorManagementImageDescriptionInfo>(makeShared<CXxImageDescriptionInfoV4>(r->client(), r->version(), id), settings);
if (!RESOURCE->good())
if UNLIKELY (!RESOURCE->good())
r->noMemory();
// CColorManagementImageDescriptionInfo should send everything in the constructor and be ready for destroying at this point
@ -504,7 +504,7 @@ SP<CXxImageDescriptionV4> CColorManagementImageDescription::resource() {
CColorManagementImageDescriptionInfo::CColorManagementImageDescriptionInfo(SP<CXxImageDescriptionInfoV4> resource_, const SImageDescription& settings_) :
m_resource(resource_), settings(settings_) {
if (!good())
if UNLIKELY (!good())
return;
pClient = m_resource->client();
@ -549,7 +549,7 @@ CColorManagementProtocol::CColorManagementProtocol(const wl_interface* iface, co
void CColorManagementProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CColorManager>(makeShared<CXxColorManagerV4>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;

View file

@ -41,7 +41,7 @@ void CCursorShapeProtocol::createCursorShapeDevice(CWpCursorShapeManagerV1* pMgr
}
void CCursorShapeProtocol::onSetShape(CWpCursorShapeDeviceV1* pMgr, uint32_t serial, wpCursorShapeDeviceV1Shape shape) {
if ((uint32_t)shape == 0 || (uint32_t)shape > CURSOR_SHAPE_NAMES.size()) {
if UNLIKELY ((uint32_t)shape == 0 || (uint32_t)shape > CURSOR_SHAPE_NAMES.size()) {
pMgr->error(WP_CURSOR_SHAPE_DEVICE_V1_ERROR_INVALID_SHAPE, "The shape is invalid");
return;
}

View file

@ -6,7 +6,7 @@
#include <fcntl.h>
CDRMLeaseResource::CDRMLeaseResource(SP<CWpDrmLeaseV1> resource_, SP<CDRMLeaseRequestResource> request) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWpDrmLeaseV1* r) { PROTO::lease->destroyResource(this); });
@ -79,7 +79,7 @@ CDRMLeaseResource::~CDRMLeaseResource() {
}
CDRMLeaseRequestResource::CDRMLeaseRequestResource(SP<CWpDrmLeaseRequestV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWpDrmLeaseRequestV1* r) { PROTO::lease->destroyResource(this); });
@ -109,7 +109,7 @@ CDRMLeaseRequestResource::CDRMLeaseRequestResource(SP<CWpDrmLeaseRequestV1> reso
}
auto RESOURCE = makeShared<CDRMLeaseResource>(makeShared<CWpDrmLeaseV1>(resource->client(), resource->version(), id), self.lock());
if (!RESOURCE) {
if UNLIKELY (!RESOURCE) {
resource->noMemory();
return;
}
@ -131,7 +131,7 @@ SP<CDRMLeaseConnectorResource> CDRMLeaseConnectorResource::fromResource(wl_resou
}
CDRMLeaseConnectorResource::CDRMLeaseConnectorResource(SP<CWpDrmLeaseConnectorV1> resource_, PHLMONITOR monitor_) : monitor(monitor_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWpDrmLeaseConnectorV1* r) { PROTO::lease->destroyResource(this); });
@ -160,7 +160,7 @@ void CDRMLeaseConnectorResource::sendData() {
}
CDRMLeaseDeviceResource::CDRMLeaseDeviceResource(SP<CWpDrmLeaseDeviceV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWpDrmLeaseDeviceV1* r) { PROTO::lease->destroyResource(this); });
@ -168,7 +168,7 @@ CDRMLeaseDeviceResource::CDRMLeaseDeviceResource(SP<CWpDrmLeaseDeviceV1> resourc
resource->setCreateLeaseRequest([this](CWpDrmLeaseDeviceV1* r, uint32_t id) {
auto RESOURCE = makeShared<CDRMLeaseRequestResource>(makeShared<CWpDrmLeaseRequestV1>(resource->client(), resource->version(), id));
if (!RESOURCE) {
if UNLIKELY (!RESOURCE) {
resource->noMemory();
return;
}
@ -209,7 +209,7 @@ void CDRMLeaseDeviceResource::sendConnector(PHLMONITOR monitor) {
return;
auto RESOURCE = makeShared<CDRMLeaseConnectorResource>(makeShared<CWpDrmLeaseConnectorV1>(resource->client(), resource->version(), 0), monitor);
if (!RESOURCE) {
if UNLIKELY (!RESOURCE) {
resource->noMemory();
return;
}
@ -262,7 +262,7 @@ CDRMLeaseProtocol::CDRMLeaseProtocol(const wl_interface* iface, const int& ver,
void CDRMLeaseProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CDRMLeaseDeviceResource>(makeShared<CWpDrmLeaseDeviceV1>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;

View file

@ -8,7 +8,7 @@
#include <fcntl.h>
CDRMSyncobjSurfaceResource::CDRMSyncobjSurfaceResource(SP<CWpLinuxDrmSyncobjSurfaceV1> resource_, SP<CWLSurfaceResource> surface_) : surface(surface_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setData(this);
@ -104,7 +104,7 @@ bool CDRMSyncobjSurfaceResource::good() {
}
CDRMSyncobjTimelineResource::CDRMSyncobjTimelineResource(SP<CWpLinuxDrmSyncobjTimelineV1> resource_, int fd_) : fd(fd_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setData(this);
@ -135,31 +135,31 @@ bool CDRMSyncobjTimelineResource::good() {
}
CDRMSyncobjManagerResource::CDRMSyncobjManagerResource(SP<CWpLinuxDrmSyncobjManagerV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWpLinuxDrmSyncobjManagerV1* r) { PROTO::sync->destroyResource(this); });
resource->setDestroy([this](CWpLinuxDrmSyncobjManagerV1* r) { PROTO::sync->destroyResource(this); });
resource->setGetSurface([this](CWpLinuxDrmSyncobjManagerV1* r, uint32_t id, wl_resource* surf) {
if (!surf) {
if UNLIKELY (!surf) {
resource->error(-1, "Invalid surface");
return;
}
auto SURF = CWLSurfaceResource::fromResource(surf);
if (!SURF) {
if UNLIKELY (!SURF) {
resource->error(-1, "Invalid surface (2)");
return;
}
if (SURF->syncobj) {
if UNLIKELY (SURF->syncobj) {
resource->error(WP_LINUX_DRM_SYNCOBJ_MANAGER_V1_ERROR_SURFACE_EXISTS, "Surface already has a syncobj attached");
return;
}
auto RESOURCE = makeShared<CDRMSyncobjSurfaceResource>(makeShared<CWpLinuxDrmSyncobjSurfaceV1>(resource->client(), resource->version(), id), SURF);
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
resource->noMemory();
return;
}
@ -172,7 +172,7 @@ CDRMSyncobjManagerResource::CDRMSyncobjManagerResource(SP<CWpLinuxDrmSyncobjMana
resource->setImportTimeline([this](CWpLinuxDrmSyncobjManagerV1* r, uint32_t id, int32_t fd) {
auto RESOURCE = makeShared<CDRMSyncobjTimelineResource>(makeShared<CWpLinuxDrmSyncobjTimelineV1>(resource->client(), resource->version(), id), fd);
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
resource->noMemory();
return;
}
@ -195,7 +195,7 @@ CDRMSyncobjProtocol::CDRMSyncobjProtocol(const wl_interface* iface, const int& v
void CDRMSyncobjProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CDRMSyncobjManagerResource>(makeShared<CWpLinuxDrmSyncobjManagerV1>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;

View file

@ -4,7 +4,7 @@
#include "core/Seat.hpp"
CWLRDataOffer::CWLRDataOffer(SP<CZwlrDataControlOfferV1> resource_, SP<IDataSource> source_) : source(source_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CZwlrDataControlOfferV1* r) { PROTO::dataWlr->destroyResource(this); });
@ -34,7 +34,7 @@ bool CWLRDataOffer::good() {
}
void CWLRDataOffer::sendData() {
if (!source)
if UNLIKELY (!source)
return;
for (auto const& m : source->mimes()) {
@ -43,7 +43,7 @@ void CWLRDataOffer::sendData() {
}
CWLRDataSource::CWLRDataSource(SP<CZwlrDataControlSourceV1> resource_, SP<CWLRDataDevice> device_) : device(device_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setData(this);
@ -104,7 +104,7 @@ void CWLRDataSource::error(uint32_t code, const std::string& msg) {
}
CWLRDataDevice::CWLRDataDevice(SP<CZwlrDataControlDeviceV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
pClient = resource->client();
@ -173,7 +173,7 @@ void CWLRDataDevice::sendPrimarySelection(SP<CWLRDataOffer> selection) {
}
CWLRDataControlManagerResource::CWLRDataControlManagerResource(SP<CZwlrDataControlManagerV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CZwlrDataControlManagerV1* r) { PROTO::dataWlr->destroyResource(this); });
@ -182,7 +182,7 @@ CWLRDataControlManagerResource::CWLRDataControlManagerResource(SP<CZwlrDataContr
resource->setGetDataDevice([this](CZwlrDataControlManagerV1* r, uint32_t id, wl_resource* seat) {
const auto RESOURCE = PROTO::dataWlr->m_vDevices.emplace_back(makeShared<CWLRDataDevice>(makeShared<CZwlrDataControlDeviceV1>(r->client(), r->version(), id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::dataWlr->m_vDevices.pop_back();
return;
@ -208,7 +208,7 @@ CWLRDataControlManagerResource::CWLRDataControlManagerResource(SP<CZwlrDataContr
const auto RESOURCE =
PROTO::dataWlr->m_vSources.emplace_back(makeShared<CWLRDataSource>(makeShared<CZwlrDataControlSourceV1>(r->client(), r->version(), id), device.lock()));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::dataWlr->m_vSources.pop_back();
return;
@ -236,7 +236,7 @@ CDataDeviceWLRProtocol::CDataDeviceWLRProtocol(const wl_interface* iface, const
void CDataDeviceWLRProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CWLRDataControlManagerResource>(makeShared<CZwlrDataControlManagerV1>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;

View file

@ -17,7 +17,7 @@ CFocusGrabSurfaceState::~CFocusGrabSurfaceState() {
}
CFocusGrab::CFocusGrab(SP<CHyprlandFocusGrabV1> resource_) : resource(resource_) {
if (!resource->resource())
if UNLIKELY (!resource->resource())
return;
grab = makeShared<CSeatGrab>();
@ -63,9 +63,8 @@ void CFocusGrab::finish(bool sendCleared) {
if (m_bGrabActive) {
m_bGrabActive = false;
if (g_pSeatManager->seatGrab == grab) {
if (g_pSeatManager->seatGrab == grab)
g_pSeatManager->setGrab(nullptr);
}
grab->clear();
m_mSurfaces.clear();
@ -77,17 +76,16 @@ void CFocusGrab::finish(bool sendCleared) {
void CFocusGrab::addSurface(SP<CWLSurfaceResource> surface) {
auto iter = std::find_if(m_mSurfaces.begin(), m_mSurfaces.end(), [surface](const auto& e) { return e.first == surface; });
if (iter == m_mSurfaces.end()) {
if (iter == m_mSurfaces.end())
m_mSurfaces.emplace(surface, std::make_unique<CFocusGrabSurfaceState>(this, surface));
}
}
void CFocusGrab::removeSurface(SP<CWLSurfaceResource> surface) {
auto iter = m_mSurfaces.find(surface);
if (iter != m_mSurfaces.end()) {
if (iter->second->state == CFocusGrabSurfaceState::PendingAddition) {
if (iter->second->state == CFocusGrabSurfaceState::PendingAddition)
m_mSurfaces.erase(iter);
} else
else
iter->second->state = CFocusGrabSurfaceState::PendingRemoval;
}
}
@ -172,7 +170,7 @@ void CFocusGrabProtocol::onCreateGrab(CHyprlandFocusGrabManagerV1* pMgr, uint32_
m_vGrabs.push_back(std::make_unique<CFocusGrab>(makeShared<CHyprlandFocusGrabV1>(pMgr->client(), pMgr->version(), id)));
const auto RESOURCE = m_vGrabs.back().get();
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vGrabs.pop_back();
}

View file

@ -3,7 +3,7 @@
#include "../managers/HookSystemManager.hpp"
CForeignToplevelHandle::CForeignToplevelHandle(SP<CExtForeignToplevelHandleV1> resource_, PHLWINDOW pWindow_) : resource(resource_), pWindow(pWindow_) {
if (!resource_->resource())
if UNLIKELY (!resource_->resource())
return;
resource->setOnDestroy([this](CExtForeignToplevelHandleV1* h) { PROTO::foreignToplevel->destroyHandle(this); });
@ -19,7 +19,7 @@ PHLWINDOW CForeignToplevelHandle::window() {
}
CForeignToplevelList::CForeignToplevelList(SP<CExtForeignToplevelListV1> resource_) : resource(resource_) {
if (!resource_->resource())
if UNLIKELY (!resource_->resource())
return;
resource->setOnDestroy([this](CExtForeignToplevelListV1* h) { PROTO::foreignToplevel->onManagerResourceDestroy(this); });
@ -40,7 +40,7 @@ CForeignToplevelList::CForeignToplevelList(SP<CExtForeignToplevelListV1> resourc
}
void CForeignToplevelList::onMap(PHLWINDOW pWindow) {
if (finished)
if UNLIKELY (finished)
return;
const auto NEWHANDLE = PROTO::foreignToplevel->m_vHandles.emplace_back(
@ -72,11 +72,11 @@ SP<CForeignToplevelHandle> CForeignToplevelList::handleForWindow(PHLWINDOW pWind
}
void CForeignToplevelList::onTitle(PHLWINDOW pWindow) {
if (finished)
if UNLIKELY (finished)
return;
const auto H = handleForWindow(pWindow);
if (!H || H->closed)
if UNLIKELY (!H || H->closed)
return;
H->resource->sendTitle(pWindow->m_szTitle.c_str());
@ -84,11 +84,11 @@ void CForeignToplevelList::onTitle(PHLWINDOW pWindow) {
}
void CForeignToplevelList::onClass(PHLWINDOW pWindow) {
if (finished)
if UNLIKELY (finished)
return;
const auto H = handleForWindow(pWindow);
if (!H || H->closed)
if UNLIKELY (!H || H->closed)
return;
H->resource->sendAppId(pWindow->m_szClass.c_str());
@ -96,11 +96,11 @@ void CForeignToplevelList::onClass(PHLWINDOW pWindow) {
}
void CForeignToplevelList::onUnmap(PHLWINDOW pWindow) {
if (finished)
if UNLIKELY (finished)
return;
const auto H = handleForWindow(pWindow);
if (!H)
if UNLIKELY (!H)
return;
H->resource->sendClosed();
@ -149,7 +149,7 @@ CForeignToplevelProtocol::CForeignToplevelProtocol(const wl_interface* iface, co
void CForeignToplevelProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(std::make_unique<CForeignToplevelList>(makeShared<CExtForeignToplevelListV1>(client, ver, id))).get();
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
LOGM(ERR, "Couldn't create a foreign list");
wl_client_post_no_memory(client);
m_vManagers.pop_back();

View file

@ -6,7 +6,7 @@
#include "../managers/HookSystemManager.hpp"
CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHandleV1> resource_, PHLWINDOW pWindow_) : resource(resource_), pWindow(pWindow_) {
if (!resource_->resource())
if UNLIKELY (!resource_->resource())
return;
resource->setOnDestroy([this](CZwlrForeignToplevelHandleV1* h) { PROTO::foreignToplevelWlr->destroyHandle(this); });
@ -15,7 +15,7 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHand
resource->setActivate([this](CZwlrForeignToplevelHandleV1* p, wl_resource* seat) {
const auto PWINDOW = pWindow.lock();
if (!PWINDOW)
if UNLIKELY (!PWINDOW)
return;
// these requests bypass the config'd stuff cuz it's usually like
@ -26,13 +26,13 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHand
resource->setSetFullscreen([this](CZwlrForeignToplevelHandleV1* p, wl_resource* output) {
const auto PWINDOW = pWindow.lock();
if (!PWINDOW)
if UNLIKELY (!PWINDOW)
return;
if (PWINDOW->m_eSuppressedEvents & SUPPRESS_FULLSCREEN)
if UNLIKELY (PWINDOW->m_eSuppressedEvents & SUPPRESS_FULLSCREEN)
return;
if (!PWINDOW->m_bIsMapped) {
if UNLIKELY (!PWINDOW->m_bIsMapped) {
PWINDOW->m_bWantsInitialFullscreen = true;
return;
}
@ -57,10 +57,10 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHand
resource->setUnsetFullscreen([this](CZwlrForeignToplevelHandleV1* p) {
const auto PWINDOW = pWindow.lock();
if (!PWINDOW)
if UNLIKELY (!PWINDOW)
return;
if (PWINDOW->m_eSuppressedEvents & SUPPRESS_FULLSCREEN)
if UNLIKELY (PWINDOW->m_eSuppressedEvents & SUPPRESS_FULLSCREEN)
return;
g_pCompositor->changeWindowFullscreenModeClient(PWINDOW, FSMODE_FULLSCREEN, false);
@ -69,13 +69,13 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHand
resource->setSetMaximized([this](CZwlrForeignToplevelHandleV1* p) {
const auto PWINDOW = pWindow.lock();
if (!PWINDOW)
if UNLIKELY (!PWINDOW)
return;
if (PWINDOW->m_eSuppressedEvents & SUPPRESS_MAXIMIZE)
if UNLIKELY (PWINDOW->m_eSuppressedEvents & SUPPRESS_MAXIMIZE)
return;
if (!PWINDOW->m_bIsMapped) {
if UNLIKELY (!PWINDOW->m_bIsMapped) {
PWINDOW->m_bWantsInitialFullscreen = true;
return;
}
@ -86,10 +86,10 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHand
resource->setUnsetMaximized([this](CZwlrForeignToplevelHandleV1* p) {
const auto PWINDOW = pWindow.lock();
if (!PWINDOW)
if UNLIKELY (!PWINDOW)
return;
if (PWINDOW->m_eSuppressedEvents & SUPPRESS_MAXIMIZE)
if UNLIKELY (PWINDOW->m_eSuppressedEvents & SUPPRESS_MAXIMIZE)
return;
g_pCompositor->changeWindowFullscreenModeClient(PWINDOW, FSMODE_MAXIMIZED, false);
@ -98,7 +98,7 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHand
resource->setClose([this](CZwlrForeignToplevelHandleV1* p) {
const auto PWINDOW = pWindow.lock();
if (!PWINDOW)
if UNLIKELY (!PWINDOW)
return;
g_pCompositor->closeWindow(PWINDOW);
@ -126,14 +126,14 @@ void CForeignToplevelHandleWlr::sendMonitor(PHLMONITOR pMonitor) {
if (const auto PLASTMONITOR = g_pCompositor->getMonitorFromID(lastMonitorID); PLASTMONITOR && PROTO::outputs.contains(PLASTMONITOR->szName)) {
const auto OLDRESOURCE = PROTO::outputs.at(PLASTMONITOR->szName)->outputResourceFrom(CLIENT);
if (OLDRESOURCE)
if LIKELY (OLDRESOURCE)
resource->sendOutputLeave(OLDRESOURCE->getResource()->resource());
}
if (PROTO::outputs.contains(pMonitor->szName)) {
const auto NEWRESOURCE = PROTO::outputs.at(pMonitor->szName)->outputResourceFrom(CLIENT);
if (NEWRESOURCE)
if LIKELY (NEWRESOURCE)
resource->sendOutputEnter(NEWRESOURCE->getResource()->resource());
}
@ -143,7 +143,7 @@ void CForeignToplevelHandleWlr::sendMonitor(PHLMONITOR pMonitor) {
void CForeignToplevelHandleWlr::sendState() {
const auto PWINDOW = pWindow.lock();
if (!PWINDOW || !PWINDOW->m_pWorkspace || !PWINDOW->m_bIsMapped)
if UNLIKELY (!PWINDOW || !PWINDOW->m_pWorkspace || !PWINDOW->m_bIsMapped)
return;
wl_array state;
@ -168,7 +168,7 @@ void CForeignToplevelHandleWlr::sendState() {
}
CForeignToplevelWlrManager::CForeignToplevelWlrManager(SP<CZwlrForeignToplevelManagerV1> resource_) : resource(resource_) {
if (!resource_->resource())
if UNLIKELY (!resource_->resource())
return;
resource->setOnDestroy([this](CZwlrForeignToplevelManagerV1* h) { PROTO::foreignToplevelWlr->onManagerResourceDestroy(this); });
@ -191,13 +191,13 @@ CForeignToplevelWlrManager::CForeignToplevelWlrManager(SP<CZwlrForeignToplevelMa
}
void CForeignToplevelWlrManager::onMap(PHLWINDOW pWindow) {
if (finished)
if UNLIKELY (finished)
return;
const auto NEWHANDLE = PROTO::foreignToplevelWlr->m_vHandles.emplace_back(
makeShared<CForeignToplevelHandleWlr>(makeShared<CZwlrForeignToplevelHandleV1>(resource->client(), resource->version(), 0), pWindow));
if (!NEWHANDLE->good()) {
if UNLIKELY (!NEWHANDLE->good()) {
LOGM(ERR, "Couldn't create a foreign handle");
resource->noMemory();
PROTO::foreignToplevelWlr->m_vHandles.pop_back();
@ -208,7 +208,7 @@ void CForeignToplevelWlrManager::onMap(PHLWINDOW pWindow) {
resource->sendToplevel(NEWHANDLE->resource.get());
NEWHANDLE->resource->sendAppId(pWindow->m_szClass.c_str());
NEWHANDLE->resource->sendTitle(pWindow->m_szTitle.c_str());
if (const auto PMONITOR = pWindow->m_pMonitor.lock(); PMONITOR)
if LIKELY (const auto PMONITOR = pWindow->m_pMonitor.lock(); PMONITOR)
NEWHANDLE->sendMonitor(PMONITOR);
NEWHANDLE->sendState();
NEWHANDLE->resource->sendDone();
@ -223,11 +223,11 @@ SP<CForeignToplevelHandleWlr> CForeignToplevelWlrManager::handleForWindow(PHLWIN
}
void CForeignToplevelWlrManager::onTitle(PHLWINDOW pWindow) {
if (finished)
if UNLIKELY (finished)
return;
const auto H = handleForWindow(pWindow);
if (!H || H->closed)
if UNLIKELY (!H || H->closed)
return;
H->resource->sendTitle(pWindow->m_szTitle.c_str());
@ -235,11 +235,11 @@ void CForeignToplevelWlrManager::onTitle(PHLWINDOW pWindow) {
}
void CForeignToplevelWlrManager::onClass(PHLWINDOW pWindow) {
if (finished)
if UNLIKELY (finished)
return;
const auto H = handleForWindow(pWindow);
if (!H || H->closed)
if UNLIKELY (!H || H->closed)
return;
H->resource->sendAppId(pWindow->m_szClass.c_str());
@ -247,11 +247,11 @@ void CForeignToplevelWlrManager::onClass(PHLWINDOW pWindow) {
}
void CForeignToplevelWlrManager::onUnmap(PHLWINDOW pWindow) {
if (finished)
if UNLIKELY (finished)
return;
const auto H = handleForWindow(pWindow);
if (!H)
if UNLIKELY (!H)
return;
H->resource->sendClosed();
@ -260,16 +260,16 @@ void CForeignToplevelWlrManager::onUnmap(PHLWINDOW pWindow) {
}
void CForeignToplevelWlrManager::onMoveMonitor(PHLWINDOW pWindow) {
if (finished)
if UNLIKELY (finished)
return;
const auto H = handleForWindow(pWindow);
if (!H || H->closed)
if UNLIKELY (!H || H->closed)
return;
const auto PMONITOR = pWindow->m_pMonitor.lock();
if (!PMONITOR)
if UNLIKELY (!PMONITOR)
return;
H->sendMonitor(PMONITOR);
@ -277,11 +277,11 @@ void CForeignToplevelWlrManager::onMoveMonitor(PHLWINDOW pWindow) {
}
void CForeignToplevelWlrManager::onFullscreen(PHLWINDOW pWindow) {
if (finished)
if UNLIKELY (finished)
return;
const auto H = handleForWindow(pWindow);
if (!H || H->closed)
if UNLIKELY (!H || H->closed)
return;
H->sendState();
@ -289,10 +289,10 @@ void CForeignToplevelWlrManager::onFullscreen(PHLWINDOW pWindow) {
}
void CForeignToplevelWlrManager::onNewFocus(PHLWINDOW pWindow) {
if (finished)
if UNLIKELY (finished)
return;
if (const auto HOLD = handleForWindow(lastFocus.lock()); HOLD) {
if LIKELY (const auto HOLD = handleForWindow(lastFocus.lock()); HOLD) {
HOLD->sendState();
HOLD->resource->sendDone();
}
@ -300,7 +300,7 @@ void CForeignToplevelWlrManager::onNewFocus(PHLWINDOW pWindow) {
lastFocus = pWindow;
const auto H = handleForWindow(pWindow);
if (!H || H->closed)
if UNLIKELY (!H || H->closed)
return;
H->sendState();
@ -378,7 +378,7 @@ CForeignToplevelWlrProtocol::CForeignToplevelWlrProtocol(const wl_interface* ifa
void CForeignToplevelWlrProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(std::make_unique<CForeignToplevelWlrManager>(makeShared<CZwlrForeignToplevelManagerV1>(client, ver, id))).get();
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
LOGM(ERR, "Couldn't create a foreign list");
wl_client_post_no_memory(client);
m_vManagers.pop_back();

View file

@ -35,7 +35,7 @@ void CFractionalScaleProtocol::onGetFractionalScale(CWpFractionalScaleManagerV1*
const auto PADDON =
m_mAddons.emplace(surface, std::make_unique<CFractionalScaleAddon>(makeShared<CWpFractionalScaleV1>(pMgr->client(), pMgr->version(), id), surface)).first->second.get();
if (!PADDON->good()) {
if UNLIKELY (!PADDON->good()) {
m_mAddons.erase(surface);
pMgr->noMemory();
return;

View file

@ -3,7 +3,7 @@
#include "protocols/core/Subcompositor.hpp"
CFrogColorManager::CFrogColorManager(SP<CFrogColorManagementFactoryV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([](CFrogColorManagementFactoryV1* r) { LOGM(TRACE, "Destroy frog_color_management at {:x} (generated default)", (uintptr_t)r); });
@ -24,7 +24,7 @@ CFrogColorManager::CFrogColorManager(SP<CFrogColorManagementFactoryV1> resource_
const auto RESOURCE = PROTO::frogColorManagement->m_vSurfaces.emplace_back(
makeShared<CFrogColorManagementSurface>(makeShared<CFrogColorManagedSurface>(r->client(), r->version(), id), SURF));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::frogColorManagement->m_vSurfaces.pop_back();
return;
@ -39,14 +39,14 @@ bool CFrogColorManager::good() {
}
CFrogColorManagementSurface::CFrogColorManagementSurface(SP<CFrogColorManagedSurface> resource_, SP<CWLSurfaceResource> surface_) : surface(surface_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
pClient = resource->client();
if (!surface->colorManagement.valid()) {
const auto RESOURCE = PROTO::colorManagement->m_vSurfaces.emplace_back(makeShared<CColorManagementSurface>(surface_));
if (!RESOURCE) {
if UNLIKELY (!RESOURCE) {
resource->noMemory();
PROTO::colorManagement->m_vSurfaces.pop_back();
return;
@ -141,7 +141,7 @@ CFrogColorManagementProtocol::CFrogColorManagementProtocol(const wl_interface* i
void CFrogColorManagementProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CFrogColorManager>(makeShared<CFrogColorManagementFactoryV1>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;

View file

@ -6,12 +6,12 @@
#include "../render/Renderer.hpp"
CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* output) : resource(resource_) {
if (!resource_->resource())
if UNLIKELY (!resource_->resource())
return;
auto OUTPUTRES = CWLOutputResource::fromResource(output);
if (!OUTPUTRES) {
if UNLIKELY (!OUTPUTRES) {
LOGM(ERR, "No output in CGammaControl");
resource->sendFailed();
return;
@ -19,14 +19,14 @@ CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* out
pMonitor = OUTPUTRES->monitor;
if (!pMonitor || !pMonitor->output) {
if UNLIKELY (!pMonitor || !pMonitor->output) {
LOGM(ERR, "No CMonitor");
resource->sendFailed();
return;
}
for (auto const& g : PROTO::gamma->m_vGammaControllers) {
if (g->pMonitor == pMonitor) {
if UNLIKELY (g->pMonitor == pMonitor) {
resource->sendFailed();
return;
}
@ -34,7 +34,7 @@ CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* out
gammaSize = pMonitor->output->getGammaSize();
if (gammaSize <= 0) {
if UNLIKELY (gammaSize <= 0) {
LOGM(ERR, "Output {} doesn't support gamma", pMonitor->szName);
resource->sendFailed();
return;
@ -46,7 +46,7 @@ CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* out
resource->setOnDestroy([this](CZwlrGammaControlV1* gamma) { PROTO::gamma->destroyGammaControl(this); });
resource->setSetGamma([this](CZwlrGammaControlV1* gamma, int32_t fd) {
if (!pMonitor) {
if UNLIKELY (!pMonitor) {
LOGM(ERR, "setGamma for a dead monitor");
resource->sendFailed();
close(fd);
@ -56,14 +56,14 @@ CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* out
LOGM(LOG, "setGamma for {}", pMonitor->szName);
int fdFlags = fcntl(fd, F_GETFL, 0);
if (fdFlags < 0) {
if UNLIKELY (fdFlags < 0) {
LOGM(ERR, "Failed to get fd flags");
resource->sendFailed();
close(fd);
return;
}
if (fcntl(fd, F_SETFL, fdFlags | O_NONBLOCK) < 0) {
if UNLIKELY (fcntl(fd, F_SETFL, fdFlags | O_NONBLOCK) < 0) {
LOGM(ERR, "Failed to set fd flags");
resource->sendFailed();
close(fd);
@ -126,7 +126,7 @@ bool CGammaControl::good() {
}
void CGammaControl::applyToMonitor() {
if (!pMonitor || !pMonitor->output)
if UNLIKELY (!pMonitor || !pMonitor->output)
return; // ??
LOGM(LOG, "setting to monitor {}", pMonitor->szName);
@ -179,7 +179,7 @@ void CGammaControlProtocol::onGetGammaControl(CZwlrGammaControlManagerV1* pMgr,
const auto CLIENT = pMgr->client();
const auto RESOURCE = m_vGammaControllers.emplace_back(std::make_unique<CGammaControl>(makeShared<CZwlrGammaControlV1>(CLIENT, pMgr->version(), id), output)).get();
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vGammaControllers.pop_back();
return;

View file

@ -1,7 +1,7 @@
#include "GlobalShortcuts.hpp"
CShortcutClient::CShortcutClient(SP<CHyprlandGlobalShortcutsManagerV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CHyprlandGlobalShortcutsManagerV1* pMgr) { PROTO::globalShortcuts->destroyResource(this); });
@ -9,7 +9,7 @@ CShortcutClient::CShortcutClient(SP<CHyprlandGlobalShortcutsManagerV1> resource_
resource->setRegisterShortcut([this](CHyprlandGlobalShortcutsManagerV1* pMgr, uint32_t shortcut, const char* id, const char* app_id, const char* description,
const char* trigger_description) {
if (PROTO::globalShortcuts->isTaken(id, app_id)) {
if UNLIKELY (PROTO::globalShortcuts->isTaken(id, app_id)) {
resource->error(HYPRLAND_GLOBAL_SHORTCUTS_MANAGER_V1_ERROR_ALREADY_TAKEN, "Combination is taken");
return;
}
@ -20,7 +20,7 @@ CShortcutClient::CShortcutClient(SP<CHyprlandGlobalShortcutsManagerV1> resource_
PSHORTCUT->appid = app_id;
PSHORTCUT->shortcut = shortcut;
if (!PSHORTCUT->resource->resource()) {
if UNLIKELY (!PSHORTCUT->resource->resource()) {
PSHORTCUT->resource->noMemory();
shortcuts.pop_back();
return;
@ -41,7 +41,7 @@ CGlobalShortcutsProtocol::CGlobalShortcutsProtocol(const wl_interface* iface, co
void CGlobalShortcutsProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESROUCE = m_vClients.emplace_back(makeShared<CShortcutClient>(makeShared<CHyprlandGlobalShortcutsManagerV1>(client, ver, id)));
if (!RESROUCE->good()) {
if UNLIKELY (!RESROUCE->good()) {
wl_client_post_no_memory(client);
m_vClients.pop_back();
return;

View file

@ -15,20 +15,20 @@ bool CHyprlandSurface::good() const {
void CHyprlandSurface::setResource(SP<CHyprlandSurfaceV1> resource) {
m_pResource = std::move(resource);
if (!m_pResource->resource())
if UNLIKELY (!m_pResource->resource())
return;
m_pResource->setDestroy([this](CHyprlandSurfaceV1* resource) { destroy(); });
m_pResource->setOnDestroy([this](CHyprlandSurfaceV1* resource) { destroy(); });
m_pResource->setSetOpacity([this](CHyprlandSurfaceV1* resource, uint32_t opacity) {
if (!m_pSurface) {
if UNLIKELY (!m_pSurface) {
m_pResource->error(HYPRLAND_SURFACE_V1_ERROR_NO_SURFACE, "set_opacity called for destroyed wl_surface");
return;
}
auto fOpacity = wl_fixed_to_double(opacity);
if (fOpacity < 0.0 || fOpacity > 1.0) {
if UNLIKELY (fOpacity < 0.0 || fOpacity > 1.0) {
m_pResource->error(HYPRLAND_SURFACE_V1_ERROR_OUT_OF_RANGE, "set_opacity called with an opacity value larger than 1.0 or smaller than 0.0.");
return;
}
@ -104,7 +104,7 @@ void CHyprlandSurfaceProtocol::getSurface(CHyprlandSurfaceManagerV1* manager, ui
.first->second.get();
}
if (!hyprlandSurface->good()) {
if UNLIKELY (!hyprlandSurface->good()) {
manager->noMemory();
m_mSurfaces.erase(surface);
}

View file

@ -11,7 +11,7 @@ static int onTimer(SP<CEventLoopTimer> self, void* data) {
}
CExtIdleNotification::CExtIdleNotification(SP<CExtIdleNotificationV1> resource_, uint32_t timeoutMs_) : resource(resource_), timeoutMs(timeoutMs_) {
if (!resource_->resource())
if UNLIKELY (!resource_->resource())
return;
resource->setDestroy([this](CExtIdleNotificationV1* r) { PROTO::idle->destroyNotification(this); });
@ -78,7 +78,7 @@ void CIdleNotifyProtocol::onGetNotification(CExtIdleNotifierV1* pMgr, uint32_t i
const auto CLIENT = pMgr->client();
const auto RESOURCE = m_vNotifications.emplace_back(makeShared<CExtIdleNotification>(makeShared<CExtIdleNotificationV1>(CLIENT, pMgr->version(), id), timeout)).get();
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vNotifications.pop_back();
return;

View file

@ -7,7 +7,7 @@
#include <cstring>
CInputMethodKeyboardGrabV2::CInputMethodKeyboardGrabV2(SP<CZwpInputMethodKeyboardGrabV2> resource_, SP<CInputMethodV2> owner_) : resource(resource_), owner(owner_) {
if (!resource->resource())
if UNLIKELY (!resource->resource())
return;
resource->setRelease([this](CZwpInputMethodKeyboardGrabV2* r) { PROTO::ime->destroyResource(this); });
@ -34,13 +34,13 @@ void CInputMethodKeyboardGrabV2::sendKeyboardData(SP<IKeyboard> keyboard) {
pLastKeyboard = keyboard;
int keymapFD = allocateSHMFile(keyboard->xkbKeymapString.length() + 1);
if (keymapFD < 0) {
if UNLIKELY (keymapFD < 0) {
LOGM(ERR, "Failed to create a keymap file for keyboard grab");
return;
}
void* data = mmap(nullptr, keyboard->xkbKeymapString.length() + 1, PROT_READ | PROT_WRITE, MAP_SHARED, keymapFD, 0);
if (data == MAP_FAILED) {
if UNLIKELY (data == MAP_FAILED) {
LOGM(ERR, "Failed to mmap a keymap file for keyboard grab");
close(keymapFD);
return;
@ -83,7 +83,7 @@ wl_client* CInputMethodKeyboardGrabV2::client() {
}
CInputMethodPopupV2::CInputMethodPopupV2(SP<CZwpInputPopupSurfaceV2> resource_, SP<CInputMethodV2> owner_, SP<CWLSurfaceResource> surface) : resource(resource_), owner(owner_) {
if (!resource->resource())
if UNLIKELY (!resource->resource())
return;
resource->setDestroy([this](CZwpInputPopupSurfaceV2* r) { PROTO::ime->destroyResource(this); });
@ -149,7 +149,7 @@ void CInputMethodV2::SState::reset() {
}
CInputMethodV2::CInputMethodV2(SP<CZwpInputMethodV2> resource_) : resource(resource_) {
if (!resource->resource())
if UNLIKELY (!resource->resource())
return;
resource->setDestroy([this](CZwpInputMethodV2* r) {
@ -189,7 +189,7 @@ CInputMethodV2::CInputMethodV2(SP<CZwpInputMethodV2> resource_) : resource(resou
const auto RESOURCE = PROTO::ime->m_vPopups.emplace_back(
makeShared<CInputMethodPopupV2>(makeShared<CZwpInputPopupSurfaceV2>(r->client(), r->version(), id), self.lock(), CWLSurfaceResource::fromResource(surface)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::ime->m_vPopups.pop_back();
return;
@ -206,7 +206,7 @@ CInputMethodV2::CInputMethodV2(SP<CZwpInputMethodV2> resource_) : resource(resou
const auto RESOURCE =
PROTO::ime->m_vGrabs.emplace_back(makeShared<CInputMethodKeyboardGrabV2>(makeShared<CZwpInputMethodKeyboardGrabV2>(r->client(), r->version(), id), self.lock()));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::ime->m_vGrabs.pop_back();
return;
@ -360,7 +360,7 @@ void CInputMethodV2Protocol::destroyResource(CInputMethodV2* ime) {
void CInputMethodV2Protocol::onGetIME(CZwpInputMethodManagerV2* mgr, wl_resource* seat, uint32_t id) {
const auto RESOURCE = m_vIMEs.emplace_back(makeShared<CInputMethodV2>(makeShared<CZwpInputMethodV2>(mgr->client(), mgr->version(), id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
mgr->noMemory();
m_vIMEs.pop_back();
return;

View file

@ -18,7 +18,7 @@ void CLayerShellResource::SState::reset() {
CLayerShellResource::CLayerShellResource(SP<CZwlrLayerSurfaceV1> resource_, SP<CWLSurfaceResource> surf_, std::string namespace_, PHLMONITOR pMonitor,
zwlrLayerShellV1Layer layer) : layerNamespace(namespace_), surface(surf_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
current.layer = layer;
@ -223,19 +223,19 @@ void CLayerShellProtocol::onGetLayerSurface(CZwlrLayerShellV1* pMgr, uint32_t id
const auto PMONITOR = output ? CWLOutputResource::fromResource(output)->monitor.lock() : nullptr;
auto SURF = CWLSurfaceResource::fromResource(surface);
if (!SURF) {
if UNLIKELY (!SURF) {
pMgr->error(-1, "Invalid surface");
return;
}
if (SURF->role->role() != SURFACE_ROLE_UNASSIGNED) {
if UNLIKELY (SURF->role->role() != SURFACE_ROLE_UNASSIGNED) {
pMgr->error(-1, "Surface already has a different role");
return;
}
const auto RESOURCE = m_vLayers.emplace_back(makeShared<CLayerShellResource>(makeShared<CZwlrLayerSurfaceV1>(CLIENT, pMgr->version(), id), SURF, namespace_, PMONITOR, layer));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vLayers.pop_back();
return;

View file

@ -126,7 +126,7 @@ bool CLinuxDMABuffer::good() {
}
CLinuxDMABBUFParamsResource::CLinuxDMABBUFParamsResource(SP<CZwpLinuxBufferParamsV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CZwpLinuxBufferParamsV1* r) { PROTO::linuxDma->destroyResource(this); });
@ -208,12 +208,12 @@ bool CLinuxDMABBUFParamsResource::good() {
void CLinuxDMABBUFParamsResource::create(uint32_t id) {
used = true;
if (!verify()) {
if UNLIKELY (!verify()) {
LOGM(ERR, "Failed creating a dmabuf: verify() said no");
return; // if verify failed, we errored the resource.
}
if (!commence()) {
if UNLIKELY (!commence()) {
LOGM(ERR, "Failed creating a dmabuf: commence() said no");
resource->sendFailed();
return;
@ -226,7 +226,7 @@ void CLinuxDMABBUFParamsResource::create(uint32_t id) {
auto buf = PROTO::linuxDma->m_vBuffers.emplace_back(makeShared<CLinuxDMABuffer>(id, resource->client(), *attrs));
if (!buf->good() || !buf->buffer->success) {
if UNLIKELY (!buf->good() || !buf->buffer->success) {
resource->sendFailed();
return;
}
@ -259,12 +259,12 @@ bool CLinuxDMABBUFParamsResource::commence() {
}
bool CLinuxDMABBUFParamsResource::verify() {
if (attrs->planes <= 0) {
if UNLIKELY (attrs->planes <= 0) {
resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, "No planes added");
return false;
}
if (attrs->fds.at(0) < 0) {
if UNLIKELY (attrs->fds.at(0) < 0) {
resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, "No plane 0");
return false;
}
@ -282,7 +282,7 @@ bool CLinuxDMABBUFParamsResource::verify() {
}
}
if (attrs->size.x < 1 || attrs->size.y < 1) {
if UNLIKELY (attrs->size.x < 1 || attrs->size.y < 1) {
resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DIMENSIONS, "x/y < 1");
return false;
}
@ -300,7 +300,7 @@ bool CLinuxDMABBUFParamsResource::verify() {
}
CLinuxDMABUFFeedbackResource::CLinuxDMABUFFeedbackResource(SP<CZwpLinuxDmabufFeedbackV1> resource_, SP<CWLSurfaceResource> surface_) : surface(surface_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CZwpLinuxDmabufFeedbackV1* r) { PROTO::linuxDma->destroyResource(this); });
@ -355,7 +355,7 @@ void CLinuxDMABUFFeedbackResource::sendDefaultFeedback() {
}
CLinuxDMABUFResource::CLinuxDMABUFResource(SP<CZwpLinuxDmabufV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CZwpLinuxDmabufV1* r) { PROTO::linuxDma->destroyResource(this); });
@ -365,7 +365,7 @@ CLinuxDMABUFResource::CLinuxDMABUFResource(SP<CZwpLinuxDmabufV1> resource_) : re
const auto RESOURCE =
PROTO::linuxDma->m_vFeedbacks.emplace_back(makeShared<CLinuxDMABUFFeedbackResource>(makeShared<CZwpLinuxDmabufFeedbackV1>(r->client(), r->version(), id), nullptr));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::linuxDma->m_vFeedbacks.pop_back();
return;
@ -376,7 +376,7 @@ CLinuxDMABUFResource::CLinuxDMABUFResource(SP<CZwpLinuxDmabufV1> resource_) : re
const auto RESOURCE = PROTO::linuxDma->m_vFeedbacks.emplace_back(
makeShared<CLinuxDMABUFFeedbackResource>(makeShared<CZwpLinuxDmabufFeedbackV1>(r->client(), r->version(), id), CWLSurfaceResource::fromResource(surf)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::linuxDma->m_vFeedbacks.pop_back();
return;
@ -386,7 +386,7 @@ CLinuxDMABUFResource::CLinuxDMABUFResource(SP<CZwpLinuxDmabufV1> resource_) : re
resource->setCreateParams([](CZwpLinuxDmabufV1* r, uint32_t id) {
const auto RESOURCE = PROTO::linuxDma->m_vParams.emplace_back(makeShared<CLinuxDMABBUFParamsResource>(makeShared<CZwpLinuxBufferParamsV1>(r->client(), r->version(), id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::linuxDma->m_vParams.pop_back();
return;
@ -535,7 +535,7 @@ CLinuxDMABufV1Protocol::~CLinuxDMABufV1Protocol() {
void CLinuxDMABufV1Protocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CLinuxDMABUFResource>(makeShared<CZwpLinuxDmabufV1>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;

View file

@ -35,7 +35,7 @@ bool CMesaDRMBufferResource::good() {
}
CMesaDRMResource::CMesaDRMResource(SP<CWlDrm> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWlDrm* r) { PROTO::mesaDRM->destroyResource(this); });
@ -87,7 +87,7 @@ CMesaDRMResource::CMesaDRMResource(SP<CWlDrm> resource_) : resource(resource_) {
const auto RESOURCE = PROTO::mesaDRM->m_vBuffers.emplace_back(makeShared<CMesaDRMBufferResource>(id, resource->client(), attrs));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::mesaDRM->m_vBuffers.pop_back();
return;
@ -140,7 +140,7 @@ CMesaDRMProtocol::CMesaDRMProtocol(const wl_interface* iface, const int& ver, co
void CMesaDRMProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CMesaDRMResource>(makeShared<CWlDrm>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;

View file

@ -8,7 +8,7 @@
using namespace Aquamarine;
COutputManager::COutputManager(SP<CZwlrOutputManagerV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
LOGM(LOG, "New OutputManager registered");
@ -23,7 +23,7 @@ COutputManager::COutputManager(SP<CZwlrOutputManagerV1> resource_) : resource(re
const auto RESOURCE = PROTO::outputManagement->m_vConfigurations.emplace_back(
makeShared<COutputConfiguration>(makeShared<CZwlrOutputConfigurationV1>(resource->client(), resource->version(), id), self.lock()));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
resource->noMemory();
PROTO::outputManagement->m_vConfigurations.pop_back();
return;
@ -48,13 +48,13 @@ bool COutputManager::good() {
}
void COutputManager::makeAndSendNewHead(PHLMONITOR pMonitor) {
if (stopped)
if UNLIKELY (stopped)
return;
const auto RESOURCE =
PROTO::outputManagement->m_vHeads.emplace_back(makeShared<COutputHead>(makeShared<CZwlrOutputHeadV1>(resource->client(), resource->version(), 0), pMonitor));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
resource->noMemory();
PROTO::outputManagement->m_vHeads.pop_back();
return;
@ -90,7 +90,7 @@ void COutputManager::sendDone() {
}
COutputHead::COutputHead(SP<CZwlrOutputHeadV1> resource_, PHLMONITOR pMonitor_) : resource(resource_), pMonitor(pMonitor_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setRelease([this](CZwlrOutputHeadV1* r) { PROTO::outputManagement->destroyResource(this); });
@ -213,7 +213,7 @@ void COutputHead::updateMode() {
void COutputHead::makeAndSendNewMode(SP<Aquamarine::SOutputMode> mode) {
const auto RESOURCE = PROTO::outputManagement->m_vModes.emplace_back(makeShared<COutputMode>(makeShared<CZwlrOutputModeV1>(resource->client(), resource->version(), 0), mode));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
resource->noMemory();
PROTO::outputManagement->m_vModes.pop_back();
return;
@ -229,7 +229,7 @@ PHLMONITOR COutputHead::monitor() {
}
COutputMode::COutputMode(SP<CZwlrOutputModeV1> resource_, SP<Aquamarine::SOutputMode> mode_) : resource(resource_), mode(mode_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setRelease([this](CZwlrOutputModeV1* r) { PROTO::outputManagement->destroyResource(this); });
@ -258,7 +258,7 @@ SP<Aquamarine::SOutputMode> COutputMode::getMode() {
}
COutputConfiguration::COutputConfiguration(SP<CZwlrOutputConfigurationV1> resource_, SP<COutputManager> owner_) : resource(resource_), owner(owner_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CZwlrOutputConfigurationV1* r) { PROTO::outputManagement->destroyResource(this); });
@ -282,7 +282,7 @@ COutputConfiguration::COutputConfiguration(SP<CZwlrOutputConfigurationV1> resour
const auto RESOURCE = PROTO::outputManagement->m_vConfigurationHeads.emplace_back(
makeShared<COutputConfigurationHead>(makeShared<CZwlrOutputConfigurationHeadV1>(resource->client(), resource->version(), id), PMONITOR));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
resource->noMemory();
PROTO::outputManagement->m_vConfigurationHeads.pop_back();
return;
@ -428,7 +428,7 @@ bool COutputConfiguration::applyTestConfiguration(bool test) {
}
COutputConfigurationHead::COutputConfigurationHead(SP<CZwlrOutputConfigurationHeadV1> resource_, PHLMONITOR pMonitor_) : resource(resource_), pMonitor(pMonitor_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CZwlrOutputConfigurationHeadV1* r) { PROTO::outputManagement->destroyResource(this); });
@ -581,7 +581,7 @@ COutputManagementProtocol::COutputManagementProtocol(const wl_interface* iface,
void COutputManagementProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<COutputManager>(makeShared<CZwlrOutputManagerV1>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;

View file

@ -3,7 +3,7 @@
#include "../helpers/Monitor.hpp"
COutputPower::COutputPower(SP<CZwlrOutputPowerV1> resource_, PHLMONITOR pMonitor_) : resource(resource_), pMonitor(pMonitor_) {
if (!resource->resource())
if UNLIKELY (!resource->resource())
return;
resource->setDestroy([this](CZwlrOutputPowerV1* r) { PROTO::outputPower->destroyOutputPower(this); });
@ -62,7 +62,7 @@ void COutputPowerProtocol::onGetOutputPower(CZwlrOutputPowerManagerV1* pMgr, uin
const auto OUTPUT = CWLOutputResource::fromResource(output);
if (!OUTPUT) {
if UNLIKELY (!OUTPUT) {
pMgr->error(0, "Invalid output resource");
return;
}
@ -70,7 +70,7 @@ void COutputPowerProtocol::onGetOutputPower(CZwlrOutputPowerManagerV1* pMgr, uin
const auto CLIENT = pMgr->client();
const auto RESOURCE = m_vOutputPowers.emplace_back(std::make_unique<COutputPower>(makeShared<CZwlrOutputPowerV1>(CLIENT, pMgr->version(), id), OUTPUT->monitor.lock())).get();
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vOutputPowers.pop_back();
return;

View file

@ -10,7 +10,7 @@
CPointerConstraint::CPointerConstraint(SP<CZwpLockedPointerV1> resource_, SP<CWLSurfaceResource> surf, wl_resource* region_, zwpPointerConstraintsV1Lifetime lifetime_) :
resourceL(resource_), locked(true), lifetime(lifetime_) {
if (!resource_->resource())
if UNLIKELY (!resource_->resource())
return;
resource_->setOnDestroy([this](CZwpLockedPointerV1* p) { PROTO::constraints->destroyPointerConstraint(this); });
@ -49,7 +49,7 @@ CPointerConstraint::CPointerConstraint(SP<CZwpLockedPointerV1> resource_, SP<CWL
CPointerConstraint::CPointerConstraint(SP<CZwpConfinedPointerV1> resource_, SP<CWLSurfaceResource> surf, wl_resource* region_, zwpPointerConstraintsV1Lifetime lifetime_) :
resourceC(resource_), lifetime(lifetime_) {
if (!resource_->resource())
if UNLIKELY (!resource_->resource())
return;
resource_->setOnDestroy([this](CZwpConfinedPointerV1* p) { PROTO::constraints->destroyPointerConstraint(this); });
@ -185,7 +185,7 @@ bool CPointerConstraint::isLocked() {
}
Vector2D CPointerConstraint::logicPositionHint() {
if (!pHLSurface)
if UNLIKELY (!pHLSurface)
return {};
const auto SURFBOX = pHLSurface->getSurfaceBoxGlobal();
@ -218,14 +218,14 @@ void CPointerConstraintsProtocol::destroyPointerConstraint(CPointerConstraint* h
}
void CPointerConstraintsProtocol::onNewConstraint(SP<CPointerConstraint> constraint, CZwpPointerConstraintsV1* pMgr) {
if (!constraint->good()) {
if UNLIKELY (!constraint->good()) {
LOGM(ERR, "Couldn't create constraint??");
pMgr->noMemory();
m_vConstraints.pop_back();
return;
}
if (!constraint->owner()) {
if UNLIKELY (!constraint->owner()) {
LOGM(ERR, "New constraint has no CWLSurface owner??");
return;
}
@ -234,7 +234,7 @@ void CPointerConstraintsProtocol::onNewConstraint(SP<CPointerConstraint> constra
const auto DUPES = std::count_if(m_vConstraints.begin(), m_vConstraints.end(), [OWNER](const auto& c) { return c->owner() == OWNER; });
if (DUPES > 1) {
if UNLIKELY (DUPES > 1) {
LOGM(ERR, "Constraint for surface duped");
pMgr->error(ZWP_POINTER_CONSTRAINTS_V1_ERROR_ALREADY_CONSTRAINED, "Surface already confined");
m_vConstraints.pop_back();

View file

@ -4,7 +4,7 @@
#include "core/Compositor.hpp"
CPointerGestureSwipe::CPointerGestureSwipe(SP<CZwpPointerGestureSwipeV1> resource_) : resource(resource_) {
if (!resource->resource())
if UNLIKELY (!resource->resource())
return;
resource->setOnDestroy([this](CZwpPointerGestureSwipeV1* p) { PROTO::pointerGestures->onGestureDestroy(this); });
@ -16,7 +16,7 @@ bool CPointerGestureSwipe::good() {
}
CPointerGestureHold::CPointerGestureHold(SP<CZwpPointerGestureHoldV1> resource_) : resource(resource_) {
if (!resource->resource())
if UNLIKELY (!resource->resource())
return;
resource->setOnDestroy([this](CZwpPointerGestureHoldV1* p) { PROTO::pointerGestures->onGestureDestroy(this); });
@ -28,7 +28,7 @@ bool CPointerGestureHold::good() {
}
CPointerGesturePinch::CPointerGesturePinch(SP<CZwpPointerGesturePinchV1> resource_) : resource(resource_) {
if (!resource->resource())
if UNLIKELY (!resource->resource())
return;
resource->setOnDestroy([this](CZwpPointerGesturePinchV1* p) { PROTO::pointerGestures->onGestureDestroy(this); });
@ -73,7 +73,7 @@ void CPointerGesturesProtocol::onGetPinchGesture(CZwpPointerGesturesV1* pMgr, ui
const auto CLIENT = pMgr->client();
const auto RESOURCE = m_vPinches.emplace_back(std::make_unique<CPointerGesturePinch>(makeShared<CZwpPointerGesturePinchV1>(CLIENT, pMgr->version(), id))).get();
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
LOGM(ERR, "Couldn't create gesture");
return;
@ -84,7 +84,7 @@ void CPointerGesturesProtocol::onGetSwipeGesture(CZwpPointerGesturesV1* pMgr, ui
const auto CLIENT = pMgr->client();
const auto RESOURCE = m_vSwipes.emplace_back(std::make_unique<CPointerGestureSwipe>(makeShared<CZwpPointerGestureSwipeV1>(CLIENT, pMgr->version(), id))).get();
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
LOGM(ERR, "Couldn't create gesture");
return;
@ -95,7 +95,7 @@ void CPointerGesturesProtocol::onGetHoldGesture(CZwpPointerGesturesV1* pMgr, uin
const auto CLIENT = pMgr->client();
const auto RESOURCE = m_vHolds.emplace_back(std::make_unique<CPointerGestureHold>(makeShared<CZwpPointerGestureHoldV1>(CLIENT, pMgr->version(), id))).get();
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
LOGM(ERR, "Couldn't create gesture");
return;

View file

@ -27,7 +27,7 @@ void CQueuedPresentationData::discarded() {
}
CPresentationFeedback::CPresentationFeedback(SP<CWpPresentationFeedback> resource_, SP<CWLSurfaceResource> surf) : resource(resource_), surface(surf) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWpPresentationFeedback* pMgr) {
@ -43,8 +43,8 @@ bool CPresentationFeedback::good() {
void CPresentationFeedback::sendQueued(SP<CQueuedPresentationData> data, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags) {
auto client = resource->client();
if (PROTO::outputs.contains(data->pMonitor->szName)) {
if (auto outputResource = PROTO::outputs.at(data->pMonitor->szName)->outputResourceFrom(client); outputResource)
if LIKELY (PROTO::outputs.contains(data->pMonitor->szName)) {
if LIKELY (auto outputResource = PROTO::outputs.at(data->pMonitor->szName)->outputResourceFrom(client); outputResource)
resource->sendSyncOutput(outputResource->getResource()->resource());
}
@ -100,7 +100,7 @@ void CPresentationProtocol::onGetFeedback(CWpPresentation* pMgr, wl_resource* su
m_vFeedbacks.emplace_back(makeShared<CPresentationFeedback>(makeShared<CWpPresentationFeedback>(CLIENT, pMgr->version(), id), CWLSurfaceResource::fromResource(surf)))
.get();
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vFeedbacks.pop_back();
return;

View file

@ -5,7 +5,7 @@
#include "../config/ConfigValue.hpp"
CPrimarySelectionOffer::CPrimarySelectionOffer(SP<CZwpPrimarySelectionOfferV1> resource_, SP<IDataSource> source_) : source(source_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CZwpPrimarySelectionOfferV1* r) { PROTO::primarySelection->destroyResource(this); });
@ -35,7 +35,7 @@ bool CPrimarySelectionOffer::good() {
}
void CPrimarySelectionOffer::sendData() {
if (!source)
if UNLIKELY (!source)
return;
for (auto const& m : source->mimes()) {
@ -44,7 +44,7 @@ void CPrimarySelectionOffer::sendData() {
}
CPrimarySelectionSource::CPrimarySelectionSource(SP<CZwpPrimarySelectionSourceV1> resource_, SP<CPrimarySelectionDevice> device_) : device(device_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setData(this);
@ -105,7 +105,7 @@ void CPrimarySelectionSource::error(uint32_t code, const std::string& msg) {
}
CPrimarySelectionDevice::CPrimarySelectionDevice(SP<CZwpPrimarySelectionDeviceV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
pClient = resource->client();
@ -159,7 +159,7 @@ void CPrimarySelectionDevice::sendSelection(SP<CPrimarySelectionOffer> selection
}
CPrimarySelectionManager::CPrimarySelectionManager(SP<CZwpPrimarySelectionDeviceManagerV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CZwpPrimarySelectionDeviceManagerV1* r) { PROTO::primarySelection->destroyResource(this); });
@ -168,7 +168,7 @@ CPrimarySelectionManager::CPrimarySelectionManager(SP<CZwpPrimarySelectionDevice
const auto RESOURCE =
PROTO::primarySelection->m_vDevices.emplace_back(makeShared<CPrimarySelectionDevice>(makeShared<CZwpPrimarySelectionDeviceV1>(r->client(), r->version(), id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::primarySelection->m_vDevices.pop_back();
return;
@ -192,7 +192,7 @@ CPrimarySelectionManager::CPrimarySelectionManager(SP<CZwpPrimarySelectionDevice
const auto RESOURCE = PROTO::primarySelection->m_vSources.emplace_back(
makeShared<CPrimarySelectionSource>(makeShared<CZwpPrimarySelectionSourceV1>(r->client(), r->version(), id), device.lock()));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::primarySelection->m_vSources.pop_back();
return;
@ -220,7 +220,7 @@ CPrimarySelectionProtocol::CPrimarySelectionProtocol(const wl_interface* iface,
void CPrimarySelectionProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CPrimarySelectionManager>(makeShared<CZwpPrimarySelectionDeviceManagerV1>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;

View file

@ -4,7 +4,7 @@
#include <algorithm>
CRelativePointer::CRelativePointer(SP<CZwpRelativePointerV1> resource_) : resource(resource_) {
if (!resource_->resource())
if UNLIKELY (!resource_->resource())
return;
pClient = resource->client();
@ -50,7 +50,7 @@ void CRelativePointerProtocol::onGetRelativePointer(CZwpRelativePointerManagerV1
const auto CLIENT = pMgr->client();
const auto RESOURCE = m_vRelativePointers.emplace_back(std::make_unique<CRelativePointer>(makeShared<CZwpRelativePointerV1>(CLIENT, pMgr->version(), id))).get();
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vRelativePointers.pop_back();
return;

View file

@ -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); });

View file

@ -49,7 +49,7 @@ void CSecurityContextSandboxedClient::onDestroy() {
}
CSecurityContext::CSecurityContext(SP<CWpSecurityContextV1> resource_, int listenFD_, int closeFD_) : listenFD(listenFD_), closeFD(closeFD_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CWpSecurityContextV1* r) {
@ -64,12 +64,12 @@ CSecurityContext::CSecurityContext(SP<CWpSecurityContextV1> resource_, int liste
LOGM(LOG, "New security_context at 0x{:x}", (uintptr_t)this);
resource->setSetSandboxEngine([this](CWpSecurityContextV1* r, const char* engine) {
if (!sandboxEngine.empty()) {
if UNLIKELY (!sandboxEngine.empty()) {
r->error(WP_SECURITY_CONTEXT_V1_ERROR_ALREADY_SET, "Sandbox engine already set");
return;
}
if (committed) {
if UNLIKELY (committed) {
r->error(WP_SECURITY_CONTEXT_V1_ERROR_ALREADY_USED, "Context already committed");
return;
}
@ -79,12 +79,12 @@ CSecurityContext::CSecurityContext(SP<CWpSecurityContextV1> resource_, int liste
});
resource->setSetAppId([this](CWpSecurityContextV1* r, const char* appid) {
if (!appID.empty()) {
if UNLIKELY (!appID.empty()) {
r->error(WP_SECURITY_CONTEXT_V1_ERROR_ALREADY_SET, "Sandbox appid already set");
return;
}
if (committed) {
if UNLIKELY (committed) {
r->error(WP_SECURITY_CONTEXT_V1_ERROR_ALREADY_USED, "Context already committed");
return;
}
@ -94,12 +94,12 @@ CSecurityContext::CSecurityContext(SP<CWpSecurityContextV1> resource_, int liste
});
resource->setSetInstanceId([this](CWpSecurityContextV1* r, const char* instance) {
if (!instanceID.empty()) {
if UNLIKELY (!instanceID.empty()) {
r->error(WP_SECURITY_CONTEXT_V1_ERROR_ALREADY_SET, "Sandbox instance already set");
return;
}
if (committed) {
if UNLIKELY (committed) {
r->error(WP_SECURITY_CONTEXT_V1_ERROR_ALREADY_USED, "Context already committed");
return;
}
@ -135,7 +135,7 @@ bool CSecurityContext::good() {
}
void CSecurityContext::onListen(uint32_t mask) {
if (mask & (WL_EVENT_HANGUP | WL_EVENT_ERROR)) {
if UNLIKELY (mask & (WL_EVENT_HANGUP | WL_EVENT_ERROR)) {
LOGM(ERR, "security_context at 0x{:x} got an error in listen", (uintptr_t)this);
PROTO::securityContext->destroyContext(this);
return;
@ -145,13 +145,13 @@ void CSecurityContext::onListen(uint32_t mask) {
return;
int clientFD = accept(listenFD, nullptr, nullptr);
if (clientFD < 0) {
if UNLIKELY (clientFD < 0) {
LOGM(ERR, "security_context at 0x{:x} couldn't accept", (uintptr_t)this);
return;
}
auto newClient = CSecurityContextSandboxedClient::create(clientFD);
if (!newClient) {
if UNLIKELY (!newClient) {
LOGM(ERR, "security_context at 0x{:x} couldn't create a client", (uintptr_t)this);
close(clientFD);
return;
@ -170,7 +170,7 @@ void CSecurityContext::onClose(uint32_t mask) {
}
CSecurityContextManagerResource::CSecurityContextManagerResource(SP<CWpSecurityContextManagerV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CWpSecurityContextManagerV1* r) { PROTO::securityContext->destroyResource(this); });
@ -180,7 +180,7 @@ CSecurityContextManagerResource::CSecurityContextManagerResource(SP<CWpSecurityC
const auto RESOURCE =
PROTO::securityContext->m_vContexts.emplace_back(makeShared<CSecurityContext>(makeShared<CWpSecurityContextV1>(r->client(), r->version(), id), lfd, cfd));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::securityContext->m_vContexts.pop_back();
return;
@ -199,7 +199,7 @@ CSecurityContextProtocol::CSecurityContextProtocol(const wl_interface* iface, co
void CSecurityContextProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CSecurityContextManagerResource>(makeShared<CWpSecurityContextManagerV1>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;

View file

@ -2,7 +2,7 @@
#include "core/Compositor.hpp"
CServerDecorationKDE::CServerDecorationKDE(SP<COrgKdeKwinServerDecoration> resource_, SP<CWLSurfaceResource> surf) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setRelease([this](COrgKdeKwinServerDecoration* pMgr) { PROTO::serverDecorationKDE->destroyResource(this); });
@ -44,7 +44,7 @@ void CServerDecorationKDEProtocol::createDecoration(COrgKdeKwinServerDecorationM
m_vDecos.emplace_back(std::make_unique<CServerDecorationKDE>(makeShared<COrgKdeKwinServerDecoration>(CLIENT, pMgr->version(), id), CWLSurfaceResource::fromResource(surf)))
.get();
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vDecos.pop_back();
return;

View file

@ -8,7 +8,7 @@
CSessionLockSurface::CSessionLockSurface(SP<CExtSessionLockSurfaceV1> resource_, SP<CWLSurfaceResource> surface_, PHLMONITOR pMonitor_, WP<CSessionLock> owner_) :
resource(resource_), sessionLock(owner_), pSurface(surface_), pMonitor(pMonitor_) {
if (!resource->resource())
if UNLIKELY (!resource->resource())
return;
resource->setDestroy([this](CExtSessionLockSurfaceV1* r) {
@ -92,7 +92,7 @@ SP<CWLSurfaceResource> CSessionLockSurface::surface() {
}
CSessionLock::CSessionLock(SP<CExtSessionLockV1> resource_) : resource(resource_) {
if (!resource->resource())
if UNLIKELY (!resource->resource())
return;
resource->setDestroy([this](CExtSessionLockV1* r) { PROTO::sessionLock->destroyResource(this); });
@ -170,7 +170,7 @@ void CSessionLockProtocol::onLock(CExtSessionLockManagerV1* pMgr, uint32_t id) {
const auto CLIENT = pMgr->client();
const auto RESOURCE = m_vLocks.emplace_back(makeShared<CSessionLock>(makeShared<CExtSessionLockV1>(CLIENT, pMgr->version(), id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vLocks.pop_back();
return;
@ -198,7 +198,7 @@ void CSessionLockProtocol::onGetLockSurface(CExtSessionLockV1* lock, uint32_t id
const auto RESOURCE =
m_vLockSurfaces.emplace_back(makeShared<CSessionLockSurface>(makeShared<CExtSessionLockSurfaceV1>(lock->client(), lock->version(), id), PSURFACE, PMONITOR, sessionLock));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
lock->noMemory();
m_vLockSurfaces.pop_back();
return;

View file

@ -4,7 +4,7 @@
#include "core/Compositor.hpp"
CKeyboardShortcutsInhibitor::CKeyboardShortcutsInhibitor(SP<CZwpKeyboardShortcutsInhibitorV1> resource_, SP<CWLSurfaceResource> surf) : resource(resource_), pSurface(surf) {
if (!resource->resource())
if UNLIKELY (!resource->resource())
return;
resource->setDestroy([this](CZwpKeyboardShortcutsInhibitorV1* pMgr) { PROTO::shortcutsInhibit->destroyInhibitor(this); });
@ -49,7 +49,7 @@ void CKeyboardShortcutsInhibitProtocol::onInhibit(CZwpKeyboardShortcutsInhibitMa
const auto CLIENT = pMgr->client();
for (auto const& in : m_vInhibitors) {
if (in->surface() != surf)
if LIKELY (in->surface() != surf)
continue;
pMgr->error(ZWP_KEYBOARD_SHORTCUTS_INHIBIT_MANAGER_V1_ERROR_ALREADY_INHIBITED, "Already inhibited for surface resource");
@ -59,7 +59,7 @@ void CKeyboardShortcutsInhibitProtocol::onInhibit(CZwpKeyboardShortcutsInhibitMa
const auto RESOURCE =
m_vInhibitors.emplace_back(std::make_unique<CKeyboardShortcutsInhibitor>(makeShared<CZwpKeyboardShortcutsInhibitorV1>(CLIENT, pMgr->version(), id), surf)).get();
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vInhibitors.pop_back();
LOGM(ERR, "Failed to create an inhibitor resource");

View file

@ -63,7 +63,7 @@ bool CSinglePixelBuffer::good() {
CSinglePixelBufferResource::CSinglePixelBufferResource(uint32_t id, wl_client* client, CHyprColor color) {
buffer = makeShared<CSinglePixelBuffer>(id, client, color);
if (!buffer->good())
if UNLIKELY (!buffer->good())
return;
buffer->resource->buffer = buffer;
@ -83,7 +83,7 @@ bool CSinglePixelBufferResource::good() {
}
CSinglePixelBufferManagerResource::CSinglePixelBufferManagerResource(SP<CWpSinglePixelBufferManagerV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CWpSinglePixelBufferManagerV1* r) { PROTO::singlePixel->destroyResource(this); });
@ -94,7 +94,7 @@ CSinglePixelBufferManagerResource::CSinglePixelBufferManagerResource(SP<CWpSingl
a / (float)std::numeric_limits<uint32_t>::max()};
const auto RESOURCE = PROTO::singlePixel->m_vBuffers.emplace_back(makeShared<CSinglePixelBufferResource>(id, resource->client(), color));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
res->noMemory();
PROTO::singlePixel->m_vBuffers.pop_back();
return;
@ -113,7 +113,7 @@ CSinglePixelProtocol::CSinglePixelProtocol(const wl_interface* iface, const int&
void CSinglePixelProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CSinglePixelBufferManagerResource>(makeShared<CWpSinglePixelBufferManagerV1>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;

View file

@ -9,7 +9,7 @@
#include <cstring>
CTabletPadStripV2Resource::CTabletPadStripV2Resource(SP<CZwpTabletPadStripV2> resource_, uint32_t id_) : id(id_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CZwpTabletPadStripV2* r) { PROTO::tablet->destroyResource(this); });
@ -21,7 +21,7 @@ bool CTabletPadStripV2Resource::good() {
}
CTabletPadRingV2Resource::CTabletPadRingV2Resource(SP<CZwpTabletPadRingV2> resource_, uint32_t id_) : id(id_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CZwpTabletPadRingV2* r) { PROTO::tablet->destroyResource(this); });
@ -33,7 +33,7 @@ bool CTabletPadRingV2Resource::good() {
}
CTabletPadGroupV2Resource::CTabletPadGroupV2Resource(SP<CZwpTabletPadGroupV2> resource_, size_t idx_) : idx(idx_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CZwpTabletPadGroupV2* r) { PROTO::tablet->destroyResource(this); });
@ -58,7 +58,7 @@ void CTabletPadGroupV2Resource::sendData(SP<CTabletPad> pad, SP<Aquamarine::ITab
const auto RESOURCE =
PROTO::tablet->m_vStrips.emplace_back(makeShared<CTabletPadStripV2Resource>(makeShared<CZwpTabletPadStripV2>(resource->client(), resource->version(), 0), i));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
resource->noMemory();
PROTO::tablet->m_vStrips.pop_back();
return;
@ -71,7 +71,7 @@ void CTabletPadGroupV2Resource::sendData(SP<CTabletPad> pad, SP<Aquamarine::ITab
const auto RESOURCE =
PROTO::tablet->m_vRings.emplace_back(makeShared<CTabletPadRingV2Resource>(makeShared<CZwpTabletPadRingV2>(resource->client(), resource->version(), 0), i));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
resource->noMemory();
PROTO::tablet->m_vRings.pop_back();
return;
@ -84,7 +84,7 @@ void CTabletPadGroupV2Resource::sendData(SP<CTabletPad> pad, SP<Aquamarine::ITab
}
CTabletPadV2Resource::CTabletPadV2Resource(SP<CZwpTabletPadV2> resource_, SP<CTabletPad> pad_, SP<CTabletSeat> seat_) : pad(pad_), seat(seat_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CZwpTabletPadV2* r) { PROTO::tablet->destroyResource(this); });
@ -114,7 +114,7 @@ void CTabletPadV2Resource::createGroup(SP<Aquamarine::ITabletPad::STabletPadGrou
const auto RESOURCE =
PROTO::tablet->m_vGroups.emplace_back(makeShared<CTabletPadGroupV2Resource>(makeShared<CZwpTabletPadGroupV2>(resource->client(), resource->version(), 0), idx));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
resource->noMemory();
PROTO::tablet->m_vGroups.pop_back();
return;
@ -126,7 +126,7 @@ void CTabletPadV2Resource::createGroup(SP<Aquamarine::ITabletPad::STabletPadGrou
}
CTabletV2Resource::CTabletV2Resource(SP<CZwpTabletV2> resource_, SP<CTablet> tablet_, SP<CTabletSeat> seat_) : tablet(tablet_), seat(seat_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CZwpTabletV2* r) { PROTO::tablet->destroyResource(this); });
@ -149,7 +149,7 @@ void CTabletV2Resource::sendData() {
}
CTabletToolV2Resource::CTabletToolV2Resource(SP<CZwpTabletToolV2> resource_, SP<CTabletTool> tool_, SP<CTabletSeat> seat_) : tool(tool_), seat(seat_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CZwpTabletToolV2* r) { PROTO::tablet->destroyResource(this); });
@ -228,7 +228,7 @@ void CTabletToolV2Resource::sendFrame(bool removeSource) {
}
CTabletSeat::CTabletSeat(SP<CZwpTabletSeatV2> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CZwpTabletSeatV2* r) { PROTO::tablet->destroyResource(this); });
@ -243,7 +243,7 @@ void CTabletSeat::sendTool(SP<CTabletTool> tool) {
const auto RESOURCE =
PROTO::tablet->m_vTools.emplace_back(makeShared<CTabletToolV2Resource>(makeShared<CZwpTabletToolV2>(resource->client(), resource->version(), 0), tool, self.lock()));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
resource->noMemory();
PROTO::tablet->m_vTools.pop_back();
return;
@ -259,7 +259,7 @@ void CTabletSeat::sendPad(SP<CTabletPad> pad) {
const auto RESOURCE =
PROTO::tablet->m_vPads.emplace_back(makeShared<CTabletPadV2Resource>(makeShared<CZwpTabletPadV2>(resource->client(), resource->version(), 0), pad, self.lock()));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
resource->noMemory();
PROTO::tablet->m_vPads.pop_back();
return;
@ -275,7 +275,7 @@ void CTabletSeat::sendTablet(SP<CTablet> tablet) {
const auto RESOURCE =
PROTO::tablet->m_vTablets.emplace_back(makeShared<CTabletV2Resource>(makeShared<CZwpTabletV2>(resource->client(), resource->version(), 0), tablet, self.lock()));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
resource->noMemory();
PROTO::tablet->m_vTablets.pop_back();
return;
@ -357,7 +357,7 @@ void CTabletV2Protocol::destroyResource(CTabletPadStripV2Resource* resource) {
void CTabletV2Protocol::onGetSeat(CZwpTabletManagerV2* pMgr, uint32_t id, wl_resource* seat) {
const auto RESOURCE = m_vSeats.emplace_back(makeShared<CTabletSeat>(makeShared<CZwpTabletSeatV2>(pMgr->client(), pMgr->version(), id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vSeats.pop_back();
return;

View file

@ -27,7 +27,7 @@ void CTearingControlProtocol::onManagerResourceDestroy(wl_resource* res) {
void CTearingControlProtocol::onGetController(wl_client* client, CWpTearingControlManagerV1* pMgr, uint32_t id, SP<CWLSurfaceResource> surf) {
const auto CONTROLLER = m_vTearingControllers.emplace_back(std::make_unique<CTearingControl>(makeShared<CWpTearingControlV1>(client, pMgr->version(), id), surf)).get();
if (!CONTROLLER->good()) {
if UNLIKELY (!CONTROLLER->good()) {
pMgr->noMemory();
m_vTearingControllers.pop_back();
return;
@ -67,7 +67,7 @@ void CTearingControl::onHint(wpTearingControlV1PresentationHint hint_) {
}
void CTearingControl::updateWindow() {
if (pWindow.expired())
if UNLIKELY (pWindow.expired())
return;
pWindow->m_bTearingHint = hint == WP_TEARING_CONTROL_V1_PRESENTATION_HINT_ASYNC;

View file

@ -7,13 +7,13 @@ CTextInputV1::~CTextInputV1() {
}
CTextInputV1::CTextInputV1(SP<CZwpTextInputV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CZwpTextInputV1* pMgr) { PROTO::textInputV1->destroyResource(this); });
resource->setActivate([this](CZwpTextInputV1* pMgr, wl_resource* seat, wl_resource* surface) {
if (!surface) {
if UNLIKELY (!surface) {
LOGM(WARN, "Text-input-v1 PTI{:x}: No surface to activate text input on!", (uintptr_t)this);
return;
}
@ -105,7 +105,7 @@ void CTextInputV1Protocol::bindManager(wl_client* client, void* data, uint32_t v
const auto PTI = m_vClients.emplace_back(makeShared<CTextInputV1>(makeShared<CZwpTextInputV1>(pMgr->client(), pMgr->version(), id)));
LOGM(LOG, "New TI V1 at {:x}", (uintptr_t)PTI.get());
if (!PTI->good()) {
if UNLIKELY (!PTI->good()) {
LOGM(ERR, "Could not alloc wl_resource for TIV1");
pMgr->noMemory();
PROTO::textInputV1->destroyResource(PTI.get());

View file

@ -10,7 +10,7 @@ void CTextInputV3::SState::reset() {
}
CTextInputV3::CTextInputV3(SP<CZwpTextInputV3> resource_) : resource(resource_) {
if (!resource->resource())
if UNLIKELY (!resource->resource())
return;
LOGM(LOG, "New tiv3 at {:016x}", (uintptr_t)this);
@ -129,7 +129,7 @@ void CTextInputV3Protocol::onGetTextInput(CZwpTextInputManagerV3* pMgr, uint32_t
const auto CLIENT = pMgr->client();
const auto RESOURCE = m_vTextInputs.emplace_back(makeShared<CTextInputV3>(makeShared<CZwpTextInputV3>(CLIENT, pMgr->version(), id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vTextInputs.pop_back();
LOGM(ERR, "Failed to create a tiv3 resource");

View file

@ -13,7 +13,7 @@
#include <algorithm>
CToplevelExportClient::CToplevelExportClient(SP<CHyprlandToplevelExportManagerV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CHyprlandToplevelExportManagerV1* pMgr) { PROTO::toplevelExport->destroyResource(this); });
@ -35,7 +35,7 @@ void CToplevelExportClient::captureToplevel(CHyprlandToplevelExportManagerV1* pM
const auto FRAME = PROTO::toplevelExport->m_vFrames.emplace_back(
makeShared<CToplevelExportFrame>(makeShared<CHyprlandToplevelExportFrameV1>(resource->client(), resource->version(), frame), overlayCursor_, handle));
if (!FRAME->good()) {
if UNLIKELY (!FRAME->good()) {
LOGM(ERR, "Couldn't alloc frame for sharing! (no memory)");
resource->noMemory();
PROTO::toplevelExport->destroyResource(FRAME.get());
@ -78,19 +78,19 @@ CToplevelExportFrame::~CToplevelExportFrame() {
}
CToplevelExportFrame::CToplevelExportFrame(SP<CHyprlandToplevelExportFrameV1> resource_, int32_t overlayCursor_, PHLWINDOW pWindow_) : resource(resource_), pWindow(pWindow_) {
if (!good())
if UNLIKELY (!good())
return;
cursorOverlayRequested = !!overlayCursor_;
if (!pWindow) {
if UNLIKELY (!pWindow) {
LOGM(ERR, "Client requested sharing of window handle {:x} which does not exist!", pWindow);
resource->sendFailed();
PROTO::toplevelExport->destroyResource(this);
return;
}
if (!pWindow->m_bIsMapped) {
if UNLIKELY (!pWindow->m_bIsMapped) {
LOGM(ERR, "Client requested sharing of window handle {:x} which is not shareable!", pWindow);
resource->sendFailed();
PROTO::toplevelExport->destroyResource(this);
@ -106,7 +106,7 @@ CToplevelExportFrame::CToplevelExportFrame(SP<CHyprlandToplevelExportFrameV1> re
g_pHyprRenderer->makeEGLCurrent();
shmFormat = g_pHyprOpenGL->getPreferredReadFormat(PMONITOR);
if (shmFormat == DRM_FORMAT_INVALID) {
if UNLIKELY (shmFormat == DRM_FORMAT_INVALID) {
LOGM(ERR, "No format supported by renderer in capture toplevel");
resource->sendFailed();
PROTO::toplevelExport->destroyResource(this);
@ -114,7 +114,7 @@ CToplevelExportFrame::CToplevelExportFrame(SP<CHyprlandToplevelExportFrameV1> re
}
const auto PSHMINFO = NFormatUtils::getPixelFormatFromDRM(shmFormat);
if (!PSHMINFO) {
if UNLIKELY (!PSHMINFO) {
LOGM(ERR, "No pixel format supported by renderer in capture toplevel");
resource->sendFailed();
PROTO::toplevelExport->destroyResource(this);
@ -131,27 +131,26 @@ CToplevelExportFrame::CToplevelExportFrame(SP<CHyprlandToplevelExportFrameV1> re
resource->sendBuffer(NFormatUtils::drmToShm(shmFormat), box.width, box.height, shmStride);
if (dmabufFormat != DRM_FORMAT_INVALID) {
if LIKELY (dmabufFormat != DRM_FORMAT_INVALID)
resource->sendLinuxDmabuf(dmabufFormat, box.width, box.height);
}
resource->sendBufferDone();
}
void CToplevelExportFrame::copy(CHyprlandToplevelExportFrameV1* pFrame, wl_resource* buffer_, int32_t ignoreDamage) {
if (!good()) {
if UNLIKELY (!good()) {
LOGM(ERR, "No frame in copyFrame??");
return;
}
if (!validMapped(pWindow)) {
if UNLIKELY (!validMapped(pWindow)) {
LOGM(ERR, "Client requested sharing of window handle {:x} which is gone!", pWindow);
resource->sendFailed();
PROTO::toplevelExport->destroyResource(this);
return;
}
if (!pWindow->m_bIsMapped) {
if UNLIKELY (!pWindow->m_bIsMapped) {
LOGM(ERR, "Client requested sharing of window handle {:x} which is not shareable (2)!", pWindow);
resource->sendFailed();
PROTO::toplevelExport->destroyResource(this);
@ -159,7 +158,7 @@ void CToplevelExportFrame::copy(CHyprlandToplevelExportFrameV1* pFrame, wl_resou
}
const auto PBUFFER = CWLBufferResource::fromResource(buffer_);
if (!PBUFFER) {
if UNLIKELY (!PBUFFER) {
resource->error(HYPRLAND_TOPLEVEL_EXPORT_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer");
PROTO::toplevelExport->destroyResource(this);
return;
@ -167,13 +166,13 @@ void CToplevelExportFrame::copy(CHyprlandToplevelExportFrameV1* pFrame, wl_resou
PBUFFER->buffer->lock();
if (PBUFFER->buffer->size != box.size()) {
if UNLIKELY (PBUFFER->buffer->size != box.size()) {
resource->error(HYPRLAND_TOPLEVEL_EXPORT_FRAME_V1_ERROR_INVALID_BUFFER, "invalid buffer dimensions");
PROTO::toplevelExport->destroyResource(this);
return;
}
if (buffer) {
if UNLIKELY (buffer) {
resource->error(HYPRLAND_TOPLEVEL_EXPORT_FRAME_V1_ERROR_ALREADY_USED, "frame already used");
PROTO::toplevelExport->destroyResource(this);
return;

View file

@ -3,14 +3,14 @@
#include <algorithm>
CViewportResource::CViewportResource(SP<CWpViewport> resource_, SP<CWLSurfaceResource> surface_) : surface(surface_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CWpViewport* r) { PROTO::viewport->destroyResource(this); });
resource->setOnDestroy([this](CWpViewport* r) { PROTO::viewport->destroyResource(this); });
resource->setSetDestination([this](CWpViewport* r, int32_t x, int32_t y) {
if (!surface) {
if UNLIKELY (!surface) {
r->error(WP_VIEWPORT_ERROR_NO_SURFACE, "Surface is gone");
return;
}
@ -20,7 +20,7 @@ CViewportResource::CViewportResource(SP<CWpViewport> resource_, SP<CWLSurfaceRes
return;
}
if (x <= 0 || y <= 0) {
if UNLIKELY (x <= 0 || y <= 0) {
r->error(WP_VIEWPORT_ERROR_BAD_SIZE, "Size was <= 0");
return;
}
@ -30,7 +30,7 @@ CViewportResource::CViewportResource(SP<CWpViewport> resource_, SP<CWLSurfaceRes
});
resource->setSetSource([this](CWpViewport* r, wl_fixed_t fx, wl_fixed_t fy, wl_fixed_t fw, wl_fixed_t fh) {
if (!surface) {
if UNLIKELY (!surface) {
r->error(WP_VIEWPORT_ERROR_NO_SURFACE, "Surface is gone");
return;
}
@ -42,7 +42,7 @@ CViewportResource::CViewportResource(SP<CWpViewport> resource_, SP<CWLSurfaceRes
return;
}
if (x < 0 || y < 0) {
if UNLIKELY (x < 0 || y < 0) {
r->error(WP_VIEWPORT_ERROR_BAD_SIZE, "Pos was < 0");
return;
}
@ -80,7 +80,7 @@ bool CViewportResource::good() {
}
CViewporterResource::CViewporterResource(SP<CWpViewporter> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CWpViewporter* r) { PROTO::viewport->destroyResource(this); });
@ -90,7 +90,7 @@ CViewporterResource::CViewporterResource(SP<CWpViewporter> resource_) : resource
const auto RESOURCE = PROTO::viewport->m_vViewports.emplace_back(
makeShared<CViewportResource>(makeShared<CWpViewport>(r->client(), r->version(), id), CWLSurfaceResource::fromResource(surf)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::viewport->m_vViewports.pop_back();
return;
@ -109,7 +109,7 @@ CViewporterProtocol::CViewporterProtocol(const wl_interface* iface, const int& v
void CViewporterProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CViewporterResource>(makeShared<CWpViewporter>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;

View file

@ -3,7 +3,7 @@
#include "../devices/IKeyboard.hpp"
CVirtualKeyboardV1Resource::CVirtualKeyboardV1Resource(SP<CZwpVirtualKeyboardV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CZwpVirtualKeyboardV1* r) {
@ -18,7 +18,7 @@ CVirtualKeyboardV1Resource::CVirtualKeyboardV1Resource(SP<CZwpVirtualKeyboardV1>
});
resource->setKey([this](CZwpVirtualKeyboardV1* r, uint32_t timeMs, uint32_t key, uint32_t state) {
if (!hasKeymap) {
if UNLIKELY (!hasKeymap) {
r->error(ZWP_VIRTUAL_KEYBOARD_V1_ERROR_NO_KEYMAP, "Key event received before a keymap was set");
return;
}
@ -37,7 +37,7 @@ CVirtualKeyboardV1Resource::CVirtualKeyboardV1Resource(SP<CZwpVirtualKeyboardV1>
});
resource->setModifiers([this](CZwpVirtualKeyboardV1* r, uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group) {
if (!hasKeymap) {
if UNLIKELY (!hasKeymap) {
r->error(ZWP_VIRTUAL_KEYBOARD_V1_ERROR_NO_KEYMAP, "Mods event received before a keymap was set");
return;
}
@ -52,7 +52,7 @@ CVirtualKeyboardV1Resource::CVirtualKeyboardV1Resource(SP<CZwpVirtualKeyboardV1>
resource->setKeymap([this](CZwpVirtualKeyboardV1* r, uint32_t fmt, int32_t fd, uint32_t len) {
auto xkbContext = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!xkbContext) {
if UNLIKELY (!xkbContext) {
LOGM(ERR, "xkbContext creation failed");
r->noMemory();
close(fd);
@ -60,7 +60,7 @@ CVirtualKeyboardV1Resource::CVirtualKeyboardV1Resource(SP<CZwpVirtualKeyboardV1>
}
auto keymapData = mmap(nullptr, len, PROT_READ, MAP_PRIVATE, fd, 0);
if (keymapData == MAP_FAILED) {
if UNLIKELY (keymapData == MAP_FAILED) {
LOGM(ERR, "keymapData alloc failed");
xkb_context_unref(xkbContext);
r->noMemory();
@ -71,7 +71,7 @@ CVirtualKeyboardV1Resource::CVirtualKeyboardV1Resource(SP<CZwpVirtualKeyboardV1>
auto xkbKeymap = xkb_keymap_new_from_string(xkbContext, (const char*)keymapData, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS);
munmap(keymapData, len);
if (!xkbKeymap) {
if UNLIKELY (!xkbKeymap) {
LOGM(ERR, "xkbKeymap creation failed");
xkb_context_unref(xkbContext);
r->noMemory();
@ -142,7 +142,7 @@ void CVirtualKeyboardProtocol::onCreateKeeb(CZwpVirtualKeyboardManagerV1* pMgr,
const auto RESOURCE = m_vKeyboards.emplace_back(makeShared<CVirtualKeyboardV1Resource>(makeShared<CZwpVirtualKeyboardV1>(pMgr->client(), pMgr->version(), id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vKeyboards.pop_back();
return;

View file

@ -2,7 +2,7 @@
#include "core/Output.hpp"
CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP<CZwlrVirtualPointerV1> resource_, PHLMONITORREF boundOutput_) : boundOutput(boundOutput_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CZwlrVirtualPointerV1* r) {
@ -41,7 +41,7 @@ CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP<CZwlrVirtualPointerV1> r
});
resource->setAxis([this](CZwlrVirtualPointerV1* r, uint32_t timeMs, uint32_t axis_, wl_fixed_t value) {
if (axis > WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
if UNLIKELY (axis > WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
r->error(ZWLR_VIRTUAL_POINTER_V1_ERROR_INVALID_AXIS, "Invalid axis");
return;
}
@ -64,7 +64,7 @@ CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP<CZwlrVirtualPointerV1> r
resource->setAxisSource([this](CZwlrVirtualPointerV1* r, uint32_t source) { axisEvents[axis].source = (wl_pointer_axis_source)source; });
resource->setAxisStop([this](CZwlrVirtualPointerV1* r, uint32_t timeMs, uint32_t axis_) {
if (axis > WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
if UNLIKELY (axis > WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
r->error(ZWLR_VIRTUAL_POINTER_V1_ERROR_INVALID_AXIS, "Invalid axis");
return;
}
@ -77,7 +77,7 @@ CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP<CZwlrVirtualPointerV1> r
});
resource->setAxisDiscrete([this](CZwlrVirtualPointerV1* r, uint32_t timeMs, uint32_t axis_, wl_fixed_t value, int32_t discrete) {
if (axis > WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
if UNLIKELY (axis > WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
r->error(ZWLR_VIRTUAL_POINTER_V1_ERROR_INVALID_AXIS, "Invalid axis");
return;
}
@ -138,7 +138,7 @@ void CVirtualPointerProtocol::onCreatePointer(CZwlrVirtualPointerManagerV1* pMgr
const auto RESOURCE = m_vPointers.emplace_back(makeShared<CVirtualPointerV1Resource>(makeShared<CZwlrVirtualPointerV1>(pMgr->client(), pMgr->version(), id), output));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vPointers.pop_back();
return;

View file

@ -20,7 +20,7 @@ void IWaylandProtocol::onDisplayDestroy() {
IWaylandProtocol::IWaylandProtocol(const wl_interface* iface, const int& ver, const std::string& name) :
m_szName(name), m_pGlobal(wl_global_create(g_pCompositor->m_sWLDisplay, iface, ver, this, &bindManagerInternal)) {
if (!m_pGlobal) {
if UNLIKELY (!m_pGlobal) {
LOGM(ERR, "could not create a global [{}]", m_szName);
return;
}

View file

@ -5,7 +5,7 @@
#include <algorithm>
CXDGActivationToken::CXDGActivationToken(SP<CXdgActivationTokenV1> resource_) : resource(resource_) {
if (!resource_->resource())
if UNLIKELY (!resource_->resource())
return;
resource->setDestroy([this](CXdgActivationTokenV1* r) { PROTO::activation->destroyToken(this); });
@ -18,7 +18,7 @@ CXDGActivationToken::CXDGActivationToken(SP<CXdgActivationTokenV1> resource_) :
resource->setCommit([this](CXdgActivationTokenV1* r) {
// TODO: should we send a protocol error of already_used here
// if it was used? the protocol spec doesn't say _when_ it should be sent...
if (committed) {
if UNLIKELY (committed) {
LOGM(WARN, "possible protocol error, two commits from one token. Ignoring.");
return;
}
@ -36,7 +36,7 @@ CXDGActivationToken::CXDGActivationToken(SP<CXdgActivationTokenV1> resource_) :
auto count = std::count_if(PROTO::activation->m_vSentTokens.begin(), PROTO::activation->m_vSentTokens.end(),
[this](const auto& other) { return other.client == resource->client(); });
if (count > 10) {
if UNLIKELY (count > 10) {
// remove first token. Too many, dear app.
for (auto i = PROTO::activation->m_vSentTokens.begin(); i != PROTO::activation->m_vSentTokens.end(); ++i) {
if (i->client == resource->client()) {
@ -70,7 +70,7 @@ void CXDGActivationProtocol::bindManager(wl_client* client, void* data, uint32_t
RESOURCE->setActivate([this](CXdgActivationV1* pMgr, const char* token, wl_resource* surface) {
auto TOKEN = std::find_if(m_vSentTokens.begin(), m_vSentTokens.end(), [token](const auto& t) { return t.token == token; });
if (TOKEN == m_vSentTokens.end()) {
if UNLIKELY (TOKEN == m_vSentTokens.end()) {
LOGM(WARN, "activate event for non-existent token {}??", token);
return;
}
@ -81,7 +81,7 @@ void CXDGActivationProtocol::bindManager(wl_client* client, void* data, uint32_t
SP<CWLSurfaceResource> surf = CWLSurfaceResource::fromResource(surface);
const auto PWINDOW = g_pCompositor->getWindowFromSurface(surf);
if (!PWINDOW) {
if UNLIKELY (!PWINDOW) {
LOGM(WARN, "activate event for non-window or gone surface with token {}, ignoring", token);
return;
}
@ -102,7 +102,7 @@ void CXDGActivationProtocol::onGetToken(CXdgActivationV1* pMgr, uint32_t id) {
const auto CLIENT = pMgr->client();
const auto RESOURCE = m_vTokens.emplace_back(std::make_unique<CXDGActivationToken>(makeShared<CXdgActivationTokenV1>(CLIENT, pMgr->version(), id))).get();
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vTokens.pop_back();
return;

View file

@ -2,7 +2,7 @@
#include <algorithm>
CXDGDecoration::CXDGDecoration(SP<CZxdgToplevelDecorationV1> resource_, wl_resource* toplevel) : resource(resource_), pToplevelResource(toplevel) {
if (!resource->resource())
if UNLIKELY (!resource->resource())
return;
resource->setDestroy([this](CZxdgToplevelDecorationV1* pMgr) { PROTO::xdgDecoration->destroyDecoration(this); });
@ -57,7 +57,7 @@ void CXDGDecorationProtocol::destroyDecoration(CXDGDecoration* decoration) {
}
void CXDGDecorationProtocol::onGetDecoration(CZxdgDecorationManagerV1* pMgr, uint32_t id, wl_resource* xdgToplevel) {
if (m_mDecorations.contains(xdgToplevel)) {
if UNLIKELY (m_mDecorations.contains(xdgToplevel)) {
pMgr->error(ZXDG_TOPLEVEL_DECORATION_V1_ERROR_ALREADY_CONSTRUCTED, "Decoration object already exists");
return;
}
@ -66,7 +66,7 @@ void CXDGDecorationProtocol::onGetDecoration(CZxdgDecorationManagerV1* pMgr, uin
const auto RESOURCE =
m_mDecorations.emplace(xdgToplevel, std::make_unique<CXDGDecoration>(makeShared<CZxdgToplevelDecorationV1>(CLIENT, pMgr->version(), id), xdgToplevel)).first->second.get();
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_mDecorations.erase(xdgToplevel);
return;

View file

@ -5,7 +5,7 @@
#include <algorithm>
CXDGDialogV1Resource::CXDGDialogV1Resource(SP<CXdgDialogV1> resource_, SP<CXDGToplevelResource> toplevel_) : resource(resource_), toplevel(toplevel_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CXdgDialogV1* r) { PROTO::xdgDialog->destroyResource(this); });
@ -23,11 +23,11 @@ CXDGDialogV1Resource::CXDGDialogV1Resource(SP<CXdgDialogV1> resource_, SP<CXDGTo
}
void CXDGDialogV1Resource::updateWindow() {
if (!toplevel || !toplevel->parent || !toplevel->parent->owner)
if UNLIKELY (!toplevel || !toplevel->parent || !toplevel->parent->owner)
return;
auto HLSurface = CWLSurface::fromResource(toplevel->parent->owner->surface.lock());
if (!HLSurface || !HLSurface->getWindow())
if UNLIKELY (!HLSurface || !HLSurface->getWindow())
return;
g_pCompositor->updateWindowAnimatedDecorationValues(HLSurface->getWindow());
@ -38,7 +38,7 @@ bool CXDGDialogV1Resource::good() {
}
CXDGWmDialogManagerResource::CXDGWmDialogManagerResource(SP<CXdgWmDialogV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CXdgWmDialogV1* r) { PROTO::xdgDialog->destroyResource(this); });
@ -46,14 +46,14 @@ CXDGWmDialogManagerResource::CXDGWmDialogManagerResource(SP<CXdgWmDialogV1> reso
resource->setGetXdgDialog([](CXdgWmDialogV1* r, uint32_t id, wl_resource* toplevel) {
auto tl = CXDGToplevelResource::fromResource(toplevel);
if (!tl) {
if UNLIKELY (!tl) {
r->error(-1, "Toplevel inert");
return;
}
const auto RESOURCE = PROTO::xdgDialog->m_vDialogs.emplace_back(makeShared<CXDGDialogV1Resource>(makeShared<CXdgDialogV1>(r->client(), r->version(), id), tl));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
return;
}
@ -73,7 +73,7 @@ CXDGDialogProtocol::CXDGDialogProtocol(const wl_interface* iface, const int& ver
void CXDGDialogProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CXDGWmDialogManagerResource>(makeShared<CXdgWmDialogV1>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
return;
}

View file

@ -23,7 +23,7 @@ void CXDGOutputProtocol::onOutputResourceDestroy(wl_resource* res) {
void CXDGOutputProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagerResources.emplace_back(std::make_unique<CZxdgOutputManagerV1>(client, ver, id)).get();
if (!RESOURCE->resource()) {
if UNLIKELY (!RESOURCE->resource()) {
LOGM(LOG, "Couldn't bind XDGOutputMgr");
wl_client_post_no_memory(client);
return;
@ -53,13 +53,13 @@ void CXDGOutputProtocol::onManagerGetXDGOutput(CZxdgOutputManagerV1* mgr, uint32
pXDGOutput->outputProto = OUTPUT->owner;
if (!pXDGOutput->resource->resource()) {
if UNLIKELY (!pXDGOutput->resource->resource()) {
m_vXDGOutputs.pop_back();
mgr->noMemory();
return;
}
if (!PMONITOR) {
if UNLIKELY (!PMONITOR) {
LOGM(ERR, "New xdg_output from client {:x} ({}) has no CMonitor?!", (uintptr_t)CLIENT, pXDGOutput->isXWayland ? "xwayland" : "not xwayland");
return;
}
@ -96,7 +96,7 @@ void CXDGOutputProtocol::updateAllOutputs() {
//
CXDGOutput::CXDGOutput(SP<CZxdgOutputV1> resource_, PHLMONITOR monitor_) : monitor(monitor_), resource(resource_) {
if (!resource->resource())
if UNLIKELY (!resource->resource())
return;
resource->setDestroy([](CZxdgOutputV1* pMgr) { PROTO::xdgOutput->onOutputResourceDestroy(pMgr->resource()); });
@ -106,7 +106,7 @@ CXDGOutput::CXDGOutput(SP<CZxdgOutputV1> resource_, PHLMONITOR monitor_) : monit
void CXDGOutput::sendDetails() {
static auto PXWLFORCESCALEZERO = CConfigValue<Hyprlang::INT>("xwayland:force_zero_scaling");
if (!monitor || !outputProto || outputProto->isDefunct())
if UNLIKELY (!monitor || !outputProto || outputProto->isDefunct())
return;
const auto POS = isXWayland ? monitor->vecXWaylandPosition : monitor->vecPosition;

View file

@ -26,7 +26,7 @@ void SXDGPositionerState::setGravity(xdgPositionerGravity edges) {
CXDGPopupResource::CXDGPopupResource(SP<CXdgPopup> resource_, SP<CXDGSurfaceResource> owner_, SP<CXDGSurfaceResource> surface_, SP<CXDGPositionerResource> positioner) :
surface(surface_), parent(owner_), resource(resource_), positionerRules(positioner) {
if (!good())
if UNLIKELY (!good())
return;
resource->setData(this);
@ -79,7 +79,7 @@ void CXDGPopupResource::applyPositioning(const CBox& box, const Vector2D& t1coor
configure(geometry);
if (lastRepositionToken)
if UNLIKELY (lastRepositionToken)
repositioned();
}
@ -118,7 +118,7 @@ void CXDGPopupResource::done() {
}
void CXDGPopupResource::repositioned() {
if (!lastRepositionToken)
if LIKELY (!lastRepositionToken)
return;
LOGM(LOG, "repositioned: sending reposition token {}", lastRepositionToken);
@ -128,7 +128,7 @@ void CXDGPopupResource::repositioned() {
}
CXDGToplevelResource::CXDGToplevelResource(SP<CXdgToplevel> resource_, SP<CXDGSurfaceResource> owner_) : owner(owner_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setData(this);
@ -350,7 +350,7 @@ Vector2D CXDGToplevelResource::layoutMaxSize() {
CXDGSurfaceResource::CXDGSurfaceResource(SP<CXdgSurface> resource_, SP<CXDGWMBase> owner_, SP<CWLSurfaceResource> surface_) :
owner(owner_), surface(surface_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setData(this);
@ -386,7 +386,7 @@ CXDGSurfaceResource::CXDGSurfaceResource(SP<CXdgSurface> resource_, SP<CXDGWMBas
if (toplevel)
toplevel->current = toplevel->pending;
if (initialCommit && surface->pending.texture) {
if UNLIKELY (initialCommit && surface->pending.texture) {
resource->error(-1, "Buffer attached before initial commit");
return;
}
@ -416,7 +416,7 @@ CXDGSurfaceResource::CXDGSurfaceResource(SP<CXdgSurface> resource_, SP<CXDGWMBas
resource->setGetToplevel([this](CXdgSurface* r, uint32_t id) {
const auto RESOURCE = PROTO::xdgShell->m_vToplevels.emplace_back(makeShared<CXDGToplevelResource>(makeShared<CXdgToplevel>(r->client(), r->version(), id), self.lock()));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::xdgShell->m_vToplevels.pop_back();
return;
@ -442,7 +442,7 @@ CXDGSurfaceResource::CXDGSurfaceResource(SP<CXdgSurface> resource_, SP<CXDGWMBas
const auto RESOURCE =
PROTO::xdgShell->m_vPopups.emplace_back(makeShared<CXDGPopupResource>(makeShared<CXdgPopup>(r->client(), r->version(), id), parent, self.lock(), positioner));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::xdgShell->m_vPopups.pop_back();
return;
@ -511,7 +511,7 @@ void CXDGSurfaceResource::configure() {
}
CXDGPositionerResource::CXDGPositionerResource(SP<CXdgPositioner> resource_, SP<CXDGWMBase> owner_) : owner(owner_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setData(this);
@ -520,7 +520,7 @@ CXDGPositionerResource::CXDGPositionerResource(SP<CXdgPositioner> resource_, SP<
resource->setOnDestroy([this](CXdgPositioner* r) { PROTO::xdgShell->destroyResource(this); });
resource->setSetSize([this](CXdgPositioner* r, int32_t x, int32_t y) {
if (x <= 0 || y <= 0) {
if UNLIKELY (x <= 0 || y <= 0) {
r->error(XDG_POSITIONER_ERROR_INVALID_INPUT, "Invalid size");
return;
}
@ -529,7 +529,7 @@ CXDGPositionerResource::CXDGPositionerResource(SP<CXdgPositioner> resource_, SP<
});
resource->setSetAnchorRect([this](CXdgPositioner* r, int32_t x, int32_t y, int32_t w, int32_t h) {
if (w <= 0 || h <= 0) {
if UNLIKELY (w <= 0 || h <= 0) {
r->error(XDG_POSITIONER_ERROR_INVALID_INPUT, "Invalid box");
return;
}
@ -686,7 +686,7 @@ CBox CXDGPositionerRules::getPosition(CBox constraint, const Vector2D& parentCoo
}
CXDGWMBase::CXDGWMBase(SP<CXdgWmBase> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CXdgWmBase* r) { PROTO::xdgShell->destroyResource(this); });
@ -698,7 +698,7 @@ CXDGWMBase::CXDGWMBase(SP<CXdgWmBase> resource_) : resource(resource_) {
const auto RESOURCE =
PROTO::xdgShell->m_vPositioners.emplace_back(makeShared<CXDGPositionerResource>(makeShared<CXdgPositioner>(r->client(), r->version(), id), self.lock()));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::xdgShell->m_vPositioners.pop_back();
return;
@ -714,19 +714,19 @@ CXDGWMBase::CXDGWMBase(SP<CXdgWmBase> resource_) : resource(resource_) {
resource->setGetXdgSurface([this](CXdgWmBase* r, uint32_t id, wl_resource* surf) {
auto SURF = CWLSurfaceResource::fromResource(surf);
if (!SURF) {
if UNLIKELY (!SURF) {
r->error(-1, "Invalid surface passed");
return;
}
if (SURF->role->role() != SURFACE_ROLE_UNASSIGNED) {
if UNLIKELY (SURF->role->role() != SURFACE_ROLE_UNASSIGNED) {
r->error(-1, "Surface already has a different role");
return;
}
const auto RESOURCE = PROTO::xdgShell->m_vSurfaces.emplace_back(makeShared<CXDGSurfaceResource>(makeShared<CXdgSurface>(r->client(), r->version(), id), self.lock(), SURF));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::xdgShell->m_vSurfaces.pop_back();
return;
@ -765,7 +765,7 @@ CXDGShellProtocol::CXDGShellProtocol(const wl_interface* iface, const int& ver,
void CXDGShellProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vWMBases.emplace_back(makeShared<CXDGWMBase>(makeShared<CXdgWmBase>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vWMBases.pop_back();
return;

View file

@ -3,7 +3,7 @@
#include <algorithm>
CXWaylandSurfaceResource::CXWaylandSurfaceResource(SP<CXwaylandSurfaceV1> resource_, SP<CWLSurfaceResource> surface_) : surface(surface_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CXwaylandSurfaceV1* r) {
@ -36,7 +36,7 @@ wl_client* CXWaylandSurfaceResource::client() {
}
CXWaylandShellResource::CXWaylandShellResource(SP<CXwaylandShellV1> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CXwaylandShellV1* r) { PROTO::xwaylandShell->destroyResource(this); });
@ -46,7 +46,7 @@ CXWaylandShellResource::CXWaylandShellResource(SP<CXwaylandShellV1> resource_) :
const auto RESOURCE = PROTO::xwaylandShell->m_vSurfaces.emplace_back(
makeShared<CXWaylandSurfaceResource>(makeShared<CXwaylandSurfaceV1>(r->client(), r->version(), id), CWLSurfaceResource::fromResource(surface)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::xwaylandShell->m_vSurfaces.pop_back();
return;
@ -67,7 +67,7 @@ CXWaylandShellProtocol::CXWaylandShellProtocol(const wl_interface* iface, const
void CXWaylandShellProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CXWaylandShellResource>(makeShared<CXwaylandShellV1>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;

View file

@ -34,7 +34,7 @@ void CWLCallbackResource::send(timespec* now) {
}
CWLRegionResource::CWLRegionResource(SP<CWlRegion> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setData(this);
@ -56,7 +56,7 @@ SP<CWLRegionResource> CWLRegionResource::fromResource(wl_resource* res) {
}
CWLSurfaceResource::CWLSurfaceResource(SP<CWlSurface> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
pClient = resource->client();
@ -187,20 +187,20 @@ void CWLSurfaceResource::enter(PHLMONITOR monitor) {
if (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) != enteredOutputs.end())
return;
if (!PROTO::outputs.contains(monitor->szName)) {
if UNLIKELY (!PROTO::outputs.contains(monitor->szName)) {
// can happen on unplug/replug
LOGM(ERR, "enter() called on a non-existent output global");
return;
}
if (PROTO::outputs.at(monitor->szName)->isDefunct()) {
if UNLIKELY (PROTO::outputs.at(monitor->szName)->isDefunct()) {
LOGM(ERR, "enter() called on a defunct output global");
return;
}
auto output = PROTO::outputs.at(monitor->szName)->outputResourceFrom(pClient);
if (!output || !output->getResource() || !output->getResource()->resource()) {
if UNLIKELY (!output || !output->getResource() || !output->getResource()->resource()) {
LOGM(ERR, "Cannot enter surface {:x} to {}, client hasn't bound the output", (uintptr_t)this, monitor->szName);
return;
}
@ -211,12 +211,12 @@ void CWLSurfaceResource::enter(PHLMONITOR monitor) {
}
void CWLSurfaceResource::leave(PHLMONITOR monitor) {
if (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) == enteredOutputs.end())
if UNLIKELY (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) == enteredOutputs.end())
return;
auto output = PROTO::outputs.at(monitor->szName)->outputResourceFrom(pClient);
if (!output) {
if UNLIKELY (!output) {
LOGM(ERR, "Cannot leave surface {:x} from {}, client hasn't bound the output", (uintptr_t)this, monitor->szName);
return;
}
@ -332,7 +332,7 @@ uint32_t CWLSurfaceResource::id() {
}
void CWLSurfaceResource::map() {
if (mapped)
if UNLIKELY (mapped)
return;
mapped = true;
@ -346,7 +346,7 @@ void CWLSurfaceResource::map() {
}
void CWLSurfaceResource::unmap() {
if (!mapped)
if UNLIKELY (!mapped)
return;
mapped = false;
@ -385,10 +385,10 @@ CBox CWLSurfaceResource::extends() {
}
Vector2D CWLSurfaceResource::sourceSize() {
if (!current.texture)
if UNLIKELY (!current.texture)
return {};
if (current.viewport.hasSource)
if UNLIKELY (current.viewport.hasSource)
return current.viewport.source.size();
Vector2D trc = current.transform % 2 == 1 ? Vector2D{current.bufferSize.y, current.bufferSize.x} : current.bufferSize;
@ -396,7 +396,7 @@ Vector2D CWLSurfaceResource::sourceSize() {
}
CRegion CWLSurfaceResource::accumulateCurrentBufferDamage() {
if (!current.texture)
if UNLIKELY (!current.texture)
return {};
CRegion surfaceDamage = current.damage;
@ -495,7 +495,7 @@ void CWLSurfaceResource::commitPendingState() {
void CWLSurfaceResource::updateCursorShm(CRegion damage) {
auto buf = current.buffer ? current.buffer->buffer : lastBuffer;
if (!buf)
if UNLIKELY (!buf)
return;
auto& shmData = CCursorSurfaceRole::cursorPixelData(self.lock());
@ -545,7 +545,7 @@ void CWLSurfaceResource::presentFeedback(timespec* when, PHLMONITOR pMonitor, bo
}
CWLCompositorResource::CWLCompositorResource(SP<CWlCompositor> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWlCompositor* r) { PROTO::compositor->destroyResource(this); });
@ -553,7 +553,7 @@ CWLCompositorResource::CWLCompositorResource(SP<CWlCompositor> resource_) : reso
resource->setCreateSurface([](CWlCompositor* r, uint32_t id) {
const auto RESOURCE = PROTO::compositor->m_vSurfaces.emplace_back(makeShared<CWLSurfaceResource>(makeShared<CWlSurface>(r->client(), r->version(), id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::compositor->m_vSurfaces.pop_back();
return;
@ -569,7 +569,7 @@ CWLCompositorResource::CWLCompositorResource(SP<CWlCompositor> resource_) : reso
resource->setCreateRegion([](CWlCompositor* r, uint32_t id) {
const auto RESOURCE = PROTO::compositor->m_vRegions.emplace_back(makeShared<CWLRegionResource>(makeShared<CWlRegion>(r->client(), r->version(), id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::compositor->m_vRegions.pop_back();
return;
@ -592,7 +592,7 @@ CWLCompositorProtocol::CWLCompositorProtocol(const wl_interface* iface, const in
void CWLCompositorProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CWLCompositorResource>(makeShared<CWlCompositor>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;

View file

@ -15,7 +15,7 @@
#include "../../render/Renderer.hpp"
CWLDataOfferResource::CWLDataOfferResource(SP<CWlDataOffer> resource_, SP<IDataSource> source_) : source(source_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setDestroy([this](CWlDataOffer* r) { PROTO::data->destroyResource(this); });
@ -127,7 +127,7 @@ SP<IDataSource> CWLDataOfferResource::getSource() {
}
CWLDataSourceResource::CWLDataSourceResource(SP<CWlDataSource> resource_, SP<CWLDataDeviceResource> device_) : device(device_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setData(this);
@ -237,7 +237,7 @@ eDataSourceType CWLDataSourceResource::type() {
}
CWLDataDeviceResource::CWLDataDeviceResource(SP<CWlDataDevice> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setRelease([this](CWlDataDevice* r) { PROTO::data->destroyResource(this); });
@ -333,7 +333,7 @@ SP<CX11DataDevice> CWLDataDeviceResource::getX11() {
}
CWLDataDeviceManagerResource::CWLDataDeviceManagerResource(SP<CWlDataDeviceManager> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWlDataDeviceManager* r) { PROTO::data->destroyResource(this); });
@ -343,7 +343,7 @@ CWLDataDeviceManagerResource::CWLDataDeviceManagerResource(SP<CWlDataDeviceManag
const auto RESOURCE = PROTO::data->m_vSources.emplace_back(makeShared<CWLDataSourceResource>(makeShared<CWlDataSource>(r->client(), r->version(), id), device.lock()));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::data->m_vSources.pop_back();
return;
@ -362,7 +362,7 @@ CWLDataDeviceManagerResource::CWLDataDeviceManagerResource(SP<CWlDataDeviceManag
resource->setGetDataDevice([this](CWlDataDeviceManager* r, uint32_t id, wl_resource* seat) {
const auto RESOURCE = PROTO::data->m_vDevices.emplace_back(makeShared<CWLDataDeviceResource>(makeShared<CWlDataDevice>(r->client(), r->version(), id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::data->m_vDevices.pop_back();
return;
@ -394,7 +394,7 @@ CWLDataDeviceProtocol::CWLDataDeviceProtocol(const wl_interface* iface, const in
void CWLDataDeviceProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CWLDataDeviceManagerResource>(makeShared<CWlDataDeviceManager>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;
@ -441,7 +441,7 @@ void CWLDataDeviceProtocol::sendSelectionToDevice(SP<IDataDevice> dev, SP<IDataS
if (const auto WL = dev->getWayland(); WL) {
const auto OFFER = m_vOffers.emplace_back(makeShared<CWLDataOfferResource>(makeShared<CWlDataOffer>(WL->resource->client(), WL->resource->version(), 0), sel));
if (!OFFER->good()) {
if UNLIKELY (!OFFER->good()) {
WL->resource->noMemory();
m_vOffers.pop_back();
return;
@ -455,7 +455,7 @@ void CWLDataDeviceProtocol::sendSelectionToDevice(SP<IDataDevice> dev, SP<IDataS
offer = g_pXWayland->pWM->createX11DataOffer(g_pSeatManager->state.keyboardFocus.lock(), sel);
#endif
if (!offer) {
if UNLIKELY (!offer) {
LOGM(ERR, "No offer could be created in sendSelectionToDevice");
return;
}

View file

@ -4,7 +4,7 @@
#include "../../helpers/Monitor.hpp"
CWLOutputResource::CWLOutputResource(SP<CWlOutput> resource_, PHLMONITOR pMonitor) : monitor(pMonitor), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setData(this);
@ -94,12 +94,12 @@ CWLOutputProtocol::CWLOutputProtocol(const wl_interface* iface, const int& ver,
}
void CWLOutputProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
if (defunct)
if UNLIKELY (defunct)
Debug::log(WARN, "[wl_output] Binding a wl_output that's inert?? Possible client bug.");
const auto RESOURCE = m_vOutputs.emplace_back(makeShared<CWLOutputResource>(makeShared<CWlOutput>(client, ver, id), monitor.lock()));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vOutputs.pop_back();
return;
@ -128,7 +128,7 @@ SP<CWLOutputResource> CWLOutputProtocol::outputResourceFrom(wl_client* client) {
}
void CWLOutputProtocol::remove() {
if (defunct)
if UNLIKELY (defunct)
return;
defunct = true;
@ -140,7 +140,7 @@ bool CWLOutputProtocol::isDefunct() {
}
void CWLOutputProtocol::sendDone() {
if (defunct)
if UNLIKELY (defunct)
return;
for (auto const& r : m_vOutputs) {

View file

@ -10,7 +10,7 @@
#include <fcntl.h>
CWLTouchResource::CWLTouchResource(SP<CWlTouch> resource_, SP<CWLSeatResource> owner_) : owner(owner_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setRelease([this](CWlTouch* r) { PROTO::seat->destroyResource(this); });
@ -105,7 +105,7 @@ void CWLTouchResource::sendOrientation(int32_t id, double angle) {
}
CWLPointerResource::CWLPointerResource(SP<CWlPointer> resource_, SP<CWLSeatResource> owner_) : owner(owner_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setRelease([this](CWlPointer* r) { PROTO::seat->destroyResource(this); });
@ -292,7 +292,7 @@ void CWLPointerResource::sendAxisRelativeDirection(wl_pointer_axis axis, wl_poin
}
CWLKeyboardResource::CWLKeyboardResource(SP<CWlKeyboard> resource_, SP<CWLSeatResource> owner_) : owner(owner_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setRelease([this](CWlKeyboard* r) { PROTO::seat->destroyResource(this); });
@ -419,7 +419,7 @@ void CWLKeyboardResource::repeatInfo(uint32_t rate, uint32_t delayMs) {
}
CWLSeatResource::CWLSeatResource(SP<CWlSeat> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWlSeat* r) {
@ -436,7 +436,7 @@ CWLSeatResource::CWLSeatResource(SP<CWlSeat> resource_) : resource(resource_) {
resource->setGetKeyboard([this](CWlSeat* r, uint32_t id) {
const auto RESOURCE = PROTO::seat->m_vKeyboards.emplace_back(makeShared<CWLKeyboardResource>(makeShared<CWlKeyboard>(r->client(), r->version(), id), self.lock()));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::seat->m_vKeyboards.pop_back();
return;
@ -448,7 +448,7 @@ CWLSeatResource::CWLSeatResource(SP<CWlSeat> resource_) : resource(resource_) {
resource->setGetPointer([this](CWlSeat* r, uint32_t id) {
const auto RESOURCE = PROTO::seat->m_vPointers.emplace_back(makeShared<CWLPointerResource>(makeShared<CWlPointer>(r->client(), r->version(), id), self.lock()));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::seat->m_vPointers.pop_back();
return;
@ -460,7 +460,7 @@ CWLSeatResource::CWLSeatResource(SP<CWlSeat> resource_) : resource(resource_) {
resource->setGetTouch([this](CWlSeat* r, uint32_t id) {
const auto RESOURCE = PROTO::seat->m_vTouches.emplace_back(makeShared<CWLTouchResource>(makeShared<CWlTouch>(r->client(), r->version(), id), self.lock()));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::seat->m_vTouches.pop_back();
return;
@ -506,7 +506,7 @@ CWLSeatProtocol::CWLSeatProtocol(const wl_interface* iface, const int& ver, cons
void CWLSeatProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vSeatResources.emplace_back(makeShared<CWLSeatResource>(makeShared<CWlSeat>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vSeatResources.pop_back();
return;

View file

@ -9,7 +9,7 @@
#include "../../render/Renderer.hpp"
CWLSHMBuffer::CWLSHMBuffer(SP<CWLSHMPoolResource> pool_, uint32_t id, int32_t offset_, const Vector2D& size_, int32_t stride_, uint32_t fmt_) {
if (!pool_->pool->data)
if UNLIKELY (!pool_->pool->data)
return;
g_pHyprRenderer->makeEGLCurrent();
@ -32,7 +32,7 @@ CWLSHMBuffer::CWLSHMBuffer(SP<CWLSHMPoolResource> pool_, uint32_t id, int32_t of
success = texture->m_iTexID;
if (!success)
if UNLIKELY (!success)
Debug::log(ERR, "Failed creating a shm texture: null texture id");
}
@ -96,13 +96,13 @@ void CSHMPool::resize(size_t size_) {
size = size_;
data = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (data == MAP_FAILED)
if UNLIKELY (data == MAP_FAILED)
LOGM(ERR, "Couldn't mmap {} bytes from fd {} of shm client", size, fd);
}
static int shmIsSizeValid(int fd, size_t size) {
struct stat st;
if (fstat(fd, &st) == -1) {
if UNLIKELY (fstat(fd, &st) == -1) {
LOGM(ERR, "Couldn't get stat for fd {} of shm client", fd);
return 0;
}
@ -111,10 +111,10 @@ static int shmIsSizeValid(int fd, size_t size) {
}
CWLSHMPoolResource::CWLSHMPoolResource(SP<CWlShmPool> resource_, int fd_, size_t size_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
if (!shmIsSizeValid(fd_, size_)) {
if UNLIKELY (!shmIsSizeValid(fd_, size_)) {
resource_->error(-1, "The size of the file is not big enough for the shm pool");
return;
}
@ -125,11 +125,11 @@ CWLSHMPoolResource::CWLSHMPoolResource(SP<CWlShmPool> resource_, int fd_, size_t
resource->setOnDestroy([this](CWlShmPool* r) { PROTO::shm->destroyResource(this); });
resource->setResize([this](CWlShmPool* r, int32_t size_) {
if (size_ < (int32_t)pool->size) {
if UNLIKELY (size_ < (int32_t)pool->size) {
r->error(-1, "Shrinking a shm pool is illegal");
return;
}
if (!shmIsSizeValid(pool->fd, size_)) {
if UNLIKELY (!shmIsSizeValid(pool->fd, size_)) {
r->error(-1, "The size of the file is not big enough for the shm pool");
return;
}
@ -138,24 +138,24 @@ CWLSHMPoolResource::CWLSHMPoolResource(SP<CWlShmPool> resource_, int fd_, size_t
});
resource->setCreateBuffer([this](CWlShmPool* r, uint32_t id, int32_t offset, int32_t w, int32_t h, int32_t stride, uint32_t fmt) {
if (!pool || !pool->data) {
if UNLIKELY (!pool || !pool->data) {
r->error(-1, "The provided shm pool failed to allocate properly");
return;
}
if (std::find(PROTO::shm->shmFormats.begin(), PROTO::shm->shmFormats.end(), fmt) == PROTO::shm->shmFormats.end()) {
if UNLIKELY (std::find(PROTO::shm->shmFormats.begin(), PROTO::shm->shmFormats.end(), fmt) == PROTO::shm->shmFormats.end()) {
r->error(WL_SHM_ERROR_INVALID_FORMAT, "Format invalid");
return;
}
if (offset < 0 || w <= 0 || h <= 0 || stride <= 0) {
if UNLIKELY (offset < 0 || w <= 0 || h <= 0 || stride <= 0) {
r->error(WL_SHM_ERROR_INVALID_STRIDE, "Invalid stride, w, h, or offset");
return;
}
const auto RESOURCE = PROTO::shm->m_vBuffers.emplace_back(makeShared<CWLSHMBuffer>(self.lock(), id, offset, Vector2D{w, h}, stride, fmt));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::shm->m_vBuffers.pop_back();
return;
@ -165,7 +165,7 @@ CWLSHMPoolResource::CWLSHMPoolResource(SP<CWlShmPool> resource_, int fd_, size_t
RESOURCE->resource->buffer = RESOURCE;
});
if (pool->data == MAP_FAILED)
if UNLIKELY (pool->data == MAP_FAILED)
resource->error(WL_SHM_ERROR_INVALID_FD, "Couldn't mmap from fd");
}
@ -174,7 +174,7 @@ bool CWLSHMPoolResource::good() {
}
CWLSHMResource::CWLSHMResource(SP<CWlShm> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWlShm* r) { PROTO::shm->destroyResource(this); });
@ -182,7 +182,7 @@ CWLSHMResource::CWLSHMResource(SP<CWlShm> resource_) : resource(resource_) {
resource->setCreatePool([](CWlShm* r, uint32_t id, int32_t fd, int32_t size) {
const auto RESOURCE = PROTO::shm->m_vPools.emplace_back(makeShared<CWLSHMPoolResource>(makeShared<CWlShmPool>(r->client(), r->version(), id), fd, size));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::shm->m_vPools.pop_back();
return;
@ -221,7 +221,7 @@ void CWLSHMProtocol::bindManager(wl_client* client, void* data, uint32_t ver, ui
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CWLSHMResource>(makeShared<CWlShm>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;

View file

@ -4,7 +4,7 @@
CWLSubsurfaceResource::CWLSubsurfaceResource(SP<CWlSubsurface> resource_, SP<CWLSurfaceResource> surface_, SP<CWLSurfaceResource> parent_) :
surface(surface_), parent(parent_), resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWlSubsurface* r) { destroy(); });
@ -142,7 +142,7 @@ SP<CWLSurfaceResource> CWLSubsurfaceResource::t1Parent() {
}
CWLSubcompositorResource::CWLSubcompositorResource(SP<CWlSubcompositor> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWlSubcompositor* r) { PROTO::subcompositor->destroyResource(this); });
@ -152,12 +152,12 @@ CWLSubcompositorResource::CWLSubcompositorResource(SP<CWlSubcompositor> resource
auto SURF = CWLSurfaceResource::fromResource(surface);
auto PARENT = CWLSurfaceResource::fromResource(parent);
if (!SURF || !PARENT || SURF == PARENT) {
if UNLIKELY (!SURF || !PARENT || SURF == PARENT) {
r->error(WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, "Invalid surface/parent");
return;
}
if (SURF->role->role() != SURFACE_ROLE_UNASSIGNED) {
if UNLIKELY (SURF->role->role() != SURFACE_ROLE_UNASSIGNED) {
r->error(-1, "Surface already has a different role");
return;
}
@ -170,7 +170,7 @@ CWLSubcompositorResource::CWLSubcompositorResource(SP<CWlSubcompositor> resource
} else
t1Parent = PARENT;
if (t1Parent == SURF) {
if UNLIKELY (t1Parent == SURF) {
r->error(WL_SUBCOMPOSITOR_ERROR_BAD_PARENT, "Bad parent, t1 parent == surf");
return;
}
@ -178,7 +178,7 @@ CWLSubcompositorResource::CWLSubcompositorResource(SP<CWlSubcompositor> resource
const auto RESOURCE =
PROTO::subcompositor->m_vSurfaces.emplace_back(makeShared<CWLSubsurfaceResource>(makeShared<CWlSubsurface>(r->client(), r->version(), id), SURF, PARENT));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::subcompositor->m_vSurfaces.pop_back();
return;
@ -205,7 +205,7 @@ CWLSubcompositorProtocol::CWLSubcompositorProtocol(const wl_interface* iface, co
void CWLSubcompositorProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CWLSubcompositorResource>(makeShared<CWlSubcompositor>(client, ver, id)));
if (!RESOURCE->good()) {
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
return;

View file

@ -17,11 +17,11 @@ CDMABuffer::CDMABuffer(uint32_t id, wl_client* client, Aquamarine::SDMABUFAttrs
auto eglImage = g_pHyprOpenGL->createEGLImage(attrs);
if (!eglImage) {
if UNLIKELY (!eglImage) {
Debug::log(ERR, "CDMABuffer: failed to import EGLImage, retrying as implicit");
attrs.modifier = DRM_FORMAT_MOD_INVALID;
eglImage = g_pHyprOpenGL->createEGLImage(attrs);
if (!eglImage) {
if UNLIKELY (!eglImage) {
Debug::log(ERR, "CDMABuffer: failed to import EGLImage");
return;
}
@ -31,7 +31,7 @@ CDMABuffer::CDMABuffer(uint32_t id, wl_client* client, Aquamarine::SDMABUFAttrs
opaque = NFormatUtils::isFormatOpaque(attrs.format);
success = texture->m_iTexID;
if (!success)
if UNLIKELY (!success)
Debug::log(ERR, "Failed to create a dmabuf: texture is null");
}

View file

@ -6,7 +6,7 @@
#include <xf86drm.h>
CWLBufferResource::CWLBufferResource(SP<CWlBuffer> resource_) : resource(resource_) {
if (!good())
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWlBuffer* r) {