2a272c4a58d7219dba8a78c0b760950211eac682
[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::Finalize()
114 {
115   if( mPlugin )
116   {
117     mPlugin->Finalize();
118   }
119 }
120
121 void VectorAnimationRendererPluginProxy::SetRenderer( Dali::Renderer renderer )
122 {
123   if( mPlugin )
124   {
125     mPlugin->SetRenderer( renderer );
126   }
127 }
128
129 void VectorAnimationRendererPluginProxy::SetSize( uint32_t width, uint32_t height )
130 {
131   if( mPlugin )
132   {
133     mPlugin->SetSize( width, height );
134   }
135 }
136
137 bool VectorAnimationRendererPluginProxy::Render( uint32_t frameNumber )
138 {
139   if( mPlugin )
140   {
141     return mPlugin->Render( frameNumber );
142   }
143   return false;
144 }
145
146 uint32_t VectorAnimationRendererPluginProxy::GetTotalFrameNumber() const
147 {
148   if( mPlugin )
149   {
150     return mPlugin->GetTotalFrameNumber();
151   }
152   return 0;
153 }
154
155 float VectorAnimationRendererPluginProxy::GetFrameRate() const
156 {
157   if( mPlugin )
158   {
159     return mPlugin->GetFrameRate();
160   }
161   return 0.0f;
162 }
163
164 void VectorAnimationRendererPluginProxy::GetDefaultSize( uint32_t& width, uint32_t& height ) const
165 {
166   if( mPlugin )
167   {
168     mPlugin->GetDefaultSize( width, height );
169   }
170 }
171
172 void VectorAnimationRendererPluginProxy::GetLayerInfo( Property::Map& map ) const
173 {
174   if( mPlugin )
175   {
176     mPlugin->GetLayerInfo( map );
177   }
178 }
179
180 bool VectorAnimationRendererPluginProxy::GetMarkerInfo( const std::string& marker, uint32_t& startFrame, uint32_t& endFrame ) const
181 {
182   if( mPlugin )
183   {
184     return mPlugin->GetMarkerInfo( marker, startFrame, endFrame );
185   }
186   return false;
187 }
188
189 void VectorAnimationRendererPluginProxy::IgnoreRenderedFrame()
190 {
191   if( mPlugin )
192   {
193     mPlugin->IgnoreRenderedFrame();
194   }
195 }
196
197 VectorAnimationRendererPlugin::UploadCompletedSignalType& VectorAnimationRendererPluginProxy::UploadCompletedSignal()
198 {
199   if( mPlugin )
200   {
201     return mPlugin->UploadCompletedSignal();
202   }
203   return mDefaultSignal;
204 }
205
206 } // namespace Adaptor
207
208 } // namespace Internal
209
210 } // namespace Dali