Blender V5.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 "DNA_node_types.h"
8
9#include "BKE_node.hh"
10
11#include "NOD_warning.hh"
12
13#include "COM_context.hh"
14#include "COM_operation.hh"
15#include "COM_result.hh"
16
17namespace blender {
18class ComputeContext;
19} // namespace blender
20
21namespace blender::compositor {
22
23struct Schedule;
24
25/* ------------------------------------------------------------------------------------------------
26 * Node Operation
27 *
28 * A node operation is a subclass of operation that nodes should implement and instantiate in the
29 * get_compositor_operation function of bNodeType, passing the inputs given to that function to the
30 * constructor. This class essentially just implements a default constructor that populates output
31 * results for all outputs of the node as well as input descriptors for all inputs of the nodes
32 * based on their socket declaration. The class also provides some utility methods for easier
33 * implementation of nodes. */
34class NodeOperation : public Operation {
35 private:
36 /* The node that this operation represents. */
37 const bNode &node_;
38 /* The compute context where this node operation is executing. */
39 const ComputeContext *compute_context_ = nullptr;
40
41 public:
42 /* Populate the output results based on the node outputs and populate the input descriptors based
43 * on the node inputs. */
45
46 /* Calls the evaluate method of the operation, but also measures the execution time and stores it
47 * in the context's profile data. */
48 void evaluate() override;
49
50 /* Compute and set the initial reference counts of all the results of the operation. The node
51 * execution schedule is given as an input. */
52 void compute_results_reference_counts(const Schedule &schedule);
53
54 /* Setter and getter for compute_context_. */
55 void set_compute_context(const ComputeContext &compute_context);
57
58 protected:
59 /* Add a warning of the given type and message to the node. */
60 void add_warning(nodes::NodeWarningType type, std::string message);
61
62 /* Log the values for the inputs and outputs of the node as well as its image preview. */
63 void log_data() override;
64
65 /* Returns a reference to the node that this operation represents. */
66 const bNode &node() const;
67
68 private:
69 /* Get the result which will be previewed in the node, this is chosen as the first linked output
70 * of the node, if no outputs exist, then the first allocated input will be chosen. Returns
71 * nullptr if no result is viewable. */
72 Result *get_preview_result();
73};
74
75} // namespace blender::compositor
NodeOperation(Context &context, const bNode &node)
void add_warning(nodes::NodeWarningType type, std::string message)
void set_compute_context(const ComputeContext &compute_context)
const ComputeContext & get_compute_context() const
void compute_results_reference_counts(const Schedule &schedule)
Operation(Context &context)
Definition operation.cc:22
Context & context() const
Definition operation.cc:57
BMesh Iterators.