• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "frameworks/bridge/js_frontend/engine/common/runtime_constants.h"
22 #include "native_engine/native_engine.h"
23 
24 extern "C" void* OHOS_MEDIA_GetPixelMap(napi_env env, napi_value value);
25 
26 namespace OHOS::Ace::Framework {
27 
RunNativeEngineLoop()28 void JsEngine::RunNativeEngineLoop()
29 {
30     static bool hasPendingExpection = false;
31     if (nativeEngine_ && !hasPendingExpection) {
32         hasPendingExpection = nativeEngine_->HasPendingException();
33         nativeEngine_->Loop(LOOP_NOWAIT, false);
34     }
35 }
36 
37 #if !defined(PREVIEW)
GetPixelMapNapiEntry()38 PixelMapNapiEntry JsEngine::GetPixelMapNapiEntry()
39 {
40 #if defined(IOS_PLATFORM) || defined(ANDROID_PLATFORM)
41     return reinterpret_cast<PixelMapNapiEntry>(&OHOS_MEDIA_GetPixelMap);
42 #else
43     static PixelMapNapiEntry pixelMapNapiEntry_ = nullptr;
44     if (!pixelMapNapiEntry_) {
45 #if defined(_ARM64_) || defined(SIMULATOR_64)
46         std::string prefix = "/system/lib64/module/";
47 #else
48         std::string prefix = "/system/lib/module/";
49 #endif
50 #ifdef OHOS_STANDARD_SYSTEM
51         std::string napiPluginName = "multimedia/libimage.z.so";
52 #else
53         std::string napiPluginName = "multimedia/libimage_napi.z.so";
54 #endif
55         auto napiPluginPath = prefix.append(napiPluginName);
56         void* handle = dlopen(napiPluginPath.c_str(), RTLD_LAZY);
57         if (handle == nullptr) {
58             LOGE("Failed to open shared library %{public}s, reason: %{public}s", napiPluginPath.c_str(), dlerror());
59             return nullptr;
60         }
61         pixelMapNapiEntry_ = reinterpret_cast<PixelMapNapiEntry>(dlsym(handle, "OHOS_MEDIA_GetPixelMap"));
62         if (pixelMapNapiEntry_ == nullptr) {
63             dlclose(handle);
64             LOGE("Failed to get symbol OHOS_MEDIA_GetPixelMap in %{public}s", napiPluginPath.c_str());
65             return nullptr;
66         }
67     }
68     return pixelMapNapiEntry_;
69 #endif
70 }
71 #endif
72 
73 } // namespace OHOS::Ace::Framework
74