mirror of
https://github.com/Ardour/ardour.git
synced 2026-01-03 12:19:33 +01:00
Replace explicit image-surface with cairo pattern/group
For MacOS/X this is equivalent, rendering happens using a CGBitmapContext + image-surface. Windows and Linux needs profiling for respective equivalent surfaces.
This commit is contained in:
parent
c3ab63a2ea
commit
2edbda2526
4 changed files with 40 additions and 73 deletions
|
|
@ -59,14 +59,20 @@ Canvas::Canvas ()
|
|||
, _bg_color (Gtkmm2ext::rgba_to_color (0, 1.0, 0.0, 1.0))
|
||||
, _last_render_start_timestamp(0)
|
||||
{
|
||||
#ifdef USE_CAIRO_IMAGE_SURFACE
|
||||
_use_image_surface = true;
|
||||
#if (defined USE_CAIRO_IMAGE_SURFACE || defined __APPLE__)
|
||||
_use_intermediate_surface = true;
|
||||
#else
|
||||
_use_image_surface = NULL != getenv("ARDOUR_IMAGE_SURFACE");
|
||||
_use_intermediate_surface = NULL != getenv("ARDOUR_IMAGE_SURFACE");
|
||||
#endif
|
||||
set_epoch ();
|
||||
}
|
||||
|
||||
void
|
||||
Canvas::use_intermediate_surface (bool yn)
|
||||
{
|
||||
_use_intermediate_surface = yn;
|
||||
}
|
||||
|
||||
void
|
||||
Canvas::scroll_to (Coord x, Coord y)
|
||||
{
|
||||
|
|
@ -840,11 +846,6 @@ void
|
|||
GtkCanvas::on_size_allocate (Gtk::Allocation& a)
|
||||
{
|
||||
EventBox::on_size_allocate (a);
|
||||
if (_use_image_surface) {
|
||||
/* allocate an image surface as large as the canvas itself */
|
||||
canvas_image.clear ();
|
||||
canvas_image = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, a.get_width(), a.get_height());
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
if (_nsglview) {
|
||||
|
|
@ -879,21 +880,16 @@ GtkCanvas::on_expose_event (GdkEventExpose* ev)
|
|||
const int64_t start = g_get_monotonic_time ();
|
||||
#endif
|
||||
|
||||
Cairo::RefPtr<Cairo::Context> draw_context;
|
||||
if (_use_image_surface) {
|
||||
if (!canvas_image) {
|
||||
canvas_image = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, get_width(), get_height());
|
||||
}
|
||||
draw_context = Cairo::Context::create (canvas_image);
|
||||
} else {
|
||||
draw_context = get_window()->create_cairo_context ();
|
||||
}
|
||||
Cairo::RefPtr<Cairo::Context> draw_context = get_window()->create_cairo_context ();
|
||||
|
||||
draw_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
||||
draw_context->clip();
|
||||
|
||||
#ifdef __APPLE__
|
||||
/* group calls cairo_quartz_surface_create() which
|
||||
/* (this comment applies to macOS, but is other platforms
|
||||
* also benefit from using CPU-rendering on a image-surface
|
||||
* with a final bitblt).
|
||||
*
|
||||
* group calls cairo_quartz_surface_create() which
|
||||
* effectively uses a CGBitmapContext + image-surface
|
||||
*
|
||||
* This avoids expensive argb32_image_mark_image() during drawing.
|
||||
|
|
@ -905,8 +901,9 @@ GtkCanvas::on_expose_event (GdkEventExpose* ev)
|
|||
*
|
||||
* Fixing this for good likely involves changes to GdkQuartzWindow, GdkQuartzView
|
||||
*/
|
||||
draw_context->push_group ();
|
||||
#endif
|
||||
if (_use_intermediate_surface) {
|
||||
draw_context->push_group ();
|
||||
}
|
||||
|
||||
/* draw background color */
|
||||
draw_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
||||
|
|
@ -930,20 +927,9 @@ GtkCanvas::on_expose_event (GdkEventExpose* ev)
|
|||
g_free (rects);
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
draw_context->pop_group_to_source ();
|
||||
draw_context->paint ();
|
||||
#endif
|
||||
|
||||
if (_use_image_surface) {
|
||||
canvas_image->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 (canvas_image, 0, 0);
|
||||
window_context->set_operator (Cairo::OPERATOR_SOURCE);
|
||||
window_context->paint ();
|
||||
if (_use_intermediate_surface) {
|
||||
draw_context->pop_group_to_source ();
|
||||
draw_context->paint ();
|
||||
}
|
||||
|
||||
#ifdef CANVAS_PROFILE
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue