2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Peter Schlaile <peter [at] schlaile [dot] de> 2010
20 * Contributor(s): Sergey Sharybin
22 * ***** END GPL LICENSE BLOCK *****
25 /** \file blender/blenkernel/intern/seqcache.c
32 #include "BLO_sys_types.h" /* for intptr_t */
34 #include "MEM_guardedalloc.h"
36 #include "DNA_sequence_types.h"
37 #include "BKE_sequencer.h"
39 #include "IMB_moviecache.h"
41 typedef struct seqCacheKey
43 struct Sequence * seq;
44 SeqRenderData context;
46 seq_stripelem_ibuf_t type;
49 static struct MovieCache *moviecache = NULL;
51 static unsigned int seqcache_hashhash(const void *key_)
53 const seqCacheKey *key = (seqCacheKey*) key_;
54 unsigned int rval = seq_hash_render_data(&key->context);
56 rval ^= *(unsigned int*) &key->cfra;
58 rval ^= ((intptr_t) key->seq) << 6;
63 static int seqcache_hashcmp(const void *a_, const void *b_)
65 const seqCacheKey * a = (seqCacheKey*) a_;
66 const seqCacheKey * b = (seqCacheKey*) b_;
68 if (a->seq < b->seq) {
71 if (a->seq > b->seq) {
75 if (a->cfra < b->cfra) {
78 if (a->cfra > b->cfra) {
82 if (a->type < b->type) {
85 if (a->type > b->type) {
89 return seq_cmp_render_data(&a->context, &b->context);
92 void seq_stripelem_cache_destruct(void)
95 IMB_moviecache_free(moviecache);
98 void seq_stripelem_cache_cleanup(void)
101 IMB_moviecache_free(moviecache);
102 moviecache = IMB_moviecache_create(sizeof(seqCacheKey), seqcache_hashhash,
103 seqcache_hashcmp, NULL);
107 struct ImBuf * seq_stripelem_cache_get(
108 SeqRenderData context, struct Sequence * seq,
109 float cfra, seq_stripelem_ibuf_t type)
112 if (moviecache && seq) {
116 key.context = context;
117 key.cfra = cfra - seq->start;
120 return IMB_moviecache_get(moviecache, &key);
126 void seq_stripelem_cache_put(
127 SeqRenderData context, struct Sequence * seq,
128 float cfra, seq_stripelem_ibuf_t type, struct ImBuf * i)
137 moviecache = IMB_moviecache_create(sizeof(seqCacheKey), seqcache_hashhash,
138 seqcache_hashcmp, NULL);
142 key.context = context;
143 key.cfra = cfra - seq->start;
146 IMB_moviecache_put(moviecache, &key, i);