From 819b0f31db0820bd54e4a290be19033cb5bd0374 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Sat, 13 Jun 2026 18:47:21 +0200 Subject: [PATCH] Extract pad destination dispatch overload --- docs/modernization/debt.md | 4 +++ docs/modernization/tasks.md | 3 ++ src/canvas.cpp | 36 +++++++++++-------- src/legacy_canvas_stroke_execution_services.h | 16 +++++++++ .../paint_renderer/stroke_execution_tests.cpp | 24 +++++++++++++ 5 files changed, 69 insertions(+), 14 deletions(-) diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index 4345d71..3568d10 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -18,6 +18,10 @@ agent or engineer to remove them without reconstructing context from chat. ## Recent Reductions +- 2026-06-13: `LATER-003` was narrowed again. `Canvas::stroke_draw()` now + routes pad destination texture dispatch through retained helper overloads, + so the face-index callback wiring is no longer built inline in the pad + branch. - 2026-06-13: `LATER-003` was narrowed again. `Canvas::stroke_draw()` now routes its main live-pass bind, execute, and unbind sequence through `execute_legacy_canvas_stroke_main_pass(...)`; the retained adapter still diff --git a/docs/modernization/tasks.md b/docs/modernization/tasks.md index 4b071c9..b30bcca 100644 --- a/docs/modernization/tasks.md +++ b/docs/modernization/tasks.md @@ -575,6 +575,9 @@ Done Checks: Progress Notes: +- 2026-06-13: `Canvas::stroke_draw()` now routes pad destination texture + dispatch through retained helper overloads, so the face-index callback + wiring is no longer built inline in the pad branch. - 2026-06-13: `Canvas::stroke_draw()` now routes its main live-pass bind, execute, and unbind sequence through `execute_legacy_canvas_stroke_main_pass(...)`; the retained adapter still diff --git a/src/canvas.cpp b/src/canvas.cpp index 20ec46a..1e9d05e 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -863,18 +863,6 @@ void Canvas::stroke_draw() .slot = 1, }, }; - const auto make_pad_destination_texture_dispatch = [&](int face_index) { - return pp::panopainter::make_legacy_canvas_stroke_pad_destination_texture_dispatch( - [&](int texture_slot) { - set_active_texture_unit(texture_slot); - }, - [&] { - m_tex[face_index].bind(); - }, - [&] { - m_tex[face_index].unbind(); - }); - }; [[maybe_unused]] const auto pad_result = pp::panopainter::execute_legacy_canvas_stroke_pad_face_callbacks( pad_faces, stroke_extent, @@ -890,7 +878,17 @@ void Canvas::stroke_draw() [&](int face_index) { pp::panopainter::bind_legacy_canvas_stroke_texture_inputs( pad_destination_texture_binding, - make_pad_destination_texture_dispatch(face_index)); + pp::panopainter::make_legacy_canvas_stroke_pad_destination_texture_dispatch( + [&](int texture_slot) { + set_active_texture_unit(texture_slot); + }, + [&](int dst_face_index) { + m_tex[dst_face_index].bind(); + }, + [&](int dst_face_index) { + m_tex[dst_face_index].unbind(); + }, + face_index)); }, [&](const pp::paint_renderer::CanvasStrokeCopyRegion& copy_region) { copy_framebuffer_to_texture_2d( @@ -904,7 +902,17 @@ void Canvas::stroke_draw() [&](int face_index) { pp::panopainter::unbind_legacy_canvas_stroke_texture_inputs( pad_destination_texture_binding, - make_pad_destination_texture_dispatch(face_index)); + pp::panopainter::make_legacy_canvas_stroke_pad_destination_texture_dispatch( + [&](int texture_slot) { + set_active_texture_unit(texture_slot); + }, + [&](int dst_face_index) { + m_tex[dst_face_index].bind(); + }, + [&](int dst_face_index) { + m_tex[dst_face_index].unbind(); + }, + face_index)); }, [&] { m_brush_shape.draw_fill(); diff --git a/src/legacy_canvas_stroke_execution_services.h b/src/legacy_canvas_stroke_execution_services.h index 4dff71a..0f494f0 100644 --- a/src/legacy_canvas_stroke_execution_services.h +++ b/src/legacy_canvas_stroke_execution_services.h @@ -140,6 +140,22 @@ struct LegacyCanvasStrokeTextureInputDispatch { }; } +[[nodiscard]] inline LegacyCanvasStrokeTextureInputDispatch make_legacy_canvas_stroke_pad_destination_texture_dispatch( + std::function activate_texture_unit, + std::function bind_stroke_destination, + std::function unbind_stroke_destination, + int face_index) +{ + return make_legacy_canvas_stroke_pad_destination_texture_dispatch( + std::move(activate_texture_unit), + [bind_stroke_destination = std::move(bind_stroke_destination), face_index]() { + bind_stroke_destination(face_index); + }, + [unbind_stroke_destination = std::move(unbind_stroke_destination), face_index]() { + unbind_stroke_destination(face_index); + }); +} + struct LegacyCanvasStrokeSamplerDispatch { std::function bind_brush_tip_sampler; std::function unbind_brush_tip_sampler; diff --git a/tests/paint_renderer/stroke_execution_tests.cpp b/tests/paint_renderer/stroke_execution_tests.cpp index ec280f6..87e1249 100644 --- a/tests/paint_renderer/stroke_execution_tests.cpp +++ b/tests/paint_renderer/stroke_execution_tests.cpp @@ -361,6 +361,27 @@ void retained_stroke_pad_destination_texture_dispatch_helper_builds_expected_cal PP_EXPECT(h, events == expected_events); } +void retained_stroke_pad_destination_texture_dispatch_helper_builds_expected_face_wiring(pp::tests::Harness& h) +{ + std::vector events; + const auto dispatch = pp::panopainter::make_legacy_canvas_stroke_pad_destination_texture_dispatch( + [&](int slot) { events.emplace_back("activate:" + std::to_string(slot)); }, + [&](int face_index) { events.emplace_back("bind:" + std::to_string(face_index)); }, + [&](int face_index) { events.emplace_back("unbind:" + std::to_string(face_index)); }, + 4); + + dispatch.activate_texture_unit(1); + dispatch.bind_stroke_destination(); + dispatch.unbind_stroke_destination(); + + const std::vector expected_events { + "activate:1", + "bind:4", + "unbind:4", + }; + PP_EXPECT(h, events == expected_events); +} + void retained_stroke_destination_texture_dispatch_helper_builds_expected_callback_wiring(pp::tests::Harness& h) { std::vector events; @@ -1791,6 +1812,9 @@ int main() harness.run( "retained_stroke_pad_destination_texture_dispatch_helper_builds_expected_callback_wiring", retained_stroke_pad_destination_texture_dispatch_helper_builds_expected_callback_wiring); + harness.run( + "retained_stroke_pad_destination_texture_dispatch_helper_builds_expected_face_wiring", + retained_stroke_pad_destination_texture_dispatch_helper_builds_expected_face_wiring); harness.run( "retained_stroke_brush_tip_texture_dispatch_helper_builds_expected_callback_wiring", retained_stroke_brush_tip_texture_dispatch_helper_builds_expected_callback_wiring);