From 6bfbfb2e1021841cf261e4ccd82f9a328e96876c Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Fri, 24 Jun 2022 11:39:40 +0100 Subject: [PATCH] toytoolkit: Delete remnants of EGL support This code was all dead, since neither cairo-glesv2 nor the sample nested compositor ever made it to the Meson build. Signed-off-by: Daniel Stone --- clients/nested-client.c | 374 ------------- clients/nested.c | 1139 --------------------------------------- clients/window.c | 361 ------------- clients/window.h | 20 - 4 files changed, 1894 deletions(-) delete mode 100644 clients/nested-client.c delete mode 100644 clients/nested.c diff --git a/clients/nested-client.c b/clients/nested-client.c deleted file mode 100644 index a9e034ef..00000000 --- a/clients/nested-client.c +++ /dev/null @@ -1,374 +0,0 @@ -/* - * Copyright © 2013 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#include "config.h" - -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include "shared/platform.h" - -struct window; -struct seat; - -struct nested_client { - struct wl_display *display; - struct wl_registry *registry; - struct wl_compositor *compositor; - - EGLDisplay egl_display; - EGLContext egl_context; - EGLConfig egl_config; - EGLSurface egl_surface; - struct program *color_program; - - GLuint vert, frag, program; - GLuint rotation; - GLuint pos; - GLuint col; - - struct wl_surface *surface; - struct wl_egl_window *native; - int width, height; -}; - -#define POS 0 -#define COL 1 - -static GLuint -create_shader(const char *source, GLenum shader_type) -{ - GLuint shader; - GLint status; - - shader = glCreateShader(shader_type); - if (shader == 0) - return 0; - - glShaderSource(shader, 1, (const char **) &source, NULL); - glCompileShader(shader); - - glGetShaderiv(shader, GL_COMPILE_STATUS, &status); - if (!status) { - char log[1000]; - GLsizei len; - glGetShaderInfoLog(shader, 1000, &len, log); - fprintf(stderr, "Error: compiling %s: %.*s\n", - shader_type == GL_VERTEX_SHADER ? "vertex" : "fragment", - len, log); - return 0; - } - - return shader; -} - -static void -create_program(struct nested_client *client, - const char *vert, const char *frag) -{ - GLint status; - - client->vert = create_shader(vert, GL_VERTEX_SHADER); - client->frag = create_shader(frag, GL_FRAGMENT_SHADER); - - client->program = glCreateProgram(); - glAttachShader(client->program, client->frag); - glAttachShader(client->program, client->vert); - glBindAttribLocation(client->program, POS, "pos"); - glBindAttribLocation(client->program, COL, "color"); - glLinkProgram(client->program); - - glGetProgramiv(client->program, GL_LINK_STATUS, &status); - if (!status) { - char log[1000]; - GLsizei len; - glGetProgramInfoLog(client->program, 1000, &len, log); - fprintf(stderr, "Error: linking:\n%.*s\n", len, log); - exit(1); - } - - client->rotation = - glGetUniformLocation(client->program, "rotation"); -} - -static const char vertex_shader_text[] = - "uniform mat4 rotation;\n" - "attribute vec4 pos;\n" - "attribute vec4 color;\n" - "varying vec4 v_color;\n" - "void main() {\n" - " gl_Position = rotation * pos;\n" - " v_color = color;\n" - "}\n"; - -static const char color_fragment_shader_text[] = - "precision mediump float;\n" - "varying vec4 v_color;\n" - "void main() {\n" - " gl_FragColor = v_color;\n" - "}\n"; - -static void -render_triangle(struct nested_client *client, uint32_t time) -{ - static const GLfloat verts[3][2] = { - { -0.5, -0.5 }, - { 0.5, -0.5 }, - { 0, 0.5 } - }; - static const GLfloat colors[3][3] = { - { 1, 0, 0 }, - { 0, 1, 0 }, - { 0, 0, 1 } - }; - GLfloat angle; - GLfloat rotation[4][4] = { - { 1, 0, 0, 0 }, - { 0, 1, 0, 0 }, - { 0, 0, 1, 0 }, - { 0, 0, 0, 1 } - }; - static const int32_t speed_div = 5; - static uint32_t start_time = 0; - - if (client->program == 0) - create_program(client, vertex_shader_text, - color_fragment_shader_text); - - if (start_time == 0) - start_time = time; - - angle = ((time - start_time) / speed_div) % 360 * M_PI / 180.0; - rotation[0][0] = cos(angle); - rotation[0][2] = sin(angle); - rotation[2][0] = -sin(angle); - rotation[2][2] = cos(angle); - - glClearColor(0.4, 0.4, 0.4, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - - glUseProgram(client->program); - - glViewport(0, 0, client->width, client->height); - - glUniformMatrix4fv(client->rotation, 1, GL_FALSE, - (GLfloat *) rotation); - - glVertexAttribPointer(POS, 2, GL_FLOAT, GL_FALSE, 0, verts); - glVertexAttribPointer(COL, 3, GL_FLOAT, GL_FALSE, 0, colors); - glEnableVertexAttribArray(POS); - glEnableVertexAttribArray(COL); - - glDrawArrays(GL_TRIANGLES, 0, 3); - - glDisableVertexAttribArray(POS); - glDisableVertexAttribArray(COL); - - glFlush(); -} - -static void -frame_callback(void *data, struct wl_callback *callback, uint32_t time); - -static const struct wl_callback_listener frame_listener = { - frame_callback -}; - -static void -frame_callback(void *data, struct wl_callback *callback, uint32_t time) -{ - struct nested_client *client = data; - - if (callback) - wl_callback_destroy(callback); - - callback = wl_surface_frame(client->surface); - wl_callback_add_listener(callback, &frame_listener, client); - - render_triangle(client, time); - - eglSwapBuffers(client->egl_display, client->egl_surface); -} - -static void -registry_handle_global(void *data, struct wl_registry *registry, - uint32_t name, const char *interface, uint32_t version) -{ - struct nested_client *client = data; - - if (strcmp(interface, "wl_compositor") == 0) { - client->compositor = - wl_registry_bind(registry, name, - &wl_compositor_interface, 1); - } -} - -static void -registry_handle_global_remove(void *data, struct wl_registry *registry, - uint32_t name) -{ -} - -static const struct wl_registry_listener registry_listener = { - registry_handle_global, - registry_handle_global_remove -}; - -static struct nested_client * -nested_client_create(void) -{ - static const EGLint context_attribs[] = { - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE - }; - - static const EGLint config_attribs[] = { - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_ALPHA_SIZE, 1, - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, - EGL_NONE - }; - - EGLint major, minor, n; - EGLBoolean ret; - - struct nested_client *client; - - client = malloc(sizeof *client); - if (client == NULL) - return NULL; - - client->width = 250; - client->height = 250; - - client->display = wl_display_connect(NULL); - - client->registry = wl_display_get_registry(client->display); - wl_registry_add_listener(client->registry, - ®istry_listener, client); - - /* get globals */ - wl_display_roundtrip(client->display); - - client->egl_display = - weston_platform_get_egl_display(EGL_PLATFORM_WAYLAND_KHR, - client->display, NULL); - if (client->egl_display == NULL) - return NULL; - - ret = eglInitialize(client->egl_display, &major, &minor); - if (!ret) - return NULL; - ret = eglBindAPI(EGL_OPENGL_ES_API); - if (!ret) - return NULL; - - ret = eglChooseConfig(client->egl_display, config_attribs, - &client->egl_config, 1, &n); - if (!ret || n != 1) - return NULL; - - client->egl_context = eglCreateContext(client->egl_display, - client->egl_config, - EGL_NO_CONTEXT, - context_attribs); - if (!client->egl_context) - return NULL; - - client->surface = wl_compositor_create_surface(client->compositor); - - client->native = wl_egl_window_create(client->surface, - client->width, client->height); - - client->egl_surface = weston_platform_create_egl_surface(client->egl_display, - client->egl_config, - client->native, NULL); - - eglMakeCurrent(client->egl_display, client->egl_surface, - client->egl_surface, client->egl_context); - - wl_egl_window_resize(client->native, - client->width, client->height, 0, 0); - - frame_callback(client, NULL, 0); - - return client; -} - -static void -nested_client_destroy(struct nested_client *client) -{ - eglMakeCurrent(client->egl_display, - EGL_NO_SURFACE, EGL_NO_SURFACE, - EGL_NO_CONTEXT); - - weston_platform_destroy_egl_surface(client->egl_display, - client->egl_surface); - wl_egl_window_destroy(client->native); - - wl_surface_destroy(client->surface); - - if (client->compositor) - wl_compositor_destroy(client->compositor); - - wl_registry_destroy(client->registry); - eglTerminate(client->egl_display); - eglReleaseThread(); - wl_display_flush(client->display); - wl_display_disconnect(client->display); -} - -int -main(int argc, char **argv) -{ - struct nested_client *client; - int ret = 0; - - if (getenv("WAYLAND_SOCKET") == NULL) { - fprintf(stderr, - "must be run by nested, don't run standalone\n"); - return EXIT_FAILURE; - } - - client = nested_client_create(); - if (client == NULL) - return EXIT_FAILURE; - - while (ret != -1) - ret = wl_display_dispatch(client->display); - - nested_client_destroy(client); - - return 0; -} diff --git a/clients/nested.c b/clients/nested.c deleted file mode 100644 index c21ab975..00000000 --- a/clients/nested.c +++ /dev/null @@ -1,1139 +0,0 @@ -/* - * Copyright © 2013 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include - -#include -#define WL_HIDE_DEPRECATED -#include - -#include "shared/helpers.h" -#include "shared/xalloc.h" -#include "window.h" - -#include "shared/weston-egl-ext.h" - - -static bool option_blit; - -struct nested { - struct display *display; - struct window *window; - struct widget *widget; - struct wl_display *child_display; - struct task child_task; - - EGLDisplay egl_display; - struct program *texture_program; - - struct wl_list surface_list; - - const struct nested_renderer *renderer; -}; - -struct nested_region { - struct wl_resource *resource; - pixman_region32_t region; -}; - -struct nested_buffer_reference { - struct nested_buffer *buffer; - struct wl_listener destroy_listener; -}; - -struct nested_buffer { - struct wl_resource *resource; - struct wl_signal destroy_signal; - struct wl_listener destroy_listener; - uint32_t busy_count; - - /* A buffer in the parent compositor representing the same - * data. This is created on-demand when the subsurface - * renderer is used */ - struct wl_buffer *parent_buffer; - /* This reference is used to mark when the parent buffer has - * been attached to the subsurface. It will be unrefenced when - * we receive a buffer release event. That way we won't inform - * the client that the buffer is free until the parent - * compositor is also finished with it */ - struct nested_buffer_reference parent_ref; -}; - -struct nested_surface { - struct wl_resource *resource; - struct nested *nested; - EGLImageKHR *image; - struct wl_list link; - - struct wl_list frame_callback_list; - - struct { - /* wl_surface.attach */ - int newly_attached; - struct nested_buffer *buffer; - struct wl_listener buffer_destroy_listener; - - /* wl_surface.frame */ - struct wl_list frame_callback_list; - - /* wl_surface.damage */ - pixman_region32_t damage; - } pending; - - void *renderer_data; -}; - -/* Data used for the blit renderer */ -struct nested_blit_surface { - struct nested_buffer_reference buffer_ref; - GLuint texture; - cairo_surface_t *cairo_surface; -}; - -/* Data used for the subsurface renderer */ -struct nested_ss_surface { - struct widget *widget; - struct wl_surface *surface; - struct wl_subsurface *subsurface; - struct wl_callback *frame_callback; -}; - -struct nested_frame_callback { - struct wl_resource *resource; - struct wl_list link; -}; - -struct nested_renderer { - void (* surface_init)(struct nested_surface *surface); - void (* surface_fini)(struct nested_surface *surface); - void (* render_clients)(struct nested *nested, cairo_t *cr); - void (* surface_attach)(struct nested_surface *surface, - struct nested_buffer *buffer); -}; - -static const struct weston_option nested_options[] = { - { WESTON_OPTION_BOOLEAN, "blit", 'b', &option_blit }, -}; - -static const struct nested_renderer nested_blit_renderer; -static const struct nested_renderer nested_ss_renderer; - -static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d; -static PFNEGLCREATEIMAGEKHRPROC create_image; -static PFNEGLDESTROYIMAGEKHRPROC destroy_image; -static PFNEGLBINDWAYLANDDISPLAYWL bind_display; -static PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display; -static PFNEGLQUERYWAYLANDBUFFERWL query_buffer; -static PFNEGLCREATEWAYLANDBUFFERFROMIMAGEWL create_wayland_buffer_from_image; - -static void -nested_buffer_destroy_handler(struct wl_listener *listener, void *data) -{ - struct nested_buffer *buffer = - container_of(listener, struct nested_buffer, destroy_listener); - - wl_signal_emit(&buffer->destroy_signal, buffer); - - if (buffer->parent_buffer) - wl_buffer_destroy(buffer->parent_buffer); - - free(buffer); -} - -static struct nested_buffer * -nested_buffer_from_resource(struct wl_resource *resource) -{ - struct nested_buffer *buffer; - struct wl_listener *listener; - - listener = - wl_resource_get_destroy_listener(resource, - nested_buffer_destroy_handler); - - if (listener) - return container_of(listener, struct nested_buffer, - destroy_listener); - - buffer = zalloc(sizeof *buffer); - if (buffer == NULL) - return NULL; - - buffer->resource = resource; - wl_signal_init(&buffer->destroy_signal); - buffer->destroy_listener.notify = nested_buffer_destroy_handler; - wl_resource_add_destroy_listener(resource, &buffer->destroy_listener); - - return buffer; -} - -static void -nested_buffer_reference_handle_destroy(struct wl_listener *listener, - void *data) -{ - struct nested_buffer_reference *ref = - container_of(listener, struct nested_buffer_reference, - destroy_listener); - - assert((struct nested_buffer *)data == ref->buffer); - ref->buffer = NULL; -} - -static void -nested_buffer_reference(struct nested_buffer_reference *ref, - struct nested_buffer *buffer) -{ - if (buffer == ref->buffer) - return; - - if (ref->buffer) { - ref->buffer->busy_count--; - if (ref->buffer->busy_count == 0) { - assert(wl_resource_get_client(ref->buffer->resource)); - wl_buffer_send_release(ref->buffer->resource); - } - wl_list_remove(&ref->destroy_listener.link); - } - - if (buffer) { - buffer->busy_count++; - wl_signal_add(&buffer->destroy_signal, - &ref->destroy_listener); - - ref->destroy_listener.notify = - nested_buffer_reference_handle_destroy; - } - - ref->buffer = buffer; -} - -static void -flush_surface_frame_callback_list(struct nested_surface *surface, - uint32_t time) -{ - struct nested_frame_callback *nc, *next; - - wl_list_for_each_safe(nc, next, &surface->frame_callback_list, link) { - wl_callback_send_done(nc->resource, time); - wl_resource_destroy(nc->resource); - } - wl_list_init(&surface->frame_callback_list); - - /* FIXME: toytoolkit need a pre-block handler where we can - * call this. */ - wl_display_flush_clients(surface->nested->child_display); -} - -static void -redraw_handler(struct widget *widget, void *data) -{ - struct nested *nested = data; - cairo_surface_t *surface; - cairo_t *cr; - struct rectangle allocation; - - widget_get_allocation(nested->widget, &allocation); - - surface = window_get_surface(nested->window); - - cr = cairo_create(surface); - cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); - cairo_rectangle(cr, - allocation.x, - allocation.y, - allocation.width, - allocation.height); - cairo_set_source_rgba(cr, 0, 0, 0, 0.8); - cairo_fill(cr); - - nested->renderer->render_clients(nested, cr); - - cairo_destroy(cr); - - cairo_surface_destroy(surface); -} - -static void -keyboard_focus_handler(struct window *window, - struct input *device, void *data) -{ - struct nested *nested = data; - - window_schedule_redraw(nested->window); -} - -static void -handle_child_data(struct task *task, uint32_t events) -{ - struct nested *nested = container_of(task, struct nested, child_task); - struct wl_event_loop *loop; - - loop = wl_display_get_event_loop(nested->child_display); - - wl_event_loop_dispatch(loop, -1); - wl_display_flush_clients(nested->child_display); -} - -struct nested_client { - struct wl_client *client; - pid_t pid; -}; - -static struct nested_client * -launch_client(struct nested *nested, const char *path) -{ - int sv[2]; - pid_t pid; - struct nested_client *client; - - client = malloc(sizeof *client); - if (client == NULL) - return NULL; - - if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) { - fprintf(stderr, "launch_client: " - "socketpair failed while launching '%s': %s\n", - path, strerror(errno)); - free(client); - return NULL; - } - - pid = fork(); - if (pid == -1) { - close(sv[0]); - close(sv[1]); - free(client); - fprintf(stderr, "launch_client: " - "fork failed while launching '%s': %s\n", path, - strerror(errno)); - return NULL; - } - - if (pid == 0) { - int clientfd; - char s[32]; - - /* SOCK_CLOEXEC closes both ends, so we dup the fd to - * get a non-CLOEXEC fd to pass through exec. */ - clientfd = dup(sv[1]); - if (clientfd == -1) { - fprintf(stderr, "compositor: dup failed: %s\n", - strerror(errno)); - exit(-1); - } - - snprintf(s, sizeof s, "%d", clientfd); - setenv("WAYLAND_SOCKET", s, 1); - - execl(path, path, NULL); - - fprintf(stderr, "compositor: executing '%s' failed: %s\n", - path, strerror(errno)); - exit(-1); - } - - close(sv[1]); - - client->client = wl_client_create(nested->child_display, sv[0]); - if (!client->client) { - close(sv[0]); - free(client); - fprintf(stderr, "launch_client: " - "wl_client_create failed while launching '%s'.\n", - path); - return NULL; - } - - client->pid = pid; - - return client; -} - -static void -destroy_surface(struct wl_resource *resource) -{ - struct nested_surface *surface = wl_resource_get_user_data(resource); - struct nested *nested = surface->nested; - struct nested_frame_callback *cb, *next; - - wl_list_for_each_safe(cb, next, - &surface->frame_callback_list, link) - wl_resource_destroy(cb->resource); - - wl_list_for_each_safe(cb, next, - &surface->pending.frame_callback_list, link) - wl_resource_destroy(cb->resource); - - pixman_region32_fini(&surface->pending.damage); - - nested->renderer->surface_fini(surface); - - wl_list_remove(&surface->link); - - free(surface); -} - -static void -surface_destroy(struct wl_client *client, struct wl_resource *resource) -{ - wl_resource_destroy(resource); -} - -static void -surface_attach(struct wl_client *client, - struct wl_resource *resource, - struct wl_resource *buffer_resource, int32_t sx, int32_t sy) -{ - struct nested_surface *surface = wl_resource_get_user_data(resource); - struct nested *nested = surface->nested; - struct nested_buffer *buffer = NULL; - - if (buffer_resource) { - int format; - - if (!query_buffer(nested->egl_display, (void *) buffer_resource, - EGL_TEXTURE_FORMAT, &format)) { - wl_resource_post_error(buffer_resource, - WL_DISPLAY_ERROR_INVALID_OBJECT, - "attaching non-egl wl_buffer"); - return; - } - - switch (format) { - case EGL_TEXTURE_RGB: - case EGL_TEXTURE_RGBA: - break; - default: - wl_resource_post_error(buffer_resource, - WL_DISPLAY_ERROR_INVALID_OBJECT, - "invalid format"); - return; - } - - buffer = nested_buffer_from_resource(buffer_resource); - if (buffer == NULL) { - wl_client_post_no_memory(client); - return; - } - } - - if (surface->pending.buffer) - wl_list_remove(&surface->pending.buffer_destroy_listener.link); - - surface->pending.buffer = buffer; - surface->pending.newly_attached = 1; - if (buffer) { - wl_signal_add(&buffer->destroy_signal, - &surface->pending.buffer_destroy_listener); - } -} - -static void -nested_surface_attach(struct nested_surface *surface, - struct nested_buffer *buffer) -{ - struct nested *nested = surface->nested; - - if (surface->image != EGL_NO_IMAGE_KHR) - destroy_image(nested->egl_display, surface->image); - - surface->image = create_image(nested->egl_display, NULL, - EGL_WAYLAND_BUFFER_WL, buffer->resource, - NULL); - if (surface->image == EGL_NO_IMAGE_KHR) { - fprintf(stderr, "failed to create img\n"); - return; - } - - nested->renderer->surface_attach(surface, buffer); -} - -static void -surface_damage(struct wl_client *client, - struct wl_resource *resource, - int32_t x, int32_t y, int32_t width, int32_t height) -{ - struct nested_surface *surface = wl_resource_get_user_data(resource); - - pixman_region32_union_rect(&surface->pending.damage, - &surface->pending.damage, - x, y, width, height); -} - -static void -destroy_frame_callback(struct wl_resource *resource) -{ - struct nested_frame_callback *callback = wl_resource_get_user_data(resource); - - wl_list_remove(&callback->link); - free(callback); -} - -static void -surface_frame(struct wl_client *client, - struct wl_resource *resource, uint32_t id) -{ - struct nested_frame_callback *callback; - struct nested_surface *surface = wl_resource_get_user_data(resource); - - callback = malloc(sizeof *callback); - if (callback == NULL) { - wl_resource_post_no_memory(resource); - return; - } - - callback->resource = wl_resource_create(client, - &wl_callback_interface, 1, id); - wl_resource_set_implementation(callback->resource, NULL, callback, - destroy_frame_callback); - - wl_list_insert(surface->pending.frame_callback_list.prev, - &callback->link); -} - -static void -surface_set_opaque_region(struct wl_client *client, - struct wl_resource *resource, - struct wl_resource *region_resource) -{ - fprintf(stderr, "surface_set_opaque_region\n"); -} - -static void -surface_set_input_region(struct wl_client *client, - struct wl_resource *resource, - struct wl_resource *region_resource) -{ - fprintf(stderr, "surface_set_input_region\n"); -} - -static void -surface_commit(struct wl_client *client, struct wl_resource *resource) -{ - struct nested_surface *surface = wl_resource_get_user_data(resource); - struct nested *nested = surface->nested; - - /* wl_surface.attach */ - if (surface->pending.newly_attached) - nested_surface_attach(surface, surface->pending.buffer); - - if (surface->pending.buffer) { - wl_list_remove(&surface->pending.buffer_destroy_listener.link); - surface->pending.buffer = NULL; - } - surface->pending.newly_attached = 0; - - /* wl_surface.damage */ - pixman_region32_clear(&surface->pending.damage); - - /* wl_surface.frame */ - wl_list_insert_list(&surface->frame_callback_list, - &surface->pending.frame_callback_list); - wl_list_init(&surface->pending.frame_callback_list); - - /* FIXME: For the subsurface renderer we don't need to - * actually redraw the window. However we do want to cause a - * commit because the subsurface is synchronized. Ideally we - * would just queue the commit */ - window_schedule_redraw(nested->window); -} - -static void -surface_set_buffer_transform(struct wl_client *client, - struct wl_resource *resource, int transform) -{ - fprintf(stderr, "surface_set_buffer_transform\n"); -} - -static const struct wl_surface_interface surface_interface = { - surface_destroy, - surface_attach, - surface_damage, - surface_frame, - surface_set_opaque_region, - surface_set_input_region, - surface_commit, - surface_set_buffer_transform -}; - -static void -surface_handle_pending_buffer_destroy(struct wl_listener *listener, void *data) -{ - struct nested_surface *surface = - container_of(listener, struct nested_surface, - pending.buffer_destroy_listener); - - surface->pending.buffer = NULL; -} - -static void -compositor_create_surface(struct wl_client *client, - struct wl_resource *resource, uint32_t id) -{ - struct nested *nested = wl_resource_get_user_data(resource); - struct nested_surface *surface; - - surface = zalloc(sizeof *surface); - if (surface == NULL) { - wl_resource_post_no_memory(resource); - return; - } - - surface->nested = nested; - - wl_list_init(&surface->frame_callback_list); - - wl_list_init(&surface->pending.frame_callback_list); - surface->pending.buffer_destroy_listener.notify = - surface_handle_pending_buffer_destroy; - pixman_region32_init(&surface->pending.damage); - - display_acquire_window_surface(nested->display, - nested->window, NULL); - - nested->renderer->surface_init(surface); - - display_release_window_surface(nested->display, nested->window); - - surface->resource = - wl_resource_create(client, &wl_surface_interface, 1, id); - - wl_resource_set_implementation(surface->resource, - &surface_interface, surface, - destroy_surface); - - wl_list_insert(nested->surface_list.prev, &surface->link); -} - -static void -destroy_region(struct wl_resource *resource) -{ - struct nested_region *region = wl_resource_get_user_data(resource); - - pixman_region32_fini(®ion->region); - free(region); -} - -static void -region_destroy(struct wl_client *client, struct wl_resource *resource) -{ - wl_resource_destroy(resource); -} - -static void -region_add(struct wl_client *client, struct wl_resource *resource, - int32_t x, int32_t y, int32_t width, int32_t height) -{ - struct nested_region *region = wl_resource_get_user_data(resource); - - pixman_region32_union_rect(®ion->region, ®ion->region, - x, y, width, height); -} - -static void -region_subtract(struct wl_client *client, struct wl_resource *resource, - int32_t x, int32_t y, int32_t width, int32_t height) -{ - struct nested_region *region = wl_resource_get_user_data(resource); - pixman_region32_t rect; - - pixman_region32_init_rect(&rect, x, y, width, height); - pixman_region32_subtract(®ion->region, ®ion->region, &rect); - pixman_region32_fini(&rect); -} - -static const struct wl_region_interface region_interface = { - region_destroy, - region_add, - region_subtract -}; - -static void -compositor_create_region(struct wl_client *client, - struct wl_resource *resource, uint32_t id) -{ - struct nested_region *region; - - region = malloc(sizeof *region); - if (region == NULL) { - wl_resource_post_no_memory(resource); - return; - } - - pixman_region32_init(®ion->region); - - region->resource = - wl_resource_create(client, &wl_region_interface, 1, id); - wl_resource_set_implementation(region->resource, ®ion_interface, - region, destroy_region); -} - -static const struct wl_compositor_interface compositor_interface = { - compositor_create_surface, - compositor_create_region -}; - -static void -compositor_bind(struct wl_client *client, - void *data, uint32_t version, uint32_t id) -{ - struct nested *nested = data; - struct wl_resource *resource; - - resource = wl_resource_create(client, &wl_compositor_interface, - MIN(version, 3), id); - wl_resource_set_implementation(resource, &compositor_interface, - nested, NULL); -} - -static int -nested_init_compositor(struct nested *nested) -{ - const char *extensions; - struct wl_event_loop *loop; - int use_ss_renderer = 0; - int fd, ret; - - wl_list_init(&nested->surface_list); - nested->child_display = wl_display_create(); - loop = wl_display_get_event_loop(nested->child_display); - fd = wl_event_loop_get_fd(loop); - nested->child_task.run = handle_child_data; - display_watch_fd(nested->display, fd, - EPOLLIN, &nested->child_task); - - if (!wl_global_create(nested->child_display, - &wl_compositor_interface, 1, - nested, compositor_bind)) - return -1; - - wl_display_init_shm(nested->child_display); - - nested->egl_display = display_get_egl_display(nested->display); - extensions = eglQueryString(nested->egl_display, EGL_EXTENSIONS); - if (!weston_check_egl_extension(extensions, "EGL_WL_bind_wayland_display")) { - fprintf(stderr, "no EGL_WL_bind_wayland_display extension\n"); - return -1; - } - - bind_display = (void *) eglGetProcAddress("eglBindWaylandDisplayWL"); - unbind_display = (void *) eglGetProcAddress("eglUnbindWaylandDisplayWL"); - create_image = (void *) eglGetProcAddress("eglCreateImageKHR"); - destroy_image = (void *) eglGetProcAddress("eglDestroyImageKHR"); - query_buffer = (void *) eglGetProcAddress("eglQueryWaylandBufferWL"); - image_target_texture_2d = - (void *) eglGetProcAddress("glEGLImageTargetTexture2DOES"); - - ret = bind_display(nested->egl_display, nested->child_display); - if (!ret) { - fprintf(stderr, "failed to bind wl_display\n"); - return -1; - } - - if (display_has_subcompositor(nested->display)) { - const char *func = "eglCreateWaylandBufferFromImageWL"; - const char *ext = "EGL_WL_create_wayland_buffer_from_image"; - - if (weston_check_egl_extension(extensions, ext)) { - create_wayland_buffer_from_image = - (void *) eglGetProcAddress(func); - use_ss_renderer = 1; - } - } - - if (option_blit) - use_ss_renderer = 0; - - if (use_ss_renderer) { - printf("Using subsurfaces to render client surfaces\n"); - nested->renderer = &nested_ss_renderer; - } else { - printf("Using local compositing with blits to " - "render client surfaces\n"); - nested->renderer = &nested_blit_renderer; - } - - return 0; -} - -static struct nested * -nested_create(struct display *display) -{ - struct nested *nested; - - nested = zalloc(sizeof *nested); - if (nested == NULL) - return nested; - - nested->window = window_create(display); - nested->widget = window_frame_create(nested->window, nested); - window_set_title(nested->window, "Wayland Nested"); - window_set_appid(nested->window, - "org.freedesktop.weston.wayland-nested"); - nested->display = display; - - window_set_user_data(nested->window, nested); - widget_set_redraw_handler(nested->widget, redraw_handler); - window_set_keyboard_focus_handler(nested->window, - keyboard_focus_handler); - - nested_init_compositor(nested); - - widget_schedule_resize(nested->widget, 400, 400); - - return nested; -} - -static void -nested_destroy(struct nested *nested) -{ - widget_destroy(nested->widget); - window_destroy(nested->window); - free(nested); -} - -/*** blit renderer ***/ - -static void -blit_surface_init(struct nested_surface *surface) -{ - struct nested_blit_surface *blit_surface = - xzalloc(sizeof *blit_surface); - - glGenTextures(1, &blit_surface->texture); - glBindTexture(GL_TEXTURE_2D, blit_surface->texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - surface->renderer_data = blit_surface; -} - -static void -blit_surface_fini(struct nested_surface *surface) -{ - struct nested_blit_surface *blit_surface = surface->renderer_data; - - nested_buffer_reference(&blit_surface->buffer_ref, NULL); - - glDeleteTextures(1, &blit_surface->texture); - - free(blit_surface); -} - -static void -blit_frame_callback(void *data, struct wl_callback *callback, uint32_t time) -{ - struct nested *nested = data; - struct nested_surface *surface; - - wl_list_for_each(surface, &nested->surface_list, link) - flush_surface_frame_callback_list(surface, time); - - if (callback) - wl_callback_destroy(callback); -} - -static const struct wl_callback_listener blit_frame_listener = { - blit_frame_callback -}; - -static void -blit_render_clients(struct nested *nested, - cairo_t *cr) -{ - struct nested_surface *s; - struct rectangle allocation; - struct wl_callback *callback; - - widget_get_allocation(nested->widget, &allocation); - - wl_list_for_each(s, &nested->surface_list, link) { - struct nested_blit_surface *blit_surface = s->renderer_data; - - display_acquire_window_surface(nested->display, - nested->window, NULL); - - glBindTexture(GL_TEXTURE_2D, blit_surface->texture); - image_target_texture_2d(GL_TEXTURE_2D, s->image); - - display_release_window_surface(nested->display, - nested->window); - - cairo_set_operator(cr, CAIRO_OPERATOR_OVER); - cairo_set_source_surface(cr, blit_surface->cairo_surface, - allocation.x + 10, - allocation.y + 10); - cairo_rectangle(cr, allocation.x + 10, - allocation.y + 10, - allocation.width - 10, - allocation.height - 10); - - cairo_fill(cr); - } - - callback = wl_surface_frame(window_get_wl_surface(nested->window)); - wl_callback_add_listener(callback, &blit_frame_listener, nested); -} - -static void -blit_surface_attach(struct nested_surface *surface, - struct nested_buffer *buffer) -{ - struct nested *nested = surface->nested; - struct nested_blit_surface *blit_surface = surface->renderer_data; - EGLint width, height; - cairo_device_t *device; - - nested_buffer_reference(&blit_surface->buffer_ref, buffer); - - if (blit_surface->cairo_surface) - cairo_surface_destroy(blit_surface->cairo_surface); - - query_buffer(nested->egl_display, (void *) buffer->resource, - EGL_WIDTH, &width); - query_buffer(nested->egl_display, (void *) buffer->resource, - EGL_HEIGHT, &height); - - device = display_get_cairo_device(nested->display); - blit_surface->cairo_surface = - cairo_gl_surface_create_for_texture(device, - CAIRO_CONTENT_COLOR_ALPHA, - blit_surface->texture, - width, height); -} - -static const struct nested_renderer -nested_blit_renderer = { - .surface_init = blit_surface_init, - .surface_fini = blit_surface_fini, - .render_clients = blit_render_clients, - .surface_attach = blit_surface_attach -}; - -/*** subsurface renderer ***/ - -static void -ss_surface_init(struct nested_surface *surface) -{ - struct nested *nested = surface->nested; - struct wl_compositor *compositor = - display_get_compositor(nested->display); - struct nested_ss_surface *ss_surface = - xzalloc(sizeof *ss_surface); - struct rectangle allocation; - struct wl_region *region; - - ss_surface->widget = - window_add_subsurface(nested->window, - nested, - SUBSURFACE_SYNCHRONIZED); - - widget_set_use_cairo(ss_surface->widget, 0); - - ss_surface->surface = widget_get_wl_surface(ss_surface->widget); - ss_surface->subsurface = widget_get_wl_subsurface(ss_surface->widget); - - /* The toy toolkit gets confused about the pointer position - * when it gets motion events for a subsurface so we'll just - * disable input on it */ - region = wl_compositor_create_region(compositor); - wl_surface_set_input_region(ss_surface->surface, region); - wl_region_destroy(region); - - widget_get_allocation(nested->widget, &allocation); - wl_subsurface_set_position(ss_surface->subsurface, - allocation.x + 10, - allocation.y + 10); - - surface->renderer_data = ss_surface; -} - -static void -ss_surface_fini(struct nested_surface *surface) -{ - struct nested_ss_surface *ss_surface = surface->renderer_data; - - widget_destroy(ss_surface->widget); - - if (ss_surface->frame_callback) - wl_callback_destroy(ss_surface->frame_callback); - - free(ss_surface); -} - -static void -ss_render_clients(struct nested *nested, - cairo_t *cr) -{ - /* The clients are composited by the parent compositor so we - * don't need to do anything here */ -} - -static void -ss_buffer_release(void *data, struct wl_buffer *wl_buffer) -{ - struct nested_buffer *buffer = data; - - nested_buffer_reference(&buffer->parent_ref, NULL); -} - -static struct wl_buffer_listener ss_buffer_listener = { - ss_buffer_release -}; - -static void -ss_frame_callback(void *data, struct wl_callback *callback, uint32_t time) -{ - struct nested_surface *surface = data; - struct nested_ss_surface *ss_surface = surface->renderer_data; - - flush_surface_frame_callback_list(surface, time); - - if (callback) - wl_callback_destroy(callback); - - ss_surface->frame_callback = NULL; -} - -static const struct wl_callback_listener ss_frame_listener = { - ss_frame_callback -}; - -static void -ss_surface_attach(struct nested_surface *surface, - struct nested_buffer *buffer) -{ - struct nested *nested = surface->nested; - struct nested_ss_surface *ss_surface = surface->renderer_data; - struct wl_buffer *parent_buffer; - const pixman_box32_t *rects; - int n_rects, i; - - if (buffer) { - /* Create a representation of the buffer in the parent - * compositor if we haven't already */ - if (buffer->parent_buffer == NULL) { - EGLDisplay *edpy = nested->egl_display; - EGLImageKHR image = surface->image; - - buffer->parent_buffer = - create_wayland_buffer_from_image(edpy, image); - - wl_buffer_add_listener(buffer->parent_buffer, - &ss_buffer_listener, - buffer); - } - - parent_buffer = buffer->parent_buffer; - - /* We'll take a reference to the buffer while the parent - * compositor is using it so that we won't report the release - * event until the parent has also finished with it */ - nested_buffer_reference(&buffer->parent_ref, buffer); - } else { - parent_buffer = NULL; - } - - wl_surface_attach(ss_surface->surface, parent_buffer, 0, 0); - - rects = pixman_region32_rectangles(&surface->pending.damage, &n_rects); - - for (i = 0; i < n_rects; i++) { - const pixman_box32_t *rect = rects + i; - wl_surface_damage(ss_surface->surface, - rect->x1, - rect->y1, - rect->x2 - rect->x1, - rect->y2 - rect->y1); - } - - if (ss_surface->frame_callback) - wl_callback_destroy(ss_surface->frame_callback); - - ss_surface->frame_callback = wl_surface_frame(ss_surface->surface); - wl_callback_add_listener(ss_surface->frame_callback, - &ss_frame_listener, - surface); - - wl_surface_commit(ss_surface->surface); -} - -static const struct nested_renderer -nested_ss_renderer = { - .surface_init = ss_surface_init, - .surface_fini = ss_surface_fini, - .render_clients = ss_render_clients, - .surface_attach = ss_surface_attach -}; - -int -main(int argc, char *argv[]) -{ - struct display *display; - struct nested *nested; - - if (parse_options(nested_options, - ARRAY_LENGTH(nested_options), &argc, argv) > 1) { - printf("Usage: %s [OPTIONS]\n --blit or -b\n", argv[0]); - exit(1); - } - - display = display_create(&argc, argv); - if (display == NULL) { - fprintf(stderr, "failed to create display: %s\n", - strerror(errno)); - return -1; - } - - nested = nested_create(display); - - launch_client(nested, "weston-nested-client"); - - display_run(display); - - nested_destroy(nested); - display_destroy(display); - - return 0; -} diff --git a/clients/window.c b/clients/window.c index 60814a21..0f631a0f 100644 --- a/clients/window.c +++ b/clients/window.c @@ -42,25 +42,6 @@ #include #include -#ifdef HAVE_CAIRO_EGL -#include - -#ifdef USE_CAIRO_GLESV2 -#include -#include -#else -#include -#endif -#include -#include - -#include -#elif !defined(ENABLE_EGL) /* platform.h defines these if EGL is enabled */ -typedef void *EGLDisplay; -typedef void *EGLConfig; -typedef void *EGLContext; -#define EGL_NO_DISPLAY ((EGLDisplay)0) -#endif /* no HAVE_CAIRO_EGL */ #include #ifdef HAVE_XKBCOMMON_COMPOSE @@ -109,10 +90,6 @@ struct display { struct xdg_wm_base *xdg_shell; struct zwp_relative_pointer_manager_v1 *relative_pointer_manager; struct zwp_pointer_constraints_v1 *pointer_constraints; - EGLDisplay dpy; - EGLConfig argb_config; - EGLContext argb_ctx; - cairo_device_t *argb_device; uint32_t serial; int display_fd; @@ -178,18 +155,6 @@ struct toysurface { enum wl_output_transform buffer_transform, int32_t buffer_scale, struct rectangle *server_allocation); - /* - * Make the toysurface current with the given EGL context. - * Returns 0 on success, and negative on failure. - */ - int (*acquire)(struct toysurface *base, EGLContext ctx); - - /* - * Release the toysurface from the EGL context, returning control - * to Cairo. - */ - void (*release)(struct toysurface *base); - /* * Destroy the toysurface, including the Cairo surface, any * backing storage, and the Wayland protocol objects. @@ -543,167 +508,6 @@ buffer_to_surface_size (enum wl_output_transform buffer_transform, int32_t buffe *height /= buffer_scale; } -#ifdef HAVE_CAIRO_EGL - -struct egl_window_surface { - struct toysurface base; - cairo_surface_t *cairo_surface; - struct display *display; - struct wl_surface *surface; - struct wl_egl_window *egl_window; - EGLSurface egl_surface; -}; - -static struct egl_window_surface * -to_egl_window_surface(struct toysurface *base) -{ - return container_of(base, struct egl_window_surface, base); -} - -static cairo_surface_t * -egl_window_surface_prepare(struct toysurface *base, int dx, int dy, - int32_t width, int32_t height, uint32_t flags, - enum wl_output_transform buffer_transform, int32_t buffer_scale) -{ - struct egl_window_surface *surface = to_egl_window_surface(base); - - surface_to_buffer_size (buffer_transform, buffer_scale, &width, &height); - - wl_egl_window_resize(surface->egl_window, width, height, dx, dy); - cairo_gl_surface_set_size(surface->cairo_surface, width, height); - - return cairo_surface_reference(surface->cairo_surface); -} - -static void -egl_window_surface_swap(struct toysurface *base, - enum wl_output_transform buffer_transform, int32_t buffer_scale, - struct rectangle *server_allocation) -{ - struct egl_window_surface *surface = to_egl_window_surface(base); - - cairo_gl_surface_swapbuffers(surface->cairo_surface); - wl_egl_window_get_attached_size(surface->egl_window, - &server_allocation->width, - &server_allocation->height); - - buffer_to_surface_size (buffer_transform, buffer_scale, - &server_allocation->width, - &server_allocation->height); -} - -static int -egl_window_surface_acquire(struct toysurface *base, EGLContext ctx) -{ - struct egl_window_surface *surface = to_egl_window_surface(base); - cairo_device_t *device; - - device = cairo_surface_get_device(surface->cairo_surface); - if (!device) - return -1; - - if (!ctx) { - if (device == surface->display->argb_device) - ctx = surface->display->argb_ctx; - else - assert(0); - } - - cairo_device_flush(device); - cairo_device_acquire(device); - if (!eglMakeCurrent(surface->display->dpy, surface->egl_surface, - surface->egl_surface, ctx)) - fprintf(stderr, "failed to make surface current\n"); - - return 0; -} - -static void -egl_window_surface_release(struct toysurface *base) -{ - struct egl_window_surface *surface = to_egl_window_surface(base); - cairo_device_t *device; - - device = cairo_surface_get_device(surface->cairo_surface); - if (!device) - return; - - if (!eglMakeCurrent(surface->display->dpy, - EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) - fprintf(stderr, "failed to make context current\n"); - - cairo_device_release(device); -} - -static void -egl_window_surface_destroy(struct toysurface *base) -{ - struct egl_window_surface *surface = to_egl_window_surface(base); - struct display *d = surface->display; - - cairo_surface_destroy(surface->cairo_surface); - weston_platform_destroy_egl_surface(d->dpy, surface->egl_surface); - wl_egl_window_destroy(surface->egl_window); - surface->surface = NULL; - - free(surface); -} - -static struct toysurface * -egl_window_surface_create(struct display *display, - struct wl_surface *wl_surface, - uint32_t flags, - struct rectangle *rectangle) -{ - struct egl_window_surface *surface; - - if (display->dpy == EGL_NO_DISPLAY) - return NULL; - - surface = zalloc(sizeof *surface); - if (!surface) - return NULL; - - surface->base.prepare = egl_window_surface_prepare; - surface->base.swap = egl_window_surface_swap; - surface->base.acquire = egl_window_surface_acquire; - surface->base.release = egl_window_surface_release; - surface->base.destroy = egl_window_surface_destroy; - - surface->display = display; - surface->surface = wl_surface; - - surface->egl_window = wl_egl_window_create(surface->surface, - rectangle->width, - rectangle->height); - - surface->egl_surface = - weston_platform_create_egl_surface(display->dpy, - display->argb_config, - surface->egl_window, NULL); - - surface->cairo_surface = - cairo_gl_surface_create_for_egl(display->argb_device, - surface->egl_surface, - rectangle->width, - rectangle->height); - - return &surface->base; -} - -#else - -static struct toysurface * -egl_window_surface_create(struct display *display, - struct wl_surface *wl_surface, - uint32_t flags, - struct rectangle *rectangle) -{ - return NULL; -} - -#endif - struct shm_surface_data { struct wl_buffer *buffer; struct shm_pool *pool; @@ -1157,17 +961,6 @@ shm_surface_swap(struct toysurface *base, surface->current = NULL; } -static int -shm_surface_acquire(struct toysurface *base, EGLContext ctx) -{ - return -1; -} - -static void -shm_surface_release(struct toysurface *base) -{ -} - static void shm_surface_destroy(struct toysurface *base) { @@ -1190,8 +983,6 @@ shm_surface_create(struct display *display, struct wl_surface *wl_surface, surface = xzalloc(sizeof *surface); surface->base.prepare = shm_surface_prepare; surface->base.swap = shm_surface_swap; - surface->base.acquire = shm_surface_acquire; - surface->base.release = shm_surface_release; surface->base.destroy = shm_surface_destroy; surface->display = display; @@ -1461,15 +1252,6 @@ surface_create_surface(struct surface *surface, uint32_t flags) struct display *display = surface->window->display; struct rectangle allocation = surface->allocation; - if (!surface->toysurface && display->dpy && - surface->buffer_type == WINDOW_BUFFER_TYPE_EGL_WINDOW) { - surface->toysurface = - egl_window_surface_create(display, - surface->surface, - flags, - &allocation); - } - if (!surface->toysurface) surface->toysurface = shm_surface_create(display, surface->surface, @@ -5257,11 +5039,6 @@ surface_create(struct window *window) static enum window_buffer_type get_preferred_buffer_type(struct display *display) { -#ifdef HAVE_CAIRO_EGL - if (display->argb_device && !getenv("TOYTOOLKIT_NO_EGL")) - return WINDOW_BUFFER_TYPE_EGL_WINDOW; -#endif - return WINDOW_BUFFER_TYPE_SHM; } @@ -6123,90 +5900,6 @@ static const struct wl_registry_listener registry_listener = { registry_handle_global_remove }; -#ifdef HAVE_CAIRO_EGL -static int -init_egl(struct display *d) -{ - EGLint major, minor; - EGLint n; - -#ifdef USE_CAIRO_GLESV2 -# define GL_BIT EGL_OPENGL_ES2_BIT -#else -# define GL_BIT EGL_OPENGL_BIT -#endif - - static const EGLint argb_cfg_attribs[] = { - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_ALPHA_SIZE, 1, - EGL_DEPTH_SIZE, 1, - EGL_RENDERABLE_TYPE, GL_BIT, - EGL_NONE - }; - -#ifdef USE_CAIRO_GLESV2 - static const EGLint context_attribs[] = { - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE - }; - EGLint api = EGL_OPENGL_ES_API; -#else - EGLint *context_attribs = NULL; - EGLint api = EGL_OPENGL_API; -#endif - - d->dpy = - weston_platform_get_egl_display(EGL_PLATFORM_WAYLAND_KHR, - d->display, NULL); - - if (!eglInitialize(d->dpy, &major, &minor)) { - fprintf(stderr, "failed to initialize EGL\n"); - return -1; - } - - if (!eglBindAPI(api)) { - fprintf(stderr, "failed to bind EGL client API\n"); - return -1; - } - - if (!eglChooseConfig(d->dpy, argb_cfg_attribs, - &d->argb_config, 1, &n) || n != 1) { - fprintf(stderr, "failed to choose argb EGL config\n"); - return -1; - } - - d->argb_ctx = eglCreateContext(d->dpy, d->argb_config, - EGL_NO_CONTEXT, context_attribs); - if (d->argb_ctx == NULL) { - fprintf(stderr, "failed to create EGL context\n"); - 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; - } - - return 0; -} - -static void -fini_egl(struct display *display) -{ - cairo_device_destroy(display->argb_device); - - eglMakeCurrent(display->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, - EGL_NO_CONTEXT); - - eglTerminate(display->dpy); - eglReleaseThread(); -} -#endif - static void init_dummy_surface(struct display *display) { @@ -6312,12 +6005,6 @@ display_create(int *argc, char *argv[]) return NULL; } -#ifdef HAVE_CAIRO_EGL - if (init_egl(d) < 0) - fprintf(stderr, "EGL does not seem to work, " - "falling back to software rendering and wl_shm.\n"); -#endif - create_cursors(d); d->theme = theme_create(); @@ -6376,10 +6063,6 @@ display_destroy(struct display *display) theme_destroy(display->theme); destroy_cursors(display); -#ifdef HAVE_CAIRO_EGL - if (display->argb_device) - fini_egl(display); -#endif if (display->relative_pointer_manager) zwp_relative_pointer_manager_v1_destroy(display->relative_pointer_manager); @@ -6445,12 +6128,6 @@ display_has_subcompositor(struct display *display) return display->subcompositor != NULL; } -cairo_device_t * -display_get_cairo_device(struct display *display) -{ - return display->argb_device; -} - struct output * display_get_output(struct display *display) { @@ -6472,12 +6149,6 @@ display_get_serial(struct display *display) return display->serial; } -EGLDisplay -display_get_egl_display(struct display *d) -{ - return d->dpy; -} - struct wl_data_source * display_create_data_source(struct display *display) { @@ -6487,38 +6158,6 @@ display_create_data_source(struct display *display) return NULL; } -EGLConfig -display_get_argb_egl_config(struct display *d) -{ - return d->argb_config; -} - -int -display_acquire_window_surface(struct display *display, - struct window *window, - EGLContext ctx) -{ - struct surface *surface = window->main_surface; - - if (surface->buffer_type != WINDOW_BUFFER_TYPE_EGL_WINDOW) - return -1; - - widget_get_cairo_surface(window->main_surface->widget); - return surface->toysurface->acquire(surface->toysurface, ctx); -} - -void -display_release_window_surface(struct display *display, - struct window *window) -{ - struct surface *surface = window->main_surface; - - if (surface->buffer_type != WINDOW_BUFFER_TYPE_EGL_WINDOW) - return; - - surface->toysurface->release(surface->toysurface); -} - void display_defer(struct display *display, struct task *task) { diff --git a/clients/window.h b/clients/window.h index 7cf82da1..22fd7e23 100644 --- a/clients/window.h +++ b/clients/window.h @@ -71,9 +71,6 @@ display_get_display(struct display *display); int display_has_subcompositor(struct display *display); -cairo_device_t * -display_get_cairo_device(struct display *display); - struct wl_compositor * display_get_compositor(struct display *display); @@ -114,22 +111,6 @@ display_set_output_configure_handler(struct display *display, struct wl_data_source * display_create_data_source(struct display *display); -#ifdef EGL_NO_DISPLAY -EGLDisplay -display_get_egl_display(struct display *d); - -EGLConfig -display_get_argb_egl_config(struct display *d); - -int -display_acquire_window_surface(struct display *display, - struct window *window, - EGLContext ctx); -void -display_release_window_surface(struct display *display, - struct window *window); -#endif - #define SURFACE_OPAQUE 0x01 #define SURFACE_SHM 0x02 @@ -416,7 +397,6 @@ struct wl_subsurface * widget_get_wl_subsurface(struct widget *widget); enum window_buffer_type { - WINDOW_BUFFER_TYPE_EGL_WINDOW, WINDOW_BUFFER_TYPE_SHM, };