The orientation of the build-in screen is configurable

Signed-off-by: lu <zhaolu2@huawei.com>
Change-Id: Ie2571d15def398ca5ad8aa3ff42b9433920b9753
This commit is contained in:
lu 2022-09-01 14:27:11 +08:00
parent 37ced94779
commit 8c83a04119
8 changed files with 74 additions and 34 deletions

View File

@ -33,8 +33,7 @@ public:
constexpr static int32_t DEFAULT_HIGHT = 1280;
constexpr static float DEFAULT_VIRTUAL_PIXEL_RATIO = 1.0;
constexpr static uint32_t DEFAULT_FRESH_RATE = 60;
AbstractDisplay(DisplayId id, ScreenId screenId, std::string name,
ScreenId screenGroupId, sptr<SupportedScreenModes> info);
AbstractDisplay(DisplayId id, std::string name, sptr<SupportedScreenModes>& info, sptr<AbstractScreen>& absScreen);
WM_DISALLOW_COPY_AND_MOVE(AbstractDisplay);
~AbstractDisplay() = default;
static inline bool IsVertical(Rotation rotation)
@ -70,9 +69,9 @@ public:
private:
DisplayId id_ { DISPLAY_ID_INVALID };
std::string name_ { "" };
ScreenId screenId_ { SCREEN_ID_INVALID };
ScreenId screenGroupId_ { SCREEN_ID_INVALID };
std::string name_ { "" };
int32_t offsetX_ { 0 };
int32_t offsetY_ { 0 };
int32_t width_ { 0 };

View File

@ -63,6 +63,7 @@ public:
ScreenId CreateVirtualScreen(VirtualScreenOption option, const sptr<IRemoteObject>& displayManagerAgent);
DMError DestroyVirtualScreen(ScreenId screenId);
DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface);
void SetBuildInDefaultOrientation(Orientation orientation);
bool SetOrientation(ScreenId screenId, Orientation orientation, bool isFromWindow);
bool SetRotation(ScreenId screenId, Rotation rotationAfter, bool isFromWindow);
@ -148,6 +149,7 @@ private:
sptr<IRSScreenChangeListener> rSScreenChangeListener_;
std::shared_ptr<AppExecFwk::EventHandler> controllerHandler_;
std::atomic<ScreenId> defaultRsScreenId_ {SCREEN_ID_INVALID };
Orientation buildInDefaultOrientation_ { Orientation::UNSPECIFIED };
bool isExpandCombination_ = false;
};
} // namespace OHOS::Rosen

View File

