2010-06-17 17:26:12 -04:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
2011-05-08 19:27:10 -04:00
|
|
|
* Copyright (C) 2010,2011 Intel Corporation.
|
2010-06-17 17:26:12 -04:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
* Authors:
|
|
|
|
* Matthew Allum
|
|
|
|
* Emmanuele Bassi
|
|
|
|
* Robert Bragg
|
|
|
|
* Neil Roberts
|
|
|
|
*/
|
|
|
|
|
2007-10-12 04:17:00 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-07-06 09:56:01 -04:00
|
|
|
#include "config.h"
|
2007-10-12 04:17:00 -04:00
|
|
|
#endif
|
2007-07-06 09:56:01 -04:00
|
|
|
|
2010-03-01 06:38:41 -05:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2010-06-17 17:26:12 -04:00
|
|
|
#include <unistd.h>
|
2010-03-01 06:38:41 -05:00
|
|
|
|
2010-03-03 10:31:01 -05:00
|
|
|
#include <errno.h>
|
|
|
|
|
2011-05-08 19:27:10 -04:00
|
|
|
#include "clutter-backend-cogl.h"
|
|
|
|
#include "clutter-stage-cogl.h"
|
2010-03-01 06:38:41 -05:00
|
|
|
|
2010-10-21 06:29:09 -04:00
|
|
|
#include "clutter-debug.h"
|
|
|
|
#include "clutter-private.h"
|
|
|
|
#include "clutter-main.h"
|
|
|
|
#include "clutter-stage-private.h"
|
2011-05-08 19:27:10 -04:00
|
|
|
|
|
|
|
static ClutterBackendCogl *backend_singleton = NULL;
|
2007-07-06 09:56:01 -04:00
|
|
|
|
2011-02-24 19:31:41 -05:00
|
|
|
static gchar *clutter_vblank = NULL;
|
2010-03-01 06:38:41 -05:00
|
|
|
|
2011-05-08 19:27:10 -04:00
|
|
|
G_DEFINE_TYPE (ClutterBackendCogl, _clutter_backend_cogl, CLUTTER_TYPE_BACKEND);
|
2007-07-06 09:56:01 -04:00
|
|
|
|
Eliminate G_CONST_RETURN
The G_CONST_RETURN define in GLib is, and has always been, a bit fuzzy.
We always used it to conform to the platform, at least for public-facing
API.
At first I assumed it has something to do with brain-damaged compilers
or with weird platforms where const was not really supported; sadly,
it's something much, much worse: it's a define that can be toggled at
compile-time to remove const from the signature of public API. This is a
truly terrifying feature that I assume was added in the past century,
and whose inception clearly had something to do with massive doses of
absynthe and opium — because any other explanation would make the
existence of such a feature even worse than assuming drugs had anything
to do with it.
Anyway, and pleasing the gods, this dubious feature is being
removed/deprecated in GLib; see bug:
https://bugzilla.gnome.org/show_bug.cgi?id=644611
Before deprecation, though, we should just remove its usage from the
whole API. We should especially remove its usage from Cally's internals,
since there it never made sense in the first place.
2011-06-07 10:49:20 -04:00
|
|
|
const gchar*
|
2011-05-08 19:27:10 -04:00
|
|
|
_clutter_backend_cogl_get_vblank (void)
|
2011-02-24 19:31:41 -05:00
|
|
|
{
|
|
|
|
if (clutter_vblank && strcmp (clutter_vblank, "0") == 0)
|
|
|
|
return "none";
|
|
|
|
else
|
|
|
|
return clutter_vblank;
|
|
|
|
}
|
|
|
|
|
2007-07-06 09:56:01 -04:00
|
|
|
static gboolean
|
2011-05-08 19:27:10 -04:00
|
|
|
clutter_backend_cogl_pre_parse (ClutterBackend *backend,
|
|
|
|
GError **error)
|
2007-07-06 09:56:01 -04:00
|
|
|
{
|
2010-03-01 06:38:41 -05:00
|
|
|
const gchar *env_string;
|
|
|
|
|
2010-11-16 08:54:15 -05:00
|
|
|
env_string = g_getenv ("CLUTTER_VBLANK");
|
|
|
|
if (env_string)
|
|
|
|
{
|
2011-02-24 19:31:41 -05:00
|
|
|
clutter_vblank = g_strdup (env_string);
|
2010-11-16 08:54:15 -05:00
|
|
|
env_string = NULL;
|
|
|
|
}
|
|
|
|
|
2007-07-06 09:56:01 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-05-08 19:27:10 -04:00
|
|
|
clutter_backend_cogl_post_parse (ClutterBackend *backend,
|
|
|
|
GError **error)
|
2007-07-06 09:56:01 -04:00
|
|
|
{
|
|
|
|
return TRUE;
|
2010-11-04 10:38:32 -04:00
|
|
|
}
|
2007-07-06 09:56:01 -04:00
|
|
|
|
|
|
|
static void
|
2011-05-08 19:27:10 -04:00
|
|
|
clutter_backend_cogl_finalize (GObject *gobject)
|
2007-07-06 09:56:01 -04:00
|
|
|
{
|
|
|
|
if (backend_singleton)
|
|
|
|
backend_singleton = NULL;
|
|
|
|
|
2011-05-08 19:27:10 -04:00
|
|
|
G_OBJECT_CLASS (_clutter_backend_cogl_parent_class)->finalize (gobject);
|
2007-07-06 09:56:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-08 19:27:10 -04:00
|
|
|
clutter_backend_cogl_dispose (GObject *gobject)
|
2007-07-06 09:56:01 -04:00
|
|
|
{
|
2011-02-24 19:31:41 -05:00
|
|
|
ClutterBackend *backend = CLUTTER_BACKEND (gobject);
|
2007-07-06 09:56:01 -04:00
|
|
|
|
2011-02-24 19:31:41 -05:00
|
|
|
if (backend->cogl_context)
|
2010-03-01 06:38:41 -05:00
|
|
|
{
|
2011-02-24 19:31:41 -05:00
|
|
|
cogl_object_unref (backend->cogl_context);
|
|
|
|
backend->cogl_context = NULL;
|
2007-10-09 09:56:29 -04:00
|
|
|
}
|
|
|
|
|
2011-08-26 18:16:12 -04:00
|
|
|
G_OBJECT_CLASS (_clutter_backend_cogl_parent_class)->dispose (gobject);
|
2007-07-06 09:56:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static GObject *
|
2011-05-08 19:27:10 -04:00
|
|
|
clutter_backend_cogl_constructor (GType gtype,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
2007-07-06 09:56:01 -04:00
|
|
|
{
|
|
|
|
GObjectClass *parent_class;
|
|
|
|
GObject *retval;
|
|
|
|
|
2011-08-26 18:16:12 -04:00
|
|
|
if (backend_singleton == NULL)
|
2007-07-06 09:56:01 -04:00
|
|
|
{
|
2011-05-08 19:27:10 -04:00
|
|
|
parent_class = G_OBJECT_CLASS (_clutter_backend_cogl_parent_class);
|
2007-07-06 09:56:01 -04:00
|
|
|
retval = parent_class->constructor (gtype, n_params, params);
|
|
|
|
|
2011-05-08 19:27:10 -04:00
|
|
|
backend_singleton = CLUTTER_BACKEND_COGL (retval);
|
2007-07-06 09:56:01 -04:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_warning ("Attempting to create a new backend object. This should "
|
|
|
|
"never happen, so we return the singleton instance.");
|
2010-06-17 17:26:12 -04:00
|
|
|
|
2007-07-06 09:56:01 -04:00
|
|
|
return g_object_ref (backend_singleton);
|
|
|
|
}
|
|
|
|
|
2007-07-26 16:08:09 -04:00
|
|
|
static ClutterFeatureFlags
|
2011-05-08 19:27:10 -04:00
|
|
|
clutter_backend_cogl_get_features (ClutterBackend *backend)
|
2007-07-26 16:08:09 -04:00
|
|
|
{
|
2011-05-08 19:27:10 -04:00
|
|
|
ClutterBackendCogl *backend_cogl = CLUTTER_BACKEND_COGL (backend);
|
2011-02-24 19:31:41 -05:00
|
|
|
ClutterFeatureFlags flags = 0;
|
2010-02-27 04:42:42 -05:00
|
|
|
|
2011-02-24 19:31:41 -05:00
|
|
|
if (cogl_clutter_winsys_has_feature (COGL_WINSYS_FEATURE_MULTIPLE_ONSCREEN))
|
|
|
|
{
|
|
|
|
CLUTTER_NOTE (BACKEND, "Cogl supports multiple onscreen framebuffers");
|
|
|
|
flags |= CLUTTER_FEATURE_STAGE_MULTIPLE;
|
|
|
|
}
|
2010-11-16 08:54:15 -05:00
|
|
|
else
|
2011-02-24 19:31:41 -05:00
|
|
|
{
|
|
|
|
CLUTTER_NOTE (BACKEND, "Cogl only supports one onscreen framebuffer");
|
|
|
|
flags |= CLUTTER_FEATURE_STAGE_STATIC;
|
|
|
|
}
|
2010-11-16 08:54:15 -05:00
|
|
|
|
2011-02-24 19:31:41 -05:00
|
|
|
if (cogl_clutter_winsys_has_feature (COGL_WINSYS_FEATURE_SWAP_THROTTLE))
|
2010-11-16 08:54:15 -05:00
|
|
|
{
|
2011-02-24 19:31:41 -05:00
|
|
|
CLUTTER_NOTE (BACKEND, "Cogl supports swap buffers throttling");
|
|
|
|
flags |= CLUTTER_FEATURE_SYNC_TO_VBLANK;
|
2010-11-16 08:54:15 -05:00
|
|
|
}
|
2011-02-24 19:31:41 -05:00
|
|
|
else
|
|
|
|
CLUTTER_NOTE (BACKEND, "Cogl doesn't support swap buffers throttling");
|
2010-11-16 08:54:15 -05:00
|
|
|
|
2011-02-24 19:31:41 -05:00
|
|
|
if (cogl_clutter_winsys_has_feature (COGL_WINSYS_FEATURE_SWAP_BUFFERS_EVENT))
|
|
|
|
{
|
|
|
|
CLUTTER_NOTE (BACKEND, "Cogl supports swap buffers complete events");
|
|
|
|
flags |= CLUTTER_FEATURE_SWAP_EVENTS;
|
|
|
|
}
|
2010-11-16 08:54:15 -05:00
|
|
|
|
2011-02-24 19:31:41 -05:00
|
|
|
if (cogl_clutter_winsys_has_feature (COGL_WINSYS_FEATURE_SWAP_REGION))
|
2010-11-16 08:54:15 -05:00
|
|
|
{
|
2011-02-24 19:31:41 -05:00
|
|
|
CLUTTER_NOTE (BACKEND, "Cogl supports swapping buffer regions");
|
2011-05-08 19:27:10 -04:00
|
|
|
backend_cogl->can_blit_sub_buffer = TRUE;
|
2010-11-16 08:54:15 -05:00
|
|
|
}
|
2011-02-24 19:31:41 -05:00
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2007-07-06 09:56:01 -04:00
|
|
|
static void
|
2011-05-08 19:27:10 -04:00
|
|
|
_clutter_backend_cogl_class_init (ClutterBackendCoglClass *klass)
|
2007-07-06 09:56:01 -04:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterBackendClass *backend_class = CLUTTER_BACKEND_CLASS (klass);
|
|
|
|
|
2011-05-08 19:27:10 -04:00
|
|
|
gobject_class->constructor = clutter_backend_cogl_constructor;
|
2011-10-03 07:25:53 -04:00
|
|
|
gobject_class->dispose = clutter_backend_cogl_dispose;
|
|
|
|
gobject_class->finalize = clutter_backend_cogl_finalize;
|
2007-07-06 09:56:01 -04:00
|
|
|
|
2011-10-03 07:25:53 -04:00
|
|
|
backend_class->pre_parse = clutter_backend_cogl_pre_parse;
|
|
|
|
backend_class->post_parse = clutter_backend_cogl_post_parse;
|
|
|
|
backend_class->get_features = clutter_backend_cogl_get_features;
|
2007-07-06 09:56:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-08 19:27:10 -04:00
|
|
|
_clutter_backend_cogl_init (ClutterBackendCogl *backend_cogl)
|
2007-07-06 09:56:01 -04:00
|
|
|
{
|
2011-02-24 19:31:41 -05:00
|
|
|
}
|