Cleanup: GreasePencil: Move to IDTypeInfo and remove unused BKE API.
This commit is contained in:
		@@ -112,15 +112,12 @@ struct bGPDlayer *BKE_gpencil_layer_duplicate(const struct bGPDlayer *gpl_src);
 | 
			
		||||
void BKE_gpencil_frame_copy_strokes(struct bGPDframe *gpf_src, struct bGPDframe *gpf_dst);
 | 
			
		||||
struct bGPDstroke *BKE_gpencil_stroke_duplicate(struct bGPDstroke *gps_src, const bool dup_points);
 | 
			
		||||
 | 
			
		||||
void BKE_gpencil_copy_data(struct bGPdata *gpd_dst, const struct bGPdata *gpd_src, const int flag);
 | 
			
		||||
struct bGPdata *BKE_gpencil_copy(struct Main *bmain, const struct bGPdata *gpd);
 | 
			
		||||
 | 
			
		||||
struct bGPdata *BKE_gpencil_data_duplicate(struct Main *bmain,
 | 
			
		||||
                                           const struct bGPdata *gpd,
 | 
			
		||||
                                           bool internal_copy);
 | 
			
		||||
 | 
			
		||||
void BKE_gpencil_make_local(struct Main *bmain, struct bGPdata *gpd, const int flags);
 | 
			
		||||
 | 
			
		||||
void BKE_gpencil_frame_delete_laststroke(struct bGPDlayer *gpl, struct bGPDframe *gpf);
 | 
			
		||||
 | 
			
		||||
/* materials */
 | 
			
		||||
 
 | 
			
		||||
@@ -150,7 +150,7 @@ extern IDTypeInfo IDType_ID_AC;
 | 
			
		||||
extern IDTypeInfo IDType_ID_NT;
 | 
			
		||||
extern IDTypeInfo IDType_ID_BR;
 | 
			
		||||
extern IDTypeInfo IDType_ID_PA;
 | 
			
		||||
// extern IDTypeInfo IDType_ID_GD;
 | 
			
		||||
extern IDTypeInfo IDType_ID_GD;
 | 
			
		||||
extern IDTypeInfo IDType_ID_WM;
 | 
			
		||||
extern IDTypeInfo IDType_ID_MC;
 | 
			
		||||
extern IDTypeInfo IDType_ID_MSK;
 | 
			
		||||
 
 | 
			
		||||
@@ -59,6 +59,7 @@
 | 
			
		||||
#include "BKE_deform.h"
 | 
			
		||||
#include "BKE_gpencil.h"
 | 
			
		||||
#include "BKE_icons.h"
 | 
			
		||||
#include "BKE_idtype.h"
 | 
			
		||||
#include "BKE_image.h"
 | 
			
		||||
#include "BKE_lib_id.h"
 | 
			
		||||
#include "BKE_main.h"
 | 
			
		||||
@@ -73,6 +74,54 @@
 | 
			
		||||
 | 
			
		||||
static CLG_LogRef LOG = {"bke.gpencil"};
 | 
			
		||||
 | 
			
		||||
