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()
59 DrawableUbuntu::~DrawableUbuntu()
62 if(mTvgPaint && !mAdded)
69 bool DrawableUbuntu::SetOpacity(float opacity)
74 DALI_LOG_ERROR("Drawable is null [%p]\n", this);
77 if(mTvgPaint->opacity(round(opacity * 255.f)) != tvg::Result::Success)
79 DALI_LOG_ERROR("Set opacity fail [%p]\n", this);
89 float DrawableUbuntu::GetOpacity() const
94 DALI_LOG_ERROR("Drawable is null [%p]\n", this);
97 return (float)mTvgPaint->opacity() / 255.f;
103 bool DrawableUbuntu::Rotate(Degree degree)
105 #ifdef THORVG_SUPPORT
108 DALI_LOG_ERROR("Drawable is null\n");
112 if(mTvgPaint->rotate(degree.degree) != tvg::Result::Success)
114 DALI_LOG_ERROR("Rotate fail.\n");
124 bool DrawableUbuntu::Scale(float factor)
126 #ifdef THORVG_SUPPORT
129 DALI_LOG_ERROR("Drawable is null\n");
133 if(mTvgPaint->scale(factor) != tvg::Result::Success)
135 DALI_LOG_ERROR("Scale fail.\n");
145 bool DrawableUbuntu::Translate(Vector2 translate)
147 #ifdef THORVG_SUPPORT
150 DALI_LOG_ERROR("Drawable is null\n");
154 if(mTvgPaint->translate(translate.x, translate.y) != tvg::Result::Success)
156 DALI_LOG_ERROR("Translate fail.\n");
166 bool DrawableUbuntu::Transform(const Dali::Matrix3& matrix)
168 #ifdef THORVG_SUPPORT
171 DALI_LOG_ERROR("Drawable is null\n");
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]};
177 if(mTvgPaint->transform(tvgMatrix) != tvg::Result::Success)
179 DALI_LOG_ERROR("Transform fail.\n");
189 void DrawableUbuntu::SetDrawableAdded(bool added)
194 void* DrawableUbuntu::GetObject() const
196 #ifdef THORVG_SUPPORT
197 return static_cast<void*>(mTvgPaint);
203 void DrawableUbuntu::SetObject(const void* object)
205 #ifdef THORVG_SUPPORT
208 mTvgPaint = static_cast<tvg::Paint*>((void*)object);
211 DALI_LOG_ERROR("Drawable is invalid [%p]\n", this);
228 void DrawableUbuntu::SetChanged(bool changed)
230 if(!mChanged && changed) Dali::Stage::GetCurrent().KeepRendering(0.0f);
231 mChanged = !!changed;
234 bool DrawableUbuntu::GetChanged() const
238 } // namespace Adaptor
240 } // namespace Internal