Merge branch 'blender2.8' of git.blender.org:blender into blender2.8

This commit is contained in:
Jeroen Bakker
2018-05-01 10:44:31 +02:00
23 changed files with 106 additions and 86 deletions

View File

@@ -69,10 +69,10 @@ bool BKE_animdata_set_action(struct ReportList *reports, struct ID *id, struct b
void BKE_animdata_free(struct ID *id, const bool do_id_user);
/* Copy AnimData */
struct AnimData *BKE_animdata_copy(struct Main *bmain, struct AnimData *adt, const bool do_action);
struct AnimData *BKE_animdata_copy(struct Main *bmain, struct AnimData *adt, const bool do_action, const bool do_id_user);
/* Copy AnimData */
bool BKE_animdata_copy_id(struct Main *bmain, struct ID *id_to, struct ID *id_from, const bool do_action);
bool BKE_animdata_copy_id(struct Main *bmain, struct ID *id_to, struct ID *id_from, const bool do_action, const bool do_id_user);
/* Copy AnimData Actions */
void BKE_animdata_copy_id_action(struct ID *id, const bool set_newid);

View File

@@ -322,6 +322,11 @@ int CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list);
struct Depsgraph *CTX_data_depsgraph(const bContext *C);
/* Will Return NULL if depsgraph is not allocated yet.
* Only used by handful of operators which are run on file load.
*/
struct Depsgraph *CTX_data_depsgraph_on_load(const bContext *C);
#ifdef __cplusplus
}
#endif

View File

@@ -264,7 +264,7 @@ void BKE_animdata_free(ID *id, const bool do_id_user)
/* Copying -------------------------------------------- */
/* Make a copy of the given AnimData - to be used when copying datablocks */
AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const bool do_action)
AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const bool do_action, const bool do_id_user)
{
AnimData *dadt;
@@ -279,7 +279,7 @@ AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const bool do_action)
BKE_id_copy_ex(bmain, (ID *)dadt->action, (ID **)&dadt->action, 0, false);
BKE_id_copy_ex(bmain, (ID *)dadt->tmpact, (ID **)&dadt->tmpact, 0, false);
}
else {
else if (do_id_user) {
id_us_plus((ID *)dadt->action);
id_us_plus((ID *)dadt->tmpact);
}
@@ -297,19 +297,19 @@ AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const bool do_action)
return dadt;
}
bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, const bool do_action)
bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, const bool do_action, const bool do_id_user)
{
AnimData *adt;
if ((id_to && id_from) && (GS(id_to->name) != GS(id_from->name)))
return false;
BKE_animdata_free(id_to, true);
BKE_animdata_free(id_to, do_id_user);
adt = BKE_animdata_from_id(id_from);
if (adt) {
IdAdtTemplate *iat = (IdAdtTemplate *)id_to;
iat->adt = BKE_animdata_copy(bmain, adt, do_action);
iat->adt = BKE_animdata_copy(bmain, adt, do_action, do_id_user);
}
return true;

View File

@@ -1244,3 +1244,10 @@ Depsgraph *CTX_data_depsgraph(const bContext *C)
ViewLayer *view_layer = CTX_data_view_layer(C);
return BKE_scene_get_depsgraph(scene, view_layer, true);
}
Depsgraph *CTX_data_depsgraph_on_load(const bContext *C)
{
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
return BKE_scene_get_depsgraph(scene, view_layer, false);
}

View File

@@ -1376,7 +1376,7 @@ static void id_copy_animdata(Main *bmain, ID *id, const bool do_action)
if (adt) {
IdAdtTemplate *iat = (IdAdtTemplate *)id;
iat->adt = BKE_animdata_copy(bmain, iat->adt, do_action); /* could be set to false, need to investigate */
iat->adt = BKE_animdata_copy(bmain, iat->adt, do_action, true); /* could be set to false, need to investigate */
}
}

View File

