Merge St.TextureCache and Shell.TextureCache

Brute force merge these two by essentially replacing St.TextureCache
with a (renamed) Shell.TextureCache.

One function was added for convenience, namely "st_texture_cache_load_file_simple".
St.TextureCache had a function to load a texture from a filename, and it
returned NULL on error but only half the callers actually checked this.  This
function is better.

https://bugzilla.gnome.org/show_bug.cgi?id=607500
This commit is contained in:
Colin Walters 2010-02-09 12:42:07 -05:00
parent aa7de264e6
commit 22948b3d39
20 changed files with 1607 additions and 2130 deletions

View File

@ -59,10 +59,10 @@ AM_CONDITIONAL(BUILD_RECORDER, $build_recorder)
PKG_CHECK_MODULES(MUTTER_PLUGIN, gio-unix-2.0 gtk+-2.0 dbus-glib-1 mutter-plugins >= 2.29.0
gjs-gi-1.0 libgnome-menu $recorder_modules gconf-2.0
gdk-x11-2.0 clutter-x11-1.0 clutter-glx-1.0
gnome-desktop-2.0 >= 2.26 libstartup-notification-1.0
libstartup-notification-1.0
gobject-introspection-1.0 >= 0.6.5)
PKG_CHECK_MODULES(TIDY, clutter-1.0)
PKG_CHECK_MODULES(ST, clutter-1.0 gtk+-2.0 libcroco-0.6)
PKG_CHECK_MODULES(ST, clutter-1.0 gtk+-2.0 libcroco-0.6 gnome-desktop-2.0 >= 2.26)
PKG_CHECK_MODULES(BIG, clutter-1.0 gtk+-2.0 librsvg-2.0)
PKG_CHECK_MODULES(GDMUSER, dbus-glib-1 gtk+-2.0)
PKG_CHECK_MODULES(TRAY, gtk+-2.0)

View File

