Blender V4.3
COM_NodeOperation.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include <functional>
8#include <list>
9
10#include "BLI_ghash.h"
11#include "BLI_hash.hh"
12#include "BLI_math_base.hh"
13#include "BLI_rect.h"
14#include "BLI_span.hh"
15#include "BLI_threads.h"
16#include "BLI_utildefines.h"
17
18#include "COM_Enums.h"
19#include "COM_MemoryBuffer.h"
20#include "COM_MetaData.h"
21
22#include "BKE_node.hh"
23#include "BKE_node_runtime.hh"
24
25#include "DNA_node_types.h"
26
27namespace blender::compositor {
28
29class ExecutionSystem;
30class NodeOperation;
31class NodeOperationOutput;
32
34
40static constexpr unsigned int RESOLUTION_INPUT_ANY = 999999;
41
69
71 private:
72 NodeOperation *operation_;
73
78 DataType datatype_;
79
81 ResizeMode resize_mode_;
82
85
86 public:
88 DataType datatype,
89 ResizeMode resize_mode = ResizeMode::Center);
90
92 {
93 return *operation_;
94 }
96 {
97 return datatype_;
98 }
99
101 {
102 link_ = link;
103 }
105 {
106 return link_;
107 }
108 bool is_connected() const
109 {
110 return link_;
111 }
112
113 void set_resize_mode(ResizeMode resize_mode)
114 {
115 resize_mode_ = resize_mode;
116 }
118 {
119 return resize_mode_;
120 }
121
123
127 bool determine_canvas(const rcti &preferred_area, rcti &r_area);
128
129#ifdef WITH_CXX_GUARDEDALLOC
130 MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation")
131#endif
132};
133
135 private:
136 NodeOperation *operation_;
137
142 DataType datatype_;
143
144 public:
146
148 {
149 return *operation_;
150 }
152 {
153 return datatype_;
154 }
155
156 void determine_canvas(const rcti &preferred_area, rcti &r_area);
157
158#ifdef WITH_CXX_GUARDEDALLOC
159 MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation")
160#endif
161};
162
180
185
189
197
202
208
210 {
211 use_render_border = false;
212 use_viewer_border = false;
213 is_canvas_set = false;
214 is_proxy_operation = false;
215 is_viewer_operation = false;
216 is_preview_operation = false;
218 is_constant_operation = false;
219 can_be_constant = false;
220 }
221};
222
225 private:
226 NodeOperation *operation_;
227 size_t type_hash_;
228 size_t parents_hash_;
229 size_t params_hash_;
230
231 friend class NodeOperation;
232
233 public:
235 {
236 return operation_;
237 }
238
239 bool operator==(const NodeOperationHash &other) const
240 {
241 return type_hash_ == other.type_hash_ && parents_hash_ == other.parents_hash_ &&
242 params_hash_ == other.params_hash_;
243 }
244
245 bool operator!=(const NodeOperationHash &other) const
246 {
247 return !(*this == other);
248 }
249
250 bool operator<(const NodeOperationHash &other) const
251 {
252 return type_hash_ < other.type_hash_ ||
253 (type_hash_ == other.type_hash_ && parents_hash_ < other.parents_hash_) ||
254 (type_hash_ == other.type_hash_ && parents_hash_ == other.parents_hash_ &&
255 params_hash_ < other.params_hash_);
256 }
257};
258
266 private:
267 int id_;
268 std::string name_;
270
273
274 size_t params_hash_;
275 bool is_hash_output_params_implemented_;
276
280 unsigned int canvas_input_index_;
281
282 std::function<void(rcti &canvas)> modify_determined_canvas_fn_;
283
287 const bNodeTree *btree_;
288
289 protected:
291
296
298
299 public:
300 virtual ~NodeOperation() {}
301
302 void set_name(const std::string name)
303 {
304 name_ = name;
305 }
306
307 const std::string get_name() const
308 {
309 return name_;
310 }
311
312 void set_id(const int id)
313 {
314 id_ = id;
315 }
316
317 const int get_id() const
318 {
319 return id_;
320 }
321
322 const void set_node_instance_key(const bNodeInstanceKey &node_instance_key)
323 {
324 node_instance_key_ = node_instance_key;
325 }
327 {
328 return node_instance_key_;
329 }
330
332 float get_constant_value_default(float default_value);
334 const float *get_constant_elem_default(const float *default_elem);
335
337 {
338 return flags_;
339 }
340
346 std::optional<NodeOperationHash> generate_hash();
347
348 unsigned int get_number_of_input_sockets() const
349 {
350 return inputs_.size();
351 }
352 unsigned int get_number_of_output_sockets() const
353 {
354 return outputs_.size();
355 }
356 NodeOperationOutput *get_output_socket(unsigned int index = 0);
357 NodeOperationInput *get_input_socket(unsigned int index);
358
360
361 virtual void determine_canvas(const rcti &preferred_area, rcti &r_area);
362
378 virtual bool is_output_operation(bool /*rendering*/) const
379 {
380 return false;
381 }
382
384 {
385 btree_ = tree;
386 }
387
389 {
390 exec_system_ = system;
391 }
392
397 virtual void init_data();
398
399 virtual void init_execution();
400
401 virtual void deinit_execution();
402
403 void set_canvas(const rcti &canvas_area);
404 const rcti &get_canvas() const;
409 void unset_canvas();
410
418 virtual bool is_active_viewer_output() const
419 {
420 return false;
421 }
422
427 void set_canvas_input_index(unsigned int index);
428
433 void set_determined_canvas_modifier(std::function<void(rcti &canvas)> fn)
434 {
435 modify_determined_canvas_fn_ = fn;
436 }
437
444 {
446 }
447
448 inline bool is_braked() const
449 {
450 return btree_->runtime->test_break(btree_->runtime->tbh);
451 }
452
453 inline void update_draw()
454 {
455 if (btree_->runtime->update_draw) {
456 btree_->runtime->update_draw(btree_->runtime->udh);
457 }
458 }
459
460 unsigned int get_width() const
461 {
462 return BLI_rcti_size_x(&get_canvas());
463 }
464
465 unsigned int get_height() const
466 {
467 return BLI_rcti_size_y(&get_canvas());
468 }
469
470 virtual MemoryBuffer *get_input_memory_buffer(MemoryBuffer ** /*memory_buffers*/)
471 {
472 return 0;
473 }
474
479 virtual std::unique_ptr<MetaData> get_meta_data()
480 {
481 return std::unique_ptr<MetaData>();
482 }
483
484 /* -------------------------------------------------------------------- */
494 void render(MemoryBuffer *output_buf, Span<rcti> areas, Span<MemoryBuffer *> inputs_bufs);
495
499 virtual void update_memory_buffer(MemoryBuffer * /*output*/,
500 const rcti & /*area*/,
501 Span<MemoryBuffer *> /*inputs*/)
502 {
503 }
504
517 virtual void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area);
518 void get_area_of_interest(NodeOperation *input_op, const rcti &output_area, rcti &r_input_area);
519
522 protected:
524
525 /* Overridden by subclasses to allow merging equal operations on compiling. Implementations must
526 * hash any subclass parameter that affects the output result using `hash_params` methods. */
527 virtual void hash_output_params()
528 {
529 is_hash_output_params_implemented_ = false;
530 }
531
532 static void combine_hashes(size_t &combined, size_t other)
533 {
534 combined = BLI_ghashutil_combine_hash(combined, other);
535 }
536
537 template<typename T> void hash_param(T param)
538 {
539 combine_hashes(params_hash_, get_default_hash(param));
540 }
541
542 template<typename T1, typename T2> void hash_params(T1 param1, T2 param2)
543 {
544 combine_hashes(params_hash_, get_default_hash(param1, param2));
545 }
546
547 template<typename T1, typename T2, typename T3> void hash_params(T1 param1, T2 param2, T3 param3)
548 {
549 combine_hashes(params_hash_, get_default_hash(param1, param2, param3));
550 }
551
552 void add_input_socket(DataType datatype, ResizeMode resize_mode = ResizeMode::Center);
553 void add_output_socket(DataType datatype);
554
555 SocketReader *get_input_socket_reader(unsigned int index);
556
557 private:
561 void render_full_frame(MemoryBuffer *output_buf,
562 Span<rcti> areas,
563 Span<MemoryBuffer *> inputs_bufs);
564
565 /* allow the DebugInfo class to look at internals */
566 friend class DebugInfo;
567
568#ifdef WITH_CXX_GUARDEDALLOC
569 MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation")
570#endif
571};
572
573std::ostream &operator<<(std::ostream &os, const NodeOperationFlags &node_operation_flags);
574std::ostream &operator<<(std::ostream &os, const NodeOperation &node_operation);
575
576} // namespace blender::compositor
size_t BLI_ghashutil_combine_hash(size_t hash_a, size_t hash_b)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.h:193
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.h:189
@ NS_CR_NONE
@ NS_CR_FIT
@ NS_CR_STRETCH
@ NS_CR_CENTER
@ NS_CR_FIT_WIDTH
@ NS_CR_FIT_HEIGHT
int64_t size() const
the ExecutionSystem contains the whole compositor tree.
a MemoryBuffer contains access to the data
void set_link(NodeOperationOutput *link)
NodeOperationOutput * get_link() const
bool determine_canvas(const rcti &preferred_area, rcti &r_area)
NodeOperationInput(NodeOperation *op, DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
void set_resize_mode(ResizeMode resize_mode)
NodeOperationOutput(NodeOperation *op, DataType datatype)
void determine_canvas(const rcti &preferred_area, rcti &r_area)
NodeOperation contains calculation logic.
const void set_node_instance_key(const bNodeInstanceKey &node_instance_key)
void set_bnodetree(const bNodeTree *tree)
static void combine_hashes(size_t &combined, size_t other)
void set_name(const std::string name)
void set_canvas(const rcti &canvas_area)
void add_output_socket(DataType datatype)
virtual std::unique_ptr< MetaData > get_meta_data()
unsigned int get_number_of_output_sockets() const
virtual bool is_output_operation(bool) const
is_output_operation determines whether this operation is an output of the ExecutionSystem during rend...
const bNodeInstanceKey get_node_instance_key() const
const NodeOperationFlags get_flags() const
SocketReader * get_input_socket_reader(unsigned int index)
virtual void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area)
Get input operation area being read by this operation on rendering given output area.
virtual MemoryBuffer * get_input_memory_buffer(MemoryBuffer **)
std::optional< NodeOperationHash > generate_hash()
float get_constant_value_default(float default_value)
unsigned int get_number_of_input_sockets() const
virtual bool is_active_viewer_output() const
is this operation the active viewer output user can select an ViewerNode to be active (the result of ...
NodeOperationOutput * get_output_socket(unsigned int index=0)
NodeOperation * get_input_operation(int index)
const float * get_constant_elem_default(const float *default_elem)
void hash_params(T1 param1, T2 param2, T3 param3)
NodeOperationInput * get_input_socket(unsigned int index)
virtual eCompositorPriority get_render_priority() const
get the render priority of this node.
void set_determined_canvas_modifier(std::function< void(rcti &canvas)> fn)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
virtual void update_memory_buffer(MemoryBuffer *, const rcti &, Span< MemoryBuffer * >)
void set_execution_system(ExecutionSystem *system)
const std::string get_name() const
void set_canvas_input_index(unsigned int index)
set the index of the input socket that will determine the canvas of this operation
void hash_params(T1 param1, T2 param2)
virtual void determine_canvas(const rcti &preferred_area, rcti &r_area)
KDTree_3d * tree
eCompositorPriority
Possible priority settings.
Definition COM_Enums.h:33
DataType
possible data types for sockets
Definition COM_defines.h:21
ResizeMode
Resize modes of inputsockets How are the input and working resolutions matched.
@ FitAny
Fit the width or the height of the input image to the width or height of the working area of the node...
@ FitWidth
Fit the width of the input image to the width of the working area of the node.
@ Center
Center the input image to the center of the working area of the node, no resizing occurs.
@ FitHeight
Fit the height of the input image to the height of the working area of the node.
@ Stretch
Fit the width and the height of the input image to the width and height of the working area of the no...
#define T2
Definition md5.cpp:19
#define T3
Definition md5.cpp:20
#define T1
Definition md5.cpp:18
const bNodeInstanceKey NODE_INSTANCE_KEY_NONE
Definition node.cc:4021
static constexpr unsigned int RESOLUTION_INPUT_ANY
constexpr rcti COM_AREA_NONE
Definition COM_defines.h:89
NodeOperation SocketReader
std::ostream & operator<<(std::ostream &os, const eCompositorPriority &priority)
Definition COM_Enums.cc:27
uint64_t get_default_hash(const T &v)
Definition BLI_hash.hh:219
bNodeTreeRuntimeHandle * runtime
bool operator!=(const NodeOperationHash &other) const
bool operator==(const NodeOperationHash &other) const
bool operator<(const NodeOperationHash &other) const