GPencil: Improve drawing feeling in big files
authorAntonioya <blendergit@gmail.com>
Fri, 5 Apr 2019 09:26:04 +0000 (11:26 +0200)
committerAntonioya <blendergit@gmail.com>
Fri, 5 Apr 2019 09:26:04 +0000 (11:26 +0200)
When drawing in big files, the first points of the stroke were not smooth because the system was doing a copy of the depsgraph datablock.

Now, the depsgraph is not updated at the beginning and the feeling is far better, especially for big files.

To avoid the copy, the original datablock is used while drawing, because it's faster the lookup of the original data, than a full datablock copy.

Also some cleanup of the code.

source/blender/draw/engines/gpencil/gpencil_engine.c
source/blender/editors/gpencil/gpencil_paint.c

index 1cc493dd8f562f4d8e72efb341903323ae68b857..3a74e44836dce66c327626380212c6528965508c 100644 (file)
@@ -617,9 +617,20 @@ void GPENCIL_cache_populate(void *vedata, Object *ob)
                }
 
                /* draw current painting strokes
                }
 
                /* draw current painting strokes
-                * (only if region is equal to originated paint region) */
+                * (only if region is equal to originated paint region)
+                *
+                * Need to use original data because to use the copy of data, the paint
+                * operator must update depsgraph and this makes that first events of the
+                * mouse are missed if the datablock is very big due the time required to
+                * copy the datablock. The search of the original data is faster than a
+                * full datablock copy.
+                * Using the original data doesn't require a copy and the feel when drawing
+                * is far better.
+                */
+
+               bGPdata *gpd_orig = (bGPdata *)DEG_get_original_id(&gpd->id);
                if ((draw_ctx->obact == ob) &&
                if ((draw_ctx->obact == ob) &&
-                   ((gpd->runtime.ar == NULL) || (gpd->runtime.ar == draw_ctx->ar)))
+                       ((gpd_orig->runtime.ar == NULL) || (gpd_orig->runtime.ar == draw_ctx->ar)))
                {
                        DRW_gpencil_populate_buffer_strokes(&e_data, vedata, ts, ob);
                }
                {
                        DRW_gpencil_populate_buffer_strokes(&e_data, vedata, ts, ob);
                }
index b66956b090dec227d65dcfbd261008eb78b8d68c..d544bd8f9b648986ecb593f29d601fe8ebeeda22 100644 (file)
@@ -1708,6 +1708,9 @@ static void gp_session_validatebuffer(tGPsdata *p)
        /* reset flags */
        gpd->runtime.sbuffer_sflag = 0;
 
        /* reset flags */
        gpd->runtime.sbuffer_sflag = 0;
 
+       /* reset region */
+       gpd->runtime.ar = NULL;
+
        /* reset inittime */
        p->inittime = 0.0;
 
        /* reset inittime */
        p->inittime = 0.0;
 
@@ -1784,11 +1787,12 @@ static void gp_init_drawing_brush(bContext *C, tGPsdata *p)
        ToolSettings *ts = CTX_data_tool_settings(C);
 
        Paint *paint = &ts->gp_paint->paint;
        ToolSettings *ts = CTX_data_tool_settings(C);
 
        Paint *paint = &ts->gp_paint->paint;
-
+       bool changed = false;
        /* if not exist, create a new one */
        if (paint->brush == NULL) {
                /* create new brushes */
                BKE_brush_gpencil_presets(C);
        /* if not exist, create a new one */
        if (paint->brush == NULL) {
                /* create new brushes */
                BKE_brush_gpencil_presets(C);
+               changed = true;
        }
        /* be sure curves are initializated */
        curvemapping_initialize(paint->brush->gpencil_settings->curve_sensitivity);
        }
        /* be sure curves are initializated */
        curvemapping_initialize(paint->brush->gpencil_settings->curve_sensitivity);
@@ -1813,7 +1817,9 @@ static void gp_init_drawing_brush(bContext *C, tGPsdata *p)
         * Maybe this update can be removed when the new tool system
         * will be in place, but while, we need this to keep drawing working.
         */
         * Maybe this update can be removed when the new tool system
         * will be in place, but while, we need this to keep drawing working.
         */
-       DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
+       if (changed) {
+               DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
+       }
 }
 
 
 }
 
 
@@ -1946,13 +1952,6 @@ static bool gp_session_initdata(bContext *C, wmOperator *op, tGPsdata *p)
                p->gpd = *gpd_ptr;
        }
 
                p->gpd = *gpd_ptr;
        }
 
-       if (ED_gpencil_session_active() == 0) {
-               /* initialize undo stack,
-                * also, existing undo stack would make buffer drawn
-                */
-               gpencil_undo_init(p->gpd);
-       }
-
        /* clear out buffer (stored in gp-data), in case something contaminated it */
        gp_session_validatebuffer(p);
 
        /* clear out buffer (stored in gp-data), in case something contaminated it */
        gp_session_validatebuffer(p);
 
@@ -1961,6 +1960,9 @@ static bool gp_session_initdata(bContext *C, wmOperator *op, tGPsdata *p)
 
        /* setup active color */
        if (curarea->spacetype == SPACE_VIEW3D) {
 
        /* setup active color */
        if (curarea->spacetype == SPACE_VIEW3D) {
+               /* region where paint was originated */
+               p->gpd->runtime.ar = CTX_wm_region(C);
+
                /* NOTE: This is only done for 3D view, as Materials aren't used for
                 *       annotations in 2D editors
                 */
                /* NOTE: This is only done for 3D view, as Materials aren't used for
                 *       annotations in 2D editors
                 */
@@ -1984,9 +1986,6 @@ static bool gp_session_initdata(bContext *C, wmOperator *op, tGPsdata *p)
                p->lock_axis = 0;
        }
 
                p->lock_axis = 0;
        }
 
-       /* region where paint was originated */
-       p->gpd->runtime.ar = CTX_wm_region(C);
-
        return 1;
 }
 
        return 1;
 }
 
@@ -2134,8 +2133,6 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps
                        add_frame_mode = GP_GETFRAME_ADD_NEW;
 
                p->gpf = BKE_gpencil_layer_getframe(p->gpl, cfra_eval, add_frame_mode);
                        add_frame_mode = GP_GETFRAME_ADD_NEW;
 
                p->gpf = BKE_gpencil_layer_getframe(p->gpl, cfra_eval, add_frame_mode);
-               /* set as dirty draw manager cache */
-               gp_update_cache(p->gpd);
 
                if (p->gpf == NULL) {
                        p->status = GP_STATUS_ERROR;
 
                if (p->gpf == NULL) {
                        p->status = GP_STATUS_ERROR;