core: add LIKELY and UNLIKELY macros
helps the compiler optimize
This commit is contained in:
parent
2bad73354a
commit
b7a3c45269
58 changed files with 395 additions and 396 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue