diff options
author | Robin Gareus <robin@gareus.org> | 2019-12-26 18:19:21 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2019-12-27 19:34:56 +0100 |
commit | c3ab63a2eadece16ab5b5494d5815c147c6bd146 (patch) | |
tree | c80d11a43a79879ed8b25ac0cd75fa724f04f0f1 /libs/gtkmm2ext/cairo_widget.cc | |
parent | 7b1a875f9c736b419285318147b3dc6b9c0a0e00 (diff) |
Allow for per-widget image-surface backing
This is an intermediate commit, before replacing image surfaces with
cairo pattern groups.
The eventual goal is to reduce flickering and/or use
CPU + bitblt for specific widgets instead of cairo
graphics-cards accel.
This also removes excessive calls to getenv() for every rendering
operation.
Diffstat (limited to 'libs/gtkmm2ext/cairo_widget.cc')
-rw-r--r-- | libs/gtkmm2ext/cairo_widget.cc | 75 |
1 files changed, 34 insertions, 41 deletions
diff --git a/libs/gtkmm2ext/cairo_widget.cc b/libs/gtkmm2ext/cairo_widget.cc index 37d7f3806b..b06e443ec0 100644 --- a/libs/gtkmm2ext/cairo_widget.cc +++ b/libs/gtkmm2ext/cairo_widget.cc @@ -17,9 +17,6 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#if !defined USE_CAIRO_IMAGE_SURFACE && !defined NDEBUG -#define OPTIONAL_CAIRO_IMAGE_SURFACE -#endif #include "gtkmm2ext/cairo_widget.h" #include "gtkmm2ext/gui_thread.h" @@ -60,6 +57,11 @@ CairoWidget::CairoWidget () , _nsglview (0) { _name_proxy.connect (sigc::mem_fun (*this, &CairoWidget::on_name_changed)); +#ifdef USE_CAIRO_IMAGE_SURFACE + _use_image_surface = true; +#else + _use_image_surface = NULL != getenv("ARDOUR_IMAGE_SURFACE"); +#endif } CairoWidget::~CairoWidget () @@ -67,7 +69,9 @@ CairoWidget::~CairoWidget () if (_canvas_widget) { gtk_widget_set_realized (GTK_WIDGET(gobj()), false); } - if (_parent_style_change) _parent_style_change.disconnect(); + if (_parent_style_change) { + _parent_style_change.disconnect(); + } } void @@ -78,6 +82,8 @@ CairoWidget::set_canvas_widget () ensure_style (); gtk_widget_set_realized (GTK_WIDGET(gobj()), true); _canvas_widget = true; + _use_image_surface = false; + image_surface.clear (); } void @@ -91,6 +97,16 @@ CairoWidget::use_nsglview () #endif } +void +CairoWidget::use_image_surface (bool yn) +{ + if (_use_image_surface == yn) { + return; + } + image_surface.clear (); + _use_image_surface = yn; +} + int CairoWidget::get_width () const { @@ -147,9 +163,8 @@ CairoWidget::on_expose_event (GdkEventExpose *ev) return true; } #endif -#ifdef OPTIONAL_CAIRO_IMAGE_SURFACE Cairo::RefPtr<Cairo::Context> cr; - if (getenv("ARDOUR_IMAGE_SURFACE")) { + if (_use_image_surface) { if (!image_surface) { image_surface = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, get_width(), get_height()); } @@ -157,16 +172,6 @@ CairoWidget::on_expose_event (GdkEventExpose *ev) } else { cr = get_window()->create_cairo_context (); } -#elif defined USE_CAIRO_IMAGE_SURFACE - - if (!image_surface) { - image_surface = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, get_width(), get_height()); - } - - Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (image_surface); -#else - Cairo::RefPtr<Cairo::Context> cr = get_window()->create_cairo_context (); -#endif cr->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height); @@ -193,24 +198,16 @@ CairoWidget::on_expose_event (GdkEventExpose *ev) render (cr, &expose_area); -#ifdef OPTIONAL_CAIRO_IMAGE_SURFACE - if (getenv("ARDOUR_IMAGE_SURFACE")) { -#endif -#if defined USE_CAIRO_IMAGE_SURFACE || defined OPTIONAL_CAIRO_IMAGE_SURFACE - image_surface->flush(); - /* now blit our private surface back to the GDK one */ - - Cairo::RefPtr<Cairo::Context> cairo_context = get_window()->create_cairo_context (); - - cairo_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height); - cairo_context->clip (); - cairo_context->set_source (image_surface, 0, 0); - cairo_context->set_operator (Cairo::OPERATOR_SOURCE); - cairo_context->paint (); -#endif -#ifdef OPTIONAL_CAIRO_IMAGE_SURFACE + if (_use_image_surface) { + image_surface->flush(); + /* now blit our private surface back to the GDK one */ + Cairo::RefPtr<Cairo::Context> window_context = get_window()->create_cairo_context (); + window_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height); + window_context->clip (); + window_context->set_source (image_surface, 0, 0); + window_context->set_operator (Cairo::OPERATOR_SOURCE); + window_context->paint (); } -#endif return true; } @@ -264,19 +261,15 @@ CairoWidget::on_size_allocate (Gtk::Allocation& alloc) memcpy (&_allocation, &alloc, sizeof(Gtk::Allocation)); } -#ifdef OPTIONAL_CAIRO_IMAGE_SURFACE - if (getenv("ARDOUR_IMAGE_SURFACE")) { -#endif -#if defined USE_CAIRO_IMAGE_SURFACE || defined OPTIONAL_CAIRO_IMAGE_SURFACE - image_surface = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, alloc.get_width(), alloc.get_height()); -#endif -#ifdef OPTIONAL_CAIRO_IMAGE_SURFACE + if (_use_image_surface) { + image_surface.clear (); + image_surface = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, alloc.get_width(), alloc.get_height()); } -#endif if (_canvas_widget) { return; } + #ifdef __APPLE__ if (_nsglview) { gint xx, yy; |