Changeset View
Changeset View
Standalone View
Standalone View
source/blender/compositor/intern/COM_NodeOperation.h
| Show All 16 Lines | |||||
| */ | */ | ||||
| #pragma once | #pragma once | ||||
| #include <list> | #include <list> | ||||
| #include <sstream> | #include <sstream> | ||||
| #include <string> | #include <string> | ||||
| #include "BLI_ghash.h" | |||||
| #include "BLI_hash.hh" | |||||
| #include "BLI_math_color.h" | #include "BLI_math_color.h" | ||||
| #include "BLI_math_vector.h" | #include "BLI_math_vector.h" | ||||
| #include "BLI_threads.h" | #include "BLI_threads.h" | ||||
| #include "COM_Enums.h" | #include "COM_Enums.h" | ||||
| #include "COM_MemoryBuffer.h" | #include "COM_MemoryBuffer.h" | ||||
| #include "COM_MemoryProxy.h" | #include "COM_MemoryProxy.h" | ||||
| #include "COM_MetaData.h" | #include "COM_MetaData.h" | ||||
| ▲ Show 20 Lines • Show All 231 Lines • ▼ Show 20 Lines | NodeOperationFlags() | ||||
| is_preview_operation = false; | is_preview_operation = false; | ||||
| use_datatype_conversion = true; | use_datatype_conversion = true; | ||||
| is_fullframe_operation = false; | is_fullframe_operation = false; | ||||
| is_constant_operation = false; | is_constant_operation = false; | ||||
| can_be_constant = false; | can_be_constant = false; | ||||
| } | } | ||||
| }; | }; | ||||
| /** Hash that identifies an operation output result in the current execution. */ | |||||
| struct NodeOperationHash { | |||||
| private: | |||||
| NodeOperation *operation_; | |||||
| size_t type_hash_; | |||||
| size_t parents_hash_; | |||||
| size_t params_hash_; | |||||
| friend class NodeOperation; | |||||
| public: | |||||
| NodeOperation *get_operation() const | |||||
| { | |||||
| return operation_; | |||||
| } | |||||
| bool operator==(const NodeOperationHash &other) const | |||||
| { | |||||
| return type_hash_ == other.type_hash_ && parents_hash_ == other.parents_hash_ && | |||||
| params_hash_ == other.params_hash_; | |||||
| } | |||||
| bool operator!=(const NodeOperationHash &other) const | |||||
| { | |||||
| return !(*this == other); | |||||
| } | |||||
| bool operator<(const NodeOperationHash &other) const | |||||
| { | |||||
| return type_hash_ < other.type_hash_ || | |||||
| (type_hash_ == other.type_hash_ && parents_hash_ < other.parents_hash_) || | |||||
| (type_hash_ == other.type_hash_ && parents_hash_ == other.parents_hash_ && | |||||
| params_hash_ < other.params_hash_); | |||||
| } | |||||
| }; | |||||
| /** | /** | ||||
| * \brief NodeOperation contains calculation logic | * \brief NodeOperation contains calculation logic | ||||
| * | * | ||||
| * Subclasses needs to implement the execution method (defined in SocketReader) to implement logic. | * Subclasses needs to implement the execution method (defined in SocketReader) to implement logic. | ||||
| * \ingroup Model | * \ingroup Model | ||||
| */ | */ | ||||
| class NodeOperation { | class NodeOperation { | ||||
| private: | private: | ||||
| int m_id; | int m_id; | ||||
| std::string m_name; | std::string m_name; | ||||
| Vector<NodeOperationInput> m_inputs; | Vector<NodeOperationInput> m_inputs; | ||||
| Vector<NodeOperationOutput> m_outputs; | Vector<NodeOperationOutput> m_outputs; | ||||
| uint64_t params_hash_; | |||||
| 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 resolution | ||||
| */ | */ | ||||
| unsigned int m_resolutionInputSocketIndex; | unsigned int m_resolutionInputSocketIndex; | ||||
| std::function<void(unsigned int resolution[2])> modify_determined_resolution_fn_; | std::function<void(unsigned int resolution[2])> modify_determined_resolution_fn_; | ||||
| /** | /** | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | const int get_id() const | ||||
| return m_id; | return m_id; | ||||
| } | } | ||||
| const NodeOperationFlags get_flags() const | const NodeOperationFlags get_flags() const | ||||
| { | { | ||||
| return flags; | return flags; | ||||
| } | } | ||||
| std::optional<NodeOperationHash> generate_hash(); | |||||
| unsigned int getNumberOfInputSockets() const | unsigned int getNumberOfInputSockets() const | ||||
| { | { | ||||
| return m_inputs.size(); | return m_inputs.size(); | ||||
| } | } | ||||
| unsigned int getNumberOfOutputSockets() const | unsigned int getNumberOfOutputSockets() const | ||||
| { | { | ||||
| return m_outputs.size(); | return m_outputs.size(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 245 Lines • ▼ Show 20 Lines | public: | ||||
| virtual void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area); | virtual void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area); | ||||
| void get_area_of_interest(NodeOperation *input_op, const rcti &output_area, rcti &r_input_area); | void get_area_of_interest(NodeOperation *input_op, const rcti &output_area, rcti &r_input_area); | ||||
| /** \} */ | /** \} */ | ||||
| protected: | protected: | ||||
| NodeOperation(); | NodeOperation(); | ||||
| /* Overriden by subclasses to allow merging equal operations on compiling. Implementations must | |||||
| * hash any subclass parameter that affects the output result using `hash_params` methods. */ | |||||
| virtual void hash_output_params() | |||||
| { | |||||
| is_hash_output_params_implemented_ = false; | |||||
| } | |||||
| static void combine_hashes(size_t &combined, size_t other) | |||||
| { | |||||
| combined = BLI_ghashutil_combine_hash(combined, other); | |||||
| } | |||||
| template<typename T> void hash_param(T param) | |||||
| { | |||||
| combine_hashes(params_hash_, get_default_hash(param)); | |||||
| } | |||||
| template<typename T1, typename T2> void hash_params(T1 param1, T2 param2) | |||||
| { | |||||
| combine_hashes(params_hash_, get_default_hash_2(param1, param2)); | |||||
| } | |||||
| 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)); | |||||
| } | |||||
| 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); | ||||
| void setWidth(unsigned int width) | void setWidth(unsigned int width) | ||||
| { | { | ||||
| this->m_width = width; | this->m_width = width; | ||||
| this->flags.is_resolution_set = true; | this->flags.is_resolution_set = true; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 99 Lines • Show Last 20 Lines | |||||