summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2013-10-31 14:33:36 +0100
committerGravatar Alexey Yakovenko <waker@users.sourceforge.net>2013-10-31 20:01:39 +0100
commit3d2cbb92f3be4c314254c157e42c8f7809e26996 (patch)
tree64b10d2d9e1bcdec746b5cd6368e6e8cc1804144
parentc0f06de893f5378117b419d8f3e27a71f17afd34 (diff)
added shm double-buffer for scope rendering
-rw-r--r--plugins/gtkui/widgets.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/plugins/gtkui/widgets.c b/plugins/gtkui/widgets.c
index cce3c1b2..393db33c 100644
--- a/plugins/gtkui/widgets.c
+++ b/plugins/gtkui/widgets.c
@@ -139,6 +139,7 @@ typedef struct {
int nsamples;
int resized;
intptr_t mutex;
+ cairo_surface_t *surf;
} w_scope_t;
// spectrum analyzer based on cairo-spectrum from audacious
@@ -2263,6 +2264,10 @@ w_scope_destroy (ddb_gtkui_widget_t *w) {
s->glcontext = NULL;
}
#endif
+ if (s->surf) {
+ cairo_surface_destroy (s->surf);
+ s->surf = NULL;
+ }
if (s->samples) {
free (s->samples);
s->samples = NULL;
@@ -2328,21 +2333,33 @@ gboolean
scope_draw_cairo (GtkWidget *widget, cairo_t *cr, gpointer user_data) {
GtkAllocation a;
gtk_widget_get_allocation (widget, &a);
- cairo_set_source_rgb (cr, 0, 0, 0);
- cairo_rectangle (cr, 0, 0, a.width, a.height);
- cairo_fill (cr);
w_scope_t *w = user_data;
+ if (!w->surf || cairo_image_surface_get_width (w->surf) != a.width) {
+ if (w->surf) {
+ cairo_surface_destroy (w->surf);
+ w->surf = NULL;
+ }
+ w->surf = cairo_surface_create_similar_image (cairo_get_target (cr), CAIRO_FORMAT_ARGB32, a.width, a.height);
+ }
+
+ cairo_t *c = cairo_create (w->surf);
+
+ cairo_set_source_rgb (c, 0, 0, 0);
+ cairo_rectangle (c, 0, 0, a.width, a.height);
+ cairo_fill (c);
+
int nsamples = a.width;
if (w->nsamples != nsamples) {
w->resized = nsamples;
+ cairo_destroy (c);
return FALSE;
}
- cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
- cairo_set_source_rgb (cr, 1, 1, 1);
- cairo_set_line_width (cr, 1);
+ cairo_set_antialias (c, CAIRO_ANTIALIAS_NONE);
+ cairo_set_source_rgb (c, 1, 1, 1);
+ cairo_set_line_width (c, 1);
deadbeef->mutex_lock (w->mutex);
float incr = a.width / (float)w->nsamples;
float h = a.height;
@@ -2355,13 +2372,17 @@ scope_draw_cairo (GtkWidget *widget, cairo_t *cr, gpointer user_data) {
h /= 2;
float hh = a.height/2.f;
- cairo_move_to (cr, 0, ftoi(w->samples[0] * h + hh));
+ cairo_move_to (c, 0, ftoi(w->samples[0] * h + hh));
for (int i = 1; i < w->nsamples; i++) {
float y = w->samples[i] * h + hh;
- cairo_line_to (cr, i, y);
+ cairo_line_to (c, i, y);
}
deadbeef->mutex_unlock (w->mutex);
- cairo_stroke (cr);
+ cairo_stroke (c);
+ cairo_destroy (c);
+ cairo_set_source_surface (cr, w->surf, 0, 0);
+ cairo_rectangle (cr, 0, 0, a.width, a.height);
+ cairo_fill (cr);
return FALSE;
}