2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2022-08-10 09:14:22 +02:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "BLI_string_ref.hh"
|
|
|
|
|
|
|
|
|
|
#include "DNA_node_types.h"
|
|
|
|
|
|
|
|
|
|
#include "NOD_derived_node_tree.hh"
|
|
|
|
|
|
|
|
|
|
#include "COM_context.hh"
|
|
|
|
|
#include "COM_operation.hh"
|
2023-06-21 05:41:49 +02:00
|
|
|
#include "COM_result.hh"
|
2022-08-10 09:14:22 +02:00
|
|
|
#include "COM_scheduler.hh"
|
|
|
|
|
|
2024-12-17 11:39:04 +01:00
|
|
|
namespace blender::compositor {
|
2022-08-10 09:14:22 +02:00
|
|
|
|
|
|
|
|
using namespace nodes::derived_node_tree_types;
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
|
* Node Operation
|
|
|
|
|
*
|
|
|
|
|
* A node operation is a subclass of operation that nodes should implement and instantiate in the
|
|
|
|
|
* get_compositor_operation function of bNodeType, passing the inputs given to that function to the
|
|
|
|
|
* constructor. This class essentially just implements a default constructor that populates output
|
|
|
|
|
* results for all outputs of the node as well as input descriptors for all inputs of the nodes
|
|
|
|
|
* based on their socket declaration. The class also provides some utility methods for easier
|
|
|
|
|
* implementation of nodes. */
|
|
|
|
|
class NodeOperation : public Operation {
|
|
|
|
|
private:
|
|
|
|
|
/* The node that this operation represents. */
|
|
|
|
|
DNode node_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/* Populate the output results based on the node outputs and populate the input descriptors based
|
|
|
|
|
* on the node inputs. */
|
|
|
|
|
NodeOperation(Context &context, DNode node);
|
|
|
|
|
|
2024-05-28 08:13:46 +02:00
|
|
|
/* Calls the evaluate method of the operation, but also measures the execution time and stores it
|
|
|
|
|
* in the context's profile data. */
|
|
|
|
|
void evaluate() override;
|
|
|
|
|
|
2022-08-10 09:14:22 +02:00
|
|
|
/* Compute and set the initial reference counts of all the results of the operation. The
|
|
|
|
|
* reference counts of the results are the number of operations that use those results, which is
|
|
|
|
|
* computed as the number of inputs whose node is part of the schedule and is linked to the
|
|
|
|
|
* output corresponding to each result. The node execution schedule is given as an input. */
|
|
|
|
|
void compute_results_reference_counts(const Schedule &schedule);
|
|
|
|
|
|
|
|
|
|
protected:
|
2023-06-23 18:46:18 +02:00
|
|
|
/* Compute a node preview using the result returned from the get_preview_result method. */
|
2023-06-21 05:41:49 +02:00
|
|
|
void compute_preview() override;
|
|
|
|
|
|
2022-08-10 09:14:22 +02:00
|
|
|
/* Returns a reference to the derived node that this operation represents. */
|
|
|
|
|
const DNode &node() const;
|
|
|
|
|
|
|
|
|
|
/* Returns a reference to the node that this operation represents. */
|
|
|
|
|
const bNode &bnode() const;
|
|
|
|
|
|
|
|
|
|
/* Returns true if the output identified by the given identifier is needed and should be
|
|
|
|
|
* computed, otherwise returns false. */
|
|
|
|
|
bool should_compute_output(StringRef identifier);
|
2023-06-21 05:41:49 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
/* Get the result which will be previewed in the node, this is chosen as the first linked output
|
2025-04-28 13:38:56 +03:00
|
|
|
* of the node, if no outputs exist, then the first allocated input will be chosen. Returns
|
|
|
|
|
* nullptr if no result is viewable. */
|
2023-06-21 05:41:49 +02:00
|
|
|
Result *get_preview_result();
|
2022-08-10 09:14:22 +02:00
|
|
|
};
|
|
|
|
|
|
2024-12-17 11:39:04 +01:00
|
|
|
} // namespace blender::compositor
|