2 * Copyright 2011, Blender Foundation.
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.
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.
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.
26 #include "BLI_threads.h"
29 #include "BKE_global.h"
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"
37 static ThreadMutex s_compositorMutex;
38 static char is_compositorMutex_init = FALSE;
40 void intern_freeCompositorCaches()
42 deintializeDistortionCache();
45 void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering,
46 const ColorManagedViewSettings *viewSettings,
47 const ColorManagedDisplaySettings *displaySettings)
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;
57 BLI_mutex_lock(&s_compositorMutex);
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);
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);
70 /* set progress bar to 0% and status to init compositing */
71 editingtree->progress(editingtree->prh, 0.0);
73 bool twopass = (editingtree->flag & NTREE_TWO_PASS) > 0 && !rendering;
74 /* initialize execution system */
76 ExecutionSystem *system = new ExecutionSystem(rd, editingtree, rendering, twopass, viewSettings, displaySettings);
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);
89 ExecutionSystem *system = new ExecutionSystem(rd, editingtree, rendering, false, viewSettings, displaySettings);
93 BLI_mutex_unlock(&s_compositorMutex);
98 if (is_compositorMutex_init) {
99 BLI_mutex_lock(&s_compositorMutex);
100 intern_freeCompositorCaches();
101 BLI_mutex_unlock(&s_compositorMutex);
105 void COM_deinitialize()
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);