fix magic number

Signed-off-by: l30031422 <liwei769@huawei.com>
This commit is contained in:
l30031422 2024-04-20 15:13:48 +08:00
parent fefceb7d7b
commit efacf2c44f
12 changed files with 92 additions and 64 deletions

View File

@ -17,6 +17,6 @@ import AbilityStage from '@ohos.app.ability.AbilityStage';
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
console.log('[Demo] MyAbilityStage onCreate')
}
}

View File

@ -35,6 +35,31 @@ namespace {
const std::string ARG_DUMP_ALL = "-a";
const std::string ARG_DUMP_SCREEN = "-s";
const std::string ARG_DUMP_DISPLAY = "-d";
// set the output width of screen
constexpr int W_SCREEN_NAME = 21;
constexpr int W_SCREEN_TYPE = 9;
constexpr int W_GROUP_TYPE = 8;
constexpr int W_DMS_ID = 6;
constexpr int W_RS_ID = 21;
constexpr int W_ACTIVE_IDX = 10;
constexpr int W_VIR_PIXEL_RATIO = 4;
constexpr int W_SCREEN_ROTATION = 9;
constexpr int W_ORIENTATION = 12;
constexpr int W_REQUESTED_ORIENTATION = 19;
constexpr int W_NODE_ID = 21;
constexpr int W_MIRROR_TYPE = 11;
constexpr int W_MIRROR_NODE_ID = 13;
// set the output width of display
constexpr int W_DISPLAY_ID = 10;
constexpr int W_ABSTR_SCREEN_ID = 9;
constexpr int W_REFRESH_RATE = 12;
constexpr int W_DISPLAY_ROTATION = 9;
constexpr int W_DISPLAY_ORIENTATION = 18;
constexpr int W_DISPLAY_FREEZE_FLAG = 11;
constexpr int W_DISPLAY_OFFSET_X = 5;
constexpr int W_DISPLAY_OFFSET_Y = 5;
constexpr int W_DISPLAY_WIDTH = 5;
constexpr int W_DISPLAY_HEITHT = 5;
}
DisplayDumper::DisplayDumper(const sptr<AbstractDisplayController>& abstractDisplayController,
@ -314,19 +339,19 @@ void DisplayDumper::GetScreenInfo(const sptr<AbstractScreen>& screen, std::ostri
std::string isMirrored = screen->rSDisplayNodeConfig_.isMirrored ? "true" : "false";
NodeId nodeId = (screen->rsDisplayNode_ == nullptr) ? SCREEN_ID_INVALID : screen->rsDisplayNode_->GetId();
// std::setw is used to set the output width and different width values are set to keep the format aligned.
oss << std::left << std::setw(21) << screenName
<< std::left << std::setw(9) << screenType
<< std::left << std::setw(8) << isGroup
<< std::left << std::setw(6) << screen->dmsId_
<< std::left << std::setw(21) << screen->rsId_
<< std::left << std::setw(10) << screen->activeIdx_
<< std::left << std::setw(4) << screen->virtualPixelRatio_
<< std::left << std::setw(9) << static_cast<uint32_t>(screen->rotation_)
<< std::left << std::setw(12) << static_cast<uint32_t>(screen->orientation_)
<< std::left << std::setw(19) << static_cast<uint32_t>(screen->screenRequestedOrientation_)
<< std::left << std::setw(21) << nodeId
<< std::left << std::setw(11) << isMirrored
<< std::left << std::setw(13) << screen->rSDisplayNodeConfig_.mirrorNodeId
oss << std::left << std::setw(W_SCREEN_NAME) << screenName
<< std::left << std::setw(W_SCREEN_TYPE) << screenType
<< std::left << std::setw(W_GROUP_TYPE) << isGroup
<< std::left << std::setw(W_DMS_ID) << screen->dmsId_
<< std::left << std::setw(W_RS_ID) << screen->rsId_
<< std::left << std::setw(W_ACTIVE_IDX) << screen->activeIdx_
<< std::left << std::setw(W_VIR_PIXEL_RATIO) << screen->virtualPixelRatio_
<< std::left << std::setw(W_SCREEN_ROTATION) << static_cast<uint32_t>(screen->rotation_)
<< std::left << std::setw(W_ORIENTATION) << static_cast<uint32_t>(screen->orientation_)
<< std::left << std::setw(W_REQUESTED_ORIENTATION) << static_cast<uint32_t>(screen->screenRequestedOrientation_)
<< std::left << std::setw(W_NODE_ID) << nodeId
<< std::left << std::setw(W_MIRROR_TYPE) << isMirrored
<< std::left << std::setw(W_MIRROR_NODE_ID) << screen->rSDisplayNodeConfig_.mirrorNodeId
<< std::endl;
}
@ -337,19 +362,19 @@ void DisplayDumper::GetDisplayInfo(const sptr<AbstractDisplay>& display, std::os
return;
}
// std::setw is used to set the output width and different width values are set to keep the format aligned.
oss << std::left << std::setw(10) << display->GetId()
<< std::left << std::setw(9) << display->GetAbstractScreenId()
<< std::left << std::setw(12) << display->GetRefreshRate()
<< std::left << std::setw(4) << display->GetVirtualPixelRatio()
<< std::left << std::setw(9) << static_cast<uint32_t>(display->GetRotation())
<< std::left << std::setw(12) << static_cast<uint32_t>(display->GetOrientation())
<< std::left << std::setw(18) << static_cast<uint32_t>(display->GetDisplayOrientation())
<< std::left << std::setw(11) << static_cast<uint32_t>(display->GetFreezeFlag())
oss << std::left << std::setw(W_DISPLAY_ID) << display->GetId()
<< std::left << std::setw(W_ABSTR_SCREEN_ID) << display->GetAbstractScreenId()
<< std::left << std::setw(W_REFRESH_RATE) << display->GetRefreshRate()
<< std::left << std::setw(W_VIR_PIXEL_RATIO) << display->GetVirtualPixelRatio()
<< std::left << std::setw(W_DISPLAY_ROTATION) << static_cast<uint32_t>(display->GetRotation())
<< std::left << std::setw(W_ORIENTATION) << static_cast<uint32_t>(display->GetOrientation())
<< std::left << std::setw(W_DISPLAY_ORIENTATION) << static_cast<uint32_t>(display->GetDisplayOrientation())
<< std::left << std::setw(W_DISPLAY_FREEZE_FLAG) << static_cast<uint32_t>(display->GetFreezeFlag())
<< "[ "
<< std::left << std::setw(5) << display->GetOffsetX()
<< std::left << std::setw(5) << display->GetOffsetY()
<< std::left << std::setw(5) << display->GetWidth()
<< std::left << std::setw(5) << display->GetHeight()
<< std::left << std::setw(W_DISPLAY_OFFSET_X) << display->GetOffsetX()
<< std::left << std::setw(W_DISPLAY_OFFSET_Y) << display->GetOffsetY()
<< std::left << std::setw(W_DISPLAY_WIDTH) << display->GetWidth()
<< std::left << std::setw(W_DISPLAY_HEITHT) << display->GetHeight()
<< "]"
<< std::endl;
}

