Bug 582248 - Async loading of pixbufs and icon caching

Add a ShellTextureCache class which loads (and can cache)
pixmap->texture conversions.  This fixes a problem with the
async code in ClutterTexture that it was lower priority
than animations, and also ensures we're really only
loading these pixbufs once in the icon case.
This commit is contained in:
Colin Walters
2009-05-13 14:06:24 -04:00
parent 10afe46195
commit d024dbd779
9 changed files with 702 additions and 231 deletions

View File

@ -8,7 +8,6 @@ dist_jsui_DATA = \
dnd.js \
docDisplay.js \
genericDisplay.js \
gtkutil.js \
link.js \
main.js \
overlay.js \

View File

@ -10,7 +10,6 @@ const Lang = imports.lang;
const Signals = imports.signals;
const GenericDisplay = imports.ui.genericDisplay;
const GtkUtil = imports.ui.gtkutil;
const Main = imports.ui.main;
const ENTERED_MENU_COLOR = new Clutter.Color();
@ -70,7 +69,14 @@ AppDisplayItem.prototype = {
let iconTheme = Gtk.IconTheme.get_default();
let gicon = appInfo.get_icon();
let icon = GtkUtil.loadIconToTexture(gicon, GenericDisplay.ITEM_DISPLAY_ICON_SIZE, true);
let texCache = Shell.TextureCache.get_default();
let icon;
if (gicon == null)
icon = new Clutter.Texture({ width: GenericDisplay.ITEM_DISPLAY_ICON_SIZE,
height: GenericDisplay.ITEM_DISPLAY_ICON_SIZE
});
else
icon = texCache.load_gicon(gicon, GenericDisplay.ITEM_DISPLAY_ICON_SIZE);
this._setItemInfo(name, description, icon);
},

View File

@ -128,16 +128,7 @@ DocDisplayItem.prototype = {
if (this._docInfo.get_mime_type() == null || this._docInfo.get_mime_type().indexOf("image/") != 0)
return null;
let largePreviewPixbuf = Shell.create_pixbuf_from_image_file(this._docInfo.get_uri(), availableWidth, availableHeight);
if (largePreviewPixbuf == null)
return null;
let largePreviewIcon = new Clutter.Texture();
Shell.clutter_texture_set_from_pixbuf(largePreviewIcon, largePreviewPixbuf);
return largePreviewIcon;
return Shell.TextureCache.load_uri_sync(this._docInfo.get_uri(), availableWidth, availableHeight);
}
};

View File

@ -1,30 +0,0 @@
/* -*- mode: js2; js2-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil -*- */
const Lang = imports.lang;
const Clutter = imports.gi.Clutter;
const Gtk = imports.gi.Gtk;
function loadIconToTexture(gicon, size, fallback) {
let iconTheme = Gtk.IconTheme.get_default();
let path = null;
let icon = null;
if (gicon != null) {
let iconinfo = iconTheme.lookup_by_gicon(gicon, size, Gtk.IconLookupFlags.NO_SVG);
if (iconinfo)
path = iconinfo.get_filename();
}
if (path) {
try {
icon = new Clutter.Texture({ width: size, height: size, load_async: true });
icon.set_from_file(path);
return icon;
} catch (e) {
icon = null;
}
}
if (icon == null && fallback)
icon = new Clutter.Texture({ width: size, height: size });
return icon;
}