[Bf-blender-cvs] [70bf5618d7e] asset-greasepencil: Merge branch 'master' into asset-greasepencil

Antonio Vazquez noreply at git.blender.org
Thu Feb 10 16:55:55 CET 2022


Commit: 70bf5618d7ec0cc6310b7d74514a71fab7270e51
Author: Antonio Vazquez
Date:   Thu Feb 10 16:51:48 2022 +0100
Branches: asset-greasepencil
https://developer.blender.org/rB70bf5618d7ec0cc6310b7d74514a71fab7270e51

Merge branch 'master' into asset-greasepencil

 Conflicts:
	source/blender/blenkernel/intern/gpencil.c
        source/blender/makesdna/DNA_gpencil_types.h

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



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

diff --cc source/blender/blenkernel/intern/gpencil.c
index 9b1cbc82b45,6e39125b252..1626aa1dc36
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@@ -2766,20 -2837,180 +2852,196 @@@ void BKE_gpencil_frame_selected_hash(bG
    }
  }
  
+ bool BKE_gpencil_can_avoid_full_copy_on_write(const Depsgraph *depsgraph, bGPdata *gpd)
+ {
+   /* For now, we only use the update cache in the active depsgraph. Othwerwise we might access the
+    * cache while another depsgraph frees it. */
+   if (!DEG_is_active(depsgraph)) {
+     return false;
+   }
+ 
+   GPencilUpdateCache *update_cache = gpd->runtime.update_cache;
+   return update_cache != NULL && update_cache->flag != GP_UPDATE_NODE_FULL_COPY;
+ }
+ 
+ typedef struct tGPencilUpdateOnWriteTraverseData {
+   bGPdata *gpd_eval;
+   bGPDlayer *gpl_eval;
+   bGPDframe *gpf_eval;
+   bGPDstroke *gps_eval;
+   int gpl_index;
+   int gpf_index;
+   int gps_index;
+ } tGPencilUpdateOnWriteTraverseData;
+ 
+ static bool gpencil_update_on_write_layer_cb(GPencilUpdateCache *gpl_cache, void *user_data)
+ {
+   tGPencilUpdateOnWriteTraverseData *td = (tGPencilUpdateOnWriteTraverseData *)user_data;
+   td->gpl_eval = BLI_findlinkfrom((Link *)td->gpl_eval, gpl_cache->index - td->gpl_index);
+   td->gpl_index = gpl_cache->index;
+   bGPDlayer *gpl = (bGPDlayer *)gpl_cache->data;
+ 
+   if (gpl_cache->flag == GP_UPDATE_NODE_FULL_COPY) {
+     bGPDlayer *gpl_eval_next = td->gpl_eval->next;
+     BLI_assert(gpl != NULL);
+ 
+     BKE_gpencil_layer_delete(td->gpd_eval, td->gpl_eval);
+ 
+     td->gpl_eval = BKE_gpencil_layer_duplicate(gpl, true, true);
+     BLI_insertlinkbefore(&td->gpd_eval->layers, gpl_eval_next, td->gpl_eval);
+ 
+     BKE_gpencil_layer_original_pointers_update(gpl, td->gpl_eval);
+     td->gpl_eval->runtime.gpl_orig = gpl;
+     return true;
+   }
+   else if (gpl_cache->flag == GP_UPDATE_NODE_LIGHT_COPY) {
+     BLI_assert(gpl != NULL);
+     BKE_gpencil_layer_copy_settings(gpl, td->gpl_eval);
+     td->gpl_eval->runtime.gpl_orig = gpl;
+   }
+ 
+   td->gpf_eval = td->gpl_eval->frames.first;
+   td->gpf_index = 0;
+   return false;
+ }
+ 
+ static bool gpencil_update_on_write_frame_cb(GPencilUpdateCache *gpf_cache, void *user_data)
+ {
+   tGPencilUpdateOnWriteTraverseData *td = (tGPencilUpdateOnWriteTraverseData *)user_data;
+   td->gpf_eval = BLI_findlinkfrom((Link *)td->gpf_eval, gpf_cache->index - td->gpf_index);
+   td->gpf_index = gpf_cache->index;
+ 
+   bGPDframe *gpf = (bGPDframe *)gpf_cache->data;
+ 
+   if (gpf_cache->flag == GP_UPDATE_NODE_FULL_COPY) {
+     /* Do a full copy of the frame. */
+     bGPDframe *gpf_eval_next = td->gpf_eval->next;
+     BLI_assert(gpf != NULL);
+ 
+     bool update_actframe = (td->gpl_eval->actframe == td->gpf_eval) ? true : false;
+     BKE_gpencil_free_strokes(td->gpf_eval);
+     BLI_freelinkN(&td->gpl_eval->frames, td->gpf_eval);
+ 
+     td->gpf_eval = BKE_gpencil_frame_duplicate(gpf, true);
+     BLI_insertlinkbefore(&td->gpl_eval->frames, gpf_eval_next, td->gpf_eval);
+ 
+     BKE_gpencil_frame_original_pointers_update(gpf, td->gpf_eval);
+     td->gpf_eval->runtime.gpf_orig = gpf;
+ 
+     if (update_actframe) {
+       td->gpl_eval->actframe = td->gpf_eval;
+     }
+ 
+     return true;
+   }
+   else if (gpf_cache->flag == GP_UPDATE_NODE_LIGHT_COPY) {
+     BLI_assert(gpf != NULL);
+     BKE_gpencil_frame_copy_settings(gpf, td->gpf_eval);
+     td->gpf_eval->runtime.gpf_orig = gpf;
+   }
+ 
+   td->gps_eval = td->gpf_eval->strokes.first;
+   td->gps_index = 0;
+   return false;
+ }
+ 
+ static bool gpencil_update_on_write_stroke_cb(GPencilUpdateCache *gps_cache, void *user_data)
+ {
+   tGPencilUpdateOnWriteTraverseData *td = (tGPencilUpdateOnWriteTraverseData *)user_data;
+   td->gps_eval = BLI_findlinkfrom((Link *)td->gps_eval, gps_cache->index - td->gps_index);
+   td->gps_index = gps_cache->index;
+ 
+   bGPDstroke *gps = (bGPDstroke *)gps_cache->data;
+ 
+   if (gps_cache->flag == GP_UPDATE_NODE_FULL_COPY) {
+     /* Do a full copy of the stroke. */
+     bGPDstroke *gps_eval_next = td->gps_eval->next;
+     BLI_assert(gps != NULL);
+ 
+     BLI_remlink(&td->gpf_eval->strokes, td->gps_eval);
+     BKE_gpencil_free_stroke(td->gps_eval);
+ 
+     td->gps_eval = BKE_gpencil_stroke_duplicate(gps, true, true);
+     BLI_insertlinkbefore(&td->gpf_eval->strokes, gps_eval_next, td->gps_eval);
+ 
+     td->gps_eval->runtime.gps_orig = gps;
+ 
+     /* Assign original pt pointers. */
+     for (int i = 0; i < gps->totpoints; i++) {
+       bGPDspoint *pt_orig = &gps->points[i];
+       bGPDspoint *pt_eval = &td->gps_eval->points[i];
+       pt_orig->runtime.pt_orig = NULL;
+       pt_orig->runtime.idx_orig = i;
+       pt_eval->runtime.pt_orig = pt_orig;
+       pt_eval->runtime.idx_orig = i;
+     }
+   }
+   else if (gps_cache->flag == GP_UPDATE_NODE_LIGHT_COPY) {
+     BLI_assert(gps != NULL);
+     BKE_gpencil_stroke_copy_settings(gps, td->gps_eval);
+     td->gps_eval->runtime.gps_orig = gps;
+   }
+ 
+   return false;
+ }
+ 
+ /**
+  * Update the geometry of the evaluated bGPdata.
+  * This function will:
+  *    1) Copy the original data over to the evaluated object.
+  *    2) Update the original pointers in the runtime structs.
+  */
+ void BKE_gpencil_update_on_write(bGPdata *gpd_orig, bGPdata *gpd_eval)
+ {
+   GPencilUpdateCache *update_cache = gpd_orig->runtime.update_cache;
+ 
+   /* We assume that a full copy is not needed and the update cache is populated. */
+   if (update_cache == NULL || update_cache->flag == GP_UPDATE_NODE_FULL_COPY) {
+     return;
+   }
+ 
+   if (update_cache->flag == GP_UPDATE_NODE_LIGHT_COPY) {
+     BKE_gpencil_data_copy_settings(gpd_orig, gpd_eval);
+   }
+ 
+   GPencilUpdateCacheTraverseSettings ts = {{
+       gpencil_update_on_write_layer_cb,
+       gpencil_update_on_write_frame_cb,
+       gpencil_update_on_write_stroke_cb,
+   }};
+ 
+   tGPencilUpdateOnWriteTraverseData data = {
+       .gpd_eval = gpd_eval,
+       .gpl_eval = gpd_eval->layers.first,
+       .gpf_eval = NULL,
+       .gps_eval = NULL,
+       .gpl_index = 0,
+       .gpf_index = 0,
+       .gps_index = 0,
+   };
+ 
+   BKE_gpencil_traverse_update_cache(update_cache, &ts, &data);
+ 
+   gpd_eval->flag |= GP_DATA_CACHE_IS_DIRTY;
+ 
+   /* TODO: This might cause issues when we have multiple depsgraphs? */
+   BKE_gpencil_free_update_cache(gpd_orig);
+ }
+ 
 +/* Get min and max frame number for all layers. */
 +void BKE_gpencil_frame_min_max(const bGPdata *gpd, int *r_min, int *r_max)
 +{
 +  *r_min = INT_MAX;
 +  *r_max = INT_MIN;
 +  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
 +    LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
 +      if (gpf->framenum < *r_min) {
 +        *r_min = gpf->framenum;
 +      }
 +      if (gpf->framenum > *r_max) {
 +        *r_max = gpf->framenum;
 +      }
 +    }
 +  }
 +}
  /** \} */
