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 <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-09-29 19:35:59 +02:00
parent c8b93cec76
commit 368925beff
6 changed files with 8 additions and 60 deletions

View File

@ -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);
}

View File

@ -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)
{

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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)