Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * Peter Schlaile <peter [at] schlaile [dot] de> 2010 00019 * 00020 * Contributor(s): Sergey Sharybin 00021 * 00022 * ***** END GPL LICENSE BLOCK ***** 00023 */ 00024 00030 #include <stddef.h> 00031 00032 #include "BLO_sys_types.h" /* for intptr_t */ 00033 00034 #include "MEM_guardedalloc.h" 00035 00036 #include "DNA_sequence_types.h" 00037 #include "BKE_sequencer.h" 00038 00039 #include "IMB_moviecache.h" 00040 00041 typedef struct seqCacheKey 00042 { 00043 struct Sequence * seq; 00044 SeqRenderData context; 00045 float cfra; 00046 seq_stripelem_ibuf_t type; 00047 } seqCacheKey; 00048 00049 static struct MovieCache *moviecache = NULL; 00050 00051 static unsigned int seqcache_hashhash(const void *key_) 00052 { 00053 const seqCacheKey *key = (seqCacheKey*) key_; 00054 unsigned int rval = seq_hash_render_data(&key->context); 00055 00056 rval ^= *(unsigned int*) &key->cfra; 00057 rval += key->type; 00058 rval ^= ((intptr_t) key->seq) << 6; 00059 00060 return rval; 00061 } 00062 00063 static int seqcache_hashcmp(const void *a_, const void *b_) 00064 { 00065 const seqCacheKey * a = (seqCacheKey*) a_; 00066 const seqCacheKey * b = (seqCacheKey*) b_; 00067 00068 if (a->seq < b->seq) { 00069 return -1; 00070 } 00071 if (a->seq > b->seq) { 00072 return 1; 00073 } 00074 00075 if (a->cfra < b->cfra) { 00076 return -1; 00077 } 00078 if (a->cfra > b->cfra) { 00079 return 1; 00080 } 00081 00082 if (a->type < b->type) { 00083 return -1; 00084 } 00085 if (a->type > b->type) { 00086 return 1; 00087 } 00088 00089 return seq_cmp_render_data(&a->context, &b->context); 00090 } 00091 00092 void seq_stripelem_cache_destruct(void) 00093 { 00094 if(moviecache) 00095 IMB_moviecache_free(moviecache); 00096 } 00097 00098 void seq_stripelem_cache_cleanup(void) 00099 { 00100 if(moviecache) { 00101 IMB_moviecache_free(moviecache); 00102 moviecache = IMB_moviecache_create(sizeof(seqCacheKey), seqcache_hashhash, 00103 seqcache_hashcmp, NULL); 00104 } 00105 } 00106 00107 struct ImBuf * seq_stripelem_cache_get( 00108 SeqRenderData context, struct Sequence * seq, 00109 float cfra, seq_stripelem_ibuf_t type) 00110 { 00111 00112 if(moviecache && seq) { 00113 seqCacheKey key; 00114 00115 key.seq = seq; 00116 key.context = context; 00117 key.cfra = cfra - seq->start; 00118 key.type = type; 00119 00120 return IMB_moviecache_get(moviecache, &key); 00121 } 00122 00123 return NULL; 00124 } 00125 00126 void seq_stripelem_cache_put( 00127 SeqRenderData context, struct Sequence * seq, 00128 float cfra, seq_stripelem_ibuf_t type, struct ImBuf * i) 00129 { 00130 seqCacheKey key; 00131 00132 if (!i) { 00133 return; 00134 } 00135 00136 if(!moviecache) { 00137 moviecache = IMB_moviecache_create(sizeof(seqCacheKey), seqcache_hashhash, 00138 seqcache_hashcmp, NULL); 00139 } 00140 00141 key.seq = seq; 00142 key.context = context; 00143 key.cfra = cfra - seq->start; 00144 key.type = type; 00145 00146 IMB_moviecache_put(moviecache, &key, i); 00147 }