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)
|
|
|
|
|
|
|
|
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;
|
|
|
|
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-01-07 11:31:47 -05:00
|
|
|
surface_actor = meta_window_actor_get_topmost_surface (window_actor);
|
|
|
|
if (!surface_actor ||
|
|
|
|
CLUTTER_ACTOR (surface_actor) !=
|
|
|
|
clutter_actor_get_last_child (CLUTTER_ACTOR (window_actor)))
|
2021-08-06 11:00:19 -04:00
|
|
|
goto done;
|
2019-09-12 16:07:20 -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;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
clutter: Paint views with individual frame clocks
Replace the default master clock with multiple frame clocks, each
driving its own stage view. As each stage view represents one CRTC, this
means we draw each CRTC with its own designated frame clock,
disconnected from all the others.
For example this means we when using the native backend will never need
to wait for one monitor to vsync before painting another, so e.g. having
a 144 Hz monitor next to a 60 Hz monitor, things including both Wayland
and X11 applications and shell UI will be able to render at the
corresponding monitor refresh rate.
This also changes a warning about missed frames when sending
_NETWM_FRAME_TIMINGS messages to a debug log entry, as it's expected
that we'll start missing frames e.g. when a X11 window (via Xwayland) is
exclusively within a stage view that was not painted, while another one
was, still increasing the global frame clock.
Addititonally, this also requires the X11 window actor to schedule
timeouts for _NET_WM_FRAME_DRAWN/_NET_WM_FRAME_TIMINGS event emitting,
if the actor wasn't on any stage views, as now we'll only get the frame
callbacks on actors when they actually were painted, while in the past,
we'd invoke that vfunc when anything was painted.
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/903
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1285
2020-05-29 18:27:56 -04:00
|
|
|
meta_compositor_native_before_paint (MetaCompositor *compositor,
|
|
|
|
ClutterStageView *stage_view)
|
2019-09-12 16:07:20 -04:00
|
|
|
{
|
|
|
|
MetaCompositorClass *parent_class;
|
|
|
|
|
|
|
|
maybe_assign_primary_plane (compositor);
|
|
|
|
|
|
|
|
parent_class = META_COMPOSITOR_CLASS (meta_compositor_native_parent_class);
|
clutter: Paint views with individual frame clocks
Replace the default master clock with multiple frame clocks, each
driving its own stage view. As each stage view represents one CRTC, this
means we draw each CRTC with its own designated frame clock,
disconnected from all the others.
For example this means we when using the native backend will never need
to wait for one monitor to vsync before painting another, so e.g. having
a 144 Hz monitor next to a 60 Hz monitor, things including both Wayland
and X11 applications and shell UI will be able to render at the
corresponding monitor refresh rate.
This also changes a warning about missed frames when sending
_NETWM_FRAME_TIMINGS messages to a debug log entry, as it's expected
that we'll start missing frames e.g. when a X11 window (via Xwayland) is
exclusively within a stage view that was not painted, while another one
was, still increasing the global frame clock.
Addititonally, this also requires the X11 window actor to schedule
timeouts for _NET_WM_FRAME_DRAWN/_NET_WM_FRAME_TIMINGS event emitting,
if the actor wasn't on any stage views, as now we'll only get the frame
callbacks on actors when they actually were painted, while in the past,
we'd invoke that vfunc when anything was painted.
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/903
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1285
2020-05-29 18:27:56 -04:00
|
|
|
parent_class->before_paint (compositor, stage_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
|
|
|
}
|