~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2011, Blender Foundation.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software Foundation,
 
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 *
 
18
 * Contributor: 
 
19
 *              Jeroen Bakker 
 
20
 *              Monique Dewanchand
 
21
 */
 
22
 
 
23
#include "COM_ExecutionSystemHelper.h"
 
24
 
 
25
#include <sstream>
 
26
#include <stdio.h>
 
27
 
 
28
#include "PIL_time.h"
 
29
#include "BKE_node.h"
 
30
 
 
31
#include "COM_Converter.h"
 
32
#include "COM_NodeOperation.h"
 
33
#include "COM_ExecutionGroup.h"
 
34
#include "COM_NodeBase.h"
 
35
#include "COM_WorkScheduler.h"
 
36
#include "COM_ReadBufferOperation.h"
 
37
#include "COM_GroupNode.h"
 
38
#include "COM_WriteBufferOperation.h"
 
39
#include "COM_ReadBufferOperation.h"
 
40
#include "COM_ViewerBaseOperation.h"
 
41
 
 
42
void ExecutionSystemHelper::addbNodeTree(ExecutionSystem &system, int nodes_start, bNodeTree *tree, bNode *groupnode)
 
43
{
 
44
        vector<Node *>& nodes = system.getNodes();
 
45
        vector<SocketConnection *>& links = system.getConnections();
 
46
        const bNode *activeGroupNode = system.getContext().getActivegNode();
 
47
        bool isActiveGroup = activeGroupNode == groupnode;
 
48
        
 
49
        /* add all nodes of the tree to the node list */
 
50
        bNode *node = (bNode *)tree->nodes.first;
 
51
        while (node != NULL) {
 
52
                Node *nnode = addNode(nodes, node, isActiveGroup, system.getContext().isFastCalculation());
 
53
                nnode->setbNodeGroup(groupnode);
 
54
                node = node->next;
 
55
        }
 
56
 
 
57
        NodeRange node_range(nodes.begin() + nodes_start, nodes.end());
 
58
 
 
59
        /* add all nodelinks of the tree to the link list */
 
60
        bNodeLink *nodelink = (bNodeLink *)tree->links.first;
 
61
        while (nodelink != NULL) {
 
62
                addNodeLink(node_range, links, nodelink);
 
63
                nodelink = nodelink->next;
 
64
        }
 
65
 
 
66
        /* Expand group nodes */
 
67
        for (unsigned int i = nodes_start; i < nodes.size(); ++i) {
 
68
                Node *execnode = nodes[i];
 
69
                if (execnode->isGroupNode()) {
 
70
                        GroupNode *groupNode = (GroupNode *)execnode;
 
71
                        groupNode->ungroup(system);
 
72
                }
 
73
        }
 
74
}
 
75
 
 
76
void ExecutionSystemHelper::addNode(vector<Node *>& nodes, Node *node)
 
77
{
 
78
        nodes.push_back(node);
 
79
}
 
80
 
 
81
Node *ExecutionSystemHelper::addNode(vector<Node *>& nodes, bNode *b_node, bool inActiveGroup, bool fast)
 
82
{
 
83
        Node *node = Converter::convert(b_node, fast);
 
84
        node->setIsInActiveGroup(inActiveGroup);
 
85
        addNode(nodes, node);
 
86
        return node;
 
87
}
 
88
void ExecutionSystemHelper::addOperation(vector<NodeOperation *>& operations, NodeOperation *operation)
 
89
{
 
90
        operations.push_back(operation);
 
91
}
 
92
 
 
93
void ExecutionSystemHelper::addExecutionGroup(vector<ExecutionGroup *>& executionGroups, ExecutionGroup *executionGroup)
 
94
{
 
95
        executionGroups.push_back(executionGroup);
 
96
}
 
97
 
 
98
void ExecutionSystemHelper::findOutputNodeOperations(vector<NodeOperation *> *result, vector<NodeOperation *>& operations, bool rendering)
 
99
{
 
100
        unsigned int index;
 
101
 
 
102
        for (index = 0; index < operations.size(); index++) {
 
103
                NodeOperation *operation = operations[index];
 
104
                if (operation->isOutputOperation(rendering)) {
 
105
                        result->push_back(operation);
 
106
                }
 
107
        }
 
108
}
 
109
 
 
110
static InputSocket *find_input(NodeRange &node_range, bNode *bnode, bNodeSocket *bsocket)
 