@@ -199,7 +199,9 @@ Material *BKE_material_localize(Material *ma)
BLI_listbase_clear(&man->gpumaterial);
/* TODO Duplicate Engine Settings and set runtime to NULL */
man->id.tag |= LIB_TAG_LOCALIZED;
return man;
}

View File

@@ -2051,6 +2051,8 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree)
if (ntree->typeinfo->localize)
ntree->typeinfo->localize(ltree, ntree);
ltree->id.tag |= LIB_TAG_LOCALIZED;
BLI_mutex_unlock(ntree->duplilock);
return ltree;

View File

@@ -865,6 +865,15 @@ void BKE_sculpt_update_mesh_elements(
Depsgraph *depsgraph, Scene *scene, Sculpt *sd, Object *ob,
bool need_pmap, bool need_mask)
{
if (depsgraph == NULL) {
/* Happens on file load.
*
* We do nothing in this case, it will be taken care about on depsgraph
* evaluation.
*/
return;
}
DerivedMesh *dm;
SculptSession *ss = ob->sculpt;
Mesh *me = ob->data;

View File

@@ -211,7 +211,7 @@ OperationDepsNode *DepsgraphRelationBuilder::get_node(
OperationDepsNode *op_node = find_node(key);
if (op_node == NULL) {
fprintf(stderr, "find_node_operation: Failed for (%s, '%s')\n",
DEG_OPNAMES[key.opcode], key.name);
operationCodeAsString(key.opcode), key.name);
}
return op_node;
}

View File

@@ -179,7 +179,7 @@ string OperationKey::identifier() const
return string("OperationKey(") +
"t: " + typebuf +
", cn: '" + component_name +
"', c: " + DEG_OPNAMES[opcode] +
"', c: " + operationCodeAsString(opcode) +
", n: '" + name + "')";
}

View File

@@ -71,11 +71,46 @@ DepsNodeFactory *deg_type_get_factory(const eDepsNode_Type type)
return depsnode_typeinfo_registry[type];
}
/* Stringified node types ---------------------------------- */
const char* nodeTypeAsString(eDepsNode_Type type)
{
switch (type) {
#define STRINGIFY_TYPE(name) case DEG_NODE_TYPE_##name: return #name
STRINGIFY_TYPE(UNDEFINED);
STRINGIFY_TYPE(OPERATION);
/* **** Generic Types **** */
STRINGIFY_TYPE(TIMESOURCE);
STRINGIFY_TYPE(ID_REF);
/* **** Outer Types **** */
STRINGIFY_TYPE(PARAMETERS);
STRINGIFY_TYPE(PROXY);
STRINGIFY_TYPE(ANIMATION);
STRINGIFY_TYPE(TRANSFORM);
STRINGIFY_TYPE(GEOMETRY);
STRINGIFY_TYPE(SEQUENCER);
STRINGIFY_TYPE(LAYER_COLLECTIONS);
STRINGIFY_TYPE(COPY_ON_WRITE);
/* **** Evaluation-Related Outer Types (with Subdata) **** */
STRINGIFY_TYPE(EVAL_POSE);
STRINGIFY_TYPE(BONE);
STRINGIFY_TYPE(EVAL_PARTICLES);
STRINGIFY_TYPE(SHADING);
STRINGIFY_TYPE(SHADING_PARAMETERS);
STRINGIFY_TYPE(CACHE);
STRINGIFY_TYPE(BATCH_CACHE);
/* Total number of meaningful node types. */
case NUM_DEG_NODE_TYPES: return "SpecialCase";
#undef STRINGIFY_TYPE
}
return "UNKNOWN";
}
/* Stringified opcodes ------------------------------------- */
DepsOperationStringifier DEG_OPNAMES;
static const char *stringify_opcode(eDepsOperation_Code opcode)
const char* operationCodeAsString(eDepsOperation_Code opcode)
{
switch (opcode) {
#define STRINGIFY_OPCODE(name) case DEG_OPCODE_##name: return #name
@@ -143,22 +178,6 @@ static const char *stringify_opcode(eDepsOperation_Code opcode)
return "UNKNOWN";
}
DepsOperationStringifier::DepsOperationStringifier()
{
for (int i = 0; i < DEG_NUM_OPCODES; ++i) {
names_[i] = stringify_opcode((eDepsOperation_Code)i);
}
}
const char *DepsOperationStringifier::operator[](eDepsOperation_Code opcode)
{
BLI_assert((opcode >= 0) && (opcode < DEG_NUM_OPCODES));
if (opcode >= 0 && opcode < DEG_NUM_OPCODES) {
return names_[opcode];
}
return "UnknownOpcode";
}
} // namespace DEG
/* Register all node types */

