Cleanup: VSE: Refactor seq_render_scene_strip

* Removes the `goto` statements
* Pulls out the store/restore logic into a higher-level function

Pull Request: https://projects.blender.org/blender/blender/pulls/147279
This commit is contained in:
Falk David
2025-10-06 11:37:59 +02:00
committed by Falk David
parent 662a49f5db
commit 3e21341188

View File

@@ -1351,22 +1351,14 @@ static ImBuf *seq_render_mask_strip(const RenderData *context, Strip *strip, flo
return seq_render_mask(context, strip->mask, frame_index, make_float);
}
static ImBuf *seq_render_scene_strip(const RenderData *context,
Strip *strip,
float frame_index,
float timeline_frame)
static ImBuf *seq_render_scene_strip_ex(const RenderData *context,
Strip *strip,
float frame_index,
float timeline_frame)
{
ImBuf *ibuf = nullptr;
double frame;
Object *camera;
struct {
int scemode;
int timeline_frame;
float subframe;
int mode;
} orig_data;
/* Old info:
* Hack! This function can be called from do_render_seq(), in that case
* the strip->scene can already have a Render initialized with same name,
@@ -1398,43 +1390,29 @@ static ImBuf *seq_render_scene_strip(const RenderData *context,
* -jahka
*/
const bool is_rendering = G.is_rendering;
bool is_preview = !context->for_render && (context->scene->r.seq_prev_type) != OB_RENDER;
bool have_comp = false;
bool use_gpencil = true;
/* do we need to re-evaluate the frame after rendering? */
bool is_frame_update = false;
Scene *scene;
/* don't refer to strip->scene above this point!, it can be nullptr */
if (strip->scene == nullptr) {
return create_missing_media_image(context, context->rectx, context->recty);
}
Scene *scene = strip->scene;
BLI_assert(scene != nullptr);
/* Prevent rendering scene recursively. */
if (strip->scene == context->scene) {
if (scene == context->scene) {
return nullptr;
}
scene = strip->scene;
frame = double(scene->r.sfra) + double(frame_index) + double(strip->anim_startofs);
const bool is_rendering = G.is_rendering;
const bool is_preview = !context->for_render && (context->scene->r.seq_prev_type) != OB_RENDER;
const bool use_gpencil = (strip->flag & SEQ_SCENE_NO_ANNOTATION) == 0;
double frame = double(scene->r.sfra) + double(frame_index) + double(strip->anim_startofs);
#if 0 /* UNUSED */
have_seq = (scene->r.scemode & R_DOSEQ) && scene->ed && scene->ed->seqbase.first;
bool have_seq = (scene->r.scemode & R_DOSEQ) && scene->ed && scene->ed->seqbase.first;
#endif
have_comp = (scene->r.scemode & R_DOCOMP) && scene->compositing_node_group;
const bool have_comp = (scene->r.scemode & R_DOCOMP) && scene->compositing_node_group;
/* Get view layer for the strip. */
ViewLayer *view_layer = BKE_view_layer_default_render(scene);
/* Depsgraph will be nullptr when doing rendering. */
Depsgraph *depsgraph = nullptr;
orig_data.scemode = scene->r.scemode;
orig_data.timeline_frame = scene->r.cfra;
orig_data.subframe = scene->r.subframe;
orig_data.mode = scene->r.mode;
BKE_scene_frame_set(scene, frame);
if (strip->scene_camera) {
@@ -1446,11 +1424,7 @@ static ImBuf *seq_render_scene_strip(const RenderData *context,
}
if (have_comp == false && camera == nullptr) {
goto finally;
}
if (strip->flag & SEQ_SCENE_NO_ANNOTATION) {
use_gpencil = false;
return nullptr;
}
/* Prevent eternal loop. */
@@ -1459,9 +1433,6 @@ static ImBuf *seq_render_scene_strip(const RenderData *context,
/* Temporarily disable camera switching to enforce using `camera`. */
scene->r.mode |= R_NO_CAMERA_SWITCH;
is_frame_update = (orig_data.timeline_frame != scene->r.cfra) ||
(orig_data.subframe != scene->r.subframe);
if (view3d_fn && is_preview && camera) {
char err_out[256] = "unknown";
int width, height;
@@ -1521,7 +1492,7 @@ static ImBuf *seq_render_scene_strip(const RenderData *context,
*/
if (is_preview && (is_rendering && !G.background)) {
goto finally;
return ibuf;
}
ibufs_arr = MEM_calloc_arrayN<ImBuf *>(totviews, "Sequence Image Views Imbufs");
@@ -1595,18 +1566,49 @@ static ImBuf *seq_render_scene_strip(const RenderData *context,
MEM_freeN(ibufs_arr);
}
finally:
/* restore */
return ibuf;
}
static ImBuf *seq_render_scene_strip(const RenderData *context,
Strip *strip,
float frame_index,
float timeline_frame)
{
if (strip->scene == nullptr) {
return create_missing_media_image(context, context->rectx, context->recty);
}
Scene *scene = strip->scene;
struct {
int scemode;
int timeline_frame;
float subframe;
int mode;
} orig_data;
/* Store state. */
orig_data.scemode = scene->r.scemode;
orig_data.timeline_frame = scene->r.cfra;
orig_data.subframe = scene->r.subframe;
orig_data.mode = scene->r.mode;
const bool is_frame_update = (orig_data.timeline_frame != scene->r.cfra) ||
(orig_data.subframe != scene->r.subframe);
ImBuf *ibuf = seq_render_scene_strip_ex(context, strip, frame_index, timeline_frame);
/* Restore state. */
scene->r.scemode = orig_data.scemode;
scene->r.cfra = orig_data.timeline_frame;
scene->r.subframe = orig_data.subframe;
scene->r.mode &= orig_data.mode | ~R_NO_CAMERA_SWITCH;
Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, BKE_view_layer_default_render(scene));
if (is_frame_update && (depsgraph != nullptr)) {
BKE_scene_graph_update_for_newframe(depsgraph);
}
scene->r.mode &= orig_data.mode | ~R_NO_CAMERA_SWITCH;
return ibuf;
}