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_H_
18 #define _TVG_RENDER_H_
25 //TODO: Union for multiple types
31 enum RenderUpdateFlag {None = 0, Path = 1, Color = 2, Gradient = 4, Stroke = 8, Transform = 16, All = 32};
33 struct RenderTransform
35 Matrix m; //3x3 Matrix Elements
38 float degree = 0.0f; //rotation degree
39 float scale = 1.0f; //scale factor
40 bool overriding = false; //user transform?
43 void override(const Matrix& m);
46 RenderTransform(const RenderTransform* lhs, const RenderTransform* rhs);
53 virtual ~RenderMethod() {}
54 virtual void* prepare(const Shape& shape, void* data, const RenderTransform* transform, RenderUpdateFlag flags) { return nullptr; }
55 virtual bool dispose(const Shape& shape, void *data) { return false; }
56 virtual bool preRender() { return false; }
57 virtual bool render(const Shape& shape, void *data) { return false; }
58 virtual bool postRender() { return false; }
59 virtual bool clear() { return false; }
60 virtual bool flush() { return false; }
61 virtual uint32_t ref() { return 0; }
62 virtual uint32_t unref() { return 0; }
65 struct RenderInitializer
67 RenderMethod* pInst = nullptr;
69 bool initialized = false;
71 static bool init(RenderInitializer& renderInit, RenderMethod* engine)
74 if (renderInit.pInst || renderInit.refCnt > 0) return false;
75 renderInit.pInst = engine;
76 renderInit.refCnt = 0;
77 renderInit.initialized = true;
81 static bool term(RenderInitializer& renderInit)
83 if (!renderInit.pInst || !renderInit.initialized) return false;
85 renderInit.initialized = false;
87 //Still it's refered....
88 if (renderInit.refCnt > 0) return true;
89 delete(renderInit.pInst);
90 renderInit.pInst = nullptr;
95 static uint32_t unref(RenderInitializer& renderInit)
97 assert(renderInit.refCnt > 0);
100 //engine has been requested to termination
101 if (!renderInit.initialized && renderInit.refCnt == 0) {
102 if (renderInit.pInst) {
103 delete(renderInit.pInst);
104 renderInit.pInst = nullptr;
107 return renderInit.refCnt;
110 static RenderMethod* inst(RenderInitializer& renderInit)
112 assert(renderInit.pInst);
113 return renderInit.pInst;
116 static uint32_t ref(RenderInitializer& renderInit)
118 return ++renderInit.refCnt;
125 #endif //_TVG_RENDER_H_