Avoid loading current dithering matrix on each mouse move (related to #4174)

With this change we are reusing the cached/loaded matrix on each
DitheringMatrixInfo struct, calling the
load_dithering_matrix_from_sprite() function just one time (not on
each brush preview/mouse movement).
This commit is contained in:
David Capello 2024-08-21 19:49:55 -03:00
parent 29479cb231
commit e87f6df72b
4 changed files with 23 additions and 17 deletions

View File

@ -936,15 +936,15 @@ const render::DitheringMatrix* Extensions::ditheringMatrix(const std::string& ma
return nullptr;
}
std::vector<Extension::DitheringMatrixInfo> Extensions::ditheringMatrices()
std::vector<Extension::DitheringMatrixInfo*> Extensions::ditheringMatrices()
{
std::vector<Extension::DitheringMatrixInfo> result;
std::vector<Extension::DitheringMatrixInfo*> result;
for (auto ext : m_extensions) {
if (!ext->isEnabled()) // Ignore disabled themes
continue;
for (auto it : ext->m_ditheringMatrices)
result.push_back(it.second);
for (auto& it : ext->m_ditheringMatrices)
result.push_back(&it.second);
}
return result;
}

View File

@ -222,7 +222,13 @@ namespace app {
std::string palettePath(const std::string& palId);
ExtensionItems palettes() const;
const render::DitheringMatrix* ditheringMatrix(const std::string& matrixId);
std::vector<Extension::DitheringMatrixInfo> ditheringMatrices();
// The returned collection can be used temporarily while
// extensions are not installed/uninstalled. Each element is
// pointing to the real matrix info owned by extensions, this is
// needed to cache the matrix because it is lazy loaded from an
// image file. These pointers cannot be deleted.
std::vector<Extension::DitheringMatrixInfo*> ditheringMatrices();
obs::signal<void(Extension*)> NewExtension;
obs::signal<void(Extension*)> KeysChange;

View File

@ -1260,9 +1260,9 @@ public:
bool found = false;
auto ditheringMatrices = App::instance()
->extensions().ditheringMatrices();
for (const auto& it : ditheringMatrices) {
if (it.name() == dynaPref.matrixName()) {
m_dynamics.ditheringMatrix = it.matrix();
for (const auto* it : ditheringMatrices) {
if (it->name() == dynaPref.matrixName()) {
m_dynamics.ditheringMatrix = it->matrix();
found = true;
break;
}

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2023 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2017 David Capello
//
// This program is distributed under the terms of
@ -217,25 +217,25 @@ void DitheringSelector::regenerate(int selectedItemIndex)
addItem(new DitherItem(render::DitheringAlgorithm::None,
render::DitheringMatrix(),
Strings::dithering_selector_no_dithering()));
for (const auto& it : ditheringMatrices) {
for (const auto* it : ditheringMatrices) {
try {
addItem(new DitherItem(
render::DitheringAlgorithm::Ordered,
it.matrix(),
Strings::dithering_selector_ordered_dithering() + it.name()));
it->matrix(),
Strings::dithering_selector_ordered_dithering() + it->name()));
}
catch (const std::exception& e) {
LOG(ERROR, "%s\n", e.what());
Console::showException(e);
}
}
for (const auto& it : ditheringMatrices) {
for (const auto* it : ditheringMatrices) {
try {
addItem(
new DitherItem(
render::DitheringAlgorithm::Old,
it.matrix(),
Strings::dithering_selector_old_dithering() + it.name()));
it->matrix(),
Strings::dithering_selector_old_dithering() + it->name()));
}
catch (const std::exception& e) {
LOG(ERROR, "%s\n", e.what());
@ -251,9 +251,9 @@ void DitheringSelector::regenerate(int selectedItemIndex)
case SelectMatrix:
addItem(new DitherItem(render::DitheringMatrix(),
Strings::dithering_selector_no_dithering()));
for (auto& it : ditheringMatrices) {
for (const auto* it : ditheringMatrices) {
try {
addItem(new DitherItem(it.matrix(), it.name()));
addItem(new DitherItem(it->matrix(), it->name()));
}
catch (const std::exception& e) {
LOG(ERROR, "%s\n", e.what());