mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-10-07 00:13:44 +00:00
add container scope for support multi-instance
Signed-off-by: sunfei <sunfei.sun@huawei.com> Change-Id: If5214d44fd24a6e5cb47e65f465d942d80deb22c
This commit is contained in:
parent
0db17338fd
commit
be76ec5ced
@ -17,8 +17,18 @@ import("//build/test.gni")
|
||||
|
||||
# Config args
|
||||
declare_args() {
|
||||
# ace debug flag, enable debug features: like dcheck, thread-checker, mem-monitor...
|
||||
enable_ace_debug = false
|
||||
|
||||
# only available when 'enable_ace_debug' set to 'true', show the LOGD infos.
|
||||
enable_ace_debug_log = true
|
||||
|
||||
# only available when 'enable_ace_debug' set to 'true', show the private logs.
|
||||
enable_ace_private_log = true
|
||||
|
||||
# show the instance id in logs.
|
||||
enable_ace_instance_log = true
|
||||
|
||||
# Disable glfw window to build for PC preview scenario.
|
||||
enable_glfw_window = false
|
||||
}
|
||||
@ -87,6 +97,16 @@ if (use_clang_coverage) {
|
||||
|
||||
if (enable_ace_debug) {
|
||||
ace_common_defines += [ "ACE_DEBUG" ]
|
||||
if (enable_ace_debug_log) {
|
||||
ace_common_defines += [ "ACE_DEBUG_LOG" ]
|
||||
}
|
||||
if (enable_ace_private_log) {
|
||||
ace_common_defines += [ "ACE_PRIVATE_LOG" ]
|
||||
}
|
||||
}
|
||||
|
||||
if (enable_ace_instance_log) {
|
||||
ace_common_defines += [ "ACE_INSTANCE_LOG" ]
|
||||
}
|
||||
|
||||
if (enable_dump_drawcmd) {
|
||||
|
@ -146,7 +146,12 @@ void AceAbility::OnStart(const Want& want)
|
||||
Ability::OnStart(want);
|
||||
LOGI("AceAbility::OnStart called");
|
||||
|
||||
SetHwIcuDirectory();
|
||||
static std::once_flag onceFlag;
|
||||
std::call_once(onceFlag, []() {
|
||||
LOGI("Initialize for current process.");
|
||||
SetHwIcuDirectory();
|
||||
Container::UpdateCurrent(INSTANCE_ID_PLATFORM);
|
||||
});
|
||||
|
||||
std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig());
|
||||
auto resourceManager = GetResourceManager();
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "base/utils/system_properties.h"
|
||||
#include "base/utils/utils.h"
|
||||
#include "core/common/ace_engine.h"
|
||||
#include "core/common/container_scope.h"
|
||||
#include "core/common/flutter/flutter_asset_manager.h"
|
||||
#include "core/common/flutter/flutter_task_executor.h"
|
||||
#include "core/common/hdc_register.h"
|
||||
@ -107,13 +108,13 @@ void AceContainer::InitializeTask()
|
||||
GetSettings().useUIAsJSThread = true;
|
||||
} else {
|
||||
flutterTaskExecutor->InitJsThread();
|
||||
taskExecutor_->PostTask([id = instanceId_]() { Container::InitForThread(id); }, TaskExecutor::TaskType::JS);
|
||||
}
|
||||
SystemProperties::SetDeclarativeFrontend(type_ == FrontendType::DECLARATIVE_JS);
|
||||
}
|
||||
|
||||
void AceContainer::Initialize()
|
||||
{
|
||||
ContainerScope scope(instanceId_);
|
||||
// For DECLARATIVE_JS frontend use UI as JS Thread, so InitializeFrontend after UI thread created.
|
||||
if (type_ != FrontendType::DECLARATIVE_JS) {
|
||||
InitializeFrontend();
|
||||
@ -122,6 +123,7 @@ void AceContainer::Initialize()
|
||||
|
||||
void AceContainer::Destroy()
|
||||
{
|
||||
ContainerScope scope(instanceId_);
|
||||
if (pipelineContext_ && taskExecutor_) {
|
||||
if (taskExecutor_) {
|
||||
// 1. Destroy Pipeline on UI thread.
|
||||
@ -146,6 +148,7 @@ void AceContainer::Destroy()
|
||||
|
||||
void AceContainer::DestroyView()
|
||||
{
|
||||
ContainerScope scope(instanceId_);
|
||||
if (aceView_ != nullptr) {
|
||||
delete aceView_;
|
||||
aceView_ = nullptr;
|
||||
@ -215,6 +218,7 @@ bool AceContainer::OnBackPressed(int32_t instanceId)
|
||||
return false;
|
||||
}
|
||||
|
||||
ContainerScope scope(instanceId);
|
||||
auto context = container->GetPipelineContext();
|
||||
if (!context) {
|
||||
return false;
|
||||
@ -229,6 +233,7 @@ void AceContainer::OnShow(int32_t instanceId)
|
||||
return;
|
||||
}
|
||||
|
||||
ContainerScope scope(instanceId);
|
||||
auto front = container->GetFrontend();
|
||||
if (front) {
|
||||
front->OnShow();
|
||||
@ -246,6 +251,7 @@ void AceContainer::OnHide(int32_t instanceId)
|
||||
if (!container) {
|
||||
return;
|
||||
}
|
||||
ContainerScope scope(instanceId);
|
||||
auto front = container->GetFrontend();
|
||||
if (front) {
|
||||
front->OnHide();
|
||||
@ -268,6 +274,7 @@ void AceContainer::OnActive(int32_t instanceId)
|
||||
return;
|
||||
}
|
||||
|
||||
ContainerScope scope(instanceId);
|
||||
auto front = container->GetFrontend();
|
||||
if (front) {
|
||||
front->OnActive();
|
||||
@ -287,6 +294,7 @@ void AceContainer::OnInactive(int32_t instanceId)
|
||||
return;
|
||||
}
|
||||
|
||||
ContainerScope scope(instanceId);
|
||||
auto front = container->GetFrontend();
|
||||
if (front) {
|
||||
front->OnInactive();
|
||||
@ -306,6 +314,8 @@ bool AceContainer::OnStartContinuation(int32_t instanceId)
|
||||
LOGI("container is null, OnStartContinuation failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
ContainerScope scope(instanceId);
|
||||
auto front = container->GetFrontend();
|
||||
if (!front) {
|
||||
LOGI("front is null, OnStartContinuation failed.");
|
||||
@ -322,6 +332,8 @@ std::string AceContainer::OnSaveData(int32_t instanceId)
|
||||
LOGI("container is null, OnSaveData failed.");
|
||||
return result;
|
||||
}
|
||||
|
||||
ContainerScope scope(instanceId);
|
||||
auto front = container->GetFrontend();
|
||||
if (!front) {
|
||||
LOGI("front is null, OnSaveData failed.");
|
||||
@ -338,6 +350,8 @@ bool AceContainer::OnRestoreData(int32_t instanceId, const std::string& data)
|
||||
LOGI("container is null, OnRestoreData failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
ContainerScope scope(instanceId);
|
||||
auto front = container->GetFrontend();
|
||||
if (!front) {
|
||||
LOGI("front is null, OnRestoreData failed.");
|
||||
@ -353,6 +367,8 @@ void AceContainer::OnCompleteContinuation(int32_t instanceId, int result)
|
||||
LOGI("container is null, OnCompleteContinuation failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
ContainerScope scope(instanceId);
|
||||
auto front = container->GetFrontend();
|
||||
if (!front) {
|
||||
LOGI("front is null, OnCompleteContinuation failed.");
|
||||
@ -368,6 +384,8 @@ void AceContainer::OnRemoteTerminated(int32_t instanceId)
|
||||
LOGI("container is null, OnRemoteTerminated failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
ContainerScope scope(instanceId);
|
||||
auto front = container->GetFrontend();
|
||||
if (!front) {
|
||||
LOGI("front is null, OnRemoteTerminated failed.");
|
||||
@ -383,6 +401,8 @@ void AceContainer::OnConfigurationUpdated(int32_t instanceId, const std::string&
|
||||
LOGI("container is null, OnConfigurationUpdated failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
ContainerScope scope(instanceId);
|
||||
auto front = container->GetFrontend();
|
||||
if (!front) {
|
||||
LOGI("front is null, OnConfigurationUpdated failed.");
|
||||
@ -398,6 +418,7 @@ void AceContainer::OnNewRequest(int32_t instanceId, const std::string& data)
|
||||
return;
|
||||
}
|
||||
|
||||
ContainerScope scope(instanceId);
|
||||
auto front = container->GetFrontend();
|
||||
if (front) {
|
||||
front->OnNewRequest(data);
|
||||
@ -409,13 +430,15 @@ void AceContainer::InitializeCallback()
|
||||
ACE_FUNCTION_TRACE();
|
||||
|
||||
ACE_DCHECK(aceView_ && taskExecutor_ && pipelineContext_);
|
||||
auto&& touchEventCallback = [context = pipelineContext_](const TouchPoint& event) {
|
||||
auto&& touchEventCallback = [context = pipelineContext_, id = instanceId_](const TouchPoint& event) {
|
||||
ContainerScope scope(id);
|
||||
context->GetTaskExecutor()->PostTask(
|
||||
[context, event]() { context->OnTouchEvent(event); }, TaskExecutor::TaskType::UI);
|
||||
};
|
||||
aceView_->RegisterTouchEventCallback(touchEventCallback);
|
||||
|
||||
auto&& keyEventCallback = [context = pipelineContext_](const KeyEvent& event) {
|
||||
auto&& keyEventCallback = [context = pipelineContext_, id = instanceId_](const KeyEvent& event) {
|
||||
ContainerScope scope(id);
|
||||
bool result = false;
|
||||
context->GetTaskExecutor()->PostSyncTask(
|
||||
[context, event, &result]() { result = context->OnKeyEvent(event); }, TaskExecutor::TaskType::UI);
|
||||
@ -423,19 +446,22 @@ void AceContainer::InitializeCallback()
|
||||
};
|
||||
aceView_->RegisterKeyEventCallback(keyEventCallback);
|
||||
|
||||
auto&& mouseEventCallback = [context = pipelineContext_](const MouseEvent& event) {
|
||||
auto&& mouseEventCallback = [context = pipelineContext_, id = instanceId_](const MouseEvent& event) {
|
||||
ContainerScope scope(id);
|
||||
context->GetTaskExecutor()->PostTask(
|
||||
[context, event]() { context->OnMouseEvent(event); }, TaskExecutor::TaskType::UI);
|
||||
};
|
||||
aceView_->RegisterMouseEventCallback(mouseEventCallback);
|
||||
|
||||
auto&& axisEventCallback = [context = pipelineContext_](const AxisEvent& event) {
|
||||
auto&& axisEventCallback = [context = pipelineContext_, id = instanceId_](const AxisEvent& event) {
|
||||
ContainerScope scope(id);
|
||||
context->GetTaskExecutor()->PostTask(
|
||||
[context, event]() { context->OnAxisEvent(event); }, TaskExecutor::TaskType::UI);
|
||||
};
|
||||
aceView_->RegisterAxisEventCallback(axisEventCallback);
|
||||
|
||||
auto&& rotationEventCallback = [context = pipelineContext_](const RotationEvent& event) {
|
||||
auto&& rotationEventCallback = [context = pipelineContext_, id = instanceId_](const RotationEvent& event) {
|
||||
ContainerScope scope(id);
|
||||
bool result = false;
|
||||
context->GetTaskExecutor()->PostSyncTask(
|
||||
[context, event, &result]() { result = context->OnRotationEvent(event); }, TaskExecutor::TaskType::UI);
|
||||
@ -443,21 +469,24 @@ void AceContainer::InitializeCallback()
|
||||
};
|
||||
aceView_->RegisterRotationEventCallback(rotationEventCallback);
|
||||
|
||||
auto&& viewChangeCallback = [context = pipelineContext_](int32_t width, int32_t height) {
|
||||
auto&& viewChangeCallback = [context = pipelineContext_, id = instanceId_](int32_t width, int32_t height) {
|
||||
ContainerScope scope(id);
|
||||
ACE_SCOPED_TRACE("ViewChangeCallback(%d, %d)", width, height);
|
||||
context->GetTaskExecutor()->PostTask(
|
||||
[context, width, height]() { context->OnSurfaceChanged(width, height); }, TaskExecutor::TaskType::UI);
|
||||
};
|
||||
aceView_->RegisterViewChangeCallback(viewChangeCallback);
|
||||
|
||||
auto&& densityChangeCallback = [context = pipelineContext_](double density) {
|
||||
auto&& densityChangeCallback = [context = pipelineContext_, id = instanceId_](double density) {
|
||||
ContainerScope scope(id);
|
||||
ACE_SCOPED_TRACE("DensityChangeCallback(%lf)", density);
|
||||
context->GetTaskExecutor()->PostTask(
|
||||
[context, density]() { context->OnSurfaceDensityChanged(density); }, TaskExecutor::TaskType::UI);
|
||||
};
|
||||
aceView_->RegisterDensityChangeCallback(densityChangeCallback);
|
||||
|
||||
auto&& systemBarHeightChangeCallback = [context = pipelineContext_](double statusBar, double navigationBar) {
|
||||
auto&& systemBarHeightChangeCallback = [context = pipelineContext_, id = instanceId_](double statusBar, double navigationBar) {
|
||||
ContainerScope scope(id);
|
||||
ACE_SCOPED_TRACE("SystemBarHeightChangeCallback(%lf, %lf)", statusBar, navigationBar);
|
||||
context->GetTaskExecutor()->PostTask(
|
||||
[context, statusBar, navigationBar]() { context->OnSystemBarHeightChanged(statusBar, navigationBar); },
|
||||
@ -465,13 +494,15 @@ void AceContainer::InitializeCallback()
|
||||
};
|
||||
aceView_->RegisterSystemBarHeightChangeCallback(systemBarHeightChangeCallback);
|
||||
|
||||
auto&& surfaceDestroyCallback = [context = pipelineContext_]() {
|
||||
auto&& surfaceDestroyCallback = [context = pipelineContext_, id = instanceId_]() {
|
||||
ContainerScope scope(id);
|
||||
context->GetTaskExecutor()->PostTask(
|
||||
[context]() { context->OnSurfaceDestroyed(); }, TaskExecutor::TaskType::UI);
|
||||
};
|
||||
aceView_->RegisterSurfaceDestroyCallback(surfaceDestroyCallback);
|
||||
|
||||
auto&& idleCallback = [context = pipelineContext_](int64_t deadline) {
|
||||
auto&& idleCallback = [context = pipelineContext_, id = instanceId_](int64_t deadline) {
|
||||
ContainerScope scope(id);
|
||||
context->GetTaskExecutor()->PostTask(
|
||||
[context, deadline]() { context->OnIdle(deadline); }, TaskExecutor::TaskType::UI);
|
||||
};
|
||||
@ -488,6 +519,7 @@ void AceContainer::CreateContainer(int32_t instanceId, FrontendType type, bool i
|
||||
|
||||
HdcRegister::Get().StartHdcRegister();
|
||||
aceContainer->Initialize();
|
||||
ContainerScope scope(instanceId);
|
||||
auto front = aceContainer->GetFrontend();
|
||||
if (front) {
|
||||
front->UpdateState(Frontend::State::ON_CREATE);
|
||||
@ -565,6 +597,7 @@ bool AceContainer::RunPage(int32_t instanceId, int32_t pageId, const std::string
|
||||
if (!container) {
|
||||
return false;
|
||||
}
|
||||
ContainerScope scope(instanceId);
|
||||
auto front = container->GetFrontend();
|
||||
if (front) {
|
||||
LOGI("RunPage content=[%{private}s]", content.c_str());
|
||||
@ -580,6 +613,7 @@ bool AceContainer::PushPage(int32_t instanceId, const std::string& content, cons
|
||||
if (!container) {
|
||||
return false;
|
||||
}
|
||||
ContainerScope scope(instanceId);
|
||||
auto front = container->GetFrontend();
|
||||
if (front) {
|
||||
front->PushPage(content, params);
|
||||
@ -594,6 +628,7 @@ bool AceContainer::UpdatePage(int32_t instanceId, int32_t pageId, const std::str
|
||||
if (!container) {
|
||||
return false;
|
||||
}
|
||||
ContainerScope scope(instanceId);
|
||||
auto context = container->GetPipelineContext();
|
||||
if (!context) {
|
||||
return false;
|
||||
@ -615,6 +650,7 @@ void AceContainer::DispatchPluginError(int32_t callbackId, int32_t errorCode, st
|
||||
return;
|
||||
}
|
||||
|
||||
ContainerScope scope(instanceId_);
|
||||
taskExecutor_->PostTask(
|
||||
[front, callbackId, errorCode, errorMessage = std::move(errorMessage)]() mutable {
|
||||
front->TransferJsPluginGetError(callbackId, errorCode, std::move(errorMessage));
|
||||
@ -624,6 +660,7 @@ void AceContainer::DispatchPluginError(int32_t callbackId, int32_t errorCode, st
|
||||
|
||||
bool AceContainer::Dump(const std::vector<std::string>& params)
|
||||
{
|
||||
ContainerScope scope(instanceId_);
|
||||
if (aceView_ && aceView_->Dump(params)) {
|
||||
return true;
|
||||
}
|
||||
@ -637,6 +674,7 @@ bool AceContainer::Dump(const std::vector<std::string>& params)
|
||||
|
||||
void AceContainer::TriggerGarbageCollection()
|
||||
{
|
||||
ContainerScope scope(instanceId_);
|
||||
#if !defined(OHOS_PLATFORM) || !defined(ENABLE_NATIVE_VIEW)
|
||||
// GPU and IO thread is standalone while disable native view
|
||||
taskExecutor_->PostTask([] { PurgeMallocCache(); }, TaskExecutor::TaskType::GPU);
|
||||
@ -693,7 +731,12 @@ void AceContainer::AttachView(
|
||||
ACE_DCHECK(state != nullptr);
|
||||
auto flutterTaskExecutor = AceType::DynamicCast<FlutterTaskExecutor>(taskExecutor_);
|
||||
flutterTaskExecutor->InitOtherThreads(state->GetTaskRunners());
|
||||
taskExecutor_->PostTask([id = instanceId_]() { Container::InitForThread(id); }, TaskExecutor::TaskType::UI);
|
||||
if (GetSettings().usePlatformAsUIThread) {
|
||||
Container::SetScopeNotify([](int32_t id) {
|
||||
flutter::UIDartState::Current()->SetCurInstance(id);
|
||||
});
|
||||
}
|
||||
ContainerScope scope(instanceId);
|
||||
if (type_ == FrontendType::DECLARATIVE_JS) {
|
||||
// For DECLARATIVE_JS frontend display UI in JS thread temporarily.
|
||||
flutterTaskExecutor->InitJsThread(false);
|
||||
@ -717,12 +760,13 @@ void AceContainer::AttachView(
|
||||
pipelineContext_->SetDrawDelegate(aceView_->GetDrawDelegate());
|
||||
InitializeCallback();
|
||||
|
||||
auto&& finishEventHandler = [weak = WeakClaim(this)] {
|
||||
auto&& finishEventHandler = [weak = WeakClaim(this), instanceId] {
|
||||
auto container = weak.Upgrade();
|
||||
if (!container) {
|
||||
LOGE("FinishEventHandler container is null!");
|
||||
return;
|
||||
}
|
||||
ContainerScope scope(instanceId);
|
||||
auto context = container->GetPipelineContext();
|
||||
if (!context) {
|
||||
LOGE("FinishEventHandler context is null!");
|
||||
@ -741,12 +785,13 @@ void AceContainer::AttachView(
|
||||
};
|
||||
pipelineContext_->SetFinishEventHandler(finishEventHandler);
|
||||
|
||||
auto&& setStatusBarEventHandler = [weak = WeakClaim(this)](const Color& color) {
|
||||
auto&& setStatusBarEventHandler = [weak = WeakClaim(this), instanceId](const Color& color) {
|
||||
auto container = weak.Upgrade();
|
||||
if (!container) {
|
||||
LOGE("StatusBarEventHandler container is null!");
|
||||
return;
|
||||
}
|
||||
ContainerScope scope(instanceId);
|
||||
auto context = container->GetPipelineContext();
|
||||
if (!context) {
|
||||
LOGE("StatusBarEventHandler context is null!");
|
||||
@ -805,6 +850,7 @@ void AceContainer::SetFontScale(int32_t instanceId, float fontScale)
|
||||
if (!container) {
|
||||
return;
|
||||
}
|
||||
ContainerScope scope(instanceId);
|
||||
auto pipelineContext = container->GetPipelineContext();
|
||||
if (!pipelineContext) {
|
||||
LOGE("fail to set font style due to context is null");
|
||||
@ -819,6 +865,7 @@ void AceContainer::SetWindowStyle(int32_t instanceId, WindowModal windowModal, C
|
||||
if (!container) {
|
||||
return;
|
||||
}
|
||||
ContainerScope scope(instanceId);
|
||||
container->SetWindowModal(windowModal);
|
||||
container->SetColorScheme(colorScheme);
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "base/utils/system_properties.h"
|
||||
#include "base/utils/utils.h"
|
||||
#include "core/common/ace_engine.h"
|
||||
#include "core/common/container_scope.h"
|
||||
#include "core/components/theme/app_theme.h"
|
||||
#include "core/components/theme/theme_manager.h"
|
||||
#include "core/event/axis_event.h"
|
||||
@ -479,12 +480,19 @@ bool FlutterAceView::IsLastPage() const
|
||||
return false;
|
||||
}
|
||||
|
||||
ContainerScope scope(instanceId_);
|
||||
auto context = container->GetPipelineContext();
|
||||
if (!context) {
|
||||
return false;
|
||||
}
|
||||
auto taskExecutor = context->GetTaskExecutor();
|
||||
|
||||
return context->IsLastPage();
|
||||
bool isLastPage = false;
|
||||
if (taskExecutor) {
|
||||
taskExecutor->PostSyncTask(
|
||||
[context, &isLastPage]() { isLastPage = context->IsLastPage(); }, TaskExecutor::TaskType::UI);
|
||||
}
|
||||
return isLastPage;
|
||||
}
|
||||
|
||||
uint32_t FlutterAceView::GetBackgroundColor()
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "base/utils/utils.h"
|
||||
#include "core/common/ace_application_info.h"
|
||||
#include "core/common/backend.h"
|
||||
#include "core/common/container_scope.h"
|
||||
#include "core/event/ace_event_helper.h"
|
||||
#include "core/event/back_end_event_manager.h"
|
||||
#include "frameworks/bridge/common/dom/dom_type.h"
|
||||
@ -404,7 +405,10 @@ bool QjsPaEngine::Initialize(const RefPtr<BackendDelegate>& delegate)
|
||||
LoadLibrary();
|
||||
nativeEngine_ = new QuickJSNativeEngine(runtime, context, static_cast<void*>(this));
|
||||
ACE_DCHECK(delegate);
|
||||
delegate->AddTaskObserver([nativeEngine = nativeEngine_]() { nativeEngine->Loop(LOOP_NOWAIT); });
|
||||
delegate->AddTaskObserver([nativeEngine = nativeEngine_, id = instanceId_]() {
|
||||
ContainerScope scope(id);
|
||||
nativeEngine->Loop(LOOP_NOWAIT);
|
||||
});
|
||||
|
||||
engineInstance_ = AceType::MakeRefPtr<QjsPaEngineInstance>(delegate, instanceId_);
|
||||
bool ret = engineInstance_->InitJsEnv(runtime, context, GetExtraNativeObject());
|
||||
@ -419,13 +423,14 @@ void QjsPaEngine::SetPostTask(NativeEngine* nativeEngine)
|
||||
{
|
||||
LOGI("SetPostTask");
|
||||
auto weakDelegate = AceType::WeakClaim(AceType::RawPtr(engineInstance_->GetDelegate()));
|
||||
auto&& postTask = [weakDelegate, nativeEngine = nativeEngine_](bool needSync) {
|
||||
auto&& postTask = [weakDelegate, nativeEngine = nativeEngine_, id = instanceId_](bool needSync) {
|
||||
auto delegate = weakDelegate.Upgrade();
|
||||
if (delegate == nullptr) {
|
||||
LOGE("delegate is nullptr");
|
||||
return;
|
||||
}
|
||||
delegate->PostJsTask([nativeEngine, needSync]() {
|
||||
delegate->PostJsTask([nativeEngine, needSync, id]() {
|
||||
ContainerScope scope(id);
|
||||
if (nativeEngine == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "base/log/log.h"
|
||||
#include "base/utils/system_properties.h"
|
||||
#include "core/common/ace_engine.h"
|
||||
#include "core/common/container_scope.h"
|
||||
#include "core/common/flutter/flutter_asset_manager.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
@ -87,7 +88,12 @@ void UIContentImpl::Initialize(OHOS::Rosen::Window* window, const std::string& u
|
||||
return;
|
||||
}
|
||||
LOGI("Initialize UIContentImpl start.");
|
||||
SetHwIcuDirectory();
|
||||
static std::once_flag onceFlag;
|
||||
std::call_once(onceFlag, []() {
|
||||
LOGI("Initialize for current process.");
|
||||
SetHwIcuDirectory();
|
||||
Container::UpdateCurrent(INSTANCE_ID_PLATFORM);
|
||||
});
|
||||
|
||||
std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig());
|
||||
auto resourceManager = context_->GetResourceManager();
|
||||
@ -153,6 +159,7 @@ void UIContentImpl::Initialize(OHOS::Rosen::Window* window, const std::string& u
|
||||
container->GetSettings().SetUsingSharedRuntime(true);
|
||||
container->SetSharedRuntime(runtime_);
|
||||
container->Initialize();
|
||||
ContainerScope scope(instanceId_);
|
||||
auto front = container->GetFrontend();
|
||||
if (front) {
|
||||
front->UpdateState(Frontend::State::ON_CREATE);
|
||||
|
@ -19,6 +19,10 @@
|
||||
|
||||
#include "hilog/log.h"
|
||||
|
||||
#ifdef ACE_INSTANCE_LOG
|
||||
#include "core/common/container.h"
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
int HiLogPrintArgs(LogType type, LogLevel level, unsigned int domain, const char* tag, const char* fmt, va_list ap);
|
||||
}
|
||||
@ -62,8 +66,24 @@ char LogWrapper::GetSeparatorCharacter()
|
||||
|
||||
void LogWrapper::PrintLog(LogDomain domain, LogLevel level, const char* fmt, va_list args)
|
||||
{
|
||||
#ifdef ACE_PRIVATE_LOG
|
||||
std::string newFmt(fmt);
|
||||
ReplaceFormatString("{private}", "{public}", newFmt);
|
||||
HiLogPrintArgs(LOG_TYPES[static_cast<uint32_t>(domain)], LOG_LEVELS[static_cast<uint32_t>(level)],
|
||||
LOG_DOMAINS[static_cast<uint32_t>(domain)], LOG_TAGS[static_cast<uint32_t>(domain)], newFmt.c_str(), args);
|
||||
#else
|
||||
HiLogPrintArgs(LOG_TYPES[static_cast<uint32_t>(domain)], LOG_LEVELS[static_cast<uint32_t>(level)],
|
||||
LOG_DOMAINS[static_cast<uint32_t>(domain)], LOG_TAGS[static_cast<uint32_t>(domain)], fmt, args);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t LogWrapper::GetId()
|
||||
{
|
||||
#ifdef ACE_INSTANCE_LOG
|
||||
return Container::CurrentId();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
|
@ -159,6 +159,11 @@ bool AceAbility::DispatchBackPressedEvent()
|
||||
|
||||
AceAbility::AceAbility(const AceRunArgs& runArgs) : runArgs_(runArgs)
|
||||
{
|
||||
static std::once_flag onceFlag;
|
||||
std::call_once(onceFlag, []() {
|
||||
LOGI("Initialize for current process.");
|
||||
Container::UpdateCurrent(INSTANCE_ID_PLATFORM);
|
||||
});
|
||||
if (runArgs_.formsEnabled) {
|
||||
LOGI("CreateContainer with JS_CARD frontend");
|
||||
AceContainer::CreateContainer(ACE_INSTANCE_ID, FrontendType::JS_CARD);
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "base/utils/utils.h"
|
||||
#include "core/common/ace_engine.h"
|
||||
#include "core/common/ace_view.h"
|
||||
#include "core/common/container_scope.h"
|
||||
#include "core/common/flutter/flutter_asset_manager.h"
|
||||
#include "core/common/flutter/flutter_task_executor.h"
|
||||
#include "core/common/platform_bridge.h"
|
||||
@ -73,12 +74,11 @@ AceContainer::AceContainer(int32_t instanceId, FrontendType type)
|
||||
}
|
||||
SystemProperties::SetDeclarativeFrontend(type_ == FrontendType::DECLARATIVE_JS);
|
||||
taskExecutor_ = flutterTaskExecutor;
|
||||
taskExecutor_->PostTask([instanceId]() { Container::InitForThread(instanceId); }, TaskExecutor::TaskType::JS);
|
||||
taskExecutor_->PostTask([instanceId]() { Container::InitForThread(instanceId); }, TaskExecutor::TaskType::UI);
|
||||
}
|
||||
|
||||
void AceContainer::Initialize()
|
||||
{
|
||||
ContainerScope scope(instanceId_);
|
||||
if (type_ != FrontendType::DECLARATIVE_JS) {
|
||||
InitializeFrontend();
|
||||
}
|
||||
@ -86,6 +86,7 @@ void AceContainer::Initialize()
|
||||
|
||||
void AceContainer::Destroy()
|
||||
{
|
||||
ContainerScope scope(instanceId_);
|
||||
LOGI("AceContainer::Destroy begin");
|
||||
if (!pipelineContext_) {
|
||||
LOGE("no context find in %{private}d container", instanceId_);
|
||||
@ -175,7 +176,8 @@ void AceContainer::InitializeCallback()
|
||||
ACE_DCHECK(aceView_ && taskExecutor_ && pipelineContext_);
|
||||
|
||||
auto weak = AceType::WeakClaim(AceType::RawPtr(pipelineContext_));
|
||||
auto&& touchEventCallback = [weak](const TouchPoint& event) {
|
||||
auto&& touchEventCallback = [weak, id = instanceId_](const TouchPoint& event) {
|
||||
ContainerScope scope(id);
|
||||
auto context = weak.Upgrade();
|
||||
if (context == nullptr) {
|
||||
LOGE("context is nullptr");
|
||||
@ -186,7 +188,8 @@ void AceContainer::InitializeCallback()
|
||||
};
|
||||
aceView_->RegisterTouchEventCallback(touchEventCallback);
|
||||
|
||||
auto&& keyEventCallback = [weak](const KeyEvent& event) {
|
||||
auto&& keyEventCallback = [weak, id = instanceId_](const KeyEvent& event) {
|
||||
ContainerScope scope(id);
|
||||
auto context = weak.Upgrade();
|
||||
if (context == nullptr) {
|
||||
LOGE("context is nullptr");
|
||||
@ -199,7 +202,8 @@ void AceContainer::InitializeCallback()
|
||||
};
|
||||
aceView_->RegisterKeyEventCallback(keyEventCallback);
|
||||
|
||||
auto&& mouseEventCallback = [weak](const MouseEvent& event) {
|
||||
auto&& mouseEventCallback = [weak, id = instanceId_](const MouseEvent& event) {
|
||||
ContainerScope scope(id);
|
||||
auto context = weak.Upgrade();
|
||||
if (context == nullptr) {
|
||||
LOGE("context is nullptr");
|
||||
@ -210,7 +214,8 @@ void AceContainer::InitializeCallback()
|
||||
};
|
||||
aceView_->RegisterMouseEventCallback(mouseEventCallback);
|
||||
|
||||
auto&& axisEventCallback = [weak](const AxisEvent& event) {
|
||||
auto&& axisEventCallback = [weak, id = instanceId_](const AxisEvent& event) {
|
||||
ContainerScope scope(id);
|
||||
auto context = weak.Upgrade();
|
||||
if (context == nullptr) {
|
||||
LOGE("context is nullptr");
|
||||
@ -221,7 +226,8 @@ void AceContainer::InitializeCallback()
|
||||
};
|
||||
aceView_->RegisterAxisEventCallback(axisEventCallback);
|
||||
|
||||
auto&& rotationEventCallback = [weak](const RotationEvent& event) {
|
||||
auto&& rotationEventCallback = [weak, id = instanceId_](const RotationEvent& event) {
|
||||
ContainerScope scope(id);
|
||||
auto context = weak.Upgrade();
|
||||
if (context == nullptr) {
|
||||
LOGE("context is nullptr");
|
||||
@ -234,7 +240,8 @@ void AceContainer::InitializeCallback()
|
||||
};
|
||||
aceView_->RegisterRotationEventCallback(rotationEventCallback);
|
||||
|
||||
auto&& cardViewPositionCallback = [weak](int id, float offsetX, float offsetY) {
|
||||
auto&& cardViewPositionCallback = [weak, instanceId = instanceId_](int id, float offsetX, float offsetY) {
|
||||
ContainerScope scope(instanceId);
|
||||
auto context = weak.Upgrade();
|
||||
if (context == nullptr) {
|
||||
LOGE("context is nullptr");
|
||||
@ -246,7 +253,8 @@ void AceContainer::InitializeCallback()
|
||||
};
|
||||
aceView_->RegisterCardViewPositionCallback(cardViewPositionCallback);
|
||||
|
||||
auto&& cardViewParamsCallback = [weak](const std::string& key, bool focus) {
|
||||
auto&& cardViewParamsCallback = [weak, id = instanceId_](const std::string& key, bool focus) {
|
||||
ContainerScope scope(id);
|
||||
auto context = weak.Upgrade();
|
||||
if (context == nullptr) {
|
||||
LOGE("context is nullptr");
|
||||
@ -258,7 +266,8 @@ void AceContainer::InitializeCallback()
|
||||
};
|
||||
aceView_->RegisterCardViewAccessibilityParamsCallback(cardViewParamsCallback);
|
||||
|
||||
auto&& viewChangeCallback = [weak](int32_t width, int32_t height) {
|
||||
auto&& viewChangeCallback = [weak, id = instanceId_](int32_t width, int32_t height) {
|
||||
ContainerScope scope(id);
|
||||
auto context = weak.Upgrade();
|
||||
if (context == nullptr) {
|
||||
LOGE("context is nullptr");
|
||||
@ -270,7 +279,8 @@ void AceContainer::InitializeCallback()
|
||||
};
|
||||
aceView_->RegisterViewChangeCallback(viewChangeCallback);
|
||||
|
||||
auto&& densityChangeCallback = [weak](double density) {
|
||||
auto&& densityChangeCallback = [weak, id = instanceId_](double density) {
|
||||
ContainerScope scope(id);
|
||||
auto context = weak.Upgrade();
|
||||
if (context == nullptr) {
|
||||
LOGE("context is nullptr");
|
||||
@ -282,7 +292,8 @@ void AceContainer::InitializeCallback()
|
||||
};
|
||||
aceView_->RegisterDensityChangeCallback(densityChangeCallback);
|
||||
|
||||
auto&& systemBarHeightChangeCallback = [weak](double statusBar, double navigationBar) {
|
||||
auto&& systemBarHeightChangeCallback = [weak, id = instanceId_](double statusBar, double navigationBar) {
|
||||
ContainerScope scope(id);
|
||||
auto context = weak.Upgrade();
|
||||
if (context == nullptr) {
|
||||
LOGE("context is nullptr");
|
||||
@ -295,7 +306,8 @@ void AceContainer::InitializeCallback()
|
||||
};
|
||||
aceView_->RegisterSystemBarHeightChangeCallback(systemBarHeightChangeCallback);
|
||||
|
||||
auto&& surfaceDestroyCallback = [weak]() {
|
||||
auto&& surfaceDestroyCallback = [weak, id = instanceId_]() {
|
||||
ContainerScope scope(id);
|
||||
auto context = weak.Upgrade();
|
||||
if (context == nullptr) {
|
||||
LOGE("context is nullptr");
|
||||
@ -306,7 +318,8 @@ void AceContainer::InitializeCallback()
|
||||
};
|
||||
aceView_->RegisterSurfaceDestroyCallback(surfaceDestroyCallback);
|
||||
|
||||
auto&& idleCallback = [weak](int64_t deadline) {
|
||||
auto&& idleCallback = [weak, id = instanceId_](int64_t deadline) {
|
||||
ContainerScope scope(id);
|
||||
auto context = weak.Upgrade();
|
||||
if (context == nullptr) {
|
||||
LOGE("context is nullptr");
|
||||
@ -324,6 +337,7 @@ void AceContainer::CreateContainer(int32_t instanceId, FrontendType type)
|
||||
std::call_once(onceFlag_, [] {
|
||||
FlutterEngineRegisterHandleTouchEventCallback([](std::unique_ptr<flutter::PointerDataPacket>& packet) -> bool {
|
||||
auto container = AceContainer::GetContainerInstance(0);
|
||||
ContainerScope scope(0);
|
||||
if (!container || !container->GetAceView() || !packet) {
|
||||
return false;
|
||||
}
|
||||
@ -331,10 +345,11 @@ void AceContainer::CreateContainer(int32_t instanceId, FrontendType type)
|
||||
});
|
||||
});
|
||||
#endif
|
||||
Container::InitForThread(INSTANCE_ID_PLATFORM);
|
||||
|
||||
auto aceContainer = AceType::MakeRefPtr<AceContainer>(instanceId, type);
|
||||
AceEngine::Get().AddContainer(aceContainer->GetInstanceId(), aceContainer);
|
||||
aceContainer->Initialize();
|
||||
ContainerScope scope(instanceId);
|
||||
auto front = aceContainer->GetFrontend();
|
||||
if (front) {
|
||||
front->UpdateState(Frontend::State::ON_CREATE);
|
||||
@ -368,6 +383,8 @@ bool AceContainer::RunPage(int32_t instanceId, int32_t pageId, const std::string
|
||||
if (!container) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ContainerScope scope(instanceId);
|
||||
auto front = container->GetFrontend();
|
||||
if (front) {
|
||||
auto type = front->GetType();
|
||||
@ -385,6 +402,7 @@ bool AceContainer::RunPage(int32_t instanceId, int32_t pageId, const std::string
|
||||
|
||||
void AceContainer::UpdateResourceConfiguration(const std::string& jsonStr)
|
||||
{
|
||||
ContainerScope scope(instanceId_);
|
||||
uint32_t updateFlags = 0;
|
||||
auto resConfig = resourceInfo_.GetResourceConfiguration();
|
||||
if (!resConfig.UpdateFromJsonString(jsonStr, updateFlags) || !updateFlags) {
|
||||
@ -432,6 +450,7 @@ void AceContainer::NativeOnConfigurationUpdated(int32_t instanceId)
|
||||
if (!container) {
|
||||
return;
|
||||
}
|
||||
ContainerScope scope(instanceId);
|
||||
auto front = container->GetFrontend();
|
||||
if (!front) {
|
||||
return;
|
||||
@ -468,6 +487,7 @@ void AceContainer::FetchResponse(const ResponseData responseData, const int32_t
|
||||
LOGE("FetchResponse container is null!");
|
||||
return;
|
||||
}
|
||||
ContainerScope scope(instanceId_);
|
||||
auto front = container->GetFrontend();
|
||||
auto type = container->GetType();
|
||||
if (type == FrontendType::JS) {
|
||||
@ -493,6 +513,8 @@ void AceContainer::CallCurlFunction(const RequestData requestData, const int32_t
|
||||
LOGE("CallCurlFunction container is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
ContainerScope scope(instanceId_);
|
||||
taskExecutor_->PostTask(
|
||||
[container, requestData, callbackId]() mutable {
|
||||
ResponseData responseData;
|
||||
@ -511,6 +533,7 @@ void AceContainer::DispatchPluginError(int32_t callbackId, int32_t errorCode, st
|
||||
return;
|
||||
}
|
||||
|
||||
ContainerScope scope(instanceId_);
|
||||
taskExecutor_->PostTask(
|
||||
[front, callbackId, errorCode, errorMessage = std::move(errorMessage)]() mutable {
|
||||
front->TransferJsPluginGetError(callbackId, errorCode, std::move(errorMessage));
|
||||
@ -520,6 +543,7 @@ void AceContainer::DispatchPluginError(int32_t callbackId, int32_t errorCode, st
|
||||
|
||||
bool AceContainer::Dump(const std::vector<std::string>& params)
|
||||
{
|
||||
ContainerScope scope(instanceId_);
|
||||
if (aceView_ && aceView_->Dump(params)) {
|
||||
return true;
|
||||
}
|
||||
@ -537,6 +561,7 @@ void AceContainer::AddRouterChangeCallback(int32_t instanceId, const OnRouterCha
|
||||
if (!container) {
|
||||
return;
|
||||
}
|
||||
ContainerScope scope(instanceId);
|
||||
if (!container->pipelineContext_) {
|
||||
LOGE("container pipelineContext not init");
|
||||
return;
|
||||
@ -581,6 +606,7 @@ void AceContainer::SetResourcesPathAndThemeStyle(int32_t instanceId, const std::
|
||||
if (!container) {
|
||||
return;
|
||||
}
|
||||
ContainerScope scope(instanceId);
|
||||
auto resConfig = container->resourceInfo_.GetResourceConfiguration();
|
||||
resConfig.SetColorMode(static_cast<OHOS::Ace::ColorMode>(colorMode));
|
||||
container->resourceInfo_.SetResourceConfiguration(resConfig);
|
||||
@ -591,6 +617,7 @@ void AceContainer::SetResourcesPathAndThemeStyle(int32_t instanceId, const std::
|
||||
|
||||
void AceContainer::UpdateColorMode(ColorMode newColorMode)
|
||||
{
|
||||
ContainerScope scope(instanceId_);
|
||||
auto resConfig = resourceInfo_.GetResourceConfiguration();
|
||||
|
||||
OHOS::Ace::ColorMode colorMode = static_cast<OHOS::Ace::ColorMode>(newColorMode);
|
||||
@ -654,6 +681,7 @@ void AceContainer::SetView(FlutterAceView* view, double density, int32_t width,
|
||||
void AceContainer::AttachView(
|
||||
std::unique_ptr<Window> window, FlutterAceView* view, double density, int32_t width, int32_t height)
|
||||
{
|
||||
ContainerScope scope(instanceId_);
|
||||
aceView_ = view;
|
||||
auto instanceId = aceView_->GetInstanceId();
|
||||
|
||||
@ -661,7 +689,6 @@ void AceContainer::AttachView(
|
||||
ACE_DCHECK(state != nullptr);
|
||||
auto flutterTaskExecutor = AceType::DynamicCast<FlutterTaskExecutor>(taskExecutor_);
|
||||
flutterTaskExecutor->InitOtherThreads(state->GetTaskRunners());
|
||||
taskExecutor_->PostTask([id = instanceId_]() { Container::InitForThread(id); }, TaskExecutor::TaskType::UI);
|
||||
if (type_ == FrontendType::DECLARATIVE_JS) {
|
||||
// For DECLARATIVE_JS frontend display UI in JS thread temporarily.
|
||||
flutterTaskExecutor->InitJsThread(false);
|
||||
@ -737,6 +764,7 @@ void AceContainer::AttachView(
|
||||
|
||||
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);
|
||||
|
@ -30,6 +30,11 @@ namespace {
|
||||
constexpr uint32_t MAX_BUFFER_SIZE = 4000;
|
||||
constexpr uint32_t MAX_TIME_SIZE = 32;
|
||||
const char* const LOGLEVELNAME[] = { "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" };
|
||||
#ifdef ACE_PRIVATE_LOG
|
||||
const bool ENABLE_SEC_LOG = false;
|
||||
#else
|
||||
const bool ENABLE_SEC_LOG = true;
|
||||
#endif
|
||||
|
||||
const char* LOG_TAGS[] = {
|
||||
"Ace",
|
||||
@ -72,7 +77,7 @@ void LogWrapper::PrintLog(LogDomain domain, LogLevel level, const char* fmt, va_
|
||||
std::string newFmt(fmt);
|
||||
|
||||
char buf[MAX_BUFFER_SIZE];
|
||||
if (vsnprintfp_s(buf, sizeof(buf), sizeof(buf) - 1, true, newFmt.c_str(), args) < 0 && errno == EINVAL) {
|
||||
if (vsnprintfp_s(buf, sizeof(buf), sizeof(buf) - 1, ENABLE_SEC_LOG, newFmt.c_str(), args) < 0 && errno == EINVAL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -95,4 +100,9 @@ void LogWrapper::PrintLog(LogDomain domain, LogLevel level, const char* fmt, va_
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int32_t LogWrapper::GetId()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
|
@ -22,16 +22,24 @@
|
||||
|
||||
#include "base/utils/macros.h"
|
||||
|
||||
#define PRINT_LOG(level, fmt, ...) \
|
||||
do { \
|
||||
if (OHOS::Ace::LogWrapper::JudgeLevel(OHOS::Ace::LogLevel::level)) { \
|
||||
OHOS::Ace::LogWrapper::PrintLog(OHOS::Ace::LogDomain::FRAMEWORK, OHOS::Ace::LogLevel::level, \
|
||||
"[%{public}-20s(%{public}s)] " fmt, OHOS::Ace::LogWrapper::GetBriefFileName(__FILE__), \
|
||||
__FUNCTION__, ##__VA_ARGS__); \
|
||||
} \
|
||||
#ifdef ACE_INSTANCE_LOG
|
||||
#define ACE_FMT_PREFIX "[%{private}s(%{private}s)-(%{public}d)] "
|
||||
#define ACE_LOG_ID ,OHOS::Ace::LogWrapper::GetId()
|
||||
#else
|
||||
#define ACE_FMT_PREFIX "[%{private}s(%{private}s)] "
|
||||
#define ACE_LOG_ID
|
||||
#endif
|
||||
|
||||
#define PRINT_LOG(level, fmt, ...) \
|
||||
do { \
|
||||
if (OHOS::Ace::LogWrapper::JudgeLevel(OHOS::Ace::LogLevel::level)) { \
|
||||
OHOS::Ace::LogWrapper::PrintLog(OHOS::Ace::LogDomain::FRAMEWORK, OHOS::Ace::LogLevel::level, \
|
||||
ACE_FMT_PREFIX fmt, OHOS::Ace::LogWrapper::GetBriefFileName(__FILE__), __FUNCTION__ ACE_LOG_ID, \
|
||||
##__VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#ifdef ACE_DEBUG
|
||||
#ifdef ACE_DEBUG_LOG
|
||||
#define LOGD(fmt, ...) PRINT_LOG(DEBUG, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LOGD(fmt, ...)
|
||||
@ -99,6 +107,13 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static void ReplaceFormatString(const std::string& prefix, const std::string& replace, std::string& str)
|
||||
{
|
||||
for (auto pos = str.find(prefix, 0); pos != std::string::npos; pos = str.find(prefix, pos)) {
|
||||
str.replace(pos, prefix.size(), replace);
|
||||
}
|
||||
}
|
||||
|
||||
static void PrintLog(LogDomain domain, LogLevel level, const char* fmt, ...)
|
||||
__attribute__((__format__(os_log, 3, 4)))
|
||||
{
|
||||
@ -111,6 +126,7 @@ public:
|
||||
// MUST implement these interface on each platform.
|
||||
static char GetSeparatorCharacter();
|
||||
static void PrintLog(LogDomain domain, LogLevel level, const char* fmt, va_list args);
|
||||
static int32_t GetId();
|
||||
|
||||
private:
|
||||
LogWrapper() = delete;
|
||||
|
@ -68,6 +68,34 @@ public:
|
||||
return PostDelayedTask(task, type, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a task to the specified thread with a trace id.
|
||||
*
|
||||
* @param task Task which need execution.
|
||||
* @param type FrontendType of task, used to specify the thread.
|
||||
* @param id The id to trace the task.
|
||||
* @return Returns 'true' whether task has been post successfully.
|
||||
*/
|
||||
bool PostTaskWithTraceId(Task&& task, TaskType type, int32_t id) const
|
||||
{
|
||||
Task wrappedTask = WrapTaskWithTraceId(std::move(task), id);
|
||||
return PostDelayedTask(std::move(wrappedTask), type, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a task to the specified thread.
|
||||
*
|
||||
* @param task Task which need execution.
|
||||
* @param type FrontendType of task, used to specify the thread.
|
||||
* @param id The id to trace the task.
|
||||
* @return Returns 'true' if task has been posted successfully.
|
||||
*/
|
||||
bool PostTaskWithTraceId(const Task& task, TaskType type, int32_t id) const
|
||||
{
|
||||
Task wrappedTask = WrapTaskWithTraceId(Task(task), id);
|
||||
return PostDelayedTask(std::move(wrappedTask), type, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a delayed task to the specified thread.
|
||||
* Never allow to post a background delayed task.
|
||||
@ -172,6 +200,7 @@ protected:
|
||||
TaskExecutor() = default;
|
||||
|
||||
virtual bool OnPostTask(Task&& task, TaskType type, uint32_t delayTime) const = 0;
|
||||
virtual Task WrapTaskWithTraceId(Task&& task, int32_t id) const = 0;
|
||||
|
||||
#ifdef ACE_DEBUG
|
||||
virtual bool OnPreSyncTask(TaskType type) const
|
||||
|
@ -70,7 +70,7 @@ void ManifestParser::Parse(const std::string& contents)
|
||||
|
||||
void ManifestParser::Printer()
|
||||
{
|
||||
#ifdef ACE_DEBUG
|
||||
#ifdef ACE_DEBUG_LOG
|
||||
LOGD("appinfo:{");
|
||||
LOGD(" Icon:%{private}s", manifestAppInfo_->GetIcon().c_str());
|
||||
LOGD(" LogLevel:%{public}s", manifestAppInfo_->GetLogLevel().c_str());
|
||||
@ -89,16 +89,6 @@ void ManifestParser::Printer()
|
||||
}
|
||||
LOGD("}");
|
||||
|
||||
if (manifestWidget_->GetWidgetNum() > 0) {
|
||||
LOGD("widgets:{");
|
||||
for (const auto& widget : manifestWidget_->GetWidgetList()) {
|
||||
LOGD(" {");
|
||||
LOGD(" WidgetName:%{public}s", widget.second->GetWidgetName().c_str());
|
||||
LOGD(" WidgetPath:%{public}s", widget.second->GetWidgetPath().c_str());
|
||||
LOGD(" }");
|
||||
}
|
||||
LOGD("}");
|
||||
}
|
||||
manifestWindow_->PrintInfo();
|
||||
#endif
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "core/common/ace_application_info.h"
|
||||
#include "core/common/ace_view.h"
|
||||
#include "core/common/container.h"
|
||||
#include "core/common/container_scope.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/js_ref_ptr.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/js_types.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/ark_js_runtime.h"
|
||||
@ -831,13 +832,14 @@ void JsiDeclarativeEngine::SetPostTask(NativeEngine* nativeEngine)
|
||||
{
|
||||
LOGI("SetPostTask");
|
||||
auto weakDelegate = AceType::WeakClaim(AceType::RawPtr(engineInstance_->GetDelegate()));
|
||||
auto&& postTask = [weakDelegate, nativeEngine = nativeEngine_](bool needSync) {
|
||||
auto&& postTask = [weakDelegate, nativeEngine = nativeEngine_, id = instanceId_](bool needSync) {
|
||||
auto delegate = weakDelegate.Upgrade();
|
||||
if (delegate == nullptr) {
|
||||
LOGE("delegate is nullptr");
|
||||
return;
|
||||
}
|
||||
delegate->PostJsTask([nativeEngine, needSync]() {
|
||||
delegate->PostJsTask([nativeEngine, needSync, id]() {
|
||||
ContainerScope scope(id);
|
||||
if (nativeEngine == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "base/log/ace_trace.h"
|
||||
#include "base/log/event_report.h"
|
||||
#include "base/log/log.h"
|
||||
#include "core/common/container_scope.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/quickjs/modules/qjs_module_manager.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/quickjs/qjs_helpers.h"
|
||||
#include "frameworks/bridge/declarative_frontend/frontend_delegate_declarative.h"
|
||||
@ -91,13 +92,14 @@ void QJSDeclarativeEngine::SetPostTask(NativeEngine* nativeEngine)
|
||||
{
|
||||
LOGI("SetPostTask");
|
||||
auto weakDelegate = AceType::WeakClaim(AceType::RawPtr(engineInstance_->GetDelegate()));
|
||||
auto&& postTask = [weakDelegate, nativeEngine = nativeEngine_](bool needSync) {
|
||||
auto&& postTask = [weakDelegate, nativeEngine = nativeEngine_, id = instanceId_](bool needSync) {
|
||||
auto delegate = weakDelegate.Upgrade();
|
||||
if (delegate == nullptr) {
|
||||
LOGE("delegate is nullptr");
|
||||
return;
|
||||
}
|
||||
delegate->PostJsTask([nativeEngine, needSync]() {
|
||||
delegate->PostJsTask([nativeEngine, needSync, id]() {
|
||||
ContainerScope scope(id);
|
||||
if (nativeEngine == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
@ -913,16 +913,17 @@ void V8DeclarativeEngine::SetPostTask(NativeEngine* nativeEngine)
|
||||
{
|
||||
LOGI("SetPostTask");
|
||||
auto weakDelegate = AceType::WeakClaim(AceType::RawPtr(engineInstance_->GetDelegate()));
|
||||
auto&& postTask = [weakDelegate, nativeEngine = nativeEngine_](bool needSync) {
|
||||
auto&& postTask = [weakDelegate, nativeEngine = nativeEngine_, id = instanceId_](bool needSync) {
|
||||
auto delegate = weakDelegate.Upgrade();
|
||||
if (delegate == nullptr) {
|
||||
LOGE("delegate is nullptr");
|
||||
return;
|
||||
}
|
||||
delegate->PostJsTask([nativeEngine, needSync]() {
|
||||
delegate->PostJsTask([nativeEngine, needSync, id]() {
|
||||
if (nativeEngine == nullptr) {
|
||||
return;
|
||||
}
|
||||
ContainerScope scope(id);
|
||||
nativeEngine->Loop(LOOP_NOWAIT, needSync);
|
||||
});
|
||||
};
|
||||
|
@ -465,7 +465,7 @@ void ViewStackProcessor::PopContainer()
|
||||
Pop();
|
||||
}
|
||||
|
||||
#ifdef ACE_DEBUG
|
||||
#ifdef ACE_DEBUG_LOG
|
||||
void ViewStackProcessor::DumpStack()
|
||||
{
|
||||
LOGD("| stack size: \033[0;33m %{public}d \033[0m", (int)componentsStack_.size());
|
||||
|
@ -149,7 +149,7 @@ private:
|
||||
|
||||
bool ShouldPopImmediately();
|
||||
|
||||
#ifdef ACE_DEBUG
|
||||
#ifdef ACE_DEBUG_LOG
|
||||
// Dump view stack comtent
|
||||
void DumpStack();
|
||||
#endif
|
||||
|
@ -31,7 +31,7 @@ ohos_shared_library("ark_debugger") {
|
||||
"BOOST_CLANG",
|
||||
]
|
||||
|
||||
defines += ace_common_defines
|
||||
defines += [ "ACE_LOG_TAG=\"ArkDebugger\"" ]
|
||||
|
||||
external_deps = hilog_deps
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "bridge/js_frontend/engine/jsi/ark_js_value.h"
|
||||
#include "core/common/ace_application_info.h"
|
||||
#include "core/common/container.h"
|
||||
#include "core/common/container_scope.h"
|
||||
#include "core/components/common/layout/grid_system_manager.h"
|
||||
#include "frameworks/bridge/common/utils/utils.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/common/js_api_perf.h"
|
||||
@ -3048,16 +3049,17 @@ void JsiEngine::SetPostTask(NativeEngine* nativeEngine)
|
||||
{
|
||||
LOGI("SetPostTask");
|
||||
auto weakDelegate = AceType::WeakClaim(AceType::RawPtr(engineInstance_->GetDelegate()));
|
||||
auto&& postTask = [weakDelegate, nativeEngine = nativeEngine_](bool needSync) {
|
||||
auto&& postTask = [weakDelegate, nativeEngine = nativeEngine_, id = instanceId_](bool needSync) {
|
||||
auto delegate = weakDelegate.Upgrade();
|
||||
if (delegate == nullptr) {
|
||||
LOGE("delegate is nullptr");
|
||||
return;
|
||||
}
|
||||
delegate->PostJsTask([nativeEngine, needSync]() {
|
||||
delegate->PostJsTask([nativeEngine, needSync, id]() {
|
||||
if (nativeEngine == nullptr) {
|
||||
return;
|
||||
}
|
||||
ContainerScope scope(id);
|
||||
nativeEngine->Loop(LOOP_NOWAIT, needSync);
|
||||
});
|
||||
};
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "base/utils/utils.h"
|
||||
#include "core/common/ace_application_info.h"
|
||||
#include "core/common/container.h"
|
||||
#include "core/common/container_scope.h"
|
||||
#include "core/event/ace_event_helper.h"
|
||||
#include "core/event/back_end_event_manager.h"
|
||||
#include "frameworks/bridge/common/dom/dom_type.h"
|
||||
@ -3119,13 +3120,14 @@ void QjsEngine::SetPostTask(NativeEngine* nativeEngine)
|
||||
{
|
||||
LOGI("SetPostTask");
|
||||
auto weakDelegate = AceType::WeakClaim(AceType::RawPtr(engineInstance_->GetDelegate()));
|
||||
auto&& postTask = [weakDelegate, nativeEngine = nativeEngine_](bool needSync) {
|
||||
auto&& postTask = [weakDelegate, nativeEngine = nativeEngine_, id = instanceId_](bool needSync) {
|
||||
auto delegate = weakDelegate.Upgrade();
|
||||
if (delegate == nullptr) {
|
||||
LOGE("delegate is nullptr");
|
||||
return;
|
||||
}
|
||||
delegate->PostJsTask([nativeEngine, needSync]() {
|
||||
delegate->PostJsTask([nativeEngine, needSync, id]() {
|
||||
ContainerScope scope(id);
|
||||
if (nativeEngine == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "base/utils/system_properties.h"
|
||||
#include "base/utils/time_util.h"
|
||||
#include "core/common/container.h"
|
||||
#include "core/common/container_scope.h"
|
||||
#include "core/common/thread_checker.h"
|
||||
#include "core/components/common/layout/grid_system_manager.h"
|
||||
#include "frameworks/bridge/common/dom/dom_type.h"
|
||||
@ -3676,13 +3677,14 @@ void V8Engine::SetPostTask()
|
||||
LOGI("SetPostTask");
|
||||
auto weakDelegate = AceType::WeakClaim(AceType::RawPtr(engineInstance_->GetDelegate()));
|
||||
std::weak_ptr<V8NativeEngine> weakNativeEngine(nativeEngine_);
|
||||
auto&& postTask = [weakDelegate, weakNativeEngine](bool needSync) {
|
||||
auto&& postTask = [weakDelegate, weakNativeEngine, id = instanceId_](bool needSync) {
|
||||
auto delegate = weakDelegate.Upgrade();
|
||||
if (delegate == nullptr) {
|
||||
LOGE("delegate is nullptr");
|
||||
return;
|
||||
}
|
||||
delegate->PostJsTask([weakNativeEngine, needSync]() {
|
||||
delegate->PostJsTask([weakNativeEngine, needSync, id]() {
|
||||
ContainerScope scope(id);
|
||||
auto nativeEngine = weakNativeEngine.lock();
|
||||
if (!nativeEngine) {
|
||||
LOGE("native v8 engine weak pointer invalid");
|
||||
|
@ -20,6 +20,7 @@
|
||||
namespace OHOS::Ace {
|
||||
|
||||
thread_local int32_t Container::currentId_ = INSTANCE_ID_UNDEFINED;
|
||||
std::function<void(int32_t)> Container::updateScopeNotify_;
|
||||
|
||||
int32_t Container::CurrentId()
|
||||
{
|
||||
@ -40,10 +41,17 @@ RefPtr<TaskExecutor> Container::CurrentTaskExecutor()
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Container::InitForThread(int32_t id)
|
||||
void Container::SetScopeNotify(std::function<void(int32_t)>&& notify)
|
||||
{
|
||||
updateScopeNotify_ = std::move(notify);
|
||||
}
|
||||
|
||||
void Container::UpdateCurrent(int32_t id)
|
||||
{
|
||||
LOGI("InitForThread id:%{public}d", id);
|
||||
currentId_ = id;
|
||||
if (updateScopeNotify_) {
|
||||
updateScopeNotify_(id);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace
|
@ -147,7 +147,8 @@ public:
|
||||
static int32_t CurrentId();
|
||||
static RefPtr<Container> Current();
|
||||
static RefPtr<TaskExecutor> CurrentTaskExecutor();
|
||||
static void InitForThread(int32_t id);
|
||||
static void SetScopeNotify(std::function<void(int32_t)>&& notify);
|
||||
static void UpdateCurrent(int32_t id);
|
||||
|
||||
protected:
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> createTime_;
|
||||
@ -156,6 +157,7 @@ protected:
|
||||
|
||||
private:
|
||||
static thread_local int32_t currentId_;
|
||||
static std::function<void(int32_t)> updateScopeNotify_;
|
||||
std::string moduleName_;
|
||||
Settings settings_;
|
||||
ACE_DISALLOW_COPY_AND_MOVE(Container);
|
||||
|
45
frameworks/core/common/container_scope.h
Normal file
45
frameworks/core/common/container_scope.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_CONTAINER_SCOPE_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_CONTAINER_SCOPE_H
|
||||
|
||||
#include "core/common/container.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
|
||||
class ACE_EXPORT ContainerScope {
|
||||
|
||||
public:
|
||||
ContainerScope(int32_t id)
|
||||
{
|
||||
restoreId_ = Container::CurrentId();
|
||||
Container::UpdateCurrent(id);
|
||||
}
|
||||
|
||||
~ContainerScope()
|
||||
{
|
||||
Container::UpdateCurrent(restoreId_);
|
||||
}
|
||||
|
||||
private:
|
||||
int32_t restoreId_;
|
||||
|
||||
ACE_DISALLOW_COPY_AND_MOVE(ContainerScope);
|
||||
};
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_CONTAINER_SCOPE_H
|
@ -36,6 +36,7 @@
|
||||
|
||||
#include "base/log/log.h"
|
||||
#include "base/thread/background_task_executor.h"
|
||||
#include "core/common/container_scope.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
namespace {
|
||||
@ -49,6 +50,15 @@ inline std::string GenJsThreadName()
|
||||
return std::string("jsThread-") + std::to_string(instanceCount.fetch_add(1, std::memory_order_relaxed));
|
||||
}
|
||||
|
||||
TaskExecutor::Task WrapTaskWithContainer(TaskExecutor::Task&& task, int32_t id)
|
||||
{
|
||||
auto wrappedTask = [originTask = std::move(task), id]() {
|
||||
ContainerScope scope(id);
|
||||
originTask();
|
||||
};
|
||||
return wrappedTask;
|
||||
}
|
||||
|
||||
bool PostTaskToTaskRunner(const fml::RefPtr<fml::TaskRunner>& taskRunner, TaskExecutor::Task&& task, uint32_t delayTime)
|
||||
{
|
||||
if (!taskRunner || !task) {
|
||||
@ -156,25 +166,33 @@ void FlutterTaskExecutor::InitOtherThreads(const flutter::TaskRunners& taskRunne
|
||||
|
||||
bool FlutterTaskExecutor::OnPostTask(Task&& task, TaskType type, uint32_t delayTime) const
|
||||
{
|
||||
int32_t currentId = Container::CurrentId();
|
||||
TaskExecutor::Task wrappedTask = currentId >= 0 ? WrapTaskWithContainer(std::move(task), currentId) : std::move(task);
|
||||
|
||||
switch (type) {
|
||||
case TaskType::PLATFORM:
|
||||
return PostTaskToTaskRunner(platformRunner_, std::move(task), delayTime);
|
||||
return PostTaskToTaskRunner(platformRunner_, std::move(wrappedTask), delayTime);
|
||||
case TaskType::UI:
|
||||
return PostTaskToTaskRunner(uiRunner_, std::move(task), delayTime);
|
||||
return PostTaskToTaskRunner(uiRunner_, std::move(wrappedTask), delayTime);
|
||||
case TaskType::IO:
|
||||
return PostTaskToTaskRunner(ioRunner_, std::move(task), delayTime);
|
||||
return PostTaskToTaskRunner(ioRunner_, std::move(wrappedTask), delayTime);
|
||||
case TaskType::GPU:
|
||||
return PostTaskToTaskRunner(gpuRunner_, std::move(task), delayTime);
|
||||
return PostTaskToTaskRunner(gpuRunner_, std::move(wrappedTask), delayTime);
|
||||
case TaskType::JS:
|
||||
return PostTaskToTaskRunner(jsRunner_, std::move(task), delayTime);
|
||||
return PostTaskToTaskRunner(jsRunner_, std::move(wrappedTask), delayTime);
|
||||
case TaskType::BACKGROUND:
|
||||
// Ignore delay time
|
||||
return BackgroundTaskExecutor::GetInstance().PostTask(std::move(task));
|
||||
return BackgroundTaskExecutor::GetInstance().PostTask(std::move(wrappedTask));
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
TaskExecutor::Task FlutterTaskExecutor::WrapTaskWithTraceId(Task&& task, int32_t id) const
|
||||
{
|
||||
return WrapTaskWithContainer(std::move(task), id);
|
||||
}
|
||||
|
||||
bool FlutterTaskExecutor::WillRunOnCurrentThread(TaskType type) const
|
||||
{
|
||||
switch (type) {
|
||||
|
@ -48,6 +48,7 @@ public:
|
||||
|
||||
private:
|
||||
bool OnPostTask(Task&& task, TaskType type, uint32_t delayTime) const final;
|
||||
Task WrapTaskWithTraceId(Task&& task, int32_t id) const final;
|
||||
|
||||
#ifdef ACE_DEBUG
|
||||
bool OnPreSyncTask(TaskType type) const final;
|
||||
|
@ -29,7 +29,7 @@ ohos_shared_library("hdc_register") {
|
||||
deps = []
|
||||
defines = [ "JS_JDWP_CONNECT" ]
|
||||
|
||||
defines += ace_common_defines
|
||||
defines += [ "ACE_LOG_TAG=\"HdcRegister\"" ]
|
||||
|
||||
external_deps = hilog_deps
|
||||
|
||||
|
@ -16,8 +16,10 @@
|
||||
#include "core/image/image_object.h"
|
||||
|
||||
#include "base/thread/background_task_executor.h"
|
||||
#include "core/common/container_scope.h"
|
||||
#include "core/components/image/render_image.h"
|
||||
#include "core/image/flutter_image_cache.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
|
||||
std::string ImageObject::GenerateCacheKey(const std::string& src, Size targetImageSize)
|
||||
@ -108,8 +110,9 @@ void StaticImageObject::UploadToGpuForRender(
|
||||
bool forceResize,
|
||||
bool syncMode)
|
||||
{
|
||||
auto task = [ context, renderTaskHolder, successCallback, failedCallback,
|
||||
imageSize, forceResize, skData = skData_, imageSource = imageSource_] () mutable {
|
||||
auto task = [context, renderTaskHolder, successCallback, failedCallback, imageSize, forceResize, skData = skData_,
|
||||
imageSource = imageSource_, id = Container::CurrentId()]() mutable {
|
||||
ContainerScope scope(id);
|
||||
auto pipelineContext = context.Upgrade();
|
||||
if (!pipelineContext) {
|
||||
LOGE("pipline context has been released.");
|
||||
|
@ -20,10 +20,12 @@
|
||||
#include "third_party/skia/include/core/SkStream.h"
|
||||
|
||||
#include "base/thread/background_task_executor.h"
|
||||
#include "core/common/container_scope.h"
|
||||
#include "core/components/image/flutter_render_image.h"
|
||||
#include "core/event/ace_event_helper.h"
|
||||
#include "core/image/flutter_image_cache.h"
|
||||
#include "core/image/image_object.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
namespace {
|
||||
|
||||
@ -45,8 +47,9 @@ void ImageProvider::FetchImageObject(
|
||||
RefPtr<FlutterRenderTaskHolder>& renderTaskHolder,
|
||||
OnPostBackgroundTask onBackgroundTaskPostCallback)
|
||||
{
|
||||
auto task = [ context, imageInfo, successCallback, failedCallback, useSkiaSvg, renderTaskHolder,
|
||||
uploadSuccessCallback, needAutoResize] () mutable {
|
||||
auto task = [context, imageInfo, successCallback, failedCallback, useSkiaSvg, renderTaskHolder,
|
||||
uploadSuccessCallback, needAutoResize, id = Container::CurrentId()]() mutable {
|
||||
ContainerScope scope(id);
|
||||
auto pipelineContext = context.Upgrade();
|
||||
if (!pipelineContext) {
|
||||
LOGE("pipline context has been released. imageInfo: %{private}s", imageInfo.ToString().c_str());
|
||||
@ -62,11 +65,11 @@ void ImageProvider::FetchImageObject(
|
||||
imageObj = GeneraterAceImageObject(imageInfo, pipelineContext, useSkiaSvg);
|
||||
}
|
||||
if (!imageObj) { // if it fails to generate an image object, trigger fail callback.
|
||||
taskExecutor->PostTask([failedCallback, imageInfo] { failedCallback(imageInfo); },
|
||||
TaskExecutor::TaskType::UI);
|
||||
taskExecutor->PostTask(
|
||||
[failedCallback, imageInfo] { failedCallback(imageInfo); }, TaskExecutor::TaskType::UI);
|
||||
return;
|
||||
}
|
||||
taskExecutor->PostTask([ successCallback, imageInfo, imageObj ] () { successCallback(imageInfo, imageObj); },
|
||||
taskExecutor->PostTask([successCallback, imageInfo, imageObj]() { successCallback(imageInfo, imageObj); },
|
||||
TaskExecutor::TaskType::UI);
|
||||
bool canStartUploadImageObj = !needAutoResize && (imageObj->GetFrameCount() == 1);
|
||||
if (canStartUploadImageObj) {
|
||||
@ -161,7 +164,8 @@ void ImageProvider::GetSVGImageDOMAsyncFromSrc(
|
||||
uint64_t svgThemeColor,
|
||||
OnPostBackgroundTask onBackgroundTaskPostCallback)
|
||||
{
|
||||
auto task = [ src, successCallback, failedCallback, context, svgThemeColor ] {
|
||||
auto task = [src, successCallback, failedCallback, context, svgThemeColor, id = Container::CurrentId()] {
|
||||
ContainerScope scope(id);
|
||||
auto pipelineContext = context.Upgrade();
|
||||
if (!pipelineContext) {
|
||||
LOGW("render image or pipeline has been released. src: %{private}s", src.c_str());
|
||||
@ -207,7 +211,8 @@ void ImageProvider::GetSVGImageDOMAsyncFromData(
|
||||
uint64_t svgThemeColor,
|
||||
OnPostBackgroundTask onBackgroundTaskPostCallback)
|
||||
{
|
||||
auto task = [ skData, successCallback, failedCallback, context, svgThemeColor ] {
|
||||
auto task = [skData, successCallback, failedCallback, context, svgThemeColor, id = Container::CurrentId()] {
|
||||
ContainerScope scope(id);
|
||||
auto pipelineContext = context.Upgrade();
|
||||
if (!pipelineContext) {
|
||||
LOGW("render image or pipeline has been released.");
|
||||
@ -396,18 +401,20 @@ sk_sp<SkImage> ImageProvider::GetSkImage(
|
||||
void ImageProvider::TryLoadImageInfo(const RefPtr<PipelineContext>& context, const std::string& src,
|
||||
std::function<void(bool, int32_t, int32_t)>&& loadCallback)
|
||||
{
|
||||
BackgroundTaskExecutor::GetInstance().PostTask([src, callback = std::move(loadCallback), context]() {
|
||||
auto taskExecutor = context->GetTaskExecutor();
|
||||
if (!taskExecutor) {
|
||||
return;
|
||||
}
|
||||
auto image = ImageProvider::GetSkImage(src, context);
|
||||
if (image) {
|
||||
callback(true, image->width(), image->height());
|
||||
return;
|
||||
}
|
||||
callback(false, 0, 0);
|
||||
});
|
||||
BackgroundTaskExecutor::GetInstance().PostTask(
|
||||
[src, callback = std::move(loadCallback), context, id = Container::CurrentId()]() {
|
||||
ContainerScope scope(id);
|
||||
auto taskExecutor = context->GetTaskExecutor();
|
||||
if (!taskExecutor) {
|
||||
return;
|
||||
}
|
||||
auto image = ImageProvider::GetSkImage(src, context);
|
||||
if (image) {
|
||||
callback(true, image->width(), image->height());
|
||||
return;
|
||||
}
|
||||
callback(false, 0, 0);
|
||||
});
|
||||
}
|
||||
|
||||
bool ImageProvider::IsWideGamut(const sk_sp<SkColorSpace>& colorSpace)
|
||||
|
@ -69,7 +69,6 @@ void FlutterRenderContext::PaintChild(const RefPtr<RenderNode>& child, const Off
|
||||
if (child->NeedRender()) {
|
||||
FlutterRenderContext context;
|
||||
auto pipelineContext = child->GetContext().Upgrade();
|
||||
LOGI("Hole: child canvas render");
|
||||
auto transparentHole = pipelineContext->GetTransparentHole();
|
||||
if (transparentHole.IsValid() && child->GetNeedClip()) {
|
||||
Offset childOffset = rect.GetOffset();
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "core/animation/shared_transition_controller.h"
|
||||
#include "core/common/ace_application_info.h"
|
||||
#include "core/common/ace_engine.h"
|
||||
#include "core/common/container_scope.h"
|
||||
#include "core/common/event_manager.h"
|
||||
#include "core/common/font_manager.h"
|
||||
#include "core/common/frontend.h"
|
||||
@ -124,7 +125,8 @@ PipelineContext::PipelineContext(std::unique_ptr<Window> window, RefPtr<TaskExec
|
||||
{
|
||||
frontendType_ = frontend->GetType();
|
||||
RegisterEventHandler(frontend->GetEventHandler());
|
||||
auto&& vsyncCallback = [weak = AceType::WeakClaim(this)](const uint64_t nanoTimestamp, const uint32_t frameCount) {
|
||||
auto&& vsyncCallback = [weak = AceType::WeakClaim(this), instanceId](const uint64_t nanoTimestamp, const uint32_t frameCount) {
|
||||
ContainerScope scope(instanceId);
|
||||
auto context = weak.Upgrade();
|
||||
if (context) {
|
||||
context->OnVsyncEvent(nanoTimestamp, frameCount);
|
||||
|
Loading…
Reference in New Issue
Block a user