Skip to content

Commit 65d3479

Browse files
committed
compositor: Add support for direct scanout of Wayland surfaces
Try to bypass compositing if there is a fullscreen toplevel window with a buffer compatible with the primary plane of the monitor it is fullscreen on. Only non-mirrored is currently supported; as well as fullscreened on a single monitor. It should be possible to extend with more cases, but this starts small. It does this by introducing a new MetaCompositor sub type MetaCompositorNative specific to the native backend, which derives from MetaCompositorServer, containing functionality only relevant for when running on top of the native backend. Original Mutter commit: https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/798/diffs?commit_id=65a6c4c361b7dad10b19f9bcabdcf7b576d7daa0
1 parent cc0a694 commit 65d3479

File tree

9 files changed

+221
-14
lines changed

9 files changed

+221
-14
lines changed

clutter/clutter/clutter-stage-view.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,7 @@ clutter_stage_view_assign_next_scanout (ClutterStageView *view,
418418
ClutterStageViewPrivate *priv =
419419
clutter_stage_view_get_instance_private (view);
420420

421-
g_clear_object (&priv->next_scanout);
422-
priv->next_scanout = scanout;
421+
g_set_object (&priv->next_scanout, scanout);
423422
}
424423

425424
CoglScanout *
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* Copyright (C) 2019 Red Hat Inc.
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License as
6+
* published by the Free Software Foundation; either version 2 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17+
* 02111-1307, USA.
18+
*
19+
*/
20+
21+
#include "config.h"
22+
23+
#include "compositor/meta-compositor-native.h"
24+
25+
#include "backends/meta-logical-monitor.h"
26+
#include "compositor/meta-surface-actor-wayland.h"
27+
28+
struct _MetaCompositorNative
29+
{
30+
MetaCompositorServer parent;
31+
};
32+
33+
G_DEFINE_TYPE (MetaCompositorNative, meta_compositor_native,
34+
META_TYPE_COMPOSITOR_SERVER)
35+
36+
static MetaRendererView *
37+
get_window_view (MetaRenderer *renderer,
38+
MetaWindow *window)
39+
{
40+
GList *l;
41+
MetaRendererView *view_found = NULL;
42+
43+
for (l = meta_renderer_get_views (renderer); l; l = l->next)
44+
{
45+
ClutterStageView *stage_view = l->data;
46+
MetaRectangle view_layout;
47+
48+
clutter_stage_view_get_layout (stage_view, &view_layout);
49+
50+
if (meta_rectangle_equal (&window->buffer_rect,
51+
&view_layout))
52+
{
53+
if (view_found)
54+
return NULL;
55+
view_found = META_RENDERER_VIEW (stage_view);
56+
}
57+
}
58+
59+
return view_found;
60+
}
61+
62+
static void
63+
maybe_assign_primary_plane (MetaCompositor *compositor)
64+
{
65+
MetaBackend *backend = meta_get_backend ();
66+
MetaRenderer *renderer = meta_backend_get_renderer (backend);
67+
MetaWindowActor *window_actor;
68+
MetaWindow *window;
69+
MetaRendererView *view;
70+
CoglFramebuffer *framebuffer;
71+
CoglOnscreen *onscreen;
72+
MetaSurfaceActor *surface_actor;
73+
MetaSurfaceActorWayland *surface_actor_wayland;
74+
g_autoptr (CoglScanout) scanout = NULL;
75+
76+
if (meta_compositor_is_unredirect_inhibited (compositor))
77+
return;
78+
79+
window_actor = meta_compositor_get_top_window_actor (compositor);
80+
if (!window_actor)
81+
return;
82+
83+
if (meta_window_actor_effect_in_progress (window_actor))
84+
return;
85+
86+
if (clutter_actor_has_transitions (CLUTTER_ACTOR (window_actor)))
87+
return;
88+
89+
if (clutter_actor_get_n_children (CLUTTER_ACTOR (window_actor)) != 1)
90+
return;
91+
92+
window = meta_window_actor_get_meta_window (window_actor);
93+
if (!window)
94+
return;
95+
96+
view = get_window_view (renderer, window);
97+
if (!view)
98+
return;
99+
100+
framebuffer = clutter_stage_view_get_framebuffer (CLUTTER_STAGE_VIEW (view));
101+
if (!cogl_is_onscreen (framebuffer))
102+
return;
103+
104+
surface_actor = meta_window_actor_get_surface (window_actor);
105+
if (!META_IS_SURFACE_ACTOR_WAYLAND (surface_actor))
106+
return;
107+
108+
surface_actor_wayland = META_SURFACE_ACTOR_WAYLAND (surface_actor);
109+
onscreen = COGL_ONSCREEN (framebuffer);
110+
scanout = meta_surface_actor_wayland_try_acquire_scanout (surface_actor_wayland,
111+
onscreen);
112+
if (!scanout)
113+
return;
114+
115+
clutter_stage_view_assign_next_scanout (CLUTTER_STAGE_VIEW (view), scanout);
116+
}
117+
118+
static void
119+
meta_compositor_native_pre_paint (MetaCompositor *compositor)
120+
{
121+
MetaCompositorClass *parent_class;
122+
123+
maybe_assign_primary_plane (compositor);
124+
125+
parent_class = META_COMPOSITOR_CLASS (meta_compositor_native_parent_class);
126+
parent_class->pre_paint (compositor);
127+
}
128+
129+
MetaCompositorNative *
130+
meta_compositor_native_new (MetaDisplay *display)
131+
{
132+
return g_object_new (META_TYPE_COMPOSITOR_NATIVE,
133+
"display", display,
134+
NULL);
135+
}
136+
137+
static void
138+
meta_compositor_native_init (MetaCompositorNative *compositor_native)
139+
{
140+
}
141+
142+
static void
143+
meta_compositor_native_class_init (MetaCompositorNativeClass *klass)
144+
{
145+
MetaCompositorClass *compositor_class = META_COMPOSITOR_CLASS (klass);
146+
147+
compositor_class->pre_paint = meta_compositor_native_pre_paint;
148+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2019 Red Hat Inc.
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License as
6+
* published by the Free Software Foundation; either version 2 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17+
* 02111-1307, USA.
18+
*
19+
*/
20+
21+
#ifndef META_COMPOSITOR_NATIVE_H
22+
#define META_COMPOSITOR_NATIVE_H
23+
24+
#include "compositor/meta-compositor-server.h"
25+
26+
#define META_TYPE_COMPOSITOR_NATIVE (meta_compositor_native_get_type ())
27+
G_DECLARE_FINAL_TYPE (MetaCompositorNative, meta_compositor_native,
28+
META, COMPOSITOR_NATIVE, MetaCompositor)
29+
30+
MetaCompositorNative * meta_compositor_native_new (MetaDisplay *display);
31+
32+
#endif /* META_COMPOSITOR_NATIVE_H */

src/compositor/meta-compositor-server.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323

2424
#include "compositor/meta-compositor-server.h"
2525

26-
struct _MetaCompositorServer
27-
{
28-
MetaCompositor parent;
29-
};
30-
3126
G_DEFINE_TYPE (MetaCompositorServer, meta_compositor_server, META_TYPE_COMPOSITOR)
3227

3328
static gboolean

src/compositor/meta-compositor-server.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@
2424
#include "compositor/compositor-private.h"
2525

2626
#define META_TYPE_COMPOSITOR_SERVER (meta_compositor_server_get_type ())
27-
G_DECLARE_FINAL_TYPE (MetaCompositorServer, meta_compositor_server,
28-
META, COMPOSITOR_SERVER, MetaCompositor)
27+
G_DECLARE_DERIVABLE_TYPE (MetaCompositorServer, meta_compositor_server,
28+
META, COMPOSITOR_SERVER, MetaCompositor)
29+
30+
struct _MetaCompositorServerClass
31+
{
32+
MetaCompositorClass parent_class;
33+
};
2934

3035
MetaCompositorServer * meta_compositor_server_new (MetaDisplay *display);
3136

src/compositor/meta-surface-actor-wayland.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ meta_surface_actor_wayland_is_opaque (MetaSurfaceActor *actor)
7171
return meta_shaped_texture_is_opaque (stex);
7272
}
7373