static void greasepencil_copy_data(Main *UNUSED(bmain),
 | 
			
		||||
                                   ID *id_dst,
 | 
			
		||||
                                   const ID *id_src,
 | 
			
		||||
                                   const int UNUSED(flag))
 | 
			
		||||
{
 | 
			
		||||
  bGPdata *gpd_dst = (bGPdata *)id_dst;
 | 
			
		||||
  const bGPdata *gpd_src = (const bGPdata *)id_src;
 | 
			
		||||
 | 
			
		||||
  /* duplicate material array */
 | 
			
		||||
  if (gpd_src->mat) {
 | 
			
		||||
    gpd_dst->mat = MEM_dupallocN(gpd_src->mat);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* copy layers */
 | 
			
		||||
  BLI_listbase_clear(&gpd_dst->layers);
 | 
			
		||||
  LISTBASE_FOREACH (bGPDlayer *, gpl_src, &gpd_src->layers) {
 | 
			
		||||
    /* make a copy of source layer and its data */
 | 
			
		||||
 | 
			
		||||
    /* TODO here too could add unused flags... */
 | 
			
		||||
    bGPDlayer *gpl_dst = BKE_gpencil_layer_duplicate(gpl_src);
 | 
			
		||||
 | 
			
		||||
    BLI_addtail(&gpd_dst->layers, gpl_dst);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void greasepencil_free_data(ID *id)
 | 
			
		||||
{
 | 
			
		||||
  /* Really not ideal, but for now will do... In theory custom behaviors like not freeing cache
 | 
			
		||||
   * should be handled through specific API, and not be part of the generic one. */
 | 
			
		||||
  BKE_gpencil_free((bGPdata *)id, true);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
IDTypeInfo IDType_ID_GD = {
 | 
			
		||||
    .id_code = ID_GD,
 | 
			
		||||
    .id_filter = FILTER_ID_GD,
 | 
			
		||||
    .main_listbase_index = INDEX_ID_GD,
 | 
			
		||||
    .struct_size = sizeof(bGPdata),
 | 
			
		||||
    .name = "GPencil",
 | 
			
		||||
    .name_plural = "grease_pencils",
 | 
			
		||||
    .translation_context = BLT_I18NCONTEXT_ID_GPENCIL,
 | 
			
		||||
    .flags = 0,
 | 
			
		||||
 | 
			
		||||
    .init_data = NULL,
 | 
			
		||||
    .copy_data = greasepencil_copy_data,
 | 
			
		||||
    .free_data = greasepencil_free_data,
 | 
			
		||||
    .make_local = NULL,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* ************************************************** */
 | 
			
		||||
/* Draw Engine */
 | 
			
		||||
 | 
			
		||||
@@ -671,35 +720,6 @@ bGPDlayer *BKE_gpencil_layer_duplicate(const bGPDlayer *gpl_src)
 | 
			
		||||
  return gpl_dst;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Only copy internal data of GreasePencil ID from source
 | 
			
		||||
 * to already allocated/initialized destination.
 | 
			
		||||
 * You probably never want to use that directly,
 | 
			
		||||
 * use #BKE_id_copy or #BKE_id_copy_ex for typical needs.
 | 
			
		||||
 *
 | 
			
		||||
 * WARNING! This function will not handle ID user count!
 | 
			
		||||
 *
 | 
			
		||||
 * \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more).
 | 
			
		||||
 */
 | 
			
		||||
void BKE_gpencil_copy_data(bGPdata *gpd_dst, const bGPdata *gpd_src, const int UNUSED(flag))
 | 
			
		||||
{
 | 
			
		||||
  /* duplicate material array */
 | 
			
		||||
  if (gpd_src->mat) {
 | 
			
		||||
    gpd_dst->mat = MEM_dupallocN(gpd_src->mat);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* copy layers */
 | 
			
		||||
  BLI_listbase_clear(&gpd_dst->layers);
 | 
			
		||||
  LISTBASE_FOREACH (bGPDlayer *, gpl_src, &gpd_src->layers) {
 | 
			
		||||
    /* make a copy of source layer and its data */
 | 
			
		||||
 | 
			
		||||
    /* TODO here too could add unused flags... */
 | 
			
		||||
    bGPDlayer *gpl_dst = BKE_gpencil_layer_duplicate(gpl_src);
 | 
			
		||||
 | 
			
		||||
    BLI_addtail(&gpd_dst->layers, gpl_dst);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Standard API to make a copy of GP datablock, separate from copying its data */
 | 
			
		||||
bGPdata *BKE_gpencil_copy(Main *bmain, const bGPdata *gpd)
 | 
			
		||||
{
 | 
			
		||||
@@ -733,17 +753,12 @@ bGPdata *BKE_gpencil_data_duplicate(Main *bmain, const bGPdata *gpd_src, bool in
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Copy internal data (layers, etc.) */
 | 
			
		||||
  BKE_gpencil_copy_data(gpd_dst, gpd_src, 0);
 | 
			
		||||
  greasepencil_copy_data(bmain, &gpd_dst->id, &gpd_src->id, 0);
 | 
			
		||||
 | 
			
		||||
  /* return new */
 | 
			
		||||
  return gpd_dst;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BKE_gpencil_make_local(Main *bmain, bGPdata *gpd, const int flags)
 | 
			
		||||
{
 | 
			
		||||
  BKE_lib_id_make_local_generic(bmain, &gpd->id, flags);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* ************************************************** */
 | 
			
		||||
/* GP Stroke API */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -77,7 +77,7 @@ static void id_type_init(void)
 | 
			
		||||
  INIT_TYPE(ID_NT);
 | 
			
		||||
  INIT_TYPE(ID_BR);
 | 
			
		||||
  INIT_TYPE(ID_PA);
 | 
			
		||||
  // INIT_TYPE(ID_GD);
 | 
			
		||||
  INIT_TYPE(ID_GD);
 | 
			
		||||
  INIT_TYPE(ID_WM);
 | 
			
		||||
  INIT_TYPE(ID_MC);
 | 
			
		||||
  INIT_TYPE(ID_MSK);
 | 
			
		||||
 
 | 
			
		||||
@@ -536,9 +536,7 @@ bool BKE_lib_id_make_local(Main *bmain, ID *id, const bool test, const int flags
 | 
			
		||||
      BLI_assert(0);
 | 
			
		||||
      return true;
 | 
			
		||||
    case ID_GD:
 | 
			
		||||
      if (!test) {
 | 
			
		||||
        BKE_gpencil_make_local(bmain, (bGPdata *)id, flags);
 | 
			
		||||
      }
 | 
			
		||||
      BLI_assert(0);
 | 
			
		||||
      return true;
 | 
			
		||||
    case ID_MC:
 | 
			
		||||
      BLI_assert(0);
 | 
			
		||||
@@ -740,7 +738,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag)
 | 
			
		||||
        BLI_assert(0);
 | 
			
		||||
        break;
 | 
			
		||||
      case ID_GD:
 | 
			
		||||
        BKE_gpencil_copy_data((bGPdata *)*r_newid, (bGPdata *)id, flag);
 | 
			
		||||
        BLI_assert(0);
 | 
			
		||||
        break;
 | 
			
		||||
      case ID_MC:
 | 
			
		||||
        BLI_assert(0);
 | 
			
		||||
@@ -1368,7 +1366,7 @@ void BKE_libblock_init_empty(ID *id)
 | 
			
		||||
      BLI_assert(0);
 | 
			
		||||
      break;
 | 
			
		||||
    case ID_GD:
 | 
			
		||||
      /* Nothing to do. */
 | 
			
		||||
      BLI_assert(0);
 | 
			
		||||
      break;
 | 
			
		||||
    case ID_MSK:
 | 
			
		||||
      BLI_assert(0);
 | 
			
		||||
 
 | 
			
		||||
@@ -220,7 +220,7 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag))
 | 
			
		||||
      BLI_assert(0);
 | 
			
		||||
      break;
 | 
			
		||||
    case ID_GD:
 | 
			
		||||
      BKE_gpencil_free((bGPdata *)id, true);
 | 
			
		||||
      BLI_assert(0);
 | 
			
		||||
      break;
 | 
			
		||||
    case ID_MC:
 | 
			
		||||
      BLI_assert(0);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user