Commit: 874cf52c10d73911cfec709d9b0202ac690aab6f
Author: Bastien Montagne
Date: Tue Oct 6 17:43:12 2020 +0200
Branches: master
https://developer.blender.org/rB874cf52c10d73911cfec709d9b0202ac690aab6f
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.
===================================================================
M source/blender/blenkernel/BKE_lib_id.h
M source/blender/blenkernel/BKE_light.h
M source/blender/blenkernel/BKE_material.h
M source/blender/blenkernel/BKE_texture.h
M source/blender/blenkernel/BKE_world.h
M source/blender/blenkernel/intern/lib_id.c
M source/blender/blenkernel/intern/light.c
M source/blender/blenkernel/intern/material.c
M source/blender/blenkernel/intern/texture.c
M source/blender/blenkernel/intern/world.c
M source/blender/editors/render/render_preview.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_lib_id.h
b/source/blender/blenkernel/BKE_lib_id.h
index c3c4c228b61..33ccd20bcff 100644
--- a/source/blender/blenkernel/BKE_lib_id.h
+++ b/source/blender/blenkernel/BKE_lib_id.h
@@ -99,6 +99,12 @@ enum {
/** Do not tag new ID for update in depsgraph. */
LIB_ID_CREATE_NO_DEG_TAG = 1 << 8,
+ /** Very similar to #LIB_ID_CREATE_NO_MAIN, and should never be used with it
(typically combined
+ * with #LIB_ID_CREATE_LOCALIZE or #LIB_ID_COPY_LOCALIZE in fact).
+ * It ensures that IDs created with it will get the #LIB_TAG_LOCALIZED tag,
and uses some
+ * specific code in some copy cases (mostly for node trees). */
+ LIB_ID_CREATE_LOCAL = 1 << 9,
+
/* *** Specific options to some ID types or usages. *** */
/* *** May be ignored by unrelated ID copying functions. *** */
/** Object only, needed by make_local code. */
diff --git a/source/blender/blenkernel/BKE_light.h
b/source/blender/blenkernel/BKE_light.h
index 026e5d1a13b..9a619f0a0fa 100644
--- a/source/blender/blenkernel/BKE_light.h
+++ b/source/blender/blenkernel/BKE_light.h
@@ -36,7 +36,6 @@ struct Main;
struct Light *BKE_light_add(struct Main *bmain, const char *name)
ATTR_WARN_UNUSED_RESULT;
struct Light *BKE_light_copy(struct Main *bmain, const struct Light *la)
ATTR_WARN_UNUSED_RESULT;
-struct Light *BKE_light_localize(struct Light *la) ATTR_WARN_UNUSED_RESULT;
void BKE_light_eval(struct Depsgraph *depsgraph, struct Light *la);
diff --git a/source/blender/blenkernel/BKE_material.h
b/source/blender/blenkernel/BKE_material.h
index a6d8d2d2d8b..aeb7600d647 100644
--- a/source/blender/blenkernel/BKE_material.h
+++ b/source/blender/blenkernel/BKE_material.h
@@ -54,7 +54,6 @@ void BKE_object_material_remap_calc(struct Object *ob_dst,
struct Material *BKE_material_add(struct Main *bmain, const char *name);
struct Material *BKE_gpencil_material_add(struct Main *bmain, const char
*name);
struct Material *BKE_material_copy(struct Main *bmain, const struct Material
*ma);
-struct Material *BKE_material_localize(struct Material *ma);
void BKE_gpencil_material_attr_init(struct Material *ma);
/* UNUSED */
diff --git a/source/blender/blenkernel/BKE_texture.h
b/source/blender/blenkernel/BKE_texture.h
index aae8ffc47b9..47ef0c4c63b 100644
--- a/source/blender/blenkernel/BKE_texture.h
+++ b/source/blender/blenkernel/BKE_texture.h
@@ -47,7 +47,6 @@ void BKE_texture_mtex_foreach_id(struct LibraryForeachIDData
*data, struct MTex
void BKE_texture_default(struct Tex *tex);
struct Tex *BKE_texture_copy(struct Main *bmain, const struct Tex *tex);
struct Tex *BKE_texture_add(struct Main *bmain, const char *name);
-struct Tex *BKE_texture_localize(struct Tex *tex);
void BKE_texture_type_set(struct Tex *tex, int type);
void BKE_texture_mtex_default(struct MTex *mtex);
diff --git a/source/blender/blenkernel/BKE_world.h
b/source/blender/blenkernel/BKE_world.h
index 73eb340e887..bbab6fa2712 100644
--- a/source/blender/blenkernel/BKE_world.h
+++ b/source/blender/blenkernel/BKE_world.h
@@ -31,7 +31,6 @@ struct Main;
struct World;
struct World *BKE_world_add(struct Main *bmain, const char *name);
-struct World *BKE_world_localize(struct World *wrld);
void BKE_world_eval(struct Depsgraph *depsgraph, struct World *world);
#ifdef __cplusplus
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 p
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs