refactor(swappy): rename surface variables for clarity

This commit is contained in:
Jeremy Attali 2021-02-15 20:36:03 -05:00 committed by Jeremy Attali
parent 7635a2ed4a
commit 3db1b13ae9
4 changed files with 23 additions and 25 deletions

View File

@ -156,8 +156,7 @@ struct swappy_state {
GdkPixbuf *original_image; GdkPixbuf *original_image;
cairo_surface_t *original_image_surface; cairo_surface_t *original_image_surface;
cairo_surface_t *scaled_image_surface; cairo_surface_t *rendering_surface;
cairo_surface_t *rendered_surface;
gdouble scaling_factor; gdouble scaling_factor;

View File

@ -249,9 +249,8 @@ void blur_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
void application_finish(struct swappy_state *state) { void application_finish(struct swappy_state *state) {
paint_free_all(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->original_image_surface);
cairo_surface_destroy(state->scaled_image_surface);
if (state->temp_file_str) { if (state->temp_file_str) {
g_info("deleting temporary file: %s", state->temp_file_str); g_info("deleting temporary file: %s", state->temp_file_str);
if (g_unlink(state->temp_file_str) != 0) { 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; double scale_y = (double)alloc->height / image_height;
cairo_scale(cr, scale_x, scale_y); 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); cairo_paint(cr);
return FALSE; return FALSE;

View File

@ -6,10 +6,10 @@
#include "notification.h" #include "notification.h"
GdkPixbuf *pixbuf_get_from_state(struct swappy_state *state) { GdkPixbuf *pixbuf_get_from_state(struct swappy_state *state) {
guint width = cairo_image_surface_get_width(state->rendered_surface); guint width = cairo_image_surface_get_width(state->rendering_surface);
guint height = cairo_image_surface_get_height(state->rendered_surface); guint height = cairo_image_surface_get_height(state->rendering_surface);
GdkPixbuf *pixbuf = GdkPixbuf *pixbuf = gdk_pixbuf_get_from_surface(state->rendering_surface, 0,
gdk_pixbuf_get_from_surface(state->rendered_surface, 0, 0, width, height); 0, width, height);
return pixbuf; 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_width = gdk_pixbuf_get_width(image);
gint image_height = gdk_pixbuf_get_height(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); cairo_image_surface_create(format, image_width, image_height);
if (!scaled_surface) { if (!original_image_surface) {
g_error("unable to create cairo surface from pixbuf"); g_error("unable to create cairo original surface from pixbuf");
goto finish; goto finish;
} else { } else {
cairo_t *cr; cairo_t *cr;
cr = cairo_create(scaled_surface); cr = cairo_create(original_image_surface);
gdk_cairo_set_source_pixbuf(cr, image, 0, 0); gdk_cairo_set_source_pixbuf(cr, image, 0, 0);
cairo_paint(cr); cairo_paint(cr);
cairo_destroy(cr); cairo_destroy(cr);
} }
cairo_surface_t *rendered_surface = cairo_surface_t *rendering_surface =
cairo_image_surface_create(format, image_width, image_height); cairo_image_surface_create(format, image_width, image_height);
if (!rendered_surface) { if (!rendering_surface) {
g_error("unable to create rendering surface"); g_error("unable to create rendering surface");
goto finish; 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); g_info("size of area to render: %ux%u", alloc->width, alloc->height);
finish: finish:
if (state->scaled_image_surface) { if (state->original_image_surface) {
cairo_surface_destroy(state->scaled_image_surface); cairo_surface_destroy(state->original_image_surface);
state->scaled_image_surface = NULL; state->original_image_surface = NULL;
} }
state->scaled_image_surface = scaled_surface; state->original_image_surface = original_image_surface;
if (state->rendered_surface) { if (state->rendering_surface) {
cairo_surface_destroy(state->rendered_surface); cairo_surface_destroy(state->rendering_surface);
state->rendered_surface = NULL; state->rendering_surface = NULL;
} }
state->rendered_surface = rendered_surface; state->rendering_surface = rendering_surface;
g_free(alloc); g_free(alloc);
} }

View File

@ -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) { 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); 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) { 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); cairo_t *cr = cairo_create(surface);
render_background(cr, state); render_background(cr, state);