• 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     if (nativeEngine_ != nullptr) {
31         nativeEngine_->Loop(LOOP_NOWAIT, false);
32     }
33 }
34 
35 #if !defined(PREVIEW)
GetPixelMapNapiEntry()36 PixelMapNapiEntry JsEngine::GetPixelMapNapiEntry()
37 {
38 #if defined(IOS_PLATFORM) || defined(ANDROID_PLATFORM)
39     return reinterpret_cast<PixelMapNapiEntry>(&OHOS_MEDIA_GetPixelMap);
40 #else
41     static PixelMapNapiEntry pixelMapNapiEntry_ = nullptr;
42     if (!pixelMapNapiEntry_) {
43 #if defined(_ARM64_) || defined(SIMULATOR_64)
44         std::string prefix = "/system/lib64/module/";
45 #else
46         std::string prefix = "/system/lib/module/";
47 #endif
48 #ifdef OHOS_STANDARD_SYSTEM
49         std::string napiPluginName = "multimedia/libimage.z.so";
50 #else
51         std::string napiPluginName = "multimedia/libimage_napi.z.so";
52 #endif
53         auto napiPluginPath = prefix.append(napiPluginName);
54         void* handle = dlopen(napiPluginPath.c_str(), RTLD_LAZY);
55         if (handle == nullptr) {
56             LOGE("Failed to open shared library %{public}s, reason: %{public}s", napiPluginPath.c_str(), dlerror());
57             return nullptr;
58         }
59         pixelMapNapiEntry_ = reinterpret_cast<PixelMapNapiEntry>(dlsym(handle, "OHOS_MEDIA_GetPixelMap"));
60         if (pixelMapNapiEntry_ == nullptr) {
61             dlclose(handle);
62             LOGE("Failed to get symbol OHOS_MEDIA_GetPixelMap in %{public}s", napiPluginPath.c_str());
63             return nullptr;
64         }
65     }
66     return pixelMapNapiEntry_;
67 #endif
68 }
69 #endif
70 
71 } // namespace OHOS::Ace::Framework