From f6e504cee9f85867554f5a0ab89b52a66c0f257e Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 29 Oct 2013 18:10:48 +0000 Subject: Make anim system safer for threading Remove usages of ANIM_unit_mapping_apply_fcurve in favor of runtime scale factor apply. There're still calls to ANIM_nla_mapping_apply_fcurve are hanging around, they're the next t be cleaned up! --- source/blender/editors/space_graph/graph_draw.c | 56 +++++++++++++---------- source/blender/editors/space_graph/graph_edit.c | 50 ++++++++++---------- source/blender/editors/space_graph/graph_select.c | 45 ++++++++---------- 3 files changed, 76 insertions(+), 75 deletions(-) (limited to 'source/blender/editors/space_graph') diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c index 23c39a5e99a..ba619fd9c77 100644 --- a/source/blender/editors/space_graph/graph_draw.c +++ b/source/blender/editors/space_graph/graph_draw.c @@ -206,7 +206,7 @@ static void draw_fcurve_handle_control(float x, float y, float xscale, float ysc } /* helper func - draw handle vertices only for an F-Curve (if it is not protected) */ -static void draw_fcurve_vertices_handles(FCurve *fcu, SpaceIpo *sipo, View2D *v2d, short sel, short sel_handle_only) +static void draw_fcurve_vertices_handles(FCurve *fcu, SpaceIpo *sipo, View2D *v2d, short sel, short sel_handle_only, float units_scale) { BezTriple *bezt = fcu->bezt; BezTriple *prevbezt = NULL; @@ -216,6 +216,9 @@ static void draw_fcurve_vertices_handles(FCurve *fcu, SpaceIpo *sipo, View2D *v2 /* get view settings */ hsize = UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE) * U.pixelsize; UI_view2d_getscale(v2d, &xscale, &yscale); + + /* Compensate OGL scale sued for unit mapping, so circle will be circle, not ellipse */ + yscale *= units_scale; /* set handle color */ if (sel) UI_ThemeColor(TH_HANDLE_VERTEX_SELECT); @@ -271,7 +274,7 @@ static void set_fcurve_vertex_color(FCurve *fcu, short sel) } -static void draw_fcurve_vertices(SpaceIpo *sipo, ARegion *ar, FCurve *fcu, short do_handles, short sel_handle_only) +static void draw_fcurve_vertices(SpaceIpo *sipo, ARegion *ar, FCurve *fcu, short do_handles, short sel_handle_only, float units_scale) { View2D *v2d = &ar->v2d; @@ -287,10 +290,10 @@ static void draw_fcurve_vertices(SpaceIpo *sipo, ARegion *ar, FCurve *fcu, short /* draw the two handles first (if they're shown, the curve doesn't have just a single keyframe, and the curve is being edited) */ if (do_handles) { set_fcurve_vertex_color(fcu, 0); - draw_fcurve_vertices_handles(fcu, sipo, v2d, 0, sel_handle_only); + draw_fcurve_vertices_handles(fcu, sipo, v2d, 0, sel_handle_only, units_scale); set_fcurve_vertex_color(fcu, 1); - draw_fcurve_vertices_handles(fcu, sipo, v2d, 1, sel_handle_only); + draw_fcurve_vertices_handles(fcu, sipo, v2d, 1, sel_handle_only, units_scale); } /* draw keyframes over the handles */ @@ -547,11 +550,14 @@ static void draw_fcurve_curve_samples(bAnimContext *ac, ID *id, FCurve *fcu, Vie FPoint *fpt = prevfpt + 1; float fac, v[2]; int b = fcu->totvert - 1; - - glBegin(GL_LINE_STRIP); - + float unit_scale; + /* apply unit mapping */ - ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 0); + glPushMatrix(); + unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, 0); + glScalef(1.0f, unit_scale, 1.0f); + + glBegin(GL_LINE_STRIP); /* extrapolate to left? - left-side of view comes before first keyframe? */ if (prevfpt->vec[0] > v2d->cur.xmin) { @@ -611,10 +617,8 @@ static void draw_fcurve_curve_samples(bAnimContext *ac, ID *id, FCurve *fcu, Vie glVertex2fv(v); } - /* unapply unit mapping */ - ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, ANIM_UNITCONV_RESTORE); - glEnd(); + glPopMatrix(); } /* helper func - draw one repeat of an F-Curve */ @@ -627,11 +631,14 @@ static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2 float fac = 0.0f; int b = fcu->totvert - 1; int resol; - - glBegin(GL_LINE_STRIP); - + float unit_scale; + /* apply unit mapping */ - ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 0); + glPushMatrix(); + unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, 0); + glScalef(1.0f, unit_scale, 1.0f); + + glBegin(GL_LINE_STRIP); /* extrapolate to left? */ if (prevbezt->vec[1][0] > v2d->cur.xmin) { @@ -766,10 +773,8 @@ static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2 glVertex2fv(v1); } - /* unapply unit mapping */ - ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, ANIM_UNITCONV_RESTORE); - glEnd(); + glPopMatrix(); } /* Debugging -------------------------------- */ @@ -1014,9 +1019,11 @@ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid } } else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) { - /* apply unit mapping */ - ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, fcu, 0); - + float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, 0); + + glPushMatrix(); + glScalef(1.0f, unit_scale, 1.0f); + if (fcu->bezt) { int do_handles = draw_fcurve_handles_check(sipo, fcu); @@ -1027,15 +1034,14 @@ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid glDisable(GL_BLEND); } - draw_fcurve_vertices(sipo, ar, fcu, do_handles, (sipo->flag & SIPO_SELVHANDLESONLY)); + draw_fcurve_vertices(sipo, ar, fcu, do_handles, (sipo->flag & SIPO_SELVHANDLESONLY), unit_scale); } else { /* samples: only draw two indicators at either end as indicators */ draw_fcurve_samples(sipo, ar, fcu); } - - /* unapply unit mapping */ - ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, fcu, ANIM_UNITCONV_RESTORE); + + glPopMatrix(); } } diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index 274c06bf871..c8e07dbda68 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -1787,20 +1787,23 @@ static int graphkeys_framejump_exec(bContext *C, wmOperator *UNUSED(op)) for (ale = anim_data.first; ale; ale = ale->next) { AnimData *adt = ANIM_nla_mapping_get(&ac, ale); - - /* apply unit corrections */ - ANIM_unit_mapping_apply_fcurve(ac.scene, ale->id, ale->key_data, ANIM_UNITCONV_ONLYKEYS); - + KeyframeEditData current_ked; + float unit_scale = ANIM_unit_mapping_get_factor(ac.scene, ale->id, ale->key_data, ANIM_UNITCONV_ONLYKEYS); + + memset(¤t_ked, 0, sizeof(current_ked)); + if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); - ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, bezt_calc_average, NULL); + ANIM_fcurve_keyframes_loop(¤t_ked, ale->key_data, NULL, bezt_calc_average, NULL); ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1); } else - ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, bezt_calc_average, NULL); - - /* unapply unit corrections */ - ANIM_unit_mapping_apply_fcurve(ac.scene, ale->id, ale->key_data, ANIM_UNITCONV_RESTORE | ANIM_UNITCONV_ONLYKEYS); + ANIM_fcurve_keyframes_loop(¤t_ked, ale->key_data, NULL, bezt_calc_average, NULL); + + ked.f1 += current_ked.f1; + ked.i1 += current_ked.i1; + ked.f2 += current_ked.f2 / unit_scale; + ked.i2 += current_ked.i2; } BLI_freelistN(&anim_data); @@ -1865,6 +1868,7 @@ static void snap_graph_keys(bAnimContext *ac, short mode) KeyframeEditData ked; KeyframeEditFunc edit_cb; + float cursor_value = 0.0f; /* filter data */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS); @@ -1881,16 +1885,16 @@ static void snap_graph_keys(bAnimContext *ac, short mode) } else if (mode == GRAPHKEYS_SNAP_VALUE) { SpaceIpo *sipo = (SpaceIpo *)ac->sl; - ked.f1 = (sipo) ? sipo->cursorVal : 0.0f; + cursor_value = (sipo) ? sipo->cursorVal : 0.0f; } /* snap keyframes */ for (ale = anim_data.first; ale; ale = ale->next) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); - - /* apply unit corrections */ - ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, 0); - + float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, ale->id, ale->key_data, 0); + + ked.f1 = cursor_value / unit_scale; + if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve); @@ -1898,9 +1902,6 @@ static void snap_graph_keys(bAnimContext *ac, short mode) } else ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve); - - /* apply unit corrections */ - ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, ANIM_UNITCONV_RESTORE); } BLI_freelistN(&anim_data); @@ -1977,7 +1978,8 @@ static void mirror_graph_keys(bAnimContext *ac, short mode) KeyframeEditData ked; KeyframeEditFunc edit_cb; - + float cursor_value; + /* get beztriple editing callbacks */ edit_cb = ANIM_editkeyframes_mirror(mode); @@ -2000,7 +2002,7 @@ static void mirror_graph_keys(bAnimContext *ac, short mode) } else if (mode == GRAPHKEYS_MIRROR_VALUE) { SpaceIpo *sipo = (SpaceIpo *)ac->sl; - ked.f1 = (sipo) ? sipo->cursorVal : 0.0f; + cursor_value = (sipo) ? sipo->cursorVal : 0.0f; } /* filter data */ @@ -2010,10 +2012,11 @@ static void mirror_graph_keys(bAnimContext *ac, short mode) /* mirror keyframes */ for (ale = anim_data.first; ale; ale = ale->next) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); - + float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, ale->id, ale->key_data, ANIM_UNITCONV_ONLYKEYS); + /* apply unit corrections */ - ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, ANIM_UNITCONV_ONLYKEYS); - + ked.f1 = cursor_value * unit_scale; + if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve); @@ -2021,9 +2024,6 @@ static void mirror_graph_keys(bAnimContext *ac, short mode) } else ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve); - - /* unapply unit corrections */ - ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, ANIM_UNITCONV_ONLYKEYS | ANIM_UNITCONV_RESTORE); } BLI_freelistN(&anim_data); diff --git a/source/blender/editors/space_graph/graph_select.c b/source/blender/editors/space_graph/graph_select.c index 4bb5e1b11d4..ce036bec380 100644 --- a/source/blender/editors/space_graph/graph_select.c +++ b/source/blender/editors/space_graph/graph_select.c @@ -227,7 +227,7 @@ static void borderselect_graphkeys(bAnimContext *ac, rcti rect, short mode, shor KeyframeEditData ked; KeyframeEditFunc ok_cb, select_cb; View2D *v2d = &ac->ar->v2d; - rctf rectf; + rctf rectf, scaled_rectf; /* convert mouse coordinates to frame ranges and channel coordinates corrected for view pan/zoom */ UI_view2d_region_to_view(v2d, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); @@ -243,7 +243,7 @@ static void borderselect_graphkeys(bAnimContext *ac, rcti rect, short mode, shor /* init editing data */ memset(&ked, 0, sizeof(KeyframeEditData)); - ked.data = &rectf; + ked.data = &scaled_rectf; /* treat handles separately? */ if (incl_handles) { @@ -252,21 +252,24 @@ static void borderselect_graphkeys(bAnimContext *ac, rcti rect, short mode, shor } else mapping_flag = ANIM_UNITCONV_ONLYKEYS; - + /* loop over data, doing border select */ for (ale = anim_data.first; ale; ale = ale->next) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); FCurve *fcu = (FCurve *)ale->key_data; - - /* apply unit corrections */ - ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, mapping_flag); - + float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, 0); + /* apply NLA mapping to all the keyframes, since it's easier than trying to * guess when a callback might use something different */ if (adt) ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, incl_handles == 0); - + + scaled_rectf.xmin = rectf.xmin; + scaled_rectf.xmax = rectf.xmax; + scaled_rectf.ymin = rectf.ymin / unit_scale; + scaled_rectf.ymax = rectf.ymax / unit_scale; + /* set horizontal range (if applicable) * NOTE: these values are only used for x-range and y-range but not region * (which uses ked.data, i.e. rectf) @@ -296,9 +299,6 @@ static void borderselect_graphkeys(bAnimContext *ac, rcti rect, short mode, shor /* un-apply NLA mapping from all the keyframes */ if (adt) ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, incl_handles == 0); - - /* unapply unit corrections */ - ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, ANIM_UNITCONV_RESTORE | mapping_flag); } /* cleanup */ @@ -936,7 +936,7 @@ static int fcurve_handle_sel_check(SpaceIpo *sipo, BezTriple *bezt) /* check if the given vertex is within bounds or not */ // TODO: should we return if we hit something? -static void nearest_fcurve_vert_store(ListBase *matches, View2D *v2d, FCurve *fcu, BezTriple *bezt, FPoint *fpt, short hpoint, const int mval[2]) +static void nearest_fcurve_vert_store(ListBase *matches, View2D *v2d, FCurve *fcu, BezTriple *bezt, FPoint *fpt, short hpoint, const int mval[2], float unit_scale) { /* Keyframes or Samples? */ if (bezt) { @@ -947,7 +947,7 @@ static void nearest_fcurve_vert_store(ListBase *matches, View2D *v2d, FCurve *fc * needed to access the relevant vertex coordinates in the 3x3 * 'vec' matrix */ - UI_view2d_view_to_region(v2d, bezt->vec[hpoint + 1][0], bezt->vec[hpoint + 1][1], &screen_co[0], &screen_co[1]); + UI_view2d_view_to_region(v2d, bezt->vec[hpoint + 1][0], bezt->vec[hpoint + 1][1] * unit_scale, &screen_co[0], &screen_co[1]); /* check if distance from mouse cursor to vert in screen space is within tolerance */ // XXX: inlined distance calculation, since we cannot do this on ints using the math lib... @@ -996,7 +996,7 @@ static void get_nearest_fcurve_verts_list(bAnimContext *ac, const int mval[2], L SpaceIpo *sipo = (SpaceIpo *)ac->sl; View2D *v2d = &ac->ar->v2d; - + /* get curves to search through * - if the option to only show keyframes that belong to selected F-Curves is enabled, * include the 'only selected' flag... @@ -1009,32 +1009,30 @@ static void get_nearest_fcurve_verts_list(bAnimContext *ac, const int mval[2], L for (ale = anim_data.first; ale; ale = ale->next) { FCurve *fcu = (FCurve *)ale->key_data; AnimData *adt = ANIM_nla_mapping_get(ac, ale); - - /* apply unit corrections */ - ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, 0); - + float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, 0); + /* apply NLA mapping to all the keyframes */ if (adt) ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 0); - + if (fcu->bezt) { BezTriple *bezt1 = fcu->bezt, *prevbezt = NULL; int i; for (i = 0; i < fcu->totvert; i++, prevbezt = bezt1, bezt1++) { /* keyframe */ - nearest_fcurve_vert_store(matches, v2d, fcu, bezt1, NULL, NEAREST_HANDLE_KEY, mval); + nearest_fcurve_vert_store(matches, v2d, fcu, bezt1, NULL, NEAREST_HANDLE_KEY, mval, unit_scale); /* handles - only do them if they're visible */ if (fcurve_handle_sel_check(sipo, bezt1) && (fcu->totvert > 1)) { /* first handle only visible if previous segment had handles */ if ((!prevbezt && (bezt1->ipo == BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ))) { - nearest_fcurve_vert_store(matches, v2d, fcu, bezt1, NULL, NEAREST_HANDLE_LEFT, mval); + nearest_fcurve_vert_store(matches, v2d, fcu, bezt1, NULL, NEAREST_HANDLE_LEFT, mval, unit_scale); } /* second handle only visible if this segment is bezier */ if (bezt1->ipo == BEZT_IPO_BEZ) { - nearest_fcurve_vert_store(matches, v2d, fcu, bezt1, NULL, NEAREST_HANDLE_RIGHT, mval); + nearest_fcurve_vert_store(matches, v2d, fcu, bezt1, NULL, NEAREST_HANDLE_RIGHT, mval, unit_scale); } } } @@ -1047,9 +1045,6 @@ static void get_nearest_fcurve_verts_list(bAnimContext *ac, const int mval[2], L /* un-apply NLA mapping from all the keyframes */ if (adt) ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 0); - - /* unapply unit corrections */ - ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, ANIM_UNITCONV_RESTORE); } /* free channels */ -- cgit v1.2.3