Blender  V2.93
COM_NodeOperation.h
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 #pragma once
20 
21 #include <list>
22 #include <sstream>
23 #include <string>
24 
25 #include "BLI_math_color.h"
26 #include "BLI_math_vector.h"
27 #include "BLI_threads.h"
28 
29 #include "COM_Enums.h"
30 #include "COM_MemoryBuffer.h"
31 #include "COM_MemoryProxy.h"
32 #include "COM_MetaData.h"
33 #include "COM_Node.h"
34 
35 #include "clew.h"
36 
37 namespace blender::compositor {
38 
39 class OpenCLDevice;
40 class ReadBufferOperation;
41 class WriteBufferOperation;
42 
43 class NodeOperation;
45 
51 static constexpr unsigned int RESOLUTION_INPUT_ANY = 999999;
52 
58 enum class ResizeMode {
64  None = NS_CR_NONE,
71  FitAny = NS_CR_FIT,
75 };
76 
77 enum class PixelSampler {
78  Nearest = 0,
79  Bilinear = 1,
80  Bicubic = 2,
81 };
82 
84  private:
85  NodeOperation *m_operation;
86 
90  DataType m_datatype;
91 
93  ResizeMode m_resizeMode;
94 
96  NodeOperationOutput *m_link;
97 
98  public:
100  DataType datatype,
101  ResizeMode resizeMode = ResizeMode::Center);
102 
104  {
105  return *m_operation;
106  }
108  {
109  return m_datatype;
110  }
111 
113  {
114  m_link = link;
115  }
117  {
118  return m_link;
119  }
120  bool isConnected() const
121  {
122  return m_link;
123  }
124 
125  void setResizeMode(ResizeMode resizeMode)
126  {
127  this->m_resizeMode = resizeMode;
128  }
130  {
131  return this->m_resizeMode;
132  }
133 
135 
136  void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]);
137 
138 #ifdef WITH_CXX_GUARDEDALLOC
139  MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation")
140 #endif
141 };
142 
144  private:
145  NodeOperation *m_operation;
146 
150  DataType m_datatype;
151 
152  public:
154 
156  {
157  return *m_operation;
158  }
160  {
161  return m_datatype;
162  }
163 
169  void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]);
170 
171 #ifdef WITH_CXX_GUARDEDALLOC
172  MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation")
173 #endif
174 };
175 
186  bool complex : 1;
187 
191  bool open_cl : 1;
192 
193  bool single_threaded : 1;
194 
211 
216 
226 
234 
236  {
237  complex = false;
238  single_threaded = false;
239  open_cl = false;
240  use_render_border = false;
241  use_viewer_border = false;
242  is_resolution_set = false;
243  is_set_operation = false;
244  is_read_buffer_operation = false;
246  is_proxy_operation = false;
247  is_viewer_operation = false;
248  is_preview_operation = false;
250  }
251 };
252 
260  private:
261  int m_id;
262  std::string m_name;
264  Vector<NodeOperationOutput> m_outputs;
265 
269  unsigned int m_resolutionInputSocketIndex;
270 
280  ThreadMutex m_mutex;
281 
285  const bNodeTree *m_btree;
286 
287  protected:
291  unsigned int m_width;
292 
296  unsigned int m_height;
297 
302 
303  public:
304  virtual ~NodeOperation()
305  {
306  }
307 
308  void set_name(const std::string name)
309  {
310  m_name = name;
311  }
312 
313  const std::string get_name() const
314  {
315  return m_name;
316  }
317 
318  void set_id(const int id)
319  {
320  m_id = id;
321  }
322 
323  const int get_id() const
324  {
325  return m_id;
326  }
327 
329  {
330  return flags;
331  }
332 
333  unsigned int getNumberOfInputSockets() const
334  {
335  return m_inputs.size();
336  }
337  unsigned int getNumberOfOutputSockets() const
338  {
339  return m_outputs.size();
340  }
341  NodeOperationOutput *getOutputSocket(unsigned int index = 0);
342  NodeOperationInput *getInputSocket(unsigned int index);
343 
350  virtual void determineResolution(unsigned int resolution[2],
351  unsigned int preferredResolution[2]);
352 
368  virtual bool isOutputOperation(bool /*rendering*/) const
369  {
370  return false;
371  }
372 
374  {
375  this->m_btree = tree;
376  }
377  virtual void initExecution();
378 
386  virtual void executeRegion(rcti * /*rect*/, unsigned int /*chunkNumber*/)
387  {
388  }
389 
402  virtual void executeOpenCLRegion(OpenCLDevice * /*device*/,
403  rcti * /*rect*/,
404  unsigned int /*chunkNumber*/,
405  MemoryBuffer ** /*memoryBuffers*/,
406  MemoryBuffer * /*outputBuffer*/)
407  {
408  }
409 
425  virtual void executeOpenCL(OpenCLDevice * /*device*/,
426  MemoryBuffer * /*outputMemoryBuffer*/,
427  cl_mem /*clOutputBuffer*/,
428  MemoryBuffer ** /*inputMemoryBuffers*/,
429  std::list<cl_mem> * /*clMemToCleanUp*/,
430  std::list<cl_kernel> * /*clKernelsToCleanUp*/)
431  {
432  }
433  virtual void deinitExecution();
434 
439  void setResolution(unsigned int resolution[2])
440  {
441  if (!this->flags.is_resolution_set) {
442  this->m_width = resolution[0];
443  this->m_height = resolution[1];
444  this->flags.is_resolution_set = true;
445  }
446  }
447 
455  virtual bool isActiveViewerOutput() const
456  {
457  return false;
458  }
459 
460  virtual bool determineDependingAreaOfInterest(rcti *input,
461  ReadBufferOperation *readOperation,
462  rcti *output);
463 
468  void setResolutionInputSocketIndex(unsigned int index);
469 
476  {
478  }
479 
480  inline bool isBraked() const
481  {
482  return this->m_btree->test_break(this->m_btree->tbh);
483  }
484 
485  inline void updateDraw()
486  {
487  if (this->m_btree->update_draw) {
488  this->m_btree->update_draw(this->m_btree->udh);
489  }
490  }
491 
492  unsigned int getWidth() const
493  {
494  return m_width;
495  }
496 
497  unsigned int getHeight() const
498  {
499  return m_height;
500  }
501 
502  inline void readSampled(float result[4], float x, float y, PixelSampler sampler)
503  {
504  executePixelSampled(result, x, y, sampler);
505  }
506 
507  inline void readFiltered(float result[4], float x, float y, float dx[2], float dy[2])
508  {
509  executePixelFiltered(result, x, y, dx, dy);
510  }
511 
512  inline void read(float result[4], int x, int y, void *chunkData)
513  {
514  executePixel(result, x, y, chunkData);
515  }
516 
517  virtual void *initializeTileData(rcti * /*rect*/)
518  {
519  return 0;
520  }
521 
522  virtual void deinitializeTileData(rcti * /*rect*/, void * /*data*/)
523  {
524  }
525 
526  virtual MemoryBuffer *getInputMemoryBuffer(MemoryBuffer ** /*memoryBuffers*/)
527  {
528  return 0;
529  }
530 
535  virtual std::unique_ptr<MetaData> getMetaData()
536  {
537  return std::unique_ptr<MetaData>();
538  }
539 
540  protected:
541  NodeOperation();
542 
543  void addInputSocket(DataType datatype, ResizeMode resize_mode = ResizeMode::Center);
544  void addOutputSocket(DataType datatype);
545 
546  void setWidth(unsigned int width)
547  {
548  this->m_width = width;
549  this->flags.is_resolution_set = true;
550  }
551  void setHeight(unsigned int height)
552  {
553  this->m_height = height;
554  this->flags.is_resolution_set = true;
555  }
556  SocketReader *getInputSocketReader(unsigned int inputSocketindex);
557  NodeOperation *getInputOperation(unsigned int inputSocketindex);
558 
559  void deinitMutex();
560  void initMutex();
561  void lockMutex();
562  void unlockMutex();
563 
570  void setComplex(bool complex)
571  {
572  this->flags.complex = complex;
573  }
574 
583  virtual void executePixelSampled(float /*output*/[4],
584  float /*x*/,
585  float /*y*/,
586  PixelSampler /*sampler*/)
587  {
588  }
589 
599  virtual void executePixel(float output[4], int x, int y, void * /*chunkData*/)
600  {
602  }
603 
614  virtual void executePixelFiltered(
615  float /*output*/[4], float /*x*/, float /*y*/, float /*dx*/[2], float /*dy*/[2])
616  {
617  }
618 
619  /* allow the DebugInfo class to look at internals */
620  friend class DebugInfo;
621 
622 #ifdef WITH_CXX_GUARDEDALLOC
623  MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation")
624 #endif
625 };
626 
627 std::ostream &operator<<(std::ostream &os, const NodeOperationFlags &node_operation_flags);
628 std::ostream &operator<<(std::ostream &os, const NodeOperation &node_operation);
629 
630 } // namespace blender::compositor
pthread_mutex_t ThreadMutex
Definition: BLI_threads.h:83
#define NS_CR_FIT_HEIGHT
#define NS_CR_STRETCH
#define NS_CR_CENTER
#define NS_CR_FIT
#define NS_CR_FIT_WIDTH
#define NS_CR_NONE
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
#define output
int64_t size() const
Definition: BLI_vector.hh:662
a MemoryBuffer contains access to the data of a chunk
void setResizeMode(ResizeMode resizeMode)
NodeOperationOutput * getLink() const
NodeOperationInput(NodeOperation *op, DataType datatype, ResizeMode resizeMode=ResizeMode::Center)
void setLink(NodeOperationOutput *link)
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.
virtual void * initializeTileData(rcti *)
virtual eCompositorPriority getRenderPriority() const
get the render priority of this node.
void set_name(const std::string name)
void readSampled(float result[4], float x, float y, PixelSampler sampler)
NodeOperationInput * getInputSocket(unsigned int index)
virtual void executeRegion(rcti *, unsigned int)
when a chunk is executed by a CPUDevice, this method is called
void addInputSocket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
NodeOperation * getInputOperation(unsigned int inputSocketindex)
virtual MemoryBuffer * getInputMemoryBuffer(MemoryBuffer **)
void read(float result[4], int x, int y, void *chunkData)
virtual void executePixelSampled(float[4], float, float, PixelSampler)
calculate a single pixel
virtual std::unique_ptr< MetaData > getMetaData()
virtual void executeOpenCL(OpenCLDevice *, MemoryBuffer *, cl_mem, MemoryBuffer **, std::list< cl_mem > *, std::list< cl_kernel > *)
custom handle to add new tasks to the OpenCL command queue in order to execute a chunk on an GPUDevic...
const NodeOperationFlags get_flags() const
unsigned int getNumberOfInputSockets() const
virtual void executePixel(float output[4], int x, int y, void *)
calculate a single pixel
void addOutputSocket(DataType datatype)
unsigned int getNumberOfOutputSockets() const
void setComplex(bool complex)
set whether this operation is complex
virtual void deinitializeTileData(rcti *, void *)
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
virtual bool isOutputOperation(bool) const
isOutputOperation determines whether this operation is an output of the ExecutionSystem during render...
void setWidth(unsigned int width)
virtual void executePixelFiltered(float[4], float, float, float[2], float[2])
calculate a single pixel using an EWA filter
void readFiltered(float result[4], float x, float y, float dx[2], float dy[2])
void setHeight(unsigned int height)
SocketReader * getInputSocketReader(unsigned int inputSocketindex)
virtual bool isActiveViewerOutput() const
is this operation the active viewer output user can select an ViewerNode to be active (the result of ...
NodeOperationOutput * getOutputSocket(unsigned int index=0)
const std::string get_name() const
void setbNodeTree(const bNodeTree *tree)
virtual bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
virtual void executeOpenCLRegion(OpenCLDevice *, rcti *, unsigned int, MemoryBuffer **, MemoryBuffer *)
when a chunk is executed by an OpenCLDevice, this method is called
void setResolution(unsigned int resolution[2])
set the resolution
device representing an GPU OpenCL device. an instance of this class represents a single cl_device
void * tree
eCompositorPriority
Possible priority settings.
Definition: COM_Enums.h:45
DataType
possible data types for sockets
Definition: COM_defines.h:27
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.
@ None
The bottom left of the input image is the bottom left of the working area of the node,...
@ 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...
static constexpr unsigned int RESOLUTION_INPUT_ANY
NodeOperation SocketReader
std::ostream & operator<<(std::ostream &os, const eCompositorPriority &priority)
Definition: COM_Enums.cc:23
int(* test_break)(void *)
void(* update_draw)(void *)