From 3db1b13ae92f83207a5b582f29bd03a48dc99399 Mon Sep 17 00:00:00 2001 From: Jeremy Attali Date: Mon, 15 Feb 2021 20:36:03 -0500 Subject: [PATCH] refactor(swappy): rename surface variables for clarity --- include/swappy.h | 3 +-- src/application.c | 5 ++--- src/pixbuf.c | 36 ++++++++++++++++++------------------ src/render.c | 4 ++-- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/include/swappy.h b/include/swappy.h index fa74556..7c84b4a 100644 --- a/include/swappy.h +++ b/include/swappy.h @@ -156,8 +156,7 @@ struct swappy_state { GdkPixbuf *original_image; cairo_surface_t *original_image_surface; - cairo_surface_t *scaled_image_surface; - cairo_surface_t *rendered_surface; + cairo_surface_t *rendering_surface; gdouble scaling_factor; diff --git a/src/application.c b/src/application.c index c68569d..6925cc8 100644 --- a/src/application.c +++ b/src/application.c @@ -249,9 +249,8 @@ void blur_clicked_handler(GtkWidget *widget, struct swappy_state *state) { void application_finish(struct swappy_state *state) { paint_free_all(state); - cairo_surface_destroy(state->rendered_surface); + cairo_surface_destroy(state->rendering_surface); cairo_surface_destroy(state->original_image_surface); - cairo_surface_destroy(state->scaled_image_surface); if (state->temp_file_str) { g_info("deleting temporary file: %s", state->temp_file_str); if (g_unlink(state->temp_file_str) != 0) { @@ -412,7 +411,7 @@ gboolean draw_area_handler(GtkWidget *widget, cairo_t *cr, double scale_y = (double)alloc->height / image_height; cairo_scale(cr, scale_x, scale_y); - cairo_set_source_surface(cr, state->rendered_surface, 0, 0); + cairo_set_source_surface(cr, state->rendering_surface, 0, 0); cairo_paint(cr); return FALSE; diff --git a/src/pixbuf.c b/src/pixbuf.c index 82abad2..95ad9d7 100644 --- a/src/pixbuf.c +++ b/src/pixbuf.c @@ -6,10 +6,10 @@ #include "notification.h" GdkPixbuf *pixbuf_get_from_state(struct swappy_state *state) { - guint width = cairo_image_surface_get_width(state->rendered_surface); - guint height = cairo_image_surface_get_height(state->rendered_surface); - GdkPixbuf *pixbuf = - gdk_pixbuf_get_from_surface(state->rendered_surface, 0, 0, width, height); + guint width = cairo_image_surface_get_width(state->rendering_surface); + guint height = cairo_image_surface_get_height(state->rendering_surface); + GdkPixbuf *pixbuf = gdk_pixbuf_get_from_surface(state->rendering_surface, 0, + 0, width, height); return pixbuf; } @@ -97,24 +97,24 @@ void pixbuf_scale_surface_from_widget(struct swappy_state *state, gint image_width = gdk_pixbuf_get_width(image); gint image_height = gdk_pixbuf_get_height(image); - cairo_surface_t *scaled_surface = + cairo_surface_t *original_image_surface = cairo_image_surface_create(format, image_width, image_height); - if (!scaled_surface) { - g_error("unable to create cairo surface from pixbuf"); + if (!original_image_surface) { + g_error("unable to create cairo original surface from pixbuf"); goto finish; } else { cairo_t *cr; - cr = cairo_create(scaled_surface); + cr = cairo_create(original_image_surface); gdk_cairo_set_source_pixbuf(cr, image, 0, 0); cairo_paint(cr); cairo_destroy(cr); } - cairo_surface_t *rendered_surface = + cairo_surface_t *rendering_surface = cairo_image_surface_create(format, image_width, image_height); - if (!rendered_surface) { + if (!rendering_surface) { g_error("unable to create rendering surface"); goto finish; } @@ -122,17 +122,17 @@ void pixbuf_scale_surface_from_widget(struct swappy_state *state, g_info("size of area to render: %ux%u", alloc->width, alloc->height); finish: - if (state->scaled_image_surface) { - cairo_surface_destroy(state->scaled_image_surface); - state->scaled_image_surface = NULL; + if (state->original_image_surface) { + cairo_surface_destroy(state->original_image_surface); + state->original_image_surface = NULL; } - state->scaled_image_surface = scaled_surface; + state->original_image_surface = original_image_surface; - if (state->rendered_surface) { - cairo_surface_destroy(state->rendered_surface); - state->rendered_surface = NULL; + if (state->rendering_surface) { + cairo_surface_destroy(state->rendering_surface); + state->rendering_surface = NULL; } - state->rendered_surface = rendered_surface; + state->rendering_surface = rendering_surface; g_free(alloc); } diff --git a/src/render.c b/src/render.c index f877ce6..2622019 100644 --- a/src/render.c +++ b/src/render.c @@ -426,7 +426,7 @@ static void render_brush(cairo_t *cr, struct swappy_paint_brush brush) { } static void render_image(cairo_t *cr, struct swappy_state *state) { - cairo_surface_t *surface = state->scaled_image_surface; + cairo_surface_t *surface = state->original_image_surface; cairo_save(cr); @@ -475,7 +475,7 @@ static void render_paints(cairo_t *cr, struct swappy_state *state) { } void render_state(struct swappy_state *state) { - cairo_surface_t *surface = state->rendered_surface; + cairo_surface_t *surface = state->rendering_surface; cairo_t *cr = cairo_create(surface); render_background(cr, state);