render: Set glViewport based on output transform

pull/20/head
Andri Yngvason 2020-03-05 20:49:22 +00:00
parent e01f75bfbd
commit 9642e086d8
3 changed files with 17 additions and 20 deletions

View File

@ -22,6 +22,7 @@
#include <wayland-client.h> #include <wayland-client.h>
struct dmabuf_frame; struct dmabuf_frame;
struct output;
enum renderer_input_type { enum renderer_input_type {
RENDERER_INPUT_FB, RENDERER_INPUT_FB,
@ -33,9 +34,7 @@ struct renderer {
EGLSurface surface; EGLSurface surface;
EGLContext context; EGLContext context;
uint32_t width; const struct output* output;
uint32_t height;
enum wl_output_transform transform;
GLint read_format; GLint read_format;
GLint read_type; GLint read_type;
@ -47,8 +46,7 @@ struct renderer {
} shader; } shader;
}; };
int renderer_init(struct renderer* self, uint32_t width, uint32_t height, int renderer_init(struct renderer* self, const struct output* output,
enum wl_output_transform transform,
enum renderer_input_type input_type); enum renderer_input_type input_type);
void renderer_destroy(struct renderer* self); void renderer_destroy(struct renderer* self);

View File

@ -781,9 +781,8 @@ int main(int argc, char* argv[])
enum renderer_input_type renderer_input_type = enum renderer_input_type renderer_input_type =
fcbackend == FRAME_CAPTURE_BACKEND_DMABUF ? fcbackend == FRAME_CAPTURE_BACKEND_DMABUF ?
RENDERER_INPUT_DMABUF : RENDERER_INPUT_FB; RENDERER_INPUT_DMABUF : RENDERER_INPUT_FB;
if (renderer_init(&self.renderer, self.selected_output->width, if (renderer_init(&self.renderer, self.selected_output,
self.selected_output->height, renderer_input_type) < 0) {
WL_OUTPUT_TRANSFORM_NORMAL, renderer_input_type) < 0) {
log_error("Failed to initialise renderer\n"); log_error("Failed to initialise renderer\n");
goto failure; goto failure;
} }

View File

@ -31,6 +31,7 @@
#include "logging.h" #include "logging.h"
#include "render.h" #include "render.h"
#include "dmabuf.h" #include "dmabuf.h"
#include "output.h"
#include "config.h" #include "config.h"
#define MAYBE_UNUSED __attribute__((unused)) #define MAYBE_UNUSED __attribute__((unused))
@ -367,8 +368,7 @@ void renderer_destroy(struct renderer* self)
eglTerminate(self->display); eglTerminate(self->display);
} }
int renderer_init(struct renderer* self, uint32_t width, uint32_t height, int renderer_init(struct renderer* self, const struct output* output,
enum wl_output_transform transform,
enum renderer_input_type input_type) enum renderer_input_type input_type)
{ {
if (!eglBindAPI(EGL_OPENGL_ES_API)) if (!eglBindAPI(EGL_OPENGL_ES_API))
@ -414,8 +414,8 @@ int renderer_init(struct renderer* self, uint32_t width, uint32_t height,
return -1; return -1;
EGLint surf_attr[] = { EGLint surf_attr[] = {
EGL_WIDTH, width, EGL_WIDTH, output->width,
EGL_HEIGHT, height, EGL_HEIGHT, output->width,
EGL_NONE EGL_NONE
}; };
@ -450,13 +450,13 @@ int renderer_init(struct renderer* self, uint32_t width, uint32_t height,
self->shader.u_tex = glGetUniformLocation(self->shader.program, "u_tex"); self->shader.u_tex = glGetUniformLocation(self->shader.program, "u_tex");
self->shader.u_proj = glGetUniformLocation(self->shader.program, "u_proj"); self->shader.u_proj = glGetUniformLocation(self->shader.program, "u_proj");
self->width = width; self->output = output;
self->height = height;
self->transform = transform;
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &self->read_format); glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &self->read_format);
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &self->read_type); glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &self->read_type);
glViewport(0, 0, width, height); glViewport(0, 0,
output_get_transformed_width(output),
output_get_transformed_height(output));
gl_clear(); gl_clear();
return 0; return 0;
@ -528,7 +528,7 @@ int render_dmabuf_frame(struct renderer* self, struct dmabuf_frame* frame)
glUniform1i(self->shader.u_tex, 0); glUniform1i(self->shader.u_tex, 0);
const float* proj = transforms[self->transform]; const float* proj = transforms[self->output->transform];
glUniformMatrix2fv(self->shader.u_proj, 1, GL_FALSE, proj); glUniformMatrix2fv(self->shader.u_proj, 1, GL_FALSE, proj);
gl_render(); gl_render();
@ -562,7 +562,7 @@ int render_framebuffer(struct renderer* self, const void* addr, uint32_t format,
glUniform1i(self->shader.u_tex, 0); glUniform1i(self->shader.u_tex, 0);
const float* proj = transforms[self->transform]; const float* proj = transforms[self->output->transform];
glUniformMatrix2fv(self->shader.u_proj, 1, GL_FALSE, proj); glUniformMatrix2fv(self->shader.u_proj, 1, GL_FALSE, proj);
gl_render(); gl_render();
@ -576,8 +576,8 @@ int render_framebuffer(struct renderer* self, const void* addr, uint32_t format,
void render_copy_pixels(struct renderer* self, void* dst, uint32_t y, void render_copy_pixels(struct renderer* self, void* dst, uint32_t y,
uint32_t height) uint32_t height)
{ {
assert(y + height <= self->height); assert(y + height <= self->output->height);
glReadPixels(0, y, self->width, height, self->read_format, glReadPixels(0, y, self->output->width, height, self->read_format,
self->read_type, dst); self->read_type, dst);
} }