Change 'RequestRotation' to 'SetOrientation'

Signed-off-by: lu <zhaolu2@huawei.com>
Change-Id: Icfeab91d336279f41f93bf2f293c6d9364459da5
This commit is contained in:
lu 2022-02-25 16:20:33 +08:00
parent dc4ceda59f
commit db927c0ac5
47 changed files with 407 additions and 237 deletions

View File

@ -74,10 +74,10 @@ private:
class ScreenManagerAdapter : public BaseAdapter {
WM_DECLARE_SINGLE_INSTANCE(ScreenManagerAdapter);
public:
virtual bool RequestRotation(ScreenId screenId, Rotation rotation);
virtual ScreenId CreateVirtualScreen(VirtualScreenOption option);
virtual DMError DestroyVirtualScreen(ScreenId screenId);
virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface);
virtual bool SetOrientation(ScreenId screenId, Orientation orientation);
virtual sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId);
virtual std::vector<sptr<ScreenInfo>> GetAllScreenInfos();
virtual ScreenId MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId);

View File

@ -29,7 +29,8 @@ public:
void NotifyDisplayStateChanged(DisplayId id, DisplayState state) override {};
void OnScreenConnect(sptr<ScreenInfo>) override {};
void OnScreenDisconnect(ScreenId) override {};
void OnScreenChange(const std::vector<sptr<ScreenInfo>>&, ScreenChangeEvent) override {};
void OnScreenChange(const sptr<ScreenInfo>&, ScreenChangeEvent) override {};
void OnScreenGroupChange(const std::vector<sptr<ScreenInfo>>&, ScreenGroupChangeEvent) override {};
void OnDisplayCreate(sptr<DisplayInfo>) override {};
void OnDisplayDestroy(DisplayId) override {};
void OnDisplayChange(const sptr<DisplayInfo>, DisplayChangeEvent) override {};

View File

@ -40,6 +40,7 @@ public:
TRANS_ID_ON_SCREEN_CONNECT,
TRANS_ID_ON_SCREEN_DISCONNECT,
TRANS_ID_ON_SCREEN_CHANGED,
TRANS_ID_ON_SCREENGROUP_CHANGED,
TRANS_ID_ON_DISPLAY_CONNECT,
TRANS_ID_ON_DISPLAY_DISCONNECT,
TRANS_ID_ON_DISPLAY_CHANGED,
@ -48,7 +49,8 @@ public:
virtual void NotifyDisplayStateChanged(DisplayId id, DisplayState state) = 0;
virtual void OnScreenConnect(sptr<ScreenInfo>) = 0;
virtual void OnScreenDisconnect(ScreenId) = 0;
virtual void OnScreenChange(const std::vector<sptr<ScreenInfo>>&, ScreenChangeEvent) = 0;
virtual void OnScreenChange(const sptr<ScreenInfo>&, ScreenChangeEvent) = 0;
virtual void OnScreenGroupChange(const std::vector<sptr<ScreenInfo>>&, ScreenGroupChangeEvent) = 0;
virtual void OnDisplayCreate(sptr<DisplayInfo>) = 0;
virtual void OnDisplayDestroy(DisplayId) = 0;
virtual void OnDisplayChange(sptr<DisplayInfo>, DisplayChangeEvent) = 0;

View File

@ -30,7 +30,8 @@ public:
virtual void NotifyDisplayStateChanged(DisplayId id, DisplayState state) override;
virtual void OnScreenConnect(sptr<ScreenInfo>) override;
virtual void OnScreenDisconnect(ScreenId) override;
virtual void OnScreenChange(const std::vector<sptr<ScreenInfo>>&, ScreenChangeEvent) override;
virtual void OnScreenChange(const sptr<ScreenInfo>&, ScreenChangeEvent) override;
virtual void OnScreenGroupChange(const std::vector<sptr<ScreenInfo>>&, ScreenGroupChangeEvent) override;
virtual void OnDisplayCreate(sptr<DisplayInfo>) override;
virtual void OnDisplayDestroy(DisplayId) override;
virtual void OnDisplayChange(sptr<DisplayInfo>, DisplayChangeEvent) override;

View File

@ -72,6 +72,18 @@ ScreenId Display::GetScreenId() const
return pImpl_->GetDisplayInfo()->GetScreenId();
}
Rotation Display::GetRotation() const
{
UpdateDisplayInfo();
return pImpl_->GetDisplayInfo()->GetRotation();
}
Orientation Display::GetOrientation() const
{
UpdateDisplayInfo();
return pImpl_->GetDisplayInfo()->GetOrientation();
}
void Display::UpdateDisplayInfo(sptr<DisplayInfo> displayInfo) const
{
if (displayInfo == nullptr) {

View File

@ -115,7 +115,7 @@ public:
WLOGD("OnDisplayChange. display %{public}" PRIu64", event %{public}u", displayInfo->GetDisplayId(), event);
pImpl_->NotifyDisplayChange(displayInfo);
for (auto listener : pImpl_->displayListeners_) {
listener->OnChange(displayInfo->GetDisplayId(), event);
listener->OnChange(displayInfo->GetDisplayId());
}
};
private:
@ -467,15 +467,6 @@ void DisplayManager::Impl::NotifyDisplayStateChanged(DisplayId id, DisplayState
WLOGFW("callback_ target is not set!");
}
void DisplayManager::Impl::NotifyDisplayChangedEvent(sptr<DisplayInfo> info, DisplayChangeEvent event)
{
WLOGI("NotifyDisplayChangedEvent event:%{public}u, size:%{public}zu", event, displayListeners_.size());
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (auto& listener : displayListeners_) {
listener->OnChange(info->GetDisplayId(), event);
}
}
void DisplayManager::Impl::NotifyDisplayCreate(sptr<DisplayInfo> info)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);

View File

@ -46,16 +46,6 @@ sptr<DisplayInfo> DisplayManagerAdapter::GetDisplayInfoByScreenId(ScreenId scree
return displayManagerServiceProxy_->GetDisplayInfoByScreen(screenId);
}
bool ScreenManagerAdapter::RequestRotation(ScreenId screenId, Rotation rotation)
{
if (!InitDMSProxy()) {
WLOGFE("fail to request rotation: InitDMSProxy failed!");
return false;
}
return displayManagerServiceProxy_->RequestRotation(screenId, rotation);
}
std::shared_ptr<Media::PixelMap> DisplayManagerAdapter::GetDisplaySnapshot(DisplayId displayId)
{
if (!InitDMSProxy()) {
@ -154,6 +144,15 @@ DMError ScreenManagerAdapter::SetVirtualScreenSurface(ScreenId screenId, sptr<Su
return displayManagerServiceProxy_->SetVirtualScreenSurface(screenId, surface);
}
bool ScreenManagerAdapter::SetOrientation(ScreenId screenId, Orientation orientation)
{
if (!InitDMSProxy()) {
WLOGFE("fail to set orientation: InitDMSProxy failed!");
return false;
}
return displayManagerServiceProxy_->SetOrientation(screenId, orientation);
}
bool BaseAdapter::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type)
{

View File

@ -99,10 +99,16 @@ Rotation Screen::GetRotation() const
return pImpl_->GetScreenInfo()->GetRotation();
}
bool Screen::RequestRotation(Rotation rotation) const
Orientation Screen::GetOrientation() const
{
WLOGFD("rotation the screen");
return SingletonContainer::Get<ScreenManagerAdapter>().RequestRotation(GetId(), rotation);
UpdateScreenInfo();
return pImpl_->GetScreenInfo()->GetOrientation();
}
bool Screen::SetOrientation(Orientation orientation) const
{
WLOGFD("set orientation %{public}u", orientation);
return SingletonContainer::Get<ScreenManagerAdapter>().SetOrientation(GetId(), orientation);
}
DMError Screen::GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut>& colorGamuts) const

View File

