Sequencer: cache currently displaying scopes
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 5 Sep 2012 11:43:05 +0000 (11:43 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 5 Sep 2012 11:43:05 +0000 (11:43 +0000)
This avoids calculation of scopes on every redraw, so such tools as panning
and zoom wouldn't imply re-calculating scopes.

Implemented as a structure inside of SpaceSeq, juts like it's done for clip
and image spaces.

Also fixed zebra display to work in display space.

source/blender/blenloader/intern/readfile.c
source/blender/editors/space_sequencer/sequencer_draw.c
source/blender/editors/space_sequencer/space_sequencer.c
source/blender/makesdna/DNA_movieclip_types.h
source/blender/makesdna/DNA_sequence_types.h
source/blender/makesdna/DNA_space_types.h
source/blender/makesrna/intern/rna_color.c

index 04c9d96..33693cf 100644 (file)
@@ -5294,6 +5294,13 @@ static void lib_link_screen(FileData *fd, Main *main)
                                                 * so fingers crossed this works fine!
                                                 */
                                                sseq->gpd = newlibadr_us(fd, sc->id.lib, sseq->gpd);
+
+                                               sseq->scopes.reference_ibuf = NULL;
+                                               sseq->scopes.zebra_ibuf = NULL;
+                                               sseq->scopes.waveform_ibuf = NULL;
+                                               sseq->scopes.sep_waveform_ibuf = NULL;
+                                               sseq->scopes.vector_ibuf = NULL;
+                                               sseq->scopes.histogram_ibuf = NULL;
                                        }
                                        else if (sl->spacetype == SPACE_NLA) {
                                                SpaceNla *snla= (SpaceNla *)sl;
index 42843b6..d1e2066 100644 (file)
@@ -850,6 +850,50 @@ ImBuf *sequencer_ibuf_get(struct Main *bmain, Scene *scene, SpaceSeq *sseq, int
        return ibuf;
 }
 
+static void sequencer_check_scopes(SequencerScopes *scopes, ImBuf *ibuf)
+{
+       if (scopes->reference_ibuf != ibuf) {
+               if (scopes->zebra_ibuf) {
+                       IMB_freeImBuf(scopes->zebra_ibuf);
+                       scopes->zebra_ibuf = NULL;
+               }
+
+               if (scopes->waveform_ibuf) {
+                       IMB_freeImBuf(scopes->waveform_ibuf);
+                       scopes->waveform_ibuf = NULL;
+               }
+
+               if (scopes->sep_waveform_ibuf) {
+                       IMB_freeImBuf(scopes->sep_waveform_ibuf);
+                       scopes->sep_waveform_ibuf = NULL;
+               }
+
+               if (scopes->vector_ibuf) {
+                       IMB_freeImBuf(scopes->vector_ibuf);
+                       scopes->vector_ibuf = NULL;
+               }
+
+               if (scopes->histogram_ibuf) {
+                       IMB_freeImBuf(scopes->histogram_ibuf);
+                       scopes->histogram_ibuf = NULL;
+               }
+       }
+}
+
+static ImBuf *sequencer_make_scope(Scene *scene, ImBuf *ibuf, ImBuf *(*make_scope_cb) (ImBuf *ibuf))
+{
+       ImBuf *display_ibuf = IMB_dupImBuf(ibuf);
+       ImBuf *scope;
+
+       IMB_colormanagement_imbuf_make_display_space(display_ibuf, &scene->view_settings, &scene->display_settings);
+
+       scope = make_scope_cb(display_ibuf);
+
+       IMB_freeImBuf(display_ibuf);
+
+       return scope;
+}
+
 void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq, int cfra, int frame_ofs, int draw_overlay)
 {
        struct Main *bmain = CTX_data_main(C);
@@ -913,34 +957,47 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
        if (ibuf->rect == NULL && ibuf->rect_float == NULL)
                return;
 
-       if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
-               if (sseq->zebra != 0) {
-                       scope = make_zebra_view_from_ibuf(ibuf, sseq->zebra);
-               }
-       }
-       else {
-               ImBuf *display_ibuf = IMB_dupImBuf(ibuf);
+       if (sseq->mainb != SEQ_DRAW_IMG_IMBUF || sseq->zebra != 0) {
+               SequencerScopes *scopes = &sseq->scopes;
 
-               IMB_colormanagement_imbuf_make_display_space(display_ibuf, &scene->view_settings, &scene->display_settings);
+               sequencer_check_scopes(scopes, ibuf);
 
                switch (sseq->mainb) {
+                       case SEQ_DRAW_IMG_IMBUF:
+                               if (!scopes->zebra_ibuf) {
+                                       ImBuf *display_ibuf = IMB_dupImBuf(ibuf);
+
+                                       IMB_colormanagement_imbuf_make_display_space(display_ibuf, &scene->view_settings, &scene->display_settings);
+                                       scopes->zebra_ibuf = make_zebra_view_from_ibuf(display_ibuf, sseq->zebra);
+                                       IMB_freeImBuf(display_ibuf);
+                               }
+                               scope = scopes->zebra_ibuf;
+                               break;
                        case SEQ_DRAW_IMG_WAVEFORM:
                                if ((sseq->flag & SEQ_DRAW_COLOR_SEPARATED) != 0) {
-                                       scope = make_sep_waveform_view_from_ibuf(display_ibuf);
+                                       if (!scopes->sep_waveform_ibuf)
+                                               scopes->sep_waveform_ibuf = sequencer_make_scope(scene, ibuf, make_sep_waveform_view_from_ibuf);
+                                       scope = scopes->sep_waveform_ibuf;
                                }
                                else {
-                                       scope = make_waveform_view_from_ibuf(display_ibuf);
+                                       if (!scopes->waveform_ibuf)
+                                               scopes->waveform_ibuf = sequencer_make_scope(scene, ibuf, make_waveform_view_from_ibuf);
+                                       scope = scopes->waveform_ibuf;
                                }
                                break;
                        case SEQ_DRAW_IMG_VECTORSCOPE:
-                               scope = make_vectorscope_view_from_ibuf(display_ibuf);
+                               if (!scopes->vector_ibuf)
+                                       scopes->vector_ibuf = sequencer_make_scope(scene, ibuf, make_vectorscope_view_from_ibuf);
+                               scope = scopes->vector_ibuf;
                                break;
                        case SEQ_DRAW_IMG_HISTOGRAM:
-                               scope = make_histogram_view_from_ibuf(display_ibuf);
+                               if (!scopes->histogram_ibuf)
+                                       scopes->histogram_ibuf = sequencer_make_scope(scene, ibuf, make_histogram_view_from_ibuf);
+                               scope = scopes->histogram_ibuf;
                                break;
                }
 
-               IMB_freeImBuf(display_ibuf);
+               scopes->reference_ibuf = ibuf;
        }
 
        if (scope) {
@@ -1049,7 +1106,8 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
        /* draw grease-pencil (image aligned) */
        draw_gpencil_2dimage(C);
 
-       IMB_freeImBuf(ibuf);
+       if (!scope)
+               IMB_freeImBuf(ibuf);
        
        /* ortho at pixel level */
        UI_view2d_view_restore(C);
index f7362aa..8ac50a5 100644 (file)
 #include "UI_resources.h"
 #include "UI_view2d.h"
 
+#include "IMB_imbuf.h"
+
 #include "sequencer_intern.h"   // own include
 
+/**************************** common state *****************************/
+
+static void sequencer_scopes_tag_refresh(ScrArea *sa)
+{
+       SpaceSeq *sseq = (SpaceSeq *)sa->spacedata.first;
+
+       sseq->scopes.reference_ibuf = NULL;
+}
+
 /* ******************** manage regions ********************* */
 
 ARegion *sequencer_has_buttons_region(ScrArea *sa)
@@ -183,12 +194,27 @@ static SpaceLink *sequencer_new(const bContext *C)
 }
 
 /* not spacelink itself */
-static void sequencer_free(SpaceLink *UNUSED(sl))
+static void sequencer_free(SpaceLink *sl)
 {      
-//     SpaceSeq *sseq= (SpaceSequencer*) sl;
-       
+       SpaceSeq *sseq= (SpaceSeq *) sl;
+       SequencerScopes *scopes = &sseq->scopes;
+
 // XXX if (sseq->gpd) BKE_gpencil_free(sseq->gpd);
 
+       if (scopes->zebra_ibuf)
+               IMB_freeImBuf(scopes->zebra_ibuf);
+
+       if (scopes->waveform_ibuf)
+               IMB_freeImBuf(scopes->waveform_ibuf);
+
+       if (scopes->sep_waveform_ibuf)
+               IMB_freeImBuf(scopes->sep_waveform_ibuf);
+
+       if (scopes->vector_ibuf)
+               IMB_freeImBuf(scopes->vector_ibuf);
+
+       if (scopes->histogram_ibuf)
+               IMB_freeImBuf(scopes->histogram_ibuf);
 }
 
 
@@ -290,7 +316,24 @@ static SpaceLink *sequencer_duplicate(SpaceLink *sl)
        return (SpaceLink *)sseqn;
 }
 
