add window rotation

Signed-off-by: xiaojianfeng <xiaojianfeng3@huawei.com>
Change-Id: If02a869aad72c5b3e54017d53f24d8e7452825f8
This commit is contained in:
xiaojianfeng
2022-04-02 16:09:48 +08:00
parent 42327bb543
commit 8cb2babe22
20 changed files with 159 additions and 6 deletions
+1
View File
@@ -70,6 +70,7 @@ public:
float virtualPixelRatio_ = { 1.0 };
Orientation orientation_ { Orientation::UNSPECIFIED };
Rotation rotation_ { Rotation::ROTATION_0 };
Orientation screenRequestedOrientation_ { Orientation::UNSPECIFIED };
protected:
void FillScreenInfo(sptr<ScreenInfo>) const;
const sptr<AbstractScreenController> screenController_;
@@ -59,7 +59,7 @@ public:
ScreenId CreateVirtualScreen(VirtualScreenOption option, const sptr<IRemoteObject>& displayManagerAgent);
DMError DestroyVirtualScreen(ScreenId screenId);
DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface);
bool SetOrientation(ScreenId screenId, Orientation orientation);
bool SetOrientation(ScreenId screenId, Orientation orientation, bool isFromWindow);
bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId);
std::shared_ptr<RSDisplayNode> GetRSDisplayNodeByScreenId(ScreenId dmsScreenId) const;
@@ -50,6 +50,7 @@ public:
sptr<DisplayInfo> GetDisplayInfoById(DisplayId displayId) override;
sptr<DisplayInfo> GetDisplayInfoByScreen(ScreenId screenId) override;
bool SetOrientation(ScreenId screenId, Orientation orientation) override;
bool SetOrientationFromWindow(ScreenId screenId, Orientation orientation);
std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId) override;
ScreenId GetRSScreenId(DisplayId displayId) const;
@@ -42,6 +42,7 @@ public:
std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId) const;
void UpdateRSTree(DisplayId displayId, std::shared_ptr<RSSurfaceNode>& surfaceNode, bool isAdd);
void RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener);
bool SetOrientationFromWindow(DisplayId displayId, Orientation orientation);
};
} // namespace OHOS::Rosen
+8 -1
View File
@@ -597,7 +597,7 @@ DMError AbstractScreenController::SetVirtualScreenSurface(ScreenId screenId, spt
return DMError::DM_OK;
}
bool AbstractScreenController::SetOrientation(ScreenId screenId, Orientation newOrientation)
bool AbstractScreenController::SetOrientation(ScreenId screenId, Orientation newOrientation, bool isFromWindow)
{
WLOGD("set orientation. screen %{public}" PRIu64" orientation %{public}u", screenId, newOrientation);
auto screen = GetAbstractScreen(screenId);
@@ -609,6 +609,13 @@ bool AbstractScreenController::SetOrientation(ScreenId screenId, Orientation new
WLOGE("cannot set orientation to the combination. screen: %{public}" PRIu64"", screenId);
return false;
}
if (isFromWindow) {
if (newOrientation == Orientation::UNSPECIFIED) {
newOrientation = screen->screenRequestedOrientation_;
}
} else {
screen->screenRequestedOrientation_ = newOrientation;
}
if (screen->orientation_ == newOrientation) {
WLOGI("skip setting orientation. screen %{public}" PRIu64" orientation %{public}u", screenId, newOrientation);
return true;
+7 -1
View File
@@ -150,7 +150,13 @@ DMError DisplayManagerService::SetVirtualScreenSurface(ScreenId screenId, sptr<S
bool DisplayManagerService::SetOrientation(ScreenId screenId, Orientation orientation)
{
WM_SCOPED_TRACE("dms:SetOrientation(%" PRIu64")", screenId);
return abstractScreenController_->SetOrientation(screenId, orientation);
return abstractScreenController_->SetOrientation(screenId, orientation, false);
}
bool DisplayManagerService::SetOrientationFromWindow(ScreenId screenId, Orientation orientation)
{
WM_SCOPED_TRACE("dms:SetOrientation(%" PRIu64")", screenId);
return abstractScreenController_->SetOrientation(screenId, orientation, true);
}
std::shared_ptr<Media::PixelMap> DisplayManagerService::GetDisplaySnapshot(DisplayId displayId)
@@ -117,4 +117,14 @@ void DisplayManagerServiceInner::RegisterDisplayChangeListener(sptr<IDisplayChan
{
DisplayManagerService::GetInstance().RegisterDisplayChangeListener(listener);
}
bool DisplayManagerServiceInner::SetOrientationFromWindow(DisplayId displayId, Orientation orientation)
{
auto displayInfo = GetDisplayById(displayId);
if (displayInfo == nullptr) {
return false;
}
return DisplayManagerService::GetInstance().
SetOrientationFromWindow(displayInfo->GetScreenId(), orientation);
}
} // namespace OHOS::Rosen
+2
View File
@@ -191,6 +191,8 @@ public:
virtual std::string GetContentInfo() = 0;
virtual Ace::UIContent* GetUIContent() const = 0;
virtual void OnNewWant(const AAFwk::Want& want) = 0;
virtual void SetRequestedOrientation(Orientation) = 0;
virtual Orientation GetRequestedOrientation() = 0;
virtual bool IsDecorEnable() const = 0;
virtual WMError Maximize() = 0;
+4
View File
@@ -19,6 +19,7 @@
#include <string>
#include <unordered_map>
#include "../dm/dm_common.h"
#include "wm_common.h"
namespace OHOS {
@@ -67,6 +68,8 @@ public:
const std::unordered_map<WindowType, SystemBarProperty>& GetSystemBarProperty() const;
const PointInfo& GetHitOffset() const;
WindowTag GetWindowTag() const;
Orientation GetRequestedOrientation() const;
void SetRequestedOrientation(Orientation orientation);
private:
Rect windowRect_ { 0, 0, 0, 0 };
WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
@@ -89,6 +92,7 @@ private:
{ WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() },
{ WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() },
};
Orientation requestedOrientation_ { Orientation::UNSPECIFIED };
};
} // namespace Rosen
} // namespace OHOS
+4
View File
@@ -20,6 +20,9 @@
#include <string>
#include <unordered_map>
#include "parcel.h"
#include "class_var_definition.h"
#include "dm_common.h"
#include "wm_common.h"
namespace OHOS {
@@ -118,6 +121,7 @@ private:
{ WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() },
};
bool isDecorEnable_ { false };
DEFINE_VAR_DEFAULT_FUNC_GET_SET(Orientation, RequestedOrientation, requestedOrientation, Orientation::UNSPECIFIED);
};
}
}
+1
View File
@@ -63,6 +63,7 @@ enum class PropertyChangeAction : uint32_t {
ACTION_UPDATE_FOCUSABLE = 1 << 4,
ACTION_UPDATE_TOUCHABLE = 1 << 5,
ACTION_UPDATE_CALLING_WINDOW = 1 << 6,
ACTION_UPDATE_ORIENTATION = 1 << 7,
};
namespace {
+3 -1
View File
@@ -324,7 +324,7 @@ bool WindowProperty::Marshalling(Parcel& parcel) const
parcel.WriteUint32(parentId_) && MapMarshalling(parcel) && parcel.WriteBool(isDecorEnable_) &&
parcel.WriteInt32(hitOffset_.x) && parcel.WriteInt32(hitOffset_.y) && parcel.WriteUint32(animationFlag_) &&
parcel.WriteUint32(static_cast<uint32_t>(windowSizeChangeReason_)) && parcel.WriteBool(tokenState_) &&
parcel.WriteUint32(callingWindow_);
parcel.WriteUint32(callingWindow_) && parcel.WriteUint32(static_cast<uint32_t>(requestedOrientation_));
}
sptr<WindowProperty> WindowProperty::Unmarshalling(Parcel& parcel)
@@ -356,6 +356,7 @@ sptr<WindowProperty> WindowProperty::Unmarshalling(Parcel& parcel)
property->SetWindowSizeChangeReason(static_cast<WindowSizeChangeReason>(parcel.ReadUint32()));
property->SetTokenState(parcel.ReadBool());
property->SetCallingWindow(parcel.ReadUint32());
property->SetRequestedOrientation(static_cast<Orientation>(parcel.ReadUint32()));
return property;
}
@@ -385,6 +386,7 @@ void WindowProperty::CopyFrom(const sptr<WindowProperty>& property)
isDecorEnable_ = property->isDecorEnable_;
tokenState_ = property->tokenState_;
callingWindow_ = property->callingWindow_;
requestedOrientation_ = property->requestedOrientation_;
}
}
}
+2
View File
@@ -181,6 +181,8 @@ public:
virtual const std::shared_ptr<AbilityRuntime::Context> GetContext() const override;
virtual Ace::UIContent* GetUIContent() const override;
virtual void OnNewWant(const AAFwk::Want& want) override;
virtual void SetRequestedOrientation(Orientation) override;
virtual Orientation GetRequestedOrientation() override;
// colorspace, gamut
virtual bool IsSupportWideGamut() override;
+15
View File
@@ -61,6 +61,7 @@ WindowImpl::WindowImpl(const sptr<WindowOption>& option)
property_->SetCallingWindow(option->GetCallingWindow());
property_->SetWindowFlags(option->GetWindowFlags());
property_->SetHitOffset(option->GetHitOffset());
property_->SetRequestedOrientation(option->GetRequestedOrientation());
windowTag_ = option->GetWindowTag();
keepScreenOn_ = option->IsKeepScreenOn();
turnScreenOn_ = option->IsTurnScreenOn();
@@ -1723,5 +1724,19 @@ bool WindowImpl::IsFullScreen() const
auto naviProperty = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_BAR);
return (IsLayoutFullScreen() && !statusProperty.enable_ && !naviProperty.enable_);
}
void WindowImpl::SetRequestedOrientation(Orientation orientation)
{
if (property_->GetRequestedOrientation() == orientation) {
return;
}
property_->SetRequestedOrientation(orientation);
UpdateProperty(PropertyChangeAction::ACTION_UPDATE_ORIENTATION);
}
Orientation WindowImpl::GetRequestedOrientation()
{
return property_->GetRequestedOrientation();
}
} // namespace Rosen
} // namespace OHOS
+10
View File
@@ -222,6 +222,16 @@ uint32_t WindowOption::GetCallingWindow() const
{
return callingWindow_;
}
Orientation WindowOption::GetRequestedOrientation() const
{
return requestedOrientation_;
}
void WindowOption::SetRequestedOrientation(Orientation orientation)
{
requestedOrientation_ = orientation;
}
} // namespace Rosen
} // namespace OHOS
+3
View File
@@ -63,6 +63,7 @@ private:
WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property);
WMError ResizeRect(uint32_t windowId, const Rect& rect, WindowSizeChangeReason reason);
WMError SetWindowMode(uint32_t windowId, WindowMode dstMode);
void ReSizeSystemBarPropertySizeIfNeed(sptr<WindowProperty>& property);
sptr<WindowRoot> windowRoot_;
sptr<InputWindowMonitor> inputWindowMonitor_;
@@ -72,6 +73,8 @@ private:
{ WindowType::WINDOW_TYPE_STATUS_BAR, INVALID_WINDOW_ID },
{ WindowType::WINDOW_TYPE_NAVIGATION_BAR, INVALID_WINDOW_ID },
};
std::unordered_map<WindowType, std::map<uint32_t, std::map<uint32_t, Rect>>> systemBarRect_;
std::unordered_map<DisplayId, sptr<DisplayInfo>> curDisplayInfo_;
constexpr static float SYSTEM_BAR_HEIGHT_RATIO = 0.08;
};
}
+2
View File
@@ -55,6 +55,7 @@ public:
void SetCallingWindow(uint32_t windowId);
uint32_t GetCallingWindow() const;
void SetWindowSizeChangeReason(WindowSizeChangeReason reason);
void SetRequestedOrientation(Orientation orientation);
const sptr<IWindow>& GetWindowToken() const;
uint32_t GetWindowId() const;
uint32_t GetParentId() const;
@@ -74,6 +75,7 @@ public:
const std::unordered_map<WindowType, SystemBarProperty>& GetSystemBarProperty() const;
bool IsSplitMode() const;
WindowSizeChangeReason GetWindowSizeChangeReason() const;
Orientation GetRequestedOrientation() const;
void ResetWindowSizeChangeReason();
sptr<WindowNode> parent_;
+56 -1
View File
@@ -59,6 +59,7 @@ WMError WindowController::AddWindowNode(sptr<WindowProperty>& property)
WLOGFE("current window is visible, windowId: %{public}u", node->GetWindowId());
return WMError::WM_ERROR_INVALID_OPERATION;
}
ReSizeSystemBarPropertySizeIfNeed(property);
node->GetWindowProperty()->CopyFrom(property);
// Need 'check permission'
@@ -89,6 +90,29 @@ WMError WindowController::AddWindowNode(sptr<WindowProperty>& property)
return WMError::WM_OK;
}
void WindowController::ReSizeSystemBarPropertySizeIfNeed(sptr<WindowProperty>& property)
{
auto displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(property->GetDisplayId());
uint32_t displayWidth = static_cast<uint32_t>(displayInfo->GetWidth());
uint32_t displayHeight = static_cast<uint32_t>(displayInfo->GetHeight());
if (property->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR) {
auto statusBarRectIter =
systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][displayWidth].find(displayHeight);
if (statusBarRectIter != systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][displayWidth].end()) {
property->SetWindowRect(statusBarRectIter->second);
}
} else if (property->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
auto navigationBarRectIter =
systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][displayWidth].find(displayHeight);
if (navigationBarRectIter != systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][displayWidth].end()) {
property->SetWindowRect(navigationBarRectIter->second);
}
}
if (curDisplayInfo_.find(displayInfo->GetDisplayId()) == curDisplayInfo_.end()) {
curDisplayInfo_[displayInfo->GetDisplayId()] = displayInfo;
}
}
WMError WindowController::RemoveWindowNode(uint32_t windowId)
{
WMError res = windowRoot_->RemoveWindowNode(windowId);
@@ -296,14 +320,39 @@ void WindowController::ProcessDisplayChange(DisplayId displayId, DisplayStateCha
switch (type) {
case DisplayStateChangeType::SIZE_CHANGE:
case DisplayStateChangeType::UPDATE_ROTATION: {
auto iter = curDisplayInfo_.find(displayId);
if (iter != curDisplayInfo_.end()) {
auto lastDisplayInfo = iter->second;
uint32_t lastDisplayWidth = static_cast<uint32_t>(lastDisplayInfo->GetWidth());
uint32_t lastDisplayHeight = static_cast<uint32_t>(lastDisplayInfo->GetHeight());
auto statusBarNode = windowRoot_->GetWindowNode(sysBarWinId_[WindowType::WINDOW_TYPE_STATUS_BAR]);
auto navigationBarNode =
windowRoot_->GetWindowNode(sysBarWinId_[WindowType::WINDOW_TYPE_NAVIGATION_BAR]);
systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][lastDisplayWidth][lastDisplayHeight]
= statusBarNode->GetWindowProperty()->GetWindowRect();
systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][lastDisplayWidth][lastDisplayHeight]
= navigationBarNode->GetWindowProperty()->GetWindowRect();
}
curDisplayInfo_[displayId] = displayInfo;
windowRoot_->NotifyDisplayChange(displayInfo);
// Remove 'sysBarWinId_' after SystemUI resize 'systembar'
uint32_t width = static_cast<uint32_t>(displayInfo->GetWidth());
uint32_t height = static_cast<uint32_t>(displayInfo->GetHeight() * SYSTEM_BAR_HEIGHT_RATIO);
Rect newRect = { 0, 0, width, height };
uint32_t displayWidth = static_cast<uint32_t>(displayInfo->GetWidth());
uint32_t displayHeight = static_cast<uint32_t>(displayInfo->GetHeight());
auto statusBarRectIter =
systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][displayWidth].find(displayHeight);
if (statusBarRectIter != systemBarRect_[WindowType::WINDOW_TYPE_STATUS_BAR][displayWidth].end()) {
newRect = statusBarRectIter->second;
}
ResizeRect(sysBarWinId_[WindowType::WINDOW_TYPE_STATUS_BAR], newRect, WindowSizeChangeReason::DRAG);
newRect = { 0, displayInfo->GetHeight() - static_cast<int32_t>(height), width, height };
auto navigationBarRectIter =
systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][displayWidth].find(displayHeight);
if (navigationBarRectIter != systemBarRect_[WindowType::WINDOW_TYPE_NAVIGATION_BAR][displayWidth].end()) {
newRect = navigationBarRectIter->second;
}
ResizeRect(sysBarWinId_[WindowType::WINDOW_TYPE_NAVIGATION_BAR], newRect, WindowSizeChangeReason::DRAG);
break;
}
@@ -537,6 +586,12 @@ WMError WindowController::UpdateProperty(sptr<WindowProperty>& property, Propert
node->SetCallingWindow(property->GetCallingWindow());
break;
}
case PropertyChangeAction::ACTION_UPDATE_ORIENTATION: {
node->SetRequestedOrientation(property->GetRequestedOrientation());
DisplayManagerServiceInner::GetInstance().
SetOrientationFromWindow(node->GetDisplayId(), property->GetRequestedOrientation());
break;
}
default:
break;
}
+10
View File
@@ -127,6 +127,11 @@ void WindowNode::SetWindowSizeChangeReason(WindowSizeChangeReason reason)
windowSizeChangeReason_ = reason;
}
void WindowNode::SetRequestedOrientation(Orientation orientation)
{
property_->SetRequestedOrientation(orientation);
}
void WindowNode::ResetWindowSizeChangeReason()
{
windowSizeChangeReason_ = WindowSizeChangeReason::UNDEFINED;
@@ -227,5 +232,10 @@ WindowSizeChangeReason WindowNode::GetWindowSizeChangeReason() const
{
return windowSizeChangeReason_;
}
Orientation WindowNode::GetRequestedOrientation() const
{
return property_->GetRequestedOrientation();
}
} // namespace Rosen
} // namespace OHOS
+18 -1
View File
@@ -221,6 +221,14 @@ WMError WindowRoot::AddWindowNode(uint32_t parentId, sptr<WindowNode>& node)
container->SetActiveWindow(node->GetWindowId(), false);
NotifyKeyboardSizeChangeInfo(node, container, node->GetLayoutRect());
}
WLOGFI("windowId:%{public}u, name:%{public}s, orientation:%{public}u, type:%{public}u, isMainWindow:%{public}d",
node->GetWindowId(), node->GetWindowName().c_str(), static_cast<uint32_t>(node->GetRequestedOrientation()),
node->GetWindowType(), WindowHelper::IsMainWindow(node->GetWindowType()));
if (res == WMError::WM_OK && WindowHelper::IsMainWindow(node->GetWindowType()) &&
node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) {
DisplayManagerServiceInner::GetInstance().
SetOrientationFromWindow(node->GetDisplayId(), node->GetRequestedOrientation());
}
return res;
}
@@ -512,7 +520,16 @@ WMError WindowRoot::RequestActiveWindow(uint32_t windowId)
WLOGFE("window container could not be found");
return WMError::WM_ERROR_NULLPTR;
}
return container->SetActiveWindow(windowId, false);
auto res = container->SetActiveWindow(windowId, false);
WLOGFI("windowId:%{public}u, name:%{public}s, orientation:%{public}u, type:%{public}u, isMainWindow:%{public}d",
windowId, node->GetWindowName().c_str(), static_cast<uint32_t>(node->GetRequestedOrientation()),
node->GetWindowType(), WindowHelper::IsMainWindow(node->GetWindowType()));
if (res == WMError::WM_OK && WindowHelper::IsMainWindow(node->GetWindowType()) &&
node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) {
DisplayManagerServiceInner::GetInstance().
SetOrientationFromWindow(node->GetDisplayId(), node->GetRequestedOrientation());
}
return res;
}
std::shared_ptr<RSSurfaceNode> WindowRoot::GetSurfaceNodeByAbilityToken(const sptr<IRemoteObject> &abilityToken) const