2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2013 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2013-09-13 13:36:47 +00:00
|
|
|
|
2018-08-08 11:49:51 +10:00
|
|
|
#pragma once
|
2013-09-13 13:36:47 +00:00
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2021-10-13 23:00:24 +02:00
|
|
|
#include "BLI_vector.hh"
|
|
|
|
|
|
2021-04-28 07:56:11 +02:00
|
|
|
#include "COM_ExecutionSystem.h"
|
2021-10-13 23:00:24 +02:00
|
|
|
#include "COM_MemoryBuffer.h"
|
|
|
|
|
#include "COM_Node.h"
|
2013-09-13 13:36:47 +00:00
|
|
|
|
2021-03-23 17:12:27 +01:00
|
|
|
namespace blender::compositor {
|
|
|
|
|
|
2021-04-28 07:56:11 +02:00
|
|
|
static constexpr bool COM_EXPORT_GRAPHVIZ = false;
|
2021-07-06 16:37:23 +02:00
|
|
|
static constexpr bool COM_GRAPHVIZ_SHOW_NODE_NAME = false;
|
|
|
|
|
|
2021-07-19 19:55:15 +02:00
|
|
|
/* Saves operations results to image files. */
|
|
|
|
|
static constexpr bool COM_EXPORT_OPERATION_BUFFERS = false;
|
|
|
|
|
|
2013-09-13 13:36:47 +00:00
|
|
|
class Node;
|
2021-10-13 23:00:24 +02:00
|
|
|
class NodeOperation;
|
2013-09-13 13:36:47 +00:00
|
|
|
class ExecutionSystem;
|
|
|
|
|
class ExecutionGroup;
|
|
|
|
|
|
|
|
|
|
class DebugInfo {
|
|
|
|
|
public:
|
|
|
|
|
typedef enum { EG_WAIT, EG_RUNNING, EG_FINISHED } GroupState;
|
2018-06-17 17:05:29 +02:00
|
|
|
|
2014-04-15 16:06:12 +02:00
|
|
|
typedef std::map<const Node *, std::string> NodeNameMap;
|
|
|
|
|
typedef std::map<const NodeOperation *, std::string> OpNameMap;
|
|
|
|
|
typedef std::map<const ExecutionGroup *, GroupState> GroupStateMap;
|
2018-06-17 17:05:29 +02:00
|
|
|
|
2014-04-15 16:06:12 +02:00
|
|
|
static std::string node_name(const Node *node);
|
|
|
|
|
static std::string operation_name(const NodeOperation *op);
|
2018-06-17 17:05:29 +02:00
|
|
|
|
2021-04-28 07:56:11 +02:00
|
|
|
private:
|
2021-10-13 23:01:04 +02:00
|
|
|
static int file_index_;
|
2021-04-28 07:56:11 +02:00
|
|
|
/** Map nodes to usable names for debug output. */
|
2021-10-13 23:01:04 +02:00
|
|
|
static NodeNameMap node_names_;
|
2021-04-28 07:56:11 +02:00
|
|
|
/** Map operations to usable names for debug output. */
|
2021-10-13 23:01:04 +02:00
|
|
|
static OpNameMap op_names_;
|
2021-04-28 07:56:11 +02:00
|
|
|
/** Base name for all operations added by a node. */
|
2021-10-13 23:01:04 +02:00
|
|
|
static std::string current_node_name_;
|
2021-04-28 07:56:11 +02:00
|
|
|
/** Base name for automatic sub-operations. */
|
2021-10-13 23:01:04 +02:00
|
|
|
static std::string current_op_name_;
|
2021-04-28 07:56:11 +02:00
|
|
|
/** For visualizing group states. */
|
2021-10-13 23:01:04 +02:00
|
|
|
static GroupStateMap group_states_;
|
2021-04-28 07:56:11 +02:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
static void convert_started()
|
|
|
|
|
{
|
|
|
|
|
if (COM_EXPORT_GRAPHVIZ) {
|
2021-10-13 23:01:04 +02:00
|
|
|
op_names_.clear();
|
2021-04-28 07:56:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void execute_started(const ExecutionSystem *system)
|
|
|
|
|
{
|
|
|
|
|
if (COM_EXPORT_GRAPHVIZ) {
|
2021-10-13 23:01:04 +02:00
|
|
|
file_index_ = 1;
|
|
|
|
|
group_states_.clear();
|
|
|
|
|
for (ExecutionGroup *execution_group : system->groups_) {
|
|
|
|
|
group_states_[execution_group] = EG_WAIT;
|
2021-04-28 07:56:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
2021-07-19 19:55:15 +02:00
|
|
|
if (COM_EXPORT_OPERATION_BUFFERS) {
|
|
|
|
|
delete_operation_exports();
|
|
|
|
|
}
|
2021-04-28 07:56:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void node_added(const Node *node)
|
|
|
|
|
{
|
|
|
|
|
if (COM_EXPORT_GRAPHVIZ) {
|
2021-10-13 23:01:15 +02:00
|
|
|
node_names_[node] = std::string(node->get_bnode() ? node->get_bnode()->name : "");
|
2021-04-28 07:56:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
2018-06-17 17:05:29 +02:00
|
|
|
|
2021-04-28 07:56:11 +02:00
|
|
|
static void node_to_operations(const Node *node)
|
|
|
|
|
{
|
|
|
|
|
if (COM_EXPORT_GRAPHVIZ) {
|
2021-10-13 23:01:04 +02:00
|
|
|
current_node_name_ = node_names_[node];
|
2021-04-28 07:56:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
2018-06-17 17:05:29 +02:00
|
|
|
|
2021-04-28 07:56:11 +02:00
|
|
|
static void operation_added(const NodeOperation *operation)
|
|
|
|
|
{
|
|
|
|
|
if (COM_EXPORT_GRAPHVIZ) {
|
2021-10-13 23:01:04 +02:00
|
|
|
op_names_[operation] = current_node_name_;
|
2021-04-28 07:56:11 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void operation_read_write_buffer(const NodeOperation *operation)
|
|
|
|
|
{
|
|
|
|
|
if (COM_EXPORT_GRAPHVIZ) {
|
2021-10-13 23:01:04 +02:00
|
|
|
current_op_name_ = op_names_[operation];
|
2021-04-28 07:56:11 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void execution_group_started(const ExecutionGroup *group)
|
|
|
|
|
{
|
|
|
|
|
if (COM_EXPORT_GRAPHVIZ) {
|
2021-10-13 23:01:04 +02:00
|
|
|
group_states_[group] = EG_RUNNING;
|
2021-04-28 07:56:11 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
static void execution_group_finished(const ExecutionGroup *group)
|
|
|
|
|
{
|
|
|
|
|
if (COM_EXPORT_GRAPHVIZ) {
|
2021-10-13 23:01:04 +02:00
|
|
|
group_states_[group] = EG_FINISHED;
|
2021-04-28 07:56:11 +02:00
|
|
|
}
|
|
|
|
|
};
|
2018-06-17 17:05:29 +02:00
|
|
|
|
2021-07-19 19:55:15 +02:00
|
|
|
static void operation_rendered(const NodeOperation *op, MemoryBuffer *render)
|
|
|
|
|
{
|
|
|
|
|
/* Don't export constant operations as there are too many and it's rarely useful. */
|
|
|
|
|
if (COM_EXPORT_OPERATION_BUFFERS && render && !render->is_a_single_elem()) {
|
|
|
|
|
export_operation(op, render);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 16:16:08 +02:00
|
|
|
static void graphviz(const ExecutionSystem *system, StringRefNull name = "");
|
2018-06-17 17:05:29 +02:00
|
|
|
|
2013-09-13 13:36:47 +00:00
|
|
|
protected:
|
2014-04-15 16:06:12 +02:00
|
|
|
static int graphviz_operation(const ExecutionSystem *system,
|
2021-03-30 09:18:40 +02:00
|
|
|
NodeOperation *operation,
|
2014-04-15 16:06:12 +02:00
|
|
|
const ExecutionGroup *group,
|
|
|
|
|
char *str,
|
|
|
|
|
int maxlen);
|
2013-09-13 13:36:47 +00:00
|
|
|
static int graphviz_legend_color(const char *name, const char *color, char *str, int maxlen);
|
|
|
|
|
static int graphviz_legend_line(
|
|
|
|
|
const char *name, const char *color, const char *style, char *str, int maxlen);
|
|
|
|
|
static int graphviz_legend_group(
|
|
|
|
|
const char *name, const char *color, const char *style, char *str, int maxlen);
|
2021-06-01 10:25:38 +02:00
|
|
|
static int graphviz_legend(char *str, int maxlen, bool has_execution_groups);
|
2014-04-15 16:06:12 +02:00
|
|
|
static bool graphviz_system(const ExecutionSystem *system, char *str, int maxlen);
|
2021-07-19 19:55:15 +02:00
|
|
|
|
|
|
|
|
static void export_operation(const NodeOperation *op, MemoryBuffer *render);
|
|
|
|
|
static void delete_operation_exports();
|
2013-09-13 13:36:47 +00:00
|
|
|
};
|
2021-03-23 17:12:27 +01:00
|
|
|
|
|
|
|
|
} // namespace blender::compositor
|