From e5d252290d6f34e0b77d5548b519edc5b1ee62a1 Mon Sep 17 00:00:00 2001 From: Quantum Date: Fri, 13 Aug 2021 06:53:56 -0400 Subject: [PATCH] [common] array: add ALIGN_PAD macro for common logic ALIGN_PAD(x, a) returns x rounded up to the nearest multiple of a. --- common/include/common/array.h | 1 + common/src/platform/linux/ivshmem.c | 3 ++- host/platform/Windows/capture/NVFBC/src/nvfbc.c | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/common/include/common/array.h b/common/include/common/array.h index 8ad6dd9d..69010911 100644 --- a/common/include/common/array.h +++ b/common/include/common/array.h @@ -22,5 +22,6 @@ #define _LG_ARRAY_H_ #define ARRAY_LENGTH(arr) (sizeof(arr) / sizeof(*(arr))) +#define ALIGN_PAD(value, align) (((value) + (align) - 1) & -(align)) #endif diff --git a/common/src/platform/linux/ivshmem.c b/common/src/platform/linux/ivshmem.c index bc1364cb..f3d09edf 100644 --- a/common/src/platform/linux/ivshmem.c +++ b/common/src/platform/linux/ivshmem.c @@ -31,6 +31,7 @@ #include #include +#include "common/array.h" #include "common/debug.h" #include "common/option.h" #include "common/sysinfo.h" @@ -232,7 +233,7 @@ int ivshmemGetDMABuf(struct IVSHMEM * dev, uint64_t offset, uint64_t size) (struct IVSHMEMInfo *)dev->opaque; // align to the page size - size = (size + pageSize - 1) & -pageSize; + size = ALIGN_PAD(size, pageSize); const struct kvmfr_dmabuf_create create = { diff --git a/host/platform/Windows/capture/NVFBC/src/nvfbc.c b/host/platform/Windows/capture/NVFBC/src/nvfbc.c index a6e7705f..edae65aa 100644 --- a/host/platform/Windows/capture/NVFBC/src/nvfbc.c +++ b/host/platform/Windows/capture/NVFBC/src/nvfbc.c @@ -23,6 +23,7 @@ #include "common/windebug.h" #include "windows/mousehook.h" #include "windows/force_compose.h" +#include "common/array.h" #include "common/option.h" #include "common/framebuffer.h" #include "common/event.h" @@ -449,7 +450,7 @@ static CaptureResult nvfbc_waitFrame(CaptureFrame * frame, this->grabHeight = this->grabInfo.dwHeight; this->grabStride = this->grabInfo.dwBufferWidth; // Round up stride in IVSHMEM to avoid issues with dmabuf import. - this->shmStride = (this->grabStride + 0x1F) & ~0x1F; + this->shmStride = ALIGN_PAD(this->grabStride, 32); ++this->formatVer; }