diff --git a/src/Makefile.am b/src/Makefile.am index 3a92f5f24..e8ff00aa5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -234,6 +234,8 @@ libmutter_la_SOURCES += \ wayland/meta-xwayland.c \ wayland/meta-xwayland.h \ wayland/meta-xwayland-private.h \ + wayland/meta-wayland-buffer.c \ + wayland/meta-wayland-buffer.h \ wayland/meta-wayland-data-device.c \ wayland/meta-wayland-data-device.h \ wayland/meta-wayland-keyboard.c \ diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c new file mode 100644 index 000000000..1c1e76e7c --- /dev/null +++ b/src/wayland/meta-wayland-buffer.c @@ -0,0 +1,82 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/* + * Copyright (C) 2014 Endless Mobile + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by: + * Jasper St. Pierre + */ + +#include "config.h" + +#include "meta-wayland-buffer.h" + +static void +meta_wayland_buffer_destroy_handler (struct wl_listener *listener, + void *data) +{ + MetaWaylandBuffer *buffer = + wl_container_of (listener, buffer, destroy_listener); + + wl_signal_emit (&buffer->destroy_signal, buffer); + g_slice_free (MetaWaylandBuffer, buffer); +} + +void +meta_wayland_buffer_ref (MetaWaylandBuffer *buffer) +{ + buffer->ref_count++; +} + +void +meta_wayland_buffer_unref (MetaWaylandBuffer *buffer) +{ + buffer->ref_count--; + if (buffer->ref_count == 0) + { + g_clear_pointer (&buffer->texture, cogl_object_unref); + wl_resource_queue_event (buffer->resource, WL_BUFFER_RELEASE); + } +} + +MetaWaylandBuffer * +meta_wayland_buffer_from_resource (struct wl_resource *resource) +{ + MetaWaylandBuffer *buffer; + struct wl_listener *listener; + + listener = + wl_resource_get_destroy_listener (resource, + meta_wayland_buffer_destroy_handler); + + if (listener) + { + buffer = wl_container_of (listener, buffer, destroy_listener); + } + else + { + buffer = g_slice_new0 (MetaWaylandBuffer); + + buffer->resource = resource; + wl_signal_init (&buffer->destroy_signal); + buffer->destroy_listener.notify = meta_wayland_buffer_destroy_handler; + wl_resource_add_destroy_listener (resource, &buffer->destroy_listener); + } + + return buffer; +} diff --git a/src/wayland/meta-wayland-buffer.h b/src/wayland/meta-wayland-buffer.h new file mode 100644 index 000000000..1b0833395 --- /dev/null +++ b/src/wayland/meta-wayland-buffer.h @@ -0,0 +1,47 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/* + * Copyright (C) 2014 Endless Mobile + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by: + * Jasper St. Pierre + */ + +#ifndef META_WAYLAND_BUFFER_H +#define META_WAYLAND_BUFFER_H + +#include +#include + +#include "meta-wayland-types.h" + +struct _MetaWaylandBuffer +{ + struct wl_resource *resource; + struct wl_signal destroy_signal; + struct wl_listener destroy_listener; + + CoglTexture *texture; + uint32_t ref_count; +}; + +MetaWaylandBuffer * meta_wayland_buffer_from_resource (struct wl_resource *resource); +void meta_wayland_buffer_ref (MetaWaylandBuffer *buffer); +void meta_wayland_buffer_unref (MetaWaylandBuffer *buffer); + +#endif /* META_WAYLAND_BUFFER_H */ diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c index 5ae685f7a..24c281886 100644 --- a/src/wayland/meta-wayland-pointer.c +++ b/src/wayland/meta-wayland-pointer.c @@ -48,6 +48,7 @@ #include "meta-wayland-pointer.h" #include "meta-wayland-private.h" +#include "meta-wayland-buffer.h" #include "meta-cursor.h" #include "meta-cursor-tracker-private.h" #include "meta-surface-actor-wayland.h" diff --git a/src/wayland/meta-wayland-private.h b/src/wayland/meta-wayland-private.h index 0edc72592..5d1a62b1d 100644 --- a/src/wayland/meta-wayland-private.h +++ b/src/wayland/meta-wayland-private.h @@ -80,8 +80,4 @@ struct _MetaWaylandCompositor MetaWaylandSeat *seat; }; -MetaWaylandBuffer * meta_wayland_buffer_from_resource (struct wl_resource *resource); -void meta_wayland_buffer_ref (MetaWaylandBuffer *buffer); -void meta_wayland_buffer_unref (MetaWaylandBuffer *buffer); - #endif /* META_WAYLAND_PRIVATE_H */ diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c index 2f92b140a..e17888947 100644 --- a/src/wayland/meta-wayland-surface.c +++ b/src/wayland/meta-wayland-surface.c @@ -43,6 +43,7 @@ #include "meta-wayland-private.h" #include "meta-xwayland-private.h" +#include "meta-wayland-buffer.h" #include "meta-wayland-seat.h" #include "meta-wayland-keyboard.h" #include "meta-wayland-pointer.h" diff --git a/src/wayland/meta-wayland-surface.h b/src/wayland/meta-wayland-surface.h index 105a449b0..6288d678c 100644 --- a/src/wayland/meta-wayland-surface.h +++ b/src/wayland/meta-wayland-surface.h @@ -36,16 +36,6 @@ struct _MetaWaylandSerial { uint32_t value; }; -struct _MetaWaylandBuffer -{ - struct wl_resource *resource; - struct wl_signal destroy_signal; - struct wl_listener destroy_listener; - - CoglTexture *texture; - uint32_t ref_count; -}; - typedef struct { /* wl_surface.attach */ diff --git a/src/wayland/meta-wayland-types.h b/src/wayland/meta-wayland-types.h index 72174310a..66b33aa07 100644 --- a/src/wayland/meta-wayland-types.h +++ b/src/wayland/meta-wayland-types.h @@ -32,7 +32,6 @@ typedef struct _MetaWaylandDataSource MetaWaylandDataSource; typedef struct _MetaWaylandDataDevice MetaWaylandDataDevice; typedef struct _MetaWaylandBuffer MetaWaylandBuffer; -typedef struct _MetaWaylandBufferReference MetaWaylandBufferReference; typedef struct _MetaWaylandSurface MetaWaylandSurface; diff --git a/src/wayland/meta-wayland.c b/src/wayland/meta-wayland.c index ce4a022db..6336cecf2 100644 --- a/src/wayland/meta-wayland.c +++ b/src/wayland/meta-wayland.c @@ -126,61 +126,6 @@ wayland_event_source_new (struct wl_display *display) return &source->source; } -static void -meta_wayland_buffer_destroy_handler (struct wl_listener *listener, - void *data) -{ - MetaWaylandBuffer *buffer = - wl_container_of (listener, buffer, destroy_listener); - - wl_signal_emit (&buffer->destroy_signal, buffer); - g_slice_free (MetaWaylandBuffer, buffer); -} - -void -meta_wayland_buffer_ref (MetaWaylandBuffer *buffer) -{ - buffer->ref_count++; -} - -void -meta_wayland_buffer_unref (MetaWaylandBuffer *buffer) -{ - buffer->ref_count--; - if (buffer->ref_count == 0) - { - g_clear_pointer (&buffer->texture, cogl_object_unref); - wl_resource_queue_event (buffer->resource, WL_BUFFER_RELEASE); - } -} - -MetaWaylandBuffer * -meta_wayland_buffer_from_resource (struct wl_resource *resource) -{ - MetaWaylandBuffer *buffer; - struct wl_listener *listener; - - listener = - wl_resource_get_destroy_listener (resource, - meta_wayland_buffer_destroy_handler); - - if (listener) - { - buffer = wl_container_of (listener, buffer, destroy_listener); - } - else - { - buffer = g_slice_new0 (MetaWaylandBuffer); - - buffer->resource = resource; - wl_signal_init (&buffer->destroy_signal); - buffer->destroy_listener.notify = meta_wayland_buffer_destroy_handler; - wl_resource_add_destroy_listener (resource, &buffer->destroy_listener); - } - - return buffer; -} - void meta_wayland_compositor_set_input_focus (MetaWaylandCompositor *compositor, MetaWindow *window)