summaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
Diffstat (limited to 'render')
-rw-r--r--render/image.c382
-rw-r--r--render/image.h12
-rw-r--r--render/imagecache.c144
-rw-r--r--render/imagecache.h51
-rw-r--r--render/obrender-4.0.pc.in (renamed from render/obrender-3.0.pc.in)2
-rw-r--r--render/render.c59
-rw-r--r--render/render.h82
-rw-r--r--render/theme.c26
-rw-r--r--render/theme.h7
-rw-r--r--render/version.h.in15
10 files changed, 718 insertions, 62 deletions
diff --git a/render/image.c b/render/image.c
index fa630b74..c7452fce 100644
--- a/render/image.c
+++ b/render/image.c
@@ -20,6 +20,7 @@
#include "geom.h"
#include "image.h"
#include "color.h"
+#include "imagecache.h"
#include <glib.h>
@@ -27,13 +28,116 @@
#define FLOOR(i) ((i) & (~0UL << FRACTION))
#define AVERAGE(a, b) (((((a) ^ (b)) & 0xfefefefeL) >> 1) + ((a) & (b)))
-static void ImageCopyResampled(RrPixel32 *dst, RrPixel32 *src,
- gulong dstW, gulong dstH,
- gulong srcW, gulong srcH)
+void RrImagePicInit(RrImagePic *pic, gint w, gint h, RrPixel32 *data)
{
+ gint i;
+
+ pic->width = w;
+ pic->height = h;
+ pic->data = data;
+ pic->sum = 0;
+ for (i = w*h; i > 0; --i)
+ pic->sum += *(data++);
+}
+
+static void RrImagePicFree(RrImagePic *pic)
+{
+ if (pic) {
+ g_free(pic->data);
+ g_free(pic);
+ }
+}
+
+/*! Add a picture to an Image, that is, add another copy of the image at
+ another size. This may add it to the "originals" list or to the
+ "resized" list. */
+static void AddPicture(RrImage *self, RrImagePic ***list, gint *len,
+ RrImagePic *pic)
+{
+ gint i;
+
+ g_assert(pic->width > 0 && pic->height > 0);
+
+ g_assert(g_hash_table_lookup(self->cache->table, pic) == NULL);
+
+ /* grow the list */
+ *list = g_renew(RrImagePic*, *list, ++*len);
+
+ /* move everything else down one */
+ for (i = *len-1; i > 0; --i)
+ (*list)[i] = (*list)[i-1];
+
+ /* set the new picture up at the front of the list */
+ (*list)[0] = pic;
+
+ /* add the picture as a key to point to this image in the cache */
+ g_hash_table_insert(self->cache->table, (*list)[0], self);
+
+#ifdef DEBUG
+ g_message("Adding %s picture to the cache:\n "
+ "Image 0x%x, w %d h %d Hash %u\n",
+ (*list == self->original ? "ORIGINAL" : "RESIZED"),
+ (guint)self, pic->width, pic->height, RrImagePicHash(pic));
+#endif
+}
+
+/*! Remove a picture from an Image. This may remove it from the "originals"
+ list or the "resized" list. */
+static void RemovePicture(RrImage *self, RrImagePic ***list,
+ gint i, gint *len)
+{
+ gint j;
+
+#ifdef DEBUG
+ g_message("Removing %s picture from the cache:\n "
+ "Image 0x%x, w %d h %d Hash %u\n",
+ (*list == self->original ? "ORIGINAL" : "RESIZED"),
+ (guint)self, (*list)[i]->width, (*list)[i]->height,
+ RrImagePicHash((*list)[i]));
+#endif
+
+ /* remove the picture as a key in the cache */
+ g_hash_table_remove(self->cache->table, (*list)[i]);
+
+ /* free the picture */
+ RrImagePicFree((*list)[i]);
+ /* shift everything down one */
+ for (j = i; j < *len-1; ++j)
+ (*list)[j] = (*list)[j+1];
+ /* shrink the list */
+ *list = g_renew(RrImagePic*, *list, --*len);
+}
+
+/*! Given a picture in RGBA format, of a specified size, resize it to the new
+ requested size (but keep its aspect ratio). If the image does not need to
+ be resized (it is already the right size) then this returns NULL. Otherwise
+ it returns a newly allocated RrImagePic with the resized picture inside it
+*/
+static RrImagePic* ResizeImage(RrPixel32 *src,
+ gulong srcW, gulong srcH,
+ gulong dstW, gulong dstH)
+{
+ RrPixel32 *dst, *dststart;
+ RrImagePic *pic;
gulong dstX, dstY, srcX, srcY;
gulong srcX1, srcX2, srcY1, srcY2;
gulong ratioX, ratioY;
+ gulong aspectW, aspectH;
+
+ /* keep the aspect ratio */
+ aspectW = dstW;
+ aspectH = (gint)(dstW * ((gdouble)srcH / srcW));
+ if (aspectH > dstH) {
+ aspectH = dstH;
+ aspectW = (gint)(dstH * ((gdouble)srcW / srcH));
+ }
+ dstW = aspectW;
+ dstH = aspectH;
+
+ if (srcW == dstW && srcH == dstH)
+ return NULL; /* no scaling needed ! */
+
+ dststart = dst = g_new(RrPixel32, dstW * dstH);
ratioX = (srcW << FRACTION) / dstW;
ratioY = (srcH << FRACTION) / dstH;
@@ -104,53 +208,47 @@ static void ImageCopyResampled(RrPixel32 *dst, RrPixel32 *src,
(alpha << RrDefaultAlphaOffset);
}
}
+
+ pic = g_new(RrImagePic, 1);
+ RrImagePicInit(pic, dstW, dstH, dststart);
+
+ return pic;
}
-void RrImageDraw(RrPixel32 *target, RrTextureRGBA *rgba,
- gint target_w, gint target_h,
- RrRect *area)
+/*! This drawns an RGBA picture into the target, within the rectangle specified
+ by the area parameter. If the area's size differs from the source's then it
+ will be centered within the rectangle */
+void DrawRGBA(RrPixel32 *target, gint target_w, gint target_h,
+ RrPixel32 *source, gint source_w, gint source_h,
+ gint alpha, RrRect *area)
{
RrPixel32 *dest;
- RrPixel32 *source;
- gint sw, sh, dw, dh;
gint col, num_pixels;
+ gint dw, dh;
- sw = rgba->width;
- sh = rgba->height;
+ g_assert(source_w <= area->width && source_h <= area->height);
+ g_assert(area->x + area->width <= target_w);
+ g_assert(area->y + area->height <= target_h);
- /* keep the ratio */
+ /* keep the aspect ratio */
dw = area->width;
- dh = (gint)(dw * ((gdouble)sh / sw));
+ dh = (gint)(dw * ((gdouble)source_h / source_w));
if (dh > area->height) {
dh = area->height;
- dw = (gint)(dh * ((gdouble)sw / sh));
- }
-
- if (sw != dw || sh != dh) {
- /*if (!(rgba->cache && dw == rgba->cwidth && dh == rgba->cheight))*/ {
- g_free(rgba->cache);
- rgba->cache = g_new(RrPixel32, dw * dh);
- ImageCopyResampled(rgba->cache, rgba->data, dw, dh, sw, sh);
- rgba->cwidth = dw;
- rgba->cheight = dh;
- }
- source = rgba->cache;
- } else {
- source = rgba->data;
+ dw = (gint)(dh * ((gdouble)source_w / source_h));
}
/* copy source -> dest, and apply the alpha channel.
-
center the image if it is smaller than the area */
col = 0;
num_pixels = dw * dh;
dest = target + area->x + (area->width - dw) / 2 +
(target_w * (area->y + (area->height - dh) / 2));
while (num_pixels-- > 0) {
- guchar alpha, r, g, b, bgr, bgg, bgb;
+ guchar a, r, g, b, bgr, bgg, bgb;
/* apply the rgba's opacity as well */
- alpha = ((*source >> RrDefaultAlphaOffset) * rgba->alpha) >> 8;
+ a = ((*source >> RrDefaultAlphaOffset) * alpha) >> 8;
r = *source >> RrDefaultRedOffset;
g = *source >> RrDefaultGreenOffset;
b = *source >> RrDefaultBlueOffset;
@@ -160,9 +258,9 @@ void RrImageDraw(RrPixel32 *target, RrTextureRGBA *rgba,
bgg = *dest >> RrDefaultGreenOffset;
bgb = *dest >> RrDefaultBlueOffset;
- r = bgr + (((r - bgr) * alpha) >> 8);
- g = bgg + (((g - bgg) * alpha) >> 8);
- b = bgb + (((b - bgb) * alpha) >> 8);
+ r = bgr + (((r - bgr) * a) >> 8);
+ g = bgg + (((g - bgg) * a) >> 8);
+ b = bgb + (((b - bgb) * a) >> 8);
*dest = ((r << RrDefaultRedOffset) |
(g << RrDefaultGreenOffset) |
@@ -177,3 +275,223 @@ void RrImageDraw(RrPixel32 *target, RrTextureRGBA *rgba,
}
}
}
+
+/*! Draw an RGBA texture into a target pixel buffer. */
+void RrImageDrawRGBA(RrPixel32 *target, RrTextureRGBA *rgba,
+ gint target_w, gint target_h,
+ RrRect *area)
+{
+ RrImagePic *scaled;
+
+ scaled = ResizeImage(rgba->data, rgba->width, rgba->height,
+ area->width, area->height);
+
+ if (scaled) {
+#ifdef DEBUG
+ g_warning("Scaling an RGBA! You should avoid this and just make "
+ "it the right size yourself!");
+#endif
+ DrawRGBA(target, target_w, target_h,
+ scaled->data, scaled->width, scaled->height,
+ rgba->alpha, area);
+ }
+ else
+ DrawRGBA(target, target_w, target_h,
+ rgba->data, rgba->width, rgba->height,
+ rgba->alpha, area);
+}
+
+/*! Create a new RrImage, which is linked to an image cache */
+RrImage* RrImageNew(RrImageCache *cache)
+{
+ RrImage *self;
+
+ g_assert(cache != NULL);
+
+ self = g_new0(RrImage, 1);
+ self->ref = 1;
+ self->cache = cache;
+ return self;
+}
+
+void RrImageRef(RrImage *self)
+{
+ ++self->ref;
+}
+
+void RrImageUnref(RrImage *self)
+{
+ if (self && --self->ref == 0) {
+#ifdef DEBUG
+ g_message("Refcount to 0, removing ALL pictures from the cache:\n "
+ "Image 0x%x\n", (guint)self);
+#endif
+ while (self->n_original > 0)
+ RemovePicture(self, &self->original, 0, &self->n_original);
+ while (self->n_resized > 0)
+ RemovePicture(self, &self->resized, 0, &self->n_resized);
+ g_free(self);
+ }
+}
+
+/*! Add a new picture with the given RGBA pixel data and dimensions into the
+ RrImage. This adds an "original" picture to the image.
+*/
+void RrImageAddPicture(RrImage *self, RrPixel32 *data, gint w, gint h)
+{
+ gint i;
+ RrImagePic *pic;
+
+ /* make sure we don't already have this size.. */
+ for (i = 0; i < self->n_original; ++i)
+ if (self->original[i]->width == w && self->original[i]->height == h) {
+#ifdef DEBUG
+ g_message("Found duplicate ORIGINAL image:\n "
+ "Image 0x%x, w %d h %d\n", (guint)self, w, h);
+#endif
+ return;
+ }
+
+ /* remove any resized pictures of this same size */
+ for (i = 0; i < self->n_resized; ++i)
+ if (self->resized[i]->width == w || self->resized[i]->height == h) {
+ RemovePicture(self, &self->resized, i, &self->n_resized);
+ break;
+ }
+
+ /* add the new picture */
+ pic = g_new(RrImagePic, 1);
+ RrImagePicInit(pic, w, h, g_memdup(data, w*h*sizeof(RrPixel32)));
+ AddPicture(self, &self->original, &self->n_original, pic);
+}
+
+/*! Remove the picture from the RrImage which has the given dimensions. This
+ removes an "original" picture from the image.
+*/
+void RrImageRemovePicture(RrImage *self, gint w, gint h)
+{
+ gint i;
+
+ /* remove any resized pictures of this same size */
+ for (i = 0; i < self->n_original; ++i)
+ if (self->original[i]->width == w && self->original[i]->height == h) {
+ RemovePicture(self, &self->original, i, &self->n_original);
+ break;
+ }
+}
+
+/*! Draw an RrImage texture into a target pixel buffer. If the RrImage does
+ not contain a picture of the appropriate size, then one of its "original"
+ pictures will be resized and used (and stored in the RrImage as a "resized"
+ picture).
+ */
+void RrImageDrawImage(RrPixel32 *target, RrTextureImage *img,
+ gint target_w, gint target_h,
+ RrRect *area)
+{
+ gint i, min_diff, min_i, min_aspect_diff, min_aspect_i;
+ RrImage *self;
+ RrImagePic *pic;
+ gboolean free_pic;
+
+ self = img->image;
+ pic = NULL;
+ free_pic = FALSE;
+
+ /* is there an original of this size? (only w or h has to be right cuz
+ we maintain aspect ratios) */
+ for (i = 0; i < self->n_original; ++i)
+ if (self->original[i]->width == area->width ||
+ self->original[i]->height == area->height)
+ {
+ pic = self->original[i];
+ break;
+ }
+
+ /* is there a resize of this size? */
+ for (i = 0; i < self->n_resized; ++i)
+ if (self->resized[i]->width == area->width ||
+ self->resized[i]->height == area->height)
+ {
+ gint j;
+ RrImagePic *saved;
+
+ /* save the selected one */
+ saved = self->resized[i];
+
+ /* shift all the others down */
+ for (j = i; j > 0; --j)
+ self->resized[j] = self->resized[j-1];
+
+ /* and move the selected one to the top of the list */
+ self->resized[0] = saved;
+
+ pic = self->resized[0];
+ break;
+ }
+
+ if (!pic) {
+ gdouble aspect;
+
+ /* find an original with a close size */
+ min_diff = min_aspect_diff = -1;
+ min_i = min_aspect_i = 0;
+ aspect = ((gdouble)area->width) / area->height;
+ for (i = 0; i < self->n_original; ++i) {
+ gint diff;
+ gint wdiff, hdiff;
+ gdouble myasp;
+
+ /* our size difference metric.. */
+ wdiff = self->original[i]->width - area->width;
+ hdiff = self->original[i]->height - area->height;
+ diff = (wdiff * wdiff) + (hdiff * hdiff);
+
+ /* find the smallest difference */
+ if (min_diff < 0 || diff < min_diff) {
+ min_diff = diff;
+ min_i = i;
+ }
+ /* and also find the smallest difference with the same aspect
+ ratio (and prefer this one) */
+ myasp = ((gdouble)self->original[i]->width) /
+ self->original[i]->height;
+ if (ABS(aspect - myasp) < 0.0000001 &&
+ (min_aspect_diff < 0 || diff < min_aspect_diff))
+ {
+ min_aspect_diff = diff;
+ min_aspect_i = i;
+ }
+ }
+
+ /* use the aspect ratio correct source if there is one */
+ if (min_aspect_i >= 0)
+ min_i = min_aspect_i;
+
+ /* resize the original to the given area */
+ pic = ResizeImage(self->original[min_i]->data,
+ self->original[min_i]->width,
+ self->original[min_i]->height,
+ area->width, area->height);
+
+ /* add the resized image to the image, as the first in the resized
+ list */
+ if (self->n_resized >= self->cache->max_resized_saved)
+ /* remove the last one (last used one) */
+ RemovePicture(self, &self->resized, self->n_resized - 1,
+ &self->n_resized);
+ if (self->cache->max_resized_saved)
+ /* add it to the top of the resized list */
+ AddPicture(self, &self->resized, &self->n_resized, pic);
+ else
+ free_pic = TRUE; /* don't leak mem! */
+ }
+
+ g_assert(pic != NULL);
+
+ DrawRGBA(target, target_w, target_h,
+ pic->data, pic->width, pic->height,
+ img->alpha, area);
+ if (free_pic)
+ RrImagePicFree(pic);
+}
diff --git a/render/image.h b/render/image.h
index 1c535960..b478daf9 100644
--- a/render/image.h
+++ b/render/image.h
@@ -22,8 +22,14 @@
#include "render.h"
#include "geom.h"
-void RrImageDraw(RrPixel32 *target, RrTextureRGBA *rgba,
- gint target_w, gint target_h,
- RrRect *area);
+/*! Initialize an RrImagePicture to the specified dimensions and pixel data */
+void RrImagePicInit(RrImagePic *pic, gint w, gint h, RrPixel32 *data);
+
+void RrImageDrawImage(RrPixel32 *target, RrTextureImage *img,
+ gint target_w, gint target_h,
+ RrRect *area);
+void RrImageDrawRGBA(RrPixel32 *target, RrTextureRGBA *rgba,
+ gint target_w, gint target_h,
+ RrRect *area);
#endif
diff --git a/render/imagecache.c b/render/imagecache.c
new file mode 100644
index 00000000..9c605f9d
--- /dev/null
+++ b/render/imagecache.c
@@ -0,0 +1,144 @@
+/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
+
+ imagecache.c for the Openbox window manager
+ Copyright (c) 2008 Dana Jansens
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ See the COPYING file for a copy of the GNU General Public License.
+*/
+
+#include "render.h"
+#include "imagecache.h"
+#include "image.h"
+
+static gboolean RrImagePicEqual(const RrImagePic *p1,
+ const RrImagePic *p2);
+
+RrImageCache* RrImageCacheNew(gint max_resized_saved)
+{
+ RrImageCache *self;
+
+ g_assert(max_resized_saved >= 0);
+
+ self = g_new(RrImageCache, 1);
+ self->ref = 1;
+ self->max_resized_saved = max_resized_saved;
+ self->table = g_hash_table_new((GHashFunc)RrImagePicHash,
+ (GEqualFunc)RrImagePicEqual);
+ return self;
+}
+
+void RrImageCacheRef(RrImageCache *self)
+{
+ ++self->ref;
+}
+
+void RrImageCacheUnref(RrImageCache *self)
+{
+ if (self && --self->ref == 0) {
+ g_assert(g_hash_table_size(self->table) == 0);
+ g_hash_table_unref(self->table);
+
+ g_free(self);
+ }
+}
+
+/*! Finds an image in the cache, if it is already in there */
+RrImage* RrImageCacheFind(RrImageCache *self,
+ RrPixel32 *data, gint w, gint h)
+{
+ RrImagePic pic;
+
+ RrImagePicInit(&pic, w, h, data);
+ return g_hash_table_lookup(self->table, &pic);
+}
+
+#define hashsize(n) ((RrPixel32)1<<(n))
+#define hashmask(n) (hashsize(n)-1)
+#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
+/* mix -- mix 3 32-bit values reversibly. */
+#define mix(a,b,c) \
+{ \
+ a -= c; a ^= rot(c, 4); c += b; \
+ b -= a; b ^= rot(a, 6); a += c; \
+ c -= b; c ^= rot(b, 8); b += a; \
+ a -= c; a ^= rot(c,16); c += b; \
+ b -= a; b ^= rot(a,19); a += c; \
+ c -= b; c ^= rot(b, 4); b += a; \
+}
+/* final -- final mixing of 3 32-bit values (a,b,c) into c */
+#define final(a,b,c) \
+{ \
+ c ^= b; c -= rot(b,14); \
+ a ^= c; a -= rot(c,11); \
+ b ^= a; b -= rot(a,25); \
+ c ^= b; c -= rot(b,16); \
+ a ^= c; a -= rot(c,4); \
+ b ^= a; b -= rot(a,14); \
+ c ^= b; c -= rot(b,24); \
+}
+
+/* This is a fast, reversable hash function called "lookup3", found here:
+ http://burtleburtle.net/bob/c/lookup3.c, by Bob Jenkins
+
+ This hashing algorithm is "reversible", that is, not cryptographically
+ secure at all. But we don't care about that, we just want something to
+ tell when images are the same or different relatively quickly.
+*/
+guint32 hashword(const guint32 *key, gint length, guint32 initval)
+{
+ guint32 a,b,c;
+
+ /* Set up the internal state */
+ a = b = c = 0xdeadbeef + (((guint32)length)<<2) + initval;
+
+ /* handle most of the key */
+ while (length > 3)
+ {
+ a += key[0];
+ b += key[1];
+ c += key[2];
+ mix(a,b,c);
+ length -= 3;
+ key += 3;
+ }
+
+ /* handle the last 3 guint32's */
+ switch(length) /* all the case statements fall through */
+ {
+ case 3: c+=key[2];
+ case 2: b+=key[1];
+ case 1: a+=key[0];
+ final(a,b,c);
+ case 0: /* case 0: nothing left to add */
+ break;
+ }
+ /* report the result */
+ return c;
+}
+
+/*! This is some arbitrary initial value for the hashing function. It's
+ constant so that you get the same result from the same data each time.
+*/
+#define HASH_INITVAL 0xf00d
+
+guint RrImagePicHash(const RrImagePic *p)
+{
+ return hashword(p->data, p->width * p->height, HASH_INITVAL);
+}
+
+static gboolean RrImagePicEqual(const RrImagePic *p1,
+ const RrImagePic *p2)
+{
+ return p1->width == p2->width && p1->height == p2->height &&
+ p1->sum == p2->sum;
+}
diff --git a/render/imagecache.h b/render/imagecache.h
new file mode 100644
index 00000000..4ad2deae
--- /dev/null
+++ b/render/imagecache.h
@@ -0,0 +1,51 @@
+/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
+
+ imagecache.h for the Openbox window manager
+ Copyright (c) 2008 Dana Jansens
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ See the COPYING file for a copy of the GNU General Public License.
+*/
+
+#ifndef __imagecache_h
+#define __imagecache_h
+
+#include <glib.h>
+
+struct _RrImagePic;
+
+guint RrImagePicHash(const struct _RrImagePic *p);
+
+/*! Create a new image cache. An image cache is basically a hash table to look
+ up RrImages. Each RrImage in the cache may contain one or more Pictures,
+ that is one or more actual copies of image data at various sizes. For eg,
+ for a window, all of its various icons are loaded into the same RrImage.
+ When an RrImage is drawn and a picture inside it needs to be resized, that
+ is also saved within the RrImage.
+
+ For each picture that an RrImage has, the picture is hashed and that is used
+ as a key to find the RrImage. So, given any picture in any RrImage in the
+ cache, if you hash it, you will find the RrImage.
+*/
+struct _RrImageCache {
+ gint ref;
+ /*! When an original picture is resized for an RrImage, the resized picture
+ is saved in the RrImage. This specifies how many pictures should be
+ saved at a time. When this is exceeded, the least recently used
+ "resized" picture is deleted.
+ */
+ gint max_resized_saved;
+
+ GHashTable *table;
+};
+
+#endif
diff --git a/render/obrender-3.0.pc.in b/render/obrender-4.0.pc.in
index ebb17ef3..9c310569 100644
--- a/render/obrender-3.0.pc.in
+++ b/render/obrender-4.0.pc.in
@@ -9,6 +9,6 @@ xlibs=@X_LIBS@
Name: ObRender
Description: Openbox Render Library
Version: @VERSION@
-Requires: obparser-3.0 glib-2.0 xft pangoxft
+Requires: obparser-4.0 glib-2.0 xft pangoxft
Libs: -L${libdir} -lobrender ${xlibs}
Cflags: -I${includedir}/openbox/@OB_VERSION@ ${xcflags}
diff --git a/render/render.c b/render/render.c
index 2813dda0..fd442d26 100644
--- a/render/render.c
+++ b/render/render.c
@@ -130,12 +130,40 @@ Pixmap RrPaintPixmap(RrAppearance *a, gint w, gint h)
}
RrPixmapMaskDraw(a->pixmap, &a->texture[i].data.mask, &tarea);
break;
+ case RR_TEXTURE_IMAGE:
+ g_assert(!transferred);
+ {
+ RrRect narea = tarea;
+ RrTextureImage *img = &a->texture[i].data.image;
+ if (img->twidth)
+ narea.width = MIN(tarea.width, img->twidth);
+ if (img->theight)
+ narea.height = MIN(tarea.height, img->theight);
+ narea.x += img->tx;
+ narea.y += img->ty;
+ RrImageDrawImage(a->surface.pixel_data,
+ &a->texture[i].data.image,
+ a->w, a->h,
+ &narea);
+ }
+ force_transfer = 1;
+ break;
case RR_TEXTURE_RGBA:
g_assert(!transferred);
- RrImageDraw(a->surface.pixel_data,
- &a->texture[i].data.rgba,
- a->w, a->h,
- &tarea);
+ {
+ RrRect narea = tarea;
+ RrTextureRGBA *rgb = &a->texture[i].data.rgba;
+ if (rgb->twidth)
+ narea.width = MIN(tarea.width, rgb->twidth);
+ if (rgb->theight)
+ narea.height = MIN(tarea.height, rgb->theight);
+ narea.x += rgb->tx;
+ narea.y += rgb->ty;
+ RrImageDrawRGBA(a->surface.pixel_data,
+ &a->texture[i].data.rgba,
+ a->w, a->h,
+ &narea);
+ }
force_transfer = 1;
break;
}
@@ -192,11 +220,15 @@ void RrAppearanceAddTextures(RrAppearance *a, gint numtex)
if (numtex) a->texture = g_new0(RrTexture, numtex);
}
+void RrAppearanceClearTextures(RrAppearance *a)
+{
+ memset(a->texture, 0, a->textures * sizeof(RrTexture));
+}
+
RrAppearance *RrAppearanceCopy(RrAppearance *orig)
{
RrSurface *spo, *spc;
RrAppearance *copy = g_new(RrAppearance, 1);
- gint i;
copy->inst = orig->inst;
@@ -272,10 +304,6 @@ RrAppearance *RrAppearanceCopy(RrAppearance *orig)
copy->textures = orig->textures;
copy->texture = g_memdup(orig->texture,
orig->textures * sizeof(RrTexture));
- for (i = 0; i < copy->textures; ++i)
- if (copy->texture[i].type == RR_TEXTURE_RGBA) {
- copy->texture[i].data.rgba.cache = NULL;
- }
copy->pixmap = None;
copy->xftdraw = NULL;
copy->w = copy->h = 0;
@@ -284,17 +312,10 @@ RrAppearance *RrAppearanceCopy(RrAppearance *orig)
void RrAppearanceFree(RrAppearance *a)
{
- gint i;
-
if (a) {
RrSurface *p;
if (a->pixmap != None) XFreePixmap(RrDisplay(a->inst), a->pixmap);
if (a->xftdraw != NULL) XftDrawDestroy(a->xftdraw);
- for (i = 0; i < a->textures; ++i)
- if (a->texture[i].type == RR_TEXTURE_RGBA) {
- g_free(a->texture[i].data.rgba.cache);
- a->texture[i].data.rgba.cache = NULL;
- }
if (a->textures)
g_free(a->texture);
p = &a->surface;
@@ -395,6 +416,9 @@ gint RrMinWidth(RrAppearance *a)
case RR_TEXTURE_RGBA:
w += MAX(w, a->texture[i].data.rgba.width);
break;
+ case RR_TEXTURE_IMAGE:
+ /* images resize so they don't contribute anything to the min */
+ break;
case RR_TEXTURE_LINE_ART:
w = MAX(w, MAX(a->texture[i].data.lineart.x1 - l - r,
a->texture[i].data.lineart.x2 - l - r));
@@ -447,6 +471,9 @@ gint RrMinHeight(RrAppearance *a)
case RR_TEXTURE_RGBA:
h += MAX(h, a->texture[i].data.rgba.height);
break;
+ case RR_TEXTURE_IMAGE:
+ /* images resize so they don't contribute anything to the min */
+ break;
case RR_TEXTURE_LINE_ART:
h = MAX(h, MAX(a->texture[i].data.lineart.y1 - t - b,
a->texture[i].data.lineart.y2 - t - b));
diff --git a/render/render.h b/render/render.h
index d9438edc..706843e3 100644
--- a/render/render.h
+++ b/render/render.h
@@ -22,7 +22,7 @@
#define __render_h
#include "geom.h"
-#include "version.h"
+#include "render/version.h"
#include <X11/Xlib.h> /* some platforms dont include this as needed for Xft */
#include <pango/pangoxft.h>
@@ -37,11 +37,15 @@ typedef struct _RrFont RrFont;
typedef struct _RrTexture RrTexture;
typedef struct _RrTextureMask RrTextureMask;
typedef struct _RrTextureRGBA RrTextureRGBA;
+typedef struct _RrTextureImage RrTextureImage;
typedef struct _RrTextureText RrTextureText;
typedef struct _RrTextureLineArt RrTextureLineArt;
typedef struct _RrPixmapMask RrPixmapMask;
typedef struct _RrInstance RrInstance;
typedef struct _RrColor RrColor;
+typedef struct _RrImage RrImage;
+typedef struct _RrImagePic RrImagePic;
+typedef struct _RrImageCache RrImageCache;
typedef guint32 RrPixel32;
typedef guint16 RrPixel16;
@@ -76,7 +80,8 @@ typedef enum {
RR_TEXTURE_MASK,
RR_TEXTURE_TEXT,
RR_TEXTURE_LINE_ART,
- RR_TEXTURE_RGBA
+ RR_TEXTURE_RGBA,
+ RR_TEXTURE_IMAGE
} RrTextureType;
typedef enum {
@@ -163,10 +168,23 @@ struct _RrTextureRGBA {
gint height;
gint alpha;
RrPixel32 *data;
-/* cached scaled so we don't have to scale often */
- gint cwidth;
- gint cheight;
- RrPixel32 *cache;
+ /* size and position to draw at (if these are zero, then it will be
+ drawn to fill the entire texture */
+ gint tx;
+ gint ty;
+ gint twidth;
+ gint theight;
+};
+
+struct _RrTextureImage {
+ RrImage *image;
+ gint alpha;
+ /* size and position to draw at (if these are zero, then it will be
+ drawn to fill the entire texture */
+ gint tx;
+ gint ty;
+ gint twidth;
+ gint theight;
};
struct _RrTextureLineArt {
@@ -179,12 +197,15 @@ struct _RrTextureLineArt {
union _RrTextureData {
RrTextureRGBA rgba;
+ RrTextureImage image;
RrTextureText text;
RrTextureMask mask;
RrTextureLineArt lineart;
};
struct _RrTexture {
+ /* If changing the type of a texture, you should DEFINITELY call
+ RrAppearanceClearTextures() first! */
RrTextureType type;
RrTextureData data;
};
@@ -202,6 +223,35 @@ struct _RrAppearance {
gint w, h;
};
+/*! Holds a RGBA image picture */
+struct _RrImagePic {
+ gint width, height;
+ RrPixel32 *data;
+ /* The sum of all the pixels. This is used to compare pictures if their
+ hashes match. */
+ gint sum;
+};
+
+/*! An RrImage is a sort of meta-image. It can contain multiple versions of
+ an image at different sizes, which may or may not be completely different
+ pictures */
+struct _RrImage {
+ gint ref;
+ RrImageCache *cache;
+
+ /*! An array of "originals", that is of RrPictures that have been added
+ to the image in various sizes, and that have not been resized. These
+ are explicitly added to the RrImage. */
+ RrImagePic **original;
+ gint n_original;
+ /*! An array of "resized" pictures. When an "original" RrPicture
+ needs to be resized for drawing, it is saved in here so that it doesn't
+ need to be resized again. These are automatically added to the
+ RrImage. */
+ RrImagePic **resized;
+ gint n_resized;
+};
+
/* these are the same on all endian machines because it seems to be dependant
on the endianness of the gfx card, not the cpu. */
#define RrDefaultAlphaOffset 24
@@ -248,6 +298,8 @@ RrAppearance *RrAppearanceCopy (RrAppearance *a);
void RrAppearanceFree (RrAppearance *a);
void RrAppearanceRemoveTextures(RrAppearance *a);
void RrAppearanceAddTextures(RrAppearance *a, gint numtex);
+/*! Always call this when changing the type of a texture in an appearance */
+void RrAppearanceClearTextures(RrAppearance *a);
RrFont *RrFontOpen (const RrInstance *inst, const gchar *name,
gint size, RrFontWeight weight, RrFontSlant slant);
@@ -275,6 +327,24 @@ gboolean RrPixmapToRGBA(const RrInstance *inst,
Pixmap pmap, Pixmap mask,
gint *w, gint *h, RrPixel32 **data);
+/*! Create a new image cache for RrImages.
+ @param max_resized_saved The number of resized copies of an image to save
+*/
+RrImageCache* RrImageCacheNew(gint max_resized_saved);
+void RrImageCacheRef(RrImageCache *self);
+void RrImageCacheUnref(RrImageCache *self);
+
+/*! Finds an image in the cache, if it is already in there */
+RrImage* RrImageCacheFind(RrImageCache *self,
+ RrPixel32 *data, gint w, gint h);
+
+RrImage* RrImageNew(RrImageCache *cache);
+void RrImageRef(RrImage *im);
+void RrImageUnref(RrImage *im);
+
+void RrImageAddPicture(RrImage *im, RrPixel32 *data, gint w, gint h);
+void RrImageRemovePicture(RrImage *im, gint w, gint h);
+
G_END_DECLS
#endif /*__render_h*/
diff --git a/render/theme.c b/render/theme.c
index b1b15ff2..ec12dafb 100644
--- a/render/theme.c
+++ b/render/theme.c
@@ -23,7 +23,7 @@
#include "mask.h"
#include "theme.h"
#include "icon.h"
-#include "parser/parse.h"
+#include "obt/paths.h"
#include <X11/Xlib.h>
#include <X11/Xresource.h>
@@ -543,10 +543,23 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
theme->menu_bullet_mask = RrPixmapMaskNew(inst, 4, 7, (gchar*)data);
}
+ /* up and down arrows */
+ {
+ guchar data[] = { 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00 };
+ theme->down_arrow_mask = RrPixmapMaskNew(inst, 9, 4, (gchar*)data);
+ }
+ {
+ guchar data[] = { 0x10, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xfe, 0x00 };
+ theme->up_arrow_mask = RrPixmapMaskNew(inst, 9, 4, (gchar*)data);
+ }
+
/* setup the default window icon */
theme->def_win_icon = read_c_image(OB_DEFAULT_ICON_WIDTH,
OB_DEFAULT_ICON_HEIGHT,
OB_DEFAULT_ICON_pixel_data);
+ theme->def_win_icon_w = OB_DEFAULT_ICON_WIDTH;
+ theme->def_win_icon_h = OB_DEFAULT_ICON_HEIGHT;
+
/* read the decoration textures */
if (!read_appearance(db, inst,
@@ -1451,6 +1464,8 @@ void RrThemeFree(RrTheme *theme)
RrPixmapMaskFree(theme->close_hover_mask);
RrPixmapMaskFree(theme->close_pressed_mask);
RrPixmapMaskFree(theme->menu_bullet_mask);
+ RrPixmapMaskFree(theme->down_arrow_mask);
+ RrPixmapMaskFree(theme->up_arrow_mask);
RrFontClose(theme->win_font_focused);
RrFontClose(theme->win_font_unfocused);
@@ -1561,6 +1576,10 @@ static XrmDatabase loaddb(const gchar *name, gchar **path)
*path = g_path_get_dirname(s);
g_free(s);
} else {
+ ObtPaths *p;
+
+ p = obt_paths_new();
+
/* XXX backwards compatibility, remove me sometime later */
s = g_build_filename(g_get_home_dir(), ".themes", name,
"openbox-3", "themerc", NULL);
@@ -1568,8 +1587,7 @@ static XrmDatabase loaddb(const gchar *name, gchar **path)
*path = g_path_get_dirname(s);
g_free(s);
- for (it = parse_xdg_data_dir_paths(); !db && it;
- it = g_slist_next(it))
+ for (it = obt_paths_data_dirs(p); !db && it; it = g_slist_next(it))
{
s = g_build_filename(it->data, "themes", name,
"openbox-3", "themerc", NULL);
@@ -1577,6 +1595,8 @@ static XrmDatabase loaddb(const gchar *name, gchar **path)
*path = g_path_get_dirname(s);
g_free(s);
}
+
+ obt_paths_unref(p);
}
if (db == NULL) {
diff --git a/render/theme.h b/render/theme.h
index 3f87ce93..9b2d663e 100644
--- a/render/theme.h
+++ b/render/theme.h
@@ -107,7 +107,9 @@ struct _RrTheme {
gchar menu_text_disabled_selected_shadow_alpha;
/* style settings - pics */
- RrPixel32 *def_win_icon; /* 48x48 RGBA */
+ RrPixel32 *def_win_icon; /* RGBA */
+ gint def_win_icon_w;
+ gint def_win_icon_h;
/* style settings - masks */
RrPixmapMask *max_mask;
@@ -145,6 +147,9 @@ struct _RrTheme {
RrPixmapMask *menu_toggle_mask; /* menu boolean */
#endif
+ RrPixmapMask *down_arrow_mask;
+ RrPixmapMask *up_arrow_mask;
+
/* global appearances */
RrAppearance *a_disabled_focused_max;
RrAppearance *a_disabled_unfocused_max;
diff --git a/render/version.h.in b/render/version.h.in
new file mode 100644
index 00000000..0ff30b57
--- /dev/null
+++ b/render/version.h.in
@@ -0,0 +1,15 @@
+#ifndef rr__version_h
+#define rr__version_h
+
+#define RR_MAJOR_VERSION @RR_MAJOR_VERSION@
+#define RR_MINOR_VERSION @RR_MINOR_VERSION@
+#define RR_MICRO_VERSION @RR_MICRO_VERSION@
+#define RR_VERSION RR_MAJOR_VERSION.RR_MINOR_VERSION.RR_MICRO_VERSION
+
+#define RR_CHECK_VERSION(major,minor,micro) \
+ (RR_MAJOR_VERSION > (major) || \
+ (RR_MAJOR_VERSION == (major) && RR_MINOR_VERSION > (minor)) || \
+ (RR_MAJOR_VERSION == (major) && RR_MINOR_VERSION == (minor) && \
+ RR_MICRO_VERSION >= (micro)))
+
+#endif