1 /*
2 * Copyright (c) 2020 - 2024 the ThorVG project. 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
23 #include "../../lv_conf_internal.h"
24 #if LV_USE_THORVG_INTERNAL
25
26 #include "tvgSwCommon.h"
27
28
29 /************************************************************************/
30 /* Internal Class Implementation */
31 /************************************************************************/
32
33
34 /************************************************************************/
35 /* External Class Implementation */
36 /************************************************************************/
37
mpoolReqOutline(SwMpool * mpool,unsigned idx)38 SwOutline* mpoolReqOutline(SwMpool* mpool, unsigned idx)
39 {
40 return &mpool->outline[idx];
41 }
42
43
mpoolRetOutline(SwMpool * mpool,unsigned idx)44 void mpoolRetOutline(SwMpool* mpool, unsigned idx)
45 {
46 mpool->outline[idx].pts.clear();
47 mpool->outline[idx].cntrs.clear();
48 mpool->outline[idx].types.clear();
49 mpool->outline[idx].closed.clear();
50 }
51
52
mpoolReqStrokeOutline(SwMpool * mpool,unsigned idx)53 SwOutline* mpoolReqStrokeOutline(SwMpool* mpool, unsigned idx)
54 {
55 return &mpool->strokeOutline[idx];
56 }
57
58
mpoolRetStrokeOutline(SwMpool * mpool,unsigned idx)59 void mpoolRetStrokeOutline(SwMpool* mpool, unsigned idx)
60 {
61 mpool->strokeOutline[idx].pts.clear();
62 mpool->strokeOutline[idx].cntrs.clear();
63 mpool->strokeOutline[idx].types.clear();
64 mpool->strokeOutline[idx].closed.clear();
65 }
66
67
mpoolReqDashOutline(SwMpool * mpool,unsigned idx)68 SwOutline* mpoolReqDashOutline(SwMpool* mpool, unsigned idx)
69 {
70 return &mpool->dashOutline[idx];
71 }
72
73
mpoolRetDashOutline(SwMpool * mpool,unsigned idx)74 void mpoolRetDashOutline(SwMpool* mpool, unsigned idx)
75 {
76 mpool->dashOutline[idx].pts.clear();
77 mpool->dashOutline[idx].cntrs.clear();
78 mpool->dashOutline[idx].types.clear();
79 mpool->dashOutline[idx].closed.clear();
80 }
81
82
mpoolInit(uint32_t threads)83 SwMpool* mpoolInit(uint32_t threads)
84 {
85 auto allocSize = threads + 1;
86
87 auto mpool = static_cast<SwMpool*>(calloc(1, sizeof(SwMpool)));
88 mpool->outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * allocSize));
89 mpool->strokeOutline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * allocSize));
90 mpool->dashOutline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * allocSize));
91 mpool->allocSize = allocSize;
92
93 return mpool;
94 }
95
96
mpoolClear(SwMpool * mpool)97 bool mpoolClear(SwMpool* mpool)
98 {
99 for (unsigned i = 0; i < mpool->allocSize; ++i) {
100 mpool->outline[i].pts.reset();
101 mpool->outline[i].cntrs.reset();
102 mpool->outline[i].types.reset();
103 mpool->outline[i].closed.reset();
104
105 mpool->strokeOutline[i].pts.reset();
106 mpool->strokeOutline[i].cntrs.reset();
107 mpool->strokeOutline[i].types.reset();
108 mpool->strokeOutline[i].closed.reset();
109
110 mpool->dashOutline[i].pts.reset();
111 mpool->dashOutline[i].cntrs.reset();
112 mpool->dashOutline[i].types.reset();
113 mpool->dashOutline[i].closed.reset();
114 }
115
116 return true;
117 }
118
119
mpoolTerm(SwMpool * mpool)120 bool mpoolTerm(SwMpool* mpool)
121 {
122 if (!mpool) return false;
123
124 mpoolClear(mpool);
125
126 free(mpool->outline);
127 free(mpool->strokeOutline);
128 free(mpool->dashOutline);
129 free(mpool);
130
131 return true;
132 }
133
134 #endif /* LV_USE_THORVG_INTERNAL */
135
136