common canvas: hide engine() interface
[platform/core/graphics/tizenvg.git] / src / lib / tvgCanvasImpl.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_CANVAS_IMPL_H_
18 #define _TVG_CANVAS_IMPL_H_
19
20 #include "tvgCommon.h"
21 #include "tvgShapeImpl.h"
22
23 /************************************************************************/
24 /* Internal Class Implementation                                        */
25 /************************************************************************/
26
27 struct Canvas::Impl
28 {
29     vector<Paint*> paints;
30     RenderMethod*  renderer;
31
32     Impl(RenderMethod* pRenderer):renderer(pRenderer)
33     {
34         renderer->ref();
35     }
36
37     ~Impl()
38     {
39         clear();
40         renderer->unref();
41     }
42
43     int push(unique_ptr<Paint> paint)
44     {
45         auto p = paint.release();
46         assert(p);
47         paints.push_back(p);
48
49         return update(p);
50     }
51
52     int clear()
53     {
54         assert(renderer);
55
56         for (auto paint : paints) {
57             if (auto scene = dynamic_cast<Scene*>(paint)) {
58                 cout << "TODO: " <<  scene << endl;
59             } else if (auto shape = dynamic_cast<Shape*>(paint)) {
60                 if (!shape->pImpl.get()->dispose(*shape, *renderer)) return -1;
61             }
62             delete(paint);
63         }
64         paints.clear();
65
66         return 0;
67     }
68
69     int update()
70     {
71         assert(renderer);
72
73         for(auto paint: paints) {
74             if (auto scene = dynamic_cast<Scene*>(paint)) {
75                 cout << "TODO: " <<  scene << endl;
76             } else if (auto shape = dynamic_cast<Shape*>(paint)) {
77                 if (!shape->pImpl.get()->update(*shape, *renderer)) return -1;
78             }
79         }
80         return 0;
81     }
82
83     int update(Paint* paint)
84     {
85         assert(renderer);
86
87         if (auto scene = dynamic_cast<Scene*>(paint)) {
88             cout << "TODO: " <<  scene << endl;
89         } else if (auto shape = dynamic_cast<Shape*>(paint)) {
90             if (!shape->pImpl.get()->update(*shape, *renderer)) return -1;
91         }
92         return 0;
93     }
94
95     int draw()
96     {
97         assert(renderer);
98
99         //Clear render target before drawing
100         if (!renderer->clear()) return -1;
101
102         for(auto paint: paints) {
103             if (auto scene = dynamic_cast<Scene*>(paint)) {
104                 cout << "TODO: " <<  scene << endl;
105             } else if (auto shape = dynamic_cast<Shape*>(paint)) {
106                 if(!shape->pImpl.get()->render(*shape, *renderer)) return -1;
107             }
108         }
109         return 0;
110     }
111 };
112
113 #endif /* _TVG_CANVAS_IMPL_H_ */