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:
authorSergey Sharybin <sergey.vfx@gmail.com>2019-09-06 18:00:09 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2019-09-11 11:43:27 +0300
commit022de797f1773f512f21cf9038787dd77e0fd5de (patch)
treecc428b1a778d5a76c7ea931c5d10cb65a80dc7f0 /source/blender
parent73a199e96a68a5b9521ba7d3e8cca85697095c03 (diff)
Depsgraph: Introduce depsgraph registry
Allows to access dependency graphs created for render engines to inform them about changes in .blend file structure from the Python handlers. Reviewers: brecht Differential Revision: https://developer.blender.org/D5724
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/depsgraph/CMakeLists.txt2
-rw-r--r--source/blender/depsgraph/intern/depsgraph.cc9
-rw-r--r--source/blender/depsgraph/intern/depsgraph_registry.cc74
-rw-r--r--source/blender/depsgraph/intern/depsgraph_registry.h38
-rw-r--r--source/blender/depsgraph/intern/depsgraph_tag.cc29
5 files changed, 128 insertions, 24 deletions
diff --git a/source/blender/depsgraph/CMakeLists.txt b/source/blender/depsgraph/CMakeLists.txt
index 49c510d9d3e..21ab148496c 100644
--- a/source/blender/depsgraph/CMakeLists.txt
+++ b/source/blender/depsgraph/CMakeLists.txt
@@ -73,6 +73,7 @@ set(SRC
intern/depsgraph_query.cc
intern/depsgraph_query_foreach.cc
intern/depsgraph_query_iter.cc
+ intern/depsgraph_registry.cc
intern/depsgraph_tag.cc
intern/depsgraph_type.cc
intern/depsgraph_update.cc
@@ -107,6 +108,7 @@ set(SRC
intern/node/deg_node_time.h
intern/depsgraph.h
intern/depsgraph_physics.h
+ intern/depsgraph_registry.h
intern/depsgraph_tag.h
intern/depsgraph_type.h
intern/depsgraph_update.h
diff --git a/source/blender/depsgraph/intern/depsgraph.cc b/source/blender/depsgraph/intern/depsgraph.cc
index 6e98907597b..dcdea87fe1a 100644
--- a/source/blender/depsgraph/intern/depsgraph.cc
+++ b/source/blender/depsgraph/intern/depsgraph.cc
@@ -45,6 +45,8 @@ extern "C" {
#include "DEG_depsgraph_debug.h"
#include "intern/depsgraph_update.h"
+#include "intern/depsgraph_physics.h"
+#include "intern/depsgraph_registry.h"
#include "intern/eval/deg_eval_copy_on_write.h"
@@ -55,8 +57,6 @@ extern "C" {
#include "intern/node/deg_node_operation.h"
#include "intern/node/deg_node_time.h"
-#include "intern/depsgraph_physics.h"
-
namespace DEG {
/* TODO(sergey): Find a better place for this. */
@@ -318,14 +318,19 @@ Depsgraph *DEG_graph_new(Main *bmain, Scene *scene, ViewLayer *view_layer, eEval
{
DEG::Depsgraph *deg_depsgraph = OBJECT_GUARDED_NEW(
DEG::Depsgraph, bmain, scene, view_layer, mode);
+ DEG::register_graph(deg_depsgraph);
return reinterpret_cast<Depsgraph *>(deg_depsgraph);
}
/* Free graph's contents and graph itself */
void DEG_graph_free(Depsgraph *graph)
{
+ if (graph == NULL) {
+ return;
+ }
using DEG::Depsgraph;
DEG::Depsgraph *deg_depsgraph = reinterpret_cast<DEG::Depsgraph *>(graph);
+ DEG::unregister_graph(deg_depsgraph);
OBJECT_GUARDED_DELETE(deg_depsgraph, Depsgraph);
}
diff --git a/source/blender/depsgraph/intern/depsgraph_registry.cc b/source/blender/depsgraph/intern/depsgraph_registry.cc
new file mode 100644
index 00000000000..ad60b1bc4cf
--- /dev/null
+++ b/source/blender/depsgraph/intern/depsgraph_registry.cc
@@ -0,0 +1,74 @@
+/*
+ * 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) 2019 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup depsgraph
+ */
+
+#include "intern/depsgraph_registry.h"
+
+#include "BLI_utildefines.h"
+
+#include "intern/depsgraph.h"
+
+namespace DEG {
+
+typedef set<Depsgraph *> DepsgraphStorage;
+typedef map<Main *, DepsgraphStorage> MainDepsgraphMap;
+
+static MainDepsgraphMap g_graph_registry;
+
+void register_graph(Depsgraph *depsgraph)
+{
+ Main *bmain = depsgraph->bmain;
+ MainDepsgraphMap::iterator it = g_graph_registry.find(bmain);
+ if (it == g_graph_registry.end()) {
+ it = g_graph_registry.insert(make_pair(bmain, DepsgraphStorage())).first;
+ }
+ DepsgraphStorage &storage = it->second;
+ storage.insert(depsgraph);
+}
+
+void unregister_graph(Depsgraph *depsgraph)
+{
+ Main *bmain = depsgraph->bmain;
+ MainDepsgraphMap::iterator it = g_graph_registry.find(bmain);
+ BLI_assert(it != g_graph_registry.end());
+
+ // Remove dependency graph from storage.
+ DepsgraphStorage &storage = it->second;
+ storage.erase(depsgraph);
+
+ // If this was the last depsgraph associated with the main, remove the main entry as well.
+ if (storage.empty()) {
+ g_graph_registry.erase(bmain);
+ }
+}
+
+const set<Depsgraph *> &get_all_registered_graphs(Main *bmain)
+{
+ MainDepsgraphMap::iterator it = g_graph_registry.find(bmain);
+ if (it == g_graph_registry.end()) {
+ static DepsgraphStorage empty_storage;
+ return empty_storage;
+ }
+ return it->second;
+}
+
+} // namespace DEG
diff --git a/source/blender/depsgraph/intern/depsgraph_registry.h b/source/blender/depsgraph/intern/depsgraph_registry.h
new file mode 100644
index 00000000000..7517b6a0b2a
--- /dev/null
+++ b/source/blender/depsgraph/intern/depsgraph_registry.h
@@ -0,0 +1,38 @@
+/*
+ * 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) 2019 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup depsgraph
+ */
+
+#pragma once
+
+#include "intern/depsgraph_type.h"
+
+struct Main;
+
+namespace DEG {
+
+struct Depsgraph;
+
+void register_graph(Depsgraph *depsgraph);
+void unregister_graph(Depsgraph *depsgraph);
+const set<Depsgraph *> &get_all_registered_graphs(Main *bmain);
+
+} // namespace DEG
diff --git a/source/blender/depsgraph/intern/depsgraph_tag.cc b/source/blender/depsgraph/intern/depsgraph_tag.cc
index fd74529a30d..2fdce0e30a5 100644
--- a/source/blender/depsgraph/intern/depsgraph_tag.cc
+++ b/source/blender/depsgraph/intern/depsgraph_tag.cc
@@ -30,7 +30,6 @@
#include <queue>
#include "BLI_utildefines.h"
-#include "BLI_listbase.h"
#include "BLI_math_bits.h"
#include "BLI_task.h"
@@ -64,6 +63,7 @@ extern "C" {
#include "intern/builder/deg_builder.h"
#include "intern/depsgraph.h"
#include "intern/depsgraph_update.h"
+#include "intern/depsgraph_registry.h"
#include "intern/eval/deg_eval_copy_on_write.h"
#include "intern/eval/deg_eval_flush.h"
#include "intern/node/deg_node.h"
@@ -605,13 +605,8 @@ NodeType geometry_tag_to_component(const ID *id)
void id_tag_update(Main *bmain, ID *id, int flag, eUpdateSource update_source)
{
graph_id_tag_update(bmain, NULL, id, flag, update_source);
- LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
- LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
- Depsgraph *depsgraph = (Depsgraph *)BKE_scene_get_depsgraph(bmain, scene, view_layer, false);
- if (depsgraph != NULL) {
- graph_id_tag_update(bmain, depsgraph, id, flag, update_source);
- }
- }
+ for (DEG::Depsgraph *depsgraph : DEG::get_all_registered_graphs(bmain)) {
+ graph_id_tag_update(bmain, depsgraph, id, flag, update_source);
}
}
@@ -769,13 +764,8 @@ void DEG_graph_id_type_tag(Depsgraph *depsgraph, short id_type)
void DEG_id_type_tag(Main *bmain, short id_type)
{
- LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
- LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
- Depsgraph *depsgraph = (Depsgraph *)BKE_scene_get_depsgraph(bmain, scene, view_layer, false);
- if (depsgraph != NULL) {
- DEG_graph_id_type_tag(depsgraph, id_type);
- }
- }
+ for (DEG::Depsgraph *depsgraph : DEG::get_all_registered_graphs(bmain)) {
+ DEG_graph_id_type_tag(reinterpret_cast<::Depsgraph *>(depsgraph), id_type);
}
}
@@ -788,13 +778,8 @@ void DEG_graph_on_visible_update(Main *bmain, Depsgraph *depsgraph, const bool d
void DEG_on_visible_update(Main *bmain, const bool do_time)
{
- LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
- LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
- Depsgraph *depsgraph = (Depsgraph *)BKE_scene_get_depsgraph(bmain, scene, view_layer, false);
- if (depsgraph != NULL) {
- DEG_graph_on_visible_update(bmain, depsgraph, do_time);
- }
- }
+ for (DEG::Depsgraph *depsgraph : DEG::get_all_registered_graphs(bmain)) {
+ DEG_graph_on_visible_update(bmain, reinterpret_cast<::Depsgraph *>(depsgraph), do_time);
}
}