Merge "atspi: disable atspi using environment variable" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / canvas-renderer / tizen / drawable-impl-tizen.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
18 // CLASS HEADER
19 #include <dali/internal/canvas-renderer/tizen/drawable-impl-tizen.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/common/stage.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/public-api/object/type-registry.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 namespace Adaptor
31 {
32 namespace // unnamed namespace
33 {
34 // Type Registration
35 Dali::BaseHandle Create()
36 {
37   return Dali::BaseHandle();
38 }
39
40 Dali::TypeRegistration type(typeid(Dali::CanvasRenderer::Drawable), typeid(Dali::BaseHandle), Create);
41
42 } // unnamed namespace
43
44 DrawableTizen* DrawableTizen::New()
45 {
46   return new DrawableTizen();
47 }
48
49 DrawableTizen::DrawableTizen()
50 : mAdded(false),
51   mChanged(false)
52 #ifdef THORVG_SUPPORT
53   ,
54   mTvgPaint(nullptr)
55 #endif
56 {
57 }
58
59 DrawableTizen::~DrawableTizen()
60 {
61 #ifdef THORVG_SUPPORT
62   if(mTvgPaint && !mAdded)
63   {
64     delete mTvgPaint;
65   }
66 #endif
67 }
68
69 bool DrawableTizen::SetOpacity(float opacity)
70 {
71 #ifdef THORVG_SUPPORT
72   if(!mTvgPaint)
73   {
74     DALI_LOG_ERROR("Drawable is null [%p]\n", this);
75     return false;
76   }
77   if(mTvgPaint->opacity(round(opacity * 255.f)) != tvg::Result::Success)
78   {
79     DALI_LOG_ERROR("Set opacity fail [%p]\n", this);
80     return false;
81   }
82   SetChanged(true);
83   return true;
84 #else
85   return false;
86 #endif
87 }
88
89 float DrawableTizen::GetOpacity() const
90 {
91 #ifdef THORVG_SUPPORT
92   if(!mTvgPaint)
93   {
94     DALI_LOG_ERROR("Drawable is null [%p]\n", this);
95     return 0;
96   }
97   return (float)mTvgPaint->opacity() / 255.f;
98 #else
99   return 0;
100 #endif
101 }
102
103 bool DrawableTizen::Rotate(Degree degree)
104 {
105 #ifdef THORVG_SUPPORT
106   if(!mTvgPaint)
107   {
108     DALI_LOG_ERROR("Drawable is null\n");
109     return false;
110   }
111
112   if(mTvgPaint->rotate(degree.degree) != tvg::Result::Success)
113   {
114     DALI_LOG_ERROR("Rotate fail.\n");
115     return false;
116   }
117   SetChanged(true);
118   return true;
119 #else
120   return false;
121 #endif
122 }
123
124 bool DrawableTizen::Scale(float factor)
125 {
126 #ifdef THORVG_SUPPORT
127   if(!mTvgPaint)
128   {
129     DALI_LOG_ERROR("Drawable is null\n");
130     return false;
131   }
132
133   if(mTvgPaint->scale(factor) != tvg::Result::Success)
134   {
135     DALI_LOG_ERROR("Scale fail.\n");
136     return false;
137   }
138   SetChanged(true);
139   return true;
140 #else
141   return false;
142 #endif
143 }
144
145 bool DrawableTizen::Translate(Vector2 translate)
146 {
147 #ifdef THORVG_SUPPORT
148   if(!mTvgPaint)
149   {
150     DALI_LOG_ERROR("Drawable is null\n");
151     return false;
152   }
153
154   if(mTvgPaint->translate(translate.x, translate.y) != tvg::Result::Success)
155   {
156     DALI_LOG_ERROR("Translate fail.\n");
157     return false;
158   }
159   SetChanged(true);
160   return true;
161 #else
162   return false;
163 #endif
164 }
165
166 bool DrawableTizen::Transform(const Dali::Matrix3& matrix)
167 {
168 #ifdef THORVG_SUPPORT
169   if(!mTvgPaint)
170   {
171     DALI_LOG_ERROR("Drawable is null\n");
172     return false;
173   }
174
175   tvg::Matrix tvgMatrix = {matrix.AsFloat()[0], matrix.AsFloat()[1], matrix.AsFloat()[2], matrix.AsFloat()[3], matrix.AsFloat()[4], matrix.AsFloat()[5], matrix.AsFloat()[6], matrix.AsFloat()[7], matrix.AsFloat()[8]};
176
177   if(mTvgPaint->transform(tvgMatrix) != tvg::Result::Success)
178   {
179     DALI_LOG_ERROR("Transform fail.\n");
180     return false;
181   }
182   SetChanged(true);
183   return true;
184 #else
185   return false;
186 #endif
187 }
188
189 void DrawableTizen::SetDrawableAdded(bool added)
190 {
191   mAdded = !!added;
192 }
193
194 void* DrawableTizen::GetObject() const
195 {
196 #ifdef THORVG_SUPPORT
197   return static_cast<void*>(mTvgPaint);
198 #else
199   return nullptr;
200 #endif
201 }
202
203 void DrawableTizen::SetObject(const void* object)
204 {
205 #ifdef THORVG_SUPPORT
206   if(object)
207   {
208     mTvgPaint = static_cast<tvg::Paint*>((void*)object);
209   }
210   else
211   {
212     if(mAdded)
213     {
214       mTvgPaint = nullptr;
215     }
216     if(mTvgPaint)
217     {
218       delete mTvgPaint;
219     }
220   }
221 #endif
222 }
223
224 void DrawableTizen::SetChanged(bool changed)
225 {
226   if(!mChanged && changed) Dali::Stage::GetCurrent().KeepRendering(0.0f);
227   mChanged = !!changed;
228 }
229
230 bool DrawableTizen::GetChanged() const
231 {
232   return mChanged;
233 }
234 } // namespace Adaptor
235
236 } // namespace Internal
237
238 } // namespace Dali