2007-10-26 22:06:45 +00:00
|
|
|
/* Clutter - An OpenGL based 'interactive canvas' library.
|
|
|
|
* OSX backend - initial entry point
|
|
|
|
*
|
OSX: add multistage support
Bug #911 - OSX: add multistage support
* clutter/osx/clutter-backend-osx.{c,h}
(clutter_backend_osx_init_stage, clutter_backend_osx_get_stage,
clutter_backend_osx_redraw, clutter_backend_osx_create_stage,
clutter_backend_osx_ensure_context, clutter_backend_osx_class_init,
clutter_backend_osx_dispose, ClutterGLView:drawRect:):
* clutter/osx/clutter-stage-osx.{c,h} (clutter_stage_osx_realize,
ClutterGLWindow:setFrameSize:):
Adapt to new multistage backend API. Don't keep a pointer to
default stage. Derive from ClutterActor instead of ClutterStage.
Implement ClutterStageWindow interface. Paint, resize and
otherwise manipulate the wrapper rather than self when necessary.
(clutter_backend_post_parse): Create our singleton GL context
here. We could probably create the context when the default
stage is created, but I think this is more clean.
* clutter/osx/clutter-event-osx.c (clutter_event_osx_translate)
* clutter/osx/clutter-stage-osx.c (clutter_stage_osx_state_update,
ClutterGLWindow:windowShouldClose:):
* clutter/osx/clutter-stage-osx.h: Export ClutterGLWindow interface
for clutter-event-osx.c to easily get the stage for NSWindow.
Fill in ClutterEventAny::stage on our events.
Consistently use 'stage_osx' and 'wrapper' as variable names
when referring to ClutterStageOSX and ClutterStage objects
respectively.
2008-06-05 21:27:58 +00:00
|
|
|
* Copyright (C) 2007-2008 Tommi Komulainen <tommi.komulainen@iki.fi>
|
2007-10-26 22:06:45 +00:00
|
|
|
* Copyright (C) 2007 OpenedHand Ltd.
|
2011-02-03 08:51:20 +00:00
|
|
|
* Copyright (C) 2011 Crystalnix <vgachkaylo@crystalnix.com>
|
2007-10-26 22:06:45 +00: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
|
2010-03-01 12:56:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2007-10-26 22:06:45 +00:00
|
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-04-04 14:33:32 +00:00
|
|
|
#import "clutter-osx.h"
|
|
|
|
#import "clutter-backend-osx.h"
|
|
|
|
#import "clutter-device-manager-osx.h"
|
|
|
|
#import "clutter-stage-osx.h"
|
|
|
|
#import "clutter-event-loop-osx.h"
|
2010-10-21 10:29:09 +00:00
|
|
|
|
|
|
|
#include "clutter-debug.h"
|
|
|
|
#include "clutter-private.h"
|
|
|
|
#include "clutter-stage-private.h"
|
|
|
|
|
2008-06-09 23:00:31 +00:00
|
|
|
#include "cogl/cogl.h"
|
2007-10-26 22:06:45 +00:00
|
|
|
|
|
|
|
#import <AppKit/AppKit.h>
|
|
|
|
|
2012-01-07 10:41:25 +00:00
|
|
|
#define DEFAULT_FONT_NAME "Lucida Grande 13"
|
|
|
|
|
2011-11-03 17:53:54 +00:00
|
|
|
#define clutter_backend_osx_get_type _clutter_backend_osx_get_type
|
|
|
|
|
2007-10-26 22:06:45 +00:00
|
|
|
G_DEFINE_TYPE (ClutterBackendOSX, clutter_backend_osx, CLUTTER_TYPE_BACKEND)
|
|
|
|
|
2013-12-04 02:43:56 +00:00
|
|
|
/* various flags corresponding to pre init setup calls */
|
|
|
|
static gboolean _no_event_retrieval = FALSE;
|
|
|
|
|
2007-10-26 22:06:45 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
static gboolean
|
|
|
|
clutter_backend_osx_post_parse (ClutterBackend *backend,
|
|
|
|
GError **error)
|
|
|
|
{
|
2012-01-07 10:41:25 +00:00
|
|
|
ClutterSettings *settings = clutter_settings_get_default ();
|
|
|
|
|
2010-07-29 14:59:46 +00:00
|
|
|
CLUTTER_OSX_POOL_ALLOC();
|
|
|
|
/* getting standart dpi for main screen */
|
|
|
|
NSDictionary* prop = [[NSScreen mainScreen] deviceDescription];
|
|
|
|
NSSize size;
|
|
|
|
[[prop valueForKey:@"NSDeviceResolution"] getValue:&size];
|
|
|
|
CLUTTER_OSX_POOL_RELEASE();
|
2010-10-10 08:31:55 +00:00
|
|
|
|
2010-07-29 14:59:46 +00:00
|
|
|
/* setting dpi for backend, it needs by font rendering library */
|
|
|
|
if (size.height > 0)
|
|
|
|
{
|
2010-10-10 08:31:55 +00:00
|
|
|
int font_dpi = size.height * 1024;
|
|
|
|
|
|
|
|
g_object_set (settings, "font-dpi", font_dpi, NULL);
|
2010-07-29 14:59:46 +00:00
|
|
|
}
|
2010-10-10 08:31:55 +00:00
|
|
|
|
2012-01-07 10:41:25 +00:00
|
|
|
/* set the default font name */
|
|
|
|
g_object_set (settings, "font-name", DEFAULT_FONT_NAME, NULL);
|
|
|
|
|
2012-01-27 12:30:04 +00:00
|
|
|
/* finish launching the application */
|
|
|
|
[NSApp finishLaunching];
|
|
|
|
|
2012-01-07 10:41:25 +00:00
|
|
|
return TRUE;
|
2007-10-26 22:06:45 +00:00
|
|
|
}
|
|
|
|
|
2013-12-04 02:43:56 +00:00
|
|
|
void
|
|
|
|
clutter_osx_disable_event_retrieval (void)
|
|
|
|
{
|
|
|
|
if (_clutter_context_is_initialized ())
|
|
|
|
{
|
|
|
|
g_warning ("clutter_osx_disable_event_retrieval() can only be "
|
|
|
|
"called before clutter_init()");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_no_event_retrieval = TRUE;
|
|
|
|
}
|
|
|
|
|
2007-10-26 22:06:45 +00:00
|
|
|
static ClutterFeatureFlags
|
|
|
|
clutter_backend_osx_get_features (ClutterBackend *backend)
|
|
|
|
{
|
2011-11-07 14:48:48 +00:00
|
|
|
return CLUTTER_FEATURE_STAGE_MULTIPLE
|
|
|
|
| CLUTTER_FEATURE_STAGE_USER_RESIZE;
|
2007-10-26 22:06:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-03 17:53:54 +00:00
|
|
|
void
|
|
|
|
_clutter_backend_osx_events_init (ClutterBackend *backend)
|
2007-10-26 22:06:45 +00:00
|
|
|
{
|
2011-01-28 14:53:08 +00:00
|
|
|
ClutterBackendOSX *backend_osx = CLUTTER_BACKEND_OSX (backend);
|
|
|
|
|
|
|
|
if (backend_osx->device_manager != NULL)
|
|
|
|
return;
|
|
|
|
|
2007-10-26 22:06:45 +00:00
|
|
|
CLUTTER_NOTE (BACKEND, "init_events");
|
|
|
|
|
2011-11-04 19:25:54 +00:00
|
|
|
backend->device_manager = backend_osx->device_manager =
|
|
|
|
g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_OSX,
|
|
|
|
"backend", CLUTTER_BACKEND(backend_osx),
|
|
|
|
NULL);
|
2011-11-03 17:53:54 +00:00
|
|
|
|
2013-12-04 02:43:56 +00:00
|
|
|
if (!_no_event_retrieval)
|
|
|
|
_clutter_osx_event_loop_init ();
|
2007-10-26 22:06:45 +00:00
|
|
|
}
|
|
|
|
|
2010-07-16 12:19:13 +00:00
|
|
|
static gboolean
|
|
|
|
clutter_backend_osx_create_context (ClutterBackend *backend,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
ClutterBackendOSX *backend_osx = CLUTTER_BACKEND_OSX (backend);
|
2011-02-15 11:34:21 +00:00
|
|
|
|
2010-07-16 12:19:13 +00:00
|
|
|
CLUTTER_OSX_POOL_ALLOC();
|
2011-02-15 11:34:21 +00:00
|
|
|
|
|
|
|
if (backend_osx->context == nil)
|
2010-07-16 12:46:17 +00:00
|
|
|
{
|
2011-02-15 11:34:21 +00:00
|
|
|
/* Allocate ourselves a GL context. Since we're supposed to have
|
|
|
|
* only one per backend we can just as well create it now.
|
2010-07-16 12:46:17 +00:00
|
|
|
*/
|
|
|
|
NSOpenGLPixelFormatAttribute attrs[] = {
|
|
|
|
NSOpenGLPFADoubleBuffer,
|
2011-11-07 14:48:48 +00:00
|
|
|
NSOpenGLPFADepthSize, 32,
|
2010-07-16 12:46:17 +00:00
|
|
|
NSOpenGLPFAStencilSize, 8,
|
|
|
|
0
|
|
|
|
};
|
2011-02-15 11:34:21 +00:00
|
|
|
|
2010-07-16 12:46:17 +00:00
|
|
|
#ifdef MAC_OS_X_VERSION_10_5
|
|
|
|
const int sw = 1;
|
|
|
|
#else
|
|
|
|
const long sw = 1;
|
|
|
|
#endif
|
2011-02-15 11:34:21 +00:00
|
|
|
|
|
|
|
backend_osx->pixel_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
|
2011-07-13 18:32:47 +00:00
|
|
|
|
|
|
|
backend_osx->context = [[NSOpenGLContext alloc] initWithFormat: backend_osx->pixel_format
|
|
|
|
shareContext: nil];
|
|
|
|
|
2011-02-15 11:34:21 +00:00
|
|
|
/* Enable vblank sync - http://developer.apple.com/qa/qa2007/qa1521.html */
|
2010-07-16 12:46:17 +00:00
|
|
|
[backend_osx->context setValues:&sw forParameter: NSOpenGLCPSwapInterval];
|
2011-07-13 18:32:47 +00:00
|
|
|
|
|
|
|
CLUTTER_NOTE (BACKEND, "Context was created");
|
2010-07-16 12:46:17 +00:00
|
|
|
}
|
2011-02-15 11:34:21 +00:00
|
|
|
|
2010-07-16 12:19:13 +00:00
|
|
|
[backend_osx->context makeCurrentContext];
|
2011-02-15 11:34:21 +00:00
|
|
|
|
2012-05-31 09:06:05 +00:00
|
|
|
CLUTTER_BACKEND_CLASS (clutter_backend_osx_parent_class)->create_context (backend,
|
|
|
|
error);
|
|
|
|
|
2010-07-16 12:19:13 +00:00
|
|
|
CLUTTER_OSX_POOL_RELEASE();
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
OSX: add multistage support
Bug #911 - OSX: add multistage support
* clutter/osx/clutter-backend-osx.{c,h}
(clutter_backend_osx_init_stage, clutter_backend_osx_get_stage,
clutter_backend_osx_redraw, clutter_backend_osx_create_stage,
clutter_backend_osx_ensure_context, clutter_backend_osx_class_init,
clutter_backend_osx_dispose, ClutterGLView:drawRect:):
* clutter/osx/clutter-stage-osx.{c,h} (clutter_stage_osx_realize,
ClutterGLWindow:setFrameSize:):
Adapt to new multistage backend API. Don't keep a pointer to
default stage. Derive from ClutterActor instead of ClutterStage.
Implement ClutterStageWindow interface. Paint, resize and
otherwise manipulate the wrapper rather than self when necessary.
(clutter_backend_post_parse): Create our singleton GL context
here. We could probably create the context when the default
stage is created, but I think this is more clean.
* clutter/osx/clutter-event-osx.c (clutter_event_osx_translate)
* clutter/osx/clutter-stage-osx.c (clutter_stage_osx_state_update,
ClutterGLWindow:windowShouldClose:):
* clutter/osx/clutter-stage-osx.h: Export ClutterGLWindow interface
for clutter-event-osx.c to easily get the stage for NSWindow.
Fill in ClutterEventAny::stage on our events.
Consistently use 'stage_osx' and 'wrapper' as variable names
when referring to ClutterStageOSX and ClutterStage objects
respectively.
2008-06-05 21:27:58 +00:00
|
|
|
static void
|
|
|
|
clutter_backend_osx_ensure_context (ClutterBackend *backend,
|
|
|
|
ClutterStage *wrapper)
|
2007-10-26 22:06:45 +00:00
|
|
|
{
|
OSX: add multistage support
Bug #911 - OSX: add multistage support
* clutter/osx/clutter-backend-osx.{c,h}
(clutter_backend_osx_init_stage, clutter_backend_osx_get_stage,
clutter_backend_osx_redraw, clutter_backend_osx_create_stage,
clutter_backend_osx_ensure_context, clutter_backend_osx_class_init,
clutter_backend_osx_dispose, ClutterGLView:drawRect:):
* clutter/osx/clutter-stage-osx.{c,h} (clutter_stage_osx_realize,
ClutterGLWindow:setFrameSize:):
Adapt to new multistage backend API. Don't keep a pointer to
default stage. Derive from ClutterActor instead of ClutterStage.
Implement ClutterStageWindow interface. Paint, resize and
otherwise manipulate the wrapper rather than self when necessary.
(clutter_backend_post_parse): Create our singleton GL context
here. We could probably create the context when the default
stage is created, but I think this is more clean.
* clutter/osx/clutter-event-osx.c (clutter_event_osx_translate)
* clutter/osx/clutter-stage-osx.c (clutter_stage_osx_state_update,
ClutterGLWindow:windowShouldClose:):
* clutter/osx/clutter-stage-osx.h: Export ClutterGLWindow interface
for clutter-event-osx.c to easily get the stage for NSWindow.
Fill in ClutterEventAny::stage on our events.
Consistently use 'stage_osx' and 'wrapper' as variable names
when referring to ClutterStageOSX and ClutterStage objects
respectively.
2008-06-05 21:27:58 +00:00
|
|
|
ClutterBackendOSX *backend_osx = CLUTTER_BACKEND_OSX (backend);
|
|
|
|
|
|
|
|
CLUTTER_OSX_POOL_ALLOC();
|
|
|
|
|
2011-02-15 11:34:21 +00:00
|
|
|
CLUTTER_NOTE (BACKEND, "ensure_context: wrapper=%p", wrapper);
|
|
|
|
|
OSX: add multistage support
Bug #911 - OSX: add multistage support
* clutter/osx/clutter-backend-osx.{c,h}
(clutter_backend_osx_init_stage, clutter_backend_osx_get_stage,
clutter_backend_osx_redraw, clutter_backend_osx_create_stage,
clutter_backend_osx_ensure_context, clutter_backend_osx_class_init,
clutter_backend_osx_dispose, ClutterGLView:drawRect:):
* clutter/osx/clutter-stage-osx.{c,h} (clutter_stage_osx_realize,
ClutterGLWindow:setFrameSize:):
Adapt to new multistage backend API. Don't keep a pointer to
default stage. Derive from ClutterActor instead of ClutterStage.
Implement ClutterStageWindow interface. Paint, resize and
otherwise manipulate the wrapper rather than self when necessary.
(clutter_backend_post_parse): Create our singleton GL context
here. We could probably create the context when the default
stage is created, but I think this is more clean.
* clutter/osx/clutter-event-osx.c (clutter_event_osx_translate)
* clutter/osx/clutter-stage-osx.c (clutter_stage_osx_state_update,
ClutterGLWindow:windowShouldClose:):
* clutter/osx/clutter-stage-osx.h: Export ClutterGLWindow interface
for clutter-event-osx.c to easily get the stage for NSWindow.
Fill in ClutterEventAny::stage on our events.
Consistently use 'stage_osx' and 'wrapper' as variable names
when referring to ClutterStageOSX and ClutterStage objects
respectively.
2008-06-05 21:27:58 +00:00
|
|
|
if (wrapper)
|
|
|
|
{
|
|
|
|
ClutterStageWindow *impl = _clutter_stage_get_window (wrapper);
|
|
|
|
ClutterStageOSX *stage_osx;
|
|
|
|
|
|
|
|
g_assert (CLUTTER_IS_STAGE_OSX (impl));
|
|
|
|
stage_osx = CLUTTER_STAGE_OSX (impl);
|
2007-10-26 22:06:45 +00:00
|
|
|
|
2011-11-07 14:48:48 +00:00
|
|
|
[backend_osx->context clearDrawable];
|
OSX: add multistage support
Bug #911 - OSX: add multistage support
* clutter/osx/clutter-backend-osx.{c,h}
(clutter_backend_osx_init_stage, clutter_backend_osx_get_stage,
clutter_backend_osx_redraw, clutter_backend_osx_create_stage,
clutter_backend_osx_ensure_context, clutter_backend_osx_class_init,
clutter_backend_osx_dispose, ClutterGLView:drawRect:):
* clutter/osx/clutter-stage-osx.{c,h} (clutter_stage_osx_realize,
ClutterGLWindow:setFrameSize:):
Adapt to new multistage backend API. Don't keep a pointer to
default stage. Derive from ClutterActor instead of ClutterStage.
Implement ClutterStageWindow interface. Paint, resize and
otherwise manipulate the wrapper rather than self when necessary.
(clutter_backend_post_parse): Create our singleton GL context
here. We could probably create the context when the default
stage is created, but I think this is more clean.
* clutter/osx/clutter-event-osx.c (clutter_event_osx_translate)
* clutter/osx/clutter-stage-osx.c (clutter_stage_osx_state_update,
ClutterGLWindow:windowShouldClose:):
* clutter/osx/clutter-stage-osx.h: Export ClutterGLWindow interface
for clutter-event-osx.c to easily get the stage for NSWindow.
Fill in ClutterEventAny::stage on our events.
Consistently use 'stage_osx' and 'wrapper' as variable names
when referring to ClutterStageOSX and ClutterStage objects
respectively.
2008-06-05 21:27:58 +00:00
|
|
|
[backend_osx->context setView:stage_osx->view];
|
|
|
|
[backend_osx->context makeCurrentContext];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[backend_osx->context clearDrawable];
|
|
|
|
[NSOpenGLContext clearCurrentContext];
|
|
|
|
}
|
|
|
|
|
|
|
|
CLUTTER_OSX_POOL_RELEASE();
|
2007-10-26 22:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
static void
|
2010-07-16 12:46:17 +00:00
|
|
|
clutter_backend_osx_init (ClutterBackendOSX *backend_osx)
|
2007-10-26 22:06:45 +00:00
|
|
|
{
|
2011-02-15 11:34:21 +00:00
|
|
|
const ProcessSerialNumber psn = { 0, kCurrentProcess };
|
|
|
|
|
2010-07-16 12:46:17 +00:00
|
|
|
backend_osx->context = nil;
|
|
|
|
backend_osx->pixel_format = nil;
|
2010-07-19 13:46:55 +00:00
|
|
|
|
2011-02-15 11:34:21 +00:00
|
|
|
/* Bring our app to foreground, background apps don't appear in dock or
|
2010-07-19 13:46:55 +00:00
|
|
|
* accept keyboard focus.
|
|
|
|
*/
|
|
|
|
TransformProcessType (&psn, kProcessTransformToForegroundApplication);
|
|
|
|
|
|
|
|
/* Also raise our app to front, otherwise our window will remain under the
|
|
|
|
* terminal.
|
|
|
|
*/
|
|
|
|
SetFrontProcess (&psn);
|
|
|
|
|
|
|
|
[NSApplication sharedApplication];
|
2007-10-26 22:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_backend_osx_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
ClutterBackendOSX *self = CLUTTER_BACKEND_OSX (object);
|
|
|
|
|
|
|
|
[self->context release];
|
|
|
|
self->context = NULL;
|
|
|
|
|
|
|
|
[self->pixel_format release];
|
|
|
|
self->pixel_format = NULL;
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (clutter_backend_osx_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_backend_osx_class_init (ClutterBackendOSXClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterBackendClass *backend_class = CLUTTER_BACKEND_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->dispose = clutter_backend_osx_dispose;
|
|
|
|
|
2011-11-04 18:27:08 +00:00
|
|
|
backend_class->stage_window_type = CLUTTER_TYPE_STAGE_OSX;
|
|
|
|
|
2011-01-28 14:53:08 +00:00
|
|
|
backend_class->post_parse = clutter_backend_osx_post_parse;
|
|
|
|
backend_class->get_features = clutter_backend_osx_get_features;
|
|
|
|
backend_class->create_context = clutter_backend_osx_create_context;
|
|
|
|
backend_class->ensure_context = clutter_backend_osx_ensure_context;
|
2007-10-26 22:06:45 +00:00
|
|
|
}
|
2015-12-11 14:23:38 +00:00
|
|
|
|
|
|
|
ClutterBackend *
|
|
|
|
clutter_backend_osx_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (CLUTTER_TYPE_BACKEND_OSX, NULL);
|
|
|
|
}
|