[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14898] branches/apricot: Apricot Branch

Brecht Van Lommel brechtvanlommel at pandora.be
Mon May 19 20:37:32 CEST 2008


Revision: 14898
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14898
Author:   blendix
Date:     2008-05-19 20:37:31 +0200 (Mon, 19 May 2008)

Log Message:
-----------
Apricot Branch
==============

- Memory usage limit for undo, specified in megabytes, the default 0
  means unlimited.
- Multiple undo levels for image painting. Works separate from global
  undo similar to editmode undo, and undo for multiple images is
  supported.

Modified Paths:
--------------
    branches/apricot/intern/guardedalloc/MEM_guardedalloc.h
    branches/apricot/intern/guardedalloc/intern/mallocn.c
    branches/apricot/intern/memutil/MEM_CacheLimiter.h
    branches/apricot/intern/memutil/intern/MEM_CacheLimiterC-Api.cpp
    branches/apricot/source/blender/blenkernel/intern/blender.c
    branches/apricot/source/blender/blenlib/BLI_blenlib.h
    branches/apricot/source/blender/include/BDR_imagepaint.h
    branches/apricot/source/blender/makesdna/DNA_userdef_types.h
    branches/apricot/source/blender/render/intern/source/pipeline.c
    branches/apricot/source/blender/src/editlattice.c
    branches/apricot/source/blender/src/editmode_undo.c
    branches/apricot/source/blender/src/header_image.c
    branches/apricot/source/blender/src/header_info.c
    branches/apricot/source/blender/src/header_view3d.c
    branches/apricot/source/blender/src/imagepaint.c
    branches/apricot/source/blender/src/playanim.c
    branches/apricot/source/blender/src/renderwin.c
    branches/apricot/source/blender/src/sequence.c
    branches/apricot/source/blender/src/space.c
    branches/apricot/source/blender/src/usiblender.c

Modified: branches/apricot/intern/guardedalloc/MEM_guardedalloc.h
===================================================================
--- branches/apricot/intern/guardedalloc/MEM_guardedalloc.h	2008-05-19 14:16:18 UTC (rev 14897)
+++ branches/apricot/intern/guardedalloc/MEM_guardedalloc.h	2008-05-19 18:37:31 UTC (rev 14898)
@@ -123,6 +123,12 @@
 	/** Attempt to enforce OSX (or other OS's) to have malloc and stack nonzero */
 	void MEM_set_memory_debug(void);
 
+	/* Memory usage stats
+	 * - MEM_get_memory_in_use is all memory
+	 * - MEM_get_mapped_memory_in_use is a subset of all memory */
+	unsigned long MEM_get_memory_in_use(void);
+	unsigned long MEM_get_mapped_memory_in_use(void);
+	int MEM_get_memory_blocks_in_use(void);
 
 #ifdef __cplusplus
 }

Modified: branches/apricot/intern/guardedalloc/intern/mallocn.c
===================================================================
--- branches/apricot/intern/guardedalloc/intern/mallocn.c	2008-05-19 14:16:18 UTC (rev 14897)
+++ branches/apricot/intern/guardedalloc/intern/mallocn.c	2008-05-19 18:37:31 UTC (rev 14898)
@@ -111,8 +111,8 @@
 /* --------------------------------------------------------------------- */
 	
 
-volatile int totblock= 0;
-volatile unsigned long mem_in_use= 0, mmap_in_use= 0;
+static volatile int totblock= 0;
+static volatile unsigned long mem_in_use= 0, mmap_in_use= 0;
 
 static volatile struct localListBase _membase;
 static volatile struct localListBase *membase = &_membase;
@@ -696,4 +696,19 @@
 	return(name);
 }
 
+unsigned long MEM_get_memory_in_use(void)
+{
+	return mem_in_use;
+}
+
+unsigned long MEM_get_mapped_memory_in_use(void)
+{
+	return mmap_in_use;
+}
+
+int MEM_get_memory_blocks_in_use(void)
+{
+	return totblock;
+}
+
 /* eof */

Modified: branches/apricot/intern/memutil/MEM_CacheLimiter.h
===================================================================
--- branches/apricot/intern/memutil/MEM_CacheLimiter.h	2008-05-19 14:16:18 UTC (rev 14897)
+++ branches/apricot/intern/memutil/MEM_CacheLimiter.h	2008-05-19 18:37:31 UTC (rev 14898)
@@ -61,11 +61,8 @@
 
 #ifndef __MEM_cache_limiter_c_api_h_included__
 extern "C" {
-	extern void MEM_CacheLimiter_set_maximum(int m);
-	extern int MEM_CacheLimiter_get_maximum();
-        // this is rather _ugly_!
-        extern int mem_in_use;
-	extern int mmap_in_use;
+	extern void MEM_CacheLimiter_set_maximum(unsigned long m);
+	extern unsigned long MEM_CacheLimiter_get_maximum();
 };
 #endif
 
