2013-01-23 20:54:41 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
2013-03-11 15:52:36 +00:00
|
|
|
|
2013-01-23 20:54:41 +00: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-12 01:42:06 +00:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2013-01-23 20:54:41 +00:00
|
|
|
*/
|
|
|
|
|
2018-07-10 08:36:24 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "compositor/meta-background-private.h"
|
2013-03-11 15:52:36 +00:00
|
|
|
|
2015-09-03 17:57:25 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2020-01-13 13:02:39 +00:00
|
|
|
#include "backends/meta-backend-private.h"
|
2018-07-10 08:36:24 +00:00
|
|
|
#include "compositor/cogl-utils.h"
|
|
|
|
#include "meta/display.h"
|
|
|
|
#include "meta/meta-background-image.h"
|
|
|
|
#include "meta/meta-background.h"
|
|
|
|
#include "meta/meta-monitor-manager.h"
|
|
|
|
#include "meta/util.h"
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CHANGED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
typedef struct _MetaBackgroundMonitor MetaBackgroundMonitor;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
struct _MetaBackgroundMonitor
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
gboolean dirty;
|
|
|
|
CoglTexture *texture;
|
2016-05-07 14:21:24 +00:00
|
|
|
CoglFramebuffer *fbo;
|
2014-08-10 15:26:14 +00:00
|
|
|
};
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
struct _MetaBackground
|
2014-08-10 15:26:14 +00:00
|
|
|
{
|
2018-10-31 10:47:17 +00:00
|
|
|
GObject parent;
|
|
|
|
|
2017-08-26 19:22:34 +00:00
|
|
|
MetaDisplay *display;
|
2014-08-10 15:26:14 +00:00
|
|
|
MetaBackgroundMonitor *monitors;
|
|
|
|
int n_monitors;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
|
|
|
GDesktopBackgroundStyle style;
|
|
|
|
GDesktopBackgroundShading shading_direction;
|
|
|
|
ClutterColor color;
|
|
|
|
ClutterColor second_color;
|
|
|
|
|
2014-09-19 01:22:39 +00:00
|
|
|
GFile *file1;
|
2014-08-10 15:26:14 +00:00
|
|
|
MetaBackgroundImage *background_image1;
|
2014-09-19 01:22:39 +00:00
|
|
|
GFile *file2;
|
2014-08-10 15:26:14 +00:00
|
|
|
MetaBackgroundImage *background_image2;
|
|
|
|
|
|
|
|
CoglTexture *color_texture;
|
|
|
|
CoglTexture *wallpaper_texture;
|
|
|
|
|
|
|
|
float blend_factor;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
guint wallpaper_allocation_failed : 1;
|
2013-01-23 20:54:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2017-08-26 19:22:34 +00:00
|
|
|
PROP_META_DISPLAY = 1,
|
2013-01-23 20:54:41 +00:00
|
|
|
PROP_MONITOR,
|
|
|
|
};
|
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
G_DEFINE_TYPE (MetaBackground, meta_background, G_TYPE_OBJECT)
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2015-09-03 17:57:25 +00:00
|
|
|
static gboolean texture_has_alpha (CoglTexture *texture);
|
|
|
|
|
2015-03-19 13:58:25 +00:00
|
|
|
static GSList *all_backgrounds = NULL;
|
|
|
|
|
2013-01-23 20:54:41 +00:00
|
|
|
static void
|
2014-08-10 15:26:14 +00:00
|
|
|
free_fbos (MetaBackground *self)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
int i;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
for (i = 0; i < self->n_monitors; i++)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2018-10-31 10:47:17 +00:00
|
|
|
MetaBackgroundMonitor *monitor = &self->monitors[i];
|
2020-10-13 09:35:47 +00:00
|
|
|
|
|
|
|
g_clear_object (&monitor->fbo);
|
2023-09-18 14:58:36 +00:00
|
|
|
g_clear_object (&monitor->texture);
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
static void
|
|
|
|
free_color_texture (MetaBackground *self)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2023-09-18 14:58:36 +00:00
|
|
|
g_clear_object (&self->color_texture);
|
2014-08-07 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
static void
|
|
|
|
free_wallpaper_texture (MetaBackground *self)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2023-09-18 14:58:36 +00:00
|
|
|
g_clear_object (&self->wallpaper_texture);
|
2014-08-07 16:38:42 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
self->wallpaper_allocation_failed = FALSE;
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-08-26 16:37:29 +00:00
|
|
|
invalidate_monitor_backgrounds (MetaBackground *self)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
free_fbos (self);
|
2020-10-14 19:16:13 +00:00
|
|
|
g_clear_pointer (&self->monitors, g_free);
|
2018-10-31 10:47:17 +00:00
|
|
|
self->n_monitors = 0;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
if (self->display)
|
2014-08-10 15:26:14 +00:00
|
|
|
{
|
2014-09-12 18:47:18 +00:00
|
|
|
int i;
|
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
self->n_monitors = meta_display_get_n_monitors (self->display);
|
|
|
|
self->monitors = g_new0 (MetaBackgroundMonitor, self->n_monitors);
|
2014-09-12 18:47:18 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
for (i = 0; i < self->n_monitors; i++)
|
|
|
|
self->monitors[i].dirty = TRUE;
|
2014-08-10 15:26:14 +00:00
|
|
|
}
|
2013-02-25 02:24:54 +00:00
|
|
|
}
|
|
|
|
|
2017-08-26 16:37:29 +00:00
|
|
|
static void
|
2017-08-27 18:44:38 +00:00
|
|
|
on_monitors_changed (MetaBackground *self)
|
2017-08-26 16:37:29 +00:00
|
|
|
{
|
|
|
|
invalidate_monitor_backgrounds (self);
|
|
|
|
}
|
|
|
|
|
2013-01-23 20:54:41 +00:00
|
|
|
static void
|
2017-08-26 19:22:34 +00:00
|
|
|
set_display (MetaBackground *self,
|
|
|
|
MetaDisplay *display)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2018-10-31 10:47:17 +00:00
|
|
|
g_set_object (&self->display, display);
|
2014-08-07 18:59:59 +00:00
|
|
|
|
2017-08-26 16:37:29 +00:00
|
|
|
invalidate_monitor_backgrounds (self);
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-10 15:26:14 +00:00
|
|
|
meta_background_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
2017-08-26 19:22:34 +00:00
|
|
|
case PROP_META_DISPLAY:
|
|
|
|
set_display (META_BACKGROUND (object), g_value_get_object (value));
|
2014-08-10 15:26:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-10 15:26:14 +00:00
|
|
|
meta_background_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2018-10-31 10:47:17 +00:00
|
|
|
MetaBackground *self = META_BACKGROUND (object);
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
2017-08-26 19:22:34 +00:00
|
|
|
case PROP_META_DISPLAY:
|
2018-10-31 10:47:17 +00:00
|
|
|
g_value_set_object (value, self->display);
|
2014-08-10 15:26:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
static gboolean
|
|
|
|
need_prerender (MetaBackground *self)
|
2013-04-23 09:02:04 +00:00
|
|
|
{
|
2018-10-31 10:47:17 +00:00
|
|
|
CoglTexture *texture1 = self->background_image1 ? meta_background_image_get_texture (self->background_image1) : NULL;
|
|
|
|
CoglTexture *texture2 = self->background_image2 ? meta_background_image_get_texture (self->background_image2) : NULL;
|
2013-04-23 09:02:04 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
if (texture1 == NULL && texture2 == NULL)
|
|
|
|
return FALSE;
|
2013-04-23 09:02:04 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
if (texture2 == NULL && self->style == G_DESKTOP_BACKGROUND_STYLE_WALLPAPER)
|
2014-08-10 15:26:14 +00:00
|
|
|
return FALSE;
|
2013-04-23 09:02:04 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
return TRUE;
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-10 15:26:14 +00:00
|
|
|
mark_changed (MetaBackground *self)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
int i;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
if (!need_prerender (self))
|
|
|
|
free_fbos (self);
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
for (i = 0; i < self->n_monitors; i++)
|
|
|
|
self->monitors[i].dirty = TRUE;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
g_signal_emit (self, signals[CHANGED], 0);
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-10 15:26:14 +00:00
|
|
|
on_background_loaded (MetaBackgroundImage *image,
|
|
|
|
MetaBackground *self)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
mark_changed (self);
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2014-09-19 01:22:39 +00:00
|
|
|
static gboolean
|
|
|
|
file_equal0 (GFile *file1,
|
|
|
|
GFile *file2)
|
|
|
|
{
|
|
|
|
if (file1 == file2)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if ((file1 == NULL) || (file2 == NULL))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_file_equal (file1, file2);
|
|
|
|
}
|
|
|
|
|
2013-01-23 20:54:41 +00:00
|
|
|
static void
|
2014-09-19 01:22:39 +00:00
|
|
|
set_file (MetaBackground *self,
|
|
|
|
GFile **filep,
|
|
|
|
MetaBackgroundImage **imagep,
|
2019-05-23 10:15:28 +00:00
|
|
|
GFile *file,
|
|
|
|
gboolean force_reload)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2019-05-23 10:15:28 +00:00
|
|
|
if (force_reload || !file_equal0 (*filep, file))
|
2014-08-10 15:26:14 +00:00
|
|
|
{
|
|
|
|
if (*imagep)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (*imagep,
|
|
|
|
(gpointer)on_background_loaded,
|
|
|
|
self);
|
2020-10-14 19:16:13 +00:00
|
|
|
g_clear_object (imagep);
|
2014-08-10 15:26:14 +00:00
|
|
|
}
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2019-05-23 10:15:28 +00:00
|
|
|
g_set_object (filep, file);
|
|
|
|
|
2014-09-19 01:22:39 +00:00
|
|
|
if (file)
|
2014-08-10 15:26:14 +00:00
|
|
|
{
|
|
|
|
MetaBackgroundImageCache *cache = meta_background_image_cache_get_default ();
|
2014-09-19 01:22:39 +00:00
|
|
|
|
|
|
|
*imagep = meta_background_image_cache_load (cache, file);
|
2014-08-10 15:26:14 +00:00
|
|
|
g_signal_connect (*imagep, "loaded",
|
|
|
|
G_CALLBACK (on_background_loaded), self);
|
|
|
|
}
|
|
|
|
}
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 10:15:28 +00:00
|
|
|
static void
|
|
|
|
on_gl_video_memory_purged (MetaBackground *self)
|
|
|
|
{
|
|
|
|
MetaBackgroundImageCache *cache = meta_background_image_cache_get_default ();
|
|
|
|
|
|
|
|
/* The GPU memory that just got invalidated is the texture inside
|
|
|
|
* self->background_image1,2 and/or its mipmaps. However, to save memory the
|
|
|
|
* original pixbuf isn't kept in RAM so we can't do a simple re-upload. The
|
|
|
|
* only copy of the image was the one in texture memory that got invalidated.
|
|
|
|
* So we need to do a full reload from disk.
|
|
|
|
*/
|
|
|
|
if (self->file1)
|
|
|
|
{
|
|
|
|
meta_background_image_cache_purge (cache, self->file1);
|
|
|
|
set_file (self, &self->file1, &self->background_image1, self->file1, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self->file2)
|
|
|
|
{
|
|
|
|
meta_background_image_cache_purge (cache, self->file2);
|
|
|
|
set_file (self, &self->file2, &self->background_image2, self->file2, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
mark_changed (self);
|
|
|
|
}
|
|
|
|
|
2013-01-23 20:54:41 +00:00
|
|
|
static void
|
2014-08-10 15:26:14 +00:00
|
|
|
meta_background_dispose (GObject *object)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
MetaBackground *self = META_BACKGROUND (object);
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
free_color_texture (self);
|
|
|
|
free_wallpaper_texture (self);
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2019-05-23 10:15:28 +00:00
|
|
|
set_file (self, &self->file1, &self->background_image1, NULL, FALSE);
|
|
|
|
set_file (self, &self->file2, &self->background_image2, NULL, FALSE);
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2017-08-26 19:22:34 +00:00
|
|
|
set_display (self, NULL);
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
G_OBJECT_CLASS (meta_background_parent_class)->dispose (object);
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-10 15:26:14 +00:00
|
|
|
meta_background_finalize (GObject *object)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2015-03-19 13:58:25 +00:00
|
|
|
all_backgrounds = g_slist_remove (all_backgrounds, object);
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
G_OBJECT_CLASS (meta_background_parent_class)->finalize (object);
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2016-05-29 17:58:25 +00:00
|
|
|
static void
|
|
|
|
meta_background_constructed (GObject *object)
|
|
|
|
{
|
2022-05-27 20:17:13 +00:00
|
|
|
MetaBackground *self = META_BACKGROUND (object);
|
|
|
|
MetaContext *context = meta_display_get_context (self->display);
|
|
|
|
MetaBackend *backend = meta_context_get_backend (context);
|
|
|
|
MetaMonitorManager *monitor_manager =
|
|
|
|
meta_backend_get_monitor_manager (backend);
|
2016-05-29 17:58:25 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_background_parent_class)->constructed (object);
|
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
g_signal_connect_object (self->display, "gl-video-memory-purged",
|
2019-05-23 10:15:28 +00:00
|
|
|
G_CALLBACK (on_gl_video_memory_purged), object, G_CONNECT_SWAPPED);
|
2017-08-27 18:44:38 +00:00
|
|
|
|
|
|
|
g_signal_connect_object (monitor_manager, "monitors-changed",
|
|
|
|
G_CALLBACK (on_monitors_changed), self,
|
|
|
|
G_CONNECT_SWAPPED);
|
2016-05-29 17:58:25 +00:00
|
|
|
}
|
|
|
|
|
2013-01-23 20:54:41 +00:00
|
|
|
static void
|
|
|
|
meta_background_class_init (MetaBackgroundClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2014-08-10 15:26:14 +00:00
|
|
|
GParamSpec *param_spec;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
|
|
|
object_class->dispose = meta_background_dispose;
|
2013-04-23 09:02:04 +00:00
|
|
|
object_class->finalize = meta_background_finalize;
|
2016-05-29 17:58:25 +00:00
|
|
|
object_class->constructed = meta_background_constructed;
|
2013-01-23 20:54:41 +00:00
|
|
|
object_class->set_property = meta_background_set_property;
|
|
|
|
object_class->get_property = meta_background_get_property;
|
|
|
|
|
2014-08-10 15:26:14 +00: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);
|
|
|
|
|
2023-06-28 12:02:43 +00:00
|
|
|
param_spec = g_param_spec_object ("meta-display", NULL, NULL,
|
2017-08-26 19:22:34 +00:00
|
|
|
META_TYPE_DISPLAY,
|
2014-08-10 15:26:14 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
|
2013-01-23 20:54:41 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
2017-08-26 19:22:34 +00:00
|
|
|
PROP_META_DISPLAY,
|
2013-01-23 20:54:41 +00:00
|
|
|
param_spec);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_background_init (MetaBackground *self)
|
|
|
|
{
|
2015-03-19 13:58:25 +00:00
|
|
|
all_backgrounds = g_slist_prepend (all_backgrounds, self);
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2014-09-12 14:33:46 +00:00
|
|
|
static void
|
2023-07-19 14:59:04 +00:00
|
|
|
set_texture_area_from_monitor_area (MtkRectangle *monitor_area,
|
|
|
|
MtkRectangle *texture_area)
|
2014-09-12 14:33:46 +00:00
|
|
|
{
|
|
|
|
texture_area->x = 0;
|
|
|
|
texture_area->y = 0;
|
|
|
|
texture_area->width = monitor_area->width;
|
|
|
|
texture_area->height = monitor_area->height;
|
|
|
|
}
|
|
|
|
|
2013-01-23 20:54:41 +00:00
|
|
|
static void
|
2023-07-19 23:46:15 +00:00
|
|
|
get_texture_area (MetaBackground *self,
|
|
|
|
MtkRectangle *monitor_rect,
|
|
|
|
float monitor_scale,
|
|
|
|
CoglTexture *texture,
|
|
|
|
MtkRectangle *texture_area)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2023-07-19 14:59:04 +00:00
|
|
|
MtkRectangle image_area;
|
2014-08-10 15:26:14 +00:00
|
|
|
int screen_width, screen_height;
|
|
|
|
float texture_width, texture_height;
|
|
|
|
float monitor_x_scale, monitor_y_scale;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
texture_width = cogl_texture_get_width (texture);
|
|
|
|
texture_height = cogl_texture_get_height (texture);
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
switch (self->style)
|
2014-08-10 15:26:14 +00:00
|
|
|
{
|
|
|
|
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 14:33:46 +00:00
|
|
|
set_texture_area_from_monitor_area (monitor_rect, texture_area);
|
2014-08-10 15:26:14 +00:00
|
|
|
break;
|
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_WALLPAPER:
|
2018-10-31 10:47:17 +00:00
|
|
|
meta_display_get_size (self->display, &screen_width, &screen_height);
|
2014-08-10 15:26:14 +00:00
|
|
|
|
|
|
|
/* Start off by centering a tile in the middle of the
|
2017-08-03 13:48:51 +00:00
|
|
|
* total screen area taking care of the monitor scaling.
|
2014-08-10 15:26:14 +00:00
|
|
|
*/
|
|
|
|
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 14:33:46 +00: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 15:26:14 +00: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;
|
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
if ((self->style == G_DESKTOP_BACKGROUND_STYLE_SCALED &&
|
2014-08-10 15:26:14 +00:00
|
|
|
(monitor_x_scale < monitor_y_scale)) ||
|
2018-10-31 10:47:17 +00:00
|
|
|
(self->style == G_DESKTOP_BACKGROUND_STYLE_ZOOM &&
|
2014-08-10 15:26:14 +00:00
|
|
|
(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 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
/* Position image centered vertically in actor */
|
2014-09-12 14:33:46 +00:00
|
|
|
image_area.x = 0;
|
|
|
|
image_area.y = monitor_rect->height / 2 - image_area.height / 2;
|
2014-08-10 15:26:14 +00: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 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
/* Position image centered horizontally in actor */
|
2014-09-12 14:33:46 +00:00
|
|
|
image_area.x = monitor_rect->width / 2 - image_area.width / 2;
|
|
|
|
image_area.y = 0;
|
2014-08-10 15:26:14 +00:00
|
|
|
}
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
*texture_area = image_area;
|
|
|
|
break;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00: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.
|
|
|
|
*/
|
2018-10-31 10:47:17 +00:00
|
|
|
meta_display_get_size (self->display, &screen_width, &screen_height);
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2017-08-03 13:48:51 +00:00
|
|
|
/* unclipped texture area is whole screen, scaled depending on monitor */
|
|
|
|
image_area.width = screen_width * monitor_scale;
|
|
|
|
image_area.height = screen_height * monitor_scale;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00: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 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 17:57:25 +00:00
|
|
|
static gboolean
|
2023-07-19 23:46:15 +00:00
|
|
|
draw_texture (MetaBackground *self,
|
|
|
|
CoglFramebuffer *framebuffer,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglTexture *texture,
|
|
|
|
MtkRectangle *monitor_area,
|
|
|
|
float monitor_scale)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2023-07-19 14:59:04 +00:00
|
|
|
MtkRectangle texture_area;
|
2015-09-03 17:57:25 +00:00
|
|
|
gboolean bare_region_visible;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2017-08-03 13:48:51 +00:00
|
|
|
get_texture_area (self, monitor_area, monitor_scale, texture, &texture_area);
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
switch (self->style)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00: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);
|
2015-09-03 17:57:25 +00:00
|
|
|
|
|
|
|
bare_region_visible = texture_has_alpha (texture);
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
/* 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);
|
2023-07-19 14:59:04 +00:00
|
|
|
bare_region_visible = texture_has_alpha (texture) || memcmp (&texture_area, monitor_area, sizeof (MtkRectangle)) != 0;
|
2015-09-03 17:57:25 +00:00
|
|
|
break;
|
2014-08-10 15:26:14 +00:00
|
|
|
case G_DESKTOP_BACKGROUND_STYLE_NONE:
|
2015-09-03 17:57:25 +00:00
|
|
|
bare_region_visible = TRUE;
|
2014-08-10 15:26:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
2015-09-04 03:44:34 +00:00
|
|
|
g_return_val_if_reached(FALSE);
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
2015-09-03 17:57:25 +00:00
|
|
|
|
|
|
|
return bare_region_visible;
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
static void
|
|
|
|
ensure_color_texture (MetaBackground *self)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2018-10-31 10:47:17 +00:00
|
|
|
if (self->color_texture == NULL)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
ClutterBackend *backend = clutter_get_default_backend ();
|
|
|
|
CoglContext *ctx = clutter_backend_get_cogl_context (backend);
|
2019-06-18 06:02:10 +00:00
|
|
|
GError *error = NULL;
|
2014-09-12 14:44:18 +00:00
|
|
|
uint8_t pixels[6];
|
2014-08-10 15:26:14 +00:00
|
|
|
int width, height;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
if (self->shading_direction == G_DESKTOP_BACKGROUND_SHADING_SOLID)
|
2014-08-10 15:26:14 +00:00
|
|
|
{
|
|
|
|
width = 1;
|
|
|
|
height = 1;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
pixels[0] = self->color.red;
|
|
|
|
pixels[1] = self->color.green;
|
|
|
|
pixels[2] = self->color.blue;
|
2014-08-10 15:26:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-31 10:47:17 +00:00
|
|
|
switch (self->shading_direction)
|
2014-08-10 15:26:14 +00:00
|
|
|
{
|
|
|
|
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 20:54:41 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
pixels[0] = self->color.red;
|
|
|
|
pixels[1] = self->color.green;
|
|
|
|
pixels[2] = self->color.blue;
|
|
|
|
pixels[3] = self->second_color.red;
|
|
|
|
pixels[4] = self->second_color.green;
|
|
|
|
pixels[5] = self->second_color.blue;
|
2014-08-10 15:26:14 +00:00
|
|
|
}
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2023-09-18 14:58:36 +00:00
|
|
|
self->color_texture = cogl_texture_2d_new_from_data (ctx, width, height,
|
|
|
|
COGL_PIXEL_FORMAT_RGB_888,
|
|
|
|
width * 3,
|
|
|
|
pixels,
|
|
|
|
&error);
|
2016-04-14 13:30:31 +00:00
|
|
|
|
|
|
|
if (error != NULL)
|
|
|
|
{
|
2020-10-02 15:47:22 +00:00
|
|
|
meta_warning ("Failed to allocate color texture: %s", error->message);
|
2019-06-18 06:02:10 +00:00
|
|
|
g_error_free (error);
|
2016-04-14 13:30:31 +00:00
|
|
|
}
|
2014-08-10 15:26:14 +00:00
|
|
|
}
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2018-12-19 08:04:25 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
PIPELINE_REPLACE,
|
|
|
|
PIPELINE_ADD,
|
|
|
|
PIPELINE_OVER_REVERSE,
|
|
|
|
} PipelineType;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
static CoglPipeline *
|
|
|
|
create_pipeline (PipelineType type)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00: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 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
if (templates[type] == NULL)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
templates[type] = meta_create_texture_pipeline (NULL);
|
|
|
|
cogl_pipeline_set_blend (templates[type], blend_strings[type], NULL);
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2018-11-15 07:39:34 +00:00
|
|
|
cogl_pipeline_set_layer_filters (templates[type],
|
|
|
|
0,
|
2019-03-25 03:27:38 +00:00
|
|
|
COGL_PIPELINE_FILTER_LINEAR_MIPMAP_LINEAR,
|
2018-11-15 07:39:34 +00:00
|
|
|
COGL_PIPELINE_FILTER_LINEAR);
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
return cogl_pipeline_copy (templates[type]);
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
static gboolean
|
|
|
|
texture_has_alpha (CoglTexture *texture)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
if (!texture)
|
|
|
|
return FALSE;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00: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 ();
|
2019-01-24 23:47:44 +00:00
|
|
|
return FALSE;
|
2014-08-10 15:26:14 +00:00
|
|
|
}
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
static gboolean
|
|
|
|
ensure_wallpaper_texture (MetaBackground *self,
|
|
|
|
CoglTexture *texture)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2018-10-31 10:47:17 +00:00
|
|
|
if (self->wallpaper_texture == NULL && !self->wallpaper_allocation_failed)
|
2014-08-10 15:26:14 +00:00
|
|
|
{
|
|
|
|
int width = cogl_texture_get_width (texture);
|
|
|
|
int height = cogl_texture_get_height (texture);
|
2016-05-07 14:21:24 +00:00
|
|
|
CoglOffscreen *offscreen;
|
2014-08-10 15:26:14 +00:00
|
|
|
CoglFramebuffer *fbo;
|
2019-06-18 06:02:10 +00:00
|
|
|
GError *catch_error = NULL;
|
2014-08-10 15:26:14 +00:00
|
|
|
CoglPipeline *pipeline;
|
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
self->wallpaper_texture = meta_create_texture (width, height,
|
2014-08-10 15:26:14 +00:00
|
|
|
COGL_TEXTURE_COMPONENTS_RGBA,
|
|
|
|
META_TEXTURE_FLAGS_NONE);
|
2018-10-31 10:47:17 +00:00
|
|
|
offscreen = cogl_offscreen_new_with_texture (self->wallpaper_texture);
|
2016-05-07 14:21:24 +00:00
|
|
|
fbo = COGL_FRAMEBUFFER (offscreen);
|
2014-08-10 15:26:14 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2019-06-18 06:02:10 +00:00
|
|
|
g_error_free (catch_error);
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2023-09-18 14:58:36 +00:00
|
|
|
g_clear_object (&self->wallpaper_texture);
|
2020-10-13 09:35:47 +00:00
|
|
|
g_object_unref (fbo);
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
self->wallpaper_allocation_failed = TRUE;
|
2014-08-10 15:26:14 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
cogl_framebuffer_orthographic (fbo, 0, 0,
|
|
|
|
width, height, -1., 1.);
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00: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.);
|
2023-09-19 09:16:43 +00:00
|
|
|
g_object_unref (pipeline);
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
if (texture_has_alpha (texture))
|
|
|
|
{
|
|
|
|
ensure_color_texture (self);
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
pipeline = create_pipeline (PIPELINE_OVER_REVERSE);
|
2018-10-31 10:47:17 +00:00
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, self->color_texture);
|
2014-08-10 15:26:14 +00:00
|
|
|
cogl_framebuffer_draw_rectangle (fbo, pipeline, 0, 0, width, height);
|
2023-09-19 09:16:43 +00:00
|
|
|
g_object_unref (pipeline);
|
2014-08-10 15:26:14 +00:00
|
|
|
}
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2020-10-13 09:35:47 +00:00
|
|
|
g_object_unref (fbo);
|
2014-08-10 15:26:14 +00:00
|
|
|
}
|
2014-08-07 17:35:35 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
return self->wallpaper_texture != NULL;
|
2014-08-10 15:26:14 +00:00
|
|
|
}
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
static CoglPipelineWrapMode
|
|
|
|
get_wrap_mode (GDesktopBackgroundStyle style)
|
|
|
|
{
|
|
|
|
switch (style)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00: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 20:54:41 +00:00
|
|
|
}
|
2014-08-10 15:26:14 +00:00
|
|
|
}
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2020-02-10 09:07:48 +00:00
|
|
|
static int
|
|
|
|
get_best_mipmap_level (CoglTexture *texture,
|
|
|
|
int visible_width,
|
|
|
|
int visible_height)
|
|
|
|
{
|
|
|
|
int mipmap_width = cogl_texture_get_width (texture);
|
|
|
|
int mipmap_height = cogl_texture_get_height (texture);
|
|
|
|
int halves = 0;
|
|
|
|
|
|
|
|
while (mipmap_width >= visible_width && mipmap_height >= visible_height)
|
|
|
|
{
|
|
|
|
halves++;
|
|
|
|
mipmap_width /= 2;
|
|
|
|
mipmap_height /= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MAX (0, halves - 1);
|
|
|
|
}
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
CoglTexture *
|
2023-07-19 23:46:15 +00:00
|
|
|
meta_background_get_texture (MetaBackground *self,
|
|
|
|
int monitor_index,
|
|
|
|
MtkRectangle *texture_area,
|
|
|
|
CoglPipelineWrapMode *wrap_mode)
|
2014-08-10 15:26:14 +00:00
|
|
|
{
|
|
|
|
MetaBackgroundMonitor *monitor;
|
2023-07-19 23:46:15 +00:00
|
|
|
MtkRectangle geometry;
|
2023-07-19 14:59:04 +00:00
|
|
|
MtkRectangle monitor_area;
|
2014-08-10 15:26:14 +00:00
|
|
|
CoglTexture *texture1, *texture2;
|
2017-08-03 13:48:51 +00:00
|
|
|
float monitor_scale;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-09-03 18:03:17 +00:00
|
|
|
g_return_val_if_fail (META_IS_BACKGROUND (self), NULL);
|
2018-10-31 10:47:17 +00:00
|
|
|
g_return_val_if_fail (monitor_index >= 0 && monitor_index < self->n_monitors, NULL);
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
monitor = &self->monitors[monitor_index];
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
meta_display_get_monitor_geometry (self->display, monitor_index, &geometry);
|
2017-08-03 13:48:51 +00:00
|
|
|
monitor_scale = meta_display_get_monitor_scale (self->display, monitor_index);
|
2014-08-10 15:26:14 +00:00
|
|
|
monitor_area.x = geometry.x;
|
|
|
|
monitor_area.y = geometry.y;
|
|
|
|
monitor_area.width = geometry.width;
|
|
|
|
monitor_area.height = geometry.height;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
texture1 = self->background_image1 ? meta_background_image_get_texture (self->background_image1) : NULL;
|
|
|
|
texture2 = self->background_image2 ? meta_background_image_get_texture (self->background_image2) : NULL;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
if (texture1 == NULL && texture2 == NULL)
|
|
|
|
{
|
|
|
|
ensure_color_texture (self);
|
|
|
|
if (texture_area)
|
2014-09-12 14:33:46 +00:00
|
|
|
set_texture_area_from_monitor_area (&monitor_area, texture_area);
|
2014-08-10 15:26:14 +00:00
|
|
|
if (wrap_mode)
|
|
|
|
*wrap_mode = COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE;
|
2018-10-31 10:47:17 +00:00
|
|
|
return self->color_texture;
|
2014-08-10 15:26:14 +00:00
|
|
|
}
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
if (texture2 == NULL && self->style == G_DESKTOP_BACKGROUND_STYLE_WALLPAPER &&
|
|
|
|
self->shading_direction == G_DESKTOP_BACKGROUND_SHADING_SOLID &&
|
2014-08-10 15:26:14 +00:00
|
|
|
ensure_wallpaper_texture (self, texture1))
|
|
|
|
{
|
|
|
|
if (texture_area)
|
2017-08-03 13:48:51 +00:00
|
|
|
get_texture_area (self, &monitor_area, monitor_scale,
|
|
|
|
self->wallpaper_texture, texture_area);
|
2014-08-10 15:26:14 +00:00
|
|
|
if (wrap_mode)
|
|
|
|
*wrap_mode = COGL_PIPELINE_WRAP_MODE_REPEAT;
|
2018-10-31 10:47:17 +00:00
|
|
|
return self->wallpaper_texture;
|
2014-08-10 15:26:14 +00:00
|
|
|
}
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
if (monitor->dirty)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2022-05-27 18:30:37 +00:00
|
|
|
MetaContext *context = meta_display_get_context (self->display);
|
|
|
|
MetaBackend *backend = meta_context_get_backend (context);
|
2019-06-18 06:02:10 +00:00
|
|
|
GError *catch_error = NULL;
|
2015-09-03 17:57:25 +00:00
|
|
|
gboolean bare_region_visible = FALSE;
|
2020-01-13 13:02:39 +00:00
|
|
|
int texture_width, texture_height;
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2022-05-27 18:30:37 +00:00
|
|
|
if (meta_backend_is_stage_views_scaled (backend))
|
2017-08-03 13:48:51 +00:00
|
|
|
{
|
2020-01-13 13:02:39 +00:00
|
|
|
texture_width = monitor_area.width * monitor_scale;
|
|
|
|
texture_height = monitor_area.height * monitor_scale;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
texture_width = monitor_area.width;
|
|
|
|
texture_height = monitor_area.height;
|
2017-08-03 13:48:51 +00:00
|
|
|
}
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
if (monitor->texture == NULL)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2016-05-07 14:21:24 +00:00
|
|
|
CoglOffscreen *offscreen;
|
|
|
|
|
2020-01-13 13:02:39 +00:00
|
|
|
monitor->texture = meta_create_texture (texture_width,
|
|
|
|
texture_height,
|
2021-01-08 07:59:21 +00:00
|
|
|
COGL_TEXTURE_COMPONENTS_RGB,
|
2014-08-10 15:26:14 +00:00
|
|
|
META_TEXTURE_FLAGS_NONE);
|
2016-05-07 14:21:24 +00:00
|
|
|
offscreen = cogl_offscreen_new_with_texture (monitor->texture);
|
|
|
|
monitor->fbo = COGL_FRAMEBUFFER (offscreen);
|
2014-08-10 15:26:14 +00:00
|
|
|
}
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2020-01-13 13:02:39 +00:00
|
|
|
if (self->style != G_DESKTOP_BACKGROUND_STYLE_WALLPAPER)
|
|
|
|
{
|
|
|
|
monitor_area.x *= monitor_scale;
|
|
|
|
monitor_area.y *= monitor_scale;
|
|
|
|
monitor_area.width *= monitor_scale;
|
|
|
|
monitor_area.height *= monitor_scale;
|
|
|
|
}
|
|
|
|
|
2014-08-10 15:26:14 +00: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.)
|
|
|
|
*/
|
2023-09-18 14:58:36 +00:00
|
|
|
g_clear_object (&monitor->texture);
|
2020-10-13 09:35:47 +00:00
|
|
|
g_clear_object (&monitor->fbo);
|
2014-08-10 15:26:14 +00:00
|
|
|
|
2019-06-18 06:02:10 +00:00
|
|
|
g_error_free (catch_error);
|
2014-08-10 15:26:14 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cogl_framebuffer_orthographic (monitor->fbo, 0, 0,
|
|
|
|
monitor_area.width, monitor_area.height, -1., 1.);
|
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
if (texture2 != NULL && self->blend_factor != 0.0)
|
2014-08-10 15:26:14 +00:00
|
|
|
{
|
|
|
|
CoglPipeline *pipeline = create_pipeline (PIPELINE_REPLACE);
|
2020-02-10 09:07:48 +00:00
|
|
|
int mipmap_level;
|
|
|
|
|
|
|
|
mipmap_level = get_best_mipmap_level (texture2,
|
|
|
|
texture_width,
|
|
|
|
texture_height);
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
cogl_pipeline_set_color4f (pipeline,
|
2018-10-31 10:47:17 +00:00
|
|
|
self->blend_factor, self->blend_factor, self->blend_factor, self->blend_factor);
|
2014-08-10 15:26:14 +00:00
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, texture2);
|
2018-10-31 10:47:17 +00:00
|
|
|
cogl_pipeline_set_layer_wrap_mode (pipeline, 0, get_wrap_mode (self->style));
|
2020-02-10 09:07:48 +00:00
|
|
|
cogl_pipeline_set_layer_max_mipmap_level (pipeline, 0, mipmap_level);
|
2014-08-10 15:26:14 +00:00
|
|
|
|
2015-09-03 17:57:25 +00:00
|
|
|
bare_region_visible = draw_texture (self,
|
|
|
|
monitor->fbo, pipeline,
|
2017-08-03 13:48:51 +00:00
|
|
|
texture2, &monitor_area,
|
|
|
|
monitor_scale);
|
2014-08-10 15:26:14 +00:00
|
|
|
|
2023-09-19 09:16:43 +00:00
|
|
|
g_object_unref (pipeline);
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
cogl_framebuffer_clear4f (monitor->fbo,
|
|
|
|
COGL_BUFFER_BIT_COLOR,
|
|
|
|
0.0, 0.0, 0.0, 0.0);
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
if (texture1 != NULL && self->blend_factor != 1.0)
|
2014-08-10 15:26:14 +00:00
|
|
|
{
|
|
|
|
CoglPipeline *pipeline = create_pipeline (PIPELINE_ADD);
|
2020-02-10 09:07:48 +00:00
|
|
|
int mipmap_level;
|
|
|
|
|
|
|
|
mipmap_level = get_best_mipmap_level (texture1,
|
|
|
|
texture_width,
|
|
|
|
texture_height);
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
cogl_pipeline_set_color4f (pipeline,
|
2018-10-31 10:47:17 +00:00
|
|
|
(1 - self->blend_factor),
|
|
|
|
(1 - self->blend_factor),
|
|
|
|
(1 - self->blend_factor),
|
2020-07-28 08:11:07 +00:00
|
|
|
(1 - self->blend_factor));
|
2014-08-10 15:26:14 +00:00
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, texture1);
|
2018-10-31 10:47:17 +00:00
|
|
|
cogl_pipeline_set_layer_wrap_mode (pipeline, 0, get_wrap_mode (self->style));
|
2020-02-10 09:07:48 +00:00
|
|
|
cogl_pipeline_set_layer_max_mipmap_level (pipeline, 0, mipmap_level);
|
2014-08-10 15:26:14 +00:00
|
|
|
|
2015-09-03 17:57:25 +00:00
|
|
|
bare_region_visible = bare_region_visible || draw_texture (self,
|
|
|
|
monitor->fbo, pipeline,
|
2017-08-03 13:48:51 +00:00
|
|
|
texture1, &monitor_area,
|
|
|
|
monitor_scale);
|
2014-08-10 15:26:14 +00:00
|
|
|
|
2023-09-19 09:16:43 +00:00
|
|
|
g_object_unref (pipeline);
|
2014-08-10 15:26:14 +00:00
|
|
|
}
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2015-09-03 17:57:25 +00:00
|
|
|
if (bare_region_visible)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
CoglPipeline *pipeline = create_pipeline (PIPELINE_OVER_REVERSE);
|
|
|
|
|
|
|
|
ensure_color_texture (self);
|
2018-10-31 10:47:17 +00:00
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, self->color_texture);
|
2014-08-10 15:26:14 +00:00
|
|
|
cogl_framebuffer_draw_rectangle (monitor->fbo,
|
|
|
|
pipeline,
|
|
|
|
0, 0,
|
|
|
|
monitor_area.width, monitor_area.height);
|
2023-09-19 09:16:43 +00:00
|
|
|
g_object_unref (pipeline);
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
monitor->dirty = FALSE;
|
|
|
|
}
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
if (texture_area)
|
2017-08-03 13:48:51 +00:00
|
|
|
set_texture_area_from_monitor_area (&geometry, texture_area);
|
2014-09-12 14:33:46 +00:00
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
if (wrap_mode)
|
|
|
|
*wrap_mode = COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE;
|
|
|
|
return monitor->texture;
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
2014-08-10 15:26:14 +00:00
|
|
|
|
2013-01-23 20:54:41 +00:00
|
|
|
MetaBackground *
|
2017-08-26 19:22:34 +00:00
|
|
|
meta_background_new (MetaDisplay *display)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
return g_object_new (META_TYPE_BACKGROUND,
|
2017-08-26 19:22:34 +00:00
|
|
|
"meta-display", display,
|
2014-08-10 15:26:14 +00:00
|
|
|
NULL);
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
void
|
|
|
|
meta_background_set_color (MetaBackground *self,
|
|
|
|
ClutterColor *color)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
ClutterColor dummy = { 0 };
|
2013-01-23 20:54:41 +00:00
|
|
|
|
2014-08-10 15:26:14 +00: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 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
void
|
|
|
|
meta_background_set_gradient (MetaBackground *self,
|
|
|
|
GDesktopBackgroundShading shading_direction,
|
|
|
|
ClutterColor *color,
|
|
|
|
ClutterColor *second_color)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
g_return_if_fail (META_IS_BACKGROUND (self));
|
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
g_return_if_fail (second_color != NULL);
|
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
self->shading_direction = shading_direction;
|
|
|
|
self->color = *color;
|
|
|
|
self->second_color = *second_color;
|
2014-08-10 15:26:14 +00:00
|
|
|
|
|
|
|
free_color_texture (self);
|
|
|
|
free_wallpaper_texture (self);
|
|
|
|
mark_changed (self);
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2019-11-18 17:20:11 +00:00
|
|
|
/**
|
|
|
|
* meta_background_set_file:
|
|
|
|
* @self: a #MetaBackground
|
|
|
|
* @file: (nullable): a #GFile representing the background file
|
|
|
|
* @style: the background style to apply
|
|
|
|
*
|
|
|
|
* Set the background to @file
|
|
|
|
*/
|
2014-08-10 15:26:14 +00:00
|
|
|
void
|
2014-09-19 01:22:39 +00:00
|
|
|
meta_background_set_file (MetaBackground *self,
|
|
|
|
GFile *file,
|
|
|
|
GDesktopBackgroundStyle style)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
g_return_if_fail (META_IS_BACKGROUND (self));
|
|
|
|
|
2014-09-19 01:22:39 +00:00
|
|
|
meta_background_set_blend (self, file, NULL, 0.0, style);
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2014-08-10 15:26:14 +00:00
|
|
|
void
|
|
|
|
meta_background_set_blend (MetaBackground *self,
|
2014-09-19 01:22:39 +00:00
|
|
|
GFile *file1,
|
|
|
|
GFile *file2,
|
2014-08-10 15:26:14 +00:00
|
|
|
double blend_factor,
|
|
|
|
GDesktopBackgroundStyle style)
|
2013-01-23 20:54:41 +00:00
|
|
|
{
|
2014-08-10 15:26:14 +00:00
|
|
|
g_return_if_fail (META_IS_BACKGROUND (self));
|
|
|
|
g_return_if_fail (blend_factor >= 0.0 && blend_factor <= 1.0);
|
|
|
|
|
2019-05-23 10:15:28 +00:00
|
|
|
set_file (self, &self->file1, &self->background_image1, file1, FALSE);
|
|
|
|
set_file (self, &self->file2, &self->background_image2, file2, FALSE);
|
2014-08-10 15:26:14 +00:00
|
|
|
|
2018-10-31 10:47:17 +00:00
|
|
|
self->blend_factor = blend_factor;
|
|
|
|
self->style = style;
|
2014-08-10 15:26:14 +00:00
|
|
|
|
|
|
|
free_wallpaper_texture (self);
|
|
|
|
mark_changed (self);
|
2013-01-23 20:54:41 +00:00
|
|
|
}
|
2015-03-19 13:58:25 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
meta_background_refresh_all (void)
|
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
for (l = all_backgrounds; l; l = l->next)
|
|
|
|
mark_changed (l->data);
|
|
|
|
}
|