draw: remove draw_image_from_file()

This should speed up tasklist image drawing.

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-06-17 09:21:26 +02:00
parent d0a5638bb6
commit 64c4202519
3 changed files with 33 additions and 53 deletions

View File

@ -721,47 +721,32 @@ draw_image_from_argb_data(draw_context_t *ctx, int x, int y, int w, int h,
cairo_surface_destroy(source); cairo_surface_destroy(source);
} }
/** Draw an image (PNG format only) from a file to a draw context
* \param ctx Draw context to draw to
* \param x x coordinate
* \param y y coordinate
* \param wanted_h wanted height: if > 0, image will be resized
* \param filename file name to draw
*/
void
draw_image_from_file(draw_context_t *ctx, int x, int y, int wanted_h, const char *filename)
{
draw_image_t *image = draw_image_new(filename);
if(image)
{
draw_image(ctx, x, y, wanted_h, image);
draw_image_delete(&image);
}
}
#ifndef WITH_IMLIB2 #ifndef WITH_IMLIB2
/** Load an image (PNG Format only) from filename /** Load an image from filename.
* \param filename the image file to load * \param filename The image file to load.
* \return a new image * \return A new image.
*/ */
draw_image_t *draw_image_new(const char *filename) draw_image_t
*draw_image_new(const char *filename)
{ {
draw_image_t *image; draw_image_t *image = NULL;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
GError *error=NULL; GError *error = NULL;
if(!(pixbuf = gdk_pixbuf_new_from_file(filename,&error))) { if(filename)
warn("cannot load image %s: %s", filename, error->message); {
return NULL; if(!(pixbuf = gdk_pixbuf_new_from_file(filename,&error)))
warn("cannot load image %s: %s", filename, error->message);
else
{
image = p_new(draw_image_t, 1);
image->data = pixbuf;
image->width = gdk_pixbuf_get_width(pixbuf);
image->height = gdk_pixbuf_get_height(pixbuf);
}
} }
image = p_new(draw_image_t, 1);
image->data = pixbuf;
image->width = gdk_pixbuf_get_width(pixbuf);
image->height = gdk_pixbuf_get_height(pixbuf);
return image; return image;
} }
@ -770,21 +755,22 @@ draw_image_t *draw_image_new(const char *filename)
*/ */
void draw_image_delete(draw_image_t **image) void draw_image_delete(draw_image_t **image)
{ {
if (*image) if(*image)
{ {
gdk_pixbuf_unref((*image)->data); gdk_pixbuf_unref((*image)->data);
p_delete(image); p_delete(image);
} }
} }
/** Draw an image to a draw context /** Draw an image to a draw context.
* \param ctx Draw context to draw to * \param ctx Draw context to draw to.
* \param x x coordinate * \param x x coordinate.
* \param y y coordinate * \param y y coordinate.
* \param wanted_h wanted height: if > 0, image will be resized * \param wanted_h Wanted height: if > 0, image will be resized.
* \param image the image to draw * \param image The image to draw.
*/ */
void draw_image(draw_context_t *ctx, int x, int y, int wanted_h, draw_image_t *image) void
draw_image(draw_context_t *ctx, int x, int y, int wanted_h, draw_image_t *image)
{ {
cairo_t *cr; cairo_t *cr;

View File

@ -165,7 +165,6 @@ void draw_circle(draw_context_t *, int, int, int, bool, xcolor_t);
draw_image_t *draw_image_new(const char *); draw_image_t *draw_image_new(const char *);
void draw_image_delete(draw_image_t **); void draw_image_delete(draw_image_t **);
void draw_image(draw_context_t *, int, int, int, draw_image_t *); void draw_image(draw_context_t *, int, int, int, draw_image_t *);
void draw_image_from_file(draw_context_t *, int, int, int, const char *);
void draw_image_from_argb_data(draw_context_t *, int, int, int, int, int, unsigned char *); void draw_image_from_argb_data(draw_context_t *, int, int, int, int, int, unsigned char *);
area_t draw_get_image_size(const char *filename); area_t draw_get_image_size(const char *filename);
void draw_rotate(draw_context_t *, xcb_drawable_t, xcb_drawable_t, int, int, int, int, double, int, int); void draw_rotate(draw_context_t *, xcb_drawable_t, xcb_drawable_t, int, int, int, int, double, int, int);

View File

@ -77,6 +77,7 @@ tasklist_draw(draw_context_t *ctx, int screen,
markup_parser_data_t *p; markup_parser_data_t *p;
const char *elements[] = { "bg", NULL }; const char *elements[] = { "bg", NULL };
xcolor_t bg_color; xcolor_t bg_color;
draw_image_t *image;
if(used >= ctx->width) if(used >= ctx->width)
return (w->area.width = 0); return (w->area.width = 0);
@ -133,18 +134,12 @@ tasklist_draw(draw_context_t *ctx, int screen,
p->text = NULL; p->text = NULL;
markup_parser_data_delete(&p); markup_parser_data_delete(&p);
if(c->icon_path) if((image = draw_image_new(c->icon_path)))
{ {
area = draw_get_image_size(c->icon_path); icon_width = ((double) ctx->height / (double) image->height) * image->width;
if(area.width > 0 && area.height > 0) draw_image(ctx, w->area.x + box_width * i,
{ w->area.y, ctx->height, image);
icon_width = ((double) ctx->height / (double) area.height) * area.width; draw_image_delete(&image);
draw_image_from_file(ctx,
w->area.x + box_width * i,
w->area.y,
ctx->height,
c->icon_path);
}
} }
if(!icon_width && (icon = ewmh_get_window_icon(c->win))) if(!icon_width && (icon = ewmh_get_window_icon(c->win)))