2006-07-24 21:15:19 +00:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Authored By Matthew Allum <mallum@openedhand.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 OpenedHand
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2010-03-01 12:56:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2006-07-24 21:15:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:clutter-feature
|
2010-01-15 17:06:56 +00:00
|
|
|
* @short_description: Run-time detection of Clutter features
|
2006-07-24 21:15:19 +00:00
|
|
|
*
|
2010-01-15 17:06:56 +00:00
|
|
|
* Parts of Clutter depend on the underlying platform, including the
|
|
|
|
* capabilities of the backend used and the OpenGL features exposed through the
|
|
|
|
* Clutter and COGL API.
|
|
|
|
*
|
|
|
|
* It is possible to ask whether Clutter has support for specific features at
|
|
|
|
* run-time.
|
2006-07-24 21:15:19 +00:00
|
|
|
*/
|
|
|
|
|
2016-05-05 22:21:51 +08:00
|
|
|
#include "clutter-build-config.h"
|
2006-07-24 21:15:19 +00:00
|
|
|
|
2006-11-15 21:19:01 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
2006-11-21 Emmanuele Bassi <ebassi@openedhand.com>
* configure.ac: Enable debug messages also when
--enable-debug is set to "minimum".
* clutter/Makefile.am:
* clutter/clutter-debug.h: Move all debugging macros inside
this private header; make all debug macros depend on the
CLUTTER_ENABLE_DEBUG compile time define, controlled by
the --enable-debug configure switch; add G_LOG_DOMAIN define.
* clutter/clutter-main.c: Clean up the debug stuff; add
command line argument parsing using GOption; the debug
messages now are triggered like this:
CLUTTER_DEBUG=section:section:... clutter-app
or like this:
clutter-app --clutter-debug=section:section:...
where "section" is one of the sections listed in clutter-main.c,
or "all", for all sections; each section is bound to a flag,
which can be used to define a domain when adding a debug note
using the CLUTTER_NOTE() macro; the old CLUTTER_DBG() macro is
just a wrapper around that, under the CLUTTER_DEBUG_MISC domain;
CLUTTER_NOTE() is used like this:
CLUTTER_NOTE (DOMAIN, log-function);
where log function is g_printerr(), g_message(), g_warning(),
g_critical() or directly g_log() - for instance:
CLUTTER_NOTE (PANGO, g_warning ("Cache miss: %d", glyph));
will print the warning only if the "pango" flag has been
set to the CLUTTER_DEBUG envvar or passed to the --clutter-debug
command line argument.
similar to CLUTTER_SHOW_FPS, there's also the --clutter-show-fps
command line switch; also, the --display and --screen command
line switches have been added: the first overrides the DISPLAY
envvar and the second controls the X screen used by Clutter to
get the root window on the display.
* clutter/clutter-main.h:
* clutter/clutter-main.c: Add extended support for GOption
in Clutter; use clutter_init_with_args() to let Clutter
parse your own command line arguments; use instead
clutter_get_option_group() to get the GOptionGroup used by
Clutter if you want to do the parsing yourself with
g_option_context_parse(). The init sequence has been verified,
updated and moved into common functions where possible.
* clutter/pango/pangoclutter-render.c:
* clutter/*.c: Include "clutter-debug.h" where needed; use
CLUTTER_NOTE() instead of CLUTTER_DBG().
* examples/super-oh.c: Use the new clutter_init_with_args()
function, and add a --num-hands command line switch to
the SuperOH example code controlling the number of hands at
runtime.
2006-11-21 21:27:53 +00:00
|
|
|
|
2010-10-21 11:49:37 +01:00
|
|
|
#include "clutter-backend-private.h"
|
2006-11-21 Emmanuele Bassi <ebassi@openedhand.com>
* configure.ac: Enable debug messages also when
--enable-debug is set to "minimum".
* clutter/Makefile.am:
* clutter/clutter-debug.h: Move all debugging macros inside
this private header; make all debug macros depend on the
CLUTTER_ENABLE_DEBUG compile time define, controlled by
the --enable-debug configure switch; add G_LOG_DOMAIN define.
* clutter/clutter-main.c: Clean up the debug stuff; add
command line argument parsing using GOption; the debug
messages now are triggered like this:
CLUTTER_DEBUG=section:section:... clutter-app
or like this:
clutter-app --clutter-debug=section:section:...
where "section" is one of the sections listed in clutter-main.c,
or "all", for all sections; each section is bound to a flag,
which can be used to define a domain when adding a debug note
using the CLUTTER_NOTE() macro; the old CLUTTER_DBG() macro is
just a wrapper around that, under the CLUTTER_DEBUG_MISC domain;
CLUTTER_NOTE() is used like this:
CLUTTER_NOTE (DOMAIN, log-function);
where log function is g_printerr(), g_message(), g_warning(),
g_critical() or directly g_log() - for instance:
CLUTTER_NOTE (PANGO, g_warning ("Cache miss: %d", glyph));
will print the warning only if the "pango" flag has been
set to the CLUTTER_DEBUG envvar or passed to the --clutter-debug
command line argument.
similar to CLUTTER_SHOW_FPS, there's also the --clutter-show-fps
command line switch; also, the --display and --screen command
line switches have been added: the first overrides the DISPLAY
envvar and the second controls the X screen used by Clutter to
get the root window on the display.
* clutter/clutter-main.h:
* clutter/clutter-main.c: Add extended support for GOption
in Clutter; use clutter_init_with_args() to let Clutter
parse your own command line arguments; use instead
clutter_get_option_group() to get the GOptionGroup used by
Clutter if you want to do the parsing yourself with
g_option_context_parse(). The init sequence has been verified,
updated and moved into common functions where possible.
* clutter/pango/pangoclutter-render.c:
* clutter/*.c: Include "clutter-debug.h" where needed; use
CLUTTER_NOTE() instead of CLUTTER_DBG().
* examples/super-oh.c: Use the new clutter_init_with_args()
function, and add a --num-hands command line switch to
the SuperOH example code controlling the number of hands at
runtime.
2006-11-21 21:27:53 +00:00
|
|
|
#include "clutter-feature.h"
|
|
|
|
#include "clutter-main.h"
|
|
|
|
#include "clutter-private.h"
|
|
|
|
#include "clutter-debug.h"
|
2006-11-15 21:19:01 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
#include "cogl/cogl.h"
|
2006-11-15 21:19:01 +00:00
|
|
|
|
|
|
|
typedef struct ClutterFeatures
|
|
|
|
{
|
|
|
|
ClutterFeatureFlags flags;
|
2006-12-04 19:19:53 +00:00
|
|
|
guint features_set : 1;
|
2006-11-15 21:19:01 +00:00
|
|
|
} ClutterFeatures;
|
|
|
|
|
|
|
|
static ClutterFeatures* __features = NULL;
|
|
|
|
|
2012-03-07 12:34:06 +00:00
|
|
|
static ClutterFeatureFlags
|
2019-10-17 21:51:05 -04:00
|
|
|
clutter_features_from_cogl (void)
|
2008-04-25 13:37:36 +00:00
|
|
|
{
|
|
|
|
ClutterFeatureFlags clutter_flags = 0;
|
|
|
|
|
2019-03-08 15:40:41 -05:00
|
|
|
clutter_flags |= CLUTTER_FEATURE_SHADERS_GLSL;
|
2008-04-25 13:37:36 +00:00
|
|
|
|
|
|
|
return clutter_flags;
|
|
|
|
}
|
|
|
|
|
2010-03-17 17:28:20 +00:00
|
|
|
gboolean
|
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-09-16 11:38:49 +02:00
|
|
|
clutter_feature_init (ClutterMainContext *context,
|
|
|
|
GError **error)
|
2006-07-24 21:15:19 +00:00
|
|
|
{
|
2006-12-04 19:19:53 +00:00
|
|
|
CLUTTER_NOTE (MISC, "checking features");
|
2006-11-15 21:19:01 +00:00
|
|
|
|
2006-12-04 19:19:53 +00:00
|
|
|
if (!__features)
|
2006-07-27 17:10:33 +00:00
|
|
|
{
|
2006-12-04 19:19:53 +00:00
|
|
|
CLUTTER_NOTE (MISC, "allocating features data");
|
|
|
|
__features = g_new0 (ClutterFeatures, 1);
|
|
|
|
__features->features_set = FALSE; /* don't rely on zero-ing */
|
2006-07-27 17:10:33 +00:00
|
|
|
}
|
2006-07-24 21:15:19 +00:00
|
|
|
|
2006-12-04 19:19:53 +00:00
|
|
|
if (__features->features_set)
|
2010-03-17 17:28:20 +00:00
|
|
|
return TRUE;
|
2006-11-15 21:19:01 +00:00
|
|
|
|
2009-12-03 20:48:55 +00:00
|
|
|
/* makes sure we have a GL context; if we have, this is a no-op */
|
2010-03-17 17:28:20 +00:00
|
|
|
if (!_clutter_backend_create_context (context->backend, error))
|
|
|
|
return FALSE;
|
2009-12-03 20:48:55 +00:00
|
|
|
|
2021-09-17 11:41:16 +02:00
|
|
|
__features->flags = clutter_features_from_cogl ();
|
2006-12-04 19:19:53 +00:00
|
|
|
|
|
|
|
__features->features_set = TRUE;
|
|
|
|
|
2007-05-16 09:08:30 +00:00
|
|
|
CLUTTER_NOTE (MISC, "features checked");
|
2010-03-17 17:28:20 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2006-07-27 16:09:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_feature_available:
|
|
|
|
* @feature: a #ClutterFeatureFlags
|
|
|
|
*
|
|
|
|
* Checks whether @feature is available. @feature can be a logical
|
|
|
|
* OR of #ClutterFeatureFlags.
|
2007-10-12 08:17:00 +00:00
|
|
|
*
|
2006-07-27 16:09:25 +00:00
|
|
|
* Return value: %TRUE if a feature is available
|
|
|
|
*
|
2015-03-03 15:53:04 +00:00
|
|
|
* Since: 0.2
|
2006-07-27 16:09:25 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
clutter_feature_available (ClutterFeatureFlags feature)
|
|
|
|
{
|
2007-05-16 15:00:41 +00:00
|
|
|
if (G_UNLIKELY (!__features))
|
2010-03-18 14:15:33 +00:00
|
|
|
{
|
|
|
|
g_critical ("Unable to check features. Have you initialized Clutter?");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-05-16 15:00:41 +00:00
|
|
|
|
|
|
|
return (__features->flags & feature);
|
2006-07-27 16:09:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-11-15 23:37:53 +00:00
|
|
|
* clutter_feature_get_all:
|
2006-07-27 16:09:25 +00:00
|
|
|
*
|
2006-12-04 19:19:53 +00:00
|
|
|
* Returns all the supported features.
|
2006-07-27 16:09:25 +00:00
|
|
|
*
|
|
|
|
* Return value: a logical OR of all the supported features.
|
|
|
|
*
|
2015-03-03 15:53:04 +00:00
|
|
|
* Since: 0.2
|
2006-07-27 16:09:25 +00:00
|
|
|
*/
|
|
|
|
ClutterFeatureFlags
|
2006-11-15 23:37:53 +00:00
|
|
|
clutter_feature_get_all (void)
|
2006-07-27 16:09:25 +00:00
|
|
|
{
|
2010-03-18 14:15:33 +00:00
|
|
|
if (G_UNLIKELY (!__features))
|
|
|
|
{
|
|
|
|
g_critical ("Unable to check features. Have you initialized Clutter?");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-11-15 21:19:01 +00:00
|
|
|
return __features->flags;
|
|
|
|
}
|
|
|
|
|