9aec054d4bf616dd7bfce8b678c9fe346f1ea703
[platform/core/uifw/dali-adaptor.git] / adaptors / 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 <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 bool VectorAnimationRendererPluginProxy::CreateRenderer( const std::string& url, Dali::Renderer renderer, uint32_t width, uint32_t height )
104 {
105   if( mPlugin )
106   {
107     return mPlugin->CreateRenderer( url, renderer, width, height );
108   }
109   return false;
110 }
111
112 bool VectorAnimationRendererPluginProxy::StartRender()
113 {
114   if( mPlugin )
115   {
116     return mPlugin->StartRender();
117   }
118   return false;
119 }
120
121 void VectorAnimationRendererPluginProxy::StopRender()
122 {
123   if( mPlugin )
124   {
125     mPlugin->StopRender();
126   }
127 }
128
129 void VectorAnimationRendererPluginProxy::Render( uint32_t frameNumber )
130 {
131   if( mPlugin )
132   {
133     mPlugin->Render( frameNumber );
134   }
135 }
136
137 uint32_t VectorAnimationRendererPluginProxy::GetTotalFrameNumber()
138 {
139   if( mPlugin )
140   {
141     return mPlugin->GetTotalFrameNumber();
142   }
143   return 0;
144 }
145
146 } // namespace Adaptor
147
148 } // namespace Internal
149
150 } // namespace Dali