diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index 889e890b..b243a7ee 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -18,6 +18,21 @@ agent or engineer to remove them without reconstructing context from chat. ## Reductions +- 2026-06-16: `DEBT-0036` was narrowed again. `NodeStrokePreview` background + preview execution now owns its worker as `std::jthread` with explicit stop, + unblock, and join semantics instead of a raw `std::thread`; retained queue + ownership, static renderer resources, and preview execution flow remain. +- 2026-06-16: `DEBT-0037` was narrowed again. Recording worker ownership now + uses `std::jthread` through `App::rec_thread` and + `src/legacy_recording_services.cpp`, with explicit stop requests before the + existing notify/join flow; retained recording loop control, progress + lifetime, and export execution remain. +- 2026-06-16: `DEBT-0017`/`DEBT-0051`/`DEBT-0052`/`DEBT-0055` were narrowed + again. `active_apple_document_platform_services()` in + `src/platform_legacy/legacy_platform_services.cpp` now captures explicit + Apple view/app handles for its bridge callbacks instead of closing over + `App::I` inside those lambdas, while the rest of the retained platform + fallback still owns broader singleton reach and platform execution. - 2026-06-16: `DEBT-0043`/`DEBT-0040`/`DEBT-0042` were narrowed again. The retained `Canvas` async import/export/save/open entrypoints in `src/canvas.cpp` no longer launch detached threads; they now use an owned @@ -2169,7 +2184,7 @@ agent or engineer to remove them without reconstructing context from chat. | DEBT-0034 | Open | Modernization | About menu command planning and execution dispatch now consume pure `pp_app_core` through `App::init_menu_about`, `pano_cli plan-about-menu`, and the `AboutMenuServices` boundary, and live execution is centralized in `src/legacy_app_shell_services.*`, but the bridge still opens legacy About/manual/what's-new dialogs, invokes the injected crash hook, and runs the legacy Canvas stroke performance test directly | Preserve About menu behavior while dialogs and diagnostics move toward app/UI/platform services | `pp_app_core_about_menu_tests`; `pano_cli plan-about-menu --command news --version-major 2 --version-minor 5 --version-fix 7`; `pano_cli plan-about-menu --command performance --no-canvas`; `ctest --preset desktop-fast --build-config Debug` | About/manual/what's-new dialog dispatch, crash-test dispatch, and performance-test execution are owned by injected app/UI/platform services with `App::init_menu_about` acting only as a UI adapter and no legacy About adapter | | DEBT-0035 | Open | Modernization | Main toolbar/status command planning and execution dispatch now consume pure `pp_app_core` through `App::init_toolbar_main`, `pano_cli plan-main-toolbar`, and the `MainToolbarServices` boundary; toolbar test-message dialog metadata now lives in `pp_app_core` through `plan_main_toolbar_message_dialog`, retained message-box creation and settings-dialog opening now route through `src/legacy_ui_overlay_services.*`, history/canvas commands now hand off through `HistoryUiServices` and `DocumentCanvasClearServices`, and live execution is centralized in `src/legacy_app_shell_services.*`, but the bridge still opens legacy open/save flows, stores raw compatibility pointers, and delegates to legacy history/canvas adapters | Preserve reachable toolbar/status behavior while app shell commands move toward app/document/UI services | `pp_app_core_main_toolbar_tests`; `pano_cli plan-main-toolbar --command undo --undo-count 2`; `pano_cli plan-main-toolbar --command message-box`; `pano_cli plan-main-toolbar --command clear-canvas --no-canvas`; `ctest --preset desktop-fast --build-config Debug` | Open/save/settings/message-box routing, undo/redo/clear-history execution, and canvas-clear execution are owned by injected app/document/UI services with `App::init_toolbar_main` acting only as a UI adapter and no legacy toolbar adapter | | DEBT-0036 | Open | Modernization | `pp_renderer_api`, `pp_paint_renderer`, `pano_cli plan-paint-feedback`, and `pano_cli plan-stroke-composite` can choose backend-neutral complex paint feedback strategies for fixed-function blending, framebuffer-fetch-capable renderers, or ping-pong render targets. OpenGL extension detection now stores `pp::renderer::RenderDeviceFeatures` through `ShaderManager`, using `pp_renderer_gl::query_opengl_capability_detection`, `detect_opengl_feature_state`, and `render_device_features` as the backend conversion point; that feature snapshot now includes float32-linear filtering, so canvas stroke texture format selection, renderer diagnostics, grid lightmap render planning, and grid bake target selection no longer read `ShaderManager::ext_*` flags directly. `pp_paint_renderer::plan_canvas_blend_gate` owns the compatibility mapping from persisted layer/brush blend indices to the extracted stroke-composite planner, and live `Canvas::draw_merge` plus `NodeCanvas` panorama rendering both call it with the stored renderer-neutral feature set for their existing shader-blend gates and destination-copy versus framebuffer-fetch decisions. `pp_paint_renderer::plan_canvas_stroke_feedback` also owns the current destination-feedback decision, and live `Canvas::stroke_draw`, thumbnail layer blending, and `NodeStrokePreview` brush-preview rendering use it for framebuffer-fetch versus destination-copy decisions. Pure document-frame compositing, renderer-neutral six-face texture upload, recorded upload-command reporting, pure six-face PNG encoding, pure equirectangular PNG/JPEG+XMP encoding, and pure layer/animation-frame collection PNG encoding are now covered by `simulate-document-render`, payload-complete `plan-canvas-document-snapshot` automation, and the shared `pp_paint_renderer::prepare_document_frame_export_readiness` helper consumed by live export before retained writer fallback. The retained `copy_framebuffer_to_texture_2d` utility bridge now routes 2D framebuffer-to-texture copies through tested `pp_renderer_gl` dispatch, retained `RTT::create`/`RTT::destroy` render-target texture parameter setup, optional depth renderbuffer allocation, framebuffer allocation/attachment/status checks, binding restore, and resource deletion now route through tested `pp_renderer_gl` dispatch, retained RTT clear, masked clear with color-write-mask restore, texture bind/unbind, and RGBA8 dirty-region texture writes now route through tested `pp_renderer_gl` dispatch, retained Canvas, NodeCanvas, and NodeStrokePreview texture-unit switches now route through tested active-texture dispatch, retained Canvas, NodeCanvas, NodeStrokePreview, and desktop HMD viewport/scissor/capability execution now route through tested `pp_renderer_gl` dispatch adapters, retained NodeCanvas, CanvasMode, and NodePanelGrid capability-state snapshots now route through tested `pp_renderer_gl` query dispatch, CanvasLayer cube/equirect generation plus frame clears now share `legacy_ui_gl_dispatch` for active-texture selection, cube texture binding, viewport execution, blend capability execution, clear-color query/restore, and color-buffer clear adapter endpoints backed by tested `pp_renderer_gl` dispatch helpers, while the cube-face framebuffer-to-texture copy now uses the shared retained `copy_framebuffer_to_texture_target` utility bridge backed by tested `pp_renderer_gl` dispatch and remains tracked by DEBT-0036 until renderer services own copy execution, `NodePanelGrid` live heightmap draw and bake setup now route depth/blend state, depth clears, color-write-mask toggles, active texture selection, bake viewport execution, sun-overlay viewport query, and desktop texture-resize readback through tested `pp_renderer_gl` dispatch adapters; its active-texture, depth/blend capability query/apply, viewport query/execution, depth-clear, and color-write-mask adapter endpoints now share `legacy_ui_gl_dispatch`, retained CanvasMode overlay/mask/transform paths now route active texture, depth/blend state, transform/cut viewport execution, paint-mode blend/depth state snapshots, and canvas-tip pick framebuffer readback through tested `pp_renderer_gl` dispatch adapters; their active-texture, capability query/apply, viewport, read-framebuffer query, and RGBA8 pixel-readback adapter endpoints now share `legacy_ui_gl_dispatch`, retained simple UI draw paths now share `legacy_ui_gl_dispatch` for blend-state execution, fallback 2D texture unbinds, `NodeViewport` viewport query/restore, color-buffer clears, and clear-color restore, retained `NodeCanvas` plus `NodeStrokePreview` draw-state paths now share `legacy_ui_gl_dispatch` for active-texture selection, fallback texture unbind, viewport/scissor execution, viewport and clear-color queries, color-buffer clears, clear-color restore, and capability query/apply adapter endpoints backed by tested `pp_renderer_gl` dispatch helpers, retained `Canvas` stroke/object/thumbnail/export/frame-clear state endpoints now share `legacy_ui_gl_dispatch` for active-texture selection, fallback texture unbind, viewport/scissor execution, viewport and clear-color query, clear-color restore, and capability query/apply adapter endpoints, retained Canvas and RTT depth renderbuffer allocation/attachment/delete now share `legacy_gl_renderbuffer_dispatch` while renderer-resource ownership remains retained, retained `Texture2D`, `TextureCube`, and RTT texture allocation/delete/bind/parameter/update/mipmap dispatch now share `legacy_gl_texture_dispatch` while renderer-resource ownership remains retained, retained `Texture2D` readback plus RTT framebuffer allocation/delete/bind/restore/blit/readback and PBO readback dispatch now share `legacy_gl_framebuffer_dispatch` while renderer-resource ownership remains retained, retained Sampler create/parameter/border/bind dispatch shares `legacy_gl_sampler_dispatch` and retained PBO allocation/readback/map/unmap/delete dispatch shares `legacy_gl_pixel_buffer_dispatch` while renderer-resource ownership remains retained, retained `Shape`, `TextMesh`, and `NodeColorWheel` mesh buffer/VAO creation/upload/draw/delete dispatch now share `legacy_gl_mesh_dispatch` while renderer-resource ownership remains retained, retained shader source compilation/deletion, program attach/link/use/delete, attribute rebinding/location lookup, active-uniform enumeration, uniform-location discovery, and uniform writes now share `legacy_gl_shader_dispatch` while shader-program ownership remains retained, retained `gl_state` save/restore and `copy_framebuffer_to_texture_target` now reuse shared retained UI/framebuffer/shader/sampler bridge callbacks while renderer state and framebuffer-copy execution remain retained, retained app startup, app clear, app UI viewport/scissor, command-convert renderer state, and desktop VR draw-state endpoints now share `legacy_ui_gl_dispatch` while app/VR renderer execution remains retained, retained RTT clear and masked-clear endpoints now share `legacy_ui_gl_dispatch` while RTT render-target execution remains retained, retained app startup logging, Windows early context logging/window-title detection, and shader capability detection now share `legacy_gl_runtime_dispatch` while runtime/capability probing remains retained, and retained `CanvasLayer` frame-clear draw-state paths route saved clear-color query and restore through the same tested helpers, but actual live stroke rasterization, dual-brush compositing, pattern feedback math, thumbnail layer compositing, brush-preview compositing, grid lightmap/heightmap mesh rendering, Web/incomplete-readback collection handoff, depth export writer execution, progress/threading parity, exact GPU filtering parity, and the retained `ShaderManager::ext_*` compatibility fields still use legacy OpenGL canvas/UI execution | Preserve current painting behavior while the renderer boundary matures for OpenGL parity and later Vulkan/Metal experiments | `pp_renderer_api_tests`; `pp_renderer_gl_capabilities_tests`; `pp_paint_renderer_compositor_tests`; `pano_cli plan-paint-feedback --framebuffer-fetch --explicit-transitions --render-only`; `pano_cli plan-paint-feedback --texture-copy`; `pano_cli plan-stroke-composite --stroke-blend 10 --framebuffer-fetch --explicit-transitions --render-only`; `pano_cli plan-stroke-composite --layer-blend 4 --dual-blend --texture-copy`; `pano_cli plan-canvas-document-snapshot --captured-face-payloads-per-layer 1`; `ctest --preset desktop-fast --build-config Debug`; `cmake --build --preset windows-msvc-default --config Debug --target PanoPainter` | Live stroke/layer/export compositing chooses its feedback path through `pp_paint_renderer` and renderer services, with OpenGL golden parity and Vulkan/Metal lab tests covering framebuffer-fetch and ping-pong behavior | -| DEBT-0037 | Open | Modernization | Recording lifecycle/export planning, export progress-dialog metadata, and execution dispatch now consume pure `pp_app_core` through `App::rec_start`, `App::rec_stop`, `App::rec_clear`, `App::rec_export`, `pano_cli plan-recording-session`, and the `RecordingServices` boundary; live execution is centralized in `src/legacy_recording_services.*`, retained MP4 export progress bar creation routes through `src/legacy_app_dialog_services.*`, and retained `PBO` allocation/readback/map/unmap/delete operations now route through tested `pp_renderer_gl` dispatch, but the bridge still owns legacy recording thread startup/shutdown, platform recorded-file cleanup, progress lifetime, retained `App::rec_loop` readback call sites, and `MP4Encoder::write_mp4` execution | Preserve current timelapse/MP4 behavior while recording moves toward app/document/renderer/video services | `pp_app_core_document_recording_tests`; `pp_renderer_gl_capabilities_tests`; `pano_cli plan-recording-session --running --frame-count 12`; `pano_cli plan-recording-session --platform-deletes-recorded-files`; `ctest --preset desktop-fast --build-config Debug` | Recording thread lifecycle, frame readback scheduling, platform cleanup, progress reporting, and MP4 writing are owned by injected app/renderer/video services with `App` methods acting only as adapters | +| DEBT-0037 | Open | Modernization | Recording lifecycle/export planning, export progress-dialog metadata, and execution dispatch now consume pure `pp_app_core` through `App::rec_start`, `App::rec_stop`, `App::rec_clear`, `App::rec_export`, `pano_cli plan-recording-session`, and the `RecordingServices` boundary; live execution is centralized in `src/legacy_recording_services.*`, retained MP4 export progress bar creation routes through `src/legacy_app_dialog_services.*`, retained `PBO` allocation/readback/map/unmap/delete operations now route through tested `pp_renderer_gl` dispatch, and the retained recording worker is now owned as `std::jthread` through `App::rec_thread` with explicit stop requests before notify/join, but the bridge still owns retained recording loop control, platform recorded-file cleanup, progress lifetime, `App::rec_loop` readback call sites, and `MP4Encoder::write_mp4` execution | Preserve current timelapse/MP4 behavior while recording moves toward app/document/renderer/video services | `pp_app_core_document_recording_tests`; `pp_renderer_gl_capabilities_tests`; `pano_cli plan-recording-session --running --frame-count 12`; `pano_cli plan-recording-session --platform-deletes-recorded-files`; `ctest --preset desktop-fast --build-config Debug` | Recording thread lifecycle, frame readback scheduling, platform cleanup, progress reporting, and MP4 writing are owned by injected app/renderer/video services with `App` methods acting only as adapters | | DEBT-0038 | Open | Modernization | Cloud upload/browse/bulk planning, cloud prompt/progress metadata, and execution dispatch now consume pure `pp_app_core` through `App::cloud_upload`, `App::cloud_upload_all`, `App::cloud_browse`, `pano_cli plan-cloud-upload`, `pano_cli plan-cloud-upload-all`, `pano_cli plan-cloud-browse`, `pano_cli plan-cloud-transfer`, and the `CloudServices` boundary; live execution is centralized in `src/legacy_cloud_services.*`, cloud-browser dialog opening now routes through `src/legacy_ui_overlay_services.*`, retained upload/download CURL setup, progress callback dispatch, TLS-verification bypass policy consumption, upload form construction, and upload post-transfer response/error handling now also live behind dedicated helpers in `src/legacy_cloud_services.*` instead of `App::upload`/`App::download` or inline transfer setup, retained save-before-upload execution now routes through `src/legacy_document_session_services.*` instead of `src/legacy_cloud_services.cpp` calling `Canvas::I->project_save_thread(...)` directly, retained downloaded-project post-open reconciliation now routes through `src/legacy_document_open_services.*` instead of living inline in `src/legacy_cloud_services.cpp`, upload warning/publish/success prompts, upload/bulk progress dialog titles, download-progress prompt metadata, and formatted download progress text come from tested app-core plans, retained cloud prompt/progress creation routes through `src/legacy_app_dialog_services.*` via `App::message_box`/`App::show_progress` or direct bridge calls, and retained `Asset::open_url`, `LogRemote::net_init`, and `NodeDialogCloud::load_thumbs_thread` curl sites consume the `pp_platform_api` default TLS policy helper instead of spelling Android branches locally; the initial cloud-browser loading placeholder setup, file-list request/response handling, and slot creation/selection wiring in `NodeDialogCloud::load_thumbs_thread()` now also route through focused helpers in `src/node_dialog_cloud.*`, but the bridge still uses retained prompt/progress lifetime, OpenGL context guarding, `NodeDialogCloud` thumbnail execution, and transfer-thread execution while downloaded-project open, layer refresh, and action-history reset remain retained in the document-open bridge | Preserve current cloud behavior while cloud/network/document import flows move toward app/document/platform services | `pp_app_core_document_cloud_tests`; `pp_platform_api_tests`; `pano_cli plan-cloud-upload --new-document --unsaved`; `pano_cli plan-cloud-browse --selected-file demo.ppi`; `pano_cli plan-cloud-upload-all --file-count 3`; `pano_cli plan-cloud-transfer --direction download --progress --disable-tls-verification`; `ctest --preset desktop-fast --build-config Debug` | Cloud upload/download, TLS policy, progress reporting, cloud browse dialog, downloaded project opening, layer refresh, OpenGL context ownership, and action-history reset are owned by injected app/document/network/platform/renderer services with `App` methods acting only as adapters | | DEBT-0039 | Open | Modernization | Document-open planning and execution dispatch now consume pure `pp_app_core` through `App::open_document`, `pano_cli plan-open-route`, `DocumentOpenServices`, and `src/legacy_document_open_services.*`; document-open history clearing is now an explicit app-core output, but the bridge still opens ABR/PPBR import prompts before delegating import execution to `src/legacy_brush_package_import_services.*`, applies unsaved-project discard prompts, calls legacy project-open execution, refreshes layer UI, updates the app title, and executes retained history services locally | Preserve current file-open/import behavior while document loading and brush import move toward app/document/asset/UI services | `pp_app_core_document_route_tests`; `pp_app_core_document_session_tests`; `pano_cli plan-open-route --path D:/Paint/Scenes/demo.ppi --unsaved`; `pano_cli plan-open-route --path D:/Paint/Brushes/clouds.ABR --unsaved`; `ctest --preset desktop-fast --build-config Debug` | Brush import prompting, project-open execution, unsaved-project discard prompting, layer refresh, title updates, and history clearing are owned by injected app/document/asset/UI services with `App::open_document` acting only as an adapter | | DEBT-0040 | Open | Modernization | Close request, document save, save-before-workflow planning/execution dispatch, close/save-before/save-error prompt metadata, and close/save/save-before history effects now consume pure `pp_app_core` through `App::request_close`, `App::save_document`, `App::continue_document_workflow_after_optional_save`, `pano_cli simulate-app-session`, `pano_cli plan-document-session-prompt`, `DocumentSaveServices`, `CloseRequestServices`, `DocumentWorkflowServices`, and `src/legacy_document_session_services.*`; close/save-before prompt creation now uses `src/legacy_app_dialog_services.*`, Save dialog working-directory picker visibility/path formatting now dispatches through `PlatformServices`, and existing-project save/save-before-workflow execution prepares a payload-bearing canvas snapshot report before retained saving, but the bridge still opens retained save dialogs, wires prompt callbacks directly, delegates actual writing to `Canvas::project_save`, mutates the unsaved flag on close confirmation, invokes native app close, and routes save-version through the retained legacy dialog | Preserve current close/save/dirty-workflow behavior while document session execution moves toward app/document/UI/platform services | `pp_app_core_document_session_tests`; `pp_platform_api_tests`; `pano_cli plan-document-session-prompt --kind close-unsaved`; `pano_cli plan-document-session-prompt --kind save-before-workflow`; `pano_cli simulate-app-session --unsaved --save-intent save-dirty-version`; `pano_cli simulate-app-session --no-canvas`; `pano_cli plan-document-file --work-dir D:/Paint --name demo --target-exists`; `pano_cli plan-document-version --directory D:/Paint --doc-name demo.01 --existing-path D:/Paint/demo.02.ppi`; `ctest --preset desktop-fast --build-config Debug` | Close prompt execution, native close requests, dirty-workflow save prompts, existing-project saves, save dialogs, save-version execution, and unsaved-flag mutation are owned by injected app/document/UI/platform services with `App` methods acting only as adapters | diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index d0e5b209..4fe0b851 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -106,9 +106,9 @@ Current architecture mismatches that must be treated as real blockers: - `app_layout.cpp` and `app_dialogs.cpp` are still mixed shell/controller files rather than thin composition/binding surfaces. - `App`, `Canvas`, `Node`, retained workers, and platform entrypoints still use - global singleton reach, raw observer pointers, detached `std::thread` - launches in preview/recording paths, and ad hoc - mutex/condition-variable ownership. + global singleton reach, raw observer pointers, retained static worker + ownership in several app families, and ad hoc mutex/condition-variable + ownership. - Modern C++23 usage exists in extracted components, especially `std::span`, explicit result/status objects, and a few concepts, but the live app still does not consistently express ownership, thread affinity, or renderer diff --git a/docs/modernization/tasks.md b/docs/modernization/tasks.md index cf91b3d4..3689182b 100644 --- a/docs/modernization/tasks.md +++ b/docs/modernization/tasks.md @@ -49,7 +49,9 @@ Completed, blocked, and superseded task history moved to - `platform_legacy` is still part of the live app shell - The app runtime boundary is not finished: - render/UI queues are static `App` state - - detached workers still launch from preview and recording code + - app-facing detached launches are no longer the main issue; preview and + recording now use owned worker threads, but those families still rely on + retained static/global ownership and ad hoc runtime control - canvas async import/export/save/open now run through an owned in-file worker, but their retained progress execution is still not a clean runtime service boundary @@ -359,7 +361,8 @@ Current slice: workers with explicit UI-thread handoff - canvas async import/export/save/open and timelapse export now also use owned worker queues instead of detached threads -- preview and recording-side detached work are still open +- preview background rendering and recording thread ownership now also use + `std::jthread`, but their retained loop/control flow is still open Write scope: - `src/canvas.cpp` diff --git a/src/app.h b/src/app.h index 2ce924e8..093099c9 100644 --- a/src/app.h +++ b/src/app.h @@ -85,7 +85,7 @@ public: std::string work_path{ "." }; std::string rec_path{ "." }; std::string tmp_path{ "." }; - std::thread rec_thread; + std::jthread rec_thread; bool rec_running = false; int rec_count = 0; std::mutex rec_mutex; diff --git a/src/legacy_recording_services.cpp b/src/legacy_recording_services.cpp index 0da0543b..7fc2e428 100644 --- a/src/legacy_recording_services.cpp +++ b/src/legacy_recording_services.cpp @@ -21,11 +21,12 @@ public: void start_thread() override { app_.update_rec_frames(); - app_.rec_thread = std::thread(&App::rec_loop, &app_); + app_.rec_thread = std::jthread(&App::rec_loop, &app_); } void stop_thread() override { + app_.rec_thread.request_stop(); app_.rec_running = false; app_.rec_cv.notify_all(); if (app_.rec_thread.joinable()) diff --git a/src/node_stroke_preview.cpp b/src/node_stroke_preview.cpp index be32ae22..2d32690d 100644 --- a/src/node_stroke_preview.cpp +++ b/src/node_stroke_preview.cpp @@ -19,6 +19,7 @@ #include "util.h" #include #include +#include namespace { @@ -410,7 +411,6 @@ void execute_stroke_preview_background_capture_pass( std::atomic_int NodeStrokePreview::s_instances{ 0 }; std::atomic_bool NodeStrokePreview::s_running{ false }; std::mutex NodeStrokePreview::s_render_mutex; -std::thread NodeStrokePreview::s_renderer; BlockingQueue> NodeStrokePreview::s_queue; RTT NodeStrokePreview::m_rtt; @@ -422,16 +422,18 @@ Sampler NodeStrokePreview::m_sampler_linear; Sampler NodeStrokePreview::m_sampler_linear_repeat; Sampler NodeStrokePreview::m_sampler_mipmap; DynamicShape NodeStrokePreview::m_brush_shape; +std::jthread NodeStrokePreview::s_renderer; void NodeStrokePreview::terminate_renderer() { - if (s_running && s_renderer.joinable()) - { - s_running = false; - s_queue.UnlockGetters(); - s_renderer.join(); - } + if (!s_renderer.joinable()) + return; + + s_running = false; + s_renderer.request_stop(); + s_queue.UnlockGetters(); + s_renderer.join(); } void NodeStrokePreview::empty_queue() @@ -906,11 +908,11 @@ void NodeStrokePreview::draw_stroke() { if (m_size.x == 0 || m_size.y == 0) return; - s_queue.mutex.lock(); - if (!s_running) + std::unique_lock queue_lock(s_queue.mutex); + if (!s_renderer.joinable()) { s_running = true; - s_renderer = std::thread([] { + s_renderer = std::jthread([](std::stop_token stop_token) { BT_SetTerminate(); m_sampler_linear.create(); @@ -922,7 +924,7 @@ void NodeStrokePreview::draw_stroke() pp::renderer::gl::linear_mipmap_linear_texture_filter(), pp::renderer::gl::linear_texture_filter()); m_brush_shape.create(); - while (s_running) + while (s_running && !stop_token.stop_requested()) { auto node = s_queue.Get(); if (node) @@ -970,9 +972,10 @@ void NodeStrokePreview::draw_stroke() m_tex_dual.destroy(); m_tex_background.destroy(); m_brush_shape.destroy(); + s_running = false; }); } - s_queue.mutex.unlock(); + queue_lock.unlock(); s_queue.PostUnique(std::static_pointer_cast(shared_from_this()), m_draw_first); } diff --git a/src/node_stroke_preview.h b/src/node_stroke_preview.h index 163fe22b..4172620c 100644 --- a/src/node_stroke_preview.h +++ b/src/node_stroke_preview.h @@ -1,4 +1,6 @@ #pragma once +#include +#include #include "node_border.h" #include "rtt.h" #include "brush.h" @@ -33,7 +35,7 @@ public: static std::atomic_int s_instances; static std::atomic_bool s_running; static std::mutex s_render_mutex; - static std::thread s_renderer; + static std::jthread s_renderer; static BlockingQueue> s_queue; static void terminate_renderer(); static void empty_queue(); diff --git a/src/platform_legacy/legacy_platform_services.cpp b/src/platform_legacy/legacy_platform_services.cpp index 67a20a23..0b2c8cd3 100644 --- a/src/platform_legacy/legacy_platform_services.cpp +++ b/src/platform_legacy/legacy_platform_services.cpp @@ -108,84 +108,87 @@ public: [[nodiscard]] pp::platform::apple::AppleDocumentPlatformServices& active_apple_document_platform_services() { #ifdef __IOS__ + auto* const ios_view = App::I->ios_view; static pp::platform::apple::AppleDocumentPlatformServices services( pp::platform::PlatformFamily::ios, - [] { + [ios_view] { pp::platform::apple::AppleDocumentPickerBridge bridge; - bridge.clipboard_text = [] { - return [App::I->ios_view clipboard_get_string]; + bridge.clipboard_text = [ios_view] { + return [ios_view clipboard_get_string]; }; - bridge.set_clipboard_text = [](std::string_view text) { + bridge.set_clipboard_text = [ios_view](std::string_view text) { const std::string value(text); - return [App::I->ios_view clipboard_set_string:value]; + return [ios_view clipboard_set_string:value]; }; - bridge.display_file = [](std::string path) { + bridge.display_file = [ios_view](std::string path) { dispatch_async(dispatch_get_main_queue(), ^{ - [App::I->ios_view display_file:path]; + [ios_view display_file:path]; }); }; - bridge.share_file = [](std::string path) { + bridge.share_file = [ios_view](std::string path) { dispatch_async(dispatch_get_main_queue(), ^{ - [App::I->ios_view share_file:[NSString stringWithUTF8String:path.c_str()]]; + [ios_view share_file:[NSString stringWithUTF8String:path.c_str()]]; }); }; - bridge.pick_image = [](pp::platform::PickedPathCallback callback) { + bridge.pick_image = [ios_view](pp::platform::PickedPathCallback callback) { dispatch_async(dispatch_get_main_queue(), ^{ - [App::I->ios_view pick_photo:callback]; + [ios_view pick_photo:callback]; }); }; - bridge.pick_file = []( + bridge.pick_file = [ios_view]( std::vector file_types, pp::platform::PickedPathCallback callback) { dispatch_async(dispatch_get_main_queue(), ^{ - [App::I->ios_view pick_file:apple_file_types_array(file_types) then:callback]; + [ios_view pick_file:apple_file_types_array(file_types) then:callback]; }); }; return bridge; }()); return services; #else + auto* const osx_view = App::I->osx_view; + auto* const osx_app = App::I->osx_app; static pp::platform::apple::AppleDocumentPlatformServices services( pp::platform::PlatformFamily::macos, - [] { + [osx_view, osx_app] { pp::platform::apple::AppleDocumentPickerBridge bridge; - bridge.clipboard_text = [] { - return [App::I->osx_view clipboard_get_string]; + bridge.clipboard_text = [osx_view] { + return [osx_view clipboard_get_string]; }; - bridge.set_clipboard_text = [](std::string_view text) { + bridge.set_clipboard_text = [osx_view](std::string_view text) { const std::string value(text); - return [App::I->osx_view clipboard_set_string:value]; + return [osx_view clipboard_set_string:value]; }; - bridge.share_file = [](std::string path) { + bridge.share_file = [osx_view](std::string path) { dispatch_async(dispatch_get_main_queue(), ^{ - [App::I->osx_view share_file:[NSString stringWithUTF8String:path.c_str()]]; + [osx_view share_file:[NSString stringWithUTF8String:path.c_str()]]; }); }; - bridge.set_cursor_visible = [](bool visible) { - [App::I->osx_view show_cursor:visible]; + bridge.set_cursor_visible = [osx_view](bool visible) { + [osx_view show_cursor:visible]; }; - bridge.save_ui_state = [] { - [App::I->osx_app save_ui_state]; + bridge.save_ui_state = [osx_app] { + [osx_app save_ui_state]; }; - bridge.pick_file = []( + bridge.pick_file = [osx_view]( std::vector file_types, pp::platform::PickedPathCallback callback) { dispatch_async(dispatch_get_main_queue(), ^{ - const std::string path = [App::I->osx_view pick_file:apple_file_types_array(file_types)]; + const std::string path = [osx_view pick_file:apple_file_types_array(file_types)]; callback(path); }); }; - bridge.pick_save_file = []( + bridge.pick_save_file = [osx_view]( std::vector file_types, pp::platform::PickedPathCallback callback) { dispatch_async(dispatch_get_main_queue(), ^{ - const std::string path = [App::I->osx_view pick_file_save:apple_file_types_array(file_types)]; + const std::string path = [osx_view pick_file_save:apple_file_types_array(file_types)]; callback(path); }); }; - bridge.pick_directory = [](pp::platform::PickedPathCallback callback) { + bridge.pick_directory = [osx_view](pp::platform::PickedPathCallback callback) { dispatch_async(dispatch_get_main_queue(), ^{ - const std::string path = [App::I->osx_view pick_dir]; + const std::string path = [osx_view pick_dir]; callback(path); }); };