1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-26 20:28:49 -05:00

Wayland: Clean up shared memory buffer creation

This commit is contained in:
Camilla Löwy 2022-07-15 12:50:18 +02:00
parent 91a96ed434
commit 7cc8b053b8

View File

@ -142,11 +142,8 @@ static int createAnonymousFile(off_t size)
static struct wl_buffer* createShmBuffer(const GLFWimage* image) static struct wl_buffer* createShmBuffer(const GLFWimage* image)
{ {
struct wl_shm_pool* pool; const int stride = image->width * 4;
struct wl_buffer* buffer; const int length = image->width * image->height * 4;
int stride = image->width * 4;
int length = image->width * image->height * 4;
void* data;
const int fd = createAnonymousFile(length); const int fd = createAnonymousFile(length);
if (fd < 0) if (fd < 0)
@ -157,7 +154,7 @@ static struct wl_buffer* createShmBuffer(const GLFWimage* image)
return NULL; return NULL;
} }
data = mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); void* data = mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (data == MAP_FAILED) if (data == MAP_FAILED)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
@ -166,9 +163,10 @@ static struct wl_buffer* createShmBuffer(const GLFWimage* image)
return NULL; return NULL;
} }
pool = wl_shm_create_pool(_glfw.wl.shm, fd, length); struct wl_shm_pool* pool = wl_shm_create_pool(_glfw.wl.shm, fd, length);
close(fd); close(fd);
unsigned char* source = (unsigned char*) image->pixels; unsigned char* source = (unsigned char*) image->pixels;
unsigned char* target = data; unsigned char* target = data;
for (int i = 0; i < image->width * image->height; i++, source += 4) for (int i = 0; i < image->width * image->height; i++, source += 4)
@ -181,7 +179,7 @@ static struct wl_buffer* createShmBuffer(const GLFWimage* image)
*target++ = (unsigned char) alpha; *target++ = (unsigned char) alpha;
} }
buffer = struct wl_buffer* buffer =
wl_shm_pool_create_buffer(pool, 0, wl_shm_pool_create_buffer(pool, 0,
image->width, image->width,
image->height, image->height,