common: fix compile warnings.
[platform/core/graphics/tizenvg.git] / src / lib / tvgRender.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *               http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 #ifndef _TVG_RENDER_H_
18 #define _TVG_RENDER_H_
19
20 namespace tvg
21 {
22
23 struct Surface
24 {
25     //TODO: Union for multiple types
26     uint32_t* buffer;
27     uint32_t stride;
28     uint32_t w, h;
29 };
30
31 enum RenderUpdateFlag {None = 0, Path = 1, Color = 2, Gradient = 4, Stroke = 8, Transform = 16, All = 32};
32
33 struct RenderTransform
34 {
35     Matrix m;             //3x3 Matrix Elements
36     float x = 0.0f;
37     float y = 0.0f;
38     float degree = 0.0f;  //rotation degree
39     float scale = 1.0f;   //scale factor
40     bool overriding = false;  //user transform?
41
42     bool update();
43     void override(const Matrix& m);
44
45     RenderTransform();
46     RenderTransform(const RenderTransform* lhs, const RenderTransform* rhs);
47 };
48
49
50 class RenderMethod
51 {
52 public:
53     virtual ~RenderMethod() {}
54     virtual void* prepare(TVG_UNUSED const Shape& shape, TVG_UNUSED void* data, TVG_UNUSED const RenderTransform* transform, TVG_UNUSED RenderUpdateFlag flags) { return nullptr; }
55     virtual bool dispose(TVG_UNUSED const Shape& shape, TVG_UNUSED void *data) { return false; }
56     virtual bool preRender() { return false; }
57     virtual bool render(TVG_UNUSED const Shape& shape, TVG_UNUSED 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; }
63 };
64
65 struct RenderInitializer
66 {
67     RenderMethod* pInst = nullptr;
68     uint32_t refCnt = 0;
69     bool initialized = false;
70
71     static bool init(RenderInitializer& renderInit, RenderMethod* engine)
72     {
73         assert(engine);
74         if (renderInit.pInst || renderInit.refCnt > 0) return false;
75         renderInit.pInst = engine;
76         renderInit.refCnt = 0;
77         renderInit.initialized = true;
78         return true;
79     }
80
81     static bool term(RenderInitializer& renderInit)
82     {
83         if (!renderInit.pInst || !renderInit.initialized) return false;
84
85         renderInit.initialized = false;
86
87         //Still it's refered....
88         if (renderInit.refCnt > 0) return  true;
89         delete(renderInit.pInst);
90         renderInit.pInst = nullptr;
91
92         return true;
93     }
94
95     static uint32_t unref(RenderInitializer& renderInit)
96     {
97         assert(renderInit.refCnt > 0);
98         --renderInit.refCnt;
99
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;
105             }
106         }
107         return renderInit.refCnt;
108     }
109
110     static RenderMethod* inst(RenderInitializer& renderInit)
111     {
112         assert(renderInit.pInst);
113         return renderInit.pInst;
114     }
115
116     static uint32_t ref(RenderInitializer& renderInit)
117     {
118         return ++renderInit.refCnt;
119     }
120
121 };
122
123 }
124
125 #endif //_TVG_RENDER_H_