@@ -141,7 +138,10 @@
 		delete handle;
 	}
 	void enforce_limits() {
-		int max = MEM_CacheLimiter_get_maximum();
+		unsigned long max = MEM_CacheLimiter_get_maximum();
+		unsigned long mem_in_use= MEM_get_memory_in_use();
+		unsigned long mmap_in_use= MEM_get_mapped_memory_in_use();
+
 		if (max == 0) {
 			return;
 		}

Modified: branches/apricot/intern/memutil/intern/MEM_CacheLimiterC-Api.cpp
===================================================================
--- branches/apricot/intern/memutil/intern/MEM_CacheLimiterC-Api.cpp	2008-05-19 14:16:18 UTC (rev 14897)
+++ branches/apricot/intern/memutil/intern/MEM_CacheLimiterC-Api.cpp	2008-05-19 18:37:31 UTC (rev 14898)
@@ -27,18 +27,18 @@
 #include "MEM_CacheLimiter.h"
 #include "MEM_CacheLimiterC-Api.h"
 
-static int & get_max() 
+static unsigned long & get_max() 
 {
-	static int m = 32*1024*1024;
+	static unsigned long m = 32*1024*1024;
 	return m;
 }
 
-void MEM_CacheLimiter_set_maximum(int m)
+void MEM_CacheLimiter_set_maximum(unsigned long m)
 {
 	get_max() = m;
 }
 
-int MEM_CacheLimiter_get_maximum()
+unsigned long MEM_CacheLimiter_get_maximum()
 {
 	return get_max();
 }

Modified: branches/apricot/source/blender/blenkernel/intern/blender.c
===================================================================
--- branches/apricot/source/blender/blenkernel/intern/blender.c	2008-05-19 14:16:18 UTC (rev 14897)
+++ branches/apricot/source/blender/blenkernel/intern/blender.c	2008-05-19 18:37:31 UTC (rev 14898)
@@ -525,6 +525,7 @@
 	char str[FILE_MAXDIR+FILE_MAXFILE];
 	char name[MAXUNDONAME];
 	MemFile memfile;
+	unsigned long undosize;
 } UndoElem;
 
 static ListBase undobase={NULL, NULL};
@@ -555,6 +556,7 @@
 /* name can be a dynamic string */
 void BKE_write_undo(char *name)
 {
+	unsigned long maxmem, totmem, memused;
 	int nr, success;
 	UndoElem *uel;
 	
@@ -616,9 +618,37 @@
 		
 		if(curundo->prev) prevfile= &(curundo->prev->memfile);
 		
+		memused= MEM_get_memory_in_use();
 		success= BLO_write_file_mem(prevfile, &curundo->memfile, G.fileflags, &err);
-		
+		curundo->undosize= MEM_get_memory_in_use() - memused;
 	}
+
+	if(U.undomemory != 0) {
+		/* limit to maximum memory (afterwards, we can't know in advance) */
+		totmem= 0;
+		maxmem= ((unsigned long)U.undomemory)*1024*1024;
+
+		/* keep at least two (original + other) */
+		uel= undobase.last;
+		while(uel && uel->prev) {
+			totmem+= uel->undosize;
+			if(totmem>maxmem) break;
+			uel= uel->prev;
+		}
+
+		if(uel) {
+			if(uel->prev && uel->prev->prev)
+				uel= uel->prev;
+
+			while(undobase.first!=uel) {
+				UndoElem *first= undobase.first;
+				BLI_remlink(&undobase, first);
+				/* the merge is because of compression */
+				BLO_merge_memfile(&first->memfile, &first->next->memfile);
+				MEM_freeN(first);
+			}
+		}
+	}
 }
 
 /* 1= an undo, -1 is a redo. we have to make sure 'curundo' remains at current situation */
@@ -682,14 +712,14 @@
 	UndoElem *uel;
 	DynStr *ds= BLI_dynstr_new();
 	char *menu;
-	
+
 	BLI_dynstr_append(ds, "Global Undo History %t");
 	
 	for(uel= undobase.first; uel; uel= uel->next) {
 		BLI_dynstr_append(ds, "|");
 		BLI_dynstr_append(ds, uel->name);
 	}
-	
+
 	menu= BLI_dynstr_get_cstring(ds);
 	BLI_dynstr_free(ds);
 

Modified: branches/apricot/source/blender/blenlib/BLI_blenlib.h
===================================================================
--- branches/apricot/source/blender/blenlib/BLI_blenlib.h	2008-05-19 14:16:18 UTC (rev 14897)
+++ branches/apricot/source/blender/blenlib/BLI_blenlib.h	2008-05-19 18:37:31 UTC (rev 14898)
@@ -73,7 +73,6 @@
  * @attention Defined in scanfill.c
  */
 extern ListBase filledgebase;
-extern int totblock;
 
 extern char btempdir[]; /* creator.c temp dir used instead of U.tempdir, set with BLI_where_is_temp( btempdir, 1 ); */
 

