2019-09-12 16:07:20 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 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"
|
|
|
|
|
|
|
|
#include "compositor/meta-compositor-native.h"
|
|
|
|
|
|
|
|
#include "backends/meta-logical-monitor.h"
|
2021-08-06 11:00:19 -04:00
|
|
|
#include "backends/native/meta-crtc-kms.h"
|
2019-09-12 16:07:20 -04:00
|
|
|
#include "compositor/meta-surface-actor-wayland.h"
|
|
|
|
|
|
|
|
struct _MetaCompositorNative
|
|
|
|
{
|
|
|
|
MetaCompositorServer parent;
|
2021-08-06 11:00:19 -04:00
|
|
|
|
|
|
|
MetaWaylandSurface *current_scanout_candidate;
|
2019-09-12 16:07:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (MetaCompositorNative, meta_compositor_native,
|
|
|
|
META_TYPE_COMPOSITOR_SERVER)
|
|
|
|
|
2022-05-03 10:47:02 -04:00
|
|
|
#ifdef HAVE_WAYLAND
|
|
|
|
|
2019-09-12 16:07:20 -04:00
|
|
|
static MetaRendererView *
|
|
|
|
get_window_view (MetaRenderer *renderer,
|
|
|
|
MetaWindow *window)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
MetaRendererView *view_found = NULL;
|
|
|
|
|
|
|
|
for (l = meta_renderer_get_views (renderer); l; l = l->next)
|
|
|
|
{
|
|
|
|
ClutterStageView *stage_view = l->data;
|
|
|
|
MetaRectangle view_layout;
|
|
|
|
|
|
|
|
clutter_stage_view_get_layout (stage_view, &view_layout);
|
|
|
|
|
|
|
|
if (meta_rectangle_equal (&window->buffer_rect,
|
|
|
|
&view_layout))
|
|
|
|
{
|
|
|
|
if (view_found)
|
|
|
|
return NULL;
|
|
|
|
view_found = META_RENDERER_VIEW (stage_view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return view_found;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
maybe_assign_primary_plane (MetaCompositor *compositor)
|
|
|
|
{
|
2021-08-06 11:00:19 -04:00
|
|
|
MetaCompositorNative *compositor_native = META_COMPOSITOR_NATIVE (compositor);
|
2019-09-12 16:07:20 -04:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaRenderer *renderer = meta_backend_get_renderer (backend);
|
|
|
|
MetaWindowActor *window_actor;
|
|
|
|
MetaWindow *window;
|
|
|
|
MetaRendererView *view;
|
2021-08-06 11:00:19 -04:00
|
|
|
MetaCrtc *crtc;
|
2019-09-12 16:07:20 -04:00
|
|
|
CoglFramebuffer *framebuffer;
|
|
|
|
CoglOnscreen *onscreen;
|
|
|
|
MetaSurfaceActor *surface_actor;
|
|
|
|
MetaSurfaceActorWayland *surface_actor_wayland;
|
2021-08-06 11:00:19 -04:00
|
|
|
MetaWaylandSurface *surface;
|
2022-02-08 14:23:27 -05:00
|
|
|
int geometry_scale;
|
2021-08-06 11:00:19 -04:00
|
|
|
MetaWaylandSurface *old_candidate =
|
|
|
|
compositor_native->current_scanout_candidate;
|
|
|
|
MetaWaylandSurface *new_candidate = NULL;
|
2019-09-12 16:07:20 -04:00
|
|
|
g_autoptr (CoglScanout) scanout = NULL;
|
|
|
|
|
|
|
|
if (meta_compositor_is_unredirect_inhibited (compositor))
|
2021-08-06 11:00:19 -04:00
|
|
|
goto done;
|
2019-09-12 16:07:20 -04:00
|
|
|
|
|
|
|
window_actor = meta_compositor_get_top_window_actor (compositor);
|
|
|
|
if (!window_actor)
|
2021-08-06 11:00:19 -04:00
|
|
|
goto done;
|
2019-09-12 16:07:20 -04:00
|
|
|
|
|
|
|
if (meta_window_actor_effect_in_progress (window_actor))
|
2021-08-06 11:00:19 -04:00
|
|
|
goto done;
|
2019-09-12 16:07:20 -04:00
|
|
|
|
|
|
|
if (clutter_actor_has_transitions (CLUTTER_ACTOR (window_actor)))
|
2021-08-06 11:00:19 -04:00
|
|
|
goto done;
|
2019-09-12 16:07:20 -04:00
|
|
|
|
|
|
|
window = meta_window_actor_get_meta_window (window_actor);
|
|
|
|
if (!window)
|
2021-08-06 11:00:19 -04:00
|
|
|
goto done;
|
2019-09-12 16:07:20 -04:00
|
|
|
|
|
|
|
view = get_window_view (renderer, window);
|
|
|
|
if (!view)
|
2021-08-06 11:00:19 -04:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
crtc = meta_renderer_view_get_crtc (META_RENDERER_VIEW (view));
|
|
|
|
if (!META_IS_CRTC_KMS (crtc))
|
|
|
|
goto done;
|
2019-09-12 16:07:20 -04:00
|
|
|
|
|
|
|
framebuffer = clutter_stage_view_get_framebuffer (CLUTTER_STAGE_VIEW (view));
|
2020-10-13 05:35:47 -04:00
|
|
|
if (!COGL_IS_ONSCREEN (framebuffer))
|
2021-08-06 11:00:19 -04:00
|
|
|
goto done;
|
2019-09-12 16:07:20 -04:00
|
|
|
|
2022-05-11 16:32:33 -04:00
|
|
|
surface_actor = meta_window_actor_get_scanout_candidate (window_actor);
|
|
|
|
if (!surface_actor)
|
2021-08-06 11:00:19 -04:00
|
|
|
goto done;
|
|
|
|
|
2022-05-11 16:32:33 -04:00
|
|
|
surface_actor_wayland = META_SURFACE_ACTOR_WAYLAND (surface_actor);
|
2021-08-06 11:00:19 -04:00
|
|
|
surface = meta_surface_actor_wayland_get_surface (surface_actor_wayland);
|
|
|
|
if (!surface)
|
|
|
|
goto done;
|
|
|
|
|
2022-02-08 14:23:27 -05:00
|
|
|
geometry_scale = meta_window_actor_get_geometry_scale (window_actor);
|
|
|
|
if (!meta_wayland_surface_can_scanout_untransformed (surface, view,
|
|
|
|
geometry_scale))
|
|
|
|
goto done;
|
|
|
|
|
2021-08-06 11:00:19 -04:00
|
|
|
new_candidate = surface;
|
|
|
|
|
2019-09-12 16:07:20 -04:00
|
|
|
onscreen = COGL_ONSCREEN (framebuffer);
|
|
|
|
scanout = meta_surface_actor_wayland_try_acquire_scanout (surface_actor_wayland,
|
|
|
|
onscreen);
|
|
|
|
if (!scanout)
|
2021-08-06 11:00:19 -04:00
|
|
|
goto done;
|
2019-09-12 16:07:20 -04:00
|
|
|
|
|
|
|
clutter_stage_view_assign_next_scanout (CLUTTER_STAGE_VIEW (view), scanout);
|
2021-08-06 11:00:19 -04:00
|
|
|
|
|
|
|
done:
|
|
|
|
|
|
|
|
if (old_candidate && old_candidate != new_candidate)
|
|
|
|
{
|
|
|
|
meta_wayland_surface_set_scanout_candidate (old_candidate, NULL);
|
|
|
|
g_clear_weak_pointer (&compositor_native->current_scanout_candidate);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_candidate)
|
|
|
|
{
|
|
|
|
meta_wayland_surface_set_scanout_candidate (surface, crtc);
|
|
|
|
g_set_weak_pointer (&compositor_native->current_scanout_candidate,
|
|
|
|
surface);
|
|
|
|
}
|
2019-09-12 16:07:20 -04:00
|
|
|
}
|
2022-05-03 10:47:02 -04:00
|
|
|
#endif /* HAVE_WAYLAND */
|
2019-09-12 16:07:20 -04:00
|
|
|
|
|
|
|
static void
|
compositor: Expose the MetaCompositorView in before_paint () vfunc
The idea is that the state of the MetaCompositorView shall be
up-to-date only in specific scenarios, thus allowing operations
performed on it to be queued and aggregated to be handled in the
right time, and only if they are still necessary.
For example, in a following commit, the top window actor in each
view will be planned (if needed) only once before painting a frame,
rendering the top window actor in the MetaCompositorView potentially
stale in all other times.
Similarly, if a MetaCompositorView is destroyed before the beginning
of the frame, a queued operation to update its top window actor can be
discarded.
As an interface segragation measure, and as part of an attempt to
avoid the use of g_return_if_fail () to check the validity of the
MetaCompositorView's state in multiple places (which is still prone to
human error), the interfaces through which a MetaCompositorView is
made available would only ones where it's state is gurenteed to be
up-to-date.
Specifically, this commit gurentees that the state of the
MetaCompositorView would be up-to-date during the before_paint () and
after_paint () vfuncs exposed to child classes of the MetaCompositor.
The frame_in_progress variable will be used in a following commit to
guarantee that the MetaCompositorView's state is not invalidated during
this time.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2526>
2022-07-11 05:23:24 -04:00
|
|
|
meta_compositor_native_before_paint (MetaCompositor *compositor,
|
|
|
|
MetaCompositorView *compositor_view)
|
2019-09-12 16:07:20 -04:00
|
|
|
{
|
|
|
|
MetaCompositorClass *parent_class;
|
|
|
|
|
2022-05-03 10:47:02 -04:00
|
|
|
#ifdef HAVE_WAYLAND
|
2019-09-12 16:07:20 -04:00
|
|
|
maybe_assign_primary_plane (compositor);
|
2022-05-03 10:47:02 -04:00
|
|
|
#endif
|
2019-09-12 16:07:20 -04:00
|
|
|
|
|
|
|
parent_class = META_COMPOSITOR_CLASS (meta_compositor_native_parent_class);
|
compositor: Expose the MetaCompositorView in before_paint () vfunc
The idea is that the state of the MetaCompositorView shall be
up-to-date only in specific scenarios, thus allowing operations
performed on it to be queued and aggregated to be handled in the
right time, and only if they are still necessary.
For example, in a following commit, the top window actor in each
view will be planned (if needed) only once before painting a frame,
rendering the top window actor in the MetaCompositorView potentially
stale in all other times.
Similarly, if a MetaCompositorView is destroyed before the beginning
of the frame, a queued operation to update its top window actor can be
discarded.
As an interface segragation measure, and as part of an attempt to
avoid the use of g_return_if_fail () to check the validity of the
MetaCompositorView's state in multiple places (which is still prone to
human error), the interfaces through which a MetaCompositorView is
made available would only ones where it's state is gurenteed to be
up-to-date.
Specifically, this commit gurentees that the state of the
MetaCompositorView would be up-to-date during the before_paint () and
after_paint () vfuncs exposed to child classes of the MetaCompositor.
The frame_in_progress variable will be used in a following commit to
guarantee that the MetaCompositorView's state is not invalidated during
this time.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2526>
2022-07-11 05:23:24 -04:00
|
|
|
parent_class->before_paint (compositor, compositor_view);
|
2019-09-12 16:07:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MetaCompositorNative *
|
2020-04-16 13:14:21 -04:00
|
|
|
meta_compositor_native_new (MetaDisplay *display,
|
|
|
|
MetaBackend *backend)
|
2019-09-12 16:07:20 -04:00
|
|
|
{
|
|
|
|
return g_object_new (META_TYPE_COMPOSITOR_NATIVE,
|
|
|
|
"display", display,
|
2020-04-16 13:14:21 -04:00
|
|
|
"backend", backend,
|
2019-09-12 16:07:20 -04:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2021-08-06 11:00:19 -04:00
|
|
|
static void
|
|
|
|
meta_compositor_native_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MetaCompositorNative *compositor_native = META_COMPOSITOR_NATIVE (object);
|
|
|
|
|
|
|
|
g_clear_weak_pointer (&compositor_native->current_scanout_candidate);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_compositor_native_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2019-09-12 16:07:20 -04:00
|
|
|
static void
|
|
|
|
meta_compositor_native_init (MetaCompositorNative *compositor_native)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_compositor_native_class_init (MetaCompositorNativeClass *klass)
|
|
|
|
{
|
2021-08-06 11:00:19 -04:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2019-09-12 16:07:20 -04:00
|
|
|
MetaCompositorClass *compositor_class = META_COMPOSITOR_CLASS (klass);
|
|
|
|
|
2021-08-06 11:00:19 -04:00
|
|
|
object_class->finalize = meta_compositor_native_finalize;
|
|
|
|
|
2020-05-29 18:02:42 -04:00
|
|
|
compositor_class->before_paint = meta_compositor_native_before_paint;
|
2019-09-12 16:07:20 -04:00
|
|
|
}
|