Blender V4.3
COM_node_operation.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include "BLI_string_ref.hh"
8
9#include "DNA_node_types.h"
10
12
13#include "COM_context.hh"
14#include "COM_operation.hh"
15#include "COM_result.hh"
16#include "COM_scheduler.hh"
17
19
20using namespace nodes::derived_node_tree_types;
21
22/* ------------------------------------------------------------------------------------------------
23 * Node Operation
24 *
25 * A node operation is a subclass of operation that nodes should implement and instantiate in the
26 * get_compositor_operation function of bNodeType, passing the inputs given to that function to the
27 * constructor. This class essentially just implements a default constructor that populates output
28 * results for all outputs of the node as well as input descriptors for all inputs of the nodes
29 * based on their socket declaration. The class also provides some utility methods for easier
30 * implementation of nodes. */
31class NodeOperation : public Operation {
32 private:
33 /* The node that this operation represents. */
34 DNode node_;
35
36 public:
37 /* Populate the output results based on the node outputs and populate the input descriptors based
38 * on the node inputs. */
39 NodeOperation(Context &context, DNode node);
40
41 /* Calls the evaluate method of the operation, but also measures the execution time and stores it
42 * in the context's profile data. */
43 void evaluate() override;
44
45 /* Compute and set the initial reference counts of all the results of the operation. The
46 * reference counts of the results are the number of operations that use those results, which is
47 * computed as the number of inputs whose node is part of the schedule and is linked to the
48 * output corresponding to each result. The node execution schedule is given as an input. */
49 void compute_results_reference_counts(const Schedule &schedule);
50
51 protected:
52 /* Compute a node preview using the result returned from the get_preview_result method. */
53 void compute_preview() override;
54
55 /* Returns a reference to the derived node that this operation represents. */
56 const DNode &node() const;
57
58 /* Returns a reference to the node that this operation represents. */
59 const bNode &bnode() const;
60
61 /* Returns true if the output identified by the given identifier is needed and should be
62 * computed, otherwise returns false. */
63 bool should_compute_output(StringRef identifier);
64
65 private:
66 /* Get the result which will be previewed in the node, this is chosen as the first linked output
67 * of the node, if no outputs exist, then the first allocated input will be chosen. Nullptr is
68 * guaranteed not to be returned, since the node will always either have a linked output or an
69 * allocated input. */
70 Result *get_preview_result();
71};
72
73} // namespace blender::realtime_compositor
NodeOperation(Context &context, DNode node)
void compute_results_reference_counts(const Schedule &schedule)
bool should_compute_output(StringRef identifier)