Modified: branches/apricot/source/blender/include/BDR_imagepaint.h
===================================================================
--- branches/apricot/source/blender/include/BDR_imagepaint.h	2008-05-19 14:16:18 UTC (rev 14897)
+++ branches/apricot/source/blender/include/BDR_imagepaint.h	2008-05-19 18:37:31 UTC (rev 14898)
@@ -34,8 +34,8 @@
 void imagepaint_pick(short mousebutton);
 void imagepaint_paint(short mousebutton, short texturepaint);
 
-void imagepaint_undo();
-void free_imagepaint();
+void undo_imagepaint_step(int step);
+void undo_imagepaint_clear(void);
 
 #endif /*  BDR_IMAGEPAINT_H */
 

Modified: branches/apricot/source/blender/makesdna/DNA_userdef_types.h
===================================================================
--- branches/apricot/source/blender/makesdna/DNA_userdef_types.h	2008-05-19 14:16:18 UTC (rev 14897)
+++ branches/apricot/source/blender/makesdna/DNA_userdef_types.h	2008-05-19 18:37:31 UTC (rev 14898)
@@ -182,6 +182,7 @@
 	char fontname[256];		// FILE_MAXDIR+FILE length
 	struct ListBase themes;
 	short undosteps;
+	short undomemory, pad[3];
 	short curssize;
 	short tb_leftmouse, tb_rightmouse;
 	struct SolidLight light[3];

Modified: branches/apricot/source/blender/render/intern/source/pipeline.c
===================================================================
--- branches/apricot/source/blender/render/intern/source/pipeline.c	2008-05-19 14:16:18 UTC (rev 14897)
+++ branches/apricot/source/blender/render/intern/source/pipeline.c	2008-05-19 18:37:31 UTC (rev 14898)
@@ -138,9 +138,11 @@
 
 static void stats_background(RenderStats *rs)
 {
-	extern unsigned long mem_in_use;
+	unsigned long mem_in_use;
 	float megs_used_memory= mem_in_use/(1024.0*1024.0);
 	char str[400], *spos= str;
+
+	mem_in_use= MEM_get_memory_in_use();
 	
 	spos+= sprintf(spos, "Fra:%d Mem:%.2fM ", G.scene->r.cfra, megs_used_memory);
 	

Modified: branches/apricot/source/blender/src/editlattice.c
===================================================================
--- branches/apricot/source/blender/src/editlattice.c	2008-05-19 14:16:18 UTC (rev 14897)
+++ branches/apricot/source/blender/src/editlattice.c	2008-05-19 18:37:31 UTC (rev 14898)
@@ -131,7 +131,7 @@
 		copy_dverts(editLatt->dvert, lt->dvert, tot);
 	}
 	
-	BIF_undo_push("original");
+	BIF_undo_push("Original");
 }
 
 

Modified: branches/apricot/source/blender/src/editmode_undo.c
===================================================================
--- branches/apricot/source/blender/src/editmode_undo.c	2008-05-19 14:16:18 UTC (rev 14897)
+++ branches/apricot/source/blender/src/editmode_undo.c	2008-05-19 18:37:31 UTC (rev 14898)
@@ -107,6 +107,7 @@
 	Object *ob;		// pointer to edited object
 	int type;		// type of edited object
 	void *undodata;
+	unsigned long undosize;
 	char name[MAXUNDONAME];
 	void (*freedata)(void *);
 	void (*to_editmode)(void *);
@@ -138,6 +139,7 @@
 {
 	UndoElem *uel;
 	int nr;
+	unsigned long memused, totmem, maxmem;
 
 	/* at first here was code to prevent an "original" key to be insterted twice
 	   this was giving conflicts for example when mesh changed due to keys or apply */
@@ -145,9 +147,8 @@
 	/* remove all undos after (also when curundo==NULL) */
 	while(undobase.last != curundo) {
 		uel= undobase.last;
-		BLI_remlink(&undobase, uel);
 		uel->freedata(uel->undodata);
-		MEM_freeN(uel);
+		BLI_freelinkN(&undobase, uel);
 	}
 	
 	/* make new */
@@ -160,7 +161,7 @@
 	uel->from_editmode= from_editmode;
 	uel->validate_undo= validate_undo;
 	
-	/* and limit amount to the maximum */
+	/* limit amount to the maximum amount*/
 	nr= 0;
 	uel= undobase.last;
 	while(uel) {
@@ -171,20 +172,44 @@
 	if(uel) {
 		while(undobase.first!=uel) {
 			UndoElem *first= undobase.first;
-			BLI_remlink(&undobase, first);
 			first->freedata(first->undodata);
-			MEM_freeN(first);
+			BLI_freelinkN(&undobase, first);
 		}
 	}
 
 	/* copy  */
+	memused= MEM_get_memory_in_use();
 	curundo->undodata= curundo->from_editmode();
+	curundo->undosize= MEM_get_memory_in_use() - memused;
 	curundo->ob= G.obedit;
 	curundo->id= G.obedit->id;
 	curundo->type= G.obedit->type;
+
+	if(U.undomemory != 0) {
+		/* limit to maximum memory (afterwards, we can't know in advance) */
+		totmem= 0;
+		maxmem= ((unsigned long)U.undomemory)*1024*1024;
+
+		uel= undobase.last;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list