Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2020-10-06 18:43:12 +0300
committerBastien Montagne <bastien@blender.org>2020-10-07 12:09:36 +0300
commit874cf52c10d73911cfec709d9b0202ac690aab6f (patch)
treeeb168090d49f83ac37bfd259a7b0e794e92b1937 /source/blender/blenkernel/intern
parent94f91827f8938153dad7d4b7f88fa8431f2f756c (diff)
Refactor: Remove `BKE_XXX_localize()`, in favor of using regular ID copying code.
Besides the NodeTree case (which remains unchanged), the localize code is only used in one place (to generate previews of shading data-blocks). This commit introduces a new `LIB_ID_CREATE_LOCAL` option for ID creation/copying, which essentially implements the behavior of the removed `BKE_XXX_localize()` functions into regular mainstream ID copy code. When this option is set: - new ID is tagged with `LIB_TAG_LOCALIZED`; - Some ID copying callbacks have specific behaviors, mainly the root nodetree of shading IDs gets duplicated with specialized `ntreeLocalize()` function. Note that I would not consider getting rid of `ntreeLocalize` for now, this function is recursive, which should ideally never happen within ID management copying code (this introduces all kind of complications). No behavioral change expected from this commit.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r--source/blender/blenkernel/intern/lib_id.c6
-rw-r--r--source/blender/blenkernel/intern/light.c37
-rw-r--r--source/blender/blenkernel/intern/material.c52
-rw-r--r--source/blender/blenkernel/intern/texture.c45
-rw-r--r--source/blender/blenkernel/intern/world.c41
5 files changed, 46 insertions, 135 deletions
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index 8f3d05ce914..fd127f5871f 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -1035,6 +1035,8 @@ void *BKE_libblock_alloc_notest(short type)
void *BKE_libblock_alloc(Main *bmain, short type, const char *name, const int flag)
{
BLI_assert((flag & LIB_ID_CREATE_NO_ALLOCATE) == 0);
+ BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || bmain != NULL);
+ BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || (flag & LIB_ID_CREATE_LOCAL) == 0);
ID *id = BKE_libblock_alloc_notest(type);
@@ -1045,6 +1047,9 @@ void *BKE_libblock_alloc(Main *bmain, short type, const char *name, const int fl
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) != 0) {
id->tag |= LIB_TAG_NO_USER_REFCOUNT;
}
+ if (flag & LIB_ID_CREATE_LOCAL) {
+ id->tag |= LIB_TAG_LOCALIZED;
+ }
id->icon_id = 0;
*((short *)id->name) = type;
@@ -1180,6 +1185,7 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int ori
BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || bmain != NULL);
BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || (flag & LIB_ID_CREATE_NO_ALLOCATE) == 0);
+ BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || (flag & LIB_ID_CREATE_LOCAL) == 0);
if (!is_private_id_data) {
/* When we are handling private ID data, we might still want to manage usercounts, even
* though that ID data-block is actually outside of Main... */
diff --git a/source/blender/blenkernel/intern/light.c b/source/blender/blenkernel/intern/light.c
index 1ce079b006e..437e61a5fca 100644
--- a/source/blender/blenkernel/intern/light.c
+++ b/source/blender/blenkernel/intern/light.c
@@ -81,13 +81,21 @@ static void light_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int
{
Light *la_dst = (Light *)id_dst;
const Light *la_src = (const Light *)id_src;
+
+ const bool is_localized = (flag & LIB_ID_CREATE_LOCAL) != 0;
/* We always need allocation of our private ID data. */
const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE;
la_dst->curfalloff = BKE_curvemapping_copy(la_src->curfalloff);
if (la_src->nodetree) {
- BKE_id_copy_ex(bmain, (ID *)la_src->nodetree, (ID **)&la_dst->nodetree, flag_private_id_data);
+ if (is_localized) {
+ la_dst->nodetree = ntreeLocalize(la_src->nodetree);
+ }
+ else {
+ BKE_id_copy_ex(
+ bmain, (ID *)la_src->nodetree, (ID **)&la_dst->nodetree, flag_private_id_data);
+ }
}
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
@@ -219,33 +227,6 @@ Light *BKE_light_copy(Main *bmain, const Light *la)
return la_copy;
}
-Light *BKE_light_localize(Light *la)
-{
- /* TODO(bastien): Replace with something like:
- *
- * Light *la_copy;
- * BKE_id_copy_ex(bmain, &la->id, (ID **)&la_copy,
- * LIB_ID_COPY_NO_MAIN | LIB_ID_COPY_NO_PREVIEW | LIB_ID_COPY_NO_USER_REFCOUNT,
- * false);
- * return la_copy;
- *
- * NOTE: Only possible once nested node trees are fully converted to that too. */
-
- Light *lan = BKE_libblock_copy_for_localize(&la->id);
-
- lan->curfalloff = BKE_curvemapping_copy(la->curfalloff);
-
- if (la->nodetree) {
- lan->nodetree = ntreeLocalize(la->nodetree);
- }
-
- lan->preview = NULL;
-
- lan->id.tag |= LIB_TAG_LOCALIZED;
-
- return lan;
-}
-
void BKE_light_eval(struct Depsgraph *depsgraph, Light *la)
{
DEG_debug_print_eval(depsgraph, __func__, la->id.name, la);
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index d8c0b5d6dce..8c09cb551a1 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -100,12 +100,20 @@ static void material_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const
Material *material_dst = (Material *)id_dst;
const Material *material_src = (const Material *)id_src;
+ const bool is_localized = (flag & LIB_ID_CREATE_LOCAL) != 0;
/* We always need allocation of our private ID data. */
const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE;
- if (material_src->nodetree) {
- BKE_id_copy_ex(
- bmain, (ID *)material_src->nodetree, (ID **)&material_dst->nodetree, flag_private_id_data);
+ if (material_src->nodetree != NULL) {
+ if (is_localized) {
+ material_dst->nodetree = ntreeLocalize(material_src->nodetree);
+ }
+ else {
+ BKE_id_copy_ex(bmain,
+ (ID *)material_src->nodetree,
+ (ID **)&material_dst->nodetree,
+ flag_private_id_data);
+ }
}
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
@@ -116,7 +124,8 @@ static void material_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const
}
if (material_src->texpaintslot != NULL) {
- material_dst->texpaintslot = MEM_dupallocN(material_src->texpaintslot);
+ /* TODO: Think we can also skip copying this data in the more generic `NO_MAIN` case? */
+ material_dst->texpaintslot = is_localized ? NULL : MEM_dupallocN(material_src->texpaintslot);
}
if (material_src->gp_style != NULL) {
@@ -315,41 +324,6 @@ Material *BKE_material_copy(Main *bmain, const Material *ma)
return ma_copy;
}
-/* XXX (see above) material copy without adding to main dbase */
-Material *BKE_material_localize(Material *ma)
-{
- /* TODO(bastien): Replace with something like:
- *
- * Material *ma_copy;
- * BKE_id_copy_ex(bmain, &ma->id, (ID **)&ma_copy,
- * LIB_ID_COPY_NO_MAIN | LIB_ID_COPY_NO_PREVIEW | LIB_ID_COPY_NO_USER_REFCOUNT,
- * false);
- * return ma_copy;
- *
- * NOTE: Only possible once nested node trees are fully converted to that too. */
-
- Material *man = BKE_libblock_copy_for_localize(&ma->id);
-
- man->texpaintslot = NULL;
- man->preview = NULL;
-
- if (ma->nodetree != NULL) {
- man->nodetree = ntreeLocalize(ma->nodetree);
- }
-
- if (ma->gp_style != NULL) {
- man->gp_style = MEM_dupallocN(ma->gp_style);
- }
-
- BLI_listbase_clear(&man->gpumaterial);
-
- /* TODO Duplicate Engine Settings and set runtime to NULL */
-
- man->id.tag |= LIB_TAG_LOCALIZED;
-
- return man;
-}
-
Material ***BKE_object_material_array_p(Object *ob)
{
if (ob->type == OB_MESH) {
diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c
index b74b7d57b2e..4d113597745 100644
--- a/source/blender/blenkernel/intern/texture.c
+++ b/source/blender/blenkernel/intern/texture.c
@@ -87,6 +87,7 @@ static void texture_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const i
Tex *texture_dst = (Tex *)id_dst;
const Tex *texture_src = (const Tex *)id_src;
+ const bool is_localized = (flag & LIB_ID_CREATE_LOCAL) != 0;
/* We always need allocation of our private ID data. */
const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE;
@@ -101,8 +102,14 @@ static void texture_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const i
if (texture_src->nodetree->execdata) {
ntreeTexEndExecTree(texture_src->nodetree->execdata);
}
- BKE_id_copy_ex(
- bmain, (ID *)texture_src->nodetree, (ID **)&texture_dst->nodetree, flag_private_id_data);
+
+ if (is_localized) {
+ texture_dst->nodetree = ntreeLocalize(texture_src->nodetree);
+ }
+ else {
+ BKE_id_copy_ex(
+ bmain, (ID *)texture_src->nodetree, (ID **)&texture_dst->nodetree, flag_private_id_data);
+ }
}
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
@@ -455,40 +462,6 @@ Tex *BKE_texture_copy(Main *bmain, const Tex *tex)
return tex_copy;
}
-/* texture copy without adding to main dbase */
-Tex *BKE_texture_localize(Tex *tex)
-{
- /* TODO(bastien): Replace with something like:
- *
- * Tex *tex_copy;
- * BKE_id_copy_ex(bmain, &tex->id, (ID **)&tex_copy,
- * LIB_ID_COPY_NO_MAIN | LIB_ID_COPY_NO_PREVIEW | LIB_ID_COPY_NO_USER_REFCOUNT,
- * false);
- * return tex_copy;
- *
- * NOTE: Only possible once nested node trees are fully converted to that too. */
-
- Tex *texn;
-
- texn = BKE_libblock_copy_for_localize(&tex->id);
-
- /* image texture: texture_free_data also doesn't decrease */
-
- if (texn->coba) {
- texn->coba = MEM_dupallocN(texn->coba);
- }
-
- texn->preview = NULL;
-
- if (tex->nodetree) {
- texn->nodetree = ntreeLocalize(tex->nodetree);
- }
-
- texn->id.tag |= LIB_TAG_LOCALIZED;
-
- return texn;
-}
-
/* ------------------------------------------------------------------------- */
Tex *give_current_linestyle_texture(FreestyleLineStyle *linestyle)
diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c
index d5142e2d1a4..7590afeaaff 100644
--- a/source/blender/blenkernel/intern/world.c
+++ b/source/blender/blenkernel/intern/world.c
@@ -99,12 +99,19 @@ static void world_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int
{
World *wrld_dst = (World *)id_dst;
const World *wrld_src = (const World *)id_src;
+
+ const bool is_localized = (flag & LIB_ID_CREATE_LOCAL) != 0;
/* We always need allocation of our private ID data. */
const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE;
if (wrld_src->nodetree) {
- BKE_id_copy_ex(
- bmain, (ID *)wrld_src->nodetree, (ID **)&wrld_dst->nodetree, flag_private_id_data);
+ if (is_localized) {
+ wrld_dst->nodetree = ntreeLocalize(wrld_src->nodetree);
+ }
+ else {
+ BKE_id_copy_ex(
+ bmain, (ID *)wrld_src->nodetree, (ID **)&wrld_dst->nodetree, flag_private_id_data);
+ }
}
BLI_listbase_clear(&wrld_dst->gpumaterial);
@@ -210,36 +217,6 @@ World *BKE_world_add(Main *bmain, const char *name)
return wrld;
}
-World *BKE_world_localize(World *wrld)
-{
- /* TODO(bastien): Replace with something like:
- *
- * World *wrld_copy;
- * BKE_id_copy_ex(bmain, &wrld->id, (ID **)&wrld_copy,
- * LIB_ID_COPY_NO_MAIN | LIB_ID_COPY_NO_PREVIEW | LIB_ID_COPY_NO_USER_REFCOUNT,
- * false);
- * return wrld_copy;
- *
- * NOTE: Only possible once nested node trees are fully converted to that too. */
-
- World *wrldn;
-
- wrldn = BKE_libblock_copy_for_localize(&wrld->id);
-
- if (wrld->nodetree) {
- wrldn->nodetree = ntreeLocalize(wrld->nodetree);
- }
-
- wrldn->preview = NULL;
-
- BLI_listbase_clear(&wrldn->gpumaterial);
- BLI_listbase_clear((ListBase *)&wrldn->drawdata);
-
- wrldn->id.tag |= LIB_TAG_LOCALIZED;
-
- return wrldn;
-}
-
void BKE_world_eval(struct Depsgraph *depsgraph, World *world)
{
DEG_debug_print_eval(depsgraph, __func__, world->id.name, world);