From 89c829a2421e97c646e6cc68b1a8b29eaf2bbd49 Mon Sep 17 00:00:00 2001 From: Jehan Date: Sun, 27 May 2018 02:13:33 +0200 Subject: [PATCH] Issue #1211: Load fonts in background after startup. Fonts should not be blocking startup as this provides a very bad experience when people have a lot of fonts. This was experienced even more on Windows where loading time are often excessively long. We were already running font loading in a thread, yet were still blocking startup (thread was only so that the loading status GUI could get updated as a feedback). Now we will only start loading and proceed directly to next steps. While fonts are not loaded, the text tool will not be usable, yet all other activities can be performed. (cherry picked from commit 2484dec7d55e75499712d913921d10902d326332) --- app/actions/fonts-commands.c | 2 +- app/core/gimp.c | 4 +-- app/pdb/fonts-cmds.c | 2 +- app/text/gimp-fonts.c | 62 +++++++++++++++--------------------- app/text/gimp-fonts.h | 1 - pdb/groups/fonts.pdb | 2 +- 6 files changed, 30 insertions(+), 43 deletions(-) diff --git a/app/actions/fonts-commands.c b/app/actions/fonts-commands.c index 0763161ff2..149cfef7c1 100644 --- a/app/actions/fonts-commands.c +++ b/app/actions/fonts-commands.c @@ -39,5 +39,5 @@ fonts_refresh_cmd_callback (GtkAction *action, GimpContext *context = action_data_get_context (data); if (context) - gimp_fonts_load (context->gimp, NULL, NULL); + gimp_fonts_load (context->gimp, NULL); } diff --git a/app/core/gimp.c b/app/core/gimp.c index 17c688a4dc..5530f5c135 100644 --- a/app/core/gimp.c +++ b/app/core/gimp.c @@ -799,8 +799,8 @@ gimp_restore (Gimp *gimp, /* initialize the list of fonts */ if (! gimp->no_fonts) { - status_callback (NULL, _("Fonts (this may take a while)"), 0.7); - gimp_fonts_load (gimp, status_callback, error); + status_callback (NULL, _("Fonts"), 0.7); + gimp_fonts_load (gimp, error); } /* initialize the template list */ diff --git a/app/pdb/fonts-cmds.c b/app/pdb/fonts-cmds.c index b599e4d5a4..c170d9ec8d 100644 --- a/app/pdb/fonts-cmds.c +++ b/app/pdb/fonts-cmds.c @@ -46,7 +46,7 @@ fonts_refresh_invoker (GimpProcedure *procedure, const GimpValueArray *args, GError **error) { - gimp_fonts_load (gimp, NULL, error); + gimp_fonts_load (gimp, error); return gimp_procedure_get_return_values (procedure, TRUE, NULL); } diff --git a/app/text/gimp-fonts.c b/app/text/gimp-fonts.c index 53413693c3..f30507a148 100644 --- a/app/text/gimp-fonts.c +++ b/app/text/gimp-fonts.c @@ -110,14 +110,22 @@ gimp_fonts_load_async (GimpAsync *async, gimp_async_finish (async, NULL); } +static void +gimp_fonts_load_async_callback (GimpAsync *async, + GimpFontList *fonts) +{ + if (gimp_async_is_finished (async)) + gimp_font_list_restore (fonts); +} + void -gimp_fonts_load (Gimp *gimp, - GimpInitStatusFunc status_callback, - GError **error) +gimp_fonts_load (Gimp *gimp, + GError **error) { - FcConfig *config; - GFile *fonts_conf; - GList *path; + FcConfig *config; + GFile *fonts_conf; + GList *path; + GimpAsync *async; g_return_if_fail (GIMP_IS_FONT_LIST (gimp->fonts)); @@ -147,36 +155,16 @@ gimp_fonts_load (Gimp *gimp, gimp_fonts_add_directories (gimp, config, path, error); g_list_free_full (path, (GDestroyNotify) g_object_unref); - if (status_callback) - { - GimpAsync *async; - gint64 end_time; - - /* We perform font cache initialization in a separate thread, so - * in the case a cache rebuild is to be done it will not block - * the UI. - */ - - async = gimp_parallel_run_async ( - (GimpParallelRunAsyncFunc) gimp_fonts_load_async, - config); - - do - { - status_callback (NULL, NULL, 0.6); - - end_time = g_get_monotonic_time () + 0.1 * G_TIME_SPAN_SECOND; - } - while (! gimp_async_wait_until (async, end_time)); - - g_object_unref (async); - } - else - { - gimp_fonts_load_func (config); - } - - gimp_font_list_restore (GIMP_FONT_LIST (gimp->fonts)); + /* We perform font cache initialization in a separate thread, so + * in the case a cache rebuild is to be done it will not block + * the UI. + */ + async = gimp_parallel_run_async ((GimpParallelRunAsyncFunc) gimp_fonts_load_async, + config); + gimp_async_add_callback (async, + (GimpAsyncCallback) gimp_fonts_load_async_callback, + gimp->fonts); + g_object_unref (async); cleanup: gimp_container_thaw (GIMP_CONTAINER (gimp->fonts)); @@ -364,7 +352,7 @@ gimp_fonts_notify_font_path (GObject *gobject, { GError *error = NULL; - gimp_fonts_load (gimp, NULL, &error); + gimp_fonts_load (gimp, &error); if (error) { diff --git a/app/text/gimp-fonts.h b/app/text/gimp-fonts.h index 1928ce2022..ca17ef140b 100644 --- a/app/text/gimp-fonts.h +++ b/app/text/gimp-fonts.h @@ -24,7 +24,6 @@ void gimp_fonts_set_config (Gimp *gimp); void gimp_fonts_exit (Gimp *gimp); void gimp_fonts_load (Gimp *gimp, - GimpInitStatusFunc status_callback, GError **error); void gimp_fonts_reset (Gimp *gimp); diff --git a/pdb/groups/fonts.pdb b/pdb/groups/fonts.pdb index 0ca214c23f..a5fb6187c2 100644 --- a/pdb/groups/fonts.pdb +++ b/pdb/groups/fonts.pdb @@ -30,7 +30,7 @@ HELP %invoke = ( code => <<'CODE' { - gimp_fonts_load (gimp, NULL, error); + gimp_fonts_load (gimp, error); } CODE ); -- 2.20.1