Revert "[Tizen] Add codes for Dali Windows Backend"
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / common / image-loader-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/imaging/common/image-loader-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 ImageLoaderPluginProxy
35 {
36
37
38 static const char * DEFAULT_OBJECT_NAME( "libdali-image-loader-plugin.so" );
39
40 static bool mInitializeAttempted = false;
41 static void* mLibHandle = NULL;
42 static CreateImageLoaderPlugin* mCreatePluginFunctionPtr = NULL;
43 static DestroyImageLoaderPlugin* mDestroyImageLoaderPluginPtr = NULL;
44 static Dali::ImageLoaderPlugin* mImageLoaderPlugin = NULL;
45
46 #if defined(DEBUG_ENABLED)
47 /**
48  * Disable logging of image loader plugin proxy or make it verbose from the commandline
49  * as follows (e.g., for dali demo app):
50  * <code>
51  * LOG_IMAGE_LOADER_PLUGIN=0 dali-demo #< off
52  * LOG_IMAGE_LOADER_PLUGIN=3 dali-demo #< on, verbose
53  * </code>
54  */
55 Debug::Filter* gImageLoaderPluginLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_IMAGE_LOADER_PLUGIN" );
56 #endif
57
58 void Initialize()
59 {
60   // Only attempt to load dll once
61   char* error = NULL;
62   if ( !mInitializeAttempted )
63   {
64     mInitializeAttempted = true;
65     mLibHandle = dlopen( DEFAULT_OBJECT_NAME, RTLD_LAZY );
66     error = dlerror();
67     if( !mLibHandle )
68     {
69       DALI_LOG_INFO( gImageLoaderPluginLogFilter, Dali::Integration::Log::Verbose, "Cannot load dali image loading plugin library error: %s\n", error );
70       return;
71     }
72
73     // load plugin
74     mCreatePluginFunctionPtr = reinterpret_cast<CreateImageLoaderPlugin*>( dlsym( mLibHandle, "CreateImageLoaderPlugin" ) );
75     error = dlerror();
76     if( !mCreatePluginFunctionPtr )
77     {
78       DALI_LOG_ERROR("Cannot load symbol CreateImageLoaderPlugin(): %s\n", error );
79       return;
80     }
81
82     mDestroyImageLoaderPluginPtr = reinterpret_cast<DestroyImageLoaderPlugin*>( dlsym( mLibHandle, "DestroyImageLoaderPlugin" ) );
83     error = dlerror();
84     if( !mDestroyImageLoaderPluginPtr )
85     {
86       DALI_LOG_ERROR("Cannot load symbol DestroyImageLoaderPlugin(): %s\n", error );
87       return;
88     }
89
90
91     mImageLoaderPlugin = mCreatePluginFunctionPtr();
92     error = dlerror();
93     if( !mImageLoaderPlugin )
94     {
95       DALI_LOG_ERROR("Call to function CreateImageLoaderPlugin() failed : %s\n", error );
96       return;
97     }
98   }
99 }
100
101 void Destroy()
102 {
103   if( mImageLoaderPlugin && mDestroyImageLoaderPluginPtr )
104   {
105     mDestroyImageLoaderPluginPtr( mImageLoaderPlugin );
106     mImageLoaderPlugin = NULL;
107   }
108 }
109
110 const ImageLoader::BitmapLoader* BitmapLoaderLookup( const std::string& filename )
111 {
112   if( mImageLoaderPlugin )
113   {
114     const ImageLoader::BitmapLoader* data = mImageLoaderPlugin->BitmapLoaderLookup( filename );
115     return data;
116   }
117   return NULL;
118 }
119
120 } // namespace ImageLoaderPluginProxy
121
122
123 } // namespace Adaptor
124
125 } // namespace Internal
126
127 } // namespace Dali