From 594d0d86729f1a6e508a4839be8f8e958b01990b Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 14 Mar 2016 16:44:51 +0100 Subject: [PATCH] GUI update for non-cairo Plugin Inline Display --- gtk2_ardour/processor_box.cc | 69 +++++++++++++++++++++++------------- gtk2_ardour/processor_box.h | 2 ++ 2 files changed, 47 insertions(+), 24 deletions(-) diff --git a/gtk2_ardour/processor_box.cc b/gtk2_ardour/processor_box.cc index b2e22969e7..a00211fecc 100644 --- a/gtk2_ardour/processor_box.cc +++ b/gtk2_ardour/processor_box.cc @@ -1201,6 +1201,7 @@ ProcessorEntry::RoutingIcon::on_expose_event (GdkEventExpose* ev) ProcessorEntry::PluginDisplay::PluginDisplay (boost::shared_ptr p, uint32_t max_height) : _plug (p) + , _surf (0) , _max_height (max_height) , _cur_height (1) { @@ -1209,6 +1210,13 @@ ProcessorEntry::PluginDisplay::PluginDisplay (boost::shared_ptr boost::bind (&Gtk::Widget::queue_draw, this), gui_context ()); } +ProcessorEntry::PluginDisplay::~PluginDisplay () +{ + if (_surf) { + cairo_surface_destroy (_surf); + } +} + void ProcessorEntry::PluginDisplay::on_size_request (Gtk::Requisition* req) { @@ -1223,14 +1231,9 @@ ProcessorEntry::PluginDisplay::on_expose_event (GdkEventExpose* ev) double const width = a.get_width(); double const height = a.get_height(); - void* csf = _plug->render_inline_display (width, _max_height); + Plugin::Display_Image_Surface* csf = _plug->render_inline_display (width, _max_height); - cairo_surface_t* surf = NULL; - if (csf) { - surf = (cairo_surface_t*) csf; - } - - if (!surf) { + if (!csf) { hide (); if (_cur_height != 1) { _cur_height = 1; @@ -1239,6 +1242,26 @@ ProcessorEntry::PluginDisplay::on_expose_event (GdkEventExpose* ev) return true; } + if (!_surf + || csf->width != cairo_image_surface_get_width (_surf) + || csf->height != cairo_image_surface_get_height (_surf) + || csf->stride != cairo_image_surface_get_stride (_surf) + ) + { + if (_surf) { + cairo_surface_destroy (_surf); + } + _surf = cairo_image_surface_create_for_data ( + csf->data, + CAIRO_FORMAT_ARGB32, + csf->width, + csf->height, + csf->stride); + } else { + memcpy (cairo_image_surface_get_data (_surf), csf->data, csf->stride * csf->height); + cairo_surface_mark_dirty(_surf); + } + cairo_t* cr = gdk_cairo_create (get_window()->gobj()); cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height); cairo_clip (cr); @@ -1248,23 +1271,21 @@ ProcessorEntry::PluginDisplay::on_expose_event (GdkEventExpose* ev) cairo_rectangle (cr, 0, 0, width, height); cairo_fill (cr); - if (surf) { - cairo_save (cr); - cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); - Gtkmm2ext::rounded_rectangle (cr, .5, -1.5, width - 1, height + 1, 7); - cairo_clip (cr); + cairo_save (cr); + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + Gtkmm2ext::rounded_rectangle (cr, .5, -1.5, width - 1, height + 1, 7); + cairo_clip (cr); - const double xc = floor ((width - cairo_image_surface_get_width (surf)) * .5); - const double sh = cairo_image_surface_get_height (surf); - uint32_t shm = std::min (_max_height, (uint32_t) ceil (sh)); - if (shm != _cur_height) { - _cur_height = shm; - queue_resize (); - } - cairo_set_source_surface(cr, surf, xc, 0); - cairo_paint (cr); - cairo_restore (cr); + const double xc = floor ((width - csf->width) * .5); + const double sh = csf->height; + uint32_t shm = std::min (_max_height, (uint32_t) ceil (sh)); + if (shm != _cur_height) { + _cur_height = shm; + queue_resize (); } + cairo_set_source_surface(cr, _surf, xc, 0); + cairo_paint (cr); + cairo_restore (cr); bool failed = false; std::string name = get_name(); @@ -2258,7 +2279,7 @@ ProcessorBox::help_count_visible_prefader_processors (boost::weak_ptr ) ) { - if (boost::dynamic_pointer_cast(processor) && + if (boost::dynamic_pointer_cast(processor) && boost::dynamic_pointer_cast(processor)->gain_control()->parameter().type() == GainAutomation) { *amp_seen = true; } else { @@ -2349,7 +2370,7 @@ ProcessorBox::setup_entry_positions () uint32_t num = 0; for (list::iterator i = children.begin(); i != children.end(); ++i) { - if (boost::dynamic_pointer_cast((*i)->processor()) && + if (boost::dynamic_pointer_cast((*i)->processor()) && boost::dynamic_pointer_cast((*i)->processor())->gain_control()->parameter().type() == GainAutomation) { pre_fader = false; (*i)->set_position (ProcessorEntry::Fader, num++); diff --git a/gtk2_ardour/processor_box.h b/gtk2_ardour/processor_box.h index 807af85ddc..1e3fa222c0 100644 --- a/gtk2_ardour/processor_box.h +++ b/gtk2_ardour/processor_box.h @@ -223,11 +223,13 @@ private: class PluginDisplay : public Gtk::DrawingArea { public: PluginDisplay(boost::shared_ptr, uint32_t max_height = 80); + ~PluginDisplay(); private: bool on_expose_event (GdkEventExpose *); void on_size_request (Gtk::Requisition* req); boost::shared_ptr _plug; PBD::ScopedConnection _qdraw_connection; + cairo_surface_t* _surf; uint32_t _max_height; uint32_t _cur_height; };