Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/gpencil.c
| Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_idtype.h" | #include "BKE_idtype.h" | ||||
| #include "BKE_image.h" | #include "BKE_image.h" | ||||
| #include "BKE_lib_id.h" | #include "BKE_lib_id.h" | ||||
| #include "BKE_lib_query.h" | #include "BKE_lib_query.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| #include "BKE_paint.h" | #include "BKE_paint.h" | ||||
| #include "BLI_dlrbTree.h" | |||||
| #include "BLI_math_color.h" | #include "BLI_math_color.h" | ||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| #include "BLO_read_write.h" | #include "BLO_read_write.h" | ||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| ▲ Show 20 Lines • Show All 994 Lines • ▼ Show 20 Lines | void BKE_gpencil_stroke_copy_settings(const bGPDstroke *gps_src, bGPDstroke *gps_dst) | ||||
| copy_v3_v3(gps_dst->boundbox_max, gps_src->boundbox_max); | copy_v3_v3(gps_dst->boundbox_max, gps_src->boundbox_max); | ||||
| gps_dst->uv_rotation = gps_src->uv_rotation; | gps_dst->uv_rotation = gps_src->uv_rotation; | ||||
| copy_v2_v2(gps_dst->uv_translation, gps_src->uv_translation); | copy_v2_v2(gps_dst->uv_translation, gps_src->uv_translation); | ||||
| gps_dst->uv_scale = gps_src->uv_scale; | gps_dst->uv_scale = gps_src->uv_scale; | ||||
| gps_dst->select_index = gps_src->select_index; | gps_dst->select_index = gps_src->select_index; | ||||
| copy_v4_v4(gps_dst->vert_color_fill, gps_src->vert_color_fill); | copy_v4_v4(gps_dst->vert_color_fill, gps_src->vert_color_fill); | ||||
| } | } | ||||
| bGPdata *BKE_gpencil_data_duplicate(Main *bmain, const bGPdata *gpd_src, bool internal_copy) | void BKE_gpencil_data_duplicate(Main *bmain, const bGPdata *gpd_src, bGPdata **gpd_dst) | ||||
| { | { | ||||
| bGPdata *gpd_dst; | |||||
| /* Yuck and super-uber-hyper yuck!!! | |||||
| * Should be replaceable with a no-main copy (LIB_ID_COPY_NO_MAIN etc.), but not sure about it, | |||||
| * so for now keep old code for that one. */ | |||||
| /* error checking */ | /* error checking */ | ||||
| if (gpd_src == NULL) { | if (gpd_src == NULL) { | ||||
| return NULL; | return; | ||||
| } | } | ||||
| if (internal_copy) { | bGPdata *gpd_new = *gpd_dst; | ||||
| /* make a straight copy for undo buffers used during stroke drawing */ | |||||
| gpd_dst = MEM_dupallocN(gpd_src); | if (bmain == NULL) { | ||||
| if (gpd_new == NULL) { | |||||
| *gpd_dst = MEM_dupallocN(gpd_src); | |||||
| gpd_new = *gpd_dst; | |||||
| } | } | ||||
| else { | else { | ||||
| BLI_assert(bmain != NULL); | *gpd_new = *gpd_src; | ||||
| gpd_dst = (bGPdata *)BKE_id_copy(bmain, &gpd_src->id); | } | ||||
| greasepencil_copy_data(NULL, (ID *)gpd_new, (ID *)gpd_src, 0); | |||||
| gpd_new->runtime.update_cache = NULL; | |||||
| } | |||||
| else { | |||||
| *gpd_dst = (bGPdata *)BKE_id_copy(bmain, &gpd_src->id); | |||||
| } | } | ||||
| /* Copy internal data (layers, etc.) */ | |||||
| greasepencil_copy_data(bmain, &gpd_dst->id, &gpd_src->id, 0); | |||||
| /* return new */ | |||||
| return gpd_dst; | |||||
| } | } | ||||
| /* ************************************************** */ | /* ************************************************** */ | ||||
| /* GP Stroke API */ | /* GP Stroke API */ | ||||
| void BKE_gpencil_stroke_sync_selection(bGPdata *gpd, bGPDstroke *gps) | void BKE_gpencil_stroke_sync_selection(bGPdata *gpd, bGPDstroke *gps) | ||||
| { | { | ||||
| bGPDspoint *pt; | bGPDspoint *pt; | ||||
| ▲ Show 20 Lines • Show All 1,761 Lines • ▼ Show 20 Lines | if (gpl_cache->flag == GP_UPDATE_NODE_FULL_COPY) { | ||||
| td->gpl_eval = BKE_gpencil_layer_duplicate(gpl, true, true); | td->gpl_eval = BKE_gpencil_layer_duplicate(gpl, true, true); | ||||
| BLI_insertlinkbefore(&td->gpd_eval->layers, gpl_eval_next, td->gpl_eval); | BLI_insertlinkbefore(&td->gpd_eval->layers, gpl_eval_next, td->gpl_eval); | ||||
| BKE_gpencil_layer_original_pointers_update(gpl, td->gpl_eval); | BKE_gpencil_layer_original_pointers_update(gpl, td->gpl_eval); | ||||
| td->gpl_eval->runtime.gpl_orig = gpl; | td->gpl_eval->runtime.gpl_orig = gpl; | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (gpl_cache->flag == GP_UPDATE_NODE_LIGHT_COPY) { | else if (gpl_cache->flag == GP_UPDATE_NODE_LIGHT_COPY) { | ||||
campbellbarton: Clang-tidy will remove the else added in this patch, same for the else below as they both have… | |||||
| BLI_assert(gpl != NULL); | BLI_assert(gpl != NULL); | ||||
| BKE_gpencil_layer_copy_settings(gpl, td->gpl_eval); | BKE_gpencil_layer_copy_settings(gpl, td->gpl_eval); | ||||
| td->gpl_eval->runtime.gpl_orig = gpl; | td->gpl_eval->runtime.gpl_orig = gpl; | ||||
| } | } | ||||
| td->gpf_eval = td->gpl_eval->frames.first; | td->gpf_eval = td->gpl_eval->frames.first; | ||||
| td->gpf_index = 0; | td->gpf_index = 0; | ||||
| return false; | return false; | ||||
| Show All 23 Lines | if (gpf_cache->flag == GP_UPDATE_NODE_FULL_COPY) { | ||||
| td->gpf_eval->runtime.gpf_orig = gpf; | td->gpf_eval->runtime.gpf_orig = gpf; | ||||
| if (update_actframe) { | if (update_actframe) { | ||||
| td->gpl_eval->actframe = td->gpf_eval; | td->gpl_eval->actframe = td->gpf_eval; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (gpf_cache->flag == GP_UPDATE_NODE_LIGHT_COPY) { | else if (gpf_cache->flag == GP_UPDATE_NODE_LIGHT_COPY) { | ||||
| BLI_assert(gpf != NULL); | BLI_assert(gpf != NULL); | ||||
| BKE_gpencil_frame_copy_settings(gpf, td->gpf_eval); | BKE_gpencil_frame_copy_settings(gpf, td->gpf_eval); | ||||
| td->gpf_eval->runtime.gpf_orig = gpf; | td->gpf_eval->runtime.gpf_orig = gpf; | ||||
| } | } | ||||
| td->gps_eval = td->gpf_eval->strokes.first; | td->gps_eval = td->gpf_eval->strokes.first; | ||||
| td->gps_index = 0; | td->gps_index = 0; | ||||
| return false; | return false; | ||||
| ▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | tGPencilUpdateOnWriteTraverseData data = { | ||||
| .gpf_eval = NULL, | .gpf_eval = NULL, | ||||
| .gps_eval = NULL, | .gps_eval = NULL, | ||||
| .gpl_index = 0, | .gpl_index = 0, | ||||
| .gpf_index = 0, | .gpf_index = 0, | ||||
| .gps_index = 0, | .gps_index = 0, | ||||
| }; | }; | ||||
| BKE_gpencil_traverse_update_cache(update_cache, &ts, &data); | BKE_gpencil_traverse_update_cache(update_cache, &ts, &data); | ||||
| gpd_eval->flag |= GP_DATA_CACHE_IS_DIRTY; | gpd_eval->flag |= GP_DATA_CACHE_IS_DIRTY; | ||||
| /* TODO: This might cause issues when we have multiple depsgraphs? */ | const bool gpencil_undo_system_inactive = !(U.experimental.use_gpencil_undo_system && | ||||
| GPENCIL_ANY_MODE(gpd_orig)); | |||||
| /* If the gpencil undo system is active, make sure to only free the cache if | |||||
| * GP_DATA_UPDATE_CACHE_DISPOSABLE is set. Even though we already used the cache to update the | |||||
| * eval object, it might still be needed for the undo system (e.g if a modal operator is running, | |||||
| * it might call the update-on-write multiple times before an undo step is encoded). Only when | |||||
| * the undo system marks the cache as disposable can we safely free it here.*/ | |||||
| if (gpencil_undo_system_inactive || (gpd_orig->flag & GP_DATA_UPDATE_CACHE_DISPOSABLE)) { | |||||
| /* The update-on-write is only triggered by the active depsgraph (see | |||||
| * BKE_gpencil_can_avoid_full_copy_on_write), so it's safe to free the cache at this point. */ | |||||
| BKE_gpencil_free_update_cache(gpd_orig); | BKE_gpencil_free_update_cache(gpd_orig); | ||||
| } | } | ||||
| } | |||||
| /** \} */ | /** \} */ | ||||
Clang-tidy will remove the else added in this patch, same for the else below as they both have returns in the previous blocks.