Skip to content

Commit

Permalink
start adding cairo_surfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
nzjrs committed Jul 26, 2012
1 parent 91a8764 commit c6bb439
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
7 changes: 5 additions & 2 deletions Makefile
Expand Up @@ -34,13 +34,12 @@ DEBUG_INCLUDES = \

INCLUDES = \
-I../ \
-DGTK_DISABLE_SINGLE_INCLUDES \
$(NULL)

OBJECTS = \
uber-graph.o \
uber-line-graph.o \
uber-heat-map.o \
uber-scatter.o \
uber-window.o \
uber-scale.o \
uber-label.o \
Expand All @@ -52,6 +51,10 @@ OBJECTS = \
g-ring.o \
$(NULL)

# uber-heat-map.o \
# uber-scatter.o \

ifeq ($(DISABLE_DEBUG),1)
INCLUDES += $(DEBUG_INCLUDES)
endif
Expand Down
10 changes: 10 additions & 0 deletions main.c
Expand Up @@ -30,6 +30,8 @@
#include "uber.h"
#include "blktrace.h"

#define USE_HEAT 0

typedef struct
{
guint len;
Expand Down Expand Up @@ -385,6 +387,7 @@ has_freq_scaling (gint cpu)
return ret;
}

#if USE_HEAT
static gboolean
dummy_scatter_func (UberScatter *scatter, /* IN */
GArray **array, /* OUT */
Expand All @@ -400,6 +403,7 @@ dummy_scatter_func (UberScatter *scatter, /* IN */
}
return TRUE;
}
#endif

