Blender  V3.3
Classes | Macros | Typedefs | Functions | Variables
image_cache.c File Reference
#include <memory.h>
#include <stddef.h>
#include <time.h>
#include "MEM_guardedalloc.h"
#include "DNA_scene_types.h"
#include "DNA_sequence_types.h"
#include "DNA_space_types.h"
#include "IMB_colormanagement.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "BLI_blenlib.h"
#include "BLI_endian_defines.h"
#include "BLI_endian_switch.h"
#include "BLI_fileops.h"
#include "BLI_fileops_types.h"
#include "BLI_ghash.h"
#include "BLI_listbase.h"
#include "BLI_mempool.h"
#include "BLI_path_util.h"
#include "BLI_threads.h"
#include "BKE_main.h"
#include "BKE_scene.h"
#include "SEQ_prefetch.h"
#include "SEQ_relations.h"
#include "SEQ_sequencer.h"
#include "SEQ_time.h"
#include "disk_cache.h"
#include "image_cache.h"
#include "prefetch.h"
#include "strip_time.h"

Go to the source code of this file.

Classes

struct  SeqCache
 
struct  SeqCacheItem
 

Macros

#define THUMB_CACHE_LIMIT   5000
 

Typedefs

typedef struct SeqCache SeqCache
 
typedef struct SeqCacheItem SeqCacheItem
 

Functions

static bool seq_cmp_render_data (const SeqRenderData *a, const SeqRenderData *b)
 
static unsigned int seq_hash_render_data (const SeqRenderData *a)
 
static unsigned int seq_cache_hashhash (const void *key_)
 
static bool seq_cache_hashcmp (const void *a_, const void *b_)
 
static float seq_cache_timeline_frame_to_frame_index (Scene *scene, Sequence *seq, float timeline_frame, int type)
 
float seq_cache_frame_index_to_timeline_frame (Sequence *seq, float frame_index)
 
static SeqCacheseq_cache_get_from_scene (Scene *scene)
 
static void seq_cache_lock (Scene *scene)
 
static void seq_cache_unlock (Scene *scene)
 
static size_t seq_cache_get_mem_total (void)
 
static void seq_cache_keyfree (void *val)
 
static void seq_cache_valfree (void *val)
 
static int get_stored_types_flag (Scene *scene, SeqCacheKey *key)
 
static void seq_cache_put_ex (Scene *scene, SeqCacheKey *key, ImBuf *ibuf)
 
static ImBufseq_cache_get_ex (SeqCache *cache, SeqCacheKey *key)
 
static void seq_cache_relink_keys (SeqCacheKey *link_next, SeqCacheKey *link_prev)
 
static SeqCacheKeyseq_cache_choose_key (Scene *scene, SeqCacheKey *lkey, SeqCacheKey *rkey)
 
static void seq_cache_recycle_linked (Scene *scene, SeqCacheKey *base)
 
static SeqCacheKeyseq_cache_get_item_for_removal (Scene *scene)
 
bool seq_cache_recycle_item (Scene *scene)
 
static void seq_cache_set_temp_cache_linked (Scene *scene, SeqCacheKey *base)
 
static void seq_cache_create (Main *bmain, Scene *scene)
 
static void seq_cache_populate_key (SeqCacheKey *key, const SeqRenderData *context, Sequence *seq, const float timeline_frame, const int type)
 
static SeqCacheKeyseq_cache_allocate_key (SeqCache *cache, const SeqRenderData *context, Sequence *seq, const float timeline_frame, const int type)
 
void seq_cache_free_temp_cache (Scene *scene, short id, int timeline_frame)
 
void seq_cache_destruct (Scene *scene)
 
void seq_cache_cleanup_all (Main *bmain)
 
void SEQ_cache_cleanup (Scene *scene)
 
void seq_cache_cleanup_sequence (Scene *scene, Sequence *seq, Sequence *seq_changed, int invalidate_types, bool force_seq_changed_range)
 
void seq_cache_thumbnail_cleanup (Scene *scene, rctf *view_area_safe)
 
struct ImBufseq_cache_get (const SeqRenderData *context, Sequence *seq, float timeline_frame, int type)
 
bool seq_cache_put_if_possible (const SeqRenderData *context, Sequence *seq, float timeline_frame, int type, ImBuf *ibuf)
 