diff --cc source/blender/editors/render/render_preview.cc
index 878cac9766f,c1c75e485f7..bd1bbfbfcd2
--- a/source/blender/editors/render/render_preview.cc
+++ b/source/blender/editors/render/render_preview.cc
@@@ -770,10 -767,8 +770,10 @@@ struct ObjectPreviewData 
    /* The main for the preview, not of the current file. */
    Main *pr_main;
    /* Copy of the object to create the preview for. The copy is for thread safety (and to insert
-    * it into an own main). */
+    * it into its own main). */
    Object *object;
 +  /* Datablock copy. Can be nullptr. */
 +  ID *datablock;
    /* Current frame. */
    int cfra;
    int sizex;
diff --cc source/blender/makesdna/DNA_gpencil_types.h
index 37fdb407e3c,3340782d64a..b78b2eff47a
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@@ -325,6 -326,8 +326,9 @@@ typedef struct bGPDstroke 
    /** Curve used to edit the stroke using Bezier handlers. */
    struct bGPDcurve *editcurve;
  
 -  /* NOTE: When adding new members, make sure to add them to BKE_gpencil_stroke_copy_settings as well! */
++  /* NOTE: When adding new members, make sure to add them to BKE_gpencil_stroke_copy_settings as
++   * well! */
+ 
    bGPDstroke_Runtime runtime;
    void *_pad5;
  } bGPDstroke;
