mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-10 03:44:16 +00:00
Create the ContextWriter+Tx from UI thread on filters (related to #2122)
When we create a Tx the active site is queried, and the UIContext needs access to the UI to calculate the active site correctly.
This commit is contained in:
parent
b5547251f5
commit
4264f199cd
@ -280,10 +280,6 @@ void FilterManagerImpl::applyToTarget()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize writting operation
|
|
||||||
ContextWriter writer(m_reader);
|
|
||||||
m_tx.reset(new Tx(writer.context(), m_filter->getName(), ModifyDocument));
|
|
||||||
|
|
||||||
m_progressBase = 0.0f;
|
m_progressBase = 0.0f;
|
||||||
m_progressWidth = (cels.size() > 0 ? 1.0f / cels.size(): 1.0f);
|
m_progressWidth = (cels.size() > 0 ? 1.0f / cels.size(): 1.0f);
|
||||||
|
|
||||||
@ -322,9 +318,18 @@ void FilterManagerImpl::applyToTarget()
|
|||||||
m_oldPalette.reset(nullptr);
|
m_oldPalette.reset(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FilterManagerImpl::initTransaction()
|
||||||
|
{
|
||||||
|
ASSERT(!m_tx);
|
||||||
|
m_writer.reset(new ContextWriter(m_reader));
|
||||||
|
m_tx.reset(new Tx(m_writer->context(),
|
||||||
|
m_filter->getName(),
|
||||||
|
ModifyDocument));
|
||||||
|
}
|
||||||
|
|
||||||
bool FilterManagerImpl::isTransaction() const
|
bool FilterManagerImpl::isTransaction() const
|
||||||
{
|
{
|
||||||
return m_tx != nullptr;
|
return (m_tx != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This must be executed in the main UI thread.
|
// This must be executed in the main UI thread.
|
||||||
@ -333,6 +338,7 @@ void FilterManagerImpl::commitTransaction()
|
|||||||
{
|
{
|
||||||
ASSERT(m_tx);
|
ASSERT(m_tx);
|
||||||
m_tx->commit();
|
m_tx->commit();
|
||||||
|
m_writer.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_UI
|
#ifdef ENABLE_UI
|
||||||
|
@ -90,6 +90,8 @@ namespace app {
|
|||||||
void end();
|
void end();
|
||||||
bool applyStep();
|
bool applyStep();
|
||||||
void applyToTarget();
|
void applyToTarget();
|
||||||
|
|
||||||
|
void initTransaction();
|
||||||
bool isTransaction() const;
|
bool isTransaction() const;
|
||||||
void commitTransaction();
|
void commitTransaction();
|
||||||
|
|
||||||
@ -141,6 +143,7 @@ namespace app {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
ContextReader m_reader;
|
ContextReader m_reader;
|
||||||
|
std::unique_ptr<ContextWriter> m_writer;
|
||||||
Site& m_site;
|
Site& m_site;
|
||||||
Filter* m_filter;
|
Filter* m_filter;
|
||||||
doc::Cel* m_cel;
|
doc::Cel* m_cel;
|
||||||
|
@ -135,6 +135,9 @@ FilterWorker::~FilterWorker()
|
|||||||
|
|
||||||
void FilterWorker::run()
|
void FilterWorker::run()
|
||||||
{
|
{
|
||||||
|
// Initialize writting transaction
|
||||||
|
m_filterMgr->initTransaction();
|
||||||
|
|
||||||
#ifdef ENABLE_UI
|
#ifdef ENABLE_UI
|
||||||
std::thread thread;
|
std::thread thread;
|
||||||
// Open the alert window in foreground (this is modal, locks the main thread)
|
// Open the alert window in foreground (this is modal, locks the main thread)
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "app/ui/workspace_tabs.h"
|
#include "app/ui/workspace_tabs.h"
|
||||||
#include "base/mutex.h"
|
#include "base/mutex.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
|
#include "ui/system.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -282,6 +283,12 @@ void UIContext::onRemoveDocument(Doc* doc)
|
|||||||
|
|
||||||
void UIContext::onGetActiveSite(Site* site) const
|
void UIContext::onGetActiveSite(Site* site) const
|
||||||
{
|
{
|
||||||
|
// We can use the activeView only from the UI thread.
|
||||||
|
#ifdef _DEBUG
|
||||||
|
if (isUIAvailable())
|
||||||
|
ui::assert_ui_thread();
|
||||||
|
#endif
|
||||||
|
|
||||||
DocView* view = activeView();
|
DocView* view = activeView();
|
||||||
if (view) {
|
if (view) {
|
||||||
view->getSite(site);
|
view->getSite(site);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user