111
{
 
112
        if (bnode != NULL) {
 
113
                for (NodeIterator it = node_range.first; it != node_range.second; ++it) {
 
114
                        Node *node = *it;
 
115
                        if (node->getbNode() == bnode)
 
116
                                return node->findInputSocketBybNodeSocket(bsocket);
 
117
                }
 
118
        }
 
119
        else {
 
120
                for (NodeIterator it = node_range.first; it != node_range.second; ++it) {
 
121
                        Node *node = *it;
 
122
                        if (node->isProxyNode()) {
 
123
                                InputSocket *proxySocket = node->getInputSocket(0);
 
124
                                if (proxySocket->getbNodeSocket() == bsocket)
 
125
                                        return proxySocket;
 
126
                        }
 
127
                }
 
128
        }
 
129
        return NULL;
 
130
}
 
131
static OutputSocket *find_output(NodeRange &node_range, bNode *bnode, bNodeSocket *bsocket)
 
132
{
 
133
        if (bnode != NULL) {
 
134
                for (NodeIterator it = node_range.first; it != node_range.second; ++it) {
 
135
                        Node *node = *it;
 
136
                        if (node->getbNode() == bnode)
 
137
                                return node->findOutputSocketBybNodeSocket(bsocket);
 
138
                }
 
139
        }
 
140
        else {
 
141
                for (NodeIterator it = node_range.first; it != node_range.second; ++it) {
 
142
                        Node *node = *it;
 
143
                        if (node->isProxyNode()) {
 
144
                                OutputSocket *proxySocket = node->getOutputSocket(0);
 
145
                                if (proxySocket->getbNodeSocket() == bsocket)
 
146
                                        return proxySocket;
 
147
                        }
 
148
                }
 
149
        }
 
150
        return NULL;
 
151
}
 
152
SocketConnection *ExecutionSystemHelper::addNodeLink(NodeRange &node_range, vector<SocketConnection *>& links, bNodeLink *b_nodelink)
 
153
{
 
154
        /// @note: ignore invalid links
 
155
        if (!(b_nodelink->flag & NODE_LINK_VALID))
 
156
                return NULL;
 
157
 
 
158
        InputSocket *inputSocket = find_input(node_range, b_nodelink->tonode, b_nodelink->tosock);
 
159
        OutputSocket *outputSocket = find_output(node_range, b_nodelink->fromnode, b_nodelink->fromsock);
 
160
        if (inputSocket == NULL || outputSocket == NULL) {
 
161
                return NULL;
 
162
        }
 
163
        if (inputSocket->isConnected()) {
 
164
                return NULL;
 
165
        }
 
166
        SocketConnection *connection = addLink(links, outputSocket, inputSocket);
 
167
        return connection;
 
168
}
 
169
 
 
170
SocketConnection *ExecutionSystemHelper::addLink(vector<SocketConnection *>& links, OutputSocket *fromSocket, InputSocket *toSocket)
 
171
{
 
172
        SocketConnection *newconnection = new SocketConnection();
 
173
        newconnection->setFromSocket(fromSocket);
 
174
        newconnection->setToSocket(toSocket);
 
175
        fromSocket->addConnection(newconnection);
 
176
        toSocket->setConnection(newconnection);
 
177
        links.push_back(newconnection);
 
178
        return newconnection;
 
179
}
 
180
 
 
181
void ExecutionSystemHelper::debugDump(ExecutionSystem *system)
 