-
+static void sequencer_listener(ScrArea *sa, wmNotifier *wmn)
+{
+       /* context changes */
+       switch (wmn->category) {
+               case NC_SCENE:
+                       switch (wmn->data) {
+                               case ND_FRAME:
+                               case ND_SEQUENCER:
+                                       sequencer_scopes_tag_refresh(sa);
+                                       break;
+                       }
+                       break;
+               case NC_SPACE:
+                       if (wmn->data == ND_SPACE_SEQUENCER)
+                               sequencer_scopes_tag_refresh(sa);
+                       break;
+       }
+}
 
 /* *********************** sequencer (main) region ************************ */
 /* add handlers, stuff you only do once or on area/region changes */
@@ -610,6 +653,7 @@ void ED_spacetype_sequencer(void)
        st->context = sequencer_context;
        st->dropboxes = sequencer_dropboxes;
        st->refresh = sequencer_refresh;
+       st->listener = sequencer_listener;
 
        /* regions: main window */
        art = MEM_callocN(sizeof(ARegionType), "spacetype sequencer region");
index cda5177..53e8556 100644 (file)
@@ -38,6 +38,7 @@
 #include "DNA_ID.h"
 #include "DNA_tracking_types.h"
 #include "DNA_color_types.h"  /* for color management */
