diff --git a/adapter/ohos/entrance/ace_ability.cpp b/adapter/ohos/entrance/ace_ability.cpp index e888b834a239d79093275714df974757b119231f..56a4d04698bfee7c704f4d4a0a0185ac120278d0 100755 --- a/adapter/ohos/entrance/ace_ability.cpp +++ b/adapter/ohos/entrance/ace_ability.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -281,22 +281,39 @@ void AceAbility::OnStart(const Want& want) Platform::AceContainer::AddAssetPath(abilityId_, packagePathStr, assetBasePathStr); } + Ace::Platform::UIEnvCallback callback = nullptr; +#ifdef ENABLE_ROSEN_BACKEND + callback = [ window, thisAbility, id = abilityId_ ] ( + const OHOS::Ace::RefPtr& context) mutable { + if (SystemProperties::GetRosenBackendEnabled()) { + auto rsUiDirector = OHOS::Rosen::RSUIDirector::Create(); + if (rsUiDirector != nullptr) { + rsUiDirector->SetRSSurfaceNode(window->GetSurfaceNode()); + + // todo regist on size change() + window->RegisterWindowChangeListener(thisAbility); + + rsUiDirector->SetUITaskRunner( + [taskExecutor = Platform::AceContainer::GetContainer(id)->GetTaskExecutor(), id ] + (const std::function& task) { + ContainerScope scope(id); + taskExecutor->PostTask(task, TaskExecutor::TaskType::UI); + }); + if (context != nullptr) { + context->SetRSUIDirector(rsUiDirector); + } + rsUiDirector->Init(); + LOGI("Init Rosen Backend"); + } + } else { + LOGI("not Init Rosen Backend"); + } + }; +#endif // set view - Platform::AceContainer::SetView(flutterAceView, density_, width, height, window->GetWindowId()); + Platform::AceContainer::SetView(flutterAceView, density_, width, height, window->GetWindowId(), callback); Platform::FlutterAceView::SurfaceChanged(flutterAceView, width, height, 0); - // get url - std::string parsedPageUrl; - if (!remotePageUrl_.empty()) { - parsedPageUrl = remotePageUrl_; - } else if (!pageUrl_.empty()) { - parsedPageUrl = pageUrl_; - } else if (want.HasParameter(PAGE_URI)) { - parsedPageUrl = want.GetStringParam(PAGE_URI); - } else { - parsedPageUrl = ""; - } - // action event hadnler auto&& actionEventHandler = [this](const std::string& action) { LOGI("on Action called to event handler"); @@ -326,33 +343,17 @@ void AceAbility::OnStart(const Want& want) context->SetActionEventHandler(actionEventHandler); } -#ifdef ENABLE_ROSEN_BACKEND - if (SystemProperties::GetRosenBackendEnabled()) { - auto rsUiDirector = OHOS::Rosen::RSUIDirector::Create(); - if (rsUiDirector != nullptr) { - rsUiDirector->SetRSSurfaceNode(window->GetSurfaceNode()); - - // todo regist on size change() - window->RegisterWindowChangeListener(thisAbility); - - rsUiDirector->SetUITaskRunner( - [taskExecutor = Platform::AceContainer::GetContainer(abilityId_)->GetTaskExecutor(), id = abilityId_] - (const std::function& task) { - ContainerScope scope(id); - taskExecutor->PostTask(task, TaskExecutor::TaskType::UI); - }); - if (context != nullptr) { - context->SetRSUIDirector(rsUiDirector); - } - rsUiDirector->Init(); - LOGI("Init Rosen Backend"); - } + // get url + std::string parsedPageUrl; + if (!remotePageUrl_.empty()) { + parsedPageUrl = remotePageUrl_; + } else if (!pageUrl_.empty()) { + parsedPageUrl = pageUrl_; + } else if (want.HasParameter(PAGE_URI)) { + parsedPageUrl = want.GetStringParam(PAGE_URI); } else { - LOGI("not Init Rosen Backend"); + parsedPageUrl = ""; } -#else - LOGI("no macro Init Rosen Backend"); -#endif // run page. Platform::AceContainer::RunPage(abilityId_, Platform::AceContainer::GetContainer(abilityId_)->GeneratePageId(), diff --git a/adapter/ohos/entrance/ui_content_impl.cpp b/adapter/ohos/entrance/ui_content_impl.cpp index ea12a49eee2500d369d9dbe264a1e2bc1bc89f65..707d99ae343472e1404045e44e19fcc9a9a1c05b 100644 --- a/adapter/ohos/entrance/ui_content_impl.cpp +++ b/adapter/ohos/entrance/ui_content_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -346,8 +346,31 @@ void UIContentImpl::CommonInitialize(OHOS::Rosen::Window* window, const std::str Platform::FlutterAceView::CreateView(instanceId_, false, container->GetSettings().usePlatformAsUIThread); Platform::FlutterAceView::SurfaceCreated(flutterAceView, window_); + Ace::Platform::UIEnvCallback callback = nullptr; +#ifdef ENABLE_ROSEN_BACKEND + callback = [ window, id = instanceId_, container] ( + const OHOS::Ace::RefPtr& context) { + if (SystemProperties::GetRosenBackendEnabled()) { + auto rsUiDirector = OHOS::Rosen::RSUIDirector::Create(); + if (rsUiDirector != nullptr) { + rsUiDirector->SetRSSurfaceNode(window->GetSurfaceNode()); + rsUiDirector->SetUITaskRunner( + [ taskExecutor = container->GetTaskExecutor(), id ](const std::function& task) { + ContainerScope scope(id); + taskExecutor->PostTask(task, TaskExecutor::TaskType::UI); + }); + auto context = container->GetPipelineContext(); + if (context != nullptr) { + context->SetRSUIDirector(rsUiDirector); + } + rsUiDirector->Init(); + LOGI("UIContent Init Rosen Backend"); + } + } + }; +#endif // set view - Platform::AceContainer::SetView(flutterAceView, density, width, height, window_->GetWindowId()); + Platform::AceContainer::SetView(flutterAceView, density, width, height, window_->GetWindowId(), callback); Platform::FlutterAceView::SurfaceChanged(flutterAceView, width, height, config_.Orientation()); auto nativeEngine = reinterpret_cast(runtime_); if (!storage) { @@ -358,26 +381,6 @@ void UIContentImpl::CommonInitialize(OHOS::Rosen::Window* window, const std::str } InitWindowCallback(info); - -#ifdef ENABLE_ROSEN_BACKEND - if (SystemProperties::GetRosenBackendEnabled()) { - auto rsUiDirector = OHOS::Rosen::RSUIDirector::Create(); - if (rsUiDirector != nullptr) { - rsUiDirector->SetRSSurfaceNode(window->GetSurfaceNode()); - rsUiDirector->SetUITaskRunner( - [taskExecutor = container->GetTaskExecutor(), id = instanceId_](const std::function& task) { - ContainerScope scope(id); - taskExecutor->PostTask(task, TaskExecutor::TaskType::UI); - }); - auto context = container->GetPipelineContext(); - if (context != nullptr) { - context->SetRSUIDirector(rsUiDirector); - } - rsUiDirector->Init(); - LOGI("UIContent Init Rosen Backend"); - } - } -#endif } void UIContentImpl::Foreground() diff --git a/frameworks/core/pipeline/pipeline_context.cpp b/frameworks/core/pipeline/pipeline_context.cpp index fbf6607979dd37781cd3f60ab2027a83ee923897..5e9641a0ac0ee681feb347c7141e3dd7ba2d428b 100644 --- a/frameworks/core/pipeline/pipeline_context.cpp +++ b/frameworks/core/pipeline/pipeline_context.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -746,6 +746,7 @@ RefPtr PipelineContext::SetupRootElement() window_->SetRootRenderNode(rootRenderNode); #ifdef ENABLE_ROSEN_BACKEND if (SystemProperties::GetRosenBackendEnabled() && rsUIDirector_) { + LOGI("rosen ui director call set root."); rsUIDirector_->SetRoot(rootRenderNode->GetRSNode()->GetId()); } #endif