window: Create a cairo device for each egl config

dev
Benjamin Franzke 13 years ago
parent 47eb8f4e91
commit 0c99163d9b
  1. 5
      clients/gears.c
  2. 102
      clients/window.c
  3. 8
      clients/window.h

@ -251,7 +251,7 @@ draw_gears(struct gears *gears)
glFlush(); glFlush();
display_release(gears->d); display_release_window_surface(gears->d, gears->window);
window_flush(gears->window); window_flush(gears->window);
} }
@ -315,6 +315,7 @@ gears_create(struct display *display)
memset(gears, 0, sizeof *gears); memset(gears, 0, sizeof *gears);
gears->d = display; gears->d = display;
gears->window = window_create(display, width, height); gears->window = window_create(display, width, height);
window_set_transparent(gears->window, 0);
window_set_title(gears->window, "Wayland Gears"); window_set_title(gears->window, "Wayland Gears");
gears->display = display_get_egl_display(gears->d); gears->display = display_get_egl_display(gears->d);
@ -323,7 +324,7 @@ gears_create(struct display *display)
eglBindAPI(EGL_OPENGL_API); eglBindAPI(EGL_OPENGL_API);
gears->config = display_get_egl_config(gears->d); gears->config = display_get_rgb_egl_config(gears->d);
gears->context = eglCreateContext(gears->display, gears->config, gears->context = eglCreateContext(gears->display, gears->config,
EGL_NO_CONTEXT, NULL); EGL_NO_CONTEXT, NULL);

