mutter/src/backends/x11/meta-clutter-backend-x11.h
Jonas Ådahl 8008f0b7b0 Explicitly create the clutter context and backend
This changes the setup phase of clutter to not be result of calling an
init function that sets up a few global singletons, via global singleton
setup vfuncs.

The way it worked was that mutter first did some initial setup
(connecting to the X11 server), then set a "custom backend" setup vfunc
global, before calling clutter_init().

During the clutter_init() call, the context and backend was setup by
calling the global singleton getters, which implicitly created the
backend and context on-demand.

This has now changed to mutter explicitly creating a `ClutterContext`
(which is actually a `ClutterMainContext`, but with the name shortened to
be consistent with `CoglContext` and `MetaContext`), calling it with a
backend constructor vfunc and user data pointer.

This function now explicitly creates the backend, without having to go
via the previously set global vfunc.

This changes the behavior of some "get_default()" like functions, which
will now fail if called after mutter has shut down, as when it does so,
it now destroys the backends and contexts, not only its own, but the
clutter ones too.

The "ownership" of the clutter backend is also moved to
`ClutterContext`, and MetaBackend is changed to fetch it via the clutter
context.

This also removed the unused option parsing that existed in clutter.

In some places, NULL checks for fetching the clutter context, or
backend, and fetching the cogl context from the clutter backend, had to
be added.

The reason for this is that some code that handles EGL contexts attempts
to restore the cogl EGL context tracking so that the right EGL context
is used by cogl the next time. This makes no sense to do before Cogl and
Clutter are even initialized, which was the case. It wasn't noticed
because the relevant singletons were initialized on demand via their
"getters".

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2002>
2021-10-18 14:36:15 +00:00

98 lines
3.0 KiB
C

/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
* Copyright (C) 2016 Red Hat
*
* 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.
*
* Written by:
* Jonas Ådahl <jadahl@gmail.com>
*/
#ifndef META_CLUTTER_BACKEND_X11_H
#define META_CLUTTER_BACKEND_X11_H
#include <glib-object.h>
#include "backends/meta-backend-types.h"
#include "clutter/clutter-mutter.h"
struct _MetaClutterBackendX11
{
ClutterBackend parent_instance;
Display *xdisplay;
int xscreen_num;
Window xwin_root;
/* event source */
GSList *event_filters;
/* props */
Atom atom_NET_WM_PID;
Atom atom_NET_WM_PING;
Atom atom_NET_WM_STATE;
Atom atom_NET_WM_USER_TIME;
Atom atom_WM_PROTOCOLS;
Atom atom_WM_DELETE_WINDOW;
Atom atom_XEMBED;
Atom atom_XEMBED_INFO;
Atom atom_NET_WM_NAME;
Atom atom_UTF8_STRING;
Time last_event_time;
};
#define META_TYPE_CLUTTER_BACKEND_X11 (meta_clutter_backend_x11_get_type ())
G_DECLARE_FINAL_TYPE (MetaClutterBackendX11, meta_clutter_backend_x11,
META, CLUTTER_BACKEND_X11,
ClutterBackend)
typedef enum
{
META_X11_FILTER_CONTINUE,
META_X11_FILTER_TRANSLATE,
META_X11_FILTER_REMOVE
} MetaX11FilterReturn;
typedef MetaX11FilterReturn (*MetaX11FilterFunc) (XEvent *xev,
ClutterEvent *cev,
gpointer data);
MetaClutterBackendX11 * meta_clutter_backend_x11_new (MetaBackend *backend);
void meta_clutter_x11_trap_x_errors (void);
gint meta_clutter_x11_untrap_x_errors (void);
Display *meta_clutter_x11_get_default_display (void);
int meta_clutter_x11_get_default_screen (void);
Window meta_clutter_x11_get_root_window (void);
void meta_clutter_backend_x11_add_filter (MetaClutterBackendX11 *clutter_backend_x11,
MetaX11FilterFunc func,
gpointer data);
void meta_clutter_backend_x11_remove_filter (MetaClutterBackendX11 *clutter_backend_x11,
MetaX11FilterFunc func,
gpointer data);
void meta_clutter_x11_set_use_stereo_stage (gboolean use_stereo);
gboolean meta_clutter_x11_get_use_stereo_stage (void);
#endif /* META_CLUTTER_BACKEND_X11_H */