!243 支持物理屏幕的旋转

Merge pull request !243 from 赵路/master
This commit is contained in:
openharmony_ci
2022-02-13 07:29:08 +00:00
committed by Gitee
47 changed files with 394 additions and 150 deletions
+1
View File
@@ -41,6 +41,7 @@ public:
virtual ScreenId CreateVirtualScreen(VirtualScreenOption option);
virtual DMError DestroyVirtualScreen(ScreenId screenId);
virtual bool RequestRotation(ScreenId screenId, Rotation rotation);
virtual std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId);
// colorspace, gamut
+1 -1
View File
@@ -27,7 +27,7 @@ public:
~DisplayManagerAgent() = default;
virtual void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) override;
virtual void NotifyDisplayStateChanged(DisplayState state) override;
virtual void NotifyDisplayStateChanged(DisplayId id, DisplayState state) override;
};
}
}
+1 -1
View File
@@ -26,7 +26,7 @@ public:
~DisplayManagerAgentDefault() = default;
void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) override {};
void NotifyDisplayStateChanged(DisplayState state) override {};
void NotifyDisplayStateChanged(DisplayId id, DisplayState state) override {};
void OnScreenConnect(sptr<ScreenInfo>) override {};
void OnScreenDisconnect(ScreenId) override {};
void OnScreenChange(const std::vector<const sptr<ScreenInfo>>&, ScreenChangeEvent) override {};
@@ -45,7 +45,7 @@ public:
TRANS_ID_ON_DISPLAY_CHANGED,
};
virtual void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) = 0;
virtual void NotifyDisplayStateChanged(DisplayState state) = 0;
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<const sptr<ScreenInfo>>&, ScreenChangeEvent) = 0;
@@ -27,7 +27,7 @@ public:
~DisplayManagerAgentProxy() = default;
virtual void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) override;
virtual void NotifyDisplayStateChanged(DisplayState state) override;
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<const sptr<ScreenInfo>>&, ScreenChangeEvent) override;
+2 -1
View File
@@ -92,6 +92,7 @@ public:
WLOGFE("OnDisplayChange, impl is nullptr.");
return;
}
WLOGD("OnDisplayChange. display %{public}" PRIu64", event %{public}u", displayInfo->id_, event);
for (auto listener : pImpl_->displayListeners_) {
listener->OnChange(displayInfo->id_);
}
@@ -351,7 +352,7 @@ void DisplayManager::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatu
}
}
void DisplayManager::NotifyDisplayStateChanged(DisplayState state)
void DisplayManager::NotifyDisplayStateChanged(DisplayId id, DisplayState state)
{
WLOGFI("state:%{public}u", state);
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
+17 -6
View File
@@ -64,6 +64,17 @@ sptr<Display> DisplayManagerAdapter::GetDisplayById(DisplayId displayId)
return display;
}
bool DisplayManagerAdapter::RequestRotation(ScreenId screenId, Rotation rotation)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (!InitDMSProxyLocked()) {
WLOGFE("fail to request rotation: InitDMSProxyLocked failed!");
return false;
}
return displayManagerServiceProxy_->RequestRotation(screenId, rotation);
}
std::shared_ptr<Media::PixelMap> DisplayManagerAdapter::GetDisplaySnapshot(DisplayId displayId)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
@@ -85,7 +96,7 @@ DMError DisplayManagerAdapter::GetScreenSupportedColorGamuts(ScreenId screenId,
if (!InitDMSProxyLocked()) {
WLOGFE("displayManagerAdapter::GetScreenSupportedColorGamuts: InitDMSProxyLocked failed!");
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
}
DMError ret = displayManagerServiceProxy_->GetScreenSupportedColorGamuts(screenId, colorGamuts);
@@ -98,7 +109,7 @@ DMError DisplayManagerAdapter::GetScreenColorGamut(ScreenId screenId, ScreenColo
if (!InitDMSProxyLocked()) {
WLOGFE("displayManagerAdapter::GetScreenColorGamut: InitDMSProxyLocked failed!");
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
}
DMError ret = displayManagerServiceProxy_->GetScreenColorGamut(screenId, colorGamut);
@@ -111,7 +122,7 @@ DMError DisplayManagerAdapter::SetScreenColorGamut(ScreenId screenId, int32_t co
if (!InitDMSProxyLocked()) {
WLOGFE("displayManagerAdapter::SetScreenColorGamut: InitDMSProxyLocked failed!");
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
}
DMError ret = displayManagerServiceProxy_->SetScreenColorGamut(screenId, colorGamutIdx);
@@ -124,7 +135,7 @@ DMError DisplayManagerAdapter::GetScreenGamutsMap(ScreenId screenId, ScreenGamut
if (!InitDMSProxyLocked()) {
WLOGFE("displayManagerAdapter::GetScreenGamutsMap: InitDMSProxyLocked failed!");
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
}
DMError ret = displayManagerServiceProxy_->GetScreenGamutsMap(screenId, gamutMap);
@@ -137,7 +148,7 @@ DMError DisplayManagerAdapter::SetScreenGamutsMap(ScreenId screenId, ScreenGamut
if (!InitDMSProxyLocked()) {
WLOGFE("displayManagerAdapter::SetScreenGamutsMap: InitDMSProxyLocked failed!");
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
}
DMError ret = displayManagerServiceProxy_->SetScreenGamutsMap(screenId, gamutMap);
@@ -150,7 +161,7 @@ DMError DisplayManagerAdapter::SetScreenColorTransform(ScreenId screenId)
if (!InitDMSProxyLocked()) {
WLOGFE("displayManagerAdapter::SetScreenColorTransform: InitDMSProxyLocked failed!");
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED;
}
DMError ret = displayManagerServiceProxy_->SetScreenColorTransform(screenId);
+2 -2
View File
@@ -24,9 +24,9 @@ void DisplayManagerAgent::NotifyDisplayPowerEvent(DisplayPowerEvent event, Event
SingletonContainer::Get<DisplayManager>().NotifyDisplayPowerEvent(event, status);
}
void DisplayManagerAgent::NotifyDisplayStateChanged(DisplayState state)
void DisplayManagerAgent::NotifyDisplayStateChanged(DisplayId id, DisplayState state)
{
SingletonContainer::Get<DisplayManager>().NotifyDisplayStateChanged(state);
SingletonContainer::Get<DisplayManager>().NotifyDisplayStateChanged(id, state);
}
} // namespace Rosen
} // namespace OHOS
+7 -5
View File
@@ -35,9 +35,10 @@ public:
uint32_t virtualHeight_ { 0 };
float virtualPixelRatio_ { 0.0 };
ScreenId parent_ { SCREEN_ID_INVALID };
bool hasChild_ { false };
bool canHasChild_ { false };
uint32_t modeId_ { 0 };
std::vector<sptr<SupportedScreenModes>> modes_ {};
Rotation rotation_ { Rotation::ROTATION_0 };
};
Screen::Screen(const ScreenInfo* info)
@@ -52,7 +53,7 @@ Screen::Screen(const ScreenInfo* info)
pImpl_->virtualHeight_ = info->virtualHeight_;
pImpl_->virtualPixelRatio_ = info->virtualPixelRatio_;
pImpl_->parent_ = info->parent_;
pImpl_->hasChild_ = info->hasChild_;
pImpl_->canHasChild_ = info->canHasChild_;
pImpl_->modeId_ = info->modeId_;
pImpl_->modes_ = info->modes_;
}
@@ -63,7 +64,7 @@ Screen::~Screen()
bool Screen::IsGroup() const
{
return pImpl_->hasChild_;
return pImpl_->canHasChild_;
}
ScreenId Screen::GetId() const
@@ -108,12 +109,13 @@ float Screen::GetVirtualPixelRatio() const
Rotation Screen::GetRotation() const
{
return Rotation::ROTATION_0;
return pImpl_->rotation_;
}
bool Screen::RequestRotation(Rotation rotation)
{
return false;
WLOGFD("rotation the screen");
return SingletonContainer::Get<DisplayManagerAdapter>().RequestRotation(pImpl_->id_, rotation);
}
DMError Screen::GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut>& colorGamuts) const
+1
View File
@@ -81,6 +81,7 @@ public:
WLOGFE("OnScreenChange, impl is nullptr.");
return;
}
WLOGFD("OnScreenChange. event %{public}u", event);
std::vector<ScreenId> screenIds;
for (auto screenInfo : screenInfos) {
if (screenInfo->id_ != SCREEN_ID_INVALID) {
+6 -1
View File
@@ -48,7 +48,7 @@ void DisplayManagerAgentProxy::NotifyDisplayPowerEvent(DisplayPowerEvent event,
}
}
void DisplayManagerAgentProxy::NotifyDisplayStateChanged(DisplayState state)
void DisplayManagerAgentProxy::NotifyDisplayStateChanged(DisplayId id, DisplayState state)
{
MessageParcel data;
MessageParcel reply;
@@ -63,6 +63,11 @@ void DisplayManagerAgentProxy::NotifyDisplayStateChanged(DisplayState state)
return;
}
if (!data.WriteUint64(static_cast<uint64_t>(id))) {
WLOGFE("Write displayId failed");
return;
}
if (Remote()->SendRequest(TRANS_ID_NOTIFY_DISPLAY_STATE_CHANGED, data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
}
+2 -1
View File
@@ -40,7 +40,8 @@ int32_t DisplayManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& d
}
case TRANS_ID_NOTIFY_DISPLAY_STATE_CHANGED: {
DisplayState state = static_cast<DisplayState>(data.ReadUint32());
NotifyDisplayStateChanged(state);
DisplayId id = static_cast<DisplayId>(data.ReadUint64());
NotifyDisplayStateChanged(id, state);
break;
}
case TRANS_ID_ON_SCREEN_CONNECT: {
+6 -1
View File
@@ -31,7 +31,10 @@ public:
AbstractDisplay(const DisplayInfo& info);
AbstractDisplay(DisplayId id, ScreenId screenId, int32_t width, int32_t height, uint32_t freshRate);
~AbstractDisplay() = default;
static inline bool IsVertical(Rotation rotation)
{
return (rotation == Rotation::ROTATION_0 || rotation == Rotation::ROTATION_180);
}
DisplayId GetId() const;
int32_t GetWidth() const;
int32_t GetHeight() const;
@@ -47,6 +50,7 @@ public:
void SetHeight(int32_t height);
void SetFreshRate(uint32_t freshRate);
void SetVirtualPixelRatio(float virtualPixelRatio);
bool RequestRotation(Rotation rotation);
private:
DisplayId id_ { DISPLAY_ID_INVALD };
@@ -55,6 +59,7 @@ private:
int32_t height_ { 0 };
uint32_t freshRate_ { 0 };
float virtualPixelRatio_ { 1.0 };
Rotation rotation_ { Rotation::ROTATION_0 };
};
} // namespace OHOS::Rosen
#endif // FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H
@@ -42,9 +42,9 @@ public:
sptr<AbstractDisplay> GetAbstractDisplay(DisplayId displayId) const;
private:
void OnAbstractScreenConnected(sptr<AbstractScreen> absScreen);
void OnAbstractScreenDisconnected(sptr<AbstractScreen> absScreen);
void OnAbstractScreenChanged(sptr<AbstractScreen> absScreen);
void OnAbstractScreenConnect(sptr<AbstractScreen> absScreen);
void OnAbstractScreenDisconnect(sptr<AbstractScreen> absScreen);
void OnAbstractScreenChange(sptr<AbstractScreen> absScreen, DisplayChangeEvent event);
void BindAloneScreenLocked(sptr<AbstractScreen> absScreen);
void AddScreenToMirrorLocked(sptr<AbstractScreenGroup> group, sptr<AbstractScreen> realAbsScreen);
void ProcessScreenDisconnected(sptr<AbstractScreen> absScreen, sptr<AbstractScreenGroup> screenGroup);
@@ -55,7 +55,7 @@ private:
std::map<DisplayId, sptr<AbstractDisplay>> abstractDisplayMap_;
sptr<AbstractScreenController> abstractScreenController_;
sptr<AbstractScreenController::AbstractScreenCallback> abstractScreenCallback_;
OHOS::Rosen::RSInterfaces *rsInterface_;
OHOS::Rosen::RSInterfaces& rsInterface_;
class ScreenshotCallback : public SurfaceCaptureCallback, public Future<std::shared_ptr<Media::PixelMap>> {
public:
+7 -1
View File
@@ -26,8 +26,8 @@
#include "screen.h"
#include "screen_group.h"
#include "screen_info.h"
#include "screen_group_info.h"
#include "screen_info.h"
namespace OHOS::Rosen {
enum class ScreenType : uint32_t {
@@ -37,6 +37,7 @@ enum class ScreenType : uint32_t {
};
class AbstractScreenGroup;
class AbstractScreenController;
class AbstractScreen : public RefBase {
public:
AbstractScreen(ScreenId dmsId, ScreenId rsId);
@@ -46,12 +47,15 @@ public:
std::vector<sptr<SupportedScreenModes>> GetAbstractScreenModes() const;
sptr<AbstractScreenGroup> GetGroup() const;
const sptr<ScreenInfo> ConvertToScreenInfo() const;
void RequestRotation(Rotation rotation);
Rotation GetRotation() const;
void UpdateRSTree(std::shared_ptr<RSSurfaceNode>& surfaceNode, bool isAdd);
void InitRSDisplayNode(RSDisplayNodeConfig& config);
ScreenId dmsId_;
ScreenId rsId_;
bool canHasChild_ { false };
std::shared_ptr<RSDisplayNode> rsDisplayNode_;
RSDisplayNodeConfig rSDisplayNodeConfig_;
ScreenId groupDmsId_ {INVALID_SCREEN_ID};
@@ -59,8 +63,10 @@ public:
int32_t activeIdx_;
float virtualPixelRatio = { 1.0 };
std::vector<sptr<SupportedScreenModes>> modes_ = {};
Rotation rotation_ { Rotation::ROTATION_0 };
protected:
void FillScreenInfo(sptr<ScreenInfo>) const;
sptr<AbstractScreenController>& screenController_;
};
class AbstractScreenGroup : public AbstractScreen {
+12 -8
View File
@@ -23,18 +23,19 @@
#include <surface.h>
#include <transaction/rs_interfaces.h>
#include "screen.h"
#include "dm_common.h"
#include "abstract_screen.h"
#include "dm_common.h"
#include "screen.h"
namespace OHOS::Rosen {
class AbstractScreenController : public RefBase {
using OnAbstractScreenCallback = std::function<void(sptr<AbstractScreen>)>;
using OnAbstractScreenConnectCb = std::function<void(sptr<AbstractScreen>)>;
using OnAbstractScreenChangeCb = std::function<void(sptr<AbstractScreen>, DisplayChangeEvent event)>;
public:
struct AbstractScreenCallback : public RefBase {
OnAbstractScreenCallback onConnected_;
OnAbstractScreenCallback onDisconnected_;
OnAbstractScreenCallback onChanged_;
OnAbstractScreenConnectCb onConnect_;
OnAbstractScreenConnectCb onDisconnect_;
OnAbstractScreenChangeCb onChange_;
};
AbstractScreenController(std::recursive_mutex& mutex);
@@ -52,6 +53,9 @@ public:
void RegisterAbstractScreenCallback(sptr<AbstractScreenCallback> cb);
ScreenId CreateVirtualScreen(VirtualScreenOption option);
DMError DestroyVirtualScreen(ScreenId screenId);
bool RequestRotation(ScreenId screenId, Rotation rotation);
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;
@@ -60,7 +64,7 @@ public:
void DumpScreenInfo() const;
void DumpScreenGroupInfo() const;
private:
void OnRsScreenChange(ScreenId rsScreenId, ScreenEvent screenEvent);
void OnRsScreenConnectionChange(ScreenId rsScreenId, ScreenEvent screenEvent);
void ProcessScreenDisconnected(ScreenId rsScreenId);
bool FillAbstractScreen(sptr<AbstractScreen>& absScreen, ScreenId rsScreenId);
sptr<AbstractScreenGroup> AddToGroupLocked(sptr<AbstractScreen> newScreen);
@@ -70,7 +74,7 @@ private:
sptr<AbstractScreenGroup> AddAsSuccedentScreenLocked(sptr<AbstractScreen> newScreen);
std::recursive_mutex& mutex_;
OHOS::Rosen::RSInterfaces *rsInterface_;
OHOS::Rosen::RSInterfaces& rsInterface_;
std::atomic<ScreenId> dmsScreenCount_;
// No AbstractScreenGroup
std::map<ScreenId, ScreenId> rs2DmsScreenIdMap_;
@@ -32,7 +32,7 @@ public:
DisplayManagerAgentType type);
bool NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status);
bool NotifyDisplayStateChanged(DisplayState state);
bool NotifyDisplayStateChanged(DisplayId id, DisplayState state);
void OnScreenConnect(sptr<ScreenInfo> screenInfo);
void OnScreenDisconnect(ScreenId);
+5 -2
View File
@@ -46,12 +46,14 @@ public:
TRANS_ID_SET_DISPLAY_STATE,
TRANS_ID_GET_DISPLAY_STATE,
TRANS_ID_NOTIFY_DISPLAY_EVENT,
TRANS_ID_CREATE_VIRTUAL_SCREEN = 1000,
TRANS_ID_SCREEN_BASE = 1000,
TRANS_ID_CREATE_VIRTUAL_SCREEN = TRANS_ID_SCREEN_BASE,
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_REQUEST_ROTATION,
TRANS_ID_SCREENGROUP_BASE = 1100,
TRANS_ID_SCREEN_MAKE_MIRROR = TRANS_ID_SCREENGROUP_BASE,
TRANS_ID_SCREEN_MAKE_EXPAND,
@@ -69,6 +71,7 @@ public:
virtual ScreenId CreateVirtualScreen(VirtualScreenOption option) = 0;
virtual DMError DestroyVirtualScreen(ScreenId screenId) = 0;
virtual bool RequestRotation(ScreenId screenId, Rotation rotation) = 0;
virtual std::shared_ptr<Media::PixelMap> GetDispalySnapshot(DisplayId displayId) = 0;
// colorspace, gamut
@@ -91,10 +94,10 @@ public:
virtual bool SetDisplayState(DisplayState state) = 0;
virtual DisplayState GetDisplayState(DisplayId displayId) = 0;
virtual void NotifyDisplayEvent(DisplayEvent event) = 0;
virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId) = 0;
virtual sptr<ScreenInfo> GetScreenInfoById(ScreenId screenId) = 0;
virtual sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId) = 0;
virtual std::vector<sptr<ScreenInfo>> GetAllScreenInfos() = 0;
virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId) = 0;
virtual DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint) = 0;
virtual bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId) = 0;
};
+1
View File
@@ -36,6 +36,7 @@ public:
ScreenId CreateVirtualScreen(VirtualScreenOption option) override;
DMError DestroyVirtualScreen(ScreenId screenId) override;
bool RequestRotation(ScreenId screenId, Rotation rotation) override;
std::shared_ptr<Media::PixelMap> GetDispalySnapshot(DisplayId displayId) override;
// colorspace, gamut
+7 -2
View File
@@ -37,6 +37,9 @@ namespace OHOS::Rosen {
class DisplayManagerService : public SystemAbility, public DisplayManagerStub {
friend class DisplayManagerServiceInner;
friend class DisplayPowerController;
friend class AbstractDisplay;
friend class AbstractDisplayController;
friend class AbstractScreen;
DECLARE_SYSTEM_ABILITY(DisplayManagerService);
WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerService);
@@ -48,6 +51,7 @@ public:
DisplayId GetDefaultDisplayId() override;
DisplayInfo GetDisplayInfoById(DisplayId displayId) override;
bool RequestRotation(ScreenId screenId, Rotation rotation) override;
std::shared_ptr<Media::PixelMap> GetDispalySnapshot(DisplayId displayId) override;
ScreenId GetRSScreenId(DisplayId displayId) const;
@@ -74,6 +78,7 @@ public:
DisplayState GetDisplayState(DisplayId displayId) override;
void NotifyDisplayEvent(DisplayEvent event) override;
sptr<AbstractDisplay> GetAbstractDisplay(DisplayId displayId);
sptr<AbstractScreenController> GetAbstractScreenController();
sptr<AbstractDisplay> GetDisplayByDisplayId(DisplayId displayId) const;
DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId) override;
@@ -90,14 +95,14 @@ private:
DisplayId GetDisplayIdFromScreenId(ScreenId screenId);
ScreenId GetScreenIdFromDisplayId(DisplayId displayId);
void RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener);
void NotifyDisplayStateChange(DisplayStateChangeType type);
void NotifyDisplayStateChange(DisplayId id, DisplayStateChangeType type);
ScreenId GetScreenIdByDisplayId(DisplayId displayId) const;
std::shared_ptr<RSDisplayNode> GetRSDisplayNodeByDisplayId(DisplayId displayId) const;
std::recursive_mutex mutex_;
static inline SingletonDelegator<DisplayManagerService> delegator_;
sptr<AbstractScreenController> abstractScreenController_;
sptr<AbstractDisplayController> abstractDisplayController_;
sptr<AbstractScreenController> abstractScreenController_;
DisplayPowerController displayPowerController_;
std::map<ScreenId, std::shared_ptr<RSDisplayNode>> displayNodeMap_;
sptr<IDisplayChangeListener> displayChangeListener_;
+16
View File
@@ -91,6 +91,22 @@ void AbstractDisplay::SetId(DisplayId id)
id_ = id;
}
bool AbstractDisplay::RequestRotation(Rotation rotation)
{
WLOGD("request rotation from %{public}u to %{public}u, display %{public}" PRIu64"", rotation_, rotation, id_);
if (rotation_ == rotation) {
WLOGFE("rotation not change %{public}u", rotation);
return false;
}
if (IsVertical(rotation) != IsVertical(rotation_)) {
int32_t tmp = width_;
width_ = height_;
height_ = tmp;
}
rotation_ = rotation;
return true;
}
bool AbstractDisplay::BindAbstractScreen(ScreenId dmsScreenId)
{
sptr<AbstractScreenController> screenController
+61 -27
View File
@@ -20,6 +20,7 @@
#include "display_manager_agent_controller.h"
#include "display_manager_service.h"
#include "screen_group.h"
#include "window_manager_hilog.h"
namespace OHOS::Rosen {
@@ -28,13 +29,12 @@ namespace {
}
AbstractDisplayController::AbstractDisplayController(std::recursive_mutex& mutex)
: mutex_(mutex), rsInterface_(&(RSInterfaces::GetInstance()))
: mutex_(mutex), rsInterface_(RSInterfaces::GetInstance())
{
}
AbstractDisplayController::~AbstractDisplayController()
{
rsInterface_ = nullptr;
abstractScreenController_ = nullptr;
}
@@ -44,18 +44,19 @@ void AbstractDisplayController::Init(sptr<AbstractScreenController> abstractScre
displayCount_ = 0;
abstractScreenController_ = abstractScreenController;
abstractScreenCallback_ = new AbstractScreenController::AbstractScreenCallback();
abstractScreenCallback_->onConnected_
= std::bind(&AbstractDisplayController::OnAbstractScreenConnected, this, std::placeholders::_1);
abstractScreenCallback_->onDisconnected_
= std::bind(&AbstractDisplayController::OnAbstractScreenDisconnected, this, std::placeholders::_1);
abstractScreenCallback_->onChanged_
= std::bind(&AbstractDisplayController::OnAbstractScreenChanged, this, std::placeholders::_1);
abstractScreenCallback_->onConnect_
= std::bind(&AbstractDisplayController::OnAbstractScreenConnect, this, std::placeholders::_1);
abstractScreenCallback_->onDisconnect_
= std::bind(&AbstractDisplayController::OnAbstractScreenDisconnect, this, std::placeholders::_1);
abstractScreenCallback_->onChange_
= std::bind(&AbstractDisplayController::OnAbstractScreenChange, this, std::placeholders::_1,
std::placeholders::_2);
abstractScreenController->RegisterAbstractScreenCallback(abstractScreenCallback_);
// TODO: Active the code after "rsDisplayNode_->SetScreenId(rsScreenId)" is provided.
/*std::lock_guard<std::recursive_mutex> lock(mutex_);
if (dummyDisplay_ == nullptr) {
sptr<AbstractDisplay> display = new AbstractDisplay(displayCount_.fetch_add(1), SCREEN_ID_INVALID,
sptr<AbstractDisplay> display = new AbstractDisplay(this, displayCount_.fetch_add(1), SCREEN_ID_INVALID,
AbstractDisplay::DEFAULT_WIDTH, AbstractDisplay::DEFAULT_HIGHT, AbstractDisplay::DEFAULT_FRESH_RATE);
abstractDisplayMap_.insert((std::make_pair(display->GetId(), display)));
dummyDisplay_ = display;
@@ -64,19 +65,12 @@ void AbstractDisplayController::Init(sptr<AbstractScreenController> abstractScre
ScreenId AbstractDisplayController::GetDefaultScreenId()
{
if (rsInterface_ == nullptr) {
return INVALID_SCREEN_ID;
}
return rsInterface_->GetDefaultScreenId();
return rsInterface_.GetDefaultScreenId();
}
RSScreenModeInfo AbstractDisplayController::GetScreenActiveMode(ScreenId id)
{
RSScreenModeInfo screenModeInfo;
if (rsInterface_ == nullptr) {
return screenModeInfo;
}
return rsInterface_->GetScreenActiveMode(id);
return rsInterface_.GetScreenActiveMode(id);
}
sptr<AbstractDisplay> AbstractDisplayController::GetAbstractDisplay(DisplayId displayId) const
@@ -92,10 +86,6 @@ sptr<AbstractDisplay> AbstractDisplayController::GetAbstractDisplay(DisplayId di
std::shared_ptr<Media::PixelMap> AbstractDisplayController::GetScreenSnapshot(DisplayId displayId)
{
if (rsInterface_ == nullptr) {
return nullptr;
}
sptr<AbstractDisplay> abstractDisplay = GetAbstractDisplay(displayId);
if (abstractDisplay == nullptr) {
WLOGFE("DisplayManagerService::GetScreenSnapshot: GetAbstarctDisplay failed");
@@ -105,7 +95,7 @@ std::shared_ptr<Media::PixelMap> AbstractDisplayController::GetScreenSnapshot(Di
std::shared_ptr<RSDisplayNode> displayNode = abstractScreenController_->GetRSDisplayNodeByScreenId(dmsScreenId);
std::shared_ptr<ScreenshotCallback> callback = std::make_shared<ScreenshotCallback>();
rsInterface_->TakeSurfaceCapture(displayNode, callback);
rsInterface_.TakeSurfaceCapture(displayNode, callback);
std::shared_ptr<Media::PixelMap> screenshot = callback->GetResult(2000); // wait for 2000ms
if (screenshot == nullptr) {
WLOGFE("Failed to get pixelmap from RS, return nullptr!");
@@ -113,7 +103,7 @@ std::shared_ptr<Media::PixelMap> AbstractDisplayController::GetScreenSnapshot(Di
return screenshot;
}
void AbstractDisplayController::OnAbstractScreenConnected(sptr<AbstractScreen> absScreen)
void AbstractDisplayController::OnAbstractScreenConnect(sptr<AbstractScreen> absScreen)
{
WLOGI("connect new screen. id:%{public}" PRIu64"", absScreen->dmsId_);
std::lock_guard<std::recursive_mutex> lock(mutex_);
@@ -137,7 +127,7 @@ void AbstractDisplayController::OnAbstractScreenConnected(sptr<AbstractScreen> a
}
}
void AbstractDisplayController::OnAbstractScreenDisconnected(sptr<AbstractScreen> absScreen)
void AbstractDisplayController::OnAbstractScreenDisconnect(sptr<AbstractScreen> absScreen)
{
WLOGI("disconnect screen. id:%{public}" PRIu64"", absScreen->dmsId_);
if (absScreen == nullptr) {
@@ -176,8 +166,52 @@ void AbstractDisplayController::ProcessScreenDisconnected(
}
}
void AbstractDisplayController::OnAbstractScreenChanged(sptr<AbstractScreen> absScreen)
void AbstractDisplayController::OnAbstractScreenChange(sptr<AbstractScreen> absScreen, DisplayChangeEvent event)
{
if (event != DisplayChangeEvent::UPDATE_ROTATION) {
WLOGFE("unknown display event: %{public}u", event);
return;
}
sptr<AbstractDisplay> abstractDisplay = nullptr;
std::lock_guard<std::recursive_mutex> lock(mutex_);
auto iter = abstractDisplayMap_.begin();
for (; iter != abstractDisplayMap_.end(); iter++) {
abstractDisplay = iter->second;
if (abstractDisplay->GetAbstractScreenId() == absScreen->dmsId_) {
WLOGFD("find abstract display of the screen. display %{public}" PRIu64", screen %{public}" PRIu64"",
abstractDisplay->GetId(), absScreen->dmsId_);
break;
}
}
sptr<AbstractScreenGroup> group = absScreen->GetGroup();
if (group == nullptr) {
WLOGFE("cannot get screen group");
return;
}
if (iter == abstractDisplayMap_.end()) {
if (group->combination_ == ScreenCombination::SCREEN_ALONE
|| group->combination_ == ScreenCombination::SCREEN_EXPAND) {
WLOGFE("cannot find abstract display of the screen %{public}" PRIu64"", absScreen->dmsId_);
return;
} else if (group->combination_ == ScreenCombination::SCREEN_MIRROR) {
// If the 'absScreen' cannot be found in 'abstractDisplayMap_', it means that the screen is the secondary.
WLOGFI("It's the secondary screen of the mirrored.");
return;
} else {
WLOGFE("Unknow combination");
return;
}
}
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);
}
}
void AbstractDisplayController::BindAloneScreenLocked(sptr<AbstractScreen> realAbsScreen)
@@ -207,7 +241,7 @@ void AbstractDisplayController::BindAloneScreenLocked(sptr<AbstractScreen> realA
dummyDisplay_ = nullptr;
}
} else {
WLOGE("the succedent real screen should be ALONE. %{public}" PRIu64"", realAbsScreen->dmsId_);
WLOGE("The first real screen should be default screen for Phone. %{public}" PRIu64"", realAbsScreen->dmsId_);
}
}
+15 -3
View File
@@ -25,7 +25,7 @@ namespace {
}
AbstractScreen::AbstractScreen(ScreenId dmsId, ScreenId rsId)
: dmsId_(dmsId), rsId_(rsId)
: dmsId_(dmsId), rsId_(rsId), screenController_(DisplayManagerService::GetInstance().abstractScreenController_)
{
}
@@ -105,15 +105,27 @@ void AbstractScreen::FillScreenInfo(sptr<ScreenInfo> info) const
info->virtualHeight_ = virtualPixelRatio * height;
info->virtualWidth_ = virtualPixelRatio * width;
info->parent_ = groupDmsId_;
info->hasChild_ = DisplayManagerService::GetInstance().GetAbstractScreenController()->IsScreenGroup(dmsId_);
info->canHasChild_ = canHasChild_;
info->rotation_ = rotation_;
info->modeId_ = activeIdx_;
info->modes_ = modes_;
}
Rotation AbstractScreen::GetRotation() const
{
return rotation_;
}
void AbstractScreen::RequestRotation(Rotation rotation)
{
rotation_ = rotation;
}
AbstractScreenGroup::AbstractScreenGroup(ScreenId dmsId, ScreenId rsId, ScreenCombination combination)
: AbstractScreen(dmsId, rsId), combination_(combination)
: AbstractScreen(dmsId, rsId), combination_(combination)
{
type_ = ScreenType::UNDEFINE;
canHasChild_ = true;
}
AbstractScreenGroup::~AbstractScreenGroup()
+55 -33
View File
@@ -30,7 +30,7 @@ namespace {
}
AbstractScreenController::AbstractScreenController(std::recursive_mutex& mutex)
: mutex_(mutex), rsInterface_(&(RSInterfaces::GetInstance()))
: mutex_(mutex), rsInterface_(RSInterfaces::GetInstance())
{
}
@@ -42,12 +42,9 @@ void AbstractScreenController::Init()
{
WLOGFD("screen controller init");
dmsScreenCount_ = 0;
if (rsInterface_ == nullptr) {
WLOGFE("rsInterface_ is nullptr, init failed");
} else {
rsInterface_->SetScreenChangeCallback(
std::bind(&AbstractScreenController::OnRsScreenChange, this, std::placeholders::_1, std::placeholders::_2));
}
rsInterface_.SetScreenChangeCallback(
std::bind(&AbstractScreenController::OnRsScreenConnectionChange,
this, std::placeholders::_1, std::placeholders::_2));
}
std::vector<ScreenId> AbstractScreenController::GetAllScreenIds()
@@ -155,7 +152,7 @@ sptr<AbstractScreenGroup> AbstractScreenController::GetAbstractScreenGroup(Scree
ScreenId AbstractScreenController::GetDefaultAbstractScreenId()
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
ScreenId rsDefaultId = rsInterface_->GetDefaultScreenId();
ScreenId rsDefaultId = rsInterface_.GetDefaultScreenId();
if (rsDefaultId == INVALID_SCREEN_ID) {
WLOGFW("GetDefaultAbstractScreenId, rsDefaultId is invalid.");
return INVALID_SCREEN_ID;
@@ -205,9 +202,9 @@ void AbstractScreenController::RegisterAbstractScreenCallback(sptr<AbstractScree
abstractScreenCallback_ = cb;
}
void AbstractScreenController::OnRsScreenChange(ScreenId rsScreenId, ScreenEvent screenEvent)
void AbstractScreenController::OnRsScreenConnectionChange(ScreenId rsScreenId, ScreenEvent screenEvent)
{
WLOGFI("rs screen event. id:%{public}" PRIu64", event:%{public}ud", rsScreenId, static_cast<uint32_t>(screenEvent));
WLOGFI("rs screen event. id:%{public}" PRIu64", event:%{public}u", rsScreenId, static_cast<uint32_t>(screenEvent));
ScreenId dmsScreenId = SCREEN_ID_INVALID;
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (screenEvent == ScreenEvent::CONNECTED) {
@@ -226,7 +223,7 @@ void AbstractScreenController::OnRsScreenChange(ScreenId rsScreenId, ScreenEvent
dmsScreenCount_++;
sptr<AbstractScreenGroup> screenGroup = AddToGroupLocked(absScreen);
if (screenGroup != nullptr && abstractScreenCallback_ != nullptr) {
abstractScreenCallback_->onConnected_(absScreen);
abstractScreenCallback_->onConnect_(absScreen);
}
} else {
WLOGE("reconnect screen, screenId=%{public}" PRIu64"", rsScreenId);
@@ -250,7 +247,7 @@ void AbstractScreenController::ProcessScreenDisconnected(ScreenId rsScreenId)
auto dmsScreenMapIter = dmsScreenMap_.find(dmsScreenId);
if (dmsScreenMapIter != dmsScreenMap_.end()) {
if (abstractScreenCallback_ != nullptr && CheckScreenInScreenGroup(dmsScreenMapIter->second)) {
abstractScreenCallback_->onDisconnected_(dmsScreenMapIter->second);
abstractScreenCallback_->onDisconnect_(dmsScreenMapIter->second);
}
RemoveFromGroupLocked(dmsScreenMapIter->second);
dmsScreenMapIter->second->rsDisplayNode_->RemoveFromTree();
@@ -267,11 +264,7 @@ void AbstractScreenController::ProcessScreenDisconnected(ScreenId rsScreenId)
bool AbstractScreenController::FillAbstractScreen(sptr<AbstractScreen>& absScreen, ScreenId rsScreenId)
{
if (rsInterface_ == nullptr) {
WLOGFE("rsInterface_ is nullptr, FillAbstractScreen failed");
return false;
}
std::vector<RSScreenModeInfo> allModes = rsInterface_->GetScreenSupportedModes(rsScreenId);
std::vector<RSScreenModeInfo> allModes = rsInterface_.GetScreenSupportedModes(rsScreenId);
if (allModes.size() == 0) {
WLOGE("supported screen mode is 0, screenId=%{public}" PRIu64"", rsScreenId);
return false;
@@ -284,7 +277,7 @@ bool AbstractScreenController::FillAbstractScreen(sptr<AbstractScreen>& absScree
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();
int32_t activeModeId = rsInterface_.GetScreenActiveMode(rsScreenId).GetScreenModeId();
WLOGD("fill screen activeModeId:%{public}d", activeModeId);
if (activeModeId >= allModes.size()) {
WLOGE("activeModeId exceed, screenId=%{public}" PRIu64", activeModeId:%{public}d/%{public}ud",
@@ -299,7 +292,7 @@ sptr<AbstractScreenGroup> AbstractScreenController::AddToGroupLocked(sptr<Abstra
{
sptr<AbstractScreenGroup> res;
if (dmsScreenGroupMap_.empty()) {
WLOGE("connect the first screen");
WLOGI("connect the first screen");
res = AddAsFirstScreenLocked(newScreen);
} else {
res = AddAsSuccedentScreenLocked(newScreen);
@@ -402,11 +395,8 @@ sptr<AbstractScreenGroup> AbstractScreenController::AddAsSuccedentScreenLocked(s
ScreenId AbstractScreenController::CreateVirtualScreen(VirtualScreenOption option)
{
if (rsInterface_ == nullptr) {
return SCREEN_ID_INVALID;
}
std::lock_guard<std::recursive_mutex> lock(mutex_);
ScreenId result = rsInterface_->CreateVirtualScreen(option.name_, option.width_,
ScreenId result = rsInterface_.CreateVirtualScreen(option.name_, option.width_,
option.height_, option.surface_, INVALID_SCREEN_ID, option.flags_);
WLOGFI("AbstractScreenController::CreateVirtualScreen id: %{public}" PRIu64"", result);
ScreenId dmsScreenId = SCREEN_ID_INVALID;
@@ -436,9 +426,6 @@ ScreenId AbstractScreenController::CreateVirtualScreen(VirtualScreenOption optio
DMError AbstractScreenController::DestroyVirtualScreen(ScreenId screenId)
{
if (rsInterface_ == nullptr) {
return DMError::DM_ERROR_NULLPTR;
}
WLOGFI("DumpScreenInfo before Destroy VirtualScreen");
DumpScreenInfo();
WLOGFI("AbstractScreenController::DestroyVirtualScreen");
@@ -449,18 +436,57 @@ DMError AbstractScreenController::DestroyVirtualScreen(ScreenId screenId)
rsScreenId = iter->second;
}
if (rsScreenId != SCREEN_ID_INVALID && GetAbstractScreen(screenId) != nullptr) {
OnRsScreenChange(rsScreenId, ScreenEvent::DISCONNECTED);
OnRsScreenConnectionChange(rsScreenId, ScreenEvent::DISCONNECTED);
}
dms2RsScreenIdMap_.erase(screenId);
rs2DmsScreenIdMap_.erase(rsScreenId);
if (rsScreenId != SCREEN_ID_INVALID) {
rsInterface_->RemoveVirtualScreen(rsScreenId);
rsInterface_.RemoveVirtualScreen(rsScreenId);
}
WLOGFI("DumpScreenInfo after Destroy VirtualScreen");
DumpScreenInfo();
return DMError::DM_OK;
}
bool AbstractScreenController::RequestRotation(ScreenId screenId, Rotation rotation)
{
WLOGD("request rotation: screen %{public}" PRIu64"", screenId);
auto screen = GetAbstractScreen(screenId);
if (screen == nullptr) {
WLOGFE("fail to request rotation, cannot find screen %{public}" PRIu64"", screenId);
return false;
}
if (screen->canHasChild_) {
WLOGE("cannot rotate 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;
}
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;
}
sptr<AbstractScreen> abstractScreen = iter->second;
// Notify rotation event to ScreenManager
DisplayManagerAgentController::GetInstance().OnScreenChange(
abstractScreen->ConvertToScreenInfo(), ScreenChangeEvent::UPDATE_ROTATION);
// Notify rotation event to AbstractDisplayController
if (abstractScreenCallback_ != nullptr) {
abstractScreenCallback_->onChange_(abstractScreen, DisplayChangeEvent::UPDATE_ROTATION);
}
}
bool AbstractScreenController::IsScreenGroup(ScreenId screenId) const
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
@@ -470,11 +496,7 @@ bool AbstractScreenController::IsScreenGroup(ScreenId screenId) const
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);
rsInterface_.SetScreenActiveMode(screenId, modeId);
auto screen = GetAbstractScreen(screenId);
if (screen == nullptr) {
WLOGFE("SetScreenActiveMode: Get AbstractScreen failed");
@@ -48,7 +48,7 @@ bool DisplayManagerAgentController::NotifyDisplayPowerEvent(DisplayPowerEvent ev
return true;
}
bool DisplayManagerAgentController::NotifyDisplayStateChanged(DisplayState state)
bool DisplayManagerAgentController::NotifyDisplayStateChanged(DisplayId id, DisplayState state)
{
auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_STATE_LISTENER);
if (agents.empty()) {
@@ -56,7 +56,7 @@ bool DisplayManagerAgentController::NotifyDisplayStateChanged(DisplayState state
}
WLOGFI("NotifyDisplayStateChanged");
for (auto& agent : agents) {
agent->NotifyDisplayStateChanged(state);
agent->NotifyDisplayStateChanged(id, state);
}
return true;
}
+30
View File
@@ -143,6 +143,36 @@ DMError DisplayManagerProxy::DestroyVirtualScreen(ScreenId screenId)
return static_cast<DMError>(reply.ReadInt32());
}
bool DisplayManagerProxy::RequestRotation(ScreenId screenId, Rotation rotation)
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
WLOGFW("fail to request rotation: remote is null");
return false;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("fail to request rotation: WriteInterfaceToken failed");
return false;
}
if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
WLOGFW("fail to request rotation: Write screenId failed");
return false;
}
if (!data.WriteUint32(static_cast<uint32_t>(rotation))) {
WLOGFW("fail to request rotation: Write rotation failed");
return false;
}
if (remote->SendRequest(TRANS_ID_REQUEST_ROTATION, data, reply, option) != ERR_NONE) {
WLOGFW("fail to request rotation: SendRequest failed");
return false;
}
return reply.ReadBool();
}
std::shared_ptr<Media::PixelMap> DisplayManagerProxy::GetDispalySnapshot(DisplayId displayId)
{
sptr<IRemoteObject> remote = Remote();
+15 -4
View File
@@ -32,8 +32,8 @@ WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerService)
const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get<DisplayManagerService>());
DisplayManagerService::DisplayManagerService() : SystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID, true),
abstractScreenController_(new AbstractScreenController(mutex_)),
abstractDisplayController_(new AbstractDisplayController(mutex_))
abstractDisplayController_(new AbstractDisplayController(mutex_)),
abstractScreenController_(new AbstractScreenController(mutex_))
{
}
@@ -65,10 +65,10 @@ void DisplayManagerService::RegisterDisplayChangeListener(sptr<IDisplayChangeLis
WLOGFI("IDisplayChangeListener registered");
}
void DisplayManagerService::NotifyDisplayStateChange(DisplayStateChangeType type)
void DisplayManagerService::NotifyDisplayStateChange(DisplayId id, DisplayStateChangeType type)
{
if (displayChangeListener_ != nullptr) {
displayChangeListener_->OnDisplayStateChange(type);
displayChangeListener_->OnDisplayStateChange(id, type);
}
}
@@ -101,6 +101,11 @@ DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId)
return displayInfo;
}
sptr<AbstractDisplay> DisplayManagerService::GetAbstractDisplay(DisplayId displayId)
{
return abstractDisplayController_->GetAbstractDisplay(displayId);
}
ScreenId DisplayManagerService::CreateVirtualScreen(VirtualScreenOption option)
{
WM_SCOPED_TRACE("dms:CreateVirtualScreen(%s)", option.name_.c_str());
@@ -139,6 +144,12 @@ DMError DisplayManagerService::DestroyVirtualScreen(ScreenId screenId)
return abstractScreenController_->DestroyVirtualScreen(screenId);
}
bool DisplayManagerService::RequestRotation(ScreenId screenId, Rotation rotation)
{
WM_SCOPED_TRACE("dms:RequestRotation(%" PRIu64")", screenId);
return abstractScreenController_->RequestRotation(screenId, rotation);
}
std::shared_ptr<Media::PixelMap> DisplayManagerService::GetDispalySnapshot(DisplayId displayId)
{
WM_SCOPED_TRACE("dms:GetDispalySnapshot(%" PRIu64")", displayId);
@@ -39,7 +39,7 @@ DisplayId DisplayManagerServiceInner::GetDefaultDisplayId()
const sptr<AbstractDisplay> DisplayManagerServiceInner::GetDisplayById(DisplayId displayId)
{
sptr<AbstractDisplay> display = DisplayManagerService::GetInstance().GetDisplayByDisplayId(displayId);
sptr<AbstractDisplay> display = DisplayManagerService::GetInstance().GetAbstractDisplay(displayId);
if (display == nullptr) {
DisplayInfo displayInfo = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId);
display = new AbstractDisplay(displayInfo);
+6
View File
@@ -77,6 +77,12 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
reply.WriteInt32(static_cast<int32_t>(result));
break;
}
case TRANS_ID_REQUEST_ROTATION: {
ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
Rotation rotation = static_cast<Rotation>(data.ReadUint32());
reply.WriteBool(RequestRotation(screenId, rotation));
break;
}
case TRANS_ID_GET_DISPLAY_SNAPSHOT: {
DisplayId displayId = data.ReadUint64();
std::shared_ptr<Media::PixelMap> dispalySnapshot = GetDispalySnapshot(displayId);
+6 -4
View File
@@ -27,7 +27,7 @@ namespace {
bool DisplayPowerController::SuspendBegin(PowerStateChangeReason reason)
{
WLOGFI("reason:%{public}u", reason);
DisplayManagerService::GetInstance().NotifyDisplayStateChange(DisplayStateChangeType::BEFORE_SUSPEND);
DisplayManagerService::GetInstance().NotifyDisplayStateChange(DISPLAY_ID_INVALD, DisplayStateChangeType::BEFORE_SUSPEND);
return true;
}
@@ -42,7 +42,8 @@ bool DisplayPowerController::SetDisplayState(DisplayState state)
case DisplayState::ON: {
displayState_ = state;
if (!isKeyguardDrawn_) {
DisplayManagerService::GetInstance().NotifyDisplayStateChange(DisplayStateChangeType::BEFORE_UNLOCK);
DisplayManagerService::GetInstance().NotifyDisplayStateChange(DISPLAY_ID_INVALD,
DisplayStateChangeType::BEFORE_UNLOCK);
}
DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DISPLAY_ON,
EventStatus::BEGIN);
@@ -59,7 +60,7 @@ bool DisplayPowerController::SetDisplayState(DisplayState state)
return false;
}
}
DisplayManagerAgentController::GetInstance().NotifyDisplayStateChanged(state);
DisplayManagerAgentController::GetInstance().NotifyDisplayStateChanged(DISPLAY_ID_INVALD, state);
return true;
}
@@ -72,7 +73,8 @@ void DisplayPowerController::NotifyDisplayEvent(DisplayEvent event)
{
WLOGFI("DisplayEvent:%{public}u", event);
if (event == DisplayEvent::UNLOCK) {
DisplayManagerService::GetInstance().NotifyDisplayStateChange(DisplayStateChangeType::BEFORE_UNLOCK);
DisplayManagerService::GetInstance().NotifyDisplayStateChange(DISPLAY_ID_INVALD,
DisplayStateChangeType::BEFORE_UNLOCK);
DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DESKTOP_READY,
EventStatus::BEGIN);
isKeyguardDrawn_ = false;
+1 -1
View File
@@ -74,7 +74,7 @@ private:
sptr<Impl> pImpl_;
void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status);
void NotifyDisplayStateChanged(DisplayState state);
void NotifyDisplayStateChanged(DisplayId id, DisplayState state);
};
} // namespace OHOS::Rosen
+2
View File
@@ -81,6 +81,7 @@ enum class ScreenChangeEvent : uint32_t {
ADD_TO_GROUP,
REMOVE_FROM_GROUP,
CHANGE_GROUP,
UPDATE_ROTATION,
};
enum class Rotation : uint32_t {
@@ -91,6 +92,7 @@ enum class Rotation : uint32_t {
};
enum class DisplayChangeEvent : uint32_t {
UPDATE_ROTATION,
DISPLAY_SIZE_CHANGED,
};
}
+2 -1
View File
@@ -23,10 +23,11 @@ namespace Rosen {
enum class DisplayStateChangeType : uint32_t {
BEFORE_SUSPEND,
BEFORE_UNLOCK,
UPDATE_ROTATION,
};
class IDisplayChangeListener : public RefBase {
public:
virtual void OnDisplayStateChange(DisplayStateChangeType type) = 0;
virtual void OnDisplayStateChange(DisplayId id, DisplayStateChangeType type) = 0;
};
}
}
+9 -7
View File
@@ -19,6 +19,7 @@
#include <parcel.h>
#include "display.h"
#include "dm_common.h"
namespace OHOS::Rosen {
class DisplayInfo : public Parcelable {
@@ -31,13 +32,14 @@ public:
virtual bool Marshalling(Parcel& parcel) const override;
static DisplayInfo *Unmarshalling(Parcel& parcel);
DisplayId id_ {DISPLAY_ID_INVALD};
DisplayType type_ {DisplayType::DEFAULT};
int32_t width_ {0};
int32_t height_ {0};
uint32_t freshRate_ {0};
float xDpi_ {0.0};
float yDpi_ {0.0};
DisplayId id_ { DISPLAY_ID_INVALD };
DisplayType type_ {DisplayType::DEFAULT };
int32_t width_ { 0 };
int32_t height_ { 0 };
uint32_t freshRate_ { 0 };
float xDpi_ { 0.0 };
float yDpi_ { 0.0 };
Rotation rotation_ { Rotation::ROTATION_0 };
};
} // namespace OHOS::Rosen
#endif // FOUNDATION_DMSERVER_DISPLAY_INFO_H
+2 -1
View File
@@ -36,7 +36,8 @@ public:
uint32_t virtualHeight_ { 0 };
float virtualPixelRatio_ { 0.0 };
ScreenId parent_ { 0 };
bool hasChild_ { false };
bool canHasChild_ { false };
Rotation rotation_ { Rotation::ROTATION_0 };
uint32_t modeId_ { 0 };
std::vector<sptr<SupportedScreenModes>> modes_ {};
protected:
+7 -2
View File
@@ -25,6 +25,7 @@ void DisplayInfo::Update(DisplayInfo* info)
freshRate_ = info->freshRate_;
xDpi_ = info->xDpi_;
yDpi_ = info->yDpi_;
rotation_ = info->rotation_;
}
bool DisplayInfo::Marshalling(Parcel &parcel) const
@@ -32,7 +33,8 @@ bool DisplayInfo::Marshalling(Parcel &parcel) const
return parcel.WriteUint64(id_) && parcel.WriteUint32(type_) &&
parcel.WriteInt32(width_) && parcel.WriteInt32(height_) &&
parcel.WriteUint32(freshRate_) &&
parcel.WriteFloat(xDpi_) && parcel.WriteFloat(yDpi_);
parcel.WriteFloat(xDpi_) && parcel.WriteFloat(yDpi_) &&
parcel.WriteUint32(static_cast<uint32_t>(rotation_));
}
DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel)
@@ -42,14 +44,17 @@ DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel)
return nullptr;
}
uint32_t type = (uint32_t)DisplayType::DEFAULT;
uint32_t rotation;
bool res = parcel.ReadUint64(displayInfo->id_) && parcel.ReadUint32(type) &&
parcel.ReadInt32(displayInfo->width_) && parcel.ReadInt32(displayInfo->height_) &&
parcel.ReadUint32(displayInfo->freshRate_) &&
parcel.ReadFloat(displayInfo->xDpi_) && parcel.ReadFloat(displayInfo->yDpi_);
parcel.ReadFloat(displayInfo->xDpi_) && parcel.ReadFloat(displayInfo->yDpi_) &&
parcel.ReadUint32(rotation);
if (!res) {
displayInfo = nullptr;
} else {
displayInfo->type_ = (DisplayType)type;
displayInfo->rotation_ = static_cast<Rotation>(rotation);
}
return displayInfo;
}
+8 -5
View File
@@ -23,7 +23,8 @@ void ScreenInfo::Update(sptr<ScreenInfo> info)
virtualHeight_ = info->virtualHeight_;
virtualPixelRatio_ = info->virtualPixelRatio_;
parent_ = info->parent_;
hasChild_ = info->hasChild_;
canHasChild_ = info->canHasChild_;
rotation_ = info->rotation_;
modeId_ = info->modeId_;
modes_ = info->modes_;
}
@@ -33,8 +34,8 @@ bool ScreenInfo::Marshalling(Parcel &parcel) const
bool res = parcel.WriteUint64(id_) &&
parcel.WriteUint32(virtualWidth_) && parcel.WriteUint32(virtualHeight_) &&
parcel.WriteFloat(virtualPixelRatio_) && parcel.WriteUint64(parent_) &&
parcel.WriteBool(hasChild_) && parcel.WriteUint32(modeId_) &&
parcel.WriteUint32(static_cast<uint32_t>(modes_.size()));
parcel.WriteBool(canHasChild_) && parcel.WriteUint32(static_cast<uint32_t>(rotation_)) &&
parcel.WriteUint32(modeId_) && parcel.WriteUint32(static_cast<uint32_t>(modes_.size()));
if (!res) {
return false;
}
@@ -58,11 +59,12 @@ ScreenInfo* ScreenInfo::Unmarshalling(Parcel &parcel)
ScreenInfo* ScreenInfo::InnerUnmarshalling(Parcel& parcel)
{
uint32_t size = 0;
uint32_t rotation;
bool res1 = parcel.ReadUint64(id_) &&
parcel.ReadUint32(virtualWidth_) && parcel.ReadUint32(virtualHeight_) &&
parcel.ReadFloat(virtualPixelRatio_) && parcel.ReadUint64(parent_) &&
parcel.ReadBool(hasChild_) && parcel.ReadUint32(modeId_) &&
parcel.ReadUint32(size);
parcel.ReadBool(canHasChild_) && parcel.ReadUint32(rotation) &&
parcel.ReadUint32(modeId_) && parcel.ReadUint32(size);
if (!res1) {
return nullptr;
}
@@ -77,6 +79,7 @@ ScreenInfo* ScreenInfo::InnerUnmarshalling(Parcel& parcel)
return nullptr;
}
}
rotation_ = static_cast<Rotation>(rotation);
return this;
}
} // namespace OHOS::Rosen
+7 -1
View File
@@ -48,7 +48,7 @@ public:
WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property);
std::vector<Rect> GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType);
WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId);
void NotifyDisplayStateChange(DisplayStateChangeType type);
void NotifyDisplayStateChange(DisplayId id, DisplayStateChangeType type);
WMError ProcessWindowTouchedEvent(uint32_t windowId);
void MinimizeAllAppWindows(DisplayId displayId);
WMError SetWindowLayoutMode(DisplayId displayId, WindowLayoutMode mode);
@@ -61,6 +61,12 @@ private:
sptr<WindowRoot> windowRoot_;
sptr<InputWindowMonitor> inputWindowMonitor_;
std::atomic<uint32_t> windowId_ { INVALID_WINDOW_ID };
// TODO: Remove 'sysBarWinId_' after SystemUI resize 'systembar'
std::unordered_map<WindowType, uint32_t> sysBarWinId_ {
{ WindowType::WINDOW_TYPE_STATUS_BAR, INVALID_WINDOW_ID },
{ WindowType::WINDOW_TYPE_NAVIGATION_BAR, INVALID_WINDOW_ID },
};
constexpr static float SYSTEM_BAR_HEIGHT_RATIO = 0.08;
};
}
}
+1 -1
View File
@@ -45,6 +45,7 @@ public:
virtual void Reorder();
virtual void UpdateDisplayInfo();
virtual void AddWindowNode(sptr<WindowNode>& node);
virtual void LayoutWindowTree();
virtual void RemoveWindowNode(sptr<WindowNode>& node);
virtual void UpdateWindowNode(sptr<WindowNode>& node);
virtual void UpdateLayoutRect(sptr<WindowNode>& node);
@@ -63,7 +64,6 @@ protected:
};
void UpdateFloatingLayoutRect(Rect& limitRect, Rect& winRect);
void UpdateLimitRect(const sptr<WindowNode>& node, Rect& limitRect);
virtual void LayoutWindowTree();
virtual void LayoutWindowNode(sptr<WindowNode>& node);
AvoidPosType GetAvoidPosType(const Rect& rect);
void LimitWindowSize(const sptr<WindowNode>& node, const Rect& displayRect, Rect& winRect);
+2 -2
View File
@@ -36,7 +36,7 @@ namespace OHOS {
namespace Rosen {
class DisplayChangeListener : public IDisplayChangeListener {
public:
virtual void OnDisplayStateChange(DisplayStateChangeType type) override;
virtual void OnDisplayStateChange(DisplayId id, DisplayStateChangeType type) override;
};
class WindowManagerService : public SystemAbility, public WindowManagerStub {
friend class DisplayChangeListener;
@@ -89,7 +89,7 @@ private:
bool Init();
void RegisterSnapshotHandler();
void OnWindowEvent(Event event, uint32_t windowId);
void NotifyDisplayStateChange(DisplayStateChangeType type);
void NotifyDisplayStateChange(DisplayId id, DisplayStateChangeType type);
static inline SingletonDelegator<WindowManagerService> delegator;
std::recursive_mutex mutex_;
+1
View File
@@ -47,6 +47,7 @@ public:
Rect GetDisplayRect() const;
sptr<WindowNode> GetTopImmersiveNode() const;
void UpdateWindowStatus(const sptr<WindowNode>& windowId, WindowUpdateType type) const;
void UpdateDisplayRect(uint32_t width, uint32_t height);
void OnAvoidAreaChange(const std::vector<Rect>& avoidAreas);
void LayoutDividerWindow(sptr<WindowNode>& node);
+1
View File
@@ -58,6 +58,7 @@ public:
WMError SetWindowLayoutMode(DisplayId displayId, WindowLayoutMode mode);
void NotifyWindowStateChange(WindowState state, WindowStateChangeReason reason);
void NotifyDisplayChange(sptr<AbstractDisplay> abstractDisplay);
WMError RaiseZOrderForAppWindow(sptr<WindowNode>& node);
private:
+28 -8
View File
@@ -78,6 +78,11 @@ WMError WindowController::AddWindowNode(sptr<WindowProperty>& property)
}
FlushWindowInfo(property->GetWindowId());
if (node->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR ||
node->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
sysBarWinId_[node->GetWindowType()] = node->GetWindowId();
}
if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN &&
WindowHelper::IsAppWindow(node->GetWindowType())) {
WM_SCOPED_TRACE_BEGIN("controller:MinimizeStructuredAppWindowsExceptSelf");
@@ -280,20 +285,36 @@ WMError WindowController::SetAlpha(uint32_t windowId, float dstAlpha)
return WMError::WM_OK;
}
void WindowController::NotifyDisplayStateChange(DisplayStateChangeType type)
void WindowController::NotifyDisplayStateChange(DisplayId displayId, DisplayStateChangeType type)
{
WLOGFD("DisplayStateChangeType:%{public}u", type);
WindowState state;
WindowStateChangeReason reason;
switch (type) {
case DisplayStateChangeType::BEFORE_SUSPEND: {
state = WindowState::STATE_FROZEN;
reason = WindowStateChangeReason::KEYGUARD;
windowRoot_->NotifyWindowStateChange(WindowState::STATE_FROZEN, WindowStateChangeReason::KEYGUARD);
break;
}
case DisplayStateChangeType::BEFORE_UNLOCK: {
state = WindowState::STATE_UNFROZEN;
reason = WindowStateChangeReason::KEYGUARD;
windowRoot_->NotifyWindowStateChange(WindowState::STATE_UNFROZEN, WindowStateChangeReason::KEYGUARD);
break;
}
case DisplayStateChangeType::UPDATE_ROTATION: {
const sptr<AbstractDisplay> abstractDisplay
= DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId);
if (abstractDisplay == nullptr) {
WLOGFE("get display failed displayId:%{public}" PRId64 "", displayId);
return;
}
windowRoot_->NotifyDisplayChange(abstractDisplay);
// TODO: Remove 'sysBarWinId_' after SystemUI resize 'systembar'
uint32_t width = abstractDisplay->GetWidth();
uint32_t height = abstractDisplay->GetHeight() * SYSTEM_BAR_HEIGHT_RATIO;
Resize(sysBarWinId_[WindowType::WINDOW_TYPE_STATUS_BAR], width, height);
MoveTo(sysBarWinId_[WindowType::WINDOW_TYPE_STATUS_BAR], 0, 0);
Resize(sysBarWinId_[WindowType::WINDOW_TYPE_NAVIGATION_BAR], width, height);
MoveTo(sysBarWinId_[WindowType::WINDOW_TYPE_NAVIGATION_BAR], 0, abstractDisplay->GetHeight() - height);
FlushWindowInfoWithDisplayId(displayId);
break;
}
default: {
@@ -301,7 +322,6 @@ void WindowController::NotifyDisplayStateChange(DisplayStateChangeType type)
return;
}
}
windowRoot_->NotifyWindowStateChange(state, reason);
}
WMError WindowController::SetWindowType(uint32_t windowId, WindowType type)
+2 -2
View File
@@ -228,8 +228,8 @@ void WindowLayoutPolicy::UpdateLayoutRect(sptr<WindowNode>& node)
void WindowLayoutPolicy::LimitWindowSize(const sptr<WindowNode>& node, const Rect& displayRect, Rect& winRect)
{
bool floatingWindow = (node->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING);
winRect.width_ = std::min(displayRect.width_, winRect.width_);
winRect.height_ = std::min(displayRect.height_, winRect.height_);
winRect.width_ = std::min(displayRect.width_ - winRect.posX_, winRect.width_);
winRect.height_ = std::min(displayRect.height_ - winRect.posY_, winRect.height_);
bool isVertical = (displayRect.height_ > displayRect.width_) ? true : false;
WindowType windowType = node->GetWindowProperty()->GetWindowType();
if (floatingWindow && !WindowHelper::IsSystemWindow(windowType)) {
+5 -5
View File
@@ -56,10 +56,10 @@ void WindowManagerService::OnStart()
if (!Init()) {
return;
}
RegisterSnapshotHandler();
SingletonContainer::Get<WindowInnerManager>().Init();
sptr<IDisplayChangeListener> listener = new DisplayChangeListener();
DisplayManagerServiceInner::GetInstance().RegisterDisplayChangeListener(listener);
RegisterSnapshotHandler();
}
void WindowManagerService::RegisterSnapshotHandler()
@@ -289,16 +289,16 @@ void WindowManagerService::OnWindowEvent(Event event, uint32_t windowId)
}
}
void WindowManagerService::NotifyDisplayStateChange(DisplayStateChangeType type)
void WindowManagerService::NotifyDisplayStateChange(DisplayId id, DisplayStateChangeType type)
{
WM_SCOPED_TRACE("wms:NotifyDisplayStateChange(%u)", type);
std::lock_guard<std::recursive_mutex> lock(mutex_);
return windowController_->NotifyDisplayStateChange(type);
return windowController_->NotifyDisplayStateChange(id, type);
}
void DisplayChangeListener::OnDisplayStateChange(DisplayStateChangeType type)
void DisplayChangeListener::OnDisplayStateChange(DisplayId id, DisplayStateChangeType type)
{
WindowManagerService::GetInstance().NotifyDisplayStateChange(type);
WindowManagerService::GetInstance().NotifyDisplayStateChange(id, type);
}
void WindowManagerService::ProcessWindowTouchedEvent(uint32_t windowId)
+13 -1
View File
@@ -40,7 +40,7 @@ namespace {
WindowNodeContainer::WindowNodeContainer(DisplayId displayId, uint32_t width, uint32_t height) : displayId_(displayId)
{
displayRect_ = {
.posX_ = 0,
.posX_ = 0,
.posY_ = 0,
.width_ = width,
.height_ = height
@@ -62,6 +62,18 @@ WindowNodeContainer::~WindowNodeContainer()
Destroy();
}
void WindowNodeContainer::UpdateDisplayRect(uint32_t width, uint32_t height)
{
WLOGFI("update display rect, w/h=%{public}u/%{public}u", width, height);
displayRect_ = {
.posX_ = 0,
.posY_ = 0,
.width_ = width,
.height_ = height
};
layoutPolicy_->LayoutWindowTree();
}
WMError WindowNodeContainer::MinimizeStructuredAppWindowsExceptSelf(const sptr<WindowNode>& node)
{
std::vector<uint32_t> exceptionalIds = { node->GetWindowId() };
+11
View File
@@ -333,6 +333,17 @@ void WindowRoot::NotifyWindowStateChange(WindowState state, WindowStateChangeRea
}
}
void WindowRoot::NotifyDisplayChange(sptr<AbstractDisplay> abstractDisplay)
{
WLOGFD("window should be updated for display changed");
auto container = GetOrCreateWindowNodeContainer(abstractDisplay->GetId());
if (container == nullptr) {
WLOGFE("can't find window node container, failed!");
return;
}
container->UpdateDisplayRect(abstractDisplay->GetWidth(), abstractDisplay->GetHeight());
}
WMError WindowRoot::RaiseZOrderForAppWindow(sptr<WindowNode>& node)
{
if (node == nullptr) {