aboutsummaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
Diffstat (limited to 'render')
-rw-r--r--render/egl.c50
-rw-r--r--render/gles2/renderer.c43
-rw-r--r--render/matrix.c33
-rw-r--r--render/meson.build2
-rw-r--r--render/wlr_renderer.c8
5 files changed, 96 insertions, 40 deletions
diff --git a/render/egl.c b/render/egl.c
index fe20973c..9ac0b307 100644
--- a/render/egl.c
+++ b/render/egl.c
@@ -127,18 +127,23 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display,
}
eglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE, egl->context);
- egl->egl_exts = eglQueryString(egl->display, EGL_EXTENSIONS);
- if (strstr(egl->egl_exts, "EGL_WL_bind_wayland_display") == NULL ||
- strstr(egl->egl_exts, "EGL_KHR_image_base") == NULL) {
+ egl->egl_exts_str = eglQueryString(egl->display, EGL_EXTENSIONS);
+ egl->gl_exts_str = (const char*) glGetString(GL_EXTENSIONS);
+
+ wlr_log(L_INFO, "Using EGL %d.%d", (int)major, (int)minor);
+ wlr_log(L_INFO, "Supported EGL extensions: %s", egl->egl_exts_str);
+ wlr_log(L_INFO, "Using %s", glGetString(GL_VERSION));
+ wlr_log(L_INFO, "Supported OpenGL ES extensions: %s", egl->gl_exts_str);
+
+ if (strstr(egl->egl_exts_str, "EGL_WL_bind_wayland_display") == NULL ||
+ strstr(egl->egl_exts_str, "EGL_KHR_image_base") == NULL) {
wlr_log(L_ERROR, "Required egl extensions not supported");
goto error;
}
- egl->gl_exts = (const char*) glGetString(GL_EXTENSIONS);
- wlr_log(L_INFO, "Using EGL %d.%d", (int)major, (int)minor);
- wlr_log(L_INFO, "Supported EGL extensions: %s", egl->egl_exts);
- wlr_log(L_INFO, "Using %s", glGetString(GL_VERSION));
- wlr_log(L_INFO, "Supported OpenGL ES extensions: %s", egl->gl_exts);
+ egl->egl_exts.buffer_age =
+ strstr(egl->egl_exts_str, "EGL_EXT_buffer_age") != NULL;
+
return true;
error:
@@ -208,3 +213,32 @@ EGLSurface wlr_egl_create_surface(struct wlr_egl *egl, void *window) {
}
return surf;
}
+
+int wlr_egl_get_buffer_age(struct wlr_egl *egl, EGLSurface surface) {
+ if (!egl->egl_exts.buffer_age) {
+ return -1;
+ }
+
+ EGLint buffer_age;
+ EGLBoolean ok = eglQuerySurface(egl->display, surface,
+ EGL_BUFFER_AGE_EXT, &buffer_age);
+ if (!ok) {
+ wlr_log(L_ERROR, "Failed to get EGL surface buffer age: %s", egl_error());
+ return -1;
+ }
+
+ return buffer_age;
+}
+
+bool wlr_egl_make_current(struct wlr_egl *egl, EGLSurface surface,
+ int *buffer_age) {
+ if (!eglMakeCurrent(egl->display, surface, surface, egl->context)) {
+ wlr_log(L_ERROR, "eglMakeCurrent failed: %s", egl_error());
+ return false;
+ }
+
+ if (buffer_age != NULL) {
+ *buffer_age = wlr_egl_get_buffer_age(egl, surface);
+ }
+ return true;
+}
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c
index 8c5b81ad..f57e9dae 100644
--- a/render/gles2/renderer.c
+++ b/render/gles2/renderer.c
@@ -105,14 +105,9 @@ static void init_globals() {
init_default_shaders();
}
-static void wlr_gles2_begin(struct wlr_renderer *_renderer,
+static void wlr_gles2_begin(struct wlr_renderer *wlr_renderer,
struct wlr_output *output) {
- // TODO: let users customize the clear color?
- GL_CALL(glClearColor(0.25f, 0.25f, 0.25f, 1));
- GL_CALL(glClear(GL_COLOR_BUFFER_BIT));
- int32_t width = output->width;
- int32_t height = output->height;
- GL_CALL(glViewport(0, 0, width, height));
+ GL_CALL(glViewport(0, 0, output->width, output->height));
// enable transparency
GL_CALL(glEnable(GL_BLEND));
@@ -122,14 +117,30 @@ static void wlr_gles2_begin(struct wlr_renderer *_renderer,
// for users to sling matricies themselves
}
-static void wlr_gles2_end(struct wlr_renderer *renderer) {
+static void wlr_gles2_end(struct wlr_renderer *wlr_renderer) {
// no-op
}
+static void wlr_gles2_clear(struct wlr_renderer *wlr_renderer,
+ const float (*color)[4]) {
+ glClearColor((*color)[0], (*color)[1], (*color)[2], (*color)[3]);
+ glClear(GL_COLOR_BUFFER_BIT);
+}
+
+static void wlr_gles2_scissor(struct wlr_renderer *wlr_renderer,
+ struct wlr_box *box) {
+ if (box != NULL) {
+ glScissor(box->x, box->y, box->width, box->height);
+ glEnable(GL_SCISSOR_TEST);
+ } else {
+ glDisable(GL_SCISSOR_TEST);
+ }
+}
+
static struct wlr_texture *wlr_gles2_texture_create(
- struct wlr_renderer *_renderer) {
+ struct wlr_renderer *wlr_renderer) {
struct wlr_gles2_renderer *renderer =
- (struct wlr_gles2_renderer *)_renderer;
+ (struct wlr_gles2_renderer *)wlr_renderer;
return gles2_texture_create(renderer->egl);
}
@@ -159,7 +170,7 @@ static void draw_quad() {
GL_CALL(glDisableVertexAttribArray(1));
}
-static bool wlr_gles2_render_texture(struct wlr_renderer *_renderer,
+static bool wlr_gles2_render_texture(struct wlr_renderer *wlr_renderer,
struct wlr_texture *texture, const float (*matrix)[16]) {
if (!texture || !texture->valid) {
wlr_log(L_ERROR, "attempt to render invalid texture");
@@ -174,7 +185,7 @@ static bool wlr_gles2_render_texture(struct wlr_renderer *_renderer,
return true;
}
-static void wlr_gles2_render_quad(struct wlr_renderer *renderer,
+static void wlr_gles2_render_quad(struct wlr_renderer *wlr_renderer,
const float (*color)[4], const float (*matrix)[16]) {
GL_CALL(glUseProgram(shaders.quad));
GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, *matrix));
@@ -182,7 +193,7 @@ static void wlr_gles2_render_quad(struct wlr_renderer *renderer,
draw_quad();
}
-static void wlr_gles2_render_ellipse(struct wlr_renderer *renderer,
+static void wlr_gles2_render_ellipse(struct wlr_renderer *wlr_renderer,
const float (*color)[4], const float (*matrix)[16]) {
GL_CALL(glUseProgram(shaders.ellipse));
GL_CALL(glUniformMatrix4fv(0, 1, GL_TRUE, *matrix));
@@ -202,10 +213,10 @@ static const enum wl_shm_format *wlr_gles2_formats(
return formats;
}
-static bool wlr_gles2_buffer_is_drm(struct wlr_renderer *_renderer,
+static bool wlr_gles2_buffer_is_drm(struct wlr_renderer *wlr_renderer,
struct wl_resource *buffer) {
struct wlr_gles2_renderer *renderer =
- (struct wlr_gles2_renderer *)_renderer;
+ (struct wlr_gles2_renderer *)wlr_renderer;
EGLint format;
return wlr_egl_query_buffer(renderer->egl, buffer,
EGL_TEXTURE_FORMAT, &format);
@@ -243,6 +254,8 @@ static bool wlr_gles2_format_supported(struct wlr_renderer *r,
static struct wlr_renderer_impl wlr_renderer_impl = {
.begin = wlr_gles2_begin,
.end = wlr_gles2_end,
+ .clear = wlr_gles2_clear,
+ .scissor = wlr_gles2_scissor,
.texture_create = wlr_gles2_texture_create,
.render_with_matrix = wlr_gles2_render_texture,
.render_quad = wlr_gles2_render_quad,
diff --git a/render/matrix.c b/render/matrix.c
index 9a1b2bb4..fa45dd04 100644
--- a/render/matrix.c
+++ b/render/matrix.c
@@ -169,22 +169,26 @@ void wlr_matrix_project_box(float (*mat)[16], struct wlr_box *box,
int width = box->width;
int height = box->height;
- float translate_center[16];
- wlr_matrix_translate(&translate_center,
- (int)x + width / 2, (int)y + height / 2, 0);
+ wlr_matrix_translate(mat, x, y, 0);
- float rotate[16];
- wlr_matrix_rotate(&rotate, rotation);
+ if (rotation != 0) {
+ float translate_center[16];
+ wlr_matrix_translate(&translate_center, width/2, height/2, 0);
- float translate_origin[16];
- wlr_matrix_translate(&translate_origin, -width / 2,
- -height / 2, 0);
+ float rotate[16];
+ wlr_matrix_rotate(&rotate, rotation);
+
+ float translate_origin[16];
+ wlr_matrix_translate(&translate_origin, -width/2, -height/2, 0);
+
+ wlr_matrix_mul(mat, &translate_center, mat);
+ wlr_matrix_mul(mat, &rotate, mat);
+ wlr_matrix_mul(mat, &translate_origin, mat);
+ }
float scale[16];
wlr_matrix_scale(&scale, width, height, 1);
- wlr_matrix_mul(&translate_center, &rotate, mat);
- wlr_matrix_mul(mat, &translate_origin, mat);
wlr_matrix_mul(mat, &scale, mat);
if (transform != WL_OUTPUT_TRANSFORM_NORMAL) {
@@ -192,17 +196,14 @@ void wlr_matrix_project_box(float (*mat)[16], struct wlr_box *box,
wlr_matrix_translate(&surface_translate_center, 0.5, 0.5, 0);
float surface_transform[16];
- wlr_matrix_transform(surface_transform,
- wlr_output_transform_invert(transform));
+ wlr_matrix_transform(surface_transform, transform);
float surface_translate_origin[16];
wlr_matrix_translate(&surface_translate_origin, -0.5, -0.5, 0);
- wlr_matrix_mul(mat, &surface_translate_center,
- mat);
+ wlr_matrix_mul(mat, &surface_translate_center, mat);
wlr_matrix_mul(mat, &surface_transform, mat);
- wlr_matrix_mul(mat, &surface_translate_origin,
- mat);
+ wlr_matrix_mul(mat, &surface_translate_origin, mat);
}
wlr_matrix_mul(projection, mat, mat);
diff --git a/render/meson.build b/render/meson.build
index 1eea9a83..309e83cd 100644
--- a/render/meson.build
+++ b/render/meson.build
@@ -22,7 +22,7 @@ lib_wlr_render = static_library(
glapi[0],
glapi[1],
include_directories: wlr_inc,
- dependencies: [glesv2, egl],
+ dependencies: [glesv2, egl, pixman],
)
wlr_render = declare_dependency(
diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c
index 711f11ef..c8f06a64 100644
--- a/render/wlr_renderer.c
+++ b/render/wlr_renderer.c
@@ -23,6 +23,14 @@ void wlr_renderer_end(struct wlr_renderer *r) {
r->impl->end(r);
}
+void wlr_renderer_clear(struct wlr_renderer *r, const float (*color)[4]) {
+ r->impl->clear(r, color);
+}
+
+void wlr_renderer_scissor(struct wlr_renderer *r, struct wlr_box *box) {
+ r->impl->scissor(r, box);
+}
+
struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r) {
return r->impl->texture_create(r);
}