2 * Copyright (c) 2021 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>
22 #include <dali/integration-api/debug.h>
31 namespace ImageLoaderPluginProxy
33 static const char* DEFAULT_OBJECT_NAME("libdali2-image-loader-plugin.so");
35 static bool mInitializeAttempted = false;
36 static void* mLibHandle = NULL;
37 static CreateImageLoaderPlugin* mCreatePluginFunctionPtr = NULL;
38 static DestroyImageLoaderPlugin* mDestroyImageLoaderPluginPtr = NULL;
39 static Dali::ImageLoaderPlugin* mImageLoaderPlugin = NULL;
41 #if defined(DEBUG_ENABLED)
43 * Disable logging of image loader plugin proxy or make it verbose from the commandline
44 * as follows (e.g., for dali demo app):
46 * LOG_IMAGE_LOADER_PLUGIN=0 dali-demo #< off
47 * LOG_IMAGE_LOADER_PLUGIN=3 dali-demo #< on, verbose
50 Debug::Filter* gImageLoaderPluginLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_IMAGE_LOADER_PLUGIN");
55 // Only attempt to load dll once
57 if(!mInitializeAttempted)
59 mInitializeAttempted = true;
60 mLibHandle = dlopen(DEFAULT_OBJECT_NAME, RTLD_LAZY);
64 DALI_LOG_INFO(gImageLoaderPluginLogFilter, Dali::Integration::Log::Verbose, "Cannot load dali image loading plugin library error: %s\n", error);
69 mCreatePluginFunctionPtr = reinterpret_cast<CreateImageLoaderPlugin*>(dlsym(mLibHandle, "CreateImageLoaderPlugin"));
71 if(!mCreatePluginFunctionPtr)
73 DALI_LOG_ERROR("Cannot load symbol CreateImageLoaderPlugin(): %s\n", error);
77 mDestroyImageLoaderPluginPtr = reinterpret_cast<DestroyImageLoaderPlugin*>(dlsym(mLibHandle, "DestroyImageLoaderPlugin"));
79 if(!mDestroyImageLoaderPluginPtr)
81 DALI_LOG_ERROR("Cannot load symbol DestroyImageLoaderPlugin(): %s\n", error);
85 mImageLoaderPlugin = mCreatePluginFunctionPtr();
87 if(!mImageLoaderPlugin)
89 DALI_LOG_ERROR("Call to function CreateImageLoaderPlugin() failed : %s\n", error);
97 if(mImageLoaderPlugin && mDestroyImageLoaderPluginPtr)
99 mDestroyImageLoaderPluginPtr(mImageLoaderPlugin);
100 mImageLoaderPlugin = NULL;
104 const ImageLoader::BitmapLoader* BitmapLoaderLookup(const std::string& filename)
106 if(mImageLoaderPlugin)
108 const ImageLoader::BitmapLoader* data = mImageLoaderPlugin->BitmapLoaderLookup(filename);
114 } // namespace ImageLoaderPluginProxy
116 } // namespace Adaptor
118 } // namespace Internal