From b744e2410e3066ca6dd0b5fcbd8ccf0dfdcf6615 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Tue, 14 Jan 2020 21:44:07 +0000 Subject: [PATCH] Handle more pixel formats --- src/main.c | 8 +++++--- src/render.c | 20 ++++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main.c b/src/main.c index 8e5d7c6..3cdd312 100644 --- a/src/main.c +++ b/src/main.c @@ -449,18 +449,20 @@ void wayvnc_process_frame(struct wayvnc* self) void wayvnc_process_screen(struct wayvnc* self) { - uint32_t format = fourcc_from_gl_format(self->renderer.read_format); + uint32_t renderer_format = + fourcc_from_gl_format(self->renderer.read_format); void* pixels = self->screencopy_backend.pixels; uint32_t width = self->capture_backend->frame_info.width; uint32_t height = self->capture_backend->frame_info.height; uint32_t stride = self->capture_backend->frame_info.stride; + uint32_t frame_format = self->capture_backend->frame_info.fourcc_format; - struct nvnc_fb* fb = nvnc_fb_new(width, height, format); + struct nvnc_fb* fb = nvnc_fb_new(width, height, renderer_format); void* addr = nvnc_fb_get_addr(fb); - render_framebuffer(&self->renderer, pixels, format, width, height, + render_framebuffer(&self->renderer, pixels, frame_format, width, height, stride); render_copy_pixels(&self->renderer, addr, 0, height); diff --git a/src/render.c b/src/render.c index 02cccc4..416d0fc 100644 --- a/src/render.c +++ b/src/render.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -54,13 +55,20 @@ X_GL_EXTENSIONS #undef X -int gl_format_from_wl_shm(GLenum* result, enum wl_shm_format format) +int gl_format_from_fourcc(GLenum* result, uint32_t format) { - *result = GL_BGRA_EXT; + switch (format) { + case DRM_FORMAT_XRGB8888: + case DRM_FORMAT_ARGB8888: + *result = GL_BGRA_EXT; + return 0; + case DRM_FORMAT_XBGR8888: + case DRM_FORMAT_ABGR8888: + *result = GL_RGBA; + return 0; + } - // TODO: Actually detect the format - - return 0; + return -1; } static inline void* gl_load_single_extension(const char* name) @@ -445,7 +453,7 @@ int render_framebuffer(struct renderer* self, const void* addr, uint32_t format, glBindTexture(GL_TEXTURE_2D, tex); GLenum gl_format; - if (gl_format_from_wl_shm(&gl_format, format) < 0) + if (gl_format_from_fourcc(&gl_format, format) < 0) return -1; glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride / 4);