Cleanup: Remove SocketReader.

SocketReader was added as an easier to understand interface on top of
the NodeOperation. It was implemented as a base class of the
NodeOperation and adds an additional hierarchy level.

Ths change replaces the abstract class with a typedef. In the end we
want to remove the typedef but will wait for some new nodes before doing
so.
This commit is contained in:
Jeroen Bakker 2021-03-26 14:02:36 +01:00
parent e5fb7eac85
commit f725f42af5
6 changed files with 114 additions and 178 deletions

View File

@ -87,8 +87,6 @@ set(SRC
intern/COM_OpenCLDevice.h
intern/COM_SingleThreadedOperation.cc
intern/COM_SingleThreadedOperation.h
intern/COM_SocketReader.cc
intern/COM_SocketReader.h
intern/COM_WorkPackage.cc
intern/COM_WorkPackage.h
intern/COM_WorkScheduler.cc

View File

@ -22,7 +22,6 @@ class MemoryBuffer;
#include "COM_ExecutionGroup.h"
#include "COM_MemoryProxy.h"
#include "COM_SocketReader.h"
#include "BLI_math.h"
#include "BLI_rect.h"

View File

@ -28,8 +28,8 @@
#include "COM_MemoryBuffer.h"
#include "COM_MemoryProxy.h"
#include "COM_MetaData.h"
#include "COM_Node.h"
#include "COM_SocketReader.h"
#include "clew.h"
@ -40,6 +40,9 @@ class WriteBufferOperation;
class NodeOperationInput;
class NodeOperationOutput;
class NodeOperation;
typedef NodeOperation SocketReader;
/**
* \brief Resize modes of inputsockets
* How are the input and working resolutions matched
@ -64,13 +67,19 @@ typedef enum InputResizeMode {
COM_SC_STRETCH = NS_CR_STRETCH,
} InputResizeMode;
enum class PixelSampler {
Nearest = 0,
Bilinear = 1,
Bicubic = 2,
};
/**
* \brief NodeOperation contains calculation logic
*
* Subclasses needs to implement the execution method (defined in SocketReader) to implement logic.
* \ingroup Model
*/
class NodeOperation : public SocketReader {
class NodeOperation {
public:
typedef std::vector<NodeOperationInput *> Inputs;
typedef std::vector<NodeOperationOutput *> Outputs;
@ -119,6 +128,17 @@ class NodeOperation : public SocketReader {
*/
bool m_isResolutionSet;
protected:
/**
* Width of the output of this operation.
*/
unsigned int m_width;
/**
* Height of the output of this operation.
*/
unsigned int m_height;
public:
virtual ~NodeOperation();
@ -373,6 +393,54 @@ class NodeOperation : public SocketReader {
}
}
unsigned int getWidth() const
{
return m_width;
}
unsigned int getHeight() const
{
return m_height;
}
inline void readSampled(float result[4], float x, float y, PixelSampler sampler)
{
executePixelSampled(result, x, y, sampler);
}
inline void readFiltered(float result[4], float x, float y, float dx[2], float dy[2])
{
executePixelFiltered(result, x, y, dx, dy);
}
inline void read(float result[4], int x, int y, void *chunkData)
{
executePixel(result, x, y, chunkData);
}
virtual void *initializeTileData(rcti * /*rect*/)
{
return 0;
}
virtual void deinitializeTileData(rcti * /*rect*/, void * /*data*/)
{
}
virtual MemoryBuffer *getInputMemoryBuffer(MemoryBuffer ** /*memoryBuffers*/)
{
return 0;
}
/**
* Return the meta data associated with this branch.
*
* The return parameter holds an instance or is an nullptr. */
virtual std::unique_ptr<MetaData> getMetaData() const
{
return std::unique_ptr<MetaData>();
}
protected:
NodeOperation();
@ -416,6 +484,50 @@ class NodeOperation : public SocketReader {
this->m_openCL = openCL;
}
/**
* \brief calculate a single pixel
* \note this method is called for non-complex
* \param result: is a float[4] array to store the result
* \param x: the x-coordinate of the pixel to calculate in image space
* \param y: the y-coordinate of the pixel to calculate in image space
* \param inputBuffers: chunks that can be read by their ReadBufferOperation.
*/
virtual void executePixelSampled(float /*output*/[4],
float /*x*/,
float /*y*/,
PixelSampler /*sampler*/)
{
}
/**
* \brief calculate a single pixel
* \note this method is called for complex
* \param result: is a float[4] array to store the result
* \param x: the x-coordinate of the pixel to calculate in image space
* \param y: the y-coordinate of the pixel to calculate in image space
* \param inputBuffers: chunks that can be read by their ReadBufferOperation.
* \param chunkData: chunk specific data a during execution time.
*/
virtual void executePixel(float output[4], int x, int y, void * /*chunkData*/)
{
executePixelSampled(output, x, y, PixelSampler::Nearest);
}
/**
* \brief calculate a single pixel using an EWA filter
* \note this method is called for complex
* \param result: is a float[4] array to store the result
* \param x: the x-coordinate of the pixel to calculate in image space
* \param y: the y-coordinate of the pixel to calculate in image space
* \param dx:
* \param dy:
* \param inputBuffers: chunks that can be read by their ReadBufferOperation.
*/
virtual void executePixelFiltered(
float /*output*/[4], float /*x*/, float /*y*/, float /*dx*/[2], float /*dy*/[2])
{
}
/* allow the DebugInfo class to look at internals */
friend class DebugInfo;

View File

@ -1,19 +0,0 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright 2011, Blender Foundation.
*/
#include "COM_SocketReader.h"

View File

@ -1,153 +0,0 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright 2011, Blender Foundation.
*/
#pragma once
#include "BLI_rect.h"
#include "COM_MetaData.h"
#include "COM_defines.h"
#include <memory>
#include <optional>
#ifdef WITH_CXX_GUARDEDALLOC
# include "MEM_guardedalloc.h"
#endif
enum class PixelSampler {
Nearest = 0,
Bilinear = 1,
Bicubic = 2,
};
class MemoryBuffer;
/**
* \brief Helper class for reading socket data.
* Only use this class for dispatching (un-ary and n-ary) executions.
* \ingroup Execution
*/
class SocketReader {
private:
protected:
/**
* \brief Holds the width of the output of this operation.
*/
unsigned int m_width;
/**
* \brief Holds the height of the output of this operation.
*/
unsigned int m_height;
/**
* \brief calculate a single pixel
* \note this method is called for non-complex
* \param result: is a float[4] array to store the result
* \param x: the x-coordinate of the pixel to calculate in image space
* \param y: the y-coordinate of the pixel to calculate in image space
* \param inputBuffers: chunks that can be read by their ReadBufferOperation.
*/
virtual void executePixelSampled(float /*output*/[4],
float /*x*/,
float /*y*/,
PixelSampler /*sampler*/)
{
}
/**
* \brief calculate a single pixel
* \note this method is called for complex
* \param result: is a float[4] array to store the result
* \param x: the x-coordinate of the pixel to calculate in image space
* \param y: the y-coordinate of the pixel to calculate in image space
* \param inputBuffers: chunks that can be read by their ReadBufferOperation.
* \param chunkData: chunk specific data a during execution time.
*/
virtual void executePixel(float output[4], int x, int y, void * /*chunkData*/)
{
executePixelSampled(output, x, y, PixelSampler::Nearest);
}
/**
* \brief calculate a single pixel using an EWA filter
* \note this method is called for complex
* \param result: is a float[4] array to store the result
* \param x: the x-coordinate of the pixel to calculate in image space
* \param y: the y-coordinate of the pixel to calculate in image space
* \param dx:
* \param dy:
* \param inputBuffers: chunks that can be read by their ReadBufferOperation.
*/
virtual void executePixelFiltered(
float /*output*/[4], float /*x*/, float /*y*/, float /*dx*/[2], float /*dy*/[2])
{
}
public:
inline void readSampled(float result[4], float x, float y, PixelSampler sampler)
{
executePixelSampled(result, x, y, sampler);
}
inline void read(float result[4], int x, int y, void *chunkData)
{
executePixel(result, x, y, chunkData);
}
inline void readFiltered(float result[4], float x, float y, float dx[2], float dy[2])
{
executePixelFiltered(result, x, y, dx, dy);
}
virtual void *initializeTileData(rcti * /*rect*/)
{
return 0;
}
virtual void deinitializeTileData(rcti * /*rect*/, void * /*data*/)
{
}
virtual ~SocketReader()
{
}
virtual MemoryBuffer *getInputMemoryBuffer(MemoryBuffer ** /*memoryBuffers*/)
{
return 0;
}
inline unsigned int getWidth() const
{
return this->m_width;
}
inline unsigned int getHeight() const
{
return this->m_height;
}
/* Return the meta data associated with this branch.
*
* The return parameter holds an instance or is an nullptr. */
virtual std::unique_ptr<MetaData> getMetaData() const
{
return std::unique_ptr<MetaData>();
}
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("COM:SocketReader")
#endif
};

View File

@ -20,7 +20,6 @@
#include "COM_MemoryProxy.h"
#include "COM_NodeOperation.h"
#include "COM_SocketReader.h"
/**
* \brief NodeOperation to write to a tile
* \ingroup Operation