svn merge ^/trunk/blender -r49763:49774
[blender.git] / source / blender / compositor / intern / COM_NodeOperation.cpp
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 <typeinfo>
24 #include <stdio.h>
25
26 #include "COM_NodeOperation.h"
27 #include "COM_InputSocket.h"
28 #include "COM_SocketConnection.h"
29 #include "COM_defines.h"
30
31 NodeOperation::NodeOperation() : NodeBase()
32 {
33         this->m_resolutionInputSocketIndex = 0;
34         this->m_complex = false;
35         this->m_width = 0;
36         this->m_height = 0;
37         this->m_openCL = false;
38         this->m_btree = NULL;
39 }
40
41 void NodeOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
42 {
43         unsigned int temp[2];
44         unsigned int temp2[2];
45         vector<InputSocket *> &inputsockets = this->getInputSockets();
46         
47         for (unsigned int index = 0; index < inputsockets.size(); index++) {
48                 InputSocket *inputSocket = inputsockets[index];
49                 if (inputSocket->isConnected()) {
50                         if (index == this->m_resolutionInputSocketIndex) {
51                                 inputSocket->determineResolution(resolution, preferredResolution);
52                                 temp2[0] = resolution[0];
53                                 temp2[1] = resolution[1];
54                                 break;
55                         }
56                 }
57         }
58         for (unsigned int index = 0; index < inputsockets.size(); index++) {
59                 InputSocket *inputSocket = inputsockets[index];
60                 if (inputSocket->isConnected()) {
61                         if (index != this->m_resolutionInputSocketIndex) {
62                                 inputSocket->determineResolution(temp, temp2);
63                         }
64                 }
65         }
66 }
67 void NodeOperation::setResolutionInputSocketIndex(unsigned int index)
68 {
69         this->m_resolutionInputSocketIndex = index;
70 }
71 void NodeOperation::initExecution()
72 {
73         /* pass */
74 }
75
76 void NodeOperation::initMutex()
77 {
78         BLI_mutex_init(&this->m_mutex);
79 }
80
81 void NodeOperation::lockMutex()
82 {
83         BLI_mutex_lock(&this->m_mutex);
84 }
85
86 void NodeOperation::unlockMutex()
87 {
88         BLI_mutex_unlock(&this->m_mutex);
89 }
90
91 void NodeOperation::deinitMutex()
92 {
93         BLI_mutex_end(&this->m_mutex);
94 }
95
96 void NodeOperation::deinitExecution()
97 {
98         /* pass */
99 }
100 SocketReader *NodeOperation::getInputSocketReader(unsigned int inputSocketIndex)
101 {
102         return this->getInputSocket(inputSocketIndex)->getReader();
103 }
104 NodeOperation *NodeOperation::getInputOperation(unsigned int inputSocketIndex)
105 {
106         return this->getInputSocket(inputSocketIndex)->getOperation();
107 }
108
109 void NodeOperation::getConnectedInputSockets(vector<InputSocket *> *sockets)
110 {
111         vector<InputSocket *> &inputsockets = this->getInputSockets();
112         for (vector<InputSocket *>::iterator iterator = inputsockets.begin(); iterator != inputsockets.end(); iterator++) {
113                 InputSocket *socket = *iterator;
114                 if (socket->isConnected()) {
115                         sockets->push_back(socket);
116                 }
117         }
118 }
119
120 bool NodeOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
121 {
122         if (this->isInputNode()) {
123                 BLI_rcti_init(output, input->xmin, input->xmax, input->ymin, input->ymax);
124                 return false;
125         }
126         else {
127                 unsigned int index;
128                 vector<InputSocket *> &inputsockets = this->getInputSockets();
129         
130                 for (index = 0; index < inputsockets.size(); index++) {
131                         InputSocket *inputsocket = inputsockets[index];
132                         if (inputsocket->isConnected()) {
133                                 NodeOperation *inputoperation = (NodeOperation *)inputsocket->getConnection()->getFromNode();
134                                 bool result = inputoperation->determineDependingAreaOfInterest(input, readOperation, output);
135                                 if (result) {
136                                         return true;
137                                 }
138                         }
139                 }
140                 return false;
141         }
142 }