From adfba3d39d520076bc54ada52c1ca91e598b23f1 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 22 Mar 2024 13:39:03 -0600 Subject: [PATCH] allow runtime control over cairo save/restore around item rendering This is to allow easier debugging of whether a given item's render method fails to leave a cairo context in the same state it received it in --- libs/canvas/canvas.cc | 7 +++++++ libs/canvas/canvas/canvas.h | 3 +++ libs/canvas/item.cc | 7 ++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libs/canvas/canvas.cc b/libs/canvas/canvas.cc index 10ff37196b..48e30a3cf4 100644 --- a/libs/canvas/canvas.cc +++ b/libs/canvas/canvas.cc @@ -68,6 +68,13 @@ Canvas::Canvas () #else _use_intermediate_surface = NULL != g_getenv("ARDOUR_INTERMEDIATE_SURFACE"); #endif + + if (g_getenv ("ARDOUR_ITEM_CAIRO_SAVE_RESTORE")) { + item_save_restore = true; + } else { + item_save_restore = false; + } + set_epoch (); } diff --git a/libs/canvas/canvas/canvas.h b/libs/canvas/canvas/canvas.h index f4ad37e920..2b05c92cf0 100644 --- a/libs/canvas/canvas/canvas.h +++ b/libs/canvas/canvas/canvas.h @@ -188,6 +188,9 @@ public: void set_debug_render (bool yn) { _debug_render = yn; } bool debug_render() const { return _debug_render; } + + bool item_save_restore; + protected: Root _root; uint32_t _queue_draw_frozen; diff --git a/libs/canvas/item.cc b/libs/canvas/item.cc index 792e9b5bae..c11fc0559c 100644 --- a/libs/canvas/item.cc +++ b/libs/canvas/item.cc @@ -941,8 +941,13 @@ Item::render_children (Rect const & area, Cairo::RefPtr context) } } #endif - + if (_canvas->item_save_restore) { + context->save(); + } (*i)->render (area, context); + if (_canvas->item_save_restore) { + context->restore(); + } ++render_count; }