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/tizen/drawable-impl-tizen.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 DrawableTizen* DrawableTizen::New()
46 return new DrawableTizen();
49 DrawableTizen::DrawableTizen()
52 mType(Drawable::Types::NONE),
53 mCompositionType(Drawable::CompositionType::NONE),
54 mCompositionDrawable()
62 DrawableTizen::~DrawableTizen()
72 bool DrawableTizen::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 DrawableTizen::GetOpacity() const
97 DALI_LOG_ERROR("Drawable is null [%p]\n", this);
100 return (float)mTvgPaint->opacity() / 255.f;
106 bool DrawableTizen::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 DrawableTizen::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 DrawableTizen::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 DrawableTizen::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> DrawableTizen::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 DrawableTizen::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 Dali::CanvasRenderer::Drawable DrawableTizen::GetCompositionDrawable() const
244 return mCompositionDrawable;
247 Drawable::CompositionType DrawableTizen::GetCompositionType() const
249 return mCompositionType;
252 void DrawableTizen::SetAdded(bool added)
257 bool DrawableTizen::IsAdded() const
262 void* DrawableTizen::GetObject() const
264 #ifdef THORVG_SUPPORT
265 return static_cast<void*>(mTvgPaint);
271 void DrawableTizen::SetObject(const void* object)
273 #ifdef THORVG_SUPPORT
276 mTvgPaint = static_cast<tvg::Paint*>((void*)object);
281 void DrawableTizen::SetChanged(bool changed)
283 if(!mChanged && changed) Dali::Stage::GetCurrent().KeepRendering(0.0f);
284 mChanged = !!changed;
287 bool DrawableTizen::GetChanged() const
292 void DrawableTizen::SetType(Drawable::Types type)
297 Drawable::Types DrawableTizen::GetType() const
301 } // namespace Adaptor
303 } // namespace Internal