[Bf-blender-cvs] [a4540116ba8] master: DRW: use memiter for on screen text allocation

Campbell Barton noreply at git.blender.org
Tue Mar 5 16:44:32 CET 2019


Commit: a4540116ba828c5b6f9b350fe28ae03eaf1d381e
Author: Campbell Barton
Date:   Wed Mar 6 02:34:30 2019 +1100
Branches: master
https://developer.blender.org/rBa4540116ba828c5b6f9b350fe28ae03eaf1d381e

DRW: use memiter for on screen text allocation

Avoid allocation for each string,
improves redraw speed for text heavy views.

A contrived test showed FPS ~18.5% speedup but this doesn't represent
typical usage.

===================================================================

M	source/blender/draw/intern/draw_manager_text.c

===================================================================

diff --git a/source/blender/draw/intern/draw_manager_text.c b/source/blender/draw/intern/draw_manager_text.c
index 82bee3f8b8e..eff3688589c 100644
--- a/source/blender/draw/intern/draw_manager_text.c
+++ b/source/blender/draw/intern/draw_manager_text.c
@@ -22,10 +22,9 @@
 
 #include "MEM_guardedalloc.h"
 
-#include "BLI_listbase.h"
+#include "BLI_memiter.h"
 #include "BLI_math.h"
 
-
 #include "GPU_matrix.h"
 
 #include "ED_screen.h"
@@ -39,7 +38,6 @@
 #include "draw_manager_text.h"
 
 typedef struct ViewCachedString {
-	struct ViewCachedString *next, *prev;
 	float vec[3];
 	union {
 		uchar ub[4];
@@ -55,18 +53,19 @@ typedef struct ViewCachedString {
 } ViewCachedString;
 
 typedef struct DRWTextStore {
-	ListBase list;
+	BLI_memiter *cache_strings;
 } DRWTextStore;
 
 DRWTextStore *DRW_text_cache_create(void)
 {
 	DRWTextStore *dt = MEM_callocN(sizeof(*dt), __func__);
+	dt->cache_strings = BLI_memiter_create(1 << 14);  /* 16kb */
 	return dt;
 }
 
 void DRW_text_cache_destroy(struct DRWTextStore *dt)
 {
-	BLI_freelistN(&dt->list);
+	BLI_memiter_destroy(dt->cache_strings);
 	MEM_freeN(dt);
 }
 
@@ -88,9 +87,7 @@ void DRW_text_cache_add(
 		alloc_len = str_len + 1;
 	}
 
-	vos = MEM_mallocN(sizeof(ViewCachedString) + alloc_len, __func__);
-
-	BLI_addtail(&dt->list, vos);
+	vos = BLI_memiter_alloc(dt->cache_strings, sizeof(ViewCachedString) + alloc_len);
 
 	copy_v3_v3(vos->vec, co);
 	copy_v4_v4_uchar(vos->col.ub, col);
@@ -115,7 +112,9 @@ void DRW_text_cache_draw(DRWTextStore *dt, ARegion *ar)
 	int tot = 0;
 
 	/* project first and test */
-	for (vos = dt->list.first; vos; vos = vos->next) {
+	BLI_memiter_handle it;
+	BLI_memiter_iter_init(dt->cache_strings, &it);
+	while ((vos = BLI_memiter_iter_step(&it))) {
 		if (ED_view3d_project_short_ex(
 		        ar,
 		        (vos->flag & DRW_TEXT_CACHE_GLOBALSPACE) ? rv3d->persmat : rv3d->persmatob,
@@ -150,7 +149,8 @@ void DRW_text_cache_draw(DRWTextStore *dt, ARegion *ar)
 
 		BLF_size(font_id, style->widget.points * U.pixelsize, U.dpi);
 
-		for (vos = dt->list.first; vos; vos = vos->next) {
+		BLI_memiter_iter_init(dt->cache_strings, &it);
+		while ((vos = BLI_memiter_iter_step(&it))) {
 			if (vos->sco[0] != IS_CLIPPED) {
 				if (col_pack_prev != vos->col.pack) {
 					BLF_color4ubv(font_id, vos->col.ub);



More information about the Bf-blender-cvs mailing list