diff --git a/include/Mw/LowLevel/Wayland.h b/include/Mw/LowLevel/Wayland.h index b37bd45..32f6547 100644 --- a/include/Mw/LowLevel/Wayland.h +++ b/include/Mw/LowLevel/Wayland.h @@ -115,6 +115,8 @@ struct _MwLLWaylandColor { struct _MwLLWaylandPixmap { struct _MwLLCommonPixmap common; + + cairo_surface_t* cs; }; #endif diff --git a/src/backend/wayland.c b/src/backend/wayland.c index 48ce0c4..d0e0e25 100644 --- a/src/backend/wayland.c +++ b/src/backend/wayland.c @@ -852,31 +852,56 @@ static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int wid r->common.raw = malloc(4 * width * height); memcpy(r->common.raw, data, 4 * width * height); + r->wayland.cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); + MwLLPixmapUpdate(r); return r; } static void MwLLPixmapUpdateImpl(MwLLPixmap r) { - /* TODO */ + int i; + unsigned char* d; + + cairo_surface_flush(r->wayland.cs); + d = cairo_image_surface_get_data(r->wayland.cs); + for(i = 0; i < r->common.width * r->common.height * 4; i += 4){ + MwU32* p = (MwU32*)&d[i]; + *p <<= 8; + *p |= r->common.raw[i + 3]; + *p <<= 8; + *p |= r->common.raw[i + 0]; + *p <<= 8; + *p |= r->common.raw[i + 1]; + *p <<= 8; + *p |= r->common.raw[i + 2]; + } + cairo_surface_mark_dirty(r->wayland.cs); } static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) { + cairo_surface_destroy(pixmap->wayland.cs); free(pixmap->common.raw); free(pixmap); } static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) { - int y, x; - for(y = rect->y; y < rect->y + rect->height; y++) { - if(y < 0 || y >= handle->wayland.wh) continue; - for(x = rect->x; x < rect->x + rect->width; x++) { - if(x < 0 || x >= handle->wayland.ww) continue; + cairo_t* c; + cairo_surface_t* cs; - /* TODO */ - //((unsigned char*)handle->wayland.mapped_shm_buf)[(x + y * handle->wayland.ww) * 4 + 0] = 0x80; - } - } + cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, rect->width, rect->height); + c = cairo_create(cs); + + cairo_scale(c, (double)rect->width / pixmap->common.width, (double)rect->height / pixmap->common.height); + cairo_set_source_surface(c, pixmap->wayland.cs, 0, 0); + cairo_paint(c); + + cairo_set_source_rgb(handle->wayland.cairo, 1, 1, 1); + cairo_set_source_surface(handle->wayland.cairo, cs, rect->x, rect->y); + cairo_paint(handle->wayland.cairo); + + cairo_destroy(c); + cairo_surface_destroy(cs); } static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) { }