Trim main task queue, recording label, and canvas draw callbacks
This commit is contained in:
10
src/app.cpp
10
src/app.cpp
@@ -214,6 +214,7 @@ void App::initLog()
|
||||
namespace pp::panopainter
|
||||
{
|
||||
bool process_legacy_recording_worker_iteration(App& app);
|
||||
void update_legacy_recording_frame_label(App& app);
|
||||
}
|
||||
|
||||
bool App::check_license()
|
||||
@@ -566,14 +567,7 @@ void App::update_memory_usage(size_t bytes)
|
||||
|
||||
void App::update_rec_frames()
|
||||
{
|
||||
if (auto txt = layout[main_id]->find<NodeText>("txt-rec"))
|
||||
{
|
||||
const auto label = pp::app::make_recording_frame_label(
|
||||
rec_running,
|
||||
Canvas::I->m_encoder != nullptr,
|
||||
Canvas::I->m_encoder ? Canvas::I->m_encoder->frames_count() : 0);
|
||||
txt->set_text(label.text.c_str());
|
||||
}
|
||||
pp::panopainter::update_legacy_recording_frame_label(*this);
|
||||
}
|
||||
|
||||
int App::res_from_index(int i)
|
||||
|
||||
@@ -529,7 +529,25 @@ template <typename LayerMergeT, typename SamplerT, typename FacePlaneT, typename
|
||||
.unbind_layer_texture = [layer_merge, plane_index] {
|
||||
layer_merge->rtt(plane_index).unbindTexture();
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
template <typename LayerT, typename FacePlaneT, typename SetActiveTextureUnit>
|
||||
[[nodiscard]] inline auto make_legacy_canvas_draw_merge_layer_frame_draw(
|
||||
LayerT* layer,
|
||||
FacePlaneT* face_plane,
|
||||
SetActiveTextureUnit set_active_texture_unit,
|
||||
int plane_index,
|
||||
float layer_opacity)
|
||||
{
|
||||
return [layer, face_plane, set_active_texture_unit, plane_index, layer_opacity](int frame, float onion_alpha) {
|
||||
ShaderManager::u_float(kShaderUniform::Alpha, layer_opacity * onion_alpha);
|
||||
set_active_texture_unit(0);
|
||||
layer->rtt(plane_index, frame).bindTexture();
|
||||
face_plane->draw_fill();
|
||||
set_active_texture_unit(0);
|
||||
layer->rtt(plane_index, frame).unbindTexture();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,14 @@
|
||||
|
||||
#include "app.h"
|
||||
#include "canvas.h"
|
||||
#include "app_core/app_status.h"
|
||||
#include "legacy_app_dialog_services.h"
|
||||
#include "legacy_ui_overlay_services.h"
|
||||
#include "node_progress_bar.h"
|
||||
|
||||
namespace pp::panopainter {
|
||||
void update_legacy_recording_frame_label(App& app);
|
||||
|
||||
namespace {
|
||||
|
||||
pp::app::RecordingWorkerIterationPlan make_recording_worker_iteration_plan(App& app)
|
||||
@@ -42,9 +45,25 @@ void encode_recording_frame(
|
||||
LOG("rec frame encoded");
|
||||
|
||||
if (plan.update_frame_label)
|
||||
app.update_rec_frames();
|
||||
update_legacy_recording_frame_label(app);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void update_legacy_recording_frame_label(App& app)
|
||||
{
|
||||
if (auto txt = app.layout[app.main_id]->find<NodeText>("txt-rec"))
|
||||
{
|
||||
const auto label = pp::app::make_recording_frame_label(
|
||||
app.rec_running,
|
||||
Canvas::I->m_encoder != nullptr,
|
||||
Canvas::I->m_encoder ? Canvas::I->m_encoder->frames_count() : 0);
|
||||
txt->set_text(label.text.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class LegacyRecordingServices final : public pp::app::RecordingServices {
|
||||
public:
|
||||
explicit LegacyRecordingServices(App& app) noexcept
|
||||
@@ -54,7 +73,7 @@ public:
|
||||
|
||||
void start_thread() override
|
||||
{
|
||||
app_.update_rec_frames();
|
||||
update_legacy_recording_frame_label(app_);
|
||||
app_.rec_thread = std::jthread(&App::rec_loop, &app_);
|
||||
}
|
||||
|
||||
@@ -65,7 +84,7 @@ public:
|
||||
app_.rec_cv.notify_all();
|
||||
if (app_.rec_thread.joinable())
|
||||
app_.rec_thread.join();
|
||||
app_.update_rec_frames();
|
||||
update_legacy_recording_frame_label(app_);
|
||||
}
|
||||
|
||||
void delete_recorded_files() override
|
||||
@@ -80,7 +99,7 @@ public:
|
||||
|
||||
void update_frame_label() override
|
||||
{
|
||||
app_.update_rec_frames();
|
||||
update_legacy_recording_frame_label(app_);
|
||||
}
|
||||
|
||||
void begin_export(int progress_total) override
|
||||
|
||||
65
src/main.cpp
65
src/main.cpp
@@ -54,8 +54,6 @@ struct RetainedState
|
||||
std::map<kKey, int> vkey_map;
|
||||
wchar_t window_title[512]{};
|
||||
std::jthread hmd_renderer;
|
||||
std::deque<std::packaged_task<void()>> main_tasklist;
|
||||
std::mutex main_task_mutex;
|
||||
float timer_stylus = 0;
|
||||
float timer_ink_touch = 0;
|
||||
float timer_ink_pen = 0;
|
||||
@@ -72,6 +70,46 @@ RetainedState& retained_state()
|
||||
return state;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
struct RetainedMainTaskQueue final
|
||||
{
|
||||
std::deque<std::packaged_task<void()>> tasklist;
|
||||
std::mutex task_mutex;
|
||||
};
|
||||
|
||||
RetainedMainTaskQueue& retained_main_task_queue()
|
||||
{
|
||||
static RetainedMainTaskQueue queue;
|
||||
return queue;
|
||||
}
|
||||
|
||||
template <typename Callable>
|
||||
void enqueue_main_task(Callable&& task)
|
||||
{
|
||||
auto& queue = retained_main_task_queue();
|
||||
std::lock_guard<std::mutex> lock(queue.task_mutex);
|
||||
queue.tasklist.emplace_back(std::forward<Callable>(task));
|
||||
}
|
||||
|
||||
void drain_main_tasks()
|
||||
{
|
||||
std::deque<std::packaged_task<void()>> working_list;
|
||||
{
|
||||
auto& queue = retained_main_task_queue();
|
||||
std::lock_guard<std::mutex> lock(queue.task_mutex);
|
||||
working_list = std::move(queue.tasklist);
|
||||
}
|
||||
|
||||
while (!working_list.empty())
|
||||
{
|
||||
working_list.front()();
|
||||
working_list.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::atomic<int> vr_frames{0};
|
||||
std::atomic<int> running{-1};
|
||||
std::atomic_bool vr_running{false};
|
||||
@@ -163,8 +201,7 @@ std::string GetLastErrorAsString()
|
||||
void destroy_window()
|
||||
{
|
||||
auto& state = retained_state();
|
||||
std::lock_guard<std::mutex> lock(state.main_task_mutex);
|
||||
state.main_tasklist.emplace_back([hWnd = state.hWnd] {
|
||||
enqueue_main_task([hWnd = state.hWnd] {
|
||||
PostMessage(hWnd, WM_USER_CLOSE, 0, 0);
|
||||
});
|
||||
}
|
||||
@@ -225,8 +262,7 @@ void win32_update_fps(int frames)
|
||||
swprintf_s(title_fps, L"%s - %d fps", state.window_title, frames);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state.main_task_mutex);
|
||||
state.main_tasklist.emplace_back([hWnd = state.hWnd] {
|
||||
enqueue_main_task([hWnd = state.hWnd] {
|
||||
SetWindowText(hWnd, title_fps);
|
||||
});
|
||||
}
|
||||
@@ -991,22 +1027,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
// list of tasks for the main thread
|
||||
{
|
||||
std::deque<std::packaged_task<void()>> working_list;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state.main_task_mutex);
|
||||
working_list = std::move(state.main_tasklist);
|
||||
}
|
||||
|
||||
if (!working_list.empty())
|
||||
{
|
||||
while (!working_list.empty())
|
||||
{
|
||||
working_list.front()();
|
||||
working_list.pop_front();
|
||||
}
|
||||
}
|
||||
}
|
||||
drain_main_tasks();
|
||||
}
|
||||
// Clean up
|
||||
WacomTablet::I.terminate();
|
||||
|
||||
@@ -469,14 +469,12 @@ void NodeCanvas::draw()
|
||||
m_canvas->m_plane_transform[plane_index] *
|
||||
glm::translate(glm::vec3(0, 0, -1));
|
||||
|
||||
const auto draw_layer_frame = [&](int frame, float onion_alpha) {
|
||||
ShaderManager::u_float(kShaderUniform::Alpha, m_canvas->m_layers[layer_index]->m_opacity * onion_alpha);
|
||||
set_active_texture_unit(0);
|
||||
m_canvas->m_layers[layer_index]->rtt(plane_index, frame).bindTexture();
|
||||
m_face_plane.draw_fill();
|
||||
set_active_texture_unit(0);
|
||||
m_canvas->m_layers[layer_index]->rtt(plane_index, frame).unbindTexture();
|
||||
};
|
||||
const auto draw_layer_frame = pp::panopainter::make_legacy_canvas_draw_merge_layer_frame_draw(
|
||||
m_canvas->m_layers[layer_index].get(),
|
||||
&m_face_plane,
|
||||
set_active_texture_unit,
|
||||
plane_index,
|
||||
m_canvas->m_layers[layer_index]->m_opacity);
|
||||
|
||||
pp::panopainter::execute_legacy_canvas_draw_merge_layer_plane(
|
||||
m_canvas->m_current_stroke && m_canvas->m_current_mode == kCanvasMode::Erase && m_canvas->m_show_tmp && m_canvas->m_current_layer_idx == layer_index,
|
||||
|
||||
Reference in New Issue
Block a user