Blender  V2.93
COM_NodeOperation.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
19 #include <cstdio>
20 #include <typeinfo>
21 
22 #include "COM_ExecutionSystem.h"
24 #include "COM_defines.h"
25 
26 #include "COM_NodeOperation.h" /* own include */
27 
28 namespace blender::compositor {
29 
30 /*******************
31  **** NodeOperation ****
32  *******************/
33 
35 {
36  this->m_resolutionInputSocketIndex = 0;
37  this->m_width = 0;
38  this->m_height = 0;
39  this->m_btree = nullptr;
40 }
41 
43 {
44  return &m_outputs[index];
45 }
46 
48 {
49  return &m_inputs[index];
50 }
51 
53 {
54  m_inputs.append(NodeOperationInput(this, datatype, resize_mode));
55 }
56 
58 {
59  m_outputs.append(NodeOperationOutput(this, datatype));
60 }
61 
62 void NodeOperation::determineResolution(unsigned int resolution[2],
63  unsigned int preferredResolution[2])
64 {
65  unsigned int used_resolution_index = 0;
66  if (m_resolutionInputSocketIndex == RESOLUTION_INPUT_ANY) {
67  for (NodeOperationInput &input : m_inputs) {
68  unsigned int any_resolution[2] = {0, 0};
69  input.determineResolution(any_resolution, preferredResolution);
70  if (any_resolution[0] * any_resolution[1] > 0) {
71  resolution[0] = any_resolution[0];
72  resolution[1] = any_resolution[1];
73  break;
74  }
75  used_resolution_index += 1;
76  }
77  }
78  else if (m_resolutionInputSocketIndex < m_inputs.size()) {
79  NodeOperationInput &input = m_inputs[m_resolutionInputSocketIndex];
80  input.determineResolution(resolution, preferredResolution);
81  used_resolution_index = m_resolutionInputSocketIndex;
82  }
83  unsigned int temp2[2] = {resolution[0], resolution[1]};
84 
85  unsigned int temp[2];
86  for (unsigned int index = 0; index < m_inputs.size(); index++) {
87  if (index == used_resolution_index) {
88  continue;
89  }
90  NodeOperationInput &input = m_inputs[index];
91  if (input.isConnected()) {
92  input.determineResolution(temp, temp2);
93  }
94  }
95 }
96 
98 {
99  this->m_resolutionInputSocketIndex = index;
100 }
102 {
103  /* pass */
104 }
105 
107 {
108  BLI_mutex_init(&this->m_mutex);
109 }
110 
112 {
113  BLI_mutex_lock(&this->m_mutex);
114 }
115 
117 {
118  BLI_mutex_unlock(&this->m_mutex);
119 }
120 
122 {
123  BLI_mutex_end(&this->m_mutex);
124 }
125 
127 {
128  /* pass */
129 }
130 SocketReader *NodeOperation::getInputSocketReader(unsigned int inputSocketIndex)
131 {
132  return this->getInputSocket(inputSocketIndex)->getReader();
133 }
134 
135 NodeOperation *NodeOperation::getInputOperation(unsigned int inputSocketIndex)
136 {
137  NodeOperationInput *input = getInputSocket(inputSocketIndex);
138  if (input && input->isConnected()) {
139  return &input->getLink()->getOperation();
140  }
141 
142  return nullptr;
143 }
144 
146  ReadBufferOperation *readOperation,
147  rcti *output)
148 {
149  if (m_inputs.size() == 0) {
150  BLI_rcti_init(output, input->xmin, input->xmax, input->ymin, input->ymax);
151  return false;
152  }
153 
154  rcti tempOutput;
155  bool first = true;
156  for (int i = 0; i < getNumberOfInputSockets(); i++) {
157  NodeOperation *inputOperation = this->getInputOperation(i);
158  if (inputOperation &&
159  inputOperation->determineDependingAreaOfInterest(input, readOperation, &tempOutput)) {
160  if (first) {
161  output->xmin = tempOutput.xmin;
162  output->ymin = tempOutput.ymin;
163  output->xmax = tempOutput.xmax;
164  output->ymax = tempOutput.ymax;
165  first = false;
166  }
167  else {
168  output->xmin = MIN2(output->xmin, tempOutput.xmin);
169  output->ymin = MIN2(output->ymin, tempOutput.ymin);
170  output->xmax = MAX2(output->xmax, tempOutput.xmax);
171  output->ymax = MAX2(output->ymax, tempOutput.ymax);
172  }
173  }
174  }
175  return !first;
176 }
177 
178 /*****************
179  **** OpInput ****
180  *****************/
181 
183  : m_operation(op), m_datatype(datatype), m_resizeMode(resizeMode), m_link(nullptr)
184 {
185 }
186 
188 {
189  if (isConnected()) {
190  return &m_link->getOperation();
191  }
192 
193  return nullptr;
194 }
195 
196 void NodeOperationInput::determineResolution(unsigned int resolution[2],
197  unsigned int preferredResolution[2])
198 {
199  if (m_link) {
200  m_link->determineResolution(resolution, preferredResolution);
201  }
202 }
203 
204 /******************
205  **** OpOutput ****
206  ******************/
207 
209  : m_operation(op), m_datatype(datatype)
210 {
211 }
212 
213 void NodeOperationOutput::determineResolution(unsigned int resolution[2],
214  unsigned int preferredResolution[2])
215 {
216  NodeOperation &operation = getOperation();
217  if (operation.get_flags().is_resolution_set) {
218  resolution[0] = operation.getWidth();
219  resolution[1] = operation.getHeight();
220  }
221  else {
222  operation.determineResolution(resolution, preferredResolution);
223  if (resolution[0] > 0 && resolution[1] > 0) {
224  operation.setResolution(resolution);
225  }
226  }
227 }
228 
229 std::ostream &operator<<(std::ostream &os, const NodeOperationFlags &node_operation_flags)
230 {
231  if (node_operation_flags.complex) {
232  os << "complex,";
233  }
234  if (node_operation_flags.open_cl) {
235  os << "open_cl,";
236  }
237  if (node_operation_flags.single_threaded) {
238  os << "single_threaded,";
239  }
240  if (node_operation_flags.use_render_border) {
241  os << "render_border,";
242  }
243  if (node_operation_flags.use_viewer_border) {
244  os << "view_border,";
245  }
246  if (node_operation_flags.is_resolution_set) {
247  os << "resolution_set,";
248  }
249  if (node_operation_flags.is_set_operation) {
250  os << "set_operation,";
251  }
252  if (node_operation_flags.is_write_buffer_operation) {
253  os << "write_buffer,";
254  }
255  if (node_operation_flags.is_read_buffer_operation) {
256  os << "read_buffer,";
257  }
258  if (node_operation_flags.is_proxy_operation) {
259  os << "proxy,";
260  }
261  if (node_operation_flags.is_viewer_operation) {
262  os << "viewer,";
263  }
264  if (node_operation_flags.is_preview_operation) {
265  os << "preview,";
266  }
267  if (!node_operation_flags.use_datatype_conversion) {
268  os << "no_conversion,";
269  }
270 
271  return os;
272 }
273 
274 std::ostream &operator<<(std::ostream &os, const NodeOperation &node_operation)
275 {
276  NodeOperationFlags flags = node_operation.get_flags();
277  os << "NodeOperation(";
278  os << "id=" << node_operation.get_id();
279  if (!node_operation.get_name().empty()) {
280  os << ",name=" << node_operation.get_name();
281  }
282  os << ",flags={" << flags << "}";
283  if (flags.is_read_buffer_operation) {
284  const ReadBufferOperation *read_operation = (const ReadBufferOperation *)&node_operation;
285  const MemoryProxy *proxy = read_operation->getMemoryProxy();
286  if (proxy) {
287  const WriteBufferOperation *write_operation = proxy->getWriteBufferOperation();
288  if (write_operation) {
289  os << ",write=" << (NodeOperation &)*write_operation;
290  }
291  }
292  }
293  os << ")";
294 
295  return os;
296 }
297 
298 } // namespace blender::compositor
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition: rct.c:446
void BLI_mutex_end(ThreadMutex *mutex)
Definition: threads.cc:416
void BLI_mutex_init(ThreadMutex *mutex)
Definition: threads.cc:396
void BLI_mutex_lock(ThreadMutex *mutex)
Definition: threads.cc:401
void BLI_mutex_unlock(ThreadMutex *mutex)
Definition: threads.cc:406
#define MAX2(a, b)
#define MIN2(a, b)
#define output
A MemoryProxy is a unique identifier for a memory buffer. A single MemoryProxy is used among all chun...
WriteBufferOperation * getWriteBufferOperation() const
get the WriteBufferOperation that is responsible for writing to this MemoryProxy
NodeOperationOutput * getLink() const
NodeOperationInput(NodeOperation *op, DataType datatype, ResizeMode resizeMode=ResizeMode::Center)
void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
determine the resolution of this data going through this socket
NodeOperationOutput(NodeOperation *op, DataType datatype)
NodeOperation contains calculation logic.
NodeOperationInput * getInputSocket(unsigned int index)
void addInputSocket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
NodeOperation * getInputOperation(unsigned int inputSocketindex)
const NodeOperationFlags get_flags() const
unsigned int getNumberOfInputSockets() const
void addOutputSocket(DataType datatype)
void setResolutionInputSocketIndex(unsigned int index)
set the index of the input socket that will determine the resolution of this operation
virtual void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
determine the resolution of this node
SocketReader * getInputSocketReader(unsigned int inputSocketindex)
NodeOperationOutput * getOutputSocket(unsigned int index=0)
const std::string get_name() const
virtual bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
void setResolution(unsigned int resolution[2])
set the resolution
DataType
possible data types for sockets
Definition: COM_defines.h:27
ResizeMode
Resize modes of inputsockets How are the input and working resolutions matched.
static constexpr unsigned int RESOLUTION_INPUT_ANY
std::ostream & operator<<(std::ostream &os, const eCompositorPriority &priority)
Definition: COM_Enums.cc:23
int ymin
Definition: DNA_vec_types.h:80
int ymax
Definition: DNA_vec_types.h:80
int xmin
Definition: DNA_vec_types.h:79
int xmax
Definition: DNA_vec_types.h:79