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/gradient-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::Gradient), typeid(Dali::BaseHandle), Create);
42 } // unnamed namespace
44 GradientTizen* GradientTizen::New()
46 return new GradientTizen();
49 GradientTizen::GradientTizen()
58 GradientTizen::~GradientTizen()
68 bool GradientTizen::SetColorStops(Dali::CanvasRenderer::Gradient::ColorStops& colorStops)
73 DALI_LOG_ERROR("Fill(Gradient) is null [%p]\n", this);
78 tvg::Fill::ColorStop* tvgColorStops = (tvg::Fill::ColorStop*)alloca(sizeof(tvg::Fill::ColorStop) * colorStops.Count());
80 for(unsigned int i = 0u; i < colorStops.Count(); ++i)
82 tvgColorStops[i].offset = colorStops[i].offset;
83 tvgColorStops[i].r = colorStops[i].color.r * 255.0f;
84 tvgColorStops[i].g = colorStops[i].color.g * 255.0f;
85 tvgColorStops[i].b = colorStops[i].color.b * 255.0f;
86 tvgColorStops[i].a = colorStops[i].color.a * 255.0f;
89 if(mTvgFill->colorStops(tvgColorStops, colorStops.Count()) != tvg::Result::Success)
91 DALI_LOG_ERROR("SetColorStops() fail.\n");
101 Dali::CanvasRenderer::Gradient::ColorStops GradientTizen::GetColorStops() const
103 #ifdef THORVG_SUPPORT
106 DALI_LOG_ERROR("Fill(Gradient) is null [%p]\n", this);
107 return Dali::CanvasRenderer::Gradient::ColorStops();
110 const tvg::Fill::ColorStop* tvgColorStops = nullptr;
113 count = mTvgFill->colorStops(&tvgColorStops);
114 if(!tvgColorStops || count <= 0)
116 DALI_LOG_ERROR("GetColorStops() fail.\n");
117 return Dali::CanvasRenderer::Gradient::ColorStops();
120 Dali::CanvasRenderer::Gradient::ColorStops colorStops;
122 colorStops.Reserve(count);
124 for(unsigned int i = 0u; i < count; ++i)
126 Dali::CanvasRenderer::Gradient::ColorStop stop = {tvgColorStops[i].offset, Vector4(tvgColorStops[i].r / 255.0f, tvgColorStops[i].g / 255.0f, tvgColorStops[i].b / 255.0f, tvgColorStops[i].a / 255.0f)};
128 colorStops.PushBack(stop);
132 return Dali::CanvasRenderer::Gradient::ColorStops();
136 bool GradientTizen::SetSpread(Dali::CanvasRenderer::Gradient::Spread spread)
138 #ifdef THORVG_SUPPORT
141 DALI_LOG_ERROR("Fill(Gradient) is null [%p]\n", this);
144 if(mTvgFill->spread(static_cast<tvg::FillSpread>(spread)) != tvg::Result::Success)
146 DALI_LOG_ERROR("SetSpread() fail.\n");
157 Dali::CanvasRenderer::Gradient::Spread GradientTizen::GetSpread() const
159 #ifdef THORVG_SUPPORT
162 DALI_LOG_ERROR("Fill(Gradient) is null [%p]\n", this);
163 return Dali::CanvasRenderer::Gradient::Spread::PAD;
166 tvg::FillSpread spread = mTvgFill->spread();
168 return static_cast<Dali::CanvasRenderer::Gradient::Spread>(spread);
170 return Dali::CanvasRenderer::Gradient::Spread::PAD;
174 void GradientTizen::SetObject(const void* object)
176 #ifdef THORVG_SUPPORT
179 mTvgFill = static_cast<tvg::Fill*>(const_cast<void*>(object));
184 void* GradientTizen::GetObject() const
186 #ifdef THORVG_SUPPORT
187 return static_cast<void*>(mTvgFill);
193 void GradientTizen::SetChanged(bool changed)
195 if(!mChanged && changed) Dali::Stage::GetCurrent().KeepRendering(0.0f);
196 mChanged = !!changed;
199 bool GradientTizen::GetChanged() const
203 } // namespace Adaptor
205 } // namespace Internal