forked from NatronGitHub/Natron
/
NodePrivate.h
498 lines (426 loc) · 17 KB
/
NodePrivate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
/* ***** BEGIN LICENSE BLOCK *****
* This file is part of Natron <https://natrongithub.github.io/>,
* (C) 2018-2021 The Natron developers
* (C) 2013-2018 INRIA and Alexandre Gauthier-Foichat
*
* Natron is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Natron is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Natron. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>
* ***** END LICENSE BLOCK ***** */
#ifndef NATRON_ENGINE_NODE_PRIVATE_H
#define NATRON_ENGINE_NODE_PRIVATE_H
// ***** BEGIN PYTHON BLOCK *****
// from <https://docs.python.org/3/c-api/intro.html#include-files>:
// "Since Python may define some pre-processor definitions which affect the standard headers on some systems, you must include Python.h before any standard headers are included."
#include <Python.h>
// ***** END PYTHON BLOCK *****
#include "Global/Macros.h"
#include "Node.h"
#include <QtCore/QWaitCondition>
#include <QtCore/QReadWriteLock>
#include <QtCore/QMutex>
#include "Engine/Hash64.h"
NATRON_NAMESPACE_ENTER
/*The output node was connected from inputNumber to this...*/
typedef std::map<NodeWPtr, int > DeactivatedState;
typedef std::list<Node::KnobLink> KnobLinkList;
typedef std::vector<NodeWPtr> InputsV;
class ChannelSelector
{
public:
KnobChoiceWPtr layer;
ChannelSelector()
: layer()
{
}
ChannelSelector(const ChannelSelector& other)
{
*this = other;
}
void operator=(const ChannelSelector& other)
{
layer = other.layer;
}
};
class MaskSelector
{
public:
KnobBoolWPtr enabled;
KnobChoiceWPtr channel;
mutable QMutex compsMutex;
//Stores the components available at build time of the choice menu
std::vector<std::pair<ImagePlaneDesc, NodeWPtr> > compsAvailable;
MaskSelector()
: enabled()
, channel()
, compsMutex()
, compsAvailable()
{
}
MaskSelector(const MaskSelector& other)
{
*this = other;
}
void operator=(const MaskSelector& other)
{
enabled = other.enabled;
channel = other.channel;
QMutexLocker k(&compsMutex);
compsAvailable = other.compsAvailable;
}
};
struct PyPlugInfo
{
std::string pluginPythonModule; // the absolute filename of the python script
//Set to true when the user has edited a PyPlug
bool isPyPlug;
std::string pyPlugID; //< if this is a pyplug, this is the ID of the Plug-in. This is because the plugin handle will be the one of the Group
std::string pyPlugLabel;
std::string pyPlugDesc;
std::string pyPlugIconFilePath;
std::list<std::string> pyPlugGrouping;
int pyPlugVersion;
PyPlugInfo()
: isPyPlug(false)
, pyPlugVersion(0)
{
}
};
struct FormatKnob
{
KnobIntWPtr size;
KnobDoubleWPtr par;
KnobChoiceWPtr formatChoice;
};
struct Node::Implementation
{
Q_DECLARE_TR_FUNCTIONS(Node)
public:
Implementation(Node* publicInterface,
const AppInstancePtr& app_,
const NodeCollectionPtr& collection,
Plugin* plugin_)
: _publicInterface(publicInterface)
, group(collection)
, precomp()
, app(app_)
, isPartOfProject(true)
, knobsInitialized(false)
, inputsInitialized(false)
, outputsMutex()
, outputs()
, guiOutputs()
, inputsMutex()
, inputs()
, guiInputs()
, effect()
, inputsComponents()
, outputComponents()
, inputsLabelsMutex()
, inputLabels()
, scriptName()
, label()
, cacheID()
, deactivatedState()
, activatedMutex()
, activated(true)
, plugin(plugin_)
, pyPluginInfoMutex()
, pyPlugInfo()
, computingPreview(false)
, previewThreadQuit(false)
, computingPreviewMutex()
, pluginInstanceMemoryUsed(0)
, memoryUsedMutex()
, mustQuitPreview(0)
, mustQuitPreviewMutex()
, mustQuitPreviewCond()
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
, renderInstancesSharedMutex()
#else
, renderInstancesSharedMutex(QMutex::Recursive)
#endif
, knobsAge(0)
, knobsAgeMutex()
, masterNodeMutex()
, masterNode()
, nodeLinks()
#ifdef NATRON_ENABLE_IO_META_NODES
, ioContainer()
#endif
, frameIncrKnob()
, nodeSettingsPage()
, nodeLabelKnob()
, previewEnabledKnob()
, disableNodeKnob()
, infoPage()
, nodeInfos()
, refreshInfoButton()
, useFullScaleImagesWhenRenderScaleUnsupported()
, forceCaching()
, hideInputs()
, beforeFrameRender()
, beforeRender()
, afterFrameRender()
, afterRender()
, enabledChan()
, channelsSelectors()
, maskSelectors()
, rotoContext()
, trackContext()
, imagesBeingRenderedMutex()
, imagesBeingRenderedCond()
, imagesBeingRendered()
, supportedDepths()
, isMultiInstance(false)
, multiInstanceParent()
, childrenMutex()
, children()
, multiInstanceParentName()
, keyframesDisplayedOnTimeline(false)
, lastRenderStartedMutex()
, lastRenderStartedSlotCallTime()
, renderStartedCounter(0)
, inputIsRenderingCounter(0)
, lastInputNRenderStartedSlotCallTime()
, nodeIsDequeuing(false)
, nodeIsDequeuingMutex()
, nodeIsDequeuingCond()
, nodeIsRendering(0)
, nodeIsRenderingMutex()
, persistentMessage()
, persistentMessageType(0)
, persistentMessageMutex()
, guiPointer()
, nativeOverlays()
, nodeCreated(false)
, wasCreatedSilently(false)
, createdComponentsMutex()
, createdComponents()
, paintStroke()
, pluginsPropMutex()
, pluginSafety(eRenderSafetyInstanceSafe)
, currentThreadSafety(eRenderSafetyInstanceSafe)
, currentSupportTiles(false)
, currentSupportOpenGLRender(ePluginOpenGLRenderSupportNone)
, currentSupportSequentialRender(eSequentialPreferenceNotSequential)
, currentCanTransform(false)
, draftModeUsed(false)
, mustComputeInputRelatedData(true)
, duringPaintStrokeCreation(false)
, lastStrokeMovementMutex()
, strokeBitmapCleared(false)
, useAlpha0ToConvertFromRGBToRGBA(false)
, isBeingDestroyedMutex()
, isBeingDestroyed(false)
, inputModifiedRecursion(0)
, inputsModified()
, refreshIdentityStateRequestsCount(0)
, isRefreshingInputRelatedData(false)
, streamWarnings()
, requiresGLFinishBeforeRender(false)
, hostChannelSelectorEnabled(false)
{
///Initialize timers
gettimeofday(&lastRenderStartedSlotCallTime, 0);
gettimeofday(&lastInputNRenderStartedSlotCallTime, 0);
}
void abortPreview_non_blocking();
void abortPreview_blocking(bool allowPreviewRenders);
bool checkForExitPreview();
void setComputingPreview(bool v)
{
QMutexLocker l(&computingPreviewMutex);
computingPreview = v;
}
void restoreUserKnobsRecursive(const std::list<KnobSerializationBasePtr>& knobs,
const KnobGroupPtr& group,
const KnobPagePtr& page);
void storeKnobLinksRecursive(const GroupKnobSerialization* group,
const std::map<std::string, std::string>& oldNewScriptNamesMapping);
void restoreKnobLinksRecursive(const NodesList & allNodes,
const KnobGroupPtr& group,
const std::map<std::string, std::string>& oldNewScriptNamesMapping,
bool throwOnFailure);
void ifGroupForceHashChangeOfInputs();
void runOnNodeCreatedCB(bool userEdited);
void runOnNodeDeleteCB();
void runOnNodeCreatedCBInternal(const std::string& cb, bool userEdited);
void runOnNodeDeleteCBInternal(const std::string& cb);
void appendChild(const NodePtr& child);
void runInputChangedCallback(int index, const std::string& script);
void createChannelSelector(int inputNb, const std::string & inputName, bool isOutput, const KnobPagePtr& page, KnobIPtr* lastKnobBeforeAdvancedOption);
void onLayerChanged(int inputNb, const ChannelSelector& selector);
void onMaskSelectorChanged(int inputNb, const MaskSelector& selector);
ImagePlaneDesc getSelectedLayerInternal(int inputNb, const std::list<ImagePlaneDesc>& availableLayers, const ChannelSelector& selector) const;
Node* _publicInterface;
NodeCollectionWPtr group;
PrecompNodeWPtr precomp;
AppInstanceWPtr app; // pointer to the app: needed to access the application's default-project's format
bool isPartOfProject;
bool knobsInitialized;
bool inputsInitialized;
mutable QMutex outputsMutex;
NodesWList outputs, guiOutputs;
mutable QMutex inputsMutex; //< protects guiInputs so the serialization thread can access them
///The inputs are the ones used while rendering and guiInputs the ones used by the gui whenever
///the node is currently rendering. Once the render is finished, inputs are refreshed automatically to the value of
///guiInputs
InputsV inputs, guiInputs;
//to the inputs in a thread-safe manner.
EffectInstancePtr effect; //< the effect hosted by this node
///The accepted components in input and in output of the plug-in
///These two are also protected by inputsMutex
std::vector<std::list<ImagePlaneDesc> > inputsComponents;
std::list<ImagePlaneDesc> outputComponents;
mutable QMutex nameMutex;
mutable QMutex inputsLabelsMutex;
std::vector<std::string> inputLabels; // inputs name, protected by inputsLabelsMutex
std::vector<std::string> inputHints; // protected by inputsLabelsMutex
std::vector<bool> inputsVisibility; // protected by inputsMutex
std::string scriptName; //node name internally and as visible to python
std::string label; // node label as visible in the GUI
///The cacheID is the first script name that was given to a node
///it is then used in the cache to identify images that belong to this node
///In order for the cache to be persistent, the cacheID is serialized with the node
///and 2 nodes cannot have the same cacheID.
std::string cacheID;
DeactivatedState deactivatedState;
mutable QMutex activatedMutex;
bool activated;
Plugin* plugin; //< the plugin which stores the function to instantiate the effect
mutable QMutex pyPluginInfoMutex;
PyPlugInfo pyPlugInfo;
bool computingPreview;
bool previewThreadQuit;
mutable QMutex computingPreviewMutex;
size_t pluginInstanceMemoryUsed; //< global count on all EffectInstance's of the memory they use.
QMutex memoryUsedMutex; //< protects _pluginInstanceMemoryUsed
int mustQuitPreview;
QMutex mustQuitPreviewMutex;
QWaitCondition mustQuitPreviewCond;
QMutex renderInstancesSharedMutex; //< see eRenderSafetyInstanceSafe in EffectInstance::renderRoI
//only 1 clone can render at any time
U64 knobsAge; //< the age of the knobs in this effect. It gets incremented every times the effect has its evaluate() function called.
mutable QReadWriteLock knobsAgeMutex; //< protects knobsAge and hash
Hash64 hash; //< recomputed every time knobsAge is changed.
mutable QMutex masterNodeMutex; //< protects masterNode and nodeLinks
NodeWPtr masterNode; //< this points to the master when the node is a clone
KnobLinkList nodeLinks; //< these point to the parents of the params links
#ifdef NATRON_ENABLE_IO_META_NODES
//When creating a Reader or Writer node, this is a pointer to the "bundle" node that the user actually see.
NodeWPtr ioContainer;
#endif
KnobIntWPtr frameIncrKnob;
KnobPageWPtr nodeSettingsPage;
KnobStringWPtr nodeLabelKnob;
KnobBoolWPtr previewEnabledKnob;
KnobBoolWPtr disableNodeKnob;
KnobChoiceWPtr openglRenderingEnabledKnob;
KnobIntWPtr lifeTimeKnob;
KnobBoolWPtr enableLifeTimeKnob;
KnobStringWPtr knobChangedCallback;
KnobStringWPtr inputChangedCallback;
KnobStringWPtr nodeCreatedCallback;
KnobStringWPtr nodeRemovalCallback;
KnobPageWPtr infoPage;
KnobStringWPtr nodeInfos;
KnobButtonWPtr refreshInfoButton;
KnobBoolWPtr useFullScaleImagesWhenRenderScaleUnsupported;
KnobBoolWPtr forceCaching;
KnobBoolWPtr hideInputs;
KnobStringWPtr beforeFrameRender;
KnobStringWPtr beforeRender;
KnobStringWPtr afterFrameRender;
KnobStringWPtr afterRender;
KnobBoolWPtr enabledChan[4];
KnobStringWPtr premultWarning;
KnobDoubleWPtr mixWithSource;
KnobButtonWPtr renderButton; //< render button for writers
FormatKnob pluginFormatKnobs;
KnobBoolWPtr processAllLayersKnob;
std::map<int, ChannelSelector> channelsSelectors;
std::map<int, MaskSelector> maskSelectors;
RotoContextPtr rotoContext; //< valid when the node has a rotoscoping context (i.e: paint context)
TrackerContextPtr trackContext;
mutable QMutex imagesBeingRenderedMutex;
QWaitCondition imagesBeingRenderedCond;
std::list<ImagePtr> imagesBeingRendered; ///< a list of all the images being rendered simultaneously
std::list<ImageBitDepthEnum> supportedDepths;
///True when several effect instances are represented under the same node.
bool isMultiInstance;
NodeWPtr multiInstanceParent;
mutable QMutex childrenMutex;
NodesWList children;
///the name of the parent at the time this node was created
std::string multiInstanceParentName;
bool keyframesDisplayedOnTimeline;
///This is to avoid the slots connected to the main-thread to be called too much
QMutex lastRenderStartedMutex; //< protects lastRenderStartedSlotCallTime & lastInputNRenderStartedSlotCallTime
timeval lastRenderStartedSlotCallTime;
int renderStartedCounter;
std::vector<int> inputIsRenderingCounter;
timeval lastInputNRenderStartedSlotCallTime;
///True when the node is dequeuing the connectionQueue and no render should be started 'til it is empty
bool nodeIsDequeuing;
QMutex nodeIsDequeuingMutex;
QWaitCondition nodeIsDequeuingCond;
///Counter counting how many parallel renders are active on the node
int nodeIsRendering;
mutable QMutex nodeIsRenderingMutex;
QString persistentMessage;
int persistentMessageType;
mutable QMutex persistentMessageMutex;
NodeGuiIWPtr guiPointer;
std::list<HostOverlayKnobsPtr> nativeOverlays;
bool nodeCreated;
bool wasCreatedSilently;
mutable QMutex createdComponentsMutex;
std::list<ImagePlaneDesc> createdComponents; // comps created by the user
RotoDrawableItemWPtr paintStroke;
// These are dynamic props
mutable QMutex pluginsPropMutex;
RenderSafetyEnum pluginSafety, currentThreadSafety;
bool currentSupportTiles;
PluginOpenGLRenderSupport currentSupportOpenGLRender;
SequentialPreferenceEnum currentSupportSequentialRender;
bool currentCanTransform;
bool draftModeUsed, mustComputeInputRelatedData;
bool duringPaintStrokeCreation; // protected by lastStrokeMovementMutex
mutable QMutex lastStrokeMovementMutex;
bool strokeBitmapCleared;
//This flag is used for the Roto plug-in and for the Merge inside the rotopaint tree
//so that if the input of the roto node is RGB, it gets converted with alpha = 0, otherwise the user
//won't be able to paint the alpha channel
bool useAlpha0ToConvertFromRGBToRGBA;
mutable QMutex isBeingDestroyedMutex;
bool isBeingDestroyed;
NodeRenderWatcherPtr renderWatcher;
/*
Used to block render emitions while modifying nodes links
MT-safe: only accessed/used on main thread
*/
int inputModifiedRecursion;
std::set<int> inputsModified;
//For readers, this is the name of the views in the file
std::vector<std::string> createdViews;
//To concatenate calls to refreshIdentityState, accessed only on main-thread
int refreshIdentityStateRequestsCount;
int isRefreshingInputRelatedData; // only used by the main thread
std::map<Node::StreamWarningEnum, QString> streamWarnings;
// Some plug-ins (mainly Hitfilm Ignite detected for now) use their own OpenGL context that is sharing resources with our OpenGL contexT.
// as a result if we don't call glFinish() before calling the render action, the plug-in context might use textures that were not finished yet.
bool requiresGLFinishBeforeRender;
bool hostChannelSelectorEnabled;
};
NATRON_NAMESPACE_EXIT
#endif // NATRON_ENGINE_NODE_PRIVATE_H