2013-01-23 15:54:41 -05:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
2013-03-11 11:52:36 -04:00
|
|
|
|
2013-01-23 15:54:41 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2013 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
|
2014-01-11 20:42:06 -05:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2013-01-23 15:54:41 -05:00
|
|
|
*/
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
#include <meta/meta-background.h>
|
|
|
|
#include <meta/meta-background-image.h>
|
|
|
|
#include "meta-background-private.h"
|
|
|
|
#include "cogl-utils.h"
|
2013-03-11 11:52:36 -04:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CHANGED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
typedef struct _MetaBackgroundMonitor MetaBackgroundMonitor;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
struct _MetaBackgroundMonitor
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
gboolean dirty;
|
|
|
|
CoglTexture *texture;
|
|
|
|
CoglOffscreen *fbo;
|
|
|
|
};
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
struct _MetaBackgroundPrivate
|
|
|
|
{
|
|
|
|
MetaScreen *screen;
|
|
|
|
MetaBackgroundMonitor *monitors;
|
|
|
|
int n_monitors;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
|
|
|
GDesktopBackgroundStyle style;
|
|
|
|
GDesktopBackgroundShading shading_direction;
|
|
|
|
ClutterColor color;
|
|
|
|
ClutterColor second_color;
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
char *filename1;
|
|
|
|
MetaBackgroundImage *background_image1;
|
|
|
|
char *filename2;
|
|
|
|
MetaBackgroundImage *background_image2;
|
|
|
|
|
|
|
|
CoglTexture *color_texture;
|
|
|
|
CoglTexture *wallpaper_texture;
|
|
|
|
|
|
|
|
float blend_factor;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
guint wallpaper_allocation_failed : 1;
|
2013-01-23 15:54:41 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_META_SCREEN = 1,
|
|
|
|
PROP_MONITOR,
|
|
|
|
};
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
G_DEFINE_TYPE (MetaBackground, meta_background, G_TYPE_OBJECT)
|
2013-01-23 15:54:41 -05:00
|
|
|
|
|
|
|
static void
|
2014-08-10 11:26:14 -04:00
|
|
|
free_fbos (MetaBackground *self)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
|
|
|
MetaBackgroundPrivate *priv = self->priv;
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
int i;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
for (i = 0; i < priv->n_monitors; i++)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
MetaBackgroundMonitor *monitor = &priv->monitors[i];
|
|
|
|
if (monitor->fbo)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
cogl_object_unref (monitor->fbo);
|
|
|
|
monitor->fbo = NULL;
|
|
|
|
}
|
|
|
|
if (monitor->texture)
|
|
|
|
{
|
|
|
|
cogl_object_unref (monitor->texture);
|
|
|
|
monitor->texture = NULL;
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
static void
|
|
|
|
free_color_texture (MetaBackground *self)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
|
|
|
MetaBackgroundPrivate *priv = self->priv;
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (priv->color_texture != NULL)
|
2014-08-07 12:38:42 -04:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
cogl_object_unref (priv->color_texture);
|
|
|
|
priv->color_texture = NULL;
|
2014-08-07 12:38:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
static void
|
|
|
|
free_wallpaper_texture (MetaBackground *self)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
|
|
|
MetaBackgroundPrivate *priv = self->priv;
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (priv->wallpaper_texture != NULL)
|
|
|
|
{
|
|
|
|
cogl_object_unref (priv->wallpaper_texture);
|
|
|
|
priv->wallpaper_texture = NULL;
|
|
|
|
}
|
2014-08-07 12:38:42 -04:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
priv->wallpaper_allocation_failed = FALSE;
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-10 11:26:14 -04:00
|
|
|
on_monitors_changed (MetaScreen *screen,
|
|
|
|
MetaBackground *self)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
MetaBackgroundPrivate *priv = self->priv;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
free_fbos (self);
|
|
|
|
g_free (priv->monitors);
|
|
|
|
priv->monitors = NULL;
|
|
|
|
priv->n_monitors = 0;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (priv->screen)
|
|
|
|
{
|
|
|
|
priv->n_monitors = meta_screen_get_n_monitors (screen);
|
|
|
|
priv->monitors = g_new0 (MetaBackgroundMonitor, priv->n_monitors);
|
|
|
|
}
|
2013-02-24 21:24:54 -05:00
|
|
|
}
|
|
|
|
|
2013-01-23 15:54:41 -05:00
|
|
|
static void
|
2014-08-10 11:26:14 -04:00
|
|
|
set_screen (MetaBackground *self,
|
|
|
|
MetaScreen *screen)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
|
|
|
MetaBackgroundPrivate *priv = self->priv;
|
2013-02-24 21:24:54 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (priv->screen != NULL)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
g_signal_handlers_disconnect_by_func (priv->screen,
|
|
|
|
(gpointer)on_monitors_changed,
|
|
|
|
self);
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
priv->screen = screen;
|
2014-08-07 14:59:59 -04:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (priv->screen != NULL)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
g_signal_connect (priv->screen, "monitors-changed",
|
|
|
|
G_CALLBACK (on_monitors_changed), self);
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
2014-08-07 14:59:59 -04:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
on_monitors_changed (priv->screen, self);
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-10 11:26:14 -04:00
|
|
|
meta_background_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_META_SCREEN:
|
|
|
|
set_screen (META_BACKGROUND (object), g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-10 11:26:14 -04:00
|
|
|
meta_background_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
MetaBackgroundPrivate *priv = META_BACKGROUND (object)->priv;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_META_SCREEN:
|
|
|
|
g_value_set_object (value, priv->screen);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
static gboolean
|
|
|
|
need_prerender (MetaBackground *self)
|
2013-04-23 05:02:04 -04:00
|
|
|
{
|
|
|
|
MetaBackgroundPrivate *priv = self->priv;
|
2014-08-10 11:26:14 -04:00
|
|
|
CoglTexture *texture1 = priv->background_image1 ? meta_background_image_get_texture (priv->background_image1) : NULL;
|
|
|
|
CoglTexture *texture2 = priv->background_image2 ? meta_background_image_get_texture (priv->background_image2) : NULL;
|
2013-04-23 05:02:04 -04:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (texture1 == NULL && texture2 == NULL)
|
|
|
|
return FALSE;
|
2013-04-23 05:02:04 -04:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (texture2 == NULL && priv->style == G_DESKTOP_BACKGROUND_STYLE_WALLPAPER)
|
|
|
|
return FALSE;
|
2013-04-23 05:02:04 -04:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
return TRUE;
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-10 11:26:14 -04:00
|
|
|
mark_changed (MetaBackground *self)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
|
|
|
MetaBackgroundPrivate *priv = self->priv;
|
2014-08-10 11:26:14 -04:00
|
|
|
int i;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (!need_prerender (self))
|
|
|
|
free_fbos (self);
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
for (i = 0; i < priv->n_monitors; i++)
|
|
|
|
priv->monitors[i].dirty = TRUE;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
g_signal_emit (self, signals[CHANGED], 0);
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-10 11:26:14 -04:00
|
|
|
on_background_loaded (MetaBackgroundImage *image,
|
|
|
|
MetaBackground *self)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
mark_changed (self);
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-10 11:26:14 -04:00
|
|
|
set_filename (MetaBackground *self,
|
|
|
|
char **filenamep,
|
|
|
|
MetaBackgroundImage **imagep,
|
|
|
|
const char *filename)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
if (g_strcmp0 (filename, *filenamep) != 0)
|
|
|
|
{
|
|
|
|
g_free (*filenamep);
|
|
|
|
*filenamep = g_strdup (filename);
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (*imagep)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (*imagep,
|
|
|
|
(gpointer)on_background_loaded,
|
|
|
|
self);
|
|
|
|
g_object_unref (*imagep);
|
|
|
|
*imagep = NULL;
|
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (filename)
|
|
|
|
{
|
|
|
|
MetaBackgroundImageCache *cache = meta_background_image_cache_get_default ();
|
|
|
|
*imagep = meta_background_image_cache_load (cache, filename);
|
|
|
|
g_signal_connect (*imagep, "loaded",
|
|
|
|
G_CALLBACK (on_background_loaded), self);
|
|
|
|
}
|
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-10 11:26:14 -04:00
|
|
|
meta_background_dispose (GObject *object)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
MetaBackground *self = META_BACKGROUND (object);
|
2013-01-23 15:54:41 -05:00
|
|
|
MetaBackgroundPrivate *priv = self->priv;
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
free_color_texture (self);
|
|
|
|
free_wallpaper_texture (self);
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
set_filename (self, &priv->filename1, &priv->background_image1, NULL);
|
|
|
|
set_filename (self, &priv->filename2, &priv->background_image2, NULL);
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
set_screen (self, NULL);
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
G_OBJECT_CLASS (meta_background_parent_class)->dispose (object);
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-10 11:26:14 -04:00
|
|
|
meta_background_finalize (GObject *object)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
G_OBJECT_CLASS (meta_background_parent_class)->finalize (object);
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_background_class_init (MetaBackgroundClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2014-08-10 11:26:14 -04:00
|
|
|
GParamSpec *param_spec;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (MetaBackgroundPrivate));
|
|
|
|
|
|
|
|
object_class->dispose = meta_background_dispose;
|
2013-04-23 05:02:04 -04:00
|
|
|
object_class->finalize = meta_background_finalize;
|
2013-01-23 15:54:41 -05:00
|
|
|
object_class->set_property = meta_background_set_property;
|
|
|
|
object_class->get_property = meta_background_get_property;
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
signals[CHANGED] =
|
|
|
|
g_signal_new ("changed",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2013-01-23 15:54:41 -05:00
|
|
|
param_spec = g_param_spec_object ("meta-screen",
|
|
|
|
"MetaScreen",
|
|
|
|
"MetaScreen",
|
|
|
|
META_TYPE_SCREEN,
|
2014-08-10 11:26:14 -04:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
|
2013-01-23 15:54:41 -05:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_META_SCREEN,
|
|
|
|
param_spec);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_background_init (MetaBackground *self)
|
|
|
|
{
|
|
|
|
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
|
|
|
|
META_TYPE_BACKGROUND,
|
|
|
|
MetaBackgroundPrivate);
|
|
|
|
}
|
|
|
|
|
2014-09-12 10:33:46 -04:00
|
|
|
static void
|
|
|
|
set_texture_area_from_monitor_area (cairo_rectangle_int_t *monitor_area,
|
|
|
|
cairo_rectangle_int_t *texture_area)
|
|
|
|
{
|
|
|
|
texture_area->x = 0;
|
|
|
|
texture_area->y = 0;
|
|
|
|
texture_area->width = monitor_area->width;
|
|
|
|
texture_area->height = monitor_area->height;
|
|
|
|
}
|
|
|
|
|
2013-01-23 15:54:41 -05:00
|
|
|
static void
|
2014-08-10 11:26:14 -04:00
|
|
|
get_texture_area (MetaBackground *self,
|
|
|
|
cairo_rectangle_int_t *monitor_rect,
|
|
|
|
CoglTexture *texture,
|
|
|
|
cairo_rectangle_int_t *texture_area)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
|
|
|
MetaBackgroundPrivate *priv = self->priv;
|
2014-08-10 11:26:14 -04:00
|
|
|
cairo_rectangle_int_t image_area;
|
|
|
|
int screen_width, screen_height;
|
|
|
|
float texture_width, texture_height;
|
|
|
|
float monitor_x_scale, monitor_y_scale;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
texture_width = cogl_texture_get_width (texture);
|
|
|
|
texture_height = cogl_texture_get_height (texture);
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
switch (priv->style)
|
|
|
|
{
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_STRETCHED:
|
|
|
|
default:
|
|
|
|
/* paint region is whole actor, and the texture
|
|
|
|
* is scaled disproportionately to fit the actor
|
|
|
|
*/
|
2014-09-12 10:33:46 -04:00
|
|
|
set_texture_area_from_monitor_area (monitor_rect, texture_area);
|
2014-08-10 11:26:14 -04:00
|
|
|
break;
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_WALLPAPER:
|
|
|
|
meta_screen_get_size (priv->screen, &screen_width, &screen_height);
|
|
|
|
|
|
|
|
/* Start off by centering a tile in the middle of the
|
|
|
|
* total screen area.
|
|
|
|
*/
|
|
|
|
image_area.x = (screen_width - texture_width) / 2.0;
|
|
|
|
image_area.y = (screen_height - texture_height) / 2.0;
|
|
|
|
image_area.width = texture_width;
|
|
|
|
image_area.height = texture_height;
|
|
|
|
|
|
|
|
/* Translate into the coordinate system of the particular monitor */
|
|
|
|
image_area.x -= monitor_rect->x;
|
|
|
|
image_area.y -= monitor_rect->y;
|
|
|
|
|
|
|
|
*texture_area = image_area;
|
|
|
|
break;
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_CENTERED:
|
|
|
|
/* paint region is the original image size centered in the actor,
|
|
|
|
* and the texture is scaled to the original image size */
|
|
|
|
image_area.width = texture_width;
|
|
|
|
image_area.height = texture_height;
|
2014-09-12 10:33:46 -04:00
|
|
|
image_area.x = monitor_rect->width / 2 - image_area.width / 2;
|
|
|
|
image_area.y = monitor_rect->height / 2 - image_area.height / 2;
|
2014-08-10 11:26:14 -04:00
|
|
|
|
|
|
|
*texture_area = image_area;
|
|
|
|
break;
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_SCALED:
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_ZOOM:
|
|
|
|
/* paint region is the actor size in one dimension, and centered and
|
|
|
|
* scaled by proportional amount in the other dimension.
|
|
|
|
*
|
|
|
|
* SCALED forces the centered dimension to fit on screen.
|
|
|
|
* ZOOM forces the centered dimension to grow off screen
|
|
|
|
*/
|
|
|
|
monitor_x_scale = monitor_rect->width / texture_width;
|
|
|
|
monitor_y_scale = monitor_rect->height / texture_height;
|
|
|
|
|
|
|
|
if ((priv->style == G_DESKTOP_BACKGROUND_STYLE_SCALED &&
|
|
|
|
(monitor_x_scale < monitor_y_scale)) ||
|
|
|
|
(priv->style == G_DESKTOP_BACKGROUND_STYLE_ZOOM &&
|
|
|
|
(monitor_x_scale > monitor_y_scale)))
|
|
|
|
{
|
|
|
|
/* Fill image to exactly fit actor horizontally */
|
|
|
|
image_area.width = monitor_rect->width;
|
|
|
|
image_area.height = texture_height * monitor_x_scale;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
/* Position image centered vertically in actor */
|
2014-09-12 10:33:46 -04:00
|
|
|
image_area.x = 0;
|
|
|
|
image_area.y = monitor_rect->height / 2 - image_area.height / 2;
|
2014-08-10 11:26:14 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Scale image to exactly fit actor vertically */
|
|
|
|
image_area.width = texture_width * monitor_y_scale;
|
|
|
|
image_area.height = monitor_rect->height;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
/* Position image centered horizontally in actor */
|
2014-09-12 10:33:46 -04:00
|
|
|
image_area.x = monitor_rect->width / 2 - image_area.width / 2;
|
|
|
|
image_area.y = 0;
|
2014-08-10 11:26:14 -04:00
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
*texture_area = image_area;
|
|
|
|
break;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_SPANNED:
|
|
|
|
{
|
|
|
|
/* paint region is the union of all monitors, with the origin
|
|
|
|
* of the region set to align with monitor associated with the background.
|
|
|
|
*/
|
|
|
|
meta_screen_get_size (priv->screen, &screen_width, &screen_height);
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
/* unclipped texture area is whole screen */
|
|
|
|
image_area.width = screen_width;
|
|
|
|
image_area.height = screen_height;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
/* But make (0,0) line up with the appropriate monitor */
|
|
|
|
image_area.x = -monitor_rect->x;
|
|
|
|
image_area.y = -monitor_rect->y;
|
|
|
|
|
|
|
|
*texture_area = image_area;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
static void
|
|
|
|
draw_texture (MetaBackground *self,
|
|
|
|
CoglFramebuffer *framebuffer,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglTexture *texture,
|
|
|
|
cairo_rectangle_int_t *monitor_area)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
|
|
|
MetaBackgroundPrivate *priv = self->priv;
|
2014-08-10 11:26:14 -04:00
|
|
|
cairo_rectangle_int_t texture_area;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
get_texture_area (self, monitor_area, texture, &texture_area);
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
switch (priv->style)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_STRETCHED:
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_WALLPAPER:
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_ZOOM:
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_SPANNED:
|
|
|
|
/* Draw the entire monitor */
|
|
|
|
cogl_framebuffer_draw_textured_rectangle (framebuffer,
|
|
|
|
pipeline,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
monitor_area->width,
|
|
|
|
monitor_area->height,
|
|
|
|
- texture_area.x / (float)texture_area.width,
|
|
|
|
- texture_area.y / (float)texture_area.height,
|
|
|
|
(monitor_area->width - texture_area.x) / (float)texture_area.width,
|
|
|
|
(monitor_area->height - texture_area.y) / (float)texture_area.height);
|
|
|
|
/* Draw just the texture */
|
|
|
|
break;
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_CENTERED:
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_SCALED:
|
|
|
|
cogl_framebuffer_draw_textured_rectangle (framebuffer,
|
|
|
|
pipeline,
|
|
|
|
texture_area.x, texture_area.y,
|
|
|
|
texture_area.x + texture_area.width,
|
|
|
|
texture_area.y + texture_area.height,
|
|
|
|
0, 0, 1.0, 1.0);
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_NONE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_return_if_reached();
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
static void
|
|
|
|
ensure_color_texture (MetaBackground *self)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
|
|
|
MetaBackgroundPrivate *priv = self->priv;
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (priv->color_texture == NULL)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
ClutterBackend *backend = clutter_get_default_backend ();
|
|
|
|
CoglContext *ctx = clutter_backend_get_cogl_context (backend);
|
2014-09-12 10:44:18 -04:00
|
|
|
uint8_t pixels[6];
|
2014-08-10 11:26:14 -04:00
|
|
|
int width, height;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (priv->shading_direction == G_DESKTOP_BACKGROUND_SHADING_SOLID)
|
|
|
|
{
|
|
|
|
width = 1;
|
|
|
|
height = 1;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
pixels[0] = priv->color.red;
|
|
|
|
pixels[1] = priv->color.green;
|
|
|
|
pixels[2] = priv->color.blue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (priv->shading_direction)
|
|
|
|
{
|
|
|
|
case G_DESKTOP_BACKGROUND_SHADING_VERTICAL:
|
|
|
|
width = 1;
|
|
|
|
height = 2;
|
|
|
|
break;
|
|
|
|
case G_DESKTOP_BACKGROUND_SHADING_HORIZONTAL:
|
|
|
|
width = 2;
|
|
|
|
height = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_return_if_reached ();
|
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
pixels[0] = priv->color.red;
|
|
|
|
pixels[1] = priv->color.green;
|
|
|
|
pixels[2] = priv->color.blue;
|
2014-09-12 10:44:18 -04:00
|
|
|
pixels[3] = priv->second_color.red;
|
|
|
|
pixels[4] = priv->second_color.green;
|
|
|
|
pixels[5] = priv->second_color.blue;
|
2014-08-10 11:26:14 -04:00
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
priv->color_texture = COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx, width, height,
|
|
|
|
COGL_PIXEL_FORMAT_RGB_888,
|
2014-09-12 10:44:18 -04:00
|
|
|
width * 3,
|
2014-08-10 11:26:14 -04:00
|
|
|
pixels,
|
|
|
|
NULL));
|
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
typedef enum {
|
|
|
|
PIPELINE_REPLACE,
|
|
|
|
PIPELINE_ADD,
|
|
|
|
PIPELINE_OVER_REVERSE,
|
|
|
|
} PipelineType;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
static CoglPipeline *
|
|
|
|
create_pipeline (PipelineType type)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
const char * const blend_strings[3] = {
|
|
|
|
[PIPELINE_REPLACE] = "RGBA = ADD (SRC_COLOR, 0)",
|
|
|
|
[PIPELINE_ADD] = "RGBA = ADD (SRC_COLOR, DST_COLOR)",
|
|
|
|
[PIPELINE_OVER_REVERSE] = "RGBA = ADD (SRC_COLOR * (1 - DST_COLOR[A]), DST_COLOR)",
|
|
|
|
};
|
|
|
|
static CoglPipeline *templates[3];
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (templates[type] == NULL)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
templates[type] = meta_create_texture_pipeline (NULL);
|
|
|
|
cogl_pipeline_set_blend (templates[type], blend_strings[type], NULL);
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
return cogl_pipeline_copy (templates[type]);
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
static gboolean
|
|
|
|
texture_has_alpha (CoglTexture *texture)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
if (!texture)
|
|
|
|
return FALSE;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
switch (cogl_texture_get_components (texture))
|
|
|
|
{
|
|
|
|
case COGL_TEXTURE_COMPONENTS_A:
|
|
|
|
case COGL_TEXTURE_COMPONENTS_RGBA:
|
|
|
|
return TRUE;
|
|
|
|
case COGL_TEXTURE_COMPONENTS_RG:
|
|
|
|
case COGL_TEXTURE_COMPONENTS_RGB:
|
|
|
|
case COGL_TEXTURE_COMPONENTS_DEPTH:
|
|
|
|
return FALSE;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
static gboolean
|
|
|
|
ensure_wallpaper_texture (MetaBackground *self,
|
|
|
|
CoglTexture *texture)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
MetaBackgroundPrivate *priv = self->priv;
|
|
|
|
|
|
|
|
if (priv->wallpaper_texture == NULL && !priv->wallpaper_allocation_failed)
|
|
|
|
{
|
|
|
|
int width = cogl_texture_get_width (texture);
|
|
|
|
int height = cogl_texture_get_height (texture);
|
|
|
|
CoglFramebuffer *fbo;
|
|
|
|
CoglError *catch_error = NULL;
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
|
|
|
|
priv->wallpaper_texture = meta_create_texture (width, height,
|
|
|
|
COGL_TEXTURE_COMPONENTS_RGBA,
|
|
|
|
META_TEXTURE_FLAGS_NONE);
|
|
|
|
fbo = cogl_offscreen_new_with_texture (priv->wallpaper_texture);
|
|
|
|
|
|
|
|
if (!cogl_framebuffer_allocate (fbo, &catch_error))
|
|
|
|
{
|
|
|
|
/* This probably means that the size of the wallpapered texture is larger
|
|
|
|
* than the maximum texture size; we treat it as permanent until the
|
|
|
|
* background is changed again.
|
|
|
|
*/
|
|
|
|
cogl_error_free (catch_error);
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
cogl_object_unref (priv->wallpaper_texture);
|
|
|
|
priv->wallpaper_texture = NULL;
|
|
|
|
cogl_object_unref (fbo);
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
priv->wallpaper_allocation_failed = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
cogl_framebuffer_orthographic (fbo, 0, 0,
|
|
|
|
width, height, -1., 1.);
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
pipeline = create_pipeline (PIPELINE_REPLACE);
|
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, texture);
|
|
|
|
cogl_framebuffer_draw_textured_rectangle (fbo, pipeline, 0, 0, width, height,
|
|
|
|
0., 0., 1., 1.);
|
|
|
|
cogl_object_unref (pipeline);
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (texture_has_alpha (texture))
|
|
|
|
{
|
|
|
|
ensure_color_texture (self);
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
pipeline = create_pipeline (PIPELINE_OVER_REVERSE);
|
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, priv->color_texture);
|
|
|
|
cogl_framebuffer_draw_rectangle (fbo, pipeline, 0, 0, width, height);
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
cogl_object_unref (fbo);
|
|
|
|
}
|
2014-08-07 13:35:35 -04:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
return priv->wallpaper_texture != NULL;
|
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
static CoglPipelineWrapMode
|
|
|
|
get_wrap_mode (GDesktopBackgroundStyle style)
|
|
|
|
{
|
|
|
|
switch (style)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_WALLPAPER:
|
|
|
|
return COGL_PIPELINE_WRAP_MODE_REPEAT;
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_NONE:
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_STRETCHED:
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_CENTERED:
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_SCALED:
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_ZOOM:
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_SPANNED:
|
|
|
|
default:
|
|
|
|
return COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE;
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
2014-08-10 11:26:14 -04:00
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
CoglTexture *
|
|
|
|
meta_background_get_texture (MetaBackground *self,
|
|
|
|
int monitor_index,
|
|
|
|
cairo_rectangle_int_t *texture_area,
|
|
|
|
CoglPipelineWrapMode *wrap_mode)
|
|
|
|
{
|
|
|
|
MetaBackgroundPrivate *priv;
|
|
|
|
MetaBackgroundMonitor *monitor;
|
|
|
|
MetaRectangle geometry;
|
|
|
|
cairo_rectangle_int_t monitor_area;
|
|
|
|
CoglTexture *texture1, *texture2;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-09-03 14:03:17 -04:00
|
|
|
g_return_val_if_fail (META_IS_BACKGROUND (self), NULL);
|
2014-08-10 11:26:14 -04:00
|
|
|
priv = self->priv;
|
2014-09-06 12:21:20 -04:00
|
|
|
g_return_val_if_fail (monitor_index >= 0 && monitor_index < priv->n_monitors, NULL);
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
monitor = &priv->monitors[monitor_index];
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
meta_screen_get_monitor_geometry (priv->screen, monitor_index, &geometry);
|
|
|
|
monitor_area.x = geometry.x;
|
|
|
|
monitor_area.y = geometry.y;
|
|
|
|
monitor_area.width = geometry.width;
|
|
|
|
monitor_area.height = geometry.height;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
texture1 = priv->background_image1 ? meta_background_image_get_texture (priv->background_image1) : NULL;
|
|
|
|
texture2 = priv->background_image2 ? meta_background_image_get_texture (priv->background_image2) : NULL;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (texture1 == NULL && texture2 == NULL)
|
|
|
|
{
|
|
|
|
ensure_color_texture (self);
|
|
|
|
if (texture_area)
|
2014-09-12 10:33:46 -04:00
|
|
|
set_texture_area_from_monitor_area (&monitor_area, texture_area);
|
2014-08-10 11:26:14 -04:00
|
|
|
if (wrap_mode)
|
|
|
|
*wrap_mode = COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE;
|
|
|
|
return priv->color_texture;
|
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (texture2 == NULL && priv->style == G_DESKTOP_BACKGROUND_STYLE_WALLPAPER &&
|
|
|
|
priv->shading_direction == G_DESKTOP_BACKGROUND_SHADING_SOLID &&
|
|
|
|
ensure_wallpaper_texture (self, texture1))
|
|
|
|
{
|
|
|
|
if (texture_area)
|
|
|
|
get_texture_area (self, &monitor_area, priv->wallpaper_texture,
|
|
|
|
texture_area);
|
|
|
|
if (wrap_mode)
|
|
|
|
*wrap_mode = COGL_PIPELINE_WRAP_MODE_REPEAT;
|
|
|
|
return priv->wallpaper_texture;
|
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (monitor->dirty)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
CoglError *catch_error = NULL;
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (monitor->texture == NULL)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
monitor->texture = meta_create_texture (monitor_area.width, monitor_area.height,
|
|
|
|
COGL_TEXTURE_COMPONENTS_RGBA,
|
|
|
|
META_TEXTURE_FLAGS_NONE);
|
|
|
|
monitor->fbo = cogl_offscreen_new_with_texture (monitor->texture);
|
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (!cogl_framebuffer_allocate (monitor->fbo, &catch_error))
|
|
|
|
{
|
|
|
|
/* Texture or framebuffer allocation failed; it's unclear why this happened;
|
|
|
|
* we'll try again the next time this is called. (MetaBackgroundActor
|
|
|
|
* caches the result, so user might be left without a background.)
|
|
|
|
*/
|
|
|
|
cogl_object_unref (monitor->texture);
|
|
|
|
monitor->texture = NULL;
|
|
|
|
cogl_object_unref (monitor->fbo);
|
|
|
|
monitor->fbo = NULL;
|
|
|
|
|
|
|
|
cogl_error_free (catch_error);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cogl_framebuffer_orthographic (monitor->fbo, 0, 0,
|
|
|
|
monitor_area.width, monitor_area.height, -1., 1.);
|
|
|
|
|
|
|
|
if (texture2 != NULL && priv->blend_factor != 0.0)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline = create_pipeline (PIPELINE_REPLACE);
|
|
|
|
cogl_pipeline_set_color4f (pipeline,
|
|
|
|
priv->blend_factor, priv->blend_factor, priv->blend_factor, priv->blend_factor);
|
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, texture2);
|
|
|
|
cogl_pipeline_set_layer_wrap_mode (pipeline, 0, get_wrap_mode (priv->style));
|
|
|
|
|
|
|
|
draw_texture (self,
|
|
|
|
monitor->fbo, pipeline,
|
|
|
|
texture2, &monitor_area);
|
|
|
|
|
|
|
|
cogl_object_unref (pipeline);
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
cogl_framebuffer_clear4f (monitor->fbo,
|
|
|
|
COGL_BUFFER_BIT_COLOR,
|
|
|
|
0.0, 0.0, 0.0, 0.0);
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (texture1 != NULL &&
|
|
|
|
!(texture2 != NULL && priv->blend_factor == 1.0 && !texture_has_alpha (texture2)))
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline = create_pipeline (PIPELINE_ADD);
|
|
|
|
cogl_pipeline_set_color4f (pipeline,
|
|
|
|
(1 - priv->blend_factor),
|
|
|
|
(1 - priv->blend_factor),
|
|
|
|
(1 - priv->blend_factor),
|
|
|
|
(1 - priv->blend_factor));;
|
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, texture1);
|
|
|
|
cogl_pipeline_set_layer_wrap_mode (pipeline, 0, get_wrap_mode (priv->style));
|
|
|
|
|
|
|
|
draw_texture (self,
|
|
|
|
monitor->fbo, pipeline,
|
|
|
|
texture1, &monitor_area);
|
|
|
|
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (!((texture2 != NULL && priv->blend_factor == 1.0 && !texture_has_alpha (texture2)) ||
|
|
|
|
(texture1 != NULL && !texture_has_alpha (texture1))))
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
CoglPipeline *pipeline = create_pipeline (PIPELINE_OVER_REVERSE);
|
|
|
|
|
|
|
|
ensure_color_texture (self);
|
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, priv->color_texture);
|
|
|
|
cogl_framebuffer_draw_rectangle (monitor->fbo,
|
|
|
|
pipeline,
|
|
|
|
0, 0,
|
|
|
|
monitor_area.width, monitor_area.height);
|
|
|
|
cogl_object_unref (pipeline);
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
monitor->dirty = FALSE;
|
|
|
|
}
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (texture_area)
|
2014-09-12 10:33:46 -04:00
|
|
|
set_texture_area_from_monitor_area (&monitor_area, texture_area);
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
if (wrap_mode)
|
|
|
|
*wrap_mode = COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE;
|
|
|
|
return monitor->texture;
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
2014-08-10 11:26:14 -04:00
|
|
|
|
2013-01-23 15:54:41 -05:00
|
|
|
MetaBackground *
|
2014-08-10 11:26:14 -04:00
|
|
|
meta_background_new (MetaScreen *screen)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
return g_object_new (META_TYPE_BACKGROUND,
|
2014-09-03 22:55:05 -04:00
|
|
|
"meta-screen", screen,
|
2014-08-10 11:26:14 -04:00
|
|
|
NULL);
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
void
|
|
|
|
meta_background_set_color (MetaBackground *self,
|
|
|
|
ClutterColor *color)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
ClutterColor dummy = { 0 };
|
2013-01-23 15:54:41 -05:00
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
g_return_if_fail (META_IS_BACKGROUND (self));
|
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
|
|
|
|
meta_background_set_gradient (self,
|
|
|
|
G_DESKTOP_BACKGROUND_SHADING_SOLID,
|
|
|
|
color, &dummy);
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
void
|
|
|
|
meta_background_set_gradient (MetaBackground *self,
|
|
|
|
GDesktopBackgroundShading shading_direction,
|
|
|
|
ClutterColor *color,
|
|
|
|
ClutterColor *second_color)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
MetaBackgroundPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (META_IS_BACKGROUND (self));
|
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
g_return_if_fail (second_color != NULL);
|
|
|
|
|
|
|
|
priv = self->priv;
|
|
|
|
|
|
|
|
priv->shading_direction = shading_direction;
|
|
|
|
priv->color = *color;
|
|
|
|
priv->second_color = *second_color;
|
|
|
|
|
|
|
|
free_color_texture (self);
|
|
|
|
free_wallpaper_texture (self);
|
|
|
|
mark_changed (self);
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
void
|
|
|
|
meta_background_set_filename (MetaBackground *self,
|
|
|
|
const char *filename,
|
|
|
|
GDesktopBackgroundStyle style)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
g_return_if_fail (META_IS_BACKGROUND (self));
|
|
|
|
|
|
|
|
meta_background_set_blend (self, filename, NULL, 0.0, style);
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:26:14 -04:00
|
|
|
void
|
|
|
|
meta_background_set_blend (MetaBackground *self,
|
|
|
|
const char *filename1,
|
|
|
|
const char *filename2,
|
|
|
|
double blend_factor,
|
|
|
|
GDesktopBackgroundStyle style)
|
2013-01-23 15:54:41 -05:00
|
|
|
{
|
2014-08-10 11:26:14 -04:00
|
|
|
MetaBackgroundPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (META_IS_BACKGROUND (self));
|
|
|
|
g_return_if_fail (blend_factor >= 0.0 && blend_factor <= 1.0);
|
|
|
|
|
|
|
|
priv = self->priv;
|
|
|
|
|
|
|
|
set_filename (self, &priv->filename1, &priv->background_image1, filename1);
|
|
|
|
set_filename (self, &priv->filename2, &priv->background_image2, filename2);
|
|
|
|
|
|
|
|
priv->blend_factor = blend_factor;
|
|
|
|
priv->style = style;
|
|
|
|
|
|
|
|
free_wallpaper_texture (self);
|
|
|
|
mark_changed (self);
|
2013-01-23 15:54:41 -05:00
|
|
|
}
|