summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2021-08-25 23:56:51 -0700
committerVito Caputo <vcaputo@pengaru.com>2021-08-25 23:56:51 -0700
commitdc3ee8c2f50260d553e5cffe3037d9f3c8a51aa1 (patch)
treefba9d531fea5fc54e69fd0205d2f913c0ca09ea3 /src
parente811aee16be8f594919beb644b2474f643588623 (diff)
charts: add vwm_chart_render_as_{pixmap,ximage}()
Preparatory work for supporting --snapshot-on-sigchld to vmon; add a way to access a chart's pixels outside of the X server.
Diffstat (limited to 'src')
-rw-r--r--src/charts.c43
-rw-r--r--src/charts.h2
2 files changed, 44 insertions, 1 deletions
diff --git a/src/charts.c b/src/charts.c
index a94714b..fddef35 100644
--- a/src/charts.c
+++ b/src/charts.c
@@ -214,7 +214,7 @@ static Picture create_picture(vwm_charts_t *charts, unsigned width, unsigned hei
/* convenience helper for creating a filled picture, supply res_pixmap to keep a reference to the pixmap drawable. */
-static Picture create_picture_fill(vwm_charts_t *charts, unsigned width, unsigned height, unsigned depth, unsigned long attrs_mask, XRenderPictureAttributes *attrs, XRenderColor *color, Pixmap *res_pixmap)
+static Picture create_picture_fill(vwm_charts_t *charts, unsigned width, unsigned height, unsigned depth, unsigned long attrs_mask, XRenderPictureAttributes *attrs, const XRenderColor *color, Pixmap *res_pixmap)
{
vwm_xserver_t *xserver = charts->xserver;
Picture picture;
@@ -1172,6 +1172,47 @@ void vwm_chart_render(vwm_charts_t *charts, vwm_chart_t *chart, int op, Picture
}
+/* render the chart into a newly allocated pixmap, intended for snapshotting purposes */
+void vwm_chart_render_as_pixmap(vwm_charts_t *charts, vwm_chart_t *chart, const XRenderColor *bg_color, Pixmap *res_pixmap)
+{
+ static const XRenderColor blackness = { 0x0000, 0x0000, 0x0000, 0xFFFF};
+ Picture dest;
+
+ assert(charts);
+ assert(chart);
+ assert(res_pixmap);
+
+ if (!bg_color)
+ bg_color = &blackness;
+
+ dest = create_picture_fill(charts, chart->width, chart->height, 32, 0, NULL, bg_color, res_pixmap);
+ vwm_chart_render(charts, chart, PictOpOver, dest, 0, 0, chart->width, chart->height);
+ XRenderFreePicture(charts->xserver->display, dest);
+}
+
+
+void vwm_chart_render_as_ximage(vwm_charts_t *charts, vwm_chart_t *chart, const XRenderColor *bg_color, XImage **res_ximage)
+{
+ Pixmap dest_pixmap;
+
+ assert(charts);
+ assert(chart);
+ assert(res_ximage);
+
+ vwm_chart_render_as_pixmap(charts, chart, bg_color, &dest_pixmap);
+ *res_ximage = XGetImage(charts->xserver->display,
+ dest_pixmap,
+ 0,
+ 0,
+ chart->width,
+ chart->height,
+ AllPlanes,
+ ZPixmap);
+
+ XFreePixmap(charts->xserver->display, dest_pixmap);
+}
+
+
/* increase the sample rate relative to current using the table of intervals */
void vwm_charts_rate_increase(vwm_charts_t *charts)
{
diff --git a/src/charts.h b/src/charts.h
index 222b968..ed71fdd 100644
--- a/src/charts.h
+++ b/src/charts.h
@@ -22,5 +22,7 @@ void vwm_chart_reset_snowflakes(vwm_charts_t *charts, vwm_chart_t *chart);
int vwm_chart_set_visible_size(vwm_charts_t *charts, vwm_chart_t *chart, int width, int height);
void vwm_chart_compose(vwm_charts_t *charts, vwm_chart_t *chart, XserverRegion *res_damaged_region);
void vwm_chart_render(vwm_charts_t *charts, vwm_chart_t *chart, int op, Picture dest, int x, int y, int width, int height);
+void vwm_chart_render_as_pixmap(vwm_charts_t *charts, vwm_chart_t *chart, const XRenderColor *bg_color, Pixmap *res_pixmap);
+void vwm_chart_render_as_ximage(vwm_charts_t *charts, vwm_chart_t *chart, const XRenderColor *bg_color, XImage **res_ximage);
#endif
© All Rights Reserved