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"
41 #include "DNA_scene_types.h"
44 #include "DEG_depsgraph.h"
46 #include "intern/eval/deg_eval.h"
47 #include "intern/eval/deg_eval_flush.h"
49 #include "intern/nodes/deg_node.h"
50 #include "intern/nodes/deg_node_operation.h"
51 #include "intern/nodes/deg_node_time.h"
53 #include "intern/depsgraph.h"
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 ViewLayer *view_layer,
82 RenderEngineType *engine_type,
85 DEG_evaluation_context_init(eval_ctx, mode);
86 eval_ctx->depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true);
87 eval_ctx->view_layer = view_layer;
88 eval_ctx->engine_type = engine_type;
89 eval_ctx->ctime = BKE_scene_frame_get(scene);
92 /* Free evaluation context. */
93 void DEG_evaluation_context_free(EvaluationContext *eval_ctx)
98 /* Evaluate all nodes tagged for updating. */
99 void DEG_evaluate_on_refresh(EvaluationContext *eval_ctx,
102 DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
103 /* Update time on primary timesource. */
104 DEG::TimeSourceDepsNode *tsrc = deg_graph->find_time_source();
105 tsrc->cfra = BKE_scene_frame_get(deg_graph->scene);
106 DEG::deg_evaluate_on_refresh(eval_ctx, deg_graph);
109 /* Frame-change happened for root scene that graph belongs to. */
110 void DEG_evaluate_on_framechange(EvaluationContext *eval_ctx,
115 DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
116 /* Update time on primary timesource. */
117 DEG::TimeSourceDepsNode *tsrc = deg_graph->find_time_source();
119 tsrc->tag_update(deg_graph);
120 DEG::deg_graph_flush_updates(bmain, deg_graph);
121 /* Perform recalculation updates. */
122 DEG::deg_evaluate_on_refresh(eval_ctx, deg_graph);
125 bool DEG_needs_eval(Depsgraph *graph)
127 DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
128 return BLI_gset_size(deg_graph->entry_tags) != 0;