diff --git a/src/app/app.cpp b/src/app/app.cpp index 2657df729..aa5c44796 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -17,6 +17,7 @@ #include "app/cli/cli_processor.h" #include "app/cli/default_cli_delegate.h" #include "app/cli/preview_cli_delegate.h" +#include "app/color_spaces.h" #include "app/color_utils.h" #include "app/commands/commands.h" #include "app/console.h" @@ -59,11 +60,11 @@ #include "base/split_string.h" #include "doc/sprite.h" #include "fmt/format.h" -#include "render/render.h" #include "os/display.h" #include "os/error.h" #include "os/surface.h" #include "os/system.h" +#include "render/render.h" #include "ui/intern.h" #include "ui/ui.h" @@ -104,6 +105,9 @@ class App::CoreModules { public: ConfigModule m_configModule; Preferences m_preferences; + CoreModules() { + initialize_color_spaces(); + } }; class App::LoadLanguage { diff --git a/src/app/color_spaces.cpp b/src/app/color_spaces.cpp index e132dfc64..46e4cccd2 100644 --- a/src/app/color_spaces.cpp +++ b/src/app/color_spaces.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018 Igara Studio S.A. +// Copyright (C) 2018-2019 Igara Studio S.A. // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -19,6 +19,20 @@ namespace app { +// We use this variable to avoid accessing Preferences::instance() +// from background threads when a color conversion between color +// spaces must be done. +static bool g_manage = false; + +void initialize_color_spaces() +{ + g_manage = Preferences::instance().color.manage(); + Preferences::instance().color.manage.AfterChange.connect( + [](bool manage){ + g_manage = manage; + }); +} + os::ColorSpacePtr get_screen_color_space() { return os::instance()->defaultDisplay()->colorSpace(); @@ -56,7 +70,7 @@ gfx::ColorSpacePtr get_working_rgb_space_from_preferences() ConvertCS::ConvertCS() { - if (Preferences::instance().color.manage()) { + if (g_manage) { auto srcCS = get_current_color_space(); auto dstCS = get_screen_color_space(); if (srcCS && dstCS) @@ -67,7 +81,7 @@ ConvertCS::ConvertCS() ConvertCS::ConvertCS(const os::ColorSpacePtr& srcCS, const os::ColorSpacePtr& dstCS) { - if (Preferences::instance().color.manage()) { + if (g_manage) { m_conversion = os::instance()->convertBetweenColorSpace(srcCS, dstCS); } } diff --git a/src/app/color_spaces.h b/src/app/color_spaces.h index 2a1cdabc2..cebdf2684 100644 --- a/src/app/color_spaces.h +++ b/src/app/color_spaces.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018 Igara Studio S.A. +// Copyright (C) 2018-2019 Igara Studio S.A. // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -20,6 +20,8 @@ namespace doc { namespace app { + void initialize_color_spaces(); + os::ColorSpacePtr get_screen_color_space(); // Returns the color space of the current document. diff --git a/src/ui/system.cpp b/src/ui/system.cpp index 982035c1a..6caec99ee 100644 --- a/src/ui/system.cpp +++ b/src/ui/system.cpp @@ -362,7 +362,8 @@ void execute_from_ui_thread(std::function&& f) bool is_ui_thread() { - return (main_gui_thread == base::this_thread::native_handle()); + return (!main_gui_thread || + main_gui_thread == base::this_thread::native_handle()); } #ifdef _DEBUG