[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55774] trunk/blender/source/blender: Changes to cache invalidation policy for movie clips

Sergey Sharybin sergey.vfx at gmail.com
Thu Apr 4 11:50:51 CEST 2013


Revision: 55774
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55774
Author:   nazgul
Date:     2013-04-04 09:50:51 +0000 (Thu, 04 Apr 2013)
Log Message:
-----------
Changes to cache invalidation policy for movie clips

- When changing clip in clip editor, remove all frames
  from it's cache to free memory for new clip.

- When changing proxy render settings, free cache as well.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_movieclip.h
    trunk/blender/source/blender/blenkernel/intern/movieclip.c
    trunk/blender/source/blender/editors/space_clip/clip_editor.c
    trunk/blender/source/blender/makesrna/intern/rna_movieclip.c

Modified: trunk/blender/source/blender/blenkernel/BKE_movieclip.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_movieclip.h	2013-04-04 09:50:38 UTC (rev 55773)
+++ trunk/blender/source/blender/blenkernel/BKE_movieclip.h	2013-04-04 09:50:51 UTC (rev 55774)
@@ -45,6 +45,7 @@
 
 struct MovieClip *BKE_movieclip_file_add(struct Main *bmain, const char *name);
 void BKE_movieclip_reload(struct MovieClip *clip);
+void BKE_movieclip_clear_cache(struct MovieClip *clip);
 
 struct ImBuf *BKE_movieclip_get_ibuf(struct MovieClip *clip, struct MovieClipUser *user);
 struct ImBuf *BKE_movieclip_get_postprocessed_ibuf(struct MovieClip *clip, struct MovieClipUser *user, int postprocess_flag);

Modified: trunk/blender/source/blender/blenkernel/intern/movieclip.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/movieclip.c	2013-04-04 09:50:38 UTC (rev 55773)
+++ trunk/blender/source/blender/blenkernel/intern/movieclip.c	2013-04-04 09:50:51 UTC (rev 55774)
@@ -1162,6 +1162,11 @@
 	BKE_free_animdata((ID *) clip);
 }
 
+void BKE_movieclip_clear_cache(MovieClip *clip)
+{
+	free_buffers(clip);
+}
+
 void BKE_movieclip_reload(MovieClip *clip)
 {
 	/* clear cache */

Modified: trunk/blender/source/blender/editors/space_clip/clip_editor.c
===================================================================
--- trunk/blender/source/blender/editors/space_clip/clip_editor.c	2013-04-04 09:50:38 UTC (rev 55773)
+++ trunk/blender/source/blender/editors/space_clip/clip_editor.c	2013-04-04 09:50:51 UTC (rev 55774)
@@ -528,6 +528,7 @@
 void ED_space_clip_set_clip(bContext *C, bScreen *screen, SpaceClip *sc, MovieClip *clip)
 {
 	MovieClip *old_clip;
+	bool old_clip_visible = false;
 
 	if (!screen && C)
 		screen = CTX_wm_screen(C);
@@ -546,16 +547,27 @@
 				if (sl->spacetype == SPACE_CLIP) {
 					SpaceClip *cur_sc = (SpaceClip *) sl;
 
-					if (cur_sc != sc && cur_sc->view != SC_VIEW_CLIP) {
-						if (cur_sc->clip == old_clip || cur_sc->clip == NULL) {
-							cur_sc->clip = clip;
+					if (cur_sc != sc) {
+						if (cur_sc->view == SC_VIEW_CLIP) {
+							if (cur_sc->clip == old_clip)
+								old_clip_visible = true;
 						}
+						else {
+							if (cur_sc->clip == old_clip || cur_sc->clip == NULL) {
+								cur_sc->clip = clip;
+							}
+						}
 					}
 				}
 			}
 		}
 	}
 
+	/* If clip is no longer visible on screen, free memory used by it's cache */
+	if (old_clip && old_clip != clip && !old_clip_visible) {
+		BKE_movieclip_clear_cache(old_clip);
+	}
+
 	if (C)
 		WM_event_add_notifier(C, NC_MOVIECLIP | NA_SELECTED, sc->clip);
 }

Modified: trunk/blender/source/blender/makesrna/intern/rna_movieclip.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_movieclip.c	2013-04-04 09:50:38 UTC (rev 55773)
+++ trunk/blender/source/blender/makesrna/intern/rna_movieclip.c	2013-04-04 09:50:51 UTC (rev 55774)
@@ -49,6 +49,11 @@
 
 #include "BKE_depsgraph.h"
 
+#include "ED_clip.h"
+
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+
 static void rna_MovieClip_reload_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
 	MovieClip *clip = (MovieClip *)ptr->id.data;
@@ -65,6 +70,39 @@
 	values[1] = clip->lastsize[1];
 }
 
+static void rna_MovieClipUser_proxy_render_settings_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+	ID *id = (ID *) ptr->id.data;
+	MovieClipUser *user = (MovieClipUser *) ptr->data;
+
+	/* when changing render settings of space clip user
+	 * clear cache for clip, so all the memory is available
+	 * for new render settings
+	 */
+	if (GS(id->name) == ID_SCR) {
+		bScreen *screen = (bScreen *) id;
+		ScrArea *area;
+		SpaceLink *sl;
+
+		for (area = screen->areabase.first; area; area = area->next) {
+			for (sl = area->spacedata.first; sl; sl = sl->next) {
+				if (sl->spacetype == SPACE_CLIP) {
+					SpaceClip *sc = (SpaceClip *) sl;
+
+					if (&sc->user == user) {
+						MovieClip *clip = ED_space_clip_get_clip(sc);
+
+						if (clip && (clip->flag & MCLIP_USE_PROXY))
+							BKE_movieclip_clear_cache(clip);
+
+						break;
+					}
+				}
+			}
+		}
+	}
+}
+
 #else
 
 static void rna_def_movieclip_proxy(BlenderRNA *brna)
@@ -197,13 +235,13 @@
 	RNA_def_property_enum_items(prop, clip_render_size_items);
 	RNA_def_property_ui_text(prop, "Proxy render size",
 	                         "Draw preview using full resolution or different proxy resolutions");
-	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);
+	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_MovieClipUser_proxy_render_settings_update");
 
 	/* render undistorted */
 	prop = RNA_def_property(srna, "use_render_undistorted", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "render_flag", MCLIP_PROXY_RENDER_UNDISTORT);
 	RNA_def_property_ui_text(prop, "Render Undistorted", "Render preview using undistorted proxy");
-	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);
+	RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, "rna_MovieClipUser_proxy_render_settings_update");
 }
 
 static void rna_def_movieClipScopes(BlenderRNA *brna)




More information about the Bf-blender-cvs mailing list