sw_engine: concrete shape rendering sequence.
[platform/core/graphics/tizenvg.git] / src / lib / sw_engine / tvgSwCommon.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *               http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  */
17 #ifndef _TVG_SW_COMMON_H_
18 #define _TVG_SW_COMMON_H_
19
20 #include "tvgCommon.h"
21
22 using namespace tvg;
23
24 constexpr auto SW_CURVE_TAG_ON = 1;
25 constexpr auto SW_CURVE_TAG_CUBIC = 2;
26 constexpr auto SW_OUTLINE_FILL_WINDING = 0;
27 constexpr auto SW_OUTLINE_FILL_EVEN_ODD = 1;
28
29 using SwCoord = signed long;
30
31 struct SwPoint
32 {
33     SwCoord x, y;
34
35     SwPoint operator+(const SwPoint& rhs) const {
36         return {x + rhs.x, y + rhs.y};
37     }
38
39     SwPoint operator-(const SwPoint& rhs) const {
40         return {x - rhs.x, y - rhs.y};
41     }
42
43     bool operator==(const SwPoint& rhs ) const {
44         return (x == rhs.x && y == rhs.y);
45     }
46
47     bool operator!=(const SwPoint& rhs) const {
48         return (x != rhs.x || y != rhs.y);
49     }
50 };
51
52 struct SwOutline
53 {
54     size_t*     cntrs;            //the contour end points
55     size_t      cntrsCnt;         //number of contours in glyph
56     size_t      reservedCntrsCnt;
57     SwPoint*    pts;              //the outline's points
58     size_t      ptsCnt;           //number of points in the glyph
59     size_t      reservedPtsCnt;
60     char*       tags;             //the points flags
61     uint8_t     fillMode;         //outline fill mode
62 };
63
64 struct SwSpan
65 {
66     uint16_t x, y;
67     uint16_t len;
68     uint8_t coverage;
69 };
70
71 struct SwRleData
72 {
73     SwSpan *spans;
74     size_t alloc;
75     size_t size;
76 };
77
78 struct SwBBox
79 {
80     SwPoint min, max;
81 };
82
83 struct SwShape
84 {
85     SwOutline*   outline;
86     SwRleData*   rle;
87     SwBBox       bbox;
88 };
89
90 void shapeReset(SwShape& sdata);
91 bool shapeGenOutline(const ShapeNode& shape, SwShape& sdata);
92 void shapeDelOutline(const ShapeNode& shape, SwShape& sdata);
93 bool shapeGenRle(const ShapeNode& shape, SwShape& sdata);
94 bool shapeTransformOutline(const ShapeNode& shape, SwShape& sdata);
95
96 SwRleData* rleRender(const SwShape& sdata);
97
98 bool rasterShape(Surface& surface, SwShape& sdata, size_t color);
99
100 #endif /* _TVG_SW_COMMON_H_ */