Style cleanup of movie cache module

This commit is contained in:
Sergey Sharybin
2012-03-26 16:04:10 +00:00
parent adbe628a1b
commit 03336c0ba7

View File

@@ -77,29 +77,29 @@ typedef struct MovieCacheItem {
static unsigned int moviecache_hashhash(const void *keyv)
{
MovieCacheKey *key= (MovieCacheKey*)keyv;
MovieCacheKey *key = (MovieCacheKey*)keyv;
return key->cache_owner->hashfp(key->userkey);
}
static int moviecache_hashcmp(const void *av, const void *bv)
{
const MovieCacheKey *a= (MovieCacheKey*)av;
const MovieCacheKey *b= (MovieCacheKey*)bv;
const MovieCacheKey *a = (MovieCacheKey*)av;
const MovieCacheKey *b = (MovieCacheKey*)bv;
return a->cache_owner->cmpfp(a->userkey, b->userkey);
}
static void moviecache_keyfree(void *val)
{
MovieCacheKey *key= (MovieCacheKey*)val;
MovieCacheKey *key = (MovieCacheKey*)val;
BLI_mempool_free(key->cache_owner->keys_pool, key);
}
static void moviecache_valfree(void *val)
{
MovieCacheItem *item= (MovieCacheItem*)val;
MovieCacheItem *item = (MovieCacheItem*)val;
if (item->ibuf) {
MEM_CacheLimiter_unmanage(item->c_handle);
@@ -115,8 +115,8 @@ static void check_unused_keys(MovieCache *cache)
iter= BLI_ghashIterator_new(cache->hash);
while (!BLI_ghashIterator_isDone(iter)) {
MovieCacheKey *key= BLI_ghashIterator_getKey(iter);
MovieCacheItem *item= BLI_ghashIterator_getValue(iter);
MovieCacheKey *key = BLI_ghashIterator_getKey(iter);
MovieCacheItem *item = BLI_ghashIterator_getValue(iter);
BLI_ghashIterator_step(iter);
@@ -129,20 +129,20 @@ static void check_unused_keys(MovieCache *cache)
static int compare_int(const void *av, const void *bv)
{
const int *a= (int *)av;
const int *b= (int *)bv;
return *a-*b;
const int *a = (int *)av;
const int *b = (int *)bv;
return *a - *b;
}
static void IMB_moviecache_destructor(void *p)
{
MovieCacheItem *item= (MovieCacheItem *) p;
MovieCacheItem *item = (MovieCacheItem *) p;
if (item && item->ibuf) {
IMB_freeImBuf(item->ibuf);
item->ibuf= NULL;
item->c_handle= NULL;
item->ibuf = NULL;
item->c_handle = NULL;
}
}
@@ -150,27 +150,27 @@ static void IMB_moviecache_destructor(void *p)
static size_t IMB_get_size_in_memory(ImBuf *ibuf)
{
int a;
size_t size= 0, channel_size= 0;
size_t size = 0, channel_size = 0;
size+= sizeof(ImBuf);
size += sizeof(ImBuf);
if (ibuf->rect)
channel_size+= sizeof(char);
channel_size += sizeof(char);
if (ibuf->rect_float)
channel_size+= sizeof(float);
channel_size += sizeof(float);
size+= channel_size*ibuf->x*ibuf->y*ibuf->channels;
size += channel_size * ibuf->x * ibuf->y * ibuf->channels;
if (ibuf->miptot) {
for (a= 0; a<ibuf->miptot; a++) {
for (a = 0; a < ibuf->miptot; a++) {
if (ibuf->mipmap[a])
size+= IMB_get_size_in_memory(ibuf->mipmap[a]);
size += IMB_get_size_in_memory(ibuf->mipmap[a]);
}
}
if (ibuf->tiles) {
size+= sizeof(unsigned int)*ibuf->ytiles*ibuf->xtiles;
size += sizeof(unsigned int)*ibuf->ytiles*ibuf->xtiles;
}
return size;
@@ -178,18 +178,18 @@ static size_t IMB_get_size_in_memory(ImBuf *ibuf)
static size_t get_item_size (void *p)
{
size_t size= sizeof(MovieCacheItem);
MovieCacheItem *item= (MovieCacheItem *) p;
size_t size = sizeof(MovieCacheItem);
MovieCacheItem *item = (MovieCacheItem *) p;
if (item->ibuf)
size+= IMB_get_size_in_memory(item->ibuf);
size += IMB_get_size_in_memory(item->ibuf);
return size;
}
void IMB_moviecache_init(void)
{
limitor= new_MEM_CacheLimiter(IMB_moviecache_destructor, get_item_size);
limitor = new_MEM_CacheLimiter(IMB_moviecache_destructor, get_item_size);
}
void IMB_moviecache_destruct(void)
@@ -203,17 +203,17 @@ struct MovieCache *IMB_moviecache_create(int keysize, GHashHashFP hashfp, GHashC
{
MovieCache *cache;
cache= MEM_callocN(sizeof(MovieCache), "MovieCache");
cache->keys_pool= BLI_mempool_create(sizeof(MovieCacheKey), 64, 64, 0);
cache->items_pool= BLI_mempool_create(sizeof(MovieCacheItem), 64, 64, 0);
cache->userkeys_pool= BLI_mempool_create(keysize, 64, 64, 0);
cache->hash= BLI_ghash_new(moviecache_hashhash, moviecache_hashcmp, "MovieClip ImBuf cache hash");
cache = MEM_callocN(sizeof(MovieCache), "MovieCache");
cache->keys_pool = BLI_mempool_create(sizeof(MovieCacheKey), 64, 64, 0);
cache->items_pool = BLI_mempool_create(sizeof(MovieCacheItem), 64, 64, 0);
cache->userkeys_pool = BLI_mempool_create(keysize, 64, 64, 0);
cache->hash = BLI_ghash_new(moviecache_hashhash, moviecache_hashcmp, "MovieClip ImBuf cache hash");
cache->keysize= keysize;
cache->hashfp= hashfp;
cache->cmpfp= cmpfp;
cache->getdatafp= getdatafp;
cache->proxy= -1;
cache->keysize = keysize;
cache->hashfp = hashfp;
cache->cmpfp = cmpfp;
cache->getdatafp = getdatafp;
cache->proxy = -1;
return cache;
}
@@ -228,21 +228,21 @@ void IMB_moviecache_put(MovieCache *cache, void *userkey, ImBuf *ibuf)
IMB_refImBuf(ibuf);
key= BLI_mempool_alloc(cache->keys_pool);
key->cache_owner= cache;
key->userkey= BLI_mempool_alloc(cache->userkeys_pool);
key = BLI_mempool_alloc(cache->keys_pool);
key->cache_owner = cache;
key->userkey = BLI_mempool_alloc(cache->userkeys_pool);
memcpy(key->userkey, userkey, cache->keysize);
item= BLI_mempool_alloc(cache->items_pool);
item->ibuf= ibuf;
item->cache_owner= cache;
item->last_access= cache->curtime++;
item->c_handle= NULL;
item = BLI_mempool_alloc(cache->items_pool);
item->ibuf = ibuf;
item->cache_owner = cache;
item->last_access = cache->curtime++;
item->c_handle = NULL;
BLI_ghash_remove(cache->hash, key, moviecache_keyfree, moviecache_valfree);
BLI_ghash_insert(cache->hash, key, item);
item->c_handle= MEM_CacheLimiter_insert(limitor, item);
item->c_handle = MEM_CacheLimiter_insert(limitor, item);
MEM_CacheLimiter_ref(item->c_handle);
MEM_CacheLimiter_enforce_limits(limitor);
@@ -262,12 +262,12 @@ ImBuf* IMB_moviecache_get(MovieCache *cache, void *userkey)
MovieCacheKey key;
MovieCacheItem *item;
key.cache_owner= cache;
key.userkey= userkey;
item= (MovieCacheItem*)BLI_ghash_lookup(cache->hash, &key);
key.cache_owner = cache;
key.userkey = userkey;
item = (MovieCacheItem*)BLI_ghash_lookup(cache->hash, &key);
if (item) {
item->last_access= cache->curtime++;
item->last_access = cache->curtime++;
if (item->ibuf) {
MEM_CacheLimiter_touch(item->c_handle);
@@ -297,41 +297,41 @@ void IMB_moviecache_free(MovieCache *cache)
/* get segments of cached frames. useful for debugging cache policies */
void IMB_moviecache_get_cache_segments(MovieCache *cache, int proxy, int render_flags, int *totseg_r, int **points_r)
{
*totseg_r= 0;
*points_r= NULL;
*totseg_r = 0;
*points_r = NULL;
if (!cache->getdatafp)
return;
if (cache->proxy!=proxy || cache->render_flags!=render_flags) {
if (cache->proxy != proxy || cache->render_flags != render_flags) {
if (cache->points)
MEM_freeN(cache->points);
cache->points= NULL;
cache->points = NULL;
}
if (cache->points) {
*totseg_r= cache->totseg;
*points_r= cache->points;
*totseg_r = cache->totseg;
*points_r = cache->points;
}
else {
int totframe= BLI_ghash_size(cache->hash);
int *frames= MEM_callocN(totframe*sizeof(int), "movieclip cache frames");
int a, totseg= 0;
int totframe = BLI_ghash_size(cache->hash);
int *frames = MEM_callocN(totframe*sizeof(int), "movieclip cache frames");
int a, totseg = 0;
GHashIterator *iter;
iter= BLI_ghashIterator_new(cache->hash);
iter = BLI_ghashIterator_new(cache->hash);
a= 0;
while (!BLI_ghashIterator_isDone(iter)) {
MovieCacheKey *key= BLI_ghashIterator_getKey(iter);
MovieCacheItem *item= BLI_ghashIterator_getValue(iter);
MovieCacheKey *key = BLI_ghashIterator_getKey(iter);
MovieCacheItem *item = BLI_ghashIterator_getValue(iter);
int framenr, curproxy, curflags;
if (item->ibuf) {
cache->getdatafp(key->userkey, &framenr, &curproxy, &curflags);
if (curproxy==proxy && curflags==render_flags)
frames[a++]= framenr;
if (curproxy == proxy && curflags == render_flags)
frames[a++] = framenr;
}
BLI_ghashIterator_step(iter);
@@ -342,40 +342,40 @@ void IMB_moviecache_get_cache_segments(MovieCache *cache, int proxy, int render_
qsort(frames, totframe, sizeof(int), compare_int);
/* count */
for (a= 0; a<totframe; a++) {
if (a && frames[a]-frames[a-1]!=1)
for (a = 0; a < totframe; a++) {
if (a && frames[a] - frames[a - 1] != 1)
totseg++;
if (a==totframe-1)
if (a == totframe - 1)
totseg++;
}
if (totseg) {
int b, *points;
points= MEM_callocN(2*sizeof(int)*totseg, "movieclip cache segments");
points = MEM_callocN(2*sizeof(int)*totseg, "movieclip cache segments");
/* fill */
for (a= 0, b= 0; a<totframe; a++) {
if (a==0)
points[b++]= frames[a];
for (a = 0, b = 0; a < totframe; a++) {
if (a == 0)
points[b++] = frames[a];
if (a && frames[a]-frames[a-1]!=1) {
points[b++]= frames[a-1];
points[b++]= frames[a];
if (a && frames[a] - frames[a - 1] != 1) {
points[b++] = frames[a - 1];
points[b++] = frames[a];
}
if (a==totframe-1)
points[b++]= frames[a];
if (a == totframe - 1)
points[b++] = frames[a];
}
*totseg_r= totseg;
*points_r= points;
*totseg_r = totseg;
*points_r = points;
cache->totseg= totseg;
cache->points= points;
cache->proxy= proxy;
cache->render_flags= render_flags;
cache->totseg = totseg;
cache->points = points;
cache->proxy = proxy;
cache->render_flags = render_flags;
}
MEM_freeN(frames);