From 0d956b88df0e420f25b2f21e101d8951f120c769 Mon Sep 17 00:00:00 2001 From: Yao yuchi Date: Fri, 20 May 2022 19:23:45 +0800 Subject: [PATCH] merge the newest plugin to release-3.1 Signed-off-by: Yao yuchi --- engine/flutter/lib/ui/ui_dart_state.cc | 43 +++++++++++++++++++++++++- engine/flutter/lib/ui/ui_dart_state.h | 6 ++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/engine/flutter/lib/ui/ui_dart_state.cc b/engine/flutter/lib/ui/ui_dart_state.cc index 1720b167..ad8267e9 100644 --- a/engine/flutter/lib/ui/ui_dart_state.cc +++ b/engine/flutter/lib/ui/ui_dart_state.cc @@ -1,4 +1,4 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. +// Copyright 2013-2022 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,6 +9,7 @@ namespace flutter { static std::unique_ptr g_ui_state; +constexpr int32_t MIN_PLUGIN_SUBCONTAINER_ID = 2000000; UIDartState::UIDartState() { } @@ -37,6 +38,7 @@ void UIDartState::Init(int32_t instanceId, void UIDartState::DeInit(int32_t instanceId) { g_ui_state->RemoveStateItem(instanceId); + g_ui_state->RemovePluginParentContainer(instanceId); } void UIDartState::SetCurStateItem(int32_t id, std::unique_ptr item) { @@ -56,6 +58,9 @@ void UIDartState::RemoveStateItem(int32_t id) { } UIDartState::UIStateItem* UIDartState::GetStateById(int32_t id) const { + if (id >= MIN_PLUGIN_SUBCONTAINER_ID) { + id = GetPluginParentContainerId(id); + } std::lock_guard lock(mutex_); auto iter = state_map_.find(id); if (iter != state_map_.end()) { @@ -111,8 +116,44 @@ Window* UIDartState::window() const { return nullptr; } int32_t id = *ptr; + if (id >= MIN_PLUGIN_SUBCONTAINER_ID) { + id = GetPluginParentContainerId(id); + } return WindowManager::GetWindow(id); } +int64_t UIDartState::GetPluginParentContainerId(int64_t pluginId) const +{ + std::lock_guard lock(parentContainerMutex_); + auto result = parentContainerMap_.find(pluginId); + if (result != parentContainerMap_.end()) { + return result->second; + } else { + FML_LOG(ERROR) << "ParentContainerId is empty."; + return 0; + } +} + +void UIDartState::AddPluginParentContainer(int64_t pluginId, int32_t pluginParentContainerId) +{ + std::lock_guard lock(parentContainerMutex_); + auto result = parentContainerMap_.try_emplace(pluginId, pluginParentContainerId); + if (!result.second) { + FML_LOG(ERROR) << "already have pluginSubContainer of this instance, pluginId: " << pluginId; + } +} + +void UIDartState::RemovePluginParentContainer(int64_t pluginParentContainerId) +{ + std::lock_guard lock(parentContainerMutex_); + auto iter = parentContainerMap_.begin(); + while(iter != parentContainerMap_.end()) { + if (iter->second == pluginParentContainerId) { + parentContainerMap_.erase(iter++); + } else { + ++iter; + } + } +} } // namespcae blink diff --git a/engine/flutter/lib/ui/ui_dart_state.h b/engine/flutter/lib/ui/ui_dart_state.h index 7248c0c3..bb56afaa 100644 --- a/engine/flutter/lib/ui/ui_dart_state.h +++ b/engine/flutter/lib/ui/ui_dart_state.h @@ -72,11 +72,17 @@ class __attribute__((visibility("default"))) UIDartState { void SetCurStateItem(int32_t id, std::unique_ptr); void RemoveStateItem(int32_t id); + void AddPluginParentContainer(int64_t pluginId, int32_t pluginParentContainerId); + void RemovePluginParentContainer(int64_t pluginParentContainerId); + int64_t GetPluginParentContainerId(int64_t pluginId) const; + private: UIDartState(); fml::ThreadLocalUniquePtr cur_instance_id_; std::map> state_map_; mutable std::mutex mutex_; + std::unordered_map parentContainerMap_; + mutable std::mutex parentContainerMutex_; FML_DISALLOW_COPY_AND_ASSIGN(UIDartState); }; -- Gitee