MovieCache implementation
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 24 Oct 2011 17:12:28 +0000 (17:12 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 24 Oct 2011 17:12:28 +0000 (17:12 +0000)
Implementation of cache for general movie-related areas
such as sequencer and clip editor (in the future)

Some changes in limiter were necessary:
- Limiter counted mapped memory twice when was checking how many memory is used.
- It was using "global" memory usage not memory usage by cached elements.
  It will cause big problems when there's large mesh or plenty of undo steps are
  in memory nothing would be cached in sequencer.
- To solve this problem introduced "callback" to measure cached element size.
  It could be not very accurate in general, but it works well for image buffers.
  And if this callback isn't set old-school memory usage check would be used.
- The whole cache used to get freed when memory limit exceeded, now it'll drop only
  as much elements as necessary to reduce memory usage.

Seqcache is switched to use this new cache code.

source/blender/imbuf/CMakeLists.txt
source/blender/imbuf/intern/allocimbuf.c

index a03d6ce..1b190ae 100644 (file)
 #
 # ***** END GPL LICENSE BLOCK *****
 
+if(WITH_CODEC_FFMPEG)
+       # FFMPEG gives warnigns which are hard to avoid across multiple versions.
+       remove_strict_flags()
+endif()
+
 set(INC 
        .
        ../avi
@@ -155,12 +160,6 @@ if(WITH_CODEC_FFMPEG)
                ${FFMPEG_INCLUDE_DIRS}
        )
        add_definitions(-DWITH_FFMPEG)
-
-       remove_strict_flags_file(
-               intern/indexer.c
-               intern/util.c
-               intern/anim_movie.c
-       )
 endif()
 
 if(WITH_IMAGE_DDS)
index 1d82c86..da08671 100644 (file)
@@ -164,9 +164,8 @@ void IMB_freeImBuf(ImBuf *ibuf)
                        IMB_freezbufImBuf(ibuf);
                        IMB_freezbuffloatImBuf(ibuf);
                        freeencodedbufferImBuf(ibuf);
+                       IMB_cache_limiter_unmanage(ibuf);
                        IMB_metadata_free(ibuf);
-                       if (ibuf->dds_data.data != NULL)
-                               free(ibuf->dds_data.data);
                        MEM_freeN(ibuf);
                }
        }
@@ -472,3 +471,56 @@ static MEM_CacheLimiterC **get_imbuf_cache_limiter(void)
 
        return &c;
 }
+
+void IMB_free_cache_limiter(void)
+{
+       delete_MEM_CacheLimiter(*get_imbuf_cache_limiter());
+       *get_imbuf_cache_limiter() = NULL;
+}
+
+void IMB_cache_limiter_insert(ImBuf *i)
+{
+       if(!i->c_handle) {
+               i->c_handle = MEM_CacheLimiter_insert(
+                       *get_imbuf_cache_limiter(), i);
+               MEM_CacheLimiter_ref(i->c_handle);
+               MEM_CacheLimiter_enforce_limits(
+                       *get_imbuf_cache_limiter());
+               MEM_CacheLimiter_unref(i->c_handle);
+       }
+}
+
+void IMB_cache_limiter_unmanage(ImBuf *i)
+{
+       if(i->c_handle) {
+               MEM_CacheLimiter_unmanage(i->c_handle);
+               i->c_handle = NULL;
+       }
+}
+
+void IMB_cache_limiter_touch(ImBuf *i)
+{
+       if(i->c_handle)
+               MEM_CacheLimiter_touch(i->c_handle);
+}
+
+void IMB_cache_limiter_ref(ImBuf *i)
+{
+       if(i->c_handle)
+               MEM_CacheLimiter_ref(i->c_handle);
+}
+
+void IMB_cache_limiter_unref(ImBuf *i)
+{
+       if(i->c_handle)
+               MEM_CacheLimiter_unref(i->c_handle);
+}
+
+int IMB_cache_limiter_get_refcount(ImBuf *i)
+{
+       if(i->c_handle)
+               return MEM_CacheLimiter_get_refcount(i->c_handle);
+
+       return 0;
+}
+