code cleanup: quiet warnings for gcc's -Wundef, -Wmissing-declarations
[blender.git] / source / blender / compositor / intern / COM_compositor.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
24 #include "BKE_node.h"
25 extern "C" {
26         #include "BLI_threads.h"
27 }
28 #include "BKE_main.h"
29 #include "BKE_global.h"
30
31 #include "COM_compositor.h"
32 #include "COM_ExecutionSystem.h"
33 #include "COM_WorkScheduler.h"
34 #include "OCL_opencl.h"
35 #include "COM_MovieDistortionOperation.h"
36
37 static ThreadMutex s_compositorMutex;
38 static char is_compositorMutex_init = FALSE;
39
40 static void intern_freeCompositorCaches()
41 {
42         deintializeDistortionCache();
43 }
44
45 void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering,
46                  const ColorManagedViewSettings *viewSettings,
47                  const ColorManagedDisplaySettings *displaySettings)
48 {
49         /* initialize mutex, TODO this mutex init is actually not thread safe and
50          * should be done somewhere as part of blender startup, all the other
51          * initializations can be done lazily */
52         if (is_compositorMutex_init == FALSE) {
53                 BLI_mutex_init(&s_compositorMutex);
54                 is_compositorMutex_init = TRUE;
55         }
56
57         BLI_mutex_lock(&s_compositorMutex);
58
59         if (editingtree->test_break(editingtree->tbh)) {
60                 // during editing multiple calls to this method can be triggered.
61                 // make sure one the last one will be doing the work.
62                 BLI_mutex_unlock(&s_compositorMutex);
63                 return;
64         }
65
66         /* initialize workscheduler, will check if already done. TODO deinitialize somewhere */
67         bool use_opencl = (editingtree->flag & NTREE_COM_OPENCL);
68         WorkScheduler::initialize(use_opencl);
69
70         /* set progress bar to 0% and status to init compositing */
71         editingtree->progress(editingtree->prh, 0.0);
72
73         bool twopass = (editingtree->flag & NTREE_TWO_PASS) > 0 && !rendering;
74         /* initialize execution system */
75         if (twopass) {
76                 ExecutionSystem *system = new ExecutionSystem(rd, editingtree, rendering, twopass, viewSettings, displaySettings);
77                 system->execute();
78                 delete system;
79                 
80                 if (editingtree->test_break(editingtree->tbh)) {
81                         // during editing multiple calls to this method can be triggered.
82                         // make sure one the last one will be doing the work.
83                         BLI_mutex_unlock(&s_compositorMutex);
84                         return;
85                 }
86         }
87
88         
89         ExecutionSystem *system = new ExecutionSystem(rd, editingtree, rendering, false, viewSettings, displaySettings);
90         system->execute();
91         delete system;
92
93         BLI_mutex_unlock(&s_compositorMutex);
94 }
95
96 static void UNUSED_FUNCTION(COM_freeCaches)()
97 {
98         if (is_compositorMutex_init) {
99                 BLI_mutex_lock(&s_compositorMutex);
100                 intern_freeCompositorCaches();
101                 BLI_mutex_unlock(&s_compositorMutex);
102         }
103 }
104
105 void COM_deinitialize()
106 {
107         if (is_compositorMutex_init) {
108                 BLI_mutex_lock(&s_compositorMutex);
109                 intern_freeCompositorCaches();
110                 WorkScheduler::deinitialize();
111                 is_compositorMutex_init = FALSE;
112                 BLI_mutex_unlock(&s_compositorMutex);
113                 BLI_mutex_end(&s_compositorMutex);
114         }
115 }