[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49936] trunk/blender/source/blender/ compositor: compositor: replace C++ new/delete with guardedalloc.

Campbell Barton ideasman42 at gmail.com
Thu Aug 16 14:32:49 CEST 2012


Revision: 49936
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49936
Author:   campbellbarton
Date:     2012-08-16 12:32:48 +0000 (Thu, 16 Aug 2012)
Log Message:
-----------
compositor: replace C++ new/delete with guardedalloc.

Modified Paths:
--------------
    trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.cpp
    trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.cpp
    trunk/blender/source/blender/compositor/intern/COM_WorkScheduler.cpp
    trunk/blender/source/blender/compositor/operations/COM_AntiAliasOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_BlurBaseOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_ConvolutionFilterOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_DilateErodeOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_InpaintOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_MovieDistortionOperation.h
    trunk/blender/source/blender/compositor/operations/COM_VectorBlurOperation.cpp

Modified: trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.cpp	2012-08-16 12:13:01 UTC (rev 49935)
+++ trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.cpp	2012-08-16 12:32:48 UTC (rev 49936)
@@ -38,6 +38,7 @@
 #include "COM_ChunkOrder.h"
 #include "COM_ExecutionSystemHelper.h"
 
+#include "MEM_guardedalloc.h"
 #include "BLI_math.h"
 #include "PIL_time.h"
 #include "WM_api.h"
@@ -148,14 +149,14 @@
 void ExecutionGroup::initExecution()
 {
 	if (this->m_chunkExecutionStates != NULL) {
-		delete[] this->m_chunkExecutionStates;
+		MEM_freeN(this->m_chunkExecutionStates);
 	}
 	unsigned int index;
 	determineNumberOfChunks();
 
 	this->m_chunkExecutionStates = NULL;
 	if (this->m_numberOfChunks != 0) {
-		this->m_chunkExecutionStates = new ChunkExecutionState[this->m_numberOfChunks];
+		this->m_chunkExecutionStates = (ChunkExecutionState *)MEM_mallocN(sizeof(ChunkExecutionState) * this->m_numberOfChunks, __func__);
 		for (index = 0; index < this->m_numberOfChunks; index++) {
 			this->m_chunkExecutionStates[index] = COM_ES_NOT_SCHEDULED;
 		}
@@ -180,7 +181,7 @@
 void ExecutionGroup::deinitExecution()
 {
 	if (this->m_chunkExecutionStates != NULL) {
-		delete[] this->m_chunkExecutionStates;
+		MEM_freeN(this->m_chunkExecutionStates);
 		this->m_chunkExecutionStates = NULL;
 	}
 	this->m_numberOfChunks = 0;
@@ -227,7 +228,7 @@
 	this->m_chunksFinished = 0;
 	this->m_bTree = bTree;
 	unsigned int index;
-	unsigned int *chunkOrder = new unsigned int[this->m_numberOfChunks];
+	unsigned int *chunkOrder = (unsigned int *)MEM_mallocN(sizeof(unsigned int) * this->m_numberOfChunks, __func__);
 
 	for (chunkNumber = 0; chunkNumber < this->m_numberOfChunks; chunkNumber++) {
 		chunkOrder[chunkNumber] = chunkNumber;
@@ -256,10 +257,10 @@
 			break;
 		case COM_TO_CENTER_OUT:
 		{
-			ChunkOrderHotspot **hotspots = new ChunkOrderHotspot *[1];
+			ChunkOrderHotspot *hotspots[1];
 			hotspots[0] = new ChunkOrderHotspot(this->m_width * centerX, this->m_height * centerY, 0.0f);
 			rcti rect;
-			ChunkOrder *chunkOrders = new ChunkOrder[this->m_numberOfChunks];
+			ChunkOrder *chunkOrders = (ChunkOrder *)MEM_mallocN(sizeof(ChunkOrder) * this->m_numberOfChunks, __func__);
 			for (index = 0; index < this->m_numberOfChunks; index++) {
 				determineChunkRect(&rect, index);
 				chunkOrders[index].setChunkNumber(index);
@@ -274,13 +275,12 @@
 			}
 
 			delete hotspots[0];
-			delete[] hotspots;
-			delete[] chunkOrders;
+			MEM_freeN(chunkOrders);
 		}
 		break;
 		case COM_TO_RULE_OF_THIRDS:
 		{
-			ChunkOrderHotspot **hotspots = new ChunkOrderHotspot *[9];
+			ChunkOrderHotspot *hotspots[9];
 			unsigned int tx = this->m_width / 6;
 			unsigned int ty = this->m_height / 6;
 			unsigned int mx = this->m_width / 2;
@@ -299,7 +299,7 @@
 			hotspots[7] = new ChunkOrderHotspot(mx, ty, addition * 7);
 			hotspots[8] = new ChunkOrderHotspot(mx, by, addition * 8);
 			rcti rect;
-			ChunkOrder *chunkOrders = new ChunkOrder[this->m_numberOfChunks];
+			ChunkOrder *chunkOrders = (ChunkOrder *)MEM_mallocN(sizeof(ChunkOrder) * this->m_numberOfChunks, __func__);
 			for (index = 0; index < this->m_numberOfChunks; index++) {
 				determineChunkRect(&rect, index);
 				chunkOrders[index].setChunkNumber(index);
@@ -323,8 +323,7 @@
 			delete hotspots[6];
 			delete hotspots[7];
 			delete hotspots[8];
-			delete[] hotspots;
-			delete[] chunkOrders;
+			MEM_freeN(chunkOrders);
 		}
 		break;
 		case COM_TO_TOP_DOWN:
@@ -372,7 +371,7 @@
 		}
 	}
 
-	delete[] chunkOrder;
+	MEM_freeN(chunkOrder);
 }
 
 MemoryBuffer **ExecutionGroup::getInputBuffersOpenCL(int chunkNumber)
@@ -383,10 +382,7 @@
 	determineChunkRect(&rect, chunkNumber);
 
 	this->determineDependingMemoryProxies(&memoryproxies);
-	MemoryBuffer **memoryBuffers = new MemoryBuffer *[this->m_cachedMaxReadBufferOffset];
-	for (index = 0; index < this->m_cachedMaxReadBufferOffset; index++) {
-		memoryBuffers[index] = NULL;
-	}
+	MemoryBuffer **memoryBuffers = (MemoryBuffer **)MEM_callocN(sizeof(MemoryBuffer *) * this->m_cachedMaxReadBufferOffset, __func__);
 	rcti output;
 	for (index = 0; index < this->m_cachedReadOperations.size(); index++) {
 		ReadBufferOperation *readOperation = (ReadBufferOperation *)this->m_cachedReadOperations[index];
@@ -422,7 +418,7 @@
 				}
 			}
 		}