View File

@@ -155,6 +155,8 @@ typedef enum eDepsNode_Type {
NUM_DEG_NODE_TYPES,
} eDepsNode_Type;
const char* nodeTypeAsString(eDepsNode_Type type);
/* Identifiers for common operations (as an enum). */
typedef enum eDepsOperation_Code {
/* Generic Operations. ------------------------------ */
@@ -268,16 +270,6 @@ typedef enum eDepsOperation_Code {
DEG_NUM_OPCODES,
} eDepsOperation_Code;
/* Some magic to stringify operation codes. */
class DepsOperationStringifier {
public:
DepsOperationStringifier();
const char *operator[](eDepsOperation_Code opcodex);
protected:
const char *names_[DEG_NUM_OPCODES];
};
/* String defines for these opcodes, defined in depsgraph_type_defines.cpp */
extern DepsOperationStringifier DEG_OPNAMES;
const char* operationCodeAsString(eDepsOperation_Code opcode);
} // namespace DEG

View File

@@ -340,17 +340,6 @@ static bool check_datablocks_copy_on_writable(const ID *id_orig)
struct RemapCallbackUserData {
/* Dependency graph for which remapping is happening. */
const Depsgraph *depsgraph;
/* Temporarily allocated memory for copying purposes. This ID will
* be discarded after expanding is done, so need to make sure temp_id
* is replaced with proper real_id.
*
* NOTE: This is due to our logic of "inplace" duplication, where we
* use generic duplication routines (which gives us new ID) which then
* is followed with copying data to a placeholder we prepared before and
* discarding pointer returned by duplication routines.
*/
const ID *temp_id;
ID *real_id;
/* Create placeholder for ID nodes for cases when we need to remap original
* ID to it[s CoW version but we don't have required ID node yet.
*
@@ -371,12 +360,7 @@ int foreach_libblock_remap_callback(void *user_data_v,
RemapCallbackUserData *user_data = (RemapCallbackUserData *)user_data_v;
const Depsgraph *depsgraph = user_data->depsgraph;
ID *id_orig = *id_p;
if (id_orig == user_data->temp_id) {
DEG_COW_PRINT(" Remapping datablock for %s: id_temp=%p id_cow=%p\n",
id_orig->name, id_orig, user_data->real_id);
*id_p = user_data->real_id;
}
else if (check_datablocks_copy_on_writable(id_orig)) {
if (check_datablocks_copy_on_writable(id_orig)) {
ID *id_cow;
if (user_data->create_placeholders) {
/* Special workaround to stop creating temp datablocks for
@@ -523,11 +507,6 @@ ID *deg_expand_copy_on_write_datablock(const Depsgraph *depsgraph,
* - We don't want bmain's content to be freed when main is freed.
*/
bool done = false;
/* Need to make sure the possibly temporary allocated memory is correct for
* until we are fully done with remapping original pointers with copied on
* write ones.
*/
ID *newid = NULL;
/* First we handle special cases which are not covered by id_copy() yet.
* or cases where we want to do something smarter than simple datablock
* copy.
@@ -569,8 +548,6 @@ ID *deg_expand_copy_on_write_datablock(const Depsgraph *depsgraph,
/* Perform remapping of the nodes. */
RemapCallbackUserData user_data;
user_data.depsgraph = depsgraph;
user_data.temp_id = newid;
user_data.real_id = id_cow;
user_data.node_builder = node_builder;
user_data.create_placeholders = create_placeholders;
BKE_library_foreach_ID_link(NULL,
@@ -582,10 +559,6 @@ ID *deg_expand_copy_on_write_datablock(const Depsgraph *depsgraph,
* from above.
*/
update_special_pointers(depsgraph, id_orig, id_cow);
/* Now we can safely discard temporary memory used for copying. */
if (newid != NULL) {
MEM_freeN(newid);
}
id_cow->recalc = id_orig->recalc | id_cow_recalc;
return id_cow;
}
@@ -608,7 +581,7 @@ static void deg_update_copy_on_write_animation(const Depsgraph * /*depsgraph*/,
const IDDepsNode *id_node)
{
DEG_debug_print_eval(__func__, id_node->id_orig->name, id_node->id_cow);
BKE_animdata_copy_id(NULL, id_node->id_cow, id_node->id_orig, false);
BKE_animdata_copy_id(NULL, id_node->id_cow, id_node->id_orig, false, false);
}
ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph,
@@ -827,6 +800,8 @@ bool deg_validate_copy_on_write_datablock(ID *id_cow)
void deg_tag_copy_on_write_id(ID *id_cow, const ID *id_orig)
{
BLI_assert(id_cow != id_orig);
BLI_assert((id_orig->tag & LIB_TAG_COPY_ON_WRITE) == 0);
id_cow->tag |= LIB_TAG_COPY_ON_WRITE;
id_cow->orig_id = (ID *)id_orig;
}

View File

@@ -103,10 +103,7 @@ DepsNode::~DepsNode()
/* Generic identifier for Depsgraph Nodes. */
string DepsNode::identifier() const
{
char typebuf[7];
sprintf(typebuf, "(%d)", type);
return string(typebuf) + " : " + name;
return string(nodeTypeAsString(type)) + " : " + name;
}
eDepsNode_Class DepsNode::get_class() const {

View File

@@ -172,6 +172,15 @@ void IDDepsNode::destroy()
id_orig = NULL;
}
string IDDepsNode::identifier() const
{
char orig_ptr[24], cow_ptr[24];
BLI_snprintf(orig_ptr, sizeof(orig_ptr), "%p", id_orig);
BLI_snprintf(cow_ptr, sizeof(cow_ptr), "%p", id_cow);
return string(nodeTypeAsString(type)) + " : " + name +
" (orig: " + orig_ptr + ", eval: " + cow_ptr + ")";
}
ComponentDepsNode *IDDepsNode::find_component(eDepsNode_Type type,
const char *name) const
{

View File

@@ -51,6 +51,8 @@ struct IDDepsNode : public DepsNode {
~IDDepsNode();
void destroy();
virtual string identifier() const;
ComponentDepsNode *find_component(eDepsNode_Type type,
const char *name = "") const;
ComponentDepsNode *add_component(eDepsNode_Type type,

View File

@@ -56,7 +56,7 @@ OperationDepsNode::~OperationDepsNode()
string OperationDepsNode::identifier() const
{
return string(DEG_OPNAMES[opcode]) + "(" + name + ")";
return string(operationCodeAsString(opcode)) + "(" + name + ")";
}
/* Full node identifier, including owner name.

View File

@@ -373,7 +373,7 @@ int join_armature_exec(bContext *C, wmOperator *op)
if (base->object->adt) {
if (ob->adt == NULL) {
/* no animdata, so just use a copy of the whole thing */
ob->adt = BKE_animdata_copy(bmain, base->object->adt, false);
ob->adt = BKE_animdata_copy(bmain, base->object->adt, false, true);
}
else {
/* merge in data - we'll fix the drivers manually */
@@ -384,7 +384,7 @@ int join_armature_exec(bContext *C, wmOperator *op)
if (curarm->adt) {
if (arm->adt == NULL) {
/* no animdata, so just use a copy of the whole thing */
arm->adt = BKE_animdata_copy(bmain, curarm->adt, false);
arm->adt = BKE_animdata_copy(bmain, curarm->adt, false, true);
}
else {
/* merge in data - we'll fix the drivers manually */

View File

@@ -1466,13 +1466,13 @@ static int make_links_data_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(&ob_dst->id, OB_RECALC_DATA);
break;
case MAKE_LINKS_ANIMDATA:
BKE_animdata_copy_id(bmain, (ID *)ob_dst, (ID *)ob_src, false);
BKE_animdata_copy_id(bmain, (ID *)ob_dst, (ID *)ob_src, false, true);
if (ob_dst->data && ob_src->data) {
if (ID_IS_LINKED(obdata_id)) {
is_lib = true;
break;
}
BKE_animdata_copy_id(bmain, (ID *)ob_dst->data, (ID *)ob_src->data, false);
BKE_animdata_copy_id(bmain, (ID *)ob_dst->data, (ID *)ob_src->data, false, true);
}
DEG_id_tag_update(&ob_dst->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
break;

View File

@@ -2342,7 +2342,7 @@ static int vpaint_mode_toggle_exec(bContext *C, wmOperator *op)
ED_object_vpaintmode_exit_ex(ob);
}
else {
Depsgraph *depsgraph = CTX_data_depsgraph(C);
Depsgraph *depsgraph = CTX_data_depsgraph_on_load(C);
wmWindowManager *wm = CTX_wm_manager(C);
ED_object_vpaintmode_enter_ex(depsgraph, wm, scene, ob);
}

View File

@@ -5793,7 +5793,7 @@ void ED_object_sculptmode_exit(bContext *C)
static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op)
{
Depsgraph *depsgraph = CTX_data_depsgraph(C);
Depsgraph *depsgraph = CTX_data_depsgraph_on_load(C);
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
const int mode_flag = OB_MODE_SCULPT;

View File

@@ -457,16 +457,17 @@ enum {
/* RESET_AFTER_USE tag existing data before linking so we know what is new. */
LIB_TAG_PRE_EXISTING = 1 << 11,
/* The datablock is a copy-on-write version. */
/* The datablock is a copy-on-write/localized version. */
LIB_TAG_COPY_ON_WRITE = 1 << 12,
LIB_TAG_COPY_ON_WRITE_EVAL = 1 << 13,
LIB_TAG_LOCALIZED = 1 << 14,
/* RESET_NEVER tag datablock for freeing etc. behavior (usually set when copying real one into temp/runtime one). */
LIB_TAG_NO_MAIN = 1 << 14, /* Datablock is not listed in Main database. */
LIB_TAG_NO_USER_REFCOUNT = 1 << 15, /* Datablock does not refcount usages of other IDs. */
LIB_TAG_NO_MAIN = 1 << 15, /* Datablock is not listed in Main database. */
LIB_TAG_NO_USER_REFCOUNT = 1 << 16, /* Datablock does not refcount usages of other IDs. */
/* Datablock was not allocated by standard system (BKE_libblock_alloc), do not free its memory
* (usual type-specific freeing is called though). */
LIB_TAG_NOT_ALLOCATED = 1 << 16,
LIB_TAG_NOT_ALLOCATED = 1 << 17,
};
/* WARNING - when adding flags check on PSYS_RECALC */

View File

@@ -601,7 +601,7 @@ bool rna_AnimaData_override_apply(
if (adt_dst == NULL && adt_src != NULL) {
/* Copy anim data from reference into final local ID. */
BKE_animdata_copy_id(NULL, ptr_dst->id.data, ptr_src->id.data, false);
BKE_animdata_copy_id(NULL, ptr_dst->id.data, ptr_src->id.data, false, true);
return true;
}
else if (adt_dst != NULL && adt_src == NULL) {