[Bf-blender-cvs] [8113b8391ae] master: Cleanup: VSE: Move thumbnail drawing to own file
Richard Antalik
noreply at git.blender.org
Wed Oct 6 04:22:22 CEST 2021
Commit: 8113b8391ae0f4d1f1612fb446f2268d093b5240
Author: Richard Antalik
Date: Wed Oct 6 04:16:50 2021 +0200
Branches: master
https://developer.blender.org/rB8113b8391ae0f4d1f1612fb446f2268d093b5240
Cleanup: VSE: Move thumbnail drawing to own file
No functional changes.
===================================================================
M source/blender/editors/space_sequencer/CMakeLists.txt
M source/blender/editors/space_sequencer/sequencer_draw.c
M source/blender/editors/space_sequencer/sequencer_intern.h
A source/blender/editors/space_sequencer/sequencer_thumbnails.c
===================================================================
diff --git a/source/blender/editors/space_sequencer/CMakeLists.txt b/source/blender/editors/space_sequencer/CMakeLists.txt
index e1c193b0c15..1471929defb 100644
--- a/source/blender/editors/space_sequencer/CMakeLists.txt
+++ b/source/blender/editors/space_sequencer/CMakeLists.txt
@@ -45,6 +45,7 @@ set(SRC
sequencer_proxy.c
sequencer_scopes.c
sequencer_select.c
+ sequencer_thumbnails.c
sequencer_view.c
space_sequencer.c
diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c
index d5cd5d11a35..bbe2def8081 100644
--- a/source/blender/editors/space_sequencer/sequencer_draw.c
+++ b/source/blender/editors/space_sequencer/sequencer_draw.c
@@ -25,7 +25,6 @@
#include <string.h>
#include "BLI_blenlib.h"
-#include "BLI_ghash.h"
#include "BLI_math.h"
#include "BLI_string_utils.h"
#include "BLI_threads.h"
@@ -45,7 +44,6 @@
#include "BKE_context.h"
#include "BKE_fcurve.h"
#include "BKE_global.h"
-#include "BKE_main.h"
#include "BKE_scene.h"
#include "BKE_sound.h"
@@ -103,7 +101,6 @@
#define SEQ_HANDLE_SIZE 8.0f
#define SEQ_SCROLLER_TEXT_OFFSET 8
#define MUTE_ALPHA 120
-#define OVERLAP_ALPHA 180
static Sequence *special_seq_update = NULL;
@@ -349,8 +346,8 @@ static void draw_seq_waveform_overlay(View2D *v2d,
float y2,
float frames_per_pixel)
{
- if (seq->sound &&
- ((sseq->timeline_overlay.flag & SEQ_TIMELINE_ALL_WAVEFORMS) || (seq->flag & SEQ_AUDIO_DRAW_WAVEFORM))) {
+ if (seq->sound && ((sseq->timeline_overlay.flag & SEQ_TIMELINE_ALL_WAVEFORMS) ||
+ (seq->flag & SEQ_AUDIO_DRAW_WAVEFORM))) {
/* Make sure that the start drawing position is aligned to the pixels on the screen to avoid
* flickering when moving around the strip.
* To do this we figure out the fractional offset in pixel space by checking where the
@@ -1312,526 +1309,6 @@ static void draw_seq_fcurve_overlay(
}
}
-typedef struct ThumbnailDrawJob {
- SeqRenderData context;
- GHash *sequences_ghash;
- Scene *scene;
- rctf *view_area;
- float pixelx;
- float pixely;
-} ThumbnailDrawJob;
-
-typedef struct ThumbDataItem {
- Sequence *seq_dupli;
- Scene *scene;
-} ThumbDataItem;
-
-static void thumbnail_hash_data_free(void *val)
-{
- ThumbDataItem *item = val;
- SEQ_sequence_free(item->scene, item->seq_dupli, 0);
- MEM_freeN(val);
-}
-
-static void thumbnail_freejob(void *data)
-{
- ThumbnailDrawJob *tj = data;
- BLI_ghash_free(tj->sequences_ghash, NULL, thumbnail_hash_data_free);
- MEM_freeN(tj->view_area);
- MEM_freeN(tj);
-}
-
-static void thumbnail_endjob(void *data)
-{
- ThumbnailDrawJob *tj = data;
- WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, tj->scene);
-}
-
-static bool check_seq_need_thumbnails(Sequence *seq, rctf *view_area)
-{
- if (seq->type != SEQ_TYPE_MOVIE && seq->type != SEQ_TYPE_IMAGE) {
- return false;
- }
- if (min_ii(seq->startdisp, seq->start) > view_area->xmax) {
- return false;
- }
- if (max_ii(seq->enddisp, seq->start + seq->len) < view_area->xmin) {
- return false;
- }
- if (seq->machine + 1.0f < view_area->ymin) {
- return false;
- }
- if (seq->machine > view_area->ymax) {
- return false;
- }
-
- return true;
-}
-
-static void seq_get_thumb_image_dimensions(Sequence *seq,
- float pixelx,
- float pixely,
- float *r_thumb_width,
- float *r_thumb_height,
- float *r_image_width,
- float *r_image_height)
-{
- float image_width = seq->strip->stripdata->orig_width;
- float image_height = seq->strip->stripdata->orig_height;
-
- /* Fix the dimensions to be max SEQ_RENDER_THUMB_SIZE (256) for x or y. */
- float aspect_ratio = (float)image_width / image_height;
- if (image_width > image_height) {
- image_width = SEQ_RENDER_THUMB_SIZE;
- image_height = round_fl_to_int(image_width / aspect_ratio);
- }
- else {
- image_height = SEQ_RENDER_THUMB_SIZE;
- image_width = round_fl_to_int(image_height * aspect_ratio);
- }
-
- /* Calculate thumb dimensions. */
- float thumb_height = (SEQ_STRIP_OFSTOP - SEQ_STRIP_OFSBOTTOM) - (20 * U.dpi_fac * pixely);
- aspect_ratio = ((float)image_width) / image_height;
- float thumb_h_px = thumb_height / pixely;
- float thumb_width = aspect_ratio * thumb_h_px * pixelx;
-
- if (r_thumb_height == NULL) {
- *r_thumb_width = thumb_width;
- return;
- }
-
- *r_thumb_height = thumb_height;
- *r_image_width = image_width;
- *r_image_height = image_height;
- *r_thumb_width = thumb_width;
-}
-
-static float seq_thumbnail_get_start_frame(Sequence *seq, float frame_step, rctf *view_area)
-{
- if (seq->start > view_area->xmin && seq->start < view_area->xmax) {
- return seq->start;
- }
-
- /* Drawing and caching both check to see if strip is in view area or not before calling this
- * function so assuming strip/part of strip in view. */
-
- int no_invisible_thumbs = (view_area->xmin - seq->start) / frame_step;
- return ((no_invisible_thumbs - 1) * frame_step) + seq->start;
-}
-
-static void thumbnail_start_job(void *data,
- short *stop,
- short *UNUSED(do_update),
- float *UNUSED(progress))
-{
- ThumbnailDrawJob *tj = data;
- float start_frame, frame_step;
-
- GHashIterator gh_iter;
- BLI_ghashIterator_init(&gh_iter, tj->sequences_ghash);
- while (!BLI_ghashIterator_done(&gh_iter) & !*stop) {
- Sequence *seq_orig = BLI_ghashIterator_getKey(&gh_iter);
- ThumbDataItem *val = BLI_ghash_lookup(tj->sequences_ghash, seq_orig);
-
- if (check_seq_need_thumbnails(seq_orig, tj->view_area)) {
- seq_get_thumb_image_dimensions(
- val->seq_dupli, tj->pixelx, tj->pixely, &frame_step, NULL, NULL, NULL);
- start_frame = seq_thumbnail_get_start_frame(seq_orig, frame_step, tj->view_area);
- SEQ_render_thumbnails(
- &tj->context, val->seq_dupli, seq_orig, start_frame, frame_step, tj->view_area, stop);
- SEQ_render_thumbnails_base_set(&tj->context, val->seq_dupli, seq_orig, tj->view_area, stop);
- }
- BLI_ghashIterator_step(&gh_iter);
- }
-}
-
-static SeqRenderData sequencer_thumbnail_context_init(const bContext *C)
-{
- struct Main *bmain = CTX_data_main(C);
- struct Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
- Scene *scene = CTX_data_scene(C);
- SpaceSeq *sseq = CTX_wm_space_seq(C);
- SeqRenderData context = {0};
-
- /* Taking rectx and recty as 0 as dimensions not known here, and context is used to calculate
- * hash key but not necessary as other variables of SeqRenderData are unique enough. */
- SEQ_render_new_render_data(bmain, depsgraph, scene, 0, 0, sseq->render_size, false, &context);
- context.view_id = BKE_scene_multiview_view_id_get(&scene->r, STEREO_LEFT_NAME);
- context.use_proxies = false;
-
- return context;
-}
-
-static GHash *sequencer_thumbnail_ghash_init(const bContext *C, View2D *v2d, Editing *ed)
-{
- Scene *scene = CTX_data_scene(C);
-
- /* Set the data for thumbnail caching job. */
- GHash *thumb_data_hash = BLI_ghash_ptr_new("seq_duplicates_and_origs");
-
- LISTBASE_FOREACH (Sequence *, seq, ed->seqbasep) {
- ThumbDataItem *val_need_update = BLI_ghash_lookup(thumb_data_hash, seq);
- if (val_need_update == NULL && check_seq_need_thumbnails(seq, &v2d->cur)) {
- ThumbDataItem *val = MEM_callocN(sizeof(ThumbDataItem), "Thumbnail Hash Values");
- val->seq_dupli = SEQ_sequence_dupli_recursive(scene, scene, NULL, seq, 0);
- val->scene = scene;
- BLI_ghash_insert(thumb_data_hash, seq, val);
- }
- else {
- if (val_need_update != NULL) {
- val_need_update->seq_dupli->start = seq->start;
- val_need_update->seq_dupli->startdisp = seq->startdisp;
- }
- }
- }
-
- return thumb_data_hash;
-}
-
-static void sequencer_thumbnail_init_job(const bContext *C, View2D *v2d, Editing *ed)
-{
- wmJob *wm_job;
- ThumbnailDrawJob *tj = NULL;
- ScrArea *area = CTX_wm_area(C);
- wm_job = WM_jobs_get(CTX_wm_manager(C),
- CTX_wm_window(C),
- CTX_data_scene(C),
- "Draw Thumbnails",
- 0,
- WM_JOB_TYPE_SEQ_DRAW_THUMBNAIL);
-
- /* Get the thumbnail job if it exists. */
- tj = WM_jobs_customdata_get(wm_job);
- if (!tj) {
- tj = MEM_callocN(sizeof(ThumbnailDrawJob), "Thumbnail cache job");
-
- /* Duplicate value of v2d->cur and v2d->tot to have module separation. */
- rctf *view_area = MEM_callocN(sizeof(struct rctf), "viewport area");
- view_area->xmax = v2d->cur.xmax;
- view_area->xmin = v2d->cur.xmin;
- view_area->ymax = v2d->cur.ymax;
- view_area->ymin = v2d->cur.ymin;
-
- tj->scene = CTX_data_scene(C);
- tj->view_area = view_area;
- tj->context = sequencer_thumbnail_context_init(C);
- tj->sequences_ghash = sequencer_thumbnail_ghash_init(C, v2d, ed);
- tj->pixelx = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask);
- tj->pixely = BLI_rctf_size_y(&v2d->cur) / BLI_rcti_size_y(&v2d->mask);
- WM_jobs_customdata_set(wm_job, tj, thumbnail_freejob);
- WM_jobs_timer(wm_job, 0.1, NC_SCENE | ND_SEQUENCER, NC_SCENE | ND_SEQUENCER);
- WM_jobs_callbacks(wm_job, thumbnail_start_job, NULL, NULL, thumbnail_endjob);
- }
-
- if (!WM_jobs_is_running(wm_job)) {
- G.is_break = false;
- WM_jobs_start(CTX_wm_manager(C), wm_job);
- }
- else {
- WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, NULL);
- }
-
- ED_area_tag_redraw(area);
-}
-
-static bool sequencer_thumbnail_v2d_is_navigating(const bContext *C)
-{
- ARegion *region = CTX_wm_region(C);
- View2D *v2d = ®ion->v2d;
- return (v2d->flag & V2D_IS_NAVIGATING) != 0;
-}
-
-static void sequencer_thumbnail_start_job_if_necessary(const bContext *C,
- Editing *ed,
- View2D *v2d,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list