Cleanup: Replace virtual methods with bitflags.

This commit is contained in:
Jeroen Bakker 2021-03-30 08:23:09 +02:00
parent 5a6d5d20de
commit 3ead9b2b36
11 changed files with 32 additions and 64 deletions

View File

@ -106,7 +106,7 @@ bool ExecutionGroup::addOperation(NodeOperation *operation)
!operation->get_flags().is_write_buffer_operation) {
m_flags.complex = operation->get_flags().complex;
m_flags.open_cl = operation->get_flags().open_cl;
m_flags.single_threaded = operation->isSingleThreaded();
m_flags.single_threaded = operation->get_flags().single_threaded;
m_flags.initialized = true;
}
@ -191,7 +191,7 @@ blender::Array<unsigned int> ExecutionGroup::determine_chunk_execution_order() c
float centerY = 0.5f;
ChunkOrdering order_type = ChunkOrdering::Default;
if (operation->isViewerOperation()) {
if (operation->get_flags().is_viewer_operation) {
ViewerOperation *viewer = (ViewerOperation *)operation;
centerX = viewer->getCenterX();
centerY = viewer->getCenterY();

View File

@ -182,6 +182,8 @@ struct NodeOperationFlags {
*/
bool open_cl : 1;
bool single_threaded : 1;
/**
* Does the operation needs a viewer border.
* Basically, setting border need to happen for only operations
@ -210,10 +212,22 @@ struct NodeOperationFlags {
bool is_set_operation : 1;
bool is_write_buffer_operation : 1;
bool is_read_buffer_operation : 1;
bool is_proxy_operation : 1;
bool is_viewer_operation : 1;
bool is_preview_operation : 1;
/**
* When set additional data conversion operations are added to
* convert the data. SocketProxyOperation don't always need to do data conversions.
*
* By default data conversions are enabled.
*/
bool use_datatype_conversion : 1;
NodeOperationFlags()
{
complex = false;
single_threaded = false;
open_cl = false;
use_render_border = false;
use_viewer_border = false;
@ -221,6 +235,10 @@ struct NodeOperationFlags {
is_set_operation = false;
is_read_buffer_operation = false;
is_write_buffer_operation = false;
is_proxy_operation = false;
is_viewer_operation = false;
is_preview_operation = false;
use_datatype_conversion = true;
}
};
@ -330,11 +348,6 @@ class NodeOperation {
return false;
}
virtual int isSingleThreaded()
{
return false;
}
void setbNodeTree(const bNodeTree *tree)
{
this->m_btree = tree;
@ -442,24 +455,6 @@ class NodeOperation {
return CompositorPriority::Low;
}
virtual bool isViewerOperation() const
{
return false;
}
virtual bool isPreviewOperation() const
{
return false;
}
virtual bool isProxyOperation() const
{
return false;
}
virtual bool useDatatypeConversion() const
{
return true;
}
inline bool isBraked() const
{
return this->m_btree->test_break(this->m_btree->tbh);

View File

@ -256,7 +256,8 @@ void NodeOperationBuilder::add_datatype_conversions()
/* proxy operations can skip data type conversion */
NodeOperation *from_op = &link.from()->getOperation();
NodeOperation *to_op = &link.to()->getOperation();
if (!(from_op->useDatatypeConversion() || to_op->useDatatypeConversion())) {
if (!(from_op->get_flags().use_datatype_conversion ||
to_op->get_flags().use_datatype_conversion)) {
continue;
}
@ -352,8 +353,8 @@ void NodeOperationBuilder::resolve_proxies()
blender::Vector<Link> proxy_links;
for (const Link &link : m_links) {
/* don't replace links from proxy to proxy, since we may need them for replacing others! */
if (link.from()->getOperation().isProxyOperation() &&
!link.to()->getOperation().isProxyOperation()) {
if (link.from()->getOperation().get_flags().is_proxy_operation &&
!link.to()->getOperation().get_flags().is_proxy_operation) {
proxy_links.append(link);
}
}
@ -364,7 +365,7 @@ void NodeOperationBuilder::resolve_proxies()
do {
/* walk upstream bypassing the proxy operation */
from = from->getOperation().getInputSocket(0)->getLink();
} while (from && from->getOperation().isProxyOperation());
} while (from && from->getOperation().get_flags().is_proxy_operation);
removeInputLink(to);
/* we may not have a final proxy input link,
@ -380,7 +381,7 @@ void NodeOperationBuilder::determineResolutions()
{
/* determine all resolutions of the operations (Width/Height) */
for (NodeOperation *op : m_operations) {
if (op->isOutputOperation(m_context->isRendering()) && !op->isPreviewOperation()) {
if (op->isOutputOperation(m_context->isRendering()) && !op->get_flags().is_preview_operation) {
unsigned int resolution[2] = {0, 0};
unsigned int preferredResolution[2] = {0, 0};
op->determineResolution(resolution, preferredResolution);
@ -389,7 +390,7 @@ void NodeOperationBuilder::determineResolutions()
}
for (NodeOperation *op : m_operations) {
if (op->isOutputOperation(m_context->isRendering()) && op->isPreviewOperation()) {
if (op->isOutputOperation(m_context->isRendering()) && op->get_flags().is_preview_operation) {
unsigned int resolution[2] = {0, 0};
unsigned int preferredResolution[2] = {0, 0};
op->determineResolution(resolution, preferredResolution);

View File

@ -24,6 +24,7 @@ SingleThreadedOperation::SingleThreadedOperation()
{
this->m_cachedInstance = nullptr;
flags.complex = true;
flags.single_threaded = true;
}
void SingleThreadedOperation::initExecution()

View File

@ -53,11 +53,6 @@ class SingleThreadedOperation : public NodeOperation {
void *initializeTileData(rcti *rect) override;
virtual MemoryBuffer *createMemoryBuffer(rcti *rect) = 0;
int isSingleThreaded() override
{
return true;
}
};
} // namespace blender::compositor

View File

@ -51,6 +51,7 @@ PreviewOperation::PreviewOperation(const ColorManagedViewSettings *viewSettings,
this->m_defaultWidth = defaultWidth;
this->m_defaultHeight = defaultHeight;
flags.use_viewer_border = true;
flags.is_preview_operation = true;
}
void PreviewOperation::verifyPreview(bNodeInstanceHash *previews, bNodeInstanceKey key)

View File

@ -63,10 +63,6 @@ class PreviewOperation : public NodeOperation {
bool determineDependingAreaOfInterest(rcti *input,
ReadBufferOperation *readOperation,
rcti *output) override;
bool isPreviewOperation() const override
{
return true;
}
};
} // namespace blender::compositor

View File

@ -21,10 +21,11 @@
namespace blender::compositor {
SocketProxyOperation::SocketProxyOperation(DataType type, bool use_conversion)
: m_use_conversion(use_conversion)
{
this->addInputSocket(type);
this->addOutputSocket(type);
flags.is_proxy_operation = true;
flags.use_datatype_conversion = use_conversion;
}
std::unique_ptr<MetaData> SocketProxyOperation::getMetaData()

View File

@ -26,27 +26,8 @@ class SocketProxyOperation : public NodeOperation {
public:
SocketProxyOperation(DataType type, bool use_conversion);
bool isProxyOperation() const override
{
return true;
}
bool useDatatypeConversion() const override
{
return m_use_conversion;
}
bool getUseConversion() const
{
return m_use_conversion;
}
void setUseConversion(bool use_conversion)
{
m_use_conversion = use_conversion;
}
std::unique_ptr<MetaData> getMetaData() override;
private:
bool m_use_conversion;
};
} // namespace blender::compositor

View File

@ -56,6 +56,7 @@ ViewerOperation::ViewerOperation()
this->m_rd = nullptr;
this->m_viewName = nullptr;
flags.use_viewer_border = true;
flags.is_viewer_operation = true;
}
void ViewerOperation::initExecution()

View File

@ -103,10 +103,6 @@ class ViewerOperation : public NodeOperation {
return this->m_chunkOrder;
}
CompositorPriority getRenderPriority() const override;
bool isViewerOperation() const override
{
return true;
}
void setUseAlphaInput(bool value)
{
this->m_useAlphaInput = value;