gadd screenInfo and screenGroupInfo

Signed-off-by: xiaojianfeng <xiaojianfeng3@huawei.com>
Change-Id: I4fa1ae05fe455746dc293acb94598efb8b27e231
This commit is contained in:
xiaojianfeng
2022-01-26 15:50:49 +08:00
parent b64800d9bf
commit 04cd4feb4e
9 changed files with 288 additions and 11 deletions
+6 -6
View File
@@ -24,14 +24,10 @@
#include <ui/rs_display_node.h>
#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<AbstractScreenInfo> GetActiveScreenInfo() const;
sptr<AbstractScreenGroup> GetGroup() const;
const sptr<ScreenInfo> ConvertToScreenInfo() const;
ScreenId dmsId_;
ScreenId rsId_;
@@ -61,6 +58,8 @@ public:
int32_t activeIdx_;
float virtualPixelRatio = { 1.0 };
std::vector<sptr<AbstractScreenInfo>> infos_ = {};
protected:
void FillScreenInfo(sptr<ScreenInfo>) const;
};
class AbstractScreenGroup : public AbstractScreen {
@@ -76,6 +75,7 @@ public:
std::vector<sptr<AbstractScreen>> GetChildren() const;
std::vector<Point> GetChildrenPosition() const;
size_t GetChildCount() const;
const sptr<ScreenGroupInfo> ConvertToScreenGroupInfo() const;
ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE };
private:
@@ -50,8 +50,7 @@ public:
void RegisterAbstractScreenCallback(sptr<AbstractScreenCallback> cb);
ScreenId CreateVirtualScreen(VirtualScreenOption option);
DMError DestroyVirtualScreen(ScreenId screenId);
std::map<ScreenId, sptr<AbstractScreen>> abstractDisplayMap_;
bool IsScreenGroup(ScreenId screenId) const;
private:
void OnRsScreenChange(ScreenId rsScreenId, ScreenEvent screenEvent);
+36 -1
View File
@@ -35,7 +35,7 @@ AbstractScreen::~AbstractScreen()
sptr<AbstractScreenInfo> 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<AbstractScreenGroup> AbstractScreen::GetGroup() const
return DisplayManagerService::GetInstance().GetAbstractScreenController()->GetAbstractScreenGroup(groupDmsId_);
}
const sptr<ScreenInfo> AbstractScreen::ConvertToScreenInfo() const
{
sptr<ScreenInfo> info = new ScreenInfo();
FillScreenInfo(info);
return info;
}
void AbstractScreen::FillScreenInfo(sptr<ScreenInfo> info) const
{
info->id_ = dmsId_;
if (activeIdx_ >= 0 && activeIdx_ < infos_.size()) {
sptr<AbstractScreenInfo> 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<ScreenGroupInfo> AbstractScreenGroup::ConvertToScreenGroupInfo() const
{
sptr<ScreenGroupInfo> 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<AbstractScreen>& dmsScreen, Point& startPoint)
{
if (dmsScreen == nullptr) {
+20 -2
View File
@@ -51,6 +51,7 @@ void AbstractScreenController::Init()
std::vector<ScreenId> AbstractScreenController::GetAllScreenIds()
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
std::vector<ScreenId> res;
for (auto iter = dmsScreenMap_.begin(); iter != dmsScreenMap_.end(); iter++) {
res.push_back(iter->first);
@@ -60,6 +61,7 @@ std::vector<ScreenId> AbstractScreenController::GetAllScreenIds()
sptr<AbstractScreen> AbstractScreenController::GetAbstractScreen(ScreenId dmsScreenId)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
auto iter = dmsScreenMap_.find(dmsScreenId);
if (iter == dmsScreenMap_.end()) {
WLOGI("didnot find screen:%{public}" PRIu64"", dmsScreenId);
@@ -71,6 +73,7 @@ sptr<AbstractScreen> AbstractScreenController::GetAbstractScreen(ScreenId dmsScr
sptr<AbstractScreenGroup> AbstractScreenController::GetAbstractScreenGroup(ScreenId dmsScreenId)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
auto iter = dmsScreenGroupMap_.find(dmsScreenId);
if (iter == dmsScreenGroupMap_.end()) {
WLOGE("didnot find screen:%{public}" PRIu64"", dmsScreenId);
@@ -82,19 +85,28 @@ sptr<AbstractScreenGroup> AbstractScreenController::GetAbstractScreenGroup(Scree
ScreenId AbstractScreenController::GetMainAbstractScreenId()
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
return primaryDmsScreenId_;
}
ScreenId AbstractScreenController::ConvertToRsScreenId(ScreenId dmsScreenId)
{
std::lock_guard<std::recursive_mutex> 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<std::recursive_mutex> 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<AbstractScreenCallback> 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<std::recursive_mutex> lock(mutex_);
return dmsScreenGroupMap_.find(screenId) != dmsScreenGroupMap_.end();
}
} // namespace OHOS::Rosen
+3
View File
@@ -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",
+42
View File
@@ -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 <parcel.h>
#include "screen_group.h"
#include "screen_info.h"
namespace OHOS::Rosen {
class ScreenGroupInfo : public ScreenInfo {
public:
ScreenGroupInfo() = default;
~ScreenGroupInfo() = default;
void Update(sptr<ScreenGroupInfo> info);
virtual bool Marshalling(Parcel& parcel) const override;
static sptr<ScreenGroupInfo> Unmarshalling(Parcel& parcel);
std::vector<ScreenId> children_;
std::vector<Point> position_;
ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE };
protected:
sptr<ScreenGroupInfo> InnerUnmarshalling(Parcel& parcel);
};
} // namespace OHOS::Rosen
#endif // FOUNDATION_DMSERVER_SCREEN_GROUP_INFO_H
+46
View File
@@ -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 <parcel.h>
#include "screen.h"
namespace OHOS::Rosen {
class ScreenInfo : public Parcelable {
public:
ScreenInfo() = default;
~ScreenInfo() = default;
void Update(sptr<ScreenInfo> info);
virtual bool Marshalling(Parcel& parcel) const override;
static sptr<ScreenInfo> 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<ScreenInfo> InnerUnmarshalling(Parcel& parcel);
};
} // namespace OHOS::Rosen
#endif // FOUNDATION_DMSERVER_DISPLAY_INFO_H
+76
View File
@@ -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<ScreenGroupInfo> 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> ScreenGroupInfo::Unmarshalling(Parcel &parcel)
{
sptr<ScreenGroupInfo> screenGroupInfo = new ScreenGroupInfo();
return screenGroupInfo->InnerUnmarshalling(parcel);
}
sptr<ScreenGroupInfo> 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
+58
View File
@@ -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<ScreenInfo> 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> ScreenInfo::Unmarshalling(Parcel &parcel)
{
sptr<ScreenInfo> info = new ScreenInfo();
return info->InnerUnmarshalling(parcel);
}
sptr<ScreenInfo> 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