void seq_cache_thumbnail_put (const SeqRenderData *context, Sequence *seq, float timeline_frame, ImBuf *i, rctf *view_area)
 
void seq_cache_put (const SeqRenderData *context, Sequence *seq, float timeline_frame, int type, ImBuf *i)
 
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))
 
bool seq_cache_is_full (void)
 

Variables

static ThreadMutex cache_create_lock = BLI_MUTEX_INITIALIZER
 

Macro Definition Documentation

◆ THUMB_CACHE_LIMIT

#define THUMB_CACHE_LIMIT   5000

Sequencer Cache Design Notes

Function: All images created during rendering are added to cache, even if the cache is already full. This is because:

  • One image may be needed multiple times during rendering.
  • Keeping the last rendered frame allows us for faster re-render when user edits strip in stack.
  • We can decide if we keep frame only when it's completely rendered. Otherwise we risk having "holes" in the cache, which can be annoying.

If the cache is full all entries for pending frame will have is_temp_cache set.

Linking: We use links to reduce number of iterations over entries needed to manage cache. Entries are linked in order as they are put into cache. Only permanent (is_temp_cache = 0) cache entries are linked. Putting SEQ_CACHE_STORE_FINAL_OUT will reset linking

Only entire frame can be freed to release resources for new entries (recycling). Once again, this is to reduce number of iterations, but also more controllable than removing entries one by one in reverse order to their creation.

User can exclude caching of some images. Such entries will have is_temp_cache set.

Definition at line 72 of file image_cache.c.

Typedef Documentation

◆ SeqCache

typedef struct SeqCache SeqCache

◆ SeqCacheItem

typedef struct SeqCacheItem SeqCacheItem

Function Documentation

◆ get_stored_types_flag()

static int get_stored_types_flag ( Scene scene,
SeqCacheKey key 
)
static

◆ seq_cache_allocate_key()

static SeqCacheKey* seq_cache_allocate_key ( SeqCache cache,
const SeqRenderData context,
Sequence seq,
const float  timeline_frame,
const int  type 
)
static

◆ seq_cache_choose_key()

static SeqCacheKey* seq_cache_choose_key ( Scene scene,
SeqCacheKey lkey,
SeqCacheKey rkey 
)
static

◆ SEQ_cache_cleanup()

void SEQ_cache_cleanup ( Scene scene)

◆ seq_cache_cleanup_all()

void seq_cache_cleanup_all ( Main bmain)

Definition at line 596 of file image_cache.c.

References ListBase::first, Scene::id, ID::next, NULL, scene, Main::scenes, and SEQ_cache_cleanup().

◆ seq_cache_cleanup_sequence()

void seq_cache_cleanup_sequence ( Scene scene,
Sequence seq,
Sequence seq_changed,
int  invalidate_types,
bool  force_seq_changed_range 
)

◆ seq_cache_create()

static void seq_cache_create ( Main bmain,
Scene scene 
)
static

◆ seq_cache_destruct()

void seq_cache_destruct ( Scene scene)

◆ seq_cache_frame_index_to_timeline_frame()

float seq_cache_frame_index_to_timeline_frame ( Sequence seq,
float  frame_index 
)

Definition at line 151 of file image_cache.c.

References SEQ_time_start_frame_get().

Referenced by seq_disk_cache_delete_invalid_files().

◆ seq_cache_free_temp_cache()

void seq_cache_free_temp_cache ( Scene scene,
short  id,
int  timeline_frame 
)

◆ seq_cache_get()

struct ImBuf* seq_cache_get ( const SeqRenderData context,
Sequence seq,
float  timeline_frame,
int  type 
)

◆ seq_cache_get_ex()

static ImBuf* seq_cache_get_ex ( SeqCache cache,
SeqCacheKey key 
)
static

Definition at line 261 of file image_cache.c.

References BLI_ghash_lookup(), SeqCache::hash, SeqCacheItem::ibuf, IMB_refImBuf(), and NULL.

Referenced by seq_cache_get().

◆ seq_cache_get_from_scene()

static SeqCache* seq_cache_get_from_scene ( Scene scene)
static

◆ seq_cache_get_item_for_removal()

static SeqCacheKey* seq_cache_get_item_for_removal ( Scene scene)
static

◆ seq_cache_get_mem_total()

static size_t seq_cache_get_mem_total ( void  )
static

