2860f42019a7e71e929cfe56c5d999e5ecf65703
[platform/core/uifw/dali-adaptor.git] / dali / internal / vector-animation / common / vector-animation-renderer-plugin-proxy.cpp
1 /*
2  * Copyright (c) 2018 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 {
48   if( !sharedObjectName.empty() )
49   {
50     mSharedObjectName = sharedObjectName;
51   }
52   else
53   {
54     mSharedObjectName = DEFAULT_OBJECT_NAME;
55   }
56
57   Initialize();
58 }
59
60 VectorAnimationRendererPluginProxy::~VectorAnimationRendererPluginProxy()
61 {
62   if( mPlugin )
63   {
64     delete mPlugin;
65     mPlugin = NULL;
66
67     if( mLibHandle && dlclose( mLibHandle ) )
68     {
69       DALI_LOG_ERROR( "Error closing vector animation renderer plugin library: %s\n", dlerror() );
70     }
71   }
72 }
73
74 void VectorAnimationRendererPluginProxy::Initialize()
75 {
76   mLibHandle = dlopen( mSharedObjectName.c_str(), RTLD_LAZY );
77
78   char* error = dlerror();
79   if( mLibHandle == NULL || error != NULL )
80   {
81     DALI_LOG_ERROR( "VectorAnimationRendererPluginProxy::Initialize: dlopen error [%s]\n", error );
82     return;
83   }
84
85   // load plugin
86   mCreateVectorAnimationRendererPtr = reinterpret_cast< CreateVectorAnimationRendererFunction >( dlsym( mLibHandle, "CreateVectorAnimationRendererPlugin" ) );
87
88   error = dlerror();
89   if( mCreateVectorAnimationRendererPtr == NULL || error != NULL )
90   {
91     DALI_LOG_ERROR( "VectorAnimationRendererPluginProxy::Initialize: Cannot load symbol: %s\n", error );
92     return;
93   }
94
95   mPlugin = mCreateVectorAnimationRendererPtr();
96   if( !mPlugin )
97   {
98     DALI_LOG_ERROR("VectorAnimationRendererPluginProxy::Initialize: Plugin creation failed\n");
99     return;
100   }
101 }
102
103 void VectorAnimationRendererPluginProxy::SetUrl( const std::string& url )
104 {
105   if( mPlugin )
106   {
107     mPlugin->SetUrl( url );
108   }
109 }
110
111 void VectorAnimationRendererPluginProxy::SetRenderer( Dali::Renderer renderer )
112 {
113   if( mPlugin )
114   {
115     mPlugin->SetRenderer( renderer );
116   }
117 }
118
119 void VectorAnimationRendererPluginProxy::SetSize( uint32_t width, uint32_t height )
120 {
121   if( mPlugin )
122   {
123     mPlugin->SetSize( width, height );
124   }
125 }
126
127 bool VectorAnimationRendererPluginProxy::StartRender()
128 {
129   if( mPlugin )
130   {
131     return mPlugin->StartRender();
132   }
133   return false;
134 }
135
136 void VectorAnimationRendererPluginProxy::StopRender()
137 {
138   if( mPlugin )
139   {
140     mPlugin->StopRender();
141   }
142 }
143
144 void VectorAnimationRendererPluginProxy::Render( uint32_t frameNumber )
145 {
146   if( mPlugin )
147   {
148     mPlugin->Render( frameNumber );
149   }
150 }
151
152 uint32_t VectorAnimationRendererPluginProxy::GetTotalFrameNumber()
153 {
154   if( mPlugin )
155   {
156     return mPlugin->GetTotalFrameNumber();
157   }
158   return 0;
159 }
160
161 } // namespace Adaptor
162
163 } // namespace Internal
164
165 } // namespace Dali