New mechanism for source update with callbacks

Similarly to Node update callbacks, sources now have SourceCallbacks called at the start of each update. Several SourceCallback are implemented to ensure thread safe update of more complex properties (mixing alpha, depth, etc.).
This commit is contained in:
Bruno Herbelin
2021-12-20 00:25:42 +01:00
parent 8deb364025
commit f921e7610c
9 changed files with 464 additions and 169 deletions

View File

@@ -4,9 +4,11 @@
#include <string>
#include <map>
#include <atomic>
#include <mutex>
#include <list>
#include "View.h"
#include "SourceCallback.h"
#define DEFAULT_MIXING_TRANSLATION -1.f, 1.f
@@ -23,6 +25,7 @@
#define ICON_SOURCE_CLONE 9, 2
#define ICON_SOURCE 12, 11
class SourceCallback;
class ImageShader;
class MaskShader;
class ImageProcessingShader;
@@ -56,6 +59,9 @@ public:
void copy(SourceCore const& other);
// alpha transfer function
static float alphaFromCordinates(float x, float y);
protected:
// nodes
std::map<View::Mode, Group*> groups_;
@@ -136,9 +142,13 @@ public:
// a Source shall be updated before displayed (Mixing, Geometry and Layer)
virtual void update (float dt);
// add callback to each update
void call(SourceCallback *callback, bool override = false);
// update mode
inline bool active () const { return active_; }
virtual void setActive (bool on);
void setActive (float threshold);
// lock mode
inline bool locked () const { return locked_; }
@@ -178,14 +188,9 @@ public:
void setMask (FrameBufferImage *img);
void storeMask (FrameBufferImage *img = nullptr);
// operations on depth
// get properties
float depth () const;
void setDepth (float d);
// operations on alpha
float mix_distance ();
float alpha () const;
void setAlpha (float a);
// groups for mixing
MixingGroup *mixingGroup() const { return mixinggroup_; }
@@ -304,6 +309,8 @@ protected:
bool need_update_;
float dt_;
Workspace workspace_;
std::list<SourceCallback *> update_callbacks_;
std::mutex access_callbacks_;
// clones
CloneList clones_;