From 2bb90baa0866c1b035a8a058bf1a130bfdd7e950 Mon Sep 17 00:00:00 2001 From: ZhangYu Date: Fri, 19 May 2023 03:32:53 +0000 Subject: [PATCH] import the dynamic library of ui_content to previewer. Signed-off-by: ZhangYu Change-Id: Icd056728788c0c30450427b2fb3e03aff3513073 --- adapter/preview/build/BUILD.gn | 27 ++++------- adapter/preview/build/config_linux.gni | 3 -- adapter/preview/build/config_mac.gni | 3 -- adapter/preview/build/config_windows.gni | 3 -- adapter/preview/build/platform.gni | 6 +-- adapter/preview/build/preview_common.gni | 2 + adapter/preview/sdk/sharedlib_config.gni | 13 ++--- interfaces/inner_api/ace/BUILD.gn | 35 ++++++++++---- .../ace/declarative_module_preloader.cpp | 28 +++++++---- .../ace/declarative_module_preloader.h | 4 +- interfaces/inner_api/ace/hot_reloader.cpp | 21 ++++++-- interfaces/inner_api/ace/hot_reloader.h | 4 +- interfaces/inner_api/ace/macros.h | 28 +++++++++++ .../inner_api/ace/serializeable_object.cpp | 24 ++++++---- .../inner_api/ace/serializeable_object.h | 6 +-- interfaces/inner_api/ace/ui_content.cpp | 48 ++++++++++--------- interfaces/inner_api/ace/ui_content.h | 21 ++++---- interfaces/inner_api/ace/ui_window.cpp | 24 +++++++--- interfaces/inner_api/ace/ui_window.h | 7 +-- interfaces/inner_api/ace/utils.h | 34 +++++++++++++ 20 files changed, 225 insertions(+), 116 deletions(-) create mode 100644 interfaces/inner_api/ace/macros.h create mode 100644 interfaces/inner_api/ace/utils.h diff --git a/adapter/preview/build/BUILD.gn b/adapter/preview/build/BUILD.gn index 2db4d4e41ee..ef50a030781 100644 --- a/adapter/preview/build/BUILD.gn +++ b/adapter/preview/build/BUILD.gn @@ -15,24 +15,15 @@ import("//build/ohos.gni") import("//foundation/arkui/ace_engine/build/ace_lib.gni") # build for preview shared library -template("libace_engine") { - forward_variables_from(invoker, "*") - - ohos_shared_library(target_name) { - deps = [ "$ace_root/build:libace_static_$platform" ] - subsystem_name = ace_engine_subsystem - part_name = ace_engine_part +ohos_shared_library("libace") { + if (use_mingw_win) { + deps = [ "$ace_root/build:libace_static_windows" ] + } else if (use_mac) { + deps = [ "$ace_root/build:libace_static_mac" ] + } else if (use_linux) { + deps = [ "$ace_root/build:libace_static_linux" ] } -} - -libace_engine("libace_engine_windows") { - platform = "windows" -} - -libace_engine("libace_engine_mac") { - platform = "mac" -} -libace_engine("libace_engine_linux") { - platform = "linux" + subsystem_name = ace_engine_subsystem + part_name = ace_engine_part } diff --git a/adapter/preview/build/config_linux.gni b/adapter/preview/build/config_linux.gni index 171d019a5aa..8393f4c6ea4 100644 --- a/adapter/preview/build/config_linux.gni +++ b/adapter/preview/build/config_linux.gni @@ -19,6 +19,3 @@ defines += [ "GPU_DISABLED", "SK_BUILD_FONT_MGR_FOR_PREVIEW_LINUX", ] - -libace_target = - "//foundation/arkui/ace_engine/adapter/preview/build:libace_engine_linux" diff --git a/adapter/preview/build/config_mac.gni b/adapter/preview/build/config_mac.gni index 17a06122d46..5bdfafed3cd 100644 --- a/adapter/preview/build/config_mac.gni +++ b/adapter/preview/build/config_mac.gni @@ -18,6 +18,3 @@ defines += [ "MAC_PLATFORM", "SK_BUILD_FONT_MGR_FOR_PREVIEW_MAC", ] - -libace_target = - "//foundation/arkui/ace_engine/adapter/preview/build:libace_engine_mac" diff --git a/adapter/preview/build/config_windows.gni b/adapter/preview/build/config_windows.gni index 05ff35e3a9b..5aa8dbc4555 100644 --- a/adapter/preview/build/config_windows.gni +++ b/adapter/preview/build/config_windows.gni @@ -30,6 +30,3 @@ cflags_cc += [ "-Wno-missing-braces", "-Wno-used-but-marked-unused", ] - -libace_target = - "//foundation/arkui/ace_engine/adapter/preview/build:libace_engine_windows" diff --git a/adapter/preview/build/platform.gni b/adapter/preview/build/platform.gni index 5a7b3131402..eb25f0049ec 100644 --- a/adapter/preview/build/platform.gni +++ b/adapter/preview/build/platform.gni @@ -16,7 +16,7 @@ import("config.gni") platforms = [] -if (use_mingw_win || true) { +if (use_mingw_win) { windows_platform = { name = "windows" config = { @@ -27,7 +27,7 @@ if (use_mingw_win || true) { platforms += [ windows_platform ] } -if (use_mac || true) { +if (use_mac) { mac_platform = { name = "mac" config = { @@ -38,7 +38,7 @@ if (use_mac || true) { platforms += [ mac_platform ] } -if (use_linux || true) { +if (use_linux) { linux_platform = { name = "linux" config = { diff --git a/adapter/preview/build/preview_common.gni b/adapter/preview/build/preview_common.gni index db1a5e56f6d..78b420d1267 100644 --- a/adapter/preview/build/preview_common.gni +++ b/adapter/preview/build/preview_common.gni @@ -104,3 +104,5 @@ if (defined(model_component_support) && model_component_support) { if (defined(enable_rosen_backend) && enable_rosen_backend) { defines += [ "ENABLE_ROSEN_BACKEND" ] } + +libace_target = "//foundation/arkui/ace_engine/adapter/preview/build:libace" diff --git a/adapter/preview/sdk/sharedlib_config.gni b/adapter/preview/sdk/sharedlib_config.gni index d139af452ec..b91b466b28d 100644 --- a/adapter/preview/sdk/sharedlib_config.gni +++ b/adapter/preview/sdk/sharedlib_config.gni @@ -19,23 +19,18 @@ if (use_mac) { "//base/global/resource_management/frameworks/resmgr:global_resmgr_mac" label_hilog = "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_mac" - label_ace = - "//foundation/arkui/ace_engine/adapter/preview/build:libace_engine_mac" } else if (use_mingw_win) { dylib_suffix = ".dll" label_res = "//base/global/resource_management/frameworks/resmgr:global_resmgr_win" label_hilog = "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_windows" - label_ace = "//foundation/arkui/ace_engine/adapter/preview/build:libace_engine_windows" } else if (use_linux) { dylib_suffix = ".so" label_res = "//base/global/resource_management/frameworks/resmgr:global_resmgr_linux" label_hilog = "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_linux" - label_ace = - "//foundation/arkui/ace_engine/adapter/preview/build:libace_engine_linux" } common_bin = [ @@ -144,7 +139,13 @@ common_bin = [ part_name = "hilog_native" }, { - label = label_ace + label = "//foundation/arkui/ace_engine/adapter/preview/build:libace" + subsystem_name = "arkui" + part_name = "ace_engine" + }, + { + label = + "//foundation/arkui/ace_engine/interfaces/inner_api/ace:ace_uicontent" subsystem_name = "arkui" part_name = "ace_engine" }, diff --git a/interfaces/inner_api/ace/BUILD.gn b/interfaces/inner_api/ace/BUILD.gn index 9084b7a212a..8e1f869cb60 100644 --- a/interfaces/inner_api/ace/BUILD.gn +++ b/interfaces/inner_api/ace/BUILD.gn @@ -21,8 +21,26 @@ config("uicontent_config") { "${ace_root}/interfaces/frameworks", "${ace_root}/interfaces/inner_api/ace", "//base/notification/common_event_service/interfaces/inner_api", + "//foundation/graphic/graphic_2d/rosen/modules/platform/utils", ] - defines = uicast_configs.uicast_defines + if (use_mingw_win) { + defines = [ + "PREVIEW", + "WINDOWS_PLATFORM", + ] + } else if (use_mac) { + defines = [ + "PREVIEW", + "MAC_PLATFORM", + ] + } else if (use_linux) { + defines = [ + "PREVIEW", + "LINUX_PLATFORM", + ] + } else { + defines = uicast_configs.uicast_defines + } } ohos_shared_library("ace_uicontent") { @@ -38,18 +56,17 @@ ohos_shared_library("ace_uicontent") { "${ace_root}/interfaces/inner_api/ace/ui_window.cpp", ] - if (defined(uicast_configs.uicast_enable)) { + if (!use_mingw_win && !use_mac && !use_linux && + defined(uicast_configs.uicast_enable)) { sources += [ "${ace_root}/interfaces/inner_api/ace/uicast/uicast_subscriber.cpp" ] + external_deps = [ + "ability_base:want", + "common_event_service:cesfwk_innerkits", + "hilog_native:libhilog", + ] } - external_deps = [ - "ability_base:want", - "common_event_service:cesfwk_innerkits", - "hilog_native:libhilog", - "multimedia_image_framework:image", - ] - subsystem_name = ace_engine_subsystem part_name = ace_engine_part } diff --git a/interfaces/inner_api/ace/declarative_module_preloader.cpp b/interfaces/inner_api/ace/declarative_module_preloader.cpp index 564a080096f..97535843143 100644 --- a/interfaces/inner_api/ace/declarative_module_preloader.cpp +++ b/interfaces/inner_api/ace/declarative_module_preloader.cpp @@ -15,27 +15,38 @@ #include "interfaces/inner_api/ace/declarative_module_preloader.h" -#include +#include "utils.h" namespace OHOS::Ace { +#if defined(WINDOWS_PLATFORM) +constexpr char ACE_LIB_NAME[] = "libace.dll"; +#elif defined(MAC_PLATFORM) +constexpr char ACE_LIB_NAME[] = "libace.dylib"; +#elif defined(LINUX_PLATFORM) +constexpr char ACE_LIB_NAME[] = "libace.so"; +#else +constexpr char ACE_LIB_NAME[] = "libace.z.so"; +#endif + using CreateFunc = void (*)(void*); constexpr char PRE_INIT_ACE_MODULE_FUNC[] = "OHOS_ACE_PreloadAceModule"; void InitAceModule(void* runtime) { - void* handle = dlopen("libace.z.so", RTLD_LAZY); + LIBHANDLE handle = LOADLIB(ACE_LIB_NAME); if (handle == nullptr) { return; } - auto entry = reinterpret_cast(dlsym(handle, PRE_INIT_ACE_MODULE_FUNC)); + auto entry = reinterpret_cast(LOADSYM(handle, PRE_INIT_ACE_MODULE_FUNC)); if (entry == nullptr) { - dlclose(handle); + FREELIB(handle); return; } entry(runtime); + FREELIB(handle); } void DeclarativeModulePreloader::Preload(NativeEngine& runtime) @@ -49,18 +60,19 @@ constexpr char PRE_INIT_ACE_MODULE_FUNC_CARD[] = "OHOS_ACE_PreloadAceModuleCard" void InitAceModuleCard(void* runtime) { - void* handle = dlopen("libace.z.so", RTLD_LAZY); + LIBHANDLE handle = LOADLIB(ACE_LIB_NAME); if (handle == nullptr) { return; } - auto entry = reinterpret_cast(dlsym(handle, PRE_INIT_ACE_MODULE_FUNC_CARD)); + auto entry = reinterpret_cast(LOADSYM(handle, PRE_INIT_ACE_MODULE_FUNC_CARD)); if (entry == nullptr) { - dlclose(handle); + FREELIB(handle); return; } entry(runtime); + FREELIB(handle); } void DeclarativeModulePreloader::PreloadCard(NativeEngine& runtime) @@ -68,4 +80,4 @@ void DeclarativeModulePreloader::PreloadCard(NativeEngine& runtime) InitAceModuleCard(reinterpret_cast(&runtime)); } // ArkTsCard end -} // namespace OHOS::Ace \ No newline at end of file +} // namespace OHOS::Ace diff --git a/interfaces/inner_api/ace/declarative_module_preloader.h b/interfaces/inner_api/ace/declarative_module_preloader.h index ebc459ae218..fbb3fb235b6 100644 --- a/interfaces/inner_api/ace/declarative_module_preloader.h +++ b/interfaces/inner_api/ace/declarative_module_preloader.h @@ -19,13 +19,13 @@ #include #include -#include "base/utils/macros.h" +#include "macros.h" class NativeEngine; namespace OHOS::Ace { -class ACE_EXPORT DeclarativeModulePreloader { +class ACE_EXPORT_WITH_PREVIEW DeclarativeModulePreloader { public: static void Preload(NativeEngine& runtime); diff --git a/interfaces/inner_api/ace/hot_reloader.cpp b/interfaces/inner_api/ace/hot_reloader.cpp index c06178b963b..2bbe4b3dfd0 100644 --- a/interfaces/inner_api/ace/hot_reloader.cpp +++ b/interfaces/inner_api/ace/hot_reloader.cpp @@ -15,27 +15,38 @@ #include "interfaces/inner_api/ace/hot_reloader.h" -#include +#include "utils.h" namespace OHOS::Ace { +#if defined(WINDOWS_PLATFORM) +constexpr char ACE_LIB_NAME[] = "libace.dll"; +#elif defined(MAC_PLATFORM) +constexpr char ACE_LIB_NAME[] = "libace.dylib"; +#elif defined(LINUX_PLATFORM) +constexpr char ACE_LIB_NAME[] = "libace.so"; +#else +constexpr char ACE_LIB_NAME[] = "libace.z.so"; +#endif + using ReloadFunc = void (*)(); constexpr char HOT_RELOAD_FUNC[] = "OHOS_ACE_HotReloadPage"; void InitAceModule() { - void* handle = dlopen("libace.z.so", RTLD_LAZY); + LIBHANDLE handle = LOADLIB(ACE_LIB_NAME); if (handle == nullptr) { return; } - auto entry = reinterpret_cast(dlsym(handle, HOT_RELOAD_FUNC)); + auto entry = reinterpret_cast(LOADSYM(handle, HOT_RELOAD_FUNC)); if (entry == nullptr) { - dlclose(handle); + FREELIB(handle); return; } entry(); + FREELIB(handle); } void HotReloader::HotReload() @@ -43,4 +54,4 @@ void HotReloader::HotReload() InitAceModule(); } -} // namespace OHOS::Ace \ No newline at end of file +} // namespace OHOS::Ace diff --git a/interfaces/inner_api/ace/hot_reloader.h b/interfaces/inner_api/ace/hot_reloader.h index e4bdca785c4..a7582bc1f96 100644 --- a/interfaces/inner_api/ace/hot_reloader.h +++ b/interfaces/inner_api/ace/hot_reloader.h @@ -19,11 +19,11 @@ #include #include -#include "base/utils/macros.h" +#include "macros.h" namespace OHOS::Ace { -class ACE_EXPORT HotReloader { +class ACE_EXPORT_WITH_PREVIEW HotReloader { public: static void HotReload(); }; diff --git a/interfaces/inner_api/ace/macros.h b/interfaces/inner_api/ace/macros.h new file mode 100644 index 00000000000..965672effd8 --- /dev/null +++ b/interfaces/inner_api/ace/macros.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_MACROS_H +#define FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_MACROS_H + +// The macro "ACE_EXPORT_WITH_PREVIEW" is the extension of the macro "ACE_EXPORT" +#ifndef ACE_EXPORT_WITH_PREVIEW +#ifndef WINDOWS_PLATFORM +#define ACE_EXPORT_WITH_PREVIEW __attribute__((visibility("default"))) +#else +#define ACE_EXPORT_WITH_PREVIEW __declspec(dllexport) +#endif +#endif + +#endif // FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_MACROS_H diff --git a/interfaces/inner_api/ace/serializeable_object.cpp b/interfaces/inner_api/ace/serializeable_object.cpp index ce6f8f6a00c..8b18499eb81 100644 --- a/interfaces/inner_api/ace/serializeable_object.cpp +++ b/interfaces/inner_api/ace/serializeable_object.cpp @@ -15,31 +15,39 @@ #include "interfaces/inner_api/ace/serializeable_object.h" -#include +#include "utils.h" namespace OHOS::Ace { namespace { + +#if defined(WINDOWS_PLATFORM) +constexpr char ACE_LIB_NAME[] = "libace.dll"; +#elif defined(MAC_PLATFORM) +constexpr char ACE_LIB_NAME[] = "libace.dylib"; +#elif defined(LINUX_PLATFORM) +constexpr char ACE_LIB_NAME[] = "libace.so"; +#else +constexpr char ACE_LIB_NAME[] = "libace.z.so"; +#endif + using CreateFunction = SerializeableObject* (*)(); constexpr char NODE_OBJECT_CREATE_FUNC[] = "OHOS_ACE_CreateNodeObject"; SerializeableObject* CreateNodeObjectInner() { - void* handle = dlopen("libace.z.so", RTLD_LAZY); + LIBHANDLE handle = LOADLIB(ACE_LIB_NAME); if (handle == nullptr) { return nullptr; } - auto entry = reinterpret_cast(dlsym(handle, NODE_OBJECT_CREATE_FUNC)); + auto entry = reinterpret_cast(LOADSYM(handle, NODE_OBJECT_CREATE_FUNC)); if (entry == nullptr) { - dlclose(handle); + FREELIB(handle); return nullptr; } auto nodeObject = entry(); - if (nodeObject == nullptr) { - dlclose(handle); - } - + FREELIB(handle); return nodeObject; } } // namespace diff --git a/interfaces/inner_api/ace/serializeable_object.h b/interfaces/inner_api/ace/serializeable_object.h index 76dd1524e5e..814a1382bdb 100644 --- a/interfaces/inner_api/ace/serializeable_object.h +++ b/interfaces/inner_api/ace/serializeable_object.h @@ -20,12 +20,10 @@ #include #include -#ifndef ACE_EXPORT -#define ACE_EXPORT __attribute__((visibility("default"))) -#endif +#include "macros.h" namespace OHOS::Ace { -class ACE_EXPORT SerializeableObject { +class ACE_EXPORT_WITH_PREVIEW SerializeableObject { public: SerializeableObject() = default; virtual ~SerializeableObject() = default; diff --git a/interfaces/inner_api/ace/ui_content.cpp b/interfaces/inner_api/ace/ui_content.cpp index 1637abbb06c..7fef26343bd 100644 --- a/interfaces/inner_api/ace/ui_content.cpp +++ b/interfaces/inner_api/ace/ui_content.cpp @@ -15,15 +15,25 @@ #include "interfaces/inner_api/ace/ui_content.h" -#include #include +#include "utils.h" #ifdef UICAST_COMPONENT_SUPPORTED #include "interfaces/inner_api/ace/uicast/uicast_subscriber.h" #endif namespace OHOS::Ace { +#if defined(WINDOWS_PLATFORM) +constexpr char ACE_LIB_NAME[] = "libace.dll"; +#elif defined(MAC_PLATFORM) +constexpr char ACE_LIB_NAME[] = "libace.dylib"; +#elif defined(LINUX_PLATFORM) +constexpr char ACE_LIB_NAME[] = "libace.so"; +#else +constexpr char ACE_LIB_NAME[] = "libace.z.so"; +#endif + using CreateCardFunc = UIContent* (*)(void*, void*, bool); using CreateFunc = UIContent* (*)(void*, void*); using CreateFunction = UIContent* (*)(void*); @@ -35,42 +45,37 @@ OHOS::AbilityRuntime::Context* context_ = nullptr; UIContent* CreateUIContent(void* context, void* runtime, bool isFormRender) { - void* handle = dlopen("libace.z.so", RTLD_LAZY); + LIBHANDLE handle = LOADLIB(ACE_LIB_NAME); if (handle == nullptr) { return nullptr; } - auto entry = reinterpret_cast(dlsym(handle, Card_CREATE_FUNC)); + auto entry = reinterpret_cast(LOADSYM(handle, Card_CREATE_FUNC)); if (entry == nullptr) { - dlclose(handle); + FREELIB(handle); return nullptr; } auto content = entry(context, runtime, isFormRender); - if (content == nullptr) { - dlclose(handle); - } - + FREELIB(handle); return content; } UIContent* CreateUIContent(void* context, void* runtime) { - void* handle = dlopen("libace.z.so", RTLD_LAZY); + LIBHANDLE handle = LOADLIB(ACE_LIB_NAME); if (handle == nullptr) { return nullptr; } - auto entry = reinterpret_cast(dlsym(handle, UI_CONTENT_CREATE_FUNC)); + auto entry = reinterpret_cast(LOADSYM(handle, UI_CONTENT_CREATE_FUNC)); if (entry == nullptr) { - dlclose(handle); + FREELIB(handle); return nullptr; } auto content = entry(context, runtime); - if (content == nullptr) { - dlclose(handle); - } + FREELIB(handle); #ifdef UICAST_COMPONENT_SUPPORTED UICastEventSubscribeProxy::GetInstance()->SubscribeStartEvent(content); #endif @@ -80,21 +85,19 @@ UIContent* CreateUIContent(void* context, void* runtime) UIContent* CreateUIContent(void* ability) { - void* handle = dlopen("libace.z.so", RTLD_LAZY); + LIBHANDLE handle = LOADLIB(ACE_LIB_NAME); if (handle == nullptr) { return nullptr; } - auto entry = reinterpret_cast(dlsym(handle, SUB_WINDOW_UI_CONTENT_CREATE_FUNC)); + auto entry = reinterpret_cast(LOADSYM(handle, SUB_WINDOW_UI_CONTENT_CREATE_FUNC)); if (entry == nullptr) { - dlclose(handle); + FREELIB(handle); return nullptr; } auto content = entry(ability); - if (content == nullptr) { - dlclose(handle); - } + FREELIB(handle); #ifdef UICAST_COMPONENT_SUPPORTED UICastEventSubscribeProxy::GetInstance()->SubscribeStartEvent(content); #endif @@ -109,9 +112,8 @@ std::unique_ptr UIContent::Create(OHOS::AbilityRuntime::Context* cont return content; } -std::unique_ptr UIContent::Create(OHOS::AbilityRuntime::Context* context, - NativeEngine* runtime, - bool isFormRender) +std::unique_ptr UIContent::Create( + OHOS::AbilityRuntime::Context* context, NativeEngine* runtime, bool isFormRender) { std::unique_ptr content; content.reset(CreateUIContent(reinterpret_cast(context), reinterpret_cast(runtime), isFormRender)); diff --git a/interfaces/inner_api/ace/ui_content.h b/interfaces/inner_api/ace/ui_content.h index 1ddeaa21396..41cd517ed0e 100644 --- a/interfaces/inner_api/ace/ui_content.h +++ b/interfaces/inner_api/ace/ui_content.h @@ -19,11 +19,13 @@ #include #include #include +#include #include +#include +#include "macros.h" #include "serializeable_object.h" #include "viewport_config.h" -#include "foundation/multimedia/image_framework/interfaces/innerkits/include/pixel_map.h" namespace OHOS { @@ -59,6 +61,10 @@ namespace Ace { class Window; } // namespace Ace +namespace Media { +class PixelMap; +} // namespace Media + } // namespace OHOS class NativeEngine; @@ -66,14 +72,10 @@ class NativeValue; namespace OHOS::Ace { -#ifndef ACE_EXPORT -#define ACE_EXPORT __attribute__((visibility("default"))) -#endif - -class ACE_EXPORT UIContent { +class ACE_EXPORT_WITH_PREVIEW UIContent { public: - static std::unique_ptr Create(OHOS::AbilityRuntime::Context* context, NativeEngine* runtime, - bool isFormRender); + static std::unique_ptr Create( + OHOS::AbilityRuntime::Context* context, NativeEngine* runtime, bool isFormRender); static std::unique_ptr Create(OHOS::AbilityRuntime::Context* context, NativeEngine* runtime); static std::unique_ptr Create(OHOS::AppExecFwk::Ability* ability); static void ShowDumpHelp(std::vector& info); @@ -127,8 +129,7 @@ public: virtual std::shared_ptr GetFormRootNode() = 0; virtual void UpdateFormData(const std::string& data) = 0; - virtual void UpdateFormSharedImage( - const std::map>& imageDataMap) {} + virtual void UpdateFormSharedImage(const std::map>& imageDataMap) {} virtual void SetFormWidth(const float width) = 0; virtual void SetFormHeight(const float height) = 0; diff --git a/interfaces/inner_api/ace/ui_window.cpp b/interfaces/inner_api/ace/ui_window.cpp index 5b926c6baab..94901f90f74 100644 --- a/interfaces/inner_api/ace/ui_window.cpp +++ b/interfaces/inner_api/ace/ui_window.cpp @@ -15,28 +15,40 @@ #include "interfaces/inner_api/ace/ui_window.h" -#include +#include "utils.h" namespace OHOS::Ace::NG { + +#if defined(WINDOWS_PLATFORM) +constexpr char ACE_LIB_NAME[] = "libace.dll"; +#elif defined(MAC_PLATFORM) +constexpr char ACE_LIB_NAME[] = "libace.dylib"; +#elif defined(LINUX_PLATFORM) +constexpr char ACE_LIB_NAME[] = "libace.so"; +#else +constexpr char ACE_LIB_NAME[] = "libace.z.so"; +#endif + using CreateWindowExtensionFunc = std::shared_ptr* (*)(const std::shared_ptr&, const sptr&); constexpr char CREATE_WINDOW_EXTENSION_FUNC[] = "OHOS_ACE_CreateWindowExtension"; -std::shared_ptr UIWindow::CreateWindowExtension(const std::shared_ptr& context, - const sptr& iSession) +std::shared_ptr UIWindow::CreateWindowExtension( + const std::shared_ptr& context, const sptr& iSession) { - void* handle = dlopen("libace.z.so", RTLD_LAZY); + LIBHANDLE handle = LOADLIB(ACE_LIB_NAME); if (handle == nullptr) { return nullptr; } - auto entry = reinterpret_cast(dlsym(handle, CREATE_WINDOW_EXTENSION_FUNC)); - dlclose(handle); + auto entry = reinterpret_cast(LOADSYM(handle, CREATE_WINDOW_EXTENSION_FUNC)); if (entry == nullptr) { + FREELIB(handle); return nullptr; } auto uiWindowPtr = entry(context, iSession); + FREELIB(handle); if (uiWindowPtr == nullptr) { return nullptr; } diff --git a/interfaces/inner_api/ace/ui_window.h b/interfaces/inner_api/ace/ui_window.h index 10545781134..508ce99c3da 100644 --- a/interfaces/inner_api/ace/ui_window.h +++ b/interfaces/inner_api/ace/ui_window.h @@ -18,6 +18,7 @@ #include +#include "macros.h" #include "ui_content.h" namespace OHOS::Rosen { @@ -26,10 +27,10 @@ class ISessionStageStateListener; } // namespace OHOS::Rosen namespace OHOS::Ace::NG { -class ACE_EXPORT UIWindow { +class ACE_EXPORT_WITH_PREVIEW UIWindow { public: - static std::shared_ptr CreateWindowExtension(const std::shared_ptr& context, - const sptr& iSession); + static std::shared_ptr CreateWindowExtension( + const std::shared_ptr& context, const sptr& iSession); virtual ~UIWindow() = default; diff --git a/interfaces/inner_api/ace/utils.h b/interfaces/inner_api/ace/utils.h new file mode 100644 index 00000000000..ff14ac6a489 --- /dev/null +++ b/interfaces/inner_api/ace/utils.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_UTILS_H +#define FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_UTILS_H + +#ifdef WINDOWS_PLATFORM +#include +#include +using LIBHANDLE = HMODULE; +#define LOADLIB(libPath) LoadLibrary(libPath) +#define FREELIB(libHandle) FreeLibrary(libHandle) +#define LOADSYM(libHandle, symbol) GetProcAddress(libHandle, symbol) +#else +#include +using LIBHANDLE = void*; +#define LOADLIB(libPath) dlopen(libPath, RTLD_LAZY) +#define FREELIB(libHandle) dlclose(libHandle) +#define LOADSYM(libHandle, symbol) dlsym(libHandle, symbol) +#endif + +#endif // FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_UTILS_H -- Gitee