-		delete[] memoryBuffers;
+		MEM_freeN(memoryBuffers);
 	}
 	if (this->m_bTree) {
 		// status report is only performed for top level Execution Groups.

Modified: trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.cpp	2012-08-16 12:13:01 UTC (rev 49935)
+++ trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.cpp	2012-08-16 12:32:48 UTC (rev 49936)
@@ -75,7 +75,7 @@
 	const unsigned int size = this->determineBufferSize();
 	unsigned int i;
 
-	float *result = new float[size];
+	float *result = (float *)MEM_mallocN(sizeof(float) * size, __func__);
 
 	const float *fp_src = this->m_buffer;
 	float       *fp_dst = result;

Modified: trunk/blender/source/blender/compositor/intern/COM_WorkScheduler.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_WorkScheduler.cpp	2012-08-16 12:13:01 UTC (rev 49935)
+++ trunk/blender/source/blender/compositor/intern/COM_WorkScheduler.cpp	2012-08-16 12:32:48 UTC (rev 49936)
@@ -32,6 +32,8 @@
 #include "OCL_opencl.h"
 #include "COM_WriteBufferOperation.h"
 
+#include "MEM_guardedalloc.h"
+
 #include "PIL_time.h"
 #include "BLI_threads.h"
 
@@ -99,20 +101,20 @@
 void COM_startReadHighlights()
 {
 	if (g_highlightedNodesRead) {
-		delete [] g_highlightedNodesRead;
+		MEM_freeN(g_highlightedNodesRead);
 	}
 	
 	g_highlightedNodesRead = g_highlightedNodes;
-	g_highlightedNodes = new void *[MAX_HIGHLIGHT];
+	g_highlightedNodes = (void **)MEM_callocN(sizeof(void *) * MAX_HIGHLIGHT, __func__);
 	g_highlightIndex = 0;
-	for (int i = 0 ; i < MAX_HIGHLIGHT; i++) {
-		g_highlightedNodes[i] = 0;
-	}
 }
 
 int COM_isHighlightedbNode(bNode *bnode)
 {
-	if (!g_highlightedNodesRead) return false;
+	if (!g_highlightedNodesRead) {
+		return false;
+	}
+
 	for (int i = 0 ; i < MAX_HIGHLIGHT; i++) {
 		void *p = g_highlightedNodesRead[i];
 		if (!p) return false;
@@ -255,8 +257,8 @@
 
 void WorkScheduler::initialize()
 {
-	g_highlightedNodesRead = 0;
-	g_highlightedNodes = 0;
+	g_highlightedNodesRead = NULL;
+	g_highlightedNodes = NULL;
 	COM_startReadHighlights();
 #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE
 	int numberOfCPUThreads = BLI_system_thread_count();
@@ -275,7 +277,7 @@
 		error = clGetPlatformIDs(0, 0, &numberOfPlatforms);
 		if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error));  }
 		if (G.f & G_DEBUG) printf("%d number of platforms\n", numberOfPlatforms);
-		cl_platform_id *platforms = new cl_platform_id[numberOfPlatforms];
+		cl_platform_id *platforms = (cl_platform_id *)MEM_mallocN(sizeof(cl_platform_id) * numberOfPlatforms, __func__);
 		error = clGetPlatformIDs(numberOfPlatforms, platforms, 0);
 		unsigned int indexPlatform;
 		for (indexPlatform = 0; indexPlatform < numberOfPlatforms; indexPlatform++) {
@@ -283,7 +285,7 @@
 			cl_uint numberOfDevices = 0;
 			clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, 0, &numberOfDevices);
 			if (numberOfDevices > 0) {
-				cl_device_id *cldevices = new cl_device_id[numberOfDevices];
+				cl_device_id *cldevices = (cl_device_id *)MEM_mallocN(sizeof(cl_device_id) * numberOfDevices, __func__);
 				clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numberOfDevices, cldevices, 0);
 
 				g_context = clCreateContext(NULL, numberOfDevices, cldevices, clContextError, NULL, &error);
@@ -297,12 +299,12 @@
 					printf("CLERROR[%d]: %s\n", error, clewErrorString(error));	
 					error2 = clGetProgramBuildInfo(g_program, cldevices[0], CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size);
 					if (error2 != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); }
