On 08/04/2012 04:22 PM, Andre Heider wrote:
---
cursor/wayland-cursor.c | 115 ++++++++++-------------------------------------
1 file changed, 24 insertions(+), 91 deletions(-)
diff --git a/cursor/wayland-cursor.c b/cursor/wayland-cursor.c
index 10e8f62..8e467f6 100644
--- a/cursor/wayland-cursor.c
+++ b/cursor/wayland-cursor.c
[...]
@@ -220,9 +142,21 @@ wl_cursor_create_from_xcursor_images(XcursorImages *images,
/* copy pixels to shm pool */
size = image->image.width * image->image.height * 4;
- image->offset = shm_pool_allocate(theme->pool, size);
- memcpy(theme->pool->data + image->offset,
- images->images[i]->pixels, size);
+ p = wl_shm_pool_helper_allocate(theme->pool, size, &offset);
+ if (!p) {
+ resize = 2 * wl_shm_pool_helper_get_size(theme->pool) +
+ size;
+ if (!wl_shm_pool_helper_resize(theme->pool, resize)) {
+ free(cursor);
+ return NULL;
+ }
I like to have the allocate function try to resize the pool if needed.
All users except wayland-cursor allocate a pool large enough, so they
should never reach and on the other hand its convenient not to have to
write the resize logic every time one needs it.
I would go for having the resize by default, and if there is a use case
where we really don't want to resize, we could have something like:
enum wl_shm_mapping_resize_behavior {
/* never try to resize */
WL_SHM_MAPPING_RESIZE_NEVER,
/* try to resize to current size + new allocation size */
WL_SHM_MAPPING_RESIZE_ADD_SIZE,
/* double the allocation size until it is large enough */
WL_SHM_MAPPING_RESIZE_DOUBLE,
...
};
void
wl_shm_mapping_set_resize_behavior(struct wl_shm_mapping *mapping,
enum wl_shm_mapping_resize_behavior
behavior);
Or maybe have that as flags for wl_shm_mapping_create(). But the former
is a change that can be done in the future without breaking the API.
Ander
+
+ p = wl_shm_pool_helper_allocate(theme->pool, size,
+ &offset);
+ }
+
+ image->offset = offset;
+ memcpy(p, images->images[i]->pixels, size);
}
return &cursor->cursor;
@@ -280,8 +214,7 @@ wl_cursor_theme_load(const char *name, int size, struct
wl_shm *shm)
theme->cursor_count = 0;
theme->cursors = NULL;
- theme->pool =
- shm_pool_create(shm, size * size * 4);
+ theme->pool = wl_shm_pool_helper_create(shm, size * size * 4);
if (!theme->pool) {
free(theme->name);
free(theme);
@@ -305,7 +238,7 @@ wl_cursor_theme_destroy(struct wl_cursor_theme *theme)
for (i = 0; i < theme->cursor_count; i++)
wl_cursor_destroy(theme->cursors[i]);
- shm_pool_destroy(theme->pool);
+ wl_shm_pool_helper_destroy(theme->pool, 1);
free(theme->cursors);
free(theme);
_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel