Blender  V2.93
COM_compositor.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
19 #include "BLI_threads.h"
20 
21 #include "BLT_translation.h"
22 
23 #include "BKE_node.h"
24 #include "BKE_scene.h"
25 
26 #include "COM_ExecutionSystem.h"
28 #include "COM_WorkScheduler.h"
29 #include "COM_compositor.h"
30 #include "clew.h"
31 
32 static struct {
33  bool is_initialized = false;
36 
37 /* Make sure node tree has previews.
38  * Don't create previews in advance, this is done when adding preview operations.
39  * Reserved preview size is determined by render output for now. */
41 {
42  /* We fit the aspect into COM_PREVIEW_SIZE x COM_PREVIEW_SIZE image to avoid
43  * insane preview resolution, which might even overflow preview dimensions. */
44  const float aspect = render_data->xsch > 0 ?
45  (float)render_data->ysch / (float)render_data->xsch :
46  1.0f;
47  int preview_width, preview_height;
48  if (aspect < 1.0f) {
50  preview_height = (int)(blender::compositor::COM_PREVIEW_SIZE * aspect);
51  }
52  else {
53  preview_width = (int)(blender::compositor::COM_PREVIEW_SIZE / aspect);
55  }
56  BKE_node_preview_init_tree(node_tree, preview_width, preview_height, false);
57 }
58 
60 {
61  node_tree->progress(node_tree->prh, 0.0);
62  node_tree->stats_draw(node_tree->sdh, IFACE_("Compositing"));
63 }
64 
65 void COM_execute(RenderData *render_data,
66  Scene *scene,
68  int rendering,
69  const ColorManagedViewSettings *viewSettings,
70  const ColorManagedDisplaySettings *displaySettings,
71  const char *viewName)
72 {
73  /* Initialize mutex, TODO this mutex init is actually not thread safe and
74  * should be done somewhere as part of blender startup, all the other
75  * initializations can be done lazily. */
76  if (!g_compositor.is_initialized) {
78  g_compositor.is_initialized = true;
79  }
80 
82 
83  if (node_tree->test_break(node_tree->tbh)) {
84  /* During editing multiple compositor executions can be triggered.
85  * Make sure this is the most recent one. */
87  return;
88  }
89 
92 
93  /* Initialize workscheduler. */
94  const bool use_opencl = (node_tree->flag & NTREE_COM_OPENCL) != 0;
96 
97  /* Execute. */
98  const bool twopass = (node_tree->flag & NTREE_TWO_PASS) && !rendering;
99  if (twopass) {
101  render_data, scene, node_tree, rendering, true, viewSettings, displaySettings, viewName);
102  fast_pass.execute();
103 
104  if (node_tree->test_break(node_tree->tbh)) {
106  return;
107  }
108  }
109 
111  render_data, scene, node_tree, rendering, false, viewSettings, displaySettings, viewName);
112  system.execute();
113 
115 }
116 
118 {
119  if (g_compositor.is_initialized) {
122  g_compositor.is_initialized = false;
124  BLI_mutex_end(&g_compositor.mutex);
125  }
126 }
typedef float(TangentPoint)[2]
void BKE_node_preview_init_tree(struct bNodeTree *ntree, int xsize, int ysize, bool create_previews)
Definition: node.cc:2659
int BKE_render_num_threads(const struct RenderData *r)
void BLI_mutex_end(ThreadMutex *mutex)
Definition: threads.cc:416
void BLI_mutex_init(ThreadMutex *mutex)
Definition: threads.cc:396
void BLI_mutex_lock(ThreadMutex *mutex)
Definition: threads.cc:401
void BLI_mutex_unlock(ThreadMutex *mutex)
Definition: threads.cc:406
pthread_mutex_t ThreadMutex
Definition: BLI_threads.h:83
#define IFACE_(msgid)
static void compositor_reset_node_tree_status(bNodeTree *node_tree)
bool is_initialized
ThreadMutex mutex
void COM_execute(RenderData *render_data, Scene *scene, bNodeTree *node_tree, int rendering, const ColorManagedViewSettings *viewSettings, const ColorManagedDisplaySettings *displaySettings, const char *viewName)
The main method that is used to execute the compositor tree. It can be executed during editing (blenk...
static struct @171 g_compositor
static void compositor_init_node_previews(const RenderData *render_data, bNodeTree *node_tree)
void COM_deinitialize()
Deinitialize the compositor caches and allocated memory. Use COM_clearCaches to only free the caches.
#define NTREE_TWO_PASS
#define NTREE_COM_OPENCL
the ExecutionSystem contains the whole compositor tree.
Scene scene
constexpr float COM_PREVIEW_SIZE
Definition: COM_defines.h:78
static void deinitialize()
deinitialize the WorkScheduler free all allocated resources
static void initialize(bool use_opencl, int num_cpu_threads)
initialize the WorkScheduler