2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef _TVG_RENDER_COMMON_H_
18 #define _TVG_RENDER_COMMON_H_
25 //TODO: Union for multiple types
34 enum UpdateFlag { None = 0, Path = 1, Fill = 2, All = 3 };
35 virtual ~RenderMethod() {}
36 virtual void* prepare(const ShapeNode& shape, void* data, UpdateFlag flags) = 0;
37 virtual bool dispose(const ShapeNode& shape, void *data) = 0;
38 virtual bool render(const ShapeNode& shape, void *data) = 0;
39 virtual size_t ref() = 0;
40 virtual size_t unref() = 0;
43 struct RenderInitializer
45 RenderMethod* pInst = nullptr;
47 bool initialized = false;
49 static int init(RenderInitializer& renderInit, RenderMethod* engine)
52 if (renderInit.pInst || renderInit.refCnt > 0) return -1;
53 renderInit.pInst = engine;
54 renderInit.refCnt = 0;
55 renderInit.initialized = true;
59 static int term(RenderInitializer& renderInit)
61 if (!renderInit.pInst || !renderInit.initialized) return -1;
63 renderInit.initialized = false;
65 //Still it's refered....
66 if (renderInit.refCnt > 0) return 0;
67 delete(renderInit.pInst);
68 renderInit.pInst = nullptr;
73 static size_t unref(RenderInitializer& renderInit)
75 assert(renderInit.refCnt > 0);
78 //engine has been requested to termination
79 if (!renderInit.initialized && renderInit.refCnt == 0) {
80 if (renderInit.pInst) {
81 delete(renderInit.pInst);
82 renderInit.pInst = nullptr;
85 return renderInit.refCnt;
88 static RenderMethod* inst(RenderInitializer& renderInit)
90 assert(renderInit.pInst);
91 return renderInit.pInst;
94 static size_t ref(RenderInitializer& renderInit)
96 return ++renderInit.refCnt;
103 #endif //_TVG_RENDER_COMMON_H_