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/vector-animation/common/vector-animation-renderer-plugin-proxy.h>
22 #include <dali/integration-api/debug.h>
33 // The default plugin name
34 const char* DEFAULT_OBJECT_NAME("libdali2-vector-animation-renderer-plugin.so");
35 // The rive animation plugin name
36 const char* RIVE_OBJECT_NAME("libdali2-rive-animation-renderer-plugin.so");
40 VectorAnimationRendererPluginProxy::VectorAnimationRendererPluginProxy(const std::string& sharedObjectName)
41 : mSharedObjectName(),
44 mCreateVectorAnimationRendererPtr(NULL),
47 if(!sharedObjectName.empty())
49 mSharedObjectName = sharedObjectName;
53 mSharedObjectName = DEFAULT_OBJECT_NAME;
57 VectorAnimationRendererPluginProxy::~VectorAnimationRendererPluginProxy()
64 if(mLibHandle && dlclose(mLibHandle))
66 DALI_LOG_ERROR("Error closing vector animation renderer plugin library: %s\n", dlerror());
71 void VectorAnimationRendererPluginProxy::Initialize(AnimationFormat format)
73 // initialization should be once
79 if(format == AnimationFormat::RIVE)
82 mSharedObjectName = RIVE_OBJECT_NAME;
87 mSharedObjectName = DEFAULT_OBJECT_NAME;
90 mLibHandle = dlopen(mSharedObjectName.c_str(), RTLD_LAZY);
92 char* error = dlerror();
93 if(mLibHandle == NULL || error != NULL)
95 DALI_LOG_ERROR("VectorAnimationRendererPluginProxy::Initialize: dlopen error [%s]\n", error);
100 mCreateVectorAnimationRendererPtr = reinterpret_cast<CreateVectorAnimationRendererFunction>(dlsym(mLibHandle, "CreateVectorAnimationRendererPlugin"));
103 if(mCreateVectorAnimationRendererPtr == NULL || error != NULL)
105 DALI_LOG_ERROR("VectorAnimationRendererPluginProxy::Initialize: Cannot load symbol: %s\n", error);
109 mPlugin = mCreateVectorAnimationRendererPtr();
112 DALI_LOG_ERROR("VectorAnimationRendererPluginProxy::Initialize: Plugin creation failed\n");
117 void VectorAnimationRendererPluginProxy::Finalize()
125 bool VectorAnimationRendererPluginProxy::Load(const std::string& url)
127 AnimationFormat format;
128 std::string extensionName = url.substr(url.find_last_of(".") + 1);
129 if(extensionName == "riv")
131 format = AnimationFormat::RIVE;
135 format = AnimationFormat::JSON;
142 return mPlugin->Load(url);
147 void VectorAnimationRendererPluginProxy::SetRenderer(Dali::Renderer renderer)
151 mPlugin->SetRenderer(renderer);
155 void VectorAnimationRendererPluginProxy::SetSize(uint32_t width, uint32_t height)
159 mPlugin->SetSize(width, height);
163 bool VectorAnimationRendererPluginProxy::Render(uint32_t frameNumber)
167 return mPlugin->Render(frameNumber);
172 uint32_t VectorAnimationRendererPluginProxy::GetTotalFrameNumber() const
176 return mPlugin->GetTotalFrameNumber();
181 float VectorAnimationRendererPluginProxy::GetFrameRate() const
185 return mPlugin->GetFrameRate();
190 void VectorAnimationRendererPluginProxy::GetDefaultSize(uint32_t& width, uint32_t& height) const
194 mPlugin->GetDefaultSize(width, height);
198 void VectorAnimationRendererPluginProxy::GetLayerInfo(Property::Map& map) const
202 mPlugin->GetLayerInfo(map);
206 bool VectorAnimationRendererPluginProxy::GetMarkerInfo(const std::string& marker, uint32_t& startFrame, uint32_t& endFrame) const
210 return mPlugin->GetMarkerInfo(marker, startFrame, endFrame);
215 void VectorAnimationRendererPluginProxy::IgnoreRenderedFrame()
219 mPlugin->IgnoreRenderedFrame();
223 VectorAnimationRendererPlugin::UploadCompletedSignalType& VectorAnimationRendererPluginProxy::UploadCompletedSignal()
227 return mPlugin->UploadCompletedSignal();
229 return mDefaultSignal;
232 } // namespace Adaptor
234 } // namespace Internal