Blender V5.3
BKE_compositor.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include <optional>
12#include <string>
13
14#include "BLI_map.hh"
15#include "BLI_mutex.hh"
16#include "BLI_set.hh"
17#include "BLI_string_ref.hh"
18#include "BLI_vector.hh"
19
21
22namespace blender {
23
24struct Scene;
25struct View3D;
26struct RegionView3D;
27struct BlendWriter;
28struct BlendDataReader;
29struct Main;
30struct ViewLayer;
32struct ImBuf;
33struct bNode;
34struct bContext;
36struct DepsNodeHandle;
37struct bNodeTree;
38struct PointerRNA;
39
40class ComputeContext;
41
42namespace bke {
43class bNodeTreeZone;
44}
45
46namespace bke::compositor {
47
48/* --------------------------------------------------------------------
49 * Cache.
50 */
51
52struct Cache {
53 struct FrameKey {
54 int frame_number = 0;
56
61
62 friend bool operator==(const FrameKey &a, const FrameKey &b) = default;
63 };
64
65 private:
66 /* A cache of final interactive compositor results across frames. */
68 /* A mutex for accessing frames_. The frames cache is intrinsically thread-safe since all access
69 * happen in the same interactive compositor job, except for drawing cache overlays since it can
70 * happen simultaneously while the job is running, that's why the mutex is needed. */
71 Mutex frames_mutex_;
72
73 public:
74 /* Clear all caches. */
75 ~Cache();
76
77 /* Get the frame cache corresponding to the given frame number and view. The returned image
78 * buffer should be freed by the caller. Returns a nullptr if no cached frame exists. */
79 ImBuf *get_frame(int frame_number, int view_identifier);
80
81 /* Add a new frame cache entry. If the new entry would surpass the memory cache limit, frames
82 * will be evicted to make room. */
83 void add_frame(int frame_number, int view_identifier, ImBuf *image_buffer);
84
85 /* Clears the frames cache. */
86 void clear_frames();
87
88 /* Stores an inclusive range of frames. */
89 struct FrameRange {
90 int start;
91 int end;
92 };
93
94 /* Computes a list of every contiguous segment of cached frames. Can be used to draw which frame
95 * ranges are cached. */
97
98 private:
99 /* Delete one entry from the frames cache given the current frame number. If a cached frame exist
100 * before the current frame, the furthest one will be removed, otherwise, the furthest cached
101 * frame after the current frame will be removed. */
102 void evict_frame(int current_frame_number);
103
104 /* Computes the total size of the cache in bytes. */
105 int64_t size();
106};
107
108/* --------------------------------------------------------------------
109 * Scene Compositor Effects.
110 */
111
112enum class ExecutionMode : uint8_t {
113 /* The compositor is executing for a final render. */
115 /* The compositor is executing for a preview, like the interactive compositor or the viewport
116 * compositor. */
118};
119
120/* Returns true if the given scene has any enabled effect for the given execution mode. */
121bool is_enabled(const Scene &scene, ExecutionMode mode);
122
123/* Gets the compositor effect with the given name in the given scene. */
125
126/* Gets the active compositor effect in the given scene. */
128
129/* Returns true if the given effect is enabled for the given execution mode. */
131
132/* Sets the given compositor effect in the given scene to be the active one. */
133void set_active_effect(const Scene &scene, SceneCompositorEffect &effect);
134
135/* Rename the given compositor effect in the given scene to the given name. Animation data paths
136 * may be updated if update_animation_data is true. */
137void rename_effect(Scene &scene,
138 SceneCompositorEffect &effect,
139 StringRef new_name,
140 bool update_animation_data = true);
141
142/* Adds a new compositor effect of the given name to the given scene. */
144
145/* Copy the given compositor effect in the given scene. */
147
148/* Frees the given compositor effect from the given scene. Does not decrement user counts. */
150
151/* Removes the given compositor effect from the given scene. */
152void remove_effect(Scene &scene, SceneCompositorEffect &effect);
153
154/* Copy the effects from the given source scene to the given destination scene using the given ID
155 * copying flags. */
156void copy_effects(Scene &target_scene, const Scene &source_scene, const int flags);
157
158/* Frees all compositor effects in the given scene. Does not decrement user counts. */
159void free_effects(Scene &scene);
160
161/* Removes all compositor effects in the given scene. */
162void clear_effects(Scene &scene);
163
164/* Walk over each ID in the effects of the given scene executing the callback defined by the given
165 * data. */
167
168/* Write the effects of the given scene to the given blend file writer. */
169void write_effects(const Scene &scene, BlendWriter &writer);
170
171/* Read the effects of the given scene from the given blend file reader. */
172void read_effects(Scene &scene, BlendDataReader &reader);
173
174/* Gets the effect that the given property belongs to. */
176
177/* Update the system properties of the effect. Should be call whenever the node group of the
178 * effect changes or the interface of the assigned node group changes. */
180
181/* --------------------------------------------------------------------
182 * Query.
183 */
184
185/* Get the set of all passes used by the compositor for the given view layer and execution mode,
186 * identified by their pass names. This might be a superset of the passes actually supported by the
187 * render engine, in which case, the compositor will return an invalid output and issue a
188 * warning. */
190 const ViewLayer *view_layer,
191 ExecutionMode mode);
192
193/* Checks if the viewport compositor is currently enabled in the given 3D viewport. */
194bool is_viewport_compositor_enabled(const View3D &view_3d, const RegionView3D &region_view_3d);
195
196/* Checks if the viewport compositor is currently being used in any 3D viewport. */
197bool is_viewport_compositor_used(const bContext &context);
198
199/* --------------------------------------------------------------------
200 * Depsgraph.
201 */
202
203/* Add the depsgraph relations needed by the given scene compositor effect in the given scene. A
204 * handle for the compositor output depsgraph node is given to be the target of the relation. */
206 const SceneCompositorEffect &effect,
207 DepsNodeHandle *compositor_output_depsgraph_node);
208
209/* --------------------------------------------------------------------
210 * Compute Contexts.
211 */
212
213/* Get the compute context of the zone that the given node lies inside given the compute context of
214 * the owner tree or zone. If the node does not lie inside a zone, the given compute context is
215 * simply returned. The compute context is assumed to be that of a viewer node, so compute contexts
216 * will be constructed using inspection index for repeat zone for instance. If the node lies inside
217 * a context that does not support viewers, like closures, nullptr is returned. */
219 const bNode &node,
220 const bke::bNodeTreeZone *zone,
221 const ComputeContext &compute_context,
222 bke::ComputeContextCache &compute_context_cache);
223
224/* Computes the compute context of the active viewer node. If no active viewer node exists, a
225 * nullptr is returned. */
227 const Scene &scene, bke::ComputeContextCache &compute_context_cache);
229 const Scene &scene,
230 const bNodeTree &root_node_group,
231 bke::ComputeContextCache &compute_context_cache);
232
233} // namespace bke::compositor
234} // namespace blender
#define main()
void free_effect(Scene &scene, SceneCompositorEffect &effect)
SceneCompositorEffect * get_active_effect(const Scene &scene)
void remove_effect(Scene &scene, SceneCompositorEffect &effect)
const SceneCompositorEffect * get_effect_from_property(const PointerRNA &property_ptr)
SceneCompositorEffect * get_effect(const Scene &scene, StringRef name)
SceneCompositorEffect & new_effect(Scene &scene, StringRef name)
void copy_effects(Scene &target_scene, const Scene &source_scene, const int flags)
bool is_viewport_compositor_enabled(const View3D &view_3d, const RegionView3D &region_view_3d)
void add_depsgraph_relations(Scene &scene, const SceneCompositorEffect &effect, DepsNodeHandle *compositor_output_depsgraph_node)
bool is_enabled(const Scene &scene, ExecutionMode mode)
void write_effects(const Scene &scene, BlendWriter &writer)
bool is_viewport_compositor_used(const bContext &context)
void set_active_effect(const Scene &scene, SceneCompositorEffect &effect)
SceneCompositorEffect & duplicate_effect(Scene &scene, SceneCompositorEffect &source_effect)
const ComputeContext * compute_viewer_compute_context(const Scene &scene, bke::ComputeContextCache &compute_context_cache)
void rename_effect(Scene &scene, SceneCompositorEffect &effect, StringRef new_name, bool update_animation_data=true)
void for_each_id_in_effects(const Scene &scene, LibraryForeachIDData &data)
Set< std::string > get_used_passes(const Scene &scene, const ViewLayer *view_layer, ExecutionMode mode)
void update_effect_node_group_interface(Main &main, Scene &scene, SceneCompositorEffect &effect)
void read_effects(Scene &scene, BlendDataReader &reader)
const ComputeContext * get_zone_viewer_compute_context(const bNode &node, const bke::bNodeTreeZone *zone, const ComputeContext &compute_context, bke::ComputeContextCache &compute_context_cache)
bool is_effect_enabled(const SceneCompositorEffect &effect, ExecutionMode mode)
BMesh Iterators.
unsigned __int64 uint64_t
Definition BKE_text.h:91
__int64 int64_t
Definition BKE_text.h:90
BMesh const char void * data
unsigned char uint8_t
Definition BKE_text.h:79
std::mutex Mutex
Definition BLI_mutex.hh:51
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:252
friend bool operator==(const FrameKey &a, const FrameKey &b)=default
void add_frame(int frame_number, int view_identifier, ImBuf *image_buffer)
ImBuf * get_frame(int frame_number, int view_identifier)