[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50565] trunk/blender/source/blender: code cleanup: reduce calls to CTX_ functions inline, add some docs to mask rasterizer.

Campbell Barton ideasman42 at gmail.com
Thu Sep 13 03:50:25 CEST 2012


Revision: 50565
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50565
Author:   campbellbarton
Date:     2012-09-13 01:50:21 +0000 (Thu, 13 Sep 2012)
Log Message:
-----------
code cleanup: reduce calls to CTX_ functions inline, add some docs to mask rasterizer.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c
    trunk/blender/source/blender/editors/animation/anim_markers.c
    trunk/blender/source/blender/editors/mask/mask_add.c
    trunk/blender/source/blender/editors/mask/mask_ops.c
    trunk/blender/source/blender/makesdna/DNA_view3d_types.h
    trunk/blender/source/blender/windowmanager/intern/wm_playanim.c

Modified: trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c	2012-09-13 00:46:50 UTC (rev 50564)
+++ trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c	2012-09-13 01:50:21 UTC (rev 50565)
@@ -26,6 +26,46 @@
 
 /** \file blender/blenkernel/intern/mask_rasterize.c
  *  \ingroup bke
+ *
+ * This module exposes a rasterizer that works as a black box - implementation details are confined to this file,
+ *
+ * The basic method to access is:
+ * - create & initialize a handle from a #Mask datablock.
+ * - execute pixel lookups.
+ * - free the handle.
+ *
+ * This file is admittedly a bit confusticated, in quite few areas speed was chosen over readability,
+ * though it is commented - so shouldn't be so hard to see whats going on.
+ *
+ *
+ * Implementation:
+ *
+ * To rasterize the mask its converted into geometry that use a ray-cast for each pixel lookup.
+ *
+ * Initially 'kdopbvh' was used but this ended up being too slow.
+ *
+ * To gain some extra speed we take advantage of a few shortcuts that can be made rasterizing masks specifically.
+ * - all triangles are known to be completely white - so no depth check is done on triangle intersection.
+ * - all quads are known to be feather outlines - the 1 and 0 depths are known by the vertex order in the quad,
+ * - there is no color - just a value for each mask pixel.
+ * - the mask spacial structure always maps to space 0-1 on X and Y axis.
+ * - bucketing is used to speed up lookups for geometry.
+ *
+ * Other Details:
+ * - used unsigned values all over for some extra speed on some arch's.
+ * - anti-aliasing is faked, just ensuring at least one pixel feather - avoids oversampling.
+ * - initializing the spacial structure doesn't need to be as optimized as pixel lookups are.
+ * - mask lookups need not be pixel aligned so any sub-pixel values from x/y (0 - 1), can be found.
+ *   (perhaps masks can be used as a vector texture in 3D later on)
+ *
+ *
+ * Currently, to build the spacial structure we have to calculate the total number of faces ahead of time.
+ *
+ * This is getting a bit complicated with the addition of unfilled splines and end capping -
+ * If large changes are needed here we would be better off using an iterable
+ * BLI_mempool for triangles and converting to a contiguous array afterwards.
+ *
+ * - Campbell
  */
 
 #include "MEM_guardedalloc.h"

Modified: trunk/blender/source/blender/editors/animation/anim_markers.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_markers.c	2012-09-13 00:46:50 UTC (rev 50564)
+++ trunk/blender/source/blender/editors/animation/anim_markers.c	2012-09-13 01:50:21 UTC (rev 50565)
@@ -1019,6 +1019,7 @@
 static int ed_marker_select(bContext *C, wmEvent *evt, int extend, int camera)
 {
 	ListBase *markers = ED_context_get_markers(C);
+	ARegion *ar = CTX_wm_region(C);
 	View2D *v2d = UI_view2d_fromcontext(C);
 	float viewx;
 	int x, y, cfra;
@@ -1026,8 +1027,8 @@
 	if (markers == NULL)
 		return OPERATOR_PASS_THROUGH;
 
-	x = evt->x - CTX_wm_region(C)->winrct.xmin;
-	y = evt->y - CTX_wm_region(C)->winrct.ymin;
+	x = evt->x - ar->winrct.xmin;
+	y = evt->y - ar->winrct.ymin;
 	
 	UI_view2d_region_to_view(v2d, x, y, &viewx, NULL);	
 	

Modified: trunk/blender/source/blender/editors/mask/mask_add.c
===================================================================
--- trunk/blender/source/blender/editors/mask/mask_add.c	2012-09-13 00:46:50 UTC (rev 50564)
+++ trunk/blender/source/blender/editors/mask/mask_add.c	2012-09-13 01:50:21 UTC (rev 50565)
@@ -556,6 +556,7 @@
 
 static int add_vertex_exec(bContext *C, wmOperator *op)
 {
+	Scene *scene = CTX_data_scene(C);
 	Mask *mask = CTX_data_edit_mask(C);
 	MaskLayer *masklay;
 
@@ -595,7 +596,7 @@
 				BKE_mask_calc_handle_point_auto(spline, point_other, FALSE);
 
 				/* TODO: only update this spline */
-				BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra);
+				BKE_mask_update_display(mask, CFRA);
 
 				WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
 				return OPERATOR_FINISHED;
@@ -617,7 +618,7 @@
 	}
 
 	/* TODO: only update this spline */
