Skip to content

Commit

Permalink
feat(draw): convert wl_shm_format to cairo_format
Browse files Browse the repository at this point in the history
  • Loading branch information
jtheoof committed Dec 6, 2019
1 parent 2284911 commit c623939
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
21 changes: 18 additions & 3 deletions src/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,31 @@

#include "swappy.h"

static cairo_format_t get_cairo_format(enum wl_shm_format wl_fmt) {
switch (wl_fmt) {
case WL_SHM_FORMAT_ARGB8888:
return CAIRO_FORMAT_ARGB32;
case WL_SHM_FORMAT_XRGB8888:
return CAIRO_FORMAT_RGB24;
default:
return CAIRO_FORMAT_INVALID;
}
}

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_format_t format = get_cairo_format(buffer->format);
cairo_surface_t *image;

g_assert(format != CAIRO_FORMAT_INVALID);

image = cairo_image_surface_create_for_data(
buffer->data, CAIRO_FORMAT_ARGB32, geometry->height, geometry->width,
buffer->data, format, geometry->height, geometry->width,
buffer->stride);
cairo_save(cr);
cairo_surface_flush(image);
Expand All @@ -25,7 +40,7 @@ static void draw_buffer(cairo_t *cr, struct swappy_state *state) {
}
}

//static void draw_image(cairo_t *cr, struct swappy_state *state) {
// 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);
Expand Down Expand Up @@ -79,6 +94,6 @@ void draw_area(GtkWidget *widget, cairo_t *cr, struct swappy_state *state) {
cairo_restore(cr);

draw_buffer(cr, state);
// draw_image(cr, state);
// draw_image(cr, state);
draw_brushes(cr, state);
}
4 changes: 3 additions & 1 deletion src/screencopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ static struct swappy_buffer *create_buffer(struct wl_shm *shm,
int32_t width, int32_t height,
int32_t stride) {
size_t size = stride * height;
g_debug("creating buffer with dimensions: %dx%d", width, height);
g_debug(
"creating buffer with dimensions: %dx%d - format: 0x%08x - stride: %d",
width, height, format, stride);

int fd = create_shm_file(size);
if (fd == -1) {
Expand Down

0 comments on commit c623939

Please sign in to comment.