2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/imaging/common/image-loader-plugin-proxy.h>
23 #include <dali/integration-api/debug.h>
34 namespace ImageLoaderPluginProxy
38 static const char * DEFAULT_OBJECT_NAME( "libdali-image-loader-plugin.so" );
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;
46 #if defined(DEBUG_ENABLED)
48 * Disable logging of image loader plugin proxy or make it verbose from the commandline
49 * as follows (e.g., for dali demo app):
51 * LOG_IMAGE_LOADER_PLUGIN=0 dali-demo #< off
52 * LOG_IMAGE_LOADER_PLUGIN=3 dali-demo #< on, verbose
55 Debug::Filter* gImageLoaderPluginLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_IMAGE_LOADER_PLUGIN" );
60 // Only attempt to load dll once
62 if ( !mInitializeAttempted )
64 mInitializeAttempted = true;
65 mLibHandle = dlopen( DEFAULT_OBJECT_NAME, RTLD_LAZY );
69 DALI_LOG_INFO( gImageLoaderPluginLogFilter, Dali::Integration::Log::Verbose, "Cannot load dali image loading plugin library error: %s\n", error );
74 mCreatePluginFunctionPtr = reinterpret_cast<CreateImageLoaderPlugin*>( dlsym( mLibHandle, "CreateImageLoaderPlugin" ) );
76 if( !mCreatePluginFunctionPtr )
78 DALI_LOG_ERROR("Cannot load symbol CreateImageLoaderPlugin(): %s\n", error );
82 mDestroyImageLoaderPluginPtr = reinterpret_cast<DestroyImageLoaderPlugin*>( dlsym( mLibHandle, "DestroyImageLoaderPlugin" ) );
84 if( !mDestroyImageLoaderPluginPtr )
86 DALI_LOG_ERROR("Cannot load symbol DestroyImageLoaderPlugin(): %s\n", error );
91 mImageLoaderPlugin = mCreatePluginFunctionPtr();
93 if( !mImageLoaderPlugin )
95 DALI_LOG_ERROR("Call to function CreateImageLoaderPlugin() failed : %s\n", error );
103 if( mImageLoaderPlugin && mDestroyImageLoaderPluginPtr )
105 mDestroyImageLoaderPluginPtr( mImageLoaderPlugin );
106 mImageLoaderPlugin = NULL;
110 const ImageLoader::BitmapLoader* BitmapLoaderLookup( const std::string& filename )
112 if( mImageLoaderPlugin )
114 const ImageLoader::BitmapLoader* data = mImageLoaderPlugin->BitmapLoaderLookup( filename );
120 } // namespace ImageLoaderPluginProxy
123 } // namespace Adaptor
125 } // namespace Internal