Cleanup: duplicate includes
[blender-staging.git] / source / blender / compositor / intern / COM_ExecutionGroup.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 <algorithm>
24 #include <math.h>
25 #include <sstream>
26 #include <stdlib.h>
27
28 #include "atomic_ops.h"
29
30 #include "COM_ExecutionGroup.h"
31 #include "COM_defines.h"
32 #include "COM_ExecutionSystem.h"
33 #include "COM_ReadBufferOperation.h"
34 #include "COM_WriteBufferOperation.h"
35 #include "COM_WorkScheduler.h"
36 #include "COM_ViewerOperation.h"
37 #include "COM_ChunkOrder.h"
38 #include "COM_Debug.h"
39
40 #include "MEM_guardedalloc.h"
41 #include "BLI_math.h"
42 #include "BLI_string.h"
43 #include "BKE_global.h"
44 #include "PIL_time.h"
45 #include "WM_api.h"
46 #include "WM_types.h"
47
48 ExecutionGroup::ExecutionGroup()
49 {
50         this->m_isOutput = false;
51         this->m_complex = false;
52         this->m_chunkExecutionStates = NULL;
53         this->m_bTree = NULL;
54         this->m_height = 0;
55         this->m_width = 0;
56         this->m_cachedMaxReadBufferOffset = 0;
57         this->m_numberOfXChunks = 0;
58         this->m_numberOfYChunks = 0;
59         this->m_numberOfChunks = 0;
60         this->m_initialized = false;
61         this->m_openCL = false;
62         this->m_singleThreaded = false;
63         this->m_chunksFinished = 0;
64         BLI_rcti_init(&this->m_viewerBorder, 0, 0, 0, 0);
65         this->m_executionStartTime = 0;
66 }
67
68 CompositorPriority ExecutionGroup::getRenderPriotrity()
69 {
70         return this->getOutputOperation()->getRenderPriority();
71 }
72
73 bool ExecutionGroup::canContainOperation(NodeOperation *operation)
74 {
75         if (!this->m_initialized) { return true; }
76         
77         if (operation->isReadBufferOperation()) { return true; }
78         if (operation->isWriteBufferOperation()) { return false; }
79         if (operation->isSetOperation()) { return true; }
80         
81         /* complex groups don't allow further ops (except read buffer and values, see above) */
82         if (m_complex) { return false; }
83         /* complex ops can't be added to other groups (except their own, which they initialize, see above) */
84         if (operation->isComplex()) { return false; }
85         
86         return true;
87 }
88
89 bool ExecutionGroup::addOperation(NodeOperation *operation)
90 {
91         if (!canContainOperation(operation))
92                 return false;
93         
94         if (!operation->isReadBufferOperation() && !operation->isWriteBufferOperation()) {
95                 m_complex = operation->isComplex();
96                 m_openCL = operation->isOpenCL();
97                 m_singleThreaded = operation->isSingleThreaded();
98                 m_initialized = true;
99         }
100         
101         m_operations.push_back(operation);
102         
103         return true;
104 }
105
106 NodeOperation *ExecutionGroup::getOutputOperation() const
107 {
108         return this->m_operations[0]; // the first operation of the group is always the output operation.
109 }
110
111 void ExecutionGroup::initExecution()
112 {
113         if (this->m_chunkExecutionStates != NULL) {
114                 MEM_freeN(this->m_chunkExecutionStates);
115         }
116         unsigned int index;
117         determineNumberOfChunks();
118
119         this->m_chunkExecutionStates = NULL;
120         if (this->m_numberOfChunks != 0) {
121                 this->m_chunkExecutionStates = (ChunkExecutionState *)MEM_mallocN(sizeof(ChunkExecutionState) * this->m_numberOfChunks, __func__);
122                 for (index = 0; index < this->m_numberOfChunks; index++) {
123                         this->m_chunkExecutionStates[index] = COM_ES_NOT_SCHEDULED;
124                 }
125         }
126
127
128         unsigned int maxNumber = 0;
129
130         for (index = 0; index < this->m_operations.size(); index++) {
131                 NodeOperation *operation = this->m_operations[index];
132                 if (operation->isReadBufferOperation()) {
133                         ReadBufferOperation *readOperation = (ReadBufferOperation *)operation;
134                         this->m_cachedReadOperations.push_back(readOperation);
135                         maxNumber = max(maxNumber, readOperation->getOffset());
136                 }
137         }
138         maxNumber++;
139         this->m_cachedMaxReadBufferOffset = maxNumber;
140
141 }
142
143 void ExecutionGroup::deinitExecution()
144 {
145         if (this->m_chunkExecutionStates != NULL) {
146                 MEM_freeN(this->m_chunkExecutionStates);
147                 this->m_chunkExecutionStates = NULL;
148         }
149         this->m_numberOfChunks = 0;
150         this->m_numberOfXChunks = 0;
151         this->m_numberOfYChunks = 0;
152         this->m_cachedReadOperations.clear();
153         this->m_bTree = NULL;
154 }
155 void ExecutionGroup::determineResolution(unsigned int resolution[2])
156 {
157         NodeOperation *operation = this->getOutputOperation();
158         resolution[0] = operation->getWidth();
159         resolution[1] = operation->getHeight();
160         this->setResolution(resolution);
161         BLI_rcti_init(&this->m_viewerBorder, 0, this->m_width, 0, this->m_height);
162 }
163
164 void ExecutionGroup::determineNumberOfChunks()
165 {
166         if (this->m_singleThreaded) {
167                 this->m_numberOfXChunks = 1;
168                 this->m_numberOfYChunks = 1;
169                 this->m_numberOfChunks = 1;
170         }
171         else {
172                 const float chunkSizef = this->m_chunkSize;
173                 const int border_width = BLI_rcti_size_x(&this->m_viewerBorder);
174                 const int border_height = BLI_rcti_size_y(&this->m_viewerBorder);
175                 this->m_numberOfXChunks = ceil(border_width / chunkSizef);
176                 this->m_numberOfYChunks = ceil(border_height / chunkSizef);
177                 this->m_numberOfChunks = this->m_numberOfXChunks * this->m_numberOfYChunks;
178         }
179 }
180
181 /**
182  * this method is called for the top execution groups. containing the compositor node or the preview node or the viewer node)
183  */
184 void ExecutionGroup::execute(ExecutionSystem *graph)
185 {
186         const CompositorContext &context = graph->getContext();
187         const bNodeTree *bTree = context.getbNodeTree();
188         if (this->m_width == 0 || this->m_height == 0) {return; } /// @note: break out... no pixels to calculate.
189         if (bTree->test_break && bTree->test_break(bTree->tbh)) {return; } /// @note: early break out for blur and preview nodes
190         if (this->m_numberOfChunks == 0) {return; } /// @note: early break out
191         unsigned int chunkNumber;
192
193         this->m_executionStartTime = PIL_check_seconds_timer();
194
195         this->m_chunksFinished = 0;
196         this->m_bTree = bTree;
197         unsigned int index;
198         unsigned int *chunkOrder = (unsigned int *)MEM_mallocN(sizeof(unsigned int) * this->m_numberOfChunks, __func__);
199
200         for (chunkNumber = 0; chunkNumber < this->m_numberOfChunks; chunkNumber++) {
201                 chunkOrder[chunkNumber] = chunkNumber;
202         }
203         NodeOperation *operation = this->getOutputOperation();
204         float centerX = 0.5;
205         float centerY = 0.5;
206         OrderOfChunks chunkorder = COM_ORDER_OF_CHUNKS_DEFAULT;
207
208         if (operation->isViewerOperation()) {
209                 ViewerOperation *viewer = (ViewerOperation *)operation;
210                 centerX = viewer->getCenterX();
211                 centerY = viewer->getCenterY();
212                 chunkorder = viewer->getChunkOrder();
213         }
214
215         const int border_width = BLI_rcti_size_x(&this->m_viewerBorder);
216         const int border_height = BLI_rcti_size_y(&this->m_viewerBorder);
217
218         switch (chunkorder) {
219                 case COM_TO_RANDOM:
220                         for (index = 0; index < 2 * this->m_numberOfChunks; index++) {
221                                 int index1 = rand() % this->m_numberOfChunks;
222                                 int index2 = rand() % this->m_numberOfChunks;
223                                 int s = chunkOrder[index1];
224                                 chunkOrder[index1] = chunkOrder[index2];
225                                 chunkOrder[index2] = s;
226                         }
227                         break;
228                 case COM_TO_CENTER_OUT:
229                 {
230                         ChunkOrderHotspot *hotspots[1];
231                         hotspots[0] = new ChunkOrderHotspot(border_width * centerX, border_height * centerY, 0.0f);
232                         rcti rect;
233                         ChunkOrder *chunkOrders = (ChunkOrder *)MEM_mallocN(sizeof(ChunkOrder) * this->m_numberOfChunks, __func__);
234                         for (index = 0; index < this->m_numberOfChunks; index++) {
235                                 determineChunkRect(&rect, index);
236                                 chunkOrders[index].setChunkNumber(index);
237                                 chunkOrders[index].setX(rect.xmin - this->m_viewerBorder.xmin);
238                                 chunkOrders[index].setY(rect.ymin - this->m_viewerBorder.ymin);
239                                 chunkOrders[index].determineDistance(hotspots, 1);
240                         }
241
242                         std::sort(&chunkOrders[0], &chunkOrders[this->m_numberOfChunks - 1]);
243                         for (index = 0; index < this->m_numberOfChunks; index++) {
244                                 chunkOrder[index] = chunkOrders[index].getChunkNumber();
245                         }
246
247                         delete hotspots[0];
248                         MEM_freeN(chunkOrders);
249                         break;
250                 }
251                 case COM_TO_RULE_OF_THIRDS:
252                 {
253                         ChunkOrderHotspot *hotspots[9];
254                         unsigned int tx = border_width / 6;
255                         unsigned int ty = border_height / 6;
256                         unsigned int mx = border_width / 2;
257                         unsigned int my = border_height / 2;
258                         unsigned int bx = mx + 2 * tx;
259                         unsigned int by = my + 2 * ty;
260
261                         float addition = this->m_numberOfChunks / COM_RULE_OF_THIRDS_DIVIDER;
262                         hotspots[0] = new ChunkOrderHotspot(mx, my, addition * 0);
263                         hotspots[1] = new ChunkOrderHotspot(tx, my, addition * 1);
264                         hotspots[2] = new ChunkOrderHotspot(bx, my, addition * 2);
265                         hotspots[3] = new ChunkOrderHotspot(bx, by, addition * 3);
266                         hotspots[4] = new ChunkOrderHotspot(tx, ty, addition * 4);
267                         hotspots[5] = new ChunkOrderHotspot(bx, ty, addition * 5);
268                         hotspots[6] = new ChunkOrderHotspot(tx, by, addition * 6);
269                         hotspots[7] = new ChunkOrderHotspot(mx, ty, addition * 7);
270                         hotspots[8] = new ChunkOrderHotspot(mx, by, addition * 8);
271                         rcti rect;
272                         ChunkOrder *chunkOrders = (ChunkOrder *)MEM_mallocN(sizeof(ChunkOrder) * this->m_numberOfChunks, __func__);
273                         for (index = 0; index < this->m_numberOfChunks; index++) {
274                                 determineChunkRect(&rect, index);
275                                 chunkOrders[index].setChunkNumber(index);
276                                 chunkOrders[index].setX(rect.xmin - this->m_viewerBorder.xmin);
277                                 chunkOrders[index].setY(rect.ymin - this->m_viewerBorder.ymin);
278                                 chunkOrders[index].determineDistance(hotspots, 9);
279                         }
280
281                         std::sort(&chunkOrders[0], &chunkOrders[this->m_numberOfChunks]);
282
283                         for (index = 0; index < this->m_numberOfChunks; index++) {
284                                 chunkOrder[index] = chunkOrders[index].getChunkNumber();
285                         }
286
287                         delete hotspots[0];
288                         delete hotspots[1];
289                         delete hotspots[2];
290                         delete hotspots[3];
291                         delete hotspots[4];
292                         delete hotspots[5];
293                         delete hotspots[6];
294                         delete hotspots[7];
295                         delete hotspots[8];
296                         MEM_freeN(chunkOrders);
297                         break;
298                 }
299                 case COM_TO_TOP_DOWN:
300                 default:
301                         break;
302         }
303
304         DebugInfo::execution_group_started(this);
305         DebugInfo::graphviz(graph);
306
307         bool breaked = false;
308         bool finished = false;
309         unsigned int startIndex = 0;
310         const int maxNumberEvaluated = BLI_system_thread_count() * 2;
311
312         while (!finished && !breaked) {
313                 bool startEvaluated = false;
314                 finished = true;
315                 int numberEvaluated = 0;
316
317                 for (index = startIndex; index < this->m_numberOfChunks && numberEvaluated < maxNumberEvaluated; index++) {
318                         chunkNumber = chunkOrder[index];
319                         int yChunk = chunkNumber / this->m_numberOfXChunks;
320                         int xChunk = chunkNumber - (yChunk * this->m_numberOfXChunks);
321                         const ChunkExecutionState state = this->m_chunkExecutionStates[chunkNumber];
322                         if (state == COM_ES_NOT_SCHEDULED) {
323                                 scheduleChunkWhenPossible(graph, xChunk, yChunk);
324                                 finished = false;
325                                 startEvaluated = true;
326                                 numberEvaluated++;
327
328                                 if (bTree->update_draw)
329                                         bTree->update_draw(bTree->udh);
330                         }
331                         else if (state == COM_ES_SCHEDULED) {
332                                 finished = false;
333                                 startEvaluated = true;
334                                 numberEvaluated++;
335                         }
336                         else if (state == COM_ES_EXECUTED && !startEvaluated) {
337                                 startIndex = index + 1;
338                         }
339                 }
340
341                 WorkScheduler::finish();
342
343                 if (bTree->test_break && bTree->test_break(bTree->tbh)) {
344                         breaked = true;
345                 }
346         }
347         DebugInfo::execution_group_finished(this);
348         DebugInfo::graphviz(graph);
349
350         MEM_freeN(chunkOrder);
351 }
352
353 MemoryBuffer **ExecutionGroup::getInputBuffersOpenCL(int chunkNumber)
354 {
355         rcti rect;
356         vector<MemoryProxy *> memoryproxies;
357         unsigned int index;
358         determineChunkRect(&rect, chunkNumber);
359
360         this->determineDependingMemoryProxies(&memoryproxies);
361         MemoryBuffer **memoryBuffers = (MemoryBuffer **)MEM_callocN(sizeof(MemoryBuffer *) * this->m_cachedMaxReadBufferOffset, __func__);
362         rcti output;
363         for (index = 0; index < this->m_cachedReadOperations.size(); index++) {
364                 ReadBufferOperation *readOperation = (ReadBufferOperation *)this->m_cachedReadOperations[index];
365                 MemoryProxy *memoryProxy = readOperation->getMemoryProxy();
366                 this->determineDependingAreaOfInterest(&rect, readOperation, &output);
367                 MemoryBuffer *memoryBuffer = memoryProxy->getExecutor()->constructConsolidatedMemoryBuffer(memoryProxy, &output);
368                 memoryBuffers[readOperation->getOffset()] = memoryBuffer;
369         }
370         return memoryBuffers;
371 }
372
373 MemoryBuffer *ExecutionGroup::constructConsolidatedMemoryBuffer(MemoryProxy *memoryProxy, rcti *rect)
374 {
375         MemoryBuffer *imageBuffer = memoryProxy->getBuffer();
376         MemoryBuffer *result = new MemoryBuffer(memoryProxy, rect);
377         result->copyContentFrom(imageBuffer);
378         return result;
379 }
380
381 void ExecutionGroup::finalizeChunkExecution(int chunkNumber, MemoryBuffer **memoryBuffers)
382 {
383         if (this->m_chunkExecutionStates[chunkNumber] == COM_ES_SCHEDULED)
384                 this->m_chunkExecutionStates[chunkNumber] = COM_ES_EXECUTED;
385         
386         atomic_add_u(&this->m_chunksFinished, 1);
387         if (memoryBuffers) {
388                 for (unsigned int index = 0; index < this->m_cachedMaxReadBufferOffset; index++) {
389                         MemoryBuffer *buffer = memoryBuffers[index];
390                         if (buffer) {
391                                 if (buffer->isTemporarily()) {
392                                         memoryBuffers[index] = NULL;
393                                         delete buffer;
394                                 }
395                         }
396                 }
397                 MEM_freeN(memoryBuffers);
398         }
399         if (this->m_bTree) {
400                 // status report is only performed for top level Execution Groups.
401                 float progress = this->m_chunksFinished;
402                 progress /= this->m_numberOfChunks;
403                 this->m_bTree->progress(this->m_bTree->prh, progress);
404
405                 char buf[128];
406                 BLI_snprintf(buf, sizeof(buf), "Compositing | Tile %u-%u",
407                              this->m_chunksFinished,
408                              this->m_numberOfChunks);
409                 this->m_bTree->stats_draw(this->m_bTree->sdh, buf);
410         }
411 }
412
413 inline void ExecutionGroup::determineChunkRect(rcti *rect, const unsigned int xChunk, const unsigned int yChunk) const
414 {
415         const int border_width = BLI_rcti_size_x(&this->m_viewerBorder);
416         const int border_height = BLI_rcti_size_y(&this->m_viewerBorder);
417
418         if (this->m_singleThreaded) {
419                 BLI_rcti_init(rect, this->m_viewerBorder.xmin, border_width, this->m_viewerBorder.ymin, border_height);
420         }
421         else {
422                 const unsigned int minx = xChunk * this->m_chunkSize + this->m_viewerBorder.xmin;
423                 const unsigned int miny = yChunk * this->m_chunkSize + this->m_viewerBorder.ymin;
424                 const unsigned int width = min((unsigned int) this->m_viewerBorder.xmax, this->m_width);
425                 const unsigned int height = min((unsigned int) this->m_viewerBorder.ymax, this->m_height);
426                 BLI_rcti_init(rect, min(minx, this->m_width), min(minx + this->m_chunkSize, width), min(miny, this->m_height), min(miny + this->m_chunkSize, height));
427         }
428 }
429
430 void ExecutionGroup::determineChunkRect(rcti *rect, const unsigned int chunkNumber) const
431 {
432         const unsigned int yChunk = chunkNumber / this->m_numberOfXChunks;
433         const unsigned int xChunk = chunkNumber - (yChunk * this->m_numberOfXChunks);
434         determineChunkRect(rect, xChunk, yChunk);
435 }
436
437 MemoryBuffer *ExecutionGroup::allocateOutputBuffer(int /*chunkNumber*/,
438                                                    rcti *rect)
439 {
440         // we asume that this method is only called from complex execution groups.
441         NodeOperation *operation = this->getOutputOperation();
442         if (operation->isWriteBufferOperation()) {
443                 WriteBufferOperation *writeOperation = (WriteBufferOperation *)operation;
444                 MemoryBuffer *buffer = new MemoryBuffer(writeOperation->getMemoryProxy(), rect);
445                 return buffer;
446         }
447         return NULL;
448 }
449
450
451 bool ExecutionGroup::scheduleAreaWhenPossible(ExecutionSystem *graph, rcti *area)
452 {
453         if (this->m_singleThreaded) {
454                 return scheduleChunkWhenPossible(graph, 0, 0);
455         }
456         // find all chunks inside the rect
457         // determine minxchunk, minychunk, maxxchunk, maxychunk where x and y are chunknumbers
458
459         int indexx, indexy;
460         int minx = max_ii(area->xmin - m_viewerBorder.xmin, 0);
461         int maxx = min_ii(area->xmax - m_viewerBorder.xmin, m_viewerBorder.xmax - m_viewerBorder.xmin);
462         int miny = max_ii(area->ymin - m_viewerBorder.ymin, 0);
463         int maxy = min_ii(area->ymax - m_viewerBorder.ymin, m_viewerBorder.ymax - m_viewerBorder.ymin);
464         int minxchunk = minx / (int)m_chunkSize;
465         int maxxchunk = (maxx + (int)m_chunkSize - 1) / (int)m_chunkSize;
466         int minychunk = miny / (int)m_chunkSize;
467         int maxychunk = (maxy + (int)m_chunkSize - 1) / (int)m_chunkSize;
468         minxchunk = max_ii(minxchunk, 0);
469         minychunk = max_ii(minychunk, 0);
470         maxxchunk = min_ii(maxxchunk, (int)m_numberOfXChunks);
471         maxychunk = min_ii(maxychunk, (int)m_numberOfYChunks);
472
473         bool result = true;
474         for (indexx = minxchunk; indexx < maxxchunk; indexx++) {
475                 for (indexy = minychunk; indexy < maxychunk; indexy++) {
476                         if (!scheduleChunkWhenPossible(graph, indexx, indexy)) {
477                                 result = false;
478                         }
479                 }
480         }
481
482         return result;
483 }
484
485 bool ExecutionGroup::scheduleChunk(unsigned int chunkNumber)
486 {
487         if (this->m_chunkExecutionStates[chunkNumber] == COM_ES_NOT_SCHEDULED) {
488                 this->m_chunkExecutionStates[chunkNumber] = COM_ES_SCHEDULED;
489                 WorkScheduler::schedule(this, chunkNumber);
490                 return true;
491         }
492         return false;
493 }
494
495 bool ExecutionGroup::scheduleChunkWhenPossible(ExecutionSystem *graph, int xChunk, int yChunk)
496 {
497         if (xChunk < 0 || xChunk >= (int)this->m_numberOfXChunks) {
498                 return true;
499         }
500         if (yChunk < 0 || yChunk >= (int)this->m_numberOfYChunks) {
501                 return true;
502         }
503         int chunkNumber = yChunk * this->m_numberOfXChunks + xChunk;
504         // chunk is already executed
505         if (this->m_chunkExecutionStates[chunkNumber] == COM_ES_EXECUTED) {
506                 return true;
507         }
508
509         // chunk is scheduled, but not executed
510         if (this->m_chunkExecutionStates[chunkNumber] == COM_ES_SCHEDULED) {
511                 return false;
512         }
513
514         // chunk is nor executed nor scheduled.
515         vector<MemoryProxy *> memoryProxies;
516         this->determineDependingMemoryProxies(&memoryProxies);
517
518         rcti rect;
519         determineChunkRect(&rect, xChunk, yChunk);
520         unsigned int index;
521         bool canBeExecuted = true;
522         rcti area;
523
524         for (index = 0; index < this->m_cachedReadOperations.size(); index++) {
525                 ReadBufferOperation *readOperation = (ReadBufferOperation *)this->m_cachedReadOperations[index];
526                 BLI_rcti_init(&area, 0, 0, 0, 0);
527                 MemoryProxy *memoryProxy = memoryProxies[index];
528                 determineDependingAreaOfInterest(&rect, readOperation, &area);
529                 ExecutionGroup *group = memoryProxy->getExecutor();
530
531                 if (group != NULL) {
532                         if (!group->scheduleAreaWhenPossible(graph, &area)) {
533                                 canBeExecuted = false;
534                         }
535                 }
536                 else {
537                         throw "ERROR";
538                 }
539         }
540
541         if (canBeExecuted) {
542                 scheduleChunk(chunkNumber);
543         }
544
545         return false;
546 }
547
548 void ExecutionGroup::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
549 {
550         this->getOutputOperation()->determineDependingAreaOfInterest(input, readOperation, output);
551 }
552
553 void ExecutionGroup::determineDependingMemoryProxies(vector<MemoryProxy *> *memoryProxies)
554 {
555         unsigned int index;
556         for (index = 0; index < this->m_cachedReadOperations.size(); index++) {
557                 ReadBufferOperation *readOperation = (ReadBufferOperation *) this->m_cachedReadOperations[index];
558                 memoryProxies->push_back(readOperation->getMemoryProxy());
559         }
560 }
561
562 bool ExecutionGroup::isOpenCL()
563 {
564         return this->m_openCL;
565 }
566
567 void ExecutionGroup::setViewerBorder(float xmin, float xmax, float ymin, float ymax)
568 {
569         NodeOperation *operation = this->getOutputOperation();
570
571         if (operation->isViewerOperation() || operation->isPreviewOperation()) {
572                 BLI_rcti_init(&this->m_viewerBorder, xmin * this->m_width, xmax * this->m_width,
573                               ymin * this->m_height, ymax * this->m_height);
574         }
575 }
576
577 void ExecutionGroup::setRenderBorder(float xmin, float xmax, float ymin, float ymax)
578 {
579         NodeOperation *operation = this->getOutputOperation();
580
581         if (operation->isOutputOperation(true)) {
582                 /* Basically, setting border need to happen for only operations
583                  * which operates in render resolution buffers (like compositor
584                  * output nodes).
585                  *
586                  * In this cases adding border will lead to mapping coordinates
587                  * from output buffer space to input buffer spaces when executing
588                  * operation.
589                  *
590                  * But nodes like viewer and file output just shall display or
591                  * safe the same exact buffer which goes to their input, no need
592                  * in any kind of coordinates mapping.
593                  */
594
595                 bool operationNeedsBorder = !(operation->isViewerOperation() ||
596                                               operation->isPreviewOperation() ||
597                                               operation->isFileOutputOperation());
598
599                 if (operationNeedsBorder) {
600                         BLI_rcti_init(&this->m_viewerBorder, xmin * this->m_width, xmax * this->m_width,
601                                       ymin * this->m_height, ymax * this->m_height);
602                 }
603         }
604 }