@ -32,6 +32,8 @@ public:
static inline SingletonDelegator<ScreenManager> delegator;
bool RegisterScreenListener(sptr<IScreenListener> listener);
bool UnregisterScreenListener(sptr<IScreenListener> listener);
bool RegisterScreenGroupListener(sptr<IScreenGroupListener> listener);
bool UnregisterScreenGroupListener(sptr<IScreenGroupListener> listener);
sptr<Screen> GetScreenById(ScreenId screenId);
sptr<ScreenGroup> GetScreenGroupById(ScreenId screenId);
std::vector<sptr<Screen>> GetAllScreens();
@ -39,6 +41,7 @@ public:
private:
void NotifyScreenConnect(sptr<ScreenInfo> info);
void NotifyScreenDisconnect(ScreenId);
void NotifyScreenChange(const sptr<ScreenInfo>& screenInfo);
void NotifyScreenChange(const std::vector<sptr<ScreenInfo>>& screenInfos);
bool UpdateScreenInfoLocked(sptr<ScreenInfo>);
@ -48,6 +51,7 @@ private:
std::map<ScreenId, sptr<ScreenGroup>> screenGroupMap_;
std::recursive_mutex mutex_;
std::vector<sptr<IScreenListener>> screenListeners_;
std::vector<sptr<IScreenGroupListener>> screenGroupListeners_;
};
class ScreenManager::Impl::ScreenManagerListener : public DisplayManagerAgentDefault {
@ -88,10 +92,10 @@ public:
}
};
void OnScreenChange(const std::vector<sptr<ScreenInfo>>& screenInfos, ScreenChangeEvent event)
void OnScreenChange(const sptr<ScreenInfo>& screenInfo, ScreenChangeEvent event)
{
if (screenInfos.empty()) {
WLOGFE("OnScreenChange, screenInfos is empty.");
if (screenInfo == nullptr) {
WLOGFE("OnScreenChange, screenInfo is null.");
return;
}
if (pImpl_ == nullptr) {
@ -99,6 +103,23 @@ public:
return;
}
WLOGFD("OnScreenChange. event %{public}u", event);
pImpl_->NotifyScreenChange(screenInfo);
for (auto listener: pImpl_->screenListeners_) {
listener->OnChange(screenInfo->GetScreenId());
}
};
void OnScreenGroupChange(const std::vector<sptr<ScreenInfo>>& screenInfos, ScreenGroupChangeEvent groupEvent)
{
if (screenInfos.empty()) {
WLOGFE("OnScreenGroupChange, screenInfos is empty.");
return;
}
if (pImpl_ == nullptr) {
WLOGFE("OnScreenGroupChange, impl is nullptr.");
return;
}
WLOGFD("OnScreenGroupChange. event %{public}u", groupEvent);
pImpl_->NotifyScreenChange(screenInfos);
std::vector<ScreenId> screenIds;
for (auto screenInfo : screenInfos) {
@ -106,8 +127,8 @@ public:
screenIds.push_back(screenInfo->GetScreenId());
}
}
for (auto listener: pImpl_->screenListeners_) {
listener->OnChange(screenIds, event);
for (auto listener: pImpl_->screenGroupListeners_) {
listener->OnChange(screenIds, groupEvent);
}
};
private:
@ -236,6 +257,55 @@ bool ScreenManager::UnregisterScreenListener(sptr<IScreenListener> listener)
return pImpl_->UnregisterScreenListener(listener);
}
bool ScreenManager::Impl::RegisterScreenGroupListener(sptr<IScreenGroupListener> listener)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
screenGroupListeners_.push_back(listener);
if (screenManagerListener_ == nullptr) {
screenManagerListener_ = new ScreenManagerListener(this);
SingletonContainer::Get<ScreenManagerAdapter>().RegisterDisplayManagerAgent(
screenManagerListener_,
DisplayManagerAgentType::SCREEN_EVENT_LISTENER);
}
return true;
}
bool ScreenManager::RegisterScreenGroupListener(sptr<IScreenGroupListener> listener)
{
if (listener == nullptr) {
WLOGFE("RegisterScreenGroupListener listener is nullptr.");
return false;
}
return pImpl_->RegisterScreenGroupListener(listener);
}
bool ScreenManager::Impl::UnregisterScreenGroupListener(sptr<IScreenGroupListener> listener)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
auto iter = std::find(screenGroupListeners_.begin(), screenGroupListeners_.end(), listener);
if (iter == screenGroupListeners_.end()) {
WLOGFE("could not find this listener");
return false;
}
screenGroupListeners_.erase(iter);
if (screenGroupListeners_.empty() && screenManagerListener_ != nullptr) {
SingletonContainer::Get<ScreenManagerAdapter>().UnregisterDisplayManagerAgent(
screenManagerListener_,
DisplayManagerAgentType::SCREEN_EVENT_LISTENER);
screenManagerListener_ = nullptr;
}
return true;
}
bool ScreenManager::UnregisterScreenGroupListener(sptr<IScreenGroupListener> listener)
{
if (listener == nullptr) {
WLOGFE("UnregisterScreenGroupListener listener is nullptr.");
return false;
}
return pImpl_->UnregisterScreenGroupListener(listener);
}
ScreenId ScreenManager::MakeExpand(const std::vector<ExpandOption>& options)
{
WLOGFI("make expand");
@ -294,6 +364,12 @@ void ScreenManager::Impl::NotifyScreenDisconnect(ScreenId screenId)
screenMap_.erase(screenId);
}
void ScreenManager::Impl::NotifyScreenChange(const sptr<ScreenInfo>& screenInfo)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
UpdateScreenInfoLocked(screenInfo);
}
void ScreenManager::Impl::NotifyScreenChange(const std::vector<sptr<ScreenInfo>>& screenInfos)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);

View File

@ -113,8 +113,33 @@ void DisplayManagerAgentProxy::OnScreenDisconnect(ScreenId screenId)
}
}
void DisplayManagerAgentProxy::OnScreenChange(
const std::vector<sptr<ScreenInfo>>& screenInfos, ScreenChangeEvent event)
void DisplayManagerAgentProxy::OnScreenChange(const sptr<ScreenInfo>& screenInfo, ScreenChangeEvent event)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_ASYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return;
}
if (!data.WriteParcelable(screenInfo.GetRefPtr())) {
WLOGFE("Write screenInfo failed");
return;
}
if (!data.WriteUint32(static_cast<uint32_t>(event))) {
WLOGFE("Write ScreenChangeEvent failed");
return;
}
if (Remote()->SendRequest(TRANS_ID_ON_SCREEN_CHANGED, data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
}
}
void DisplayManagerAgentProxy::OnScreenGroupChange(
const std::vector<sptr<ScreenInfo>>& screenInfos, ScreenGroupChangeEvent event)
{
MessageParcel data;
MessageParcel reply;
@ -138,11 +163,11 @@ void DisplayManagerAgentProxy::OnScreenChange(
}
if (!data.WriteUint32(static_cast<uint32_t>(event))) {
WLOGFE("Write ScreenChangeEvent failed");
WLOGFE("Write ScreenGroupChangeEvent failed");
return;
}
if (Remote()->SendRequest(TRANS_ID_ON_SCREEN_CHANGED, data, reply, option) != ERR_NONE) {
if (Remote()->SendRequest(TRANS_ID_ON_SCREENGROUP_CHANGED, data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
}
}

View File

@ -59,6 +59,16 @@ int32_t DisplayManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& d
break;
}
case TRANS_ID_ON_SCREEN_CHANGED: {
sptr<ScreenInfo> screenInfo = data.ReadParcelable<ScreenInfo>();
uint32_t event;
if (!data.ReadUint32(event)) {
WLOGFE("Read ScreenChangeEvent failed");
return -1;
}
OnScreenChange(screenInfo, static_cast<ScreenChangeEvent>(event));
break;
}
case TRANS_ID_ON_SCREENGROUP_CHANGED: {
std::vector<sptr<ScreenInfo>> screenInfos;
uint32_t size;
if (!data.ReadUint32(size)) {
@ -75,7 +85,7 @@ int32_t DisplayManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& d
WLOGFE("Read ScreenChangeEvent failed");
return -1;
}
OnScreenChange(screenInfos, static_cast<ScreenChangeEvent>(event));
OnScreenGroupChange(screenInfos, static_cast<ScreenGroupChangeEvent>(event));
break;
}
case TRANS_ID_ON_DISPLAY_CONNECT: {

View File

@ -44,15 +44,13 @@ public:
WLOGI("DisplayChangeEventListener::OnDestroy displayId=%{public}" PRIu64"", displayId);
}
virtual void OnChange(DisplayId displayId, DisplayChangeEvent event)
virtual void OnChange(DisplayId displayId)
{
WLOGI("DisplayChangeEventListener::OnChange displayId=%{public}" PRIu64"", displayId);
isCallbackCalled_ = true;
event_ = event;
displayId_ = displayId;
}
bool isCallbackCalled_ { false };
DisplayChangeEvent event_ { DisplayChangeEvent::UNKNOWN };
DisplayId displayId_ { DISPLAY_ID_INVALD };
};
@ -105,7 +103,6 @@ void DisplayChangeTest::TearDown()
void DisplayChangeTest::ResetDisplayChangeListener()
{
listener_->isCallbackCalled_ = false;
listener_->event_ = DisplayChangeEvent::UNKNOWN;
listener_->displayId_ = DISPLAY_ID_INVALD;
}

View File

@ -15,7 +15,9 @@
// gtest
#include <gtest/gtest.h>
#include "display_test_utils.h"
#include "screen.h"
#include "window.h"
#include "window_option.h"
using namespace testing;
@ -361,6 +363,28 @@ HWTEST_F(ScreenManagerTest, ScreenManager11, Function | MediumTest | Level2)
ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId));
}
}
/**
* @tc.name: ScreenManager11
* @tc.desc: Screen orientatin.
* @tc.type: FUNC
*/
HWTEST_F(ScreenManagerTest, ScreenManager12, Function | MediumTest | Level2)
{
auto screens = ScreenManager::GetInstance().GetAllScreens();
auto display = DisplayManager::GetInstance().GetDefaultDisplay();
uint32_t orientation = static_cast<uint32_t>(Orientation::VERTICAL);
uint32_t end = static_cast<uint32_t>(Orientation::REVERSE_HORIZONTAL);
for (; orientation <= end; ++orientation) {
screens[0]->SetOrientation(static_cast<Orientation>(orientation));
usleep(1E6);
ASSERT_EQ(static_cast<uint32_t>(screens[0]->GetOrientation()), orientation);
ASSERT_EQ(static_cast<uint32_t>(display->GetOrientation()), orientation);
}
screens[0]->SetOrientation(Orientation::UNSPECIFIED);
ASSERT_EQ(static_cast<uint32_t>(screens[0]->GetOrientation()), static_cast<uint32_t>(Orientation::UNSPECIFIED));
ASSERT_EQ(static_cast<uint32_t>(display->GetOrientation()), static_cast<uint32_t>(Orientation::UNSPECIFIED));
}
}
} // namespace Rosen
} // namespace OHOS

View File

@ -37,7 +37,7 @@ public:
virtual void OnDestroy(DisplayId displayId) {}
virtual void OnChange(DisplayId displayId, DisplayChangeEvent event) {}
virtual void OnChange(DisplayId displayId) {}
};
class DisplayChangeUnitTest : public testing::Test {

View File

@ -50,6 +50,7 @@ public:
void SetHeight(int32_t height);
void SetFreshRate(uint32_t freshRate);
void SetVirtualPixelRatio(float virtualPixelRatio);
void SetOrientation(Orientation orientation);
bool RequestRotation(Rotation rotation);
Rotation GetRotation();
@ -61,6 +62,7 @@ private:
uint32_t freshRate_ { 0 };
float virtualPixelRatio_ { 1.0 };
Rotation rotation_ { Rotation::ROTATION_0 };
Orientation orientation_ { Orientation::UNSPECIFIED };
};
} // namespace OHOS::Rosen
#endif // FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H

View File

@ -48,7 +48,7 @@ private:
void OnAbstractScreenConnect(sptr<AbstractScreen> absScreen);
void OnAbstractScreenDisconnect(sptr<AbstractScreen> absScreen);
void OnAbstractScreenChange(sptr<AbstractScreen> absScreen, DisplayChangeEvent event);
void ProcessDisplayUpdateRotation(sptr<AbstractScreen> absScreen);
void ProcessDisplayUpdateOrientation(sptr<AbstractScreen> absScreen);
void ProcessDisplaySizeChange(sptr<AbstractScreen> absScreen);
void BindAloneScreenLocked(sptr<AbstractScreen> absScreen);
void AddScreenToMirrorLocked(sptr<AbstractScreen> absScreen);

View File

@ -47,8 +47,8 @@ public:
std::vector<sptr<SupportedScreenModes>> GetAbstractScreenModes() const;
sptr<AbstractScreenGroup> GetGroup() const;
sptr<ScreenInfo> ConvertToScreenInfo() const;
void RequestRotation(Rotation rotation);
Rotation GetRotation() const;
bool SetOrientation(Orientation orientation);
Rotation CalcRotation(Orientation orientation) const;
void UpdateRSTree(std::shared_ptr<RSSurfaceNode>& surfaceNode, bool isAdd);
void InitRSDisplayNode(RSDisplayNodeConfig& config);
@ -66,11 +66,12 @@ public:
bool canHasChild_ { false };
std::shared_ptr<RSDisplayNode> rsDisplayNode_;
RSDisplayNodeConfig rSDisplayNodeConfig_;
ScreenId groupDmsId_ {INVALID_SCREEN_ID};
ScreenId groupDmsId_ { SCREEN_ID_INVALID };
ScreenType type_ { ScreenType::REAL };
int32_t activeIdx_ { 0 };
float virtualPixelRatio = { 1.0 };
std::vector<sptr<SupportedScreenModes>> modes_ = {};
Orientation orientation_ { Orientation::UNSPECIFIED };
Rotation rotation_ { Rotation::ROTATION_0 };
protected:
void FillScreenInfo(sptr<ScreenInfo>) const;
@ -94,7 +95,7 @@ public:
bool SetRSDisplayNodeConfig(sptr<AbstractScreen>& dmsScreen, struct RSDisplayNodeConfig& config);
ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE };
ScreenId mirrorScreenId_ {INVALID_SCREEN_ID};
ScreenId mirrorScreenId_ { SCREEN_ID_INVALID };
private:
std::map<ScreenId, std::pair<sptr<AbstractScreen>, Point>> abstractScreenMap_;

View File

@ -56,9 +56,8 @@ public:
ScreenId CreateVirtualScreen(VirtualScreenOption option);
DMError DestroyVirtualScreen(ScreenId screenId);
DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface);
bool RequestRotation(ScreenId screenId, Rotation rotation);
bool SetOrientation(ScreenId screenId, Orientation orientation);
void OnScreenRotate(ScreenId dmsScreenId, Rotation before, Rotation after);
bool IsScreenGroup(ScreenId screenId) const;
bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId);
std::shared_ptr<RSDisplayNode> GetRSDisplayNodeByScreenId(ScreenId dmsScreenId) const;

View File

@ -36,8 +36,9 @@ public:
void OnScreenConnect(sptr<ScreenInfo> screenInfo);
void OnScreenDisconnect(ScreenId);
void OnScreenChange(const std::vector<sptr<ScreenInfo>>&, ScreenChangeEvent);
void OnScreenChange(sptr<ScreenInfo>, ScreenChangeEvent);
void OnScreenChange(const sptr<ScreenInfo>, ScreenChangeEvent);
void OnScreenGroupChange(const sptr<ScreenInfo>&, ScreenGroupChangeEvent);
void OnScreenGroupChange(const std::vector<sptr<ScreenInfo>>&, ScreenGroupChangeEvent);
void OnDisplayCreate(sptr<DisplayInfo>);
void OnDisplayDestroy(DisplayId);
void OnDisplayChange(sptr<DisplayInfo>, DisplayChangeEvent);

