From 510dd8e5389ba62283d5ac3083856aa453428b33 Mon Sep 17 00:00:00 2001 From: ZhangYu Date: Tue, 4 Jul 2023 03:47:02 +0000 Subject: [PATCH] Support the stage model in the previewer. Signed-off-by: ZhangYu --- adapter/preview/build/BUILD.gn | 29 -- adapter/preview/build/preview_common.gni | 2 +- adapter/preview/entrance/BUILD.gn | 15 +- adapter/preview/entrance/ace_ability.cpp | 420 ++++------------ adapter/preview/entrance/ace_ability.h | 76 ++- adapter/preview/entrance/ace_container.cpp | 109 ++--- adapter/preview/entrance/ace_container.h | 40 +- .../entrance/clipboard/clipboard_impl.cpp | 31 +- .../entrance/clipboard/clipboard_impl.h | 6 - .../clipboard/clipboard_proxy_impl.cpp | 9 +- .../entrance/clipboard/clipboard_proxy_impl.h | 6 +- adapter/preview/entrance/event_dispatcher.cpp | 37 +- adapter/preview/entrance/ui_content_impl.cpp | 447 ++++++++++++++++++ adapter/preview/entrance/ui_content_impl.h | 151 ++++++ adapter/preview/external/BUILD.gn | 14 +- .../ability/stage/stage_hap_module_info.cpp | 6 + .../ability/stage/stage_hap_module_info.h | 2 + .../external/flutter/main_event_loop.cpp | 72 --- .../external/flutter/main_event_loop.h | 48 -- .../flutter/platform_task_runner_adapter.cpp | 10 +- .../flutter/platform_task_runner_adapter.h | 2 - adapter/preview/external/window/window.h | 46 -- .../preview/external/window/window_impl.cpp | 86 ---- adapter/preview/external/window/window_impl.h | 49 -- adapter/preview/sdk/sharedlib_config.gni | 4 +- build/BUILD.gn | 41 +- bundle.json | 13 +- frameworks/core/components_ng/components.gni | 6 +- .../render/adapter/rosen_window.h | 2 +- frameworks/core/pipeline_ng/BUILD.gn | 6 +- 30 files changed, 922 insertions(+), 863 deletions(-) delete mode 100644 adapter/preview/build/BUILD.gn create mode 100644 adapter/preview/entrance/ui_content_impl.cpp create mode 100644 adapter/preview/entrance/ui_content_impl.h delete mode 100644 adapter/preview/external/flutter/main_event_loop.cpp delete mode 100644 adapter/preview/external/flutter/main_event_loop.h delete mode 100644 adapter/preview/external/window/window.h delete mode 100644 adapter/preview/external/window/window_impl.cpp delete mode 100644 adapter/preview/external/window/window_impl.h diff --git a/adapter/preview/build/BUILD.gn b/adapter/preview/build/BUILD.gn deleted file mode 100644 index ef50a030781..00000000000 --- a/adapter/preview/build/BUILD.gn +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2021 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. - -import("//build/ohos.gni") -import("//foundation/arkui/ace_engine/build/ace_lib.gni") - -# build for preview shared library -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" ] - } - - subsystem_name = ace_engine_subsystem - part_name = ace_engine_part -} diff --git a/adapter/preview/build/preview_common.gni b/adapter/preview/build/preview_common.gni index 334be730b30..684e6aabf6e 100644 --- a/adapter/preview/build/preview_common.gni +++ b/adapter/preview/build/preview_common.gni @@ -115,4 +115,4 @@ if (defined(window_scene_support) && window_scene_support) { defines += [ "WINDOW_SCENE_SUPPORTED" ] } -libace_target = "//foundation/arkui/ace_engine/adapter/preview/build:libace" +libace_target = "//foundation/arkui/ace_engine/build:libace" diff --git a/adapter/preview/entrance/BUILD.gn b/adapter/preview/entrance/BUILD.gn index fc8ae39faaf..819ca35d16d 100644 --- a/adapter/preview/entrance/BUILD.gn +++ b/adapter/preview/entrance/BUILD.gn @@ -51,17 +51,28 @@ ohos_source_set("preview_entrance_source") { "editing/text_input_impl.cpp", "event_dispatcher.cpp", "subwindow_preview.cpp", + "ui_content_impl.cpp", ] deps = [ "$ace_napi:ace_napi", "$ace_root/frameworks/core/components/theme:build_theme_code", + "$ace_root/interfaces/inner_api/ace:ace_uicontent", ] external_deps = [] - include_dirs = [ "$flutter_root/engine" ] + include_dirs = [ + "$flutter_root/engine", + "//foundation/window/window_manager", + "//foundation/ability/ability_runtime", + "//ide/tools/previewer", + ] if (defined(config.enable_rosen_backend) && config.enable_rosen_backend) { - external_deps += [ "graphic_standard:librender_service_client" ] + external_deps += [ + "graphic_standard:librender_service_client", + "previewer:ide_util", + "window_manager:previewer_window", + ] } else { deps += [ "$ace_flutter_engine_root/glfw:flutter_glfw_preview_$platform", diff --git a/adapter/preview/entrance/ace_ability.cpp b/adapter/preview/entrance/ace_ability.cpp index e68f6f4adca..f42a2389465 100644 --- a/adapter/preview/entrance/ace_ability.cpp +++ b/adapter/preview/entrance/ace_ability.cpp @@ -19,8 +19,13 @@ #include "unicode/putil.h" #endif +#include +#include + #include "include/core/SkFontMgr.h" +#include "previewer/include/window.h" +#include "adapter/ohos/entrance/ace_new_pipe_judgement.h" #include "adapter/preview/entrance/ace_application_info.h" #include "adapter/preview/entrance/ace_container.h" #include "adapter/preview/entrance/event_dispatcher.h" @@ -30,19 +35,7 @@ #include "frameworks/bridge/common/utils/utils.h" #include "frameworks/bridge/js_frontend/js_frontend.h" -#ifndef ENABLE_ROSEN_BACKEND -#include "frameworks/core/components/common/painter/flutter_svg_painter.h" -#else -#include -#include - -#include "adapter/preview/external/flutter/main_event_loop.h" -#endif - namespace OHOS::Ace::Platform { - -std::atomic AceAbility::loopRunning_ = true; - namespace { // JS frontend maintain the page ID self, so it's useless to pass page ID from platform @@ -58,29 +51,6 @@ constexpr char DELIMITER[] = "/"; constexpr char ASSET_PATH_SHARE_STAGE[] = "resources/base/profile"; #endif -#ifdef USE_GLFW_WINDOW -// Screen Density Coefficient/Base Density = Resolution/ppi -constexpr double SCREEN_DENSITY_COEFFICIENT_PHONE = 1080.0 * 160.0 / 480.0; -constexpr double SCREEN_DENSITY_COEFFICIENT_WATCH = 466.0 * 160 / 320.0; -constexpr double SCREEN_DENSITY_COEFFICIENT_TABLE = 2560.0 * 160.0 / 280.0; -constexpr double SCREEN_DENSITY_COEFFICIENT_TV = 3840.0 * 160.0 / 640.0; - -void AdaptDeviceType(AceRunArgs& runArgs) -{ - if (runArgs.deviceConfig.deviceType == DeviceType::PHONE) { - runArgs.deviceConfig.density = runArgs.deviceWidth / SCREEN_DENSITY_COEFFICIENT_PHONE; - } else if (runArgs.deviceConfig.deviceType == DeviceType::WATCH) { - runArgs.deviceConfig.density = runArgs.deviceWidth / SCREEN_DENSITY_COEFFICIENT_WATCH; - } else if (runArgs.deviceConfig.deviceType == DeviceType::TABLET) { - runArgs.deviceConfig.density = runArgs.deviceWidth / SCREEN_DENSITY_COEFFICIENT_TABLE; - } else if (runArgs.deviceConfig.deviceType == DeviceType::TV) { - runArgs.deviceConfig.density = runArgs.deviceWidth / SCREEN_DENSITY_COEFFICIENT_TV; - } else { - LOGE("DeviceType not supported"); - } -} -#endif - void SetFontMgrConfig(const std::string& containerSdkPath) { // To check if use ohos or container fonts. @@ -112,6 +82,29 @@ std::string GetCustomAssetPath(std::string assetPath) return customAssetPath; } +inline void DumpAceRunArgs(const AceRunArgs& runArgs) +{ +#ifdef ACE_DEBUG + LOGI("runArgs.pageProfile: %{private}s", runArgs.pageProfile.c_str()); + LOGI("runArgs.asset: %{private}s", runArgs.assetPath.c_str()); + LOGI("runArgs.systemResources: %{private}s", runArgs.systemResourcesPath.c_str()); + LOGI("runArgs.appResources: %{private}s", runArgs.appResourcesPath.c_str()); + LOGI("runArgs.themeId: %{private}u", runArgs.themeId); + LOGI("runArgs.deviceConfig.orientation: %{private}d", static_cast(runArgs.deviceConfig.orientation)); + LOGI("runArgs.deviceConfig.density: %{private}lf", runArgs.deviceConfig.density); + LOGI("runArgs.deviceConfig.deviceType: %{private}d", static_cast(runArgs.deviceConfig.deviceType)); + LOGI("runArgs.deviceConfig.fontRatio: %{private}lf", runArgs.deviceConfig.fontRatio); + LOGI("runArgs.deviceConfig.colorMode: %{private}d", static_cast(runArgs.deviceConfig.colorMode)); + LOGI("runArgs.url: %{private}s", runArgs.url.c_str()); + LOGI("runArgs.windowTitle: %{private}s", runArgs.windowTitle.c_str()); + LOGI("runArgs.isRound: %{private}s", runArgs.isRound ? "true" : "false"); + LOGI("runArgs.viewWidth: %{private}d", runArgs.viewWidth); + LOGI("runArgs.viewHeight: %{private}d", runArgs.viewHeight); + LOGI("runArgs.deviceWidth: %{private}d", runArgs.deviceWidth); + LOGI("runArgs.deviceHeight: %{private}d", runArgs.deviceHeight); +#endif +} + } // namespace AceAbility::AceAbility(const AceRunArgs& runArgs) : runArgs_(runArgs) @@ -121,183 +114,65 @@ AceAbility::AceAbility(const AceRunArgs& runArgs) : runArgs_(runArgs) LOGI("Initialize for current process."); Container::UpdateCurrent(INSTANCE_ID_PLATFORM); }); - + SystemProperties::SetExtSurfaceEnabled(!runArgs.containerSdkPath.empty()); + SystemProperties::InitDeviceInfo(runArgs.deviceWidth, runArgs.deviceHeight, + runArgs.deviceConfig.orientation == DeviceOrientation::PORTRAIT ? 0 : 1, runArgs.deviceConfig.density, + runArgs.isRound); + SystemProperties::InitDeviceType(runArgs.deviceConfig.deviceType); + SystemProperties::SetColorMode(runArgs.deviceConfig.colorMode); + InitializeAppInfo(); if (runArgs_.aceVersion == AceVersion::ACE_1_0) { if (runArgs_.formsEnabled) { LOGI("CreateContainer with JS_CARD frontend"); - AceContainer::CreateContainer(ACE_INSTANCE_ID, FrontendType::JS_CARD, runArgs_); + AceContainer::CreateContainer(ACE_INSTANCE_ID, FrontendType::JS_CARD, false); } else { LOGI("CreateContainer with JS frontend"); - AceContainer::CreateContainer(ACE_INSTANCE_ID, FrontendType::JS, runArgs_); + AceContainer::CreateContainer(ACE_INSTANCE_ID, FrontendType::JS, false); } } else if (runArgs_.aceVersion == AceVersion::ACE_2_0) { if (runArgs_.formsEnabled) { LOGI("CreateContainer with ETS_CARD frontend"); - AceContainer::CreateContainer(ACE_INSTANCE_ID, FrontendType::ETS_CARD, runArgs_); + AceContainer::CreateContainer(ACE_INSTANCE_ID, FrontendType::ETS_CARD, useNewPipeline_); } else { LOGI("CreateContainer with JSDECLARATIVE frontend"); - AceContainer::CreateContainer(ACE_INSTANCE_ID, FrontendType::DECLARATIVE_JS, runArgs_); + AceContainer::CreateContainer(ACE_INSTANCE_ID, FrontendType::DECLARATIVE_JS, useNewPipeline_); } } else { LOGE("UnKnown frontend type"); } + AceContainer::SetComponentModeFlag(runArgs.isComponentMode); + SetConfigChanges(runArgs.configChanges); auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID); - if (!container) { - LOGE("container is null, set configuration failed."); - return; - } - container->InitDeviceInfo(ACE_INSTANCE_ID, runArgs); + CHECK_NULL_VOID(container); container->SetContainerSdkPath(runArgs.containerSdkPath); - SetConfigChanges(runArgs.configChanges); - auto resConfig = container->GetResourceConfiguration(); - resConfig.SetOrientation(SystemProperties::GetDeviceOrientation()); - resConfig.SetDensity(SystemProperties::GetResolution()); - resConfig.SetDeviceType(SystemProperties::GetDeviceType()); - container->SetResourceConfiguration(resConfig); + container->SetInstallationFree(installationFree_); + container->SetLabelId(labelId_); + auto config = container->GetResourceConfiguration(); + config.SetDeviceType(SystemProperties::GetDeviceType()); + config.SetOrientation(SystemProperties::GetDeviceOrientation()); + config.SetDensity(SystemProperties::GetResolution()); + config.SetColorMode(SystemProperties::GetColorMode()); + config.SetFontRatio(runArgs.deviceConfig.fontRatio); + container->SetResourceConfiguration(config); + InitializeClipboard(); } -#ifndef ENABLE_ROSEN_BACKEND AceAbility::~AceAbility() { - if (controller_) { - FlutterDesktopDestroyWindow(controller_); - } - FlutterDesktopTerminate(); -} -#else -AceAbility::~AceAbility() -{ - if (controller_ != nullptr) { - controller_->DestroyWindow(); - controller_->Terminate(); - } -} -#endif - -namespace { -inline void DumpAceRunArgs(const AceRunArgs& runArgs) -{ -#ifdef ACE_DEBUG - LOGI("runArgs.pageProfile: %{private}s", runArgs.pageProfile.c_str()); - LOGI("runArgs.asset: %{private}s", runArgs.assetPath.c_str()); - LOGI("runArgs.systemResources: %{private}s", runArgs.systemResourcesPath.c_str()); - LOGI("runArgs.appResources: %{private}s", runArgs.appResourcesPath.c_str()); - LOGI("runArgs.themeId: %{private}u", runArgs.themeId); - LOGI("runArgs.deviceConfig.orientation: %{private}d", static_cast(runArgs.deviceConfig.orientation)); - LOGI("runArgs.deviceConfig.density: %{private}lf", runArgs.deviceConfig.density); - LOGI("runArgs.deviceConfig.deviceType: %{private}d", static_cast(runArgs.deviceConfig.deviceType)); - LOGI("runArgs.deviceConfig.fontRatio: %{private}lf", runArgs.deviceConfig.fontRatio); - LOGI("runArgs.deviceConfig.colorMode: %{private}d", static_cast(runArgs.deviceConfig.colorMode)); - LOGI("runArgs.url: %{private}s", runArgs.url.c_str()); - LOGI("runArgs.windowTitle: %{private}s", runArgs.windowTitle.c_str()); - LOGI("runArgs.isRound: %{private}s", runArgs.isRound ? "true" : "false"); - LOGI("runArgs.viewWidth: %{private}d", runArgs.viewWidth); - LOGI("runArgs.viewHeight: %{private}d", runArgs.viewHeight); - LOGI("runArgs.deviceWidth: %{private}d", runArgs.deviceWidth); - LOGI("runArgs.deviceHeight: %{private}d", runArgs.deviceHeight); -#endif + AceContainer::DestroyContainer(ACE_INSTANCE_ID); } -} // namespace -#ifndef ENABLE_ROSEN_BACKEND std::unique_ptr AceAbility::CreateInstance(AceRunArgs& runArgs) { DumpAceRunArgs(runArgs); LOGI("Start create AceAbility instance"); - bool initSucceeded = FlutterDesktopInit(); - if (!initSucceeded) { - LOGE("Could not create window; AceDesktopInit failed."); - return nullptr; - } - AceApplicationInfo::GetInstance().SetLocale(runArgs.language, runArgs.region, runArgs.script, ""); - - SetFontMgrConfig(runArgs.containerSdkPath); - - auto controller = FlutterDesktopCreateWindow( - runArgs.deviceWidth, runArgs.deviceHeight, runArgs.windowTitle.c_str(), runArgs.onRender); - EventDispatcher::GetInstance().SetGlfwWindowController(controller); - EventDispatcher::GetInstance().Initialize(); - auto aceAbility = std::make_unique(runArgs); - aceAbility->SetGlfwWindowController(controller); - return aceAbility; -} -#else -std::unique_ptr AceAbility::CreateInstance(AceRunArgs& runArgs) -{ - DumpAceRunArgs(runArgs); - LOGI("Start create AceAbility instance"); - const auto& ctx = OHOS::Rosen::GlfwRenderContext::GetGlobal(); - if (!ctx->Init()) { - LOGE("Could not create window; AceDesktopInit failed."); - return nullptr; - } -#ifdef USE_GLFW_WINDOW - ctx->CreateGlfwWindow(runArgs.deviceWidth, runArgs.deviceHeight, true); -#else - ctx->CreateGlfwWindow(runArgs.deviceWidth, runArgs.deviceHeight, false); -#endif AceApplicationInfo::GetInstance().SetLocale(runArgs.language, runArgs.region, runArgs.script, ""); SetFontMgrConfig(runArgs.containerSdkPath); EventDispatcher::GetInstance().Initialize(); auto aceAbility = std::make_unique(runArgs); - aceAbility->SetWindow(Rosen::Window::Create(runArgs.onRender)); - aceAbility->SetGlfwWindowController(ctx); return aceAbility; } -#endif - -#ifndef ENABLE_ROSEN_BACKEND -void AceAbility::InitEnv() -{ -#ifdef INIT_ICU_DATA_PATH - std::string icuPath = "."; - u_setDataDirectory(icuPath.c_str()); -#endif - std::vector paths; - paths.push_back(runArgs_.assetPath); - std::string appResourcesPath(runArgs_.appResourcesPath); - if (!OHOS::Ace::Framework::EndWith(appResourcesPath, DELIMITER)) { - appResourcesPath.append(DELIMITER); - } - if (runArgs_.projectModel == ProjectModel::STAGE) { - paths.push_back(appResourcesPath); - paths.push_back(appResourcesPath + ASSET_PATH_SHARE_STAGE); - } else { - paths.push_back(GetCustomAssetPath(runArgs_.assetPath) + ASSET_PATH_SHARE); - } - AceContainer::AddAssetPath(ACE_INSTANCE_ID, "", paths); - auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID); - CHECK_NULL_VOID(container); - if (runArgs_.projectModel == ProjectModel::STAGE) { - if (runArgs_.formsEnabled) { - container->SetStageCardConfig(runArgs_.pageProfile, runArgs_.url); - } else { - container->SetPageProfile((runArgs_.pageProfile.empty() ? "" : runArgs_.pageProfile + ".json")); - } - } - AceContainer::SetResourcesPathAndThemeStyle(ACE_INSTANCE_ID, runArgs_.systemResourcesPath, - runArgs_.appResourcesPath, runArgs_.themeId, runArgs_.deviceConfig.colorMode); - auto view = new AceViewPreview(ACE_INSTANCE_ID, nullptr); - if (runArgs_.aceVersion == AceVersion::ACE_2_0) { - AceContainer::SetView(view, runArgs_.deviceConfig.density, runArgs_.deviceWidth, runArgs_.deviceHeight); - AceContainer::RunPage(ACE_INSTANCE_ID, UNUSED_PAGE_ID, runArgs_.url, ""); - } else { - AceContainer::RunPage(ACE_INSTANCE_ID, UNUSED_PAGE_ID, runArgs_.url, ""); - AceContainer::SetView(view, runArgs_.deviceConfig.density, runArgs_.deviceWidth, runArgs_.deviceHeight); - } - // Drive the native engine with the platform thread. - container->RunNativeEngineLoop(); - if (runArgs_.projectModel == ProjectModel::STAGE) { - container->InitializeStageAppConfig(runArgs_.assetPath, runArgs_.formsEnabled); - } - AceContainer::AddRouterChangeCallback(ACE_INSTANCE_ID, runArgs_.onRouterChange); - OHOS::Ace::Framework::InspectorClient::GetInstance().RegisterFastPreviewErrorCallback(runArgs_.onError); - // Should make it possible to update surface changes by using viewWidth and viewHeight. - view->NotifySurfaceChanged(runArgs_.deviceWidth, runArgs_.deviceHeight); - view->NotifyDensityChanged(runArgs_.deviceConfig.density); -} -#else void AceAbility::InitEnv() { #ifdef INIT_ICU_DATA_PATH @@ -368,7 +243,8 @@ void AceAbility::InitEnv() // Drive the native engine with the platform thread. container->RunNativeEngineLoop(); if (runArgs_.projectModel == ProjectModel::STAGE) { - container->InitializeStageAppConfig(runArgs_.assetPath, runArgs_.formsEnabled); + container->InitializeStageAppConfig( + runArgs_.assetPath, bundleName_, moduleName_, compileMode_, compatibleVersion_); } AceContainer::AddRouterChangeCallback(ACE_INSTANCE_ID, runArgs_.onRouterChange); OHOS::Ace::Framework::InspectorClient::GetInstance().RegisterFastPreviewErrorCallback(runArgs_.onError); @@ -376,27 +252,10 @@ void AceAbility::InitEnv() view->NotifySurfaceChanged(runArgs_.deviceWidth, runArgs_.deviceHeight); view->NotifyDensityChanged(runArgs_.deviceConfig.density); } -#endif -void AceAbility::Start() +void AceAbility::InitializeClipboard() const { - RunEventLoop(); -} - -void AceAbility::Stop() -{ - auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID); - if (!container) { - return; - } - - container->GetTaskExecutor()->PostTask([]() { loopRunning_ = false; }, TaskExecutor::TaskType::PLATFORM); -} - -void AceAbility::InitializeClipboard(CallbackSetClipboardData cbkSetData, CallbackGetClipboardData cbkGetData) const -{ - ClipboardProxy::GetInstance()->SetDelegate( - std::make_unique(cbkSetData, cbkGetData)); + ClipboardProxy::GetInstance()->SetDelegate(std::make_unique()); } void AceAbility::OnBackPressed() const @@ -429,92 +288,43 @@ bool AceAbility::OnInputMethodEvent(const unsigned int codePoint) const return EventDispatcher::GetInstance().DispatchInputMethodEvent(codePoint); } -#ifndef ENABLE_ROSEN_BACKEND -void AceAbility::RunEventLoop() +void AceAbility::InitializeAppInfo() { - while (!FlutterDesktopWindowShouldClose(controller_) && loopRunning_) { - FlutterDesktopWaitForEvents(controller_); -#ifdef USE_GLFW_WINDOW - auto window = FlutterDesktopGetWindow(controller_); - int width; - int height; - FlutterDesktopGetWindowSize(window, &width, &height); - if (width != runArgs_.deviceWidth || height != runArgs_.deviceHeight) { - AdaptDeviceType(runArgs_); - SurfaceChanged(runArgs_.deviceConfig.orientation, runArgs_.deviceConfig.density, width, height); - } -#endif - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - } - loopRunning_ = true; - - // Currently exit loop is only to restart the AceContainer for real-time preview case. - // Previewer background thread will release the AceAbility instance and create new one, - // then call the InitEnv() and Start() again. - auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID); - if (!container) { - LOGE("container is null"); - FlutterDesktopDestroyWindow(controller_); - controller_ = nullptr; - return; - } - auto viewPtr = container->GetAceView(); - AceContainer::DestroyContainer(ACE_INSTANCE_ID); - - FlutterDesktopDestroyWindow(controller_); - if (viewPtr != nullptr) { - delete viewPtr; - viewPtr = nullptr; - } - controller_ = nullptr; -} -#else -void AceAbility::RunEventLoop() -{ - while (controller_ != nullptr && !controller_->WindowShouldClose() && loopRunning_) { - // Execute all tasks in the platform thread - flutter::MainEventLoop::GetInstance().Run(); - -#ifdef USE_GLFW_WINDOW - int32_t width; - int32_t height; - controller_->GetWindowSize(width, height); - if (width != runArgs_.deviceWidth || height != runArgs_.deviceHeight) { - AdaptDeviceType(runArgs_); - SurfaceChanged(runArgs_.deviceConfig.orientation, runArgs_.deviceConfig.density, width, height); - } -#endif - // Process the event of glfw - controller_->PollEvents(); - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - } - loopRunning_ = true; - - // Currently exit loop is only to restart the AceContainer for real-time preview case. - // Previewer background thread will release the AceAbility instance and create new one, - // then call the InitEnv() and Start() again. - auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID); - if (!container) { - LOGE("container is null"); - if (controller_ != nullptr) { - controller_->DestroyWindow(); + RefPtr context = + Context::CreateContext(runArgs_.projectModel == ProjectModel::STAGE, runArgs_.appResourcesPath); + if (runArgs_.projectModel == ProjectModel::STAGE) { + auto stageContext = AceType::DynamicCast(context); + CHECK_NULL_VOID(stageContext); + auto appInfo = stageContext->GetAppInfo(); + CHECK_NULL_VOID(appInfo); + auto hapModuleInfo = stageContext->GetHapModuleInfo(); + CHECK_NULL_VOID(hapModuleInfo); + bundleName_ = appInfo->GetBundleName(); + moduleName_ = hapModuleInfo->GetModuleName(); + compileMode_ = hapModuleInfo->GetCompileMode(); + compatibleVersion_ = appInfo->GetMinAPIVersion(); + auto targetVersion = appInfo->GetTargetAPIVersion(); + auto releaseType = appInfo->GetApiReleaseType(); + bool enablePartialUpdate = hapModuleInfo->GetPartialUpdateFlag(); + // only app should have menubar, card don't need + if (!runArgs_.formsEnabled) { + installationFree_ = appInfo->IsInstallationFree(); + labelId_ = hapModuleInfo->GetLabelId(); } - controller_ = nullptr; - return; - } - auto viewPtr = container->GetAceView(); - AceContainer::DestroyContainer(ACE_INSTANCE_ID); - - if (controller_ != nullptr) { - controller_->DestroyWindow(); - } - if (viewPtr != nullptr) { - delete viewPtr; - viewPtr = nullptr; + useNewPipeline_ = AceNewPipeJudgement::QueryAceNewPipeEnabledStage( + "", compatibleVersion_, targetVersion, releaseType, !enablePartialUpdate); + } else { + auto faContext = AceType::DynamicCast(context); + CHECK_NULL_VOID(faContext); + auto appInfo = faContext->GetAppInfo(); + CHECK_NULL_VOID(appInfo); + compatibleVersion_ = appInfo->GetMinAPIVersion(); + auto targetVersion = appInfo->GetTargetAPIVersion(); + auto releaseType = appInfo->GetApiReleaseType(); + useNewPipeline_ = + AceNewPipeJudgement::QueryAceNewPipeEnabledFA("", compatibleVersion_, targetVersion, releaseType); } - controller_ = nullptr; } -#endif void AceAbility::SetConfigChanges(const std::string& configChanges) { @@ -569,37 +379,13 @@ void AceAbility::SurfaceChanged( const DeviceOrientation& orientation, const double& resolution, int32_t& width, int32_t& height) { auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID); - if (!container) { - LOGE("container is null, SurfaceChanged failed."); - return; - } - + CHECK_NULL_VOID(container); auto viewPtr = container->GetAceView(); - if (viewPtr == nullptr) { - LOGE("aceView is null, SurfaceChanged failed."); - return; - } + CHECK_NULL_VOID(viewPtr); // Need to change the window resolution and then change the rendering resolution. Otherwise, the image may not adapt // to the new window after the window is modified. auto context = container->GetPipelineContext(); - if (context == nullptr) { - LOGE("context is null, SurfaceChanged failed."); - return; - } -#ifndef ENABLE_ROSEN_BACKEND - auto window = FlutterDesktopGetWindow(controller_); - context->GetTaskExecutor()->PostSyncTask( - [window, &width, &height]() { FlutterDesktopSetWindowSize(window, width, height); }, - TaskExecutor::TaskType::PLATFORM); -#else - context->GetTaskExecutor()->PostSyncTask( - [this, width, height]() { - if (controller_ != nullptr) { - controller_->SetWindowSize(width, height); - } - }, - TaskExecutor::TaskType::PLATFORM); -#endif + CHECK_NULL_VOID(context); SystemProperties::InitDeviceInfo( width, height, orientation == DeviceOrientation::PORTRAIT ? 0 : 1, resolution, runArgs_.isRound); DeviceConfig deviceConfig = runArgs_.deviceConfig; @@ -622,10 +408,7 @@ void AceAbility::SurfaceChanged( void AceAbility::ReplacePage(const std::string& url, const std::string& params) { auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID); - if (!container) { - LOGE("container is null"); - return; - } + CHECK_NULL_VOID(container); container->GetFrontend()->ReplacePage(url, params); } @@ -642,10 +425,7 @@ void AceAbility::LoadDocument(const std::string& url, const std::string& compone }; OnConfigurationChanged(deviceConfig); auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID); - if (!container) { - LOGE("container is null"); - return; - } + CHECK_NULL_VOID(container); container->LoadDocument(url, componentName); } @@ -706,4 +486,14 @@ bool AceAbility::OperateComponent(const std::string& attrsJson) return true; } +void AceAbility::SetWindow(sptr rsWindow) +{ + rsWindow_ = rsWindow; +} + +sptr AceAbility::GetWindow() +{ + return rsWindow_; +} + } // namespace OHOS::Ace::Platform diff --git a/adapter/preview/entrance/ace_ability.h b/adapter/preview/entrance/ace_ability.h index 66685c1e3bb..6ed485229d2 100644 --- a/adapter/preview/entrance/ace_ability.h +++ b/adapter/preview/entrance/ace_ability.h @@ -19,20 +19,23 @@ #include #include -#ifdef ENABLE_ROSEN_BACKEND -#include "glfw_render_context.h" -#else -#include "flutter/shell/platform/glfw/public/flutter_glfw.h" -#endif - #include "adapter/preview/entrance/ace_run_args.h" -#include "adapter/preview/external/window/window.h" -#include "base/utils/macros.h" -#include "adapter/preview/external/multimodalinput/key_event.h" -#include "adapter/preview/external/multimodalinput/axis_event.h" -#include "adapter/preview/external/multimodalinput/pointer_event.h" #include "adapter/preview/entrance/clipboard/clipboard_impl.h" #include "adapter/preview/entrance/clipboard/clipboard_proxy_impl.h" +#include "adapter/preview/external/ability/context.h" +#include "adapter/preview/external/ability/fa/fa_context.h" +#include "adapter/preview/external/ability/stage/stage_context.h" +#include "adapter/preview/external/multimodalinput/axis_event.h" +#include "adapter/preview/external/multimodalinput/key_event.h" +#include "adapter/preview/external/multimodalinput/pointer_event.h" +#include "frameworks/base/utils/macros.h" + +#include +#include + +namespace OHOS::Rosen { + class Window; +} namespace OHOS::Ace::Platform { @@ -57,23 +60,15 @@ struct SystemParams { OHOS::Ace::DeviceOrientation orientation { DeviceOrientation::PORTRAIT }; }; -#ifndef ENABLE_ROSEN_BACKEND -using GlfwController = FlutterDesktopWindowControllerRef; -#else -using GlfwController = std::shared_ptr; -#endif - class ACE_FORCE_EXPORT AceAbility { public: explicit AceAbility(const AceRunArgs& runArgs); ~AceAbility(); - // Be called in Previewer frontend thread, which is not ACE platform thread. - static std::unique_ptr CreateInstance(AceRunArgs& runArgs); - void InitEnv(); - void Start(); - static void Stop(); - void InitializeClipboard(CallbackSetClipboardData cbkSetData, CallbackGetClipboardData cbkGetData) const; + // Be called in Previewer frontend thread, which is not ACE platform thread. + static std::unique_ptr CreateInstance(AceRunArgs& runArgs); + void InitEnv(); + void InitializeClipboard() const; void OnBackPressed() const; bool OnInputEvent(const std::shared_ptr& keyEvent) const; bool OnInputEvent(const std::shared_ptr& pointerEvent) const; @@ -89,37 +84,24 @@ public: std::string GetJSONTree(); std::string GetDefaultJSONTree(); bool OperateComponent(const std::string& attrsJson); - GlfwController GetGlfwWindowController() - { - return controller_; - } - - void SetWindow(sptr rsWindow) - { - rsWindow_ = rsWindow; - } - - sptr GetWindow() - { - return rsWindow_; - } + void SetWindow(sptr rsWindow); + sptr GetWindow(); private: - void RunEventLoop(); - + void InitializeAppInfo(); void SetConfigChanges(const std::string& configChanges); - void SetGlfwWindowController(const GlfwController &controller) - { - controller_ = controller; - } - - // flag indicating if the glfw message loop should be running. - static std::atomic loopRunning_; AceRunArgs runArgs_; ConfigChanges configChanges_; - GlfwController controller_ = nullptr; sptr rsWindow_; + + std::string bundleName_; + std::string moduleName_; + std::string compileMode_; + int32_t compatibleVersion_ = 0; + bool installationFree_ = false; + uint32_t labelId_ = 0; + bool useNewPipeline_ = true; }; } // namespace OHOS::Ace::Platform diff --git a/adapter/preview/entrance/ace_container.cpp b/adapter/preview/entrance/ace_container.cpp index 6f6ba082bba..681f7675d1b 100644 --- a/adapter/preview/entrance/ace_container.cpp +++ b/adapter/preview/entrance/ace_container.cpp @@ -31,7 +31,6 @@ #include "native_engine/native_engine.h" -#include "adapter/ohos/entrance/ace_new_pipe_judgement.h" #include "adapter/preview/entrance/ace_application_info.h" #include "adapter/preview/osal/stage_card_parser.h" #include "base/log/ace_trace.h" @@ -61,6 +60,7 @@ #include "core/pipeline/base/element.h" #include "core/pipeline/pipeline_context.h" #include "core/pipeline_ng/pipeline_context.h" +#include "previewer/include/window.h" namespace OHOS::Ace::Platform { namespace { @@ -75,9 +75,13 @@ const char LOCALE_KEY[] = "locale"; std::once_flag AceContainer::onceFlag_; bool AceContainer::isComponentMode_ = false; -AceContainer::AceContainer(int32_t instanceId, FrontendType type, RefPtr context, bool useCurrentEventRunner) - : instanceId_(instanceId), messageBridge_(AceType::MakeRefPtr()), type_(type), context_(context) +AceContainer::AceContainer(int32_t instanceId, FrontendType type, bool useNewPipeline, bool useCurrentEventRunner) + : instanceId_(instanceId), messageBridge_(AceType::MakeRefPtr()), type_(type) { + LOGI("Using %{public}s pipeline context ...", (useNewPipeline ? "new" : "old")); + if (useNewPipeline) { + SetUseNewPipeline(); + } ThemeConstants::InitDeviceType(); #ifndef ENABLE_ROSEN_BACKEND auto state = flutter::UIDartState::Current()->GetStateById(instanceId); @@ -101,39 +105,6 @@ AceContainer::AceContainer(int32_t instanceId, FrontendType type, RefPtr(context_); - auto faContext = AceType::DynamicCast(context_); - bool useNewPipe = true; - if (type_ != FrontendType::DECLARATIVE_JS && type_ != FrontendType::ETS_CARD) { - useNewPipe = false; - } else if (stageContext) { - auto appInfo = stageContext->GetAppInfo(); - CHECK_NULL_VOID(appInfo); - auto hapModuleInfo = stageContext->GetHapModuleInfo(); - CHECK_NULL_VOID(hapModuleInfo); - auto compatibleVersion = appInfo->GetMinAPIVersion(); - auto targetVersion = appInfo->GetTargetAPIVersion(); - auto releaseType = appInfo->GetApiReleaseType(); - labelId_ = hapModuleInfo->GetLabelId(); - bool enablePartialUpdate = hapModuleInfo->GetPartialUpdateFlag(); - // only app should have menubar, card don't need - if (type_ == FrontendType::DECLARATIVE_JS) { - installationFree_ = appInfo->IsInstallationFree(); - } - useNewPipe = AceNewPipeJudgement::QueryAceNewPipeEnabledStage( - "", compatibleVersion, targetVersion, releaseType, !enablePartialUpdate); - } else if (faContext) { - auto appInfo = faContext->GetAppInfo(); - CHECK_NULL_VOID(appInfo); - auto compatibleVersion = appInfo->GetMinAPIVersion(); - auto targetVersion = appInfo->GetTargetAPIVersion(); - auto releaseType = appInfo->GetApiReleaseType(); - useNewPipe = AceNewPipeJudgement::QueryAceNewPipeEnabledFA("", compatibleVersion, targetVersion, releaseType); - } - LOGI("Using %{public}s pipeline context ...", (useNewPipe ? "new" : "old")); - if (useNewPipe) { - SetUseNewPipeline(); - } if (type_ != FrontendType::DECLARATIVE_JS && type_ != FrontendType::ETS_CARD) { InitializeFrontend(); } @@ -203,7 +174,13 @@ void AceContainer::InitializeFrontend() } else if (type_ == FrontendType::DECLARATIVE_JS) { frontend_ = AceType::MakeRefPtr(); auto declarativeFrontend = AceType::DynamicCast(frontend_); - auto jsEngine = Framework::JsEngineLoader::GetDeclarative().CreateJsEngine(instanceId_); + auto& loader = Framework::JsEngineLoader::GetDeclarative(); + RefPtr jsEngine; + if (GetSettings().usingSharedRuntime) { + jsEngine = loader.CreateJsEngineUsingSharedRuntime(instanceId_, sharedRuntime_); + } else { + jsEngine = loader.CreateJsEngine(instanceId_); + } EngineHelper::AddEngine(instanceId_, jsEngine); declarativeFrontend->SetJsEngine(jsEngine); declarativeFrontend->SetPageProfile(pageProfile_); @@ -241,21 +218,14 @@ void AceContainer::RunNativeEngineLoop() taskExecutor_->PostTask([this]() { RunNativeEngineLoop(); }, TaskExecutor::TaskType::PLATFORM); } -void AceContainer::InitializeStageAppConfig(const std::string& assetPath, bool formsEnabled) +void AceContainer::InitializeStageAppConfig(const std::string& assetPath, const std::string& bundleName, + const std::string& moduleName, const std::string& compileMode, uint32_t minPlatformVersion) { - auto stageContext = AceType::DynamicCast(context_); - CHECK_NULL_VOID(stageContext); - auto appInfo = stageContext->GetAppInfo(); - CHECK_NULL_VOID(appInfo); - auto hapModuleInfo = stageContext->GetHapModuleInfo(); - CHECK_NULL_VOID(hapModuleInfo); if (pipelineContext_) { - LOGI("Set MinPlatformVersion to %{public}d", appInfo->GetMinAPIVersion()); - pipelineContext_->SetMinPlatformVersion(appInfo->GetMinAPIVersion()); + LOGI("Set MinPlatformVersion to %{public}d", minPlatformVersion); + pipelineContext_->SetMinPlatformVersion(minPlatformVersion); } - auto& bundleName = appInfo->GetBundleName(); - auto& compileMode = hapModuleInfo->GetCompileMode(); - auto& moduleName = hapModuleInfo->GetModuleName(); + bool isBundle = (compileMode != "esmodule"); auto declarativeFrontend = AceType::DynamicCast(frontend_); CHECK_NULL_VOID(declarativeFrontend); @@ -456,13 +426,9 @@ void AceContainer::InitializeCallback() } void AceContainer::CreateContainer( - int32_t instanceId, FrontendType type, const AceRunArgs& runArgs, bool useCurrentEventRunner) + int32_t instanceId, FrontendType type, bool useNewPipeline, bool useCurrentEventRunner) { - // for ohos container use newPipeline - SystemProperties::SetExtSurfaceEnabled(!runArgs.containerSdkPath.empty()); - - auto context = Context::CreateContext(runArgs.projectModel == ProjectModel::STAGE, runArgs.appResourcesPath); - auto aceContainer = AceType::MakeRefPtr(instanceId, type, context, useCurrentEventRunner); + auto aceContainer = AceType::MakeRefPtr(instanceId, type, useNewPipeline, useCurrentEventRunner); AceEngine::Get().AddContainer(aceContainer->GetInstanceId(), aceContainer); aceContainer->Initialize(); ContainerScope scope(instanceId); @@ -1027,35 +993,22 @@ void AceContainer::AttachView(std::unique_ptr window, AceViewPreview* vi } #endif -void AceContainer::InitDeviceInfo(int32_t instanceId, const AceRunArgs& runArgs) -{ - ContainerScope scope(instanceId); - SystemProperties::InitDeviceInfo(runArgs.deviceWidth, runArgs.deviceHeight, - runArgs.deviceConfig.orientation == DeviceOrientation::PORTRAIT ? 0 : 1, runArgs.deviceConfig.density, - runArgs.isRound); - SystemProperties::InitDeviceType(runArgs.deviceConfig.deviceType); - SystemProperties::SetColorMode(runArgs.deviceConfig.colorMode); - auto container = GetContainerInstance(instanceId); - if (!container) { - LOGE("container is null, AceContainer::InitDeviceInfo failed."); - return; - } - auto config = container->GetResourceConfiguration(); - config.SetDeviceType(SystemProperties::GetDeviceType()); - config.SetOrientation(SystemProperties::GetDeviceOrientation()); - config.SetDensity(runArgs.deviceConfig.density); - config.SetColorMode(runArgs.deviceConfig.colorMode); - config.SetFontRatio(runArgs.deviceConfig.fontRatio); - container->SetResourceConfiguration(config); - isComponentMode_ = runArgs.isComponentMode; -} - RefPtr AceContainer::GetContainerInstance(int32_t instanceId) { auto container = AceType::DynamicCast(AceEngine::Get().GetContainer(instanceId)); return container; } +std::string AceContainer::GetContentInfo(int32_t instanceId) +{ + auto container = AceEngine::Get().GetContainer(instanceId); + CHECK_NULL_RETURN_NOLOG(container, ""); + ContainerScope scope(instanceId); + auto front = container->GetFrontend(); + CHECK_NULL_RETURN_NOLOG(front, ""); + return front->GetContentInfo(); +} + void AceContainer::LoadDocument(const std::string& url, const std::string& componentName) { ContainerScope scope(instanceId_); diff --git a/adapter/preview/entrance/ace_container.h b/adapter/preview/entrance/ace_container.h index 4130f365d53..6b2a77e69b5 100644 --- a/adapter/preview/entrance/ace_container.h +++ b/adapter/preview/entrance/ace_container.h @@ -23,10 +23,6 @@ #include "adapter/preview/entrance/ace_run_args.h" #include "adapter/preview/entrance/ace_view_preview.h" -#include "adapter/preview/external/ability/context.h" -#include "adapter/preview/external/ability/fa/fa_context.h" -#include "adapter/preview/external/ability/stage/stage_context.h" -#include "adapter/preview/external/window/window.h" #include "adapter/preview/osal/fetch_manager.h" #include "base/resource/asset_manager.h" #include "base/thread/task_executor.h" @@ -37,6 +33,13 @@ #include "core/common/platform_bridge.h" #include "frameworks/bridge/js_frontend/engine/common/js_engine.h" + +#include + +namespace OHOS::Rosen { + class Window; +} + namespace OHOS::Ace::Platform { namespace { @@ -54,7 +57,7 @@ class AceContainer : public Container, public JsMessageDispatcher { public: static void CreateContainer( - int32_t instanceId, FrontendType type, const AceRunArgs& runArgs, bool useCurrentEventRunner = false); + int32_t instanceId, FrontendType type, bool useNewPipeline, bool useCurrentEventRunner = false); static void DestroyContainer(int32_t instanceId); static void AddAssetPath(int32_t instanceId, const std::string& packagePath, const std::vector& paths); @@ -68,13 +71,12 @@ public: int32_t height, UIEnvCallback callback); #endif - static void InitDeviceInfo(int32_t instanceId, const AceRunArgs& runArgs); static bool RunPage(int32_t instanceId, int32_t pageId, const std::string& url, const std::string& params); static RefPtr GetContainerInstance(int32_t instanceId); static void AddRouterChangeCallback(int32_t instanceId, const OnRouterChangeCallback& onRouterChangeCallback); static void NativeOnConfigurationUpdated(int32_t instanceId); - AceContainer(int32_t instanceId, FrontendType type, RefPtr context, bool useCurrentEventRunner = false); + AceContainer(int32_t instanceId, FrontendType type, bool useNewPipeline, bool useCurrentEventRunner = false); ~AceContainer() override = default; void Initialize() override; @@ -213,7 +215,8 @@ public: pageProfile_ = pageProfile; } - void InitializeStageAppConfig(const std::string& assetPath, bool formsEnabled); + void InitializeStageAppConfig(const std::string& assetPath, const std::string& bundleName, + const std::string& moduleName, const std::string& compileMode, uint32_t minPlatformVersion); void SetCardFrontend(WeakPtr frontend, int64_t cardId) override { @@ -252,6 +255,25 @@ public: return it->second; } + static std::string GetContentInfo(int32_t instanceId); + void SetSharedRuntime(void* runtime) override + { + sharedRuntime_ = runtime; + } + void SetInstallationFree(bool installationFree) + { + installationFree_ = installationFree; + } + + void SetLabelId(int32_t labelId) + { + labelId_ = labelId; + } + static void SetComponentModeFlag(bool isComponentMode) + { + isComponentMode_ = isComponentMode; + } + void SetContainerSdkPath(const std::string& containerSdkPath) { containerSdkPath_ = containerSdkPath; @@ -287,7 +309,7 @@ private: std::unordered_map> cardPipelineMap_; mutable std::mutex cardFrontMutex_; mutable std::mutex cardPipelineMutex_; - RefPtr context_; + void* sharedRuntime_ = nullptr; // app bar to use bool installationFree_ = false; diff --git a/adapter/preview/entrance/clipboard/clipboard_impl.cpp b/adapter/preview/entrance/clipboard/clipboard_impl.cpp index 5e8199c1af6..0b6658c00a7 100644 --- a/adapter/preview/entrance/clipboard/clipboard_impl.cpp +++ b/adapter/preview/entrance/clipboard/clipboard_impl.cpp @@ -15,38 +15,35 @@ #include "adapter/preview/entrance/clipboard/clipboard_impl.h" +#include "frameworks/base/utils/utils.h" +#include "util/ClipboardHelper.h" + namespace OHOS::Ace::Platform { void ClipboardImpl::SetData(const std::string& data, CopyOptions copyOption, bool isDragData) { - if (!taskExecutor_ || !callbackSetClipboardData_) { - LOGE("Failed to set the data to clipboard."); - return; - } - taskExecutor_->PostTask( - [callbackSetClipboardData = callbackSetClipboardData_, data] { callbackSetClipboardData(data); }, + CHECK_NULL_VOID(taskExecutor_); + taskExecutor_->PostTask([data] { ClipboardHelper::SetClipboardData(data); }, TaskExecutor::TaskType::UI); } void ClipboardImpl::GetData(const std::function& callback, bool syncMode) { - if (!taskExecutor_ || !callbackGetClipboardData_ || !callback) { + if (!taskExecutor_ || !callback) { LOGE("Failed to get the data from clipboard."); return; } - taskExecutor_->PostTask( - [callbackGetClipboardData = callbackGetClipboardData_, callback] { callback(callbackGetClipboardData()); }, + taskExecutor_->PostTask([callback] { callback(ClipboardHelper::GetClipboardData()); }, TaskExecutor::TaskType::UI); } void ClipboardImpl::HasData(const std::function& callback) { - if (!taskExecutor_ || !callbackGetClipboardData_ || !callback) { + if (!taskExecutor_ || !callback) { LOGE("Failed to know if data exists from clipboard."); return; } - taskExecutor_->PostTask([callbackGetClipboardData = callbackGetClipboardData_, - callback] { callback(!callbackGetClipboardData().empty()); }, + taskExecutor_->PostTask([callback] { callback(!ClipboardHelper::GetClipboardData().empty()); }, TaskExecutor::TaskType::UI); } @@ -74,16 +71,6 @@ void ClipboardImpl::GetPixelMapData(const std::function; -using CallbackGetClipboardData = std::function; using CallbackSetClipboardPixmapData = std::function&)>; using CallbackGetClipboardPixmapData = std::function(void)>; @@ -44,14 +42,10 @@ public: void GetPixelMapData(const std::function&)>& callback, bool syncMode = false) override; void Clear() override; void HasData(const std::function& callback) override; - void RegisterCallbackSetClipboardData(CallbackSetClipboardData callback); - void RegisterCallbackGetClipboardData(CallbackGetClipboardData callback); void RegisterCallbackSetClipboardPixmapData(CallbackSetClipboardPixmapData callback); void RegisterCallbackGetClipboardPixmapData(CallbackGetClipboardPixmapData callback); private: - CallbackSetClipboardData callbackSetClipboardData_; - CallbackGetClipboardData callbackGetClipboardData_; CallbackSetClipboardPixmapData callbackSetClipboardPixmapData_; CallbackGetClipboardPixmapData callbackGetClipboardPixmapData_; }; diff --git a/adapter/preview/entrance/clipboard/clipboard_proxy_impl.cpp b/adapter/preview/entrance/clipboard/clipboard_proxy_impl.cpp index 39913f26bd1..6b77331c289 100644 --- a/adapter/preview/entrance/clipboard/clipboard_proxy_impl.cpp +++ b/adapter/preview/entrance/clipboard/clipboard_proxy_impl.cpp @@ -17,16 +17,11 @@ namespace OHOS::Ace::Platform { -ClipboardProxyImpl::ClipboardProxyImpl(CallbackSetClipboardData callbackSetData, - CallbackGetClipboardData callbackGetData) : callbackSetClipboardData_(callbackSetData), - callbackGetClipboardData_(callbackGetData) {} +ClipboardProxyImpl::ClipboardProxyImpl() {} RefPtr ClipboardProxyImpl::GetClipboard(const RefPtr& taskExecutor) const { - auto clipboard = AceType::MakeRefPtr(taskExecutor); - clipboard->RegisterCallbackSetClipboardData(callbackSetClipboardData_); - clipboard->RegisterCallbackGetClipboardData(callbackGetClipboardData_); - return clipboard; + return AceType::MakeRefPtr(taskExecutor); } } // namespace OHOS::Ace::Platform diff --git a/adapter/preview/entrance/clipboard/clipboard_proxy_impl.h b/adapter/preview/entrance/clipboard/clipboard_proxy_impl.h index 529ba229dbf..e71054baa2d 100644 --- a/adapter/preview/entrance/clipboard/clipboard_proxy_impl.h +++ b/adapter/preview/entrance/clipboard/clipboard_proxy_impl.h @@ -24,14 +24,10 @@ namespace OHOS::Ace::Platform { class ACE_FORCE_EXPORT ClipboardProxyImpl : public ClipboardInterface { public: - ClipboardProxyImpl(CallbackSetClipboardData callbackSetData, CallbackGetClipboardData callbackGetData); + ClipboardProxyImpl(); ~ClipboardProxyImpl() = default; RefPtr GetClipboard(const RefPtr& taskExecutor) const override; - -private: - CallbackSetClipboardData callbackSetClipboardData_; - CallbackGetClipboardData callbackGetClipboardData_; }; } // namespace OHOS::Ace::Platform diff --git a/adapter/preview/entrance/event_dispatcher.cpp b/adapter/preview/entrance/event_dispatcher.cpp index 01e6cc0ef69..0e37fea0c42 100644 --- a/adapter/preview/entrance/event_dispatcher.cpp +++ b/adapter/preview/entrance/event_dispatcher.cpp @@ -71,23 +71,54 @@ const std::map SHIFT_PRINTABEL_SYMBOLS = { void ConvertTouchEvent(const std::shared_ptr& pointerEvent, TouchEvent& event) { - event.time = pointerEvent->time; event.id = pointerEvent->id; event.x = pointerEvent->x; event.y = pointerEvent->y; + event.screenX = pointerEvent->screenX; + event.screenY = pointerEvent->screenY; event.type = static_cast(static_cast(pointerEvent->type)); - event.size = sizeof(TouchEvent); + event.pullType = static_cast(static_cast(pointerEvent->pullType)); + event.time = pointerEvent->time; + event.size = pointerEvent->size; + event.force = pointerEvent->force; + event.tiltX = pointerEvent->tiltX; + event.tiltY = pointerEvent->tiltY; + event.deviceId = pointerEvent->deviceId; + event.sourceType = static_cast(static_cast(pointerEvent->sourceType)); + event.sourceTool = static_cast(static_cast(pointerEvent->sourceTool)); + event.pointerEvent = pointerEvent; + for (auto& item : pointerEvent->pointers) { + TouchPoint pointer; + pointer.id = item.id; + pointer.x = item.x; + pointer.y = item.y; + pointer.screenX = item.screenX; + pointer.screenY = item.screenY; + pointer.downTime = item.downTime; + pointer.size = item.size; + pointer.force = item.force; + pointer.tiltX = item.tiltX; + pointer.tiltY = item.tiltY; + pointer.sourceTool = static_cast(static_cast(item.sourceTool)); + pointer.isPressed = item.isPressed; + event.pointers.emplace_back(pointer); + } } void ConvertKeyEvent(const std::shared_ptr& keyEvent, KeyEvent& event) { event.code = static_cast(static_cast(keyEvent->code)); + event.key = keyEvent->key; event.action = static_cast(static_cast(keyEvent->action)); for (auto& item : keyEvent->pressedCodes) { event.pressedCodes.push_back(static_cast(static_cast(item))); } + event.repeatTime = keyEvent->repeatTime; event.timeStamp = keyEvent->timeStamp; - event.key = keyEvent->key; + event.metaKey = keyEvent->metaKey; + event.deviceId = keyEvent->deviceId; + event.sourceType = static_cast(static_cast(keyEvent->sourceType)); + event.rawKeyEvent = keyEvent; } } // namespace diff --git a/adapter/preview/entrance/ui_content_impl.cpp b/adapter/preview/entrance/ui_content_impl.cpp new file mode 100644 index 00000000000..632e9f602f5 --- /dev/null +++ b/adapter/preview/entrance/ui_content_impl.cpp @@ -0,0 +1,447 @@ +/* + * 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. + */ + +#include "adapter/preview/entrance/ui_content_impl.h" + +#include +#include + +#include "include/core/SkFontMgr.h" + +#include "adapter/ohos/entrance/ace_new_pipe_judgement.h" +#include "adapter/ohos/entrance/platform_event_callback.h" +#include "adapter/preview/entrance/ace_application_info.h" +#include "adapter/preview/entrance/ace_container.h" +#include "adapter/preview/entrance/event_dispatcher.h" +#include "adapter/preview/entrance/rs_dir_asset_provider.h" +#include "adapter/preview/external/multimodalinput/axis_event.h" +#include "adapter/preview/external/multimodalinput/key_event.h" +#include "adapter/preview/external/multimodalinput/pointer_event.h" +#include "adapter/preview/inspector/inspector_client.h" +#include "frameworks/base/log/log.h" +#include "frameworks/base/utils/utils.h" +#include "frameworks/bridge/common/utils/utils.h" +#include "frameworks/bridge/js_frontend/js_frontend.h" +#ifdef INIT_ICU_DATA_PATH +#include "unicode/putil.h" +#endif + +#include "frameworks/simulator/common/include/context.h" + +namespace OHOS::Ace { + +using namespace Platform; + +namespace { + +constexpr int32_t UNUSED_PAGE_ID = 1; + +#ifdef WINDOWS_PLATFORM +constexpr char DELIMITER[] = "\\"; +constexpr char ASSET_PATH_SHARE_STAGE[] = "resources\\base\\profile"; +#else +constexpr char DELIMITER[] = "/"; +constexpr char ASSET_PATH_SHARE_STAGE[] = "resources/base/profile"; +#endif + +void SetFontMgrConfig(const std::string& containerSdkPath) +{ + // To check if use ohos or container fonts. + std::string runtimeOS = "OHOS_Container"; + std::string containerFontBasePath = containerSdkPath + DELIMITER + "resources" + DELIMITER + "fonts" + DELIMITER; + RSDirAssetProvider dirAsset(containerFontBasePath); + std::vector fileList; + dirAsset.GetAssetList("", fileList); + if (containerSdkPath.empty() || fileList.empty()) { + runtimeOS = "OHOS"; + containerFontBasePath = ""; + } + LOGI("Runtime OS is %{public}s, and the container fontBasePath is %{public}s", runtimeOS.c_str(), + containerFontBasePath.c_str()); + SkFontMgr::SetFontMgrConfig(runtimeOS, containerFontBasePath); +} + +} // namespace + +using ContentFinishCallback = std::function; +using ContentStartAbilityCallback = std::function; +class ContentEventCallback final : public PlatformEventCallback { +public: + explicit ContentEventCallback(ContentFinishCallback onFinish) : onFinish_(onFinish) {} + ContentEventCallback(ContentFinishCallback onFinish, ContentStartAbilityCallback onStartAbility) + : onFinish_(onFinish), onStartAbility_(onStartAbility) + {} + ~ContentEventCallback() override = default; + + void OnFinish() const override + { + LOGI("UIContent OnFinish"); + CHECK_NULL_VOID_NOLOG(onFinish_); + onFinish_(); + } + + void OnStartAbility(const std::string& address) override + { + LOGI("UIContent OnStartAbility"); + CHECK_NULL_VOID_NOLOG(onStartAbility_); + onStartAbility_(address); + } + + void OnStatusBarBgColorChanged(uint32_t color) override + { + LOGI("UIContent OnStatusBarBgColorChanged"); + } + +private: + ContentFinishCallback onFinish_; + ContentStartAbilityCallback onStartAbility_; +}; + +class DragWindowListener : public OHOS::Rosen::IWindowDragListener { +public: + explicit DragWindowListener(int32_t instanceId) : instanceId_(instanceId) {} + ~DragWindowListener() = default; + void OnDrag(int32_t x, int32_t y, OHOS::Rosen::DragEvent event) + { + LOGI("[Engine Log] The feature is not supported on the previewer, and instanceId_ = %{public}d", instanceId_); + } + +private: + int32_t instanceId_ = -1; +}; + +class TouchOutsideListener : public OHOS::Rosen::ITouchOutsideListener { +public: + explicit TouchOutsideListener(int32_t instanceId) : instanceId_(instanceId) {} + ~TouchOutsideListener() = default; + + void OnTouchOutside() const + { + LOGI("[Engine Log] The feature is not supported on the previewer, and instanceId_ = %{public}d", instanceId_); + } + +private: + int32_t instanceId_ = -1; +}; + +extern "C" ACE_FORCE_EXPORT void* OHOS_ACE_CreateUIContent(void* context, void* runtime) +{ + LOGI("Ace lib loaded, CreateUIContent."); + return new UIContentImpl(reinterpret_cast(context), runtime); +} + +extern "C" ACE_FORCE_EXPORT void* OHOS_ACE_CreateFormContent(void* context, void* runtime, bool isCard) +{ + LOGI("Ace lib loaded, CreateFormUIContent."); + return new UIContentImpl(reinterpret_cast(context), runtime, isCard); +} + +extern "C" ACE_FORCE_EXPORT void* OHOS_ACE_CreateSubWindowUIContent(void* ability) +{ + LOGI("Ace lib loaded, Create SubWindowUIContent."); + return new UIContentImpl(reinterpret_cast(ability)); +} + +UIContentImpl::UIContentImpl(OHOS::AbilityRuntime::Context* context, void* runtime) + : instanceId_(ACE_INSTANCE_ID), runtime_(runtime) +{ + // 基于Options的方式传递参数 + auto options = context->GetOptions(); + assetPath_ = options.assetPath; + systemResourcesPath_ = options.systemResourcePath; + appResourcesPath_ = options.appResourcePath; + containerSdkPath_ = options.containerSdkPath; + startUrl_ = options.url; + language_ = options.language; + region_ = options.region; + script_ = options.script; + themeId_ = options.themeId; + deviceWidth_ = options.deviceWidth; + deviceHeight_ = options.deviceHeight; + isRound_ = options.isRound; + onRouterChange_ = options.onRouterChange; + deviceConfig_.orientation = static_cast(options.deviceConfig.orientation); + deviceConfig_.deviceType = static_cast(options.deviceConfig.deviceType); + deviceConfig_.colorMode = static_cast(options.deviceConfig.colorMode); + deviceConfig_.density = options.deviceConfig.density; + deviceConfig_.fontRatio = options.deviceConfig.fontRatio; + + bundleName_ = options.bundleName; + compatibleVersion_ = options.compatibleVersion; + installationFree_ = options.installationFree; + labelId_ = options.labelId; + moduleName_ = options.moduleName; + compileMode_ = options.compileMode; + pageProfile_ = options.pageProfile; + const std::string profilePrefix = "$profile:"; + if (pageProfile_.compare(0, profilePrefix.size(), profilePrefix) == 0) { + pageProfile_ = pageProfile_.substr(profilePrefix.length()).append(".json"); + } + auto targetVersion = options.targetVersion; + auto releaseType = options.releaseType; + bool enablePartialUpdate = options.enablePartialUpdate; + useNewPipeline_ = AceNewPipeJudgement::QueryAceNewPipeEnabledStage( + "", compatibleVersion_, targetVersion, releaseType, !enablePartialUpdate); +} + +UIContentImpl::UIContentImpl(OHOS::AbilityRuntime::Context* context, void* runtime, bool isCard) + : instanceId_(ACE_INSTANCE_ID), runtime_(runtime), isFormRender_(isCard) +{ + LOGI("The constructor is used to support ets card, isFormRender_ = %{public}d", isFormRender_); +} + +UIContentImpl::UIContentImpl(OHOS::AppExecFwk::Ability* ability) : instanceId_(ACE_INSTANCE_ID) {} + +void UIContentImpl::DestroyUIDirector() +{ + auto container = AceContainer::GetContainerInstance(instanceId_); + CHECK_NULL_VOID_NOLOG(container); + auto pipelineContext = AceType::DynamicCast(container->GetPipelineContext()); + CHECK_NULL_VOID_NOLOG(pipelineContext); + auto rsUIDirector = pipelineContext->GetRSUIDirector(); + CHECK_NULL_VOID_NOLOG(rsUIDirector); + rsUIDirector->Destroy(); +} + +void UIContentImpl::DestroyCallback() const +{ + auto container = AceContainer::GetContainerInstance(instanceId_); + CHECK_NULL_VOID(container); + auto pipelineContext = container->GetPipelineContext(); + CHECK_NULL_VOID(pipelineContext); + pipelineContext->SetNextFrameLayoutCallback(nullptr); +} + +void UIContentImpl::Initialize(OHOS::Rosen::Window* window, const std::string& url, NativeValue* storage) +{ + CommonInitialize(window, url, storage); + AceContainer::RunPage(instanceId_, UNUSED_PAGE_ID, startUrl_, ""); +} + +std::string UIContentImpl::GetContentInfo() const +{ + LOGI("UIContent GetContentInfo"); + return AceContainer::GetContentInfo(instanceId_); +} + +void UIContentImpl::CommonInitialize(OHOS::Rosen::Window* window, const std::string& contentInfo, NativeValue* storage) +{ + static std::once_flag onceFlag; + std::call_once(onceFlag, []() { + LOGI("Initialize for current process."); +#ifdef INIT_ICU_DATA_PATH + std::string icuPath = "."; + u_setDataDirectory(icuPath.c_str()); +#endif + Container::UpdateCurrent(INSTANCE_ID_PLATFORM); + }); + rsWindow_ = window; + + AceApplicationInfo::GetInstance().SetLocale(language_, region_, script_, ""); + SetFontMgrConfig(containerSdkPath_); + EventDispatcher::GetInstance().Initialize(); + SystemProperties::SetExtSurfaceEnabled(!containerSdkPath_.empty()); + SystemProperties::InitDeviceInfo(deviceWidth_, deviceHeight_, + deviceConfig_.orientation == DeviceOrientation::PORTRAIT ? 0 : 1, deviceConfig_.density, isRound_); + SystemProperties::InitDeviceType(deviceConfig_.deviceType); + SystemProperties::SetColorMode(deviceConfig_.colorMode); + LOGI("CreateContainer with JSDECLARATIVE frontend"); + AceContainer::CreateContainer(instanceId_, FrontendType::DECLARATIVE_JS, useNewPipeline_); + auto container = AceContainer::GetContainerInstance(instanceId_); + CHECK_NULL_VOID(container); + if (runtime_) { + container->GetSettings().SetUsingSharedRuntime(true); + container->SetSharedRuntime(runtime_); + } else { + container->GetSettings().SetUsingSharedRuntime(false); + } + container->SetInstallationFree(installationFree_); + container->SetLabelId(labelId_); + auto config = container->GetResourceConfiguration(); + config.SetDeviceType(SystemProperties::GetDeviceType()); + config.SetOrientation(SystemProperties::GetDeviceOrientation()); + config.SetDensity(SystemProperties::GetResolution()); + config.SetColorMode(SystemProperties::GetColorMode()); + config.SetFontRatio(deviceConfig_.fontRatio); + container->SetResourceConfiguration(config); + container->SetPageProfile(pageProfile_); + std::vector paths; + paths.push_back(assetPath_); + std::string appResourcesPath(appResourcesPath_); + if (!OHOS::Ace::Framework::EndWith(appResourcesPath, DELIMITER)) { + appResourcesPath.append(DELIMITER); + } + paths.push_back(appResourcesPath); + paths.push_back(appResourcesPath + ASSET_PATH_SHARE_STAGE); + if (!containerSdkPath_.empty()) { + paths.push_back(containerSdkPath_); + } + AceContainer::AddAssetPath(instanceId_, "", paths); + AceContainer::SetResourcesPathAndThemeStyle( + instanceId_, systemResourcesPath_ + "/entry", appResourcesPath_, themeId_, deviceConfig_.colorMode); + + auto view = AceViewPreview::CreateView(instanceId_, false, container->GetSettings().usePlatformAsUIThread); + UIEnvCallback callback = [window = rsWindow_, id = instanceId_]( + const OHOS::Ace::RefPtr& context) mutable { + CHECK_NULL_VOID(context); + CHECK_NULL_VOID(window); + auto director = OHOS::Rosen::RSUIDirector::Create(); + CHECK_NULL_VOID(director); + director->SetRSSurfaceNode(window->GetSurfaceNode()); + auto container = AceContainer::GetContainerInstance(id); + CHECK_NULL_VOID(container); + auto func = [taskExecutor = container->GetTaskExecutor(), id](const std::function& task) { + CHECK_NULL_VOID(taskExecutor); + ContainerScope scope(id); + taskExecutor->PostTask(task, TaskExecutor::TaskType::UI); + }; + director->SetUITaskRunner(func); + director->Init(); + context->SetRSUIDirector(director); + }; + AceContainer::SetView(view, rsWindow_, deviceConfig_.density, deviceWidth_, deviceHeight_, callback); + // Drive the native engine with the platform thread. + container->RunNativeEngineLoop(); + container->InitializeStageAppConfig(assetPath_, bundleName_, moduleName_, compileMode_, compatibleVersion_); + AceContainer::AddRouterChangeCallback(instanceId_, onRouterChange_); + // Should make it possible to update surface changes by using viewWidth and viewHeight. + view->NotifySurfaceChanged(deviceWidth_, deviceHeight_); + view->NotifyDensityChanged(deviceConfig_.density); +} + +void UIContentImpl::Destroy() +{ + LOGI("UIContentImpl: window destroy"); + AceContainer::DestroyContainer(instanceId_); +} + +uint32_t UIContentImpl::GetBackgroundColor() +{ + auto container = AceContainer::GetContainerInstance(instanceId_); + CHECK_NULL_RETURN(container, 0x000000); + auto taskExecutor = container->GetTaskExecutor(); + CHECK_NULL_RETURN(taskExecutor, 0x000000); + ContainerScope scope(instanceId_); + uint32_t bgColor = 0x000000; + taskExecutor->PostSyncTask( + [&bgColor, container]() { + CHECK_NULL_VOID(container); + auto pipelineContext = container->GetPipelineContext(); + CHECK_NULL_VOID(pipelineContext); + bgColor = pipelineContext->GetAppBgColor().GetValue(); + }, + TaskExecutor::TaskType::UI); + + LOGI("UIContentImpl::GetBackgroundColor, value is %{public}u", bgColor); + return bgColor; +} + +void UIContentImpl::SetBackgroundColor(uint32_t color) +{ + LOGI("UIContentImpl: SetBackgroundColor color is %{public}u", color); + auto container = AceContainer::GetContainerInstance(instanceId_); + CHECK_NULL_VOID(container); + ContainerScope scope(instanceId_); + auto taskExecutor = container->GetTaskExecutor(); + CHECK_NULL_VOID(taskExecutor); + taskExecutor->PostSyncTask( + [container, bgColor = color]() { + auto pipelineContext = container->GetPipelineContext(); + CHECK_NULL_VOID(pipelineContext); + pipelineContext->SetAppBgColor(Color(bgColor)); + }, + TaskExecutor::TaskType::UI); +} + +bool UIContentImpl::ProcessBackPressed() +{ + LOGI("Process Back Pressed Event"); + return EventDispatcher::GetInstance().DispatchBackPressedEvent(); +} + +bool UIContentImpl::ProcessPointerEvent(const std::shared_ptr& pointerEvent) +{ + LOGI("Process MMI::PointerEvent"); + return EventDispatcher::GetInstance().DispatchTouchEvent(pointerEvent); +} + +bool UIContentImpl::ProcessKeyEvent(const std::shared_ptr& keyEvent) +{ + LOGI("Process MMI::KeyEvent"); + return EventDispatcher::GetInstance().DispatchKeyEvent(keyEvent); +} + +bool UIContentImpl::ProcessAxisEvent(const std::shared_ptr& axisEvent) +{ + LOGI("Process MMI::AxisEvent"); + return false; +} + +bool UIContentImpl::ProcessVsyncEvent(uint64_t timeStampNanos) +{ + LOGI("Process VsyncEvent"); + return false; +} + +void UIContentImpl::UpdateConfiguration(const std::shared_ptr& config) {} + +void UIContentImpl::UpdateViewportConfig(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason, + const std::shared_ptr& rsTransaction) +{ + LOGI("ViewportConfig: %{public}s", config.ToString().c_str()); + auto container = AceContainer::GetContainerInstance(instanceId_); + CHECK_NULL_VOID(container); + auto viewPtr = container->GetAceView(); + CHECK_NULL_VOID(viewPtr); + SystemProperties::InitDeviceInfo( + config.Width(), config.Height(), config.Height() >= config.Width() ? 0 : 1, config.Density(), false); + deviceConfig_.orientation = + config.Height() >= config.Width() ? DeviceOrientation::PORTRAIT : DeviceOrientation::LANDSCAPE; + deviceConfig_.density = config.Density(); + // Unlike the real machine, previewer require updating device configuration information to change window size. + container->UpdateDeviceConfig(deviceConfig_); + viewPtr->NotifyDensityChanged(config.Density()); + viewPtr->NotifySurfaceChanged(config.Width(), config.Height()); +} + +void UIContentImpl::DumpInfo(const std::vector& params, std::vector& info) +{ + auto container = AceContainer::GetContainerInstance(instanceId_); + CHECK_NULL_VOID(container); + container->Dump(params, info); +} + +void UIContentImpl::SetNextFrameLayoutCallback(std::function&& callback) +{ + CHECK_NULL_VOID(callback); + auto container = AceContainer::GetContainerInstance(instanceId_); + CHECK_NULL_VOID(container); + auto pipelineContext = container->GetPipelineContext(); + CHECK_NULL_VOID(pipelineContext); + pipelineContext->SetNextFrameLayoutCallback(std::move(callback)); +} + +void UIContentImpl::NotifyMemoryLevel(int32_t level) +{ + LOGI("Receive Memory level notification, level: %{public}d", level); + auto container = AceContainer::GetContainerInstance(instanceId_); + CHECK_NULL_VOID(container); + auto pipelineContext = container->GetPipelineContext(); + CHECK_NULL_VOID(pipelineContext); + ContainerScope scope(instanceId_); + pipelineContext->NotifyMemoryLevel(level); +} + +} // namespace OHOS::Ace diff --git a/adapter/preview/entrance/ui_content_impl.h b/adapter/preview/entrance/ui_content_impl.h new file mode 100644 index 00000000000..4cfcd02e8b0 --- /dev/null +++ b/adapter/preview/entrance/ui_content_impl.h @@ -0,0 +1,151 @@ +/* + * 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_ADAPTER_PREVIEW_ENTRANCE_UI_CONTENT_IMPL_H +#define FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_UI_CONTENT_IMPL_H + +#include "interfaces/inner_api/ace/ui_content.h" +#include "interfaces/inner_api/ace/viewport_config.h" +#include "native_engine/native_engine.h" +#include "native_engine/native_value.h" +#include "previewer/include/window.h" + +#include "adapter/preview/entrance/ace_run_args.h" +#include "adapter/preview/external/ability/context.h" +#include "adapter/preview/external/ability/fa/fa_context.h" +#include "adapter/preview/external/ability/stage/stage_context.h" + +namespace OHOS::Ace { + +class ACE_FORCE_EXPORT UIContentImpl : public UIContent { +public: + UIContentImpl(OHOS::AbilityRuntime::Context* context, void* runtime); + UIContentImpl(OHOS::AppExecFwk::Ability* ability); + UIContentImpl(OHOS::AbilityRuntime::Context* context, void* runtime, bool isCard); + ~UIContentImpl() + { + DestroyUIDirector(); + DestroyCallback(); + } + + // UI content lifeCycles + void Initialize(OHOS::Rosen::Window* window, const std::string& url, NativeValue* storage) override; + void Foreground() override {} + void Background() override {} + void Focus() override {} + void UnFocus() override {} + void Destroy() override; + void OnNewWant(const OHOS::AAFwk::Want& want) override {} + + // distribute + void Restore(OHOS::Rosen::Window* window, const std::string& contentInfo, NativeValue* storage) override {} + std::string GetContentInfo() const override; + void DestroyUIDirector() override; + + // UI content event process + bool ProcessBackPressed() override; + bool ProcessPointerEvent(const std::shared_ptr& pointerEvent) override; + bool ProcessKeyEvent(const std::shared_ptr& keyEvent) override; + bool ProcessAxisEvent(const std::shared_ptr& axisEvent) override; + bool ProcessVsyncEvent(uint64_t timeStampNanos) override; + void SetIsFocusActive(bool isFocusActive) override {} + void SetFocusWindowId(uint32_t focusWindowId) override {} + void UpdateConfiguration(const std::shared_ptr& config) override; + void UpdateViewportConfig(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason, + const std::shared_ptr& rsTransaction = nullptr) override; + void UpdateWindowMode(OHOS::Rosen::WindowMode mode, bool hasDeco = true) override {} + void HideWindowTitleButton(bool hideSplit, bool hideMaximize, bool hideMinimize) override {} + void SetIgnoreViewSafeArea(bool ignoreViewSafeArea) override {} + + // Window color + uint32_t GetBackgroundColor() override; + void SetBackgroundColor(uint32_t color) override; + + void DumpInfo(const std::vector& params, std::vector& info) override; + + // Set UIContent callback for custom window animation + void SetNextFrameLayoutCallback(std::function&& callback) override; + + // Receive memory level notification + void NotifyMemoryLevel(int32_t level) override; + + void SetAppWindowTitle(const std::string& title) override {} + void SetAppWindowIcon(const std::shared_ptr& pixelMap) override {} + void SetActionEventHandler(std::function&& actionCallback) override {} + void SetErrorEventHandler(std::function&& errorCallback) override {} + + // ArkTS Form + void OnFormSurfaceChange(float width, float height) override {} + void UpdateFormData(const std::string& data) override {} + void UpdateFormSharedImage(const std::map>& imageDataMap) override + {} + void SetFormWidth(float width) override {} + void SetFormHeight(float height) override {} + float GetFormWidth() override + { + return 0.0; + } + float GetFormHeight() override + { + return 0.0; + } + std::shared_ptr GetFormRootNode() override + { + return nullptr; + } + +private: + void CommonInitialize(OHOS::Rosen::Window* window, const std::string& contentInfo, NativeValue* storage); + void DestroyCallback() const; + +private: + int32_t instanceId_ = -1; + void* runtime_ = nullptr; + // All parameters that need to be passed. + std::string assetPath_; + std::string systemResourcesPath_; + std::string appResourcesPath_; + std::string containerSdkPath_; + std::string startUrl_; + std::string language_; + std::string region_; + std::string script_; + uint32_t themeId_ = 0; + int32_t deviceWidth_ = 0; + int32_t deviceHeight_ = 0; + bool isRound_ = false; + Platform::SendCurrentRouterCallback onRouterChange_; + DeviceConfig deviceConfig_; + + std::string bundleName_; + std::string moduleName_; + std::string compileMode_; + std::string pageProfile_; + int32_t compatibleVersion_ = 0; + bool installationFree_ = false; + uint32_t labelId_ = 0; + bool useNewPipeline_ = true; + + sptr rsWindow_; + // ITouchOutsideListener is used for touching out of hot areas of window. + OHOS::sptr touchOutsideListener_ = nullptr; + OHOS::sptr dragWindowListener_ = nullptr; + // ArkTS Form + bool isFormRender_ = false; +}; + +} // namespace OHOS::Ace + +#endif // FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_UI_CONTENT_IMPL_H diff --git a/adapter/preview/external/BUILD.gn b/adapter/preview/external/BUILD.gn index d6beb580567..efa5b6f5394 100644 --- a/adapter/preview/external/BUILD.gn +++ b/adapter/preview/external/BUILD.gn @@ -47,19 +47,21 @@ ohos_source_set("preview_external_source") { # for rosen backend if (defined(config.enable_rosen_backend) && config.enable_rosen_backend) { # for event loop - include_dirs = [ "//third_party/flutter/engine" ] + include_dirs = [ + "//third_party/flutter/engine", + "//ide/tools/previewer", + ] # for window - external_deps = [ "graphic_standard:librender_service_client" ] + external_deps = [ + "graphic_standard:librender_service_client", + "previewer:ide_extension", + ] sources += [ # for event loop - "flutter/main_event_loop.cpp", "flutter/platform_task_runner.cpp", "flutter/platform_task_runner_adapter.cpp", - - # for window - "window/window_impl.cpp", ] } } diff --git a/adapter/preview/external/ability/stage/stage_hap_module_info.cpp b/adapter/preview/external/ability/stage/stage_hap_module_info.cpp index a20970b5a5c..80f152fec85 100644 --- a/adapter/preview/external/ability/stage/stage_hap_module_info.cpp +++ b/adapter/preview/external/ability/stage/stage_hap_module_info.cpp @@ -24,6 +24,7 @@ void StageHapModuleInfo::Parse(const std::unique_ptr& root) } compileMode_ = root->GetString("compileMode"); moduleName_ = root->GetString("name"); + pageProfile_ = root->GetString("pages"); auto metaData = root->GetValue("metadata"); if (metaData && metaData->IsArray()) { for (auto index = 0; index < metaData->GetArraySize(); ++index) { @@ -52,6 +53,11 @@ const std::string& StageHapModuleInfo::GetModuleName() const return moduleName_; } +const std::string& StageHapModuleInfo::GetPageProfile() const +{ + return pageProfile_; +} + bool StageHapModuleInfo::GetPartialUpdateFlag() const { return isPartialUpdate_; diff --git a/adapter/preview/external/ability/stage/stage_hap_module_info.h b/adapter/preview/external/ability/stage/stage_hap_module_info.h index bc36a14170d..5f80881e317 100644 --- a/adapter/preview/external/ability/stage/stage_hap_module_info.h +++ b/adapter/preview/external/ability/stage/stage_hap_module_info.h @@ -33,12 +33,14 @@ public: void Parse(const std::unique_ptr& root); const std::string& GetCompileMode() const; const std::string& GetModuleName() const; + const std::string& GetPageProfile() const; bool GetPartialUpdateFlag() const; uint32_t GetLabelId() const; private: std::string compileMode_; std::string moduleName_; + std::string pageProfile_; bool isPartialUpdate_ = true; uint32_t labelId_ = 0; ACE_DISALLOW_COPY_AND_MOVE(StageHapModuleInfo); diff --git a/adapter/preview/external/flutter/main_event_loop.cpp b/adapter/preview/external/flutter/main_event_loop.cpp deleted file mode 100644 index b233c2cf3d3..00000000000 --- a/adapter/preview/external/flutter/main_event_loop.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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. - */ - -#include "adapter/preview/external/flutter/main_event_loop.h" - -namespace flutter { - -MainEventLoop& MainEventLoop::GetInstance() -{ - static MainEventLoop eventLoop(std::this_thread::get_id()); - return eventLoop; -} - -MainEventLoop::MainEventLoop(std::thread::id mainThreadId) : mainThreadId_(mainThreadId) {} - -MainEventLoop::~MainEventLoop() = default; - -bool MainEventLoop::RunsTasksOnCurrentThread() const -{ - return std::this_thread::get_id() == mainThreadId_; -} - -void MainEventLoop::Run() -{ - const auto now = fml::TimePoint::Now(); - std::vector expiredTasks; - - // Process expired tasks. - { - std::lock_guard lock(taskQueueMutex_); - while (!taskQueue_.empty()) { - const auto& top = taskQueue_.top(); - // If the task at the top of task queue has not yet expired, there is nothing more to do. - if (top.GetTargetTime() > now) { - break; - } - - // Only record tasks without executing them when the task queue mutex is hold. - expiredTasks.push_back(top.GetTask()); - taskQueue_.pop(); - } - } - - { - // Flushing tasks here without holing onto the task queue mutex. - for (const auto& task : expiredTasks) { - task(); - } - } -} - -void MainEventLoop::PostTask(fml::closure task, fml::TimePoint targetTime) -{ - static size_t globalTaskOrder = 0; - std::lock_guard lock(taskQueueMutex_); - size_t order = globalTaskOrder++; - taskQueue_.push({ order, std::move(task), targetTime }); -} - -} // namespace flutter diff --git a/adapter/preview/external/flutter/main_event_loop.h b/adapter/preview/external/flutter/main_event_loop.h deleted file mode 100644 index 448a6f4659d..00000000000 --- a/adapter/preview/external/flutter/main_event_loop.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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_ADAPTER_PREVIEW_EXTERNAL_EVENT_LOOP_MAIN_EVENT_LOOP_H -#define FOUNDATION_ACE_ADAPTER_PREVIEW_EXTERNAL_EVENT_LOOP_MAIN_EVENT_LOOP_H - -#include -#include -#include - -#include "flutter/fml/delayed_task.h" - -namespace flutter { -class MainEventLoop { -public: - static MainEventLoop& GetInstance(); - ~MainEventLoop(); - // Determine whether the thread that post the task is the same as the thread where the event loop is located. - bool RunsTasksOnCurrentThread() const; - // Post a tasks to the event loop. - void PostTask(fml::closure task, fml::TimePoint targetTime); - // Execute all tasks in the task queue - void Run(); - -private: - MainEventLoop(std::thread::id mainThreadId); - MainEventLoop(const MainEventLoop&) = delete; - MainEventLoop& operator=(const MainEventLoop&) = delete; - std::thread::id mainThreadId_; - std::mutex taskQueueMutex_; - fml::DelayedTaskQueue taskQueue_; -}; - -} // namespace flutter - -#endif // FOUNDATION_ACE_ADAPTER_PREVIEW_EXTERNAL_EVENT_LOOP_MAIN_EVENT_LOOP_H diff --git a/adapter/preview/external/flutter/platform_task_runner_adapter.cpp b/adapter/preview/external/flutter/platform_task_runner_adapter.cpp index 5b337b2437c..43f43761496 100644 --- a/adapter/preview/external/flutter/platform_task_runner_adapter.cpp +++ b/adapter/preview/external/flutter/platform_task_runner_adapter.cpp @@ -16,28 +16,30 @@ #include "adapter/preview/external/flutter/platform_task_runner_adapter.h" #include "flutter/fml/time/time_point.h" +#include "jsapp/rich/external/EventHandler.h" + namespace flutter { PlatformTaskRunnerAdapter::PlatformTaskRunnerAdapter(bool useCurrentEventRunner) : fml::TaskRunner(nullptr) {} void PlatformTaskRunnerAdapter::PostTask(fml::closure task) { - MainEventLoop::GetInstance().PostTask(std::move(task), fml::TimePoint::Now()); + OHOS::AppExecFwk::EventHandler::Current().PostTask(std::move(task)); } void PlatformTaskRunnerAdapter::PostTaskForTime(fml::closure task, fml::TimePoint target_time) { - MainEventLoop::GetInstance().PostTask(std::move(task), target_time); + OHOS::AppExecFwk::EventHandler::Current().PostTask(std::move(task), target_time.ToEpochDelta().ToMilliseconds()); } void PlatformTaskRunnerAdapter::PostDelayedTask(fml::closure task, fml::TimeDelta delay) { - MainEventLoop::GetInstance().PostTask(std::move(task), fml::TimePoint::Now() + delay); + OHOS::AppExecFwk::EventHandler::Current().PostTask(std::move(task), delay.ToMilliseconds()); } bool PlatformTaskRunnerAdapter::RunsTasksOnCurrentThread() { - return MainEventLoop::GetInstance().RunsTasksOnCurrentThread(); + return OHOS::AppExecFwk::EventHandler::Current().IsCurrentRunnerThread(); } fml::TaskQueueId PlatformTaskRunnerAdapter::GetTaskQueueId() diff --git a/adapter/preview/external/flutter/platform_task_runner_adapter.h b/adapter/preview/external/flutter/platform_task_runner_adapter.h index 770eb03df67..1380bc1ceac 100644 --- a/adapter/preview/external/flutter/platform_task_runner_adapter.h +++ b/adapter/preview/external/flutter/platform_task_runner_adapter.h @@ -19,8 +19,6 @@ #include "flutter/fml/message_loop_impl.h" #include "flutter/fml/message_loop_task_queues.h" -#include "adapter/preview/external/flutter/main_event_loop.h" - namespace flutter { class PlatformTaskRunnerAdapter : public fml::TaskRunner { diff --git a/adapter/preview/external/window/window.h b/adapter/preview/external/window/window.h deleted file mode 100644 index 2178db58b62..00000000000 --- a/adapter/preview/external/window/window.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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_ADAPTER_PREVIEW_EXTERNAL_WINDOW_WINDOW_H -#define FOUNDATION_ACE_ADAPTER_PREVIEW_EXTERNAL_WINDOW_WINDOW_H - -#include -#include - -namespace OHOS { -namespace Rosen { - -class RSSurfaceNode; - -using SendRenderDataCallback = bool (*)(const void*, const size_t, const int32_t, const int32_t); -using OnCallback = std::function; -struct VsyncCallback { - OnCallback onCallback; -}; - -class Window : public RefBase { -public: - Window() = default; - virtual ~Window() = default; - - static sptr Create(SendRenderDataCallback onRender); - - virtual void RequestVsync(const std::shared_ptr& vsyncCallback); - virtual std::shared_ptr GetSurfaceNode() const; -}; - -} // namespace Rosen -} // namespace OHOS -#endif // FOUNDATION_ACE_ADAPTER_PREVIEW_EXTERNAL_WINDOW_WINDOW_H diff --git a/adapter/preview/external/window/window_impl.cpp b/adapter/preview/external/window/window_impl.cpp deleted file mode 100644 index dcbb18c39cd..00000000000 --- a/adapter/preview/external/window/window_impl.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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. - */ - -#include "adapter/preview/external/window/window_impl.h" - -#include - -#include "base/utils/time_util.h" - -namespace OHOS { -namespace Rosen { - -sptr Window::Create(SendRenderDataCallback onRender) -{ - return sptr(new WindowImpl(onRender)); -} - -WindowImpl::WindowImpl(SendRenderDataCallback onRender) -{ - struct Rosen::RSSurfaceNodeConfig rsSurfaceNodeConfig = { - .SurfaceNodeName = "preview_surface", - .additionalData = reinterpret_cast(onRender), - }; - surfaceNode_ = Rosen::RSSurfaceNode::Create(rsSurfaceNodeConfig); -} - -WindowImpl::~WindowImpl() -{ - vsyncRequests_.Push(false); - vsyncThread_->join(); -} - -void WindowImpl::RequestVsync(const std::shared_ptr& vsyncCallback) -{ - { - std::unique_lock lock(mutex_); - pendingVsyncCallbacks_.emplace_back(std::move(vsyncCallback)); - } - if (vsyncThread_ == nullptr) { - auto func = [this] { VsyncThreadMain(); }; - vsyncThread_ = std::make_unique(func); - } - vsyncRequests_.Push(true); -} - -std::shared_ptr WindowImpl::GetSurfaceNode() const -{ - return surfaceNode_; -} - -void WindowImpl::VsyncThreadMain() -{ - while (true) { - bool next = false; - vsyncRequests_.PopFront(next); - if (next == false) { - break; - } - - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - { - std::unique_lock lock(mutex_); - vsyncCallbacks_.swap(pendingVsyncCallbacks_); - } - int64_t now = Ace::GetSysTimestamp(); - for (auto& callback : vsyncCallbacks_) { - callback->onCallback(now); - } - vsyncCallbacks_.clear(); - } -} - -} // namespace Rosen -} // namespace OHOS diff --git a/adapter/preview/external/window/window_impl.h b/adapter/preview/external/window/window_impl.h deleted file mode 100644 index 9f251a5cc14..00000000000 --- a/adapter/preview/external/window/window_impl.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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_ADAPTER_PREVIEW_EXTERNAL_WINDOW_WINDOW_IMPL_H -#define FOUNDATION_ACE_ADAPTER_PREVIEW_EXTERNAL_WINDOW_WINDOW_IMPL_H - -#include -#include -#include - -#include "adapter/preview/external/window/window.h" -#include "base/thread/sem_queue.h" - -namespace OHOS { -namespace Rosen { - -class WindowImpl : public Window { -public: - WindowImpl(SendRenderDataCallback onRender); - ~WindowImpl() override; - - void RequestVsync(const std::shared_ptr& vsyncCallback) override; - std::shared_ptr GetSurfaceNode() const override; - -private: - void VsyncThreadMain(); - std::shared_ptr surfaceNode_; - std::vector> vsyncCallbacks_; - std::vector> pendingVsyncCallbacks_; - std::unique_ptr vsyncThread_; - Ace::SemQueue vsyncRequests_; - std::mutex mutex_; -}; - -} // namespace Rosen -} // namespace OHOS -#endif // FOUNDATION_ACE_ADAPTER_PREVIEW_EXTERNAL_WINDOW_WINDOW_IMPL_H diff --git a/adapter/preview/sdk/sharedlib_config.gni b/adapter/preview/sdk/sharedlib_config.gni index 4d74cefc15a..24482f3833a 100644 --- a/adapter/preview/sdk/sharedlib_config.gni +++ b/adapter/preview/sdk/sharedlib_config.gni @@ -145,7 +145,7 @@ common_bin = [ part_name = "hilog" }, { - label = "//foundation/arkui/ace_engine/adapter/preview/build:libace" + label = "//foundation/arkui/ace_engine/build:libace" subsystem_name = "arkui" part_name = "ace_engine" }, @@ -186,7 +186,7 @@ napi_modules = [ label = "//base/hiviewdfx/hilog/interfaces/js/kits/napi:libhilognapi" subsystem_name = "hiviewdfx" part_name = "hilog" - lib_names = [ "hilog" ] + lib_names = [ "hilog_napi" ] }, { label = "//commonlibrary/ets_utils/js_api_module/buffer:buffer_packages" diff --git a/build/BUILD.gn b/build/BUILD.gn index 0a75298adbb..84d7286dcf0 100644 --- a/build/BUILD.gn +++ b/build/BUILD.gn @@ -83,24 +83,6 @@ foreach(item, ace_platforms) { foreach(item, ace_platforms) { platform = item.name if (platform == "ohos") { - # libace target - ohos_shared_library("libace") { - if (current_os == "ohos") { - sanitize = { - integer_overflow = true - boundary_sanitize = true - debug = ace_sanitize_debug - } - } - - deps = [ "$ace_root/build:libace_static_ohos" ] - version_script = "libace.map" - innerapi_tags = [ "platformsdk" ] - part_name = ace_engine_part - subsystem_name = ace_engine_subsystem - configs = [ "$ace_root:ace_coverage_config" ] - } - ohos_source_set("ace_ohos_unittest_base") { subsystem_name = ace_engine_subsystem part_name = ace_engine_part @@ -151,3 +133,26 @@ config("reduce_eh_frame_config") { cflags_cc = cflags } } + +ohos_shared_library("libace") { + if (is_ohos) { + sanitize = { + integer_overflow = true + boundary_sanitize = true + debug = ace_sanitize_debug + } + deps = [ "$ace_root/build:libace_static_ohos" ] + version_script = "libace.map" + innerapi_tags = [ "platformsdk" ] + configs = [ "$ace_root:ace_coverage_config" ] + } else 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" ] + } + + part_name = ace_engine_part + subsystem_name = ace_engine_subsystem +} diff --git a/bundle.json b/bundle.json index b96f8bd4d35..d08143bc15f 100644 --- a/bundle.json +++ b/bundle.json @@ -71,7 +71,8 @@ "imf", "device_status", "soc_perf", - "security_component" + "security_component", + "previewer" ], "third_party": [ "json", @@ -138,6 +139,16 @@ ] }, "name": "//foundation/arkui/ace_engine/interfaces/inner_api/drawable_descriptor:drawable_descriptor" + }, + { + "header": { + "header_base": "//foundation/arkui/ace_engine/", + "header_files": [ + "adapter/preview/entrance/ace_ability.h", + "adapter/preview/entrance/ace_run_args.h" + ] + }, + "name": "//foundation/arkui/ace_engine/build:libace" } ], "test": [ diff --git a/frameworks/core/components_ng/components.gni b/frameworks/core/components_ng/components.gni index a857dbbeae8..af47f9aa54b 100644 --- a/frameworks/core/components_ng/components.gni +++ b/frameworks/core/components_ng/components.gni @@ -157,8 +157,10 @@ template("build_component_ng") { external_deps += [ "graphic_standard:librender_service_client" ] } - include_dirs += - [ "//foundation/window/window_manager/interfaces/innerkits" ] + include_dirs += [ + "//foundation/window/window_manager", + "//foundation/window/window_manager/interfaces/innerkits", + ] } if (defined(config.enable_standard_input) && diff --git a/frameworks/core/components_ng/render/adapter/rosen_window.h b/frameworks/core/components_ng/render/adapter/rosen_window.h index dd594de3b32..35618383b03 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_window.h +++ b/frameworks/core/components_ng/render/adapter/rosen_window.h @@ -29,7 +29,7 @@ #include "adapter/android/entrance/java/jni/virtual_rs_window.h" #endif #else -#include "adapter/preview/external/window/window.h" +#include "previewer/include/window.h" #endif #include "base/thread/task_executor.h" diff --git a/frameworks/core/pipeline_ng/BUILD.gn b/frameworks/core/pipeline_ng/BUILD.gn index 5992c7f172e..77235a66af2 100644 --- a/frameworks/core/pipeline_ng/BUILD.gn +++ b/frameworks/core/pipeline_ng/BUILD.gn @@ -66,8 +66,10 @@ template("ace_core_pipeline_ng_source_set") { } deps += [ "$ace_root/frameworks/core/components_ng/render:ace_core_components_render_ng_$platform" ] - include_dirs = - [ "//foundation/window/window_manager/interfaces/innerkits" ] + include_dirs = [ + "//foundation/window/window_manager", + "//foundation/window/window_manager/interfaces/innerkits", + ] } if (platform == "ohos" && defined(config.enable_native_view) && -- Gitee