182
{
 
183
        Node *node;
 
184
        NodeOperation *operation;
 
185
        ExecutionGroup *group;
 
186
        SocketConnection *connection;
 
187
        int tot, tot2;
 
188
        printf("-- BEGIN COMPOSITOR DUMP --\r\n");
 
189
        printf("digraph compositorexecution {\r\n");
 
190
        tot = system->getNodes().size();
 
191
        for (int i = 0; i < tot; i++) {
 
192
                node = system->getNodes()[i];
 
193
                printf("// NODE: %s\r\n", node->getbNode()->typeinfo->name);
 
194
        }
 
195
        tot = system->getOperations().size();
 
196
        for (int i = 0; i < tot; i++) {
 
197
                operation = system->getOperations()[i];
 
198
                printf("// OPERATION: %p\r\n", operation);
 
199
                printf("\t\"O_%p\"", operation);
 
200
                printf(" [shape=record,label=\"{");
 
201
                tot2 = operation->getNumberOfInputSockets();
 
202
                if (tot2 != 0) {
 
203
                        printf("{");
 
204
                        for (int j = 0; j < tot2; j++) {
 
205
                                InputSocket *socket = operation->getInputSocket(j);
 
206
                                if (j != 0) {
 
207
                                        printf("|");
 
208
                                }
 
209
                                printf("<IN_%p>", socket);
 
210
                                switch (socket->getDataType()) {
 
211
                                        case COM_DT_VALUE:
 
212
                                                printf("Value");
 
213
                                                break;
 
214
                                        case COM_DT_VECTOR:
 
215
                                                printf("Vector");
 
216
                                                break;
 
217
                                        case COM_DT_COLOR:
 
218
                                                printf("Color");
 
219
                                                break;
 
220
                                }
 
221
                        }
 
222
                        printf("}");
 
223
                        printf("|");
 
224
                }
 
225
                if (operation->isViewerOperation()) {
 
226
                        ViewerBaseOperation *viewer = (ViewerBaseOperation *)operation;
 
227
                        if (viewer->isActiveViewerOutput()) {
 
228
                                printf("Active viewer");
 
229
                        }
 
230
                        else {
 
231
                                printf("Viewer");
 
232
                        }
 
233
                }
 
234
                else if (operation->isOutputOperation(system->getContext().isRendering())) {
 
235
                        printf("Output");
 
236
                }
 
237
                else if (operation->isSetOperation()) {
 
238
                        printf("Set");
 
239
                }
 
240
                else if (operation->isReadBufferOperation()) {
 
241
                        printf("ReadBuffer");
 
242
                }
 
243
                else if (operation->isWriteBufferOperation()) {
 
244
                        printf("WriteBuffer");
 
245
                }
 
246
                else {
 
247
                        printf("O_%p", operation);
 
248
                }
 
249
                printf(" (%d,%d)", operation->getWidth(), operation->getHeight());
 
250
                tot2 = operation->getNumberOfOutputSockets();
 
251
                if (tot2 != 0) {
 
252
                        printf("|");
 
253
                        printf("{");
 
254
                        for (int j = 0; j < tot2; j++) {
 
255
                                OutputSocket *socket = operation->getOutputSocket(j);
 
256
                                if (j != 0) {
 
257
                                        printf("|");
 
258
                                }
 
259
                                printf("<OUT_%p>", socket);
 
260
                                switch (socket->getDataType()) {
 
261
                                        case COM_DT_VALUE:
 
262
                                                printf("Value");
 
263
                                                break;
 
264
                                        case COM_DT_VECTOR:
 
265
                                                printf("Vector");
 
266
                                                break;
 
267
                                        case COM_DT_COLOR:
 
268
                                                printf("Color");
 
269
                                                break;
 
270
                                }
 
271
                        }
 
272
                        printf("}");
 
273
                }
 
274
                printf("}\"]");
 
275
                printf("\r\n");
 
276
        }
 
277
        tot = system->getExecutionGroups().size();
 
278
        for (int i = 0; i < tot; i++) {
 
279
                group = system->getExecutionGroups()[i];
 
280
                printf("// GROUP: %d\r\n", i);
 
281
                printf("subgraph {\r\n");
 
282
                printf("//  OUTPUTOPERATION: %p\r\n", group->getOutputNodeOperation());
 
283
                printf(" O_%p\r\n", group->getOutputNodeOperation());
 
284
                printf("}\r\n");
 
285
        }
 
286
        tot = system->getOperations().size();
 
287
        for (int i = 0; i < tot; i++) {
 
288
                operation = system->getOperations()[i];
 
289
                if (operation->isReadBufferOperation()) {
 
290
                        ReadBufferOperation *read = (ReadBufferOperation *)operation;
 
291
                        WriteBufferOperation *write = read->getMemoryProxy()->getWriteBufferOperation();
 
292
                        printf("\t\"O_%p\" -> \"O_%p\" [style=dotted]\r\n", write, read);
 
293
                }
 
294
        }
 
295
        tot = system->getConnections().size();
 
296
        for (int i = 0; i < tot; i++) {
 
297
                connection = system->getConnections()[i];
 
298
                printf("// CONNECTION: %p.%p -> %p.%p\r\n", connection->getFromNode(), connection->getFromSocket(), connection->getToNode(), connection->getToSocket());
 
299
                printf("\t\"O_%p\":\"OUT_%p\" -> \"O_%p\":\"IN_%p\"", connection->getFromNode(), connection->getFromSocket(), connection->getToNode(), connection->getToSocket());
 
300
                if (!connection->isValid()) {
 
301
                        printf(" [color=red]");
 
302
                }
 
303
                else {
 
304
                        switch (connection->getFromSocket()->getDataType()) {
 
305
                                case COM_DT_VALUE:
 
306
                                        printf(" [color=grey]");
 
307
                                        break;
 
308
                                case COM_DT_VECTOR:
 
309
                                        printf(" [color=blue]");
 
310
                                        break;
 
311
                                case COM_DT_COLOR:
 
312
                                        printf(" [color=orange]");
 
313
                                        break;
 
314
                        }
 
315
                }
 
316
                printf("\r\n");
 
317
        }
 
318
        printf("}\r\n");
 
319
        printf("-- END COMPOSITOR DUMP --\r\n");
 
320
}