View File

@ -56,7 +56,7 @@ public:
TRANS_ID_GET_SCREEN_GROUP_INFO_BY_ID,
TRANS_ID_SET_SCREEN_ACTIVE_MODE,
TRANS_ID_GET_ALL_SCREEN_INFOS,
TRANS_ID_REQUEST_ROTATION,
TRANS_ID_SET_ORIENTATION,
TRANS_ID_SCREENGROUP_BASE = 1100,
TRANS_ID_SCREEN_MAKE_MIRROR = TRANS_ID_SCREENGROUP_BASE,
TRANS_ID_SCREEN_MAKE_EXPAND,
@ -76,7 +76,7 @@ public:
virtual ScreenId CreateVirtualScreen(VirtualScreenOption option) = 0;
virtual DMError DestroyVirtualScreen(ScreenId screenId) = 0;
virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface) = 0;
virtual bool RequestRotation(ScreenId screenId, Rotation rotation) = 0;
virtual bool SetOrientation(ScreenId screenId, Orientation orientation) = 0;
virtual std::shared_ptr<Media::PixelMap> GetDispalySnapshot(DisplayId displayId) = 0;
// colorspace, gamut

View File

@ -38,7 +38,7 @@ public:
ScreenId CreateVirtualScreen(VirtualScreenOption option) override;
DMError DestroyVirtualScreen(ScreenId screenId) override;
DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface) override;
bool RequestRotation(ScreenId screenId, Rotation rotation) override;
bool SetOrientation(ScreenId screenId, Orientation orientation) override;
std::shared_ptr<Media::PixelMap> GetDispalySnapshot(DisplayId displayId) override;
// colorspace, gamut

View File

@ -53,7 +53,7 @@ public:
DisplayId GetDefaultDisplayId() override;
sptr<DisplayInfo> GetDisplayInfoById(DisplayId displayId) override;
sptr<DisplayInfo> GetDisplayInfoByScreen(ScreenId screenId) override;
bool RequestRotation(ScreenId screenId, Rotation rotation) override;
bool SetOrientation(ScreenId screenId, Orientation orientation) override;
std::shared_ptr<Media::PixelMap> GetDispalySnapshot(DisplayId displayId) override;
ScreenId GetRSScreenId(DisplayId displayId) const;

View File

@ -95,6 +95,11 @@ void AbstractDisplay::SetId(DisplayId id)
id_ = id;
}
void AbstractDisplay::SetOrientation(Orientation orientation)
{
orientation_ = orientation;
}
bool AbstractDisplay::RequestRotation(Rotation rotation)
{
WLOGD("request rotation from %{public}u to %{public}u, display %{public}" PRIu64"", rotation_, rotation, id_);
@ -158,6 +163,8 @@ sptr<DisplayInfo> AbstractDisplay::ConvertToDisplayInfo() const
displayInfo->id_ = id_;
displayInfo->freshRate_ = freshRate_;
displayInfo->screenId_ = screenId_;
displayInfo->rotation_ = rotation_;
displayInfo->orientation_ = orientation_;
return displayInfo;
}
} // namespace OHOS::Rosen

View File

@ -237,16 +237,16 @@ void AbstractDisplayController::OnAbstractScreenChange(sptr<AbstractScreen> absS
return;
}
WLOGI("screen changes. id:%{public}" PRIu64"", absScreen->dmsId_);
if (event == DisplayChangeEvent::UPDATE_ROTATION) {
ProcessDisplayUpdateRotation(absScreen);
}
if (event == DisplayChangeEvent::DISPLAY_SIZE_CHANGED) {
if (event == DisplayChangeEvent::UPDATE_ORIENTATION) {
ProcessDisplayUpdateOrientation(absScreen);
} else if (event == DisplayChangeEvent::DISPLAY_SIZE_CHANGED) {
ProcessDisplaySizeChange(absScreen);
} else {
WLOGE("unknow screen change event. id:%{public}" PRIu64" event %{public}u", absScreen->dmsId_, event);
}
}
void AbstractDisplayController::ProcessDisplayUpdateRotation(sptr<AbstractScreen> absScreen)
void AbstractDisplayController::ProcessDisplayUpdateOrientation(sptr<AbstractScreen> absScreen)
{
sptr<AbstractDisplay> abstractDisplay = nullptr;
{
@ -281,15 +281,16 @@ void AbstractDisplayController::ProcessDisplayUpdateRotation(sptr<AbstractScreen
}
}
}
abstractDisplay->SetOrientation(absScreen->orientation_);
if (abstractDisplay->RequestRotation(absScreen->rotation_)) {
// Notify rotation event to WMS
DisplayManagerService::GetInstance().NotifyDisplayStateChange(abstractDisplay->GetId(),
DisplayStateChangeType::UPDATE_ROTATION);
// Notify rotation event to DisplayManager
sptr<DisplayInfo> displayInfo = abstractDisplay->ConvertToDisplayInfo();
DisplayManagerAgentController::GetInstance().OnDisplayChange(displayInfo,
DisplayChangeEvent::UPDATE_ROTATION);
}
// Notify orientation event to DisplayManager
sptr<DisplayInfo> displayInfo = abstractDisplay->ConvertToDisplayInfo();
DisplayManagerAgentController::GetInstance().OnDisplayChange(displayInfo,
DisplayChangeEvent::UPDATE_ORIENTATION);
}
void AbstractDisplayController::ProcessDisplaySizeChange(sptr<AbstractScreen> absScreen)

View File

@ -188,18 +188,43 @@ void AbstractScreen::FillScreenInfo(sptr<ScreenInfo> info) const
info->parent_ = groupDmsId_;
info->canHasChild_ = canHasChild_;
info->rotation_ = rotation_;
info->orientation_ = orientation_;
info->modeId_ = activeIdx_;
info->modes_ = modes_;
}
Rotation AbstractScreen::GetRotation() const
bool AbstractScreen::SetOrientation(Orientation orientation)
{
return rotation_;
orientation_ = orientation;
return true;
}
void AbstractScreen::RequestRotation(Rotation rotation)
Rotation AbstractScreen::CalcRotation(Orientation orientation) const
{
rotation_ = rotation;
sptr<SupportedScreenModes> info = AbstractScreen::GetActiveScreenMode();
// virtical: phone(Plugin screen); horizontal: pad & external screen
bool isVerticalScreen = info->width_ < info->height_;
switch (orientation) {
case Orientation::UNSPECIFIED: {
return Rotation::ROTATION_0;
}
case Orientation::VERTICAL: {
return isVerticalScreen ? Rotation::ROTATION_0 : Rotation::ROTATION_90;
}
case Orientation::HORIZONTAL: {
return isVerticalScreen ? Rotation::ROTATION_90 : Rotation::ROTATION_0;
}
case Orientation::REVERSE_VERTICAL: {
return isVerticalScreen ? Rotation::ROTATION_180 : Rotation::ROTATION_270;
}
case Orientation::REVERSE_HORIZONTAL: {
return isVerticalScreen ? Rotation::ROTATION_270 : Rotation::ROTATION_180;
}
default: {
WLOGE("unknown orientation %{public}u", orientation);
return Rotation::ROTATION_0;
}
}
}
AbstractScreenGroup::AbstractScreenGroup(ScreenId dmsId, ScreenId rsId, ScreenCombination combination)

View File

