code cleanup: reduce calls to CTX_ functions inline, add some docs to mask rasterizer.

This commit is contained in:
Campbell Barton
2012-09-13 01:50:21 +00:00
parent 3e4b353cfa
commit 4cb6d5d214
6 changed files with 64 additions and 16 deletions

View File

@@ -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"

View File

@@ -1019,6 +1019,7 @@ static void select_timeline_marker_frame(ListBase *markers, int frame, unsigned
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 @@ static int ed_marker_select(bContext *C, wmEvent *evt, int extend, int camera)
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);

View File

@@ -556,6 +556,7 @@ static int add_vertex_new(const bContext *C, Mask *mask, MaskLayer *masklay, con
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 @@ static int add_vertex_exec(bContext *C, wmOperator *op)
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 @@ static int add_vertex_exec(bContext *C, wmOperator *op)
}
/* 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;
}

View File

@@ -915,6 +915,7 @@ static void delete_feather_points(MaskSplinePoint *point)
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 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op))
}
/* 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 @@ static int mask_switch_direction_exec(bContext *C, wmOperator *UNUSED(op))
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 @@ static int mask_normals_make_consistent_exec(bContext *C, wmOperator *UNUSED(op)
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 @@ void MASK_OT_hide_view_set(wmOperatorType *ot)
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 @@ static int mask_feather_weight_clear_exec(bContext *C, wmOperator *UNUSED(op))
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);

View File

@@ -133,11 +133,11 @@ typedef struct RegionView3D {
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];

View File

@@ -326,7 +326,11 @@ static void build_pict_list(char *first, int totframes, int fstep, int fontid)
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 @@ void playanim_window_open(const char *title, int posx, int posy, int sizex, int
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) {