Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/twin.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ typedef struct _twin_pixmap {
#endif

twin_window_t *window; /**< Associated window (if any) */

/* Transform buffer cache for compositing operations */
void *xform_cache; /**< Cached xform buffer */
size_t xform_cache_size; /**< Cached xform buffer size in bytes */
} twin_pixmap_t;

/**
Expand Down
24 changes: 19 additions & 5 deletions src/draw-builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,22 @@ static twin_xform_t *twin_pixmap_init_xform(twin_pixmap_t *pixmap,
if (fmt == TWIN_RGB16)
fmt = TWIN_ARGB32;

twin_xform_t *xform =
calloc(1, sizeof(twin_xform_t) + width * twin_bytes_per_pixel(fmt));
if (!xform)
return NULL;
size_t required_size =
sizeof(twin_xform_t) + (size_t) width * twin_bytes_per_pixel(fmt);

/* Reuse cached xform buffer if large enough */
twin_xform_t *xform;
if (pixmap->xform_cache && pixmap->xform_cache_size >= required_size) {
xform = (twin_xform_t *) pixmap->xform_cache;
} else {
/* Need larger cache - reallocate */
void *new_cache = realloc(pixmap->xform_cache, required_size);
if (!new_cache)
return NULL;
pixmap->xform_cache = new_cache;
pixmap->xform_cache_size = required_size;
xform = (twin_xform_t *) new_cache;
}

xform->span.v = (twin_argb32_t *) (char *) (xform + 1);
xform->pixmap = pixmap;
Expand All @@ -650,7 +662,9 @@ static twin_xform_t *twin_pixmap_init_xform(twin_pixmap_t *pixmap,

static void twin_pixmap_free_xform(twin_xform_t *xform)
{
free(xform);
/* Xform buffer is now cached in pixmap - don't free */
/* This function is kept for API compatibility but does nothing */
(void) xform;
}

#define FX(x) twin_int_to_fixed(x)
Expand Down
5 changes: 5 additions & 0 deletions src/pixmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ twin_pixmap_t *twin_pixmap_create(twin_format_t format,
pixmap->shadow = false;
#endif
pixmap->window = NULL; /* Initialize window field */
pixmap->xform_cache = NULL;
pixmap->xform_cache_size = 0;
pixmap->p.v = pixmap + 1;
memset(pixmap->p.v, '\0', space);
return pixmap;
Expand Down Expand Up @@ -82,6 +84,8 @@ twin_pixmap_t *twin_pixmap_create_const(twin_format_t format,
pixmap->stride = stride;
pixmap->disable = 0;
pixmap->window = NULL; /* Initialize window field */
pixmap->xform_cache = NULL;
pixmap->xform_cache_size = 0;
pixmap->p = pixels;
return pixmap;
}
Expand All @@ -90,6 +94,7 @@ void twin_pixmap_destroy(twin_pixmap_t *pixmap)
{
if (pixmap->screen)
twin_pixmap_hide(pixmap);
free(pixmap->xform_cache); /* Free xform buffer cache */
free(pixmap);
}

Expand Down