@ -26,23 +26,25 @@ namespace {
constexpr int32_t PHONE_SCREEN_WIDTH = 2160;
}
AbstractDisplay::AbstractDisplay(DisplayId id, ScreenId screenId, std::string name,
ScreenId screenGroupId, sptr<SupportedScreenModes> info)
AbstractDisplay::AbstractDisplay(DisplayId id, std::string name,
sptr<SupportedScreenModes>& info, sptr<AbstractScreen>& absScreen)
: id_(id),
screenId_(screenId),
screenGroupId_(screenGroupId),
name_(name),
screenId_(absScreen->dmsId_),
screenGroupId_(absScreen->groupDmsId_),
width_(info->width_),
height_(info->height_),
refreshRate_(info->refreshRate_)
refreshRate_(info->refreshRate_),
orientation_(absScreen->orientation_)
{
RequestRotation(absScreen->rotation_);
if (DisplayManagerService::GetCustomVirtualPixelRatio() &&
fabs(DisplayManagerService::GetCustomVirtualPixelRatio() + 1) > 1e-6) {
virtualPixelRatio_ = DisplayManagerService::GetCustomVirtualPixelRatio();
return;
}
if ((width_ >= PHONE_SCREEN_WIDTH) || (height_ >= PHONE_SCREEN_WIDTH)) {
if ((width_ == PAD_SCREEN_WIDTH) || (height_ == PAD_SCREEN_WIDTH)) {
if ((info->width_ >= PHONE_SCREEN_WIDTH) || (info->height_ >= PHONE_SCREEN_WIDTH)) {
if ((info->width_ == PAD_SCREEN_WIDTH) || (info->height_ == PAD_SCREEN_WIDTH)) {
virtualPixelRatio_ = 2.0f; // Pad is 2.0
} else {
virtualPixelRatio_ = 3.0f; // Phone is 3.0

View File

@ -466,8 +466,7 @@ void AbstractDisplayController::BindAloneScreenLocked(sptr<AbstractScreen> realA
std::ostringstream buffer;
buffer<<"display_"<<displayId;
std::string name = buffer.str();
sptr<AbstractDisplay> display = new(std::nothrow) AbstractDisplay(displayId, realAbsScreen->dmsId_,
name, realAbsScreen->groupDmsId_, info);
sptr<AbstractDisplay> display = new(std::nothrow) AbstractDisplay(displayId, name, info, realAbsScreen);
if (display == nullptr) {
WLOGFE("create display failed");
return;
@ -536,8 +535,7 @@ void AbstractDisplayController::AddScreenToExpandLocked(sptr<AbstractScreen> abs
std::ostringstream buffer;
buffer<<"display_"<<displayId;
std::string name = buffer.str();
sptr<AbstractDisplay> display = new AbstractDisplay(displayId,
absScreen->dmsId_, name, absScreen->groupDmsId_, info);
sptr<AbstractDisplay> display = new AbstractDisplay(displayId, name, info, absScreen);
Point point = abstractScreenController_->GetAbstractScreenGroup(absScreen->groupDmsId_)->
GetChildPosition(absScreen->dmsId_);
display->SetOffset(point.posX_, point.posY_);

View File

@ -282,25 +282,48 @@ void AbstractScreenController::ScreenConnectionInDisplayInit(sptr<AbstractScreen
void AbstractScreenController::ProcessScreenConnected(ScreenId rsScreenId)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (!screenIdManager_.HasRsScreenId(rsScreenId)) {
WLOGFD("connect new screen");
auto absScreen = InitAndGetScreen(rsScreenId);
if (absScreen == nullptr) {
return;
}
sptr<AbstractScreenGroup> screenGroup = AddToGroupLocked(absScreen);
if (screenGroup == nullptr) {
return;
}
NotifyScreenGroupChanged(absScreen->ConvertToScreenInfo(), ScreenGroupChangeEvent::ADD_TO_GROUP);
if (abstractScreenCallback_ != nullptr) {
abstractScreenCallback_->onConnect_(absScreen);
}
if (rSScreenChangeListener_ != nullptr) {
rSScreenChangeListener_->onConnected_();
}
} else {
if (screenIdManager_.HasRsScreenId(rsScreenId)) {
WLOGE("reconnect screen, screenId=%{public}" PRIu64"", rsScreenId);
return;
}
WLOGFD("connect new screen");
auto absScreen = InitAndGetScreen(rsScreenId);
if (absScreen == nullptr) {
return;
}
sptr<AbstractScreenGroup> screenGroup = AddToGroupLocked(absScreen);
if (screenGroup == nullptr) {
return;
}
if (rsScreenId == rsInterface_.GetDefaultScreenId() && absScreen->rsDisplayNode_ != nullptr) {
absScreen->screenRequestedOrientation_ = buildInDefaultOrientation_;
Rotation rotationAfter = absScreen->CalcRotation(absScreen->screenRequestedOrientation_);
WLOGFD("set default rotation to %{public}d for buildin screen", rotationAfter);
sptr<SupportedScreenModes> abstractScreenModes = absScreen->GetActiveScreenMode();
if (abstractScreenModes != nullptr) {
float w = abstractScreenModes->width_;
float h = abstractScreenModes->height_;
float x = 0;
float y = 0;
if (!IsVertical(rotationAfter)) {
std::swap(w, h);
x = (h - w) / 2; // 2: used to calculate offset to center display node
y = (w - h) / 2; // 2: used to calculate offset to center display node
}
// 90.f is base degree
absScreen->rsDisplayNode_->SetRotation(-90.0f * static_cast<uint32_t>(rotationAfter));
absScreen->rsDisplayNode_->SetFrame(x, y, w, h);
absScreen->rotation_ = rotationAfter;
absScreen->SetOrientation(absScreen->screenRequestedOrientation_);
}
}
NotifyScreenConnected(absScreen->ConvertToScreenInfo());
NotifyScreenGroupChanged(absScreen->ConvertToScreenInfo(), ScreenGroupChangeEvent::ADD_TO_GROUP);
if (abstractScreenCallback_ != nullptr) {
abstractScreenCallback_->onConnect_(absScreen);
}
if (rSScreenChangeListener_ != nullptr) {
rSScreenChangeListener_->onConnected_();
}
}
@ -323,7 +346,6 @@ sptr<AbstractScreen> AbstractScreenController::InitAndGetScreen(ScreenId rsScree
return nullptr;
}
dmsScreenMap_.insert(std::make_pair(dmsScreenId, absScreen));
NotifyScreenConnected(absScreen->ConvertToScreenInfo());
return absScreen;
}
@ -635,6 +657,13 @@ DMError AbstractScreenController::SetVirtualScreenSurface(ScreenId screenId, spt
return DMError::DM_OK;
}
void AbstractScreenController::SetBuildInDefaultOrientation(Orientation orientation)
{
if (orientation >= Orientation::BEGIN && orientation <= Orientation::END) {
buildInDefaultOrientation_ = orientation;
}
}
bool AbstractScreenController::SetOrientation(ScreenId screenId, Orientation newOrientation, bool isFromWindow)
{
WLOGD("set orientation. screen %{public}" PRIu64" orientation %{public}u", screenId, newOrientation);

View File

@ -108,7 +108,8 @@ bool DisplayManagerConfig::LoadConfigXml()
if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("dpi")) ||
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("defaultDeviceRotationOffset")) ||
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("cutoutArea")) ||
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("curvedScreenBoundary"))) {
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("curvedScreenBoundary")) ||
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("buildInDefaultOrientation"))) {
ReadIntNumbersConfigInfo(curNodePtr);
continue;
}

View File

@ -130,6 +130,10 @@ void DisplayManagerService::ConfigureDisplayManagerService()
displayCutoutController_->SetBuiltInDisplayCutoutSvgPath(
static_cast<std::string>(stringConfig["defaultDisplayCutoutPath"]));
}
if (numbersConfig.count("buildInDefaultOrientation") != 0) {
Orientation orientation = static_cast<Orientation>(numbersConfig["buildInDefaultOrientation"][0]);
abstractScreenController_->SetBuildInDefaultOrientation(orientation);
}
}
void DisplayManagerService::RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener)

View File

@ -36,4 +36,9 @@
<!-- default value: false -->
<!-- sample: false -->
<isWaterfallDisplay enable="false"></isWaterfallDisplay>
<!-- Indicates orientation of the built-in screen -->
<!-- 0: Orientation::UNSPECIFIED -->
<!-- 1: Orientation::VERTICAL 2: Orientation::HORIZONTAL-->
<!-- 3: Orientation::REVERSE_VERTICAL 4: Orientation::REVERSE_HORIZONTAL -->
<buildInDefaultOrientation>0</buildInDefaultOrientation>
</Configs>