2 * Copyright (c) 2020 - 2022 Samsung Electronics Co., Ltd. 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
22 #include "tvgCommon.h"
23 #include "tvgTaskScheduler.h"
24 #include "tvgLoader.h"
30 #ifdef THORVG_SW_RASTER_SUPPORT
31 #include "tvgSwRenderer.h"
34 #ifdef THORVG_GL_RASTER_SUPPORT
35 #include "tvgGlRenderer.h"
39 /************************************************************************/
40 /* Internal Class Implementation */
41 /************************************************************************/
43 static int _initCnt = 0;
44 static uint16_t _version = 0;
47 static bool _buildVersionInfo()
49 auto SRC = THORVG_VERSION_STRING; //ex) 0.3.99
56 memcpy(major, p, x - p);
63 memcpy(minor, p, x - p);
68 x = SRC + strlen(THORVG_VERSION_STRING);
69 memcpy(micro, p, x - p);
73 snprintf(sum, sizeof(sum), "%s%s%s", major, minor, micro);
81 /************************************************************************/
82 /* External Class Implementation */
83 /************************************************************************/
85 Result Initializer::init(CanvasEngine engine, uint32_t threads) noexcept
87 auto nonSupport = true;
89 if (static_cast<uint32_t>(engine) & static_cast<uint32_t>(CanvasEngine::Sw)) {
90 #ifdef THORVG_SW_RASTER_SUPPORT
91 if (!SwRenderer::init(threads)) return Result::FailedAllocation;
94 } else if (static_cast<uint32_t>(engine) & static_cast<uint32_t>(CanvasEngine::Gl)) {
95 #ifdef THORVG_GL_RASTER_SUPPORT
96 if (!GlRenderer::init(threads)) return Result::FailedAllocation;
100 return Result::InvalidArguments;
103 if (nonSupport) return Result::NonSupport;
105 if (_initCnt++ > 0) return Result::Success;
107 if (!_buildVersionInfo()) return Result::Unknown;
109 if (!LoaderMgr::init()) return Result::Unknown;
111 TaskScheduler::init(threads);
113 return Result::Success;
117 Result Initializer::term(CanvasEngine engine) noexcept
119 if (_initCnt == 0) return Result::InsufficientCondition;
121 auto nonSupport = true;
123 if (static_cast<uint32_t>(engine) & static_cast<uint32_t>(CanvasEngine::Sw)) {
124 #ifdef THORVG_SW_RASTER_SUPPORT
125 if (!SwRenderer::term()) return Result::InsufficientCondition;
128 } else if (static_cast<uint32_t>(engine) & static_cast<uint32_t>(CanvasEngine::Gl)) {
129 #ifdef THORVG_GL_RASTER_SUPPORT
130 if (!GlRenderer::term()) return Result::InsufficientCondition;
134 return Result::InvalidArguments;
137 if (nonSupport) return Result::NonSupport;
139 if (--_initCnt > 0) return Result::Success;
141 TaskScheduler::term();
143 if (!LoaderMgr::term()) return Result::Unknown;
145 return Result::Success;
149 uint16_t THORVG_VERSION_NUMBER()