-	BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra);
+	BKE_mask_update_display(mask, CFRA);
 
 	return OPERATOR_FINISHED;
 }

Modified: trunk/blender/source/blender/editors/mask/mask_ops.c
===================================================================
--- trunk/blender/source/blender/editors/mask/mask_ops.c	2012-09-13 00:46:50 UTC (rev 50564)
+++ trunk/blender/source/blender/editors/mask/mask_ops.c	2012-09-13 01:50:21 UTC (rev 50565)
@@ -915,6 +915,7 @@
 
 static int delete_exec(bContext *C, wmOperator *UNUSED(op))
 {
+	Scene *scene = CTX_data_scene(C);
 	Mask *mask = CTX_data_edit_mask(C);
 	MaskLayer *masklay;
 
@@ -1002,7 +1003,7 @@
 	}
 
 	/* TODO: only update edited splines */
-	BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra);
+	BKE_mask_update_display(mask, CFRA);
 
 	WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
 
@@ -1060,7 +1061,7 @@
 
 	if (change) {
 		/* TODO: only update this spline */
-		BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra);
+		BKE_mask_update_display(mask, CFRA);
 
 		WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask);
 
@@ -1126,7 +1127,7 @@
 
 	if (change) {
 		/* TODO: only update this spline */
-		BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra);
+		BKE_mask_update_display(mask, CFRA);
 
 		WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask);
 
@@ -1324,6 +1325,7 @@
 
 static int mask_feather_weight_clear_exec(bContext *C, wmOperator *UNUSED(op))
 {
+	Scene *scene = CTX_data_scene(C);
 	Mask *mask = CTX_data_edit_mask(C);
 	MaskLayer *masklay;
 	int changed = FALSE;
@@ -1351,7 +1353,7 @@
 
 	if (changed) {
 		/* TODO: only update edited splines */
-		BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra);
+		BKE_mask_update_display(mask, CFRA);
 
 		WM_event_add_notifier(C, NC_MASK | ND_DRAW, mask);
 		DAG_id_tag_update(&mask->id, 0);

Modified: trunk/blender/source/blender/makesdna/DNA_view3d_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_view3d_types.h	2012-09-13 00:46:50 UTC (rev 50564)
+++ trunk/blender/source/blender/makesdna/DNA_view3d_types.h	2012-09-13 01:50:21 UTC (rev 50565)
@@ -133,11 +133,11 @@
 	short rflag;
 	
 
-	/* last view */
+	/* last view (use when switching out of camera view) */
 	float lviewquat[4];
 	short lpersp, lview; /* lpersp can never be set to 'RV3D_CAMOB' */
+
 	float gridview;
-	
 	float twangle[3];
 
 

Modified: trunk/blender/source/blender/windowmanager/intern/wm_playanim.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_playanim.c	2012-09-13 00:46:50 UTC (rev 50564)
+++ trunk/blender/source/blender/windowmanager/intern/wm_playanim.c	2012-09-13 01:50:21 UTC (rev 50565)
@@ -326,7 +326,11 @@
 			int file;
 
 			file = open(filepath, O_BINARY | O_RDONLY, 0);
-			if (file < 0) return;
+			if (file < 0) {
+				/* print errno? */
+				return;
+			}
+
 			picture = (PlayAnimPict *)MEM_callocN(sizeof(PlayAnimPict), "picture");
 			if (picture == NULL) {
 				printf("Not enough memory for pict struct '%s'\n", filepath);
@@ -700,11 +704,11 @@
 		inital_state = start_maximized ? GHOST_kWindowStateMaximized : GHOST_kWindowStateNormal;
 
 	g_WS.ghost_window = GHOST_CreateWindow(g_WS.ghost_system,
-	                              title,
-	                              posx, posy, sizex, sizey,
-	                              inital_state,
-	                              GHOST_kDrawingContextTypeOpenGL,
-	                              FALSE /* no stereo */, FALSE);
+	                                       title,
+	                                       posx, posy, sizex, sizey,
+	                                       inital_state,
+	                                       GHOST_kDrawingContextTypeOpenGL,
+	                                       FALSE /* no stereo */, FALSE);
 
 	//if (ghostwin) {
 	//if (win) {




More information about the Bf-blender-cvs mailing list