aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/compositor/main.c1
-rw-r--r--examples/compositor/wl_compositor.c3
-rw-r--r--include/wlr/types/wlr_region.h3
-rw-r--r--include/wlr/types/wlr_surface.h3
-rw-r--r--render/gles2/renderer.c5
-rw-r--r--render/gles2/texture.c14
-rw-r--r--types/wlr_region.c19
-rw-r--r--types/wlr_surface.c56
8 files changed, 80 insertions, 24 deletions
diff --git a/examples/compositor/main.c b/examples/compositor/main.c
index 7ac549e5..fd592600 100644
--- a/examples/compositor/main.c
+++ b/examples/compositor/main.c
@@ -42,6 +42,7 @@ void handle_output_frame(struct output_state *output, struct timespec *ts) {
float matrix[16];
wl_list_for_each(_res, &sample->compositor.surfaces, link) {
struct wlr_surface *surface = wl_resource_get_user_data(_res);
+ wlr_surface_flush_damage(surface);
if (surface->texture->valid) {
wlr_texture_get_matrix(surface->texture, &matrix,
&wlr_output->transform_matrix, 200, 200);
diff --git a/examples/compositor/wl_compositor.c b/examples/compositor/wl_compositor.c
index 66c069ba..e25dddac 100644
--- a/examples/compositor/wl_compositor.c
+++ b/examples/compositor/wl_compositor.c
@@ -3,6 +3,7 @@
#include <wayland-server.h>
#include <wlr/util/log.h>
#include <wlr/types/wlr_surface.h>
+#include <wlr/types/wlr_region.h>
#include "compositor.h"
static void destroy_surface_listener(struct wl_listener *listener, void *data) {
@@ -33,7 +34,7 @@ static void wl_compositor_create_surface(struct wl_client *client,
static void wl_compositor_create_region(struct wl_client *client,
struct wl_resource *resource, uint32_t id) {
- wlr_log(L_DEBUG, "TODO: implement create_region");
+ wlr_region_create(client, resource, id);
}
struct wl_compositor_interface wl_compositor_impl = {
diff --git a/include/wlr/types/wlr_region.h b/include/wlr/types/wlr_region.h
index 9fff0150..0aff48a3 100644
--- a/include/wlr/types/wlr_region.h
+++ b/include/wlr/types/wlr_region.h
@@ -5,6 +5,7 @@ struct wl_resource;
// Implements the given resource as region.
// Sets the associated pixman_region32_t as userdata.
-void wlr_region_create(struct wl_resource *res);
+void wlr_region_create(struct wl_client *client, struct wl_resource *res,
+ uint32_t id);
#endif
diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h
index a195798f..c9cbeba6 100644
--- a/include/wlr/types/wlr_surface.h
+++ b/include/wlr/types/wlr_surface.h
@@ -48,6 +48,7 @@ struct wlr_surface {
struct wlr_renderer;
struct wlr_surface *wlr_surface_create(struct wl_resource *res,
- struct wlr_renderer *renderer);
+ struct wlr_renderer *renderer);
+void wlr_surface_flush_damage(struct wlr_surface *surface);
#endif
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c
index 729eaa75..0de777cc 100644
--- a/render/gles2/renderer.c
+++ b/render/gles2/renderer.c
@@ -109,6 +109,11 @@ static void wlr_gles2_begin(struct wlr_renderer_state *state,
int32_t width = output->width;
int32_t height = output->height;
GL_CALL(glViewport(0, 0, width, height));
+
+ // enable transparency
+ GL_CALL(glEnable(GL_BLEND));
+ GL_CALL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
+
// Note: maybe we should save output projection and remove some of the need
// for users to sling matricies themselves
}
diff --git a/render/gles2/texture.c b/render/gles2/texture.c
index b7de65be..2a2073c6 100644
--- a/render/gles2/texture.c
+++ b/render/gles2/texture.c
@@ -61,7 +61,9 @@ static bool gles2_texture_update_pixels(struct wlr_texture_state *texture,
assert(texture && texture->wlr_texture->valid);
// TODO: Test if the unpack subimage extension is supported and adjust the
// upload strategy if not
- if (texture->wlr_texture->format != format) {
+ if (!texture->wlr_texture->valid
+ || texture->wlr_texture->format != format
+ /* || unpack not supported */) {
return gles2_texture_upload_pixels(texture, format, stride,
width, height, pixels);
}
@@ -112,8 +114,10 @@ static bool gles2_texture_update_shm(struct wlr_texture_state *texture,
struct wl_shm_buffer *buffer) {
// TODO: Test if the unpack subimage extension is supported and adjust the
// upload strategy if not
- assert(texture && texture->wlr_texture->valid);
- if (texture->wlr_texture->format != format) {
+ assert(texture);
+ if (!texture->wlr_texture->valid
+ || texture->wlr_texture->format != format
+ /* || unpack not supported */) {
return gles2_texture_upload_shm(texture, format, buffer);
}
const struct pixel_format *fmt = texture->pixel_format;
@@ -125,8 +129,8 @@ static bool gles2_texture_update_shm(struct wlr_texture_state *texture,
GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, pitch));
GL_CALL(glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, x));
GL_CALL(glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, y));
- GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, fmt->gl_format, width, height, 0,
- fmt->gl_format, fmt->gl_type, pixels));
+ GL_CALL(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height,
+ fmt->gl_format, fmt->gl_type, pixels));
GL_CALL(glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, 0));
GL_CALL(glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, 0));
diff --git a/types/wlr_region.c b/types/wlr_region.c
index a1c45542..dead3784 100644
--- a/types/wlr_region.c
+++ b/types/wlr_region.c
@@ -37,8 +37,23 @@ static void destroy_region(struct wl_resource *resource) {
free(reg);
}
-void wlr_region_create(struct wl_resource *res) {
+void wlr_region_create(struct wl_client *client, struct wl_resource *res,
+ uint32_t id) {
pixman_region32_t *region = calloc(1, sizeof(pixman_region32_t));
+ if (region == NULL) {
+ wl_resource_post_no_memory(res);
+ return;
+ }
+
pixman_region32_init(region);
- wl_resource_set_implementation(res, &region_interface, region, destroy_region);
+
+ struct wl_resource *region_resource = wl_resource_create(client,
+ &wl_region_interface, 1, id);
+ if (region_resource == NULL) {
+ free(region);
+ wl_resource_post_no_memory(res);
+ return;
+ }
+ wl_resource_set_implementation(region_resource, &region_interface, region,
+ destroy_region);
}
diff --git a/types/wlr_surface.c b/types/wlr_surface.c
index ff83db83..1ce4926e 100644
--- a/types/wlr_surface.c
+++ b/types/wlr_surface.c
@@ -4,6 +4,7 @@
#include <wlr/util/log.h>
#include <wlr/render/interface.h>
#include <wlr/types/wlr_surface.h>
+#include "backend/egl.h"
static void surface_destroy(struct wl_client *client, struct wl_resource *resource) {
wl_resource_destroy(resource);
@@ -95,20 +96,6 @@ static void surface_commit(struct wl_client *client,
if ((surface->pending.invalid & WLR_SURFACE_INVALID_BUFFER)) {
surface->current.buffer = surface->pending.buffer;
- // TODO: Move to wlr_surface_flush_damage and call from output frame
- // callbacks instead of immediately here
- if (surface->current.buffer) {
- struct wl_shm_buffer *buffer = wl_shm_buffer_get(surface->current.buffer);
- if (buffer) {
- uint32_t format = wl_shm_buffer_get_format(buffer);
- wlr_texture_upload_shm(surface->texture, format, buffer);
- wl_resource_queue_event(surface->current.buffer, WL_BUFFER_RELEASE);
- } else if (wlr_texture_upload_drm(surface->texture, surface->pending.buffer)) {
- wl_resource_queue_event(surface->current.buffer, WL_BUFFER_RELEASE);
- } else {
- wlr_log(L_INFO, "Unknown buffer handle attached");
- }
- }
}
if ((surface->pending.invalid & WLR_SURFACE_INVALID_SURFACE_DAMAGE)) {
// TODO: Sort out buffer damage too
@@ -128,6 +115,47 @@ static void surface_commit(struct wl_client *client,
wl_signal_emit(&surface->signals.commit, surface);
}
+void wlr_surface_flush_damage(struct wlr_surface *surface) {
+ if (!surface->current.buffer) {
+ if (surface->texture->valid) {
+ // TODO: Detach buffers
+ }
+ return;
+ }
+ struct wl_shm_buffer *buffer = wl_shm_buffer_get(surface->current.buffer);
+ if (!buffer) {
+ EGLint format;
+ if (wlr_egl_query_buffer(surface->current.buffer, EGL_TEXTURE_FORMAT, &format)) {
+ wlr_texture_upload_drm(surface->texture, surface->pending.buffer);
+ goto release;
+ } else {
+ wlr_log(L_INFO, "Unknown buffer handle attached");
+ return;
+ }
+ }
+ pixman_region32_t damage = surface->current.surface_damage;
+ if (!pixman_region32_not_empty(&damage)) {
+ goto release;
+ }
+ int n;
+ pixman_box32_t *rects = pixman_region32_rectangles(&damage, &n);
+ uint32_t format = wl_shm_buffer_get_format(buffer);
+ for (int i = 0; i < n; ++i) {
+ pixman_box32_t rect = rects[i];
+ if (!wlr_texture_update_shm(surface->texture, format,
+ rect.x1, rect.y1,
+ rect.x2 - rect.x1,
+ rect.y2 - rect.y1,
+ buffer)) {
+ break;
+ }
+ }
+ pixman_region32_fini(&surface->current.surface_damage);
+ pixman_region32_init(&surface->current.surface_damage);
+release:
+ wl_resource_queue_event(surface->current.buffer, WL_BUFFER_RELEASE);
+}
+
static void surface_set_buffer_transform(struct wl_client *client,
struct wl_resource *resource, int transform) {
wlr_log(L_DEBUG, "TODO: surface surface buffer transform");