Changeset View
Changeset View
Standalone View
Standalone View
source/blender/compositor/intern/COM_NodeOperation.h
| Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | |||||
| * \brief Resize modes of inputsockets | * \brief Resize modes of inputsockets | ||||
| * How are the input and working resolutions matched | * How are the input and working resolutions matched | ||||
| * \ingroup Model | * \ingroup Model | ||||
| */ | */ | ||||
| enum class ResizeMode { | enum class ResizeMode { | ||||
| /** \brief Center the input image to the center of the working area of the node, no resizing | /** \brief Center the input image to the center of the working area of the node, no resizing | ||||
| * occurs */ | * occurs */ | ||||
| Center = NS_CR_CENTER, | Center = NS_CR_CENTER, | ||||
| /** \brief The bottom left of the input image is the bottom left of the working area of the node, | /** No resizing or translation. */ | ||||
| * no resizing occurs */ | |||||
| None = NS_CR_NONE, | None = NS_CR_NONE, | ||||
| /** | |||||
| * Input image is translated so that its bottom left matches the bottom left of the working area | |||||
| * of the node, no resizing occurs. | |||||
| */ | |||||
| Align = 100, | |||||
| /** \brief Fit the width of the input image to the width of the working area of the node */ | /** \brief Fit the width of the input image to the width of the working area of the node */ | ||||
| FitWidth = NS_CR_FIT_WIDTH, | FitWidth = NS_CR_FIT_WIDTH, | ||||
| /** \brief Fit the height of the input image to the height of the working area of the node */ | /** \brief Fit the height of the input image to the height of the working area of the node */ | ||||
| FitHeight = NS_CR_FIT_HEIGHT, | FitHeight = NS_CR_FIT_HEIGHT, | ||||
| /** \brief Fit the width or the height of the input image to the width or height of the working | /** \brief Fit the width or the height of the input image to the width or height of the working | ||||
| * area of the node, image will be larger than the working area */ | * area of the node, image will be larger than the working area */ | ||||
| FitAny = NS_CR_FIT, | FitAny = NS_CR_FIT, | ||||
| /** \brief Fit the width and the height of the input image to the width and height of the working | /** \brief Fit the width and the height of the input image to the width and height of the working | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | public: | ||||
| } | } | ||||
| ResizeMode getResizeMode() const | ResizeMode getResizeMode() const | ||||
| { | { | ||||
| return this->m_resizeMode; | return this->m_resizeMode; | ||||
| } | } | ||||
| SocketReader *getReader(); | SocketReader *getReader(); | ||||
| void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); | bool determine_canvas(const rcti &preferred_area, rcti &r_area); | ||||
| #ifdef WITH_CXX_GUARDEDALLOC | #ifdef WITH_CXX_GUARDEDALLOC | ||||
| MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation") | MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation") | ||||
| #endif | #endif | ||||
| }; | }; | ||||
| class NodeOperationOutput { | class NodeOperationOutput { | ||||
| private: | private: | ||||
| Show All 11 Lines | public: | ||||
| { | { | ||||
| return *m_operation; | return *m_operation; | ||||
| } | } | ||||
| DataType getDataType() const | DataType getDataType() const | ||||
| { | { | ||||
| return m_datatype; | return m_datatype; | ||||
| } | } | ||||
| /** | void determine_canvas(const rcti &preferred_area, rcti &r_area); | ||||
| * \brief determine the resolution of this data going through this socket | |||||
| * \param resolution: the result of this operation | |||||
| * \param preferredResolution: the preferable resolution as no resolution could be determined | |||||
| */ | |||||
| void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); | |||||
| #ifdef WITH_CXX_GUARDEDALLOC | #ifdef WITH_CXX_GUARDEDALLOC | ||||
| MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation") | MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation") | ||||
| #endif | #endif | ||||
| }; | }; | ||||
| struct NodeOperationFlags { | struct NodeOperationFlags { | ||||
| /** | /** | ||||
| Show All 31 Lines | struct NodeOperationFlags { | ||||
| * But nodes like viewer and file output just shall display or | * But nodes like viewer and file output just shall display or | ||||
| * safe the same exact buffer which goes to their input, no need | * safe the same exact buffer which goes to their input, no need | ||||
| * in any kind of coordinates mapping. | * in any kind of coordinates mapping. | ||||
| */ | */ | ||||
| bool use_render_border : 1; | bool use_render_border : 1; | ||||
| bool use_viewer_border : 1; | bool use_viewer_border : 1; | ||||
| /** | /** | ||||
| * Is the resolution of the operation set. | * Is the canvas of the operation set. | ||||
| */ | */ | ||||
| bool is_resolution_set : 1; | bool is_canvas_set : 1; | ||||
| /** | /** | ||||
| * Is this a set operation (value, color, vector). | * Is this a set operation (value, color, vector). | ||||
| * TODO: To be replaced by is_constant_operation flag once tiled implementation is removed. | * TODO: To be replaced by is_constant_operation flag once tiled implementation is removed. | ||||
| */ | */ | ||||
| bool is_set_operation : 1; | bool is_set_operation : 1; | ||||
| bool is_write_buffer_operation : 1; | bool is_write_buffer_operation : 1; | ||||
| bool is_read_buffer_operation : 1; | bool is_read_buffer_operation : 1; | ||||
| Show All 27 Lines | struct NodeOperationFlags { | ||||
| NodeOperationFlags() | NodeOperationFlags() | ||||
| { | { | ||||
| complex = false; | complex = false; | ||||
| single_threaded = false; | single_threaded = false; | ||||
| open_cl = false; | open_cl = false; | ||||
| use_render_border = false; | use_render_border = false; | ||||
| use_viewer_border = false; | use_viewer_border = false; | ||||
| is_resolution_set = false; | is_canvas_set = false; | ||||
| is_set_operation = false; | is_set_operation = false; | ||||
| is_read_buffer_operation = false; | is_read_buffer_operation = false; | ||||
| is_write_buffer_operation = false; | is_write_buffer_operation = false; | ||||
| is_proxy_operation = false; | is_proxy_operation = false; | ||||
| is_viewer_operation = false; | is_viewer_operation = false; | ||||
| is_preview_operation = false; | is_preview_operation = false; | ||||
| use_datatype_conversion = true; | use_datatype_conversion = true; | ||||
| is_fullframe_operation = false; | is_fullframe_operation = false; | ||||
| ▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | private: | ||||
| std::string m_name; | std::string m_name; | ||||
| Vector<NodeOperationInput> m_inputs; | Vector<NodeOperationInput> m_inputs; | ||||
| Vector<NodeOperationOutput> m_outputs; | Vector<NodeOperationOutput> m_outputs; | ||||
| size_t params_hash_; | size_t params_hash_; | ||||
| bool is_hash_output_params_implemented_; | bool is_hash_output_params_implemented_; | ||||
| /** | /** | ||||
| * \brief the index of the input socket that will be used to determine the resolution | * \brief the index of the input socket that will be used to determine the canvas | ||||
| */ | */ | ||||
| unsigned int m_resolutionInputSocketIndex; | unsigned int canvas_input_index_; | ||||
| std::function<void(unsigned int resolution[2])> modify_determined_resolution_fn_; | std::function<void(rcti &canvas)> modify_determined_canvas_fn_; | ||||
| /** | /** | ||||
| * \brief mutex reference for very special node initializations | * \brief mutex reference for very special node initializations | ||||
| * \note only use when you really know what you are doing. | * \note only use when you really know what you are doing. | ||||
| * this mutex is used to share data among chunks in the same operation | * this mutex is used to share data among chunks in the same operation | ||||
| * \see TonemapOperation for an example of usage | * \see TonemapOperation for an example of usage | ||||
| * \see NodeOperation.initMutex initializes this mutex | * \see NodeOperation.initMutex initializes this mutex | ||||
| * \see NodeOperation.deinitMutex deinitializes this mutex | * \see NodeOperation.deinitMutex deinitializes this mutex | ||||
| * \see NodeOperation.getMutex retrieve a pointer to this mutex. | * \see NodeOperation.getMutex retrieve a pointer to this mutex. | ||||
| */ | */ | ||||
| ThreadMutex m_mutex; | ThreadMutex m_mutex; | ||||
| /** | /** | ||||
| * \brief reference to the editing bNodeTree, used for break and update callback | * \brief reference to the editing bNodeTree, used for break and update callback | ||||
| */ | */ | ||||
| const bNodeTree *m_btree; | const bNodeTree *m_btree; | ||||
| protected: | protected: | ||||
| /** | /** | ||||
| * Compositor execution model. | * Compositor execution model. | ||||
| */ | */ | ||||
| eExecutionModel execution_model_; | eExecutionModel execution_model_; | ||||
| /** | rcti canvas_; | ||||
| * Width of the output of this operation. | |||||
| */ | |||||
| unsigned int m_width; | |||||
| /** | |||||
| * Height of the output of this operation. | |||||
| */ | |||||
| unsigned int m_height; | |||||
| /** | /** | ||||
| * Flags how to evaluate this operation. | * Flags how to evaluate this operation. | ||||
| */ | */ | ||||
| NodeOperationFlags flags; | NodeOperationFlags flags; | ||||
| ExecutionSystem *exec_system_; | ExecutionSystem *exec_system_; | ||||
| public: | public: | ||||
| virtual ~NodeOperation() | virtual ~NodeOperation() | ||||
| { | { | ||||
| } | } | ||||
| void set_execution_model(const eExecutionModel model) | |||||
| { | |||||
| execution_model_ = model; | |||||
| } | |||||
| void set_name(const std::string name) | void set_name(const std::string name) | ||||
| { | { | ||||
| m_name = name; | m_name = name; | ||||
| } | } | ||||
| const std::string get_name() const | const std::string get_name() const | ||||
| { | { | ||||
| return m_name; | return m_name; | ||||
| } | } | ||||
| void set_id(const int id) | void set_id(const int id) | ||||
| { | { | ||||
| m_id = id; | m_id = id; | ||||
| } | } | ||||
| const int get_id() const | const int get_id() const | ||||
| { | { | ||||
| return m_id; | return m_id; | ||||
| } | } | ||||
| float get_constant_value_default(float default_value); | |||||
| const float *get_constant_elem_default(const float *default_elem); | |||||
| const NodeOperationFlags get_flags() const | const NodeOperationFlags get_flags() const | ||||
| { | { | ||||
| return flags; | return flags; | ||||
| } | } | ||||
| std::optional<NodeOperationHash> generate_hash(); | std::optional<NodeOperationHash> generate_hash(); | ||||
| unsigned int getNumberOfInputSockets() const | unsigned int getNumberOfInputSockets() const | ||||
| Show All 9 Lines | public: | ||||
| NodeOperation *get_input_operation(int index) | NodeOperation *get_input_operation(int index) | ||||
| { | { | ||||
| /* TODO: Rename protected getInputOperation to get_input_operation and make it public replacing | /* TODO: Rename protected getInputOperation to get_input_operation and make it public replacing | ||||
| * this method. */ | * this method. */ | ||||
| return getInputOperation(index); | return getInputOperation(index); | ||||
| } | } | ||||
| /** | virtual void determine_canvas(const rcti &preferred_area, rcti &r_area); | ||||
| * \brief determine the resolution of this node | |||||
| * \note this method will not set the resolution, this is the responsibility of the caller | |||||
| * \param resolution: the result of this operation | |||||
| * \param preferredResolution: the preferable resolution as no resolution could be determined | |||||
| */ | |||||
| virtual void determineResolution(unsigned int resolution[2], | |||||
| unsigned int preferredResolution[2]); | |||||
| /** | /** | ||||
| * \brief isOutputOperation determines whether this operation is an output of the | * \brief isOutputOperation determines whether this operation is an output of the | ||||
| * ExecutionSystem during rendering or editing. | * ExecutionSystem during rendering or editing. | ||||
| * | * | ||||
| * Default behavior if not overridden, this operation will not be evaluated as being an output | * Default behavior if not overridden, this operation will not be evaluated as being an output | ||||
| * of the ExecutionSystem. | * of the ExecutionSystem. | ||||
| * | * | ||||
| * \see ExecutionSystem | * \see ExecutionSystem | ||||
| * \ingroup check | * \ingroup check | ||||
| * \param rendering: [true false] | * \param rendering: [true false] | ||||
| * true: rendering | * true: rendering | ||||
| * false: editing | * false: editing | ||||
| * | * | ||||
| * \return bool the result of this method | * \return bool the result of this method | ||||
| */ | */ | ||||
| virtual bool isOutputOperation(bool /*rendering*/) const | virtual bool isOutputOperation(bool /*rendering*/) const | ||||
| { | { | ||||
| return false; | return false; | ||||
| } | } | ||||
| void set_execution_model(const eExecutionModel model) | |||||
| { | |||||
| execution_model_ = model; | |||||
| } | |||||
| void setbNodeTree(const bNodeTree *tree) | void setbNodeTree(const bNodeTree *tree) | ||||
| { | { | ||||
| this->m_btree = tree; | this->m_btree = tree; | ||||
| } | } | ||||
| void set_execution_system(ExecutionSystem *system) | void set_execution_system(ExecutionSystem *system) | ||||
| { | { | ||||
| exec_system_ = system; | exec_system_ = system; | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | virtual void executeOpenCL(OpenCLDevice * /*device*/, | ||||
| cl_mem /*clOutputBuffer*/, | cl_mem /*clOutputBuffer*/, | ||||
| MemoryBuffer ** /*inputMemoryBuffers*/, | MemoryBuffer ** /*inputMemoryBuffers*/, | ||||
| std::list<cl_mem> * /*clMemToCleanUp*/, | std::list<cl_mem> * /*clMemToCleanUp*/, | ||||
| std::list<cl_kernel> * /*clKernelsToCleanUp*/) | std::list<cl_kernel> * /*clKernelsToCleanUp*/) | ||||
| { | { | ||||
| } | } | ||||
| virtual void deinitExecution(); | virtual void deinitExecution(); | ||||
| /** | void set_canvas(const rcti &canvas_area); | ||||
| * \brief set the resolution | const rcti &get_canvas() const; | ||||
| * \param resolution: the resolution to set | void unset_canvas(); | ||||
| */ | |||||
| void setResolution(unsigned int resolution[2]) | |||||
| { | |||||
| if (!this->flags.is_resolution_set) { | |||||
| this->m_width = resolution[0]; | |||||
| this->m_height = resolution[1]; | |||||
| this->flags.is_resolution_set = true; | |||||
| } | |||||
| } | |||||
| /** | /** | ||||
| * \brief is this operation the active viewer output | * \brief is this operation the active viewer output | ||||
| * user can select an ViewerNode to be active | * user can select an ViewerNode to be active | ||||
| * (the result of this node will be drawn on the backdrop). | * (the result of this node will be drawn on the backdrop). | ||||
| * \return [true:false] | * \return [true:false] | ||||
| * \see BaseViewerOperation | * \see BaseViewerOperation | ||||
| */ | */ | ||||
| virtual bool isActiveViewerOutput() const | virtual bool isActiveViewerOutput() const | ||||
| { | { | ||||
| return false; | return false; | ||||
| } | } | ||||
| virtual bool determineDependingAreaOfInterest(rcti *input, | virtual bool determineDependingAreaOfInterest(rcti *input, | ||||
| ReadBufferOperation *readOperation, | ReadBufferOperation *readOperation, | ||||
| rcti *output); | rcti *output); | ||||
| /** | /** | ||||
| * \brief set the index of the input socket that will determine the resolution of this | * \brief set the index of the input socket that will determine the canvas of this | ||||
| * operation \param index: the index to set | * operation \param index: the index to set | ||||
| */ | */ | ||||
| void setResolutionInputSocketIndex(unsigned int index); | void set_canvas_input_index(unsigned int index); | ||||
| /** | /** | ||||
| * Set a custom function to modify determined resolution from main input just before setting it | * Set a custom function to modify determined canvas from main input just before setting it | ||||
| * as preferred resolution for the other inputs. | * as preferred for the other inputs. | ||||
| */ | */ | ||||
| void set_determined_resolution_modifier(std::function<void(unsigned int resolution[2])> fn) | void set_determined_canvas_modifier(std::function<void(rcti &canvas)> fn) | ||||
| { | { | ||||
| modify_determined_resolution_fn_ = fn; | modify_determined_canvas_fn_ = fn; | ||||
| } | } | ||||
| /** | /** | ||||
| * \brief get the render priority of this node. | * \brief get the render priority of this node. | ||||
| * \note only applicable for output operations like ViewerOperation | * \note only applicable for output operations like ViewerOperation | ||||
| * \return eCompositorPriority | * \return eCompositorPriority | ||||
| */ | */ | ||||
| virtual eCompositorPriority getRenderPriority() const | virtual eCompositorPriority getRenderPriority() const | ||||
| Show All 10 Lines | public: | ||||
| { | { | ||||
| if (this->m_btree->update_draw) { | if (this->m_btree->update_draw) { | ||||
| this->m_btree->update_draw(this->m_btree->udh); | this->m_btree->update_draw(this->m_btree->udh); | ||||
| } | } | ||||
| } | } | ||||
| unsigned int getWidth() const | unsigned int getWidth() const | ||||
| { | { | ||||
| return m_width; | return BLI_rcti_size_x(&get_canvas()); | ||||
| } | } | ||||
| unsigned int getHeight() const | unsigned int getHeight() const | ||||
| { | { | ||||
| return m_height; | return BLI_rcti_size_y(&get_canvas()); | ||||
| } | } | ||||
| inline void readSampled(float result[4], float x, float y, PixelSampler sampler) | inline void readSampled(float result[4], float x, float y, PixelSampler sampler) | ||||
| { | { | ||||
| executePixelSampled(result, x, y, sampler); | executePixelSampled(result, x, y, sampler); | ||||
| } | } | ||||
| inline void readFiltered(float result[4], float x, float y, float dx[2], float dy[2]) | inline void readFiltered(float result[4], float x, float y, float dx[2], float dy[2]) | ||||
| ▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | protected: | ||||
| template<typename T1, typename T2, typename T3> void hash_params(T1 param1, T2 param2, T3 param3) | template<typename T1, typename T2, typename T3> void hash_params(T1 param1, T2 param2, T3 param3) | ||||
| { | { | ||||
| combine_hashes(params_hash_, get_default_hash_3(param1, param2, param3)); | combine_hashes(params_hash_, get_default_hash_3(param1, param2, param3)); | ||||
| } | } | ||||
| void addInputSocket(DataType datatype, ResizeMode resize_mode = ResizeMode::Center); | void addInputSocket(DataType datatype, ResizeMode resize_mode = ResizeMode::Center); | ||||
| void addOutputSocket(DataType datatype); | void addOutputSocket(DataType datatype); | ||||
| /* TODO(manzanilla): to be removed with tiled implementation. */ | |||||
| void setWidth(unsigned int width) | void setWidth(unsigned int width) | ||||
| { | { | ||||
| this->m_width = width; | canvas_.xmax = canvas_.xmin + width; | ||||
| this->flags.is_resolution_set = true; | this->flags.is_canvas_set = true; | ||||
| } | } | ||||
| void setHeight(unsigned int height) | void setHeight(unsigned int height) | ||||
| { | { | ||||
| this->m_height = height; | canvas_.ymax = canvas_.ymin + height; | ||||
| this->flags.is_resolution_set = true; | this->flags.is_canvas_set = true; | ||||
| } | } | ||||
| SocketReader *getInputSocketReader(unsigned int inputSocketindex); | SocketReader *getInputSocketReader(unsigned int inputSocketindex); | ||||
| NodeOperation *getInputOperation(unsigned int inputSocketindex); | NodeOperation *getInputOperation(unsigned int inputSocketindex); | ||||
| void deinitMutex(); | void deinitMutex(); | ||||
| void initMutex(); | void initMutex(); | ||||
| void lockMutex(); | void lockMutex(); | ||||
| void unlockMutex(); | void unlockMutex(); | ||||
| ▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines | |||||