From 5017d7f7625e4ca3369feb241a81ad8a570d0fd1 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 18 Jan 2018 14:36:42 +0100 Subject: rootston: only draw damaged regions --- render/gles2/renderer.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'render') diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 89cc4ffb..2dd64176 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -108,11 +108,9 @@ static void init_globals() { static void wlr_gles2_begin(struct wlr_renderer *_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(glClearColor(0.25f, 0.25f, 0.25f, 1)); + //GL_CALL(glClear(GL_COLOR_BUFFER_BIT)); + GL_CALL(glViewport(0, 0, output->width, output->height)); // enable transparency GL_CALL(glEnable(GL_BLEND)); -- cgit v1.2.3 From bde255933eb4cd2bab2d310725ab5de39467b900 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 18 Jan 2018 19:47:21 +0100 Subject: output: add wlr_output::damage, fixes #572 --- backend/meson.build | 13 ++++++++++++- include/wlr/types/wlr_output.h | 3 ++- render/meson.build | 2 +- rootston/output.c | 11 ++++------- types/wlr_output.c | 39 +++++++++++++++++++++++++++++++-------- xcursor/wlr_xcursor.c | 1 - 6 files changed, 50 insertions(+), 19 deletions(-) (limited to 'render') diff --git a/backend/meson.build b/backend/meson.build index b8084448..9931f546 100644 --- a/backend/meson.build +++ b/backend/meson.build @@ -45,5 +45,16 @@ lib_wlr_backend = static_library( 'wlr_backend', backend_files, include_directories: wlr_inc, - dependencies: [wayland_server, egl, gbm, libinput, systemd, elogind, wlr_render, wlr_protos, drm], + dependencies: [ + wayland_server, + egl, + gbm, + libinput, + systemd, + elogind, + wlr_render, + wlr_protos, + drm, + pixman, + ], ) diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 71463cb5..f6a5ac84 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -2,6 +2,7 @@ #define WLR_TYPES_WLR_OUTPUT_H #include +#include #include #include @@ -51,8 +52,8 @@ struct wlr_output { float scale; enum wl_output_subpixel subpixel; enum wl_output_transform transform; - bool needs_swap; + pixman_region32_t damage; float transform_matrix[16]; // Note: some backends may have zero modes 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/rootston/output.c b/rootston/output.c index 6e3403fc..38ca7241 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -62,7 +62,6 @@ static void render_surface(struct wlr_surface *surface, goto render_subsurfaces; } - // TODO: do not render regions of the surface that aren't damaged // TODO: output scale, output transform support pixman_region32_t surface_damage; pixman_region32_init(&surface_damage); @@ -71,7 +70,7 @@ static void render_surface(struct wlr_surface *surface, pixman_region32_intersect(&surface_damage, &surface_damage, damage); bool damaged = pixman_region32_not_empty(&surface_damage); if (!damaged) { - goto finish_surface_damage; + goto surface_damage_finish; } float transform[16]; @@ -130,7 +129,7 @@ static void render_surface(struct wlr_surface *surface, wlr_surface_send_frame_done(surface, when); -finish_surface_damage: +surface_damage_finish: pixman_region32_fini(&surface_damage); render_subsurfaces:; @@ -272,14 +271,12 @@ static void render_output(struct roots_output *output) { struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); + pixman_region32_union(&output->damage, &output->damage, &wlr_output->damage); + pixman_region32_t damage; pixman_region32_init(&damage); pixman_region32_union(&damage, &output->damage, &output->previous_damage); - // TODO: use real wlr_output damage - if (wlr_output->needs_swap) { - output_damage_whole(output); - } // TODO: fullscreen if (!pixman_region32_not_empty(&output->damage)) { float hz = wlr_output->refresh / 1000.0f; diff --git a/types/wlr_output.c b/types/wlr_output.c index b47fb3a0..e55243ef 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -279,6 +279,7 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, wl_signal_init(&output->events.scale); wl_signal_init(&output->events.transform); wl_signal_init(&output->events.destroy); + pixman_region32_init(&output->damage); output->display_destroy.notify = handle_display_destroy; wl_display_add_destroy_listener(display, &output->display_destroy); @@ -292,6 +293,7 @@ void wlr_output_destroy(struct wlr_output *output) { wl_list_remove(&output->display_destroy.link); wlr_output_destroy_global(output); wlr_output_set_fullscreen_surface(output, NULL); + pixman_region32_fini(&output->damage); wl_signal_emit(&output->events.destroy, output); @@ -440,7 +442,7 @@ void wlr_output_swap_buffers(struct wlr_output *output) { } output->impl->swap_buffers(output); - output->needs_swap = false; + pixman_region32_clear(&output->damage); } void wlr_output_set_gamma(struct wlr_output *output, @@ -457,12 +459,17 @@ uint32_t wlr_output_get_gamma_size(struct wlr_output *output) { return output->impl->get_gamma_size(output); } +static void output_damage_whole(struct wlr_output *output) { + pixman_region32_union_rect(&output->damage, &output->damage, 0, 0, + output->width, output->height); +} + static void output_fullscreen_surface_reset(struct wlr_output *output) { if (output->fullscreen_surface != NULL) { wl_list_remove(&output->fullscreen_surface_commit.link); wl_list_remove(&output->fullscreen_surface_destroy.link); output->fullscreen_surface = NULL; - output->needs_swap = true; + output_damage_whole(output); } } @@ -470,7 +477,8 @@ static void output_fullscreen_surface_handle_commit( struct wl_listener *listener, void *data) { struct wlr_output *output = wl_container_of(listener, output, fullscreen_surface_commit); - output->needs_swap = true; + // TODO: use surface damage + output_damage_whole(output); } static void output_fullscreen_surface_handle_destroy( @@ -491,7 +499,7 @@ void wlr_output_set_fullscreen_surface(struct wlr_output *output, output_fullscreen_surface_reset(output); output->fullscreen_surface = surface; - output->needs_swap = true; + output_damage_whole(output); if (surface == NULL) { return; @@ -507,9 +515,16 @@ void wlr_output_set_fullscreen_surface(struct wlr_output *output, } +static void output_cursor_damage_whole(struct wlr_output_cursor *cursor) { + struct wlr_box box; + output_cursor_get_box(cursor, &box); + pixman_region32_union_rect(&cursor->output->damage, &cursor->output->damage, + box.x, box.y, box.width, box.height); +} + static void output_cursor_reset(struct wlr_output_cursor *cursor) { if (cursor->output->hardware_cursor != cursor) { - cursor->output->needs_swap = true; + output_cursor_damage_whole(cursor); } if (cursor->surface != NULL) { wl_list_remove(&cursor->surface_commit.link); @@ -543,7 +558,7 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, } wlr_log(L_DEBUG, "Falling back to software cursor"); - cursor->output->needs_swap = true; + output_cursor_damage_whole(cursor); cursor->enabled = pixels != NULL; if (!cursor->enabled) { @@ -602,7 +617,7 @@ static void output_cursor_commit(struct wlr_output_cursor *cursor) { cursor->height = cursor->surface->current->height * cursor->output->scale; if (cursor->output->hardware_cursor != cursor) { - cursor->output->needs_swap = true; + output_cursor_damage_whole(cursor); } else { // TODO: upload pixels @@ -677,6 +692,14 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, double x, double y) { + if (cursor->x == x && cursor->y == y) { + return true; + } + + if (cursor->output->hardware_cursor != cursor) { + output_cursor_damage_whole(cursor); + } + x *= cursor->output->scale; y *= cursor->output->scale; cursor->x = x; @@ -684,7 +707,7 @@ bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, output_cursor_update_visible(cursor); if (cursor->output->hardware_cursor != cursor) { - cursor->output->needs_swap = true; + output_cursor_damage_whole(cursor); return true; } diff --git a/xcursor/wlr_xcursor.c b/xcursor/wlr_xcursor.c index b1678223..2d1a38b5 100644 --- a/xcursor/wlr_xcursor.c +++ b/xcursor/wlr_xcursor.c @@ -24,7 +24,6 @@ */ #define _XOPEN_SOURCE 500 -#include #include #include #include -- cgit v1.2.3 From a0f24b809e3b5f25885d44f8d2cfd9271ec1c506 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 19 Jan 2018 13:13:46 +0100 Subject: output: add damage event --- include/wlr/types/wlr_output.h | 1 + render/gles2/renderer.c | 3 --- types/wlr_output.c | 5 +++++ 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'render') diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index bc05dfbf..2c28e82f 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -63,6 +63,7 @@ struct wlr_output { int32_t refresh; // mHz struct { + struct wl_signal damage; struct wl_signal frame; struct wl_signal swap_buffers; struct wl_signal enable; diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 2dd64176..32f2eb02 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -107,9 +107,6 @@ static void init_globals() { static void wlr_gles2_begin(struct wlr_renderer *_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)); GL_CALL(glViewport(0, 0, output->width, output->height)); // enable transparency diff --git a/types/wlr_output.c b/types/wlr_output.c index dfcba906..bf02967c 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -272,6 +272,7 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, output->scale = 1; wl_list_init(&output->cursors); wl_list_init(&output->wl_resources); + wl_signal_init(&output->events.damage); wl_signal_init(&output->events.frame); wl_signal_init(&output->events.swap_buffers); wl_signal_init(&output->events.enable); @@ -494,6 +495,7 @@ uint32_t wlr_output_get_gamma_size(struct wlr_output *output) { static void output_damage_whole(struct wlr_output *output) { pixman_region32_union_rect(&output->damage, &output->damage, 0, 0, output->width, output->height); + wl_signal_emit(&output->events.damage, output); } static void output_fullscreen_surface_reset(struct wlr_output *output) { @@ -520,6 +522,8 @@ static void output_fullscreen_surface_handle_commit( pixman_region32_translate(&damage, box.x, box.y); pixman_region32_union(&output->damage, &output->damage, &damage); pixman_region32_fini(&damage); + + wl_signal_emit(&output->events.damage, output); } static void output_fullscreen_surface_handle_destroy( @@ -561,6 +565,7 @@ static void output_cursor_damage_whole(struct wlr_output_cursor *cursor) { output_cursor_get_box(cursor, &box); pixman_region32_union_rect(&cursor->output->damage, &cursor->output->damage, box.x, box.y, box.width, box.height); + wl_signal_emit(&cursor->output->events.damage, cursor->output); } static void output_cursor_reset(struct wlr_output_cursor *cursor) { -- cgit v1.2.3 From 0365b587f03411d6a55017e111a991d466decc35 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 21 Jan 2018 00:06:35 +0100 Subject: output: add damage tracking via buffer age --- backend/drm/drm.c | 13 ++++++---- backend/drm/renderer.c | 17 +++++++------ backend/headless/output.c | 13 ++++------ backend/wayland/output.c | 23 ++++++++++------- backend/x11/backend.c | 15 ++++------- examples/multi-pointer.c | 2 +- examples/output-layout.c | 2 +- examples/pointer.c | 2 +- examples/rotation.c | 2 +- examples/simple.c | 2 +- examples/tablet.c | 2 +- examples/touch.c | 2 +- include/backend/drm/renderer.h | 2 +- include/rootston/output.h | 7 +++++- include/wlr/interfaces/wlr_output.h | 4 +-- include/wlr/render/egl.h | 14 +++++++++-- include/wlr/types/wlr_output.h | 14 ++++++++--- render/egl.c | 50 +++++++++++++++++++++++++++++++------ rootston/output.c | 35 ++++++++++++++++++++------ types/wlr_output.c | 22 ++++++++-------- types/wlr_screenshooter.c | 1 - 21 files changed, 163 insertions(+), 81 deletions(-) (limited to 'render') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 72acbeab..72fc1441 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -183,12 +183,13 @@ void wlr_drm_resources_free(struct wlr_drm_backend *drm) { free(drm->planes); } -static void wlr_drm_connector_make_current(struct wlr_output *output) { +static bool wlr_drm_connector_make_current(struct wlr_output *output, + int *buffer_age) { struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; - wlr_drm_surface_make_current(&conn->crtc->primary->surf); + return wlr_drm_surface_make_current(&conn->crtc->primary->surf, buffer_age); } -static void wlr_drm_connector_swap_buffers(struct wlr_output *output) { +static bool wlr_drm_connector_swap_buffers(struct wlr_output *output) { struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; @@ -203,7 +204,7 @@ static void wlr_drm_connector_swap_buffers(struct wlr_output *output) { if (conn->pageflip_pending) { wlr_log(L_ERROR, "Skipping pageflip"); - return; + return true; } if (drm->iface->crtc_pageflip(drm, conn, crtc, fb_id, NULL)) { @@ -212,6 +213,8 @@ static void wlr_drm_connector_swap_buffers(struct wlr_output *output) { wl_event_source_timer_update(conn->retry_pageflip, 1000000.0f / conn->output.current_mode->refresh); } + + return true; } static void wlr_drm_connector_set_gamma(struct wlr_output *output, @@ -595,7 +598,7 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, return false; } - wlr_drm_surface_make_current(&plane->surf); + wlr_drm_surface_make_current(&plane->surf, NULL); wlr_texture_upload_pixels(plane->wlr_tex, WL_SHM_FORMAT_ARGB8888, stride, width, height, buf); diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index 00182c59..e2891057 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -113,9 +113,9 @@ void wlr_drm_surface_finish(struct wlr_drm_surface *surf) { memset(surf, 0, sizeof(*surf)); } -void wlr_drm_surface_make_current(struct wlr_drm_surface *surf) { - eglMakeCurrent(surf->renderer->egl.display, surf->egl, surf->egl, - surf->renderer->egl.context); +bool wlr_drm_surface_make_current(struct wlr_drm_surface *surf, + int *buffer_damage) { + return wlr_egl_make_current(&surf->renderer->egl, surf->egl, buffer_damage); } struct gbm_bo *wlr_drm_surface_swap_buffers(struct wlr_drm_surface *surf) { @@ -123,7 +123,9 @@ struct gbm_bo *wlr_drm_surface_swap_buffers(struct wlr_drm_surface *surf) { gbm_surface_release_buffer(surf->gbm, surf->front); } - eglSwapBuffers(surf->renderer->egl.display, surf->egl); + if (!eglSwapBuffers(surf->renderer->egl.display, surf->egl)) { + wlr_log(L_ERROR, "eglSwapBuffers failed"); + } surf->front = surf->back; surf->back = gbm_surface_lock_front_buffer(surf->gbm); @@ -135,7 +137,7 @@ struct gbm_bo *wlr_drm_surface_get_front(struct wlr_drm_surface *surf) { return surf->front; } - wlr_drm_surface_make_current(surf); + wlr_drm_surface_make_current(surf, NULL); glViewport(0, 0, surf->width, surf->height); glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); @@ -207,8 +209,9 @@ static struct wlr_texture *get_tex_for_bo(struct wlr_drm_renderer *renderer, str return tex->tex; } -struct gbm_bo *wlr_drm_surface_mgpu_copy(struct wlr_drm_surface *dest, struct gbm_bo *src) { - wlr_drm_surface_make_current(dest); +struct gbm_bo *wlr_drm_surface_mgpu_copy(struct wlr_drm_surface *dest, + struct gbm_bo *src) { + wlr_drm_surface_make_current(dest, NULL); struct wlr_texture *tex = get_tex_for_bo(dest->renderer, src); diff --git a/backend/headless/output.c b/backend/headless/output.c index 9fc92e88..a9a538ed 100644 --- a/backend/headless/output.c +++ b/backend/headless/output.c @@ -48,18 +48,15 @@ static void output_transform(struct wlr_output *wlr_output, output->wlr_output.transform = transform; } -static void output_make_current(struct wlr_output *wlr_output) { +static bool output_make_current(struct wlr_output *wlr_output, int *buffer_age) { struct wlr_headless_output *output = (struct wlr_headless_output *)wlr_output; - if (!eglMakeCurrent(output->backend->egl.display, - output->egl_surface, output->egl_surface, - output->backend->egl.context)) { - wlr_log(L_ERROR, "eglMakeCurrent failed: %s", egl_error()); - } + return wlr_egl_make_current(&output->backend->egl, output->egl_surface, + buffer_age); } -static void output_swap_buffers(struct wlr_output *wlr_output) { - // No-op +static bool output_swap_buffers(struct wlr_output *wlr_output) { + return true; // No-op } static void output_destroy(struct wlr_output *wlr_output) { diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 7e299ecc..5de18d41 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -38,22 +38,27 @@ static bool wlr_wl_output_set_custom_mode(struct wlr_output *_output, return true; } -static void wlr_wl_output_make_current(struct wlr_output *_output) { - struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output; - if (!eglMakeCurrent(output->backend->egl.display, - output->egl_surface, output->egl_surface, - output->backend->egl.context)) { - wlr_log(L_ERROR, "eglMakeCurrent failed: %s", egl_error()); - } +static bool wlr_wl_output_make_current(struct wlr_output *wlr_output, + int *buffer_age) { + struct wlr_wl_backend_output *output = + (struct wlr_wl_backend_output *)wlr_output; + return wlr_egl_make_current(&output->backend->egl, output->egl_surface, + buffer_age); } -static void wlr_wl_output_swap_buffers(struct wlr_output *_output) { - struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output; +static bool wlr_wl_output_swap_buffers(struct wlr_output *wlr_output) { + struct wlr_wl_backend_output *output = + (struct wlr_wl_backend_output *)wlr_output; + output->frame_callback = wl_surface_frame(output->surface); wl_callback_add_listener(output->frame_callback, &frame_listener, output); + if (!eglSwapBuffers(output->backend->egl.display, output->egl_surface)) { wlr_log(L_ERROR, "eglSwapBuffers failed: %s", egl_error()); + return false; } + + return true; } static void wlr_wl_output_transform(struct wlr_output *_output, diff --git a/backend/x11/backend.c b/backend/x11/backend.c index a2547f8d..b9ea7d0f 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -379,28 +379,23 @@ static void output_destroy(struct wlr_output *wlr_output) { // output has been allocated on the stack, do not free it } -static void output_make_current(struct wlr_output *wlr_output) { +static bool output_make_current(struct wlr_output *wlr_output, int *buffer_age) { struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; struct wlr_x11_backend *x11 = output->x11; - if (!eglMakeCurrent(x11->egl.display, output->surf, output->surf, x11->egl.context)) { - wlr_log(L_ERROR, "eglMakeCurrent failed: %s", egl_error()); - } + return wlr_egl_make_current(&x11->egl, output->surf, buffer_age); } -static void output_swap_buffers(struct wlr_output *wlr_output) { +static bool output_swap_buffers(struct wlr_output *wlr_output) { struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; struct wlr_x11_backend *x11 = output->x11; if (!eglSwapBuffers(x11->egl.display, output->surf)) { wlr_log(L_ERROR, "eglSwapBuffers failed: %s", egl_error()); + return false; } - // Damage the whole output - // TODO: use the buffer age extension - pixman_region32_union_rect(&wlr_output->damage, &wlr_output->damage, - 0, 0, wlr_output->width, wlr_output->height); - wlr_output_update_needs_swap(wlr_output); + return true; } static struct wlr_output_impl output_impl = { diff --git a/examples/multi-pointer.c b/examples/multi-pointer.c index d5297aef..d3d425f2 100644 --- a/examples/multi-pointer.c +++ b/examples/multi-pointer.c @@ -56,7 +56,7 @@ static void handle_output_frame(struct output_state *output, struct sample_state *sample = state->data; struct wlr_output *wlr_output = output->output; - wlr_output_make_current(wlr_output); + wlr_output_make_current(wlr_output, NULL); glClearColor(sample->clear_color[0], sample->clear_color[1], sample->clear_color[2], sample->clear_color[3]); diff --git a/examples/output-layout.c b/examples/output-layout.c index 825e97d1..b97d3723 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -100,7 +100,7 @@ static void handle_output_frame(struct output_state *output, struct sample_state *sample = state->data; struct wlr_output *wlr_output = output->output; - wlr_output_make_current(wlr_output); + wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); animate_cat(sample, output->output); diff --git a/examples/pointer.c b/examples/pointer.c index 8b0993e5..0dbd02d2 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -85,7 +85,7 @@ static void handle_output_frame(struct output_state *output, struct sample_state *sample = state->data; struct wlr_output *wlr_output = output->output; - wlr_output_make_current(wlr_output); + wlr_output_make_current(wlr_output, NULL); glClearColor(sample->clear_color[0], sample->clear_color[1], sample->clear_color[2], sample->clear_color[3]); diff --git a/examples/rotation.c b/examples/rotation.c index 6fa06dcc..65e436f6 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -42,7 +42,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts int32_t width, height; wlr_output_effective_resolution(wlr_output, &width, &height); - wlr_output_make_current(wlr_output); + wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); float matrix[16]; diff --git a/examples/simple.c b/examples/simple.c index f788618d..90808b0f 100644 --- a/examples/simple.c +++ b/examples/simple.c @@ -35,7 +35,7 @@ void handle_output_frame(struct output_state *output, struct timespec *ts) { sample->dec = inc; } - wlr_output_make_current(output->output); + wlr_output_make_current(output->output, NULL); glClearColor(sample->color[0], sample->color[1], sample->color[2], 1.0); glClear(GL_COLOR_BUFFER_BIT); diff --git a/examples/tablet.c b/examples/tablet.c index 5498c9ff..35326664 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -42,7 +42,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts int32_t width, height; wlr_output_effective_resolution(wlr_output, &width, &height); - wlr_output_make_current(wlr_output); + wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); float matrix[16], view[16]; diff --git a/examples/touch.c b/examples/touch.c index 5c778743..74642b96 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -41,7 +41,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts int32_t width, height; wlr_output_effective_resolution(wlr_output, &width, &height); - wlr_output_make_current(wlr_output); + wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); float matrix[16]; diff --git a/include/backend/drm/renderer.h b/include/backend/drm/renderer.h index 45127cd0..a3f19fc3 100644 --- a/include/backend/drm/renderer.h +++ b/include/backend/drm/renderer.h @@ -45,7 +45,7 @@ bool wlr_drm_plane_surfaces_init(struct wlr_drm_plane *plane, struct wlr_drm_bac int32_t width, uint32_t height, uint32_t format); void wlr_drm_surface_finish(struct wlr_drm_surface *surf); -void wlr_drm_surface_make_current(struct wlr_drm_surface *surf); +bool wlr_drm_surface_make_current(struct wlr_drm_surface *surf, int *buffer_age); struct gbm_bo *wlr_drm_surface_swap_buffers(struct wlr_drm_surface *surf); struct gbm_bo *wlr_drm_surface_get_front(struct wlr_drm_surface *surf); void wlr_drm_surface_post(struct wlr_drm_surface *surf); diff --git a/include/rootston/output.h b/include/rootston/output.h index e8241de7..c0022d1a 100644 --- a/include/rootston/output.h +++ b/include/rootston/output.h @@ -5,6 +5,8 @@ #include #include +#define ROOTS_OUTPUT_PREVIOUS_DAMAGE_LEN 2 + struct roots_desktop; struct roots_output { @@ -15,9 +17,12 @@ struct roots_output { struct roots_view *fullscreen_view; struct timespec last_frame; - pixman_region32_t damage, previous_damage; + pixman_region32_t damage; bool frame_pending; + pixman_region32_t previous_damage[ROOTS_OUTPUT_PREVIOUS_DAMAGE_LEN]; + size_t previous_damage_idx; + struct wl_listener frame; struct wl_listener mode; struct wl_listener needs_swap; diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index 56404ec7..f2b65066 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -18,8 +18,8 @@ struct wlr_output_impl { int32_t hotspot_x, int32_t hotspot_y, bool update_pixels); bool (*move_cursor)(struct wlr_output *output, int x, int y); void (*destroy)(struct wlr_output *output); - void (*make_current)(struct wlr_output *output); - void (*swap_buffers)(struct wlr_output *output); + bool (*make_current)(struct wlr_output *output, int *buffer_age); + bool (*swap_buffers)(struct wlr_output *output); void (*set_gamma)(struct wlr_output *output, uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); uint32_t (*get_gamma_size)(struct wlr_output *output); diff --git a/include/wlr/render/egl.h b/include/wlr/render/egl.h index bdb8d286..c292a6f8 100644 --- a/include/wlr/render/egl.h +++ b/include/wlr/render/egl.h @@ -11,8 +11,12 @@ struct wlr_egl { EGLConfig config; EGLContext context; - const char *egl_exts; - const char *gl_exts; + const char *egl_exts_str; + const char *gl_exts_str; + + struct { + bool buffer_age; + } egl_exts; struct wl_display *wl_display; }; @@ -65,4 +69,10 @@ bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImageKHR image); */ const char *egl_error(void); +bool wlr_egl_make_current(struct wlr_egl *egl, EGLSurface surface, + int *buffer_age); + +// TODO: remove +int wlr_egl_get_buffer_age(struct wlr_egl *egl, EGLSurface surface); + #endif diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 33d27501..3267a608 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -33,6 +33,8 @@ struct wlr_output_cursor { struct wl_listener surface_destroy; }; +#define WLR_OUTPUT_PREVIOUS_DAMAGE_COUNT 2 + struct wlr_output_impl; struct wlr_output { @@ -55,7 +57,7 @@ struct wlr_output { enum wl_output_transform transform; bool needs_swap; - pixman_region32_t damage, previous_damage; + pixman_region32_t damage; float transform_matrix[16]; // Note: some backends may have zero modes @@ -104,13 +106,19 @@ void wlr_output_set_scale(struct wlr_output *output, float scale); void wlr_output_destroy(struct wlr_output *output); void wlr_output_effective_resolution(struct wlr_output *output, int *width, int *height); -void wlr_output_make_current(struct wlr_output *output); +/** + * Makes the output GL context current. + * + * `buffer_age` is set to the drawing buffer age in number of frames or -1 if + * unknown. + */ +bool wlr_output_make_current(struct wlr_output *output, int *buffer_age); /** * Swaps the output buffers. If the time of the frame isn't known, set `when` to * NULL. If the compositor doesn't support damage tracking, set `damage` to * NULL. */ -void wlr_output_swap_buffers(struct wlr_output *output, struct timespec *when, +bool wlr_output_swap_buffers(struct wlr_output *output, struct timespec *when, pixman_region32_t *damage); void wlr_output_set_gamma(struct wlr_output *output, uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); 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/rootston/output.c b/rootston/output.c index 7f539347..13e78082 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -294,11 +294,26 @@ static void render_output(struct roots_output *output) { wlr_output_set_fullscreen_surface(wlr_output, NULL); } + int buffer_age = -1; + wlr_output_make_current(wlr_output, &buffer_age); + pixman_region32_t damage; pixman_region32_init(&damage); - pixman_region32_union(&damage, &output->damage, &output->previous_damage); - pixman_region32_intersect_rect(&damage, &damage, 0, 0, wlr_output->width, - wlr_output->height); + if (buffer_age <= 0 || buffer_age - 1 > ROOTS_OUTPUT_PREVIOUS_DAMAGE_LEN) { + // Buffer new or too old, damage the whole output + pixman_region32_union_rect(&damage, &damage, 0, 0, + wlr_output->width, wlr_output->height); + } else { + pixman_region32_copy(&damage, &output->damage); + + size_t idx = output->previous_damage_idx; + for (int i = 0; i < buffer_age - 1; i++) { + int j = (idx + i) % ROOTS_OUTPUT_PREVIOUS_DAMAGE_LEN; + pixman_region32_union(&damage, &damage, &output->previous_damage[j]); + } + } + pixman_region32_intersect_rect(&damage, &damage, 0, 0, + wlr_output->width, wlr_output->height); if (!pixman_region32_not_empty(&damage) && !wlr_output->needs_swap) { // Output doesn't need swap and isn't damaged, skip rendering completely @@ -308,7 +323,6 @@ static void render_output(struct roots_output *output) { wlr_log(L_DEBUG, "render"); - wlr_output_make_current(wlr_output); wlr_renderer_begin(server->renderer, wlr_output); glEnable(GL_SCISSOR_TEST); @@ -384,7 +398,10 @@ renderer_end: wlr_renderer_end(server->renderer); wlr_output_swap_buffers(wlr_output, &now, &damage); output->frame_pending = true; - pixman_region32_copy(&output->previous_damage, &output->damage); + output->previous_damage_idx += ROOTS_OUTPUT_PREVIOUS_DAMAGE_LEN - 1; + output->previous_damage_idx %= ROOTS_OUTPUT_PREVIOUS_DAMAGE_LEN; + pixman_region32_copy(&output->previous_damage[output->previous_damage_idx], + &output->damage); pixman_region32_clear(&output->damage); output->last_frame = desktop->last_frame = now; @@ -551,7 +568,9 @@ void output_add_notify(struct wl_listener *listener, void *data) { output->wlr_output = wlr_output; wl_list_insert(&desktop->outputs, &output->link); pixman_region32_init(&output->damage); - pixman_region32_init(&output->previous_damage); + for (size_t i = 0; i < ROOTS_OUTPUT_PREVIOUS_DAMAGE_LEN; ++i) { + pixman_region32_init(&output->previous_damage[i]); + } output->frame.notify = output_handle_frame; wl_signal_add(&wlr_output->events.frame, &output->frame); @@ -610,7 +629,9 @@ void output_remove_notify(struct wl_listener *listener, void *data) { // sample->compositor); pixman_region32_fini(&output->damage); - pixman_region32_fini(&output->previous_damage); + for (size_t i = 0; i < ROOTS_OUTPUT_PREVIOUS_DAMAGE_LEN; ++i) { + pixman_region32_fini(&output->previous_damage[i]); + } wl_list_remove(&output->link); wl_list_remove(&output->frame.link); wl_list_remove(&output->mode.link); diff --git a/types/wlr_output.c b/types/wlr_output.c index 4dd2ecc7..83b4166d 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -281,7 +281,6 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, wl_signal_init(&output->events.transform); wl_signal_init(&output->events.destroy); pixman_region32_init(&output->damage); - pixman_region32_init(&output->previous_damage); output->display_destroy.notify = handle_display_destroy; wl_display_add_destroy_listener(display, &output->display_destroy); @@ -310,7 +309,6 @@ void wlr_output_destroy(struct wlr_output *output) { } pixman_region32_fini(&output->damage); - pixman_region32_fini(&output->previous_damage); if (output->impl && output->impl->destroy) { output->impl->destroy(output); @@ -332,8 +330,8 @@ void wlr_output_effective_resolution(struct wlr_output *output, *height /= output->scale; } -void wlr_output_make_current(struct wlr_output *output) { - output->impl->make_current(output); +bool wlr_output_make_current(struct wlr_output *output, int *buffer_age) { + return output->impl->make_current(output, buffer_age); } static void output_fullscreen_surface_get_box(struct wlr_output *output, @@ -466,17 +464,17 @@ surface_damage_finish: pixman_region32_fini(&surface_damage); } -void wlr_output_swap_buffers(struct wlr_output *output, struct timespec *when, +bool wlr_output_swap_buffers(struct wlr_output *output, struct timespec *when, pixman_region32_t *damage) { wl_signal_emit(&output->events.swap_buffers, damage); pixman_region32_t *render_damage = damage; if (damage == NULL) { + // Damage tracking not supported, repaint the whole output pixman_region32_t output_damage; pixman_region32_init(&output_damage); - pixman_region32_copy(&output_damage, &output->damage); - pixman_region32_union(&output_damage, &output_damage, - &output->previous_damage); + pixman_region32_union_rect(&output_damage, &output_damage, + 0, 0, output->width, output->height); render_damage = &output_damage; } @@ -503,14 +501,18 @@ void wlr_output_swap_buffers(struct wlr_output *output, struct timespec *when, } // TODO: provide `damage` (not `render_damage`) to backend - output->impl->swap_buffers(output); + if (!output->impl->swap_buffers(output)) { + return false; + } + output->needs_swap = false; - pixman_region32_copy(&output->previous_damage, &output->damage); pixman_region32_clear(&output->damage); if (damage == NULL) { pixman_region32_fini(render_damage); } + + return true; } void wlr_output_set_gamma(struct wlr_output *output, diff --git a/types/wlr_screenshooter.c b/types/wlr_screenshooter.c index 4d591c45..e24b85f1 100644 --- a/types/wlr_screenshooter.c +++ b/types/wlr_screenshooter.c @@ -47,7 +47,6 @@ static void output_frame_notify(struct wl_listener *listener, void *_data) { struct wlr_renderer *renderer = state->screenshot->screenshooter->renderer; struct wlr_output *output = state->screenshot->output; - wlr_output_make_current(output); wlr_renderer_read_pixels(renderer, 0, 0, output->width, output->height, state->pixels); -- cgit v1.2.3 From 415a2b7c569457ebf85d7ae066cc19bee196d22e Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 22 Jan 2018 16:42:22 +0100 Subject: render: add wlr_renderer_clear and wlr_renderer_scissor --- examples/output-layout.c | 1 + examples/rotation.c | 1 + examples/tablet.c | 1 + examples/touch.c | 1 + include/wlr/render.h | 4 ++++ include/wlr/render/egl.h | 3 --- include/wlr/render/interface.h | 4 ++++ render/gles2/renderer.c | 40 +++++++++++++++++++++++++++++----------- render/wlr_renderer.c | 9 +++++++++ rootston/output.c | 26 +++++++++++++++++--------- 10 files changed, 67 insertions(+), 23 deletions(-) (limited to 'render') diff --git a/examples/output-layout.c b/examples/output-layout.c index b97d3723..0c85ba7f 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -102,6 +102,7 @@ static void handle_output_frame(struct output_state *output, wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); + wlr_renderer_clear(sample->renderer, 0.25f, 0.25f, 0.25f, 1); animate_cat(sample, output->output); diff --git a/examples/rotation.c b/examples/rotation.c index 64de73f9..4f7b1567 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -44,6 +44,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); + wlr_renderer_clear(sample->renderer, 0.25f, 0.25f, 0.25f, 1); float matrix[16]; for (int y = -128 + (int)odata->y_offs; y < height; y += 128) { diff --git a/examples/tablet.c b/examples/tablet.c index 35326664..f12ecbc4 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -44,6 +44,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); + wlr_renderer_clear(sample->renderer, 0.25f, 0.25f, 0.25f, 1); float matrix[16], view[16]; float distance = 0.8f * (1 - sample->distance); diff --git a/examples/touch.c b/examples/touch.c index 74642b96..2ef2712f 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -43,6 +43,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); + wlr_renderer_clear(sample->renderer, 0.25f, 0.25f, 0.25f, 1); float matrix[16]; struct touch_point *p; diff --git a/include/wlr/render.h b/include/wlr/render.h index 5027064d..bfd9e829 100644 --- a/include/wlr/render.h +++ b/include/wlr/render.h @@ -5,6 +5,7 @@ #include #include #include +#include #include struct wlr_texture; @@ -12,6 +13,9 @@ struct wlr_renderer; void wlr_renderer_begin(struct wlr_renderer *r, struct wlr_output *output); void wlr_renderer_end(struct wlr_renderer *r); +void wlr_renderer_clear(struct wlr_renderer *r, float red, float green, + float blue, float alpha); +void wlr_renderer_scissor(struct wlr_renderer *r, struct wlr_box *box); /** * Requests a texture handle from this renderer. */ diff --git a/include/wlr/render/egl.h b/include/wlr/render/egl.h index c292a6f8..6979fd9b 100644 --- a/include/wlr/render/egl.h +++ b/include/wlr/render/egl.h @@ -72,7 +72,4 @@ const char *egl_error(void); bool wlr_egl_make_current(struct wlr_egl *egl, EGLSurface surface, int *buffer_age); -// TODO: remove -int wlr_egl_get_buffer_age(struct wlr_egl *egl, EGLSurface surface); - #endif diff --git a/include/wlr/render/interface.h b/include/wlr/render/interface.h index bbc5acb4..3927795d 100644 --- a/include/wlr/render/interface.h +++ b/include/wlr/render/interface.h @@ -6,6 +6,7 @@ #include #include #include +#include #include struct wlr_renderer_impl; @@ -17,6 +18,9 @@ struct wlr_renderer { struct wlr_renderer_impl { void (*begin)(struct wlr_renderer *renderer, struct wlr_output *output); void (*end)(struct wlr_renderer *renderer); + void (*clear)(struct wlr_renderer *renderer, float red, float green, + float blue, float alpha); + void (*scissor)(struct wlr_renderer *renderer, struct wlr_box *box); struct wlr_texture *(*texture_create)(struct wlr_renderer *renderer); bool (*render_with_matrix)(struct wlr_renderer *renderer, struct wlr_texture *texture, const float (*matrix)[16]); diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 32f2eb02..3909fd84 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -105,7 +105,7 @@ 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) { GL_CALL(glViewport(0, 0, output->width, output->height)); @@ -117,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, float red, + float green, float blue, float alpha) { + glClearColor(red, green, blue, alpha); + 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); } @@ -154,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"); @@ -169,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_TRUE, *matrix)); @@ -177,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)); @@ -197,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); @@ -216,8 +232,8 @@ static void rgba_to_argb(uint32_t *data, size_t height, size_t stride) { } } -static void wlr_gles2_read_pixels(struct wlr_renderer *renderer, int x, int y, - int width, int height, void *out_data) { +static void wlr_gles2_read_pixels(struct wlr_renderer *wlr_renderer, + int x, int y, int width, int height, void *out_data) { glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, out_data); rgba_to_argb(out_data, height, width*4); } @@ -225,6 +241,8 @@ static void wlr_gles2_read_pixels(struct wlr_renderer *renderer, int x, int y, 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/wlr_renderer.c b/render/wlr_renderer.c index ef0c31be..ba7d4b74 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -23,6 +23,15 @@ void wlr_renderer_end(struct wlr_renderer *r) { r->impl->end(r); } +void wlr_renderer_clear(struct wlr_renderer *r, float red, float green, + float blue, float alpha) { + r->impl->clear(r, red, green, blue, alpha); +} + +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); } diff --git a/rootston/output.c b/rootston/output.c index 644fca92..b6879965 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -247,8 +246,13 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly, pixman_box32_t *rects = pixman_region32_rectangles(&surface_damage, &nrects); for (int i = 0; i < nrects; ++i) { - glScissor(rects[i].x1, output->wlr_output->height - rects[i].y2, - rects[i].x2 - rects[i].x1, rects[i].y2 - rects[i].y1); + struct wlr_box scissor = { + .x = rects[i].x1, + .y = output->wlr_output->height - rects[i].y2, + .width = rects[i].x2 - rects[i].x1, + .height = rects[i].y2 - rects[i].y1, + }; + wlr_renderer_scissor(output->desktop->server->renderer, &scissor); wlr_render_with_matrix(output->desktop->server->renderer, surface->texture, &matrix); } @@ -353,7 +357,6 @@ static void render_output(struct roots_output *output) { }; wlr_renderer_begin(server->renderer, wlr_output); - glEnable(GL_SCISSOR_TEST); if (!pixman_region32_not_empty(&damage)) { // Output isn't damaged but needs buffer swap @@ -363,10 +366,15 @@ static void render_output(struct roots_output *output) { int nrects; pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); for (int i = 0; i < nrects; ++i) { - glScissor(rects[i].x1, wlr_output->height - rects[i].y2, - rects[i].x2 - rects[i].x1, rects[i].y2 - rects[i].y1); - glClearColor(clear_color[0], clear_color[1], clear_color[2], 1); - glClear(GL_COLOR_BUFFER_BIT); + struct wlr_box scissor = { + .x = rects[i].x1, + .y = wlr_output->height - rects[i].y2, + .width = rects[i].x2 - rects[i].x1, + .height = rects[i].y2 - rects[i].y1, + }; + wlr_renderer_scissor(output->desktop->server->renderer, &scissor); + wlr_renderer_clear(output->desktop->server->renderer, + clear_color[0], clear_color[1], clear_color[2], 1); } // If a view is fullscreen on this output, render it @@ -425,7 +433,7 @@ static void render_output(struct roots_output *output) { } renderer_end: - glDisable(GL_SCISSOR_TEST); + wlr_renderer_scissor(output->desktop->server->renderer, NULL); wlr_renderer_end(server->renderer); wlr_output_swap_buffers(wlr_output, &now, &damage); output->frame_pending = true; -- cgit v1.2.3 From ddb1779f9fee28b6393ba6607852a078ed65575f Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 3 Feb 2018 09:32:02 +0100 Subject: render: make wlr_renderer_clear take a float[4] for the color --- examples/output-layout.c | 2 +- examples/rotation.c | 2 +- examples/tablet.c | 2 +- examples/touch.c | 2 +- include/wlr/render.h | 3 +-- include/wlr/render/interface.h | 3 +-- render/gles2/renderer.c | 6 +++--- render/wlr_renderer.c | 5 ++--- rootston/output.c | 5 ++--- 9 files changed, 13 insertions(+), 17 deletions(-) (limited to 'render') diff --git a/examples/output-layout.c b/examples/output-layout.c index 0c85ba7f..91ab80f4 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -102,7 +102,7 @@ static void handle_output_frame(struct output_state *output, wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); - wlr_renderer_clear(sample->renderer, 0.25f, 0.25f, 0.25f, 1); + wlr_renderer_clear(sample->renderer, &(float[]){0.25f, 0.25f, 0.25f, 1}); animate_cat(sample, output->output); diff --git a/examples/rotation.c b/examples/rotation.c index 4f7b1567..e390daaf 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -44,7 +44,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); - wlr_renderer_clear(sample->renderer, 0.25f, 0.25f, 0.25f, 1); + wlr_renderer_clear(sample->renderer, &(float[]){0.25f, 0.25f, 0.25f, 1}); float matrix[16]; for (int y = -128 + (int)odata->y_offs; y < height; y += 128) { diff --git a/examples/tablet.c b/examples/tablet.c index f12ecbc4..ca76ec5a 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -44,7 +44,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); - wlr_renderer_clear(sample->renderer, 0.25f, 0.25f, 0.25f, 1); + wlr_renderer_clear(sample->renderer, &(float[]){0.25f, 0.25f, 0.25f, 1}); float matrix[16], view[16]; float distance = 0.8f * (1 - sample->distance); diff --git a/examples/touch.c b/examples/touch.c index 2ef2712f..3cf00e9c 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -43,7 +43,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_make_current(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output); - wlr_renderer_clear(sample->renderer, 0.25f, 0.25f, 0.25f, 1); + wlr_renderer_clear(sample->renderer, &(float[]){0.25f, 0.25f, 0.25f, 1}); float matrix[16]; struct touch_point *p; diff --git a/include/wlr/render.h b/include/wlr/render.h index c277ab17..ccc66d36 100644 --- a/include/wlr/render.h +++ b/include/wlr/render.h @@ -13,8 +13,7 @@ struct wlr_renderer; void wlr_renderer_begin(struct wlr_renderer *r, struct wlr_output *output); void wlr_renderer_end(struct wlr_renderer *r); -void wlr_renderer_clear(struct wlr_renderer *r, float red, float green, - float blue, float alpha); +void wlr_renderer_clear(struct wlr_renderer *r, const float (*color)[4]); /** * Defines a scissor box. Only pixels that lie within the scissor box can be * modified by drawing functions. Providing a NULL `box` disables the scissor diff --git a/include/wlr/render/interface.h b/include/wlr/render/interface.h index 2531f33c..b8e99898 100644 --- a/include/wlr/render/interface.h +++ b/include/wlr/render/interface.h @@ -18,8 +18,7 @@ struct wlr_renderer { struct wlr_renderer_impl { void (*begin)(struct wlr_renderer *renderer, struct wlr_output *output); void (*end)(struct wlr_renderer *renderer); - void (*clear)(struct wlr_renderer *renderer, float red, float green, - float blue, float alpha); + void (*clear)(struct wlr_renderer *renderer, const float (*color)[4]); void (*scissor)(struct wlr_renderer *renderer, struct wlr_box *box); struct wlr_texture *(*texture_create)(struct wlr_renderer *renderer); bool (*render_with_matrix)(struct wlr_renderer *renderer, diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index bdb62ff3..f57e9dae 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -121,9 +121,9 @@ static void wlr_gles2_end(struct wlr_renderer *wlr_renderer) { // no-op } -static void wlr_gles2_clear(struct wlr_renderer *wlr_renderer, float red, - float green, float blue, float alpha) { - glClearColor(red, green, blue, alpha); +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); } diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index b60a3f73..c8f06a64 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -23,9 +23,8 @@ void wlr_renderer_end(struct wlr_renderer *r) { r->impl->end(r); } -void wlr_renderer_clear(struct wlr_renderer *r, float red, float green, - float blue, float alpha) { - r->impl->clear(r, red, green, blue, alpha); +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) { diff --git a/rootston/output.c b/rootston/output.c index 96e466a7..7c520d86 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -361,7 +361,7 @@ static void render_output(struct roots_output *output) { struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); - float clear_color[] = {0.25f, 0.25f, 0.25f}; + float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f}; // Check if we can delegate the fullscreen surface to the output if (output->fullscreen_view != NULL) { @@ -438,8 +438,7 @@ static void render_output(struct roots_output *output) { pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); for (int i = 0; i < nrects; ++i) { scissor_output(output, &rects[i]); - wlr_renderer_clear(renderer, clear_color[0], clear_color[1], - clear_color[2], 1); + wlr_renderer_clear(renderer, &clear_color); } // If a view is fullscreen on this output, render it -- cgit v1.2.3