Tracking: Make frame access cache aware of region
Cache is still kept disabled, need to think of a policy for cache cleanup.
This commit is contained in:
@@ -523,6 +523,8 @@ typedef struct AccessCacheKey {
|
|||||||
int frame;
|
int frame;
|
||||||
int downscale;
|
int downscale;
|
||||||
libmv_InputMode input_mode;
|
libmv_InputMode input_mode;
|
||||||
|
bool has_region;
|
||||||
|
float region_min[2], region_max[2];
|
||||||
int64_t transform_key;
|
int64_t transform_key;
|
||||||
} AccessCacheKey;
|
} AccessCacheKey;
|
||||||
|
|
||||||
@@ -541,10 +543,19 @@ static bool accesscache_hashcmp(const void *a_v, const void *b_v)
|
|||||||
a->frame != b->frame ||
|
a->frame != b->frame ||
|
||||||
a->downscale != b->downscale ||
|
a->downscale != b->downscale ||
|
||||||
a->input_mode != b->input_mode ||
|
a->input_mode != b->input_mode ||
|
||||||
|
a->has_region != b->has_region ||
|
||||||
a->transform_key != b->transform_key)
|
a->transform_key != b->transform_key)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
/* If there is region applied, compare it. */
|
||||||
|
if (a->has_region) {
|
||||||
|
if (!equals_v2v2(a->region_min, b->region_min) ||
|
||||||
|
!equals_v2v2(a->region_max, b->region_max))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,14 +564,25 @@ static void accesscache_put(TrackingImageAccessor *accessor,
|
|||||||
int frame,
|
int frame,
|
||||||
libmv_InputMode input_mode,
|
libmv_InputMode input_mode,
|
||||||
int downscale,
|
int downscale,
|
||||||
|
const libmv_Region *region,
|
||||||
int64_t transform_key,
|
int64_t transform_key,
|
||||||
ImBuf *ibuf)
|
ImBuf *ibuf)
|
||||||
{
|
{
|
||||||
|
/* Currently we don't want global memory limiter to be tossing our cached
|
||||||
|
* frames from tracking context. We are controlling what we want to be cached
|
||||||
|
* from our side.
|
||||||
|
*/
|
||||||
|
ibuf->userflags |= IB_PERSISTENT;
|
||||||
AccessCacheKey key;
|
AccessCacheKey key;
|
||||||
key.clip_index = clip_index;
|
key.clip_index = clip_index;
|
||||||
key.frame = frame;
|
key.frame = frame;
|
||||||
key.input_mode = input_mode;
|
key.input_mode = input_mode;
|
||||||
key.downscale = downscale;
|
key.downscale = downscale;
|
||||||
|
key.has_region = (region != NULL);
|
||||||
|
if (key.has_region) {
|
||||||
|
copy_v2_v2(key.region_min, region->min);
|
||||||
|
copy_v2_v2(key.region_max, region->max);
|
||||||
|
}
|
||||||
key.transform_key = transform_key;
|
key.transform_key = transform_key;
|
||||||
IMB_moviecache_put(accessor->cache, &key, ibuf);
|
IMB_moviecache_put(accessor->cache, &key, ibuf);
|
||||||
}
|
}
|
||||||
@@ -570,6 +592,7 @@ static ImBuf *accesscache_get(TrackingImageAccessor *accessor,
|
|||||||
int frame,
|
int frame,
|
||||||
libmv_InputMode input_mode,
|
libmv_InputMode input_mode,
|
||||||
int downscale,
|
int downscale,
|
||||||
|
const libmv_Region *region,
|
||||||
int64_t transform_key)
|
int64_t transform_key)
|
||||||
{
|
{
|
||||||
AccessCacheKey key;
|
AccessCacheKey key;
|
||||||
@@ -577,6 +600,11 @@ static ImBuf *accesscache_get(TrackingImageAccessor *accessor,
|
|||||||
key.frame = frame;
|
key.frame = frame;
|
||||||
key.input_mode = input_mode;
|
key.input_mode = input_mode;
|
||||||
key.downscale = downscale;
|
key.downscale = downscale;
|
||||||
|
key.has_region = (region != NULL);
|
||||||
|
if (key.has_region) {
|
||||||
|
copy_v2_v2(key.region_min, region->min);
|
||||||
|
copy_v2_v2(key.region_max, region->max);
|
||||||
|
}
|
||||||
key.transform_key = transform_key;
|
key.transform_key = transform_key;
|
||||||
return IMB_moviecache_get(accessor->cache, &key);
|
return IMB_moviecache_get(accessor->cache, &key);
|
||||||
}
|
}
|
||||||
@@ -677,6 +705,7 @@ static ImBuf *accessor_get_ibuf(TrackingImageAccessor *accessor,
|
|||||||
frame,
|
frame,
|
||||||
input_mode,
|
input_mode,
|
||||||
downscale,
|
downscale,
|
||||||
|
region,
|
||||||
transform_key);
|
transform_key);
|
||||||
if (ibuf != NULL) {
|
if (ibuf != NULL) {
|
||||||
return ibuf;
|
return ibuf;
|
||||||
@@ -800,11 +829,8 @@ static ImBuf *accessor_get_ibuf(TrackingImageAccessor *accessor,
|
|||||||
* not the smartest thing in the world, but who cares at this point.
|
* not the smartest thing in the world, but who cares at this point.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* TODO(sergey): Disable cache for now, because we don't store region
|
/* TODO(sergey): Disable cache for now, need some good policy on what to
|
||||||
* in the cache key and can't check whether cached version is usable for
|
* cache and for how long.
|
||||||
* us or not.
|
|
||||||
*
|
|
||||||
* Need to think better about what to cache and when.
|
|
||||||
*/
|
*/
|
||||||
if (false) {
|
if (false) {
|
||||||
accesscache_put(accessor,
|
accesscache_put(accessor,
|
||||||
@@ -812,6 +838,7 @@ static ImBuf *accessor_get_ibuf(TrackingImageAccessor *accessor,
|
|||||||
frame,
|
frame,
|
||||||
input_mode,
|
input_mode,
|
||||||
downscale,
|
downscale,
|
||||||
|
region,
|
||||||
transform_key,
|
transform_key,
|
||||||
final_ibuf);
|
final_ibuf);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user