From 4cf2d95bb575589c34b712919bd6a2e2666104dc Mon Sep 17 00:00:00 2001 From: Aras Pranckevicius Date: Mon, 5 Feb 2024 11:37:42 +0200 Subject: [PATCH] Cleanup: more C++ constructs in VSE render.hh and friends - enum class StripEarlyOut instead of raw integer defines - SeqRenderState default initializer instead of seq_render_state_init - Vector instead of manually sized arrays of pointers - some const to several function arguments Pull Request: https://projects.blender.org/blender/blender/pulls/117829 --- source/blender/sequencer/SEQ_effects.hh | 26 ++-- source/blender/sequencer/intern/effects.cc | 140 ++++++++--------- source/blender/sequencer/intern/modifier.cc | 1 - source/blender/sequencer/intern/prefetch.cc | 7 +- source/blender/sequencer/intern/proxy.cc | 1 - source/blender/sequencer/intern/render.cc | 160 +++++++++----------- source/blender/sequencer/intern/render.hh | 23 +-- 7 files changed, 166 insertions(+), 192 deletions(-) diff --git a/source/blender/sequencer/SEQ_effects.hh b/source/blender/sequencer/SEQ_effects.hh index a8d62f8c6ec..7c9f93cc3ad 100644 --- a/source/blender/sequencer/SEQ_effects.hh +++ b/source/blender/sequencer/SEQ_effects.hh @@ -13,6 +13,13 @@ struct SeqRenderData; struct Sequence; struct TextVars; +enum class StripEarlyOut { + NoInput = -1, /* No input needed. */ + DoEffect = 0, /* No early out (do the effect). */ + UseInput1 = 1, /* Output = input1. */ + UseInput2 = 2, /* Output = input2. */ +}; + /* Wipe effect */ enum { DO_SINGLE_WIPE, @@ -40,19 +47,18 @@ struct SeqEffectHandle { void (*load)(Sequence *seqconst); /* duplicate */ - void (*copy)(Sequence *dst, Sequence *src, int flag); + void (*copy)(Sequence *dst, const Sequence *src, int flag); /* destruct */ void (*free)(Sequence *seq, bool do_id_user); - /* returns: -1: no input needed, - * 0: no early out, - * 1: out = ibuf1, - * 2: out = ibuf2 */ - int (*early_out)(Sequence *seq, float fac); + StripEarlyOut (*early_out)(const Sequence *seq, float fac); /* sets the default `fac` value */ - void (*get_default_fac)(const Scene *scene, Sequence *seq, float timeline_frame, float *fac); + void (*get_default_fac)(const Scene *scene, + const Sequence *seq, + float timeline_frame, + float *fac); /* execute the effect * sequence effects are only required to either support @@ -73,9 +79,9 @@ struct SeqEffectHandle { Sequence *seq, float timeline_frame, float fac, - ImBuf *ibuf1, - ImBuf *ibuf2, - ImBuf *ibuf3, + const ImBuf *ibuf1, + const ImBuf *ibuf2, + const ImBuf *ibuf3, int start_line, int total_lines, ImBuf *out); diff --git a/source/blender/sequencer/intern/effects.cc b/source/blender/sequencer/intern/effects.cc index fb098641228..c0cb43a7913 100644 --- a/source/blender/sequencer/intern/effects.cc +++ b/source/blender/sequencer/intern/effects.cc @@ -290,9 +290,9 @@ static void do_alphaover_effect(const SeqRenderData *context, Sequence * /*seq*/, float /*timeline_frame*/, float fac, - ImBuf *ibuf1, - ImBuf *ibuf2, - ImBuf * /*ibuf3*/, + const ImBuf *ibuf1, + const ImBuf *ibuf2, + const ImBuf * /*ibuf3*/, int start_line, int total_lines, ImBuf *out) @@ -355,9 +355,9 @@ static void do_alphaunder_effect(const SeqRenderData *context, Sequence * /*seq*/, float /*timeline_frame*/, float fac, - ImBuf *ibuf1, - ImBuf *ibuf2, - ImBuf * /*ibuf3*/, + const ImBuf *ibuf1, + const ImBuf *ibuf2, + const ImBuf * /*ibuf3*/, int start_line, int total_lines, ImBuf *out) @@ -435,9 +435,9 @@ static void do_cross_effect(const SeqRenderData *context, Sequence * /*seq*/, float /*timeline_frame*/, float fac, - ImBuf *ibuf1, - ImBuf *ibuf2, - ImBuf * /*ibuf3*/, + const ImBuf *ibuf1, + const ImBuf *ibuf2, + const ImBuf * /*ibuf3*/, int start_line, int total_lines, ImBuf *out) @@ -519,9 +519,9 @@ static void do_gammacross_effect(const SeqRenderData *context, Sequence * /*seq*/, float /*timeline_frame*/, float fac, - ImBuf *ibuf1, - ImBuf *ibuf2, - ImBuf * /*ibuf3*/, + const ImBuf *ibuf1, + const ImBuf *ibuf2, + const ImBuf * /*ibuf3*/, int start_line, int total_lines, ImBuf *out) @@ -598,9 +598,9 @@ static void do_add_effect(const SeqRenderData *context, Sequence * /*seq*/, float /*timeline_frame*/, float fac, - ImBuf *ibuf1, - ImBuf *ibuf2, - ImBuf * /*ibuf3*/, + const ImBuf *ibuf1, + const ImBuf *ibuf2, + const ImBuf * /*ibuf3*/, int start_line, int total_lines, ImBuf *out) @@ -679,9 +679,9 @@ static void do_sub_effect(const SeqRenderData *context, Sequence * /*seq*/, float /*timeline_frame*/, float fac, - ImBuf *ibuf1, - ImBuf *ibuf2, - ImBuf * /*ibuf3*/, + const ImBuf *ibuf1, + const ImBuf *ibuf2, + const ImBuf * /*ibuf3*/, int start_line, int total_lines, ImBuf *out) @@ -840,9 +840,9 @@ static void do_mul_effect(const SeqRenderData *context, Sequence * /*seq*/, float /*timeline_frame*/, float fac, - ImBuf *ibuf1, - ImBuf *ibuf2, - ImBuf * /*ibuf3*/, + const ImBuf *ibuf1, + const ImBuf *ibuf2, + const ImBuf * /*ibuf3*/, int start_line, int total_lines, ImBuf *out) @@ -1038,9 +1038,9 @@ static void do_blend_mode_effect(const SeqRenderData *context, Sequence *seq, float /*timeline_frame*/, float fac, - ImBuf *ibuf1, - ImBuf *ibuf2, - ImBuf * /*ibuf3*/, + const ImBuf *ibuf1, + const ImBuf *ibuf2, + const ImBuf * /*ibuf3*/, int start_line, int total_lines, ImBuf *out) @@ -1084,9 +1084,9 @@ static void do_colormix_effect(const SeqRenderData *context, Sequence *seq, float /*timeline_frame*/, float /*fac*/, - ImBuf *ibuf1, - ImBuf *ibuf2, - ImBuf * /*ibuf3*/, + const ImBuf *ibuf1, + const ImBuf *ibuf2, + const ImBuf * /*ibuf3*/, int start_line, int total_lines, ImBuf *out) @@ -1403,7 +1403,7 @@ static void free_wipe_effect(Sequence *seq, const bool /*do_id_user*/) MEM_SAFE_FREE(seq->effectdata); } -static void copy_wipe_effect(Sequence *dst, Sequence *src, const int /*flag*/) +static void copy_wipe_effect(Sequence *dst, const Sequence *src, const int /*flag*/) { dst->effectdata = MEM_dupallocN(src->effectdata); } @@ -1528,7 +1528,7 @@ static void free_transform_effect(Sequence *seq, const bool /*do_id_user*/) MEM_SAFE_FREE(seq->effectdata); } -static void copy_transform_effect(Sequence *dst, Sequence *src, const int /*flag*/) +static void copy_transform_effect(Sequence *dst, const Sequence *src, const int /*flag*/) { dst->effectdata = MEM_dupallocN(src->effectdata); } @@ -1537,7 +1537,7 @@ static void transform_image(int x, int y, int start_line, int total_lines, - ImBuf *ibuf, + const ImBuf *ibuf, ImBuf *out, float scale_x, float scale_y, @@ -1608,9 +1608,9 @@ static void do_transform_effect(const SeqRenderData *context, Sequence *seq, float /*timeline_frame*/, float /*fac*/, - ImBuf *ibuf1, - ImBuf * /*ibuf2*/, - ImBuf * /*ibuf3*/, + const ImBuf *ibuf1, + const ImBuf * /*ibuf2*/, + const ImBuf * /*ibuf3*/, int start_line, int total_lines, ImBuf *out) @@ -1800,7 +1800,7 @@ static void free_glow_effect(Sequence *seq, const bool /*do_id_user*/) MEM_SAFE_FREE(seq->effectdata); } -static void copy_glow_effect(Sequence *dst, Sequence *src, const int /*flag*/) +static void copy_glow_effect(Sequence *dst, const Sequence *src, const int /*flag*/) { dst->effectdata = MEM_dupallocN(src->effectdata); } @@ -1938,14 +1938,14 @@ static void free_solid_color(Sequence *seq, const bool /*do_id_user*/) MEM_SAFE_FREE(seq->effectdata); } -static void copy_solid_color(Sequence *dst, Sequence *src, const int /*flag*/) +static void copy_solid_color(Sequence *dst, const Sequence *src, const int /*flag*/) { dst->effectdata = MEM_dupallocN(src->effectdata); } -static int early_out_color(Sequence * /*seq*/, float /*fac*/) +static StripEarlyOut early_out_color(const Sequence * /*seq*/, float /*fac*/) { - return EARLY_NO_INPUT; + return StripEarlyOut::NoInput; } static ImBuf *do_solid_color(const SeqRenderData *context, @@ -2009,9 +2009,9 @@ static int num_inputs_multicam() return 0; } -static int early_out_multicam(Sequence * /*seq*/, float /*fac*/) +static StripEarlyOut early_out_multicam(const Sequence * /*seq*/, float /*fac*/) { - return EARLY_NO_INPUT; + return StripEarlyOut::NoInput; } static ImBuf *do_multicam(const SeqRenderData *context, @@ -2057,9 +2057,9 @@ static int num_inputs_adjustment() return 0; } -static int early_out_adjustment(Sequence * /*seq*/, float /*fac*/) +static StripEarlyOut early_out_adjustment(const Sequence * /*seq*/, float /*fac*/) { - return EARLY_NO_INPUT; + return StripEarlyOut::NoInput; } static ImBuf *do_adjustment_impl(const SeqRenderData *context, Sequence *seq, float timeline_frame) @@ -2166,7 +2166,7 @@ static void free_speed_effect(Sequence *seq, const bool /*do_id_user*/) MEM_SAFE_FREE(seq->effectdata); } -static void copy_speed_effect(Sequence *dst, Sequence *src, const int /*flag*/) +static void copy_speed_effect(Sequence *dst, const Sequence *src, const int /*flag*/) { SpeedControlVars *v; dst->effectdata = MEM_dupallocN(src->effectdata); @@ -2174,9 +2174,9 @@ static void copy_speed_effect(Sequence *dst, Sequence *src, const int /*flag*/) v->frameMap = nullptr; } -static int early_out_speed(Sequence * /*seq*/, float /*fac*/) +static StripEarlyOut early_out_speed(const Sequence * /*seq*/, float /*fac*/) { - return EARLY_DO_EFFECT; + return StripEarlyOut::DoEffect; } static FCurve *seq_effect_speed_speed_factor_curve_get(Scene *scene, Sequence *seq) @@ -2326,9 +2326,9 @@ static void do_overdrop_effect(const SeqRenderData *context, Sequence * /*seq*/, float /*timeline_frame*/, float fac, - ImBuf *ibuf1, - ImBuf *ibuf2, - ImBuf * /*ibuf3*/, + const ImBuf *ibuf1, + const ImBuf *ibuf2, + const ImBuf * /*ibuf3*/, int start_line, int total_lines, ImBuf *out) @@ -2381,18 +2381,18 @@ static void free_gaussian_blur_effect(Sequence *seq, const bool /*do_id_user*/) MEM_SAFE_FREE(seq->effectdata); } -static void copy_gaussian_blur_effect(Sequence *dst, Sequence *src, const int /*flag*/) +static void copy_gaussian_blur_effect(Sequence *dst, const Sequence *src, const int /*flag*/) { dst->effectdata = MEM_dupallocN(src->effectdata); } -static int early_out_gaussian_blur(Sequence *seq, float /*fac*/) +static StripEarlyOut early_out_gaussian_blur(const Sequence *seq, float /*fac*/) { GaussianBlurVars *data = static_cast(seq->effectdata); if (data->size_x == 0.0f && data->size_y == 0) { - return EARLY_USE_INPUT_1; + return StripEarlyOut::UseInput1; } - return EARLY_DO_EFFECT; + return StripEarlyOut::DoEffect; } static blender::Array make_gaussian_blur_kernel(float rad, int size) @@ -2679,7 +2679,7 @@ static void load_text_effect(Sequence *seq) SEQ_effect_text_font_load(data, false); } -static void copy_text_effect(Sequence *dst, Sequence *src, const int flag) +static void copy_text_effect(Sequence *dst, const Sequence *src, const int flag) { dst->effectdata = MEM_dupallocN(src->effectdata); TextVars *data = static_cast(dst->effectdata); @@ -2693,16 +2693,16 @@ static int num_inputs_text() return 0; } -static int early_out_text(Sequence *seq, float /*fac*/) +static StripEarlyOut early_out_text(const Sequence *seq, float /*fac*/) { TextVars *data = static_cast(seq->effectdata); if (data->text[0] == 0 || data->text_size < 1.0f || ((data->color[3] == 0.0f) && (data->shadow_color[3] == 0.0f || (data->flag & SEQ_TEXT_SHADOW) == 0))) { - return EARLY_USE_INPUT_1; + return StripEarlyOut::UseInput1; } - return EARLY_NO_INPUT; + return StripEarlyOut::NoInput; } static ImBuf *do_text_effect(const SeqRenderData *context, @@ -2842,7 +2842,7 @@ static int num_inputs_default() return 2; } -static void copy_effect_default(Sequence *dst, Sequence *src, const int /*flag*/) +static void copy_effect_default(Sequence *dst, const Sequence *src, const int /*flag*/) { dst->effectdata = MEM_dupallocN(src->effectdata); } @@ -2852,40 +2852,40 @@ static void free_effect_default(Sequence *seq, const bool /*do_id_user*/) MEM_SAFE_FREE(seq->effectdata); } -static int early_out_noop(Sequence * /*seq*/, float /*fac*/) +static StripEarlyOut early_out_noop(const Sequence * /*seq*/, float /*fac*/) { - return EARLY_DO_EFFECT; + return StripEarlyOut::DoEffect; } -static int early_out_fade(Sequence * /*seq*/, float fac) +static StripEarlyOut early_out_fade(const Sequence * /*seq*/, float fac) { if (fac == 0.0f) { - return EARLY_USE_INPUT_1; + return StripEarlyOut::UseInput1; } if (fac == 1.0f) { - return EARLY_USE_INPUT_2; + return StripEarlyOut::UseInput2; } - return EARLY_DO_EFFECT; + return StripEarlyOut::DoEffect; } -static int early_out_mul_input2(Sequence * /*seq*/, float fac) +static StripEarlyOut early_out_mul_input2(const Sequence * /*seq*/, float fac) { if (fac == 0.0f) { - return EARLY_USE_INPUT_1; + return StripEarlyOut::UseInput1; } - return EARLY_DO_EFFECT; + return StripEarlyOut::DoEffect; } -static int early_out_mul_input1(Sequence * /*seq*/, float fac) +static StripEarlyOut early_out_mul_input1(const Sequence * /*seq*/, float fac) { if (fac == 0.0f) { - return EARLY_USE_INPUT_2; + return StripEarlyOut::UseInput2; } - return EARLY_DO_EFFECT; + return StripEarlyOut::DoEffect; } static void get_default_fac_noop(const Scene * /*scene*/, - Sequence * /*seq*/, + const Sequence * /*seq*/, float /*timeline_frame*/, float *fac) { @@ -2893,7 +2893,7 @@ static void get_default_fac_noop(const Scene * /*scene*/, } static void get_default_fac_fade(const Scene *scene, - Sequence *seq, + const Sequence *seq, float timeline_frame, float *fac) { diff --git a/source/blender/sequencer/intern/modifier.cc b/source/blender/sequencer/intern/modifier.cc index 0bf4a776dd5..be3854c89bb 100644 --- a/source/blender/sequencer/intern/modifier.cc +++ b/source/blender/sequencer/intern/modifier.cc @@ -86,7 +86,6 @@ static ImBuf *modifier_render_mask_input(const SeqRenderData *context, if (mask_input_type == SEQUENCE_MASK_INPUT_STRIP) { if (mask_sequence) { SeqRenderState state; - seq_render_state_init(&state); mask_input = seq_render_strip(context, &state, mask_sequence, timeline_frame); diff --git a/source/blender/sequencer/intern/prefetch.cc b/source/blender/sequencer/intern/prefetch.cc index cc9ad607b8b..bc0f4afc3eb 100644 --- a/source/blender/sequencer/intern/prefetch.cc +++ b/source/blender/sequencer/intern/prefetch.cc @@ -401,12 +401,11 @@ static bool seq_prefetch_scene_strip_is_rendered(PrefetchJob *pfjob, bool is_recursive_check) { float cfra = seq_prefetch_cfra(pfjob); - Sequence *seq_arr[MAXSEQ + 1]; - int count = seq_get_shown_sequences(pfjob->scene_eval, channels, seqbase, cfra, 0, seq_arr); + blender::Vector strips = seq_get_shown_sequences( + pfjob->scene_eval, channels, seqbase, cfra, 0); /* Iterate over rendered strips. */ - for (int i = 0; i < count; i++) { - Sequence *seq = seq_arr[i]; + for (Sequence *seq : strips) { if (seq->type == SEQ_TYPE_META && seq_prefetch_scene_strip_is_rendered(pfjob, channels, &seq->seqbase, scene_strips, true)) { diff --git a/source/blender/sequencer/intern/proxy.cc b/source/blender/sequencer/intern/proxy.cc index cdbd56776c6..3f86dca3310 100644 --- a/source/blender/sequencer/intern/proxy.cc +++ b/source/blender/sequencer/intern/proxy.cc @@ -550,7 +550,6 @@ void SEQ_proxy_rebuild(SeqIndexBuildContext *context, wmJobWorkerStatus *worker_ render_context.view_id = context->view_id; SeqRenderState state; - seq_render_state_init(&state); for (timeline_frame = SEQ_time_left_handle_frame_get(scene, seq); timeline_frame < SEQ_time_right_handle_frame_get(scene, seq); diff --git a/source/blender/sequencer/intern/render.cc b/source/blender/sequencer/intern/render.cc index 1dced0ed19b..de998d5f0d7 100644 --- a/source/blender/sequencer/intern/render.cc +++ b/source/blender/sequencer/intern/render.cc @@ -1,11 +1,11 @@ /* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved. - * SPDX-FileCopyrightText: 2003-2009 Blender Authors + * SPDX-FileCopyrightText: 2003-2024 Blender Authors * SPDX-FileCopyrightText: 2005-2006 Peter Schlaile * * SPDX-License-Identifier: GPL-2.0-or-later */ /** \file - * \ingroup bke + * \ingroup sequencer */ #include @@ -75,6 +75,10 @@ #include "strip_time.hh" #include "utils.hh" +#include + +using namespace blender; + static ImBuf *seq_render_strip_stack(const SeqRenderData *context, SeqRenderState *state, ListBase *channels, @@ -89,7 +93,7 @@ SequencerDrawView sequencer_view3d_fn = nullptr; /* nullptr in background mode * /** \name Color-space utility functions * \{ */ -void seq_imbuf_assign_spaces(Scene *scene, ImBuf *ibuf) +void seq_imbuf_assign_spaces(const Scene *scene, ImBuf *ibuf) { #if 0 /* Byte buffer is supposed to be in sequencer working space already. */ @@ -102,7 +106,7 @@ void seq_imbuf_assign_spaces(Scene *scene, ImBuf *ibuf) } } -void seq_imbuf_to_sequencer_space(Scene *scene, ImBuf *ibuf, bool make_float) +void seq_imbuf_to_sequencer_space(const Scene *scene, ImBuf *ibuf, bool make_float) { /* Early output check: if both buffers are nullptr we have nothing to convert. */ if (ibuf->float_buffer.data == nullptr && ibuf->byte_buffer.data == nullptr) { @@ -243,11 +247,6 @@ void SEQ_render_new_render_data(Main *bmain, r_context->is_prefetch_render = false; } -void seq_render_state_init(SeqRenderState *state) -{ - state->scene_parents = nullptr; -} - StripElem *SEQ_render_give_stripelem(const Scene *scene, Sequence *seq, int timeline_frame) { StripElem *se = seq->strip->stripdata; @@ -268,39 +267,32 @@ StripElem *SEQ_render_give_stripelem(const Scene *scene, Sequence *seq, int time return se; } -static int seq_channel_cmp_fn(const void *a, const void *b) +Vector seq_get_shown_sequences(const Scene *scene, + ListBase *channels, + ListBase *seqbase, + const int timeline_frame, + const int chanshown) { - return (*(Sequence **)a)->machine - (*(Sequence **)b)->machine; -} - -int seq_get_shown_sequences(const Scene *scene, - ListBase *channels, - ListBase *seqbase, - const int timeline_frame, - const int chanshown, - Sequence **r_seq_arr) -{ - blender::VectorSet strips = SEQ_query_rendered_strips( + Vector result; + VectorSet strips = SEQ_query_rendered_strips( scene, channels, seqbase, timeline_frame, chanshown); const int strip_count = strips.size(); if (UNLIKELY(strip_count > MAXSEQ)) { BLI_assert_msg(0, "Too many strips, this shouldn't happen"); - return 0; + return result; } - /* Copy collection elements into array. */ - memset(r_seq_arr, 0, sizeof(Sequence *) * (MAXSEQ + 1)); - int index = 0; + result.reserve(strips.size()); for (Sequence *seq : strips) { - r_seq_arr[index] = seq; - index++; + result.append(seq); } - /* Sort array by channel. */ - qsort(r_seq_arr, strip_count, sizeof(Sequence *), seq_channel_cmp_fn); - - return strip_count; + /* Sort strips by channel. */ + std::sort(result.begin(), result.end(), [](const Sequence *a, const Sequence *b) { + return a->machine < b->machine; + }); + return result; } /** \} */ @@ -424,9 +416,9 @@ static void sequencer_image_crop_transform_matrix(const Sequence *seq, float rotation_matrix[3][3]; axis_angle_to_mat3_single(rotation_matrix, 'Z', transform->rotation); loc_rot_size_to_mat4(r_transform_matrix, - blender::float3{translate_x, translate_y, 0.0f}, + float3{translate_x, translate_y, 0.0f}, rotation_matrix, - blender::float3{scale_x, scale_y, 1.0f}); + float3{scale_x, scale_y, 1.0f}); transform_pivot_set_m4(r_transform_matrix, pivot); invert_m4(r_transform_matrix); } @@ -460,9 +452,9 @@ static void sequencer_thumbnail_transform(ImBuf *in, ImBuf *out) float rotation_matrix[3][3]; unit_m3(rotation_matrix); loc_rot_size_to_mat4(transform_matrix, - blender::float3{image_center_offs_x, image_center_offs_y, 0.0f}, + float3{image_center_offs_x, image_center_offs_y, 0.0f}, rotation_matrix, - blender::float3{scale_x, scale_y, 1.0f}); + float3{scale_x, scale_y, 1.0f}); transform_pivot_set_m4(transform_matrix, pivot); invert_m4(transform_matrix); IMB_transform( @@ -483,25 +475,25 @@ static bool seq_image_transform_transparency_gained(const SeqRenderData *context float seq_image_quad[4][2]; SEQ_image_transform_final_quad_get(scene, seq, seq_image_quad); for (int i = 0; i < 4; i++) { - add_v2_v2(seq_image_quad[i], blender::float2{x / 2.0f, y / 2.0f}); + add_v2_v2(seq_image_quad[i], float2{x / 2.0f, y / 2.0f}); } - return !isect_point_quad_v2(blender::float2{float(x), float(y)}, + return !isect_point_quad_v2(float2{float(x), float(y)}, seq_image_quad[0], seq_image_quad[1], seq_image_quad[2], seq_image_quad[3]) || - !isect_point_quad_v2(blender::float2{0, float(y)}, + !isect_point_quad_v2(float2{0, float(y)}, seq_image_quad[0], seq_image_quad[1], seq_image_quad[2], seq_image_quad[3]) || - !isect_point_quad_v2(blender::float2{float(x), 0}, + !isect_point_quad_v2(float2{float(x), 0}, seq_image_quad[0], seq_image_quad[1], seq_image_quad[2], seq_image_quad[3]) || - !isect_point_quad_v2(blender::float2{0, 0}, + !isect_point_quad_v2(float2{0, 0}, seq_image_quad[0], seq_image_quad[1], seq_image_quad[2], @@ -805,7 +797,6 @@ static ImBuf *seq_render_effect_strip_impl(const SeqRenderData *context, { Scene *scene = context->scene; float fac; - int early_out; int i; SeqEffectHandle sh = SEQ_effect_handle_get(seq); FCurve *fcu = nullptr; @@ -838,13 +829,13 @@ static ImBuf *seq_render_effect_strip_impl(const SeqRenderData *context, } } - early_out = sh.early_out(seq, fac); + StripEarlyOut early_out = sh.early_out(seq, fac); switch (early_out) { - case EARLY_NO_INPUT: + case StripEarlyOut::NoInput: out = sh.execute(context, seq, timeline_frame, fac, nullptr, nullptr, nullptr); break; - case EARLY_DO_EFFECT: + case StripEarlyOut::DoEffect: for (i = 0; i < 3; i++) { /* Speed effect requires time remapping of `timeline_frame` for input(s). */ if (input[0] && seq->type == SEQ_TYPE_SPEED) { @@ -868,12 +859,12 @@ static ImBuf *seq_render_effect_strip_impl(const SeqRenderData *context, } } break; - case EARLY_USE_INPUT_1: + case StripEarlyOut::UseInput1: if (input[0]) { out = seq_render_strip(context, state, input[0], timeline_frame); } break; - case EARLY_USE_INPUT_2: + case StripEarlyOut::UseInput2: if (input[1]) { out = seq_render_strip(context, state, input[1], timeline_frame); } @@ -1820,22 +1811,22 @@ static bool seq_must_swap_input_in_blend_mode(Sequence *seq) return swap_input; } -static int seq_get_early_out_for_blend_mode(Sequence *seq) +static StripEarlyOut seq_get_early_out_for_blend_mode(Sequence *seq) { SeqEffectHandle sh = seq_effect_get_sequence_blend(seq); float fac = seq->blend_opacity / 100.0f; - int early_out = sh.early_out(seq, fac); + StripEarlyOut early_out = sh.early_out(seq, fac); - if (ELEM(early_out, EARLY_DO_EFFECT, EARLY_NO_INPUT)) { + if (ELEM(early_out, StripEarlyOut::DoEffect, StripEarlyOut::NoInput)) { return early_out; } if (seq_must_swap_input_in_blend_mode(seq)) { - if (early_out == EARLY_USE_INPUT_2) { - return EARLY_USE_INPUT_1; + if (early_out == StripEarlyOut::UseInput2) { + return StripEarlyOut::UseInput1; } - if (early_out == EARLY_USE_INPUT_1) { - return EARLY_USE_INPUT_2; + if (early_out == StripEarlyOut::UseInput1) { + return StripEarlyOut::UseInput2; } } return early_out; @@ -1878,21 +1869,16 @@ static ImBuf *seq_render_strip_stack(const SeqRenderData *context, float timeline_frame, int chanshown) { - Sequence *seq_arr[MAXSEQ + 1]; - int count; - int i; - ImBuf *out = nullptr; - - count = seq_get_shown_sequences( - context->scene, channels, seqbasep, timeline_frame, chanshown, seq_arr); - - if (count == 0) { + Vector strips = seq_get_shown_sequences( + context->scene, channels, seqbasep, timeline_frame, chanshown); + if (strips.is_empty()) { return nullptr; } - for (i = count - 1; i >= 0; i--) { - int early_out; - Sequence *seq = seq_arr[i]; + int64_t i; + ImBuf *out = nullptr; + for (i = strips.size() - 1; i >= 0; i--) { + Sequence *seq = strips[i]; out = seq_cache_get(context, seq, timeline_frame, SEQ_CACHE_STORE_COMPOSITE); @@ -1904,33 +1890,33 @@ static ImBuf *seq_render_strip_stack(const SeqRenderData *context, break; } - early_out = seq_get_early_out_for_blend_mode(seq); + StripEarlyOut early_out = seq_get_early_out_for_blend_mode(seq); /* Early out for alpha over. It requires image to be rendered, so it can't use * `seq_get_early_out_for_blend_mode`. */ if (out == nullptr && seq->blend_mode == SEQ_TYPE_ALPHAOVER && seq->blend_opacity == 100.0f) { ImBuf *test = seq_render_strip(context, state, seq, timeline_frame); if (ELEM(test->planes, R_IMF_PLANES_BW, R_IMF_PLANES_RGB)) { - early_out = EARLY_USE_INPUT_2; + early_out = StripEarlyOut::UseInput2; } else { - early_out = EARLY_DO_EFFECT; + early_out = StripEarlyOut::DoEffect; } /* Free the image. It is stored in cache, so this doesn't affect performance. */ IMB_freeImBuf(test); } switch (early_out) { - case EARLY_NO_INPUT: - case EARLY_USE_INPUT_2: + case StripEarlyOut::NoInput: + case StripEarlyOut::UseInput2: out = seq_render_strip(context, state, seq, timeline_frame); break; - case EARLY_USE_INPUT_1: + case StripEarlyOut::UseInput1: if (i == 0) { out = IMB_allocImBuf(context->rectx, context->recty, 32, IB_rect); } break; - case EARLY_DO_EFFECT: + case StripEarlyOut::DoEffect: if (i == 0) { ImBuf *ibuf1 = IMB_allocImBuf(context->rectx, context->recty, 32, IB_rect); ImBuf *ibuf2 = seq_render_strip(context, state, seq, timeline_frame); @@ -1938,7 +1924,7 @@ static ImBuf *seq_render_strip_stack(const SeqRenderData *context, out = seq_render_strip_stack_apply_effect(context, seq, timeline_frame, ibuf1, ibuf2); IMB_metadata_copy(out, ibuf2); - seq_cache_put(context, seq_arr[i], timeline_frame, SEQ_CACHE_STORE_COMPOSITE, out); + seq_cache_put(context, strips[i], timeline_frame, SEQ_CACHE_STORE_COMPOSITE, out); IMB_freeImBuf(ibuf1); IMB_freeImBuf(ibuf2); @@ -1952,10 +1938,10 @@ static ImBuf *seq_render_strip_stack(const SeqRenderData *context, } i++; - for (; i < count; i++) { - Sequence *seq = seq_arr[i]; + for (; i < strips.size(); i++) { + Sequence *seq = strips[i]; - if (seq_get_early_out_for_blend_mode(seq) == EARLY_DO_EFFECT) { + if (seq_get_early_out_for_blend_mode(seq) == StripEarlyOut::DoEffect) { ImBuf *ibuf1 = out; ImBuf *ibuf2 = seq_render_strip(context, state, seq, timeline_frame); @@ -1965,7 +1951,7 @@ static ImBuf *seq_render_strip_stack(const SeqRenderData *context, IMB_freeImBuf(ibuf2); } - seq_cache_put(context, seq_arr[i], timeline_frame, SEQ_CACHE_STORE_COMPOSITE, out); + seq_cache_put(context, strips[i], timeline_frame, SEQ_CACHE_STORE_COMPOSITE, out); } return out; @@ -1994,31 +1980,29 @@ ImBuf *SEQ_render_give_ibuf(const SeqRenderData *context, float timeline_frame, } SeqRenderState state; - seq_render_state_init(&state); ImBuf *out = nullptr; - Sequence *seq_arr[MAXSEQ + 1]; - int count; - count = seq_get_shown_sequences(scene, channels, seqbasep, timeline_frame, chanshown, seq_arr); + Vector strips = seq_get_shown_sequences( + scene, channels, seqbasep, timeline_frame, chanshown); - if (count) { - out = seq_cache_get(context, seq_arr[count - 1], timeline_frame, SEQ_CACHE_STORE_FINAL_OUT); + if (!strips.is_empty()) { + out = seq_cache_get(context, strips.last(), timeline_frame, SEQ_CACHE_STORE_FINAL_OUT); } seq_cache_free_temp_cache(context->scene, context->task_id, timeline_frame); /* Make sure we only keep the `anim` data for strips that are in view. */ SEQ_relations_free_all_anim_ibufs(context->scene, timeline_frame); - if (count && !out) { + if (!strips.is_empty() && !out) { BLI_mutex_lock(&seq_render_mutex); out = seq_render_strip_stack(context, &state, channels, seqbasep, timeline_frame, chanshown); if (context->is_prefetch_render) { - seq_cache_put(context, seq_arr[count - 1], timeline_frame, SEQ_CACHE_STORE_FINAL_OUT, out); + seq_cache_put(context, strips.last(), timeline_frame, SEQ_CACHE_STORE_FINAL_OUT, out); } else { seq_cache_put_if_possible( - context, seq_arr[count - 1], timeline_frame, SEQ_CACHE_STORE_FINAL_OUT, out); + context, strips.last(), timeline_frame, SEQ_CACHE_STORE_FINAL_OUT, out); } BLI_mutex_unlock(&seq_render_mutex); } @@ -2035,7 +2019,6 @@ ImBuf *seq_render_give_ibuf_seqbase(const SeqRenderData *context, ListBase *seqbasep) { SeqRenderState state; - seq_render_state_init(&state); return seq_render_strip_stack(context, &state, channels, seqbasep, timeline_frame, chan_shown); } @@ -2045,7 +2028,6 @@ ImBuf *SEQ_render_give_ibuf_direct(const SeqRenderData *context, Sequence *seq) { SeqRenderState state; - seq_render_state_init(&state); ImBuf *ibuf = seq_render_strip(context, &state, seq, timeline_frame); return ibuf; @@ -2150,7 +2132,6 @@ void SEQ_render_thumbnails(const SeqRenderData *context, const bool *stop) { SeqRenderState state; - seq_render_state_init(&state); const Scene *scene = context->scene; /* Adding the hold offset value (seq->anim_startofs) to the start frame. Position of image not @@ -2211,7 +2192,6 @@ void SEQ_render_thumbnails_base_set(const SeqRenderData *context, const bool *stop) { SeqRenderState state; - seq_render_state_init(&state); const Scene *scene = context->scene; int timeline_frame = SEQ_time_left_handle_frame_get(scene, seq); diff --git a/source/blender/sequencer/intern/render.hh b/source/blender/sequencer/intern/render.hh index a1bd097acde..b313be9b2ba 100644 --- a/source/blender/sequencer/intern/render.hh +++ b/source/blender/sequencer/intern/render.hh @@ -8,6 +8,8 @@ * \ingroup sequencer */ +#include "BLI_vector.hh" + struct ImBuf; struct LinkNode; struct ListBase; @@ -16,18 +18,11 @@ struct SeqEffectHandle; struct SeqRenderData; struct Sequence; -#define EARLY_NO_INPUT -1 -#define EARLY_DO_EFFECT 0 -#define EARLY_USE_INPUT_1 1 -#define EARLY_USE_INPUT_2 2 - /* mutable state for sequencer */ struct SeqRenderState { - LinkNode *scene_parents; + LinkNode *scene_parents = nullptr; }; -void seq_render_state_init(SeqRenderState *state); - ImBuf *seq_render_give_ibuf_seqbase(const SeqRenderData *context, float timeline_frame, int chan_shown, @@ -41,13 +36,9 @@ ImBuf *seq_render_effect_execute_threaded(SeqEffectHandle *sh, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *ibuf3); -void seq_imbuf_to_sequencer_space(Scene *scene, ImBuf *ibuf, bool make_float); -int seq_get_shown_sequences(const Scene *scene, - ListBase *channels, - ListBase *seqbase, - int timeline_frame, - int chanshown, - Sequence **r_seq_arr); +void seq_imbuf_to_sequencer_space(const Scene *scene, ImBuf *ibuf, bool make_float); +blender::Vector seq_get_shown_sequences( + const Scene *scene, ListBase *channels, ListBase *seqbase, int timeline_frame, int chanshown); ImBuf *seq_render_strip(const SeqRenderData *context, SeqRenderState *state, Sequence *seq, @@ -56,4 +47,4 @@ ImBuf *seq_render_mask(const SeqRenderData *context, Mask *mask, float frame_index, bool make_float); -void seq_imbuf_assign_spaces(Scene *scene, ImBuf *ibuf); +void seq_imbuf_assign_spaces(const Scene *scene, ImBuf *ibuf);