[Bf-blender-cvs] [3c6f38048bb] temp-vse-thumbnail-mod: Finish reusable frame implementation

Richard Antalik noreply at git.blender.org
Thu Sep 16 00:37:39 CEST 2021


Commit: 3c6f38048bb24029a9a363ce2ff8933257feff4a
Author: Richard Antalik
Date:   Thu Sep 16 00:27:02 2021 +0200
Branches: temp-vse-thumbnail-mod
https://developer.blender.org/rB3c6f38048bb24029a9a363ce2ff8933257feff4a

Finish reusable frame implementation

===================================================================

M	source/blender/blenloader/intern/versioning_300.c
M	source/blender/editors/space_sequencer/sequencer_draw.c
M	source/blender/editors/space_sequencer/sequencer_intern.h
M	source/blender/editors/space_sequencer/space_sequencer.c
M	source/blender/sequencer/SEQ_render.h
M	source/blender/sequencer/intern/image_cache.c
M	source/blender/sequencer/intern/render.c

===================================================================

diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index bb7f12612ac..5461d2eb221 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -1084,19 +1084,6 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
     }
   }
 
-  if (!MAIN_VERSION_ATLEAST(bmain, 300, 20)) {
-    LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
-      LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
-        LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
-          if (sl->spacetype == SPACE_SEQ) {
-            SpaceSeq *sseq = (SpaceSeq *)sl;
-            sseq->flag |= SEQ_SHOW_THUMBNAILS;
-          }
-        }
-      }
-    }
-  }
-
   if (!MAIN_VERSION_ATLEAST(bmain, 300, 21)) {
     LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
       LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
@@ -1104,6 +1091,14 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
           if (sl->spacetype == SPACE_SEQ) {
             SpaceSeq *sseq = (SpaceSeq *)sl;
             sseq->flag |= SEQ_SHOW_THUMBNAILS;
+
+            ListBase *regionbase = (sl == area->spacedata.first) ? &area->regionbase :
+                                                                   &sl->regionbase;
+            LISTBASE_FOREACH (ARegion *, region, regionbase) {
+              if (region->regiontype == RGN_TYPE_WINDOW) {
+                region->v2d.min[1] = 2.0f;
+              }
+            }
           }
         }
       }
diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c
index cb7c6ce9d03..b1560714d62 100644
--- a/source/blender/editors/space_sequencer/sequencer_draw.c
+++ b/source/blender/editors/space_sequencer/sequencer_draw.c
@@ -1545,7 +1545,12 @@ static bool sequencer_thumbnail_v2d_is_navigating(const bContext *C)
   return x_diff > 0.01 || y_diff > 0.01;
 }
 