View File

@ -13,6 +13,9 @@
* limitations under the License.
*/
#ifndef OHOS_JS_WINDOW_MANAGER_H
#define OHOS_JS_WINDOW_MANAGER_H
#include "js_runtime_utils.h"
#include "js_window_register_manager.h"
#include "native_engine/native_engine.h"
@ -20,8 +23,6 @@
#include "native_engine/native_value.h"
#include "wm_common.h"
#ifndef OHOS_JS_WINDOW_MANAGER_H
#define OHOS_JS_WINDOW_MANAGER_H
namespace OHOS {
namespace Rosen {
napi_value JsWindowManagerInit(napi_env env, napi_value exportObj);

View File

@ -33,7 +33,7 @@ VsyncStation::VsyncStation(NodeId nodeId) : nodeId_(nodeId)
void VsyncStation::RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback)
{
{
{
std::lock_guard<std::mutex> lock(mtx_);
if (destroyed_) {
return;

View File

@ -32,11 +32,11 @@ bool ColorParser::Parse(const std::string& colorStr, uint32_t& colorValue)
}
constexpr int HEX = 16;
colorValue = std::strtoul(color.c_str(), 0, HEX); // convert hex string to number
if (colorStr.size() == 7) { // #RRGGBB: RRGGBB -> AARRGGBB
if (colorStr.size() == 7) { // 7 is color string length.#RRGGBB: RRGGBB -> AARRGGBB
colorValue |= 0xff000000;
return true;
}
if (colorStr.size() == 9) { // #AARRGGBB
if (colorStr.size() == 9) { // 9 is color string length.#AARRGGBB
return true;
}
}

View File

@ -118,13 +118,13 @@ void Matrix4::SwapRow(int row1, int row2)
p[1] = q[1];
q[1] = tmp;
tmp = p[2];
p[2] = q[2];
q[2] = tmp;
tmp = p[2]; // 2: row2
p[2] = q[2]; // 2: row2
q[2] = tmp; // 2: row2
tmp = p[3];
p[3] = q[3];
q[3] = tmp;
tmp = p[3]; // 3: row3
p[3] = q[3]; // 3: row3
q[3] = tmp; // 3: row3
}
void Matrix4::Invert()
@ -171,15 +171,15 @@ void Matrix4::Invert()
Vector3 Matrix4::GetScale() const
{
Vector3 retVal;
retVal.x_ = Vector3(mat_[0][0], mat_[0][1], mat_[0][2]).Length();
retVal.y_ = Vector3(mat_[1][0], mat_[1][1], mat_[1][2]).Length();
retVal.z_ = Vector3(mat_[2][0], mat_[2][1], mat_[2][2]).Length();
retVal.x_ = Vector3(mat_[0][0], mat_[0][1], mat_[0][2]).Length(); // 2: column2
retVal.y_ = Vector3(mat_[1][0], mat_[1][1], mat_[1][2]).Length(); // 2: column2
retVal.z_ = Vector3(mat_[2][0], mat_[2][1], mat_[2][2]).Length(); // 2: row2
return retVal;
}
Vector3 Matrix4::GetTranslation() const
{
return Vector3(mat_[3][0], mat_[3][1], mat_[3][2]);
return Vector3(mat_[3][0], mat_[3][1], mat_[3][2]); // 3: row3, 2: column2
}
// Create a scale matrix with x and y scales
@ -303,8 +303,8 @@ Matrix4 CreatePerspective(const Vector3& camera)
Vector2 Transform(const Vector2& vec, const Matrix3& mat)
{
Vector2 retVal;
retVal.x_ = vec.x_ * mat.mat_[0][0] + vec.y_ * mat.mat_[1][0] + mat.mat_[2][0];
retVal.y_ = vec.x_ * mat.mat_[0][1] + vec.y_ * mat.mat_[1][1] + mat.mat_[2][1];
retVal.x_ = vec.x_ * mat.mat_[0][0] + vec.y_ * mat.mat_[1][0] + mat.mat_[2][0]; // 2: row2
retVal.y_ = vec.x_ * mat.mat_[0][1] + vec.y_ * mat.mat_[1][1] + mat.mat_[2][1]; // 2: row2
return retVal;
}

View File

@ -35,7 +35,7 @@ int64_t GetSysClockTime()
WLOGFE("clock_gettime failed:%{public}d", errno);
return 0;
}
return (ts.tv_sec * 1000 * 1000) + (ts.tv_nsec / 1000);
return (ts.tv_sec * 1000 * 1000) + (ts.tv_nsec / 1000); // 1000 is for convert time units.
}
int64_t GetMillisTime()

View File

@ -3283,17 +3283,18 @@ void ScreenSessionManager::DumpAllScreensInfo(std::string& dumpInfo)
std::string screenType = TransferTypeToString(screenInfo->GetType());
NodeId nodeId = (screenSession->GetDisplayNode() == nullptr) ?
SCREEN_ID_INVALID : screenSession->GetDisplayNode()->GetId();
oss << std::left << std::setw(21) << screenInfo->GetName()
<< std::left << std::setw(9) << screenType
<< std::left << std::setw(8) << (screenSession->isScreenGroup_ ? "true" : "false")
<< std::left << std::setw(6) << screenSession->screenId_
<< std::left << std::setw(21) << screenSession->rsId_
<< std::left << std::setw(10) << screenSession->activeIdx_
<< std::left << std::setw(4) << screenInfo->GetVirtualPixelRatio()
<< std::left << std::setw(9) << static_cast<uint32_t>(screenInfo->GetRotation())
<< std::left << std::setw(12) << static_cast<uint32_t>(screenInfo->GetOrientation())
<< std::left << std::setw(19) << static_cast<uint32_t>(screenSession->GetScreenRequestedOrientation())
<< std::left << std::setw(21) << nodeId
oss << std::left << std::setw(21) << screenInfo->GetName() // 21 is width
<< std::left << std::setw(9) << screenType // 9 is width
<< std::left << std::setw(8) << (screenSession->isScreenGroup_ ? "true" : "false") // 8 is width
<< std::left << std::setw(6) << screenSession->screenId_ // 6 is width
<< std::left << std::setw(21) << screenSession->rsId_ // 21 is width
<< std::left << std::setw(10) << screenSession->activeIdx_ // 10 is width
<< std::left << std::setw(4) << screenInfo->GetVirtualPixelRatio() // 4 is width
<< std::left << std::setw(9) << static_cast<uint32_t>(screenInfo->GetRotation()) // 9 is width
<< std::left << std::setw(12) << static_cast<uint32_t>(screenInfo->GetOrientation()) // 12 is width
<< std::left << std::setw(19) // 19 is width
<< static_cast<uint32_t>(screenSession->GetScreenRequestedOrientation())
<< std::left << std::setw(21) << nodeId // 21 is width
<< std::endl;
}
oss << "total screen num: " << screenSessionMap_.size() << std::endl;

View File

@ -72,8 +72,8 @@ std::map<uint32_t, std::vector<sptr<IAvoidAreaChangedListener>>> WindowImpl::avo
std::map<uint32_t, std::vector<sptr<IOccupiedAreaChangeListener>>> WindowImpl::occupiedAreaChangeListeners_;
std::map<uint32_t, sptr<IDialogDeathRecipientListener>> WindowImpl::dialogDeathRecipientListener_;
std::recursive_mutex WindowImpl::globalMutex_;
int constructorCnt = 0;
int deConstructorCnt = 0;
int g_constructorCnt = 0;
int g_deConstructorCnt = 0;
WindowImpl::WindowImpl(const sptr<WindowOption>& option)
{
property_ = new (std::nothrow) WindowProperty();
@ -109,8 +109,8 @@ WindowImpl::WindowImpl(const sptr<WindowOption>& option)
if (moveDragProperty_ == nullptr) {
WLOGFE("MoveDragProperty is null");
}
WLOGFD("constructorCnt: %{public}d name: %{public}s",
++constructorCnt, property_->GetWindowName().c_str());
WLOGFD("g_constructorCnt: %{public}d name: %{public}s",
++g_constructorCnt, property_->GetWindowName().c_str());
}
void WindowImpl::InitWindowProperty(const sptr<WindowOption>& option)
@ -163,8 +163,8 @@ RSSurfaceNode::SharedPtr WindowImpl::CreateSurfaceNode(std::string name, WindowT
WindowImpl::~WindowImpl()
{
WLOGI("windowName: %{public}s, windowId: %{public}d, deConstructorCnt: %{public}d, surfaceNode:%{public}d",
GetWindowName().c_str(), GetWindowId(), ++deConstructorCnt, static_cast<uint32_t>(surfaceNode_.use_count()));
WLOGI("windowName: %{public}s, windowId: %{public}d, g_deConstructorCnt: %{public}d, surfaceNode:%{public}d",
GetWindowName().c_str(), GetWindowId(), ++g_deConstructorCnt, static_cast<uint32_t>(surfaceNode_.use_count()));
Destroy(true, false);
}

View File

@ -42,7 +42,7 @@ void MinimizeApp::AddNeedMinimizeApp(const sptr<WindowNode>& node, MinimizeReaso
for (auto& appNodes: needMinimizeAppNodes_) {
auto windowId = node->GetWindowId();
auto iter = std::find_if(appNodes.second.begin(), appNodes.second.end(),
[windowId](wptr<WindowNode> srcNode) {
[windowId](wptr<WindowNode> srcNode) {
auto weakSrcNode = srcNode.promote();
if (weakSrcNode == nullptr) {
return false;

View File

@ -72,7 +72,8 @@ bool WmsUtils::IsExpectedRotatableWindow(Orientation requestOrientation,
if (disOrientation == currentOrientation) {
return false;
}
if (restricted && (static_cast<int32_t>(disOrientation) - static_cast<int32_t>(currentOrientation)) % 2 == 0) {
if (restricted && (static_cast<int32_t>(disOrientation) -
static_cast<int32_t>(currentOrientation)) % 2 == 0) { // Divided by 2
return false;
}
return true;

View File

@ -1726,7 +1726,7 @@ void WindowRoot::SetSplitRatios(const std::vector<float>& splitRatioNumbers)
void WindowRoot::SetExitSplitRatios(const std::vector<float>& exitSplitRatios)
{
if (exitSplitRatios.size() != 2) {
if (exitSplitRatios.size() != 2) { // 2 is size of vector.
return;
}
if (exitSplitRatios[0] > 0 && exitSplitRatios[0] < DEFAULT_SPLIT_RATIO) {