2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/canvas-renderer/ubuntu/drawable-impl-ubuntu.h>
22 #include <dali/devel-api/common/stage.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/public-api/object/type-registry.h>
32 namespace // unnamed namespace
35 Dali::BaseHandle Create()
37 return Dali::BaseHandle();
40 Dali::TypeRegistration type(typeid(Dali::CanvasRenderer::Drawable), typeid(Dali::BaseHandle), Create);
42 } // unnamed namespace
44 DrawableUbuntu* DrawableUbuntu::New()
46 return new DrawableUbuntu();
49 DrawableUbuntu::DrawableUbuntu()
52 mType(Drawable::Types::NONE),
53 mCompositionType(Drawable::CompositionType::NONE),
54 mCompositionDrawable()
62 DrawableUbuntu::~DrawableUbuntu()
72 bool DrawableUbuntu::SetOpacity(float opacity)
77 DALI_LOG_ERROR("Drawable is null [%p]\n", this);
80 if(mTvgPaint->opacity(round(opacity * 255.f)) != tvg::Result::Success)
82 DALI_LOG_ERROR("Set opacity fail [%p]\n", this);
92 float DrawableUbuntu::GetOpacity() const
97 DALI_LOG_ERROR("Drawable is null [%p]\n", this);
100 return (float)mTvgPaint->opacity() / 255.f;
106 bool DrawableUbuntu::Rotate(Degree degree)
108 #ifdef THORVG_SUPPORT
111 DALI_LOG_ERROR("Drawable is null\n");
115 if(mTvgPaint->rotate(degree.degree) != tvg::Result::Success)
117 DALI_LOG_ERROR("Rotate fail.\n");
127 bool DrawableUbuntu::Scale(float factor)
129 #ifdef THORVG_SUPPORT
132 DALI_LOG_ERROR("Drawable is null\n");
136 if(mTvgPaint->scale(factor) != tvg::Result::Success)
138 DALI_LOG_ERROR("Scale fail.\n");
148 bool DrawableUbuntu::Translate(Vector2 translate)
150 #ifdef THORVG_SUPPORT
153 DALI_LOG_ERROR("Drawable is null\n");
157 if(mTvgPaint->translate(translate.x, translate.y) != tvg::Result::Success)
159 DALI_LOG_ERROR("Translate fail.\n");
169 bool DrawableUbuntu::Transform(const Dali::Matrix3& matrix)
171 #ifdef THORVG_SUPPORT
174 DALI_LOG_ERROR("Drawable is null\n");
178 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]};
180 if(mTvgPaint->transform(tvgMatrix) != tvg::Result::Success)
182 DALI_LOG_ERROR("Transform fail.\n");
192 Rect<float> DrawableUbuntu::GetBoundingBox() const
194 #ifdef THORVG_SUPPORT
197 DALI_LOG_ERROR("Drawable is null\n");
198 return Rect<float>(0, 0, 0, 0);
201 float x, y, width, height;
202 x = y = width = height = 0;
204 if(mTvgPaint->bounds(&x, &y, &width, &height) != tvg::Result::Success)
206 DALI_LOG_ERROR("Get bounds fail.\n");
207 return Rect<float>(0, 0, 0, 0);
209 return Rect<float>(x, y, width, height);
211 return Rect<float>(0, 0, 0, 0);
215 bool DrawableUbuntu::SetClipPath(Dali::CanvasRenderer::Drawable& clip)
217 #ifdef THORVG_SUPPORT
220 DALI_LOG_ERROR("Drawable is null\n");
224 Internal::Adaptor::Drawable& drawableImpl = Dali::GetImplementation(clip);
225 if(drawableImpl.IsAdded())
227 DALI_LOG_ERROR("Already used [%p][%p]\n", this, &clip);
231 drawableImpl.SetAdded(true);
232 mCompositionDrawable = clip;
233 mCompositionType = Drawable::CompositionType::CLIP_PATH;
234 Drawable::SetChanged(true);
242 bool DrawableUbuntu::SetMask(Dali::CanvasRenderer::Drawable& mask, Dali::CanvasRenderer::Drawable::MaskType type)
244 #ifdef THORVG_SUPPORT
247 DALI_LOG_ERROR("Drawable is null\n");
251 Internal::Adaptor::Drawable& drawableImpl = Dali::GetImplementation(mask);
252 if(drawableImpl.IsAdded())
254 DALI_LOG_ERROR("Already used [%p][%p]\n", this, &mask);
258 drawableImpl.SetAdded(true);
259 mCompositionDrawable = mask;
262 case Dali::CanvasRenderer::Drawable::MaskType::ALPHA:
264 mCompositionType = Drawable::CompositionType::ALPHA_MASK;
267 case Dali::CanvasRenderer::Drawable::MaskType::ALPHA_INVERSE:
269 mCompositionType = Drawable::CompositionType::ALPHA_MASK_INVERSE;
274 mCompositionType = Drawable::CompositionType::ALPHA_MASK;
278 Drawable::SetChanged(true);
286 Dali::CanvasRenderer::Drawable DrawableUbuntu::GetCompositionDrawable() const
288 return mCompositionDrawable;
291 Drawable::CompositionType DrawableUbuntu::GetCompositionType() const
293 return mCompositionType;
296 void DrawableUbuntu::SetAdded(bool added)
301 bool DrawableUbuntu::IsAdded() const
306 void* DrawableUbuntu::GetObject() const
308 #ifdef THORVG_SUPPORT
309 return static_cast<void*>(mTvgPaint);
315 void DrawableUbuntu::SetObject(const void* object)
317 #ifdef THORVG_SUPPORT
320 mTvgPaint = static_cast<tvg::Paint*>(const_cast<void*>(object));
325 void DrawableUbuntu::SetChanged(bool changed)
327 if(!mChanged && changed) Dali::Stage::GetCurrent().KeepRendering(0.0f);
328 mChanged = !!changed;
331 bool DrawableUbuntu::GetChanged() const
336 void DrawableUbuntu::SetType(Drawable::Types type)
341 Drawable::Types DrawableUbuntu::GetType() const
345 } // namespace Adaptor
347 } // namespace Internal