From 04cd4feb4e131fb4eb03cb46df6e3120f4ba4bf6 Mon Sep 17 00:00:00 2001 From: xiaojianfeng Date: Wed, 26 Jan 2022 15:50:49 +0800 Subject: [PATCH] gadd screenInfo and screenGroupInfo Signed-off-by: xiaojianfeng Change-Id: I4fa1ae05fe455746dc293acb94598efb8b27e231 --- dmserver/include/abstract_screen.h | 12 +-- dmserver/include/abstract_screen_controller.h | 3 +- dmserver/src/abstract_screen.cpp | 37 ++++++++- dmserver/src/abstract_screen_controller.cpp | 22 +++++- utils/BUILD.gn | 3 + utils/include/screen_group_info.h | 42 ++++++++++ utils/include/screen_info.h | 46 +++++++++++ utils/src/screen_group_info.cpp | 76 +++++++++++++++++++ utils/src/screen_info.cpp | 58 ++++++++++++++ 9 files changed, 288 insertions(+), 11 deletions(-) create mode 100644 utils/include/screen_group_info.h create mode 100644 utils/include/screen_info.h create mode 100644 utils/src/screen_group_info.cpp create mode 100644 utils/src/screen_info.cpp diff --git a/dmserver/include/abstract_screen.h b/dmserver/include/abstract_screen.h index 1cdcd30e..3c7809ad 100644 --- a/dmserver/include/abstract_screen.h +++ b/dmserver/include/abstract_screen.h @@ -24,14 +24,10 @@ #include #include "screen.h" +#include "screen_group.h" +#include "screen_group_info.h" namespace OHOS::Rosen { -enum class ScreenCombination : uint32_t { - SCREEN_ALONE, - SCREEN_EXPAND, - SCREEN_MIRROR, -}; - enum class ScreenType : uint32_t { UNDEFINE, REAL, @@ -52,6 +48,7 @@ public: ~AbstractScreen(); sptr GetActiveScreenInfo() const; sptr GetGroup() const; + const sptr ConvertToScreenInfo() const; ScreenId dmsId_; ScreenId rsId_; @@ -61,6 +58,8 @@ public: int32_t activeIdx_; float virtualPixelRatio = { 1.0 }; std::vector> infos_ = {}; +protected: + void FillScreenInfo(sptr) const; }; class AbstractScreenGroup : public AbstractScreen { @@ -76,6 +75,7 @@ public: std::vector> GetChildren() const; std::vector GetChildrenPosition() const; size_t GetChildCount() const; + const sptr ConvertToScreenGroupInfo() const; ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE }; private: diff --git a/dmserver/include/abstract_screen_controller.h b/dmserver/include/abstract_screen_controller.h index e9527f93..89936e64 100644 --- a/dmserver/include/abstract_screen_controller.h +++ b/dmserver/include/abstract_screen_controller.h @@ -50,8 +50,7 @@ public: void RegisterAbstractScreenCallback(sptr cb); ScreenId CreateVirtualScreen(VirtualScreenOption option); DMError DestroyVirtualScreen(ScreenId screenId); - - std::map> abstractDisplayMap_; + bool IsScreenGroup(ScreenId screenId) const; private: void OnRsScreenChange(ScreenId rsScreenId, ScreenEvent screenEvent); diff --git a/dmserver/src/abstract_screen.cpp b/dmserver/src/abstract_screen.cpp index ef1a4c71..b62deeb1 100644 --- a/dmserver/src/abstract_screen.cpp +++ b/dmserver/src/abstract_screen.cpp @@ -35,7 +35,7 @@ AbstractScreen::~AbstractScreen() sptr AbstractScreen::GetActiveScreenInfo() const { - if (activeIdx_ < 0 && activeIdx_ >= infos_.size()) { + if (activeIdx_ < 0 || activeIdx_ >= infos_.size()) { WLOGE("active mode index is wrong: %{public}d", activeIdx_); return nullptr; } @@ -47,6 +47,28 @@ sptr AbstractScreen::GetGroup() const return DisplayManagerService::GetInstance().GetAbstractScreenController()->GetAbstractScreenGroup(groupDmsId_); } +const sptr AbstractScreen::ConvertToScreenInfo() const +{ + sptr info = new ScreenInfo(); + FillScreenInfo(info); + return info; +} + +void AbstractScreen::FillScreenInfo(sptr info) const +{ + info->id_ = dmsId_; + if (activeIdx_ >= 0 && activeIdx_ < infos_.size()) { + sptr abstractScreenInfo = infos_[activeIdx_]; + info->height_ = abstractScreenInfo->height_; + info->width_ = abstractScreenInfo->width_; + } + info->virtualPixelRatio_ = virtualPixelRatio; + info->virtualHeight_ = virtualPixelRatio * info->height_; + info->virtualWidth_ = virtualPixelRatio * info->width_; + info->parent_ = groupDmsId_; + info->hasChild_ = DisplayManagerService::GetInstance().GetAbstractScreenController()->IsScreenGroup(dmsId_); +} + AbstractScreenGroup::AbstractScreenGroup(ScreenId dmsId, ScreenId rsId, ScreenCombination combination) : AbstractScreen(dmsId, rsId), combination_(combination) { @@ -59,6 +81,19 @@ AbstractScreenGroup::~AbstractScreenGroup() abstractScreenMap_.clear(); } +const sptr AbstractScreenGroup::ConvertToScreenGroupInfo() const +{ + sptr screenGroupInfo = new ScreenGroupInfo(); + FillScreenInfo(screenGroupInfo); + screenGroupInfo->combination_ = combination_; + for (auto iter = abstractScreenMap_.begin(); iter != abstractScreenMap_.end(); iter++) { + screenGroupInfo->children_.push_back(iter->first); + } + auto positions = GetChildrenPosition(); + screenGroupInfo->position_.insert(screenGroupInfo->position_.end(), positions.begin(), positions.end()); + return screenGroupInfo; +} + bool AbstractScreenGroup::AddChild(sptr& dmsScreen, Point& startPoint) { if (dmsScreen == nullptr) { diff --git a/dmserver/src/abstract_screen_controller.cpp b/dmserver/src/abstract_screen_controller.cpp index c482bccd..147c1343 100644 --- a/dmserver/src/abstract_screen_controller.cpp +++ b/dmserver/src/abstract_screen_controller.cpp @@ -51,6 +51,7 @@ void AbstractScreenController::Init() std::vector AbstractScreenController::GetAllScreenIds() { + std::lock_guard lock(mutex_); std::vector res; for (auto iter = dmsScreenMap_.begin(); iter != dmsScreenMap_.end(); iter++) { res.push_back(iter->first); @@ -60,6 +61,7 @@ std::vector AbstractScreenController::GetAllScreenIds() sptr AbstractScreenController::GetAbstractScreen(ScreenId dmsScreenId) { + std::lock_guard lock(mutex_); auto iter = dmsScreenMap_.find(dmsScreenId); if (iter == dmsScreenMap_.end()) { WLOGI("didnot find screen:%{public}" PRIu64"", dmsScreenId); @@ -71,6 +73,7 @@ sptr AbstractScreenController::GetAbstractScreen(ScreenId dmsScr sptr AbstractScreenController::GetAbstractScreenGroup(ScreenId dmsScreenId) { + std::lock_guard lock(mutex_); auto iter = dmsScreenGroupMap_.find(dmsScreenId); if (iter == dmsScreenGroupMap_.end()) { WLOGE("didnot find screen:%{public}" PRIu64"", dmsScreenId); @@ -82,19 +85,28 @@ sptr AbstractScreenController::GetAbstractScreenGroup(Scree ScreenId AbstractScreenController::GetMainAbstractScreenId() { + std::lock_guard lock(mutex_); return primaryDmsScreenId_; } ScreenId AbstractScreenController::ConvertToRsScreenId(ScreenId dmsScreenId) { std::lock_guard lock(mutex_); - return SCREEN_ID_INVALID; + auto iter = dms2RsScreenIdMap_.find(dmsScreenId); + if (iter == dms2RsScreenIdMap_.end()) { + return SCREEN_ID_INVALID; + } + return iter->second; } ScreenId AbstractScreenController::ConvertToDmsScreenId(ScreenId rsScreenId) { std::lock_guard lock(mutex_); - return SCREEN_ID_INVALID; + auto iter = rs2DmsScreenIdMap_.find(rsScreenId); + if (iter == rs2DmsScreenIdMap_.end()) { + return SCREEN_ID_INVALID; + } + return iter->second; } void AbstractScreenController::RegisterAbstractScreenCallback(sptr cb) @@ -313,4 +325,10 @@ DMError AbstractScreenController::DestroyVirtualScreen(ScreenId screenId) rsInterface_->RemoveVirtualScreen(screenId); return DMError::DM_OK; } + +bool AbstractScreenController::IsScreenGroup(ScreenId screenId) const +{ + std::lock_guard lock(mutex_); + return dmsScreenGroupMap_.find(screenId) != dmsScreenGroupMap_.end(); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/utils/BUILD.gn b/utils/BUILD.gn index b68368d9..d187d990 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -31,6 +31,8 @@ ohos_shared_library("libwmutil") { sources = [ "src/agent_death_recipient.cpp", "src/display_info.cpp", + "src/screen_group_info.cpp", + "src/screen_info.cpp", "src/singleton_container.cpp", "src/window_property.cpp", "src/wm_trace.cpp", @@ -42,6 +44,7 @@ ohos_shared_library("libwmutil") { external_deps = [ "bytrace_standard:bytrace_core", + "graphic_standard:surface", "hilog_native:libhilog", "ipc:ipc_core", "utils_base:utils", diff --git a/utils/include/screen_group_info.h b/utils/include/screen_group_info.h new file mode 100644 index 00000000..02e17581 --- /dev/null +++ b/utils/include/screen_group_info.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 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 + * + * 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 p ermissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_DMSERVER_SCREEN_GROUP_INFO_H +#define FOUNDATION_DMSERVER_SCREEN_GROUP_INFO_H + +#include + +#include "screen_group.h" +#include "screen_info.h" + +namespace OHOS::Rosen { +class ScreenGroupInfo : public ScreenInfo { +public: + ScreenGroupInfo() = default; + ~ScreenGroupInfo() = default; + + void Update(sptr info); + + virtual bool Marshalling(Parcel& parcel) const override; + static sptr Unmarshalling(Parcel& parcel); + + std::vector children_; + std::vector position_; + ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE }; +protected: + sptr InnerUnmarshalling(Parcel& parcel); +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_SCREEN_GROUP_INFO_H \ No newline at end of file diff --git a/utils/include/screen_info.h b/utils/include/screen_info.h new file mode 100644 index 00000000..304e49c3 --- /dev/null +++ b/utils/include/screen_info.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 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 + * + * 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 p ermissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_DMSERVER_SCREEN_INFO_H +#define FOUNDATION_DMSERVER_SCREEN_INFO_H + +#include + +#include "screen.h" + +namespace OHOS::Rosen { +class ScreenInfo : public Parcelable { +public: + ScreenInfo() = default; + ~ScreenInfo() = default; + + void Update(sptr info); + + virtual bool Marshalling(Parcel& parcel) const override; + static sptr Unmarshalling(Parcel& parcel); + + ScreenId id_ { SCREEN_ID_INVALID }; + uint32_t width_ { 0 }; + uint32_t height_ { 0 }; + uint32_t virtualWidth_ { 0 }; + uint32_t virtualHeight_ { 0 }; + float virtualPixelRatio_ { 0.0 }; + ScreenId parent_ { 0 }; + bool hasChild_ { false }; +protected: + sptr InnerUnmarshalling(Parcel& parcel); + }; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_DISPLAY_INFO_H \ No newline at end of file diff --git a/utils/src/screen_group_info.cpp b/utils/src/screen_group_info.cpp new file mode 100644 index 00000000..9727e1c0 --- /dev/null +++ b/utils/src/screen_group_info.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 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 + * + * 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 "screen_group_info.h" + +namespace OHOS::Rosen { +void ScreenGroupInfo::Update(sptr info) +{ + ScreenInfo::Update(info); + children_.clear(); + children_.insert(children_.begin(), info->children_.begin(), info->children_.end()); + position_.clear(); + position_.insert(position_.begin(), info->position_.begin(), info->position_.end()); + combination_ = info->combination_; +} + +bool ScreenGroupInfo::Marshalling(Parcel &parcel) const +{ + bool res = ScreenInfo::Marshalling(parcel) && parcel.WriteUint32((uint32_t)combination_) && + parcel.WriteUInt64Vector(children_); + if (!res) { + return false; + } + size_t size = position_.size(); + if (!parcel.WriteUint32(size)) { + return false; + } + for (size_t i = 0; i < size; i++) { + if (!parcel.WriteInt32(position_[i].posX_) || !parcel.WriteInt32(position_[i].posY_)) { + return false; + } + } + return true; +} + +sptr ScreenGroupInfo::Unmarshalling(Parcel &parcel) +{ + sptr screenGroupInfo = new ScreenGroupInfo(); + return screenGroupInfo->InnerUnmarshalling(parcel); +} + +sptr ScreenGroupInfo::InnerUnmarshalling(Parcel& parcel) +{ + uint32_t combination; + if (!ScreenInfo::InnerUnmarshalling(parcel) || !parcel.ReadUint32(combination) || + !parcel.ReadUInt64Vector(&children_)) { + return nullptr; + } + combination_ = (ScreenCombination) combination; + uint32_t size; + if (!parcel.ReadUint32(size)) { + return nullptr; + } + for (size_t i = 0; i < size; i++) { + Point point; + if (parcel.ReadInt32(point.posX_) && parcel.ReadInt32(point.posY_)) { + position_.push_back(point); + } else { + return nullptr; + } + } + return this; +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/utils/src/screen_info.cpp b/utils/src/screen_info.cpp new file mode 100644 index 00000000..f4e7419b --- /dev/null +++ b/utils/src/screen_info.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 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 + * + * 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 "screen_info.h" + +namespace OHOS::Rosen { +void ScreenInfo::Update(sptr info) +{ + id_ = info->id_; + width_ = info->width_; + height_ = info->height_; + virtualWidth_ = info->virtualWidth_; + virtualHeight_ = info->virtualHeight_; + virtualPixelRatio_ = info->virtualPixelRatio_; + parent_ = info->parent_; + hasChild_ = info->hasChild_; +} + +bool ScreenInfo::Marshalling(Parcel &parcel) const +{ + return parcel.WriteUint64(id_) && + parcel.WriteUint32(width_) && parcel.WriteUint32(height_) && + parcel.WriteUint32(virtualWidth_) && parcel.WriteUint32(virtualHeight_) && + parcel.WriteFloat(virtualPixelRatio_) && parcel.WriteUint64(parent_) && + parcel.WriteBool(hasChild_); +} + +sptr ScreenInfo::Unmarshalling(Parcel &parcel) +{ + sptr info = new ScreenInfo(); + return info->InnerUnmarshalling(parcel); +} + +sptr ScreenInfo::InnerUnmarshalling(Parcel& parcel) +{ + bool res = parcel.ReadUint64(id_) && + parcel.ReadUint32(width_) && parcel.ReadUint32(height_) && + parcel.ReadUint32(virtualWidth_) && parcel.ReadUint32(virtualHeight_) && + parcel.ReadFloat(virtualPixelRatio_) && parcel.ReadUint64(parent_) && + parcel.ReadBool(hasChild_); + if (!res) { + return nullptr; + } + return this; +} +} // namespace OHOS::Rosen \ No newline at end of file