修改预览中锁以及其他意见

Signed-off-by: lw19901203 <liuwei793@h-partners.com>
This commit is contained in:
lw19901203 2024-05-22 11:14:55 +08:00
parent 4d71c761a2
commit e8aaf83a8e
3 changed files with 15 additions and 10 deletions

View File

@ -228,7 +228,7 @@ public:
virtual WMError UpdateSystemBarProperty(bool status);
private:
static sptr<Window> FindWindowById(uint32_t WinId);
static sptr<Window> FindWindowById(uint32_t windowId);
template<typename T1, typename T2, typename Ret>
using EnableIfSame = typename std::enable_if<std::is_same_v<T1, T2>, Ret>::type;
template<typename T> WMError RegisterListener(std::vector<sptr<T>>& holder, const sptr<T>& listener);
@ -274,6 +274,7 @@ private:
void NotifySystemBarChange(WindowType type, const SystemBarProperty& property);
void NotifySetIgnoreSafeArea(bool value);
void NotifyAvoidAreaChange(const sptr<AvoidArea>& avoidArea, AvoidAreaType type);
static std::mutex globalMutex_;
static std::map<std::string, std::pair<uint32_t, sptr<Window>>> windowMap_;
static std::map<uint32_t, std::vector<sptr<WindowImpl>>> subWindowMap_;
static std::map<uint32_t, std::vector<sptr<IWindowSystemBarEnableListener>>> systemBarEnableListeners_;
@ -296,8 +297,8 @@ private:
bool isIgnoreSafeArea_ = false;
uint32_t windowId_ = 0;
WindowMode windowMode_ = WindowMode::WINDOW_MODE_FULLSCREEN;
static std::mutex globalMutex_;
sptr<WindowProperty> property_;
mutable std::mutex mutex_;
std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ {
{ WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty(true, 0x00FFFFFF, 0xFF000000) },
{ WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty(true, 0x00FFFFFF, 0xFF000000) },

View File

@ -79,7 +79,7 @@ const std::shared_ptr<AbilityRuntime::Context> WindowImpl::GetContext() const
return nullptr;
}
sptr<Window> WindowImpl::FindWindowById(uint32_t WinId)
sptr<Window> WindowImpl::FindWindowById(uint32_t windowId)
{
std::lock_guard<std::mutex> lock(globalMutex_);
if (windowMap_.empty()) {
@ -87,8 +87,8 @@ sptr<Window> WindowImpl::FindWindowById(uint32_t WinId)
return nullptr;
}
for (auto iter = windowMap_.begin(); iter != windowMap_.end(); iter++) {
if (WinId == iter->second.first) {
WLOGI("FindWindow id: %{public}u", WinId);
if (windowId == iter->second.first) {
WLOGI("FindWindow id: %{public}u", windowId);
return iter->second.second;
}
}
@ -202,6 +202,7 @@ bool WindowImpl::IsMainHandlerAvailable() const
SystemBarProperty WindowImpl::GetSystemBarPropertyByType(WindowType type) const
{
std::lock_guard<std::mutex> lock(mutex_);
auto it = sysBarPropMap_.find(type);
if (it == sysBarPropMap_.end()) {
return SystemBarProperty(false, 0x0, 0x0);
@ -211,7 +212,7 @@ SystemBarProperty WindowImpl::GetSystemBarPropertyByType(WindowType type) const
WMError WindowImpl::GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea)
{
std::lock_guard<std::mutex> lock(globalMutex_);
std::lock_guard<std::mutex> lock(mutex_);
auto avoidAreaPtr = avoidAreaMap_[type];
if (avoidAreaPtr == nullptr) {
return WMError::WM_OK;
@ -354,7 +355,10 @@ WMError WindowImpl::SetSpecificBarProperty(WindowType type, const SystemBarPrope
if (GetSystemBarPropertyByType(type) == property) {
return WMError::WM_OK;
}
{
std::lock_guard<std::mutex> lock(mutex_);
sysBarPropMap_[type] = property;
}
NotifySystemBarChange(type, property);
UpdateViewportConfig();
return WMError::WM_OK;
@ -829,7 +833,7 @@ void WindowImpl::UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType
avoidArea->bottomRect_.height_);
{
std::lock_guard<std::mutex> lock(globalMutex_);
std::lock_guard<std::mutex> lock(mutex_);
avoidAreaMap_[type] = avoidArea;
}
NotifyAvoidAreaChange(avoidArea, type);