Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/sequencer/intern/image_cache.c')
-rw-r--r--source/blender/sequencer/intern/image_cache.c161
1 files changed, 69 insertions, 92 deletions
diff --git a/source/blender/sequencer/intern/image_cache.c b/source/blender/sequencer/intern/image_cache.c
index d515a13cdee..40ad70cf9a0 100644
--- a/source/blender/sequencer/intern/image_cache.c
+++ b/source/blender/sequencer/intern/image_cache.c
@@ -48,6 +48,9 @@
#include "BKE_main.h"
#include "BKE_scene.h"
+#include "SEQ_prefetch.h"
+#include "SEQ_relations.h"
+#include "SEQ_render.h"
#include "SEQ_sequencer.h"
#include "image_cache.h"
@@ -144,7 +147,6 @@ typedef struct SeqCache {
struct BLI_mempool *keys_pool;
struct BLI_mempool *items_pool;
struct SeqCacheKey *last_key;
- size_t memory_used;
SeqDiskCache *disk_cache;
} SeqCache;
@@ -793,17 +795,15 @@ static void seq_cache_keyfree(void *val)
static void seq_cache_valfree(void *val)
{
SeqCacheItem *item = (SeqCacheItem *)val;
- SeqCache *cache = item->cache_owner;
if (item->ibuf) {
- cache->memory_used -= IMB_get_size_in_memory(item->ibuf);
IMB_freeImBuf(item->ibuf);
}
BLI_mempool_free(item->cache_owner->items_pool, item);
}
-static void seq_cache_put(SeqCache *cache, SeqCacheKey *key, ImBuf *ibuf)
+static void seq_cache_put_ex(SeqCache *cache, SeqCacheKey *key, ImBuf *ibuf)
{
SeqCacheItem *item;
item = BLI_mempool_alloc(cache->items_pool);
@@ -813,11 +813,10 @@ static void seq_cache_put(SeqCache *cache, SeqCacheKey *key, ImBuf *ibuf)
if (BLI_ghash_reinsert(cache->hash, key, item, seq_cache_keyfree, seq_cache_valfree)) {
IMB_refImBuf(ibuf);
cache->last_key = key;
- cache->memory_used += IMB_get_size_in_memory(ibuf);
}
}
-static ImBuf *seq_cache_get(SeqCache *cache, SeqCacheKey *key)
+static ImBuf *seq_cache_get_ex(SeqCache *cache, SeqCacheKey *key)
{
SeqCacheItem *item = BLI_ghash_lookup(cache->hash, key);
@@ -856,10 +855,9 @@ static SeqCacheKey *seq_cache_choose_key(Scene *scene, SeqCacheKey *lkey, SeqCac
* We could use temp cache as a shield and later make it a non-temporary entry,
* but it is not worth of increasing system complexity.
*/
- if (scene->ed->cache_flag & SEQ_CACHE_PREFETCH_ENABLE &&
- BKE_sequencer_prefetch_job_is_running(scene)) {
+ if (scene->ed->cache_flag & SEQ_CACHE_PREFETCH_ENABLE && seq_prefetch_job_is_running(scene)) {
int pfjob_start, pfjob_end;
- BKE_sequencer_prefetch_get_time_range(scene, &pfjob_start, &pfjob_end);
+ seq_prefetch_get_time_range(scene, &pfjob_start, &pfjob_end);
if (lkey) {
if (lkey->timeline_frame < pfjob_start || lkey->timeline_frame > pfjob_end) {
@@ -940,7 +938,6 @@ static SeqCacheKey *seq_cache_get_item_for_removal(Scene *scene)
GHashIterator gh_iter;
BLI_ghashIterator_init(&gh_iter, cache->hash);
int total_count = 0;
- int cheap_count = 0;
while (!BLI_ghashIterator_done(&gh_iter)) {
key = BLI_ghashIterator_getKey(&gh_iter);
@@ -961,25 +958,22 @@ static SeqCacheKey *seq_cache_get_item_for_removal(Scene *scene)
total_count++;
- if (key->cost <= scene->ed->recycle_max_cost) {
- cheap_count++;
- if (lkey) {
- if (key->timeline_frame < lkey->timeline_frame) {
- lkey = key;
- }
- }
- else {
+ if (lkey) {
+ if (key->timeline_frame < lkey->timeline_frame) {
lkey = key;
}
- if (rkey) {
- if (key->timeline_frame > rkey->timeline_frame) {
- rkey = key;
- }
- }
- else {
+ }
+ else {
+ lkey = key;
+ }
+ if (rkey) {
+ if (key->timeline_frame > rkey->timeline_frame) {
rkey = key;
}
}
+ else {
+ rkey = key;
+ }
}
finalkey = seq_cache_choose_key(scene, lkey, rkey);
@@ -990,9 +984,8 @@ static SeqCacheKey *seq_cache_get_item_for_removal(Scene *scene)
/* Find only "base" keys.
* Sources(other types) for a frame must be freed all at once.
*/
-bool BKE_sequencer_cache_recycle_item(Scene *scene)
+bool seq_cache_recycle_item(Scene *scene)
{
- size_t memory_total = seq_cache_get_mem_total();
SeqCache *cache = seq_cache_get_from_scene(scene);
if (!cache) {
return false;
@@ -1000,7 +993,7 @@ bool BKE_sequencer_cache_recycle_item(Scene *scene)
seq_cache_lock(scene);
- while (cache->memory_used > memory_total) {
+ while (seq_cache_is_full()) {
SeqCacheKey *finalkey = seq_cache_get_item_for_removal(scene);
if (finalkey) {
@@ -1083,7 +1076,7 @@ static void seq_cache_create(Main *bmain, Scene *scene)
/* ***************************** API ****************************** */
-void BKE_sequencer_cache_free_temp_cache(Scene *scene, short id, int timeline_frame)
+void seq_cache_free_temp_cache(Scene *scene, short id, int timeline_frame)
{
SeqCache *cache = seq_cache_get_from_scene(scene);
if (!cache) {
@@ -1111,7 +1104,7 @@ void BKE_sequencer_cache_free_temp_cache(Scene *scene, short id, int timeline_fr
seq_cache_unlock(scene);
}
-void BKE_sequencer_cache_destruct(Scene *scene)
+void seq_cache_destruct(Scene *scene)
{
SeqCache *cache = seq_cache_get_from_scene(scene);
if (!cache) {
@@ -1133,15 +1126,15 @@ void BKE_sequencer_cache_destruct(Scene *scene)
scene->ed->cache = NULL;
}
-void BKE_sequencer_cache_cleanup_all(Main *bmain)
+void seq_cache_cleanup_all(Main *bmain)
{
for (Scene *scene = bmain->scenes.first; scene != NULL; scene = scene->id.next) {
- BKE_sequencer_cache_cleanup(scene);
+ SEQ_cache_cleanup(scene);
}
}
-void BKE_sequencer_cache_cleanup(Scene *scene)
+void SEQ_cache_cleanup(Scene *scene)
{
- BKE_sequencer_prefetch_stop(scene);
+ SEQ_prefetch_stop(scene);
SeqCache *cache = seq_cache_get_from_scene(scene);
if (!cache) {
@@ -1162,11 +1155,11 @@ void BKE_sequencer_cache_cleanup(Scene *scene)
seq_cache_unlock(scene);
}
-void BKE_sequencer_cache_cleanup_sequence(Scene *scene,
- Sequence *seq,
- Sequence *seq_changed,
- int invalidate_types,
- bool force_seq_changed_range)
+void seq_cache_cleanup_sequence(Scene *scene,
+ Sequence *seq,
+ Sequence *seq_changed,
+ int invalidate_types,
+ bool force_seq_changed_range)
{
SeqCache *cache = seq_cache_get_from_scene(scene);
if (!cache) {
@@ -1226,11 +1219,11 @@ void BKE_sequencer_cache_cleanup_sequence(Scene *scene,
seq_cache_unlock(scene);
}
-struct ImBuf *BKE_sequencer_cache_get(const SeqRenderData *context,
- Sequence *seq,
- float timeline_frame,
- int type,
- bool skip_disk_cache)
+struct ImBuf *seq_cache_get(const SeqRenderData *context,
+ Sequence *seq,
+ float timeline_frame,
+ int type,
+ bool skip_disk_cache)
{
if (context->skip_cache || context->is_proxy_render || !seq) {
@@ -1240,9 +1233,9 @@ struct ImBuf *BKE_sequencer_cache_get(const SeqRenderData *context,
Scene *scene = context->scene;
if (context->is_prefetch_render) {
- context = BKE_sequencer_prefetch_get_original_context(context);
+ context = seq_prefetch_get_original_context(context);
scene = context->scene;
- seq = BKE_sequencer_prefetch_get_original_sequence(seq, scene);
+ seq = seq_prefetch_get_original_sequence(seq, scene);
}
if (!seq) {
@@ -1265,7 +1258,7 @@ struct ImBuf *BKE_sequencer_cache_get(const SeqRenderData *context,
key.frame_index = seq_cache_timeline_frame_to_frame_index(seq, timeline_frame, type);
key.type = type;
- ibuf = seq_cache_get(cache, &key);
+ ibuf = seq_cache_get_ex(cache, &key);
}
seq_cache_unlock(scene);
@@ -1284,10 +1277,10 @@ struct ImBuf *BKE_sequencer_cache_get(const SeqRenderData *context,
BLI_mutex_unlock(&cache->disk_cache->read_write_mutex);
if (ibuf) {
if (key.type == SEQ_CACHE_STORE_FINAL_OUT) {
- BKE_sequencer_cache_put_if_possible(context, seq, timeline_frame, type, ibuf, 0.0f, true);
+ seq_cache_put_if_possible(context, seq, timeline_frame, type, ibuf, true);
}
else {
- BKE_sequencer_cache_put(context, seq, timeline_frame, type, ibuf, 0.0f, true);
+ seq_cache_put(context, seq, timeline_frame, type, ibuf, true);
}
}
}
@@ -1295,28 +1288,27 @@ struct ImBuf *BKE_sequencer_cache_get(const SeqRenderData *context,
return ibuf;
}
-bool BKE_sequencer_cache_put_if_possible(const SeqRenderData *context,
- Sequence *seq,
- float timeline_frame,
- int type,
- ImBuf *ibuf,
- float cost,
- bool skip_disk_cache)
+bool seq_cache_put_if_possible(const SeqRenderData *context,
+ Sequence *seq,
+ float timeline_frame,
+ int type,
+ ImBuf *ibuf,
+ bool skip_disk_cache)
{
Scene *scene = context->scene;
if (context->is_prefetch_render) {
- context = BKE_sequencer_prefetch_get_original_context(context);
+ context = seq_prefetch_get_original_context(context);
scene = context->scene;
- seq = BKE_sequencer_prefetch_get_original_sequence(seq, scene);
+ seq = seq_prefetch_get_original_sequence(seq, scene);
}
if (!seq) {
return false;
}
- if (BKE_sequencer_cache_recycle_item(scene)) {
- BKE_sequencer_cache_put(context, seq, timeline_frame, type, ibuf, cost, skip_disk_cache);
+ if (seq_cache_recycle_item(scene)) {
+ seq_cache_put(context, seq, timeline_frame, type, ibuf, skip_disk_cache);
return true;
}
@@ -1325,13 +1317,12 @@ bool BKE_sequencer_cache_put_if_possible(const SeqRenderData *context,
return false;
}
-void BKE_sequencer_cache_put(const SeqRenderData *context,
- Sequence *seq,
- float timeline_frame,
- int type,
- ImBuf *i,
- float cost,
- bool skip_disk_cache)
+void seq_cache_put(const SeqRenderData *context,
+ Sequence *seq,
+ float timeline_frame,
+ int type,
+ ImBuf *i,
+ bool skip_disk_cache)
{
if (i == NULL || context->skip_cache || context->is_proxy_render || !seq) {
return;
@@ -1340,14 +1331,14 @@ void BKE_sequencer_cache_put(const SeqRenderData *context,
Scene *scene = context->scene;
if (context->is_prefetch_render) {
- context = BKE_sequencer_prefetch_get_original_context(context);
+ context = seq_prefetch_get_original_context(context);
scene = context->scene;
- seq = BKE_sequencer_prefetch_get_original_sequence(seq, scene);
+ seq = seq_prefetch_get_original_sequence(seq, scene);
BLI_assert(seq != NULL);
}
/* Prevent reinserting, it breaks cache key linking. */
- ImBuf *test = BKE_sequencer_cache_get(context, seq, timeline_frame, type, true);
+ ImBuf *test = seq_cache_get(context, seq, timeline_frame, type, true);
if (test) {
IMB_freeImBuf(test);
return;
@@ -1373,10 +1364,6 @@ void BKE_sequencer_cache_put(const SeqRenderData *context,
flag = scene->ed->cache_flag;
}
- if (cost > SEQ_CACHE_COST_MAX) {
- cost = SEQ_CACHE_COST_MAX;
- }
-
SeqCacheKey *key;
key = BLI_mempool_alloc(cache->keys_pool);
key->cache_owner = cache;
@@ -1385,7 +1372,6 @@ void BKE_sequencer_cache_put(const SeqRenderData *context,
key->frame_index = seq_cache_timeline_frame_to_frame_index(seq, timeline_frame, type);
key->timeline_frame = timeline_frame;
key->type = type;
- key->cost = cost;
key->link_prev = NULL;
key->link_next = NULL;
key->is_temp_cache = true;
@@ -1398,7 +1384,7 @@ void BKE_sequencer_cache_put(const SeqRenderData *context,
}
SeqCacheKey *temp_last_key = cache->last_key;
- seq_cache_put(cache, key, i);
+ seq_cache_put_ex(cache, key, i);
/* Restore pointer to previous item as this one will be freed when stack is rendered. */
if (key->is_temp_cache) {
@@ -1433,14 +1419,11 @@ void BKE_sequencer_cache_put(const SeqRenderData *context,
}
}
-void BKE_sequencer_cache_iterate(struct Scene *scene,
- void *userdata,
- bool callback_init(void *userdata, size_t item_count),
- bool callback_iter(void *userdata,
- struct Sequence *seq,
- int timeline_frame,
- int cache_type,
- float cost))
+void SEQ_cache_iterate(
+ struct Scene *scene,
+ void *userdata,
+ bool callback_init(void *userdata, size_t item_count),
+ bool callback_iter(void *userdata, struct Sequence *seq, int timeline_frame, int cache_type))
{
SeqCache *cache = seq_cache_get_from_scene(scene);
if (!cache) {
@@ -1457,20 +1440,14 @@ void BKE_sequencer_cache_iterate(struct Scene *scene,
SeqCacheKey *key = BLI_ghashIterator_getKey(&gh_iter);
BLI_ghashIterator_step(&gh_iter);
- interrupt = callback_iter(userdata, key->seq, key->timeline_frame, key->type, key->cost);
+ interrupt = callback_iter(userdata, key->seq, key->timeline_frame, key->type);
}
cache->last_key = NULL;
seq_cache_unlock(scene);
}
-bool BKE_sequencer_cache_is_full(Scene *scene)
+bool seq_cache_is_full(void)
{
- size_t memory_total = seq_cache_get_mem_total();
- SeqCache *cache = seq_cache_get_from_scene(scene);
- if (!cache) {
- return false;
- }
-
- return memory_total < cache->memory_used;
+ return seq_cache_get_mem_total() < MEM_get_memory_in_use();
}