Own brush workers and thin preview/platform seams
This commit is contained in:
@@ -7,12 +7,90 @@
|
||||
#include "node_dialog_export_ppbr.h"
|
||||
#include "node_panel_brush.h"
|
||||
|
||||
#include <condition_variable>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include <stop_token>
|
||||
#include <thread>
|
||||
|
||||
namespace pp::panopainter {
|
||||
namespace {
|
||||
|
||||
class LegacyBrushPackageWorker final {
|
||||
public:
|
||||
LegacyBrushPackageWorker()
|
||||
: worker_([this](std::stop_token stop_token) {
|
||||
run(stop_token);
|
||||
})
|
||||
{
|
||||
}
|
||||
|
||||
~LegacyBrushPackageWorker()
|
||||
{
|
||||
shutdown();
|
||||
}
|
||||
|
||||
void post(std::function<void()> task)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (stopping_)
|
||||
return;
|
||||
tasks_.push_back(std::move(task));
|
||||
}
|
||||
cv_.notify_one();
|
||||
}
|
||||
|
||||
private:
|
||||
void shutdown()
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
stopping_ = true;
|
||||
}
|
||||
cv_.notify_all();
|
||||
}
|
||||
|
||||
void run(std::stop_token stop_token)
|
||||
{
|
||||
for (;;) {
|
||||
std::function<void()> task;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
cv_.wait(lock, [&] {
|
||||
return stopping_ || stop_token.stop_requested() || !tasks_.empty();
|
||||
});
|
||||
if ((stopping_ || stop_token.stop_requested()) && tasks_.empty())
|
||||
break;
|
||||
task = std::move(tasks_.front());
|
||||
tasks_.pop_front();
|
||||
}
|
||||
|
||||
if (task) {
|
||||
try {
|
||||
task();
|
||||
} catch (...) {
|
||||
LOG("brush package export worker task failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::mutex mutex_;
|
||||
std::condition_variable cv_;
|
||||
std::deque<std::function<void()>> tasks_;
|
||||
bool stopping_ = false;
|
||||
std::jthread worker_;
|
||||
};
|
||||
|
||||
LegacyBrushPackageWorker& brush_package_worker()
|
||||
{
|
||||
static LegacyBrushPackageWorker worker;
|
||||
return worker;
|
||||
}
|
||||
|
||||
NodePanelBrushPreset::PPBRInfo to_legacy_ppbr_info(
|
||||
const pp::app::BrushPackageExportRequest& request,
|
||||
const NodeDialogExportPPBR& dialog)
|
||||
@@ -44,20 +122,29 @@ public:
|
||||
{
|
||||
const auto path_string = std::string(path);
|
||||
const auto info = to_legacy_ppbr_info(request, dialog_);
|
||||
auto presets = app_.presets;
|
||||
if (mode_ == LegacyBrushPackageExportMode::desktop_async_close_and_message) {
|
||||
auto* app = &app_;
|
||||
auto* dialog = &dialog_;
|
||||
std::thread([app, dialog, path_string, info] {
|
||||
auto dialog = std::static_pointer_cast<NodeDialogExportPPBR>(dialog_.shared_from_this());
|
||||
brush_package_worker().post([app, presets, dialog, path_string, info] {
|
||||
BT_SetTerminate();
|
||||
app->presets->export_ppbr(path_string, info);
|
||||
pp::panopainter::close_legacy_dialog_node(*dialog);
|
||||
if (presets) {
|
||||
presets->export_ppbr(path_string, info);
|
||||
}
|
||||
const auto plan = pp::app::plan_brush_package_export_success_dialog(path_string);
|
||||
app->message_box(plan.title, plan.message, plan.show_cancel);
|
||||
}).detach();
|
||||
app->ui_task([dialog, plan] {
|
||||
if (dialog) {
|
||||
pp::panopainter::close_legacy_dialog_node(*dialog);
|
||||
}
|
||||
App::I->message_box(plan.title, plan.message, plan.show_cancel);
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
app_.presets->export_ppbr(path_string, info);
|
||||
if (presets) {
|
||||
presets->export_ppbr(path_string, info);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user