74+
CoglScanout *
75+
meta_surface_actor_wayland_try_acquire_scanout (MetaSurfaceActorWayland *self,
76+
CoglOnscreen *onscreen)
77+
{
78+
MetaWaylandSurface *surface;
79+
CoglScanout *scanout;
80+
81+
surface = meta_surface_actor_wayland_get_surface (self);
82+
scanout = meta_wayland_surface_try_acquire_scanout (surface, onscreen);
83+
if (!scanout)
84+
return NULL;
85+
86+
return scanout;
87+
}
88+
7489
static void
7590
meta_surface_actor_wayland_dispose (GObject *object)
7691
{

src/compositor/meta-surface-actor-wayland.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ void meta_surface_actor_wayland_get_subsurface_rect (MetaSurfaceActorWayland *se
5252
void meta_surface_actor_wayland_add_frame_callbacks (MetaSurfaceActorWayland *self,
5353
struct wl_list *frame_callbacks);
5454

55+
CoglScanout * meta_surface_actor_wayland_try_acquire_scanout (MetaSurfaceActorWayland *self,
56+
CoglOnscreen *onscreen);
57+
5558
G_END_DECLS
5659

5760
#endif /* __META_SURFACE_ACTOR_WAYLAND_H__ */
61+

src/core/display.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "backends/x11/meta-backend-x11.h"
5252
#include "backends/x11/meta-event-x11.h"
5353
#include "backends/x11/cm/meta-backend-x11-cm.h"
54+
#include "backends/x11/nested/meta-backend-x11-nested.h"
5455
#include "clutter/x11/clutter-x11.h"
5556
#include "compositor/compositor-private.h"
5657
#include "compositor/meta-compositor-x11.h"
@@ -81,6 +82,7 @@
8182
#include "x11/xprops.h"
8283

8384
#ifdef HAVE_WAYLAND
85+
#include "compositor/meta-compositor-native.h"
8486
#include "compositor/meta-compositor-server.h"
8587
#include "wayland/meta-xwayland-private.h"
8688
#include "wayland/meta-wayland-tablet-seat.h"
@@ -620,11 +622,16 @@ static MetaCompositor *
620622
create_compositor (MetaDisplay *display)
621623
{
622624
#ifdef HAVE_WAYLAND
623-
if (meta_is_wayland_compositor ())
625+
MetaBackend *backend = meta_get_backend ();
626+
627+
#ifdef HAVE_NATIVE_BACKEND
628+
if (META_IS_BACKEND_NATIVE (backend))
629+
return META_COMPOSITOR (meta_compositor_native_new (display));
630+
#endif
631+
if (META_IS_BACKEND_X11_NESTED (backend))
624632
return META_COMPOSITOR (meta_compositor_server_new (display));
625-
else
626633
#endif
627-
return META_COMPOSITOR (meta_compositor_x11_new (display));
634+
return META_COMPOSITOR (meta_compositor_x11_new (display));
628635
}
629636

630637
static void

src/meson.build

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ muffin_sources = [
290290
'compositor/meta-background-group.c',
291291
'compositor/meta-background-image.c',
292292
'compositor/meta-background-private.h',
293+
'compositor/meta-compositor-server.c',
294+
'compositor/meta-compositor-server.h',
293295
'compositor/meta-compositor-x11.c',
294296
'compositor/meta-compositor-x11.h',
295297
'compositor/meta-cullable.c',
@@ -480,8 +482,6 @@ if have_wayland
480482
'compositor/meta-surface-actor-wayland.h',
481483
'compositor/meta-window-actor-wayland.c',
482484
'compositor/meta-window-actor-wayland.h',
483-
'compositor/meta-compositor-server.c',
484-
'compositor/meta-compositor-server.h',
485485
'wayland/meta-cursor-sprite-wayland.c',
486486
'wayland/meta-cursor-sprite-wayland.h',
487487
'wayland/meta-pointer-confinement-wayland.c',
@@ -691,6 +691,8 @@ if have_native_backend
691691
'backends/native/meta-virtual-input-device-native.h',
692692
'backends/native/meta-xkb-utils.c',
693693
'backends/native/meta-xkb-utils.h',
694+
'compositor/meta-compositor-native.c',
695+
'compositor/meta-compositor-native.h',
694696
]
695697
endif
696698

0 commit comments

Comments
 (0)