@ -107,7 +107,7 @@ std::shared_ptr<RSDisplayNode> AbstractScreenController::GetRSDisplayNodeByScree
if (screen == nullptr) {
return nullptr;
}
WLOGI("GetAbstractScreen: screen: %{public}" PRIu64", nodeId: %{public}" PRIu64" ",
WLOGI("GetRSDisplayNodeByScreenId: screen: %{public}" PRIu64", nodeId: %{public}" PRIu64" ",
screen->dmsId_, screen->rsDisplayNode_->GetId());
return screen->rsDisplayNode_;
}
@ -320,8 +320,8 @@ sptr<AbstractScreenGroup> AbstractScreenController::AddToGroupLocked(sptr<Abstra
res = AddAsSuccedentScreenLocked(newScreen);
}
if (res != nullptr) {
DisplayManagerAgentController::GetInstance().OnScreenChange(
newScreen->ConvertToScreenInfo(), ScreenChangeEvent::ADD_TO_GROUP);
DisplayManagerAgentController::GetInstance().OnScreenGroupChange(
newScreen->ConvertToScreenInfo(), ScreenGroupChangeEvent::ADD_TO_GROUP);
}
return res;
}
@ -351,8 +351,8 @@ sptr<AbstractScreenGroup> AbstractScreenController::RemoveFromGroupLocked(sptr<A
dmsScreenGroupMap_.erase(screenGroup->dmsId_);
dmsScreenMap_.erase(screenGroup->dmsId_);
}
DisplayManagerAgentController::GetInstance().OnScreenChange(
screen->ConvertToScreenInfo(), ScreenChangeEvent::REMOVE_FROM_GROUP);
DisplayManagerAgentController::GetInstance().OnScreenGroupChange(
screen->ConvertToScreenInfo(), ScreenGroupChangeEvent::REMOVE_FROM_GROUP);
return screenGroup;
}
@ -497,43 +497,47 @@ DMError AbstractScreenController::SetVirtualScreenSurface(ScreenId screenId, spt
return DMError::DM_OK;
}
bool AbstractScreenController::RequestRotation(ScreenId screenId, Rotation rotation)
bool AbstractScreenController::SetOrientation(ScreenId screenId, Orientation newOrientation)
{
WLOGD("request rotation: screen %{public}" PRIu64"", screenId);
WLOGD("set orientation. screen %{public}" PRIu64" orientation %{public}u", screenId, newOrientation);
auto screen = GetAbstractScreen(screenId);
if (screen == nullptr) {
WLOGFE("fail to request rotation, cannot find screen %{public}" PRIu64"", screenId);
WLOGFE("fail to set orientation, cannot find screen %{public}" PRIu64"", screenId);
return false;
}
if (screen->canHasChild_) {
WLOGE("cannot rotate the combination screen: %{public}" PRIu64"", screenId);
WLOGE("cannot set orientation to the combination. screen: %{public}" PRIu64"", screenId);
return false;
}
if (!rsInterface_.RequestRotation(screenId, static_cast<ScreenRotation>(rotation))) {
WLOGE("rotate screen fail: %{public}" PRIu64"", screenId);
return false;
if (screen->orientation_ == newOrientation) {
WLOGI("skip setting orientation. screen %{public}" PRIu64" orientation %{public}u", screenId, newOrientation);
return true;
}
Rotation before = screen->rotation_;
screen->RequestRotation(rotation);
OnScreenRotate(screenId, before, rotation);
return true;
}
void AbstractScreenController::OnScreenRotate(ScreenId dmsId, Rotation before, Rotation after)
{
auto iter = dmsScreenMap_.find(dmsId);
if (iter == dmsScreenMap_.end()) {
WLOGE("rotate screen fail, not found abstract screen %{public}" PRIu64"", dmsId);
return;
Rotation rotationAfter = screen->CalcRotation(newOrientation);
if (rotationAfter != screen->rotation_) {
WLOGI("set orientation. roatiton %{public}u", rotationAfter);
if (!rsInterface_.RequestRotation(screenId, static_cast<ScreenRotation>(rotationAfter))) {
WLOGE("rotate screen fail. %{public}" PRIu64"", screenId);
return false;
}
} else {
WLOGI("rotation not changed. screen %{public}" PRIu64" rotation %{public}u", screenId, rotationAfter);
}
sptr<AbstractScreen> abstractScreen = iter->second;
if (!screen->SetOrientation(newOrientation)) {
WLOGE("fail to set orientation, screen %{public}" PRIu64"", screenId);
return false;
}
screen->rotation_ = rotationAfter;
// Notify rotation event to ScreenManager
DisplayManagerAgentController::GetInstance().OnScreenChange(
abstractScreen->ConvertToScreenInfo(), ScreenChangeEvent::UPDATE_ROTATION);
screen->ConvertToScreenInfo(), ScreenChangeEvent::UPDATE_ORIENTATION);
// Notify rotation event to AbstractDisplayController
if (abstractScreenCallback_ != nullptr) {
abstractScreenCallback_->onChange_(abstractScreen, DisplayChangeEvent::UPDATE_ROTATION);
abstractScreenCallback_->onChange_(screen, DisplayChangeEvent::UPDATE_ORIENTATION);
}
return true;
}
DMError AbstractScreenController::GetScreenSupportedColorGamuts(ScreenId screenId,
@ -663,7 +667,7 @@ void AbstractScreenController::ProcessScreenModeChanged(ScreenId dmsScreenId)
bool AbstractScreenController::MakeMirror(ScreenId screenId, std::vector<ScreenId> screens)
{
WLOGI("AbstractScreenController::MakeMirror, screenId:%{public}" PRIu64"", screenId);
WLOGI("MakeMirror, screenId:%{public}" PRIu64"", screenId);
sptr<AbstractScreen> screen = GetAbstractScreen(screenId);
if (screen == nullptr || screen->type_ != ScreenType::REAL) {
WLOGFE("screen is nullptr, or screenType is not real.");

View File

@ -88,26 +88,43 @@ void DisplayManagerAgentController::OnScreenDisconnect(ScreenId screenId)
}
}
void DisplayManagerAgentController::OnScreenChange(sptr<ScreenInfo> screenInfo, ScreenChangeEvent screenChangeEvent)
void DisplayManagerAgentController::OnScreenChange(const sptr<ScreenInfo> screenInfo,
ScreenChangeEvent screenChangeEvent)
{
if (screenInfo == nullptr) {
return;
}
auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::SCREEN_EVENT_LISTENER);
if (agents.empty()) {
return;
}
WLOGFI("OnScreenChange");
for (auto& agent : agents) {
agent->OnScreenChange(screenInfo, screenChangeEvent);
}
}
void DisplayManagerAgentController::OnScreenGroupChange(const sptr<ScreenInfo>& screenInfo,
ScreenGroupChangeEvent groupEvent)
{
if (screenInfo == nullptr) {
return;
}
std::vector<sptr<ScreenInfo>> screenInfos;
screenInfos.push_back(screenInfo);
OnScreenChange(screenInfos, screenChangeEvent);
OnScreenGroupChange(screenInfos, groupEvent);
}
void DisplayManagerAgentController::OnScreenChange(
const std::vector<sptr<ScreenInfo>>& screenInfos, ScreenChangeEvent screenChangeEvent)
void DisplayManagerAgentController::OnScreenGroupChange(
const std::vector<sptr<ScreenInfo>>& screenInfos, ScreenGroupChangeEvent groupEvent)
{
auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::SCREEN_EVENT_LISTENER);
if (agents.empty() || screenInfos.empty()) {
return;
}
WLOGFI("OnScreenChange");
WLOGFI("OnScreenGroupChange");
for (auto& agent : agents) {
agent->OnScreenChange(screenInfos, screenChangeEvent);
agent->OnScreenGroupChange(screenInfos, groupEvent);
}
}

View File