@ -29,6 +29,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <math.h> #include <math.h>
#include <assert.h>
#include <time.h> #include <time.h>
#include <cairo.h> #include <cairo.h>
#include <glib.h> #include <glib.h>
@ -65,8 +66,10 @@ struct display {
EGLDisplay dpy; EGLDisplay dpy;
EGLConfig rgb_config; EGLConfig rgb_config;
EGLConfig premultiplied_argb_config; EGLConfig premultiplied_argb_config;
EGLContext ctx; EGLContext rgb_ctx;
cairo_device_t *device; EGLContext argb_ctx;
cairo_device_t *rgb_device;
cairo_device_t *argb_device;
int display_fd; int display_fd;
uint32_t mask; uint32_t mask;
@ -228,6 +231,7 @@ display_create_egl_window_surface(struct display *display,
struct egl_window_surface_data *data; struct egl_window_surface_data *data;
EGLConfig config; EGLConfig config;
const EGLint *attribs; const EGLint *attribs;
cairo_device_t *device;
static const EGLint premul_attribs[] = { static const EGLint premul_attribs[] = {
EGL_ALPHA_FORMAT, EGL_ALPHA_FORMAT_PRE, EGL_ALPHA_FORMAT, EGL_ALPHA_FORMAT_PRE,
@ -243,9 +247,11 @@ display_create_egl_window_surface(struct display *display,
if (flags & SURFACE_OPAQUE) { if (flags & SURFACE_OPAQUE) {
config = display->rgb_config; config = display->rgb_config;
device = display->rgb_device;
attribs = NULL; attribs = NULL;
} else { } else {
config = display->premultiplied_argb_config; config = display->premultiplied_argb_config;
device = display->argb_device;
attribs = premul_attribs; attribs = premul_attribs;
} }
@ -256,7 +262,7 @@ display_create_egl_window_surface(struct display *display,
data->surf = eglCreateWindowSurface(display->dpy, config, data->surf = eglCreateWindowSurface(display->dpy, config,
data->window, attribs); data->window, attribs);
cairo_surface = cairo_gl_surface_create_for_egl(display->device, cairo_surface = cairo_gl_surface_create_for_egl(device,
data->surf, data->surf,
rectangle->width, rectangle->width,
rectangle->height); rectangle->height);
@ -269,6 +275,7 @@ display_create_egl_window_surface(struct display *display,
struct egl_image_surface_data { struct egl_image_surface_data {
struct surface_data data; struct surface_data data;
cairo_device_t *device;
EGLImageKHR image; EGLImageKHR image;
GLuint texture; GLuint texture;
struct display *display; struct display *display;
@ -281,9 +288,9 @@ egl_image_surface_data_destroy(void *p)
struct egl_image_surface_data *data = p; struct egl_image_surface_data *data = p;
struct display *d = data->display; struct display *d = data->display;
cairo_device_acquire(d->device); cairo_device_acquire(data->device);
glDeleteTextures(1, &data->texture); glDeleteTextures(1, &data->texture);
cairo_device_release(d->device); cairo_device_release(data->device);
d->destroy_image(d->dpy, data->image); d->destroy_image(d->dpy, data->image);
wl_buffer_destroy(data->data.buffer); wl_buffer_destroy(data->data.buffer);
@ -311,6 +318,7 @@ display_create_egl_image_surface(struct display *display,
EGLDisplay dpy = display->dpy; EGLDisplay dpy = display->dpy;
cairo_surface_t *surface; cairo_surface_t *surface;
EGLConfig config; EGLConfig config;
cairo_content_t content;
data = malloc(sizeof *data); data = malloc(sizeof *data);
if (data == NULL) if (data == NULL)
@ -325,10 +333,15 @@ display_create_egl_image_surface(struct display *display,
return NULL; return NULL;
} }
if (flags & SURFACE_OPAQUE) if (flags & SURFACE_OPAQUE) {
data->device = display->rgb_device;
config = display->rgb_config; config = display->rgb_config;
else content = CAIRO_CONTENT_COLOR;
} else {
data->device = display->argb_device;
config = display->premultiplied_argb_config; config = display->premultiplied_argb_config;
content = CAIRO_CONTENT_COLOR_ALPHA;
}
data->image = display->create_image(dpy, NULL, data->image = display->create_image(dpy, NULL,
EGL_NATIVE_PIXMAP_KHR, EGL_NATIVE_PIXMAP_KHR,
@ -343,14 +356,14 @@ display_create_egl_image_surface(struct display *display,
data->data.buffer = data->data.buffer =
wl_egl_pixmap_create_buffer(data->pixmap); wl_egl_pixmap_create_buffer(data->pixmap);
cairo_device_acquire(display->device); cairo_device_acquire(data->device);
glGenTextures(1, &data->texture); glGenTextures(1, &data->texture);
glBindTexture(GL_TEXTURE_2D, data->texture); glBindTexture(GL_TEXTURE_2D, data->texture);
display->image_target_texture_2d(GL_TEXTURE_2D, data->image); display->image_target_texture_2d(GL_TEXTURE_2D, data->image);
cairo_device_release(display->device); cairo_device_release(data->device);
surface = cairo_gl_surface_create_for_texture(display->device, surface = cairo_gl_surface_create_for_texture(data->device,
CAIRO_CONTENT_COLOR_ALPHA, content,
data->texture, data->texture,
rectangle->width, rectangle->width,
rectangle->height); rectangle->height);
@ -411,11 +424,11 @@ display_create_egl_image_surface_from_file(struct display *display,
data = cairo_surface_get_user_data(surface, &surface_data_key); data = cairo_surface_get_user_data(surface, &surface_data_key);
cairo_device_acquire(display->device); cairo_device_acquire(display->argb_device);
glBindTexture(GL_TEXTURE_2D, data->texture); glBindTexture(GL_TEXTURE_2D, data->texture);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, rect->width, rect->height, glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, rect->width, rect->height,
GL_RGBA, GL_UNSIGNED_BYTE, pixels); GL_RGBA, GL_UNSIGNED_BYTE, pixels);
cairo_device_release(display->device); cairo_device_release(display->argb_device);
g_object_unref(pixbuf); g_object_unref(pixbuf);
@ -1403,7 +1416,8 @@ input_get_modifiers(struct input *input)
struct wl_drag * struct wl_drag *
window_create_drag(struct window *window) window_create_drag(struct window *window)
{ {
cairo_device_flush (window->display->device); cairo_device_flush (window->display->rgb_device);
cairo_device_flush (window->display->argb_device);
return wl_shell_create_drag(window->display->shell); return wl_shell_create_drag(window->display->shell);
} }
@ -2036,23 +2050,34 @@ init_egl(struct display *d)
return -1; return -1;
} }
d->ctx = eglCreateContext(d->dpy, d->rgb_config, EGL_NO_CONTEXT, NULL); d->rgb_ctx = eglCreateContext(d->dpy, d->rgb_config, EGL_NO_CONTEXT, NULL);
if (d->ctx == NULL) { if (d->rgb_ctx == NULL) {
fprintf(stderr, "failed to create context\n");
return -1;
}
d->argb_ctx = eglCreateContext(d->dpy, d->premultiplied_argb_config,
EGL_NO_CONTEXT, NULL);
if (d->argb_ctx == NULL) {
fprintf(stderr, "failed to create context\n"); fprintf(stderr, "failed to create context\n");
return -1; return -1;
} }
if (!eglMakeCurrent(d->dpy, NULL, NULL, d->ctx)) { if (!eglMakeCurrent(d->dpy, NULL, NULL, d->rgb_ctx)) {
fprintf(stderr, "failed to make context current\n"); fprintf(stderr, "failed to make context current\n");
return -1; return -1;
} }
#ifdef HAVE_CAIRO_EGL #ifdef HAVE_CAIRO_EGL
d->device = cairo_egl_device_create(d->dpy, d->ctx); d->rgb_device = cairo_egl_device_create(d->dpy, d->rgb_ctx);
if (cairo_device_status(d->device) != CAIRO_STATUS_SUCCESS) { if (cairo_device_status(d->rgb_device) != CAIRO_STATUS_SUCCESS) {
fprintf(stderr, "failed to get cairo egl device\n"); fprintf(stderr, "failed to get cairo egl device\n");
return -1; return -1;
} }
d->argb_device = cairo_egl_device_create(d->dpy, d->argb_ctx);
if (cairo_device_status(d->argb_device) != CAIRO_STATUS_SUCCESS) {
fprintf(stderr, "failed to get cairo egl argb device\n");
return -1;
}
#endif #endif
return 0; return 0;
@ -2169,11 +2194,17 @@ display_get_egl_display(struct display *d)
} }
EGLConfig EGLConfig
display_get_egl_config(struct display *d) display_get_rgb_egl_config(struct display *d)
{ {
return d->rgb_config; return d->rgb_config;
} }
EGLConfig
display_get_argb_egl_config(struct display *d)
{
return d->premultiplied_argb_config;
}
struct wl_shell * struct wl_shell *
display_get_shell(struct display *display) display_get_shell(struct display *display)
{ {
@ -2187,28 +2218,47 @@ display_acquire_window_surface(struct display *display,
{ {
#ifdef HAVE_CAIRO_EGL #ifdef HAVE_CAIRO_EGL
struct egl_window_surface_data *data; struct egl_window_surface_data *data;
cairo_device_t *device;
if (!window->cairo_surface) if (!window->cairo_surface)
return; return;
device = cairo_surface_get_device(window->cairo_surface);
if (!device)
return;
if (!ctx) if (!ctx) {
ctx = display->ctx; if (device == display->rgb_device)
ctx = display->rgb_ctx;
else if (device == display->argb_device)
ctx = display->argb_ctx;
else
assert(0);
}
data = cairo_surface_get_user_data(window->cairo_surface, data = cairo_surface_get_user_data(window->cairo_surface,
&surface_data_key); &surface_data_key);
cairo_device_acquire(display->device); cairo_device_acquire(device);
if (!eglMakeCurrent(display->dpy, data->surf, data->surf, ctx)) if (!eglMakeCurrent(display->dpy, data->surf, data->surf, ctx))
fprintf(stderr, "failed to make surface current\n"); fprintf(stderr, "failed to make surface current\n");
#endif #endif
} }
void void
display_release(struct display *display) display_release_window_surface(struct display *display,
struct window *window)
{ {
if (!eglMakeCurrent(display->dpy, NULL, NULL, display->ctx)) #ifdef HAVE_CAIRO_EGL
cairo_device_t *device;
device = cairo_surface_get_device(window->cairo_surface);
if (!device)
return;
if (!eglMakeCurrent(display->dpy, NULL, NULL, display->rgb_ctx))
fprintf(stderr, "failed to make context current\n"); fprintf(stderr, "failed to make context current\n");
cairo_device_release(display->device); cairo_device_release(device);
#endif
} }
void void

@ -62,14 +62,18 @@ EGLDisplay
display_get_egl_display(struct display *d); display_get_egl_display(struct display *d);
EGLConfig EGLConfig
display_get_egl_config(struct display *d); display_get_rgb_egl_config(struct display *d);
EGLConfig
display_get_argb_egl_config(struct display *d);
void void
display_acquire_window_surface(struct display *display, display_acquire_window_surface(struct display *display,
struct window *window, struct window *window,
EGLContext ctx); EGLContext ctx);
void void
display_release(struct display *display); display_release_window_surface(struct display *display,
struct window *window);
#ifdef HAVE_CAIRO_EGL #ifdef HAVE_CAIRO_EGL
EGLImageKHR EGLImageKHR

Loading…
Cancel
Save