From 368925beff39cdc6bc950841ed808b2f4b1d76cb Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 29 Sep 2010 19:35:59 +0200 Subject: [PATCH] Remove compatibility to image class All the APIs that accept both an image and a cairo surface now only accept cairo surfaces. Images are gone. Signed-off-by: Uli Schlachter --- objects/client.c | 4 ++-- objects/image.c | 49 -------------------------------------- objects/image.h | 2 -- objects/wibox.c | 4 ++-- objects/widgets/imagebox.c | 5 ++-- objects/widgets/textbox.c | 4 ++-- 6 files changed, 8 insertions(+), 60 deletions(-) diff --git a/objects/client.c b/objects/client.c index c93b14b00..f7b1e91f5 100644 --- a/objects/client.c +++ b/objects/client.c @@ -1100,10 +1100,10 @@ client_set_icon(lua_State *L, int cidx, int iidx) cairo_surface_destroy(c->icon); c->icon = NULL; } else { - cairo_surface_t *surface = luaA_image_to_surface(L, iidx); + cairo_surface_t **cairo_surface = (cairo_surface_t **)luaL_checkudata(L, iidx, OOCAIRO_MT_NAME_SURFACE); if(c->icon) cairo_surface_destroy(c->icon); - c->icon = surface; + c->icon = draw_dup_image_surface(*cairo_surface); } luaA_object_emit_signal(L, cidx < iidx ? cidx : cidx - 1, "property::icon", 0); } diff --git a/objects/image.c b/objects/image.c index 56f0f9e7a..718634e23 100644 --- a/objects/image.c +++ b/objects/image.c @@ -784,55 +784,6 @@ luaA_image_get_alpha(lua_State *L, image_t *image) return 1; } -/** Convert an image into a cairo image surface. - * \param image The image to convert. - * \returns A cairo surface with the same content. This surface must be - * destroyed by the caller! - */ -cairo_surface_t * -image_to_surface(image_t *image) -{ - cairo_surface_t *ret; - cairo_surface_t *surface = cairo_image_surface_create_for_data( - image_getdata(image), CAIRO_FORMAT_ARGB32, - image_getwidth(image), image_getheight(image), - image_getwidth(image) * 4); - /* Cairo doesn't copy the data we give to it so we have to make a - * copy of the data. This is the lazy way to do that. */ - ret = draw_dup_image_surface(surface); - cairo_surface_destroy(surface); - return ret; -} - -/** Convert an image into a cairo image surface. - * \param L The Lua VM state. - * \param idx The index of the image in the lua stack - * \returns A cairo surface with the same content as the image. This surface - * must be destroyed by the caller! - */ -cairo_surface_t * -luaA_image_to_surface(lua_State *L, int idx) -{ - bool is_surface = false; - /* This inlines luaL_checkudata() but skips luaL_typerror() */ - if(lua_getmetatable(L, idx)) - { - lua_getfield(L, LUA_REGISTRYINDEX, OOCAIRO_MT_NAME_SURFACE); - if(lua_rawequal(L, -1, -2)) - is_surface = true; - lua_pop(L, 2); - } - if(is_surface) - { - cairo_surface_t **cairo_surface = (cairo_surface_t **)luaL_checkudata(L, idx, OOCAIRO_MT_NAME_SURFACE); - return draw_dup_image_surface(*cairo_surface); - } - - luaA_checkudata(L, idx, &image_class); - image_t *image = (void *) lua_topointer(L, idx); - return image_to_surface(image); -} - void image_class_setup(lua_State *L) { diff --git a/objects/image.h b/objects/image.h index d260b2c32..12c619276 100644 --- a/objects/image.h +++ b/objects/image.h @@ -32,8 +32,6 @@ int image_new_from_argb32(lua_State *L, int, int, uint32_t *); uint8_t * image_getdata(image_t *); int image_getwidth(image_t *); int image_getheight(image_t *); -cairo_surface_t *image_to_surface(image_t *); -cairo_surface_t *luaA_image_to_surface(lua_State *, int idx); xcb_pixmap_t image_to_1bit_pixmap(image_t *, xcb_drawable_t); diff --git a/objects/wibox.c b/objects/wibox.c index 1b3ab1fe3..ed6e1344f 100644 --- a/objects/wibox.c +++ b/objects/wibox.c @@ -946,10 +946,10 @@ luaA_wibox_set_bg_image(lua_State *L, wibox_t *wibox) cairo_surface_destroy(wibox->bg_image); wibox->bg_image = NULL; } else { - cairo_surface_t *surface = luaA_image_to_surface(L, -1); + cairo_surface_t **cairo_surface = (cairo_surface_t **)luaL_checkudata(L, -1, OOCAIRO_MT_NAME_SURFACE); if(wibox->bg_image) cairo_surface_destroy(wibox->bg_image); - wibox->bg_image = surface; + wibox->bg_image = draw_dup_image_surface(*cairo_surface); } wibox->need_update = true; luaA_object_emit_signal(L, -3, "property::bg_image", 0); diff --git a/objects/widgets/imagebox.c b/objects/widgets/imagebox.c index 7a740e773..d7f0e9adb 100644 --- a/objects/widgets/imagebox.c +++ b/objects/widgets/imagebox.c @@ -95,11 +95,10 @@ imagebox_set_image(lua_State *L, widget_t *widget, int idx) cairo_surface_destroy(d->image); d->image = NULL; } else { - cairo_surface_t *new_surface = luaA_image_to_surface(L, idx); - + cairo_surface_t **cairo_surface = (cairo_surface_t **)luaL_checkudata(L, idx, OOCAIRO_MT_NAME_SURFACE); if(d->image) cairo_surface_destroy(d->image); - d->image = new_surface; + d->image = draw_dup_image_surface(*cairo_surface); } widget_invalidate_bywidget(widget); diff --git a/objects/widgets/textbox.c b/objects/widgets/textbox.c index c97e472ff..4fa49931f 100644 --- a/objects/widgets/textbox.c +++ b/objects/widgets/textbox.c @@ -345,9 +345,9 @@ luaA_textbox_newindex(lua_State *L, const char *prop) cairo_surface_destroy(d->bg_image); d->bg_image = NULL; } else { - cairo_surface_t *surface = luaA_image_to_surface(L, -1); + cairo_surface_t **cairo_surface = (cairo_surface_t **)luaL_checkudata(L, -1, OOCAIRO_MT_NAME_SURFACE); cairo_surface_destroy(d->bg_image); - d->bg_image = surface; + d->bg_image = draw_dup_image_surface(*cairo_surface); } } else if(a_strcmp(prop, "bg") == 0)