Exemplo n.º 1
0
void seq_stripelem_cache_init(void)
{
	hash = BLI_ghash_new(HashHash, HashCmp, "seq stripelem cache hash");
	limitor = new_MEM_CacheLimiter( IMB_seq_cache_destructor );

	entrypool = BLI_mempool_create(sizeof(seqCacheEntry), 64, 64, 0);
	keypool = BLI_mempool_create(sizeof(seqCacheKey), 64, 64, 0);
}
Exemplo n.º 2
0
BME_Mesh *BME_make_mesh(int allocsize[4])
{
	/*allocate the structure*/
	BME_Mesh *bm = MEM_callocN(sizeof(BME_Mesh),"BMesh");
	/*allocate the memory pools for the mesh elements*/
	bm->vpool = BLI_mempool_create(sizeof(BME_Vert), allocsize[0], allocsize[0], 0);
	bm->epool = BLI_mempool_create(sizeof(BME_Edge), allocsize[1], allocsize[1], 0);
	bm->lpool = BLI_mempool_create(sizeof(BME_Loop), allocsize[2], allocsize[2], 0);
	bm->ppool = BLI_mempool_create(sizeof(BME_Poly), allocsize[3], allocsize[3], 0);
	return bm;
}
Exemplo n.º 3
0
static void check_persistent(SpaceOops *soops, TreeElement *te, ID *id, short type, short nr)
{
	TreeStoreElem *tselem;
	
	if (soops->treestore == NULL) {
		/* if treestore was not created in readfile.c, create it here */
		soops->treestore = BLI_mempool_create(sizeof(TreeStoreElem), 1, 512, BLI_MEMPOOL_ALLOW_ITER);
		
	}
	if (soops->treehash == NULL) {
		soops->treehash = BKE_treehash_create_from_treestore(soops->treestore);
	}

	/* find any unused tree element in treestore and mark it as used
	 * (note that there may be multiple unused elements in case of linked objects) */
	tselem = BKE_treehash_lookup_unused(soops->treehash, type, nr, id);
	if (tselem) {
		te->store_elem = tselem;
		tselem->used = 1;
		return;
	}

	/* add 1 element to treestore */
	tselem = BLI_mempool_alloc(soops->treestore);
	tselem->type = type;
	tselem->nr = type ? nr : 0;
	tselem->id = id;
	tselem->used = 0;
	tselem->flag = TSE_CLOSED;
	te->store_elem = tselem;
	BKE_treehash_add_element(soops->treehash, tselem);
}
Exemplo n.º 4
0
static void outliner_storage_cleanup(SpaceOops *soops)
{
	BLI_mempool *ts = soops->treestore;
	
	if (ts) {
		TreeStoreElem *tselem;
		int unused = 0;
		
		/* each element used once, for ID blocks with more users to have each a treestore */
		BLI_mempool_iter iter;

		BLI_mempool_iternew(ts, &iter);
		while ((tselem = BLI_mempool_iterstep(&iter))) {
			tselem->used = 0;
		}
		
		/* cleanup only after reading file or undo step, and always for
		 * RNA datablocks view in order to save memory */
		if (soops->storeflag & SO_TREESTORE_CLEANUP) {
			BLI_mempool_iternew(ts, &iter);
			while ((tselem = BLI_mempool_iterstep(&iter))) {
				if (tselem->id == NULL) unused++;
			}
			
			if (unused) {
				if (BLI_mempool_count(ts) == unused) {
					BLI_mempool_destroy(ts);
					soops->treestore = NULL;
					if (soops->treehash) {
						BKE_treehash_free(soops->treehash);
						soops->treehash = NULL;
					}
				}
				else {
					TreeStoreElem *tsenew;
					BLI_mempool *new_ts = BLI_mempool_create(sizeof(TreeStoreElem), BLI_mempool_count(ts) - unused,
					                                         512, BLI_MEMPOOL_ALLOW_ITER);
					BLI_mempool_iternew(ts, &iter);
					while ((tselem = BLI_mempool_iterstep(&iter))) {
						if (tselem->id) {
							tsenew = BLI_mempool_alloc(new_ts);
							*tsenew = *tselem;
						}
					}
					BLI_mempool_destroy(ts);
					soops->treestore = new_ts;
					if (soops->treehash) {
						/* update hash table to fix broken pointers */
						BKE_treehash_rebuild_from_treestore(soops->treehash, soops->treestore);
					}
				}
			}
		}
	}
}
Exemplo n.º 5
0
EdgeHash *BLI_edgehash_new(void)
{
	EdgeHash *eh = MEM_callocN(sizeof(*eh), "EdgeHash");
	eh->cursize = 0;
	eh->nentries = 0;
	eh->nbuckets = _ehash_hashsizes[eh->cursize];
	
	eh->buckets = MEM_callocN(eh->nbuckets * sizeof(*eh->buckets), "eh buckets 2");
	eh->epool = BLI_mempool_create(sizeof(EdgeEntry), 512, 512, BLI_MEMPOOL_SYSMALLOC);

	return eh;
}
Exemplo n.º 6
0
MovieCache *IMB_moviecache_create(const char *name, int keysize, GHashHashFP hashfp, GHashCmpFP cmpfp)
{
	MovieCache *cache;

	PRINT("%s: cache '%s' create\n", __func__, name);

	cache = MEM_callocN(sizeof(MovieCache), "MovieCache");

	BLI_strncpy(cache->name, name, sizeof(cache->name));

	cache->keys_pool = BLI_mempool_create(sizeof(MovieCacheKey), 64, 64, 0);
	cache->items_pool = BLI_mempool_create(sizeof(MovieCacheItem), 64, 64, 0);
	cache->userkeys_pool = BLI_mempool_create(keysize, 64, 64, 0);
	cache->hash = BLI_ghash_new(moviecache_hashhash, moviecache_hashcmp, "MovieClip ImBuf cache hash");

	cache->keysize = keysize;
	cache->hashfp = hashfp;
	cache->cmpfp = cmpfp;
	cache->proxy = -1;

	return cache;
}
Exemplo n.º 7
0
GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) {
	GHash *gh= MEM_mallocN(sizeof(*gh), info);
	gh->hashfp= hashfp;
	gh->cmpfp= cmpfp;
	gh->entrypool = BLI_mempool_create(sizeof(Entry), 64, 64, 0);

	gh->cursize= 0;
	gh->nentries= 0;
	gh->nbuckets= hashsizes[gh->cursize];
	
	gh->buckets= MEM_mallocN(gh->nbuckets*sizeof(*gh->buckets), "buckets");
	memset(gh->buckets, 0, gh->nbuckets*sizeof(*gh->buckets));
	
	return gh;
}
Exemplo n.º 8
0
static GHash *ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info,
                        const unsigned int nentries_reserve, const unsigned int flag)
{
	GHash *gh = MEM_mallocN(sizeof(*gh), info);

	gh->hashfp = hashfp;
	gh->cmpfp = cmpfp;

	gh->buckets = NULL;
	gh->flag = flag;

	ghash_buckets_reset(gh, nentries_reserve);
	gh->entrypool = BLI_mempool_create(GHASH_ENTRY_SIZE(flag & GHASH_FLAG_IS_GSET), 64, 64, BLI_MEMPOOL_NOP);

	return gh;
}
Exemplo n.º 9
0
/**
 * \brief Init Walker
 *
 * Allocates and returns a new mesh walker of
 * a given type. The elements visited are filtered
 * by the bitmask 'searchmask'.
 */