-static GSet *displayed_thumbnails_cache_ensure(const bContext *C, Sequence *seq)
+void last_displayed_thumbnails_list_free(void *val)
+{
+  BLI_gset_free(val, NULL);
+}
+
+static GSet *last_displayed_thumbnails_list_ensure(const bContext *C, Sequence *seq)
 {
   SpaceSeq *sseq = CTX_wm_space_seq(C);
   if (sseq->runtime.last_displayed_thumbnails == NULL) {
@@ -1565,14 +1570,14 @@ static GSet *displayed_thumbnails_cache_ensure(const bContext *C, Sequence *seq)
   return displayed_thumbnails;
 }
 
-static int sequencer_thumbnail_closest_guaranteed_image(Sequence *seq,
-                                                        int timeline_frame,
-                                                        GSet *previously_displayed)
+static int sequencer_thumbnail_closest_guaranteed_frame_get(Sequence *seq,
+                                                            int timeline_frame,
+                                                            GSet *previously_displayed)
 {
   int best_diff = INT_MAX;
   int best_frame = timeline_frame;
 
-  /* Previously displayed frames. */
+  /* Previously displayed thumbnails. */
   GSetIterator gset_iter;
   BLI_gsetIterator_init(&gset_iter, previously_displayed);
   while (!BLI_gsetIterator_done(&gset_iter)) {
@@ -1585,14 +1590,13 @@ static int sequencer_thumbnail_closest_guaranteed_image(Sequence *seq,
     BLI_gsetIterator_step(&gset_iter);
   }
 
-  /* Guaranteed base set. */
-  const int relative_frame = timeline_frame - seq->startdisp;
-  const int frame_step = SEQ_render_thumbnails_base_set_get_frame_step(seq);
-  const int relative_base_frame = round_fl_to_int((relative_frame / (float)frame_step)) *
-                                  frame_step;
-  const int base_frame = relative_base_frame + seq->startdisp;
-  if (abs(base_frame - timeline_frame) < best_diff) {
-    return base_frame;
+  /* Set of "guaranteed" thumbnails. */
+  const int frame_index = timeline_frame - seq->startdisp;
+  const int frame_step = SEQ_render_thumbnails_guaranteed_set_frame_step_get(seq);
+  const int relative_base_frame = round_fl_to_int((frame_index / (float)frame_step)) * frame_step;
+  const int nearest_guaranted_absolute_frame = relative_base_frame + seq->startdisp;
+  if (abs(nearest_guaranted_absolute_frame - timeline_frame) < best_diff) {
+    return nearest_guaranted_absolute_frame;
   }
 
   return best_frame;
@@ -1628,7 +1632,7 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
     upper_thumb_bound = seq->enddisp;
   }
 
-  GSet *displayed_thumbnails = displayed_thumbnails_cache_ensure(C, seq);
+  GSet *last_displayed_thumbnails = last_displayed_thumbnails_list_ensure(C, seq);
 
   thumb_x_start = seq_thumbnail_get_start_frame(seq, thumb_width, &v2d->cur);
   float thumb_x_end;
@@ -1683,8 +1687,8 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
 
     /* Store displayed thumbnails so they can be reused for zooming. */
     if (sequencer_thumbnail_v2d_is_navigating(C)) {
-      timeline_frame = sequencer_thumbnail_closest_guaranteed_image(
-          seq, timeline_frame, displayed_thumbnails);
+      timeline_frame = sequencer_thumbnail_closest_guaranteed_frame_get(
+          seq, timeline_frame, last_displayed_thumbnails);
     }
 
     /* Get the image. */
@@ -1694,21 +1698,20 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
       sequencer_thumbnail_start_job_if_necessary(C, scene->ed, v2d, true);
 
       /* Render one of guaranteed frames, if image is not found. */
-      timeline_frame = sequencer_thumbnail_closest_guaranteed_image(
-          seq, timeline_frame, displayed_thumbnails);
+      timeline_frame = sequencer_thumbnail_closest_guaranteed_frame_get(
+          seq, timeline_frame, last_displayed_thumbnails);
       ibuf = SEQ_get_thumbnail(&context, seq, timeline_frame, &crop, clipped);
     }
+    /* Store recently rendered frames, so they can be reused when zooming. */
+    else if (!sequencer_thumbnail_v2d_is_navigating(C)) {
+      BLI_gset_add(last_displayed_thumbnails, POINTER_FROM_INT(timeline_frame));
+    }
 
     /* If there is no image still, abort. */
     if (!ibuf) {
       break;
     }
 
-    /* Override timeline frame when zooming. */
-    if (!sequencer_thumbnail_v2d_is_navigating(C)) {
-      BLI_gset_add(displayed_thumbnails, POINTER_FROM_INT(timeline_frame));
-    }
-
     /* Transparency on overlap. */
     if (seq->flag & SEQ_OVERLAP) {
       GPU_blend(GPU_BLEND_ALPHA);
diff --git a/source/blender/editors/space_sequencer/sequencer_intern.h b/source/blender/editors/space_sequencer/sequencer_intern.h
index 767ac76efe6..5b5c381509f 100644
--- a/source/blender/editors/space_sequencer/sequencer_intern.h
+++ b/source/blender/editors/space_sequencer/sequencer_intern.h
@@ -67,6 +67,7 @@ struct ImBuf *sequencer_ibuf_get(struct Main *bmain,
                                  int timeline_frame,
                                  int frame_ofs,
                                  const char *viewname);
+void last_displayed_thumbnails_list_free(void *val);
 
 /* sequencer_edit.c */
 struct View2D;
diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c
index 0e68f748829..7f30dd11188 100644
--- a/source/blender/editors/space_sequencer/space_sequencer.c
+++ b/source/blender/editors/space_sequencer/space_sequencer.c
@@ -176,7 +176,7 @@ static SpaceLink *sequencer_create(const ScrArea *UNUSED(area), const Scene *sce
   region->v2d.cur = region->v2d.tot;
 
   region->v2d.min[0] = 10.0f;
-  region->v2d.min[1] = 0.5f;
+  region->v2d.min[1] = 2.0f;
 
   region->v2d.max[0] = MAXFRAMEF;
   region->v2d.max[1] = MAXSEQ;
@@ -222,7 +222,8 @@ static void sequencer_free(SpaceLink *sl)
   }
 
   if (sseq->runtime.last_displayed_thumbnails) {
-    BLI_ghash_free(sseq->runtime.last_displayed_thumbnails, NULL, NULL);
+    BLI_ghash_free(
+        sseq->runtime.last_displayed_thumbnails, NULL, last_displayed_thumbnails_list_free);
     sseq->runtime.last_displayed_thumbnails = NULL;
   }
 }
diff --git a/source/blender/sequencer/SEQ_render.h b/source/blender/sequencer/SEQ_render.h
index b60abd91dd9..50280db55ff 100644
--- a/source/blender/sequencer/SEQ_render.h
+++ b/source/blender/sequencer/SEQ_render.h
@@ -76,10 +76,13 @@ void SEQ_render_thumbnails(const struct SeqRenderData *context,
                            float frame_step,
                            rctf *view_area,
                            short *stop);
-struct ImBuf *SEQ_get_thumbnail(
-    const struct SeqRenderData *context, struct Sequence *seq, float timeline_frame, rcti *crop, bool clipped);
-int SEQ_render_thumbnails_base_set_get_frame_step(const struct Sequence *seq);
-void SEQ_render_thumbnails_base_set(const struct  SeqRenderData *context,
+struct ImBuf *SEQ_get_thumbnail(const struct SeqRenderData *context,
+                                struct Sequence *seq,
+                                float timeline_frame,
+                                rcti *crop,
+                                bool clipped);
+int SEQ_render_thumbnails_guaranteed_set_frame_step_get(const struct Sequence *seq);
+void SEQ_render_thumbnails_base_set(const struct SeqRenderData *context,
                                     struct Sequence *seq,
                                     struct Sequence *seq_orig,
                                     rctf *view_area,
diff --git a/source/blender/sequencer/intern/image_cache.c b/source/blender/sequencer/intern/image_cache.c
index c641947c05a..32da1ade617 100644
--- a/source/blender/sequencer/intern/image_cache.c
+++ b/source/blender/sequencer/intern/image_cache.c
@@ -104,7 +104,7 @@
 #define DCACHE_IMAGES_PER_FILE 100
 #define DCACHE_CURRENT_VERSION 2
 #define COLORSPACE_NAME_MAX 64 /* XXX: defined in imb intern */
-#define THUMB_CACHE_LIMIT 5000
+#define THUMB_CACHE_LIMIT 100
 
 typedef struct DiskCacheHeaderEntry {
   unsigned char encoding;
@@ -1368,15 +1368,22 @@ void seq_cache_thumbnail_cleanup(Scene *scene, rctf *view_area_safe)
     SeqCacheKey *key = BLI_ghashIterator_getKey(&gh_iter);
     BLI_ghashIterator_step(&gh_iter);
 
+    const int frame_index = key->timeline_frame - key->seq->startdisp;
+    const int frame_step = 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list