-					char *build_log =  new char[ret_val_size + 1];
+					char *build_log = (char *)MEM_mallocN(sizeof(char) * ret_val_size + 1, __func__);
 					error2 = clGetProgramBuildInfo(g_program, cldevices[0], CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);
 					if (error2 != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); }
 					build_log[ret_val_size] = '\0';
 					printf("%s", build_log);
-					delete build_log;
+					MEM_freeN(build_log);
 				}
 				else {
 					unsigned int indexDevices;
@@ -316,10 +318,10 @@
 						g_gpudevices.push_back(clDevice);
 					}
 				}
-				delete[] cldevices;
+				MEM_freeN(cldevices);
 			}
 		}
-		delete[] platforms;
+		MEM_freeN(platforms);
 	}
 #endif
 #endif

Modified: trunk/blender/source/blender/compositor/operations/COM_AntiAliasOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_AntiAliasOperation.cpp	2012-08-16 12:13:01 UTC (rev 49935)
+++ trunk/blender/source/blender/compositor/operations/COM_AntiAliasOperation.cpp	2012-08-16 12:32:48 UTC (rev 49936)
@@ -23,6 +23,10 @@
 #include "COM_AntiAliasOperation.h"
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
+#include "BKE_utildefines.h"
+
+#include "MEM_guardedalloc.h"
+
 extern "C" {
 	#include "RE_render_ext.h"
 }
@@ -58,7 +62,7 @@
 {
 	this->m_valueReader = NULL;
 	if (this->m_buffer) {
-		delete this->m_buffer;
+		MEM_freeN(this->m_buffer);
 	}
 	NodeOperation::deinitMutex();
 }
@@ -90,12 +94,10 @@
 		MemoryBuffer *tile = (MemoryBuffer *)this->m_valueReader->initializeTileData(rect);
 		int size = tile->getHeight() * tile->getWidth();
 		float *input = tile->getBuffer();
-		char *valuebuffer = new char[size];
+		char *valuebuffer = (char *)MEM_mallocN(sizeof(char) * size, __func__);
 		for (int i = 0; i < size; i++) {
 			float in = input[i * COM_NUMBER_OF_CHANNELS];
-			if (in < 0.0f) { in = 0.0f; }
-			if (in > 1.0f) {in = 1.0f; }
-			valuebuffer[i] = in * 255;
+			valuebuffer[i] = FTOCHAR(in);
 		}
 		antialias_tagbuf(tile->getWidth(), tile->getHeight(), valuebuffer);
 		this->m_buffer = valuebuffer;

Modified: trunk/blender/source/blender/compositor/operations/COM_BlurBaseOperation.cpp

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list