diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-02-10 12:04:30 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-02-11 00:17:10 +0100 |
commit | 4bffdfd6805edf1427f23c5a472681b3d3d6f1c8 (patch) | |
tree | 3f5d81968e10b5642439eb59cdb3743382c14f5c | |
parent | 48e29895942be00d391cee484ffa8f7fc4ce4c1c (diff) |
window: Use window surfaces for windowscairo_window_surface
-rw-r--r-- | clients/Makefile.am | 2 | ||||
-rw-r--r-- | clients/dnd.c | 4 | ||||
-rw-r--r-- | clients/gears.c | 1 | ||||
-rw-r--r-- | clients/window.c | 164 | ||||
-rw-r--r-- | clients/window.h | 2 | ||||
-rw-r--r-- | configure.ac | 6 |
6 files changed, 155 insertions, 24 deletions
diff --git a/clients/Makefile.am b/clients/Makefile.am index 6c92a1c..a2de173 100644 --- a/clients/Makefile.am +++ b/clients/Makefile.am @@ -31,7 +31,7 @@ libtoytoolkit_la_SOURCES = \ toolkit_libs = \ libtoytoolkit.la \ $(top_builddir)/wayland/libwayland-client.la \ - $(CLIENT_LIBS) -lrt -lm -lwayland-egl + $(CLIENT_LIBS) -lrt -lm gears_SOURCES = gears.c gears_LDADD = $(toolkit_libs) diff --git a/clients/dnd.c b/clients/dnd.c index 1625ffd..a842b68 100644 --- a/clients/dnd.c +++ b/clients/dnd.c @@ -110,7 +110,7 @@ item_create(struct display *display, int x, int y, int seed) rect.width = item_width; rect.height = item_height; - item->surface = display_create_surface(display, &rect); + item->surface = display_create_surface(display, NULL, &rect); item->x = x; item->y = y; @@ -527,7 +527,7 @@ create_drag_cursor(struct dnd_drag *dnd_drag, rectangle.width = item_width + 2 * pointer_width; rectangle.height = item_height + 2 * pointer_height; - surface = display_create_surface(dnd->display, &rectangle); + surface = display_create_surface(dnd->display, NULL, &rectangle); cr = cairo_create(surface); cairo_translate(cr, pointer_width, pointer_height); diff --git a/clients/gears.c b/clients/gears.c index 8496abb..2df79c3 100644 --- a/clients/gears.c +++ b/clients/gears.c @@ -359,6 +359,7 @@ gears_create(struct display *display) gears->d = display; gears->window = window_create(display, width, height); window_set_title(gears->window, "Wayland Gears"); + window_set_buffer_type(gears->window, WINDOW_BUFFER_TYPE_EGL_IMAGE); gears->display = display_get_egl_display(gears->d); if (gears->display == NULL) diff --git a/clients/window.c b/clients/window.c index c8836a8..6721f73 100644 --- a/clients/window.c +++ b/clients/window.c @@ -66,6 +66,7 @@ struct display { struct rectangle screen_allocation; int authenticated; EGLDisplay dpy; + EGLConfig conf; EGLContext ctx; cairo_device_t *device; int fd; @@ -188,6 +189,64 @@ struct surface_data { #ifdef HAVE_CAIRO_EGL +struct egl_window_surface_data { + struct display *display; + struct wl_surface *surface; + struct wl_egl_window *window; + EGLSurface surf; +}; + +static void +egl_window_surface_data_destroy(void *p) +{ + struct egl_window_surface_data *data = p; + struct display *d = data->display; + + eglDestroySurface(d->dpy, data->surf); + wl_egl_window_destroy(data->window); + data->surface = NULL; + + free(p); +} + +static cairo_surface_t * +display_create_egl_window_surface(struct display *display, + struct wl_surface *surface, + struct rectangle *rectangle) +{ + cairo_surface_t *cairo_surface; + struct egl_window_surface_data *data; + struct wl_visual *visual; + + data = malloc(sizeof *data); + if (data == NULL) + return NULL; + + data->display = display; + data->surface = surface; + + visual = wl_display_get_premultiplied_argb_visual(display->display); + + data->window = wl_egl_window_create(display->native_dpy, + surface, + rectangle->width, + rectangle->height, + visual); + + data->surf = eglCreateWindowSurface(display->dpy, display->conf, + data->window, NULL); + + cairo_surface = cairo_gl_surface_create_for_egl(display->device, + data->surf, + rectangle->width, + rectangle->height); + + cairo_surface_set_user_data(cairo_surface, &surface_data_key, + data, egl_window_surface_data_destroy); + + return cairo_surface; +} + struct egl_image_surface_data { struct surface_data data; EGLImageKHR image; @@ -499,13 +558,20 @@ check_size(struct rectangle *rect) cairo_surface_t * display_create_surface(struct display *display, + struct wl_surface *surface, struct rectangle *rectangle) { if (check_size(rectangle) < 0) return NULL; #ifdef HAVE_CAIRO_EGL if (display->dpy) { - return display_create_egl_image_surface(display, rectangle); + if (surface) + return display_create_egl_window_surface(display, + surface, + rectangle); + else + return display_create_egl_image_surface(display, + rectangle); } #endif return display_create_shm_surface(display, rectangle); @@ -607,32 +673,52 @@ window_attach_surface(struct window *window) { struct display *display = window->display; struct wl_buffer *buffer; + struct egl_window_surface_data *data; int32_t x, y; + int width = window->allocation.width; + int height = window->allocation.height; - if (window->pending_surface != NULL) - return; - - window->pending_surface = window->cairo_surface; - window->cairo_surface = NULL; - - buffer = display_get_buffer_for_surface(display, - window->pending_surface); if (window->resize_edges & WINDOW_RESIZING_LEFT) - x = window->server_allocation.width - - window->allocation.width; + x = window->server_allocation.width - width; else x = 0; if (window->resize_edges & WINDOW_RESIZING_TOP) - y = window->server_allocation.height - - window->allocation.height; + y = window->server_allocation.height - height; else y = 0; - window->server_allocation = window->allocation; window->resize_edges = 0; - wl_surface_attach(window->surface, buffer, x, y); - wl_display_sync_callback(display->display, free_surface, window); + + switch (window->buffer_type) { + case WINDOW_BUFFER_TYPE_EGL_WINDOW: + data = cairo_surface_get_user_data(window->cairo_surface, + &surface_data_key); + + wl_egl_window_resize(data->window, width, height, x, y); + cairo_gl_surface_swapbuffers(window->cairo_surface); + wl_egl_window_get_attached_size(data->window, + &window->server_allocation.width, + &window->server_allocation.height); + break; + case WINDOW_BUFFER_TYPE_EGL_IMAGE: + case WINDOW_BUFFER_TYPE_SHM: + if (window->pending_surface != NULL) + return; + + window->pending_surface = window->cairo_surface; + window->cairo_surface = NULL; + + buffer = + display_get_buffer_for_surface(display, + window->pending_surface); + + wl_surface_attach(window->surface, buffer, x, y); + window->server_allocation = window->allocation; + wl_display_sync_callback(display->display, free_surface, + window); + break; + } if (window->fullscreen) wl_surface_map_fullscreen(window->surface); @@ -666,6 +752,22 @@ window_set_surface(struct window *window, cairo_surface_t *surface) window->cairo_surface = surface; } +static void +window_resize_cairo_window_surface(struct window *window) +{ + struct egl_window_surface_data *data; + + data = cairo_surface_get_user_data(window->cairo_surface, + &surface_data_key); + + wl_egl_window_resize(data->window, + window->allocation.width, + window->allocation.height, 0, 0); + cairo_gl_surface_set_size(window->cairo_surface, + window->allocation.width, + window->allocation.height); +} + void window_create_surface(struct window *window) { @@ -673,8 +775,18 @@ window_create_surface(struct window *window) switch (window->buffer_type) { #ifdef HAVE_CAIRO_EGL + case WINDOW_BUFFER_TYPE_EGL_WINDOW: + if (window->cairo_surface) { + window_resize_cairo_window_surface(window); + return; + } + surface = display_create_surface(window->display, + window->surface, + &window->allocation); + break; case WINDOW_BUFFER_TYPE_EGL_IMAGE: surface = display_create_surface(window->display, + NULL, &window->allocation); break; #endif @@ -1325,7 +1437,8 @@ window_create_internal(struct display *display, struct window *parent, window->decoration = 1; if (display->dpy) - window->buffer_type = WINDOW_BUFFER_TYPE_EGL_IMAGE; + /* FIXME: make TYPE_EGL_IMAGE choosable for testing */ + window->buffer_type = WINDOW_BUFFER_TYPE_EGL_WINDOW; else window->buffer_type = WINDOW_BUFFER_TYPE_SHM; @@ -1595,6 +1708,16 @@ static int init_egl(struct display *d) { EGLint major, minor; + EGLint n; + static const EGLint cfg_attribs[] = { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PIXMAP_BIT, + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_DEPTH_SIZE, 1, + EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, + EGL_NONE + }; d->dpy = eglGetDisplay(d->native_dpy); if (!eglInitialize(d->dpy, &major, &minor)) { @@ -1607,7 +1730,12 @@ init_egl(struct display *d) return -1; } - d->ctx = eglCreateContext(d->dpy, NULL, EGL_NO_CONTEXT, NULL); + if (!eglChooseConfig(d->dpy, cfg_attribs, &d->conf, 1, &n) || n != 1) { + fprintf(stderr, "failed to choose config\n"); + return -1; + } + + d->ctx = eglCreateContext(d->dpy, d->conf, EGL_NO_CONTEXT, NULL); if (d->ctx == NULL) { fprintf(stderr, "failed to create context\n"); return -1; diff --git a/clients/window.h b/clients/window.h index 7073f4a..c1c5212 100644 --- a/clients/window.h +++ b/clients/window.h @@ -64,6 +64,7 @@ display_get_image_for_egl_image_surface(struct display *display, cairo_surface_t * display_create_surface(struct display *display, + struct wl_surface *surface, struct rectangle *rectangle); struct wl_buffer * @@ -167,6 +168,7 @@ void window_create_surface(struct window *window); enum window_buffer_type { + WINDOW_BUFFER_TYPE_EGL_WINDOW, WINDOW_BUFFER_TYPE_EGL_IMAGE, WINDOW_BUFFER_TYPE_SHM, }; diff --git a/configure.ac b/configure.ac index b671722..11ee5d4 100644 --- a/configure.ac +++ b/configure.ac @@ -24,8 +24,8 @@ PKG_CHECK_MODULES(FFI, [libffi]) PKG_CHECK_MODULES(COMPOSITOR, [egl >= 7.10 glesv2 gdk-pixbuf-2.0 libudev >= 136 libdrm >= 2.4.23] xcb-dri2 xcb-xfixes) -PKG_CHECK_MODULES(GLES2, [egl >= 7.10 glesv2]) -PKG_CHECK_MODULES(CLIENT, [egl >= 7.10 gl cairo >= 1.10.0 gdk-pixbuf-2.0 glib-2.0 gobject-2.0 xkbcommon]) +PKG_CHECK_MODULES(GLES2, [egl >= 7.10 glesv2 wayland-egl]) +PKG_CHECK_MODULES(CLIENT, [egl >= 7.10 gl cairo >= 1.10.0 gdk-pixbuf-2.0 glib-2.0 gobject-2.0 xkbcommon wayland-egl]) PKG_CHECK_MODULES(POPPLER, [poppler-glib gdk-2.0 gio-2.0], [have_poppler=yes], [have_poppler=no]) AM_CONDITIONAL(HAVE_POPPLER, test "x$have_poppler" = "xyes") @@ -59,7 +59,7 @@ if test x$enable_wayland_compositor == xyes; then fi -PKG_CHECK_MODULES(CAIRO_EGL, [cairo-egl], +PKG_CHECK_MODULES(CAIRO_EGL, [cairo-egl >= 1.11.3], [have_cairo_egl=yes], [have_cairo_egl=no]) AS_IF([test "x$have_cairo_egl" = "xyes"], [AC_DEFINE([HAVE_CAIRO_EGL], [1], [Have cairo-egl])]) |