2 * Copyright (c) 2020 - 2023 the ThorVG project. All rights reserved.
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:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
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
23 #include "tvgSwCommon.h"
26 /************************************************************************/
27 /* Internal Class Implementation */
28 /************************************************************************/
31 /************************************************************************/
32 /* External Class Implementation */
33 /************************************************************************/
35 SwOutline* mpoolReqOutline(SwMpool* mpool, unsigned idx)
37 return &mpool->outline[idx];
41 void mpoolRetOutline(SwMpool* mpool, unsigned idx)
43 mpool->outline[idx].cntrsCnt = 0;
44 mpool->outline[idx].ptsCnt = 0;
48 SwOutline* mpoolReqStrokeOutline(SwMpool* mpool, unsigned idx)
50 return &mpool->strokeOutline[idx];
54 void mpoolRetStrokeOutline(SwMpool* mpool, unsigned idx)
56 mpool->strokeOutline[idx].cntrsCnt = 0;
57 mpool->strokeOutline[idx].ptsCnt = 0;
61 SwMpool* mpoolInit(unsigned threads)
63 if (threads == 0) threads = 1;
65 auto mpool = static_cast<SwMpool*>(calloc(sizeof(SwMpool), 1));
66 mpool->outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * threads));
67 if (!mpool->outline) goto err;
69 mpool->strokeOutline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * threads));
70 if (!mpool->strokeOutline) goto err;
72 mpool->allocSize = threads;
79 mpool->outline = nullptr;
82 if (mpool->strokeOutline) {
83 free(mpool->strokeOutline);
84 mpool->strokeOutline = nullptr;
91 bool mpoolClear(SwMpool* mpool)
95 for (unsigned i = 0; i < mpool->allocSize; ++i) {
98 p = &mpool->outline[i];
112 p->cntrsCnt = p->reservedCntrsCnt = 0;
113 p->ptsCnt = p->reservedPtsCnt = 0;
116 p = &mpool->strokeOutline[i];
130 p->cntrsCnt = p->reservedCntrsCnt = 0;
131 p->ptsCnt = p->reservedPtsCnt = 0;
138 bool mpoolTerm(SwMpool* mpool)
140 if (!mpool) return false;
144 if (mpool->outline) {
145 free(mpool->outline);
146 mpool->outline = nullptr;
149 if (mpool->strokeOutline) {
150 free(mpool->strokeOutline);
151 mpool->strokeOutline = nullptr;