From ad65b7b86b85aba39a2e686c6c5aacdec2c1b3ff Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 25 May 2012 12:37:11 +0000 Subject: Animation playback: now all windows are update during playback, rather than just the active window. --- source/blender/editors/include/ED_screen.h | 5 ++- source/blender/editors/object/object_modifier.c | 2 +- source/blender/editors/physics/dynamicpaint_ops.c | 4 +- source/blender/editors/physics/physics_fluid.c | 4 +- source/blender/editors/render/render_internal.c | 7 ++- source/blender/editors/screen/screen_edit.c | 28 ++++++++---- source/blender/editors/screen/screen_ops.c | 51 ++++++++++++++-------- source/blender/editors/space_clip/tracking_ops.c | 2 +- source/blender/editors/space_view3d/view3d_draw.c | 3 +- .../blender/editors/transform/transform_generics.c | 4 +- .../blender/windowmanager/intern/wm_event_system.c | 6 +-- 11 files changed, 72 insertions(+), 44 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index 2fc72f7e8da..13cb8eac653 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -113,10 +113,11 @@ void ED_screen_full_restore(struct bContext *C, ScrArea *sa); struct ScrArea *ED_screen_full_toggle(struct bContext *C, struct wmWindow *win, struct ScrArea *sa); /* anim */ -void ED_update_for_newframe(struct Main *bmain, struct Scene *scene, struct bScreen *screen, int mute); +void ED_update_for_newframe(struct Main *bmain, struct Scene *scene, int mute); void ED_refresh_viewport_fps(struct bContext *C); -int ED_screen_animation_play(struct bContext *C, int sync, int mode); +int ED_screen_animation_play(struct bContext *C, int sync, int mode); +bScreen *ED_screen_animation_playing(const struct bContext *C); /* screen keymaps */ void ED_operatortypes_screen(void); diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 9e891353f35..79a9a29ae8f 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -2023,7 +2023,7 @@ static int ocean_bake_exec(bContext *C, wmOperator *op) * this part of the process before a threaded job is created */ //scene->r.cfra = f; - //ED_update_for_newframe(CTX_data_main(C), scene, CTX_wm_screen(C), 1); + //ED_update_for_newframe(CTX_data_main(C), scene, 1); /* ok, this doesn't work with drivers, but is way faster. * let's use this for now and hope nobody wants to drive the time value... */ diff --git a/source/blender/editors/physics/dynamicpaint_ops.c b/source/blender/editors/physics/dynamicpaint_ops.c index c82e0459218..ea8718f0e66 100644 --- a/source/blender/editors/physics/dynamicpaint_ops.c +++ b/source/blender/editors/physics/dynamicpaint_ops.c @@ -285,7 +285,7 @@ static int dynamicPaint_bakeImageSequence(bContext *C, DynamicPaintSurface *surf /* Set frame to start point (also inits modifier data) */ frame = surface->start_frame; scene->r.cfra = (int)frame; - ED_update_for_newframe(CTX_data_main(C), scene, win->screen, 1); + ED_update_for_newframe(CTX_data_main(C), scene, 1); /* Init surface */ if (!dynamicPaint_createUVSurface(surface)) return 0; @@ -303,7 +303,7 @@ static int dynamicPaint_bakeImageSequence(bContext *C, DynamicPaintSurface *surf /* calculate a frame */ scene->r.cfra = (int)frame; - ED_update_for_newframe(CTX_data_main(C), scene, win->screen, 1); + ED_update_for_newframe(CTX_data_main(C), scene, 1); if (!dynamicPaint_calculateFrame(surface, scene, cObject, frame)) return 0; /* diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c index c8ca75835e4..b31e5c0aea3 100644 --- a/source/blender/editors/physics/physics_fluid.c +++ b/source/blender/editors/physics/physics_fluid.c @@ -419,7 +419,7 @@ static void fluid_init_all_channels(bContext *C, Object *UNUSED(fsDomain), Fluid /* Modifying the global scene isn't nice, but we can do it in * this part of the process before a threaded job is created */ scene->r.cfra = (int)eval_time; - ED_update_for_newframe(CTX_data_main(C), scene, CTX_wm_screen(C), 1); + ED_update_for_newframe(CTX_data_main(C), scene, 1); /* now scene data should be current according to animation system, so we fill the channels */ @@ -967,7 +967,7 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain, shor /* reset to original current frame */ scene->r.cfra = origFrame; - ED_update_for_newframe(CTX_data_main(C), scene, CTX_wm_screen(C), 1); + ED_update_for_newframe(CTX_data_main(C), scene, 1); /* ******** init domain object's matrix ******** */ copy_m4_m4(domainMat, fsDomain->obmat); diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index 7b4dda1a48f..9ed9c150dcb 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -236,7 +236,7 @@ static int screen_render_exec(bContext *C, wmOperator *op) RE_SetReports(re, NULL); // no redraw needed, we leave state as we entered it - ED_update_for_newframe(mainp, scene, CTX_wm_screen(C), 1); + ED_update_for_newframe(mainp, scene, 1); WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, scene); @@ -408,7 +408,7 @@ static void render_endjob(void *rjv) /* else the frame will not update for the original value */ if (!(rj->scene->r.scemode & R_NO_FRAME_UPDATE)) - ED_update_for_newframe(G.main, rj->scene, rj->win->screen, 1); + ED_update_for_newframe(G.main, rj->scene, 1); /* XXX above function sets all tags in nodes */ ntreeCompositClearTags(rj->scene->nodetree); @@ -470,7 +470,6 @@ static int screen_render_invoke(bContext *C, wmOperator *op, wmEvent *event) Main *mainp; Scene *scene = CTX_data_scene(C); SceneRenderLayer *srl = NULL; - bScreen *screen = CTX_wm_screen(C); View3D *v3d = CTX_wm_view3d(C); Render *re; wmJob *steve; @@ -507,7 +506,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, wmEvent *event) mainp = CTX_data_main(C); /* cancel animation playback */ - if (screen->animtimer) + if (ED_screen_animation_playing(C)) ED_screen_animation_play(C, 0, 0); /* handle UI stuff */ diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index f973d3cc070..a2fc763163a 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -1506,7 +1506,7 @@ void ED_screen_set_scene(bContext *C, bScreen *screen, Scene *scene) BKE_scene_set_background(bmain, scene); ED_render_engine_changed(bmain); - ED_update_for_newframe(bmain, scene, screen, 1); + ED_update_for_newframe(bmain, scene, 1); /* complete redraw */ WM_event_add_notifier(C, NC_WINDOW, NULL); @@ -1750,10 +1750,12 @@ void ED_screen_animation_timer(bContext *C, int redraws, int refresh, int sync, wmWindowManager *wm = CTX_wm_manager(C); wmWindow *win = CTX_wm_window(C); Scene *scene = CTX_data_scene(C); + bScreen *stopscreen = ED_screen_animation_playing(C); - if (screen->animtimer) - WM_event_remove_timer(wm, win, screen->animtimer); - screen->animtimer = NULL; + if (stopscreen) { + WM_event_remove_timer(wm, win, stopscreen->animtimer); + stopscreen->animtimer = NULL; + } if (enable) { ScreenAnimData *sad = MEM_callocN(sizeof(ScreenAnimData), "ScreenAnimData"); @@ -1777,8 +1779,9 @@ void ED_screen_animation_timer(bContext *C, int redraws, int refresh, int sync, screen->animtimer->customdata = sad; } + /* notifier catched by top header, for button */ - WM_event_add_notifier(C, NC_SCREEN | ND_ANIMPLAY, screen); + WM_event_add_notifier(C, NC_SCREEN | ND_ANIMPLAY, NULL); } /* helper for screen_animation_play() - only to be used for TimeLine */ @@ -1821,8 +1824,12 @@ void ED_screen_animation_timer_update(bScreen *screen, int redraws, int refresh) /* results in fully updated anim system * screen can be NULL */ -void ED_update_for_newframe(Main *bmain, Scene *scene, bScreen *screen, int UNUSED(mute)) -{ +void ED_update_for_newframe(Main *bmain, Scene *scene, int UNUSED(mute)) +{ + wmWindowManager *wm = bmain->wm.first; + wmWindow *window; + int layers = 0; + #ifdef DURIAN_CAMERA_SWITCH void *camera = BKE_scene_camera_switch_find(scene); if (camera && scene->camera != camera) { @@ -1843,9 +1850,12 @@ void ED_update_for_newframe(Main *bmain, Scene *scene, bScreen *screen, int UNUS ED_clip_update_frame(bmain, scene->r.cfra); + /* get layers from all windows */ + for (window = wm->windows.first; window; window = window->next) + layers |= BKE_screen_visible_layers(window->screen, scene); + /* this function applies the changes too */ - /* XXX future: do all windows */ - BKE_scene_update_for_newframe(bmain, scene, BKE_screen_visible_layers(screen, scene)); /* BKE_scene.h */ + BKE_scene_update_for_newframe(bmain, scene, layers); /* BKE_scene.h */ //if ( (CFRA>1) && (!mute) && (scene->r.audio.flag & AUDIO_SCRUB)) // audiostream_scrub( CFRA ); diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 5c68c92500b..5280968c11f 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -2905,6 +2905,8 @@ static int screen_animation_step(bContext *C, wmOperator *UNUSED(op), wmEvent *e Scene *scene = CTX_data_scene(C); wmTimer *wt = screen->animtimer; ScreenAnimData *sad = wt->customdata; + wmWindowManager *wm = CTX_wm_manager(C); + wmWindow *window; ScrArea *sa; int sync; float time; @@ -2985,22 +2987,24 @@ static int screen_animation_step(bContext *C, wmOperator *UNUSED(op), wmEvent *e sound_seek_scene(bmain, scene); /* since we follow drawflags, we can't send notifier but tag regions ourselves */ - ED_update_for_newframe(CTX_data_main(C), scene, screen, 1); - - for (sa = screen->areabase.first; sa; sa = sa->next) { - ARegion *ar; - for (ar = sa->regionbase.first; ar; ar = ar->next) { - if (ar == sad->ar) - ED_region_tag_redraw(ar); - else - if (match_region_with_redraws(sa->spacetype, ar->regiontype, sad->redraws)) - ED_region_tag_redraw(ar); + ED_update_for_newframe(CTX_data_main(C), scene, 1); + + for (window = wm->windows.first; window; window = window->next) { + for (sa = window->screen->areabase.first; sa; sa = sa->next) { + ARegion *ar; + for (ar = sa->regionbase.first; ar; ar = ar->next) { + if (ar == sad->ar) + ED_region_tag_redraw(ar); + else + if (match_region_with_redraws(sa->spacetype, ar->regiontype, sad->redraws)) + ED_region_tag_redraw(ar); + } + + if (match_area_with_refresh(sa->spacetype, sad->refresh)) + ED_area_tag_refresh(sa); } - - if (match_area_with_refresh(sa->spacetype, sad->refresh)) - ED_area_tag_refresh(sa); } - + /* update frame rate info too * NOTE: this may not be accurate enough, since we might need this after modifiers/etc. * have been calculated instead of just before updates have been done? @@ -3034,13 +3038,26 @@ static void SCREEN_OT_animation_step(wmOperatorType *ot) /* ****************** anim player, starts or ends timer ***************** */ +/* find window that owns the animation timer */ +bScreen *ED_screen_animation_playing(const bContext *C) +{ + wmWindowManager *wm = CTX_wm_manager(C); + wmWindow *window; + + for (window = wm->windows.first; window; window = window->next) + if (window->screen->animtimer) + return window->screen; + + return NULL; +} + /* toggle operator */ int ED_screen_animation_play(bContext *C, int sync, int mode) { bScreen *screen = CTX_wm_screen(C); Scene *scene = CTX_data_scene(C); - if (screen->animtimer) { + if (ED_screen_animation_playing(C)) { /* stop playback now */ ED_screen_animation_timer(C, 0, 0, 0, 0); sound_stop_scene(scene); @@ -3097,9 +3114,9 @@ static void SCREEN_OT_animation_play(wmOperatorType *ot) static int screen_animation_cancel_exec(bContext *C, wmOperator *op) { - bScreen *screen = CTX_wm_screen(C); + bScreen *screen = ED_screen_animation_playing(C); - if (screen->animtimer) { + if (screen) { if (RNA_boolean_get(op->ptr, "restore_frame")) { ScreenAnimData *sad = screen->animtimer->customdata; Scene *scene = CTX_data_scene(C); diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c index 8fafcd9d675..f6dbae596b8 100644 --- a/source/blender/editors/space_clip/tracking_ops.c +++ b/source/blender/editors/space_clip/tracking_ops.c @@ -1528,7 +1528,7 @@ static void track_markers_freejob(void *tmv) tmj->clip->tracking_context = NULL; tmj->scene->r.cfra = tmj->lastfra; - ED_update_for_newframe(tmj->main, tmj->scene, tmj->screen, 0); + ED_update_for_newframe(tmj->main, tmj->scene, 0); BKE_tracking_sync(tmj->context); BKE_tracking_context_free(tmj->context); diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index f7014bb51eb..0019839aa4f 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -2997,7 +2997,6 @@ static void view3d_main_area_draw_info(const bContext *C, ARegion *ar, const cha Scene *scene = CTX_data_scene(C); View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); - bScreen *screen = CTX_wm_screen(C); Object *ob; @@ -3026,7 +3025,7 @@ static void view3d_main_area_draw_info(const bContext *C, ARegion *ar, const cha return; } - if ((U.uiflag & USER_SHOW_FPS) && screen->animtimer) { + if ((U.uiflag & USER_SHOW_FPS) && ED_screen_animation_playing(C)) { draw_viewport_fps(scene, ar); } else if (U.uiflag & USER_SHOW_VIEWPORTNAME) { diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index 23c1fba6107..dd8af64c15d 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -93,6 +93,7 @@ #include "ED_view3d.h" #include "ED_curve.h" /* for curve_editnurbs */ #include "ED_clip.h" +#include "ED_screen.h" //#include "BDR_unwrapper.h" @@ -1038,9 +1039,10 @@ int initTransInfo(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event) if (t->spacetype == SPACE_VIEW3D) { View3D *v3d = sa->spacedata.first; + bScreen *animscreen = ED_screen_animation_playing(C); t->view = v3d; - t->animtimer= CTX_wm_screen(C)->animtimer; + t->animtimer= (animscreen)? animscreen->animtimer: NULL; /* turn manipulator off during transform */ // FIXME: but don't do this when USING the manipulator... diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 3533b8a19f6..a4127b2bdfd 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -245,7 +245,7 @@ void wm_event_do_notifiers(bContext *C) if (!G.rendering) { /* depsgraph gets called, might send more notifiers */ - ED_update_for_newframe(CTX_data_main(C), win->screen->scene, win->screen, 1); + ED_update_for_newframe(CTX_data_main(C), win->screen->scene, 1); } } } @@ -1961,7 +1961,7 @@ void wm_event_do_handlers(bContext *C) CTX_wm_screen_set(C, win->screen); CTX_data_scene_set(C, scene); - if (((playing == 1) && (!win->screen->animtimer)) || ((playing == 0) && (win->screen->animtimer))) { + if (((playing == 1) && (!ED_screen_animation_playing(C))) || ((playing == 0) && (ED_screen_animation_playing(C)))) { ED_screen_animation_play(C, -1, 1); } @@ -1971,7 +1971,7 @@ void wm_event_do_handlers(bContext *C) int ncfra = sound_sync_scene(scene) * (float)FPS + 0.5f; if (ncfra != scene->r.cfra) { scene->r.cfra = ncfra; - ED_update_for_newframe(CTX_data_main(C), scene, win->screen, 1); + ED_update_for_newframe(CTX_data_main(C), scene, 1); WM_event_add_notifier(C, NC_WINDOW, NULL); } } -- cgit v1.2.3