Commit b5f1a47
Create fontconfig cache in a background thread
Changed files (6)
modifiedbirdfont/GtkWindow.valamodifiedlibbirdfont/NativeWindow.valamodifiedlibbirdfont/Renderer/FallbackFont.valamodifiedlibbirdfont/Renderer/fontconfig.cmodifiedlibbirdfont/Task.valamodifiedscripts/builder.py
Diff
@@ -483,6 +483,16 @@ public class GtkWindow : Gtk.Window, NativeWindow { } } + public void run_non_blocking_background_thread (Task t) {+ unowned Thread<void*> bg;+ + try {+ bg = Thread.create<void> (t.perform_task, true);+ } catch (GLib.Error e) {+ warning (e.message);+ }+ }+ public void* background_thread () { background_task.run (); MenuTab.stop_background_thread ();@@ -51,9 +51,12 @@ public interface NativeWindow : GLib.Object { /** Load images in a background thread. */ public abstract void load_background_image (); - /** Load images in a background thread. */+ /** Run a background thread and block the gui. */ public abstract void run_background_thread (Task t); + /** Run a background thread without blocking the gui. */+ public abstract void run_non_blocking_background_thread (Task t);+ /** Copy text to clipboard. */ public abstract void set_clipboard_text (string text); @@ -36,6 +36,7 @@ public class FallbackFont : GLib.Object { FcConfig* font_config = null; FontFace* default_font = null;+ static bool font_config_stated = false; string default_font_file_name = "Roboto-Regular.ttf"; string default_font_family_name = "Roboto";@@ -49,8 +50,20 @@ public class FallbackFont : GLib.Object { string home = Environment.get_home_dir (); font_directories = new Gee.ArrayList<File> ();- font_config = FcInitLoadConfigAndFonts (); + if (!font_config_stated) {+ font_config_stated = true;+ + IdleSource idle = new IdleSource ();+ idle.set_callback (() => {+ Task t = new Task ();+ t.task.connect (init_font_config);+ MainWindow.native_window.run_non_blocking_background_thread (t);+ return false;+ });+ idle.attach (null);+ }+ add_font_folder ("/usr/share/fonts/"); add_font_folder ("/usr/local/share/fonts/"); add_font_folder (home + "/.local/share/fonts");@@ -74,6 +87,17 @@ public class FallbackFont : GLib.Object { } } + public void init_font_config () {+ FcConfig* fc = FcInitLoadConfigAndFonts ();+ IdleSource idle = new IdleSource ();+ + idle.set_callback (() => {+ font_config = fc;+ return false;+ });+ idle.attach (null);+ }+ public Font get_single_glyph_font (unichar c) { Font f; unichar last; @@ -30,6 +30,11 @@ gchar* find_font (FcConfig* fontconfig, const gchar* characters) { gchar* remaining_characters; gunichar character; + if (fontconfig == NULL) {+ g_warning("Font config not loaded.");+ return NULL;+ }+ result = NULL; pattern = FcPatternCreate (); @@ -88,6 +93,11 @@ gchar* find_font_file (FcConfig* font_config, const gchar* font_name) { FcObjectSet* font_properties; FcFontSet* fonts; int i;++ if (font_config == NULL) {+ g_warning("Font config not loaded.");+ return NULL;+ } path = NULL; name = font_name;@@ -24,6 +24,11 @@ public class Task : GLib.Object { public void run () { task (); }++ public void* perform_task() {+ run ();+ return null;+ } } }@@ -66,12 +66,12 @@ class Builder(object): 'basename': 'mkdir ' + build_directory, 'actions': ['mkdir -p ' + path.join('build', 'bin'), 'mkdir -p ' + build_directory, - 'touch ' + build_file],+ '[ -e "' + build_file + '" ] || touch "' + build_file + '"'], 'targets': [build_file], } copied_csources = []- copied_cheader = []+ copied_cheader = [] for csource in copied_cheader_paths + copied_csource_paths: dest = path.join(build_directory, path.basename(csource)) @@ -82,7 +82,7 @@ class Builder(object): yield { 'basename': 'copy ' + csource,- 'file_dep': [build_file] + bindep,+ 'file_dep': [build_file] + [csource], 'actions': ['cp ' + csource + ' ' + build_directory], 'targets': [dest] }@@ -155,7 +155,7 @@ def is_up_to_date(task): if len(dependency_times) == 0 or len(target_times) == 0: return False - return dependency_times[-1] > target_times[0]+ return dependency_times[-1] <= target_times[0] def execute_task(task): if is_up_to_date(task):