2009-06-29 14:30:26 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
2010-06-29 18:43:56 -04:00
|
|
|
#include <config.h>
|
|
|
|
|
2009-06-29 14:30:26 -04:00
|
|
|
#define _ISOC99_SOURCE /* for roundf */
|
|
|
|
#include <math.h>
|
|
|
|
|
2010-11-13 15:44:59 -05:00
|
|
|
#include <gdk/gdk.h> /* for gdk_rectangle_intersect() */
|
|
|
|
|
2013-01-23 15:54:41 -05:00
|
|
|
#include "clutter-utils.h"
|
2011-08-27 05:43:09 -04:00
|
|
|
#include "compositor-private.h"
|
2010-10-18 13:27:14 -04:00
|
|
|
#include "meta-window-actor-private.h"
|
|
|
|
#include "meta-window-group.h"
|
2011-08-28 21:20:29 -04:00
|
|
|
#include "meta-background-actor-private.h"
|
2013-01-23 15:54:41 -05:00
|
|
|
#include "meta-background-group-private.h"
|
2012-01-07 17:21:32 -05:00
|
|
|
#include "window-private.h"
|
2009-06-29 14:30:26 -04:00
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
struct _MetaWindowGroupClass
|
2009-06-29 14:30:26 -04:00
|
|
|
{
|
2012-01-17 09:16:46 -05:00
|
|
|
ClutterActorClass parent_class;
|
2009-06-29 14:30:26 -04:00
|
|
|
};
|
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
struct _MetaWindowGroup
|
2009-06-29 14:30:26 -04:00
|
|
|
{
|
2012-01-17 09:16:46 -05:00
|
|
|
ClutterActor parent;
|
2009-06-29 14:30:26 -04:00
|
|
|
|
|
|
|
MetaScreen *screen;
|
|
|
|
};
|
|
|
|
|
2012-01-17 09:16:46 -05:00
|
|
|
G_DEFINE_TYPE (MetaWindowGroup, meta_window_group, CLUTTER_TYPE_ACTOR);
|
2009-06-29 14:30:26 -04:00
|
|
|
|
2012-08-15 19:03:39 -04:00
|
|
|
/* Help macros to scale from OpenGL <-1,1> coordinates system to
|
|
|
|
* window coordinates ranging [0,window-size]. Borrowed from clutter-utils.c
|
|
|
|
*/
|
|
|
|
#define MTX_GL_SCALE_X(x,w,v1,v2) ((((((x) / (w)) + 1.0f) / 2.0f) * (v1)) + (v2))
|
|
|
|
#define MTX_GL_SCALE_Y(y,w,v1,v2) ((v1) - (((((y) / (w)) + 1.0f) / 2.0f) * (v1)) + (v2))
|
|
|
|
|
|
|
|
/* Check if we're painting the MetaWindowGroup "untransformed". This can
|
|
|
|
* differ from the result of actor_is_untransformed(window_group) if we're
|
|
|
|
* inside a clone paint. The integer translation, if any, is returned.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
painting_untransformed (MetaWindowGroup *window_group,
|
|
|
|
int *x_origin,
|
|
|
|
int *y_origin)
|
|
|
|
{
|
|
|
|
CoglMatrix modelview, projection, modelview_projection;
|
|
|
|
ClutterVertex vertices[4];
|
|
|
|
int width, height;
|
|
|
|
float viewport[4];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
cogl_get_modelview_matrix (&modelview);
|
|
|
|
cogl_get_projection_matrix (&projection);
|
|
|
|
|
|
|
|
cogl_matrix_multiply (&modelview_projection,
|
|
|
|
&projection,
|
|
|
|
&modelview);
|
|
|
|
|
|
|
|
meta_screen_get_size (window_group->screen, &width, &height);
|
|
|
|
|
|
|
|
vertices[0].x = 0;
|
|
|
|
vertices[0].y = 0;
|
|
|
|
vertices[0].z = 0;
|
|
|
|
vertices[1].x = width;
|
|
|
|
vertices[1].y = 0;
|
|
|
|
vertices[1].z = 0;
|
|
|
|
vertices[2].x = 0;
|
|
|
|
vertices[2].y = height;
|
|
|
|
vertices[2].z = 0;
|
|
|
|
vertices[3].x = width;
|
|
|
|
vertices[3].y = height;
|
|
|
|
vertices[3].z = 0;
|
|
|
|
|
|
|
|
cogl_get_viewport (viewport);
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
float w = 1;
|
|
|
|
cogl_matrix_transform_point (&modelview_projection, &vertices[i].x, &vertices[i].y, &vertices[i].z, &w);
|
|
|
|
vertices[i].x = MTX_GL_SCALE_X (vertices[i].x, w,
|
|
|
|
viewport[2], viewport[0]);
|
|
|
|
vertices[i].y = MTX_GL_SCALE_Y (vertices[i].y, w,
|
|
|
|
viewport[3], viewport[1]);
|
|
|
|
}
|
|
|
|
|
2013-02-18 17:55:26 -05:00
|
|
|
return meta_actor_vertices_are_untransformed (vertices, width, height, x_origin, y_origin);
|
2012-08-15 19:03:39 -04:00
|
|
|
}
|
|
|
|
|
2009-06-29 14:30:26 -04:00
|
|
|
static void
|
2013-11-25 15:17:14 -05:00
|
|
|
meta_window_group_cull_out (MetaWindowGroup *group,
|
|
|
|
cairo_region_t *unobscured_region,
|
|
|
|
cairo_region_t *clip_region)
|
2009-06-29 14:30:26 -04:00
|
|
|
{
|
2013-11-25 15:17:14 -05:00
|
|
|
ClutterActor *actor = CLUTTER_ACTOR (group);
|
2013-07-17 05:16:35 -04:00
|
|
|
ClutterActor *child;
|
2011-08-27 05:43:09 -04:00
|
|
|
|
2013-07-17 05:16:35 -04:00
|
|
|
/* We walk the list from top to bottom (opposite of painting order),
|
|
|
|
* and subtract the opaque area of each window out of the visible
|
|
|
|
* region that we pass to the windows below.
|
|
|
|
*/
|
|
|
|
clutter_actor_iter_init (&iter, actor);
|
|
|
|
while (clutter_actor_iter_prev (&iter, &child))
|
2009-06-29 14:30:26 -04:00
|
|
|
{
|
2013-07-17 05:16:35 -04:00
|
|
|
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
|
2009-06-29 14:30:26 -04:00
|
|
|
continue;
|
|
|
|
|
2011-09-20 10:55:48 -04:00
|
|
|
/* If an actor has effects applied, then that can change the area
|
|
|
|
* it paints and the opacity, so we no longer can figure out what
|
|
|
|
* portion of the actor is obscured and what portion of the screen
|
|
|
|
* it obscures, so we skip the actor.
|
|
|
|
*
|
|
|
|
* This has a secondary beneficial effect: if a ClutterOffscreenEffect
|
|
|
|
* is applied to an actor, then our clipped redraws interfere with the
|
|
|
|
* caching of the FBO - even if we only need to draw a small portion
|
|
|
|
* of the window right now, ClutterOffscreenEffect may use other portions
|
|
|
|
* of the FBO later. So, skipping actors with effects applied also
|
|
|
|
* prevents these bugs.
|
|
|
|
*
|
|
|
|
* Theoretically, we should check clutter_actor_get_offscreen_redirect()
|
|
|
|
* as well for the same reason, but omitted for simplicity in the
|
|
|
|
* hopes that no-one will do that.
|
|
|
|
*/
|
2013-07-17 05:16:35 -04:00
|
|
|
if (clutter_actor_has_effects (child))
|
2011-10-20 15:23:28 -04:00
|
|
|
continue;
|
2011-09-20 10:55:48 -04:00
|
|
|
|
2013-07-17 05:16:35 -04:00
|
|
|
if (META_IS_WINDOW_ACTOR (child))
|
2010-11-14 12:37:17 -05:00
|
|
|
{
|
2011-11-09 15:12:11 -05:00
|
|
|
int x, y;
|
2010-11-14 12:37:17 -05:00
|
|
|
|
2013-11-21 15:13:18 -05:00
|
|
|
if (!meta_actor_is_untransformed (child, &x, &y))
|
2010-11-14 12:37:17 -05:00
|
|
|
continue;
|
2009-06-29 14:30:26 -04:00
|
|
|
|
2010-11-14 12:37:17 -05:00
|
|
|
/* Temporarily move to the coordinate system of the actor */
|
2013-08-27 10:45:15 -04:00
|
|
|
cairo_region_translate (unobscured_region, - x, - y);
|
|
|
|
cairo_region_translate (clip_region, - x, - y);
|
2009-06-29 14:30:26 -04:00
|
|
|
|
2013-11-21 15:13:18 -05:00
|
|
|
meta_window_actor_cull_out (META_WINDOW_ACTOR (child), unobscured_region, clip_region);
|
2013-08-27 10:45:15 -04:00
|
|
|
|
|
|
|
cairo_region_translate (unobscured_region, x, y);
|
|
|
|
cairo_region_translate (clip_region, x, y);
|
2010-11-14 12:37:17 -05:00
|
|
|
}
|
2013-07-17 05:16:35 -04:00
|
|
|
else if (META_IS_BACKGROUND_ACTOR (child) ||
|
|
|
|
META_IS_BACKGROUND_GROUP (child))
|
2009-06-29 14:30:26 -04:00
|
|
|
{
|
2012-08-15 13:28:34 -04:00
|
|
|
int x, y;
|
|
|
|
|
2013-07-17 05:16:35 -04:00
|
|
|
if (!meta_actor_is_untransformed (child, &x, &y))
|
2012-08-15 13:28:34 -04:00
|
|
|
continue;
|
2012-08-05 12:30:31 -04:00
|
|
|
|
2013-08-27 10:45:15 -04:00
|
|
|
cairo_region_translate (clip_region, - x, - y);
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2013-07-17 05:16:35 -04:00
|
|
|
if (META_IS_BACKGROUND_GROUP (child))
|
2013-08-27 10:45:15 -04:00
|
|
|
meta_background_group_set_clip_region (META_BACKGROUND_GROUP (child), clip_region);
|
2013-01-23 15:54:41 -05:00
|
|
|
else
|
2013-08-27 10:45:15 -04:00
|
|
|
meta_background_actor_set_clip_region (META_BACKGROUND_ACTOR (child), clip_region);
|
|
|
|
cairo_region_translate (clip_region, x, y);
|
2009-06-29 14:30:26 -04:00
|
|
|
}
|
|
|
|
}
|
2013-11-25 15:17:14 -05:00
|
|
|
}
|
2009-06-29 14:30:26 -04:00
|
|
|
|
2013-11-25 15:17:14 -05:00
|
|
|
static void
|
|
|
|
meta_window_group_reset_culling (MetaWindowGroup *group)
|
|
|
|
{
|
|
|
|
ClutterActor *actor = CLUTTER_ACTOR (group);
|
|
|
|
ClutterActor *child;
|
|
|
|
ClutterActorIter iter;
|
2009-06-29 14:30:26 -04:00
|
|
|
|
|
|
|
/* Now that we are done painting, unset the visible regions (they will
|
|
|
|
* mess up painting clones of our actors)
|
|
|
|
*/
|
2013-07-17 05:16:35 -04:00
|
|
|
clutter_actor_iter_init (&iter, actor);
|
|
|
|
while (clutter_actor_iter_next (&iter, &child))
|
2009-06-29 14:30:26 -04:00
|
|
|
{
|
2013-07-17 05:16:35 -04:00
|
|
|
if (META_IS_WINDOW_ACTOR (child))
|
2010-11-14 12:37:17 -05:00
|
|
|
{
|
2013-07-17 05:16:35 -04:00
|
|
|
MetaWindowActor *window_actor = META_WINDOW_ACTOR (child);
|
2013-11-21 15:13:18 -05:00
|
|
|
meta_window_actor_reset_culling (window_actor);
|
2010-11-14 12:37:17 -05:00
|
|
|
}
|
2013-07-17 05:16:35 -04:00
|
|
|
else if (META_IS_BACKGROUND_ACTOR (child))
|
2010-11-14 12:37:17 -05:00
|
|
|
{
|
2013-07-17 05:16:35 -04:00
|
|
|
MetaBackgroundActor *background_actor = META_BACKGROUND_ACTOR (child);
|
2013-08-27 10:30:39 -04:00
|
|
|
meta_background_actor_set_clip_region (background_actor, NULL);
|
2010-11-14 12:37:17 -05:00
|
|
|
}
|
2009-06-29 14:30:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-25 15:17:14 -05:00
|
|
|
static void
|
|
|
|
meta_window_group_paint (ClutterActor *actor)
|
|
|
|
{
|
|
|
|
cairo_region_t *clip_region;
|
|
|
|
cairo_region_t *unobscured_region;
|
|
|
|
ClutterActorIter iter;
|
|
|
|
ClutterActor *child;
|
|
|
|
cairo_rectangle_int_t visible_rect, clip_rect;
|
|
|
|
int paint_x_offset, paint_y_offset;
|
|
|
|
int paint_x_origin, paint_y_origin;
|
|
|
|
int actor_x_origin, actor_y_origin;
|
|
|
|
|
|
|
|
MetaWindowGroup *window_group = META_WINDOW_GROUP (actor);
|
|
|
|
ClutterActor *stage = clutter_actor_get_stage (actor);
|
|
|
|
|
|
|
|
/* Start off by treating all windows as completely unobscured, so damage anywhere
|
|
|
|
* in a window queues redraws, but confine it more below. */
|
|
|
|
clutter_actor_iter_init (&iter, actor);
|
|
|
|
while (clutter_actor_iter_next (&iter, &child))
|
|
|
|
{
|
|
|
|
if (META_IS_WINDOW_ACTOR (child))
|
|
|
|
{
|
|
|
|
MetaWindowActor *window_actor = META_WINDOW_ACTOR (child);
|
|
|
|
meta_window_actor_set_unobscured_region (window_actor, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Normally we expect an actor to be drawn at it's position on the screen.
|
|
|
|
* However, if we're inside the paint of a ClutterClone, that won't be the
|
|
|
|
* case and we need to compensate. We look at the position of the window
|
|
|
|
* group under the current model-view matrix and the position of the actor.
|
|
|
|
* If they are both simply integer translations, then we can compensate
|
|
|
|
* easily, otherwise we give up.
|
|
|
|
*
|
|
|
|
* Possible cleanup: work entirely in paint space - we can compute the
|
|
|
|
* combination of the model-view matrix with the local matrix for each child
|
|
|
|
* actor and get a total transformation for that actor for how we are
|
|
|
|
* painting currently, and never worry about how actors are positioned
|
|
|
|
* on the stage.
|
|
|
|
*/
|
|
|
|
if (!painting_untransformed (window_group, &paint_x_origin, &paint_y_origin) ||
|
|
|
|
!meta_actor_is_untransformed (actor, &actor_x_origin, &actor_y_origin))
|
|
|
|
{
|
|
|
|
CLUTTER_ACTOR_CLASS (meta_window_group_parent_class)->paint (actor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
visible_rect.x = visible_rect.y = 0;
|
|
|
|
visible_rect.width = clutter_actor_get_width (CLUTTER_ACTOR (stage));
|
|
|
|
visible_rect.height = clutter_actor_get_height (CLUTTER_ACTOR (stage));
|
|
|
|
|
|
|
|
unobscured_region = cairo_region_create_rectangle (&visible_rect);
|
|
|
|
|
|
|
|
/* Get the clipped redraw bounds from Clutter so that we can avoid
|
|
|
|
* painting shadows on windows that don't need to be painted in this
|
|
|
|
* frame. In the case of a multihead setup with mismatched monitor
|
|
|
|
* sizes, we could intersect this with an accurate union of the
|
|
|
|
* monitors to avoid painting shadows that are visible only in the
|
|
|
|
* holes. */
|
|
|
|
clutter_stage_get_redraw_clip_bounds (CLUTTER_STAGE (stage),
|
|
|
|
&clip_rect);
|
|
|
|
|
|
|
|
clip_region = cairo_region_create_rectangle (&clip_rect);
|
|
|
|
|
|
|
|
paint_x_offset = paint_x_origin - actor_x_origin;
|
|
|
|
paint_y_offset = paint_y_origin - actor_y_origin;
|
|
|
|
cairo_region_translate (clip_region, -paint_x_offset, -paint_y_offset);
|
|
|
|
|
|
|
|
if (!meta_is_wayland_compositor ())
|
|
|
|
{
|
|
|
|
MetaCompScreen *info = meta_screen_get_compositor_data (window_group->screen);
|
|
|
|
if (info->unredirected_window != NULL)
|
|
|
|
{
|
|
|
|
cairo_rectangle_int_t unredirected_rect;
|
|
|
|
MetaWindow *window = meta_window_actor_get_meta_window (info->unredirected_window);
|
|
|
|
|
|
|
|
meta_window_get_frame_rect (window, (MetaRectangle *)&unredirected_rect);
|
|
|
|
cairo_region_subtract_rectangle (unobscured_region, &unredirected_rect);
|
|
|
|
cairo_region_subtract_rectangle (clip_region, &unredirected_rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
meta_window_group_cull_out (window_group, unobscured_region, clip_region);
|
|
|
|
|
|
|
|
cairo_region_destroy (unobscured_region);
|
|
|
|
cairo_region_destroy (clip_region);
|
|
|
|
|
|
|
|
CLUTTER_ACTOR_CLASS (meta_window_group_parent_class)->paint (actor);
|
|
|
|
|
|
|
|
meta_window_group_reset_culling (window_group);
|
|
|
|
}
|
|
|
|
|
2013-03-02 07:04:20 -05:00
|
|
|
static gboolean
|
|
|
|
meta_window_group_get_paint_volume (ClutterActor *actor,
|
|
|
|
ClutterPaintVolume *volume)
|
|
|
|
{
|
|
|
|
return clutter_paint_volume_set_from_allocation (volume, actor);
|
|
|
|
}
|
|
|
|
|
2009-06-29 14:30:26 -04:00
|
|
|
static void
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_window_group_class_init (MetaWindowGroupClass *klass)
|
2009-06-29 14:30:26 -04:00
|
|
|
{
|
|
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
actor_class->paint = meta_window_group_paint;
|
2013-03-02 07:04:20 -05:00
|
|
|
actor_class->get_paint_volume = meta_window_group_get_paint_volume;
|
2009-06-29 14:30:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_window_group_init (MetaWindowGroup *window_group)
|
2009-06-29 14:30:26 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ClutterActor *
|
2010-10-18 13:27:14 -04:00
|
|
|
meta_window_group_new (MetaScreen *screen)
|
2009-06-29 14:30:26 -04:00
|
|
|
{
|
2010-10-18 13:27:14 -04:00
|
|
|
MetaWindowGroup *window_group;
|
2009-06-29 14:30:26 -04:00
|
|
|
|
2010-10-18 13:27:14 -04:00
|
|
|
window_group = g_object_new (META_TYPE_WINDOW_GROUP, NULL);
|
2009-06-29 14:30:26 -04:00
|
|
|
|
|
|
|
window_group->screen = screen;
|
|
|
|
|
|
|
|
return CLUTTER_ACTOR (window_group);
|
|
|
|
}
|