From 4da96d0dc1fbf77ac1540472d99509773649d591 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Tue, 24 Mar 2020 22:48:13 +0000 Subject: [PATCH] renderer: Split buffer import and rendering --- include/render.h | 16 ++++++++++++---- src/main.c | 10 +++++++--- src/render.c | 27 ++++++++++----------------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/include/render.h b/include/render.h index 6c7a207..2984cb3 100644 --- a/include/render.h +++ b/include/render.h @@ -18,7 +18,7 @@ #include #include -#include +#include #include struct dmabuf_frame; @@ -59,10 +59,18 @@ int renderer_init(struct renderer* self, const struct output* output, enum renderer_input_type input_type); void renderer_destroy(struct renderer* self); -int render_dmabuf_frame(struct renderer* self, struct dmabuf_frame* frame); -int render_framebuffer(struct renderer* self, const void* addr, uint32_t format, - uint32_t width, uint32_t height, uint32_t stride); +int renderer_import_dmabuf_frame(struct renderer* self, GLuint tex, + struct dmabuf_frame* frame); +int renderer_import_framebuffer(struct renderer* self, GLuint tex, + const void* addr, uint32_t format, + uint32_t width, uint32_t height, + uint32_t stride); /* Copy a horizontal stripe from the GL frame into a pixel buffer */ void render_copy_pixels(struct renderer* self, void* dst, uint32_t y, uint32_t height); + +GLuint renderer_next_tex(struct renderer* self); +GLuint renderer_last_tex(const struct renderer* self); + +void render(void); diff --git a/src/main.c b/src/main.c index 09f3539..8e06e55 100644 --- a/src/main.c +++ b/src/main.c @@ -516,7 +516,9 @@ void wayvnc_process_frame(struct wayvnc* self) struct nvnc_fb* fb = nvnc_fb_new(fb_width, fb_height, format); void* addr = nvnc_fb_get_addr(fb); - render_dmabuf_frame(&self->renderer, frame); + GLuint tex = renderer_next_tex(&self->renderer); + renderer_import_dmabuf_frame(&self->renderer, tex, frame); + render(); render_copy_pixels(&self->renderer, addr, 0, fb_height); wayvnc_update_vnc(self, fb); @@ -540,8 +542,10 @@ void wayvnc_process_screen(struct wayvnc* self) struct nvnc_fb* fb = nvnc_fb_new(fb_width, fb_height, renderer_format); void* addr = nvnc_fb_get_addr(fb); - render_framebuffer(&self->renderer, pixels, frame_format, width, height, - stride); + GLuint tex = renderer_next_tex(&self->renderer); + renderer_import_framebuffer(&self->renderer, tex, pixels, frame_format, + width, height, stride); + render(); render_copy_pixels(&self->renderer, addr, 0, fb_height); wayvnc_update_vnc(self, fb); diff --git a/src/render.c b/src/render.c index 540ae4a..d3ca998 100644 --- a/src/render.c +++ b/src/render.c @@ -322,14 +322,14 @@ fragment_failure: return rc; } -static inline GLuint gl_next_tex(struct renderer* self) +GLuint renderer_next_tex(struct renderer* self) { GLuint tex = self->tex[self->tex_index]; self->tex_index = (self->tex_index + 1) % ARRAY_LEN(self->tex); return tex; } -static inline GLuint gl_last_tex(const struct renderer* self) +GLuint renderer_last_tex(const struct renderer* self) { size_t len = ARRAY_LEN(self->tex); size_t index = (len + self->tex_index - 1) % len; @@ -342,7 +342,7 @@ void gl_clear(void) glClear(GL_COLOR_BUFFER_BIT); } -void gl_render(void) +void render(void) { static const GLfloat s_vertices[4][2] = { { -1.0, 1.0 }, @@ -550,7 +550,8 @@ static void dmabuf_attr_append_planes(EGLint* dst, int* i, #undef APPEND_PLANE_ATTR } -int render_dmabuf_frame(struct renderer* self, struct dmabuf_frame* frame) +int renderer_import_dmabuf_frame(struct renderer* self, GLuint tex, + struct dmabuf_frame* frame) { int index = 0; EGLint attr[6 + 10 * 4 + 1]; @@ -570,10 +571,10 @@ int render_dmabuf_frame(struct renderer* self, struct dmabuf_frame* frame) if (!image) return -1; - GLuint tex = gl_next_tex(self); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex); glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, image); + eglDestroyImageKHR(self->display, image); glUseProgram(self->shader.program); @@ -582,18 +583,14 @@ int render_dmabuf_frame(struct renderer* self, struct dmabuf_frame* frame) const float* proj = transforms[self->output->transform]; glUniformMatrix2fv(self->shader.u_proj, 1, GL_FALSE, proj); - gl_render(); - - glBindTexture(GL_TEXTURE_2D, 0); - eglDestroyImageKHR(self->display, image); - return 0; } -int render_framebuffer(struct renderer* self, const void* addr, uint32_t format, - uint32_t width, uint32_t height, uint32_t stride) +int renderer_import_framebuffer(struct renderer* self, GLuint tex, + const void* addr, uint32_t format, + uint32_t width, uint32_t height, + uint32_t stride) { - GLuint tex = gl_next_tex(self); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, tex); @@ -614,10 +611,6 @@ int render_framebuffer(struct renderer* self, const void* addr, uint32_t format, const float* proj = transforms[self->output->transform]; glUniformMatrix2fv(self->shader.u_proj, 1, GL_FALSE, proj); - gl_render(); - - glBindTexture(GL_TEXTURE_2D, 0); - return 0; }