Definition at line 183 of file image_cache.c.

Referenced by seq_cache_is_full().

◆ seq_cache_hashcmp()

static bool seq_cache_hashcmp ( const void a_,
const void b_ 
)
static

Definition at line 127 of file image_cache.c.

References Freestyle::a, usdtokens::b(), and seq_cmp_render_data().

Referenced by seq_cache_create().

◆ seq_cache_hashhash()

static unsigned int seq_cache_hashhash ( const void key_)
static

◆ seq_cache_is_full()

bool seq_cache_is_full ( void  )

◆ SEQ_cache_iterate()

void SEQ_cache_iterate ( struct Scene scene,
void userdata,
bool   callback_initvoid *userdata, size_t item_count,
bool   callback_itervoid *userdata, struct Sequence *seq, int timeline_frame, int cache_type 
)

◆ seq_cache_keyfree()

static void seq_cache_keyfree ( void val)
static

◆ seq_cache_lock()

static void seq_cache_lock ( Scene scene)
static

◆ seq_cache_populate_key()

static void seq_cache_populate_key ( SeqCacheKey key,
const SeqRenderData context,
Sequence seq,
const float  timeline_frame,
const int  type 
)
static

◆ seq_cache_put()

void seq_cache_put ( const SeqRenderData context,
Sequence seq,
float  timeline_frame,
int  type,
ImBuf i 
)

◆ seq_cache_put_ex()

static void seq_cache_put_ex ( Scene scene,
SeqCacheKey key,
ImBuf ibuf 
)
static

◆ seq_cache_put_if_possible()

bool seq_cache_put_if_possible ( const SeqRenderData context,
Sequence seq,
float  timeline_frame,
int  type,
ImBuf ibuf 
)

◆ seq_cache_recycle_item()

bool seq_cache_recycle_item ( struct Scene scene)

Find only "base" keys. Sources(other types) for a frame must be freed all at once.

Definition at line 446 of file image_cache.c.

References scene, seq_cache_get_from_scene(), seq_cache_get_item_for_removal(), seq_cache_is_full(), seq_cache_lock(), seq_cache_recycle_linked(), and seq_cache_unlock().

Referenced by seq_cache_get(), seq_cache_put_if_possible(), and seq_prefetch_is_cache_full().

◆ seq_cache_recycle_linked()

static void seq_cache_recycle_linked ( Scene scene,
SeqCacheKey base 
)
static

◆ seq_cache_relink_keys()

static void seq_cache_relink_keys ( SeqCacheKey link_next,
SeqCacheKey link_prev 
)
static

Definition at line 274 of file image_cache.c.

References SeqCacheKey::link_next, and SeqCacheKey::link_prev.

Referenced by seq_cache_cleanup_sequence().

◆ seq_cache_set_temp_cache_linked()

static void seq_cache_set_temp_cache_linked ( Scene scene,
SeqCacheKey base 
)
static

◆ seq_cache_thumbnail_cleanup()

void seq_cache_thumbnail_cleanup ( Scene scene,
rctf view_area_safe 
)

◆ seq_cache_thumbnail_put()

void seq_cache_thumbnail_put ( const SeqRenderData context,
Sequence seq,
float  timeline_frame,
ImBuf i,
rctf view_area 
)

◆ seq_cache_timeline_frame_to_frame_index()

static float seq_cache_timeline_frame_to_frame_index ( Scene scene,
Sequence seq,
float  timeline_frame,
int  type 
)
static

◆ seq_cache_unlock()

static void seq_cache_unlock ( Scene scene)
static

◆ seq_cache_valfree()

static void seq_cache_valfree ( void val)
static

◆ seq_cmp_render_data()

static bool seq_cmp_render_data ( const SeqRenderData a,
const SeqRenderData b 
)
static

Definition at line 92 of file image_cache.c.

References Freestyle::a, and usdtokens::b().

Referenced by seq_cache_hashcmp().

◆ seq_hash_render_data()

static unsigned int seq_hash_render_data ( const SeqRenderData a)
static

Definition at line 101 of file image_cache.c.

References Freestyle::a.

Referenced by seq_cache_hashhash().

Variable Documentation

◆ cache_create_lock

ThreadMutex cache_create_lock = BLI_MUTEX_INITIALIZER
static

Definition at line 90 of file image_cache.c.

Referenced by seq_cache_create().