@ -217,11 +217,11 @@ DMError DisplayManagerProxy::SetVirtualScreenSurface(ScreenId screenId, sptr<Sur
return static_cast<DMError>(reply.ReadInt32());
}
bool DisplayManagerProxy::RequestRotation(ScreenId screenId, Rotation rotation)
bool DisplayManagerProxy::SetOrientation(ScreenId screenId, Orientation orientation)
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
WLOGFW("fail to request rotation: remote is null");
WLOGFW("fail to set orientation: remote is null");
return false;
}
@ -229,19 +229,19 @@ bool DisplayManagerProxy::RequestRotation(ScreenId screenId, Rotation rotation)
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("fail to request rotation: WriteInterfaceToken failed");
WLOGFE("fail to set orientation: WriteInterfaceToken failed");
return false;
}
if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
WLOGFW("fail to request rotation: Write screenId failed");
WLOGFW("fail to set orientation: Write screenId failed");
return false;
}
if (!data.WriteUint32(static_cast<uint32_t>(rotation))) {
WLOGFW("fail to request rotation: Write rotation failed");
if (!data.WriteUint32(static_cast<uint32_t>(orientation))) {
WLOGFW("fail to set orientation: Write orientation failed");
return false;
}
if (remote->SendRequest(TRANS_ID_REQUEST_ROTATION, data, reply, option) != ERR_NONE) {
WLOGFW("fail to request rotation: SendRequest failed");
if (remote->SendRequest(TRANS_ID_SET_ORIENTATION, data, reply, option) != ERR_NONE) {
WLOGFW("fail to set orientation: SendRequest failed");
return false;
}
return reply.ReadBool();

View File

@ -170,10 +170,10 @@ DMError DisplayManagerService::SetVirtualScreenSurface(ScreenId screenId, sptr<S
return abstractScreenController_->SetVirtualScreenSurface(screenId, surface);
}
bool DisplayManagerService::RequestRotation(ScreenId screenId, Rotation rotation)
bool DisplayManagerService::SetOrientation(ScreenId screenId, Orientation orientation)
{
WM_SCOPED_TRACE("dms:RequestRotation(%" PRIu64")", screenId);
return abstractScreenController_->RequestRotation(screenId, rotation);
WM_SCOPED_TRACE("dms:SetOrientation(%" PRIu64")", screenId);
return abstractScreenController_->SetOrientation(screenId, orientation);
}
std::shared_ptr<Media::PixelMap> DisplayManagerService::GetDispalySnapshot(DisplayId displayId)

View File

@ -100,10 +100,10 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
reply.WriteInt32(static_cast<int32_t>(result));
break;
}
case TRANS_ID_REQUEST_ROTATION: {
case TRANS_ID_SET_ORIENTATION: {
ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
Rotation rotation = static_cast<Rotation>(data.ReadUint32());
reply.WriteBool(RequestRotation(screenId, rotation));
Orientation orientation = static_cast<Orientation>(data.ReadUint32());
reply.WriteBool(SetOrientation(screenId, orientation));
break;
}
case TRANS_ID_GET_DISPLAY_SNAPSHOT: {

View File

@ -40,6 +40,8 @@ public:
uint32_t GetFreshRate() const;
ScreenId GetScreenId() const;
float GetVirtualPixelRatio() const;
Rotation GetRotation() const;
Orientation GetOrientation() const;
protected:
// No more methods or variables can be defined here.

View File

@ -33,7 +33,7 @@ public:
public:
virtual void OnCreate(DisplayId) = 0;
virtual void OnDestroy(DisplayId) = 0;
virtual void OnChange(DisplayId, DisplayChangeEvent) = 0;
virtual void OnChange(DisplayId) = 0;
};
std::vector<sptr<Display>> GetAllDisplays();

View File

@ -84,11 +84,14 @@ public:
};
enum class ScreenChangeEvent : uint32_t {
UPDATE_ORIENTATION,
CHANGE_MODE,
};
enum class ScreenGroupChangeEvent : uint32_t {
ADD_TO_GROUP,
REMOVE_FROM_GROUP,
CHANGE_GROUP,
UPDATE_ROTATION,
CHANGE_MODE,
};
enum class Rotation : uint32_t {
@ -98,8 +101,21 @@ enum class Rotation : uint32_t {
ROTATION_270,
};
enum class Orientation : uint32_t {
BEGIN = 0,
UNSPECIFIED = BEGIN,
VERTICAL = 1,
HORIZONTAL = 2,
REVERSE_VERTICAL = 3,
REVERSE_HORIZONTAL = 4,
SENSOR = 5,
SENSOR_VERTICAL = 6,
SENSOR_HORIZONTAL = 7,
END = SENSOR_HORIZONTAL,
};
enum class DisplayChangeEvent : uint32_t {
UPDATE_ROTATION,
UPDATE_ORIENTATION,
DISPLAY_SIZE_CHANGED,
UNKNOWN,
};

View File

@ -71,12 +71,13 @@ public:
uint32_t GetVirtualWidth() const;
uint32_t GetVirtualHeight() const;
float GetVirtualPixelRatio() const;
bool RequestRotation(Rotation rotation) const;
Rotation GetRotation() const;
Orientation GetOrientation() const;
ScreenId GetParentId() const;
uint32_t GetModeId() const;
std::vector<sptr<SupportedScreenModes>> GetSupportedModes() const;
bool SetScreenActiveMode(uint32_t modeId);
bool SetOrientation(Orientation orientation) const;
// colorspace, gamut
DMError GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut>& colorGamuts) const;

View File

@ -31,7 +31,12 @@ public:
public:
virtual void OnConnect(ScreenId) = 0;
virtual void OnDisconnect(ScreenId) = 0;
virtual void OnChange(const std::vector<ScreenId>&, ScreenChangeEvent) = 0;
virtual void OnChange(ScreenId) = 0;
};
class IScreenGroupListener : public virtual RefBase {
public:
virtual void OnChange(const std::vector<ScreenId>&, ScreenGroupChangeEvent) = 0;
};
sptr<Screen> GetScreenById(ScreenId screenId);
@ -40,6 +45,8 @@ public:
bool RegisterScreenListener(sptr<IScreenListener> listener);
bool UnregisterScreenListener(sptr<IScreenListener> listener);
bool RegisterScreenGroupListener(sptr<IScreenGroupListener> listener);
bool UnregisterScreenGroupListener(sptr<IScreenGroupListener> listener);
ScreenId MakeExpand(const std::vector<ExpandOption>& options);
ScreenId MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId);
ScreenId CreateVirtualScreen(VirtualScreenOption option);

View File

