[Bf-blender-cvs] [7afa353d5e2] greasepencil-object: Redo stats calculation

Antonio Vazquez noreply at git.blender.org
Fri Jun 8 09:44:33 CEST 2018


Commit: 7afa353d5e24d186799d1a011479859abda637a0
Author: Antonio Vazquez
Date:   Fri Jun 8 09:44:01 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rB7afa353d5e24d186799d1a011479859abda637a0

Redo stats calculation

Now the stat info is saved in the datablock to avoid recalculations and the stats are calculated in one function.

Still pending move the update of the stats to a better place to calculate only when the object change, maybe in depsgraph evaluation.

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/editors/space_info/info_stats.c
M	source/blender/makesdna/DNA_gpencil_types.h

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 3311b117135..da3f8efcb8c 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -95,10 +95,7 @@ void BKE_gpencil_material_index_remove(struct bGPdata *gpd, int index);
 void BKE_gpencil_material_remap(struct bGPdata *gpd, const unsigned int *remap, unsigned int remap_len);
 
 /* statistics functions */
-int BKE_gpencil_stats_total_layers(struct bGPdata *gpd);
-int BKE_gpencil_stats_total_frames(struct bGPdata *gpd);
-int BKE_gpencil_stats_total_strokes(struct bGPdata *gpd);
-int BKE_gpencil_stats_total_points(struct bGPdata *gpd);
+void BKE_gpencil_stats_update(struct bGPdata *gpd);
 
 /* Utilities for creating and populating GP strokes */
 /* - Number of values defining each point in the built-in data 
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index f196ad27613..1a47ec8385c 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1608,44 +1608,23 @@ void BKE_gpencil_material_remap(struct bGPdata *gpd, const unsigned int *remap,
 }
 
 /* statistics functions */
-int BKE_gpencil_stats_total_layers(bGPdata *gpd)
+void BKE_gpencil_stats_update(bGPdata *gpd)
 {
-	return BLI_listbase_count(&gpd->layers);
-}
-
-int BKE_gpencil_stats_total_frames(bGPdata *gpd)
-{
-	int tot = 0;
-	for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
-		tot += BLI_listbase_count(&gpl->frames);
-	}
-
-	return tot;
-}
-
-int BKE_gpencil_stats_total_strokes(bGPdata *gpd)
-{
-	int tot = 0;
-	for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
-		for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
-			tot += BLI_listbase_count(&gpf->strokes);
-		}
-	}
-
-	return tot;
-}
+	gpd->totlayer = 0;
+	gpd->totframe = 0;
+	gpd->totstroke = 0;
+	gpd->totpoint = 0;
 
-int BKE_gpencil_stats_total_points(bGPdata *gpd)
-{
-	int tot = 0;
 	for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+		gpd->totlayer++;
 		for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+			gpd->totframe++;
 			for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
-				tot += gps->totpoints;
+				gpd->totstroke++;
+				gpd->totpoint += gps->totpoints;
 			}
 		}
 	}
 
-	return tot;
 }
 
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 6fe2f68aba8..7b84917a710 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -33,8 +33,6 @@
 #include "DNA_gpencil_types.h"
 #include "DNA_view3d_types.h"
 
-#include "DEG_depsgraph_query.h"
-
 #include "draw_mode_engines.h"
 
 #include "UI_resources.h"
@@ -403,11 +401,11 @@ void GPENCIL_cache_populate(void *vedata, Object *ob)
 
 	/* object datablock (this is not draw now) */
 	if (ob->type == OB_GPENCIL && ob->data) {
+		bGPdata *gpd = (bGPdata *)ob->data;
 		if ((stl->g_data->session_flag & GP_DRW_PAINT_READY) == 0) {
 
 			/* if render set as dirty */
 			if (stl->storage->is_render == true) {
-				bGPdata *gpd = (bGPdata *)ob->data;
 				gpd->flag |= GP_DATA_CACHE_IS_DIRTY;
 			}
 
diff --git a/source/blender/editors/space_info/info_stats.c b/source/blender/editors/space_info/info_stats.c
index d9f290a69e6..624e0e72277 100644
--- a/source/blender/editors/space_info/info_stats.c
+++ b/source/blender/editors/space_info/info_stats.c
@@ -50,13 +50,13 @@
 #include "BKE_curve.h"
 #include "BKE_displist.h"
 #include "BKE_DerivedMesh.h"
-#include "BKE_gpencil.h"
 #include "BKE_key.h"
 #include "BKE_layer.h"
 #include "BKE_paint.h"
 #include "BKE_particle.h"
 #include "BKE_editmesh.h"
 #include "BKE_object.h"
+#include "BKE_gpencil.h"
 
 #include "ED_info.h"
 #include "ED_armature.h"
@@ -152,10 +152,15 @@ static void stats_object(Object *ob, int sel, int totob, SceneStats *stats)
 		case OB_GPENCIL:
 		{
 			bGPdata *gpd = (bGPdata *)ob->data;
-			stats->totgplayer = BKE_gpencil_stats_total_layers(gpd);
-			stats->totgpframe = BKE_gpencil_stats_total_frames(gpd);
-			stats->totgpstroke = BKE_gpencil_stats_total_strokes(gpd);
-			stats->totgppoint = BKE_gpencil_stats_total_points(gpd);
+			/* GPXX Review if we can move to other place when object change 
+			 * maybe to depsgraph evaluation 
+			 */
+			BKE_gpencil_stats_update(gpd);
+
+			stats->totgplayer = gpd->totlayer;
+			stats->totgpframe = gpd->totframe;
+			stats->totgpstroke = gpd->totstroke;
+			stats->totgppoint = gpd->totpoint;
 			break;
 		}
 	}
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 2372d4f2e70..b3db2c8140f 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -347,6 +347,12 @@ typedef struct bGPdata {
 	char pad[4];
 	struct Material **mat;      /* materials array */
 	short totcol;               /* total materials */
+
+	/* stats */
+	short totlayer;
+	short totframe;
+	short totstroke;
+	short totpoint;
 	char pad2[6];
 } bGPdata;



More information about the Bf-blender-cvs mailing list