diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-12-20 18:40:49 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-12-20 18:40:49 +0300 |
commit | a52452c043b34c664f2772a6f72b886ac641acd7 (patch) | |
tree | 6ccdbd0cd6258ede7fc0967b926a323e91365360 /source | |
parent | f6766c31cf6c6b7c5d723a0e901d851de1046298 (diff) | |
parent | 3474db4b37e75150924d3cec73472ad3eadea4cb (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source')
32 files changed, 482 insertions, 305 deletions
diff --git a/source/blender/alembic/intern/abc_customdata.cc b/source/blender/alembic/intern/abc_customdata.cc index d6e7a80d174..8b526616053 100644 --- a/source/blender/alembic/intern/abc_customdata.cc +++ b/source/blender/alembic/intern/abc_customdata.cc @@ -235,17 +235,19 @@ static void read_uvs(const CDStreamConfig &config, void *data, MPoly *mpolys = config.mpoly; MLoopUV *mloopuvs = static_cast<MLoopUV *>(data); - unsigned int uv_index, loop_index; + unsigned int uv_index, loop_index, rev_loop_index; for (int i = 0; i < config.totpoly; ++i) { MPoly &poly = mpolys[i]; + unsigned int rev_loop_offset = poly.loopstart + poly.totloop - 1; for (int f = 0; f < poly.totloop; ++f) { loop_index = poly.loopstart + f; + rev_loop_index = rev_loop_offset - f; uv_index = (*indices)[loop_index]; const Imath::V2f &uv = (*uvs)[uv_index]; - MLoopUV &loopuv = mloopuvs[loop_index]; + MLoopUV &loopuv = mloopuvs[rev_loop_index]; loopuv.uv[0] = uv[0]; loopuv.uv[1] = uv[1]; } diff --git a/source/blender/blenlib/intern/math_bits_inline.c b/source/blender/blenlib/intern/math_bits_inline.c index d96cf969dae..37fdcd7878a 100644 --- a/source/blender/blenlib/intern/math_bits_inline.c +++ b/source/blender/blenlib/intern/math_bits_inline.c @@ -25,6 +25,10 @@ #ifndef __MATH_BITS_INLINE_C__ #define __MATH_BITS_INLINE_C__ +#ifdef _MSC_VER +# include <intrin.h> +#endif + #include "BLI_math_bits.h" MINLINE int bitscan_forward_i(int a) diff --git a/source/blender/depsgraph/CMakeLists.txt b/source/blender/depsgraph/CMakeLists.txt index 9495321a0ff..f5e43c71f93 100644 --- a/source/blender/depsgraph/CMakeLists.txt +++ b/source/blender/depsgraph/CMakeLists.txt @@ -59,7 +59,9 @@ set(SRC intern/eval/deg_eval_flush.cc intern/nodes/deg_node.cc intern/nodes/deg_node_component.cc + intern/nodes/deg_node_id.cc intern/nodes/deg_node_operation.cc + intern/nodes/deg_node_time.cc intern/depsgraph.cc intern/depsgraph_build.cc intern/depsgraph_debug.cc @@ -87,7 +89,9 @@ set(SRC intern/eval/deg_eval_flush.h intern/nodes/deg_node.h intern/nodes/deg_node_component.h + intern/nodes/deg_node_id.h intern/nodes/deg_node_operation.h + intern/nodes/deg_node_time.h intern/depsgraph.h intern/depsgraph_intern.h intern/depsgraph_types.h diff --git a/source/blender/depsgraph/intern/builder/deg_builder.cc b/source/blender/depsgraph/intern/builder/deg_builder.cc index 1e906d454ac..2fcad233044 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder.cc @@ -36,6 +36,7 @@ #include "intern/depsgraph.h" #include "intern/depsgraph_types.h" #include "intern/nodes/deg_node.h" +#include "intern/nodes/deg_node_id.h" #include "util/deg_util_foreach.h" diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc index eb297682308..60562641c93 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc @@ -106,9 +106,11 @@ extern "C" { #include "intern/eval/deg_eval_copy_on_write.h" #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_component.h" +#include "intern/nodes/deg_node_id.h" #include "intern/nodes/deg_node_operation.h" #include "intern/depsgraph_types.h" #include "intern/depsgraph_intern.h" + #include "util/deg_util_foreach.h" namespace DEG { diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index 1864827339b..3fb19adbb5c 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -104,7 +104,9 @@ extern "C" { #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_component.h" +#include "intern/nodes/deg_node_id.h" #include "intern/nodes/deg_node_operation.h" +#include "intern/nodes/deg_node_time.h" #include "intern/depsgraph_intern.h" #include "intern/depsgraph_types.h" diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc index 29cff0cb28d..9b3e46df69a 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc @@ -59,6 +59,7 @@ extern "C" { #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_component.h" +#include "intern/nodes/deg_node_id.h" #include "intern/nodes/deg_node_operation.h" #include "intern/depsgraph_intern.h" diff --git a/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc b/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc index b12af21fc8d..7731b76c6b9 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc @@ -37,6 +37,7 @@ #include "intern/nodes/deg_node_operation.h" #include "intern/depsgraph.h" +#include "intern/depsgraph_intern.h" #include "util/deg_util_foreach.h" @@ -79,13 +80,13 @@ static void deg_graph_tag_paths_recursive(DepsNode *node) void deg_graph_transitive_reduction(Depsgraph *graph) { + int num_removed_relations = 0; foreach (OperationDepsNode *target, graph->operations) { /* Clear tags. */ foreach (OperationDepsNode *node, graph->operations) { node->done = 0; } - - /* mark nodes from which we can reach the target + /* Mark nodes from which we can reach the target * start with children, so the target node and direct children are not * flagged. */ @@ -93,27 +94,30 @@ void deg_graph_transitive_reduction(Depsgraph *graph) foreach (DepsRelation *rel, target->inlinks) { deg_graph_tag_paths_recursive(rel->from); } - /* Remove redundant paths to the target. */ for (DepsNode::Relations::const_iterator it_rel = target->inlinks.begin(); it_rel != target->inlinks.end(); ) { DepsRelation *rel = *it_rel; - /* Increment in advance, so we can safely remove the relation. */ - ++it_rel; - if (rel->from->type == DEG_NODE_TYPE_TIMESOURCE) { /* HACK: time source nodes don't get "done" flag set/cleared. */ /* TODO: there will be other types in future, so iterators above * need modifying. */ + ++it_rel; } else if (rel->from->done & OP_REACHABLE) { + rel->unlink(); OBJECT_GUARDED_DELETE(rel, DepsRelation); + ++num_removed_relations; + } + else { + ++it_rel; } } } + DEG_DEBUG_PRINTF("Removed %d relations\n", num_removed_relations); } } // namespace DEG diff --git a/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc b/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc index bd3d74b307b..f5772124088 100644 --- a/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc +++ b/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc @@ -41,6 +41,9 @@ extern "C" { #include "DEG_depsgraph_debug.h" #include "intern/depsgraph_intern.h" +#include "intern/nodes/deg_node_id.h" +#include "intern/nodes/deg_node_time.h" + #include "util/deg_util_foreach.h" /* ****************** */ diff --git a/source/blender/depsgraph/intern/depsgraph.cc b/source/blender/depsgraph/intern/depsgraph.cc index 995157f5c9a..45013bb1bcd 100644 --- a/source/blender/depsgraph/intern/depsgraph.cc +++ b/source/blender/depsgraph/intern/depsgraph.cc @@ -49,6 +49,7 @@ extern "C" { #include "RNA_access.h" } +#include <algorithm> #include <cstring> #include "DEG_depsgraph.h" @@ -57,7 +58,9 @@ extern "C" { #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_component.h" +#include "intern/nodes/deg_node_id.h" #include "intern/nodes/deg_node_operation.h" +#include "intern/nodes/deg_node_time.h" #include "intern/depsgraph_intern.h" #include "util/deg_util_foreach.h" @@ -79,6 +82,14 @@ namespace DEG { static DEG_EditorUpdateIDCb deg_editor_update_id_cb = NULL; static DEG_EditorUpdateSceneCb deg_editor_update_scene_cb = NULL; +/* TODO(sergey): Find a better place for this. */ +template <typename T> +static void remove_from_vector(vector<T> *vector, const T& value) +{ + vector->erase(std::remove(vector->begin(), vector->end(), value), + vector->end()); +} + Depsgraph::Depsgraph() : time_source(NULL), need_update(true), @@ -431,7 +442,15 @@ DepsRelation::DepsRelation(DepsNode *from, DepsRelation::~DepsRelation() { /* Sanity check. */ - BLI_assert(this->from && this->to); + BLI_assert(from != NULL && to != NULL); +} + +void DepsRelation::unlink() +{ + /* Sanity check. */ + BLI_assert(from != NULL && to != NULL); + remove_from_vector(&from->outlinks, this); + remove_from_vector(&to->inlinks, this); } /* Low level tagging -------------------------------------- */ diff --git a/source/blender/depsgraph/intern/depsgraph.h b/source/blender/depsgraph/intern/depsgraph.h index 8a34be0c7a2..f18b93c9807 100644 --- a/source/blender/depsgraph/intern/depsgraph.h +++ b/source/blender/depsgraph/intern/depsgraph.h @@ -87,6 +87,8 @@ struct DepsRelation { const char *description); ~DepsRelation(); + + void unlink(); }; /* ********* */ diff --git a/source/blender/depsgraph/intern/depsgraph_build.cc b/source/blender/depsgraph/intern/depsgraph_build.cc index 57153279acb..5b07630240d 100644 --- a/source/blender/depsgraph/intern/depsgraph_build.cc +++ b/source/blender/depsgraph/intern/depsgraph_build.cc @@ -68,6 +68,7 @@ extern "C" { #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_component.h" +#include "intern/nodes/deg_node_id.h" #include "intern/nodes/deg_node_operation.h" #include "intern/depsgraph_types.h" diff --git a/source/blender/depsgraph/intern/depsgraph_debug.cc b/source/blender/depsgraph/intern/depsgraph_debug.cc index 42c1cf861eb..e8d166532ad 100644 --- a/source/blender/depsgraph/intern/depsgraph_debug.cc +++ b/source/blender/depsgraph/intern/depsgraph_debug.cc @@ -42,6 +42,9 @@ extern "C" { #include "DEG_depsgraph_build.h" #include "intern/depsgraph_intern.h" +#include "intern/nodes/deg_node_id.h" +#include "intern/nodes/deg_node_time.h" + #include "util/deg_util_foreach.h" bool DEG_debug_compare(const struct Depsgraph *graph1, diff --git a/source/blender/depsgraph/intern/depsgraph_eval.cc b/source/blender/depsgraph/intern/depsgraph_eval.cc index 2ed403c463a..0603e467192 100644 --- a/source/blender/depsgraph/intern/depsgraph_eval.cc +++ b/source/blender/depsgraph/intern/depsgraph_eval.cc @@ -48,6 +48,7 @@ extern "C" { #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_operation.h" +#include "intern/nodes/deg_node_time.h" #include "intern/depsgraph.h" diff --git a/source/blender/depsgraph/intern/depsgraph_query.cc b/source/blender/depsgraph/intern/depsgraph_query.cc index 6892bdaa178..98bf335f89e 100644 --- a/source/blender/depsgraph/intern/depsgraph_query.cc +++ b/source/blender/depsgraph/intern/depsgraph_query.cc @@ -46,6 +46,7 @@ extern "C" { #include "DEG_depsgraph_query.h" #include "intern/depsgraph_intern.h" +#include "intern/nodes/deg_node_id.h" bool DEG_id_type_tagged(Main *bmain, short id_type) { diff --git a/source/blender/depsgraph/intern/depsgraph_query_foreach.cc b/source/blender/depsgraph/intern/depsgraph_query_foreach.cc index b1353f528bc..e6692cf49b3 100644 --- a/source/blender/depsgraph/intern/depsgraph_query_foreach.cc +++ b/source/blender/depsgraph/intern/depsgraph_query_foreach.cc @@ -50,6 +50,7 @@ extern "C" { #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_component.h" +#include "intern/nodes/deg_node_id.h" #include "intern/nodes/deg_node_operation.h" #include "util/deg_util_foreach.h" diff --git a/source/blender/depsgraph/intern/depsgraph_query_iter.cc b/source/blender/depsgraph/intern/depsgraph_query_iter.cc index a7f37575ff6..2a323fe63bd 100644 --- a/source/blender/depsgraph/intern/depsgraph_query_iter.cc +++ b/source/blender/depsgraph/intern/depsgraph_query_iter.cc @@ -50,6 +50,8 @@ extern "C" { #include "intern/depsgraph_intern.h" #include "util/deg_util_foreach.h" +#include "intern/nodes/deg_node_id.h" + #ifndef NDEBUG # include "intern/eval/deg_eval_copy_on_write.h" #endif diff --git a/source/blender/depsgraph/intern/depsgraph_tag.cc b/source/blender/depsgraph/intern/depsgraph_tag.cc index e0a424883f5..2255e1ce1b9 100644 --- a/source/blender/depsgraph/intern/depsgraph_tag.cc +++ b/source/blender/depsgraph/intern/depsgraph_tag.cc @@ -64,6 +64,7 @@ extern "C" { #include "intern/eval/deg_eval_flush.h" #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_component.h" +#include "intern/nodes/deg_node_id.h" #include "intern/nodes/deg_node_operation.h" #include "intern/depsgraph_intern.h" diff --git a/source/blender/depsgraph/intern/eval/deg_eval.cc b/source/blender/depsgraph/intern/eval/deg_eval.cc index 5aebd6814a0..583261024ee 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval.cc @@ -48,18 +48,13 @@ #include "intern/eval/deg_eval_flush.h" #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_component.h" +#include "intern/nodes/deg_node_id.h" #include "intern/nodes/deg_node_operation.h" +#include "intern/nodes/deg_node_time.h" #include "intern/depsgraph.h" #include "intern/depsgraph_intern.h" -#include "util/deg_util_foreach.h" - -/* Unfinished and unused, and takes quite some pre-processing time. */ -#undef USE_EVAL_PRIORITY -/* Use integrated debugger to keep track how much each of the nodes was - * evaluating. - */ -#undef USE_DEBUGGER +#include "util/deg_util_foreach.h" namespace DEG { @@ -103,22 +98,8 @@ static void deg_task_run_func(TaskPool *pool, * but that's all fine, we'll just scheduler it's children. */ if (node->evaluate) { - /* Take note of current time. */ -#ifdef USE_DEBUGGER - double start_time = PIL_check_seconds_timer(); - DepsgraphDebug::task_started(state->graph, node); -#endif - /* Perform operation. */ node->evaluate(state->eval_ctx); - - /* Note how long this took. */ -#ifdef USE_DEBUGGER - double end_time = PIL_check_seconds_timer(); - DepsgraphDebug::task_completed(state->graph, - node, - end_time - start_time); -#endif } BLI_task_pool_delayed_push_begin(pool, thread_id); @@ -167,33 +148,6 @@ static void calculate_pending_parents(Depsgraph *graph) do_threads); } -#ifdef USE_EVAL_PRIORITY -static void calculate_eval_priority(OperationDepsNode *node) -{ - if (node->done) { - return; - } - node->done = 1; - - if (node->flag & DEPSOP_FLAG_NEEDS_UPDATE) { - /* XXX standard cost of a node, could be estimated somewhat later on */ - const float cost = 1.0f; - /* NOOP nodes have no cost */ - node->eval_priority = node->is_noop() ? cost : 0.0f; - - foreach (DepsRelation *rel, node->outlinks) { - OperationDepsNode *to = (OperationDepsNode *)rel->to; - BLI_assert(to->type == DEG_NODE_TYPE_OPERATION); - calculate_eval_priority(to); - node->eval_priority += to->eval_priority; - } - } - else { - node->eval_priority = 0.0f; - } -} -#endif - /* Schedule a node if it needs evaluation. * dec_parents: Decrement pending parents count, true when child nodes are * scheduled after a task has been completed. @@ -307,13 +261,6 @@ void deg_evaluate_on_refresh(EvaluationContext *eval_ctx, node->done = 0; } - /* Calculate priority for operation nodes. */ -#ifdef USE_EVAL_PRIORITY - foreach (OperationDepsNode *node, graph->operations) { - calculate_eval_priority(node); - } -#endif - schedule_graph(task_pool, graph); BLI_task_pool_work_and_wait(task_pool); diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc index 00406cc8342..abd17616584 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc @@ -80,6 +80,7 @@ extern "C" { #include "intern/depsgraph.h" #include "intern/builder/deg_builder_nodes.h" #include "intern/nodes/deg_node.h" +#include "intern/nodes/deg_node_id.h" namespace DEG { diff --git a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc index 0362313b484..af1d09ad54a 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc @@ -47,6 +47,7 @@ extern "C" { #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_component.h" +#include "intern/nodes/deg_node_id.h" #include "intern/nodes/deg_node_operation.h" #include "intern/depsgraph_intern.h" diff --git a/source/blender/depsgraph/intern/nodes/deg_node.cc b/source/blender/depsgraph/intern/nodes/deg_node.cc index de340907114..8a9eb0b1169 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node.cc +++ b/source/blender/depsgraph/intern/nodes/deg_node.cc @@ -49,8 +49,11 @@ extern "C" { #include "intern/eval/deg_eval_copy_on_write.h" #include "intern/nodes/deg_node_component.h" +#include "intern/nodes/deg_node_id.h" #include "intern/nodes/deg_node_operation.h" +#include "intern/nodes/deg_node_time.h" #include "intern/depsgraph_intern.h" + #include "util/deg_util_foreach.h" #include "util/deg_util_function.h" @@ -103,186 +106,11 @@ string DepsNode::identifier() const return string(typebuf) + " : " + name; } -/* ************* */ /* Generic Nodes */ -/* Time Source Node ============================================== */ - -void TimeSourceDepsNode::tag_update(Depsgraph *graph) -{ - foreach (DepsRelation *rel, outlinks) { - DepsNode *node = rel->to; - node->tag_update(graph); - } -} - -/* Time Source Node ======================================= */ - DEG_DEPSNODE_DEFINE(TimeSourceDepsNode, DEG_NODE_TYPE_TIMESOURCE, "Time Source"); static DepsNodeFactoryImpl<TimeSourceDepsNode> DNTI_TIMESOURCE; -/* ID Node ================================================ */ - -IDDepsNode::ComponentIDKey::ComponentIDKey(eDepsNode_Type type, - const char *name) - : type(type), name(name) -{ -} - -bool IDDepsNode::ComponentIDKey::operator== (const ComponentIDKey &other) const -{ - return type == other.type && - STREQ(name, other.name); -} - -static unsigned int id_deps_node_hash_key(const void *key_v) -{ - const IDDepsNode::ComponentIDKey *key = - reinterpret_cast<const IDDepsNode::ComponentIDKey *>(key_v); - return BLI_ghashutil_combine_hash(BLI_ghashutil_uinthash(key->type), - BLI_ghashutil_strhash_p(key->name)); -} - -static bool id_deps_node_hash_key_cmp(const void *a, const void *b) -{ - const IDDepsNode::ComponentIDKey *key_a = - reinterpret_cast<const IDDepsNode::ComponentIDKey *>(a); - const IDDepsNode::ComponentIDKey *key_b = - reinterpret_cast<const IDDepsNode::ComponentIDKey *>(b); - return !(*key_a == *key_b); -} - -static void id_deps_node_hash_key_free(void *key_v) -{ - typedef IDDepsNode::ComponentIDKey ComponentIDKey; - ComponentIDKey *key = reinterpret_cast<ComponentIDKey *>(key_v); - OBJECT_GUARDED_DELETE(key, ComponentIDKey); -} - -static void id_deps_node_hash_value_free(void *value_v) -{ - ComponentDepsNode *comp_node = reinterpret_cast<ComponentDepsNode *>(value_v); - OBJECT_GUARDED_DELETE(comp_node, ComponentDepsNode); -} - -/* Initialize 'id' node - from pointer data given. */ -void IDDepsNode::init(const ID *id, const char *UNUSED(subdata)) -{ - BLI_assert(id != NULL); - /* Store ID-pointer. */ - id_orig = (ID *)id; - eval_flags = 0; - linked_state = DEG_ID_LINKED_INDIRECTLY; - - components = BLI_ghash_new(id_deps_node_hash_key, - id_deps_node_hash_key_cmp, - "Depsgraph id components hash"); -} - -void IDDepsNode::init_copy_on_write(ID *id_cow_hint) -{ - /* Early output for non-copy-on-write case: we keep CoW pointer same as - * an original one. - */ - if (!DEG_depsgraph_use_copy_on_write()) { - UNUSED_VARS(id_cow_hint); - id_cow = id_orig; - return; - } - /* Create pointer as early as possible, so we can use it for function - * bindings. Rest of data we'll be copying to the new datablock when - * it is actually needed. - */ - if (id_cow_hint != NULL) { - // BLI_assert(deg_copy_on_write_is_needed(id_orig)); - if (deg_copy_on_write_is_needed(id_orig)) { - id_cow = id_cow_hint; - } - else { - id_cow = id_orig; - } - } - else if (deg_copy_on_write_is_needed(id_orig)) { - id_cow = (ID *)BKE_libblock_alloc_notest(GS(id_orig->name)); - DEG_COW_PRINT("Create shallow copy for %s: id_orig=%p id_cow=%p\n", - id_orig->name, id_orig, id_cow); - deg_tag_copy_on_write_id(id_cow, id_orig); - } - else { - id_cow = id_orig; - } -} - -/* Free 'id' node. */ -IDDepsNode::~IDDepsNode() -{ - destroy(); -} - -void IDDepsNode::destroy() -{ - if (id_orig == NULL) { - return; - } - - BLI_ghash_free(components, - id_deps_node_hash_key_free, - id_deps_node_hash_value_free); - - /* Free memory used by this CoW ID. */ - if (id_cow != id_orig && id_cow != NULL) { - deg_free_copy_on_write_datablock(id_cow); - MEM_freeN(id_cow); - DEG_COW_PRINT("Destroy CoW for %s: id_orig=%p id_cow=%p\n", - id_orig->name, id_orig, id_cow); - } - - /* Tag that the node is freed. */ - id_orig = NULL; -} - -ComponentDepsNode *IDDepsNode::find_component(eDepsNode_Type type, - const char *name) const -{ - ComponentIDKey key(type, name); - return reinterpret_cast<ComponentDepsNode *>(BLI_ghash_lookup(components, &key)); -} - -ComponentDepsNode *IDDepsNode::add_component(eDepsNode_Type type, - const char *name) -{ - ComponentDepsNode *comp_node = find_component(type, name); - if (!comp_node) { - DepsNodeFactory *factory = deg_type_get_factory(type); - comp_node = (ComponentDepsNode *)factory->create_node(this->id_orig, "", name); - - /* Register. */ - ComponentIDKey *key = OBJECT_GUARDED_NEW(ComponentIDKey, type, name); - BLI_ghash_insert(components, key, comp_node); - comp_node->owner = this; - } - return comp_node; -} - -void IDDepsNode::tag_update(Depsgraph *graph) -{ - GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp_node, components) - { - comp_node->tag_update(graph); - } - GHASH_FOREACH_END(); -} - -void IDDepsNode::finalize_build(Depsgraph *graph) -{ - /* Finalize build of all components. */ - GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp_node, components) - { - comp_node->finalize_build(graph); - } - GHASH_FOREACH_END(); -} - DEG_DEPSNODE_DEFINE(IDDepsNode, DEG_NODE_TYPE_ID_REF, "ID Node"); static DepsNodeFactoryImpl<IDDepsNode> DNTI_ID_REF; diff --git a/source/blender/depsgraph/intern/nodes/deg_node.h b/source/blender/depsgraph/intern/nodes/deg_node.h index c699de67eda..54042ae4a1b 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node.h +++ b/source/blender/depsgraph/intern/nodes/deg_node.h @@ -109,68 +109,6 @@ struct DepsNode { #define DEG_DEPSNODE_DEFINE(NodeType, type_, tname_) \ const DepsNode::TypeInfo NodeType::typeinfo = DepsNode::TypeInfo(type_, tname_) -/* Generic Nodes ======================= */ - -struct ComponentDepsNode; -struct IDDepsNode; - -/* Time Source Node. */ -struct TimeSourceDepsNode : public DepsNode { - /* New "current time". */ - float cfra; - - /* time-offset relative to the "official" time source that this one has. */ - float offset; - - // TODO: evaluate() operation needed - - void tag_update(Depsgraph *graph); - - DEG_DEPSNODE_DECLARE; -}; - -/* ID-Block Reference */ -struct IDDepsNode : public DepsNode { - struct ComponentIDKey { - ComponentIDKey(eDepsNode_Type type, const char *name = ""); - bool operator==(const ComponentIDKey &other) const; - - eDepsNode_Type type; - const char *name; - }; - - void init(const ID *id, const char *subdata); - void init_copy_on_write(ID *id_cow_hint = NULL); - ~IDDepsNode(); - void destroy(); - - ComponentDepsNode *find_component(eDepsNode_Type type, - const char *name = "") const; - ComponentDepsNode *add_component(eDepsNode_Type type, - const char *name = ""); - - void tag_update(Depsgraph *graph); - - void finalize_build(Depsgraph *graph); - - /* ID Block referenced. */ - ID *id_orig; - ID *id_cow; - - /* Hash to make it faster to look up components. */ - GHash *components; - - /* Additional flags needed for scene evaluation. - * TODO(sergey): Only needed for until really granular updates - * of all the entities. - */ - int eval_flags; - - eDepsNode_LinkedState_Type linked_state; - - DEG_DEPSNODE_DECLARE; -}; - void deg_register_base_depsnodes(); } // namespace DEG diff --git a/source/blender/depsgraph/intern/nodes/deg_node_component.cc b/source/blender/depsgraph/intern/nodes/deg_node_component.cc index 9d2a8dd6808..1f56edd1f87 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node_component.cc +++ b/source/blender/depsgraph/intern/nodes/deg_node_component.cc @@ -42,6 +42,7 @@ extern "C" { #include "BKE_action.h" } /* extern "C" */ +#include "intern/nodes/deg_node_id.h" #include "intern/nodes/deg_node_operation.h" #include "intern/depsgraph_intern.h" #include "util/deg_util_foreach.h" diff --git a/source/blender/depsgraph/intern/nodes/deg_node_component.h b/source/blender/depsgraph/intern/nodes/deg_node_component.h index 882a16adf82..8c747bc3e32 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node_component.h +++ b/source/blender/depsgraph/intern/nodes/deg_node_component.h @@ -46,6 +46,7 @@ namespace DEG { struct Depsgraph; struct OperationDepsNode; struct BoneComponentDepsNode; +struct IDDepsNode; /* ID Component - Base type for all components */ struct ComponentDepsNode : public DepsNode { diff --git a/source/blender/depsgraph/intern/nodes/deg_node_id.cc b/source/blender/depsgraph/intern/nodes/deg_node_id.cc new file mode 100644 index 00000000000..572b421bdee --- /dev/null +++ b/source/blender/depsgraph/intern/nodes/deg_node_id.cc @@ -0,0 +1,219 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * Original Author: Joshua Leung + * Contributor(s): None Yet + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/depsgraph/intern/nodes/deg_node_id.cc + * \ingroup depsgraph + */ + +#include "intern/nodes/deg_node_id.h" + +#include <stdio.h> +#include <cstring> /* required for STREQ later on. */ + +#include "BLI_utildefines.h" +#include "BLI_ghash.h" + +extern "C" { +#include "DNA_ID.h" +#include "DNA_anim_types.h" + +#include "BKE_animsys.h" +#include "BKE_library.h" +} + +#include "DEG_depsgraph.h" + +#include "intern/eval/deg_eval_copy_on_write.h" +#include "intern/nodes/deg_node_component.h" +#include "intern/nodes/deg_node_operation.h" +#include "intern/nodes/deg_node_time.h" +#include "intern/depsgraph_intern.h" + +#include "util/deg_util_foreach.h" + +namespace DEG { + +IDDepsNode::ComponentIDKey::ComponentIDKey(eDepsNode_Type type, + const char *name) + : type(type), name(name) +{ +} + +bool IDDepsNode::ComponentIDKey::operator== (const ComponentIDKey &other) const +{ + return type == other.type && + STREQ(name, other.name); +} + +static unsigned int id_deps_node_hash_key(const void *key_v) +{ + const IDDepsNode::ComponentIDKey *key = + reinterpret_cast<const IDDepsNode::ComponentIDKey *>(key_v); + return BLI_ghashutil_combine_hash(BLI_ghashutil_uinthash(key->type), + BLI_ghashutil_strhash_p(key->name)); +} + +static bool id_deps_node_hash_key_cmp(const void *a, const void *b) +{ + const IDDepsNode::ComponentIDKey *key_a = + reinterpret_cast<const IDDepsNode::ComponentIDKey *>(a); + const IDDepsNode::ComponentIDKey *key_b = + reinterpret_cast<const IDDepsNode::ComponentIDKey *>(b); + return !(*key_a == *key_b); +} + +static void id_deps_node_hash_key_free(void *key_v) +{ + typedef IDDepsNode::ComponentIDKey ComponentIDKey; + ComponentIDKey *key = reinterpret_cast<ComponentIDKey *>(key_v); + OBJECT_GUARDED_DELETE(key, ComponentIDKey); +} + +static void id_deps_node_hash_value_free(void *value_v) +{ + ComponentDepsNode *comp_node = reinterpret_cast<ComponentDepsNode *>(value_v); + OBJECT_GUARDED_DELETE(comp_node, ComponentDepsNode); +} + +/* Initialize 'id' node - from pointer data given. */ +void IDDepsNode::init(const ID *id, const char *UNUSED(subdata)) +{ + BLI_assert(id != NULL); + /* Store ID-pointer. */ + id_orig = (ID *)id; + eval_flags = 0; + linked_state = DEG_ID_LINKED_INDIRECTLY; + + components = BLI_ghash_new(id_deps_node_hash_key, + id_deps_node_hash_key_cmp, + "Depsgraph id components hash"); +} + +void IDDepsNode::init_copy_on_write(ID *id_cow_hint) +{ + /* Early output for non-copy-on-write case: we keep CoW pointer same as + * an original one. + */ + if (!DEG_depsgraph_use_copy_on_write()) { + UNUSED_VARS(id_cow_hint); + id_cow = id_orig; + return; + } + /* Create pointer as early as possible, so we can use it for function + * bindings. Rest of data we'll be copying to the new datablock when + * it is actually needed. + */ + if (id_cow_hint != NULL) { + // BLI_assert(deg_copy_on_write_is_needed(id_orig)); + if (deg_copy_on_write_is_needed(id_orig)) { + id_cow = id_cow_hint; + } + else { + id_cow = id_orig; + } + } + else if (deg_copy_on_write_is_needed(id_orig)) { + id_cow = (ID *)BKE_libblock_alloc_notest(GS(id_orig->name)); + DEG_COW_PRINT("Create shallow copy for %s: id_orig=%p id_cow=%p\n", + id_orig->name, id_orig, id_cow); + deg_tag_copy_on_write_id(id_cow, id_orig); + } + else { + id_cow = id_orig; + } +} + +/* Free 'id' node. */ +IDDepsNode::~IDDepsNode() +{ + destroy(); +} + +void IDDepsNode::destroy() +{ + if (id_orig == NULL) { + return; + } + + BLI_ghash_free(components, + id_deps_node_hash_key_free, + id_deps_node_hash_value_free); + + /* Free memory used by this CoW ID. */ + if (id_cow != id_orig && id_cow != NULL) { + deg_free_copy_on_write_datablock(id_cow); + MEM_freeN(id_cow); + DEG_COW_PRINT("Destroy CoW for %s: id_orig=%p id_cow=%p\n", + id_orig->name, id_orig, id_cow); + } + + /* Tag that the node is freed. */ + id_orig = NULL; +} + +ComponentDepsNode *IDDepsNode::find_component(eDepsNode_Type type, + const char *name) const +{ + ComponentIDKey key(type, name); + return reinterpret_cast<ComponentDepsNode *>(BLI_ghash_lookup(components, &key)); +} + +ComponentDepsNode *IDDepsNode::add_component(eDepsNode_Type type, + const char *name) +{ + ComponentDepsNode *comp_node = find_component(type, name); + if (!comp_node) { + DepsNodeFactory *factory = deg_type_get_factory(type); + comp_node = (ComponentDepsNode *)factory->create_node(this->id_orig, "", name); + + /* Register. */ + ComponentIDKey *key = OBJECT_GUARDED_NEW(ComponentIDKey, type, name); + BLI_ghash_insert(components, key, comp_node); + comp_node->owner = this; + } + return comp_node; +} + +void IDDepsNode::tag_update(Depsgraph *graph) +{ + GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp_node, components) + { + comp_node->tag_update(graph); + } + GHASH_FOREACH_END(); +} + +void IDDepsNode::finalize_build(Depsgraph *graph) +{ + /* Finalize build of all components. */ + GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp_node, components) + { + comp_node->finalize_build(graph); + } + GHASH_FOREACH_END(); +} + +} // namespace DEG diff --git a/source/blender/depsgraph/intern/nodes/deg_node_id.h b/source/blender/depsgraph/intern/nodes/deg_node_id.h new file mode 100644 index 00000000000..505a1129192 --- /dev/null +++ b/source/blender/depsgraph/intern/nodes/deg_node_id.h @@ -0,0 +1,81 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * Original Author: Joshua Leung + * Contributor(s): None Yet + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file depsgraph/intern/nodes/deg_node_id.h + * \ingroup depsgraph + */ + +#pragma once + +#include "intern/nodes/deg_node.h" + +namespace DEG { + +struct ComponentDepsNode; + +/* ID-Block Reference */ +struct IDDepsNode : public DepsNode { + struct ComponentIDKey { + ComponentIDKey(eDepsNode_Type type, const char *name = ""); + bool operator==(const ComponentIDKey &other) const; + + eDepsNode_Type type; + const char *name; + }; + + void init(const ID *id, const char *subdata); + void init_copy_on_write(ID *id_cow_hint = NULL); + ~IDDepsNode(); + void destroy(); + + ComponentDepsNode *find_component(eDepsNode_Type type, + const char *name = "") const; + ComponentDepsNode *add_component(eDepsNode_Type type, + const char *name = ""); + + void tag_update(Depsgraph *graph); + + void finalize_build(Depsgraph *graph); + + /* ID Block referenced. */ + ID *id_orig; + ID *id_cow; + + /* Hash to make it faster to look up components. */ + GHash *components; + + /* Additional flags needed for scene evaluation. + * TODO(sergey): Only needed for until really granular updates + * of all the entities. + */ + int eval_flags; + + eDepsNode_LinkedState_Type linked_state; + + DEG_DEPSNODE_DECLARE; +}; + +} // namespace DEG diff --git a/source/blender/depsgraph/intern/nodes/deg_node_operation.cc b/source/blender/depsgraph/intern/nodes/deg_node_operation.cc index 7467264f612..0fc87a52005 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node_operation.cc +++ b/source/blender/depsgraph/intern/nodes/deg_node_operation.cc @@ -37,6 +37,7 @@ #include "intern/depsgraph.h" #include "intern/depsgraph_intern.h" +#include "intern/nodes/deg_node_id.h" namespace DEG { diff --git a/source/blender/depsgraph/intern/nodes/deg_node_operation.h b/source/blender/depsgraph/intern/nodes/deg_node_operation.h index d8203540fc5..ffb95a53b5d 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node_operation.h +++ b/source/blender/depsgraph/intern/nodes/deg_node_operation.h @@ -38,6 +38,8 @@ struct Depsgraph; namespace DEG { +struct ComponentDepsNode; + /* Flags for Depsgraph Nodes */ typedef enum eDepsOperation_Flag { /* node needs to be updated */ diff --git a/source/blender/depsgraph/intern/nodes/deg_node_time.cc b/source/blender/depsgraph/intern/nodes/deg_node_time.cc new file mode 100644 index 00000000000..230488b2328 --- /dev/null +++ b/source/blender/depsgraph/intern/nodes/deg_node_time.cc @@ -0,0 +1,46 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * Original Author: Joshua Leung + * Contributor(s): None Yet + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/depsgraph/intern/nodes/deg_node_time.cc + * \ingroup depsgraph + */ + +#include "intern/nodes/deg_node_time.h" + +#include "intern/depsgraph_intern.h" +#include "util/deg_util_foreach.h" + +namespace DEG { + +void TimeSourceDepsNode::tag_update(Depsgraph *graph) +{ + foreach (DepsRelation *rel, outlinks) { + DepsNode *node = rel->to; + node->tag_update(graph); + } +} + +} // namespace DEG diff --git a/source/blender/depsgraph/intern/nodes/deg_node_time.h b/source/blender/depsgraph/intern/nodes/deg_node_time.h new file mode 100644 index 00000000000..93f3edef9cf --- /dev/null +++ b/source/blender/depsgraph/intern/nodes/deg_node_time.h @@ -0,0 +1,52 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * Original Author: Joshua Leung + * Contributor(s): None Yet + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file depsgraph/intern/nodes/deg_node_time.h + * \ingroup depsgraph + */ + +#pragma once + +#include "intern/nodes/deg_node.h" + +namespace DEG { + +/* Time Source Node. */ +struct TimeSourceDepsNode : public DepsNode { + /* New "current time". */ + float cfra; + + /* time-offset relative to the "official" time source that this one has. */ + float offset; + + // TODO: evaluate() operation needed + + void tag_update(Depsgraph *graph); + + DEG_DEPSNODE_DECLARE; +}; + +} // namespace DEG diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index 3ff3e7d7a21..7c2a171e7d4 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -29,6 +29,14 @@ * ToolTip Region and Construction */ +/* TODO(campbell): + * We may want to have a higher level API that initializes a timer, + * checks for mouse motion and clears the tool-tip afterwards. + * We never want multiple tool-tips at once so this could be handled on the window / window-manager level. + * + * For now it's not a priority, so leave as-is. + */ + #include <stdarg.h> #include <stdlib.h> #include <string.h> @@ -97,7 +105,6 @@ typedef struct uiTooltipField { } uiTooltipField; -#define MAX_TOOLTIP_LINES 8 typedef struct uiTooltipData { rcti bbox; uiTooltipField *fields; @@ -609,8 +616,6 @@ static uiTooltipData *ui_tooltip_data_from_button(bContext *C, uiBut *but) if (rna_prop.strinfo) MEM_freeN(rna_prop.strinfo); - BLI_assert(data->fields_len < MAX_TOOLTIP_LINES); - if (data->fields_len == 0) { MEM_freeN(data); return NULL; |