@ -118,7 +118,7 @@ void JsDisplayListener::OnDestroy(DisplayId id)
callback, std::move(execute), std::move(complete)));
}
void JsDisplayListener::OnChange(DisplayId id, DisplayChangeEvent event)
void JsDisplayListener::OnChange(DisplayId id)
{
std::lock_guard<std::mutex> lock(mtx_);
WLOGFI("JsDisplayListener::OnChange is called, displayId: %{public}d", static_cast<uint32_t>(id));

View File

@ -33,7 +33,7 @@ public:
void RemoveCallback(NativeValue* jsListenerObject);
void OnCreate(DisplayId id) override;
void OnDestroy(DisplayId id) override;
void OnChange(DisplayId id, DisplayChangeEvent event) override;
void OnChange(DisplayId id) override;
private:
void CallJsMethod(const char* methodName, NativeValue* const* argv = nullptr, size_t argc = 0);

View File

@ -30,8 +30,8 @@ declare namespace screen {
function getAllScreen(): Promise<Array<Screen>>;
// Screen plug-in event; Screen resolution ratio and other parameters, combination relationship changes
function on(eventType: 'screenConnectEvent' | 'screenChangeEvent', callback: Callback<ScreenEvent>): void;
function off(eventType: 'screenConnectEvent' | 'screenChangeEvent', callback?: Callback<ScreenEvent>): void;
function on(eventType: 'connect' | 'disconnect' | 'change', callback: Callback<number>): void;
function off(eventType: 'connect' | 'disconnect' | 'change', callback?: Callback<number>): void;
/**
* make screens as expand-screen
@ -89,14 +89,14 @@ declare namespace screen {
readonly activeModeIndex: number;
readonly orientation: Orientation;
/**
* get the rotation of the screen
* set the orientation of the screen
* @devices tv, phone, tablet, wearable
* @since 8
*/
readonly rotation: Rotation;
requestRotation(rotation: Rotation): Promise<boolean>;
setOrientation(orientation: Orientation): Promise<boolean>;
setScreenActiveMode(modeIndex: number): Promise<boolean>;
}
@ -128,54 +128,15 @@ declare namespace screen {
mirrorScreenId: Array<number>;
}
/**
* screen connect or disconnect event
* @devices tv, phone, tablet, wearable
* @since 8
*/
type ScreenEvent = {
screenId: number;
type: ScreenConnectEventType;
} | {
screenId: Array<number>;
type: ScreenChangeEventType;
}
enum ScreenConnectEventType {
DISCONNECT = 0,
CONNECT = 1,
}
enum ScreenChangeEventType {
ADD_TO_GROUP = 0,
REMOVE_FROM_GROUP = 1,
CHANGE_GROUP = 2,
UPDATE_ROTATION = 3,
CHANGE_MODE = 4,
}
/**
* rotation degree of screen
* @devices tv, phone, tablet, wearable
* @since 8
*/
enum Rotation {
/**
* 0 degree
*/
ROTATION_0 = 0,
/**
* 90 degree
*/
ROTATION_90 = 1,
/**
* 180 degree
*/
ROTATION_180 = 2,
/**
* 270 degree
*/
ROTATION_270 = 3,
enum Orientation {
UNSPECIFIED = 0,
VERTICAL = 1,
HORIZONTAL = 2,
REVERSE_VERTICAL = 3,
REVERSE_HORIZONTAL = 4,
SENSOR = 5,
SENSOR_VERTICAL = 6,
SENSOR_HORIZONTAL = 7,
}
interface ScreenModeInfo {

View File

@ -61,52 +61,49 @@ void JsScreen::Finalizer(NativeEngine* engine, void* data, void* hint)
}
}
NativeValue* JsScreen::RequestRotation(NativeEngine* engine, NativeCallbackInfo* info)
NativeValue* JsScreen::SetOrientation(NativeEngine* engine, NativeCallbackInfo* info)
{
JsScreen* me = CheckParamsAndGetThis<JsScreen>(engine, info);
return (me != nullptr) ? me->OnRequestRotation(*engine, *info) : nullptr;
return (me != nullptr) ? me->OnSetOrientation(*engine, *info) : nullptr;
}
NativeValue* JsScreen::OnRequestRotation(NativeEngine& engine, NativeCallbackInfo& info)
NativeValue* JsScreen::OnSetOrientation(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsScreen::OnRequestRotation is called");
WLOGFI("JsScreen::OnSetOrientation is called");
bool paramValidFlag = true;
Rotation rotation = Rotation::ROTATION_0;
Orientation orientation = Orientation::UNSPECIFIED;
if (info.argc != ARGC_ONE) {
WLOGFE("OnRequestRotation Params not match, info argc: %{public}zu", info.argc);
WLOGFE("OnSetOrientation Params not match, info argc: %{public}zu", info.argc);
paramValidFlag = false;
} else {
if (!ConvertFromJsValue(engine, info.argv[0], rotation)) {
if (!ConvertFromJsValue(engine, info.argv[0], orientation)) {
paramValidFlag = false;
WLOGFE("Failed to convert parameter to rotation");
WLOGFE("Failed to convert parameter to orientation");
}
}
AsyncTask::CompleteCallback complete =
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
if (!paramValidFlag) {
WLOGE("JsScreen::OnRequestRotation paramValidFlag error");
WLOGE("JsScreen::OnSetOrientation paramValidFlag error");
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(DMError::DM_ERROR_INVALID_PARAM),
"JsScreen::OnRequestRotation failed."));
"JsScreen::OnSetOrientation failed."));
return;
}
if (rotation != Rotation::ROTATION_0 &&
rotation != Rotation::ROTATION_90 &&
rotation != Rotation::ROTATION_180 &&
rotation != Rotation::ROTATION_270) {
WLOGE("Rotation param error! rotation value must from enum Rotation");
if (orientation < Orientation::BEGIN || orientation > Orientation::END) {
WLOGE("Orientation param error! orientation value must from enum Orientation");
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(DMError::DM_ERROR_INVALID_PARAM),
"JsScreen::OnRequestRotation failed."));
"JsScreen::OnSetOrientation failed."));
return;
}
bool res = screen_->RequestRotation(rotation);
bool res = screen_->SetOrientation(orientation);
if (res) {
task.Resolve(engine, CreateJsValue(engine, true));
WLOGFI("JsScreen::OnRequestRotation success");
WLOGFI("JsScreen::OnSetOrientation success");
} else {
task.Resolve(engine, CreateJsError(engine, false, "JsScreen::OnRequestRotation failed."));
WLOGFE("JsScreen::OnRequestRotation failed");
task.Resolve(engine, CreateJsError(engine, false, "JsScreen::OnSetOrientation failed."));
WLOGFE("JsScreen::OnSetOrientation failed");
}
};
NativeValue* lastParam = nullptr;
@ -178,7 +175,7 @@ NativeValue* CreateJsScreenObject(NativeEngine& engine, sptr<Screen>& screen)
object->SetProperty("id", CreateJsValue(engine, static_cast<uint32_t>(screen->GetId())));
object->SetProperty("parent", CreateJsValue(engine, static_cast<uint32_t>(screen->GetParentId())));
object->SetProperty("rotation", CreateJsValue(engine, screen->GetRotation()));
object->SetProperty("orientation", CreateJsValue(engine, screen->GetOrientation()));
object->SetProperty("activeModeIndex", CreateJsValue(engine, screen->GetModeId()));
object->SetProperty("supportedModeInfo", CreateJsScreenModeArrayObject(engine, screen->GetSupportedModes()));
@ -188,7 +185,7 @@ NativeValue* CreateJsScreenObject(NativeEngine& engine, sptr<Screen>& screen)
std::lock_guard<std::recursive_mutex> lock(g_mutex);
g_JsScreenMap[screenId] = JsScreenRef;
BindNativeFunction(engine, *object, "setScreenActiveMode", JsScreen::SetScreenActiveMode);
BindNativeFunction(engine, *object, "requestRotation", JsScreen::RequestRotation);
BindNativeFunction(engine, *object, "setOrientation", JsScreen::SetOrientation);
return objValue;
}

View File

