1 /*
2  * Copyright (c) 2020 - 2024 the ThorVG project. All rights reserved.
3 
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10 
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13 
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22 
23 #include "../../lv_conf_internal.h"
24 #if LV_USE_THORVG_INTERNAL
25 
26 #include <cstdarg>
27 #include "tvgScene.h"
28 
29 /************************************************************************/
30 /* Internal Class Implementation                                        */
31 /************************************************************************/
32 
resetEffects()33 Result Scene::Impl::resetEffects()
34 {
35     if (effects) {
36         for (auto e = effects->begin(); e < effects->end(); ++e) {
37             delete(*e);
38         }
39         delete(effects);
40         effects = nullptr;
41     }
42     return Result::Success;
43 }
44 
45 
46 /************************************************************************/
47 /* External Class Implementation                                        */
48 /************************************************************************/
49 
Scene()50 Scene::Scene() : pImpl(new Impl(this))
51 {
52 }
53 
54 
~Scene()55 Scene::~Scene()
56 {
57     delete(pImpl);
58 }
59 
60 
gen()61 unique_ptr<Scene> Scene::gen() noexcept
62 {
63     return unique_ptr<Scene>(new Scene);
64 }
65 
66 
identifier()67 TVG_DEPRECATED uint32_t Scene::identifier() noexcept
68 {
69     return (uint32_t) Type::Scene;
70 }
71 
72 
type() const73 Type Scene::type() const noexcept
74 {
75     return Type::Scene;
76 }
77 
78 
push(unique_ptr<Paint> paint)79 Result Scene::push(unique_ptr<Paint> paint) noexcept
80 {
81     auto p = paint.release();
82     if (!p) return Result::MemoryCorruption;
83     PP(p)->ref();
84     pImpl->paints.push_back(p);
85 
86     return Result::Success;
87 }
88 
89 
reserve(TVG_UNUSED uint32_t size)90 Result Scene::reserve(TVG_UNUSED uint32_t size) noexcept
91 {
92     return Result::NonSupport;
93 }
94 
95 
clear(bool free)96 Result Scene::clear(bool free) noexcept
97 {
98     pImpl->clear(free);
99 
100     return Result::Success;
101 }
102 
103 
paints()104 list<Paint*>& Scene::paints() noexcept
105 {
106     return pImpl->paints;
107 }
108 
109 
push(SceneEffect effect,...)110 Result Scene::push(SceneEffect effect, ...) noexcept
111 {
112     if (effect == SceneEffect::ClearAll) return pImpl->resetEffects();
113 
114     if (!pImpl->effects) pImpl->effects = new Array<RenderEffect*>;
115 
116     va_list args;
117     va_start(args, effect);
118 
119     RenderEffect* re = nullptr;
120 
121     switch (effect) {
122         case SceneEffect::GaussianBlur: {
123             re = RenderEffectGaussian::gen(args);
124             break;
125         }
126         default: break;
127     }
128 
129     if (!re) return Result::InvalidArguments;
130 
131     pImpl->effects->push(re);
132 
133     return Result::Success;
134 }
135 
136 #endif /* LV_USE_THORVG_INTERNAL */
137 
138