common taskscheduler: revise functionalities.
[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
39 /************************************************************************/
40 /* External Class Implementation                                        */
41 /************************************************************************/
42
43 Result Initializer::init(CanvasEngine engine, uint32_t threads) noexcept
44 {
45     auto nonSupport = true;
46
47     if (engine == CanvasEngine::Sw) {
48         #ifdef THORVG_SW_RASTER_SUPPORT
49             if (!SwRenderer::init()) return Result::InsufficientCondition;
50             nonSupport = false;
51         #endif
52     } else if (engine == CanvasEngine::Gl) {
53         #ifdef THORVG_GL_RASTER_SUPPORT
54             if (!GlRenderer::init()) return Result::InsufficientCondition;
55             nonSupport = false;
56         #endif
57     } else {
58         return Result::InvalidArguments;
59     }
60
61     if (nonSupport) return Result::NonSupport;
62
63     if (!LoaderMgr::init()) return Result::Unknown;
64
65     TaskScheduler::init(threads);
66
67     return Result::Success;
68 }
69
70
71 Result Initializer::term(CanvasEngine engine) noexcept
72 {
73     auto nonSupport = true;
74
75     if (engine == CanvasEngine::Sw) {
76         #ifdef THORVG_SW_RASTER_SUPPORT
77             if (!SwRenderer::term()) return Result::InsufficientCondition;
78             nonSupport = false;
79         #endif
80     } else if (engine == CanvasEngine::Gl) {
81         #ifdef THORVG_GL_RASTER_SUPPORT
82             if (!GlRenderer::term()) return Result::InsufficientCondition;
83             nonSupport = false;
84         #endif
85     } else {
86         return Result::InvalidArguments;
87     }
88
89     if (nonSupport) return Result::NonSupport;
90
91     TaskScheduler::term();
92
93     if (!LoaderMgr::term()) return Result::Unknown;
94
95     return Result::Success;
96 }