mirror of
https://github.com/brl/mutter.git
synced 2024-11-27 18:40:40 -05:00
125bded814
Bug 1138 - No trackable "mapped" state * Add a VISIBLE flag tracking application programmer's expected showing-state for the actor, allowing us to always ensure we keep what the app wants while tracking internal implementation state separately. * Make MAPPED reflect whether the actor will be painted; add notification on a ClutterActor::mapped property. Keep MAPPED state updated as the actor is shown, ancestors are shown, actor is reparented, etc. * Require a stage and realized parents to realize; this means at realization time the correct window system and GL resources are known. But unparented actors can no longer be realized. * Allow children to be unrealized even if parent is realized. Otherwise in effect either all actors or no actors are realized, i.e. it becomes a stage-global flag. * Allow clutter_actor_realize() to "fail" if not inside a toplevel * Rework clutter_actor_unrealize() so internally we have a flavor that does not mess with visibility flag * Add _clutter_actor_rerealize() to encapsulate a somewhat tricky operation we were doing in a couple of places * Do not realize/unrealize children in ClutterGroup, ClutterActor already does it * Do not realize impl by hand in clutter_stage_show(), since showing impl already does that * Do not unrealize in various dispose() methods, since ClutterActor dispose implementation already does it and chaining up is mandatory * ClutterTexture uses COGL while unrealizable (before it's added to a stage). Previously this breakage was affecting ClutterActor because we had to allow realize outside a stage. Move the breakage to ClutterTexture, by making ClutterTexture just use COGL while not realized. * Unrealize before we set parent to NULL in clutter_actor_unparent(). This means unrealize() implementations can get to the stage. Because actors need the stage in order to detach from stage. * Update clutter-actor-invariants.txt to reflect latest changes * Remove explicit hide/unrealize from ClutterActor::dispose since unparent already forces those Instead just assert that unparent() occurred and did the right thing. * Check whether parent implements unrealize before chaining up Needed because ClutterGroup no longer has to implement unrealize. * Perform unrealize in the default handler for the signal. This allows non-containers that have children to work properly, and allows containers to override how it's done. * Add map/unmap virtual methods and set MAPPED flag on self and children in there. This allows subclasses to hook map/unmap. These are not signals, because notify::mapped is better for anything it's legitimate for a non-subclass to do. Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
237 lines
6.7 KiB
C
237 lines
6.7 KiB
C
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include "clutter-stage-sdl.h"
|
|
#include "clutter-sdl.h"
|
|
|
|
#include "../clutter-main.h"
|
|
#include "../clutter-feature.h"
|
|
#include "../clutter-color.h"
|
|
#include "../clutter-util.h"
|
|
#include "../clutter-event.h"
|
|
#include "../clutter-enum-types.h"
|
|
#include "../clutter-private.h"
|
|
#include "../clutter-debug.h"
|
|
#include "../clutter-units.h"
|
|
#include "../clutter-stage-window.h"
|
|
|
|
#include "cogl/cogl.h"
|
|
|
|
static void clutter_stage_window_iface_init (ClutterStageWindowIface *iface);
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (ClutterStageSDL,
|
|
clutter_stage_sdl,
|
|
CLUTTER_TYPE_ACTOR,
|
|
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_STAGE_WINDOW,
|
|
clutter_stage_window_iface_init));
|
|
|
|
static void
|
|
clutter_stage_sdl_show (ClutterActor *actor)
|
|
{
|
|
CLUTTER_ACTOR_SET_FLAGS (actor, CLUTTER_ACTOR_MAPPED);
|
|
CLUTTER_ACTOR_SET_FLAGS (CLUTTER_STAGE_SDL (actor)->wrapper,
|
|
CLUTTER_ACTOR_MAPPED);
|
|
|
|
CLUTTER_ACTOR_CLASS (clutter_stage_sdl_parent_class)->show (actor);
|
|
}
|
|
|
|
static void
|
|
clutter_stage_sdl_hide (ClutterActor *actor)
|
|
{
|
|
/* No way to easily unmap SDL window ? */
|
|
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_MAPPED);
|
|
CLUTTER_ACTOR_UNSET_FLAGS (CLUTTER_STAGE_SDL (actor)->wrapper,
|
|
CLUTTER_ACTOR_MAPPED);
|
|
|
|
CLUTTER_ACTOR_CLASS (clutter_stage_sdl_parent_class)->hide (actor);
|
|
}
|
|
|
|
static void
|
|
clutter_stage_sdl_unrealize (ClutterActor *actor)
|
|
{
|
|
;
|
|
}
|
|
|
|
static void
|
|
clutter_stage_sdl_realize (ClutterActor *actor)
|
|
{
|
|
ClutterStageSDL *stage_sdl = CLUTTER_STAGE_SDL (actor);
|
|
gboolean is_offscreen, is_fullscreen;
|
|
|
|
CLUTTER_NOTE (BACKEND, "Realizing main stage");
|
|
|
|
is_offscreen = is_fullscreen = FALSE;
|
|
g_object_get (stage_sdl->wrapper,
|
|
"offscreen", &is_offscreen,
|
|
"fullscreen", &is_fullscreen,
|
|
NULL);
|
|
|
|
if (G_LIKELY (!is_offscreen))
|
|
{
|
|
gint flags = SDL_OPENGL;
|
|
|
|
if (is_fullscreen)
|
|
flags |= SDL_FULLSCREEN;
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_ACCUM_RED_SIZE, 0);
|
|
SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0);
|
|
SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0);
|
|
SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0);
|
|
|
|
if (SDL_SetVideoMode (stage_sdl->win_width,
|
|
stage_sdl->win_height,
|
|
0, flags) == NULL)
|
|
{
|
|
CLUTTER_NOTE (BACKEND, "SDL appears not to handle this mode - %s",
|
|
SDL_GetError ());
|
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
|
|
return;
|
|
}
|
|
else
|
|
CLUTTER_ACTOR_SET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
|
|
}
|
|
else
|
|
{
|
|
/* FIXME */
|
|
g_critical ("SDL Backend does not yet support offscreen rendering");
|
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
|
|
}
|
|
}
|
|
|
|
static void
|
|
clutter_stage_sdl_get_preferred_width (ClutterActor *self,
|
|
ClutterUnit for_height,
|
|
ClutterUnit *min_width_p,
|
|
ClutterUnit *natural_width_p)
|
|
{
|
|
ClutterStageSDL *stage_sdl = CLUTTER_STAGE_SDL (self);
|
|
|
|
if (min_width_p)
|
|
*min_width_p = CLUTTER_UNITS_FROM_DEVICE (stage_sdl->win_width);
|
|
|
|
if (natural_width_p)
|
|
*natural_width_p = CLUTTER_UNITS_FROM_DEVICE (stage_sdl->win_width);
|
|
}
|
|
|
|
static void
|
|
clutter_stage_sdl_get_preferred_height (ClutterActor *self,
|
|
ClutterUnit for_width,
|
|
ClutterUnit *min_height_p,
|
|
ClutterUnit *natural_height_p)
|
|
{
|
|
ClutterStageSDL *stage_sdl = CLUTTER_STAGE_SDL (self);
|
|
|
|
if (min_height_p)
|
|
*min_height_p = CLUTTER_UNITS_FROM_DEVICE (stage_sdl->win_height);
|
|
|
|
if (natural_height_p)
|
|
*natural_height_p = CLUTTER_UNITS_FROM_DEVICE (stage_sdl->win_height);
|
|
}
|
|
|
|
static void
|
|
clutter_stage_sdl_allocate (ClutterActor *self,
|
|
const ClutterActorBox *box,
|
|
gboolean origin_changed)
|
|
{
|
|
ClutterStageSDL *stage_sdl = CLUTTER_STAGE_SDL (self);
|
|
gint new_width, new_height;
|
|
ClutterActorClass *parent_class;
|
|
|
|
/* FIXME: some how have X configure_notfiy call this ? */
|
|
new_width = ABS (CLUTTER_UNITS_TO_INT (box->x2 - box->x1));
|
|
new_height = ABS (CLUTTER_UNITS_TO_INT (box->y2 - box->y1));
|
|
|
|
if (new_width != stage_sdl->win_width ||
|
|
new_height != stage_sdl->win_height)
|
|
{
|
|
if (SDL_SetVideoMode(new_width,
|
|
new_height,
|
|
0, SDL_OPENGL) == NULL)
|
|
{
|
|
/* Failed */
|
|
return;
|
|
}
|
|
|
|
stage_sdl->win_width = new_width;
|
|
stage_sdl->win_height = new_height;
|
|
|
|
CLUTTER_SET_PRIVATE_FLAGS (self, CLUTTER_ACTOR_SYNC_MATRICES);
|
|
}
|
|
|
|
parent_class = CLUTTER_ACTOR_CLASS (clutter_stage_sdl_parent_class);
|
|
parent_class->allocate (self, box, origin_changed);
|
|
}
|
|
|
|
static void
|
|
clutter_stage_sdl_set_fullscreen (ClutterStageWindow *stage_window,
|
|
gboolean fullscreen)
|
|
{
|
|
ClutterStageSDL *stage_sdl = CLUTTER_STAGE_SDL (stage_window);
|
|
int flags = SDL_OPENGL;
|
|
|
|
if (fullscreen)
|
|
flags |= SDL_FULLSCREEN;
|
|
|
|
SDL_SetVideoMode (stage_sdl->win_width,
|
|
stage_sdl->win_height,
|
|
0, flags);
|
|
}
|
|
|
|
static void
|
|
clutter_stage_sdl_set_cursor_visible (ClutterStageWindow *stage_window,
|
|
gboolean show_cursor)
|
|
{
|
|
SDL_ShowCursor (show_cursor);
|
|
}
|
|
|
|
static void
|
|
clutter_stage_sdl_set_title (ClutterStageWindow *stage_window,
|
|
const gchar *title)
|
|
{
|
|
SDL_WM_SetCaption (title, NULL);
|
|
}
|
|
|
|
static void
|
|
clutter_stage_sdl_dispose (GObject *gobject)
|
|
{
|
|
ClutterStageSDL *stage_sdl = CLUTTER_STAGE_SDL (gobject);
|
|
|
|
G_OBJECT_CLASS (clutter_stage_sdl_parent_class)->dispose (gobject);
|
|
}
|
|
|
|
static void
|
|
clutter_stage_sdl_class_init (ClutterStageSDLClass *klass)
|
|
{
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
|
|
|
gobject_class->dispose = clutter_stage_sdl_dispose;
|
|
|
|
actor_class->show = clutter_stage_sdl_show;
|
|
actor_class->hide = clutter_stage_sdl_hide;
|
|
actor_class->realize = clutter_stage_sdl_realize;
|
|
actor_class->unrealize = clutter_stage_sdl_unrealize;
|
|
actor_class->get_preferred_width = clutter_stage_sdl_get_preferred_width;
|
|
actor_class->get_preferred_height = clutter_stage_sdl_get_preferred_height;
|
|
actor_class->allocate = clutter_stage_sdl_allocate;
|
|
}
|
|
|
|
static void
|
|
clutter_stage_window_iface_init (ClutterStageWindowIface *iface)
|
|
{
|
|
iface->set_fullscreen = clutter_stage_sdl_set_fullscreen;
|
|
iface->set_cursor_visible = clutter_stage_sdl_set_cursor_visible;
|
|
iface->set_title = clutter_stage_sdl_set_title;
|
|
}
|
|
|
|
static void
|
|
clutter_stage_sdl_init (ClutterStageSDL *stage)
|
|
{
|
|
stage->win_width = 640;
|
|
stage->win_height = 480;
|
|
}
|
|
|