mirror of https://github.com/aseprite/aseprite.git
Startup optimizations (#5090)
* Delay DitheringSelector startup * Delay setting the drag target * Delay & enqueue menu reloading
This commit is contained in:
parent
816be744ac
commit
b130601716
2
laf
2
laf
|
@ -1 +1 @@
|
|||
Subproject commit f858a8412897a4f9e95fd8aeac891466fbd06852
|
||||
Subproject commit fdc9001cb0251a40092ebb9b2bca6e61fdf9f6f7
|
|
@ -180,7 +180,6 @@ DitheringSelector::DitheringSelector(Type type) : m_type(type)
|
|||
m_extChanges = extensions.DitheringMatricesChange.connect([this] { regenerate(); });
|
||||
|
||||
setUseCustomWidget(true);
|
||||
regenerate();
|
||||
}
|
||||
|
||||
void DitheringSelector::onInitTheme(ui::InitThemeEvent& ev)
|
||||
|
@ -190,6 +189,16 @@ void DitheringSelector::onInitTheme(ui::InitThemeEvent& ev)
|
|||
setSizeHint(calcItemSizeHint(0));
|
||||
}
|
||||
|
||||
void DitheringSelector::onVisible(bool visible)
|
||||
{
|
||||
if (visible && !m_initialized) {
|
||||
// Only do the expensive regeneration when we're set as visible for the first time.
|
||||
regenerate();
|
||||
m_initialized = true;
|
||||
}
|
||||
ComboBox::onVisible(visible);
|
||||
}
|
||||
|
||||
void DitheringSelector::setSelectedItemByName(const std::string& name)
|
||||
{
|
||||
int index = findItemIndex(name);
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
|
||||
protected:
|
||||
void onInitTheme(ui::InitThemeEvent& ev) override;
|
||||
void onVisible(bool visible) override;
|
||||
|
||||
private:
|
||||
void regenerate(int selectedItemIndex = 0);
|
||||
|
@ -38,6 +39,7 @@ private:
|
|||
|
||||
Type m_type;
|
||||
obs::scoped_connection m_extChanges;
|
||||
bool m_initialized = false;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include "app/app.h"
|
||||
#include "app/app_menus.h"
|
||||
#include "app/extensions.h"
|
||||
#include "ui/manager.h"
|
||||
#include "ui/message.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
|
@ -26,13 +28,26 @@ MainMenuBar::MainMenuBar()
|
|||
|
||||
// Reload the main menu if there are changes in keyboard shortcuts
|
||||
// or scripts when extensions are installed/uninstalled or
|
||||
// enabled/disabled.
|
||||
m_extKeys = extensions.KeysChange.connect([this] { reload(); });
|
||||
m_extScripts = extensions.ScriptsChange.connect([this] { reload(); });
|
||||
// enabled/disabled, enqueued to avoid multiple reloads.
|
||||
m_extKeys = extensions.KeysChange.connect([&] { queueReload(); });
|
||||
m_extScripts = extensions.ScriptsChange.connect([&] { queueReload(); });
|
||||
}
|
||||
|
||||
void MainMenuBar::queueReload()
|
||||
{
|
||||
if (m_queuedReload)
|
||||
return;
|
||||
|
||||
m_queuedReload = true;
|
||||
|
||||
auto* msg = new CallbackMessage([this] { reload(); });
|
||||
msg->setRecipient(this);
|
||||
Manager::getDefault()->enqueueMessage(msg);
|
||||
}
|
||||
|
||||
void MainMenuBar::reload()
|
||||
{
|
||||
m_queuedReload = false;
|
||||
setMenu(nullptr);
|
||||
|
||||
// Reload all menus.
|
||||
|
|
|
@ -18,11 +18,13 @@ class MainMenuBar : public ui::MenuBar {
|
|||
public:
|
||||
MainMenuBar();
|
||||
|
||||
void queueReload();
|
||||
void reload();
|
||||
|
||||
private:
|
||||
obs::scoped_connection m_extKeys;
|
||||
obs::scoped_connection m_extScripts;
|
||||
bool m_queuedReload = false;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
|
|
@ -197,10 +197,8 @@ Manager::Manager(const os::WindowRef& nativeWindow)
|
|||
, m_mouseButton(kButtonNone)
|
||||
{
|
||||
// The native window can be nullptr when running tests
|
||||
if (nativeWindow) {
|
||||
if (nativeWindow)
|
||||
nativeWindow->setUserData(&m_display);
|
||||
nativeWindow->setDragTarget(this);
|
||||
}
|
||||
|
||||
ASSERT(manager_thread == std::thread::id());
|
||||
manager_thread = std::this_thread::get_id();
|
||||
|
@ -242,6 +240,14 @@ Manager::Manager(const os::WindowRef& nativeWindow)
|
|||
|
||||
// TODO check if this is needed
|
||||
onNewDisplayConfiguration(&m_display);
|
||||
|
||||
if (nativeWindow) {
|
||||
// Setting the drag target has a slight performance cost that we can offset by running it later.
|
||||
auto* callbackMessage = new CallbackMessage(
|
||||
[this, nativeWindow] { nativeWindow->setDragTarget(this); });
|
||||
callbackMessage->setRecipient(this);
|
||||
enqueueMessage(callbackMessage);
|
||||
}
|
||||
}
|
||||
|
||||
Manager::~Manager()
|
||||
|
|
Loading…
Reference in New Issue