gint
main (gint argc, /* IN */
Expand All @@ -413,8 +417,10 @@ main (gint argc, /* IN */
GtkWidget *cpu;
GtkWidget *net;
GtkWidget *line;
#if USE_HEAT
GtkWidget *map;
GtkWidget *scatter;
#endif
GtkWidget *label;
GtkAccelGroup *ag;
GdkColor color;
Expand Down Expand Up @@ -451,8 +457,10 @@ main (gint argc, /* IN */
cpu = uber_line_graph_new();
net = uber_line_graph_new();
line = uber_line_graph_new();
#if USE_HEAT
map = uber_heat_map_new();
scatter = uber_scatter_new();
#endif
/*
* Configure CPU graph.
*/
Expand Down Expand Up @@ -509,6 +517,7 @@ main (gint argc, /* IN */
uber_label_set_text(UBER_LABEL(label), "Bytes Out");
gdk_color_parse("#4e9a06", &color);
uber_line_graph_add_line(UBER_LINE_GRAPH(net), &color, UBER_LABEL(label));
#if USE_HEAT
/*
* Configure heat map.
*/
Expand All @@ -534,6 +543,7 @@ main (gint argc, /* IN */
uber_graph_set_show_xlabels(UBER_GRAPH(map), FALSE);
gtk_widget_show(map);
}
#endif
/*
* Add graphs.
*/
Expand Down
24 changes: 23 additions & 1 deletion uber-graph.c
Expand Up @@ -21,6 +21,7 @@
#endif

#include <glib/gi18n.h>
#include <gdk/gdk.h>
#include <math.h>
#include <string.h>

Expand All @@ -38,6 +39,13 @@
p = NULL; \
} \
} G_STMT_END
#define UNSET_SURFACE(p) \
G_STMT_START { \
if (p) { \
cairo_surface_destroy (p); \
p = NULL; \
} \
} G_STMT_END
#define CLEAR_CAIRO(c, a) \
G_STMT_START { \
cairo_save(c); \
Expand Down Expand Up @@ -73,6 +81,10 @@ struct _UberGraphPrivate
{
GdkPixmap *fg_pixmap; /* Server side pixmap for foreground. */
GdkPixmap *bg_pixmap; /* Server side pixmap for background. */

cairo_surface_t *fg_surface;
cairo_surface_t *bg_surface;

GdkRectangle content_rect; /* Content area rectangle. */
GdkRectangle nonvis_rect; /* Non-visible drawing area larger than
* content rect. Used to draw over larger
Expand Down Expand Up @@ -370,6 +382,7 @@ uber_graph_init_texture (UberGraph *graph) /* IN */
GdkDrawable *drawable;
GdkColormap *colormap;
GdkVisual *visual;
GdkWindow *window;
cairo_t *cr;
gint depth = -1;
gint width;
Expand All @@ -378,6 +391,7 @@ uber_graph_init_texture (UberGraph *graph) /* IN */

priv = graph->priv;
gtk_widget_get_allocation(GTK_WIDGET(graph), &alloc);
window = gtk_widget_get_window(GTK_WIDGET(graph));
/*
* Get drawable to base pixmaps upon.
*/
Expand All @@ -397,6 +411,7 @@ uber_graph_init_texture (UberGraph *graph) /* IN */
*/
width = MAX(priv->nonvis_rect.x + priv->nonvis_rect.width, alloc.width);
priv->fg_pixmap = gdk_pixmap_new(drawable, width, alloc.height, depth);
priv->fg_surface = gdk_window_create_similar_surface(window, CAIRO_CONTENT_COLOR_ALPHA, width, alloc.height);
/*
* Create a 32-bit colormap if needed.
*/
Expand Down Expand Up @@ -431,13 +446,15 @@ uber_graph_init_bg (UberGraph *graph) /* IN */
GtkAllocation alloc;
GdkVisual *visual;
GdkColormap *colormap;
GdkWindow *window;
cairo_t *cr;
gint depth = 32;

g_return_if_fail(UBER_IS_GRAPH(graph));

priv = graph->priv;
gtk_widget_get_allocation(GTK_WIDGET(graph), &alloc);
window = gtk_widget_get_window(GTK_WIDGET(graph));
/*
* Get drawable for pixmap.
*/
Expand All @@ -455,6 +472,7 @@ uber_graph_init_bg (UberGraph *graph) /* IN */
* Create the server-side pixmap.
*/
priv->bg_pixmap = gdk_pixmap_new(drawable, alloc.width, alloc.height, depth);
priv->bg_surface = gdk_window_create_similar_surface(window, CAIRO_CONTENT_COLOR_ALPHA, alloc.width, alloc.height);
/*
* Setup 32-bit colormap if needed.
*/
Expand Down Expand Up @@ -822,6 +840,7 @@ uber_graph_realize (GtkWidget *widget) /* IN */
* Re-initialize textures for updated sizes.
*/
UNSET_PIXMAP(priv->bg_pixmap);
UNSET_SURFACE(priv->bg_surface);
UNSET_PIXMAP(priv->fg_pixmap);
uber_graph_init_bg(graph);
uber_graph_init_texture(graph);
Expand Down Expand Up @@ -868,6 +887,7 @@ uber_graph_unrealize (GtkWidget *widget) /* IN */
* Destroy textures.
*/
UNSET_PIXMAP(priv->bg_pixmap);
UNSET_SURFACE(priv->bg_surface);
UNSET_PIXMAP(priv->fg_pixmap);
}

Expand Down Expand Up @@ -1025,7 +1045,7 @@ uber_graph_render_fg (UberGraph *graph) /* IN */
cairo_fill(cr);
cairo_restore(cr);

#if 0
#if 1
/*
* XXX: Draw line helper for debugging.
*/
Expand Down Expand Up @@ -1789,6 +1809,7 @@ uber_graph_size_allocate (GtkWidget *widget, /* IN */
* Recreate server side pixmaps.
*/
UNSET_PIXMAP(priv->bg_pixmap);
UNSET_SURFACE(priv->bg_surface);
UNSET_PIXMAP(priv->fg_pixmap);
uber_graph_init_bg(graph);
uber_graph_init_texture(graph);
Expand Down Expand Up @@ -2011,6 +2032,7 @@ uber_graph_dispose (GObject *object) /* IN */
* Destroy textures.
*/
UNSET_PIXMAP(priv->bg_pixmap);
UNSET_SURFACE(priv->bg_surface);
UNSET_PIXMAP(priv->fg_pixmap);
/*
* Call base class.
Expand Down

0 comments on commit c6bb439

Please sign in to comment.