@ -31,11 +31,11 @@ public:
~JsScreen();
static void Finalizer(NativeEngine* engine, void* data, void* hint);
static NativeValue* SetScreenActiveMode(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* RequestRotation(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetOrientation(NativeEngine* engine, NativeCallbackInfo* info);
private:
sptr<Screen> screen_ = nullptr;
NativeValue* OnRequestRotation(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSetOrientation(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSetScreenActiveMode(NativeEngine& engine, NativeCallbackInfo& info);
};
} // namespace Rosen

View File

@ -83,16 +83,8 @@ void JsScreenListener::OnConnect(ScreenId id)
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
[=] (NativeEngine &engine, AsyncTask &task, int32_t status) {
NativeValue* propertyValue = engine_->CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(propertyValue);
if (object == nullptr) {
WLOGFE("Failed to convert prop to jsObject");
return;
}
object->SetProperty("screenId", CreateJsValue(*engine_, static_cast<uint32_t>(id)));
object->SetProperty("type", CreateJsValue(*engine_, SCREEN_CONNECT_TYPE));
NativeValue* argv[] = {propertyValue};
CallJsMethod("screenConnectEvent", argv, ArraySize(argv));
NativeValue* argv[] = {CreateJsValue(*engine_, static_cast<uint32_t>(id))};
CallJsMethod("connect", argv, ArraySize(argv));
}
);
@ -113,16 +105,8 @@ void JsScreenListener::OnDisconnect(ScreenId id)
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
[=] (NativeEngine &engine, AsyncTask &task, int32_t status) {
NativeValue* propertyValue = engine_->CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(propertyValue);
if (object == nullptr) {
WLOGFE("Failed to convert prop to jsObject");
return;
}
object->SetProperty("screenId", CreateJsValue(*engine_, static_cast<uint32_t>(id)));
object->SetProperty("type", CreateJsValue(*engine_, SCREEN_DISCONNECT_TYPE));
NativeValue* argv[] = {propertyValue};
CallJsMethod("screenConnectEvent", argv, ArraySize(argv));
NativeValue* argv[] = {CreateJsValue(*engine_, static_cast<uint32_t>(id))};
CallJsMethod("disconnect", argv, ArraySize(argv));
}
);
@ -132,7 +116,7 @@ void JsScreenListener::OnDisconnect(ScreenId id)
callback, std::move(execute), std::move(complete)));
}
void JsScreenListener::OnChange(const std::vector<ScreenId> &vector, ScreenChangeEvent event)
void JsScreenListener::OnChange(ScreenId id)
{
std::lock_guard<std::mutex> lock(mtx_);
WLOGFI("JsScreenListener::OnChange is called");
@ -143,16 +127,8 @@ void JsScreenListener::OnChange(const std::vector<ScreenId> &vector, ScreenChang
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
[=] (NativeEngine &engine, AsyncTask &task, int32_t status) {
NativeValue* propertyValue = engine_->CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(propertyValue);
if (object == nullptr) {
WLOGFE("Failed to convert prop to jsObject");
return;
}
object->SetProperty("screenId", CreateScreenIdArray(*engine_, vector));
object->SetProperty("type", CreateJsValue(*engine_, event));
NativeValue* argv[] = {propertyValue};
CallJsMethod("screenChangeEvent", argv, ArraySize(argv));
NativeValue* argv[] = {CreateJsValue(*engine_, static_cast<uint32_t>(id))};
CallJsMethod("change", argv, ArraySize(argv));
}
);

View File

@ -33,7 +33,7 @@ public:
void RemoveCallback(NativeValue* jsListenerObject);
void OnConnect(ScreenId id) override;
void OnDisconnect(ScreenId id) override;
void OnChange(const std::vector<ScreenId> &vector, ScreenChangeEvent event) override;
void OnChange(ScreenId id) override;
private:
void CallJsMethod(const char* methodName, NativeValue* const* argv = nullptr, size_t argc = 0);

View File

@ -139,7 +139,7 @@ void RegisterScreenListenerWithType(NativeEngine& engine, const std::string& typ
std::unique_ptr<NativeReference> callbackRef;
callbackRef.reset(engine.CreateReference(value, 1));
sptr<JsScreenListener> screenListener = new JsScreenListener(&engine);
if (type == "screenConnectEvent" || type == "screenChangeEvent") {
if (type == "connect" || type == "disconnect" || type == "change") {
SingletonContainer::Get<ScreenManager>().RegisterScreenListener(screenListener);
WLOGFI("JsScreenManager::RegisterScreenListenerWithType success");
} else {

View File

@ -44,6 +44,7 @@ public:
DEFINE_VAR_DEFAULT_FUNC_GET(float, XDpi, xDpi, 0.0f);
DEFINE_VAR_DEFAULT_FUNC_GET(float, YDpi, yDpi, 0.0f);
DEFINE_VAR_DEFAULT_FUNC_GET(Rotation, Rotation, rotation, Rotation::ROTATION_0);
DEFINE_VAR_DEFAULT_FUNC_GET(Orientation, Orientation, orientation, Orientation::UNSPECIFIED);
protected:
DisplayInfo() = default;
};

View File

@ -41,6 +41,7 @@ public:
DEFINE_VAR_DEFAULT_FUNC_GET(ScreenId, ParentId, parent, 0);
DEFINE_VAR_DEFAULT_FUNC_GET(bool, CanHasChild, canHasChild, false);
DEFINE_VAR_DEFAULT_FUNC_GET(Rotation, Rotation, rotation, Rotation::ROTATION_0);
DEFINE_VAR_DEFAULT_FUNC_GET(Orientation, Orientation, orientation, Orientation::UNSPECIFIED);
DEFINE_VAR_DEFAULT_FUNC_GET_SET(uint32_t, ModeId, modeId, 0);
DEFINE_VAR_FUNC_GET(std::vector<sptr<SupportedScreenModes>>, Modes, modes);
protected:

View File

@ -22,7 +22,8 @@ bool DisplayInfo::Marshalling(Parcel &parcel) const
parcel.WriteInt32(width_) && parcel.WriteInt32(height_) &&
parcel.WriteUint32(freshRate_) && parcel.WriteUint64(screenId_) &&
parcel.WriteFloat(xDpi_) && parcel.WriteFloat(yDpi_) &&
parcel.WriteUint32(static_cast<uint32_t>(rotation_));
parcel.WriteUint32(static_cast<uint32_t>(rotation_)) &&
parcel.WriteUint32(static_cast<uint32_t>(orientation_));
}
DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel)
@ -30,17 +31,19 @@ DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel)
DisplayInfo *displayInfo = new DisplayInfo();
uint32_t type = (uint32_t)DisplayType::DEFAULT;
uint32_t rotation;
uint32_t orientation;
bool res = parcel.ReadUint64(displayInfo->id_) && parcel.ReadUint32(type) &&
parcel.ReadInt32(displayInfo->width_) && parcel.ReadInt32(displayInfo->height_) &&
parcel.ReadUint32(displayInfo->freshRate_) && parcel.ReadUint64(displayInfo->screenId_) &&
parcel.ReadFloat(displayInfo->xDpi_) && parcel.ReadFloat(displayInfo->yDpi_) &&
parcel.ReadUint32(rotation);
parcel.ReadUint32(rotation) && parcel.ReadUint32(orientation);
if (!res) {
delete displayInfo;
return nullptr;
}
displayInfo->type_ = (DisplayType)type;
displayInfo->rotation_ = static_cast<Rotation>(rotation);
displayInfo->orientation_ = static_cast<Orientation>(orientation);
return displayInfo;
}
} // namespace OHOS::Rosen

View File

@ -22,6 +22,7 @@ bool ScreenInfo::Marshalling(Parcel &parcel) const
parcel.WriteUint32(virtualWidth_) && parcel.WriteUint32(virtualHeight_) &&
parcel.WriteFloat(virtualPixelRatio_) && parcel.WriteUint64(parent_) &&
parcel.WriteBool(canHasChild_) && parcel.WriteUint32(static_cast<uint32_t>(rotation_)) &&
parcel.WriteUint32(static_cast<uint32_t>(orientation_)) &&
parcel.WriteUint32(modeId_) && parcel.WriteUint32(static_cast<uint32_t>(modes_.size()));
if (!res) {
return false;
@ -52,10 +53,12 @@ bool ScreenInfo::InnerUnmarshalling(Parcel& parcel)
{
uint32_t size = 0;
uint32_t rotation;
uint32_t orientation;
bool res1 = parcel.ReadUint64(id_) &&
parcel.ReadUint32(virtualWidth_) && parcel.ReadUint32(virtualHeight_) &&
parcel.ReadFloat(virtualPixelRatio_) && parcel.ReadUint64(parent_) &&
parcel.ReadBool(canHasChild_) && parcel.ReadUint32(rotation) &&
parcel.ReadUint32(orientation) &&
parcel.ReadUint32(modeId_) && parcel.ReadUint32(size);
if (!res1) {
return false;
@ -72,6 +75,7 @@ bool ScreenInfo::InnerUnmarshalling(Parcel& parcel)
}
}
rotation_ = static_cast<Rotation>(rotation);
orientation_ = static_cast<Orientation>(orientation);
return true;
}
} // namespace OHOS::Rosen