common: nothing was rendered after an empty masked node came across
[platform/core/graphics/tizenvg.git] / src / lib / tvgRender.h
1 /*
2  * Copyright (c) 2020-2021 Samsung Electronics Co., Ltd. All rights reserved.
3
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22 #ifndef _TVG_RENDER_H_
23 #define _TVG_RENDER_H_
24
25 #include "tvgCommon.h"
26 #include "tvgArray.h"
27
28 namespace tvg
29 {
30
31 enum RenderUpdateFlag {None = 0, Path = 1, Color = 2, Gradient = 4, Stroke = 8, Transform = 16, Image = 32, GradientStroke = 64, All = 127};
32
33 struct Surface
34 {
35     //TODO: Union for multiple types
36     uint32_t* buffer;
37     uint32_t  stride;
38     uint32_t  w, h;
39     uint32_t  cs;
40 };
41
42 using RenderData = void*;
43
44 struct Compositor
45 {
46     CompositeMethod method;
47     uint32_t        opacity;
48 };
49
50 struct RenderRegion
51 {
52     int32_t x, y, w, h;
53
54     void intersect(const RenderRegion& rhs)
55     {
56         auto x1 = x + w;
57         auto y1 = y + h;
58         auto x2 = rhs.x + rhs.w;
59         auto y2 = rhs.y + rhs.h;
60
61         x = (x > rhs.x) ? x : rhs.x;
62         y = (y > rhs.y) ? y : rhs.y;
63         w = ((x1 < x2) ? x1 : x2) - x;
64         h = ((y1 < y2) ? y1 : y2) - y;
65
66         if (w < 0) w = 0;
67         if (h < 0) h = 0;
68     }
69 };
70
71 struct RenderTransform
72 {
73     Matrix m;             //3x3 Matrix Elements
74     float x = 0.0f;
75     float y = 0.0f;
76     float degree = 0.0f;  //rotation degree
77     float scale = 1.0f;   //scale factor
78     bool overriding = false;  //user transform?
79
80     bool update();
81     void override(const Matrix& m);
82
83     RenderTransform();
84     RenderTransform(const RenderTransform* lhs, const RenderTransform* rhs);
85 };
86
87 class RenderMethod
88 {
89 public:
90     virtual ~RenderMethod() {}
91     virtual RenderData prepare(const Shape& shape, RenderData data, const RenderTransform* transform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag flags) = 0;
92     virtual RenderData prepare(const Picture& picture, RenderData data, const RenderTransform* transform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag flags) = 0;
93     virtual bool preRender() = 0;
94     virtual bool renderShape(RenderData data) = 0;
95     virtual bool renderImage(RenderData data) = 0;
96     virtual bool postRender() = 0;
97     virtual bool dispose(RenderData data) = 0;
98     virtual RenderRegion region(RenderData data) = 0;
99     virtual RenderRegion viewport() = 0;
100     virtual bool viewport(const RenderRegion& vp) = 0;
101
102     virtual bool clear() = 0;
103     virtual bool sync() = 0;
104
105     virtual Compositor* target(const RenderRegion& region) = 0;
106     virtual bool beginComposite(Compositor* cmp, CompositeMethod method, uint32_t opacity) = 0;
107     virtual bool endComposite(Compositor* cmp) = 0;
108 };
109
110 }
111
112 #endif //_TVG_RENDER_H_