2008-03-25 15:42:50 +00: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 12:56:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2008-03-25 15:42:50 +00: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 18:18:38 +00:00
|
|
|
#include "clutter-device-manager-win32.h"
|
2008-03-25 15:42:50 +00:00
|
|
|
|
2010-10-21 10:29:09 +00: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 15:42:50 +00:00
|
|
|
|
2011-10-12 09:50:32 +00:00
|
|
|
#include "clutter-shader.h"
|
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
#include "cogl/cogl.h"
|
2008-03-25 15:42:50 +00:00
|
|
|
|
|
|
|
G_DEFINE_TYPE (ClutterBackendWin32, clutter_backend_win32,
|
|
|
|
CLUTTER_TYPE_BACKEND);
|
|
|
|
|
2008-06-24 22:07:15 +00:00
|
|
|
typedef int (WINAPI * SwapIntervalProc) (int interval);
|
2008-03-25 15:42:50 +00:00
|
|
|
|
|
|
|
/* singleton object */
|
|
|
|
static ClutterBackendWin32 *backend_singleton = NULL;
|
|
|
|
|
2010-01-15 22:56:37 +00:00
|
|
|
static HINSTANCE clutter_hinst = NULL;
|
|
|
|
|
2010-10-21 16:20:44 +00:00
|
|
|
/* various flags corresponding to pre init setup calls */
|
|
|
|
static gboolean _no_event_retrieval = FALSE;
|
|
|
|
|
2008-03-25 15:42:50 +00:00
|
|
|
static void
|
|
|
|
clutter_backend_win32_init_events (ClutterBackend *backend)
|
|
|
|
{
|
2010-01-15 11:47:05 +00:00
|
|
|
ClutterBackendWin32 *backend_win32 = CLUTTER_BACKEND_WIN32 (backend);
|
|
|
|
|
2008-03-25 15:42:50 +00:00
|
|
|
CLUTTER_NOTE (EVENT, "initialising the event loop");
|
|
|
|
|
2011-11-04 19:25:54 +00:00
|
|
|
backend->device_manager =
|
2010-02-17 17:06:25 +00:00
|
|
|
g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_WIN32,
|
|
|
|
"backend", backend_win32,
|
|
|
|
NULL);
|
2010-01-15 11:47:05 +00:00
|
|
|
|
2010-10-21 16:20:44 +00:00
|
|
|
if (!_no_event_retrieval)
|
|
|
|
_clutter_backend_win32_events_init (backend);
|
2008-03-25 15:42:50 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:56:37 +00: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 15:42:50 +00:00
|
|
|
static void
|
|
|
|
clutter_backend_win32_finalize (GObject *gobject)
|
|
|
|
{
|
|
|
|
backend_singleton = NULL;
|
|
|
|
|
2008-03-30 22:27:27 +00:00
|
|
|
timeEndPeriod (1);
|
|
|
|
|
2008-03-25 15:42:50 +00:00
|
|
|
G_OBJECT_CLASS (clutter_backend_win32_parent_class)->finalize (gobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_backend_win32_dispose (GObject *gobject)
|
|
|
|
{
|
2011-04-21 15:52:54 +00:00
|
|
|
ClutterBackend *backend = CLUTTER_BACKEND (gobject);
|
2008-03-25 15:42:50 +00:00
|
|
|
ClutterBackendWin32 *backend_win32 = CLUTTER_BACKEND_WIN32 (gobject);
|
2008-03-30 16:51:01 +00:00
|
|
|
ClutterStageManager *stage_manager;
|
|
|
|
|
|
|
|
CLUTTER_NOTE (BACKEND, "Disposing the of stages");
|
2009-06-17 16:59:54 +00:00
|
|
|
stage_manager = clutter_stage_manager_get_default ();
|
2008-03-30 16:51:01 +00:00
|
|
|
|
2010-11-01 15:13:12 +00:00
|
|
|
g_object_unref (stage_manager);
|
2008-03-25 15:42:50 +00:00
|
|
|
|
|
|
|
CLUTTER_NOTE (BACKEND, "Removing the event source");
|
|
|
|
_clutter_backend_win32_events_uninit (CLUTTER_BACKEND (backend_win32));
|
|
|
|
|
2011-04-21 15:52:54 +00:00
|
|
|
G_OBJECT_CLASS (clutter_backend_win32_parent_class)->dispose (gobject);
|
2010-01-20 16:41:25 +00:00
|
|
|
|
2011-04-21 15:52:54 +00:00
|
|
|
if (backend->cogl_context)
|
2010-01-20 16:41:25 +00:00
|
|
|
{
|
2011-04-21 15:52:54 +00:00
|
|
|
cogl_object_unref (backend->cogl_context);
|
|
|
|
backend->cogl_context = NULL;
|
2010-01-20 16:41:25 +00:00
|
|
|
}
|
2008-03-25 15:42:50 +00: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 15:52:54 +00:00
|
|
|
ClutterBackendClass *parent_class;
|
2010-01-20 16:41:25 +00:00
|
|
|
|
2011-04-21 15:52:54 +00:00
|
|
|
parent_class = CLUTTER_BACKEND_CLASS (clutter_backend_win32_parent_class);
|
2008-03-25 15:42:50 +00:00
|
|
|
|
2011-11-04 16:13:04 +00:00
|
|
|
return parent_class->get_features (backend)
|
|
|
|
| CLUTTER_FEATURE_STAGE_USER_RESIZE
|
|
|
|
| CLUTTER_FEATURE_STAGE_CURSOR;
|
2010-02-17 17:06:25 +00:00
|
|
|
}
|
|
|
|
|
2010-10-21 16:20:44 +00: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 15:42:50 +00: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;
|
|
|
|
|
2011-11-04 18:27:08 +00:00
|
|
|
backend_class->stage_window_type = CLUTTER_TYPE_STAGE_WIN32;
|
|
|
|
|
|
|
|
backend_class->init_events = clutter_backend_win32_init_events;
|
|
|
|
backend_class->get_features = clutter_backend_win32_get_features;
|
2008-03-25 15:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_backend_win32_init (ClutterBackendWin32 *backend_win32)
|
|
|
|
{
|
2010-01-15 22:56:37 +00:00
|
|
|
backend_win32->invisible_cursor = NULL;
|
2008-03-30 16:51:01 +00:00
|
|
|
|
2010-06-21 16:57:57 +00:00
|
|
|
/* FIXME: get from GetSystemMetric?
|
2008-03-25 15:42:50 +00: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 16:57:57 +00:00
|
|
|
*/
|
2008-03-30 22:27:27 +00: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 15:42:50 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:56:37 +00: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;
|
|
|
|
}
|