2008-03-25 11:42:50 -04:00
|
|
|
/* Clutter.
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
* Authored By Matthew Allum <mallum@openedhand.com>
|
|
|
|
* Copyright (C) 2006-2007 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 07:56:10 -05:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2008-03-25 11:42:50 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include "clutter-backend-win32.h"
|
|
|
|
#include "clutter-stage-win32.h"
|
|
|
|
#include "clutter-win32.h"
|
2010-02-17 13:18:38 -05:00
|
|
|
#include "clutter-device-manager-win32.h"
|
2008-03-25 11:42:50 -04:00
|
|
|
|
2010-10-21 06:29:09 -04:00
|
|
|
#include "clutter-event.h"
|
|
|
|
#include "clutter-main.h"
|
|
|
|
#include "clutter-device-manager-private.h"
|
|
|
|
#include "clutter-debug.h"
|
|
|
|
#include "clutter-private.h"
|
|
|
|
#include "clutter-stage-private.h"
|
2008-03-25 11:42:50 -04:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
#include "cogl/cogl.h"
|
2008-03-25 11:42:50 -04:00
|
|
|
|
|
|
|
G_DEFINE_TYPE (ClutterBackendWin32, clutter_backend_win32,
|
|
|
|
CLUTTER_TYPE_BACKEND);
|
|
|
|
|
2008-06-24 18:07:15 -04:00
|
|
|
typedef int (WINAPI * SwapIntervalProc) (int interval);
|
2008-03-25 11:42:50 -04:00
|
|
|
|
|
|
|
/* singleton object */
|
|
|
|
static ClutterBackendWin32 *backend_singleton = NULL;
|
|
|
|
|
|
|
|
static gchar *clutter_vblank_name = NULL;
|
|
|
|
|
2010-01-15 17:56:37 -05:00
|
|
|
static HINSTANCE clutter_hinst = NULL;
|
|
|
|
|
2010-10-21 12:20:44 -04:00
|
|
|
/* various flags corresponding to pre init setup calls */
|
|
|
|
static gboolean _no_event_retrieval = FALSE;
|
|
|
|
|
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-04-21 11:52:54 -04:00
|
|
|
_clutter_backend_win32_get_vblank (void)
|
|
|
|
{
|
|
|
|
if (clutter_vblank_name && strcmp (clutter_vblank_name, "0") == 0)
|
|
|
|
return "none";
|
|
|
|
else
|
|
|
|
return clutter_vblank_name;
|
|
|
|
}
|
|
|
|
|
2008-03-25 11:42:50 -04:00
|
|
|
gboolean
|
|
|
|
clutter_backend_win32_pre_parse (ClutterBackend *backend,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
const gchar *env_string;
|
|
|
|
|
|
|
|
if ((env_string = g_getenv ("CLUTTER_VBLANK")))
|
|
|
|
clutter_vblank_name = g_strdup (env_string);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_backend_win32_init_events (ClutterBackend *backend)
|
|
|
|
{
|
2010-01-15 06:47:05 -05:00
|
|
|
ClutterBackendWin32 *backend_win32 = CLUTTER_BACKEND_WIN32 (backend);
|
|
|
|
|
2008-03-25 11:42:50 -04:00
|
|
|
CLUTTER_NOTE (EVENT, "initialising the event loop");
|
|
|
|
|
2010-02-17 12:06:25 -05:00
|
|
|
backend_win32->device_manager =
|
|
|
|
g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_WIN32,
|
|
|
|
"backend", backend_win32,
|
|
|
|
NULL);
|
2010-01-15 06:47:05 -05:00
|
|
|
|
2010-10-21 12:20:44 -04:00
|
|
|
if (!_no_event_retrieval)
|
|
|
|
_clutter_backend_win32_events_init (backend);
|
2008-03-25 11:42:50 -04:00
|
|
|
}
|
|
|
|
|
2010-01-15 17:56:37 -05:00
|
|
|
HCURSOR
|
|
|
|
_clutter_backend_win32_get_invisible_cursor (ClutterBackend *backend)
|
|
|
|
{
|
|
|
|
ClutterBackendWin32 *backend_win32 = CLUTTER_BACKEND_WIN32 (backend);
|
|
|
|
|
|
|
|
if (backend_win32->invisible_cursor == NULL)
|
|
|
|
backend_win32->invisible_cursor =
|
|
|
|
LoadCursor (clutter_hinst, MAKEINTRESOURCE (42));
|
|
|
|
|
|
|
|
return backend_win32->invisible_cursor;
|
|
|
|
}
|
|
|
|
|
2008-03-25 11:42:50 -04:00
|
|
|
static const GOptionEntry entries[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"vblank", 0,
|
|
|
|
0,
|
|
|
|
G_OPTION_ARG_STRING, &clutter_vblank_name,
|
|
|
|
"VBlank method to be used (none, default or wgl)", "METHOD"
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
clutter_backend_win32_add_options (ClutterBackend *backend,
|
|
|
|
GOptionGroup *group)
|
|
|
|
{
|
|
|
|
g_option_group_add_entries (group, entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_backend_win32_finalize (GObject *gobject)
|
|
|
|
{
|
|
|
|
backend_singleton = NULL;
|
|
|
|
|
2008-03-30 18:27:27 -04:00
|
|
|
timeEndPeriod (1);
|
|
|
|
|
2008-03-25 11:42:50 -04:00
|
|
|
G_OBJECT_CLASS (clutter_backend_win32_parent_class)->finalize (gobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_backend_win32_dispose (GObject *gobject)
|
|
|
|
{
|
2011-04-21 11:52:54 -04:00
|
|
|
ClutterBackend *backend = CLUTTER_BACKEND (gobject);
|
2008-03-25 11:42:50 -04:00
|
|
|
ClutterBackendWin32 *backend_win32 = CLUTTER_BACKEND_WIN32 (gobject);
|
2008-03-30 12:51:01 -04:00
|
|
|
ClutterStageManager *stage_manager;
|
|
|
|
|
|
|
|
CLUTTER_NOTE (BACKEND, "Disposing the of stages");
|
2009-06-17 12:59:54 -04:00
|
|
|
stage_manager = clutter_stage_manager_get_default ();
|
2008-03-30 12:51:01 -04:00
|
|
|
|
2010-11-01 11:13:12 -04:00
|
|
|
g_object_unref (stage_manager);
|
2008-03-25 11:42:50 -04:00
|
|
|
|
|
|
|
CLUTTER_NOTE (BACKEND, "Removing the event source");
|
|
|
|
_clutter_backend_win32_events_uninit (CLUTTER_BACKEND (backend_win32));
|
|
|
|
|
2011-04-21 11:52:54 -04:00
|
|
|
G_OBJECT_CLASS (clutter_backend_win32_parent_class)->dispose (gobject);
|
2010-01-20 11:41:25 -05:00
|
|
|
|
2011-04-21 11:52:54 -04:00
|
|
|
if (backend->cogl_context)
|
2010-01-20 11:41:25 -05:00
|
|
|
{
|
2011-04-21 11:52:54 -04:00
|
|
|
cogl_object_unref (backend->cogl_context);
|
|
|
|
backend->cogl_context = NULL;
|
2010-01-20 11:41:25 -05:00
|
|
|
}
|
2008-03-25 11:42:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static GObject *
|
|
|
|
clutter_backend_win32_constructor (GType gtype,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
|
|
|
{
|
|
|
|
GObjectClass *parent_class;
|
|
|
|
GObject *retval;
|
|
|
|
|
|
|
|
if (!backend_singleton)
|
|
|
|
{
|
|
|
|
parent_class = G_OBJECT_CLASS (clutter_backend_win32_parent_class);
|
|
|
|
retval = parent_class->constructor (gtype, n_params, params);
|
|
|
|
|
|
|
|
backend_singleton = CLUTTER_BACKEND_WIN32 (retval);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_warning ("Attempting to create a new backend object. This should "
|
|
|
|
"never happen, so we return the singleton instance.");
|
|
|
|
|
|
|
|
return g_object_ref (backend_singleton);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClutterFeatureFlags
|
|
|
|
clutter_backend_win32_get_features (ClutterBackend *backend)
|
|
|
|
{
|
2011-04-21 11:52:54 -04:00
|
|
|
ClutterBackendClass *parent_class;
|
|
|
|
ClutterFeatureFlags flags;
|
2010-01-20 11:41:25 -05:00
|
|
|
|
2011-04-21 11:52:54 -04:00
|
|
|
parent_class = CLUTTER_BACKEND_CLASS (clutter_backend_win32_parent_class);
|
2008-03-25 11:42:50 -04:00
|
|
|
|
2011-04-21 11:52:54 -04:00
|
|
|
flags = CLUTTER_FEATURE_STAGE_USER_RESIZE | CLUTTER_FEATURE_STAGE_CURSOR;
|
2010-01-20 11:41:25 -05:00
|
|
|
|
2011-04-21 11:52:54 -04:00
|
|
|
if (cogl_clutter_winsys_has_feature (COGL_WINSYS_FEATURE_MULTIPLE_ONSCREEN))
|
2010-01-20 11:41:25 -05:00
|
|
|
{
|
2011-04-21 11:52:54 -04:00
|
|
|
CLUTTER_NOTE (BACKEND, "Cogl supports multiple onscreen framebuffers");
|
|
|
|
flags |= CLUTTER_FEATURE_STAGE_MULTIPLE;
|
2010-01-20 11:41:25 -05:00
|
|
|
}
|
2011-04-21 11:52:54 -04:00
|
|
|
else
|
2010-01-20 11:41:25 -05:00
|
|
|
{
|
2011-04-21 11:52:54 -04:00
|
|
|
CLUTTER_NOTE (BACKEND, "Cogl only supports one onscreen framebuffer");
|
|
|
|
flags |= CLUTTER_FEATURE_STAGE_STATIC;
|
2010-01-20 11:41:25 -05:00
|
|
|
}
|
|
|
|
|
2011-04-21 11:52:54 -04:00
|
|
|
if (cogl_clutter_winsys_has_feature (COGL_WINSYS_FEATURE_SWAP_THROTTLE))
|
2010-01-20 11:41:25 -05:00
|
|
|
{
|
2011-04-21 11:52:54 -04:00
|
|
|
CLUTTER_NOTE (BACKEND, "Cogl supports swap buffers throttling");
|
|
|
|
flags |= CLUTTER_FEATURE_SYNC_TO_VBLANK;
|
2010-01-20 11:41:25 -05:00
|
|
|
}
|
2011-04-21 11:52:54 -04:00
|
|
|
else
|
|
|
|
CLUTTER_NOTE (BACKEND, "Cogl doesn't support swap buffers throttling");
|
2010-01-20 11:41:25 -05:00
|
|
|
|
2011-04-21 11:52:54 -04:00
|
|
|
CLUTTER_NOTE (BACKEND, "backend features checked");
|
2010-01-20 11:41:25 -05:00
|
|
|
|
2011-04-21 11:52:54 -04:00
|
|
|
return flags;
|
2010-01-20 11:41:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_backend_win32_create_context (ClutterBackend *backend,
|
|
|
|
GError **error)
|
|
|
|
{
|
2011-04-21 11:52:54 -04:00
|
|
|
CoglSwapChain *swap_chain;
|
|
|
|
CoglOnscreenTemplate *onscreen_template;
|
2010-01-20 11:41:25 -05:00
|
|
|
|
2011-04-21 11:52:54 -04:00
|
|
|
if (backend->cogl_context)
|
|
|
|
return TRUE;
|
2010-01-20 11:41:25 -05:00
|
|
|
|
2011-04-21 11:52:54 -04:00
|
|
|
backend->cogl_renderer = cogl_renderer_new ();
|
|
|
|
if (!cogl_renderer_connect (backend->cogl_renderer, error))
|
|
|
|
goto error;
|
2010-01-20 11:41:25 -05:00
|
|
|
|
2011-04-21 11:52:54 -04:00
|
|
|
swap_chain = cogl_swap_chain_new ();
|
2010-01-20 11:41:25 -05:00
|
|
|
|
2011-04-21 11:52:54 -04:00
|
|
|
onscreen_template = cogl_onscreen_template_new (swap_chain);
|
|
|
|
cogl_object_unref (swap_chain);
|
2010-01-20 11:41:25 -05:00
|
|
|
|
2011-04-21 11:52:54 -04:00
|
|
|
if (!cogl_renderer_check_onscreen_template (backend->cogl_renderer,
|
|
|
|
onscreen_template,
|
|
|
|
error))
|
|
|
|
goto error;
|
2010-01-20 11:41:25 -05:00
|
|
|
|
2011-04-21 11:52:54 -04:00
|
|
|
backend->cogl_display = cogl_display_new (backend->cogl_renderer,
|
|
|
|
onscreen_template);
|
|
|
|
cogl_object_unref (backend->cogl_renderer);
|
|
|
|
cogl_object_unref (onscreen_template);
|
2010-01-20 11:41:25 -05:00
|
|
|
|
2011-04-21 11:52:54 -04:00
|
|
|
if (!cogl_display_setup (backend->cogl_display, error))
|
|
|
|
goto error;
|
2010-01-20 11:41:25 -05:00
|
|
|
|
2011-04-21 11:52:54 -04:00
|
|
|
backend->cogl_context = cogl_context_new (backend->cogl_display, error);
|
|
|
|
if (!backend->cogl_context)
|
|
|
|
goto error;
|
2010-01-20 11:41:25 -05:00
|
|
|
|
|
|
|
return TRUE;
|
2011-04-21 11:52:54 -04:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (backend->cogl_display)
|
|
|
|
{
|
|
|
|
cogl_object_unref (backend->cogl_display);
|
|
|
|
backend->cogl_display = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (onscreen_template)
|
|
|
|
cogl_object_unref (onscreen_template);
|
|
|
|
if (swap_chain)
|
|
|
|
cogl_object_unref (swap_chain);
|
|
|
|
|
|
|
|
if (backend->cogl_renderer)
|
|
|
|
{
|
|
|
|
cogl_object_unref (backend->cogl_renderer);
|
|
|
|
backend->cogl_renderer = NULL;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2010-01-20 11:41:25 -05:00
|
|
|
}
|
|
|
|
|
2009-10-26 11:28:36 -04:00
|
|
|
static ClutterStageWindow *
|
2008-03-30 12:51:01 -04:00
|
|
|
clutter_backend_win32_create_stage (ClutterBackend *backend,
|
2008-04-13 04:43:32 -04:00
|
|
|
ClutterStage *wrapper,
|
2008-03-30 12:51:01 -04:00
|
|
|
GError **error)
|
2008-03-25 11:42:50 -04:00
|
|
|
{
|
|
|
|
ClutterBackendWin32 *backend_win32 = CLUTTER_BACKEND_WIN32 (backend);
|
2008-03-30 12:51:01 -04:00
|
|
|
ClutterStageWin32 *stage_win32;
|
2009-10-26 11:28:36 -04:00
|
|
|
ClutterStageWindow *stage;
|
2008-03-25 11:42:50 -04:00
|
|
|
|
2008-05-15 18:03:22 -04:00
|
|
|
stage = g_object_new (CLUTTER_TYPE_STAGE_WIN32, NULL);
|
2008-03-25 11:42:50 -04:00
|
|
|
|
2008-03-30 12:51:01 -04:00
|
|
|
/* copy backend data into the stage */
|
|
|
|
stage_win32 = CLUTTER_STAGE_WIN32 (stage);
|
|
|
|
stage_win32->backend = backend_win32;
|
2008-04-13 04:43:32 -04:00
|
|
|
stage_win32->wrapper = wrapper;
|
|
|
|
|
2008-03-30 12:51:01 -04:00
|
|
|
return stage;
|
2008-03-25 11:42:50 -04:00
|
|
|
}
|
|
|
|
|
2010-02-17 12:06:25 -05:00
|
|
|
static ClutterDeviceManager *
|
|
|
|
clutter_backend_win32_get_device_manager (ClutterBackend *backend)
|
|
|
|
{
|
|
|
|
ClutterBackendWin32 *backend_win32 = CLUTTER_BACKEND_WIN32 (backend);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (backend_win32->device_manager == NULL))
|
|
|
|
{
|
|
|
|
backend_win32->device_manager =
|
|
|
|
g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_WIN32,
|
|
|
|
"backend", backend_win32,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return backend_win32->device_manager;
|
|
|
|
}
|
|
|
|
|
2010-10-21 12:20:44 -04:00
|
|
|
/**
|
|
|
|
* clutter_win32_disable_event_retrieval
|
|
|
|
*
|
|
|
|
* Disables retrieval of Windows messages in the main loop. Use to
|
|
|
|
* create event-less canvas.
|
|
|
|
*
|
|
|
|
* This function can only be called before calling clutter_init().
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_win32_disable_event_retrieval (void)
|
|
|
|
{
|
|
|
|
if (_clutter_context_is_initialized ())
|
|
|
|
{
|
|
|
|
g_warning ("clutter_win32_disable_event_retrieval() can only be "
|
|
|
|
"called before clutter_init()");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_no_event_retrieval = TRUE;
|
|
|
|
}
|
|
|
|
|
2008-03-25 11:42:50 -04:00
|
|
|
static void
|
|
|
|
clutter_backend_win32_class_init (ClutterBackendWin32Class *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterBackendClass *backend_class = CLUTTER_BACKEND_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->constructor = clutter_backend_win32_constructor;
|
|
|
|
gobject_class->dispose = clutter_backend_win32_dispose;
|
|
|
|
gobject_class->finalize = clutter_backend_win32_finalize;
|
|
|
|
|
2008-06-25 12:51:43 -04:00
|
|
|
backend_class->pre_parse = clutter_backend_win32_pre_parse;
|
|
|
|
backend_class->init_events = clutter_backend_win32_init_events;
|
|
|
|
backend_class->create_stage = clutter_backend_win32_create_stage;
|
|
|
|
backend_class->add_options = clutter_backend_win32_add_options;
|
|
|
|
backend_class->get_features = clutter_backend_win32_get_features;
|
2010-01-20 11:41:25 -05:00
|
|
|
backend_class->create_context = clutter_backend_win32_create_context;
|
2010-02-17 12:06:25 -05:00
|
|
|
backend_class->get_device_manager = clutter_backend_win32_get_device_manager;
|
2008-03-25 11:42:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_backend_win32_init (ClutterBackendWin32 *backend_win32)
|
|
|
|
{
|
2010-01-15 17:56:37 -05:00
|
|
|
backend_win32->invisible_cursor = NULL;
|
2008-03-30 12:51:01 -04:00
|
|
|
|
2010-06-21 12:57:57 -04:00
|
|
|
/* FIXME: get from GetSystemMetric?
|
2008-03-25 11:42:50 -04:00
|
|
|
clutter_backend_set_double_click_time (backend, 250);
|
|
|
|
clutter_backend_set_double_click_distance (backend, 5);
|
|
|
|
clutter_backend_set_resolution (backend, 96.0);
|
2010-06-21 12:57:57 -04:00
|
|
|
*/
|
2008-03-30 18:27:27 -04:00
|
|
|
|
|
|
|
/* Set the maximum precision for Windows time functions. Without
|
|
|
|
this glib will not be able to sleep accurately enough to give a
|
|
|
|
reasonable frame rate */
|
|
|
|
timeBeginPeriod (1);
|
2008-03-25 11:42:50 -04:00
|
|
|
}
|
|
|
|
|
2010-01-15 17:56:37 -05:00
|
|
|
BOOL WINAPI
|
|
|
|
DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserved)
|
|
|
|
{
|
|
|
|
if (reason == DLL_PROCESS_ATTACH)
|
|
|
|
/* Store the module handle so that we can use it to load resources */
|
|
|
|
clutter_hinst = hinst;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|