Added support for threadsafe MEM_mallocN/MEM_freeN in the guardedalloc
module itself, replacing the special MEM_mallocT/MEM_freeT functions. Mutex locking is only enabled when threads are running. There was no good reason to have these separate, it just led to ugly hacks when calling functions with non-threadsafe malloc from threads.
This commit is contained in:
@@ -112,6 +112,10 @@ extern "C" {
|
||||
* @retval 0 for correct memory, 1 for corrupted memory. */
|
||||
int MEM_check_memory_integrity(void);
|
||||
|
||||
/** Set thread locking functions for safe memory allocation from multiple
|
||||
threads, pass NULL pointers to disable thread locking again. */
|
||||
void MEM_set_lock_callback(void (*lock)(void), void (*unlock)(void));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -117,6 +117,8 @@ volatile unsigned long mem_in_use= 0, mmap_in_use= 0;
|
||||
volatile static struct localListBase _membase;
|
||||
volatile static struct localListBase *membase = &_membase;
|
||||
static void (*error_callback)(char *) = NULL;
|
||||
static void (*thread_lock_callback)(void) = NULL;
|
||||
static void (*thread_unlock_callback)(void) = NULL;
|
||||
|
||||
#ifdef malloc
|
||||
#undef malloc
|
||||
@@ -147,6 +149,18 @@ static void print_error(const char *str, ...)
|
||||
if (error_callback) error_callback(buf);
|
||||
}
|
||||
|
||||
static void mem_lock_thread()
|
||||
{
|
||||
if (thread_lock_callback)
|
||||
thread_lock_callback();
|
||||
}
|
||||
|
||||
static void mem_unlock_thread()
|
||||
{
|
||||
if (thread_unlock_callback)
|
||||
thread_unlock_callback();
|
||||
}
|
||||
|
||||
int MEM_check_memory_integrity()
|
||||
{
|
||||
const char* err_val = NULL;
|
||||
@@ -167,6 +181,11 @@ void MEM_set_error_callback(void (*func)(char *))
|
||||
error_callback = func;
|
||||
}
|
||||
|
||||
void MEM_set_lock_callback(void (*lock)(void), void (*unlock)(void))
|
||||
{
|
||||
thread_lock_callback = lock;
|
||||
thread_unlock_callback = unlock;
|
||||
}
|
||||
|
||||
int MEM_allocN_len(void *vmemh)
|
||||
{
|
||||
@@ -222,14 +241,18 @@ void *MEM_mallocN(unsigned int len, const char *str)
|
||||
{
|
||||
MemHead *memh;
|
||||
|
||||
mem_lock_thread();
|
||||
|
||||
len = (len + 3 ) & ~3; /* allocate in units of 4 */
|
||||
|
||||
memh= (MemHead *)malloc(len+sizeof(MemHead)+sizeof(MemTail));
|
||||
|
||||
if(memh) {
|
||||
make_memhead_header(memh, len, str);
|
||||
mem_unlock_thread();
|
||||
return (++memh);
|
||||
}
|
||||
mem_unlock_thread();
|
||||
print_error("Malloc returns nill: len=%d in %s, total %u\n",len, str, mem_in_use);
|
||||
return NULL;
|
||||
}
|
||||
@@ -238,14 +261,18 @@ void *MEM_callocN(unsigned int len, const char *str)
|
||||
{
|
||||
MemHead *memh;
|
||||
|
||||
mem_lock_thread();
|
||||
|
||||
len = (len + 3 ) & ~3; /* allocate in units of 4 */
|
||||
|
||||
memh= (MemHead *)calloc(len+sizeof(MemHead)+sizeof(MemTail),1);
|
||||
|
||||
if(memh) {
|
||||
make_memhead_header(memh, len, str);
|
||||
mem_unlock_thread();
|
||||
return (++memh);
|
||||
}
|
||||
mem_unlock_thread();
|
||||
print_error("Calloc returns nill: len=%d in %s, total %u\n",len, str, mem_in_use);
|
||||
return 0;
|
||||
}
|
||||
@@ -257,6 +284,8 @@ void *MEM_mapallocN(unsigned int len, const char *str)
|
||||
return MEM_callocN(len, str);
|
||||
#else
|
||||
MemHead *memh;
|
||||
|
||||
mem_lock_thread();
|
||||
|
||||
len = (len + 3 ) & ~3; /* allocate in units of 4 */
|
||||
|
||||
@@ -280,13 +309,14 @@ void *MEM_mapallocN(unsigned int len, const char *str)
|
||||
make_memhead_header(memh, len, str);
|
||||
memh->mmap= 1;
|
||||
mmap_in_use += len;
|
||||
mem_unlock_thread();
|
||||
return (++memh);
|
||||
}
|
||||
else {
|
||||
mem_unlock_thread();
|
||||
print_error("Mapalloc returns nill, fallback to regular malloc: len=%d in %s, total %u\n",len, str, mmap_in_use);
|
||||
return MEM_callocN(len, str);
|
||||
}
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -295,6 +325,8 @@ void MEM_printmemlist()
|
||||
{
|
||||
MemHead *membl;
|
||||
|
||||
mem_lock_thread();
|
||||
|
||||
membl = membase->first;
|
||||
if (membl) membl = MEMNEXT(membl);
|
||||
while(membl) {
|
||||
@@ -303,6 +335,8 @@ void MEM_printmemlist()
|
||||
membl= MEMNEXT(membl->next);
|
||||
else break;
|
||||
}
|
||||
|
||||
mem_unlock_thread();
|
||||
}
|
||||
|
||||
short MEM_freeN(void *vmemh) /* anders compileertie niet meer */
|
||||
@@ -337,6 +371,8 @@ short MEM_freeN(void *vmemh) /* anders compileertie niet meer */
|
||||
return(-1);
|
||||
}
|
||||
|
||||
mem_lock_thread();
|
||||
|
||||
if ((memh->tag1 == MEMTAG1) && (memh->tag2 == MEMTAG2) && ((memh->len & 0x3) == 0)) {
|
||||
memt = (MemTail *)(((char *) memh) + sizeof(MemHead) + memh->len);
|
||||
if (memt->tag3 == MEMTAG3){
|
||||
@@ -346,6 +382,8 @@ short MEM_freeN(void *vmemh) /* anders compileertie niet meer */
|
||||
memt->tag3 = MEMFREE;
|
||||
/* after tags !!! */
|
||||
rem_memblock(memh);
|
||||
|
||||
mem_unlock_thread();
|
||||
|
||||
return(0);
|
||||
}
|
||||
@@ -365,6 +403,8 @@ short MEM_freeN(void *vmemh) /* anders compileertie niet meer */
|
||||
totblock--;
|
||||
/* here a DUMP should happen */
|
||||
|
||||
mem_unlock_thread();
|
||||
|
||||
return(error);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,8 +53,6 @@
|
||||
#include "IMB_imbuf.h"
|
||||
#include "IMB_imbuf_types.h"
|
||||
|
||||
/* NOTE: uses threadsafe malloc/calloc/free, for use in compositor */
|
||||
|
||||
/* ********************************* color curve ********************* */
|
||||
|
||||
/* ***************** operations on full struct ************* */
|
||||
@@ -295,7 +293,7 @@ static void curvemap_make_table(CurveMap *cuma, rctf *clipr)
|
||||
cuma->maxtable= clipr->xmax;
|
||||
|
||||
/* hrmf... we now rely on blender ipo beziers, these are more advanced */
|
||||
bezt= MEM_callocT(cuma->totpoint*sizeof(BezTriple), "beztarr");
|
||||
bezt= MEM_callocN(cuma->totpoint*sizeof(BezTriple), "beztarr");
|
||||
|
||||
for(a=0; a<cuma->totpoint; a++) {
|
||||
cuma->mintable= MIN2(cuma->mintable, cmp[a].x);
|
||||
@@ -356,9 +354,9 @@ static void curvemap_make_table(CurveMap *cuma, rctf *clipr)
|
||||
}
|
||||
/* make the bezier curve */
|
||||
if(cuma->table)
|
||||
MEM_freeT(cuma->table);
|
||||
MEM_freeN(cuma->table);
|
||||
totpoint= (cuma->totpoint-1)*CM_RESOL;
|
||||
fp= allpoints= MEM_callocT(totpoint*2*sizeof(float), "table");
|
||||
fp= allpoints= MEM_callocN(totpoint*2*sizeof(float), "table");
|
||||
|
||||
for(a=0; a<cuma->totpoint-1; a++, fp += 2*CM_RESOL) {
|
||||
correct_bezpart(bezt[a].vec[1], bezt[a].vec[2], bezt[a+1].vec[0], bezt[a+1].vec[1]);
|
||||
@@ -366,7 +364,7 @@ static void curvemap_make_table(CurveMap *cuma, rctf *clipr)
|
||||
forward_diff_bezier(bezt[a].vec[1][1], bezt[a].vec[2][1], bezt[a+1].vec[0][1], bezt[a+1].vec[1][1], fp+1, CM_RESOL-1, 2);
|
||||
}
|
||||
|
||||
MEM_freeT(bezt);
|
||||
MEM_freeN(bezt);
|
||||
|
||||
range= CM_TABLEDIV*(cuma->maxtable - cuma->mintable);
|
||||
cuma->range= 1.0f/range;
|
||||
@@ -374,7 +372,7 @@ static void curvemap_make_table(CurveMap *cuma, rctf *clipr)
|
||||
/* now make a table with CM_TABLE equal x distances */
|
||||
fp= allpoints;
|
||||
lastpoint= allpoints + 2*(totpoint-1);
|
||||
cmp= MEM_callocT((CM_TABLE+1)*sizeof(CurveMapPoint), "dist table");
|
||||
cmp= MEM_callocN((CM_TABLE+1)*sizeof(CurveMapPoint), "dist table");
|
||||
cmp[0].x= cuma->mintable;
|
||||
cmp[0].y= allpoints[1];
|
||||
|
||||
@@ -401,7 +399,7 @@ static void curvemap_make_table(CurveMap *cuma, rctf *clipr)
|
||||
cmp[CM_TABLE].x= cuma->maxtable;
|
||||
cmp[CM_TABLE].y= allpoints[2*totpoint-1];
|
||||
|
||||
MEM_freeT(allpoints);
|
||||
MEM_freeN(allpoints);
|
||||
cuma->table= cmp;
|
||||
}
|
||||
|
||||
@@ -414,7 +412,7 @@ void curvemapping_premultiply(CurveMapping *cumap, int restore)
|
||||
if(restore) {
|
||||
if(cumap->flag & CUMA_PREMULLED) {
|
||||
for(a=0; a<3; a++) {
|
||||
MEM_freeT(cumap->cm[a].table);
|
||||
MEM_freeN(cumap->cm[a].table);
|
||||
cumap->cm[a].table= cumap->cm[a].premultable;
|
||||
cumap->cm[a].premultable= NULL;
|
||||
}
|
||||
@@ -429,7 +427,7 @@ void curvemapping_premultiply(CurveMapping *cumap, int restore)
|
||||
if(cumap->cm[a].table==NULL)
|
||||
curvemap_make_table(cumap->cm+a, &cumap->clipr);
|
||||
cumap->cm[a].premultable= cumap->cm[a].table;
|
||||
cumap->cm[a].table= MEM_mallocT((CM_TABLE+1)*sizeof(CurveMapPoint), "premul table");
|
||||
cumap->cm[a].table= MEM_mallocN((CM_TABLE+1)*sizeof(CurveMapPoint), "premul table");
|
||||
memcpy(cumap->cm[a].table, cumap->cm[a].premultable, (CM_TABLE+1)*sizeof(CurveMapPoint));
|
||||
}
|
||||
|
||||
|
||||
@@ -623,8 +623,6 @@ void image_de_interlace(Image *ima, int odd)
|
||||
de_interlace_ng(ima->ibuf);
|
||||
}
|
||||
|
||||
/* important note: all calls here and calls inside can NOT use threadsafe malloc! */
|
||||
/* this entire function is mutex'ed with the same lock as for mallocs */
|
||||
void ima_ibuf_is_nul(Tex *tex, Image *ima)
|
||||
{
|
||||
void (*de_interlacefunc)(struct ImBuf *ibuf);
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "DNA_ID.h"
|
||||
#include "DNA_image_types.h"
|
||||
#include "DNA_node_types.h"
|
||||
@@ -52,7 +54,6 @@
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_threads.h"
|
||||
|
||||
/* NOTE: no imbuf calls allowed in composit, we need threadsafe malloc! */
|
||||
#include "IMB_imbuf_types.h"
|
||||
#include "IMB_imbuf.h"
|
||||
|
||||
@@ -88,7 +89,7 @@ typedef struct CompBuf {
|
||||
|
||||
static CompBuf *alloc_compbuf(int sizex, int sizey, int type, int alloc)
|
||||
{
|
||||
CompBuf *cbuf= MEM_callocT(sizeof(CompBuf), "compbuf");
|
||||
CompBuf *cbuf= MEM_callocN(sizeof(CompBuf), "compbuf");
|
||||
|
||||
cbuf->x= sizex;
|
||||
cbuf->y= sizey;
|
||||
@@ -98,13 +99,13 @@ static CompBuf *alloc_compbuf(int sizex, int sizey, int type, int alloc)
|
||||
cbuf->type= type;
|
||||
if(alloc) {
|
||||
if(cbuf->type==CB_RGBA)
|
||||
cbuf->rect= MEM_mapallocT(4*sizeof(float)*sizex*sizey, "compbuf RGBA rect");
|
||||
cbuf->rect= MEM_mapallocN(4*sizeof(float)*sizex*sizey, "compbuf RGBA rect");
|
||||
else if(cbuf->type==CB_VEC3)
|
||||
cbuf->rect= MEM_mapallocT(3*sizeof(float)*sizex*sizey, "compbuf Vector3 rect");
|
||||
cbuf->rect= MEM_mapallocN(3*sizeof(float)*sizex*sizey, "compbuf Vector3 rect");
|
||||
else if(cbuf->type==CB_VEC2)
|
||||
cbuf->rect= MEM_mapallocT(2*sizeof(float)*sizex*sizey, "compbuf Vector2 rect");
|
||||
cbuf->rect= MEM_mapallocN(2*sizeof(float)*sizex*sizey, "compbuf Vector2 rect");
|
||||
else
|
||||
cbuf->rect= MEM_mapallocT(sizeof(float)*sizex*sizey, "compbuf Fac rect");
|
||||
cbuf->rect= MEM_mapallocN(sizeof(float)*sizex*sizey, "compbuf Fac rect");
|
||||
cbuf->malloc= 1;
|
||||
}
|
||||
cbuf->disprect.xmin= 0;
|
||||
@@ -140,9 +141,9 @@ static CompBuf *pass_on_compbuf(CompBuf *cbuf)
|
||||
void free_compbuf(CompBuf *cbuf)
|
||||
{
|
||||
if(cbuf->malloc && cbuf->rect)
|
||||
MEM_freeT(cbuf->rect);
|
||||
MEM_freeN(cbuf->rect);
|
||||
|
||||
MEM_freeT(cbuf);
|
||||
MEM_freeN(cbuf);
|
||||
}
|
||||
|
||||
void print_compbuf(char *str, CompBuf *cbuf)
|
||||
@@ -531,31 +532,27 @@ static void node_composit_exec_viewer(void *data, bNode *node, bNodeStack **in,
|
||||
recty= tbuf->y;
|
||||
}
|
||||
|
||||
/* full copy of imbuf, but threadsafe... */
|
||||
if(ima->ibuf==NULL) {
|
||||
ima->ibuf = MEM_callocT(sizeof(struct ImBuf), "ImBuf_struct");
|
||||
ima->ibuf->depth= 32;
|
||||
ima->ibuf->ftype= TGA;
|
||||
}
|
||||
if(ima->ibuf==NULL)
|
||||
ima->ibuf= IMB_allocImBuf(rectx, recty, 32, 0, 0);
|
||||
|
||||
/* cleanup of composit image */
|
||||
if(ima->ibuf->rect) {
|
||||
MEM_freeT(ima->ibuf->rect);
|
||||
MEM_freeN(ima->ibuf->rect);
|
||||
ima->ibuf->rect= NULL;
|
||||
ima->ibuf->mall &= ~IB_rect;
|
||||
}
|
||||
if(ima->ibuf->zbuf_float) {
|
||||
MEM_freeT(ima->ibuf->zbuf_float);
|
||||
MEM_freeN(ima->ibuf->zbuf_float);
|
||||
ima->ibuf->zbuf_float= NULL;
|
||||
ima->ibuf->mall &= ~IB_zbuffloat;
|
||||
}
|
||||
if(ima->ibuf->rect_float)
|
||||
MEM_freeT(ima->ibuf->rect_float);
|
||||
MEM_freeN(ima->ibuf->rect_float);
|
||||
|
||||
ima->ibuf->x= rectx;
|
||||
ima->ibuf->y= recty;
|
||||
ima->ibuf->mall |= IB_rectfloat;
|
||||
ima->ibuf->rect_float= MEM_mallocT(4*rectx*recty*sizeof(float), "viewer rect");
|
||||
ima->ibuf->rect_float= MEM_mallocN(4*rectx*recty*sizeof(float), "viewer rect");
|
||||
|
||||
/* now we combine the input with ibuf */
|
||||
cbuf= alloc_compbuf(rectx, recty, CB_RGBA, 0); // no alloc
|
||||
@@ -632,7 +629,7 @@ static void node_composit_exec_composite(void *data, bNode *node, bNodeStack **i
|
||||
CompBuf *outbuf, *zbuf=NULL;
|
||||
|
||||
if(rr->rectf)
|
||||
MEM_freeT(rr->rectf);
|
||||
MEM_freeN(rr->rectf);
|
||||
outbuf= alloc_compbuf(rr->rectx, rr->recty, CB_RGBA, 1);
|
||||
|
||||
if(in[1]->data==NULL)
|
||||
@@ -642,7 +639,7 @@ static void node_composit_exec_composite(void *data, bNode *node, bNodeStack **i
|
||||
|
||||
if(in[2]->data) {
|
||||
if(rr->rectz)
|
||||
MEM_freeT(rr->rectz);
|
||||
MEM_freeN(rr->rectz);
|
||||
zbuf= alloc_compbuf(rr->rectx, rr->recty, CB_VAL, 1);
|
||||
composit1_pixel_processor(node, zbuf, in[2]->data, in[2]->vec, do_copy_value, CB_VAL);
|
||||
rr->rectz= zbuf->rect;
|
||||
@@ -787,10 +784,8 @@ static void animated_image(bNode *node, int cfra)
|
||||
if(imanr < 0) imanr = 0;
|
||||
if(imanr > (dur-1)) imanr= dur-1;
|
||||
|
||||
BLI_lock_thread(LOCK_MALLOC);
|
||||
if(ima->ibuf) IMB_freeImBuf(ima->ibuf);
|
||||
ima->ibuf = IMB_anim_absolute(ima->anim, imanr);
|
||||
BLI_unlock_thread(LOCK_MALLOC);
|
||||
|
||||
/* patch for textbutton with name ima (B_NAMEIMA) */
|
||||
if(ima->ibuf) {
|
||||
@@ -826,26 +821,6 @@ static void animated_image(bNode *node, int cfra)
|
||||
}
|
||||
}
|
||||
|
||||
static float *float_from_byte_rect(int rectx, int recty, char *rect)
|
||||
{
|
||||
/* quick method to convert byte to floatbuf */
|
||||
float *rect_float= MEM_mallocT(4*sizeof(float)*rectx*recty, "float rect");
|
||||
float *tof = rect_float;
|
||||
int i;
|
||||
|
||||
for (i = rectx*recty; i > 0; i--) {
|
||||
tof[0] = ((float)rect[0])*(1.0f/255.0f);
|
||||
tof[1] = ((float)rect[1])*(1.0f/255.0f);
|
||||
tof[2] = ((float)rect[2])*(1.0f/255.0f);
|
||||
tof[3] = ((float)rect[3])*(1.0f/255.0f);
|
||||
rect += 4;
|
||||
tof += 4;
|
||||
}
|
||||
return rect_float;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static CompBuf *node_composit_get_image(bNode *node, RenderData *rd)
|
||||
{
|
||||
Image *ima;
|
||||
@@ -861,19 +836,14 @@ static CompBuf *node_composit_get_image(bNode *node, RenderData *rd)
|
||||
if(ima->ok==0) return NULL;
|
||||
|
||||
if(ima->ibuf==NULL) {
|
||||
BLI_lock_thread(LOCK_MALLOC);
|
||||
load_image(ima, IB_rect, G.sce, rd->cfra); /* G.sce is current .blend path */
|
||||
BLI_unlock_thread(LOCK_MALLOC);
|
||||
if(ima->ibuf==NULL) {
|
||||
ima->ok= 0;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if(ima->ibuf->rect_float==NULL) {
|
||||
/* can't use imbuf module, we need secure malloc */
|
||||
ima->ibuf->rect_float= float_from_byte_rect(ima->ibuf->x, ima->ibuf->y, (char *)ima->ibuf->rect);
|
||||
ima->ibuf->mall |= IB_rectfloat;
|
||||
}
|
||||
if(ima->ibuf->rect_float==NULL)
|
||||
IMB_float_from_rect(ima->ibuf);
|
||||
|
||||
if(rd->scemode & R_COMP_CROP) {
|
||||
stackbuf= get_cropped_compbuf(&rd->disprect, ima->ibuf->rect_float, ima->ibuf->x, ima->ibuf->y, CB_RGBA);
|
||||
@@ -2309,7 +2279,7 @@ static float *make_gausstab(int filtertype, int rad)
|
||||
|
||||
n = 2 * rad + 1;
|
||||
|
||||
gausstab = (float *) MEM_mallocT(n * sizeof(float), "gauss");
|
||||
gausstab = (float *) MEM_mallocN(n * sizeof(float), "gauss");
|
||||
|
||||
sum = 0.0f;
|
||||
for (i = -rad; i <= rad; i++) {
|
||||
@@ -2332,7 +2302,7 @@ static float *make_bloomtab(int rad)
|
||||
|
||||
n = 2 * rad + 1;
|
||||
|
||||
bloomtab = (float *) MEM_mallocT(n * sizeof(float), "bloom");
|
||||
bloomtab = (float *) MEM_mallocN(n * sizeof(float), "bloom");
|
||||
|
||||
for (i = -rad; i <= rad; i++) {
|
||||
val = pow(1.0 - fabs((float)i)/((float)rad), 4.0);
|
||||
@@ -2400,7 +2370,7 @@ static void blur_single_image(CompBuf *new, CompBuf *img, float scale, NodeBlurD
|
||||
}
|
||||
|
||||
/* vertical */
|
||||
MEM_freeT(gausstab);
|
||||
MEM_freeN(gausstab);
|
||||
|
||||
rad = scale*(float)nbd->sizey;
|
||||
if(rad>imgy/2)
|
||||
@@ -2447,7 +2417,7 @@ static void blur_single_image(CompBuf *new, CompBuf *img, float scale, NodeBlurD
|
||||
}
|
||||
|
||||
free_compbuf(work);
|
||||
MEM_freeT(gausstab);
|
||||
MEM_freeN(gausstab);
|
||||
}
|
||||
|
||||
/* reference has to be mapped 0-1, and equal in size */
|
||||
@@ -2481,7 +2451,7 @@ static void bloom_with_reference(CompBuf *new, CompBuf *img, CompBuf *ref, float
|
||||
rady= 1;
|
||||
|
||||
x= MAX2(radx, rady);
|
||||
maintabs= MEM_mallocT(x*sizeof(void *), "gauss array");
|
||||
maintabs= MEM_mallocN(x*sizeof(void *), "gauss array");
|
||||
for(i= 0; i<x; i++)
|
||||
maintabs[i]= make_bloomtab(i+1);
|
||||
|
||||
@@ -2563,8 +2533,8 @@ static void bloom_with_reference(CompBuf *new, CompBuf *img, CompBuf *ref, float
|
||||
|
||||
x= MAX2(radx, rady);
|
||||
for(i= 0; i<x; i++)
|
||||
MEM_freeT(maintabs[i]);
|
||||
MEM_freeT(maintabs);
|
||||
MEM_freeN(maintabs[i]);
|
||||
MEM_freeN(maintabs);
|
||||
|
||||
}
|
||||
|
||||
@@ -2641,7 +2611,7 @@ static void bokeh_single_image(CompBuf *new, CompBuf *img, float fac, NodeBlurDa
|
||||
n = (2*radx+1)*(2*rady+1);
|
||||
|
||||
/* create a full filter image */
|
||||
gausstab= MEM_mallocT(sizeof(float)*n, "filter tab");
|
||||
gausstab= MEM_mallocN(sizeof(float)*n, "filter tab");
|
||||
dgauss= gausstab;
|
||||
val= 0.0f;
|
||||
for(j=-rady; j<=rady; j++) {
|
||||
@@ -2701,7 +2671,7 @@ static void bokeh_single_image(CompBuf *new, CompBuf *img, float fac, NodeBlurDa
|
||||
}
|
||||
}
|
||||
|
||||
MEM_freeT(gausstab);
|
||||
MEM_freeN(gausstab);
|
||||
}
|
||||
|
||||
|
||||
@@ -2751,7 +2721,7 @@ static void blur_with_reference(CompBuf *new, CompBuf *img, CompBuf *ref, NodeBl
|
||||
rady= 1;
|
||||
|
||||
x= MAX2(radx, rady);
|
||||
maintabs= MEM_mallocT(x*sizeof(void *), "gauss array");
|
||||
maintabs= MEM_mallocN(x*sizeof(void *), "gauss array");
|
||||
for(i= 0; i<x; i++)
|
||||
maintabs[i]= make_gausstab(nbd->filtertype, i+1);
|
||||
|
||||
@@ -2821,8 +2791,8 @@ static void blur_with_reference(CompBuf *new, CompBuf *img, CompBuf *ref, NodeBl
|
||||
|
||||
x= MAX2(radx, rady);
|
||||
for(i= 0; i<x; i++)
|
||||
MEM_freeT(maintabs[i]);
|
||||
MEM_freeT(maintabs);
|
||||
MEM_freeN(maintabs[i]);
|
||||
MEM_freeN(maintabs);
|
||||
|
||||
if(ref_use!=ref)
|
||||
free_compbuf(ref_use);
|
||||
@@ -3179,7 +3149,7 @@ static void bilinear_interpolation_rotate(CompBuf *in, float *out, float u, floa
|
||||
static void node_composit_exec_rotate(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
|
||||
{
|
||||
|
||||
if(out[0]->hasoutput==NULL)
|
||||
if(out[0]->hasoutput==0)
|
||||
return;
|
||||
|
||||
if(in[0]->data) {
|
||||
|
||||
@@ -31,11 +31,9 @@
|
||||
#ifndef BLI_THREADS_H
|
||||
#define BLI_THREADS_H
|
||||
|
||||
/* default lock is to protect MEM_ module calls, one custom lock available now. van be extended */
|
||||
#define LOCK_MALLOC 0
|
||||
/* one custom lock available now. can be extended */
|
||||
#define LOCK_CUSTOM1 1
|
||||
|
||||
|
||||
void BLI_init_threads (ListBase *threadbase, void *(*do_thread)(void *), int tot);
|
||||
int BLI_available_threads(ListBase *threadbase);
|
||||
int BLI_available_thread_index(ListBase *threadbase);
|
||||
@@ -46,11 +44,5 @@ void BLI_end_threads (ListBase *threadbase);
|
||||
void BLI_lock_thread (int type);
|
||||
void BLI_unlock_thread (int type);
|
||||
|
||||
/* threadsafe version of MEM_malloc and friends */
|
||||
void *MEM_mallocT(int len, char *name);
|
||||
void *MEM_callocT(int len, char *name);
|
||||
void *MEM_mapallocT(int len, char *name);
|
||||
void MEM_freeT(void *poin);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -97,6 +97,16 @@ typedef struct ThreadSlot {
|
||||
int avail;
|
||||
} ThreadSlot;
|
||||
|
||||
static void BLI_lock_malloc_thread()
|
||||
{
|
||||
pthread_mutex_lock(&_malloc_lock);
|
||||
}
|
||||
|
||||
static void BLI_unlock_malloc_thread()
|
||||
{
|
||||
pthread_mutex_unlock(&_malloc_lock);
|
||||
}
|
||||
|
||||
void BLI_init_threads(ListBase *threadbase, void *(*do_thread)(void *), int tot)
|
||||
{
|
||||
int a;
|
||||
@@ -114,6 +124,8 @@ void BLI_init_threads(ListBase *threadbase, void *(*do_thread)(void *), int tot)
|
||||
tslot->do_thread= do_thread;
|
||||
tslot->avail= 1;
|
||||
}
|
||||
|
||||
MEM_set_lock_callback(BLI_lock_malloc_thread, BLI_unlock_malloc_thread);
|
||||
}
|
||||
|
||||
/* amount of available threads */
|
||||
@@ -182,57 +194,19 @@ void BLI_end_threads(ListBase *threadbase)
|
||||
}
|
||||
BLI_freelistN(threadbase);
|
||||
|
||||
MEM_set_lock_callback(NULL, NULL);
|
||||
}
|
||||
|
||||
void BLI_lock_thread(int type)
|
||||
{
|
||||
if(type==LOCK_MALLOC)
|
||||
pthread_mutex_lock(&_malloc_lock);
|
||||
else
|
||||
if (type==LOCK_CUSTOM1)
|
||||
pthread_mutex_lock(&_custom1_lock);
|
||||
}
|
||||
|
||||
void BLI_unlock_thread(int type)
|
||||
{
|
||||
if(type==LOCK_MALLOC)
|
||||
pthread_mutex_unlock(&_malloc_lock);
|
||||
else
|
||||
if(type==LOCK_CUSTOM1)
|
||||
pthread_mutex_unlock(&_custom1_lock);
|
||||
}
|
||||
|
||||
|
||||
/* ***************** Thread safe MEM_malloc/calloc/free ************************** */
|
||||
|
||||
void *MEM_mallocT(int len, char *name)
|
||||
{
|
||||
void *mem;
|
||||
pthread_mutex_lock(&_malloc_lock);
|
||||
mem= MEM_mallocN(len, name);
|
||||
pthread_mutex_unlock(&_malloc_lock);
|
||||
return mem;
|
||||
}
|
||||
void *MEM_callocT(int len, char *name)
|
||||
{
|
||||
void *mem;
|
||||
pthread_mutex_lock(&_malloc_lock);
|
||||
mem= MEM_callocN(len, name);
|
||||
pthread_mutex_unlock(&_malloc_lock);
|
||||
return mem;
|
||||
}
|
||||
void *MEM_mapallocT(int len, char *name)
|
||||
{
|
||||
void *mem;
|
||||
pthread_mutex_lock(&_malloc_lock);
|
||||
mem= MEM_mapallocN(len, name);
|
||||
pthread_mutex_unlock(&_malloc_lock);
|
||||
return mem;
|
||||
}
|
||||
void MEM_freeT(void *poin)
|
||||
{
|
||||
pthread_mutex_lock(&_malloc_lock);
|
||||
MEM_freeN(poin);
|
||||
pthread_mutex_unlock(&_malloc_lock);
|
||||
}
|
||||
|
||||
|
||||
/* eof */
|
||||
|
||||
@@ -76,20 +76,21 @@ LIBEXPORT short freeN(void *vmemh)
|
||||
return MEM_freeN(vmemh);
|
||||
}
|
||||
|
||||
|
||||
/* these are not needed anymore, mallocN/callocN/freeN is now threadsafe */
|
||||
LIBEXPORT void *mallocT(int len, char *str)
|
||||
{
|
||||
return MEM_mallocT(len, str);
|
||||
return MEM_mallocN(len, str);
|
||||
}
|
||||
|
||||
LIBEXPORT void *callocT(int len, char *str)
|
||||
{
|
||||
return MEM_callocT(len, str);
|
||||
return MEM_callocN(len, str);
|
||||
}
|
||||
|
||||
LIBEXPORT void freeT(void *vmemh)
|
||||
{
|
||||
return MEM_freeT(vmemh);
|
||||
MEM_freeN(vmemh);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -141,7 +141,6 @@ void glaDrawPixelsSafe (float x, float y, int img_w, int img_h, int row_w, int
|
||||
*/
|
||||
|
||||
/* only for float rects, converts to 32 bits and draws */
|
||||
/* uses threadsafe malloc */
|
||||
void glaDrawPixelsSafe_to32(float fx, float fy, int img_w, int img_h, int row_w, float *rectf);
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
|
||||
#include "BLI_arithb.h"
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_threads.h"
|
||||
|
||||
#include "IMB_imbuf_types.h"
|
||||
#include "IMB_imbuf.h" /* for rectcpy */
|
||||
@@ -646,10 +645,9 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe
|
||||
if(env->ima && env->ima->ok) {
|
||||
if(env->ima->ibuf==NULL) {
|
||||
printf("load ibuf\n");
|
||||
BLI_lock_thread(LOCK_MALLOC);
|
||||
ima_ibuf_is_nul(tex, tex->ima);
|
||||
if(env->ima->ok && env->ok==0) envmap_split_ima(env);
|
||||
BLI_unlock_thread(LOCK_MALLOC);
|
||||
if(env->ima->ok && env->ok==0)
|
||||
envmap_split_ima(env);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@
|
||||
#include "DNA_texture_types.h"
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_threads.h"
|
||||
|
||||
#include "BKE_utildefines.h"
|
||||
#include "BKE_global.h"
|
||||
@@ -105,9 +104,8 @@ int imagewrap(Tex *tex, Image *ima, float *texvec, TexResult *texres)
|
||||
/* hack for icon render */
|
||||
if(R.r.scemode &R_NO_IMAGE_LOAD)
|
||||
return 0;
|
||||
BLI_lock_thread(LOCK_MALLOC);
|
||||
if(ima->ibuf==NULL) ima_ibuf_is_nul(tex, ima);
|
||||
BLI_unlock_thread(LOCK_MALLOC);
|
||||
if(ima->ibuf==NULL)
|
||||
ima_ibuf_is_nul(tex, ima);
|
||||
}
|
||||
|
||||
if (ima->ok) {
|
||||
@@ -628,21 +626,15 @@ int imagewraposa(Tex *tex, Image *ima, float *texvec, float *dxt, float *dyt, Te
|
||||
return retval;
|
||||
}
|
||||
|
||||
if(ima->ibuf==NULL) {
|
||||
BLI_lock_thread(LOCK_MALLOC);
|
||||
if(ima->ibuf==NULL) ima_ibuf_is_nul(tex, ima);
|
||||
BLI_unlock_thread(LOCK_MALLOC);
|
||||
}
|
||||
if(ima->ibuf==NULL)
|
||||
ima_ibuf_is_nul(tex, ima);
|
||||
|
||||
if (ima->ok) {
|
||||
|
||||
if(tex->imaflag & TEX_MIPMAP) {
|
||||
if(ima->mipmap[0]==NULL) {
|
||||
BLI_lock_thread(LOCK_MALLOC);
|
||||
if(ima->mipmap[0]==NULL) makemipmap(tex, ima);
|
||||
BLI_unlock_thread(LOCK_MALLOC);
|
||||
}
|
||||
}
|
||||
if(tex->imaflag & TEX_MIPMAP)
|
||||
if(ima->mipmap[0]==NULL)
|
||||
if(ima->mipmap[0]==NULL)
|
||||
makemipmap(tex, ima);
|
||||
|
||||
ibuf = ima->ibuf;
|
||||
|
||||
|
||||
@@ -163,28 +163,28 @@ static void free_render_result(RenderResult *res)
|
||||
while(res->layers.first) {
|
||||
RenderLayer *rl= res->layers.first;
|
||||
|
||||
if(rl->rectf) MEM_freeT(rl->rectf);
|
||||
if(rl->rectf) MEM_freeN(rl->rectf);
|
||||
/* acolrect is optionally allocated in shade_tile, only free here since it can be used for drawing */
|
||||
if(rl->acolrect) MEM_freeT(rl->acolrect);
|
||||
if(rl->acolrect) MEM_freeN(rl->acolrect);
|
||||
|
||||
while(rl->passes.first) {
|
||||
RenderPass *rpass= rl->passes.first;
|
||||
if(rpass->rect) MEM_freeT(rpass->rect);
|
||||
if(rpass->rect) MEM_freeN(rpass->rect);
|
||||
BLI_remlink(&rl->passes, rpass);
|
||||
MEM_freeT(rpass);
|
||||
MEM_freeN(rpass);
|
||||
}
|
||||
BLI_remlink(&res->layers, rl);
|
||||
MEM_freeT(rl);
|
||||
MEM_freeN(rl);
|
||||
}
|
||||
|
||||
if(res->rect32)
|
||||
MEM_freeT(res->rect32);
|
||||
MEM_freeN(res->rect32);
|
||||
if(res->rectz)
|
||||
MEM_freeT(res->rectz);
|
||||
MEM_freeN(res->rectz);
|
||||
if(res->rectf)
|
||||
MEM_freeT(res->rectf);
|
||||
MEM_freeN(res->rectf);
|
||||
|
||||
MEM_freeT(res);
|
||||
MEM_freeN(res);
|
||||
}
|
||||
|
||||
/* all layers except the active one get temporally pushed away */
|
||||
@@ -309,7 +309,7 @@ static void render_unique_exr_name(Render *re, char *str)
|
||||
static void render_layer_add_pass(RenderResult *rr, RenderLayer *rl, int channels, int passtype)
|
||||
{
|
||||
char *typestr= get_pass_name(passtype, 0);
|
||||
RenderPass *rpass= MEM_callocT(sizeof(RenderPass), typestr);
|
||||
RenderPass *rpass= MEM_callocN(sizeof(RenderPass), typestr);
|
||||
int rectsize= rr->rectx*rr->recty*channels;
|
||||
|
||||
BLI_addtail(&rl->passes, rpass);
|
||||
@@ -327,12 +327,12 @@ static void render_layer_add_pass(RenderResult *rr, RenderLayer *rl, int channel
|
||||
int x;
|
||||
|
||||
/* initialize to max speed */
|
||||
rect= rpass->rect= MEM_mapallocT(sizeof(float)*rectsize, typestr);
|
||||
rect= rpass->rect= MEM_mapallocN(sizeof(float)*rectsize, typestr);
|
||||
for(x= rectsize-1; x>=0; x--)
|
||||
rect[x]= PASS_VECTOR_MAX;
|
||||
}
|
||||
else
|
||||
rpass->rect= MEM_mapallocT(sizeof(float)*rectsize, typestr);
|
||||
rpass->rect= MEM_mapallocN(sizeof(float)*rectsize, typestr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ static RenderResult *new_render_result(Render *re, rcti *partrct, int crop, int
|
||||
if(rectx<=0 || recty<=0)
|
||||
return NULL;
|
||||
|
||||
rr= MEM_callocT(sizeof(RenderResult), "new render result");
|
||||
rr= MEM_callocN(sizeof(RenderResult), "new render result");
|
||||
rr->rectx= rectx;
|
||||
rr->recty= recty;
|
||||
rr->renrect.xmin= 0; rr->renrect.xmax= rectx-2*crop;
|
||||
@@ -399,7 +399,7 @@ static RenderResult *new_render_result(Render *re, rcti *partrct, int crop, int
|
||||
if((re->r.scemode & R_SINGLE_LAYER) && nr!=re->r.actlay)
|
||||
continue;
|
||||
|
||||
rl= MEM_callocT(sizeof(RenderLayer), "new render layer");
|
||||
rl= MEM_callocN(sizeof(RenderLayer), "new render layer");
|
||||
BLI_addtail(&rr->layers, rl);
|
||||
|
||||
strcpy(rl->name, srl->name);
|
||||
@@ -414,7 +414,7 @@ static RenderResult *new_render_result(Render *re, rcti *partrct, int crop, int
|
||||
IMB_exr_add_channel(rr->exrhandle, rl->name, "Combined.A");
|
||||
}
|
||||
else
|
||||
rl->rectf= MEM_mapallocT(rectx*recty*sizeof(float)*4, "Combined rgba");
|
||||
rl->rectf= MEM_mapallocN(rectx*recty*sizeof(float)*4, "Combined rgba");
|
||||
|
||||
if(srl->passflag & SCE_PASS_Z)
|
||||
render_layer_add_pass(rr, rl, 1, SCE_PASS_Z);
|
||||
@@ -438,10 +438,10 @@ static RenderResult *new_render_result(Render *re, rcti *partrct, int crop, int
|
||||
}
|
||||
/* previewrender and envmap don't do layers, so we make a default one */
|
||||
if(rr->layers.first==NULL) {
|
||||
rl= MEM_callocT(sizeof(RenderLayer), "new render layer");
|
||||
rl= MEM_callocN(sizeof(RenderLayer), "new render layer");
|
||||
BLI_addtail(&rr->layers, rl);
|
||||
|
||||
rl->rectf= MEM_mapallocT(rectx*recty*sizeof(float)*4, "prev/env float rgba");
|
||||
rl->rectf= MEM_mapallocN(rectx*recty*sizeof(float)*4, "prev/env float rgba");
|
||||
|
||||
/* note, this has to be in sync with scene.c */
|
||||
rl->lay= (1<<20) -1;
|
||||
@@ -716,7 +716,7 @@ Render *RE_NewRender(const char *name)
|
||||
if(re==NULL) {
|
||||
|
||||
/* new render data struct */
|
||||
re= MEM_callocT(sizeof(Render), "new render");
|
||||
re= MEM_callocN(sizeof(Render), "new render");
|
||||
BLI_addtail(&RenderList, re);
|
||||
strncpy(re->name, name, RE_MAXNAME);
|
||||
}
|
||||
@@ -751,7 +751,7 @@ void RE_FreeRender(Render *re)
|
||||
free_render_result(re->pushedresult);
|
||||
|
||||
BLI_remlink(&RenderList, re);
|
||||
MEM_freeT(re);
|
||||
MEM_freeN(re);
|
||||
}
|
||||
|
||||
/* exit blender */
|
||||
@@ -1921,13 +1921,13 @@ static void do_write_image_or_movie(Render *re, Scene *scene, bMovieHandle *mh)
|
||||
int dofree = 0;
|
||||
/* note; the way it gets 32 bits rects is weak... */
|
||||
if(rres.rect32==NULL) {
|
||||
rres.rect32= MEM_mapallocT(sizeof(int)*rres.rectx*rres.recty, "temp 32 bits rect");
|
||||
rres.rect32= MEM_mapallocN(sizeof(int)*rres.rectx*rres.recty, "temp 32 bits rect");
|
||||
dofree = 1;
|
||||
}
|
||||
RE_ResultGet32(re, rres.rect32);
|
||||
mh->append_movie(scene->r.cfra, rres.rect32, rres.rectx, rres.recty);
|
||||
if(dofree) {
|
||||
MEM_freeT(rres.rect32);
|
||||
MEM_freeN(rres.rect32);
|
||||
}
|
||||
printf("Append frame %d", scene->r.cfra);
|
||||
} else {
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
/* External modules: */
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "MTC_matrixops.h"
|
||||
|
||||
#include "BLI_arithb.h"
|
||||
@@ -3088,10 +3090,10 @@ static PixStrMain *addpsmain(ListBase *lb)
|
||||
{
|
||||
PixStrMain *psm;
|
||||
|
||||
psm= (PixStrMain *)MEM_mallocT(sizeof(PixStrMain),"pixstrMain");
|
||||
psm= (PixStrMain *)MEM_mallocN(sizeof(PixStrMain),"pixstrMain");
|
||||
BLI_addtail(lb, psm);
|
||||
|
||||
psm->ps= (PixStr *)MEM_mallocT(4096*sizeof(PixStr),"pixstr");
|
||||
psm->ps= (PixStr *)MEM_mallocN(4096*sizeof(PixStr),"pixstr");
|
||||
psm->counter= 0;
|
||||
|
||||
return psm;
|
||||
@@ -3104,8 +3106,8 @@ static void freeps(ListBase *lb)
|
||||
for(psm= lb->first; psm; psm= psmnext) {
|
||||
psmnext= psm->next;
|
||||
if(psm->ps)
|
||||
MEM_freeT(psm->ps);
|
||||
MEM_freeT(psm);
|
||||
MEM_freeN(psm->ps);
|
||||
MEM_freeN(psm);
|
||||
}
|
||||
lb->first= lb->last= NULL;
|
||||
}
|
||||
@@ -3189,15 +3191,15 @@ void zbufshadeDA_tile(RenderPart *pa)
|
||||
|
||||
/* allocate the necessary buffers */
|
||||
/* zbuffer inits these rects */
|
||||
pa->rectp= MEM_mallocT(sizeof(int)*pa->rectx*pa->recty, "rectp");
|
||||
pa->rectz= MEM_mallocT(sizeof(int)*pa->rectx*pa->recty, "rectz");
|
||||
pa->rectp= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectp");
|
||||
pa->rectz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectz");
|
||||
|
||||
for(rl= rr->layers.first; rl; rl= rl->next) {
|
||||
|
||||
/* initialize pixelstructs and edge buffer */
|
||||
addpsmain(&psmlist);
|
||||
pa->rectdaps= MEM_callocT(sizeof(long)*pa->rectx*pa->recty+4, "zbufDArectd");
|
||||
if(R.r.mode & R_EDGE) edgerect= MEM_callocT(sizeof(float)*pa->rectx*pa->recty, "rectedge");
|
||||
pa->rectdaps= MEM_callocN(sizeof(long)*pa->rectx*pa->recty+4, "zbufDArectd");
|
||||
if(R.r.mode & R_EDGE) edgerect= MEM_callocN(sizeof(float)*pa->rectx*pa->recty, "rectedge");
|
||||
|
||||
/* always fill visibility */
|
||||
for(pa->sample=0; pa->sample<R.osa; pa->sample++) {
|
||||
@@ -3235,7 +3237,7 @@ void zbufshadeDA_tile(RenderPart *pa)
|
||||
int x;
|
||||
|
||||
/* allocate, but not free here, for asynchronous display of this rect in main thread */
|
||||
rl->acolrect= MEM_callocT(4*sizeof(float)*pa->rectx*pa->recty, "alpha layer");
|
||||
rl->acolrect= MEM_callocN(4*sizeof(float)*pa->rectx*pa->recty, "alpha layer");
|
||||
|
||||
if(rl->passflag & SCE_PASS_VECTOR)
|
||||
if(rl->layflag & SCE_LAY_SOLID)
|
||||
@@ -3266,16 +3268,16 @@ void zbufshadeDA_tile(RenderPart *pa)
|
||||
convert_to_key_alpha(pa, rl->rectf);
|
||||
|
||||
/* free stuff within loop! */
|
||||
MEM_freeT(pa->rectdaps); pa->rectdaps= NULL;
|
||||
MEM_freeN(pa->rectdaps); pa->rectdaps= NULL;
|
||||
freeps(&psmlist);
|
||||
|
||||
if(edgerect) MEM_freeT(edgerect);
|
||||
if(edgerect) MEM_freeN(edgerect);
|
||||
edgerect= NULL;
|
||||
}
|
||||
|
||||
/* free all */
|
||||
MEM_freeT(pa->rectp); pa->rectp= NULL;
|
||||
MEM_freeT(pa->rectz); pa->rectz= NULL;
|
||||
MEM_freeN(pa->rectp); pa->rectp= NULL;
|
||||
MEM_freeN(pa->rectz); pa->rectz= NULL;
|
||||
|
||||
/* display active layer */
|
||||
rr->renrect.ymin=rr->renrect.ymax= 0;
|
||||
@@ -3297,14 +3299,14 @@ void zbufshade_tile(RenderPart *pa)
|
||||
set_part_zbuf_clipflag(pa);
|
||||
|
||||
/* zbuffer code clears/inits rects */
|
||||
pa->rectp= MEM_mallocT(sizeof(int)*pa->rectx*pa->recty, "rectp");
|
||||
pa->rectz= MEM_mallocT(sizeof(int)*pa->rectx*pa->recty, "rectz");
|
||||
pa->rectp= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectp");
|
||||
pa->rectz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectz");
|
||||
|
||||
shpi.thread= pa->thread;
|
||||
|
||||
for(rl= rr->layers.first; rl; rl= rl->next) {
|
||||
|
||||
if(R.r.mode & R_EDGE) edgerect= MEM_callocT(sizeof(float)*pa->rectx*pa->recty, "rectedge");
|
||||
if(R.r.mode & R_EDGE) edgerect= MEM_callocN(sizeof(float)*pa->rectx*pa->recty, "rectedge");
|
||||
|
||||
/* fill shadepixel info struct */
|
||||
shpi.lay= rl->lay;
|
||||
@@ -3369,7 +3371,7 @@ void zbufshade_tile(RenderPart *pa)
|
||||
int x;
|
||||
|
||||
/* allocate, but not free here, for asynchronous display of this rect in main thread */
|
||||
rl->acolrect= MEM_callocT(4*sizeof(float)*pa->rectx*pa->recty, "alpha layer");
|
||||
rl->acolrect= MEM_callocN(4*sizeof(float)*pa->rectx*pa->recty, "alpha layer");
|
||||
|
||||
if(addpassflag & SCE_PASS_VECTOR)
|
||||
if(rl->layflag & SCE_LAY_SOLID)
|
||||
@@ -3400,7 +3402,7 @@ void zbufshade_tile(RenderPart *pa)
|
||||
if(R.r.alphamode & R_ALPHAKEY)
|
||||
convert_to_key_alpha(pa, rl->rectf);
|
||||
|
||||
if(edgerect) MEM_freeT(edgerect);
|
||||
if(edgerect) MEM_freeN(edgerect);
|
||||
edgerect= NULL;
|
||||
}
|
||||
|
||||
@@ -3408,8 +3410,8 @@ void zbufshade_tile(RenderPart *pa)
|
||||
rr->renrect.ymin=rr->renrect.ymax= 0;
|
||||
rr->renlay= render_get_active_layer(&R, rr);
|
||||
|
||||
MEM_freeT(pa->rectp); pa->rectp= NULL;
|
||||
MEM_freeT(pa->rectz); pa->rectz= NULL;
|
||||
MEM_freeN(pa->rectp); pa->rectp= NULL;
|
||||
MEM_freeN(pa->rectz); pa->rectz= NULL;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
@@ -85,15 +85,15 @@ void zbuf_alloc_span(ZSpan *zspan, int rectx, int recty)
|
||||
zspan->rectx= rectx;
|
||||
zspan->recty= recty;
|
||||
|
||||
zspan->span1= MEM_mallocT(recty*sizeof(float), "zspan");
|
||||
zspan->span2= MEM_mallocT(recty*sizeof(float), "zspan");
|
||||
zspan->span1= MEM_mallocN(recty*sizeof(float), "zspan");
|
||||
zspan->span2= MEM_mallocN(recty*sizeof(float), "zspan");
|
||||
}
|
||||
|
||||
static void zbuf_free_span(ZSpan *zspan)
|
||||
{
|
||||
if(zspan) {
|
||||
if(zspan->span1) MEM_freeT(zspan->span1);
|
||||
if(zspan->span2) MEM_freeT(zspan->span2);
|
||||
if(zspan->span1) MEM_freeN(zspan->span1);
|
||||
if(zspan->span2) MEM_freeN(zspan->span2);
|
||||
zspan->span1= zspan->span2= NULL;
|
||||
}
|
||||
}
|
||||
@@ -259,9 +259,9 @@ static APixstr *addpsmainA(ListBase *lb)
|
||||
{
|
||||
APixstrMain *psm;
|
||||
|
||||
psm= MEM_mallocT(sizeof(APixstrMain), "addpsmainA");
|
||||
psm= MEM_mallocN(sizeof(APixstrMain), "addpsmainA");
|
||||
BLI_addtail(lb, psm);
|
||||
psm->ps= MEM_callocT(4096*sizeof(APixstr),"pixstr");
|
||||
psm->ps= MEM_callocN(4096*sizeof(APixstr),"pixstr");
|
||||
|
||||
return psm->ps;
|
||||
}
|
||||
@@ -273,8 +273,8 @@ static void freepsA(ListBase *lb)
|
||||
for(psm= lb->first; psm; psm= psmnext) {
|
||||
psmnext= psm->next;
|
||||
if(psm->ps)
|
||||
MEM_freeT(psm->ps);
|
||||
MEM_freeT(psm);
|
||||
MEM_freeN(psm->ps);
|
||||
MEM_freeN(psm);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2099,11 +2099,11 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
|
||||
zspan.zofsy= 0.0f;
|
||||
|
||||
/* the buffers */
|
||||
rectz= MEM_mapallocT(sizeof(float)*xsize*ysize, "zbuf accum");
|
||||
rectz= MEM_mapallocN(sizeof(float)*xsize*ysize, "zbuf accum");
|
||||
zspan.rectz= (int *)rectz;
|
||||
|
||||
rectmove= MEM_mapallocT(xsize*ysize, "rectmove");
|
||||
rectdraw= MEM_mapallocT(sizeof(DrawBufPixel)*xsize*ysize, "rect draw");
|
||||
rectmove= MEM_mapallocN(xsize*ysize, "rectmove");
|
||||
rectdraw= MEM_mapallocN(sizeof(DrawBufPixel)*xsize*ysize, "rect draw");
|
||||
zspan.rectp= (int *)rectdraw;
|
||||
|
||||
/* debug... check if PASS_VECTOR_MAX still is in buffers */
|
||||
@@ -2121,7 +2121,7 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
|
||||
float minspeed= (float)nbd->minspeed;
|
||||
float minspeedsq= minspeed*minspeed;
|
||||
|
||||
minvecbufrect= MEM_mapallocT(4*sizeof(float)*xsize*ysize, "minspeed buf");
|
||||
minvecbufrect= MEM_mapallocN(4*sizeof(float)*xsize*ysize, "minspeed buf");
|
||||
|
||||
dvec1= vecbufrect;
|
||||
dvec2= minvecbufrect;
|
||||
@@ -2147,7 +2147,7 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
|
||||
}
|
||||
|
||||
/* make vertex buffer with averaged speed and zvalues */
|
||||
rectvz= MEM_mapallocT(5*sizeof(float)*(xsize+1)*(ysize+1), "vertices");
|
||||
rectvz= MEM_mapallocN(5*sizeof(float)*(xsize+1)*(ysize+1), "vertices");
|
||||
dvz= rectvz;
|
||||
for(y=0; y<=ysize; y++) {
|
||||
|
||||
@@ -2343,11 +2343,11 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
|
||||
}
|
||||
}
|
||||
|
||||
MEM_freeT(rectz);
|
||||
MEM_freeT(rectmove);
|
||||
MEM_freeT(rectdraw);
|
||||
MEM_freeT(rectvz);
|
||||
if(minvecbufrect) MEM_freeT(vecbufrect); /* rects were swapped! */
|
||||
MEM_freeN(rectz);
|
||||
MEM_freeN(rectmove);
|
||||
MEM_freeN(rectdraw);
|
||||
MEM_freeN(rectvz);
|
||||
if(minvecbufrect) MEM_freeN(vecbufrect); /* rects were swapped! */
|
||||
zbuf_free_span(&zspan);
|
||||
}
|
||||
|
||||
@@ -2415,7 +2415,7 @@ static void zbuffer_abuf(RenderPart *pa, APixstr *APixbuf, ListBase *apsmbase, u
|
||||
zspan.zmuly= ((float)R.winy)/2.0;
|
||||
|
||||
/* the buffers */
|
||||
zspan.arectz= MEM_mallocT(sizeof(int)*pa->rectx*pa->recty, "Arectz");
|
||||
zspan.arectz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "Arectz");
|
||||
zspan.apixbuf= APixbuf;
|
||||
zspan.apsmbase= apsmbase;
|
||||
|
||||
@@ -2508,7 +2508,7 @@ static void zbuffer_abuf(RenderPart *pa, APixstr *APixbuf, ListBase *apsmbase, u
|
||||
if(R.test_break()) break;
|
||||
}
|
||||
|
||||
MEM_freeT(zspan.arectz);
|
||||
MEM_freeN(zspan.arectz);
|
||||
zbuf_free_span(&zspan);
|
||||
|
||||
}
|
||||
@@ -2694,7 +2694,7 @@ void zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pass)
|
||||
if(R.test_break())
|
||||
return;
|
||||
|
||||
APixbuf= MEM_callocT(pa->rectx*pa->recty*sizeof(APixstr), "APixbuf");
|
||||
APixbuf= MEM_callocN(pa->rectx*pa->recty*sizeof(APixstr), "APixbuf");
|
||||
|
||||
if(R.osa>16) {
|
||||
printf("abufsetrow: osa too large\n");
|
||||
@@ -2861,7 +2861,7 @@ void zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pass)
|
||||
/* disable scanline updating */
|
||||
rr->renlay= NULL;
|
||||
|
||||
MEM_freeT(APixbuf);
|
||||
MEM_freeN(APixbuf);
|
||||
freepsA(&apsmbase);
|
||||
|
||||
}
|
||||
|
||||
@@ -297,8 +297,7 @@ void glaDrawPixelsSafe_to32(float fx, float fy, int img_w, int img_h, int row_w,
|
||||
/* copy imgw-imgh to a temporal 32 bits rect */
|
||||
if(img_w<1 || img_h<1) return;
|
||||
|
||||
/* happens during threaded render... */
|
||||
rc= rect32= MEM_mallocT(img_w*img_h*sizeof(int), "temp 32 bits");
|
||||
rc= rect32= MEM_mallocN(img_w*img_h*sizeof(int), "temp 32 bits");
|
||||
|
||||
for(y=0; y<img_h; y++) {
|
||||
rf= rectf;
|
||||
@@ -312,8 +311,8 @@ void glaDrawPixelsSafe_to32(float fx, float fy, int img_w, int img_h, int row_w,
|
||||
}
|
||||
|
||||
glaDrawPixelsSafe(fx, fy, img_w, img_h, img_w, GL_RGBA, GL_UNSIGNED_BYTE, rect32);
|
||||
|
||||
MEM_freeT(rect32);
|
||||
|
||||
MEM_freeN(rect32);
|
||||
}
|
||||
|
||||
void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int format, int type, void *rect)
|
||||
|
||||
Reference in New Issue
Block a user