|
| 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 | +} |
0 commit comments