Speed up initialization of DocInfo objects
We achieve this with two changes: - Move the Shell.get_thumbnail call in DocInfo from _init to getIcon, so that it isn't executed until it's actually needed. (If caching the output of said call permanently is desired we could still do it on the first getIcon invocation, but I don't believe this is necessary given that looking up an already generated icon is pretty fast and this also gives us an updated icon in case the file changes.) - More importantly, we ommit the get_thumbnail call in case the URI doesn't start with file://. Looking up, for example, an http:// URI is very slow, and doesn't give us an icon anyway. http://bugzilla.gnome.org/show_bug.cgi?id=586539
This commit is contained in:
parent
b8af0c1b8b
commit
f215935d2d
@ -19,14 +19,16 @@ DocInfo.prototype = {
|
||||
this.name = recentInfo.get_display_name();
|
||||
this.uri = recentInfo.get_uri();
|
||||
this.mimeType = recentInfo.get_mime_type();
|
||||
|
||||
this._iconPixbuf = Shell.get_thumbnail(this.uri, this.mimeType);
|
||||
},
|
||||
|
||||
getIcon : function(size) {
|
||||
let icon = new Clutter.Texture();
|
||||
let iconPixbuf;
|
||||
|
||||
if (this._iconPixbuf) {
|
||||
if (this.uri.match("^file://"))
|
||||
iconPixbuf = Shell.get_thumbnail(this.uri, this.mimeType);
|
||||
|
||||
if (iconPixbuf) {
|
||||
// We calculate the width and height of the texture so as
|
||||
// to preserve the aspect ratio of the thumbnail. Because
|
||||
// the images generated based on thumbnails don't have an
|
||||
@ -34,10 +36,10 @@ DocInfo.prototype = {
|
||||
// slightly smaller texture and then create a group around
|
||||
// it for padding purposes
|
||||
|
||||
let scalingFactor = (size - THUMBNAIL_ICON_MARGIN * 2) / Math.max(this._iconPixbuf.get_width(), this._iconPixbuf.get_height());
|
||||
icon.set_width(Math.ceil(this._iconPixbuf.get_width() * scalingFactor));
|
||||
icon.set_height(Math.ceil(this._iconPixbuf.get_height() * scalingFactor));
|
||||
Shell.clutter_texture_set_from_pixbuf(icon, this._iconPixbuf);
|
||||
let scalingFactor = (size - THUMBNAIL_ICON_MARGIN * 2) / Math.max(iconPixbuf.get_width(), iconPixbuf.get_height());
|
||||
icon.set_width(Math.ceil(iconPixbuf.get_width() * scalingFactor));
|
||||
icon.set_height(Math.ceil(iconPixbuf.get_height() * scalingFactor));
|
||||
Shell.clutter_texture_set_from_pixbuf(icon, iconPixbuf);
|
||||
|
||||
let group = new Clutter.Group({ width: size,
|
||||
height: size });
|
||||
|
Loading…
Reference in New Issue
Block a user