nr-arena-item.cpp revision 9e87caa574d67b9b1aa1015d4faae055336c9d30
#define __NR_ARENA_ITEM_C__
/*
* RGBA display list system for inkscape
*
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
*
* Copyright (C) 2001-2002 Lauris Kaplinski
* Copyright (C) 2001 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#define noNR_ARENA_ITEM_VERBOSE
#define noNR_ARENA_ITEM_DEBUG_CASCADE
#include <libnr/nr-pixops.h>
#include "nr-arena.h"
#include "nr-arena-item.h"
#include "gc-core.h"
#include "nr-filter.h"
#include "nr-arena-group.h"
#ifdef arena_item_tile_cache
bool insert_cache(NRArenaItem* owner,int th,int tv,NRPixBlock *ipb,NRPixBlock *mpb,double activity,double duration);
#endif
static NRObjectClass *parent_class;
nr_arena_item_get_type (void)
{
if (!type) {
"NRArenaItem",
sizeof (NRArenaItemClass),
sizeof (NRArenaItem),
(void (*) (NRObjectClass *)) nr_arena_item_class_init,
(void (*) (NRObject *)) nr_arena_item_init);
}
return type;
}
static void
{
}
static void
{
#ifdef arena_item_tile_cache
item->skipCaching=false;
#endif
item->background_new = false;
}
static void
{
#ifdef arena_item_tile_cache
#endif
}
{
return NULL;
}
{
} else {
return ref;
}
}
void
{
}
void
{
}
void
{
}
{
return item;
}
{
return NULL;
}
unsigned int
nr_arena_item_invoke_update (NRArenaItem *item, NRRectL *area, NRGC *gc, unsigned int state, unsigned int reset)
{
#ifdef NR_ARENA_ITEM_DEBUG_CASCADE
printf ("Update %s:%p %x %x %x\n", nr_type_name_from_instance ((GTypeInstance *) item), item, state, item->state, reset);
#endif
/* return if in error */
/* Set reset flags according to propagation status */
}
/* Reset our state */
/* Return if NOP */
/* Test whether to return immediately */
}
/* Reset image cache, if not to be kept */
}
#ifdef arena_item_tile_cache
#endif
/* Set up local gc */
}
/* Remember the transformation matrix */
/* Invoke the real method */
/* Enlarge the bounding box to contain filter effects */
}
/* Clipping */
unsigned int newstate;
if (newstate & NR_ARENA_ITEM_STATE_INVALID) {
}
}
/* Masking */
unsigned int newstate;
if (newstate & NR_ARENA_ITEM_STATE_INVALID) {
}
}
}
/**
* Render item to pixblock.
*
* \return Has NR_ARENA_ITEM_STATE_RENDER set on success.
*/
unsigned int nr_arena_item_invoke_render(NRArenaItem *item, NRRectL const *area, NRPixBlock *pb, unsigned int flags)
{
unsigned int state;
#ifdef NR_ARENA_ITEM_VERBOSE
#endif
#ifdef arena_item_tile_cache
#endif
/* If we are outside bbox just return successfully */
}
/* Has cache pixblock, render this and return */
/* fixme: This probably cannot overflow, because we render only if visible */
/* fixme: and pixel cache is there only for small items */
/* fixme: But this still needs extra check (Lauris) */
}
bool canCache=false;
#ifdef arena_item_tile_cache
bool checkCache=false;
#endif
/* Setup cache if we can */
if ((!(flags & NR_ARENA_ITEM_RENDER_NO_CACHE)) &&
// Item bbox is fully in renderable area and size is acceptable
// Set nocache flag for downstream rendering
} else {
#ifdef arena_item_tile_cache
if ( item->skipCaching ) {
} else {
checkCache=true;
if ( surf >= 4096 ) {
canCache=true;
}
}
}
#endif
}
#ifdef arena_item_tile_cache
#endif
#ifdef arena_item_tile_cache
if ( checkCache ) {
bool hasMask;
// youpi! c'etait deja cache
if ( hasMask ) {
} else {
}
}
}
#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);
int duration=0;
/* Setup and render item buffer */
nr_pixblock_setup_fast (&ipb, NR_PIXBLOCK_MODE_R8G8B8A8P, carea.x0, carea.y0, carea.x1, carea.y1, TRUE);
if (state & NR_ARENA_ITEM_STATE_INVALID) {
/* Clean up and return error */
}
/* Setup mask pixblock */
/* Do clip if needed */
if (state & NR_ARENA_ITEM_STATE_INVALID) {
/* Clean up and return error */
}
}
/* Do mask if needed */
/* 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 (state & NR_ARENA_ITEM_STATE_INVALID) {
/* Clean up and return error */
}
/* Composite with clip */
int x, y;
unsigned char *s, *d;
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;
unsigned char *s, *d;
unsigned int m;
m = ((s[0] + s[1] + s[2]) * s[3] + 127) / (3 * 255);
d[0] = m;
s += 4;
d += 1;
}
}
}
}
/* Multiply with opacity if needed */
if ((item->opacity != 255) && !item->render_opacity && item->arena->rendermode != RENDERMODE_OUTLINE) {
int x, y;
unsigned int a;
unsigned char *d;
d[0] = NR_PREMUL (d[0], a);
d += 1;
}
}
}
/* Compose rendering pixblock int destination */
// gettimeofday(&end_time,NULL);
} else {
}
} else {
}
} else if ( ((item->opacity != 255) && !item->render_opacity && item->arena->rendermode != RENDERMODE_OUTLINE) ) {
/* Opacity only */
// gettimeofday(&end_time,NULL);
} else {
}
} else {
}
} else {
// gettimeofday(&end_time,NULL);
} else {
}
} else {
}
}
#endif
} else {
/* Determine, whether we need temporary buffer */
|| ((item->opacity != 255) && !item->render_opacity && item->arena->rendermode != RENDERMODE_OUTLINE)
{
/* Setup and render item buffer */
nr_pixblock_setup_fast (&ipb, NR_PIXBLOCK_MODE_R8G8B8A8P, carea.x0, carea.y0, carea.x1, carea.y1, TRUE);
/* 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
}
if (state & NR_ARENA_ITEM_STATE_INVALID) {
/* Clean up and return error */
}
/* Run filtering, if a filter is set for this object */
}
/* Setup mask pixblock */
/* Do clip if needed */
if (state & NR_ARENA_ITEM_STATE_INVALID) {
/* Clean up and return error */
}
}
/* Do mask if needed */
/* 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 (state & NR_ARENA_ITEM_STATE_INVALID) {
/* Clean up and return error */
}
/* Composite with clip */
int x, y;
unsigned char *s, *d;
unsigned int m;
s += 4;
d += 1;
}
}
} else {
int x, y;
unsigned char *s, *d;
unsigned int m;
s += 4;
d += 1;
}
}
}
}
/* Multiply with opacity if needed */
if ((item->opacity != 255) && !item->render_opacity && item->arena->rendermode != RENDERMODE_OUTLINE) {
int x, y;
unsigned int a;
unsigned char *d;
d[0] = NR_PREMUL_111 (d[0], a);
d += 1;
}
}
}
/* Compose rendering pixblock int destination */
/* This pointer wouldn't be valid outside this block, so clear it */
} else {
/* Opacity only */
}
} else {
/* Just render */
if (state & NR_ARENA_ITEM_STATE_INVALID) {
/* Clean up and return error */
}
}
/* Have to blit from cache */
}
}
}
unsigned int
{
/* we originally short-circuited if the object state included
* NR_ARENA_ITEM_STATE_CLIP (and showed a warning on the console);
* anyone know why we stopped doing so?
*/
nr_return_val_if_fail ((pb->area.x1 - pb->area.x0) >= (area->x1 - area->x0), NR_ARENA_ITEM_STATE_INVALID);
nr_return_val_if_fail ((pb->area.y1 - pb->area.y0) >= (area->y1 - area->y0), NR_ARENA_ITEM_STATE_INVALID);
#ifdef NR_ARENA_ITEM_VERBOSE
printf ("Invoke clip by %p: %d %d - %d %d, item bbox %d %d - %d %d\n", item, area->x0, area->y0, area->x1, area->y1, (&item->bbox)->x0, (&item->bbox)->y0, (&item->bbox)->x1, (&item->bbox)->y1);
#endif
/* Need render that item */
}
}
}
{
// Sometimes there's no BBOX in item->state, reason unknown (bug 992817); I made this not an assert to remove the warning
return NULL;
// TODO: rewrite using NR::Rect
const double x = p[NR::X];
const double y = p[NR::Y];
}
return NULL;
}
void
{
} else {
}
}
}
void
{
}
/* Public */
{
}
return NULL;
}
void
{
}
void
{
}
void
{
/* Set to identity affine */
} else {
}
}
}
void
{
}
void
{
}
void
{
}
void
{
}
}
void
{
}
}
void
{
int pos;
pos = 0;
pos += 1;
}
}
}
/** Returns a background image for use with filter effects. */
{
NRPixBlock *pb;
if (item->background_new) {
pb = new NRPixBlock();
} else return NULL;
if (depth > 0)
return pb;
}
/* Helpers */
nr_arena_item_attach (NRArenaItem *parent, NRArenaItem *child, NRArenaItem *prev, NRArenaItem *next)
{
return child;
}
{
return next;
}
/*
*
* caches
*
*/
#ifdef arena_item_tile_cache
typedef struct cache_entry {
int key;
double score;
bool hasMask;
} cache_entry;
int nbCch=0;
//#define tile_cache_stats
#ifdef tile_cache_stats
int hitMissCount=0;
#endif
{
res*=17;
res*=59;
res*=217;
return res;
}
{
}
#ifdef tile_cache_stats
misses+=1.0;
#endif
return false;
}
#ifdef tile_cache_stats
hits+=1.0;
#endif
return true;
}
}
#ifdef tile_cache_stats
misses+=1.0;
#endif
return false;
}
void remove_one_cache(int no)
{
nbEnt--;
return;
}
}
{
}
for (int i=nbEnt-1;i>=0;i--) {
remove_one_cache(i);
}
}
}
void age_cache(void)
{
}
bool insert_cache(NRArenaItem* owner,int th,int tv,NRPixBlock *ipb,NRPixBlock *mpb,double activity,double duration)
{
}
#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
break;
}
}
}
bool doAdd=false;
doAdd=true;
} else {
int worstE=0;
for (int i=1;i<nbEnt;i++) {
worstE=i;
}
}
doAdd=true;
}
}
if ( doAdd == false ) return false;
}
if ( mpb ) {
} else {
}
nbEnt++;
return true;
}
#endif