mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-19 17:08:11 -04:00
@@ -48,6 +48,11 @@ DisplayId Display::GetId() const
|
||||
return pImpl_->GetDisplayInfo()->GetDisplayId();
|
||||
}
|
||||
|
||||
std::string Display::GetName() const
|
||||
{
|
||||
return pImpl_->GetDisplayInfo()->GetName();
|
||||
}
|
||||
|
||||
int32_t Display::GetWidth() const
|
||||
{
|
||||
UpdateDisplayInfo();
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ bool Screen::IsGroup() const
|
||||
return pImpl_->GetScreenInfo()->GetIsScreenGroup();
|
||||
}
|
||||
|
||||
const std::string Screen::GetName() const
|
||||
std::string Screen::GetName() const
|
||||
{
|
||||
return pImpl_->GetScreenInfo()->GetName();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ 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, ScreenId screenGroupId, sptr<SupportedScreenModes> info);
|
||||
AbstractDisplay(DisplayId id, ScreenId screenId, std::string name,
|
||||
ScreenId screenGroupId, sptr<SupportedScreenModes> info);
|
||||
WM_DISALLOW_COPY_AND_MOVE(AbstractDisplay);
|
||||
~AbstractDisplay() = default;
|
||||
static inline bool IsVertical(Rotation rotation)
|
||||
@@ -71,6 +72,7 @@ private:
|
||||
DisplayId id_ { DISPLAY_ID_INVALID };
|
||||
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 };
|
||||
@@ -80,6 +82,7 @@ private:
|
||||
Rotation rotation_ { Rotation::ROTATION_0 };
|
||||
Orientation orientation_ { Orientation::UNSPECIFIED };
|
||||
FreezeFlag freezeFlag_ { FreezeFlag::UNFREEZING };
|
||||
DEFINE_VAR_DEFAULT_FUNC_SET(DisplayState, DisplayState, displayState, DisplayState::UNKNOWN);
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
#endif // FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H
|
||||
@@ -81,7 +81,8 @@ protected:
|
||||
|
||||
class AbstractScreenGroup : public AbstractScreen {
|
||||
public:
|
||||
AbstractScreenGroup(sptr<AbstractScreenController>, ScreenId dmsId, ScreenId rsId, ScreenCombination combination);
|
||||
AbstractScreenGroup(sptr<AbstractScreenController>, ScreenId dmsId, ScreenId rsId, std::string name,
|
||||
ScreenCombination combination);
|
||||
AbstractScreenGroup() = delete;
|
||||
WM_DISALLOW_COPY_AND_MOVE(AbstractScreenGroup);
|
||||
~AbstractScreenGroup();
|
||||
|
||||
@@ -26,11 +26,12 @@ namespace {
|
||||
constexpr int32_t PHONE_SCREEN_WIDTH = 2160;
|
||||
}
|
||||
|
||||
AbstractDisplay::AbstractDisplay(DisplayId id, ScreenId screenId,
|
||||
AbstractDisplay::AbstractDisplay(DisplayId id, ScreenId screenId, std::string name,
|
||||
ScreenId screenGroupId, sptr<SupportedScreenModes> info)
|
||||
: id_(id),
|
||||
screenId_(screenId),
|
||||
screenGroupId_(screenGroupId),
|
||||
name_(name),
|
||||
width_(info->width_),
|
||||
height_(info->height_),
|
||||
refreshRate_(info->refreshRate_)
|
||||
@@ -207,6 +208,7 @@ sptr<DisplayInfo> AbstractDisplay::ConvertToDisplayInfo() const
|
||||
if (displayInfo == nullptr) {
|
||||
return displayInfo;
|
||||
}
|
||||
displayInfo->name_ = name_;
|
||||
displayInfo->SetOffsetX(offsetX_);
|
||||
displayInfo->SetOffsetY(offsetY_);
|
||||
displayInfo->SetWidth(width_);
|
||||
@@ -218,6 +220,7 @@ sptr<DisplayInfo> AbstractDisplay::ConvertToDisplayInfo() const
|
||||
displayInfo->SetVirtualPixelRatio(virtualPixelRatio_);
|
||||
displayInfo->SetRotation(rotation_);
|
||||
displayInfo->SetOrientation(orientation_);
|
||||
displayInfo->displayState_ = displayState_;
|
||||
return displayInfo;
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <cinttypes>
|
||||
#include <hitrace_meter.h>
|
||||
#include <sstream>
|
||||
#include <surface.h>
|
||||
|
||||
#include "display_manager_agent_controller.h"
|
||||
@@ -453,8 +454,12 @@ void AbstractDisplayController::BindAloneScreenLocked(sptr<AbstractScreen> realA
|
||||
return;
|
||||
}
|
||||
if (dummyDisplay_ == nullptr) {
|
||||
sptr<AbstractDisplay> display = new(std::nothrow) AbstractDisplay(displayCount_.fetch_add(1),
|
||||
realAbsScreen->dmsId_, realAbsScreen->groupDmsId_, info);
|
||||
DisplayId displayId = displayCount_.fetch_add(1);
|
||||
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);
|
||||
if (display == nullptr) {
|
||||
WLOGFE("create display failed");
|
||||
return;
|
||||
@@ -519,9 +524,12 @@ void AbstractDisplayController::AddScreenToExpandLocked(sptr<AbstractScreen> abs
|
||||
WLOGE("bind display error, cannot get info.");
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<AbstractDisplay> display = new AbstractDisplay(displayCount_.fetch_add(1),
|
||||
absScreen->dmsId_, absScreen->groupDmsId_, info);
|
||||
DisplayId displayId = displayCount_.fetch_add(1);
|
||||
std::ostringstream buffer;
|
||||
buffer<<"display_"<<displayId;
|
||||
std::string name = buffer.str();
|
||||
sptr<AbstractDisplay> display = new AbstractDisplay(displayId,
|
||||
absScreen->dmsId_, name, absScreen->groupDmsId_, info);
|
||||
Point point = abstractScreenController_->GetAbstractScreenGroup(absScreen->groupDmsId_)->
|
||||
GetChildPosition(absScreen->dmsId_);
|
||||
display->SetOffset(point.posX_, point.posY_);
|
||||
|
||||
@@ -269,7 +269,8 @@ Rotation AbstractScreen::CalcRotation(Orientation orientation) const
|
||||
}
|
||||
|
||||
AbstractScreenGroup::AbstractScreenGroup(sptr<AbstractScreenController> screenController, ScreenId dmsId, ScreenId rsId,
|
||||
ScreenCombination combination) : AbstractScreen(screenController, "", dmsId, rsId), combination_(combination)
|
||||
std::string name, ScreenCombination combination) : AbstractScreen(screenController, name, dmsId, rsId),
|
||||
combination_(combination)
|
||||
{
|
||||
type_ = ScreenType::UNDEFINE;
|
||||
isScreenGroup_ = true;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
#include "abstract_screen_controller.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <hitrace_meter.h>
|
||||
#include <screen_manager/rs_screen_mode_info.h>
|
||||
@@ -276,8 +278,11 @@ void AbstractScreenController::ProcessScreenConnected(ScreenId rsScreenId)
|
||||
sptr<AbstractScreen> AbstractScreenController::InitAndGetScreen(ScreenId rsScreenId)
|
||||
{
|
||||
ScreenId dmsScreenId = screenIdManager_.CreateAndGetNewScreenId(rsScreenId);
|
||||
std::ostringstream buffer;
|
||||
buffer<<DEFAULT_SCREEN_NAME<<"_"<<dmsScreenId;
|
||||
std::string name = buffer.str();
|
||||
sptr<AbstractScreen> absScreen =
|
||||
new(std::nothrow) AbstractScreen(this, DEFAULT_SCREEN_NAME, dmsScreenId, rsScreenId);
|
||||
new(std::nothrow) AbstractScreen(this, name, dmsScreenId, rsScreenId);
|
||||
if (absScreen == nullptr) {
|
||||
WLOGFE("new AbstractScreen failed.");
|
||||
screenIdManager_.DeleteScreenId(dmsScreenId);
|
||||
@@ -421,8 +426,11 @@ bool AbstractScreenController::CheckScreenInScreenGroup(sptr<AbstractScreen> scr
|
||||
sptr<AbstractScreenGroup> AbstractScreenController::AddAsFirstScreenLocked(sptr<AbstractScreen> newScreen)
|
||||
{
|
||||
ScreenId dmsGroupScreenId = screenIdManager_.CreateAndGetNewScreenId(SCREEN_ID_INVALID);
|
||||
std::ostringstream buffer;
|
||||
buffer<<"ScreenGroup_"<<dmsGroupScreenId;
|
||||
std::string name = buffer.str();
|
||||
sptr<AbstractScreenGroup> screenGroup = new(std::nothrow) AbstractScreenGroup(this, dmsGroupScreenId,
|
||||
SCREEN_ID_INVALID, ScreenCombination::SCREEN_MIRROR);
|
||||
SCREEN_ID_INVALID, name, ScreenCombination::SCREEN_MIRROR);
|
||||
if (screenGroup == nullptr) {
|
||||
WLOGE("new AbstractScreenGroup failed");
|
||||
screenIdManager_.DeleteScreenId(dmsGroupScreenId);
|
||||
|
||||
@@ -384,6 +384,12 @@ bool DisplayManagerService::SetDisplayState(DisplayState state)
|
||||
WLOGFI("permission denied!");
|
||||
return false;
|
||||
}
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
ScreenId dmsScreenId = abstractScreenController_->GetDefaultAbstractScreenId();
|
||||
sptr<AbstractDisplay> display = abstractDisplayController_->GetAbstractDisplayByScreen(dmsScreenId);
|
||||
if (display != nullptr) {
|
||||
display->SetDisplayState(state);
|
||||
}
|
||||
return displayPowerController_->SetDisplayState(state);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ public:
|
||||
Display& operator=(const Display&) = delete;
|
||||
Display& operator=(Display&&) = delete;
|
||||
DisplayId GetId() const;
|
||||
std::string GetName() const;
|
||||
int32_t GetWidth() const;
|
||||
int32_t GetHeight() const;
|
||||
uint32_t GetRefreshRate() const;
|
||||
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
Screen& operator=(const Screen&) = delete;
|
||||
Screen& operator=(Screen&&) = delete;
|
||||
bool IsGroup() const;
|
||||
const std::string GetName() const;
|
||||
std::string GetName() const;
|
||||
ScreenId GetId() const;
|
||||
uint32_t GetWidth() const;
|
||||
uint32_t GetHeight() const;
|
||||
|
||||
@@ -26,6 +26,11 @@ namespace Rosen {
|
||||
using namespace AbilityRuntime;
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "JsDisplay"};
|
||||
const std::map<DisplayState, DisplayStateMode> NATIVE_TO_JS_DISPLAY_STATE_MAP {
|
||||
{ DisplayState::UNKNOWN, DisplayStateMode::STATE_UNKNOWN },
|
||||
{ DisplayState::OFF, DisplayStateMode::STATE_OFF },
|
||||
{ DisplayState::ON, DisplayStateMode::STATE_ON },
|
||||
};
|
||||
}
|
||||
|
||||
static thread_local std::map<DisplayId, std::shared_ptr<NativeReference>> g_JsDisplayMap;
|
||||
@@ -101,15 +106,19 @@ NativeValue* CreateJsDisplayObject(NativeEngine& engine, sptr<Display>& display)
|
||||
object->SetProperty("width", CreateJsValue(engine, info->GetWidth()));
|
||||
object->SetProperty("height", CreateJsValue(engine, info->GetHeight()));
|
||||
object->SetProperty("refreshRate", CreateJsValue(engine, info->GetRefreshRate()));
|
||||
object->SetProperty("name", engine.CreateUndefined());
|
||||
object->SetProperty("alive", engine.CreateUndefined());
|
||||
object->SetProperty("state", engine.CreateUndefined());
|
||||
object->SetProperty("name", CreateJsValue(engine, info->GetName()));
|
||||
object->SetProperty("alive", CreateJsValue(engine, true));
|
||||
if (NATIVE_TO_JS_DISPLAY_STATE_MAP.count(info->GetDisplayState()) != 0) {
|
||||
object->SetProperty("state", CreateJsValue(engine, NATIVE_TO_JS_DISPLAY_STATE_MAP.at(info->GetDisplayState())));
|
||||
} else {
|
||||
object->SetProperty("state", CreateJsValue(engine, DisplayStateMode::STATE_UNKNOWN));
|
||||
}
|
||||
object->SetProperty("rotation", CreateJsValue(engine, info->GetRotation()));
|
||||
object->SetProperty("densityDPI", CreateJsValue(engine, info->GetVirtualPixelRatio() * DOT_PER_INCH));
|
||||
object->SetProperty("densityPixels", engine.CreateUndefined());
|
||||
object->SetProperty("scaledDensity", engine.CreateUndefined());
|
||||
object->SetProperty("xDPI", engine.CreateUndefined());
|
||||
object->SetProperty("yDPI", engine.CreateUndefined());
|
||||
object->SetProperty("densityPixels", CreateJsValue(engine, info->GetVirtualPixelRatio()));
|
||||
object->SetProperty("scaledDensity", CreateJsValue(engine, info->GetVirtualPixelRatio()));
|
||||
object->SetProperty("xDPI", CreateJsValue(engine, 0.0f));
|
||||
object->SetProperty("yDPI", CreateJsValue(engine, 0.0f));
|
||||
if (jsDisplayObj == nullptr || jsDisplayObj->Get() == nullptr) {
|
||||
std::shared_ptr<NativeReference> jsDisplayRef;
|
||||
jsDisplayRef.reset(engine.CreateReference(objValue, 1));
|
||||
|
||||
@@ -23,7 +23,7 @@ private:
|
||||
|
||||
#define DEFINE_VAR_WITH_LOCK(type, memberName) \
|
||||
private: \
|
||||
std::recursive_mutex memberName##Mutex_; \
|
||||
std::atomic<bool> memberName##atomicBool_ { false }; \
|
||||
type memberName##_;
|
||||
|
||||
#define DEFINE_VAR_DEFAULT(type, memberName, defaultValue) \
|
||||
@@ -41,8 +41,15 @@ public:
|
||||
public: \
|
||||
type Get##funcName() \
|
||||
{ \
|
||||
std::lock_guard<std::recursive_mutex> lock(memberName##Mutex_); \
|
||||
return memberName##_; \
|
||||
bool expect = false; \
|
||||
type res; \
|
||||
while (!memberName##atomicBool_.compare_exchange_weak(expect, true, \
|
||||
std::memory_order_relaxed)) { \
|
||||
expect = false; \
|
||||
} \
|
||||
res = memberName##_; \
|
||||
memberName##atomicBool_.store(false); \
|
||||
return res; \
|
||||
}
|
||||
|
||||
#define DEFINE_FUNC_SET(type, funcName, memberName) \
|
||||
@@ -56,8 +63,14 @@ public:
|
||||
public: \
|
||||
void Set##funcName(type value) \
|
||||
{ \
|
||||
std::lock_guard<std::recursive_mutex> lock(memberName##Mutex_); \
|
||||
bool expect = false; \
|
||||
while (!memberName##atomicBool_.compare_exchange_weak(expect, true, \
|
||||
std::memory_order_relaxed)) { \
|
||||
expect = false; \
|
||||
} \
|
||||
\
|
||||
memberName##_ = value; \
|
||||
memberName##atomicBool_.store(false); \
|
||||
}
|
||||
|
||||
#define DEFINE_VAR_FUNC_GET(type, funcName, memberName) \
|
||||
|
||||
@@ -32,6 +32,7 @@ public:
|
||||
virtual bool Marshalling(Parcel& parcel) const override;
|
||||
static DisplayInfo *Unmarshalling(Parcel& parcel);
|
||||
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(std::string, Name, name, "");
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(DisplayId, DisplayId, id, DISPLAY_ID_INVALID);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(DisplayType, DisplayType, type, DisplayType::DEFAULT);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(int32_t, Width, width, 0);
|
||||
@@ -46,7 +47,7 @@ public:
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(Orientation, Orientation, orientation, Orientation::UNSPECIFIED);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(int32_t, OffsetX, offsetX, 0);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(int32_t, OffsetY, offsetY, 0);
|
||||
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(DisplayState, DisplayState, displayState, DisplayState::UNKNOWN);
|
||||
protected:
|
||||
DisplayInfo() = default;
|
||||
};
|
||||
|
||||
@@ -18,13 +18,14 @@
|
||||
namespace OHOS::Rosen {
|
||||
bool DisplayInfo::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
return parcel.WriteUint64(id_) && parcel.WriteUint32(static_cast<uint32_t>(type_)) &&
|
||||
return parcel.WriteString(name_) && parcel.WriteUint64(id_) && parcel.WriteUint32(static_cast<uint32_t>(type_)) &&
|
||||
parcel.WriteInt32(width_) && parcel.WriteInt32(height_) &&
|
||||
parcel.WriteUint32(refreshRate_) && parcel.WriteUint64(screenId_) &&
|
||||
parcel.WriteFloat(virtualPixelRatio_) && parcel.WriteFloat(xDpi_) && parcel.WriteFloat(yDpi_) &&
|
||||
parcel.WriteUint32(static_cast<uint32_t>(rotation_)) &&
|
||||
parcel.WriteUint32(static_cast<uint32_t>(orientation_)) &&
|
||||
parcel.WriteInt32(offsetX_) && parcel.WriteInt32(offsetY_);
|
||||
parcel.WriteInt32(offsetX_) && parcel.WriteInt32(offsetY_) &&
|
||||
parcel.WriteUint32(static_cast<uint32_t>(displayState_));
|
||||
}
|
||||
|
||||
DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel)
|
||||
@@ -36,13 +37,16 @@ DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel)
|
||||
uint32_t type = (uint32_t)DisplayType::DEFAULT;
|
||||
uint32_t rotation;
|
||||
uint32_t orientation;
|
||||
bool res = parcel.ReadUint64(displayInfo->id_) && parcel.ReadUint32(type) &&
|
||||
uint32_t displayState;
|
||||
bool res = parcel.ReadString(displayInfo->name_) &&
|
||||
parcel.ReadUint64(displayInfo->id_) && parcel.ReadUint32(type) &&
|
||||
parcel.ReadInt32(displayInfo->width_) && parcel.ReadInt32(displayInfo->height_) &&
|
||||
parcel.ReadUint32(displayInfo->refreshRate_) && parcel.ReadUint64(displayInfo->screenId_) &&
|
||||
parcel.ReadFloat(displayInfo->virtualPixelRatio_) &&
|
||||
parcel.ReadFloat(displayInfo->xDpi_) && parcel.ReadFloat(displayInfo->yDpi_) &&
|
||||
parcel.ReadUint32(rotation) && parcel.ReadUint32(orientation) &&
|
||||
parcel.ReadInt32(displayInfo->offsetX_) && parcel.ReadInt32(displayInfo->offsetY_);
|
||||
parcel.ReadInt32(displayInfo->offsetX_) && parcel.ReadInt32(displayInfo->offsetY_) &&
|
||||
parcel.ReadUint32(displayState);
|
||||
if (!res) {
|
||||
delete displayInfo;
|
||||
return nullptr;
|
||||
@@ -50,6 +54,7 @@ DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel)
|
||||
displayInfo->type_ = (DisplayType)type;
|
||||
displayInfo->rotation_ = static_cast<Rotation>(rotation);
|
||||
displayInfo->orientation_ = static_cast<Orientation>(orientation);
|
||||
displayInfo->displayState_ = static_cast<DisplayState>(displayState);
|
||||
return displayInfo;
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
Reference in New Issue
Block a user