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