@ -3,8 +3,9 @@
const Clutter = imports.gi.Clutter;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const Shell = imports.gi.Shell;
const St = imports.gi.St;
const Shell = imports.gi.Shell;
const Lang = imports.lang;
const Signals = imports.signals;
const Search = imports.ui.search;
@ -30,7 +31,7 @@ DocInfo.prototype = {
},
createIcon : function(size) {
return Shell.TextureCache.get_default().load_recent_thumbnail(size, this.recentInfo);
return St.TextureCache.get_default().load_recent_thumbnail(size, this.recentInfo);
},
launch : function() {

View File

@ -694,7 +694,7 @@ AppIconMenu.prototype = {
this._windowContainer.show();
let iconsDiffer = false;
let texCache = Shell.TextureCache.get_default();
let texCache = St.TextureCache.get_default();
if (windows.length > 0) {
let firstIcon = windows[0].mini_icon;
for (let i = 1; i < windows.length; i++) {

View File

@ -268,10 +268,10 @@ SearchEntry.prototype = {
box.append(this._iconBox, Big.BoxPackFlags.END);
let magnifierUri = "file://" + global.imagedir + "magnifier.svg";
this._magnifierIcon = Shell.TextureCache.get_default().load_uri_sync(Shell.TextureCachePolicy.FOREVER,
this._magnifierIcon = St.TextureCache.get_default().load_uri_sync(St.TextureCachePolicy.FOREVER,
magnifierUri, 18, 18);
let closeUri = "file://" + global.imagedir + "close-black.svg";
this._closeIcon = Shell.TextureCache.get_default().load_uri_sync(Shell.TextureCachePolicy.FOREVER,
this._closeIcon = St.TextureCache.get_default().load_uri_sync(St.TextureCachePolicy.FOREVER,
closeUri, 18, 18);
this._closeIcon.reactive = true;
this._closeIcon.connect('button-press-event', Lang.bind(this, function () {

View File

@ -85,7 +85,7 @@ DocDisplayItem.prototype = {
return null;
try {
return Shell.TextureCache.get_default().load_uri_sync(Shell.TextureCachePolicy.NONE,
return St.TextureCache.get_default().load_uri_sync(St.TextureCachePolicy.NONE,
this._docInfo.uri, -1, -1);
} catch (e) {
// An exception will be raised when the image format isn't know

View File

@ -484,7 +484,7 @@ LookingGlass.prototype = {
let toolbar = new St.BoxLayout({ name: "Toolbar" });
this.actor.add_actor(toolbar);
let inspectIcon = Shell.TextureCache.get_default().load_gicon(new Gio.ThemedIcon({ name: 'gtk-color-picker' }),
let inspectIcon = St.TextureCache.get_default().load_gicon(new Gio.ThemedIcon({ name: 'gtk-color-picker' }),
24);
toolbar.add_actor(inspectIcon);
inspectIcon.reactive = true;

View File

@ -318,7 +318,7 @@ Source.prototype = {
},
createIcon: function(size) {
let textureCache = Shell.TextureCache.get_default();
let textureCache = St.TextureCache.get_default();
if (this._icon) {
if (this._icon.substr(0, 7) == 'file://')

View File

@ -77,7 +77,7 @@ PlaceDeviceInfo.prototype = {
iconFactory: function(size) {
let icon = this._mount.get_icon();
return Shell.TextureCache.get_default().load_gicon(icon, size);
return St.TextureCache.get_default().load_gicon(icon, size);
},
launch: function() {
@ -122,7 +122,7 @@ PlacesManager.prototype = {
let homeIcon = Shell.util_get_icon_for_uri (homeUri);
this._home = new PlaceInfo('special:home', homeLabel,
function(size) {
return Shell.TextureCache.get_default().load_gicon(homeIcon, size);
return St.TextureCache.get_default().load_gicon(homeIcon, size);
},
function() {
Gio.app_info_launch_default_for_uri(homeUri, global.create_app_launch_context());
@ -135,7 +135,7 @@ PlacesManager.prototype = {
let desktopIcon = Shell.util_get_icon_for_uri (desktopUri);
this._desktopMenu = new PlaceInfo('special:desktop', desktopLabel,
function(size) {
return Shell.TextureCache.get_default().load_gicon(desktopIcon, size);
return St.TextureCache.get_default().load_gicon(desktopIcon, size);
},
function() {
Gio.app_info_launch_default_for_uri(desktopUri, global.create_app_launch_context());
@ -143,7 +143,7 @@ PlacesManager.prototype = {
this._connect = new PlaceInfo('special:connect', _("Connect to..."),
function (size) {
return Shell.TextureCache.get_default().load_icon_name("applications-internet", size);
return St.TextureCache.get_default().load_icon_name("applications-internet", size);
},
function () {
new Shell.Process({ args: ['nautilus-connect-server'] }).run();
@ -310,7 +310,7 @@ PlacesManager.prototype = {
let item = new PlaceInfo('bookmark:' + bookmark, label,
function(size) {
return Shell.TextureCache.get_default().load_gicon(icon, size);
return St.TextureCache.get_default().load_gicon(icon, size);
},
function() {
Gio.app_info_launch_default_for_uri(bookmark, global.create_app_launch_context());
@ -414,7 +414,7 @@ DashPlaceDisplayItem.prototype = {
this.actor.append(text, Big.BoxPackFlags.EXPAND);
if (info.isRemovable()) {
let removeIcon = Shell.TextureCache.get_default().load_icon_name ('media-eject', PLACES_ICON_SIZE);
let removeIcon = St.TextureCache.get_default().load_icon_name ('media-eject', PLACES_ICON_SIZE);
let removeIconBox = new St.Button({ child: removeIcon,
reactive: true });
this.actor.append(removeIconBox, Big.BoxPackFlags.NONE);

View File

@ -7,9 +7,9 @@ const GLib = imports.gi.GLib;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Meta = imports.gi.Meta;
const St = imports.gi.St;
const Shell = imports.gi.Shell;
const Signals = imports.signals;
const St = imports.gi.St;
const Gettext = imports.gettext.domain('gnome-shell');
const _ = Gettext.gettext;

View File

@ -36,7 +36,7 @@ StatusMenu.prototype = {
this._iconBox = new St.Bin();
this.actor.add(this._iconBox, { y_align: St.Align.MIDDLE });
let textureCache = Shell.TextureCache.get_default();
let textureCache = St.TextureCache.get_default();
// FIXME: these icons are all wrong (likewise in createSubMenu)
this._availableIcon = textureCache.load_icon_name('gtk-yes', 16);
this._busyIcon = textureCache.load_icon_name('gtk-no', 16);

View File

@ -90,8 +90,6 @@ libgnome_shell_la_SOURCES = \
shell-stack.h \
shell-tray-manager.c \
shell-tray-manager.h \
shell-texture-cache.c \
shell-texture-cache.h \
shell-uri-util.c \
shell-uri-util.h \
shell-window-tracker.c \

View File

@ -14,7 +14,7 @@
#include "shell-app-private.h"
#include "shell-global.h"
#include "shell-texture-cache.h"
#include "st/st-texture-cache.h"
#include "display.h"
#define GMENU_I_KNOW_THIS_IS_UNSTABLE
@ -1100,7 +1100,7 @@ shell_app_info_create_icon_texture (ShellAppInfo *info, float size)
if (info->type == SHELL_APP_INFO_TYPE_WINDOW)
{
return shell_texture_cache_bind_pixbuf_property (shell_texture_cache_get_default (),
return st_texture_cache_bind_pixbuf_property (st_texture_cache_get_default (),
G_OBJECT (info->window),
"icon");
}
@ -1113,7 +1113,7 @@ shell_app_info_create_icon_texture (ShellAppInfo *info, float size)
}
else
{
ret = shell_texture_cache_load_gicon (shell_texture_cache_get_default (), icon, (int)size);
ret = st_texture_cache_load_gicon (st_texture_cache_get_default (), icon, (int)size);
g_object_unref (icon);
}

View File

@ -5,7 +5,6 @@
#include "shell-doc-system.h"
#include "shell-global.h"
#include "shell-texture-cache.h"
/**

File diff suppressed because it is too large Load Diff

View File

@ -1,100 +0,0 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
#ifndef __SHELL_TEXTURE_CACHE_H__
#define __SHELL_TEXTURE_CACHE_H__
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <clutter/clutter.h>
#define SHELL_TYPE_TEXTURE_CACHE (shell_texture_cache_get_type ())
#define SHELL_TEXTURE_CACHE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SHELL_TYPE_TEXTURE_CACHE, ShellTextureCache))
#define SHELL_TEXTURE_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SHELL_TYPE_TEXTURE_CACHE, ShellTextureCacheClass))
#define SHELL_IS_TEXTURE_CACHE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SHELL_TYPE_TEXTURE_CACHE))
#define SHELL_IS_TEXTURE_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SHELL_TYPE_TEXTURE_CACHE))
#define SHELL_TEXTURE_CACHE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SHELL_TYPE_TEXTURE_CACHE, ShellTextureCacheClass))
typedef struct _ShellTextureCache ShellTextureCache;
typedef struct _ShellTextureCacheClass ShellTextureCacheClass;
typedef struct _ShellTextureCachePrivate ShellTextureCachePrivate;
struct _ShellTextureCache
{
GObject parent;
ShellTextureCachePrivate *priv;
};
struct _ShellTextureCacheClass
{
GObjectClass parent_class;
};
typedef enum {
SHELL_TEXTURE_CACHE_POLICY_NONE,
SHELL_TEXTURE_CACHE_POLICY_FOREVER
} ShellTextureCachePolicy;
GType shell_texture_cache_get_type (void) G_GNUC_CONST;
ShellTextureCache* shell_texture_cache_get_default (void);
ClutterActor *shell_texture_cache_bind_pixbuf_property (ShellTextureCache *cache,
GObject *object,
const char *property_name);
ClutterActor *shell_texture_cache_load_icon_name (ShellTextureCache *cache,
const char *name,
gint size);
ClutterActor *shell_texture_cache_load_gicon (ShellTextureCache *cache,
GIcon *icon,
gint size);
ClutterActor *shell_texture_cache_load_thumbnail (ShellTextureCache *cache,
int size,
const char *uri,
const char *mimetype);
ClutterActor *shell_texture_cache_load_recent_thumbnail (ShellTextureCache *cache,
int size,
GtkRecentInfo *info);
void shell_texture_cache_evict_thumbnail (ShellTextureCache *cache,
const char *uri);
void shell_texture_cache_evict_recent_thumbnail (ShellTextureCache *cache,
GtkRecentInfo *info);
ClutterActor *shell_texture_cache_load_uri_async (ShellTextureCache *cache,
const gchar *filename,
int available_width,
int available_height);
ClutterActor *shell_texture_cache_load_uri_sync (ShellTextureCache *cache,
ShellTextureCachePolicy policy,
const gchar *filename,
int available_width,
int available_height,
GError **error);
ClutterActor *shell_texture_cache_load_from_data (ShellTextureCache *cache,
const guchar *data,
gsize len,
int size,
GError **error);
ClutterActor *shell_texture_cache_load_from_raw (ShellTextureCache *cache,
const guchar *data,
gsize len,
gboolean has_alpha,
int width,
int height,
int rowstride,
int size,
GError **error);
gboolean shell_texture_cache_pixbuf_equal (ShellTextureCache *cache, GdkPixbuf *a, GdkPixbuf *b);
#endif /* __SHELL_TEXTURE_CACHE_H__ */

View File

@ -16,7 +16,7 @@
#include "shell-window-tracker.h"
#include "shell-app-system.h"
#include "shell-app-private.h"
#include "shell-texture-cache.h"
#include "st/st-texture-cache.h"
#include "shell-global.h"
#include "shell-marshal.h"
@ -847,7 +847,7 @@ shell_startup_sequence_create_icon (ShellStartupSequence *sequence, guint size)
}
themed = g_themed_icon_new (icon_name);
texture = shell_texture_cache_load_gicon (shell_texture_cache_get_default (),
texture = st_texture_cache_load_gicon (st_texture_cache_get_default (),
themed, size);
g_object_unref (G_OBJECT (themed));
return texture;

View File

@ -842,9 +842,7 @@ _st_entry_set_icon_from_file (StEntry *entry,
cache = st_texture_cache_get_default ();
*icon = (ClutterActor*) st_texture_cache_get_texture (cache, filename);
*icon = (ClutterActor*) st_texture_cache_load_file_simple (cache, filename);
clutter_actor_set_reactive (*icon, TRUE);
clutter_actor_set_parent (*icon, CLUTTER_ACTOR (entry));

File diff suppressed because it is too large Load Diff

View File

@ -1,96 +1,103 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
* st-texture-cache.h: Cached textures object
*
* Copyright 2007 OpenedHand
* Copyright 2009 Intel Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU Lesser General Public License,
* version 2.1, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
* more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
* Boston, MA 02111-1307, USA.
*
*/
#ifndef __ST_TEXTURE_CACHE_H__
#define __ST_TEXTURE_CACHE_H__
#if !defined(ST_H_INSIDE) && !defined(ST_COMPILATION)
#error "Only <st/st.h> can be included directly.h"
#endif
#ifndef _ST_TEXTURE_CACHE
#define _ST_TEXTURE_CACHE
#include <glib-object.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <clutter/clutter.h>
G_BEGIN_DECLS
#define ST_TYPE_TEXTURE_CACHE (st_texture_cache_get_type ())
#define ST_TEXTURE_CACHE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ST_TYPE_TEXTURE_CACHE, StTextureCache))
#define ST_TEXTURE_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ST_TYPE_TEXTURE_CACHE, StTextureCacheClass))
#define ST_IS_TEXTURE_CACHE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ST_TYPE_TEXTURE_CACHE))
#define ST_IS_TEXTURE_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ST_TYPE_TEXTURE_CACHE))
#define ST_TEXTURE_CACHE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ST_TYPE_TEXTURE_CACHE, StTextureCacheClass))
#define ST_TYPE_TEXTURE_CACHE st_texture_cache_get_type()
typedef struct _StTextureCache StTextureCache;
typedef struct _StTextureCacheClass StTextureCacheClass;
#define ST_TEXTURE_CACHE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
ST_TYPE_TEXTURE_CACHE, StTextureCache))
typedef struct _StTextureCachePrivate StTextureCachePrivate;
#define ST_TEXTURE_CACHE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), \
ST_TYPE_TEXTURE_CACHE, StTextureCacheClass))
#define ST_IS_TEXTURE_CACHE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
ST_TYPE_TEXTURE_CACHE))
#define ST_IS_TEXTURE_CACHE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
ST_TYPE_TEXTURE_CACHE))
#define ST_TEXTURE_CACHE_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
ST_TYPE_TEXTURE_CACHE, StTextureCacheClass))
/**
* StTextureCache:
*
* The contents of this structure are private and should only be accessed
* through the public API.
*/
typedef struct {
/*< private >*/
struct _StTextureCache
{
GObject parent;
} StTextureCache;
typedef struct {
StTextureCachePrivate *priv;
};
struct _StTextureCacheClass
{
GObjectClass parent_class;
void (* loaded) (StTextureCache *self,
const gchar *path,
ClutterTexture *texture);
};
void (* error_loading) (StTextureCache *self,
GError *error);
} StTextureCacheClass;
typedef enum {
ST_TEXTURE_CACHE_POLICY_NONE,
ST_TEXTURE_CACHE_POLICY_FOREVER
} StTextureCachePolicy;
GType st_texture_cache_get_type (void);
GType st_texture_cache_get_type (void) G_GNUC_CONST;
StTextureCache* st_texture_cache_get_default (void);
ClutterTexture* st_texture_cache_get_texture (StTextureCache *self,
const gchar *path);
ClutterActor* st_texture_cache_get_actor (StTextureCache *self,
const gchar *path);
ClutterActor *st_texture_cache_bind_pixbuf_property (StTextureCache *cache,
GObject *object,
const char *property_name);
gint st_texture_cache_get_size (StTextureCache *self);
ClutterActor *st_texture_cache_load_icon_name (StTextureCache *cache,
const char *name,
gint size);
void st_texture_cache_load_cache (StTextureCache *self,
const char *filename);
ClutterActor *st_texture_cache_load_gicon (StTextureCache *cache,
GIcon *icon,
gint size);
G_END_DECLS
ClutterActor *st_texture_cache_load_thumbnail (StTextureCache *cache,
int size,
const char *uri,
const char *mimetype);
#endif /* _ST_TEXTURE_CACHE */
ClutterActor *st_texture_cache_load_recent_thumbnail (StTextureCache *cache,
int size,
GtkRecentInfo *info);
void st_texture_cache_evict_thumbnail (StTextureCache *cache,
const char *uri);
void st_texture_cache_evict_recent_thumbnail (StTextureCache *cache,
GtkRecentInfo *info);
ClutterActor *st_texture_cache_load_uri_async (StTextureCache *cache,
const gchar *filename,
int available_width,
int available_height);
ClutterActor *st_texture_cache_load_uri_sync (StTextureCache *cache,
StTextureCachePolicy policy,
const gchar *filename,
int available_width,
int available_height,
GError **error);
ClutterActor *st_texture_cache_load_file_simple (StTextureCache *cache,
const gchar *file_path);
ClutterActor *st_texture_cache_load_from_data (StTextureCache *cache,
const guchar *data,
gsize len,
int size,
GError **error);
ClutterActor *st_texture_cache_load_from_raw (StTextureCache *cache,
const guchar *data,
gsize len,
gboolean has_alpha,
int width,
int height,
int rowstride,
int size,
GError **error);
gboolean st_texture_cache_pixbuf_equal (StTextureCache *cache, GdkPixbuf *a, GdkPixbuf *b);
#endif /* __ST_TEXTURE_CACHE_H__ */

View File

@ -905,7 +905,7 @@ st_widget_real_style_changed (StWidget *self)
/* `border-image' takes precedence over `background-image'.
* Firefox lets the background-image shine thru when border-image has
* alpha an channel, maybe that would be an option for the future. */
texture = st_texture_cache_get_texture (texture_cache,
texture = (ClutterTexture*) st_texture_cache_load_file_simple (texture_cache,
filename);
clutter_texture_get_base_size (CLUTTER_TEXTURE (texture),
@ -968,16 +968,8 @@ st_widget_real_style_changed (StWidget *self)
bg_file = st_theme_node_get_background_image (theme_node);
if (bg_file != NULL)
{
texture = st_texture_cache_get_texture (texture_cache, bg_file);
priv->background_image = (ClutterActor*) texture;
if (priv->background_image != NULL)
{
clutter_actor_set_parent (priv->background_image,
CLUTTER_ACTOR (self));
}
else
g_warning ("Could not load %s", bg_file);
priv->background_image = st_texture_cache_load_file_simple (texture_cache, bg_file);
clutter_actor_set_parent (priv->background_image, CLUTTER_ACTOR (self));
has_changed = TRUE;
relayout_needed = TRUE;