Skip to content

Commit

Permalink
wip(draw): trying to draw the buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
jtheoof committed Dec 5, 2019
1 parent 275cc27 commit 2284911
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions src/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,41 @@

#include "swappy.h"

static void draw_image(cairo_t *cr, struct swappy_state *state) {
cairo_surface_t *image;
image = cairo_image_surface_create_from_png(state->image);
cairo_save(cr);
cairo_surface_flush(image);
cairo_surface_mark_dirty(image);
cairo_set_source_surface(cr, image, 0, 0);
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST);
cairo_paint(cr);
cairo_surface_destroy(image);
cairo_restore(cr);
static void draw_buffer(cairo_t *cr, struct swappy_state *state) {
// FIXME This is wrong, the geometry here is not quite valid
// It must be based on output, but will work fine on single screen
struct swappy_box *geometry = state->geometry;
struct swappy_output *output;
wl_list_for_each(output, &state->outputs, link) {
struct swappy_buffer *buffer = output->buffer;
cairo_surface_t *image;
image = cairo_image_surface_create_for_data(
buffer->data, CAIRO_FORMAT_ARGB32, geometry->height, geometry->width,
buffer->stride);
cairo_save(cr);
cairo_surface_flush(image);
cairo_surface_mark_dirty(image);
cairo_set_source_surface(cr, image, 0, 0);
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST);
cairo_paint(cr);
cairo_surface_destroy(image);
cairo_restore(cr);
}
}

//static void draw_image(cairo_t *cr, struct swappy_state *state) {
// cairo_surface_t *image;
// image = cairo_image_surface_create_from_png(state->image);
// cairo_save(cr);
// cairo_surface_flush(image);
// cairo_surface_mark_dirty(image);
// cairo_set_source_surface(cr, image, 0, 0);
// cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST);
// cairo_paint(cr);
// cairo_surface_destroy(image);
// cairo_restore(cr);
//}

static void draw_brushes(cairo_t *cr, struct swappy_state *state) {
for (GSList *brush = state->brushes; brush; brush = brush->next) {
GSList *brush_next = brush->next;
Expand Down Expand Up @@ -56,6 +78,7 @@ void draw_area(GtkWidget *widget, cairo_t *cr, struct swappy_state *state) {
cairo_fill(cr);
cairo_restore(cr);

draw_image(cr, state);
draw_buffer(cr, state);
// draw_image(cr, state);
draw_brushes(cr, state);
}

0 comments on commit 2284911

Please sign in to comment.