implement sw engine basic sequence.
[platform/core/graphics/tizenvg.git] / src / lib / sw_engine / tvgSwShape.cpp
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_SHAPE_H_
18 #define _TVG_SW_SHAPE_H_
19
20 #include "tvgSwCommon.h"
21
22 static void growOutlineContour(SwShape *sdata, size_t n)
23 {
24     sdata->outline.cntrsCnt = n;
25
26     if (n == 0) {
27         free(sdata->outline.cntrs);
28         sdata->outline.cntrs = nullptr;
29         return;
30     }
31     sdata->outline.cntrs = static_cast<short *>(realloc(sdata->outline.cntrs, n * sizeof(short)));
32     assert(sdata->outline.cntrs);
33 }
34
35
36 static void growOutlinePoint(SwShape *sdata, size_t n)
37 {
38     sdata->outline.ptsCnt = n;
39
40     if (n == 0) {
41         free(sdata->outline.pts);
42         sdata->outline.pts = nullptr;
43         free(sdata->outline.tags);
44         sdata->outline.tags = nullptr;
45         return;
46     }
47
48     sdata->outline.pts = static_cast<SwVector *>(realloc(sdata->outline.pts, n * sizeof(SwVector)));
49     assert(sdata->outline.pts);
50     sdata->outline.tags = static_cast<char*>(realloc(sdata->outline.tags, n * sizeof(char)));
51     assert(sdata->outline.tags);
52 }
53
54
55 static void outlineEnd(SwShape* sdata)
56 {
57     //grow contour 1
58 }
59
60
61 static void outlineMoveTo(SwShape* sdata, const Point* pt)
62 {
63     //grow pts 1,
64     //grow contour 1
65 }
66
67
68 static void outlineLineTo(SwShape* sdata, const Point* pt)
69 {
70     //grow pts 1
71 }
72
73
74 static void outlineCubicTo(SwShape* sdata, const Point* ctrl1, const Point* ctrl2, const Point* pt)
75 {
76     //grow pts 3
77 }
78
79
80 static void outlineClose(SwShape* sdata)
81 {
82     //grow pts 1
83 }
84
85
86 bool shapeGenOutline(ShapeNode *shape, SwShape* sdata)
87 {
88     bool closed = false;
89
90     const PathCommand* cmds = nullptr;
91     auto cmdCnt = shape->pathCommands(&cmds);
92
93     const Point* pts = nullptr;
94     shape->pathCoords(&pts);
95
96     //reservation
97     auto outlinePtsCnt = 0;
98     auto outlineCntrsCnt = 0;
99
100     for (auto i = 0; i < cmdCnt; ++i) {
101         switch(*cmds) {
102             case PathCommand::Close: {
103                 ++outlinePtsCnt;
104                 break;
105             }
106             case PathCommand::MoveTo: {
107                 ++outlineCntrsCnt;
108                 ++outlinePtsCnt;
109                 break;
110             }
111             case PathCommand::LineTo: {
112                 ++outlinePtsCnt;
113                 break;
114             }
115             case PathCommand::CubicTo: {
116                 outlinePtsCnt += 3;
117                 break;
118             }
119         }
120     }
121
122     ++outlinePtsCnt;  //for close
123
124     growOutlinePoint(sdata, outlinePtsCnt);
125     growOutlineContour(sdata, outlineCntrsCnt);
126
127     //Generate Outlines
128     while (cmdCnt-- > 0) {
129         switch(*cmds) {
130             case PathCommand::Close: {
131                 outlineClose(sdata);
132                 break;
133             }
134             case PathCommand::MoveTo: {
135                 outlineMoveTo(sdata, pts);
136                 ++pts;
137                 break;
138             }
139             case PathCommand::LineTo: {
140                 outlineLineTo(sdata, pts);
141                 ++pts;
142                 break;
143             }
144             case PathCommand::CubicTo: {
145                 outlineCubicTo(sdata, pts, pts + 1, pts + 2);
146                 pts += 3;
147                 break;
148             }
149         }
150         ++cmds;
151     }
152
153     outlineEnd(sdata);
154
155     return closed;
156 }
157
158
159 #endif /* _TVG_SW_SHAPE_H_ */