1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #if !defined(PREVIEW)
16 #include <dlfcn.h>
17 #endif
18
19 #include "frameworks/bridge/js_frontend/engine/common/js_engine.h"
20
21 #include "native_engine/native_engine.h"
22
23 extern "C" void* OHOS_MEDIA_GetPixelMap(napi_env env, napi_value value);
24
25 namespace OHOS::Ace::Framework {
26
RunNativeEngineLoop()27 void JsEngine::RunNativeEngineLoop()
28 {
29 static bool hasPendingExpection = false;
30 if (nativeEngine_ && !hasPendingExpection) {
31 hasPendingExpection = nativeEngine_->HasPendingException();
32 nativeEngine_->Loop(LOOP_NOWAIT, false);
33 }
34 }
35
36 #if !defined(PREVIEW)
GetPixelMapNapiEntry()37 PixelMapNapiEntry JsEngine::GetPixelMapNapiEntry()
38 {
39 #if defined(IOS_PLATFORM) || defined(ANDROID_PLATFORM)
40 return reinterpret_cast<PixelMapNapiEntry>(&OHOS_MEDIA_GetPixelMap);
41 #else
42 static PixelMapNapiEntry pixelMapNapiEntry_ = nullptr;
43 if (!pixelMapNapiEntry_) {
44 #if defined(_ARM64_) || defined(SIMULATOR_64)
45 std::string prefix = "/system/lib64/module/";
46 #else
47 std::string prefix = "/system/lib/module/";
48 #endif
49 #ifdef OHOS_STANDARD_SYSTEM
50 std::string napiPluginName = "multimedia/libimage.z.so";
51 #else
52 std::string napiPluginName = "multimedia/libimage_napi.z.so";
53 #endif
54 auto napiPluginPath = prefix.append(napiPluginName);
55 void* handle = dlopen(napiPluginPath.c_str(), RTLD_LAZY);
56 if (handle == nullptr) {
57 LOGE("Failed to open shared library %{public}s, reason: %{public}s", napiPluginPath.c_str(), dlerror());
58 return nullptr;
59 }
60 pixelMapNapiEntry_ = reinterpret_cast<PixelMapNapiEntry>(dlsym(handle, "OHOS_MEDIA_GetPixelMap"));
61 if (pixelMapNapiEntry_ == nullptr) {
62 dlclose(handle);
63 LOGE("Failed to get symbol OHOS_MEDIA_GetPixelMap in %{public}s", napiPluginPath.c_str());
64 return nullptr;
65 }
66 }
67 return pixelMapNapiEntry_;
68 #endif
69 }
70 #endif
71
72 } // namespace OHOS::Ace::Framework
73