summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cf96255)
raw | patch | inline | side by side (parent: cf96255)
author | buliabyak <buliabyak@users.sourceforge.net> | |
Tue, 17 Oct 2006 04:33:53 +0000 (04:33 +0000) | ||
committer | buliabyak <buliabyak@users.sourceforge.net> | |
Tue, 17 Oct 2006 04:33:53 +0000 (04:33 +0000) |
index 84ed621dbebe904b54a8b7d60a62faee29df16a4..7b3e5bc94b2f11d042044dd5d473fced36f74ace 100644 (file)
arena->root = NRArenaGroup::create(arena->arena);
nr_arena_group_set_transparent (NR_ARENA_GROUP (arena->root), TRUE);
-#ifdef arena_item_tile_cache
- arena->root->skipCaching=true;
-#endif
-
arena->active = NULL;
nr_active_object_add_listener ((NRActiveObject *) arena->arena, (NRObjectEventVector *) &carenaev, sizeof (carenaev), arena);
@@ -186,10 +182,6 @@ sp_canvas_arena_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned i
}
}
-#ifdef arena_item_tile_cache
-extern void age_cache(void);
-#endif
-
static void
sp_canvas_arena_render (SPCanvasItem *item, SPCanvasBuf *buf)
{
sp_canvas_prepare_buffer(buf);
-#ifdef arena_item_tile_cache
- age_cache();
-#endif
bw = buf->rect.x1 - buf->rect.x0;
bh = buf->rect.y1 - buf->rect.y0;
if ((bw < 1) || (bh < 1)) return;
index 8df0453327492b04ad65f4bef1d711ead3198542..b1319822da3ae35dad08cead32bc9034cf58f399 100644 (file)
group->last = NULL;
group->style = NULL;
nr_matrix_set_identity (&group->child_transform);
-
-#ifdef arena_item_tile_cache
- group->skipCaching=true;
-#endif
-
}
static NRArenaItem *
index 12d25249665482f0bf8281a9e61a45b96a6b0cd5..d4e237104ea0c66acd5283cb9470556f3c8ff44b 100644 (file)
#include "nr-filter.h"
#include "libnr/nr-rect.h"
#include "nr-arena-group.h"
+#include "prefs-utils.h"
namespace GC = Inkscape::GC;
static void nr_arena_item_init (NRArenaItem *item);
static void nr_arena_item_private_finalize (NRObject *object);
-#ifdef arena_item_tile_cache
-bool insert_cache (NRArenaItem *owner, int th, int tv, NRPixBlock *ipb,
- NRPixBlock *mpb, double activity, double duration);
-void remove_caches (NRArenaItem *owner);
-bool test_cache (NRArenaItem *owner, int th, int tv, NRPixBlock & ipb,
- NRPixBlock &mpb, bool &hasMask);
-#endif
-
static NRObjectClass *parent_class;
NRType
item->opacity = 255;
item->render_opacity = FALSE;
-#ifdef arena_item_tile_cache
- item->activity = 0.0;
- item->skipCaching = false;
-#endif
-
item->transform = NULL;
item->clip = NULL;
item->mask = NULL;
{
NRArenaItem *item = static_cast < NRArenaItem * >(object);
-#ifdef arena_item_tile_cache
- remove_caches (item);
-#endif
-
item->px = NULL;
item->transform = NULL;
if (!(item->state & NR_ARENA_ITEM_STATE_IMAGE) && (item->px)) {
item->px = NULL;
}
-#ifdef arena_item_tile_cache
- remove_caches (item);
-#endif
/* Set up local gc */
childgc = *gc;
area->x1, area->y1);
#endif
-#ifdef arena_item_tile_cache
- item->activity *= 0.5;
-#endif
-
/* If we are outside bbox just return successfully */
if (!item->visible)
return item->state | NR_ARENA_ITEM_STATE_RENDER;
}
NRPixBlock *dpb = pb;
- bool canCache = false;
-#ifdef arena_item_tile_cache
- bool checkCache = false;
- int tile_h = 0, tile_v = 0;
-#endif
+
/* Setup cache if we can */
if ((!(flags & NR_ARENA_ITEM_RENDER_NO_CACHE)) &&
(carea.x0 <= item->bbox.x0) && (carea.y0 <= item->bbox.y0) &&
dpb = &cpb;
// Set nocache flag for downstream rendering
flags |= NR_ARENA_ITEM_RENDER_NO_CACHE;
- } else {
-#ifdef arena_item_tile_cache
- if (item->skipCaching) {
- } else {
- int
- tl = area->x0 & (~127);
- int
- tt = area->y0 & (~127);
- if (area->x1 <= tl + 128 && area->y1 <= tt + 128) {
- checkCache = true;
- tile_h = tl / 128;
- tile_v = tt / 128;
- int
- surf = (area->x1 - area->x0) * (area->y1 - area->y0);
- if (surf >= 4096) {
- canCache = true;
- carea.x0 = tl;
- carea.y0 = tt;
- carea.x1 = tl + 128;
- carea.y1 = tt + 128;
- }
- }
- }
-#endif
- }
+ }
-#ifdef arena_item_tile_cache
- item->activity += 1.0;
-#endif
-
-#ifdef arena_item_tile_cache
- if (checkCache) {
- NRPixBlock
- ipb,
- mpb;
- bool
- hasMask;
- if (test_cache (item, tile_h, tile_v, ipb, mpb, hasMask)) {
- // youpi! c'etait deja cache
- if (hasMask) {
- nr_blit_pixblock_pixblock_mask (dpb, &ipb, &mpb);
- } else if (((item->opacity != 255) && !item->render_opacity)) {
- nr_blit_pixblock_pixblock_alpha (dpb, &ipb, item->opacity);
- } else {
- nr_blit_pixblock_pixblock (pb, &ipb);
- }
- pb->empty = FALSE;
- return item->state | NR_ARENA_ITEM_STATE_RENDER;
- }
- }
-#endif
- if (canCache) {
-#ifdef arena_item_tile_cache
- // nota: exclusif de dpb != pb, donc pas de cas particulier a la fin
-
- // struct timeval start_time,end_time;
- // gettimeofday(&start_time,NULL);
- GTimeVal start_time, end_time;
- g_get_current_time (&start_time);
- int duration = 0;
+ /* Determine, whether we need temporary buffer */
+ if (item->clip || item->mask
+ || ((item->opacity != 255) && !item->render_opacity && !outline)
+ || (item->filter && !outline) || item->background_new
+ || (item->parent && item->parent->background_pb)) {
/* Setup and render item buffer */
NRPixBlock ipb;
- nr_pixblock_setup_fast (&ipb, NR_PIXBLOCK_MODE_R8G8B8A8P, carea.x0,
- carea.y0, carea.x1, carea.y1, TRUE);
+ nr_pixblock_setup_fast (&ipb, NR_PIXBLOCK_MODE_R8G8B8A8P,
+ carea.x0, carea.y0, carea.x1, carea.y1,
+ TRUE);
- // if memory allocation failed, abort render
+ // if memory allocation failed, abort render
if (ipb.data.px == NULL) {
nr_pixblock_release (&ipb);
return (item->state);
}
+ /* If background access is used, save the pixblock address.
+ * This address is set to NULL at the end of this block */
+ if (item->background_new
+ || (item->parent && item->parent->background_pb)) {
+ item->background_pb = &ipb;
+ }
ipb.visible_area = pb->visible_area;
- {
- unsigned int state = NR_ARENA_ITEM_VIRTUAL (item, render) (item, &carea, &ipb, flags);
- if (state & NR_ARENA_ITEM_STATE_INVALID) {
- /* Clean up and return error */
- nr_pixblock_release (&ipb);
- if (dpb != pb)
- nr_pixblock_release (dpb);
- item->state |= NR_ARENA_ITEM_STATE_INVALID;
- return item->state;
- }
+ unsigned int state = NR_ARENA_ITEM_VIRTUAL (item, render) (item, &carea, &ipb, flags);
+ if (state & NR_ARENA_ITEM_STATE_INVALID) {
+ /* Clean up and return error */
+ nr_pixblock_release (&ipb);
+ if (dpb != pb)
+ nr_pixblock_release (dpb);
+ item->state |= NR_ARENA_ITEM_STATE_INVALID;
+ return item->state;
}
ipb.empty = FALSE;
+ /* Run filtering, if a filter is set for this object */
+ if (item->filter && !outline) {
+ item->filter->render (item, &ipb);
+ }
+
if (item->clip || item->mask) {
/* Setup mask pixblock */
NRPixBlock mpb;
- nr_pixblock_setup_fast (&mpb, NR_PIXBLOCK_MODE_A8, carea.x0, carea.y0, carea.x1, carea.y1, TRUE);
+ nr_pixblock_setup_fast (&mpb, NR_PIXBLOCK_MODE_A8, carea.x0,
+ carea.y0, carea.x1, carea.y1, TRUE);
if (mpb.data.px != NULL) { // if memory allocation was successful
- mpb.visible_area = pb->visible_area;
- /* Do clip if needed */
- if (item->clip) {
- unsigned int state = nr_arena_item_invoke_clip (item->clip, &carea, &mpb);
- if (state & NR_ARENA_ITEM_STATE_INVALID) {
- /* Clean up and return error */
- nr_pixblock_release (&mpb);
- nr_pixblock_release (&ipb);
- if (dpb != pb)
- nr_pixblock_release (dpb);
- item->state |= NR_ARENA_ITEM_STATE_INVALID;
- return item->state;
- }
- mpb.empty = FALSE;
- }
- /* Do mask if needed */
- if (item->mask) {
- NRPixBlock tpb;
- /* Set up yet another temporary pixblock */
- nr_pixblock_setup_fast (&tpb, NR_PIXBLOCK_MODE_R8G8B8A8N,
- carea.x0, carea.y0, carea.x1,
- carea.y1, TRUE);
-
- if (tpb.data.px != NULL) { // if memory allocation was successful
-
- tpb.visible_area = pb->visible_area;
- unsigned int state = NR_ARENA_ITEM_VIRTUAL (item->mask, render) (item->mask, &carea, &tpb, flags);
- if (state & NR_ARENA_ITEM_STATE_INVALID) {
- /* Clean up and return error */
- nr_pixblock_release (&tpb);
- nr_pixblock_release (&mpb);
- nr_pixblock_release (&ipb);
- if (dpb != pb)
- nr_pixblock_release (dpb);
- item->state |= NR_ARENA_ITEM_STATE_INVALID;
- return item->state;
- }
- /* Composite with clip */
- if (item->clip) {
- int x, y;
- for (y = carea.y0; y < carea.y1; y++) {
- unsigned char *s, *d;
- s = NR_PIXBLOCK_PX (&tpb) + (y - carea.y0) * tpb.rs;
- d = NR_PIXBLOCK_PX (&mpb) + (y - carea.y0) * mpb.rs;
- for (x = carea.x0; x < carea.x1; x++) {
- unsigned int m;
- m = ((s[0] + s[1] + s[2]) * s[3] +
- 127) / (3 * 255);
- d[0] = NR_PREMUL (d[0], m);
- s += 4;
- d += 1;
- }
- }
- } else {
- int x, y;
- for (y = carea.y0; y < carea.y1; y++) {
- unsigned char *s, *d;
- s = NR_PIXBLOCK_PX (&tpb) + (y - carea.y0) * tpb.rs;
- d = NR_PIXBLOCK_PX (&mpb) + (y - carea.y0) * mpb.rs;
- for (x = carea.x0; x < carea.x1; x++) {
- unsigned int m;
- m = ((s[0] + s[1] + s[2]) * s[3] +
- 127) / (3 * 255);
- d[0] = m;
- s += 4;
- d += 1;
- }
- }
- mpb.empty = FALSE;
- }
- }
- nr_pixblock_release (&tpb);
- }
- /* Multiply with opacity if needed */
- if ((item->opacity != 255) && !item->render_opacity && !outline) {
- int x, y;
- unsigned int a;
- a = item->opacity;
- for (y = carea.y0; y < carea.y1; y++) {
- unsigned char *d;
- d = NR_PIXBLOCK_PX (&mpb) + (y - carea.y0) * mpb.rs;
- for (x = carea.x0; x < carea.x1; x++) {
- d[0] = NR_PREMUL (d[0], a);
- d += 1;
- }
- }
- }
- /* Compose rendering pixblock int destination */
- // gettimeofday(&end_time,NULL);
- g_get_current_time (&end_time);
- duration =
- (end_time.tv_sec - start_time.tv_sec) * 1000 +
- (end_time.tv_usec - start_time.tv_usec) / 1000;
- if (!(ipb.empty)) {
- nr_blit_pixblock_pixblock_mask (dpb, &ipb, &mpb);
- if (insert_cache
- (item, tile_h, tile_v, &ipb, &mpb, item->activity,
- (double) duration)) {
- } else {
- nr_pixblock_release (&mpb);
- nr_pixblock_release (&ipb);
- }
- dpb->empty = FALSE;
- } else {
- nr_pixblock_release (&ipb);
- }
- }
- } else
- if (((item->opacity != 255) && !item->render_opacity
- && !outline)) {
- /* Opacity only */
- // gettimeofday(&end_time,NULL);
- g_get_current_time (&end_time);
- duration =
- (end_time.tv_sec - start_time.tv_sec) * 1000 +
- (end_time.tv_usec - start_time.tv_usec) / 1000;
- if (!(ipb.empty)) {
- nr_blit_pixblock_pixblock_alpha (dpb, &ipb, item->opacity);
- if (insert_cache
- (item, tile_h, tile_v, &ipb, NULL, item->activity,
- (double) duration)) {
- } else {
- nr_pixblock_release (&ipb);
- }
- dpb->empty = FALSE;
- } else {
- nr_pixblock_release (&ipb);
- }
- } else {
- // gettimeofday(&end_time,NULL);
- g_get_current_time (&end_time);
- duration =
- (end_time.tv_sec - start_time.tv_sec) * 1000 +
- (end_time.tv_usec - start_time.tv_usec) / 1000;
- if (!(ipb.empty)) {
- nr_blit_pixblock_pixblock (dpb, &ipb);
- if (insert_cache
- (item, tile_h, tile_v, &ipb, NULL, item->activity,
- (double) duration)) {
- } else {
- nr_pixblock_release (&ipb);
- }
- dpb->empty = FALSE;
- } else {
- nr_pixblock_release (&ipb);
- }
- }
-#endif
- } else {
- /* Determine, whether we need temporary buffer */
- if (item->clip || item->mask
- || ((item->opacity != 255) && !item->render_opacity && !outline)
- || (item->filter && !outline) || item->background_new
- || (item->parent && item->parent->background_pb)) {
-
- /* Setup and render item buffer */
- NRPixBlock ipb;
- nr_pixblock_setup_fast (&ipb, NR_PIXBLOCK_MODE_R8G8B8A8P,
- carea.x0, carea.y0, carea.x1, carea.y1,
- TRUE);
-
- // if memory allocation failed, abort render
- if (ipb.data.px == NULL) {
- nr_pixblock_release (&ipb);
- return (item->state);
- }
-
- /* If background access is used, save the pixblock address.
- * This address is set to NULL at the end of this block */
- if (item->background_new
- || (item->parent && item->parent->background_pb)) {
- item->background_pb = &ipb;
- }
- ipb.visible_area = pb->visible_area;
- unsigned int state = NR_ARENA_ITEM_VIRTUAL (item, render) (item, &carea, &ipb, flags);
- if (state & NR_ARENA_ITEM_STATE_INVALID) {
- /* Clean up and return error */
- nr_pixblock_release (&ipb);
- if (dpb != pb)
- nr_pixblock_release (dpb);
- item->state |= NR_ARENA_ITEM_STATE_INVALID;
- return item->state;
- }
- ipb.empty = FALSE;
-
- /* Run filtering, if a filter is set for this object */
- if (item->filter && !outline) {
- item->filter->render (item, &ipb);
- }
-
- if (item->clip || item->mask) {
- /* Setup mask pixblock */
- NRPixBlock mpb;
- nr_pixblock_setup_fast (&mpb, NR_PIXBLOCK_MODE_A8, carea.x0,
- carea.y0, carea.x1, carea.y1, TRUE);
-
- if (mpb.data.px != NULL) { // if memory allocation was successful
-
mpb.visible_area = pb->visible_area;
/* Do clip if needed */
if (item->clip) {
if (tpb.data.px != NULL) { // if memory allocation was successful
- tpb.visible_area = pb->visible_area;
- unsigned int state = NR_ARENA_ITEM_VIRTUAL (item->mask, render) (item->mask, &carea, &tpb, flags);
- if (state & NR_ARENA_ITEM_STATE_INVALID) {
- /* Clean up and return error */
- nr_pixblock_release (&tpb);
- nr_pixblock_release (&mpb);
- nr_pixblock_release (&ipb);
- if (dpb != pb)
- nr_pixblock_release (dpb);
- item->state |= NR_ARENA_ITEM_STATE_INVALID;
- return item->state;
- }
- /* Composite with clip */
- if (item->clip) {
- int x, y;
- for (y = carea.y0; y < carea.y1; y++) {
- unsigned char *s, *d;
- s = NR_PIXBLOCK_PX (&tpb) + (y -
- carea.y0) * tpb.rs;
- d = NR_PIXBLOCK_PX (&mpb) + (y -
- carea.y0) * mpb.rs;
- for (x = carea.x0; x < carea.x1; x++) {
- unsigned int m;
- m = NR_PREMUL_112 (s[0] + s[1] + s[2], s[3]);
- d[0] =
- FAST_DIV_ROUND < 3 * 255 * 255 >
- (NR_PREMUL_123 (d[0], m));
- s += 4;
- d += 1;
- }
+ tpb.visible_area = pb->visible_area;
+ unsigned int state = NR_ARENA_ITEM_VIRTUAL (item->mask, render) (item->mask, &carea, &tpb, flags);
+ if (state & NR_ARENA_ITEM_STATE_INVALID) {
+ /* Clean up and return error */
+ nr_pixblock_release (&tpb);
+ nr_pixblock_release (&mpb);
+ nr_pixblock_release (&ipb);
+ if (dpb != pb)
+ nr_pixblock_release (dpb);
+ item->state |= NR_ARENA_ITEM_STATE_INVALID;
+ return item->state;
}
- } else {
- int x, y;
- for (y = carea.y0; y < carea.y1; y++) {
- unsigned char *s, *d;
- s = NR_PIXBLOCK_PX (&tpb) + (y -
- carea.y0) * tpb.rs;
- d = NR_PIXBLOCK_PX (&mpb) + (y -
- carea.y0) * mpb.rs;
- for (x = carea.x0; x < carea.x1; x++) {
- unsigned int m;
- m = NR_PREMUL_112 (s[0] + s[1] + s[2], s[3]);
- d[0] = FAST_DIV_ROUND < 3 * 255 > (m);
- s += 4;
- d += 1;
+ /* Composite with clip */
+ if (item->clip) {
+ int x, y;
+ for (y = carea.y0; y < carea.y1; y++) {
+ unsigned char *s, *d;
+ s = NR_PIXBLOCK_PX (&tpb) + (y -
+ carea.y0) * tpb.rs;
+ d = NR_PIXBLOCK_PX (&mpb) + (y -
+ carea.y0) * mpb.rs;
+ for (x = carea.x0; x < carea.x1; x++) {
+ unsigned int m;
+ m = NR_PREMUL_112 (s[0] + s[1] + s[2], s[3]);
+ d[0] =
+ FAST_DIV_ROUND < 3 * 255 * 255 >
+ (NR_PREMUL_123 (d[0], m));
+ s += 4;
+ d += 1;
+ }
+ }
+ } else {
+ int x, y;
+ for (y = carea.y0; y < carea.y1; y++) {
+ unsigned char *s, *d;
+ s = NR_PIXBLOCK_PX (&tpb) + (y -
+ carea.y0) * tpb.rs;
+ d = NR_PIXBLOCK_PX (&mpb) + (y -
+ carea.y0) * mpb.rs;
+ for (x = carea.x0; x < carea.x1; x++) {
+ unsigned int m;
+ m = NR_PREMUL_112 (s[0] + s[1] + s[2], s[3]);
+ d[0] = FAST_DIV_ROUND < 3 * 255 > (m);
+ s += 4;
+ d += 1;
+ }
}
+ mpb.empty = FALSE;
}
- mpb.empty = FALSE;
- }
}
nr_pixblock_release (&tpb);
}
}
/* Compose rendering pixblock int destination */
nr_blit_pixblock_pixblock_mask (dpb, &ipb, &mpb);
- }
- nr_pixblock_release (&mpb);
- /* This pointer wouldn't be valid outside this block, so clear it */
- item->background_pb = NULL;
- } else {
- /* Opacity only */
- nr_blit_pixblock_pixblock_alpha (dpb, &ipb, item->opacity);
}
- nr_pixblock_release (&ipb);
- dpb->empty = FALSE;
+ nr_pixblock_release (&mpb);
+ /* This pointer wouldn't be valid outside this block, so clear it */
+ item->background_pb = NULL;
} else {
- /* Just render */
- unsigned int state = NR_ARENA_ITEM_VIRTUAL (item, render) (item, &carea, dpb, flags);
- if (state & NR_ARENA_ITEM_STATE_INVALID) {
- /* Clean up and return error */
- if (dpb != pb)
- nr_pixblock_release (dpb);
- item->state |= NR_ARENA_ITEM_STATE_INVALID;
- return item->state;
- }
- dpb->empty = FALSE;
+ /* Opacity only */
+ nr_blit_pixblock_pixblock_alpha (dpb, &ipb, item->opacity);
}
-
- if (dpb != pb) {
- /* Have to blit from cache */
- nr_blit_pixblock_pixblock (pb, dpb);
- nr_pixblock_release (dpb);
- pb->empty = FALSE;
- item->state |= NR_ARENA_ITEM_STATE_IMAGE;
+ nr_pixblock_release (&ipb);
+ dpb->empty = FALSE;
+ } else {
+ /* Just render */
+ unsigned int state = NR_ARENA_ITEM_VIRTUAL (item, render) (item, &carea, dpb, flags);
+ if (state & NR_ARENA_ITEM_STATE_INVALID) {
+ /* Clean up and return error */
+ if (dpb != pb)
+ nr_pixblock_release (dpb);
+ item->state |= NR_ARENA_ITEM_STATE_INVALID;
+ return item->state;
}
+ dpb->empty = FALSE;
+ }
+
+ if (dpb != pb) {
+ /* Have to blit from cache */
+ nr_blit_pixblock_pixblock (pb, dpb);
+ nr_pixblock_release (dpb);
+ pb->empty = FALSE;
+ item->state |= NR_ARENA_ITEM_STATE_IMAGE;
}
+
return item->state | NR_ARENA_ITEM_STATE_RENDER;
}
return next;
}
-/*
- *
- * caches
- *
- */
-
-#ifdef arena_item_tile_cache
-typedef struct cache_entry {
- int key;
- double score;
- NRArenaItem *owner;
- int th, tv;
- int prev, next;
- NRPixBlock ipb;
- bool hasMask;
- NRPixBlock mpb;
-} cache_entry;
-
-int hash_max = 2048, hash_fill = 1024;
-
-int *keys = NULL;
-int nbCch = 0;
-
-int nbEnt = 0, maxEnt = 0;
-cache_entry *entries = NULL;
-
-//#define tile_cache_stats
-#ifdef tile_cache_stats
-double hits = 0, misses = 0;
-int hitMissCount = 0;
-#endif
-
-int
-hash_that (NRArenaItem *owner, int th, int tv)
-{
- int res = GPOINTER_TO_INT (owner);
- res *= 17;
- res += th;
- res *= 59;
- res += tv;
- res *= 217;
- if (res < 0)
- res = -res;
- res %= hash_max;
- return res;
-}
-
-bool
-test_cache (NRArenaItem *owner, int th, int tv, NRPixBlock & ipb,
- NRPixBlock & mpb, bool & hasMask)
-{
- if (keys == NULL) {
- hash_max = prefs_get_int_attribute ("options.arenatilescachesize", "value", 2048);
- hash_fill = (hash_max * 3) / 4;
- keys = (int *) malloc (hash_max * sizeof (int));
- for (int i = 0; i < hash_max; i++)
- keys[i] = -1;
- }
- int key = hash_that (owner, th, tv);
- if (keys[key] < 0) {
-#ifdef tile_cache_stats
- misses += 1.0;
-#endif
- return false;
- }
- int cur = keys[key];
- while (cur >= 0 && cur < nbEnt) {
- if (entries[cur].owner == owner && entries[cur].th == th
- && entries[cur].tv == tv) {
- hasMask = entries[cur].hasMask;
- ipb = entries[cur].ipb;
- mpb = entries[cur].mpb;
-#ifdef tile_cache_stats
- hits += 1.0;
-#endif
- return true;
- }
- cur = entries[cur].next;
- }
-#ifdef tile_cache_stats
- misses += 1.0;
-#endif
- return false;
-}
-
-void
-remove_one_cache (int no)
-{
- if (no < 0 || no >= nbEnt)
- return;
-
- nr_pixblock_release (&entries[no].ipb);
- if (entries[no].hasMask)
- nr_pixblock_release (&entries[no].mpb);
-
- if (entries[no].prev >= 0)
- entries[entries[no].prev].next = entries[no].next;
- if (entries[no].next >= 0)
- entries[entries[no].next].prev = entries[no].prev;
- if (entries[no].prev < 0)
- keys[entries[no].key] = entries[no].next;
- entries[no].prev = entries[no].next = entries[no].key = -1;
-
- if (no == nbEnt - 1) {
- nbEnt--;
- return;
- }
- entries[no] = entries[--nbEnt];
- if (entries[no].prev >= 0)
- entries[entries[no].prev].next = no;
- if (entries[no].next >= 0)
- entries[entries[no].next].prev = no;
- if (entries[no].prev < 0)
- keys[entries[no].key] = no;
-}
-
-void
-remove_caches (NRArenaItem *owner)
-{
- if (keys == NULL) {
- hash_max = prefs_get_int_attribute ("options.arenatilescachesize", "value", 2048);
- hash_fill = (hash_max * 3) / 4;
- keys = (int *) malloc (hash_max * sizeof (int));
- for (int i = 0; i < hash_max; i++)
- keys[i] = -1;
- }
- for (int i = nbEnt - 1; i >= 0; i--) {
- if (entries[i].owner == owner) {
- remove_one_cache (i);
- }
- }
-}
-void
-age_cache (void)
-{
- for (int i = 0; i < nbEnt; i++)
- entries[i].score *= 0.95;
-}
-
-bool
-insert_cache (NRArenaItem *owner, int th, int tv, NRPixBlock *ipb,
- NRPixBlock *mpb, double activity, double duration)
-{
- if (keys == NULL) {
- hash_max = prefs_get_int_attribute ("options.arenatilescachesize", "value", 2048);
- hash_fill = (hash_max * 3) / 4;
- keys = (int *) malloc (hash_max * sizeof (int));
- for (int i = 0; i < hash_max; i++)
- keys[i] = -1;
- }
- for (int i = 0; i < nbEnt; i++)
- entries[i].score *= 0.95;
-#ifdef tile_cache_stats
- hits *= 0.95;
- misses *= 0.95;
- hitMissCount++;
- if (hitMissCount > 100) {
- hitMissCount = 0;
- printf ("hit/miss = %f used/total=%i/%i\n", (misses > 0.001) ? hits / misses : 100000.0, nbEnt, hash_max); // localizing ok
- }
-#endif
- int key = hash_that (owner, th, tv);
- double nScore = /*activity* */ duration;
-
- if (keys[key] >= 0) {
- int cur = keys[key];
- while (cur >= 0 && cur < nbEnt) {
- if (entries[cur].owner == owner && entries[cur].th == th
- && entries[cur].tv == tv) {
- remove_one_cache (cur);
- break;
- }
- cur = entries[cur].next;
- }
- }
-
- bool doAdd = false;
- if (nbEnt < hash_fill) {
- doAdd = true;
- } else {
- double worstS = entries[0].score;
- int worstE = 0;
- for (int i = 1; i < nbEnt; i++) {
- if (entries[i].score < worstS) {
- worstS = entries[i].score;
- worstE = i;
- }
- }
- if (worstS < nScore) {
- doAdd = true;
- remove_one_cache (worstE);
- }
- }
- if (doAdd == false)
- return false;
- if (nbEnt >= maxEnt) {
- maxEnt = 2 * nbEnt + 1;
- entries = (cache_entry *) realloc (entries, maxEnt * sizeof (cache_entry));
- }
- entries[nbEnt].key = key;
- entries[nbEnt].score = nScore;
- entries[nbEnt].owner = owner;
- entries[nbEnt].th = th;
- entries[nbEnt].tv = tv;
- entries[nbEnt].prev = entries[nbEnt].next = -1;
- entries[nbEnt].ipb = *ipb;
- if (mpb) {
- entries[nbEnt].hasMask = true;
- entries[nbEnt].mpb = *mpb;
- } else {
- entries[nbEnt].hasMask = false;
- }
- entries[nbEnt].next = keys[key];
- if (entries[nbEnt].next >= 0)
- entries[entries[nbEnt].next].prev = nbEnt;
- keys[key] = nbEnt;
-
- nbEnt++;
- return true;
-}
-#endif
-
/*
Local Variables:
mode:c++
index 52408d1547f09892879ad9aa28e652e191c37f89..16a7a0c129a9c1500e7f7d5b1a6957e587f54881 100644 (file)
#include "nr-arena-forward.h"
#include "display/nr-filter.h"
-// My testing shows that disabling cache reduces the amount
-// of leaked memory when many documents are loaded one from the other,
-// while there's no noticeable change in speed
-//#define arena_item_tile_cache
-
struct NRGC {
NRGC(NRGC const *p) : parent(p) {}
NRGC const *parent;
/* Key for secondary rendering */
unsigned int key;
-#ifdef arena_item_tile_cache
- bool skipCaching;
- double activity;
-#endif
-
/* BBox in grid coordinates */
NRRectL bbox;
/* Our affine */