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.
This commit is contained in:
Tommi Komulainen
2008-06-05 21:27:58 +00:00
parent cba23c0b26
commit b8e8a80a40
6 changed files with 196 additions and 132 deletions

View File

@ -1,7 +1,7 @@
/* Clutter - An OpenGL based 'interactive canvas' library.
* OSX backend - initial entry point
*
* Copyright (C) 2007 Tommi Komulainen <tommi.komulainen@iki.fi>
* Copyright (C) 2007-2008 Tommi Komulainen <tommi.komulainen@iki.fi>
* Copyright (C) 2007 OpenedHand Ltd.
*
* This library is free software; you can redistribute it and/or
@ -36,6 +36,8 @@ static gboolean
clutter_backend_osx_post_parse (ClutterBackend *backend,
GError **error)
{
ClutterBackendOSX *self = CLUTTER_BACKEND_OSX (backend);
CLUTTER_NOTE (BACKEND, "post_parse");
CLUTTER_OSX_POOL_ALLOC();
@ -53,40 +55,8 @@ clutter_backend_osx_post_parse (ClutterBackend *backend,
[NSApplication sharedApplication];
/* Initialize(?) OpenGL -- without this glGetString crashes
*
* Program received signal EXC_BAD_ACCESS, Could not access memory.
* Reason: KERN_PROTECTION_FAILURE at address: 0x00000ac0
* 0x92b22b2f in glGetString ()
*/
[NSOpenGLView defaultPixelFormat];
CLUTTER_OSX_POOL_RELEASE();
return TRUE;
}
static ClutterFeatureFlags
clutter_backend_osx_get_features (ClutterBackend *backend)
{
return CLUTTER_FEATURE_STAGE_USER_RESIZE;
}
static gboolean
clutter_backend_osx_init_stage (ClutterBackend *backend,
GError **error)
{
ClutterBackendOSX *self = CLUTTER_BACKEND_OSX (backend);
ClutterActor *stage;
CLUTTER_NOTE (BACKEND, "init_stage");
CLUTTER_OSX_POOL_ALLOC();
g_assert (self->stage == NULL);
/* Allocate ourselves a GL context. We need one this early for clutter to
* manage textures.
/* Allocate ourselves a GL context. Since we're supposed to have only one per
* backend we can just as well create it now.
*/
NSOpenGLPixelFormatAttribute attrs[] = {
NSOpenGLPFADoubleBuffer,
@ -96,16 +66,42 @@ clutter_backend_osx_init_stage (ClutterBackend *backend,
self->context = [[NSOpenGLContext alloc]
initWithFormat: self->pixel_format
shareContext: nil];
[self->context makeCurrentContext];
stage = clutter_stage_osx_new (backend);
self->stage = g_object_ref_sink (stage);
/* Enable vblank sync - http://developer.apple.com/qa/qa2007/qa1521.html*/
const long sw = 1;
[self->context setValues:&sw forParameter: NSOpenGLCPSwapInterval];
CLUTTER_OSX_POOL_RELEASE();
return TRUE;
}
static ClutterFeatureFlags
clutter_backend_osx_get_features (ClutterBackend *backend)
{
return CLUTTER_FEATURE_STAGE_MULTIPLE|CLUTTER_FEATURE_STAGE_USER_RESIZE;
}
static ClutterActor*
clutter_backend_osx_create_stage (ClutterBackend *backend,
ClutterStage *wrapper,
GError **error)
{
ClutterActor *impl;
CLUTTER_NOTE (BACKEND, "create_stage: wrapper=%p", wrapper);
CLUTTER_OSX_POOL_ALLOC();
impl = clutter_stage_osx_new (backend, wrapper);
CLUTTER_NOTE (BACKEND, "create_stage: impl=%p", impl);
CLUTTER_OSX_POOL_RELEASE();
return impl;
}
static void
clutter_backend_osx_init_events (ClutterBackend *backend)
{
@ -114,21 +110,41 @@ clutter_backend_osx_init_events (ClutterBackend *backend)
_clutter_events_osx_init ();
}
static ClutterActor *
clutter_backend_osx_get_stage (ClutterBackend *backend)
static void
clutter_backend_osx_ensure_context (ClutterBackend *backend,
ClutterStage *wrapper)
{
ClutterBackendOSX *self = CLUTTER_BACKEND_OSX (backend);
ClutterBackendOSX *backend_osx = CLUTTER_BACKEND_OSX (backend);
return self->stage;
CLUTTER_NOTE (BACKEND, "ensure_context: wrapper=%p", wrapper);
CLUTTER_OSX_POOL_ALLOC();
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);
[backend_osx->context setView:stage_osx->view];
[backend_osx->context makeCurrentContext];
}
else
{
[backend_osx->context clearDrawable];
[NSOpenGLContext clearCurrentContext];
}
CLUTTER_OSX_POOL_RELEASE();
}
static void
clutter_backend_osx_redraw (ClutterBackend *backend)
clutter_backend_osx_redraw (ClutterBackend *backend, ClutterStage *wrapper)
{
ClutterBackendOSX *self = CLUTTER_BACKEND_OSX (backend);
ClutterStageOSX *stage_osx;
stage_osx = CLUTTER_STAGE_OSX (self->stage);
ClutterStageWindow *impl = _clutter_stage_get_window (wrapper);
ClutterStageOSX *stage_osx = CLUTTER_STAGE_OSX (impl);
CLUTTER_OSX_POOL_ALLOC();
@ -149,12 +165,7 @@ clutter_backend_osx_dispose (GObject *object)
{
ClutterBackendOSX *self = CLUTTER_BACKEND_OSX (object);
if (self->stage)
{
CLUTTER_UNSET_PRIVATE_FLAGS (self->stage, CLUTTER_ACTOR_IS_TOPLEVEL);
clutter_actor_destroy (self->stage);
self->stage = NULL;
}
_clutter_shader_release_all ();
[self->context release];
self->context = NULL;
@ -162,7 +173,6 @@ clutter_backend_osx_dispose (GObject *object)
[self->pixel_format release];
self->pixel_format = NULL;
G_OBJECT_CLASS (clutter_backend_osx_parent_class)->dispose (object);
}
@ -176,9 +186,9 @@ clutter_backend_osx_class_init (ClutterBackendOSXClass *klass)
backend_class->post_parse = clutter_backend_osx_post_parse;
backend_class->get_features = clutter_backend_osx_get_features;
backend_class->init_stage = clutter_backend_osx_init_stage;
backend_class->create_stage = clutter_backend_osx_create_stage;
backend_class->ensure_context = clutter_backend_osx_ensure_context;
backend_class->init_events = clutter_backend_osx_init_events;
backend_class->get_stage = clutter_backend_osx_get_stage;
backend_class->redraw = clutter_backend_osx_redraw;
}