@@@ -409,6 -412,8 +413,9 @@@ typedef struct bGPDframe 
    /** Keyframe type (eBezTriple_KeyframeType). */
    short key_type;
  
 -  /* NOTE: When adding new members, make sure to add them to BKE_gpencil_frame_copy_settings as well! */
++  /* NOTE: When adding new members, make sure to add them to BKE_gpencil_frame_copy_settings as
++   * well! */
+ 
    bGPDframe_Runtime runtime;
  } bGPDframe;
  
@@@ -532,6 -537,8 +539,9 @@@ typedef struct bGPDlayer 
    float layer_mat[4][4], layer_invmat[4][4];
    char _pad3[4];
  
 -  /* NOTE: When adding new members, make sure to add them to BKE_gpencil_layer_copy_settings as well! */
++  /* NOTE: When adding new members, make sure to add them to BKE_gpencil_layer_copy_settings as
++   * well! */
+ 
    bGPDlayer_Runtime runtime;
  } bGPDlayer;
  
@@@ -726,8 -735,7 +738,11 @@@ typedef struct bGPdata 
  
    bGPgrid grid;
  
 -  /* NOTE: When adding new members, make sure to add them to BKE_gpencil_data_copy_settings as well! */
++  /* NOTE: When adding new members, make sure to add them to BKE_gpencil_data_copy_settings as
++   * well! */
++
 +  /** Preview image for assets. */
 +  struct PreviewImage *preview;
  
    bGPdata_Runtime runtime;
  } bGPdata;



More information about the Bf-blender-cvs mailing list