compositor: export actor_is_untransformed function
actor_is_untransformed is a function meta-window-group uses to determine if an actor is relatively pixel aligned and not contorted. It then returns the coordinates of the actor. In a subsequent commit will need the function in a different file, so this commit separates it out. https://bugzilla.gnome.org/show_bug.cgi?id=682427
This commit is contained in:
parent
aba87407e9
commit
842bc4421c
@ -42,6 +42,8 @@ libmutter_la_SOURCES = \
|
|||||||
core/boxes.c \
|
core/boxes.c \
|
||||||
core/boxes-private.h \
|
core/boxes-private.h \
|
||||||
meta/boxes.h \
|
meta/boxes.h \
|
||||||
|
compositor/clutter-utils.c \
|
||||||
|
compositor/clutter-utils.h \
|
||||||
compositor/cogl-utils.c \
|
compositor/cogl-utils.c \
|
||||||
compositor/cogl-utils.h \
|
compositor/cogl-utils.h \
|
||||||
compositor/compositor.c \
|
compositor/compositor.c \
|
||||||
|
120
src/compositor/clutter-utils.c
Normal file
120
src/compositor/clutter-utils.c
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||||
|
/*
|
||||||
|
* Utilities for use with Cogl
|
||||||
|
*
|
||||||
|
* Copyright 2010 Red Hat, Inc.
|
||||||
|
* Copyright 2010 Intel Corporation
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "clutter-utils.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/* This file uses pixel-aligned region computation to determine what
|
||||||
|
* can be clipped out. This only really works if everything is aligned
|
||||||
|
* to the pixel grid - not scaled or rotated and at integer offsets.
|
||||||
|
*
|
||||||
|
* (This could be relaxed - if we turned off filtering for unscaled
|
||||||
|
* windows then windows would be, by definition aligned to the pixel
|
||||||
|
* grid. And for rectangular windows without a shape, the outline that
|
||||||
|
* we draw for an unrotated window is always a rectangle because we
|
||||||
|
* don't use antialasing for the window boundary - with or without
|
||||||
|
* filtering, with or without a scale. But figuring out exactly
|
||||||
|
* what pixels will be drawn by the graphics system in these cases
|
||||||
|
* gets tricky, so we just go for the easiest part - no scale,
|
||||||
|
* and at integer offsets.)
|
||||||
|
*
|
||||||
|
* The way we check for pixel-aligned is by looking at the
|
||||||
|
* transformation into screen space of the allocation box of an actor
|
||||||
|
* and and checking if the corners are "close enough" to integral
|
||||||
|
* pixel values.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* The definition of "close enough" to integral pixel values is
|
||||||
|
* equality when we convert to 24.8 fixed-point.
|
||||||
|
*/
|
||||||
|
static inline int
|
||||||
|
round_to_fixed (float x)
|
||||||
|
{
|
||||||
|
return roundf (x * 256);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This helper function checks if (according to our fixed point precision)
|
||||||
|
* the vertices @verts form a box of width @widthf and height @heightf
|
||||||
|
* located at integral coordinates. These coordinates are returned
|
||||||
|
* in @x_origin and @y_origin.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
meta_actor_vertices_are_untransformed (ClutterVertex *verts,
|
||||||
|
float widthf,
|
||||||
|
float heightf,
|
||||||
|
int *x_origin,
|
||||||
|
int *y_origin)
|
||||||
|
{
|
||||||
|
int width, height;
|
||||||
|
int v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y;
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
width = round_to_fixed (widthf); height = round_to_fixed (heightf);
|
||||||
|
|
||||||
|
v0x = round_to_fixed (verts[0].x); v0y = round_to_fixed (verts[0].y);
|
||||||
|
v1x = round_to_fixed (verts[1].x); v1y = round_to_fixed (verts[1].y);
|
||||||
|
v2x = round_to_fixed (verts[2].x); v2y = round_to_fixed (verts[2].y);
|
||||||
|
v3x = round_to_fixed (verts[3].x); v3y = round_to_fixed (verts[3].y);
|
||||||
|
|
||||||
|
/* Using shifting for converting fixed => int, gets things right for
|
||||||
|
* negative values. / 256. wouldn't do the same
|
||||||
|
*/
|
||||||
|
x = v0x >> 8;
|
||||||
|
y = v0y >> 8;
|
||||||
|
|
||||||
|
/* At integral coordinates? */
|
||||||
|
if (x * 256 != v0x || y * 256 != v0y)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
/* Not scaled? */
|
||||||
|
if (v1x - v0x != width || v2y - v0y != height)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
/* Not rotated/skewed? */
|
||||||
|
if (v0x != v2x || v0y != v1y ||
|
||||||
|
v3x != v1x || v3y != v2y)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
*x_origin = x;
|
||||||
|
*y_origin = y;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if an actor is "untransformed" - which actually means transformed by
|
||||||
|
* at most a integer-translation. The integer translation, if any, is returned.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
meta_actor_is_untransformed (ClutterActor *actor,
|
||||||
|
int *x_origin,
|
||||||
|
int *y_origin)
|
||||||
|
{
|
||||||
|
gfloat widthf, heightf;
|
||||||
|
ClutterVertex verts[4];
|
||||||
|
|
||||||
|
clutter_actor_get_size (actor, &widthf, &heightf);
|
||||||
|
clutter_actor_get_abs_allocation_vertices (actor, verts);
|
||||||
|
|
||||||
|
return meta_actor_vertices_are_untransformed (verts, widthf, heightf, x_origin, y_origin);
|
||||||
|
}
|
||||||
|
|
36
src/compositor/clutter-utils.h
Normal file
36
src/compositor/clutter-utils.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||||
|
/*
|
||||||
|
* Utilities for use with Clutter
|
||||||
|
*
|
||||||
|
* Copyright 2010 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __META_CLUTTER_UTILS_H__
|
||||||
|
#define __META_CLUTTER_UTILS_H__
|
||||||
|
|
||||||
|
#include <clutter/clutter.h>
|
||||||
|
gboolean meta_actor_vertices_are_untransformed (ClutterVertex *verts,
|
||||||
|
float widthf,
|
||||||
|
float heightf,
|
||||||
|
int *x_origin,
|
||||||
|
int *y_origin);
|
||||||
|
gboolean meta_actor_is_untransformed (ClutterActor *actor,
|
||||||
|
int *x_origin,
|
||||||
|
int *y_origin);
|
||||||
|
|
||||||
|
#endif /* __META_CLUTTER_UTILS_H__ */
|
@ -11,6 +11,7 @@
|
|||||||
#include "meta-window-actor-private.h"
|
#include "meta-window-actor-private.h"
|
||||||
#include "meta-window-group.h"
|
#include "meta-window-group.h"
|
||||||
#include "meta-background-actor-private.h"
|
#include "meta-background-actor-private.h"
|
||||||
|
#include "clutter-utils.h"
|
||||||
|
|
||||||
struct _MetaWindowGroupClass
|
struct _MetaWindowGroupClass
|
||||||
{
|
{
|
||||||
@ -26,100 +27,6 @@ struct _MetaWindowGroup
|
|||||||
|
|
||||||
G_DEFINE_TYPE (MetaWindowGroup, meta_window_group, CLUTTER_TYPE_GROUP);
|
G_DEFINE_TYPE (MetaWindowGroup, meta_window_group, CLUTTER_TYPE_GROUP);
|
||||||
|
|
||||||
/* This file uses pixel-aligned region computation to determine what
|
|
||||||
* can be clipped out. This only really works if everything is aligned
|
|
||||||
* to the pixel grid - not scaled or rotated and at integer offsets.
|
|
||||||
*
|
|
||||||
* (This could be relaxed - if we turned off filtering for unscaled
|
|
||||||
* windows then windows would be, by definition aligned to the pixel
|
|
||||||
* grid. And for rectangular windows without a shape, the outline that
|
|
||||||
* we draw for an unrotated window is always a rectangle because we
|
|
||||||
* don't use antialasing for the window boundary - with or without
|
|
||||||
* filtering, with or without a scale. But figuring out exactly
|
|
||||||
* what pixels will be drawn by the graphics system in these cases
|
|
||||||
* gets tricky, so we just go for the easiest part - no scale,
|
|
||||||
* and at integer offsets.)
|
|
||||||
*
|
|
||||||
* The way we check for pixel-aligned is by looking at the
|
|
||||||
* transformation into screen space of the allocation box of an actor
|
|
||||||
* and and checking if the corners are "close enough" to integral
|
|
||||||
* pixel values.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* The definition of "close enough" to integral pixel values is
|
|
||||||
* equality when we convert to 24.8 fixed-point.
|
|
||||||
*/
|
|
||||||
static inline int
|
|
||||||
round_to_fixed (float x)
|
|
||||||
{
|
|
||||||
return roundf (x * 256);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This helper function checks if (according to our fixed point precision)
|
|
||||||
* the vertices @verts form a box of width @widthf and height @heightf
|
|
||||||
* located at integral coordinates. These coordinates are returned
|
|
||||||
* in @x_origin and @y_origin.
|
|
||||||
*/
|
|
||||||
static gboolean
|
|
||||||
vertices_are_untransformed (ClutterVertex *verts,
|
|
||||||
float widthf,
|
|
||||||
float heightf,
|
|
||||||
int *x_origin,
|
|
||||||
int *y_origin)
|
|
||||||
{
|
|
||||||
int width, height;
|
|
||||||
int v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y;
|
|
||||||
int x, y;
|
|
||||||
|
|
||||||
width = round_to_fixed (widthf); height = round_to_fixed (heightf);
|
|
||||||
|
|
||||||
v0x = round_to_fixed (verts[0].x); v0y = round_to_fixed (verts[0].y);
|
|
||||||
v1x = round_to_fixed (verts[1].x); v1y = round_to_fixed (verts[1].y);
|
|
||||||
v2x = round_to_fixed (verts[2].x); v2y = round_to_fixed (verts[2].y);
|
|
||||||
v3x = round_to_fixed (verts[3].x); v3y = round_to_fixed (verts[3].y);
|
|
||||||
|
|
||||||
/* Using shifting for converting fixed => int, gets things right for
|
|
||||||
* negative values. / 256. wouldn't do the same
|
|
||||||
*/
|
|
||||||
x = v0x >> 8;
|
|
||||||
y = v0y >> 8;
|
|
||||||
|
|
||||||
/* At integral coordinates? */
|
|
||||||
if (x * 256 != v0x || y * 256 != v0y)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
/* Not scaled? */
|
|
||||||
if (v1x - v0x != width || v2y - v0y != height)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
/* Not rotated/skewed? */
|
|
||||||
if (v0x != v2x || v0y != v1y ||
|
|
||||||
v3x != v1x || v3y != v2y)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
*x_origin = x;
|
|
||||||
*y_origin = y;
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if an actor is "untransformed" - which actually means transformed by
|
|
||||||
* at most a integer-translation. The integer translation, if any, is returned.
|
|
||||||
*/
|
|
||||||
static gboolean
|
|
||||||
actor_is_untransformed (ClutterActor *actor,
|
|
||||||
int *x_origin,
|
|
||||||
int *y_origin)
|
|
||||||
{
|
|
||||||
gfloat widthf, heightf;
|
|
||||||
ClutterVertex verts[4];
|
|
||||||
|
|
||||||
clutter_actor_get_size (actor, &widthf, &heightf);
|
|
||||||
clutter_actor_get_abs_allocation_vertices (actor, verts);
|
|
||||||
|
|
||||||
return vertices_are_untransformed (verts, widthf, heightf, x_origin, y_origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Help macros to scale from OpenGL <-1,1> coordinates system to
|
/* Help macros to scale from OpenGL <-1,1> coordinates system to
|
||||||
* window coordinates ranging [0,window-size]. Borrowed from clutter-utils.c
|
* window coordinates ranging [0,window-size]. Borrowed from clutter-utils.c
|
||||||
*/
|
*/
|
||||||
@ -175,7 +82,7 @@ painting_untransformed (MetaWindowGroup *window_group,
|
|||||||
viewport[3], viewport[1]);
|
viewport[3], viewport[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return vertices_are_untransformed (vertices, width, height, x_origin, y_origin);
|
return meta_actor_vertices_are_untransformed (vertices, width, height, x_origin, y_origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -206,7 +113,7 @@ meta_window_group_paint (ClutterActor *actor)
|
|||||||
* on the stage.
|
* on the stage.
|
||||||
*/
|
*/
|
||||||
if (!painting_untransformed (window_group, &paint_x_origin, &paint_y_origin) ||
|
if (!painting_untransformed (window_group, &paint_x_origin, &paint_y_origin) ||
|
||||||
!actor_is_untransformed (actor, &actor_x_origin, &actor_y_origin))
|
!meta_actor_is_untransformed (actor, &actor_x_origin, &actor_y_origin))
|
||||||
{
|
{
|
||||||
CLUTTER_ACTOR_CLASS (meta_window_group_parent_class)->paint (actor);
|
CLUTTER_ACTOR_CLASS (meta_window_group_parent_class)->paint (actor);
|
||||||
return;
|
return;
|
||||||
@ -275,7 +182,7 @@ meta_window_group_paint (ClutterActor *actor)
|
|||||||
MetaWindowActor *window_actor = l->data;
|
MetaWindowActor *window_actor = l->data;
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
if (!actor_is_untransformed (CLUTTER_ACTOR (window_actor), &x, &y))
|
if (!meta_actor_is_untransformed (CLUTTER_ACTOR (window_actor), &x, &y))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
x += paint_x_offset;
|
x += paint_x_offset;
|
||||||
@ -301,7 +208,7 @@ meta_window_group_paint (ClutterActor *actor)
|
|||||||
MetaBackgroundActor *background_actor = l->data;
|
MetaBackgroundActor *background_actor = l->data;
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
if (!actor_is_untransformed (CLUTTER_ACTOR (background_actor), &x, &y))
|
if (!meta_actor_is_untransformed (CLUTTER_ACTOR (background_actor), &x, &y))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
x += paint_x_offset;
|
x += paint_x_offset;
|
||||||
|
@ -49,4 +49,7 @@ GType meta_window_group_get_type (void);
|
|||||||
|
|
||||||
ClutterActor *meta_window_group_new (MetaScreen *screen);
|
ClutterActor *meta_window_group_new (MetaScreen *screen);
|
||||||
|
|
||||||
|
gboolean meta_window_group_actor_is_untransformed (ClutterActor *actor,
|
||||||
|
int *x_origin,
|
||||||
|
int *y_origin);
|
||||||
#endif /* META_WINDOW_GROUP_H */
|
#endif /* META_WINDOW_GROUP_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user