diff options
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/boxpack2d.c | 28 | ||||
-rw-r--r-- | source/blender/blenlib/intern/bpath.c | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/fileops.c | 70 | ||||
-rw-r--r-- | source/blender/blenlib/intern/freetypefont.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_color.c | 28 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_color_inline.c | 7 | ||||
-rw-r--r-- | source/blender/blenlib/intern/pbvh.c | 202 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string_utf8.c | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/threads.c | 51 |
9 files changed, 228 insertions, 168 deletions
diff --git a/source/blender/blenlib/intern/boxpack2d.c b/source/blender/blenlib/intern/boxpack2d.c index bf63517a4c2..feaa60b40b2 100644 --- a/source/blender/blenlib/intern/boxpack2d.c +++ b/source/blender/blenlib/intern/boxpack2d.c @@ -33,7 +33,7 @@ * * The defined Below are for internal use only */ -typedef struct boxVert { +typedef struct BoxVert { float x; float y; short free; @@ -48,7 +48,7 @@ typedef struct boxVert { struct BoxPack *isect_cache[4]; int index; -} boxVert; +} BoxVert; /* free vert flags */ #define EPSILON 0.0000001f @@ -121,11 +121,11 @@ static int box_areasort(const void *p1, const void *p2) * */ static float box_width; static float box_height; -static boxVert *vertarray; +static BoxVert *vertarray; static int vertex_sort(const void *p1, const void *p2) { - boxVert *v1, *v2; + BoxVert *v1, *v2; float a1, a2; v1 = vertarray + ((int *)p1)[0]; @@ -154,7 +154,7 @@ static int vertex_sort(const void *p1, const void *p2) * */ void BLI_box_pack_2D(BoxPack *boxarray, const int len, float *tot_width, float *tot_height) { - boxVert *vert; /* the current vert */ + BoxVert *vert; /* the current vert */ int box_index, verts_pack_len, i, j, k, isect; int quad_flags[4] = {BLF, TRF, TLF, BRF}; /* use for looping */ BoxPack *box, *box_test; /*current box and another for intersection tests*/ @@ -170,38 +170,38 @@ void BLI_box_pack_2D(BoxPack *boxarray, const int len, float *tot_width, float * qsort(boxarray, len, sizeof(BoxPack), box_areasort); /* add verts to the boxes, these are only used internally */ - vert = vertarray = MEM_mallocN(len * 4 * sizeof(boxVert), "BoxPack Verts"); + vert = vertarray = MEM_mallocN(len * 4 * sizeof(BoxVert), "BoxPack Verts"); vertex_pack_indices = MEM_mallocN(len * 3 * sizeof(int), "BoxPack Indices"); for (box = boxarray, box_index = 0, i = 0; box_index < len; box_index++, box++) { vert->blb = vert->brb = vert->tlb = - vert->isect_cache[0] = vert->isect_cache[1] = - vert->isect_cache[2] = vert->isect_cache[3] = NULL; + vert->isect_cache[0] = vert->isect_cache[1] = + vert->isect_cache[2] = vert->isect_cache[3] = NULL; vert->free = CORNERFLAGS & ~TRF; vert->trb = box; vert->index = i; i++; box->v[BL] = vert; vert++; vert->trb = vert->brb = vert->tlb = - vert->isect_cache[0] = vert->isect_cache[1] = - vert->isect_cache[2] = vert->isect_cache[3] = NULL; + vert->isect_cache[0] = vert->isect_cache[1] = + vert->isect_cache[2] = vert->isect_cache[3] = NULL; vert->free = CORNERFLAGS & ~BLF; vert->blb = box; vert->index = i; i++; box->v[TR] = vert; vert++; vert->trb = vert->blb = vert->tlb = - vert->isect_cache[0] = vert->isect_cache[1] = - vert->isect_cache[2] = vert->isect_cache[3] = NULL; + vert->isect_cache[0] = vert->isect_cache[1] = + vert->isect_cache[2] = vert->isect_cache[3] = NULL; vert->free = CORNERFLAGS & ~BRF; vert->brb = box; vert->index = i; i++; box->v[TL] = vert; vert++; vert->trb = vert->blb = vert->brb = - vert->isect_cache[0] = vert->isect_cache[1] = - vert->isect_cache[2] = vert->isect_cache[3] = NULL; + vert->isect_cache[0] = vert->isect_cache[1] = + vert->isect_cache[2] = vert->isect_cache[3] = NULL; vert->free = CORNERFLAGS & ~TLF; vert->tlb = box; vert->index = i; i++; diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index 131ea59d3e5..85391336c86 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -510,11 +510,11 @@ void BLI_bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int SEQ_BEGIN(scene->ed, seq) { if (SEQ_HAS_PATH(seq)) { - if (ELEM(seq->type, SEQ_MOVIE, SEQ_SOUND)) { + if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM)) { rewrite_path_fixed_dirfile(seq->strip->dir, seq->strip->stripdata->name, visit_cb, absbase, bpath_user_data); } - else if (seq->type == SEQ_IMAGE) { + else if (seq->type == SEQ_TYPE_IMAGE) { /* might want an option not to loop over all strips */ StripElem *se = seq->strip->stripdata; int len = MEM_allocN_len(se) / sizeof(*se); diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index e6d06484e74..ec7b59702bd 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -385,16 +385,16 @@ int BLI_rename(const char *from, const char *to) enum { /* operation succeeded succeeded */ - recursiveOp_Callback_OK = 0, + RecursiveOp_Callback_OK = 0, /* operation requested not to perform recursive digging for current path */ - recursiveOp_Callback_StopRecurs = 1, + RecursiveOp_Callback_StopRecurs = 1, /* error occured in callback and recursive walking should stop immediately */ - recursiveOp_Callback_Error = 2 + RecursiveOp_Callback_Error = 2 } recuresiveOp_Callback_Result; -typedef int (*recursiveOp_Callback)(const char *from, const char *to); +typedef int (*RecursiveOp_Callback)(const char *from, const char *to); /* appending of filename to dir (ensures for buffer size before appending) */ static void join_dirfile_alloc(char **dst, size_t *alloc_len, const char *dir, const char *file) @@ -419,8 +419,8 @@ static char *strip_last_slash(const char *dir) return result; } -static int recursive_operation(const char *startfrom, const char *startto, recursiveOp_Callback callback_dir_pre, - recursiveOp_Callback callback_file, recursiveOp_Callback callback_dir_post) +static int recursive_operation(const char *startfrom, const char *startto, RecursiveOp_Callback callback_dir_pre, + RecursiveOp_Callback callback_file, RecursiveOp_Callback callback_dir_post) { struct dirent **dirlist; struct stat st; @@ -446,7 +446,7 @@ static int recursive_operation(const char *startfrom, const char *startto, recur if (callback_file) { ret = callback_file(from, to); - if (ret != recursiveOp_Callback_OK) + if (ret != RecursiveOp_Callback_OK) ret = -1; } @@ -472,11 +472,11 @@ static int recursive_operation(const char *startfrom, const char *startto, recur /* call pre-recursive walking directory callback */ ret = callback_dir_pre(from, to); - if (ret != recursiveOp_Callback_OK) { + if (ret != RecursiveOp_Callback_OK) { MEM_freeN(from); if (to) free(to); - if (ret == recursiveOp_Callback_StopRecurs) { + if (ret == RecursiveOp_Callback_StopRecurs) { /* callback requested not to perform recursive walking, not an error */ return 0; } @@ -505,7 +505,7 @@ static int recursive_operation(const char *startfrom, const char *startto, recur else if (callback_file) { /* call file callback for current path */ ret = callback_file(from_path, to_path); - if (ret != recursiveOp_Callback_OK) + if (ret != RecursiveOp_Callback_OK) ret = -1; } @@ -522,7 +522,7 @@ static int recursive_operation(const char *startfrom, const char *startto, recur if (callback_dir_post) { /* call post-recursive directory callback */ ret = callback_dir_post(from, to); - if (ret != recursiveOp_Callback_OK) + if (ret != RecursiveOp_Callback_OK) ret = -1; } } @@ -541,10 +541,10 @@ static int delete_callback_post(const char *from, const char *UNUSED(to)) if (rmdir(from)) { perror("rmdir"); - return recursiveOp_Callback_Error; + return RecursiveOp_Callback_Error; } - return recursiveOp_Callback_OK; + return RecursiveOp_Callback_OK; } static int delete_single_file(const char *from, const char *UNUSED(to)) @@ -552,10 +552,10 @@ static int delete_single_file(const char *from, const char *UNUSED(to)) if (unlink(from)) { perror("unlink"); - return recursiveOp_Callback_Error; + return RecursiveOp_Callback_Error; } - return recursiveOp_Callback_OK; + return RecursiveOp_Callback_OK; } FILE *BLI_fopen(const char *filename, const char *mode) @@ -628,27 +628,27 @@ static int copy_callback_pre(const char *from, const char *to) if (check_the_same(from, to)) { fprintf(stderr, "%s: '%s' is the same as '%s'\n", __func__, from, to); - return recursiveOp_Callback_Error; + return RecursiveOp_Callback_Error; } if (lstat(from, &st)) { perror("stat"); - return recursiveOp_Callback_Error; + return RecursiveOp_Callback_Error; } /* create a directory */ if (mkdir(to, st.st_mode)) { perror("mkdir"); - return recursiveOp_Callback_Error; + return RecursiveOp_Callback_Error; } /* set proper owner and group on new directory */ if (chown(to, st.st_uid, st.st_gid)) { perror("chown"); - return recursiveOp_Callback_Error; + return RecursiveOp_Callback_Error; } - return recursiveOp_Callback_OK; + return RecursiveOp_Callback_OK; } static int copy_single_file(const char *from, const char *to) @@ -660,12 +660,12 @@ static int copy_single_file(const char *from, const char *to) if (check_the_same(from, to)) { fprintf(stderr, "%s: '%s' is the same as '%s'\n", __func__, from, to); - return recursiveOp_Callback_Error; + return RecursiveOp_Callback_Error; } if (lstat(from, &st)) { perror("lstat"); - return recursiveOp_Callback_Error; + return RecursiveOp_Callback_Error; } if (S_ISLNK(st.st_mode)) { @@ -690,7 +690,7 @@ static int copy_single_file(const char *from, const char *to) if (need_free) MEM_freeN(link_buffer); - return recursiveOp_Callback_Error; + return RecursiveOp_Callback_Error; } link_buffer[link_len] = 0; @@ -698,13 +698,13 @@ static int copy_single_file(const char *from, const char *to) if (symlink(link_buffer, to)) { perror("symlink"); if (need_free) MEM_freeN(link_buffer); - return recursiveOp_Callback_Error; + return RecursiveOp_Callback_Error; } if (need_free) MEM_freeN(link_buffer); - return recursiveOp_Callback_OK; + return RecursiveOp_Callback_OK; } else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) || @@ -714,30 +714,30 @@ static int copy_single_file(const char *from, const char *to) /* copy special type of file */ if (mknod(to, st.st_mode, st.st_rdev)) { perror("mknod"); - return recursiveOp_Callback_Error; + return RecursiveOp_Callback_Error; } if (set_permissions(to, &st)) - return recursiveOp_Callback_Error; + return RecursiveOp_Callback_Error; - return recursiveOp_Callback_OK; + return RecursiveOp_Callback_OK; } else if (!S_ISREG(st.st_mode)) { fprintf(stderr, "Copying of this kind of files isn't supported yet\n"); - return recursiveOp_Callback_Error; + return RecursiveOp_Callback_Error; } from_stream = fopen(from, "rb"); if (!from_stream) { perror("fopen"); - return recursiveOp_Callback_Error; + return RecursiveOp_Callback_Error; } to_stream = fopen(to, "wb"); if (!to_stream) { perror("fopen"); fclose(from_stream); - return recursiveOp_Callback_Error; + return RecursiveOp_Callback_Error; } while ((len = fread(buf, 1, sizeof(buf), from_stream)) > 0) { @@ -748,9 +748,9 @@ static int copy_single_file(const char *from, const char *to) fclose(from_stream); if (set_permissions(to, &st)) - return recursiveOp_Callback_Error; + return RecursiveOp_Callback_Error; - return recursiveOp_Callback_OK; + return RecursiveOp_Callback_OK; } static int move_callback_pre(const char *from, const char *to) @@ -760,7 +760,7 @@ static int move_callback_pre(const char *from, const char *to) if (ret) return copy_callback_pre(from, to); - return recursiveOp_Callback_StopRecurs; + return RecursiveOp_Callback_StopRecurs; } static int move_single_file(const char *from, const char *to) @@ -770,7 +770,7 @@ static int move_single_file(const char *from, const char *to) if (ret) return copy_single_file(from, to); - return recursiveOp_Callback_OK; + return RecursiveOp_Callback_OK; } int BLI_move(const char *file, const char *to) diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c index da07bb156d7..ef2eb25a891 100644 --- a/source/blender/blenlib/intern/freetypefont.c +++ b/source/blender/blenlib/intern/freetypefont.c @@ -614,7 +614,7 @@ font driver produces such outlines. # \ # - Two "on" points + Two "on" points and two "cubic" point between them diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c index 9433cfd31df..5b034bd2872 100644 --- a/source/blender/blenlib/intern/math_color.c +++ b/source/blender/blenlib/intern/math_color.c @@ -285,8 +285,8 @@ void rgb_to_hsl(float r, float g, float b, float *lh, float *ls, float *ll) else { h = (r - g) / d + 4.0f; } - } - h /= 6.0f; + } + h /= 6.0f; *lh = h; *ls = s; @@ -634,23 +634,23 @@ void BLI_init_srgb_conversion(void) } static float inverse_srgb_companding(float v) { - if (v > 0.04045f) { - return powf((v + 0.055f) / 1.055f, 2.4); - } - else { - return v / 12.92f; - } + if (v > 0.04045f) { + return powf((v + 0.055f) / 1.055f, 2.4); + } + else { + return v / 12.92f; + } } void rgb_to_xyz(float r, float g, float b, float *x, float *y, float *z) { - r = inverse_srgb_companding(r) * 100.0f; - g = inverse_srgb_companding(g) * 100.0f; - b = inverse_srgb_companding(b) * 100.0f; + r = inverse_srgb_companding(r) * 100.0f; + g = inverse_srgb_companding(g) * 100.0f; + b = inverse_srgb_companding(b) * 100.0f; - *x = r * 0.4124 + g * 0.3576 + b * 0.1805; - *y = r * 0.2126 + g * 0.7152 + b * 0.0722; - *z = r * 0.0193 + g * 0.1192 + b * 0.9505; + *x = r * 0.4124 + g * 0.3576 + b * 0.1805; + *y = r * 0.2126 + g * 0.7152 + b * 0.0722; + *z = r * 0.0193 + g * 0.1192 + b * 0.9505; } static float xyz_to_lab_component(float v) diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c index 243e9fc8a57..b2a87a91433 100644 --- a/source/blender/blenlib/intern/math_color_inline.c +++ b/source/blender/blenlib/intern/math_color_inline.c @@ -215,4 +215,11 @@ MINLINE void rgba_char_args_test_set(char col[4], const char r, const char g, co } } +MINLINE void cpack_cpy_3ub(unsigned char r_col[3], const unsigned int pack) +{ + r_col[0] = ((pack) >> 0) & 0xFF; + r_col[1] = ((pack) >> 8) & 0xFF; + r_col[2] = ((pack) >> 16) & 0xFF; +} + #endif /* __MATH_COLOR_INLINE_C__ */ diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c index f4b57857173..5361682caa4 100644 --- a/source/blender/blenlib/intern/pbvh.c +++ b/source/blender/blenlib/intern/pbvh.c @@ -1137,17 +1137,21 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode) if (node->flag & PBVH_RebuildDrawBuffers) { GPU_free_buffers(node->draw_buffers); - if (bvh->grids) { - node->draw_buffers = - GPU_build_grid_buffers(node->prim_indices, - node->totprim, bvh->grid_hidden, bvh->gridkey.grid_size); - } - else { - node->draw_buffers = - GPU_build_mesh_buffers(node->face_vert_indices, - bvh->faces, bvh->verts, - node->prim_indices, - node->totprim); + switch (bvh->type) { + case PBVH_GRIDS: + node->draw_buffers = + GPU_build_grid_buffers(node->prim_indices, + node->totprim, + bvh->grid_hidden, + bvh->gridkey.grid_size); + break; + case PBVH_FACES: + node->draw_buffers = + GPU_build_mesh_buffers(node->face_vert_indices, + bvh->faces, bvh->verts, + node->prim_indices, + node->totprim); + break; } node->flag &= ~PBVH_RebuildDrawBuffers; @@ -1473,7 +1477,8 @@ static int ray_aabb_intersect(PBVHNode *node, void *data_v) } void BLI_pbvh_raycast(PBVH *bvh, BLI_pbvh_HitOccludedCallback cb, void *data, - float ray_start[3], float ray_normal[3], int original) + const float ray_start[3], const float ray_normal[3], + int original) { RaycastData rcd; @@ -1489,8 +1494,10 @@ void BLI_pbvh_raycast(PBVH *bvh, BLI_pbvh_HitOccludedCallback cb, void *data, BLI_pbvh_search_callback_occluded(bvh, ray_aabb_intersect, &rcd, cb, data); } -static int ray_face_intersection(float ray_start[3], float ray_normal[3], - float *t0, float *t1, float *t2, float *t3, +static int ray_face_intersection(const float ray_start[3], + const float ray_normal[3], + const float *t0, const float *t1, + const float *t2, const float *t3, float *fdist) { float dist; @@ -1506,91 +1513,114 @@ static int ray_face_intersection(float ray_start[3], float ray_normal[3], } } -int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], - float ray_start[3], float ray_normal[3], float *dist) +static int pbvh_faces_node_raycast(PBVH *bvh, const PBVHNode *node, + float (*origco)[3], + const float ray_start[3], + const float ray_normal[3], float *dist) { - MVert *vert; - BLI_bitmap gh; - int *faces, totface, gridsize, totgrid; + const MVert *vert = bvh->verts; + const int *faces = node->prim_indices; + int i, hit = 0, totface = node->totprim; + + for (i = 0; i < totface; ++i) { + const MFace *f = bvh->faces + faces[i]; + const int *face_verts = node->face_vert_indices[i]; + + if (paint_is_face_hidden(f, vert)) + continue; + + if (origco) { + /* intersect with backuped original coordinates */ + hit |= ray_face_intersection(ray_start, ray_normal, + origco[face_verts[0]], + origco[face_verts[1]], + origco[face_verts[2]], + f->v4 ? origco[face_verts[3]] : NULL, + dist); + } + else { + /* intersect with current coordinates */ + hit |= ray_face_intersection(ray_start, ray_normal, + vert[f->v1].co, + vert[f->v2].co, + vert[f->v3].co, + f->v4 ? vert[f->v4].co : NULL, + dist); + } + } + + return hit; +} + +static int pbvh_grids_node_raycast(PBVH *bvh, PBVHNode *node, + float (*origco)[3], + const float ray_start[3], + const float ray_normal[3], float *dist) +{ + int totgrid = node->totprim; + int gridsize = bvh->gridkey.grid_size; int i, x, y, hit = 0; - if (node->flag & PBVH_FullyHidden) - return 0; + for (i = 0; i < totgrid; ++i) { + CCGElem *grid = bvh->grids[node->prim_indices[i]]; + BLI_bitmap gh; - switch (bvh->type) { - case PBVH_FACES: - vert = bvh->verts; - faces = node->prim_indices; - totface = node->totprim; + if (!grid) + continue; - for (i = 0; i < totface; ++i) { - const MFace *f = bvh->faces + faces[i]; - int *face_verts = node->face_vert_indices[i]; + gh = bvh->grid_hidden[node->prim_indices[i]]; - if (paint_is_face_hidden(f, vert)) - continue; + for (y = 0; y < gridsize - 1; ++y) { + for (x = 0; x < gridsize - 1; ++x) { + /* check if grid face is hidden */ + if (gh) { + if (paint_is_grid_face_hidden(gh, gridsize, x, y)) + continue; + } if (origco) { - /* intersect with backuped original coordinates */ hit |= ray_face_intersection(ray_start, ray_normal, - origco[face_verts[0]], - origco[face_verts[1]], - origco[face_verts[2]], - f->v4 ? origco[face_verts[3]] : NULL, - dist); + origco[y * gridsize + x], + origco[y * gridsize + x + 1], + origco[(y + 1) * gridsize + x + 1], + origco[(y + 1) * gridsize + x], + dist); } else { - /* intersect with current coordinates */ hit |= ray_face_intersection(ray_start, ray_normal, - vert[f->v1].co, - vert[f->v2].co, - vert[f->v3].co, - f->v4 ? vert[f->v4].co : NULL, - dist); + CCG_grid_elem_co(&bvh->gridkey, grid, x, y), + CCG_grid_elem_co(&bvh->gridkey, grid, x + 1, y), + CCG_grid_elem_co(&bvh->gridkey, grid, x + 1, y + 1), + CCG_grid_elem_co(&bvh->gridkey, grid, x, y + 1), + dist); } } + } + + if (origco) + origco += gridsize * gridsize; + } + + return hit; +} + +int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], + const float ray_start[3], const float ray_normal[3], + float *dist) +{ + int hit = 0; + + if (node->flag & PBVH_FullyHidden) + return 0; + + switch (bvh->type) { + case PBVH_FACES: + hit |= pbvh_faces_node_raycast(bvh, node, origco, + ray_start, ray_normal, dist); break; case PBVH_GRIDS: - totgrid = node->totprim; - gridsize = bvh->gridkey.grid_size; - - for (i = 0; i < totgrid; ++i) { - CCGElem *grid = bvh->grids[node->prim_indices[i]]; - if (!grid) - continue; - - gh = bvh->grid_hidden[node->prim_indices[i]]; - - for (y = 0; y < gridsize - 1; ++y) { - for (x = 0; x < gridsize - 1; ++x) { - /* check if grid face is hidden */ - if (gh) { - if (paint_is_grid_face_hidden(gh, gridsize, x, y)) - continue; - } - - if (origco) { - hit |= ray_face_intersection(ray_start, ray_normal, - origco[y * gridsize + x], - origco[y * gridsize + x + 1], - origco[(y + 1) * gridsize + x + 1], - origco[(y + 1) * gridsize + x], - dist); - } - else { - hit |= ray_face_intersection(ray_start, ray_normal, - CCG_grid_elem_co(&bvh->gridkey, grid, x, y), - CCG_grid_elem_co(&bvh->gridkey, grid, x + 1, y), - CCG_grid_elem_co(&bvh->gridkey, grid, x + 1, y + 1), - CCG_grid_elem_co(&bvh->gridkey, grid, x, y + 1), - dist); - } - } - } - - if (origco) - origco += gridsize * gridsize; - } + hit |= pbvh_grids_node_raycast(bvh, node, origco, + ray_start, ray_normal, dist); break; } @@ -1787,11 +1817,7 @@ PBVHProxyNode *BLI_pbvh_node_add_proxy(PBVH *bvh, PBVHNode *node) else node->proxies = MEM_mallocN(sizeof(PBVHProxyNode), "PBVHNodeProxy"); - if (bvh->grids) - totverts = node->totprim * bvh->gridkey.grid_area; - else - totverts = node->uniq_verts; - + BLI_pbvh_node_num_verts(bvh, node, &totverts, NULL); node->proxies[index].co = MEM_callocN(sizeof(float[3]) * totverts, "PBVHNodeProxy.co"); } diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c index e9bccd4244b..9795d4dea2d 100644 --- a/source/blender/blenlib/intern/string_utf8.c +++ b/source/blender/blenlib/intern/string_utf8.c @@ -335,9 +335,9 @@ size_t BLI_strncpy_wchar_from_utf8(wchar_t *dst_w, const char *src_c, const size int BLI_str_utf8_size(const char *p) { int mask = 0, len; - unsigned char c = (unsigned char) *p; + unsigned char c = (unsigned char) *p; - UTF8_COMPUTE (c, mask, len); + UTF8_COMPUTE (c, mask, len); (void)mask; /* quiet warning */ diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c index f9f677d7c22..dc4c15a82fc 100644 --- a/source/blender/blenlib/intern/threads.c +++ b/source/blender/blenlib/intern/threads.c @@ -520,8 +520,10 @@ void BLI_insert_work(ThreadedWorker *worker, void *param) struct ThreadQueue { GSQueue *queue; pthread_mutex_t mutex; - pthread_cond_t cond; - int nowait; + pthread_cond_t push_cond; + pthread_cond_t finish_cond; + volatile int nowait; + volatile int cancelled; }; ThreadQueue *BLI_thread_queue_init(void) @@ -532,14 +534,17 @@ ThreadQueue *BLI_thread_queue_init(void) queue->queue = BLI_gsqueue_new(sizeof(void *)); pthread_mutex_init(&queue->mutex, NULL); - pthread_cond_init(&queue->cond, NULL); + pthread_cond_init(&queue->push_cond, NULL); + pthread_cond_init(&queue->finish_cond, NULL); return queue; } void BLI_thread_queue_free(ThreadQueue *queue) { - pthread_cond_destroy(&queue->cond); + /* destroy everything, assumes no one is using queue anymore */ + pthread_cond_destroy(&queue->finish_cond); + pthread_cond_destroy(&queue->push_cond); pthread_mutex_destroy(&queue->mutex); BLI_gsqueue_free(queue->queue); @@ -554,7 +559,7 @@ void BLI_thread_queue_push(ThreadQueue *queue, void *work) BLI_gsqueue_push(queue->queue, &work); /* signal threads waiting to pop */ - pthread_cond_signal(&queue->cond); + pthread_cond_signal(&queue->push_cond); pthread_mutex_unlock(&queue->mutex); } @@ -565,11 +570,15 @@ void *BLI_thread_queue_pop(ThreadQueue *queue) /* wait until there is work */ pthread_mutex_lock(&queue->mutex); while (BLI_gsqueue_is_empty(queue->queue) && !queue->nowait) - pthread_cond_wait(&queue->cond, &queue->mutex); - + pthread_cond_wait(&queue->push_cond, &queue->mutex); + /* if we have something, pop it */ - if (!BLI_gsqueue_is_empty(queue->queue)) + if (!BLI_gsqueue_is_empty(queue->queue)) { BLI_gsqueue_pop(queue->queue, &work); + + if(BLI_gsqueue_is_empty(queue->queue)) + pthread_cond_broadcast(&queue->finish_cond); + } pthread_mutex_unlock(&queue->mutex); @@ -623,16 +632,20 @@ void *BLI_thread_queue_pop_timeout(ThreadQueue *queue, int ms) /* wait until there is work */ pthread_mutex_lock(&queue->mutex); while (BLI_gsqueue_is_empty(queue->queue) && !queue->nowait) { - if (pthread_cond_timedwait(&queue->cond, &queue->mutex, &timeout) == ETIMEDOUT) + if (pthread_cond_timedwait(&queue->push_cond, &queue->mutex, &timeout) == ETIMEDOUT) break; else if (PIL_check_seconds_timer() - t >= ms * 0.001) break; } /* if we have something, pop it */ - if (!BLI_gsqueue_is_empty(queue->queue)) + if (!BLI_gsqueue_is_empty(queue->queue)) { BLI_gsqueue_pop(queue->queue, &work); - + + if(BLI_gsqueue_is_empty(queue->queue)) + pthread_cond_broadcast(&queue->finish_cond); + } + pthread_mutex_unlock(&queue->mutex); return work; @@ -656,10 +669,23 @@ void BLI_thread_queue_nowait(ThreadQueue *queue) queue->nowait = 1; /* signal threads waiting to pop */ - pthread_cond_signal(&queue->cond); + pthread_cond_broadcast(&queue->push_cond); + pthread_mutex_unlock(&queue->mutex); +} + +void BLI_thread_queue_wait_finish(ThreadQueue *queue) +{ + /* wait for finish condition */ + pthread_mutex_lock(&queue->mutex); + + while(!BLI_gsqueue_is_empty(queue->queue)) + pthread_cond_wait(&queue->finish_cond, &queue->mutex); + pthread_mutex_unlock(&queue->mutex); } +/* ************************************************ */ + void BLI_begin_threaded_malloc(void) { if (thread_levels == 0) { @@ -674,3 +700,4 @@ void BLI_end_threaded_malloc(void) if (thread_levels == 0) MEM_set_lock_callback(NULL, NULL); } + |