009312bce727a0b92db8745dc0dd5024d9b31fdc
[platform/core/uifw/dali-adaptor.git] / dali / internal / vector-animation / common / vector-animation-renderer-plugin-proxy.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/vector-animation/common/vector-animation-renderer-plugin-proxy.h>
20
21 // EXTERNAL INCLUDES
22 #include <dlfcn.h>
23 #include <dali/integration-api/debug.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 namespace Adaptor
32 {
33
34 namespace
35 {
36
37 // The default plugin name
38 const char* DEFAULT_OBJECT_NAME( "libdali-vector-animation-renderer-plugin.so" );
39
40 }
41
42 VectorAnimationRendererPluginProxy::VectorAnimationRendererPluginProxy( const std::string& sharedObjectName )
43 : mSharedObjectName(),
44   mLibHandle( NULL ),
45   mPlugin( NULL ),
46   mCreateVectorAnimationRendererPtr( NULL ),
47   mDefaultSignal()
48 {
49   if( !sharedObjectName.empty() )
50   {
51     mSharedObjectName = sharedObjectName;
52   }
53   else
54   {
55     mSharedObjectName = DEFAULT_OBJECT_NAME;
56   }
57
58   Initialize();
59 }
60
61 VectorAnimationRendererPluginProxy::~VectorAnimationRendererPluginProxy()
62 {
63   if( mPlugin )
64   {
65     delete mPlugin;
66     mPlugin = NULL;
67
68     if( mLibHandle && dlclose( mLibHandle ) )
69     {
70       DALI_LOG_ERROR( "Error closing vector animation renderer plugin library: %s\n", dlerror() );
71     }
72   }
73 }
74
75 void VectorAnimationRendererPluginProxy::Initialize()
76 {
77   mLibHandle = dlopen( mSharedObjectName.c_str(), RTLD_LAZY );
78
79   char* error = dlerror();
80   if( mLibHandle == NULL || error != NULL )
81   {
82     DALI_LOG_ERROR( "VectorAnimationRendererPluginProxy::Initialize: dlopen error [%s]\n", error );
83     return;
84   }
85
86   // load plugin
87   mCreateVectorAnimationRendererPtr = reinterpret_cast< CreateVectorAnimationRendererFunction >( dlsym( mLibHandle, "CreateVectorAnimationRendererPlugin" ) );
88
89   error = dlerror();
90   if( mCreateVectorAnimationRendererPtr == NULL || error != NULL )
91   {
92     DALI_LOG_ERROR( "VectorAnimationRendererPluginProxy::Initialize: Cannot load symbol: %s\n", error );
93     return;
94   }
95
96   mPlugin = mCreateVectorAnimationRendererPtr();
97   if( !mPlugin )
98   {
99     DALI_LOG_ERROR("VectorAnimationRendererPluginProxy::Initialize: Plugin creation failed\n");
100     return;
101   }
102 }
103
104 bool VectorAnimationRendererPluginProxy::Initialize( const std::string& url )
105 {
106   if( mPlugin )
107   {
108     return mPlugin->Initialize( url );
109   }
110   return false;
111 }
112
113 void VectorAnimationRendererPluginProxy::SetRenderer( Dali::Renderer renderer )
114 {
115   if( mPlugin )
116   {
117     mPlugin->SetRenderer( renderer );
118   }
119 }
120
121 void VectorAnimationRendererPluginProxy::SetSize( uint32_t width, uint32_t height )
122 {
123   if( mPlugin )
124   {
125     mPlugin->SetSize( width, height );
126   }
127 }
128
129 bool VectorAnimationRendererPluginProxy::Render( uint32_t frameNumber )
130 {
131   if( mPlugin )
132   {
133     return mPlugin->Render( frameNumber );
134   }
135   return false;
136 }
137
138 uint32_t VectorAnimationRendererPluginProxy::GetTotalFrameNumber() const
139 {
140   if( mPlugin )
141   {
142     return mPlugin->GetTotalFrameNumber();
143   }
144   return 0;
145 }
146
147 float VectorAnimationRendererPluginProxy::GetFrameRate() const
148 {
149   if( mPlugin )
150   {
151     return mPlugin->GetFrameRate();
152   }
153   return 0.0f;
154 }
155
156 void VectorAnimationRendererPluginProxy::GetDefaultSize( uint32_t& width, uint32_t& height ) const
157 {
158   if( mPlugin )
159   {
160     mPlugin->GetDefaultSize( width, height );
161   }
162 }
163
164 void VectorAnimationRendererPluginProxy::GetLayerInfo( Property::Map& map ) const
165 {
166   if( mPlugin )
167   {
168     mPlugin->GetLayerInfo( map );
169   }
170 }
171
172 VectorAnimationRendererPlugin::UploadCompletedSignalType& VectorAnimationRendererPluginProxy::UploadCompletedSignal()
173 {
174   if( mPlugin )
175   {
176     return mPlugin->UploadCompletedSignal();
177   }
178   return mDefaultSignal;
179 }
180
181 } // namespace Adaptor
182
183 } // namespace Internal
184
185 } // namespace Dali