From 097425ca32b60dd966e8754d50687e43c52fd78b Mon Sep 17 00:00:00 2001 From: Junghoon Date: Mon, 31 Aug 2015 16:10:39 +0900 Subject: [PATCH] pepper: implement surface flush damage - and implement shm buffer upload in gl-renderer Change-Id: I26f5dc93b51522561400da0a6c912d885b5509fd --- src/lib/drm/drm-output.c | 7 +++++++ src/lib/fbdev/fbdev-output.c | 7 +++++++ src/lib/pepper/pepper-output-backend.h | 1 + src/lib/pepper/pepper.h | 6 +++--- src/lib/pepper/surface.c | 12 +++++++----- src/lib/render/gl-renderer.c | 32 +++++++++++++++++++++++++++++++- src/lib/wayland/wayland-output.c | 7 +++++++ src/lib/x11/x11-output.c | 7 +++++++ 8 files changed, 70 insertions(+), 9 deletions(-) diff --git a/src/lib/drm/drm-output.c b/src/lib/drm/drm-output.c index f3b859d..2664993 100644 --- a/src/lib/drm/drm-output.c +++ b/src/lib/drm/drm-output.c @@ -260,6 +260,12 @@ drm_output_attach_surface(void *o, pepper_surface_t *surface, int *w, int *h) pepper_renderer_attach_surface(output->renderer, surface, w, h); } +static void +drm_output_flush_surface(void *o, pepper_surface_t *surface) +{ + pepper_renderer_flush_surface_damage(((drm_output_t *)o)->renderer, surface); +} + struct pepper_output_backend drm_output_backend = { drm_output_destroy, @@ -275,6 +281,7 @@ struct pepper_output_backend drm_output_backend = drm_output_assign_planes, drm_output_repaint, drm_output_attach_surface, + drm_output_flush_surface, }; static int diff --git a/src/lib/fbdev/fbdev-output.c b/src/lib/fbdev/fbdev-output.c index 3891045..d9e74c5 100644 --- a/src/lib/fbdev/fbdev-output.c +++ b/src/lib/fbdev/fbdev-output.c @@ -202,6 +202,12 @@ fbdev_output_attach_surface(void *o, pepper_surface_t *surface, int *w, int *h) pepper_renderer_attach_surface(((fbdev_output_t *)o)->renderer, surface, w, h); } +static void +fbdev_output_flush_surface(void *o, pepper_surface_t *surface) +{ + pepper_renderer_flush_surface_damage(((fbdev_output_t *)o)->renderer, surface); +} + struct pepper_output_backend fbdev_output_backend = { fbdev_output_destroy, @@ -217,6 +223,7 @@ struct pepper_output_backend fbdev_output_backend = fbdev_output_assign_planes, fbdev_output_repaint, fbdev_output_attach_surface, + fbdev_output_flush_surface, }; static pepper_bool_t diff --git a/src/lib/pepper/pepper-output-backend.h b/src/lib/pepper/pepper-output-backend.h index 8673adf..e306aea 100644 --- a/src/lib/pepper/pepper-output-backend.h +++ b/src/lib/pepper/pepper-output-backend.h @@ -26,6 +26,7 @@ struct pepper_output_backend void (*assign_planes)(void *output, const pepper_list_t *view_list); void (*repaint)(void *output, const pepper_list_t *plane_list); void (*attach_surface)(void *output, pepper_surface_t *surface, int *w, int *h); + void (*flush_surface)(void *output, pepper_surface_t *surface); }; PEPPER_API pepper_output_t * diff --git a/src/lib/pepper/pepper.h b/src/lib/pepper/pepper.h index 265b016..7ec9c7b 100644 --- a/src/lib/pepper/pepper.h +++ b/src/lib/pepper/pepper.h @@ -394,13 +394,13 @@ pepper_surface_get_buffer_scale(pepper_surface_t *surface); PEPPER_API int32_t pepper_surface_get_buffer_transform(pepper_surface_t *surface); -PEPPER_API const pixman_region32_t * +PEPPER_API pixman_region32_t * pepper_surface_get_damage_region(pepper_surface_t *surface); -PEPPER_API const pixman_region32_t * +PEPPER_API pixman_region32_t * pepper_surface_get_opaque_region(pepper_surface_t *surface); -PEPPER_API const pixman_region32_t * +PEPPER_API pixman_region32_t * pepper_surface_get_input_region(pepper_surface_t *surface); /* Buffer. */ diff --git a/src/lib/pepper/surface.c b/src/lib/pepper/surface.c index 8ab7927..556c3ce 100644 --- a/src/lib/pepper/surface.c +++ b/src/lib/pepper/surface.c @@ -469,19 +469,19 @@ pepper_surface_get_buffer_transform(pepper_surface_t *surface) return surface->buffer.transform; } -PEPPER_API const pixman_region32_t * +PEPPER_API pixman_region32_t * pepper_surface_get_damage_region(pepper_surface_t *surface) { return &surface->damage_region; } -PEPPER_API const pixman_region32_t * +PEPPER_API pixman_region32_t * pepper_surface_get_opaque_region(pepper_surface_t *surface) { return &surface->opaque_region; } -PEPPER_API const pixman_region32_t * +PEPPER_API pixman_region32_t * pepper_surface_get_input_region(pepper_surface_t *surface) { return &surface->input_region; @@ -490,7 +490,8 @@ pepper_surface_get_input_region(pepper_surface_t *surface) void pepper_surface_flush_damage(pepper_surface_t *surface) { - pepper_view_t *view; + pepper_view_t *view; + pepper_output_t *output; if (!pixman_region32_not_empty(&surface->damage_region)) return; @@ -498,5 +499,6 @@ pepper_surface_flush_damage(pepper_surface_t *surface) pepper_list_for_each(view, &surface->view_list, surface_link) pepper_view_surface_damage(view); - /* TODO: Call backend.urface_flush(). */ + pepper_list_for_each(output, &surface->compositor->output_list, link) + output->backend->flush_surface(output->data, surface); } diff --git a/src/lib/render/gl-renderer.c b/src/lib/render/gl-renderer.c index 99f41ac..a1b0a7b 100644 --- a/src/lib/render/gl-renderer.c +++ b/src/lib/render/gl-renderer.c @@ -458,7 +458,37 @@ gl_renderer_flush_surface_damage(pepper_renderer_t *renderer, pepper_surface_t * if (state->buffer_type != BUFFER_TYPE_SHM) return PEPPER_TRUE; - /* TODO: Texture upload. */ + /* Texture upload. */ + if (state->shm.need_full_upload) + { + glBindTexture(GL_TEXTURE_2D, state->textures[0]); + wl_shm_buffer_begin_access(state->shm.buffer); + glTexImage2D(GL_TEXTURE_2D, 0, state->shm.format, + state->buffer_width, state->buffer_height, 0, + state->shm.format, state->shm.pixel_format, + wl_shm_buffer_get_data(state->shm.buffer)); + wl_shm_buffer_end_access(state->shm.buffer); + } + else + { + int i, nrects; + pixman_box32_t *rects; + pixman_region32_t *damage; + + damage = pepper_surface_get_damage_region(surface); + rects = pixman_region32_rectangles(damage, &nrects); /* FIXME: compile warning */ + + glBindTexture(GL_TEXTURE_2D, state->textures[0]); + wl_shm_buffer_begin_access(state->shm.buffer); + for (i = 0; i < nrects; i++) + { + glTexSubImage2D(GL_TEXTURE_2D, 0, rects[i].x1, rects[i].x2, + rects[i].x2 - rects[i].x1, rects[i].y2 - rects[i].y1, + state->shm.format, state->shm.pixel_format, + wl_shm_buffer_get_data(state->shm.buffer)); + } + wl_shm_buffer_end_access(state->shm.buffer); + } return PEPPER_TRUE; } diff --git a/src/lib/wayland/wayland-output.c b/src/lib/wayland/wayland-output.c index 40119b3..d0e4ca8 100644 --- a/src/lib/wayland/wayland-output.c +++ b/src/lib/wayland/wayland-output.c @@ -200,6 +200,12 @@ wayland_output_attach_surface(void *o, pepper_surface_t *surface, int *w, int *h pepper_renderer_attach_surface(((wayland_output_t *)o)->renderer, surface, w, h); } +static void +wayland_output_flush_surface(void *o, pepper_surface_t *surface) +{ + pepper_renderer_flush_surface_damage(((wayland_output_t *)o)->renderer, surface); +} + static const pepper_output_backend_t wayland_output_backend = { wayland_output_destroy, @@ -215,6 +221,7 @@ static const pepper_output_backend_t wayland_output_backend = wayland_output_assign_planes, wayland_output_repaint, wayland_output_attach_surface, + wayland_output_flush_surface, }; static void diff --git a/src/lib/x11/x11-output.c b/src/lib/x11/x11-output.c index 526bd6e..e2e2942 100644 --- a/src/lib/x11/x11-output.c +++ b/src/lib/x11/x11-output.c @@ -497,6 +497,12 @@ x11_output_attach_surface(void *o, pepper_surface_t *surface, int *w, int *h) pepper_renderer_attach_surface(((x11_output_t *)o)->renderer, surface, w, h); } +static void +x11_output_flush_surface(void *o, pepper_surface_t *surface) +{ + pepper_renderer_flush_surface_damage(((x11_output_t *)o)->renderer, surface); +} + /* X11 output backend to export for PePPer core */ static const pepper_output_backend_t x11_output_backend = { @@ -513,6 +519,7 @@ static const pepper_output_backend_t x11_output_backend = x11_output_assign_planes, x11_output_repaint, x11_output_attach_surface, + x11_output_flush_surface, }; PEPPER_API pepper_output_t * -- 2.7.4