Blender  V3.3
COM_compositor.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
4 #include "BLI_threads.h"
5 
6 #include "BLT_translation.h"
7 
8 #include "BKE_node.h"
9 #include "BKE_scene.h"
10 
11 #include "COM_ExecutionSystem.h"
12 #include "COM_WorkScheduler.h"
13 #include "COM_compositor.h"
14 
15 static struct {
16  bool is_initialized = false;
19 
20 /* Make sure node tree has previews.
21  * Don't create previews in advance, this is done when adding preview operations.
22  * Reserved preview size is determined by render output for now. */
24 {
25  /* We fit the aspect into COM_PREVIEW_SIZE x COM_PREVIEW_SIZE image to avoid
26  * insane preview resolution, which might even overflow preview dimensions. */
27  const float aspect = render_data->xsch > 0 ?
28  (float)render_data->ysch / (float)render_data->xsch :
29  1.0f;
30  int preview_width, preview_height;
31  if (aspect < 1.0f) {
33  preview_height = (int)(blender::compositor::COM_PREVIEW_SIZE * aspect);
34  }
35  else {
36  preview_width = (int)(blender::compositor::COM_PREVIEW_SIZE / aspect);
38  }
39  BKE_node_preview_init_tree(node_tree, preview_width, preview_height);
40 }
41 
43 {
44  node_tree->progress(node_tree->prh, 0.0);
45  node_tree->stats_draw(node_tree->sdh, IFACE_("Compositing"));
46 }
47 
48 void COM_execute(RenderData *render_data,
49  Scene *scene,
51  int rendering,
52  const char *view_name)
53 {
54  /* Initialize mutex, TODO: this mutex init is actually not thread safe and
55  * should be done somewhere as part of blender startup, all the other
56  * initializations can be done lazily. */
57  if (!g_compositor.is_initialized) {
59  g_compositor.is_initialized = true;
60  }
61 
63 
64  if (node_tree->test_break(node_tree->tbh)) {
65  /* During editing multiple compositor executions can be triggered.
66  * Make sure this is the most recent one. */
68  return;
69  }
70 
73 
74  /* Initialize workscheduler. */
75  const bool use_opencl = (node_tree->flag & NTREE_COM_OPENCL) != 0;
77 
78  /* Execute. */
79  const bool twopass = (node_tree->flag & NTREE_TWO_PASS) && !rendering;
80  if (twopass) {
82  render_data, scene, node_tree, rendering, true, view_name);
83  fast_pass.execute();
84 
85  if (node_tree->test_break(node_tree->tbh)) {
87  return;
88  }
89  }
90 
92  render_data, scene, node_tree, rendering, false, view_name);
93  system.execute();
94 
96 }
97 
99 {
100  if (g_compositor.is_initialized) {
103  g_compositor.is_initialized = false;
105  BLI_mutex_end(&g_compositor.mutex);
106  }
107 }
typedef float(TangentPoint)[2]
void BKE_node_preview_init_tree(struct bNodeTree *ntree, int xsize, int ysize)
Definition: node.cc:2801
int BKE_render_num_threads(const struct RenderData *r)
void BLI_mutex_end(ThreadMutex *mutex)
Definition: threads.cc:388
void BLI_mutex_init(ThreadMutex *mutex)
Definition: threads.cc:368
void BLI_mutex_lock(ThreadMutex *mutex)
Definition: threads.cc:373
void BLI_mutex_unlock(ThreadMutex *mutex)
Definition: threads.cc:378
pthread_mutex_t ThreadMutex
Definition: BLI_threads.h:82
#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 char *view_name)
The main method that is used to execute the compositor tree. It can be executed during editing (blenk...
static struct @177 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_clear_caches 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:108
static void deinitialize()
deinitialize the WorkScheduler free all allocated resources
static void initialize(bool use_opencl, int num_cpu_threads)
initialize the WorkScheduler