void BMW_init(BMWalker *walker, BMesh *bm, int type,
              short mask_vert, short mask_edge, short mask_face,
              BMWFlag flag,
              int layer)
{
	memset(walker, 0, sizeof(BMWalker));

	walker->layer = layer;
	walker->flag = flag;
	walker->bm = bm;

	walker->mask_vert = mask_vert;
	walker->mask_edge = mask_edge;
	walker->mask_face = mask_face;

	walker->visit_set = BLI_gset_ptr_new("bmesh walkers");
	walker->visit_set_alt = BLI_gset_ptr_new("bmesh walkers sec");

	if (UNLIKELY(type >= BMW_MAXWALKERS || type < 0)) {
		fprintf(stderr,
		        "%s: Invalid walker type in BMW_init; type: %d, "
		        "searchmask: (v:%d, e:%d, f:%d), flag: %d, layer: %d\n",
		        __func__, type, mask_vert, mask_edge, mask_face, flag, layer);
		BLI_assert(0);
		return;
	}
	
	if (type != BMW_CUSTOM) {
		walker->begin = bm_walker_types[type]->begin;
		walker->yield = bm_walker_types[type]->yield;
		walker->step = bm_walker_types[type]->step;
		walker->structsize = bm_walker_types[type]->structsize;
		walker->order = bm_walker_types[type]->order;
		walker->valid_mask = bm_walker_types[type]->valid_mask;

		/* safety checks */
		/* if this raises an error either the caller is wrong or
		 * 'bm_walker_types' needs updating */
		BLI_assert(mask_vert == 0 || (walker->valid_mask & BM_VERT));
		BLI_assert(mask_edge == 0 || (walker->valid_mask & BM_EDGE));
		BLI_assert(mask_face == 0 || (walker->valid_mask & BM_FACE));
	}
	
	walker->worklist = BLI_mempool_create(walker->structsize, 100, 100, BLI_MEMPOOL_SYSMALLOC);
	walker->states.first = walker->states.last = NULL;
}
Exemplo n.º 10
0
/** Generate the mappings between used IDs and their users, and vice-versa. */
void BKE_main_relations_create(Main *bmain)
{
  if (bmain->relations != NULL) {
    BKE_main_relations_free(bmain);
  }

  bmain->relations = MEM_mallocN(sizeof(*bmain->relations), __func__);
  bmain->relations->id_used_to_user = BLI_ghash_new(
      BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
  bmain->relations->id_user_to_used = BLI_ghash_new(
      BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
  bmain->relations->entry_pool = BLI_mempool_create(
      sizeof(MainIDRelationsEntry), 128, 128, BLI_MEMPOOL_NOP);

  ID *id;
  FOREACH_MAIN_ID_BEGIN (bmain, id) {
    BKE_library_foreach_ID_link(
        NULL, id, main_relations_create_idlink_cb, bmain->relations, IDWALK_READONLY);
  }
Exemplo n.º 11
0
static EdgeHash *edgehash_new(const char *info,
                              const unsigned int nentries_reserve,
                              const unsigned int entry_size)
{
	EdgeHash *eh = MEM_mallocN(sizeof(*eh), info);

	eh->nbuckets = _ehash_hashsizes[0];  /* eh->cursize */
	eh->nentries = 0;
	eh->cursize = 0;
	eh->flag = 0;

	/* if we have reserved the number of elements that this hash will contain */
	if (nentries_reserve) {
		edgehash_buckets_reserve(eh, nentries_reserve);
	}

	eh->buckets = MEM_callocN(eh->nbuckets * sizeof(*eh->buckets), "eh buckets");
	eh->epool = BLI_mempool_create(entry_size, nentries_reserve, 512, BLI_MEMPOOL_NOP);

	return eh;
}
Exemplo n.º 12
0
void BME_CD_Create(BME_CustomData *data, BME_CustomDataInit *init, int initalloc)
{
	int i, j, offset=0;
	const BME_LayerTypeInfo *info;
	
	/*initialize data members*/
	data->layers = NULL;
	data->pool = NULL;
	data->totlayer = 0;
	data->totsize = 0;

	/*first count how many layers to alloc*/
	for(i=0; i < BME_CD_NUMTYPES; i++){
		info = BME_layerType_getInfo(i);
		data->totlayer += init->layout[i];
		data->totsize  += (init->layout[i] * info->size);
	}
	/*alloc our layers*/
	if(data->totlayer){
		/*alloc memory*/
		data->layers = MEM_callocN(sizeof(BME_CustomDataLayer)*data->totlayer, "BMesh Custom Data Layers");
		data->pool = BLI_mempool_create(data->totsize, initalloc, initalloc, FALSE, FALSE);
		/*initialize layer data*/
		for(i=0; i < BME_CD_NUMTYPES; i++){
			if(init->layout[i]){
				info = BME_layerType_getInfo(i);
				for(j=0; j < init->layout[i]; j++){
					if(j==0) data->layers[j+i].active = init->active[i];
					data->layers[j+i].type = i;
					data->layers[j+i].offset = offset;	
					strcpy(data->layers[j+i].name, &(init->nametemplate[j+i]));
					offset += info->size;
				}
			}
		}
	}
}
Exemplo n.º 13
0
/**
 * \note This function sets the edge indices to invalid values.
 */
void BM_mesh_beautify_fill(
        BMesh *bm, BMEdge **edge_array, const int edge_array_len,
        const short flag, const short method,
        const short oflag_edge, const short oflag_face)
{
	Heap *eheap;             /* edge heap */
	HeapNode **eheap_table;  /* edge index aligned table pointing to the eheap */

	GSet       **edge_state_arr  = MEM_callocN((size_t)edge_array_len * sizeof(GSet *), __func__);
	BLI_mempool *edge_state_pool = BLI_mempool_create(sizeof(EdRotState), 0, 512, BLI_MEMPOOL_NOP);
	int i;

#ifdef DEBUG_TIME
	TIMEIT_START(beautify_fill);
#endif

	eheap = BLI_heap_new_ex((uint)edge_array_len);
	eheap_table = MEM_mallocN(sizeof(HeapNode *) * (size_t)edge_array_len, __func__);

	/* build heap */
	for (i = 0; i < edge_array_len; i++) {
		BMEdge *e = edge_array[i];
		const float cost = bm_edge_calc_rotate_beauty(e, flag, method);
		if (cost < 0.0f) {
			eheap_table[i] = BLI_heap_insert(eheap, cost, e);
		}
		else {
			eheap_table[i] = NULL;
		}

		BM_elem_index_set(e, i);  /* set_dirty */
	}
	bm->elem_index_dirty |= BM_EDGE;

	while (BLI_heap_is_empty(eheap) == false) {
		BMEdge *e = BLI_heap_popmin(eheap);
		i = BM_elem_index_get(e);
		eheap_table[i] = NULL;

		BLI_assert(BM_edge_face_count_is_equal(e, 2));

		e = BM_edge_rotate(bm, e, false, BM_EDGEROT_CHECK_EXISTS);

		BLI_assert(e == NULL || BM_edge_face_count_is_equal(e, 2));

		if (LIKELY(e)) {
			GSet *e_state_set = edge_state_arr[i];

			/* add the new state into the set so we don't move into this state again
			 * note: we could add the previous state too but this isn't essential)
			 *       for avoiding eternal loops */
			EdRotState *e_state = BLI_mempool_alloc(edge_state_pool);
			erot_state_current(e, e_state);
			if (UNLIKELY(e_state_set == NULL)) {
				edge_state_arr[i] = e_state_set = erot_gset_new();  /* store previous state */
			}
			BLI_assert(BLI_gset_haskey(e_state_set, (void *)e_state) == false);
			BLI_gset_insert(e_state_set, e_state);


			// printf("  %d -> %d, %d\n", i, BM_elem_index_get(e->v1), BM_elem_index_get(e->v2));

			/* maintain the index array */
			edge_array[i] = e;
			BM_elem_index_set(e, i);

			/* recalculate faces connected on the heap */
			bm_edge_update_beauty_cost(e, eheap, eheap_table, edge_state_arr,
			                           (const BMEdge **)edge_array, edge_array_len,
			                           flag, method);

			/* update flags */
			if (oflag_edge) {
				BMO_edge_flag_enable(bm, e, oflag_edge);
			}

			if (oflag_face) {
				BMO_face_flag_enable(bm, e->l->f, oflag_face);
				BMO_face_flag_enable(bm, e->l->radial_next->f, oflag_face);
			}
		}
	}

	BLI_heap_free(eheap, NULL);
	MEM_freeN(eheap_table);

	for (i = 0; i < edge_array_len; i++) {
		if (edge_state_arr[i]) {
			BLI_gset_free(edge_state_arr[i], NULL);
		}
	}

	MEM_freeN(edge_state_arr);
	BLI_mempool_destroy(edge_state_pool);

#ifdef DEBUG_TIME
	TIMEIT_END(beautify_fill);
#endif
}