+#include "DNA_sequence_types.h"
 
 struct anim;
 struct AnimData;
index c34ff00..ebe1350 100644 (file)
@@ -275,6 +275,18 @@ typedef struct BrightContrastModifierData {
        float contrast;
 } BrightContrastModifierData;
 
+/* ***************** Scopes ****************** */
+
+typedef struct SequencerScopes {
+       struct ImBuf *reference_ibuf;
+
+       struct ImBuf *zebra_ibuf;
+       struct ImBuf *waveform_ibuf;
+       struct ImBuf *sep_waveform_ibuf;
+       struct ImBuf *vector_ibuf;
+       struct ImBuf *histogram_ibuf;
+} SequencerScopes;
+
 #define MAXSEQ          32
 
 #define SELECT 1
index b828247..e70d80f 100644 (file)
@@ -473,6 +473,8 @@ typedef struct SpaceSeq {
        int overlay_type;
 
        struct bGPdata *gpd;        /* grease-pencil data */
+
+       struct SequencerScopes scopes;  /* different scoped displayed in space */
 } SpaceSeq;
 
 
index 5f1669c..45d6ea2 100644 (file)
@@ -386,6 +386,8 @@ static void rna_ColorManagedDisplaySettings_display_device_update(Main *UNUSED(b
                Scene *scene = (Scene *) id;
 
                IMB_colormanagement_validate_settings(&scene->display_settings, &scene->view_settings);
+
+               WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
        }
 }
 
@@ -470,6 +472,15 @@ static void rna_ColorManagedColorspaceSettings_reload_update(Main *UNUSED(bmain)
        }
 }
 
+static void rna_ColorManagement_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+       ID *id = ptr->id.data;
+
+       if (GS(id->name) == ID_SCE) {
+               WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
+       }
+}
+
 /* this function only exists because #curvemap_evaluateF uses a 'const' qualifier */
 float rna_CurveMap_evaluateF(struct CurveMap *cuma, float value)
 {
@@ -852,21 +863,21 @@ static void rna_def_colormanage(BlenderRNA *brna)
                                          "rna_ColorManagedViewSettings_view_transform_set",
                                          "rna_ColorManagedViewSettings_view_transform_itemf");
        RNA_def_property_ui_text(prop, "View Transform", "View used ");
-       RNA_def_property_update(prop, NC_WINDOW, NULL);
+       RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
 
        prop = RNA_def_property(srna, "exposure", PROP_FLOAT, PROP_FACTOR);
        RNA_def_property_float_sdna(prop, NULL, "exposure");
        RNA_def_property_range(prop, -10.0f, 10.0f);
        RNA_def_property_float_default(prop, 0.0f);
        RNA_def_property_ui_text(prop, "Exposure", "Exposure (stops) applied on displaying image buffers");
-       RNA_def_property_update(prop, NC_WINDOW, NULL);
+       RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
 
        prop = RNA_def_property(srna, "gamma", PROP_FLOAT, PROP_FACTOR);
        RNA_def_property_float_sdna(prop, NULL, "gamma");
        RNA_def_property_float_default(prop, 1.0f);
        RNA_def_property_range(prop, 0.0f, 5.0f);
        RNA_def_property_ui_text(prop, "Gamma", "Amount f gamma modification for displaying image buffers");
-       RNA_def_property_update(prop, NC_WINDOW, NULL);
+       RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
 
        /* ** Colorspace **  */
        srna = RNA_def_struct(brna, "ColorManagedColorspaceSettings", NULL);