forked from NatronGitHub/Natron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EffectInstance.h
2277 lines (1867 loc) · 91.2 KB
/
EffectInstance.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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ***** 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_EFFECTINSTANCE_H
#define NATRON_ENGINE_EFFECTINSTANCE_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 <list>
#include <bitset>
#if !defined(Q_MOC_RUN) && !defined(SBK_RUN)
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#endif
#include "Global/GlobalDefines.h"
#include "Global/KeySymbols.h"
#include "Engine/ImagePlaneDesc.h"
#include "Engine/ImageLocker.h"
#include "Engine/Knob.h" // for KnobHolder
#include "Engine/RectD.h"
#include "Engine/RectI.h"
#include "Engine/RenderStats.h"
#include "Engine/EngineFwd.h"
#include "Engine/ParallelRenderArgs.h"
#include "Engine/PluginActionShortcut.h"
#include "Engine/ViewIdx.h"
// Various useful plugin IDs, @see EffectInstance::getPluginID()
#define PLUGINID_OFX_MERGE "net.sf.openfx.MergePlugin"
#define PLUGINID_OFX_TRACKERPM "net.sf.openfx.TrackerPM"
#define PLUGINID_OFX_DOTEXAMPLE "net.sf.openfx.dotexample"
#define PLUGINID_OFX_RADIAL "net.sf.openfx.Radial"
#define PLUGINID_OFX_SENOISE "net.sf.openfx.SeNoise"
#define PLUGINID_OFX_READOIIO "fr.inria.openfx.ReadOIIO"
#define PLUGINID_OFX_WRITEOIIO "fr.inria.openfx.WriteOIIO"
#define PLUGINID_OFX_ROTO "net.sf.openfx.RotoPlugin"
#define CLIP_OFX_ROTO "Roto" // The Roto input clip from the Roto plugin
#define PLUGINID_OFX_TRANSFORM "net.sf.openfx.TransformPlugin"
#define PLUGINID_OFX_GRADE "net.sf.openfx.GradePlugin"
#define PLUGINID_OFX_COLORCORRECT "net.sf.openfx.ColorCorrectPlugin"
#define PLUGINID_OFX_COLORLOOKUP "net.sf.openfx.ColorLookupPlugin"
#define PLUGINID_OFX_BLURCIMG "net.sf.cimg.CImgBlur"
#define PLUGINID_OFX_CORNERPIN "net.sf.openfx.CornerPinPlugin"
#define PLUGINID_OFX_CONSTANT "net.sf.openfx.ConstantPlugin"
#define PLUGINID_OFX_TIMEOFFSET "net.sf.openfx.timeOffset"
#define PLUGINID_OFX_FRAMEHOLD "net.sf.openfx.FrameHold"
#define PLUGINID_OFX_RETIME "net.sf.openfx.Retime"
#define PLUGINID_OFX_FRAMERANGE "net.sf.openfx.FrameRange"
#define PLUGINID_OFX_RUNSCRIPT "fr.inria.openfx.RunScript"
#define PLUGINID_OFX_READFFMPEG "fr.inria.openfx.ReadFFmpeg"
#define PLUGINID_OFX_SHUFFLE "net.sf.openfx.ShufflePlugin"
#define PLUGINID_OFX_TIMEDISSOLVE "net.sf.openfx.TimeDissolvePlugin"
#define PLUGINID_OFX_WRITEFFMPEG "fr.inria.openfx.WriteFFmpeg"
#define PLUGINID_OFX_READPFM "fr.inria.openfx.ReadPFM"
#define PLUGINID_OFX_WRITEPFM "fr.inria.openfx.WritePFM"
#define PLUGINID_OFX_READMISC "fr.inria.openfx.ReadMisc"
#define PLUGINID_OFX_READPSD "net.fxarena.openfx.ReadPSD"
#define PLUGINID_OFX_READKRITA "fr.inria.openfx.ReadKrita"
#define PLUGINID_OFX_READSVG "net.fxarena.openfx.ReadSVG"
#define PLUGINID_OFX_READORA "fr.inria.openfx.OpenRaster"
#define PLUGINID_OFX_READCDR "fr.inria.openfx.ReadCDR"
#define PLUGINID_OFX_READPNG "fr.inria.openfx.ReadPNG"
#define PLUGINID_OFX_WRITEPNG "fr.inria.openfx.WritePNG"
#define PLUGINID_OFX_READPDF "fr.inria.openfx.ReadPDF"
#define PLUGINID_OFX_READBRAW "net.sf.openfx.BlackmagicRAW"
#define PLUGINID_NATRON_VIEWER (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.Viewer")
#define PLUGINID_NATRON_DISKCACHE (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.DiskCache")
#define PLUGINID_NATRON_DOT (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.Dot")
#define PLUGINID_NATRON_READQT (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.ReadQt")
#define PLUGINID_NATRON_WRITEQT (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.WriteQt")
#define PLUGINID_NATRON_GROUP (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.Group")
#define PLUGINID_NATRON_INPUT (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.Input")
#define PLUGINID_NATRON_OUTPUT (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.Output")
#define PLUGINID_NATRON_BACKDROP (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.BackDrop") // DO NOT change the capitalization, even if it's wrong
#define PLUGINID_NATRON_ROTOPAINT (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.RotoPaint")
#define PLUGINID_NATRON_ROTO (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.Roto")
#define PLUGINID_NATRON_ROTOSMEAR (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.RotoSmear")
#define PLUGINID_NATRON_PRECOMP (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.Precomp")
#define PLUGINID_NATRON_TRACKER (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.Tracker")
#define PLUGINID_NATRON_JOINVIEWS (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.JoinViews")
#define PLUGINID_NATRON_READ (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.Read")
#define PLUGINID_NATRON_WRITE (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.Write")
#define PLUGINID_NATRON_ONEVIEW (NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.OneView")
#define kReaderParamNameOriginalFrameRange "originalFrameRange"
NATRON_NAMESPACE_ENTER
/**
* @brief This is the base class for visual effects.
* A live instance is always living throughout the lifetime of a Node and other copies are
* created on demand when a render is needed.
**/
class EffectInstance
: public NamedKnobHolder
, public LockManagerI<Image>
, public boost::enable_shared_from_this<EffectInstance>
{
GCC_DIAG_SUGGEST_OVERRIDE_OFF
Q_OBJECT
GCC_DIAG_SUGGEST_OVERRIDE_ON
public:
typedef std::map<int, std::list<ImagePtr> > InputImagesMap;
typedef std::map<int, std::list<ImagePlaneDesc> > ComponentsNeededMap;
typedef boost::shared_ptr<ComponentsNeededMap> ComponentsNeededMapPtr;
struct RenderRoIArgs
{
// Developer note: the fields were reordered to optimize packing.
// see http://www.catb.org/esr/structure-packing/
double time; //< the time at which to render
RenderScale scale; //< the scale at which to render
unsigned int mipMapLevel; //< the mipmap level (redundant with the scale, stored here to avoid refetching it everytimes)
ViewIdx view; //< the view to render
RectI roi; //< the renderWindow (in pixel coordinates) , watch out OpenFX action getRegionsOfInterest expects canonical coords!
RectD preComputedRoD; //< pre-computed region of definition in canonical coordinates for this effect to speed-up the call to renderRoi
std::list<ImagePlaneDesc> components; //< the requested image components (per plane)
///When called from getImage() the calling node will have already computed input images, hence the image of this node
///might already be in this list
EffectInstance::InputImagesMap inputImagesList;
const EffectInstance* caller;
ImageBitDepthEnum bitdepth; //< the requested bit depth
bool byPassCache;
bool calledFromGetImage;
// Request what kind of storage we need images to be in return of renderRoI
StorageModeEnum returnStorage;
// Set to false if you don't want the node to render using the GPU at all
bool allowGPURendering;
// the time that was passed to the original renderRoI call of the caller node
double callerRenderTime;
RenderRoIArgs()
: time(0)
, scale(1.)
, mipMapLevel(0)
, view(0)
, roi()
, preComputedRoD()
, components()
, inputImagesList()
, caller(0)
, bitdepth(eImageBitDepthFloat)
, byPassCache(false)
, calledFromGetImage(false)
, returnStorage(eStorageModeRAM)
, allowGPURendering(true)
, callerRenderTime(0.)
{
}
RenderRoIArgs( double time_,
const RenderScale & scale_,
unsigned int mipMapLevel_,
ViewIdx view_,
bool byPassCache_,
const RectI & roi_,
const RectD & preComputedRoD_,
const std::list<ImagePlaneDesc> & components_,
ImageBitDepthEnum bitdepth_,
bool calledFromGetImage,
const EffectInstance* caller,
StorageModeEnum returnStorage,
double callerRenderTime,
const EffectInstance::InputImagesMap & inputImages = EffectInstance::InputImagesMap() )
: time(time_)
, scale(scale_)
, mipMapLevel(mipMapLevel_)
, view(view_)
, roi(roi_)
, preComputedRoD(preComputedRoD_)
, components(components_)
, inputImagesList(inputImages)
, caller(caller)
, bitdepth(bitdepth_)
, byPassCache(byPassCache_)
, calledFromGetImage(calledFromGetImage)
, returnStorage(returnStorage)
, allowGPURendering(true)
, callerRenderTime(callerRenderTime)
{
}
};
enum SupportsEnum
{
eSupportsMaybe = -1,
eSupportsNo = 0,
eSupportsYes = 1
};
public:
// TODO: enable_shared_from_this
// constructors should be privatized in any class that derives from boost::enable_shared_from_this<>
/**
* @brief Constructor used once for each node created. Its purpose is to create the "live instance".
* You shouldn't do any heavy processing here nor lengthy initialization as the constructor is often
* called just to be able to call a few virtuals functions.
* The constructor is always called by the main thread of the application.
**/
explicit EffectInstance(NodePtr node);
protected:
EffectInstance(const EffectInstance& other);
public:
// dtor
virtual ~EffectInstance();
virtual bool canHandleEvaluateOnChangeInOtherThread() const OVERRIDE
{
return true;
}
/**
* @brief Returns true once the effect has been fully initialized and is ready to have its actions called apart from
* the createInstanceAction
**/
virtual bool isEffectCreated() const
{
return true;
}
/**
* @brief Returns a pointer to the node holding this effect.
**/
NodePtr getNode() const WARN_UNUSED_RETURN
{
return _node.lock();
}
/**
* @brief Returns the "real" hash of the node synchronized with the gui state
**/
U64 getHash() const WARN_UNUSED_RETURN;
/**
* @brief Returns the hash the node had at the start of renderRoI. This will return the same value
* at any time during the same render call.
* @returns This function returns true if case of success, false otherwise.
**/
U64 getRenderHash() const WARN_UNUSED_RETURN;
U64 getKnobsAge() const WARN_UNUSED_RETURN;
/**
* @brief Set the knobs age of this node to be 'age'. Note that this can be called
* for 2 reasons:
* - loading a project
* - If this node is a clone and the master node changed its hash.
**/
void setKnobsAge(U64 age);
/**
* @brief Forwarded to the node's name
**/
const std::string & getScriptName() const WARN_UNUSED_RETURN;
virtual std::string getScriptName_mt_safe() const OVERRIDE FINAL WARN_UNUSED_RETURN;
virtual std::string getFullyQualifiedName() const OVERRIDE FINAL WARN_UNUSED_RETURN;
virtual void onScriptNameChanged(const std::string& /*fullyQualifiedName*/) {}
/**
* @brief Returns the node output format
**/
RectI getOutputFormat() const;
/**
* @brief Forwarded to the node's render views count
**/
int getRenderViewsCount() const WARN_UNUSED_RETURN;
/**
* @brief Returns input n. It might be NULL if the input is not connected.
* MT-Safe
**/
EffectInstancePtr getInput(int n) const WARN_UNUSED_RETURN;
/**
* @brief Forwarded to the node holding the effect
**/
bool hasOutputConnected() const WARN_UNUSED_RETURN;
/**
* @brief Must return the plugin's major version.
**/
virtual int getMajorVersion() const WARN_UNUSED_RETURN = 0;
/**
* @brief Must return the plugin's minor version.
**/
virtual int getMinorVersion() const WARN_UNUSED_RETURN = 0;
/**
* @brief Is this node an input node ? An input node means
* it has no input.
**/
virtual bool isGenerator() const WARN_UNUSED_RETURN
{
return false;
}
/**
* @brief Is the node a reader ?
**/
virtual bool isReader() const WARN_UNUSED_RETURN
{
return false;
}
/**
* @brief Basically returns true for PLUGINID_OFX_READFFMPEG
**/
virtual bool isVideoReader() const WARN_UNUSED_RETURN
{
return false;
}
/**
* @brief Is the node a writer ?
**/
virtual bool isWriter() const WARN_UNUSED_RETURN
{
return false;
}
/**
* @brief Basically returns true for PLUGINID_OFX_WRITEFFMPEG
**/
virtual bool isVideoWriter() const WARN_UNUSED_RETURN
{
return false;
}
/**
* @brief Is this node an output node ? An output node means
* it has no output.
**/
virtual bool isOutput() const WARN_UNUSED_RETURN
{
return false;
}
/**
* @brief Returns true if this node is a tracker
**/
virtual bool isTrackerNodePlugin() const WARN_UNUSED_RETURN
{
return false;
}
/**
* @brief Returns true if this is our tracking node.
**/
virtual bool isBuiltinTrackerNode() const WARN_UNUSED_RETURN
{
return false;
}
/**
* @brief Returns true if this node is a tracker
**/
virtual bool isRotoPaintNode() const WARN_UNUSED_RETURN
{
return false;
}
virtual bool isPaintingOverItselfEnabled() const WARN_UNUSED_RETURN;
/**
* @brief Returns true if the node is capable of processing data from its input
**/
virtual bool isFilter() const WARN_UNUSED_RETURN
{
return false;
}
/**
* @brief Is this node an OpenFX node?
**/
virtual bool isOpenFX() const WARN_UNUSED_RETURN
{
return false;
}
/**
* @brief How many input can we have at most. (i.e: how many input arrows)
* This function should be MT-safe and should never change the value returned.
**/
virtual int getNInputs() const WARN_UNUSED_RETURN = 0;
/**
* @brief Is inputNb optional ? In which case the render can be made without it.
**/
virtual bool isInputOptional(int inputNb) const WARN_UNUSED_RETURN = 0;
/**
* @brief Is inputNb a mask ? In which case the effect will have an additional mask parameter.
**/
virtual bool isInputMask(int /*inputNb*/) const WARN_UNUSED_RETURN
{
return false;
};
/**
* @brief Is the input a roto brush ?
**/
virtual bool isInputRotoBrush(int /*inputNb*/) const WARN_UNUSED_RETURN
{
return false;
}
virtual int getRotoBrushInputIndex() const WARN_UNUSED_RETURN
{
return -1;
}
virtual bool getMakeSettingsPanel() const { return true; }
virtual bool getCreateChannelSelectorKnob() const;
/**
* @brief Returns the index of the channel to use to produce the mask and the components.
* None = -1
* R = 0
* G = 1
* B = 2
* A = 3
**/
int getMaskChannel(int inputNb, const std::list<ImagePlaneDesc>& availableLayers, ImagePlaneDesc* comps) const;
/**
* @brief Returns whether masking is enabled or not
**/
bool isMaskEnabled(int inputNb) const;
/**
* @brief Routine called after the creation of an effect. This function must
* fill for the given input what image components we can feed it with.
* This function is also called to specify what image components this effect can output.
* In that case inputNb equals -1.
**/
virtual void addAcceptedComponents(int inputNb, std::list<ImagePlaneDesc>* comps) = 0;
virtual void addSupportedBitDepth(std::list<ImageBitDepthEnum>* depths) const = 0;
/**
* @brief Must return the deepest bit depth that this plug-in can support.
* If 32 float is supported then return eImageBitDepthFloat, otherwise
* return eImageBitDepthShort if 16 bits is supported, and as a last resort, return
* eImageBitDepthByte. At least one must be returned.
**/
ImageBitDepthEnum getBestSupportedBitDepth() const;
bool isSupportedBitDepth(ImageBitDepthEnum depth) const;
/**
* @brief Returns true if the given input supports the given components. If inputNb equals -1
* then this function will check whether the effect can produce the given components.
**/
bool isSupportedComponent(int inputNb, const ImagePlaneDesc & comp) const;
/**
* @brief Returns the most appropriate components that can be supported by the inputNb.
* If inputNb equals -1 then this function will check the output components.
**/
ImagePlaneDesc findClosestSupportedComponents(int inputNb, const ImagePlaneDesc & comp) const WARN_UNUSED_RETURN;
/**
* @brief Can be derived to give a more meaningful label to the input 'inputNb'
**/
virtual std::string getInputLabel(int inputNb) const WARN_UNUSED_RETURN;
/**
* @brief Return a string indicating the purpose of the given input. It is used for the user documentation.
**/
virtual std::string getInputHint(int inputNb) const WARN_UNUSED_RETURN;
/**
* @brief Must be implemented to give the plugin internal id(i.e: net.sf.openfx:invertPlugin)
**/
virtual std::string getPluginID() const WARN_UNUSED_RETURN = 0;
/**
* @brief Must be implemented to give the plugin a label that will be used by the graphical
* user interface.
**/
virtual std::string getPluginLabel() const WARN_UNUSED_RETURN = 0;
/**
* @brief The grouping of the plug-in. For instance Views/Stereo/MyStuff
* Each string being one level of the grouping. The first one being the name
* of one group that will appear in the user interface.
**/
virtual void getPluginGrouping(std::list<std::string>* grouping) const = 0;
/**
* @brief Must be implemented to give a description of the effect that this node does. This is typically
* what you'll see displayed when the user clicks the '?' button on the node's panel in the user interface.
**/
virtual std::string getPluginDescription() const WARN_UNUSED_RETURN = 0;
/**
* @brief Returns whether the plugin description is written in markdown or not
**/
virtual bool isPluginDescriptionInMarkdown() const
{
return false;
}
/**
* @brief Must returns the shortcuts that are going to be used for this plug-in. Each shortcut
* will be added to the shortcut editor and must have an ID and a description label.
* Make sure that within the same plug-in there are no conflicting shortcuts.
* Each shortcut ID can then be set to KnobButton used to indicate they have a shortcut.
**/
virtual void getPluginShortcuts(std::list<PluginActionShortcut>* /*shortcuts*/) {}
/**
* @bried Returns the effect render order preferences:
* eSequentialPreferenceNotSequential: The effect does not need to be run in a sequential order
* eSequentialPreferenceOnlySequential: The effect can only be run in a sequential order (i.e like the background render would do)
* eSequentialPreferencePreferSequential: This indicates that the effect would work better by rendering sequential. This is merely
* a hint to Natron but for now we just consider it as eSequentialPreferenceNotSequential.
**/
virtual SequentialPreferenceEnum getSequentialPreference() const
{
return eSequentialPreferenceNotSequential;
}
enum RenderRoIRetCode
{
eRenderRoIRetCodeOk = 0,
eRenderRoIRetCodeAborted,
eRenderRoIRetCodeFailed
};
/**
* @brief Renders the image planes at the given time,scale and for the given view & render window.
* This returns a list of all planes requested in the args.
* @param args See the definition of the class for comments on each argument.
* The return code indicates whether the render succeeded or failed. Note that this function may succeed
* and return 0 plane if the RoI does not intersect the RoD of the effect.
**/
RenderRoIRetCode renderRoI(const RenderRoIArgs & args,
std::map<ImagePlaneDesc, ImagePtr>* outputPlanes) WARN_UNUSED_RETURN;
void getImageFromCacheAndConvertIfNeeded(bool useCache,
StorageModeEnum storage,
StorageModeEnum returnStorage,
const ImageKey & key,
unsigned int mipMapLevel,
const RectI* boundsParam,
const RectD* rodParam,
const RectI& roi,
ImageBitDepthEnum bitdepth,
const ImagePlaneDesc & components,
const EffectInstance::InputImagesMap & inputImages,
const RenderStatsPtr & stats,
const OSGLContextAttacherPtr& glContextAttacher,
ImagePtr* image);
/**
* @brief Converts the given OpenGL texture to a RAM-stored image. The resulting image will be cached.
* This function is SLOW as it makes use of glReadPixels.
* The OpenGL context should have been made current prior to calling this function.
**/
ImagePtr convertOpenGLTextureToCachedRAMImage(const ImagePtr& image);
/**
* @brief Converts the given RAM-stored image to an OpenGL texture.
* THe resulting texture will not be cached and will destroyed when the shared pointer is released.
* The OpenGL context should have been made current prior to calling this function.
**/
ImagePtr convertRAMImageToOpenGLTexture(const ImagePtr& image);
/**
* @brief This function is to be called by getImage() when the plug-ins renders more planes than the ones suggested
* by the render action. We allocate those extra planes and cache them so they were not rendered for nothing.
* Note that the plug-ins may call this only while in the render action, and there must be other planes to render.
**/
ImagePtr allocateImagePlaneAndSetInThreadLocalStorage(const ImagePlaneDesc & plane);
class NotifyRenderingStarted_RAII
{
Node* _node;
bool _didEmit;
bool _didGroupEmit;
public:
NotifyRenderingStarted_RAII(Node* node);
~NotifyRenderingStarted_RAII();
};
typedef boost::shared_ptr<NotifyRenderingStarted_RAII> NotifyRenderingStarted_RAIIPtr;
class NotifyInputNRenderingStarted_RAII
{
Node* _node;
int _inputNumber;
bool _didEmit;
public:
NotifyInputNRenderingStarted_RAII(Node* node,
int inputNumber);
~NotifyInputNRenderingStarted_RAII();
};
typedef boost::shared_ptr<NotifyInputNRenderingStarted_RAII> NotifyInputNRenderingStarted_RAIIPtr;
/**
* @brief Sets render preferences for the rendering of a frame for the current thread.
* This is thread-local storage. This is NOT local to a call to renderRoI
**/
void setParallelRenderArgsTLS(double time,
ViewIdx view,
bool isRenderUserInteraction,
bool isSequential,
U64 nodeHash,
const AbortableRenderInfoPtr& abortInfo,
const NodePtr & treeRoot,
int visitsCount,
const NodeFrameRequestPtr & nodeRequest,
const OSGLContextPtr& glContext,
int textureIndex,
const TimeLine* timeline,
bool isAnalysis,
bool isDuringPaintStrokeCreation,
const NodesList & rotoPaintNodes,
RenderSafetyEnum currentThreadSafety,
PluginOpenGLRenderSupport currentOpenGLSupport,
bool doNanHandling,
bool draftMode,
const RenderStatsPtr & stats);
void setDuringPaintStrokeCreationThreadLocal(bool duringPaintStroke);
void setNodeRequestThreadLocal(const NodeFrameRequestPtr & nodeRequest);
void setParallelRenderArgsTLS(const ParallelRenderArgsPtr & args);
/**
*@returns whether the effect was flagged with canSetValue = true or false
**/
void invalidateParallelRenderArgsTLS();
ParallelRenderArgsPtr getParallelRenderArgsTLS() const;
//Implem in ParallelRenderArgs.cpp
static StatusEnum getInputsRoIsFunctor(bool useTransforms,
double time,
ViewIdx view,
unsigned originalMipMapLevel,
const NodePtr & node,
const NodePtr& callerNode,
const NodePtr & treeRoot,
const RectD & canonicalRenderWindow,
FrameRequestMap & requests);
/**
* @brief Visit recursively the compositing tree and computes required information about region of interests for each node and
* for each frame/view pair. This helps to call render a single time per frame/view pair for a node.
* Implem is in ParallelRenderArgs.cpp
**/
static StatusEnum computeRequestPass(double time,
ViewIdx view,
unsigned int mipMapLevel,
const RectD & renderWindow,
const NodePtr & treeRoot,
FrameRequestMap & request);
// Implem is in ParallelRenderArgs.cpp
static EffectInstance::RenderRoIRetCode treeRecurseFunctor(bool isRenderFunctor,
const NodePtr & node,
const FramesNeededMap & framesNeeded,
const RoIMap & inputRois,
const InputMatrixMapPtr & reroutesMap,
bool useTransforms, // roi functor specific
StorageModeEnum renderStorageMode, // The storage of the image returned by the current Render
unsigned int originalMipMapLevel, // roi functor specific
double time,
ViewIdx view,
const NodePtr & treeRoot,
FrameRequestMap* requests, // roi functor specific
EffectInstance::InputImagesMap* inputImages, // render functor specific
const EffectInstance::ComponentsNeededMap* neededComps, // render functor specific
bool useScaleOneInputs, // render functor specific
bool byPassCache); // render functor specific
/**
* @brief Don't override this one, override onKnobValueChanged instead.
**/
virtual bool onKnobValueChanged_public(KnobI* k, ValueChangedReasonEnum reason, double time, ViewSpec view, bool originatedFromMainThread) OVERRIDE FINAL;
/**
* @brief Returns a pointer to the first non disabled upstream node.
* When cycling through the tree, we prefer non optional inputs and we span inputs
* from last to first.
* If this not is not disabled, it will return a pointer to this.
**/
EffectInstancePtr getNearestNonDisabled() const;
/**
* @brief Same as getNearestNonDisabled() except that it returns the *last* disabled node before the nearest non disabled node.
* @param inputNb[out] The inputNb of the node that is non disabled.
**/
EffectInstancePtr getNearestNonDisabledPrevious(int* inputNb);
/**
* @brief Same as getNearestNonDisabled except that it looks for the nearest non identity node.
* This function calls the action isIdentity and getRegionOfDefinition and can be expensive!
**/
EffectInstancePtr getNearestNonIdentity(double time);
/**
* @brief This is purely for the OfxEffectInstance derived class, but passed here for the sake of abstraction
**/
bool refreshMetadata_public(bool recurse);
virtual void onChannelsSelectorRefreshed() {}
void setDefaultMetadata();
protected:
bool refreshMetadata_internal();
bool setMetadataInternal(const NodeMetadata& metadata);
virtual void onMetadataRefreshed(const NodeMetadata& /*metadata*/) {}
bool refreshMetadata_recursive(std::list<Node*> & markedNodes);
friend class ClipPreferencesRunning_RAII;
void setClipPreferencesRunning(bool running);
public:
///////////////////////Metadatas related////////////////////////
/**
* @brief Returns the preferred metadata to render with
* This should only be called to compute the clip preferences, call the appropriate
* getters to get the actual values.
* The default implementation gives reasonable values appropriate to the context of the node (the inputs)
* and the values reported by the supported components/bitdepth
*
* This should not be reimplemented except for OpenFX which already has its default specification
* for clip Preferences, see setDefaultClipPreferences()
* Returns eStatusOK on success, eStatusFailed on failure.
*
**/
StatusEnum getPreferredMetadata_public(NodeMetadata& metadata);
protected:
virtual StatusEnum getPreferredMetadata(NodeMetadata& /*metadata*/) { return eStatusOK; }
private:
StatusEnum getDefaultMetadata(NodeMetadata& metadata);
public:
/**
* @brief Returns whether the effect is frame-varying (i.e: a Reader with different images in the sequence)
**/
bool isFrameVarying() const;
/**
* @brief Returns whether the current node and/or the tree upstream is frame varying or animated.
* It is frame varying/animated if at least one of the node is animated/varying
**/
bool isFrameVaryingOrAnimated_Recursive() const;
/**
* @brief Returns the preferred output frame rate to render with
**/
double getFrameRate() const;
/**
* @brief Returns the preferred premultiplication flag for the output image
**/
ImagePremultiplicationEnum getPremult() const;
/**
* @brief If true, the plug-in knows how to render frames at non integer times. If false
* this is the hint indicating that the plug-ins can only render integer frame times (such as a Reader)
**/
bool canRenderContinuously() const;
/**
* @brief Returns the field ordering of images produced by this plug-in
**/
ImageFieldingOrderEnum getFieldingOrder() const;
/**
* @brief Returns the pixel aspect ratio, depth and components for the given input.
* If inputNb equals -1 then this function will check the output components.
**/
double getAspectRatio(int inputNb) const;
void getMetadataComponents(int inputNb, ImagePlaneDesc* plane, ImagePlaneDesc* pairedPlane) const;
int getMetadataNComps(int inputNb) const;
ImageBitDepthEnum getBitDepth(int inputNb) const;
///////////////////////End Metadatas related////////////////////////
virtual void lock(const boost::shared_ptr<Image> & entry) OVERRIDE FINAL;
virtual bool tryLock(const boost::shared_ptr<Image> & entry) OVERRIDE FINAL;
virtual void unlock(const boost::shared_ptr<Image> & entry) OVERRIDE FINAL;
virtual bool canSetValue() const OVERRIDE FINAL WARN_UNUSED_RETURN;
virtual void abortAnyEvaluation(bool keepOldestRender = true) OVERRIDE FINAL;
virtual double getCurrentTime() const OVERRIDE WARN_UNUSED_RETURN;
virtual ViewIdx getCurrentView() const OVERRIDE WARN_UNUSED_RETURN;
virtual bool getCanTransform() const
{
return false;
}
RenderScale getOverlayInteractRenderScale() const;
SequenceTime getFrameRenderArgsCurrentTime() const;
ViewIdx getFrameRenderArgsCurrentView() const;
virtual bool getInputsHoldingTransform(std::list<int>* /*inputs*/) const
{
return false;
}
bool getThreadLocalRegionsOfInterests(RoIMap & roiMap) const;
OSGLContextPtr getThreadLocalOpenGLContext() const;
void getThreadLocalInputImages(InputImagesMap* images) const;
void addThreadLocalInputImageTempPointer(int inputNb, const ImagePtr & img);
bool getThreadLocalRotoPaintTreeNodes(NodesList* nodes) const;
virtual bool isMultiPlanar() const
{
return false;
}
enum PassThroughEnum
{
ePassThroughBlockNonRenderedPlanes,
ePassThroughPassThroughNonRenderedPlanes,
ePassThroughRenderAllRequestedPlanes
};
virtual EffectInstance::PassThroughEnum isPassThroughForNonRenderedPlanes() const
{
return ePassThroughPassThroughNonRenderedPlanes;
}
virtual bool isViewAware() const
{
return false;
}
enum ViewInvarianceLevel
{
eViewInvarianceAllViewsVariant,
eViewInvarianceOnlyPassThroughPlanesVariant,
eViewInvarianceAllViewsInvariant,
};
virtual ViewInvarianceLevel isViewInvariant() const
{
return eViewInvarianceAllViewsVariant;
}
class OpenGLContextEffectData
{
// True if we did not unlock the context mutex in attachOpenGLContext()
bool hasTakenLock;
public:
OpenGLContextEffectData()
: hasTakenLock(false)
{
}
void setHasTakenLock(bool b)
{
hasTakenLock = b;
}
bool getHasTakenLock() const
{
return hasTakenLock;
}
virtual ~OpenGLContextEffectData()
{
}
};
typedef boost::shared_ptr<OpenGLContextEffectData> OpenGLContextEffectDataPtr;
struct RenderActionArgs
{
double time;
RenderScale originalScale;
RenderScale mappedScale;
RectI roi;
std::list<std::pair<ImagePlaneDesc, ImagePtr> > outputPlanes;
EffectInstance::InputImagesMap inputImages;
ViewIdx view;
bool isSequentialRender;
bool isRenderResponseToUserInteraction;
bool byPassCache;
bool draftMode;
bool useOpenGL;
EffectInstance::OpenGLContextEffectDataPtr glContextData;
std::bitset<4> processChannels;
};
protected:
/**
* @brief Must fill the image 'output' for the region of interest 'roi' at the given time and
* at the given scale.
* Pre-condition: render() has been called for all inputs so the portion of the image contained
* in output corresponding to the roi is valid.
* Note that this function can be called concurrently for the same output image but with different
* rois, depending on the threading-affinity of the plug-in.
**/
virtual StatusEnum render(const RenderActionArgs & /*args*/) WARN_UNUSED_RETURN
{
return eStatusOK;
}
virtual StatusEnum getTransform(double /*time*/,
const RenderScale & /*renderScale*/,
bool /*draftRender*/,
ViewIdx /*view*/,
EffectInstancePtr* /*inputToTransform*/,
Transform::Matrix3x3* /*transform*/) WARN_UNUSED_RETURN
{
return eStatusReplyDefault;
}
public: