13
0

Revert to use an image surface for CairoWidgets

This partially reverts 2edbda2526 and is a follow up to 0b266a54f,
to fix performance issues with MS Windows graphics performance.
This commit is contained in:
Robin Gareus 2020-01-08 04:23:44 +01:00
parent c59c46a70a
commit 563a8b15e0
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 35 additions and 13 deletions

View File

@ -58,9 +58,9 @@ CairoWidget::CairoWidget ()
{
_name_proxy.connect (sigc::mem_fun (*this, &CairoWidget::on_name_changed));
#ifdef USE_CAIRO_IMAGE_SURFACE
_use_intermediate_surface = true;
_use_image_surface = true;
#else
_use_intermediate_surface = NULL != getenv("ARDOUR_IMAGE_SURFACE");
_use_image_surface = NULL != getenv("ARDOUR_IMAGE_SURFACE");
#endif
}
@ -82,7 +82,8 @@ CairoWidget::set_canvas_widget ()
ensure_style ();
gtk_widget_set_realized (GTK_WIDGET(gobj()), true);
_canvas_widget = true;
_use_intermediate_surface = false;
_use_image_surface = false;
image_surface.clear ();
}
void
@ -97,9 +98,13 @@ CairoWidget::use_nsglview ()
}
void
CairoWidget::use_intermediate_surface (bool yn)
CairoWidget::use_image_surface (bool yn)
{
_use_intermediate_surface = yn;
if (_use_image_surface == yn) {
return;
}
image_surface.clear ();
_use_image_surface = yn;
}
int
@ -158,9 +163,14 @@ CairoWidget::on_expose_event (GdkEventExpose *ev)
return true;
}
#endif
Cairo::RefPtr<Cairo::Context> cr = get_window()->create_cairo_context ();
if (_use_intermediate_surface) {
cr->push_group ();
Cairo::RefPtr<Cairo::Context> cr;
if (_use_image_surface) {
if (!image_surface) {
image_surface = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, get_width(), get_height());
}
cr = Cairo::Context::create (image_surface);
} else {
cr = get_window()->create_cairo_context ();
}
cr->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
@ -188,9 +198,15 @@ CairoWidget::on_expose_event (GdkEventExpose *ev)
render (cr, &expose_area);
if (_use_intermediate_surface) {
cr->pop_group_to_source ();
cr->paint ();
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 ();
}
return true;
@ -245,6 +261,11 @@ CairoWidget::on_size_allocate (Gtk::Allocation& alloc)
memcpy (&_allocation, &alloc, sizeof(Gtk::Allocation));
}
if (_use_image_surface) {
image_surface.clear ();
image_surface = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, alloc.get_width(), alloc.get_height());
}
if (_canvas_widget) {
return;
}

View File

@ -40,7 +40,7 @@ public:
void set_canvas_widget ();
void use_nsglview ();
void use_intermediate_surface (bool yn = true);
void use_image_surface (bool yn = true);
/* swizzle Gtk::Widget methods for Canvas::Widget */
void queue_draw ();
@ -143,12 +143,13 @@ protected:
static sigc::slot<void,Gtk::Widget*> focus_handler;
private:
Cairo::RefPtr<Cairo::Surface> image_surface;
Glib::SignalProxyProperty _name_proxy;
sigc::connection _parent_style_change;
Widget * _current_parent;
bool _canvas_widget;
void* _nsglview;
bool _use_intermediate_surface;
bool _use_image_surface;
Gdk::Rectangle _allocation;
};