Add get/set screen mode interface

Signed-off-by: Grady <yangguangwei4@huawei.com>
Change-Id: I1825f60f00cd1b89fdd72bc7246022ee32518e2d
This commit is contained in:
Grady
2022-02-07 19:26:19 +08:00
parent c051e9db4e
commit 56e10cb1ee
19 changed files with 204 additions and 41 deletions
+1
View File
@@ -61,6 +61,7 @@ public:
virtual sptr<ScreenGroup> GetScreenGroupById(ScreenId screenId);
virtual std::vector<sptr<Screen>> GetAllScreens();
virtual DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint);
virtual bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId);
private:
bool InitDMSProxyLocked();
+9
View File
@@ -338,4 +338,13 @@ DMError DisplayManagerAdapter::MakeExpand(std::vector<ScreenId> screenId, std::v
}
return displayManagerServiceProxy_->MakeExpand(screenId, startPoint);
}
bool DisplayManagerAdapter::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (!InitDMSProxyLocked()) {
return false;
}
return displayManagerServiceProxy_->SetScreenActiveMode(screenId, modeId);
}
} // namespace OHOS::Rosen
+41 -7
View File
@@ -14,9 +14,10 @@
*/
#include "screen.h"
#include "screen_info.h"
#include "display_manager_adapter.h"
#include "screen_group.h"
#include "screen_info.h"
namespace OHOS::Rosen {
class Screen::Impl : public RefBase {
@@ -26,26 +27,26 @@ public:
~Impl() = default;
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_ { SCREEN_ID_INVALID };
bool hasChild_ { false };
uint32_t modeId_ { 0 };
std::vector<sptr<SupportedScreenModes>> modes_ {};
};
Screen::Screen(const ScreenInfo* info)
: pImpl_(new Impl())
{
pImpl_->id_ = info->id_;
pImpl_->width_ = info->width_;
pImpl_->height_ = info->height_;
pImpl_->virtualWidth_ = info->virtualWidth_;
pImpl_->virtualHeight_ = info->virtualHeight_;
pImpl_->virtualPixelRatio_ = info->virtualPixelRatio_;
pImpl_->parent_ = info->parent_;
pImpl_->hasChild_ = info->hasChild_;
pImpl_->modeId_ = info->modeId_;
pImpl_->modes_ = info->modes_;
}
Screen::~Screen()
@@ -64,12 +65,22 @@ ScreenId Screen::GetId() const
uint32_t Screen::GetWidth() const
{
return pImpl_->width_;
auto modeId = pImpl_->modeId_;
auto modes = pImpl_->modes_;
if (modeId < 0 || modeId >= modes.size()) {
return 0;
}
return modes[modeId]->width_;
}
uint32_t Screen::GetHeight() const
{
return pImpl_->height_;
auto modeId = pImpl_->modeId_;
auto modes = pImpl_->modes_;
if (modeId < 0 || modeId >= modes.size()) {
return 0;
}
return modes[modeId]->height_;
}
uint32_t Screen::GetVirtualWidth() const
@@ -101,4 +112,27 @@ ScreenId Screen::GetParentId() const
{
return pImpl_->parent_;
}
uint32_t Screen::GetModeId() const
{
return pImpl_->modeId_;
}
std::vector<sptr<SupportedScreenModes>> Screen::GetSupportedModes() const
{
return pImpl_->modes_;
}
bool Screen::SetScreenActiveMode(uint32_t modeId)
{
ScreenId screenId = pImpl_->id_;
if (modeId < 0 || modeId >= pImpl_->modes_.size()) {
return false;
}
if (DisplayManagerAdapter::GetInstance().SetScreenActiveMode(screenId, modeId)) {
pImpl_->modeId_ = modeId;
return true;
}
return false;
}
} // namespace OHOS::Rosen
@@ -178,6 +178,23 @@ HWTEST_F(ScreenManagerTest, ScreenManager05, Function | MediumTest | Level1)
ASSERT_GT(utils.successCount_, 0);
ASSERT_GT(maxWaitCount_, waitCount_);
}
/**
* @tc.name: ScreenManager06
* @tc.desc: Get and set screenMode
* @tc.type: FUNC
*/
HWTEST_F(ScreenManagerTest, ScreenManager06, Function | MediumTest | Level1)
{
ScreenId defaultScreenId = static_cast<ScreenId>(defaultDisplayId_);
sptr<Screen> screen = ScreenManager::GetInstance().GetScreenById(defaultScreenId);
auto modes = screen->GetSupportedModes();
ASSERT_GT(modes.size(), 0);
for (uint32_t modeIdx = 0; modeIdx < modes.size(); modeIdx++) {
ASSERT_EQ(true, screen->SetScreenActiveMode(modeIdx));
ASSERT_EQ(modeIdx, screen->GetModeId());
}
}
}
} // namespace Rosen
} // namespace OHOS
+3 -8
View File
@@ -35,19 +35,14 @@ enum class ScreenType : uint32_t {
VIRTUAL
};
struct AbstractScreenInfo : public RefBase {
int32_t width_;
int32_t height_;
uint32_t freshRate_;
};
class AbstractScreenGroup;
class AbstractScreen : public RefBase {
public:
AbstractScreen(ScreenId dmsId, ScreenId rsId);
AbstractScreen() = delete;
~AbstractScreen();
sptr<AbstractScreenInfo> GetActiveScreenInfo() const;
sptr<SupportedScreenModes> GetActiveScreenMode() const;
std::vector<sptr<SupportedScreenModes>> GetAbstractScreenModes() const;
sptr<AbstractScreenGroup> GetGroup() const;
const sptr<ScreenInfo> ConvertToScreenInfo() const;
@@ -58,7 +53,7 @@ public:
ScreenType type_ { ScreenType::REAL };
int32_t activeIdx_;
float virtualPixelRatio = { 1.0 };
std::vector<sptr<AbstractScreenInfo>> infos_ = {};
std::vector<sptr<SupportedScreenModes>> modes_ = {};
protected:
void FillScreenInfo(sptr<ScreenInfo>) const;
};
@@ -51,6 +51,7 @@ public:
ScreenId CreateVirtualScreen(VirtualScreenOption option);
DMError DestroyVirtualScreen(ScreenId screenId);
bool IsScreenGroup(ScreenId screenId) const;
bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId);
private:
void OnRsScreenChange(ScreenId rsScreenId, ScreenEvent screenEvent);
@@ -50,6 +50,7 @@ public:
TRANS_ID_DESTROY_VIRTUAL_SCREEN,
TRANS_ID_GET_SCREEN_INFO_BY_ID,
TRANS_ID_GET_SCREEN_GROUP_INFO_BY_ID,
TRANS_ID_SET_SCREEN_ACTIVE_MODE,
TRANS_ID_GET_ALL_SCREEN_INFOS,
TRANS_ID_SCREENGROUP_BASE = 1100,
TRANS_ID_SCREEN_MAKE_MIRROR = TRANS_ID_SCREENGROUP_BASE,
@@ -80,6 +81,7 @@ public:
virtual sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId) = 0;
virtual std::vector<sptr<ScreenInfo>> GetAllScreenInfos() = 0;
virtual DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint) = 0;
virtual bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId) = 0;
};
} // namespace OHOS::Rosen
+1
View File
@@ -55,6 +55,7 @@ public:
sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId) override;
std::vector<sptr<ScreenInfo>> GetAllScreenInfos() override;
DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint) override;
bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId) override;
private:
static inline BrokerDelegator<DisplayManagerProxy> delegator_;
@@ -68,6 +68,7 @@ public:
sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId) override;
std::vector<sptr<ScreenInfo>> GetAllScreenInfos() override;
DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint) override;
bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId) override;
private:
DisplayManagerService();
+1 -1
View File
@@ -106,7 +106,7 @@ bool AbstractDisplay::BindAbstractScreen(sptr<AbstractScreen> abstractScreen)
}
ScreenId dmsScreenId = abstractScreen->dmsId_;
// TODO: screen->rsDisplayNode_->SetScreenId(rsScreenId);
sptr<AbstractScreenInfo> info = abstractScreen->GetActiveScreenInfo();
sptr<SupportedScreenModes> info = abstractScreen->GetActiveScreenMode();
if (info == nullptr) {
WLOGE("display bind screen error, cannot get info. display:%{public}" PRIu64", screen:%{public}" PRIu64"",
id_, dmsScreenId);
+1 -1
View File
@@ -170,7 +170,7 @@ void AbstractDisplayController::BindAloneScreenLocked(sptr<AbstractScreen> realA
ScreenId defaultScreenId = abstractScreenController_->GetDefaultAbstractScreenId();
if (defaultScreenId == SCREEN_ID_INVALID) {
if (dummyDisplay_ == nullptr) {
sptr<AbstractScreenInfo> info = realAbsScreen->GetActiveScreenInfo();
sptr<SupportedScreenModes> info = realAbsScreen->GetActiveScreenMode();
if (info == nullptr) {
WLOGE("bind alone screen error, cannot get info.");
return;
+18 -9
View File
@@ -33,13 +33,18 @@ AbstractScreen::~AbstractScreen()
{
}
sptr<AbstractScreenInfo> AbstractScreen::GetActiveScreenInfo() const
sptr<SupportedScreenModes> AbstractScreen::GetActiveScreenMode() const
{
if (activeIdx_ < 0 || activeIdx_ >= infos_.size()) {
if (activeIdx_ < 0 || activeIdx_ >= modes_.size()) {
WLOGE("active mode index is wrong: %{public}d", activeIdx_);
return nullptr;
}
return infos_[activeIdx_];
return modes_[activeIdx_];
}
std::vector<sptr<SupportedScreenModes>> AbstractScreen::GetAbstractScreenModes() const
{
return modes_;
}
sptr<AbstractScreenGroup> AbstractScreen::GetGroup() const
@@ -57,16 +62,20 @@ const sptr<ScreenInfo> AbstractScreen::ConvertToScreenInfo() const
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_;
uint32_t width = 0;
uint32_t height = 0;
if (activeIdx_ >= 0 && activeIdx_ < modes_.size()) {
sptr<SupportedScreenModes> abstractScreenModes = modes_[activeIdx_];
height = abstractScreenModes->height_;
width = abstractScreenModes->width_;
}
info->virtualPixelRatio_ = virtualPixelRatio;
info->virtualHeight_ = virtualPixelRatio * info->height_;
info->virtualWidth_ = virtualPixelRatio * info->width_;
info->virtualHeight_ = virtualPixelRatio * height;
info->virtualWidth_ = virtualPixelRatio * width;
info->parent_ = groupDmsId_;
info->hasChild_ = DisplayManagerService::GetInstance().GetAbstractScreenController()->IsScreenGroup(dmsId_);
info->modeId_ = activeIdx_;
info->modes_ = modes_;
}
AbstractScreenGroup::AbstractScreenGroup(ScreenId dmsId, ScreenId rsId, ScreenCombination combination)
+20 -2
View File
@@ -63,6 +63,7 @@ std::vector<ScreenId> AbstractScreenController::GetAllScreenIds()
sptr<AbstractScreen> AbstractScreenController::GetAbstractScreen(ScreenId dmsScreenId)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
WLOGI("GetAbstractScreen: screenId: %{public}" PRIu64"", dmsScreenId);
auto iter = dmsScreenMap_.find(dmsScreenId);
if (iter == dmsScreenMap_.end()) {
WLOGI("didnot find screen:%{public}" PRIu64"", dmsScreenId);
@@ -203,11 +204,11 @@ bool AbstractScreenController::FillAbstractScreen(sptr<AbstractScreen>& absScree
return false;
}
for (RSScreenModeInfo rsScreenModeInfo : allModes) {
sptr<AbstractScreenInfo> info = new AbstractScreenInfo();
sptr<SupportedScreenModes> info = new SupportedScreenModes();
info->width_ = rsScreenModeInfo.GetScreenWidth();
info->height_ = rsScreenModeInfo.GetScreenHeight();
info->freshRate_ = rsScreenModeInfo.GetScreenFreshRate();
absScreen->infos_.push_back(info);
absScreen->modes_.push_back(info);
WLOGD("fill screen w/h:%{public}d/%{public}d", info->width_, info->height_);
}
int32_t activeModeId = rsInterface_->GetScreenActiveMode(rsScreenId).GetScreenModeId();
@@ -355,4 +356,21 @@ bool AbstractScreenController::IsScreenGroup(ScreenId screenId) const
std::lock_guard<std::recursive_mutex> lock(mutex_);
return dmsScreenGroupMap_.find(screenId) != dmsScreenGroupMap_.end();
}
bool AbstractScreenController::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
{
WLOGI("SetScreenActiveMode: screenId: %{public}" PRIu64", modeId: %{public}u", screenId, modeId);
if (rsInterface_ == nullptr) {
WLOGFE("SetScreenActiveMode: Get RsInterface failed");
return false;
}
rsInterface_->SetScreenActiveMode(screenId, modeId);
auto screen = GetAbstractScreen(screenId);
if (screen == nullptr) {
WLOGFE("SetScreenActiveMode: Get AbstractScreen failed");
return false;
}
screen->activeIdx_ = modeId;
return true;
}
} // namespace OHOS::Rosen
+30
View File
@@ -439,6 +439,10 @@ sptr<ScreenInfo> DisplayManagerProxy::GetScreenInfoById(ScreenId screenId)
WLOGFW("GetScreenInfoById SendRequest nullptr.");
return nullptr;
}
for (int i = 0; i < info->modes_.size(); i++) {
WLOGFI("info modes is width: %{public}u, height: %{public}u, freshRate: %{public}u",
info->modes_[i]->width_, info->modes_[i]->height_, info->modes_[i]->freshRate_);
}
return info;
}
@@ -539,4 +543,30 @@ DMError DisplayManagerProxy::MakeExpand(std::vector<ScreenId> screenId, std::vec
}
return static_cast<DMError>(reply.ReadInt32());
}
bool DisplayManagerProxy::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
WLOGFW("SetScreenActiveMode: remote is null");
return false;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("SetScreenActiveMode: WriteInterfaceToken failed");
return false;
}
if (!data.WriteUint64(screenId) || !data.WriteUint32(modeId)) {
WLOGFE("SetScreenActiveMode: write screenId/modeId failed");
return false;
}
if (remote->SendRequest(TRANS_ID_SET_SCREEN_ACTIVE_MODE, data, reply, option) != ERR_NONE) {
WLOGFE("SetScreenActiveMode: SendRequest failed");
return false;
}
return reply.ReadBool();
}
} // namespace OHOS::Rosen
+5
View File
@@ -290,4 +290,9 @@ DMError DisplayManagerService::MakeExpand(std::vector<ScreenId> screenId, std::v
// todo: make expand
return DMError::DM_OK;
}
bool DisplayManagerService::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
{
return abstractScreenController_->SetScreenActiveMode(screenId, modeId);
}
} // namespace OHOS::Rosen
+11
View File
@@ -149,6 +149,10 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
case TRANS_ID_GET_SCREEN_INFO_BY_ID: {
ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
auto screenInfo = GetScreenInfoById(screenId);
for (int i = 0; i < screenInfo->modes_.size(); i++) {
WLOGFI("info modes is width: %{public}u, height: %{public}u, freshRate: %{public}u",
screenInfo->modes_[i]->width_, screenInfo->modes_[i]->height_, screenInfo->modes_[i]->freshRate_);
}
reply.WriteStrongParcelable(screenInfo);
break;
}
@@ -183,6 +187,13 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
reply.WriteInt32(static_cast<int32_t>(result));
break;
}
case TRANS_ID_SET_SCREEN_ACTIVE_MODE: {
ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
uint32_t modeId = data.ReadUint32();
bool res = SetScreenActiveMode(screenId, modeId);
reply.WriteBool(res);
break;
}
default:
WLOGFW("unknown transaction code");
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
+9
View File
@@ -33,6 +33,12 @@ struct Point {
int32_t posY_;
};
struct SupportedScreenModes : public RefBase {
uint32_t width_;
uint32_t height_;
uint32_t freshRate_;
};
struct VirtualScreenOption {
const std::string name_;
uint32_t width_;
@@ -56,6 +62,9 @@ public:
bool RequestRotation(Rotation rotation);
Rotation GetRotation() const;
ScreenId GetParentId() const;
uint32_t GetModeId() const;
std::vector<sptr<SupportedScreenModes>> GetSupportedModes() const;
bool SetScreenActiveMode(uint32_t modeId);
private:
class Impl;
+4 -4
View File
@@ -32,15 +32,15 @@ public:
static 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 };
uint32_t modeId_ { 0 };
std::vector<sptr<SupportedScreenModes>> modes_ {};
protected:
ScreenInfo* InnerUnmarshalling(Parcel& parcel);
};
};
} // namespace OHOS::Rosen
#endif // FOUNDATION_DMSERVER_DISPLAY_INFO_H
#endif // FOUNDATION_DMSERVER_DISPLAY_INFO_H
+29 -9
View File
@@ -19,22 +19,29 @@ 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_;
modeId_ = info->modeId_;
modes_ = info->modes_;
}
bool ScreenInfo::Marshalling(Parcel &parcel) const
{
return parcel.WriteUint64(id_) &&
parcel.WriteUint32(width_) && parcel.WriteUint32(height_) &&
bool res1 = parcel.WriteUint64(id_) &&
parcel.WriteUint32(virtualWidth_) && parcel.WriteUint32(virtualHeight_) &&
parcel.WriteFloat(virtualPixelRatio_) && parcel.WriteUint64(parent_) &&
parcel.WriteBool(hasChild_);
parcel.WriteBool(hasChild_) && parcel.WriteUint32(modeId_) &&
parcel.WriteUint32(static_cast<uint32_t>(modes_.size()));
bool res2 = true;
for (uint32_t modeIndex = 0; modeIndex < modes_.size(); modeIndex++) {
res2 = res2 && parcel.WriteUint32(modes_[modeIndex]->height_) &&
parcel.WriteUint32(modes_[modeIndex]->width_) &&
parcel.WriteUint32(modes_[modeIndex]->freshRate_);
}
return res1 && res2;
}
ScreenInfo* ScreenInfo::Unmarshalling(Parcel &parcel)
@@ -45,12 +52,25 @@ ScreenInfo* ScreenInfo::Unmarshalling(Parcel &parcel)
ScreenInfo* ScreenInfo::InnerUnmarshalling(Parcel& parcel)
{
bool res = parcel.ReadUint64(id_) &&
parcel.ReadUint32(width_) && parcel.ReadUint32(height_) &&
uint32_t size = 0;
bool res1 = parcel.ReadUint64(id_) &&
parcel.ReadUint32(virtualWidth_) && parcel.ReadUint32(virtualHeight_) &&
parcel.ReadFloat(virtualPixelRatio_) && parcel.ReadUint64(parent_) &&
parcel.ReadBool(hasChild_);
if (!res) {
parcel.ReadBool(hasChild_) && parcel.ReadUint32(modeId_) &&
parcel.ReadUint32(size);
if (!res1) {
return nullptr;
}
bool res2 = true;
modes_.clear();
for (uint32_t modeIndex = 0; modeIndex < size; modeIndex++) {
sptr<SupportedScreenModes> mode = new SupportedScreenModes();
res2 = res2 && parcel.ReadUint32(mode->height_) &&
parcel.ReadUint32(mode->width_) &&
parcel.ReadUint32(mode->freshRate_);
modes_.push_back(mode);
}
if (!res2) {
return nullptr;
}
return this;