2012-01-18 23:03:23 +00:00
|
|
|
/*
|
2014-04-22 18:46:57 +00:00
|
|
|
* Copyright (C) 2014 Red Hat
|
2012-01-18 23:03:23 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
2014-04-22 18:46:57 +00:00
|
|
|
*
|
|
|
|
* Written by:
|
|
|
|
* Jasper St. Pierre <jstpierre@mecheye.net>
|
2012-01-18 23:03:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2014-04-22 18:46:57 +00:00
|
|
|
#include "meta-stage.h"
|
2014-04-22 00:49:38 +00:00
|
|
|
|
2014-08-05 12:11:59 +00:00
|
|
|
#include <meta/meta-backend.h>
|
Introduce regional stage rendering
Add support for drawing a stage using multiple framebuffers each making
up one part of the stage. This works by the stage backend
(ClutterStageWindow) providing a list of views which will be for
splitting up the stage in different regions.
A view layout, for now, is a set of rectangles. The stage window (i.e.
stage "backend" will use this information when drawing a frame, using
one framebuffer for each view. The scene graph is adapted to explictly
take a view when painting the stage. It will use this view, its
assigned framebuffer and layout to offset and clip the drawing
accordingly.
This effectively removes any notion of "stage framebuffer", since each
stage now may consist of multiple framebuffers. Therefore, API
involving this has been deprecated and made no-ops; namely
clutter_stage_ensure_context(). Callers are now assumed to either
always use a framebuffer reference explicitly, or push/pop the
framebuffer of a given view where the code has not yet changed to use
the explicit-buffer-using cogl API.
Currently only the nested X11 backend supports this mode fully, and the
per view framebuffers are all offscreen. Upon frame completion, it'll
blit each view's framebuffer onto the onscreen framebuffer before
swapping.
Other backends (X11 CM and native/KMS) are adapted to manage a
full-stage view. The X11 CM backend will continue to use this method,
while the native/KMS backend will be adopted to use multiple view
drawing.
https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 03:09:24 +00:00
|
|
|
#include <meta/meta-monitor-manager.h>
|
2014-04-22 18:32:55 +00:00
|
|
|
#include <meta/util.h>
|
Introduce regional stage rendering
Add support for drawing a stage using multiple framebuffers each making
up one part of the stage. This works by the stage backend
(ClutterStageWindow) providing a list of views which will be for
splitting up the stage in different regions.
A view layout, for now, is a set of rectangles. The stage window (i.e.
stage "backend" will use this information when drawing a frame, using
one framebuffer for each view. The scene graph is adapted to explictly
take a view when painting the stage. It will use this view, its
assigned framebuffer and layout to offset and clip the drawing
accordingly.
This effectively removes any notion of "stage framebuffer", since each
stage now may consist of multiple framebuffers. Therefore, API
involving this has been deprecated and made no-ops; namely
clutter_stage_ensure_context(). Callers are now assumed to either
always use a framebuffer reference explicitly, or push/pop the
framebuffer of a given view where the code has not yet changed to use
the explicit-buffer-using cogl API.
Currently only the nested X11 backend supports this mode fully, and the
per view framebuffers are all offscreen. Upon frame completion, it'll
blit each view's framebuffer onto the onscreen framebuffer before
swapping.
Other backends (X11 CM and native/KMS) are adapted to manage a
full-stage view. The X11 CM backend will continue to use this method,
while the native/KMS backend will be adopted to use multiple view
drawing.
https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 03:09:24 +00:00
|
|
|
#include "backends/meta-backend-private.h"
|
|
|
|
#include "clutter/clutter-mutter.h"
|
2012-01-18 23:03:23 +00:00
|
|
|
|
2016-05-02 11:49:13 +00:00
|
|
|
struct _MetaOverlay {
|
2014-08-21 18:47:39 +00:00
|
|
|
gboolean enabled;
|
2014-04-22 19:06:42 +00:00
|
|
|
|
2014-08-21 18:47:39 +00:00
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglTexture *texture;
|
2014-04-22 19:06:42 +00:00
|
|
|
|
|
|
|
MetaRectangle current_rect;
|
|
|
|
MetaRectangle previous_rect;
|
|
|
|
gboolean previous_is_valid;
|
2016-05-02 11:49:13 +00:00
|
|
|
};
|
2014-08-21 18:47:39 +00:00
|
|
|
|
|
|
|
struct _MetaStagePrivate {
|
2016-05-02 11:49:13 +00:00
|
|
|
GList *overlays;
|
2015-03-24 16:40:10 +00:00
|
|
|
gboolean is_active;
|
2014-04-22 19:06:42 +00:00
|
|
|
};
|
|
|
|
typedef struct _MetaStagePrivate MetaStagePrivate;
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (MetaStage, meta_stage, CLUTTER_TYPE_STAGE);
|
|
|
|
|
2016-05-02 11:49:13 +00:00
|
|
|
static MetaOverlay *
|
2016-05-31 17:49:08 +00:00
|
|
|
meta_overlay_new (void)
|
2014-04-22 19:06:42 +00:00
|
|
|
{
|
2016-05-02 11:49:13 +00:00
|
|
|
MetaOverlay *overlay;
|
2014-08-21 18:47:39 +00:00
|
|
|
CoglContext *ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
|
2014-04-22 19:06:42 +00:00
|
|
|
|
2016-05-02 11:49:13 +00:00
|
|
|
overlay = g_slice_new0 (MetaOverlay);
|
2014-08-21 18:47:39 +00:00
|
|
|
overlay->pipeline = cogl_pipeline_new (ctx);
|
2016-05-02 11:49:13 +00:00
|
|
|
|
|
|
|
return overlay;
|
2014-04-22 19:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-21 18:47:39 +00:00
|
|
|
meta_overlay_free (MetaOverlay *overlay)
|
2014-04-22 19:06:42 +00:00
|
|
|
{
|
2014-08-21 18:47:39 +00:00
|
|
|
if (overlay->pipeline)
|
|
|
|
cogl_object_unref (overlay->pipeline);
|
2016-05-02 11:49:13 +00:00
|
|
|
|
|
|
|
g_slice_free (MetaOverlay, overlay);
|
2014-04-22 19:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-21 18:47:39 +00:00
|
|
|
meta_overlay_set (MetaOverlay *overlay,
|
|
|
|
CoglTexture *texture,
|
|
|
|
MetaRectangle *rect)
|
2014-04-22 19:06:42 +00:00
|
|
|
{
|
2014-08-21 18:47:39 +00:00
|
|
|
if (overlay->texture != texture)
|
|
|
|
{
|
|
|
|
overlay->texture = texture;
|
|
|
|
|
|
|
|
if (texture)
|
|
|
|
{
|
|
|
|
cogl_pipeline_set_layer_texture (overlay->pipeline, 0, texture);
|
|
|
|
overlay->enabled = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cogl_pipeline_set_layer_texture (overlay->pipeline, 0, NULL);
|
|
|
|
overlay->enabled = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
overlay->current_rect = *rect;
|
|
|
|
}
|
2014-04-22 19:06:42 +00:00
|
|
|
|
2014-08-21 18:47:39 +00:00
|
|
|
static void
|
|
|
|
meta_overlay_paint (MetaOverlay *overlay)
|
|
|
|
{
|
|
|
|
if (!overlay->enabled)
|
2014-04-22 19:06:42 +00:00
|
|
|
return;
|
|
|
|
|
2014-08-21 22:03:03 +00:00
|
|
|
g_assert (meta_is_wayland_compositor ());
|
|
|
|
|
2014-04-22 19:06:42 +00:00
|
|
|
cogl_framebuffer_draw_rectangle (cogl_get_draw_framebuffer (),
|
2014-08-21 18:47:39 +00:00
|
|
|
overlay->pipeline,
|
|
|
|
overlay->current_rect.x,
|
|
|
|
overlay->current_rect.y,
|
|
|
|
overlay->current_rect.x +
|
|
|
|
overlay->current_rect.width,
|
|
|
|
overlay->current_rect.y +
|
|
|
|
overlay->current_rect.height);
|
|
|
|
|
|
|
|
overlay->previous_rect = overlay->current_rect;
|
|
|
|
overlay->previous_is_valid = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_stage_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MetaStage *stage = META_STAGE (object);
|
|
|
|
MetaStagePrivate *priv = meta_stage_get_instance_private (stage);
|
2016-05-02 11:49:13 +00:00
|
|
|
GList *l = priv->overlays;
|
2014-08-21 18:47:39 +00:00
|
|
|
|
2016-05-02 11:49:13 +00:00
|
|
|
while (l)
|
|
|
|
{
|
|
|
|
meta_overlay_free (l->data);
|
|
|
|
l = g_list_delete_link (l, l);
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_stage_parent_class)->finalize (object);
|
2014-04-22 19:06:42 +00:00
|
|
|
}
|
2012-01-18 23:03:23 +00:00
|
|
|
|
|
|
|
static void
|
2014-04-22 18:46:57 +00:00
|
|
|
meta_stage_paint (ClutterActor *actor)
|
2012-01-18 23:03:23 +00:00
|
|
|
{
|
2014-04-22 19:06:42 +00:00
|
|
|
MetaStage *stage = META_STAGE (actor);
|
2014-08-21 18:47:39 +00:00
|
|
|
MetaStagePrivate *priv = meta_stage_get_instance_private (stage);
|
2016-05-02 11:49:13 +00:00
|
|
|
GList *l;
|
2014-04-22 19:06:42 +00:00
|
|
|
|
2014-04-22 18:46:57 +00:00
|
|
|
CLUTTER_ACTOR_CLASS (meta_stage_parent_class)->paint (actor);
|
2012-01-18 23:03:23 +00:00
|
|
|
|
2016-05-02 11:49:13 +00:00
|
|
|
for (l = priv->overlays; l; l = l->next)
|
|
|
|
meta_overlay_paint (l->data);
|
2012-01-18 23:03:23 +00:00
|
|
|
}
|
|
|
|
|
2015-03-24 16:40:10 +00:00
|
|
|
static void
|
|
|
|
meta_stage_activate (ClutterStage *actor)
|
|
|
|
{
|
|
|
|
MetaStage *stage = META_STAGE (actor);
|
|
|
|
MetaStagePrivate *priv = meta_stage_get_instance_private (stage);
|
|
|
|
|
|
|
|
CLUTTER_STAGE_CLASS (meta_stage_parent_class)->activate (actor);
|
|
|
|
|
|
|
|
priv->is_active = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_stage_deactivate (ClutterStage *actor)
|
|
|
|
{
|
|
|
|
MetaStage *stage = META_STAGE (actor);
|
|
|
|
MetaStagePrivate *priv = meta_stage_get_instance_private (stage);
|
|
|
|
|
|
|
|
CLUTTER_STAGE_CLASS (meta_stage_parent_class)->deactivate (actor);
|
|
|
|
|
|
|
|
priv->is_active = FALSE;
|
|
|
|
}
|
|
|
|
|
2012-01-18 23:03:23 +00:00
|
|
|
static void
|
2014-04-22 18:46:57 +00:00
|
|
|
meta_stage_class_init (MetaStageClass *klass)
|
2012-01-18 23:03:23 +00:00
|
|
|
{
|
2015-03-24 16:40:10 +00:00
|
|
|
ClutterStageClass *stage_class = (ClutterStageClass *) klass;
|
2012-01-18 23:03:23 +00:00
|
|
|
ClutterActorClass *actor_class = (ClutterActorClass *) klass;
|
2014-04-22 19:06:42 +00:00
|
|
|
GObjectClass *object_class = (GObjectClass *) klass;
|
|
|
|
|
|
|
|
object_class->finalize = meta_stage_finalize;
|
2012-01-18 23:03:23 +00:00
|
|
|
|
2014-04-22 18:46:57 +00:00
|
|
|
actor_class->paint = meta_stage_paint;
|
2015-03-24 16:40:10 +00:00
|
|
|
|
|
|
|
stage_class->activate = meta_stage_activate;
|
|
|
|
stage_class->deactivate = meta_stage_deactivate;
|
2012-01-18 23:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-04-22 19:06:42 +00:00
|
|
|
meta_stage_init (MetaStage *stage)
|
2012-01-18 23:03:23 +00:00
|
|
|
{
|
2014-04-22 19:06:42 +00:00
|
|
|
clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), FALSE);
|
2012-01-18 23:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ClutterActor *
|
2014-04-22 18:46:57 +00:00
|
|
|
meta_stage_new (void)
|
2012-01-18 23:03:23 +00:00
|
|
|
{
|
2014-04-22 18:46:57 +00:00
|
|
|
return g_object_new (META_TYPE_STAGE,
|
2014-04-22 01:06:18 +00:00
|
|
|
"cursor-visible", FALSE,
|
|
|
|
NULL);
|
2012-01-18 23:03:23 +00:00
|
|
|
}
|
2014-04-22 19:06:42 +00:00
|
|
|
|
|
|
|
static void
|
2014-08-21 18:47:39 +00:00
|
|
|
queue_redraw_for_overlay (MetaStage *stage,
|
|
|
|
MetaOverlay *overlay)
|
2014-04-22 19:06:42 +00:00
|
|
|
{
|
|
|
|
cairo_rectangle_int_t clip;
|
|
|
|
|
2014-08-21 18:47:39 +00:00
|
|
|
/* Clear the location the overlay was at before, if we need to. */
|
|
|
|
if (overlay->previous_is_valid)
|
2014-04-22 19:06:42 +00:00
|
|
|
{
|
2014-08-21 18:47:39 +00:00
|
|
|
clip.x = overlay->previous_rect.x;
|
|
|
|
clip.y = overlay->previous_rect.y;
|
|
|
|
clip.width = overlay->previous_rect.width;
|
|
|
|
clip.height = overlay->previous_rect.height;
|
2014-04-22 19:06:42 +00:00
|
|
|
clutter_actor_queue_redraw_with_clip (CLUTTER_ACTOR (stage), &clip);
|
2014-08-21 18:47:39 +00:00
|
|
|
overlay->previous_is_valid = FALSE;
|
2014-04-22 19:06:42 +00:00
|
|
|
}
|
|
|
|
|
2014-08-21 18:47:39 +00:00
|
|
|
/* Draw the overlay at the new position */
|
|
|
|
if (overlay->enabled)
|
2014-04-22 19:06:42 +00:00
|
|
|
{
|
2014-08-21 18:47:39 +00:00
|
|
|
clip.x = overlay->current_rect.x;
|
|
|
|
clip.y = overlay->current_rect.y;
|
|
|
|
clip.width = overlay->current_rect.width;
|
|
|
|
clip.height = overlay->current_rect.height;
|
2014-04-22 19:06:42 +00:00
|
|
|
clutter_actor_queue_redraw_with_clip (CLUTTER_ACTOR (stage), &clip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-02 11:49:13 +00:00
|
|
|
MetaOverlay *
|
|
|
|
meta_stage_create_cursor_overlay (MetaStage *stage)
|
|
|
|
{
|
|
|
|
MetaStagePrivate *priv = meta_stage_get_instance_private (stage);
|
|
|
|
MetaOverlay *overlay;
|
|
|
|
|
|
|
|
overlay = meta_overlay_new ();
|
|
|
|
priv->overlays = g_list_prepend (priv->overlays, overlay);
|
|
|
|
|
|
|
|
return overlay;
|
|
|
|
}
|
|
|
|
|
2014-04-22 19:06:42 +00:00
|
|
|
void
|
2016-05-02 11:49:13 +00:00
|
|
|
meta_stage_remove_cursor_overlay (MetaStage *stage,
|
|
|
|
MetaOverlay *overlay)
|
2014-04-22 19:06:42 +00:00
|
|
|
{
|
|
|
|
MetaStagePrivate *priv = meta_stage_get_instance_private (stage);
|
2016-05-02 11:49:13 +00:00
|
|
|
GList *link;
|
2014-04-22 19:06:42 +00:00
|
|
|
|
2016-05-02 11:49:13 +00:00
|
|
|
link = g_list_find (priv->overlays, overlay);
|
|
|
|
if (!link)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->overlays = g_list_delete_link (priv->overlays, link);
|
|
|
|
meta_overlay_free (overlay);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_stage_update_cursor_overlay (MetaStage *stage,
|
|
|
|
MetaOverlay *overlay,
|
|
|
|
CoglTexture *texture,
|
|
|
|
MetaRectangle *rect)
|
|
|
|
{
|
2014-08-21 22:03:03 +00:00
|
|
|
g_assert (meta_is_wayland_compositor () || texture == NULL);
|
2014-08-21 18:47:39 +00:00
|
|
|
|
2016-05-02 11:49:13 +00:00
|
|
|
meta_overlay_set (overlay, texture, rect);
|
|
|
|
queue_redraw_for_overlay (stage, overlay);
|
2014-04-22 19:06:42 +00:00
|
|
|
}
|
2015-03-24 16:40:10 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
meta_stage_set_active (MetaStage *stage,
|
|
|
|
gboolean is_active)
|
|
|
|
{
|
|
|
|
MetaStagePrivate *priv = meta_stage_get_instance_private (stage);
|
|
|
|
ClutterEvent event = { 0 };
|
|
|
|
|
|
|
|
/* Used by the native backend to inform accessibility technologies
|
|
|
|
* about when the stage loses and gains input focus.
|
|
|
|
*
|
|
|
|
* For the X11 backend, clutter transparently takes care of this
|
|
|
|
* for us.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (priv->is_active == is_active)
|
|
|
|
return;
|
|
|
|
|
2015-03-30 13:41:22 +00:00
|
|
|
event.type = CLUTTER_STAGE_STATE;
|
2015-03-24 16:40:10 +00:00
|
|
|
clutter_event_set_stage (&event, CLUTTER_STAGE (stage));
|
|
|
|
event.stage_state.changed_mask = CLUTTER_STAGE_STATE_ACTIVATED;
|
|
|
|
|
|
|
|
if (is_active)
|
|
|
|
event.stage_state.new_state = CLUTTER_STAGE_STATE_ACTIVATED;
|
|
|
|
|
|
|
|
/* Emitting this StageState event will result in the stage getting
|
|
|
|
* activated or deactivated (with the activated or deactivated signal
|
|
|
|
* getting emitted from the stage)
|
|
|
|
*
|
|
|
|
* FIXME: This won't update ClutterStage's own notion of its
|
|
|
|
* activeness. For that we would need to somehow trigger a
|
|
|
|
* _clutter_stage_update_state call, which will probably
|
|
|
|
* require new API in clutter. In practice, nothing relies
|
|
|
|
* on the ClutterStage's own notion of activeness when using
|
|
|
|
* the EGL backend.
|
|
|
|
*
|
|
|
|
* See http://bugzilla.gnome.org/746670
|
|
|
|
*/
|
|
|
|
clutter_stage_event (CLUTTER_STAGE (stage), &event);
|
|
|
|
}
|