2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2013 Blender Foundation.
19 * All rights reserved.
21 * Original Author: Joshua Leung
22 * Contributor(s): None Yet
24 * ***** END GPL LICENSE BLOCK *****
27 /** \file blender/depsgraph/intern/depsgraph_eval.cc
30 * Evaluation engine entrypoints for Depsgraph Engine.
33 #include "MEM_guardedalloc.h"
35 #include "BLI_utildefines.h"
36 #include "BLI_ghash.h"
39 #include "BKE_scene.h"
42 #include "DEG_depsgraph.h"
44 #include "intern/eval/deg_eval.h"
45 #include "intern/eval/deg_eval_flush.h"
47 #include "intern/nodes/deg_node.h"
48 #include "intern/nodes/deg_node_operation.h"
50 #include "intern/depsgraph.h"
52 /* Unfinished and unused, and takes quite some pre-processing time. */
53 #undef USE_EVAL_PRIORITY
55 /* ****************** */
56 /* Evaluation Context */
58 /* Create new evaluation context. */
59 EvaluationContext *DEG_evaluation_context_new(eEvaluationMode mode)
61 EvaluationContext *eval_ctx =
62 (EvaluationContext *)MEM_callocN(sizeof(EvaluationContext),
64 DEG_evaluation_context_init(eval_ctx, mode);
69 * Initialize evaluation context.
70 * Used by the areas which currently overrides the context or doesn't have
71 * access to a proper one.
73 void DEG_evaluation_context_init(EvaluationContext *eval_ctx,
76 eval_ctx->mode = mode;
79 void DEG_evaluation_context_init_from_scene(EvaluationContext *eval_ctx,
81 SceneLayer *scene_layer,
84 DEG_evaluation_context_init(eval_ctx, mode);
85 eval_ctx->scene_layer = scene_layer;
86 eval_ctx->ctime = BKE_scene_frame_get(scene);
89 /* Free evaluation context. */
90 void DEG_evaluation_context_free(EvaluationContext *eval_ctx)
95 /* Evaluate all nodes tagged for updating. */
96 void DEG_evaluate_on_refresh(EvaluationContext *eval_ctx,
100 DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
101 /* Update time on primary timesource. */
102 DEG::TimeSourceDepsNode *tsrc = deg_graph->find_time_source();
103 tsrc->cfra = BKE_scene_frame_get(scene);
104 DEG::deg_evaluate_on_refresh(eval_ctx, deg_graph);
107 /* Frame-change happened for root scene that graph belongs to. */
108 void DEG_evaluate_on_framechange(EvaluationContext *eval_ctx,
113 DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
114 /* Update time on primary timesource. */
115 DEG::TimeSourceDepsNode *tsrc = deg_graph->find_time_source();
117 tsrc->tag_update(deg_graph);
118 DEG::deg_graph_flush_updates(bmain, deg_graph);
119 /* Perform recalculation updates. */
120 DEG::deg_evaluate_on_refresh(eval_ctx, deg_graph);
123 bool DEG_needs_eval(Depsgraph *graph)
125 DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
126 return BLI_gset_size(deg_graph->entry_tags) != 0;