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:
authorSergey Sharybin <sergey.vfx@gmail.com>2013-12-10 12:40:09 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2013-12-22 12:44:56 +0400
commit78698a2ecf9d17340ce337ecf73ce6e355299f89 (patch)
treeb25d5e7a6b53a3c51733b5319b0b9535e037bf6a /intern/memutil/MEM_CacheLimiter.h
parentc7a970a78eab2dea902b202d583fa98f70b54ba3 (diff)
Add ItemDestroyable to the cache limitor
This callback is used when cache limiter needs to remove some cached objects when running out of limit. From blender side it's used to keep painted images always in memory. This fixes issue when painted images were removing from the memory after image cache rewrite.
Diffstat (limited to 'intern/memutil/MEM_CacheLimiter.h')
-rw-r--r--intern/memutil/MEM_CacheLimiter.h23
1 files changed, 21 insertions, 2 deletions
diff --git a/intern/memutil/MEM_CacheLimiter.h b/intern/memutil/MEM_CacheLimiter.h
index 32f97a21815..88e06833b4a 100644
--- a/intern/memutil/MEM_CacheLimiter.h
+++ b/intern/memutil/MEM_CacheLimiter.h
@@ -137,6 +137,7 @@ class MEM_CacheLimiter {
public:
typedef size_t (*MEM_CacheLimiter_DataSize_Func) (void *data);
typedef int (*MEM_CacheLimiter_ItemPriority_Func) (void *item, int default_priority);
+ typedef bool (*MEM_CacheLimiter_ItemDestroyable_Func) (void *item);
MEM_CacheLimiter(MEM_CacheLimiter_DataSize_Func data_size_func)
: data_size_func(data_size_func) {
@@ -230,11 +231,28 @@ public:
this->item_priority_func = item_priority_func;
}
+ void set_item_destroyable_func(MEM_CacheLimiter_ItemDestroyable_Func item_destroyable_func) {
+ this->item_destroyable_func = item_destroyable_func;
+ }
+
private:
typedef MEM_CacheLimiterHandle<T> *MEM_CacheElementPtr;
typedef std::list<MEM_CacheElementPtr, MEM_Allocator<MEM_CacheElementPtr> > MEM_CacheQueue;
typedef typename MEM_CacheQueue::iterator iterator;
+ /* Check whether element can be destroyed when enforcing cache limits */
+ bool can_destroy_element(MEM_CacheElementPtr &elem) {
+ if (!elem->can_destroy()) {
+ /* Element is referenced */
+ return false;
+ }
+ if (item_destroyable_func) {
+ if (!item_destroyable_func(elem->get()->get_data()))
+ return false;
+ }
+ return true;
+ }
+
MEM_CacheElementPtr get_least_priority_destroyable_element(void) {
if (queue.empty())
return NULL;
@@ -244,7 +262,7 @@ private:
if (!item_priority_func) {
for (iterator it = queue.begin(); it != queue.end(); it++) {
MEM_CacheElementPtr elem = *it;
- if (!elem->can_destroy())
+ if (!can_destroy_element(elem))
continue;
best_match_elem = elem;
break;
@@ -258,7 +276,7 @@ private:
for (it = queue.begin(), i = 0; it != queue.end(); it++, i++) {
MEM_CacheElementPtr elem = *it;
- if (!elem->can_destroy())
+ if (!can_destroy_element(elem))
continue;
/* by default 0 means highest priority element */
@@ -280,6 +298,7 @@ private:
MEM_CacheQueue queue;
MEM_CacheLimiter_DataSize_Func data_size_func;
MEM_CacheLimiter_ItemPriority_Func item_priority_func;
+ MEM_CacheLimiter_ItemDestroyable_Func item_destroyable_func;
};
#endif // __MEM_CACHELIMITER_H__