mirror of
https://github.com/jtheoof/swappy.git
synced 2024-07-14 18:00:25 +03:00
refactor(swappy): rename surface variables for clarity
This commit is contained in:
parent
7635a2ed4a
commit
3db1b13ae9
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
36
src/pixbuf.c
36
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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user