]>
git.saurik.com Git - wxWidgets.git/blob - src/gdk_imlib/cache.c
3 #include "gdk_imlib_private.h"
5 /* uncomment this to compile imlib's cahce with pixmap accounting output */
6 /*#define PIXMAP_ACCOUNTING */
9 gdirty_pixmaps(GdkImlibImage
* im
)
11 struct pixmap_cache
*ptr
;
13 ptr
= id
->cache
.pixmap
;
16 if ((ptr
->im
== im
) && ((!ptr
->file
) || (!strcmp(im
->filename
, ptr
->file
))))
23 gdirty_images(GdkImlibImage
* im
)
25 struct image_cache
*ptr
;
27 ptr
= id
->cache
.image
;
30 if ((!strcmp(im
->filename
, ptr
->file
)) && (im
== ptr
->im
))
40 gfind_pixmap(GdkImlibImage
* im
, int width
, int height
, GdkPixmap
** pmap
, GdkBitmap
** mask
)
42 struct pixmap_cache
*ptr
;
44 ptr
= id
->cache
.pixmap
;
47 if ((ptr
->im
== im
) && (ptr
->width
== width
) && (ptr
->height
== height
) &&
48 ((!ptr
->file
) || (!strcmp(im
->filename
, ptr
->file
))) &&
56 id
->cache
.num_pixmap
++;
58 id
->cache
.used_pixmap
-= width
* height
* id
->x
.depth
;
60 id
->cache
.used_pixmap
-= width
* height
;
61 if (id
->cache
.used_pixmap
< 0)
63 id
->cache
.used_pixmap
= 0;
64 fprintf(stderr
, "IMLIB: uhoh.. caching problems.... meep meep\n");
69 ptr
->prev
->next
= ptr
->next
;
71 ptr
->next
->prev
= ptr
->prev
;
72 ptr
->next
= id
->cache
.pixmap
;
73 ptr
->next
->prev
= ptr
;
74 id
->cache
.pixmap
= ptr
;
78 *mask
= ptr
->shape_mask
;
88 gfind_image(char *file
)
90 struct image_cache
*ptr
;
92 ptr
= id
->cache
.image
;
95 if ((!strcmp(file
, ptr
->file
)) && (!ptr
->dirty
))
102 id
->cache
.num_image
++;
103 id
->cache
.used_image
-= ptr
->im
->rgb_width
* ptr
->im
->rgb_height
* 3;
104 if (id
->cache
.used_image
< 0)
106 id
->cache
.used_image
= 0;
107 fprintf(stderr
, "IMLIB: uhoh.. caching problems.... meep meep\n");
112 ptr
->prev
->next
= ptr
->next
;
114 ptr
->next
->prev
= ptr
->prev
;
115 ptr
->next
= id
->cache
.image
;
116 ptr
->next
->prev
= ptr
;
117 id
->cache
.image
= ptr
;
128 gfree_pixmappmap(GdkPixmap
* pmap
)
130 struct pixmap_cache
*ptr
;
132 ptr
= id
->cache
.pixmap
;
135 if ((ptr
->pmap
== pmap
) || (ptr
->shape_mask
== pmap
))
137 if (ptr
->shape_mask
== pmap
)
142 if (ptr
->refnum
== 0)
144 id
->cache
.num_pixmap
--;
146 id
->cache
.used_pixmap
+= ptr
->width
* ptr
->height
* id
->x
.depth
;
148 id
->cache
.used_pixmap
+= ptr
->width
* ptr
->height
;
155 gdk_pixmap_unref(pmap
);
159 gfree_image(GdkImlibImage
* im
)
161 struct image_cache
*ptr
;
163 ptr
= id
->cache
.image
;
173 id
->cache
.num_image
--;
174 id
->cache
.used_image
+= ptr
->im
->rgb_width
* ptr
->im
->rgb_height
* 3;
185 gflush_image(GdkImlibImage
* im
)
192 gadd_image(GdkImlibImage
* im
, char *file
)
194 struct image_cache
*ptr
;
195 struct image_cache
*n
;
197 if ((!im
) || (!file
))
199 ptr
= id
->cache
.image
;
200 n
= malloc(sizeof(struct image_cache
));
206 n
->file
= malloc(strlen(file
) + 1);
212 strcpy(n
->file
, file
);
219 id
->cache
.num_image
++;
223 gadd_pixmap(GdkImlibImage
* im
, int width
, int height
, XImage
* xim
, XImage
* sxim
)
225 struct pixmap_cache
*ptr
;
226 struct pixmap_cache
*n
;
230 ptr
= id
->cache
.pixmap
;
231 n
= malloc(sizeof(struct pixmap_cache
));
240 n
->file
= malloc(strlen(im
->filename
) + 1);
242 strcpy(n
->file
, im
->filename
);
250 n
->pmap
= im
->pixmap
;
251 n
->shape_mask
= im
->shape_mask
;
256 id
->cache
.pixmap
= n
;
257 id
->cache
.num_pixmap
++;
264 struct image_cache
*ptr
= NULL
;
265 struct image_cache
*pptr
= NULL
;
266 struct image_cache
*last
= NULL
;
269 /* find the back of the list */
270 ptr
= id
->cache
.image
;
278 /* remove all images that are tagged non-cachable, and have 0 */
279 /* references , even if the cache has spare room. */
288 id
->cache
.used_image
-= ptr
->im
->rgb_width
* ptr
->im
->rgb_height
* 3;
289 gnullify_image(ptr
->im
);
293 ptr
->prev
->next
= ptr
->next
;
295 id
->cache
.image
= ptr
->next
;
297 ptr
->next
->prev
= ptr
->prev
;
309 ptr
= id
->cache
.image
;
319 /* find the back of the list */
320 ptr
= id
->cache
.image
;
329 /* while the amount of data in the cache is greater than the set */
330 /* amount, delete the last entry (last used) from the unreferenced */
331 /* cached 24-bit images */
332 while (id
->cache
.used_image
> id
->cache
.size_image
)
340 id
->cache
.used_image
-= ptr
->im
->rgb_width
* ptr
->im
->rgb_height
* 3;
341 gnullify_image(ptr
->im
);
343 ptr
->prev
->next
= ptr
->next
;
345 id
->cache
.image
= ptr
->next
;
347 ptr
->next
->prev
= ptr
->prev
;
360 ptr
= id
->cache
.image
;
374 struct pixmap_cache
*ptr
;
375 struct pixmap_cache
*last
;
378 #ifdef PIXMAP_ACCOUNTING
379 int total
, total2
, num
, num2
;
381 printf("--------- Pixmap cashe zise %i / %i with %i pixmaps referenced\n",
382 id
->cache
.used_pixmap
, id
->cache
.size_pixmap
,
383 id
->cache
.num_pixmap
);
384 ptr
= id
->cache
.pixmap
;
391 printf("Pmap for file %s REFNUM %3i SIZE %4ix%4i PMAP %8x MASK %8x\n",
392 ptr
->file
, ptr
->refnum
, ptr
->width
, ptr
->height
, ptr
->pmap
,
396 total
+= (ptr
->width
* ptr
->height
* id
->x
.depth
);
398 total
+= (ptr
->width
* ptr
->height
);
403 total2
+= (ptr
->width
* ptr
->height
* id
->x
.depth
);
405 total2
+= (ptr
->width
* ptr
->height
);
410 printf("Accounting Data:\n");
411 printf("*** total pixmap's in cache %i with %i pixmaps\n",
413 printf("*** total unreffed pixmap's in cache %i with %i pixmaps\n\n",
416 /* find the back of the list */
417 ptr
= id
->cache
.pixmap
;
426 /* while the amount of data in the cache is greater than the set */
427 /* amount, delete the last entry (last used) from the unreferenced */
429 while (id
->cache
.used_pixmap
> id
->cache
.size_pixmap
)
438 id
->cache
.used_pixmap
-= ptr
->width
* ptr
->height
* id
->x
.depth
;
440 id
->cache
.used_pixmap
-= ptr
->width
* ptr
->height
;
442 gdk_pixmap_unref(ptr
->pmap
);
444 gdk_pixmap_unref(ptr
->shape_mask
);
446 XDestroyImage(ptr
->xim
);
448 XDestroyImage(ptr
->sxim
);
450 ptr
->prev
->next
= ptr
->next
;
452 id
->cache
.pixmap
= ptr
->next
;
454 ptr
->next
->prev
= ptr
->prev
;
467 ptr
= id
->cache
.pixmap
;
483 gnullify_image(GdkImlibImage
* im
)
490 free(im
->alpha_data
);
492 gfree_pixmappmap(im
->pixmap
);