2015-10-21 10:36:44 -04:00
|
|
|
/*
|
|
|
|
* Wayland Support
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "wayland/meta-wayland-cursor-surface.h"
|
|
|
|
|
2016-11-29 21:49:00 -05:00
|
|
|
#include "backends/meta-backend-private.h"
|
2016-12-12 21:37:11 -05:00
|
|
|
#include "backends/meta-logical-monitor.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "cogl/cogl.h"
|
2017-06-08 10:13:16 -04:00
|
|
|
#include "core/boxes-private.h"
|
2018-04-30 06:03:31 -04:00
|
|
|
#include "wayland/meta-cursor-sprite-wayland.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "wayland/meta-wayland-buffer.h"
|
2021-02-02 08:51:34 -05:00
|
|
|
#include "wayland/meta-wayland-presentation-time-private.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "wayland/meta-wayland-private.h"
|
2022-06-13 04:09:26 -04:00
|
|
|
|
|
|
|
#ifdef HAVE_XWAYLAND
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "wayland/meta-xwayland.h"
|
2022-06-13 04:09:26 -04:00
|
|
|
#endif
|
2015-10-21 10:36:44 -04:00
|
|
|
|
2018-04-19 15:51:31 -04:00
|
|
|
typedef struct _MetaWaylandCursorSurfacePrivate MetaWaylandCursorSurfacePrivate;
|
2015-10-21 10:36:44 -04:00
|
|
|
|
2018-04-19 15:51:31 -04:00
|
|
|
struct _MetaWaylandCursorSurfacePrivate
|
2016-05-12 09:53:07 -04:00
|
|
|
{
|
2015-10-21 10:36:44 -04:00
|
|
|
int hot_x;
|
|
|
|
int hot_y;
|
2018-04-30 06:03:31 -04:00
|
|
|
MetaCursorSpriteWayland *cursor_sprite;
|
2015-10-21 10:36:44 -04:00
|
|
|
MetaCursorRenderer *cursor_renderer;
|
|
|
|
MetaWaylandBuffer *buffer;
|
2016-08-16 12:21:46 -04:00
|
|
|
struct wl_list frame_callbacks;
|
|
|
|
gulong cursor_painted_handler_id;
|
2015-10-21 10:36:44 -04:00
|
|
|
};
|
|
|
|
|
2018-04-19 15:51:31 -04:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (MetaWaylandCursorSurface,
|
|
|
|
meta_wayland_cursor_surface,
|
2016-05-12 09:53:07 -04:00
|
|
|
META_TYPE_WAYLAND_SURFACE_ROLE)
|
2015-10-21 10:36:44 -04:00
|
|
|
|
|
|
|
static void
|
2018-04-19 15:51:31 -04:00
|
|
|
update_cursor_sprite_texture (MetaWaylandCursorSurface *cursor_surface)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurfacePrivate *priv =
|
|
|
|
meta_wayland_cursor_surface_get_instance_private (cursor_surface);
|
|
|
|
MetaWaylandSurface *surface =
|
|
|
|
meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (cursor_surface));
|
2018-04-30 06:03:31 -04:00
|
|
|
MetaCursorSprite *cursor_sprite = META_CURSOR_SPRITE (priv->cursor_sprite);
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
CoglTexture *texture;
|
2015-10-21 10:36:44 -04:00
|
|
|
|
2018-04-30 05:59:22 -04:00
|
|
|
if (!priv->cursor_renderer)
|
2015-10-21 10:36:44 -04:00
|
|
|
return;
|
|
|
|
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
texture = meta_wayland_surface_get_texture (surface);
|
|
|
|
if (texture)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
|
|
|
meta_cursor_sprite_set_texture (cursor_sprite,
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
texture,
|
2016-05-12 09:53:07 -04:00
|
|
|
priv->hot_x * surface->scale,
|
|
|
|
priv->hot_y * surface->scale);
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
meta_cursor_sprite_set_texture (cursor_sprite, NULL, 0, 0);
|
|
|
|
}
|
|
|
|
|
2016-05-12 09:53:07 -04:00
|
|
|
meta_cursor_renderer_force_update (priv->cursor_renderer);
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-04-19 15:51:31 -04:00
|
|
|
cursor_sprite_prepare_at (MetaCursorSprite *cursor_sprite,
|
2020-07-10 06:25:12 -04:00
|
|
|
float best_scale,
|
2018-04-19 15:51:31 -04:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
MetaWaylandCursorSurface *cursor_surface)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandSurfaceRole *role = META_WAYLAND_SURFACE_ROLE (cursor_surface);
|
2015-10-21 10:36:44 -04:00
|
|
|
MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (role);
|
|
|
|
|
2022-06-13 04:09:26 -04:00
|
|
|
#ifdef HAVE_XWAYLAND
|
2015-10-21 10:36:44 -04:00
|
|
|
if (!meta_xwayland_is_xwayland_surface (surface))
|
|
|
|
{
|
2022-05-30 17:48:44 -04:00
|
|
|
MetaWaylandSurfaceRole *surface_role =
|
|
|
|
META_WAYLAND_SURFACE_ROLE (cursor_surface);
|
|
|
|
MetaWaylandSurface *surface =
|
|
|
|
meta_wayland_surface_role_get_surface (surface_role);
|
|
|
|
MetaContext *context =
|
|
|
|
meta_wayland_compositor_get_context (surface->compositor);
|
|
|
|
MetaBackend *backend = meta_context_get_backend (context);
|
2016-11-29 21:49:00 -05:00
|
|
|
MetaMonitorManager *monitor_manager =
|
|
|
|
meta_backend_get_monitor_manager (backend);
|
2017-05-25 04:12:51 -04:00
|
|
|
MetaLogicalMonitor *logical_monitor;
|
2016-11-25 01:31:38 -05:00
|
|
|
|
2016-11-29 21:49:00 -05:00
|
|
|
logical_monitor =
|
|
|
|
meta_monitor_manager_get_logical_monitor_at (monitor_manager, x, y);
|
2016-11-25 01:31:38 -05:00
|
|
|
if (logical_monitor)
|
|
|
|
{
|
|
|
|
float texture_scale;
|
|
|
|
|
2022-05-27 14:30:37 -04:00
|
|
|
if (meta_backend_is_stage_views_scaled (backend))
|
2017-02-24 05:10:52 -05:00
|
|
|
texture_scale = 1.0 / surface->scale;
|
|
|
|
else
|
2017-05-25 04:12:51 -04:00
|
|
|
texture_scale = (meta_logical_monitor_get_scale (logical_monitor) /
|
|
|
|
surface->scale);
|
2017-02-24 05:10:52 -05:00
|
|
|
|
2016-11-25 01:31:38 -05:00
|
|
|
meta_cursor_sprite_set_texture_scale (cursor_sprite, texture_scale);
|
2022-06-22 08:03:41 -04:00
|
|
|
meta_cursor_sprite_set_texture_transform (cursor_sprite,
|
|
|
|
surface->buffer_transform);
|
2016-11-25 01:31:38 -05:00
|
|
|
}
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
2022-06-13 04:09:26 -04:00
|
|
|
#endif
|
|
|
|
|
2015-10-21 10:36:44 -04:00
|
|
|
meta_wayland_surface_update_outputs (surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-04-19 15:51:31 -04:00
|
|
|
meta_wayland_cursor_surface_assigned (MetaWaylandSurfaceRole *surface_role)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
|
|
|
MetaWaylandSurface *surface =
|
|
|
|
meta_wayland_surface_role_get_surface (surface_role);
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurface *cursor_surface =
|
|
|
|
META_WAYLAND_CURSOR_SURFACE (surface_role);
|
|
|
|
MetaWaylandCursorSurfacePrivate *priv =
|
|
|
|
meta_wayland_cursor_surface_get_instance_private (cursor_surface);
|
2015-10-21 10:36:44 -04:00
|
|
|
|
2016-08-16 12:21:46 -04:00
|
|
|
wl_list_insert_list (&priv->frame_callbacks,
|
2020-04-27 09:43:19 -04:00
|
|
|
&surface->unassigned.pending_frame_callback_list);
|
|
|
|
wl_list_init (&surface->unassigned.pending_frame_callback_list);
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-07-11 05:20:44 -04:00
|
|
|
meta_wayland_cursor_surface_pre_apply_state (MetaWaylandSurfaceRole *surface_role,
|
|
|
|
MetaWaylandSurfaceState *pending)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurface *cursor_surface =
|
|
|
|
META_WAYLAND_CURSOR_SURFACE (surface_role);
|
|
|
|
MetaWaylandCursorSurfacePrivate *priv =
|
|
|
|
meta_wayland_cursor_surface_get_instance_private (cursor_surface);
|
2015-10-21 10:36:44 -04:00
|
|
|
|
2016-05-12 09:53:07 -04:00
|
|
|
if (pending->newly_attached && priv->buffer)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
wayland/surface: Overhaul handling of buffer use count
Move the use count from a separate MetaWaylandBufferRef struct to the
MetaWaylandBuffer class, and remove the former.
The buffer use count is now incremented already in
meta_wayland_surface_commit, since the Wayland protocol defines the
buffer to be in use by the compositor at that point. If the buffer
attachment ends up being dropped again before it is applied to the
surface state (e.g. because another buffer is committed to a
synchronized sub-surface before the parent surface is committed),
the use count is now decremented, and a buffer release event is sent if
the use count drops to 0.
Buffer release events were previously incorrectly not sent under these
circumstances. Test case: Run the weston-subsurfaces demo with the -r1
and/or -t1 command line parameter. Resize the window. Before this
change, weston-subsurfaces would freeze or abort after a few resize
operations, because mutter failed to send release events and the
client ran out of usable buffers.
v2:
* Handle NULL priv->buffer_ref in
meta_wayland_cursor_surface_apply_state.
v3:
* Remove MetaWaylandBufferRef altogether, move the use count tracking
to MetaWaylandBuffer itself. Much simpler, and doesn't run into
lifetime issues when mutter shuts down.
v4:
* Warn if use count isn't 0 in meta_wayland_buffer_finalize.
* Keep pending_buffer_resource_destroyed for attached but not yet
committed buffers. If the client attaches a buffer and then destroys
it before commit, we ignore the buffer attachement, same as before
this MR.
v5:
* Rebase on top of new commit which splits up surface->texture.
* MetaWaylandSurfaceState::buffer can only be non-NULL if
::newly_attached is TRUE, simplify accordingly.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-06-22 12:43:11 -04:00
|
|
|
meta_wayland_buffer_dec_use_count (priv->buffer);
|
2016-05-12 09:53:07 -04:00
|
|
|
g_clear_object (&priv->buffer);
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-07-11 05:20:44 -04:00
|
|
|
meta_wayland_cursor_surface_apply_state (MetaWaylandSurfaceRole *surface_role,
|
|
|
|
MetaWaylandSurfaceState *pending)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurface *cursor_surface =
|
|
|
|
META_WAYLAND_CURSOR_SURFACE (surface_role);
|
|
|
|
MetaWaylandCursorSurfacePrivate *priv =
|
|
|
|
meta_wayland_cursor_surface_get_instance_private (cursor_surface);
|
2015-10-21 10:36:44 -04:00
|
|
|
|
wayland/surface: Overhaul handling of buffer use count
Move the use count from a separate MetaWaylandBufferRef struct to the
MetaWaylandBuffer class, and remove the former.
The buffer use count is now incremented already in
meta_wayland_surface_commit, since the Wayland protocol defines the
buffer to be in use by the compositor at that point. If the buffer
attachment ends up being dropped again before it is applied to the
surface state (e.g. because another buffer is committed to a
synchronized sub-surface before the parent surface is committed),
the use count is now decremented, and a buffer release event is sent if
the use count drops to 0.
Buffer release events were previously incorrectly not sent under these
circumstances. Test case: Run the weston-subsurfaces demo with the -r1
and/or -t1 command line parameter. Resize the window. Before this
change, weston-subsurfaces would freeze or abort after a few resize
operations, because mutter failed to send release events and the
client ran out of usable buffers.
v2:
* Handle NULL priv->buffer_ref in
meta_wayland_cursor_surface_apply_state.
v3:
* Remove MetaWaylandBufferRef altogether, move the use count tracking
to MetaWaylandBuffer itself. Much simpler, and doesn't run into
lifetime issues when mutter shuts down.
v4:
* Warn if use count isn't 0 in meta_wayland_buffer_finalize.
* Keep pending_buffer_resource_destroyed for attached but not yet
committed buffers. If the client attaches a buffer and then destroys
it before commit, we ignore the buffer attachement, same as before
this MR.
v5:
* Rebase on top of new commit which splits up surface->texture.
* MetaWaylandSurfaceState::buffer can only be non-NULL if
::newly_attached is TRUE, simplify accordingly.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-06-22 12:43:11 -04:00
|
|
|
if (pending->buffer)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
wayland/surface: Overhaul handling of buffer use count
Move the use count from a separate MetaWaylandBufferRef struct to the
MetaWaylandBuffer class, and remove the former.
The buffer use count is now incremented already in
meta_wayland_surface_commit, since the Wayland protocol defines the
buffer to be in use by the compositor at that point. If the buffer
attachment ends up being dropped again before it is applied to the
surface state (e.g. because another buffer is committed to a
synchronized sub-surface before the parent surface is committed),
the use count is now decremented, and a buffer release event is sent if
the use count drops to 0.
Buffer release events were previously incorrectly not sent under these
circumstances. Test case: Run the weston-subsurfaces demo with the -r1
and/or -t1 command line parameter. Resize the window. Before this
change, weston-subsurfaces would freeze or abort after a few resize
operations, because mutter failed to send release events and the
client ran out of usable buffers.
v2:
* Handle NULL priv->buffer_ref in
meta_wayland_cursor_surface_apply_state.
v3:
* Remove MetaWaylandBufferRef altogether, move the use count tracking
to MetaWaylandBuffer itself. Much simpler, and doesn't run into
lifetime issues when mutter shuts down.
v4:
* Warn if use count isn't 0 in meta_wayland_buffer_finalize.
* Keep pending_buffer_resource_destroyed for attached but not yet
committed buffers. If the client attaches a buffer and then destroys
it before commit, we ignore the buffer attachement, same as before
this MR.
v5:
* Rebase on top of new commit which splits up surface->texture.
* MetaWaylandSurfaceState::buffer can only be non-NULL if
::newly_attached is TRUE, simplify accordingly.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-06-22 12:43:11 -04:00
|
|
|
priv->buffer = g_object_ref (pending->buffer);
|
|
|
|
meta_wayland_buffer_inc_use_count (priv->buffer);
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:21:46 -04:00
|
|
|
wl_list_insert_list (&priv->frame_callbacks,
|
|
|
|
&pending->frame_callback_list);
|
|
|
|
wl_list_init (&pending->frame_callback_list);
|
2015-10-21 10:36:44 -04:00
|
|
|
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
if (pending->newly_attached &&
|
2019-06-07 09:51:45 -04:00
|
|
|
((!cairo_region_is_empty (pending->surface_damage) ||
|
|
|
|
!cairo_region_is_empty (pending->buffer_damage)) ||
|
|
|
|
!priv->buffer))
|
2018-04-19 15:51:31 -04:00
|
|
|
update_cursor_sprite_texture (META_WAYLAND_CURSOR_SURFACE (surface_role));
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-04-19 15:51:31 -04:00
|
|
|
meta_wayland_cursor_surface_is_on_logical_monitor (MetaWaylandSurfaceRole *role,
|
|
|
|
MetaLogicalMonitor *logical_monitor)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
|
|
|
MetaWaylandSurface *surface =
|
|
|
|
meta_wayland_surface_role_get_surface (role);
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurface *cursor_surface =
|
|
|
|
META_WAYLAND_CURSOR_SURFACE (surface->role);
|
|
|
|
MetaWaylandCursorSurfacePrivate *priv =
|
|
|
|
meta_wayland_cursor_surface_get_instance_private (cursor_surface);
|
2020-07-13 07:34:59 -04:00
|
|
|
ClutterInputDevice *device;
|
2019-02-20 09:53:44 -05:00
|
|
|
graphene_point_t point;
|
2019-02-20 10:23:04 -05:00
|
|
|
graphene_rect_t logical_monitor_rect;
|
2015-10-21 10:36:44 -04:00
|
|
|
|
2019-04-18 13:21:36 -04:00
|
|
|
if (!priv->cursor_renderer)
|
|
|
|
return FALSE;
|
|
|
|
|
2017-06-08 10:13:16 -04:00
|
|
|
logical_monitor_rect =
|
2019-02-20 10:23:04 -05:00
|
|
|
meta_rectangle_to_graphene_rect (&logical_monitor->rect);
|
2018-03-23 08:05:12 -04:00
|
|
|
|
2020-07-13 07:34:59 -04:00
|
|
|
device = meta_cursor_renderer_get_input_device (priv->cursor_renderer);
|
2020-11-18 09:49:02 -05:00
|
|
|
clutter_seat_query_state (clutter_input_device_get_seat (device),
|
|
|
|
device, NULL, &point, NULL);
|
2018-03-23 08:05:12 -04:00
|
|
|
|
2019-02-20 10:23:04 -05:00
|
|
|
return graphene_rect_contains_point (&logical_monitor_rect, &point);
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-04-19 15:51:31 -04:00
|
|
|
meta_wayland_cursor_surface_dispose (GObject *object)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurface *cursor_surface =
|
|
|
|
META_WAYLAND_CURSOR_SURFACE (object);
|
|
|
|
MetaWaylandCursorSurfacePrivate *priv =
|
|
|
|
meta_wayland_cursor_surface_get_instance_private (cursor_surface);
|
2016-08-16 12:21:46 -04:00
|
|
|
MetaWaylandFrameCallback *cb, *next;
|
|
|
|
|
|
|
|
wl_list_for_each_safe (cb, next, &priv->frame_callbacks, link)
|
|
|
|
wl_resource_destroy (cb->resource);
|
2015-10-21 10:36:44 -04:00
|
|
|
|
2016-05-12 09:53:07 -04:00
|
|
|
g_signal_handlers_disconnect_by_func (priv->cursor_sprite,
|
2018-04-19 15:51:31 -04:00
|
|
|
cursor_sprite_prepare_at, cursor_surface);
|
2015-10-21 10:36:44 -04:00
|
|
|
|
2016-05-12 09:53:07 -04:00
|
|
|
g_clear_object (&priv->cursor_renderer);
|
2021-07-05 10:19:05 -04:00
|
|
|
|
|
|
|
if (priv->cursor_sprite)
|
|
|
|
{
|
|
|
|
meta_cursor_sprite_set_prepare_func (META_CURSOR_SPRITE (priv->cursor_sprite),
|
|
|
|
NULL, NULL);
|
|
|
|
g_clear_object (&priv->cursor_sprite);
|
|
|
|
}
|
2015-10-21 10:36:44 -04:00
|
|
|
|
2016-05-12 09:53:07 -04:00
|
|
|
if (priv->buffer)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
wayland/surface: Overhaul handling of buffer use count
Move the use count from a separate MetaWaylandBufferRef struct to the
MetaWaylandBuffer class, and remove the former.
The buffer use count is now incremented already in
meta_wayland_surface_commit, since the Wayland protocol defines the
buffer to be in use by the compositor at that point. If the buffer
attachment ends up being dropped again before it is applied to the
surface state (e.g. because another buffer is committed to a
synchronized sub-surface before the parent surface is committed),
the use count is now decremented, and a buffer release event is sent if
the use count drops to 0.
Buffer release events were previously incorrectly not sent under these
circumstances. Test case: Run the weston-subsurfaces demo with the -r1
and/or -t1 command line parameter. Resize the window. Before this
change, weston-subsurfaces would freeze or abort after a few resize
operations, because mutter failed to send release events and the
client ran out of usable buffers.
v2:
* Handle NULL priv->buffer_ref in
meta_wayland_cursor_surface_apply_state.
v3:
* Remove MetaWaylandBufferRef altogether, move the use count tracking
to MetaWaylandBuffer itself. Much simpler, and doesn't run into
lifetime issues when mutter shuts down.
v4:
* Warn if use count isn't 0 in meta_wayland_buffer_finalize.
* Keep pending_buffer_resource_destroyed for attached but not yet
committed buffers. If the client attaches a buffer and then destroys
it before commit, we ignore the buffer attachement, same as before
this MR.
v5:
* Rebase on top of new commit which splits up surface->texture.
* MetaWaylandSurfaceState::buffer can only be non-NULL if
::newly_attached is TRUE, simplify accordingly.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-06-22 12:43:11 -04:00
|
|
|
meta_wayland_buffer_dec_use_count (priv->buffer);
|
2016-05-12 09:53:07 -04:00
|
|
|
g_clear_object (&priv->buffer);
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
|
|
|
|
2018-04-19 15:51:31 -04:00
|
|
|
G_OBJECT_CLASS (meta_wayland_cursor_surface_parent_class)->dispose (object);
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
|
|
|
|
2016-08-25 05:38:45 -04:00
|
|
|
static void
|
2018-04-19 15:51:31 -04:00
|
|
|
meta_wayland_cursor_surface_constructed (GObject *object)
|
2016-08-25 05:38:45 -04:00
|
|
|
{
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurface *cursor_surface =
|
|
|
|
META_WAYLAND_CURSOR_SURFACE (object);
|
|
|
|
MetaWaylandCursorSurfacePrivate *priv =
|
|
|
|
meta_wayland_cursor_surface_get_instance_private (cursor_surface);
|
2016-08-25 05:38:45 -04:00
|
|
|
MetaWaylandSurfaceRole *surface_role =
|
2018-04-19 15:51:31 -04:00
|
|
|
META_WAYLAND_SURFACE_ROLE (cursor_surface);
|
2016-08-25 05:38:45 -04:00
|
|
|
MetaWaylandSurface *surface =
|
|
|
|
meta_wayland_surface_role_get_surface (surface_role);
|
2021-11-15 08:24:53 -05:00
|
|
|
MetaWaylandCompositor *compositor = surface->compositor;
|
|
|
|
MetaBackend *backend = meta_context_get_backend (compositor->context);
|
|
|
|
MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
|
2016-08-25 05:38:45 -04:00
|
|
|
MetaWaylandBuffer *buffer;
|
|
|
|
|
|
|
|
buffer = meta_wayland_surface_get_buffer (surface);
|
2016-09-07 04:23:25 -04:00
|
|
|
|
|
|
|
g_warn_if_fail (!buffer || buffer->resource);
|
|
|
|
|
|
|
|
if (buffer && buffer->resource)
|
2016-08-25 05:38:45 -04:00
|
|
|
{
|
wayland/surface: Overhaul handling of buffer use count
Move the use count from a separate MetaWaylandBufferRef struct to the
MetaWaylandBuffer class, and remove the former.
The buffer use count is now incremented already in
meta_wayland_surface_commit, since the Wayland protocol defines the
buffer to be in use by the compositor at that point. If the buffer
attachment ends up being dropped again before it is applied to the
surface state (e.g. because another buffer is committed to a
synchronized sub-surface before the parent surface is committed),
the use count is now decremented, and a buffer release event is sent if
the use count drops to 0.
Buffer release events were previously incorrectly not sent under these
circumstances. Test case: Run the weston-subsurfaces demo with the -r1
and/or -t1 command line parameter. Resize the window. Before this
change, weston-subsurfaces would freeze or abort after a few resize
operations, because mutter failed to send release events and the
client ran out of usable buffers.
v2:
* Handle NULL priv->buffer_ref in
meta_wayland_cursor_surface_apply_state.
v3:
* Remove MetaWaylandBufferRef altogether, move the use count tracking
to MetaWaylandBuffer itself. Much simpler, and doesn't run into
lifetime issues when mutter shuts down.
v4:
* Warn if use count isn't 0 in meta_wayland_buffer_finalize.
* Keep pending_buffer_resource_destroyed for attached but not yet
committed buffers. If the client attaches a buffer and then destroys
it before commit, we ignore the buffer attachement, same as before
this MR.
v5:
* Rebase on top of new commit which splits up surface->texture.
* MetaWaylandSurfaceState::buffer can only be non-NULL if
::newly_attached is TRUE, simplify accordingly.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-06-22 12:43:11 -04:00
|
|
|
priv->buffer = g_object_ref (surface->buffer);
|
|
|
|
meta_wayland_buffer_inc_use_count (priv->buffer);
|
2016-08-25 05:38:45 -04:00
|
|
|
}
|
2018-05-02 06:27:02 -04:00
|
|
|
|
2021-11-15 08:24:53 -05:00
|
|
|
priv->cursor_sprite = meta_cursor_sprite_wayland_new (surface,
|
|
|
|
cursor_tracker);
|
2021-07-05 10:19:05 -04:00
|
|
|
meta_cursor_sprite_set_prepare_func (META_CURSOR_SPRITE (priv->cursor_sprite),
|
|
|
|
(MetaCursorPrepareFunc) cursor_sprite_prepare_at,
|
|
|
|
cursor_surface);
|
2016-08-25 05:38:45 -04:00
|
|
|
}
|
|
|
|
|
2015-10-21 10:36:44 -04:00
|
|
|
static void
|
2018-04-19 15:51:31 -04:00
|
|
|
meta_wayland_cursor_surface_init (MetaWaylandCursorSurface *role)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurfacePrivate *priv =
|
|
|
|
meta_wayland_cursor_surface_get_instance_private (role);
|
2016-05-12 09:53:07 -04:00
|
|
|
|
2016-08-16 12:21:46 -04:00
|
|
|
wl_list_init (&priv->frame_callbacks);
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-04-19 15:51:31 -04:00
|
|
|
meta_wayland_cursor_surface_class_init (MetaWaylandCursorSurfaceClass *klass)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
|
|
|
MetaWaylandSurfaceRoleClass *surface_role_class =
|
|
|
|
META_WAYLAND_SURFACE_ROLE_CLASS (klass);
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2018-04-19 15:51:31 -04:00
|
|
|
surface_role_class->assigned = meta_wayland_cursor_surface_assigned;
|
2019-07-11 05:20:44 -04:00
|
|
|
surface_role_class->pre_apply_state =
|
|
|
|
meta_wayland_cursor_surface_pre_apply_state;
|
|
|
|
surface_role_class->apply_state = meta_wayland_cursor_surface_apply_state;
|
2018-04-19 15:51:31 -04:00
|
|
|
surface_role_class->is_on_logical_monitor =
|
|
|
|
meta_wayland_cursor_surface_is_on_logical_monitor;
|
2015-10-21 10:36:44 -04:00
|
|
|
|
2018-04-19 15:51:31 -04:00
|
|
|
object_class->constructed = meta_wayland_cursor_surface_constructed;
|
|
|
|
object_class->dispose = meta_wayland_cursor_surface_dispose;
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MetaCursorSprite *
|
2018-04-19 15:51:31 -04:00
|
|
|
meta_wayland_cursor_surface_get_sprite (MetaWaylandCursorSurface *cursor_surface)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurfacePrivate *priv =
|
|
|
|
meta_wayland_cursor_surface_get_instance_private (cursor_surface);
|
2016-05-12 09:53:07 -04:00
|
|
|
|
2018-04-30 06:03:31 -04:00
|
|
|
return META_CURSOR_SPRITE (priv->cursor_sprite);
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-04-19 15:51:31 -04:00
|
|
|
meta_wayland_cursor_surface_set_hotspot (MetaWaylandCursorSurface *cursor_surface,
|
|
|
|
int hotspot_x,
|
|
|
|
int hotspot_y)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurfacePrivate *priv =
|
|
|
|
meta_wayland_cursor_surface_get_instance_private (cursor_surface);
|
2016-05-12 09:53:07 -04:00
|
|
|
|
|
|
|
if (priv->hot_x == hotspot_x &&
|
|
|
|
priv->hot_y == hotspot_y)
|
2015-10-21 10:36:44 -04:00
|
|
|
return;
|
|
|
|
|
2016-05-12 09:53:07 -04:00
|
|
|
priv->hot_x = hotspot_x;
|
|
|
|
priv->hot_y = hotspot_y;
|
2018-04-19 15:51:31 -04:00
|
|
|
update_cursor_sprite_texture (cursor_surface);
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-04-19 15:51:31 -04:00
|
|
|
meta_wayland_cursor_surface_get_hotspot (MetaWaylandCursorSurface *cursor_surface,
|
|
|
|
int *hotspot_x,
|
|
|
|
int *hotspot_y)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurfacePrivate *priv =
|
|
|
|
meta_wayland_cursor_surface_get_instance_private (cursor_surface);
|
2016-05-12 09:53:07 -04:00
|
|
|
|
2015-10-21 10:36:44 -04:00
|
|
|
if (hotspot_x)
|
2016-05-12 09:53:07 -04:00
|
|
|
*hotspot_x = priv->hot_x;
|
2015-10-21 10:36:44 -04:00
|
|
|
if (hotspot_y)
|
2016-05-12 09:53:07 -04:00
|
|
|
*hotspot_y = priv->hot_y;
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:21:46 -04:00
|
|
|
static void
|
2018-04-19 15:51:31 -04:00
|
|
|
on_cursor_painted (MetaCursorRenderer *renderer,
|
|
|
|
MetaCursorSprite *displayed_sprite,
|
2021-02-02 08:49:56 -05:00
|
|
|
ClutterStageView *stage_view,
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurface *cursor_surface)
|
2016-08-16 12:21:46 -04:00
|
|
|
{
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurfacePrivate *priv =
|
|
|
|
meta_wayland_cursor_surface_get_instance_private (cursor_surface);
|
2016-08-16 12:21:46 -04:00
|
|
|
guint32 time = (guint32) (g_get_monotonic_time () / 1000);
|
2022-05-30 17:48:44 -04:00
|
|
|
MetaWaylandSurfaceRole *surface_role =
|
|
|
|
META_WAYLAND_SURFACE_ROLE (cursor_surface);
|
|
|
|
MetaWaylandSurface *surface =
|
|
|
|
meta_wayland_surface_role_get_surface (surface_role);
|
|
|
|
MetaContext *context =
|
|
|
|
meta_wayland_compositor_get_context (surface->compositor);
|
2021-02-02 08:51:34 -05:00
|
|
|
MetaWaylandCompositor *compositor =
|
2021-03-03 16:00:05 -05:00
|
|
|
meta_context_get_wayland_compositor (context);
|
2016-08-16 12:21:46 -04:00
|
|
|
|
2018-04-30 06:03:31 -04:00
|
|
|
if (displayed_sprite != META_CURSOR_SPRITE (priv->cursor_sprite))
|
2016-08-16 12:21:46 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
while (!wl_list_empty (&priv->frame_callbacks))
|
|
|
|
{
|
|
|
|
MetaWaylandFrameCallback *callback =
|
|
|
|
wl_container_of (priv->frame_callbacks.next, callback, link);
|
|
|
|
|
|
|
|
wl_callback_send_done (callback->resource, time);
|
|
|
|
wl_resource_destroy (callback->resource);
|
|
|
|
}
|
2021-02-02 08:51:34 -05:00
|
|
|
|
|
|
|
meta_wayland_presentation_time_cursor_painted (&compositor->presentation_time,
|
|
|
|
stage_view,
|
|
|
|
cursor_surface);
|
2016-08-16 12:21:46 -04:00
|
|
|
}
|
|
|
|
|
2015-10-21 10:36:44 -04:00
|
|
|
void
|
2018-04-19 15:51:31 -04:00
|
|
|
meta_wayland_cursor_surface_set_renderer (MetaWaylandCursorSurface *cursor_surface,
|
|
|
|
MetaCursorRenderer *renderer)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurfacePrivate *priv =
|
|
|
|
meta_wayland_cursor_surface_get_instance_private (cursor_surface);
|
2016-05-12 09:53:07 -04:00
|
|
|
|
|
|
|
if (priv->cursor_renderer == renderer)
|
2015-10-21 10:36:44 -04:00
|
|
|
return;
|
|
|
|
|
2016-05-12 09:53:07 -04:00
|
|
|
if (priv->cursor_renderer)
|
2016-08-16 12:21:46 -04:00
|
|
|
{
|
2019-11-15 19:25:52 -05:00
|
|
|
g_clear_signal_handler (&priv->cursor_painted_handler_id,
|
|
|
|
priv->cursor_renderer);
|
2016-08-16 12:21:46 -04:00
|
|
|
g_object_unref (priv->cursor_renderer);
|
|
|
|
}
|
|
|
|
if (renderer)
|
|
|
|
{
|
|
|
|
priv->cursor_painted_handler_id =
|
|
|
|
g_signal_connect_object (renderer, "cursor-painted",
|
2018-04-19 15:51:31 -04:00
|
|
|
G_CALLBACK (on_cursor_painted), cursor_surface, 0);
|
2016-08-16 12:21:46 -04:00
|
|
|
g_object_ref (renderer);
|
|
|
|
}
|
2015-10-21 10:36:44 -04:00
|
|
|
|
2016-05-12 09:53:07 -04:00
|
|
|
priv->cursor_renderer = renderer;
|
2018-04-19 15:51:31 -04:00
|
|
|
update_cursor_sprite_texture (cursor_surface);
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MetaCursorRenderer *
|
2018-04-19 15:51:31 -04:00
|
|
|
meta_wayland_cursor_surface_get_renderer (MetaWaylandCursorSurface *cursor_surface)
|
2015-10-21 10:36:44 -04:00
|
|
|
{
|
2018-04-19 15:51:31 -04:00
|
|
|
MetaWaylandCursorSurfacePrivate *priv =
|
|
|
|
meta_wayland_cursor_surface_get_instance_private (cursor_surface);
|
2016-05-12 09:53:07 -04:00
|
|
|
|
|
|
|
return priv->cursor_renderer;
|
2015-10-21 10:36:44 -04:00
|
|
|
}
|