[f-spot/rubenv-gsoc-2009: 56/86] Make Editors suck less by threading previews.
- From: Ruben Vermeersch <rubenv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot/rubenv-gsoc-2009: 56/86] Make Editors suck less by threading previews.
- Date: Sun, 23 May 2010 12:36:39 +0000 (UTC)
commit a1af26dc26ee9b00addc00e0d07ae4c483360249
Author: Ruben Vermeersch <ruben savanne be>
Date: Wed Aug 5 00:36:36 2009 +0200
Make Editors suck less by threading previews.
This makes editors totally sweet and responsive, because the preview is
calculated in a thread. Still left TODO is figure out the memory uglyness going
on.
src/Editors/Editor.cs | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/src/Editors/Editor.cs b/src/Editors/Editor.cs
index 304f0ea..517e8d6 100644
--- a/src/Editors/Editor.cs
+++ b/src/Editors/Editor.cs
@@ -18,6 +18,7 @@ using Gtk;
using Mono.Unix;
using System;
+using System.Threading;
namespace FSpot.Editors {
// This is the base class from which all editors inherit.
@@ -150,6 +151,9 @@ namespace FSpot.Editors {
Pixbuf Original { get; set; }
Pixbuf Preview { get; set; }
+ volatile bool preview_needed = false;
+ volatile Thread preview_thread = null;
+
protected void UpdatePreview () {
if (State.InBrowseMode) {
throw new Exception ("Previews cannot be made in browse mode!");
@@ -159,6 +163,34 @@ namespace FSpot.Editors {
throw new Exception ("We should have one item selected when this happened, otherwise something is terribly wrong.");
}
+ lock (this) {
+ preview_needed = true;
+ if (preview_thread == null) {
+ preview_thread = new Thread (new ThreadStart (DoUpdatePreview));
+ preview_thread.Start ();
+ }
+ }
+ }
+
+ void DoUpdatePreview ()
+ {
+ bool done = false;
+ while (!done) {
+ preview_needed = false;
+
+ RenderPreview ();
+
+ lock (this) {
+ if (!preview_needed) {
+ done = true;
+ preview_thread = null;
+ }
+ }
+ }
+ }
+
+ void RenderPreview ()
+ {
if (Original == null) {
Original = State.PhotoImageView.Pixbuf;
}
@@ -214,6 +246,10 @@ namespace FSpot.Editors {
}
private void Reset () {
+ preview_needed = false;
+ while (preview_thread != null)
+ preview_thread.Join ();
+
if (Preview != null) {
Preview.Dispose ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]