summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsubhransu mohanty <sub.mohanty@samsung.com>2018-07-11 11:53:55 +0900
committersubhransu mohanty <sub.mohanty@samsung.com>2018-07-11 11:57:09 +0900
commitbfbd98b29368778eaa5893d7c46614a3c8d8d1cd (patch)
tree8229973368aecad026e55a9e51133371041ee85c
parent35b178d268f14aee2c05e4d60c0611d83b9e7eb4 (diff)
lottie: remove unnecessary folder
-rw-r--r--include/sgcontext.h76
-rw-r--r--include/sgfontdatabase.h33
-rw-r--r--include/sgnodeupdater_p.h30
-rw-r--r--include/sgnodevisitor_p.h28
-rw-r--r--include/sgrectnode.h15
-rw-r--r--include/sgshapenode.h31
-rw-r--r--include/ssg6
-rw-r--r--include/ssg.h9
-rw-r--r--src/animation/meson.build0
-rw-r--r--src/animation/sgkeyframe.h120
-rw-r--r--src/scenegraph/backend/meson.build2
-rw-r--r--src/scenegraph/backend/software/meson.build8
-rw-r--r--src/scenegraph/backend/software/sgsoftwaredrawable.cpp135
-rw-r--r--src/scenegraph/backend/software/sgsoftwaredrawable.h68
-rw-r--r--src/scenegraph/backend/software/sgsoftwarenodeupdater.cpp134
-rw-r--r--src/scenegraph/backend/software/sgsoftwarenodeupdater.h76
-rw-r--r--src/scenegraph/backend/software/sgsoftwarerectnode.cpp0
-rw-r--r--src/scenegraph/backend/software/sgsoftwarerectnode.h12
-rw-r--r--src/scenegraph/backend/software/sgsoftwarerenderer.cpp207
-rw-r--r--src/scenegraph/backend/software/sgsoftwarerenderer.h50
-rw-r--r--src/scenegraph/core/meson.build10
-rw-r--r--src/scenegraph/core/sgcontext.cpp1
-rw-r--r--src/scenegraph/core/sgnode.cpp383
-rw-r--r--src/scenegraph/core/sgnodeupdater.cpp98
-rw-r--r--src/scenegraph/core/sgrectnode.cpp0
-rw-r--r--src/scenegraph/core/sgrenderer.cpp192
-rw-r--r--src/scenegraph/meson.build6
-rw-r--r--src/text/meson.build5
-rw-r--r--src/text/sgfontdatabase.cpp53
29 files changed, 0 insertions, 1788 deletions
diff --git a/include/sgcontext.h b/include/sgcontext.h
deleted file mode 100644
index 0e699ea..0000000
--- a/include/sgcontext.h
+++ /dev/null
@@ -1,76 +0,0 @@
1#ifndef SGCONTEXT_H
2#define SGCONTEXT_H
3
4#include"vglobal.h"
5
6class SGRectangleNode;
7class SGImageNode;
8class SGGlyphNode;
9class SGLayer;
10class SGRenderContext;
11
12class SG_EXPORT SGContext
13{
14
15public:
16 enum AntialiasingMethod {
17 UndecidedAntialiasing,
18 VertexAntialiasing,
19 MsaaAntialiasing
20 };
21
22 explicit SGContext();
23 virtual ~SGContext();
24
25 virtual void renderContextInitialized(SGRenderContext *renderContext);
26 virtual void renderContextInvalidated(SGRenderContext *renderContext);
27 virtual SGRenderContext *createRenderContext() = 0;
28
29 virtual SGRectangleNode *createRectangleNode() = 0;
30 virtual SGImageNode *createImageNode() = 0;
31 virtual SGGlyphNode *createGlyphNode(SGRenderContext *rc) = 0;
32 virtual SGLayer *createLayer(SGRenderContext *renderContext) = 0;
33
34 static SGContext *createDefaultContext();
35 //static SGRenderLoop *createWindowManager();
36
37 static void setBackend(const char *backend);
38 static const char *backend();
39};
40
41class SG_EXPORT SGRenderContext
42{
43public:
44 enum CreateTextureFlags {
45 CreateTexture_Alpha = 0x1,
46 CreateTexture_Atlas = 0x2,
47 CreateTexture_Mipmap = 0x4
48 };
49
50 SGRenderContext(SGContext *context);
51 virtual ~SGRenderContext();
52
53 SGContext *sceneGraphContext() const { return m_sg; }
54 virtual bool isValid() const { return true; }
55
56 virtual void initialize(void *context);
57 virtual void invalidate();
58 virtual void renderNextFrame(SGRenderer *renderer, uint fboId) = 0;
59 virtual void endSync();
60
61 virtual SGTexture *createTexture() const = 0;
62 virtual SGRenderer *createRenderer() = 0;
63
64 virtual void setAttachToGraphicsContext(bool attach) { Q_UNUSED(attach); }
65
66 virtual int maxTextureSize() const = 0;
67
68 void registerFontengineForCleanup(QFontEngine *engine);
69
70protected:
71 // Hold m_sg with QPointer in the rare case it gets deleted before us.
72 SGContext *m_sg;
73};
74
75
76#endif // SGCONTEXT_H
diff --git a/include/sgfontdatabase.h b/include/sgfontdatabase.h
deleted file mode 100644
index 3a0198b..0000000
--- a/include/sgfontdatabase.h
+++ /dev/null
@@ -1,33 +0,0 @@
1#ifndef SGFONTDATABASE_H
2#define SGFONTDATABASE_H
3
4#include"vglobal.h"
5
6class SGFontDatabasePrivate;
7class SG_EXPORT SGFontDatabase
8{
9public:
10 enum HintMode{
11 Default,
12 None,
13 Auto,
14 Full
15 };
16 ~SGFontDatabase();
17 static SGFontDatabase &instance()
18 {
19 static SGFontDatabase Singleton;
20 return Singleton;
21 }
22 SGFontDatabase(const SGFontDatabase &other) = delete;
23 SGFontDatabase(SGFontDatabase&&) = delete;
24 SGFontDatabase& operator=(SGFontDatabase const&) = delete;
25 SGFontDatabase& operator=(SGFontDatabase &&) = delete;
26 void print() const;
27private:
28 SGFontDatabase();
29 friend class SGFontDatabasePrivate;
30 SGFontDatabasePrivate *d;
31};
32
33#endif // SGFONTDATABASE_H
diff --git a/include/sgnodeupdater_p.h b/include/sgnodeupdater_p.h
deleted file mode 100644
index 7c1cd18..0000000
--- a/include/sgnodeupdater_p.h
+++ /dev/null
@@ -1,30 +0,0 @@
1#ifndef SGNODEUPDATER_P_H
2#define SGNODEUPDATER_P_H
3
4#include"vglobal.h"
5#include"sgnode.h"
6#include "sgnodevisitor_p.h"
7
8class SG_EXPORT SGNodeUpdater : public SGNodeVisitor
9{
10public:
11 SGNodeUpdater();
12 ~SGNodeUpdater();
13 bool visit(SGTransformNode *) override;
14 void endVisit(SGTransformNode *) override;
15 bool visit(SGClipNode *) override;
16 void endVisit(SGClipNode *) override;
17 bool visit(SGGeometryNode *) override;
18 void endVisit(SGGeometryNode *) override;
19 bool visit(SGOpacityNode *) override;
20 void endVisit(SGOpacityNode *) override;
21 bool visit(SGRootNode *) override;
22 void endVisit(SGRootNode *) override;
23 void visitChildren(SGNode *node) override;
24
25 bool isNodeBlocked(SGNode *n, SGNode *root) const;
26 void updateStates(SGNode *n);
27
28 void visitNode(SGNode *node);
29};
30#endif // SGNODEUPDATER_P_H
diff --git a/include/sgnodevisitor_p.h b/include/sgnodevisitor_p.h
deleted file mode 100644
index 16120cc..0000000
--- a/include/sgnodevisitor_p.h
+++ /dev/null
@@ -1,28 +0,0 @@
1#ifndef SGNODEVISITOR_P_H
2#define SGNODEVISITOR_P_H
3
4class SGTransformNode;
5class SGClipNode;
6class SGGeometryNode;
7class SGOpacityNode;
8class SGRootNode;
9class SGNode;
10
11class SGNodeVisitor
12{
13public:
14 virtual ~SGNodeVisitor() {}
15 virtual bool visit(SGTransformNode *) = 0;
16 virtual void endVisit(SGTransformNode *) = 0;
17 virtual bool visit(SGClipNode *) = 0;
18 virtual void endVisit(SGClipNode *) = 0;
19 virtual bool visit(SGGeometryNode *) = 0;
20 virtual void endVisit(SGGeometryNode *) = 0;
21 virtual bool visit(SGOpacityNode *) = 0;
22 virtual void endVisit(SGOpacityNode *) = 0;
23 virtual bool visit(SGRootNode *) = 0;
24 virtual void endVisit(SGRootNode *) = 0;
25 virtual void visitChildren(SGNode *) = 0;
26};
27
28#endif // SGNODEVISITOR_P_H
diff --git a/include/sgrectnode.h b/include/sgrectnode.h
deleted file mode 100644
index 404197a..0000000
--- a/include/sgrectnode.h
+++ /dev/null
@@ -1,15 +0,0 @@
1#ifndef SGRECTNODE_H
2#define SGRECTNODE_H
3#include<sgnode.h>
4
5class SGRectNode : public SGGeometryNode
6{
7public:
8 virtual void setRect(const SGRect &rect) = 0;
9 inline void setRect(int x, int y, int w, int h) noexcept { setRect(SGRect(x, y, w, h)); }
10 virtual SGRect rect() const noexcept = 0;
11
12 virtual void setColor(const SGColor &color) = 0;
13 virtual SGColor color() const = 0;
14};
15#endif // SGRECTNODE_H
diff --git a/include/sgshapenode.h b/include/sgshapenode.h
deleted file mode 100644
index d28f2fa..0000000
--- a/include/sgshapenode.h
+++ /dev/null
@@ -1,31 +0,0 @@
1#ifndef SGSHAPENODE_H
2#define SGSHAPENODE_H
3
4#include "sgnode.h"
5
6class SGGradient;
7
8class SGShapeNode : public SGGeometryNode
9{
10public:
11 FillRule fillRule() const;
12 void setFillRule(FillRule fillRule);
13 JoinStyle joinStyle() const;
14 void setJoinStyle(JoinStyle style);
15 CapStyle capStyle() const;
16 void setCapStyle(CapStyle style);
17 StrokeStyle strokeStyle() const;
18 void setStrokeStyle(StrokeStyle style);
19 double strokeWidth() const;
20 void setStrokeWidth(double w);
21
22 SGColor fillColor() const;
23 void setFillColor(const SGColor &color);
24 SGColor strokeColor() const;
25 void setStrokeColor(const SGColor &color);
26
27 SGGradient *fillGradient() const;
28 void setFillGradient(SGGradient *gradient);
29};
30
31#endif // SGSHAPENODE_H
diff --git a/include/ssg b/include/ssg
deleted file mode 100644
index c718b58..0000000
--- a/include/ssg
+++ /dev/null
@@ -1,6 +0,0 @@
1#ifndef SSG_MODULE_H
2#define SSG_MODULE_H
3
4#include"ssg.h"
5
6#endif //SSG_MODULE_H
diff --git a/include/ssg.h b/include/ssg.h
deleted file mode 100644
index acd3d68..0000000
--- a/include/ssg.h
+++ /dev/null
@@ -1,9 +0,0 @@
1#ifndef SSG_H
2#define SSG_H
3
4#include "vglobal.h"
5#include "vmatrix.h"
6#include "sgnode.h"
7#include "sgregion.h"
8
9#endif // SSG_H
diff --git a/src/animation/meson.build b/src/animation/meson.build
deleted file mode 100644
index e69de29..0000000
--- a/src/animation/meson.build
+++ /dev/null
diff --git a/src/animation/sgkeyframe.h b/src/animation/sgkeyframe.h
deleted file mode 100644
index cc7cf4e..0000000
--- a/src/animation/sgkeyframe.h
+++ /dev/null
@@ -1,120 +0,0 @@
1#ifndef SGKEYFRAME_H
2#define SGKEYFRAME_H
3#include"vglobal.h"
4#include<vector>
5
6template<typename T>
7class KeyFrame
8{
9public:
10 float getStartProgress();
11 float getEndProgress();
12 bool isStatic();
13 bool containsProgress(float progress) {
14 return progress >= getStartProgress() && progress < getEndProgress();
15 }
16private:
17 T startValue;
18 T endValue;
19 float startFrame;
20 float endFrame;
21 //Interpolater interpolater;
22};
23
24/**
25 * <K> Keyframe type
26 * <A> Animation type
27 */
28template<typename K, typename A>
29class BaseKeyframeAnimation
30{
31 BaseKeyframeAnimation(const std::vector<KeyFrame<K>> &keyframes);
32 void setIsDiscrete();
33 void setProgress(float progress);
34 KeyFrame<K> getCurrentKeyframe();
35 float getCurrentKeyframeProgress() {
36 if (isDiscrete) {
37 return 0;
38 }
39
40 KeyFrame<K> keyframe = getCurrentKeyframe();
41 if (keyframe.isStatic()) {
42 return 0;
43 }
44 float progressIntoFrame = progress - keyframe.getStartProgress();
45 float keyframeProgress = keyframe.getEndProgress() - keyframe.getStartProgress();
46 /**
47 * This wil be [0, 1] unless the interpolator has overshoot in which case getValue() should be
48 * able to handle values outside of that range.
49 */
50 //return keyframe.interpolator.getInterpolation(progressIntoFrame / keyframeProgress);
51 }
52 float getStartDelayProgress();
53 float getEndProgress();
54 A getValue() {
55 return getValue(getCurrentKeyframe(), getCurrentKeyframeProgress());
56 }
57
58 float getProgress();
59 /**
60 * keyframeProgress will be [0, 1] unless the interpolator has overshoot in which case, this
61 * should be able to handle values outside of that range.
62 */
63 virtual A getValue(KeyFrame<K> keyframe, float keyframeProgress) = 0;
64private:
65 std::vector<KeyFrame<K>> keyframes;
66 KeyFrame<K> cachedKeyframe;
67 float progress;
68 bool isDiscrete;
69};
70
71template<typename K, typename A> //interface
72class AnimatableValue
73{
74 virtual BaseKeyframeAnimation<K, A> createAnimation() = 0;
75 virtual bool hasAnimation() = 0;
76};
77
78template<typename K, typename O>
79class BaseAnimatableValue<K, O> : public AnimatableValue<K, O>
80{
81public:
82 BaseAnimatableValue(const std::vector<KeyFrame<K>> keyframes, K initialValue) {
83 keyframes = keyframes;
84 initialValue = initialValue;
85 }
86 /**
87 * Convert the value type of the keyframe to the value type of the animation. Often, these
88 * are the same type.
89 */
90 O convertType(K value) {
91 //noinspection unchecked
92 return (O) value;
93 }
94 bool hasAnimation() {
95 return !keyframes.empty();
96 }
97
98 virtual O getInitialValue() {
99 return convertType(initialValue);
100 }
101private:
102 std::vector<KeyFrame<K>> keyframes;
103 K initialValue;
104};
105
106class AnimatableIntegerValue : public BaseAnimatableValue<int, int>
107{
108public:
109 AnimatableIntegerValue();
110 BaseKeyframeAnimation<int, int> createAnimation() {
111 if (!hasAnimation()) {
112 return new StaticKeyframeAnimation<>(initialValue);
113 }
114
115 return new IntegerKeyframeAnimation(keyframes);
116 }
117};
118
119
120#endif // SGKEYFRAME_H
diff --git a/src/scenegraph/backend/meson.build b/src/scenegraph/backend/meson.build
deleted file mode 100644
index b101a21..0000000
--- a/src/scenegraph/backend/meson.build
+++ /dev/null
@@ -1,2 +0,0 @@
1subdir('software')
2
diff --git a/src/scenegraph/backend/software/meson.build b/src/scenegraph/backend/software/meson.build
deleted file mode 100644
index ff2f39d..0000000
--- a/src/scenegraph/backend/software/meson.build
+++ /dev/null
@@ -1,8 +0,0 @@
1source_file = files('sgsoftwarenodeupdater.cpp')
2source_file += files('sgsoftwaredrawable.cpp')
3source_file += files('sgsoftwarerenderer.cpp')
4
5
6sw_dep = declare_dependency(
7 include_directories : include_directories('.'),
8 sources : source_file)
diff --git a/src/scenegraph/backend/software/sgsoftwaredrawable.cpp b/src/scenegraph/backend/software/sgsoftwaredrawable.cpp
deleted file mode 100644
index 747bd45..0000000
--- a/src/scenegraph/backend/software/sgsoftwaredrawable.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
1#include"sgsoftwaredrawable.h"
2#include"sgglobal.h"
3#include"sgmatrix.h"
4#include"sgsoftwarerectnode.h"
5
6SGSoftwareDrawable::SGSoftwareDrawable(NodeType type, SGNode *node)
7 : m_nodeType(type)
8 , m_isOpaque(true)
9 , m_isDirty(true)
10 , m_hasClipRegion(false)
11 , m_opacity(1.0f)
12{
13 switch (m_nodeType) {
14 case SGSoftwareDrawable::NodeType::Rect:
15 m_handle.rectNode = static_cast<SGSoftwareRectNode*>(node);
16 break;
17 default:
18 break;
19 }
20}
21
22SGSoftwareDrawable::~SGSoftwareDrawable()
23{
24
25}
26
27bool SGSoftwareDrawable::isDirtyRegionEmpty() const
28{
29 return m_dirtyRegion.isEmpty();
30}
31
32void SGSoftwareDrawable::setTransform(const SGMatrix &transform)
33{
34 if (m_transform == transform)
35 return;
36 m_transform = transform;
37 update();
38}
39
40void SGSoftwareDrawable::setClipRegion(const SGRegion &clipRect, bool hasClipRegion)
41{
42 if (m_clipRegion == clipRect && m_hasClipRegion == hasClipRegion)
43 return;
44
45 m_clipRegion = clipRect;
46 m_hasClipRegion = hasClipRegion;
47 update();
48}
49
50void SGSoftwareDrawable::setOpacity(float opacity)
51{
52 if (sgCompare(m_opacity, opacity))
53 return;
54
55 m_opacity = opacity;
56 update();
57}
58
59
60void SGSoftwareDrawable::addDirtyRegion(const SGRegion &dirtyRegion, bool forceDirty)
61{
62 // Check if the dirty region applies to this node
63 if (dirtyRegion.intersects(m_boundingRect)) {
64 if (forceDirty)
65 m_isDirty = true;
66 m_dirtyRegion += dirtyRegion.intersected(m_boundingRect);
67 }
68}
69
70void SGSoftwareDrawable::subtractDirtyRegion(const SGRegion &dirtyRegion)
71{
72 if (m_isDirty) {
73 // Check if this rect concerns us
74 if (dirtyRegion.intersects(m_boundingRect)) {
75 m_dirtyRegion -= dirtyRegion;
76 if (m_dirtyRegion.isEmpty())
77 m_isDirty = false;
78 }
79 }
80}
81
82SGRegion SGSoftwareDrawable::previousDirtyRegion(bool wasRemoved) const
83{
84 // When removing a node, the boundingRect shouldn't be subtracted
85 // because a deleted node has no valid boundingRect
86 if (wasRemoved)
87 return m_previousDirtyRegion;
88
89 return m_previousDirtyRegion.subtracted(SGRegion(m_boundingRect));
90}
91
92SGRegion SGSoftwareDrawable::dirtyRegion() const
93{
94 return m_dirtyRegion;
95}
96
97void SGSoftwareDrawable::update()
98{
99 // Update the Node properties
100 m_isDirty = true;
101
102 SGRect boundingRect;
103
104 switch (m_nodeType) {
105 case SGSoftwareDrawable::NodeType::Rect:
106// if (m_handle.simpleRectNode->color().alpha() == 255 && !m_transform.isRotating())
107// m_isOpaque = true;
108// else
109// m_isOpaque = false;
110
111// boundingRect = m_handle.simpleRectNode->rect();
112 break;
113 default:
114 break;
115 }
116
117 const SGRect transformedRect = m_transform.map(boundingRect);
118 //m_boundingRect = toRectMax(transformedRect);
119
120 if (m_hasClipRegion && m_clipRegion.rectCount() <= 1) {
121 // If there is a clipRegion, and it is empty, the item wont be rendered
122 if (m_clipRegion.isEmpty()) {
123 m_boundingRect = SGRect();
124 } else {
125// m_boundingRectMin = m_boundingRectMin.intersected(m_clipRegion.rects().constFirst());
126// m_boundingRectMax = m_boundingRectMax.intersected(m_clipRegion.rects().constFirst());
127 }
128 }
129
130 // Overrides
131 if (m_opacity < 1.0f)
132 m_isOpaque = false;
133
134 m_dirtyRegion = SGRegion(m_boundingRect);
135}
diff --git a/src/scenegraph/backend/software/sgsoftwaredrawable.h b/src/scenegraph/backend/software/sgsoftwaredrawable.h
deleted file mode 100644
index 9aee57b..0000000
--- a/src/scenegraph/backend/software/sgsoftwaredrawable.h
+++ /dev/null
@@ -1,68 +0,0 @@
1#ifndef SGSOFTWAREDRAWABLE_H
2#define SGSOFTWAREDRAWABLE_H
3
4#include"sgnode.h"
5
6class SGRectNode;
7
8class SGSoftwareDrawable
9{
10public:
11 enum NodeType {
12 Invalid = -1,
13 Rect,
14 Shape
15 };
16
17 SGSoftwareDrawable(NodeType type, SGNode *node);
18 ~SGSoftwareDrawable();
19
20 void update();
21
22 //SGRegion renderNode(QPainter *painter, bool forceOpaquePainting = false);
23 SGRect boundingRectMin() const { return m_boundingRect; }
24 SGRect boundingRectMax() const { return m_boundingRect; }
25 NodeType type() const { return m_nodeType; }
26 bool isOpaque() const { return m_isOpaque; }
27 bool isDirty() const { return m_isDirty; }
28 bool isDirtyRegionEmpty() const;
29
30 void setTransform(const SGMatrix &transform);
31 void setClipRegion(const SGRegion &clipRegion, bool hasClipRegion = true);
32 void setOpacity(float opacity);
33 SGMatrix transform() const { return m_transform; }
34 SGRegion clipRegion() const { return m_clipRegion; }
35 float opacity() const { return m_opacity; }
36
37// void markGeometryDirty();
38// void markMaterialDirty();
39
40 void addDirtyRegion(const SGRegion &dirtyRegion, bool forceDirty = true);
41 void subtractDirtyRegion(const SGRegion &dirtyRegion);
42
43 SGRegion previousDirtyRegion(bool wasRemoved = false) const;
44 SGRegion dirtyRegion() const;
45
46private:
47 union RenderableNodeHandle {
48 SGRectNode *rectNode;
49 };
50
51 const NodeType m_nodeType;
52 RenderableNodeHandle m_handle;
53
54 bool m_isOpaque;
55
56 bool m_isDirty;
57 SGRegion m_dirtyRegion;
58 SGRegion m_previousDirtyRegion;
59
60 SGMatrix m_transform;
61 SGRegion m_clipRegion;
62 bool m_hasClipRegion;
63 float m_opacity;
64
65 SGRect m_boundingRect;
66};
67
68#endif //SGSOFTWAREDRAWABLE_H
diff --git a/src/scenegraph/backend/software/sgsoftwarenodeupdater.cpp b/src/scenegraph/backend/software/sgsoftwarenodeupdater.cpp
deleted file mode 100644
index 40dbbd3..0000000
--- a/src/scenegraph/backend/software/sgsoftwarenodeupdater.cpp
+++ /dev/null
@@ -1,134 +0,0 @@
1#include<sgrectnode.h>
2#include"sgsoftwarenodeupdater.h"
3#include"sgsoftwaredrawable.h"
4
5SGSoftwareNodeUpdater::SGSoftwareNodeUpdater(SGSoftwareRenderer *renderer)
6 : m_renderer(renderer)
7{
8 m_opacityState.push(1.0f);
9 // by default there is no clip
10 m_clipState.push(SGRegion());
11 m_hasClip = false;
12 m_transformState.push(SGMatrix());
13}
14SGSoftwareNodeUpdater::~SGSoftwareNodeUpdater()
15{
16
17}
18
19bool SGSoftwareNodeUpdater::visit(SGTransformNode *node)
20{
21 m_transformState.push(node->matrix() * m_transformState.top());
22 m_stateMap[node] = currentState(node);
23 return true;
24}
25
26void SGSoftwareNodeUpdater::endVisit(SGTransformNode *)
27{
28 m_transformState.pop();
29}
30
31bool SGSoftwareNodeUpdater::visit(SGClipNode *node)
32{
33 // Make sure to translate the clip rect into world coordinates
34 if (m_clipState.size() == 0 || m_clipState.top().isEmpty()) {
35 m_clipState.push(m_transformState.top().map(SGRegion(node->clipRect())));
36 m_hasClip = true;
37 } else {
38 const SGRegion transformedClipRect = m_transformState.top().map(SGRegion(node->clipRect()));
39 m_clipState.push(transformedClipRect.intersected(m_clipState.top()));
40 }
41 m_stateMap[node] = currentState(node);
42 return true;
43}
44
45void SGSoftwareNodeUpdater::endVisit(SGClipNode *)
46{
47 m_clipState.pop();
48 if (m_clipState.size() == 0 || m_clipState.top().isEmpty())
49 m_hasClip = false;
50}
51
52bool SGSoftwareNodeUpdater::visit(SGOpacityNode *node)
53{
54 m_opacityState.push(m_opacityState.top() * node->opacity());
55 m_stateMap[node] = currentState(node);
56 return true;
57}
58
59void SGSoftwareNodeUpdater::endVisit(SGOpacityNode *)
60{
61 m_opacityState.pop();
62}
63
64bool SGSoftwareNodeUpdater::visit(SGRootNode *node)
65{
66 m_stateMap[node] = currentState(node);
67 return true;
68}
69
70void SGSoftwareNodeUpdater::endVisit(SGRootNode *)
71{
72}
73
74bool SGSoftwareNodeUpdater::visit(SGGeometryNode *node)
75{
76 if (SGRectNode *rectNode = dynamic_cast<SGRectNode *>(node)) {
77 return updateRenderableNode(SGSoftwareDrawable::Rect, rectNode);
78 } else {
79 // We dont know, so skip
80 return false;
81 }
82}
83
84void SGSoftwareNodeUpdater::endVisit(SGGeometryNode *)
85{
86}
87
88void SGSoftwareNodeUpdater::updateNodes(SGNode *node, bool isNodeRemoved)
89{
90 m_opacityState = std::stack<float>();
91 m_clipState = std::stack<SGRegion>();
92 m_transformState = std::stack<SGMatrix>();
93
94 auto parentNode = node->parent();
95 // If the node was deleted, it will have no parent
96 // check if the state map has the previous parent
97 if ((!parentNode || isNodeRemoved ) && (m_stateMap.find(node) != m_stateMap.end()))
98 parentNode = m_stateMap[node].parent;
99
100 // If we find a parent, use its state for updating the new children
101 if (parentNode && (m_stateMap.find(parentNode) != m_stateMap.end())) {
102 auto state = m_stateMap[parentNode];
103 m_opacityState.push(state.opacity);
104 m_transformState.push(state.transform);
105 m_clipState.push(state.clip);
106 m_hasClip = state.hasClip;
107 } else {
108 // There is no parent, and no previous parent, so likely a root node
109 m_opacityState.push(1.0f);
110 m_transformState.push(SGMatrix());
111 m_clipState.push(SGRegion());
112 m_hasClip = false;
113 }
114
115 // If the node is being removed, then cleanup the state data
116 // Then just visit the children without visiting the now removed node
117 if (isNodeRemoved) {
118 m_stateMap.erase(node);
119 return;
120 }
121
122 node->accept(this);
123}
124
125SGSoftwareNodeUpdater::NodeState SGSoftwareNodeUpdater::currentState(SGNode *node) const
126{
127 NodeState state;
128 state.opacity = m_opacityState.top();
129 state.clip = m_clipState.top();
130 state.hasClip = m_hasClip;
131 state.transform = m_transformState.top();
132 state.parent = node->parent();
133 return state;
134}
diff --git a/src/scenegraph/backend/software/sgsoftwarenodeupdater.h b/src/scenegraph/backend/software/sgsoftwarenodeupdater.h
deleted file mode 100644
index f668fc5..0000000
--- a/src/scenegraph/backend/software/sgsoftwarenodeupdater.h
+++ /dev/null
@@ -1,76 +0,0 @@
1#ifndef SGSOFTWARENODEUPDATER_H
2#define SGSOFTWARENODEUPDATER_H
3
4#include"sgnode.h"
5#include "sgnodeupdater_p.h"
6#include"sgsoftwaredrawable.h"
7#include"sgsoftwarerenderer.h"
8
9#include<stack>
10#include<unordered_map>
11
12class SGSoftwareRenderer;
13
14class SGSoftwareNodeUpdater : public SGNodeUpdater
15{
16public:
17 SGSoftwareNodeUpdater(SGSoftwareRenderer *renderer);
18 virtual ~SGSoftwareNodeUpdater();
19
20 bool visit(SGTransformNode *);
21 void endVisit(SGTransformNode *);
22 bool visit(SGClipNode *);
23 void endVisit(SGClipNode *);
24 bool visit(SGGeometryNode *);
25 void endVisit(SGGeometryNode *);
26 bool visit(SGOpacityNode *);
27 void endVisit(SGOpacityNode *);
28 bool visit(SGRootNode *);
29 void endVisit(SGRootNode *) ;
30 void updateNodes(SGNode *node, bool isNodeRemoved = false);
31
32 struct NodeState {
33 float opacity;
34 SGRegion clip;
35 bool hasClip;
36 SGMatrix transform;
37 SGNode *parent;
38 };
39
40private:
41
42 NodeState currentState(SGNode *node) const;
43
44 template<class NODE>
45 bool updateRenderableNode(SGSoftwareDrawable::NodeType type, NODE *node);
46
47 SGSoftwareRenderer *m_renderer;
48 std::stack<float> m_opacityState;
49 std::stack<SGRegion> m_clipState;
50 bool m_hasClip;
51 std::stack<SGMatrix> m_transformState;
52 std::unordered_map<SGNode*,NodeState> m_stateMap;
53};
54
55template<class NODE>
56bool SGSoftwareNodeUpdater::updateRenderableNode(SGSoftwareDrawable::NodeType type, NODE *node)
57{
58 //Check if we already know about node
59 auto renderableNode = m_renderer->renderableNode(node);
60 if (renderableNode == nullptr) {
61 renderableNode = new SGSoftwareDrawable(type, node);
62 m_renderer->addNodeMapping(node, renderableNode);
63 }
64
65 //Update the node
66 renderableNode->setTransform(m_transformState.top());
67 renderableNode->setOpacity(m_opacityState.top());
68 renderableNode->setClipRegion(m_clipState.top(), m_hasClip);
69
70 renderableNode->update();
71 m_stateMap[node] = currentState(node);
72
73 return true;
74}
75
76#endif //SGSOFTWARENODEUPDATER_H
diff --git a/src/scenegraph/backend/software/sgsoftwarerectnode.cpp b/src/scenegraph/backend/software/sgsoftwarerectnode.cpp
deleted file mode 100644
index e69de29..0000000
--- a/src/scenegraph/backend/software/sgsoftwarerectnode.cpp
+++ /dev/null
diff --git a/src/scenegraph/backend/software/sgsoftwarerectnode.h b/src/scenegraph/backend/software/sgsoftwarerectnode.h
deleted file mode 100644
index efb64d5..0000000
--- a/src/scenegraph/backend/software/sgsoftwarerectnode.h
+++ /dev/null
@@ -1,12 +0,0 @@
1#ifndef SGSOFTWARERECTNODE_H
2#define SGSOFTWARERECTNODE_H
3#include"sgrectnode.h"
4
5class SGSoftwareRectNode : public SGRectNode
6{
7public:
8 SGSoftwareRectNode() {}
9};
10
11
12#endif //SGSOFTWARERECTNODE_H
diff --git a/src/scenegraph/backend/software/sgsoftwarerenderer.cpp b/src/scenegraph/backend/software/sgsoftwarerenderer.cpp
deleted file mode 100644
index d15f3cf..0000000
--- a/src/scenegraph/backend/software/sgsoftwarerenderer.cpp
+++ /dev/null
@@ -1,207 +0,0 @@
1#include"sgsoftwarerenderer.h"
2#include"sgsoftwarerectnode.h"
3#include"sgsoftwarenodeupdater.h"
4
5SGSoftwareRenderer::SGSoftwareRenderer(SGRenderContext *context)
6 : SGRenderer(context)
7 //, m_background(new SGSoftwareRectNode)
8 , m_nodeUpdater(new SGSoftwareNodeUpdater(this))
9{
10 // Setup special background node
11 auto backgroundRenderable = new SGSoftwareDrawable(SGSoftwareDrawable::Rect, m_background);
12 addNodeMapping(m_background, backgroundRenderable);
13}
14
15SGSoftwareRenderer::~SGSoftwareRenderer()
16{
17 // Cleanup RenderableNodes
18 delete m_background;
19
20 // clean the hash m_nodes;
21
22 delete m_nodeUpdater;
23}
24
25SGSoftwareDrawable *SGSoftwareRenderer::renderableNode(SGNode *node) const
26{
27 auto search = m_nodes.find(node);
28 if (search != m_nodes.end()) {
29 return search->second;
30 }
31 return nullptr;
32}
33
34void SGSoftwareRenderer::addNodeMapping(SGNode *node, SGSoftwareDrawable *renderableNode)
35{
36 m_nodes.insert({node, renderableNode});
37}
38
39void SGSoftwareRenderer::appendRenderableNode(SGSoftwareDrawable *node)
40{
41 m_renderableNodes.push_back(node);
42}
43
44SGRegion SGSoftwareRenderer::optimizeRenderList()
45{
46 // Iterate through the renderlist from front to back
47 // Objective is to update the dirty status and rects.
48 for (auto i = m_renderableNodes.rbegin(); i != m_renderableNodes.rend(); ++i) {
49 auto node = *i;
50 if (!m_dirtyRegion.isEmpty()) {
51 // See if the current dirty regions apply to the current node
52 node->addDirtyRegion(m_dirtyRegion, true);
53 }
54
55 if (!m_obscuredRegion.isEmpty()) {
56 // Don't try to paint things that are covered by opaque objects
57 node->subtractDirtyRegion(m_obscuredRegion);
58 }
59
60 // Keep up with obscured regions
61 if (node->isOpaque()) {
62 m_obscuredRegion += node->boundingRectMin();
63 }
64
65 if (node->isDirty()) {
66 // Don't paint things outside of the rendering area
67 if (!m_background->rect().contains(node->boundingRectMax(), /*proper*/ true)) {
68 // Some part(s) of node is(are) outside of the rendering area
69 SGRegion renderArea(m_background->rect());
70 SGRegion outsideRegions = node->dirtyRegion().subtracted(renderArea);
71 if (!outsideRegions.isEmpty())
72 node->subtractDirtyRegion(outsideRegions);
73 }
74
75 // Get the dirty region's to pass to the next nodes
76 if (node->isOpaque()) {
77 // if isOpaque, subtract node's dirty rect from m_dirtyRegion
78 m_dirtyRegion -= node->boundingRectMin();
79 } else {
80 // if isAlpha, add node's dirty rect to m_dirtyRegion
81 m_dirtyRegion += node->dirtyRegion();
82 }
83 // if previousDirtyRegion has content outside of boundingRect add to m_dirtyRegion
84 SGRegion prevDirty = node->previousDirtyRegion();
85 if (!prevDirty.isEmpty())
86 m_dirtyRegion += prevDirty;
87 }
88 }
89
90 // Empty dirtyRegion (for second pass)
91 m_dirtyRegion = SGRegion();
92 m_obscuredRegion = SGRegion();
93
94 // Iterate through the renderlist from back to front
95 // Objective is to make sure all non-opaque items are painted when an item under them is dirty
96 for (auto j = m_renderableNodes.begin(); j != m_renderableNodes.end(); ++j) {
97 auto node = *j;
98
99 if (!node->isOpaque() && !m_dirtyRegion.isEmpty()) {
100 // Only blended nodes need to be updated
101 node->addDirtyRegion(m_dirtyRegion, true);
102 }
103
104 m_dirtyRegion += node->dirtyRegion();
105 }
106
107 SGRegion updateRegion = m_dirtyRegion;
108
109 // Empty dirtyRegion
110 m_dirtyRegion = SGRegion();
111 m_obscuredRegion = SGRegion();
112
113 return updateRegion;
114}
115
116void SGSoftwareRenderer::nodeChanged(SGNode *node, SGNode::DirtyFlag state)
117{
118 if (state & SGNode::DirtyState::Geometry) {
119 nodeGeometryUpdated(node);
120 }
121 if (state & SGNode::DirtyState::Material) {
122 nodeMaterialUpdated(node);
123 }
124 if (state & SGNode::DirtyState::Matrix) {
125 nodeMatrixUpdated(node);
126 }
127 if (state & SGNode::DirtyState::NodeAdded) {
128 nodeAdded(node);
129 }
130 if (state & SGNode::DirtyState::NodeRemoved) {
131 nodeRemoved(node);
132 }
133 if (state & SGNode::DirtyState::Opacity) {
134 nodeOpacityUpdated(node);
135 }
136 if (state & SGNode::DirtyState::SubtreeBlocked) {
137 m_nodeUpdater->updateNodes(node);
138 }
139 if (state & SGNode::DirtyState::ForceUpdate) {
140 m_nodeUpdater->updateNodes(node);
141 }
142 SGRenderer::nodeChanged(node, state);
143}
144
145void SGSoftwareRenderer::nodeAdded(SGNode *node)
146{
147 m_nodeUpdater->updateNodes(node);
148}
149
150void SGSoftwareRenderer::nodeRemoved(SGNode *node)
151{
152
153 auto renderable = renderableNode(node);
154 // remove mapping
155 if (renderable != nullptr) {
156 // Need to mark this region dirty in the other nodes
157 SGRegion dirtyRegion = renderable->previousDirtyRegion(true);
158 if (dirtyRegion.isEmpty())
159 dirtyRegion = renderable->boundingRectMax();
160 m_dirtyRegion += dirtyRegion;
161 m_nodes.erase(node);
162 delete renderable;
163 }
164
165 // Remove all children nodes as well
166 for (SGNode *child = node->firstChild(); child; child = child->nextSibling()) {
167 nodeRemoved(child);
168 }
169
170 m_nodeUpdater->updateNodes(node, true);
171}
172
173void SGSoftwareRenderer::nodeMatrixUpdated(SGNode *node)
174{
175 // Update children nodes
176 m_nodeUpdater->updateNodes(node);
177}
178
179void SGSoftwareRenderer::nodeOpacityUpdated(SGNode *node)
180{
181 // Update children nodes
182 m_nodeUpdater->updateNodes(node);
183}
184
185void SGSoftwareRenderer::nodeGeometryUpdated(SGNode *node)
186{
187
188 // Mark node as dirty
189 auto renderable = renderableNode(node);
190 if (renderable != nullptr) {
191 //renderable->markGeometryDirty();
192 } else {
193 m_nodeUpdater->updateNodes(node);
194 }
195}
196
197void SGSoftwareRenderer::nodeMaterialUpdated(SGNode *node)
198{
199 // Mark node as dirty
200 auto renderable = renderableNode(node);
201 if (renderable != nullptr) {
202 //renderable->markMaterialDirty();
203 } else {
204 m_nodeUpdater->updateNodes(node);
205 }
206}
207
diff --git a/src/scenegraph/backend/software/sgsoftwarerenderer.h b/src/scenegraph/backend/software/sgsoftwarerenderer.h
deleted file mode 100644
index 0174abb..0000000
--- a/src/scenegraph/backend/software/sgsoftwarerenderer.h
+++ /dev/null
@@ -1,50 +0,0 @@
1#ifndef SGSOFTWARERENDERER_H
2#define SGSOFTWARERENDERER_H
3
4#include"sgrenderer.h"
5#include<unordered_map>
6
7class SGSoftwareDrawable;
8class SGSoftwareNodeUpdater;
9class SGRectNode;
10
11class SG_EXPORT SGSoftwareRenderer : public SGRenderer
12{
13public:
14 SGSoftwareRenderer(SGRenderContext *context);
15 virtual ~SGSoftwareRenderer();
16
17 SGSoftwareDrawable *renderableNode(SGNode *node) const;
18 void addNodeMapping(SGNode *node, SGSoftwareDrawable *renderableNode);
19 void appendRenderableNode(SGSoftwareDrawable *node);
20
21 void nodeChanged(SGNode *node, SGNode::DirtyFlag flag) override;
22
23 void markDirty();
24
25 void buildRenderList();
26 SGRegion optimizeRenderList();
27
28 void setBackgroundColor(const SGColor &color);
29 SGColor backgroundColor();
30
31private:
32 void nodeAdded(SGNode *node);
33 void nodeRemoved(SGNode *node);
34 void nodeGeometryUpdated(SGNode *node);
35 void nodeMaterialUpdated(SGNode *node);
36 void nodeMatrixUpdated(SGNode *node);
37 void nodeOpacityUpdated(SGNode *node);
38
39 std::unordered_map<SGNode*, SGSoftwareDrawable*> m_nodes;
40 std::vector<SGSoftwareDrawable*> m_renderableNodes;
41
42 SGRectNode *m_background;
43
44 SGRegion m_dirtyRegion;
45 SGRegion m_obscuredRegion;
46
47 SGSoftwareNodeUpdater *m_nodeUpdater;
48};
49
50#endif //SGSOFTWARERENDERER_H
diff --git a/src/scenegraph/core/meson.build b/src/scenegraph/core/meson.build
deleted file mode 100644
index 8c0e62d..0000000
--- a/src/scenegraph/core/meson.build
+++ /dev/null
@@ -1,10 +0,0 @@
1source_file = files('sgnode.cpp')
2source_file += files('sgrenderer.cpp')
3source_file += files('sgnodeupdater.cpp')
4
5
6core_dep = declare_dependency(
7 include_directories : include_directories('.'),
8 sources : source_file)
9
10
diff --git a/src/scenegraph/core/sgcontext.cpp b/src/scenegraph/core/sgcontext.cpp
deleted file mode 100644
index 8b13789..0000000
--- a/src/scenegraph/core/sgcontext.cpp
+++ /dev/null
@@ -1 +0,0 @@
1
diff --git a/src/scenegraph/core/sgnode.cpp b/src/scenegraph/core/sgnode.cpp
deleted file mode 100644
index 628928b..0000000
--- a/src/scenegraph/core/sgnode.cpp
+++ /dev/null
@@ -1,383 +0,0 @@
1#include<sgnode.h>
2#include<sgrenderer.h>
3#include<cassert>
4#include"sgnodevisitor_p.h"
5
6SGNode::SGNode(NodeType type)
7 : m_parent(0)
8 , m_type(type)
9 , m_firstChild(0)
10 , m_lastChild(0)
11 , m_nextSibling(0)
12 , m_previousSibling(0)
13 , m_nodeFlags(Flag::OwnedByParent)
14{
15}
16SGNode::~SGNode()
17{
18 destroy();
19}
20
21bool SGNode::isSubtreeBlocked() const
22{
23 return false;
24}
25
26void SGNode::destroy()
27{
28 if (m_parent) {
29 m_parent->removeChildNode(this);
30 assert(m_parent == 0);
31 }
32 while (m_firstChild) {
33 SGNode *child = m_firstChild;
34 removeChildNode(child);
35 assert(child->m_parent == 0);
36 if (child->flags() & Flag::OwnedByParent)
37 delete child;
38 }
39
40 assert(m_firstChild == 0 && m_lastChild == 0);
41}
42
43void SGNode::prependChildNode(SGNode *node)
44{
45 assert(!node->m_parent && "SGNode::prependChildNode, SGNode already has a parent");
46
47 if (m_firstChild)
48 m_firstChild->m_previousSibling = node;
49 else
50 m_lastChild = node;
51 node->m_nextSibling = m_firstChild;
52 m_firstChild = node;
53 node->m_parent = this;
54
55 node->markDirty(DirtyState::NodeAdded);
56}
57
58void SGNode::appendChildNode(SGNode *node)
59{
60 assert(!node->m_parent && "SGNode::appendChildNode, SGNode already has a parent");
61
62 if (m_lastChild)
63 m_lastChild->m_nextSibling = node;
64 else
65 m_firstChild = node;
66 node->m_previousSibling = m_lastChild;
67 m_lastChild = node;
68 node->m_parent = this;
69
70 node->markDirty(DirtyState::NodeAdded);
71}
72
73void SGNode::insertChildNodeBefore(SGNode *node, SGNode *before)
74{
75 assert(!node->m_parent && "SGNode::appendChildNode, SGNode already has a parent");
76 assert(before && before->m_parent == this && "SGNode::insertChildNodeBefore, The parent of \'before\' is wrong");
77
78 SGNode *previous = before->m_previousSibling;
79 if (previous)
80 previous->m_nextSibling = node;
81 else
82 m_firstChild = node;
83 node->m_previousSibling = previous;
84 node->m_nextSibling = before;
85 before->m_previousSibling = node;
86 node->m_parent = this;
87
88 node->markDirty(DirtyState::NodeAdded);
89}
90
91void SGNode::insertChildNodeAfter(SGNode *node, SGNode *after)
92{
93 assert(!node->m_parent && "SGNode::appendChildNode, SGNode already has a parent");
94 assert(after && after->m_parent == this && "SGNode::insertChildNodeBefore, The parent of 'after' is wrong");
95
96 SGNode *next = after->m_nextSibling;
97 if (next)
98 next->m_previousSibling = node;
99 else
100 m_lastChild = node;
101 node->m_nextSibling = next;
102 node->m_previousSibling = after;
103 after->m_nextSibling = node;
104 node->m_parent = this;
105
106 node->markDirty(DirtyState::NodeAdded);
107}
108
109void SGNode::removeChildNode(SGNode *node)
110{
111 assert(node->parent() == this);
112
113 SGNode *previous = node->m_previousSibling;
114 SGNode *next = node->m_nextSibling;
115 if (previous)
116 previous->m_nextSibling = next;
117 else
118 m_firstChild = next;
119 if (next)
120 next->m_previousSibling = previous;
121 else
122 m_lastChild = previous;
123 node->m_previousSibling = 0;
124 node->m_nextSibling = 0;
125
126 node->markDirty(DirtyState::NodeRemoved);
127 node->m_parent = 0;
128}
129
130void SGNode::removeAllChildNodes()
131{
132 while (m_firstChild) {
133 SGNode *node = m_firstChild;
134 m_firstChild = node->m_nextSibling;
135 node->m_nextSibling = 0;
136 if (m_firstChild)
137 m_firstChild->m_previousSibling = 0;
138 else
139 m_lastChild = 0;
140 node->markDirty(DirtyState::NodeRemoved);
141 node->m_parent = 0;
142 }
143}
144
145void SGNode::reparentChildNodesTo(SGNode *newParent)
146{
147 for (SGNode *c = firstChild(); c; c = firstChild()) {
148 removeChildNode(c);
149 newParent->appendChildNode(c);
150 }
151}
152
153int SGNode::childCount() const
154{
155 int count = 0;
156 SGNode *n = m_firstChild;
157 while (n) {
158 ++count;
159 n = n->m_nextSibling;
160 }
161 return count;
162}
163
164
165SGNode *SGNode::childAtIndex(int i) const
166{
167 SGNode *n = m_firstChild;
168 while (i && n) {
169 --i;
170 n = n->m_nextSibling;
171 }
172 return n;
173}
174
175void SGNode::setFlag(NodeFlag f, bool enabled)
176{
177 if (bool(m_nodeFlags & f) == enabled)
178 return;
179 m_nodeFlags ^= f;
180 int changedFlag = f & Flag::UsePreprocess;
181 if (changedFlag)
182 markDirty(DirtyState::UsePreprocess);
183}
184
185void SGNode::setFlags(NodeFlag f, bool enabled)
186{
187 NodeFlag oldFlags = m_nodeFlags;
188 if (enabled)
189 m_nodeFlags |= f;
190 else
191 m_nodeFlags &= ~f;
192 int changedFlags = (oldFlags ^ m_nodeFlags) & Flag::UsePreprocess;
193 if (changedFlags)
194 markDirty(DirtyState::UsePreprocess);
195}
196
197void SGNode::markDirty(DirtyFlag bits)
198{
199 int renderableCountDiff = 0;
200 if (bits & DirtyState::NodeAdded)
201 renderableCountDiff += m_subtreeRenderableCount;
202 if (bits & DirtyState::NodeRemoved)
203 renderableCountDiff -= m_subtreeRenderableCount;
204
205 SGNode *p = m_parent;
206 while (p) {
207 p->m_subtreeRenderableCount += renderableCountDiff;
208 if (p->type() == NodeType::Root)
209 static_cast<SGRootNode *>(p)->notifyNodeChange(this, bits);
210 p = p->m_parent;
211 }
212}
213
214SGBasicGeometryNode::SGBasicGeometryNode(NodeType type)
215 : SGNode(type)
216 , m_geometry(0)
217 , m_matrix(0)
218 , m_clip_list(0)
219{
220}
221
222SGBasicGeometryNode::~SGBasicGeometryNode()
223{
224// if (flags() & Flag::OwnsGeometry)
225// delete m_geometry;
226}
227
228void SGBasicGeometryNode::setGeometry(SGGeometry *geometry)
229{
230// if ((flags() & Flag::OwnsGeometry) != 0 && m_geometry != geometry)
231// delete m_geometry;
232 m_geometry = geometry;
233 markDirty(DirtyState::Geometry);
234}
235
236
237SGGeometryNode::SGGeometryNode()
238 : SGBasicGeometryNode(NodeType::Geometry)
239 , m_render_order(0)
240 , m_opacity(1)
241{
242}
243
244SGGeometryNode::~SGGeometryNode()
245{
246}
247
248void SGGeometryNode::setRenderOrder(int order)
249{
250 m_render_order = order;
251}
252
253
254void SGGeometryNode::setInheritedOpacity(double opacity)
255{
256 m_opacity = opacity;
257}
258
259SGClipNode::SGClipNode()
260 : SGBasicGeometryNode(NodeType::Clip)
261 , m_is_rectangular(false)
262{
263}
264
265
266SGClipNode::~SGClipNode()
267{
268}
269
270
271
272
273void SGClipNode::setIsRectangular(bool rectHint)
274{
275 m_is_rectangular = rectHint;
276}
277
278void SGClipNode::setClipRect(const SGRect &rect)
279{
280 m_clip_rect = rect;
281}
282
283SGTransformNode::SGTransformNode()
284 : SGNode(NodeType::Transform)
285{
286}
287
288
289SGTransformNode::~SGTransformNode()
290{
291}
292
293void SGTransformNode::setMatrix(const SGMatrix &matrix)
294{
295 m_matrix = matrix;
296 markDirty(DirtyState::Matrix);
297}
298
299void SGTransformNode::setCombinedMatrix(const SGMatrix &matrix)
300{
301 m_combined_matrix = matrix;
302}
303
304SGRootNode::SGRootNode()
305 : SGNode(NodeType::Root)
306{
307}
308
309
310SGRootNode::~SGRootNode()
311{
312 while (!m_renderers.empty())
313 m_renderers.back()->setRootNode(nullptr);
314 destroy(); // Must call destroy() here because markDirty() casts this to SGRootNode.
315}
316
317void SGRootNode::notifyNodeChange(SGNode *node, DirtyFlag flag)
318{
319 for (uint i=0; i<m_renderers.size(); ++i) {
320 m_renderers.at(i)->nodeChanged(node, flag);
321 }
322}
323
324const double OPACITY_THRESHOLD = 0.001;
325
326SGOpacityNode::SGOpacityNode()
327 : SGNode(NodeType::Opacity)
328 , m_opacity(1)
329 , m_combined_opacity(1)
330{
331}
332
333
334SGOpacityNode::~SGOpacityNode()
335{
336}
337
338void SGOpacityNode::setOpacity(double opacity)
339{
340 //opacity = qBound<double>(0, opacity, 1);
341 if (m_opacity == opacity)
342 return;
343 DirtyFlag dirtyFlag = DirtyState::Opacity;
344
345 if ((m_opacity < OPACITY_THRESHOLD && opacity >= OPACITY_THRESHOLD) // blocked to unblocked
346 || (m_opacity >= OPACITY_THRESHOLD && opacity < OPACITY_THRESHOLD)) // unblocked to blocked
347 dirtyFlag |= DirtyState::SubtreeBlocked;
348
349 m_opacity = opacity;
350 markDirty(dirtyFlag);
351}
352
353
354void SGOpacityNode::setCombinedOpacity(double opacity)
355{
356 m_combined_opacity = opacity;
357}
358
359bool SGOpacityNode::isSubtreeBlocked() const
360{
361 return m_opacity < OPACITY_THRESHOLD;
362}
363
364void SGClipNode::accept(SGNodeVisitor *visitor)
365{if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this);}
366
367void SGTransformNode::accept(SGNodeVisitor *visitor)
368{if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this);}
369
370void SGOpacityNode::accept(SGNodeVisitor *visitor)
371{if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this);}
372
373void SGRootNode::accept(SGNodeVisitor *visitor)
374{if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this);}
375
376void SGGeometryNode::accept(SGNodeVisitor *visitor)
377{if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this);}
378
379
380
381
382
383
diff --git a/src/scenegraph/core/sgnodeupdater.cpp b/src/scenegraph/core/sgnodeupdater.cpp
deleted file mode 100644
index dfe3e24..0000000
--- a/src/scenegraph/core/sgnodeupdater.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
1#include"sgnodeupdater_p.h"
2
3SGNodeUpdater::SGNodeUpdater()
4{
5}
6
7SGNodeUpdater::~SGNodeUpdater()
8{
9}
10
11/*!
12 Returns true if \a node is has something that blocks it in the chain from
13 \a node to \a root doing a full state update pass.
14
15 This function does not process dirty states, simply does a simple traversion
16 up to the top.
17
18 The function assumes that \a root exists in the parent chain of \a node.
19 */
20
21bool SGNodeUpdater::isNodeBlocked(SGNode *node, SGNode *root) const
22{
23 while (node != root && node != 0) {
24 if (node->isSubtreeBlocked())
25 return true;
26 node = node->parent();
27 }
28 return false;
29}
30
31void SGNodeUpdater::updateStates(SGNode *n)
32{
33
34}
35
36bool SGNodeUpdater::visit(SGTransformNode *) { return true; }
37void SGNodeUpdater::endVisit(SGTransformNode *){}
38bool SGNodeUpdater::visit(SGClipNode *) { return true; }
39void SGNodeUpdater::endVisit(SGClipNode *){}
40bool SGNodeUpdater::visit(SGGeometryNode *) { return true; }
41void SGNodeUpdater::endVisit(SGGeometryNode *){}
42bool SGNodeUpdater::visit(SGOpacityNode *) { return true; }
43void SGNodeUpdater::endVisit(SGOpacityNode *){}
44bool SGNodeUpdater::visit(SGRootNode *) { return true; }
45void SGNodeUpdater::endVisit(SGRootNode *){}
46
47void SGNodeUpdater::visitChildren(SGNode *n)
48{
49 for (SGNode *c = n->firstChild(); c; c = c->nextSibling())
50 c->accept(this);
51}
52
53//void SGNodeUpdater::visitNode(SGNode *node)
54//{
55// switch (node->type()) {
56// case SGNode::NodeType::Clip: {
57// SGClipNode *c = static_cast<SGClipNode*>(node);
58// if (visit(c))
59// visitChildren(c);
60// endVisit(c);
61// break;
62// }
63// case SGNode::NodeType::Transform: {
64// SGTransformNode *c = static_cast<SGTransformNode*>(node);
65// if (visit(c))
66// visitChildren(c);
67// endVisit(c);
68// break;
69// }
70// case SGNode::NodeType::Opacity: {
71// SGOpacityNode *c = static_cast<SGOpacityNode*>(node);
72// if (visit(c))
73// visitChildren(c);
74// endVisit(c);
75// break;
76// }
77// case SGNode::NodeType::Geometry: {
78// if (node->flags() & SGNode::Flag::IsVisitableNode) {
79// node->accept(this);
80// } else {
81// SGGeometryNode *c = static_cast<SGGeometryNode*>(node);
82// if (visit(c))
83// visitChildren(c);
84// endVisit(c);
85// }
86// break;
87// }
88// case SGNode::NodeType::Root: {
89// SGRootNode *root = static_cast<SGRootNode*>(node);
90// if (visit(root))
91// visitChildren(root);
92// endVisit(root);
93// break;
94// }
95// default:
96// break;
97// }
98//}
diff --git a/src/scenegraph/core/sgrectnode.cpp b/src/scenegraph/core/sgrectnode.cpp
deleted file mode 100644
index e69de29..0000000
--- a/src/scenegraph/core/sgrectnode.cpp
+++ /dev/null
diff --git a/src/scenegraph/core/sgrenderer.cpp b/src/scenegraph/core/sgrenderer.cpp
deleted file mode 100644
index 06afc73..0000000
--- a/src/scenegraph/core/sgrenderer.cpp
+++ /dev/null
@@ -1,192 +0,0 @@
1#include"sgrenderer.h"
2#include"sgnodeupdater_p.h"
3#include<algorithm>
4#include<cassert>
5
6
7class SGRendererPrivate
8{
9 friend class SGRenderer;
10public:
11 SGRenderContext *m_context;
12 SGRootNode *m_root_node;
13
14 //QColor m_clear_color;
15 SGRenderer::ClearMode m_clear_mode;
16
17 uint m_mirrored : 1;
18
19 std::unordered_set<SGNode *> m_nodes_to_preprocess;
20 std::unordered_set<SGNode *> m_nodes_dont_preprocess;
21
22 SGNodeUpdater *m_node_updater;
23
24 double m_current_opacity;
25
26 bool m_changed_emitted;
27 bool m_is_rendering;
28 bool m_is_preprocessing;
29};
30
31SGRenderer::SGRenderer(SGRenderContext *context)
32{
33 d = new SGRendererPrivate();
34 d->m_current_opacity = 1,
35 d->m_changed_emitted = false;
36 d->m_is_preprocessing = false;
37 d->m_is_rendering = false;
38 d->m_context = context;
39 d->m_node_updater = new SGNodeUpdater();
40}
41
42SGRenderer::~SGRenderer()
43{
44 setRootNode(nullptr);
45 delete d;
46}
47
48
49/*!
50 Sets the \a node as the root of the SGNode scene
51 that you want to render. You need to provide a \a node
52 before trying to render the scene.
53
54 \note This doesn't take ownership of \a node.
55
56 \sa rootNode()
57*/
58void SGRenderer::setRootNode(SGRootNode *node)
59{
60 if (d->m_root_node == node)
61 return;
62 if (d->m_root_node) {
63 auto itr = find(d->m_root_node->m_renderers.begin(), d->m_root_node->m_renderers.end(), this);
64 if (itr != d->m_root_node->m_renderers.end())
65 d->m_root_node->m_renderers.erase(itr);
66 nodeChanged(d->m_root_node, SGNode::DirtyState::NodeRemoved);
67 }
68 d->m_root_node = node;
69 if (d->m_root_node) {
70 d->m_root_node->m_renderers.push_back(this);
71 nodeChanged(d->m_root_node, SGNode::DirtyState::NodeAdded);
72 }
73}
74
75/*!
76 Returns the root of the SGNode scene.
77
78 \sa setRootNode()
79*/
80SGRootNode *SGRenderer::rootNode() const
81{
82 return d->m_root_node;
83}
84
85SGNodeUpdater *SGRenderer::nodeUpdater() const
86{
87 return d->m_node_updater;
88}
89
90void SGRenderer::setNodeUpdater(SGNodeUpdater *updater)
91{
92 if (d->m_node_updater)
93 delete d->m_node_updater;
94 d->m_node_updater = updater;
95}
96
97
98/*!
99 Updates internal data structures and emits the sceneGraphChanged() signal.
100
101 If \a flags contains the SGNode::DirtyState::NodeRemoved flag, the node might be
102 in the process of being destroyed. It is then not safe to downcast the node
103 pointer.
104*/
105
106void SGRenderer::nodeChanged(SGNode *node, SGNode::DirtyFlag state)
107{
108 if (state & SGNode::DirtyState::NodeAdded)
109 addNodesToPreprocess(node);
110 if (state & SGNode::DirtyState::NodeRemoved)
111 removeNodesToPreprocess(node);
112 if (state & SGNode::DirtyState::UsePreprocess) {
113 if (node->flags() & SGNode::Flag::UsePreprocess)
114 d->m_nodes_to_preprocess.insert(node);
115 else
116 d->m_nodes_to_preprocess.erase(node);
117 }
118
119 if (!d->m_changed_emitted && !d->m_is_rendering) {
120 // Premature overoptimization to avoid excessive signal emissions
121 d->m_changed_emitted = true;
122 //sceneGraphChanged();
123 }
124}
125
126void SGRenderer::addNodesToPreprocess(SGNode *node)
127{
128 for (SGNode *c = node->firstChild(); c; c = c->nextSibling())
129 addNodesToPreprocess(c);
130 if (node->flags() & SGNode::Flag::UsePreprocess)
131 d->m_nodes_to_preprocess.insert(node);
132}
133
134void SGRenderer::removeNodesToPreprocess(SGNode *node)
135{
136 for (SGNode *c = node->firstChild(); c; c = c->nextSibling())
137 removeNodesToPreprocess(c);
138 if (node->flags() & SGNode::Flag::UsePreprocess) {
139 d->m_nodes_to_preprocess.erase(node);
140
141 // If preprocessing *now*, mark the node as gone.
142 if (d->m_is_preprocessing)
143 d->m_nodes_dont_preprocess.insert(node);
144 }
145}
146
147void SGRenderer::renderScene()
148{
149 if (!rootNode())
150 return;
151
152 d->m_is_rendering = true;
153
154 preprocess();
155
156 render();
157
158 d->m_is_rendering = false;
159 d->m_changed_emitted = false;
160
161}
162
163
164void SGRenderer::preprocess()
165{
166 d->m_is_preprocessing = true;
167
168 SGRootNode *root = rootNode();
169 assert(root);
170
171 // We need to take a copy here, in case any of the preprocess calls deletes a node that
172 // is in the preprocess list and thus, changes the m_nodes_to_preprocess behind our backs
173 // For the default case, when this does not happen, the cost is negligible.
174 std::unordered_set<SGNode *> items = d->m_nodes_to_preprocess;
175
176 for (auto n : items) {
177
178 // If we are currently preprocessing, check this node hasn't been
179 // deleted or something. we don't want a use-after-free!
180 if (d->m_nodes_dont_preprocess.find(n) != d->m_nodes_dont_preprocess.end()) // skip
181 continue;
182 if (!nodeUpdater()->isNodeBlocked(n, root)) {
183 n->preprocess();
184 }
185 }
186
187 nodeUpdater()->updateStates(root);
188
189 d->m_is_preprocessing = false;
190 d->m_nodes_dont_preprocess.clear();
191}
192
diff --git a/src/scenegraph/meson.build b/src/scenegraph/meson.build
deleted file mode 100644
index 0b03914..0000000
--- a/src/scenegraph/meson.build
+++ /dev/null
@@ -1,6 +0,0 @@
1
2subdir('core')
3subdir('backend')
4
5scenegraph_dep = [core_dep]
6scenegraph_dep += [sw_dep] \ No newline at end of file
diff --git a/src/text/meson.build b/src/text/meson.build
deleted file mode 100644
index a3fb9a2..0000000
--- a/src/text/meson.build
+++ /dev/null
@@ -1,5 +0,0 @@
1source_file = files('sgfontdatabase.cpp')
2
3text_dep = declare_dependency(
4 include_directories : include_directories('.'),
5 sources : source_file) \ No newline at end of file
diff --git a/src/text/sgfontdatabase.cpp b/src/text/sgfontdatabase.cpp
deleted file mode 100644
index c94e3b5..0000000
--- a/src/text/sgfontdatabase.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
1#include"sgfontdatabase.h"
2#include <pango/pangoft2.h>
3#include"vdebug.h"
4
5class SGFontDatabasePrivate
6{
7public:
8 SGFontDatabasePrivate();
9public:
10 PangoFontMap *m_fontmap;
11 SGFontDatabase::HintMode m_hinting;
12};
13
14static void
15substitute_func (FcPattern *pattern,
16 gpointer data )
17{
18 SGFontDatabasePrivate *p = (SGFontDatabasePrivate *) data;
19 if (p->m_hinting != SGFontDatabase::HintMode::Default)
20 {
21 FcPatternDel (pattern, FC_HINTING);
22 FcPatternAddBool (pattern, FC_HINTING, p->m_hinting != SGFontDatabase::HintMode::None);
23
24 FcPatternDel (pattern, FC_AUTOHINT);
25 FcPatternAddBool (pattern, FC_AUTOHINT, p->m_hinting == SGFontDatabase::HintMode::Auto);
26 }
27}
28
29SGFontDatabasePrivate::SGFontDatabasePrivate():m_hinting(SGFontDatabase::HintMode::Auto)
30{
31 m_fontmap = pango_ft2_font_map_new();
32 pango_ft2_font_map_set_resolution (PANGO_FT2_FONT_MAP (m_fontmap), 1, 1);
33 pango_ft2_font_map_set_default_substitute (PANGO_FT2_FONT_MAP (m_fontmap), substitute_func, this, NULL);
34}
35
36void SGFontDatabase::print() const
37{
38 PangoFontFamily** families = NULL;
39 int nb;
40
41 pango_font_map_list_families(d->m_fontmap, &families, &nb);
42
43}
44
45SGFontDatabase::~SGFontDatabase()
46{
47}
48
49
50SGFontDatabase::SGFontDatabase()
51{
52 d = new SGFontDatabasePrivate;
53}