sw_engine: concrete shape rendering sequence.
[platform/core/graphics/tizenvg.git] / src / lib / tvgSwCanvas.cpp
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_SWCANVAS_CPP_
18 #define _TVG_SWCANVAS_CPP_
19
20 #include "tvgCommon.h"
21 #include "tvgCanvasBase.h"
22 #include "tvgSwRenderer.h"
23
24
25 /************************************************************************/
26 /* Internal Class Implementation                                        */
27 /************************************************************************/
28
29 struct SwCanvas::Impl : CanvasBase
30 {
31     Impl() : CanvasBase(SwRenderer::inst()) {}
32 };
33
34
35 /************************************************************************/
36 /* External Class Implementation                                        */
37 /************************************************************************/
38
39 int SwCanvas::target(uint32_t* buffer, size_t stride, size_t height) noexcept
40 {
41     auto impl = pImpl.get();
42     assert(impl);
43
44     dynamic_cast<SwRenderer*>(impl->renderer)->target(buffer, stride, height);
45
46     return 0;
47 }
48
49
50 int SwCanvas::draw(bool async) noexcept
51 {
52     auto impl = pImpl.get();
53     assert(impl);
54     return impl->draw();
55 }
56
57
58 int SwCanvas::sync() noexcept
59 {
60     return 0;
61 }
62
63
64 int SwCanvas::push(unique_ptr<PaintNode> paint) noexcept
65 {
66     auto impl = pImpl.get();
67     assert(impl);
68
69     return impl->push(move(paint));
70 }
71
72
73 int SwCanvas::clear() noexcept
74 {
75     auto impl = pImpl.get();
76     assert(impl);
77     return impl->clear();
78 }
79
80
81 SwCanvas::SwCanvas() : pImpl(make_unique<Impl>())
82 {
83 }
84
85
86 SwCanvas::~SwCanvas()
87 {
88 }
89
90
91 unique_ptr<SwCanvas> SwCanvas::gen(uint32_t* buffer, size_t stride, size_t height) noexcept
92 {
93     auto canvas = unique_ptr<SwCanvas>(new SwCanvas);
94     assert(canvas);
95
96     int ret = canvas.get()->target(buffer, stride, height);
97     if (ret > 0)  return nullptr;
98
99    return canvas;
100 }
101
102
103 int SwCanvas::update() noexcept
104 {
105     auto impl = pImpl.get();
106     assert(impl);
107     return impl->update();
108 }
109
110
111 RenderMethod* SwCanvas::engine() noexcept
112 {
113     auto impl = pImpl.get();
114     assert(impl);
115     return impl->renderer;
116 }
117
118 #endif /* _TVG_SWCANVAS_CPP_ */