2185c0f095e83b9828bfe368c3ca0d7b121be3d6
[platform/core/graphics/tizenvg.git] / src / lib / tvgInitializer.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. 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 #include "tvgCommon.h"
23 #include "tvgLoaderMgr.h"
24
25 #ifdef THORVG_SW_RASTER_SUPPORT
26     #include "tvgSwRenderer.h"
27 #endif
28
29 #ifdef THORVG_GL_RASTER_SUPPORT
30     #include "tvgGlRenderer.h"
31 #endif
32
33
34 /************************************************************************/
35 /* Internal Class Implementation                                        */
36 /************************************************************************/
37
38 static uint32_t threadCnt = 0;
39
40 /************************************************************************/
41 /* External Class Implementation                                        */
42 /************************************************************************/
43
44 Result Initializer::init(CanvasEngine engine) noexcept
45 {
46     auto nonSupport = true;
47
48     if (engine == CanvasEngine::Sw) {
49         #ifdef THORVG_SW_RASTER_SUPPORT
50             if (!SwRenderer::init()) return Result::InsufficientCondition;
51             nonSupport = false;
52         #endif
53     } else if (engine == CanvasEngine::Gl) {
54         #ifdef THORVG_GL_RASTER_SUPPORT
55             if (!GlRenderer::init()) return Result::InsufficientCondition;
56             nonSupport = false;
57         #endif
58     } else {
59         return Result::InvalidArguments;
60     }
61
62     if (nonSupport) return Result::NonSupport;
63
64     if (!LoaderMgr::init()) return Result::Unknown;
65
66     return Result::Success;
67 }
68
69
70 Result Initializer::term(CanvasEngine engine) noexcept
71 {
72     auto nonSupport = true;
73
74     if (engine == CanvasEngine::Sw) {
75         #ifdef THORVG_SW_RASTER_SUPPORT
76             if (!SwRenderer::term()) return Result::InsufficientCondition;
77             nonSupport = false;
78         #endif
79     } else if (engine == CanvasEngine::Gl) {
80         #ifdef THORVG_GL_RASTER_SUPPORT
81             if (!GlRenderer::term()) return Result::InsufficientCondition;
82             nonSupport = false;
83         #endif
84     } else {
85         return Result::InvalidArguments;
86     }
87
88     if (nonSupport) return Result::NonSupport;
89
90     if (!LoaderMgr::term()) return Result::Unknown;
91
92     return Result::Success;
93 }
94
95
96 Result Initializer::threads(uint32_t cnt) noexcept
97 {
98     threadCnt = cnt;
99
100     return Result::Success;
101 }
102
103
104 uint32_t Initializer::threads() noexcept
105 {
106     return threadCnt;
107 }