From 6d4a6385ddc6812df98f0c05a6b35fbaf8ec2215 Mon Sep 17 00:00:00 2001 From: likaiyuan Date: Mon, 30 Jun 2025 16:20:29 +0800 Subject: [PATCH 1/4] fix tablet hard curser pointer Change-Id: Iee30f29a57348f85d6a596160b7d80f892f82e2d Signed-off-by: likaiyuan --- service/module_loader/src/mmi_service.cpp | 3 + .../src/mouse_transform_processor.cpp | 2 + .../include/i_pointer_drawing_manager.h | 1 + .../include/pointer_drawing_manager.h | 3 + .../window_manager/include/screen_pointer.h | 25 ++++ .../src/input_windows_manager.cpp | 1 + .../src/pointer_drawing_manager.cpp | 91 +++++++------ .../window_manager/src/pointer_renderer.cpp | 2 +- service/window_manager/src/screen_pointer.cpp | 12 +- .../test/pointer_drawing_manager_test.cpp | 123 ++++++++++++++++++ .../test/screen_pointer_test.cpp | 84 ++++++++++++ 11 files changed, 304 insertions(+), 43 deletions(-) diff --git a/service/module_loader/src/mmi_service.cpp b/service/module_loader/src/mmi_service.cpp index 2d0e5c0a60..0219970842 100644 --- a/service/module_loader/src/mmi_service.cpp +++ b/service/module_loader/src/mmi_service.cpp @@ -2289,6 +2289,9 @@ void MMIService::OnAddSystemAbility(int32_t systemAbilityId, const std::string & #ifdef OHOS_BUILD_ENABLE_ANCO WIN_MGR->InitializeAnco(); #endif // OHOS_BUILD_ENABLE_ANCO +#if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) + IPointerDrawingManager::GetInstance()->RegisterDisplayStatusReceiver(); +#endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING } #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) if (systemAbilityId == RENDER_SERVICE) { diff --git a/service/mouse_event_normalize/src/mouse_transform_processor.cpp b/service/mouse_event_normalize/src/mouse_transform_processor.cpp index 05a389c4ff..a80370d5ae 100644 --- a/service/mouse_event_normalize/src/mouse_transform_processor.cpp +++ b/service/mouse_event_normalize/src/mouse_transform_processor.cpp @@ -414,6 +414,7 @@ bool MouseTransformProcessor::IsWindowRotation(const OLD::DisplayInfo* displayIn { MMI_HILOGD("ROTATE_POLICY: %{public}d, FOLDABLE_DEVICE_POLICY:%{public}s", ROTATE_POLICY, FOLDABLE_DEVICE_POLICY.c_str()); + CHKPF(displayInfo); bool foldableDevicePolicyMain = false; bool foldableDevicePolicyFull = false; @@ -433,6 +434,7 @@ bool MouseTransformProcessor::IsWindowRotation(const OLD::DisplayInfo* displayIn Direction MouseTransformProcessor::GetDisplayDirection(const OLD::DisplayInfo *displayInfo) { Direction displayDirection = DIRECTION0; + CHKPR(displayInfo, DIRECTION0); if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { displayDirection = static_cast(( ((displayInfo->direction - displayInfo->displayDirection) * ANGLE_90 + ANGLE_360) % ANGLE_360) / ANGLE_90); diff --git a/service/window_manager/include/i_pointer_drawing_manager.h b/service/window_manager/include/i_pointer_drawing_manager.h index 17282f2d23..a484f12dd2 100644 --- a/service/window_manager/include/i_pointer_drawing_manager.h +++ b/service/window_manager/include/i_pointer_drawing_manager.h @@ -165,6 +165,7 @@ public: virtual void DestroyPointerWindow() {} virtual void DrawScreenCenterPointer(const PointerStyle &pointerStyle) {} virtual void SubscribeScreenModeChange() {} + virtual void RegisterDisplayStatusReceiver() {} virtual int32_t UpdateMouseLayer(const PointerStyle& pointerStyle, int32_t physicalX, int32_t physicalY) { diff --git a/service/window_manager/include/pointer_drawing_manager.h b/service/window_manager/include/pointer_drawing_manager.h index 847c139317..494f44b658 100644 --- a/service/window_manager/include/pointer_drawing_manager.h +++ b/service/window_manager/include/pointer_drawing_manager.h @@ -118,6 +118,7 @@ public: int32_t EnableHardwareCursorStats(int32_t pid, bool enable) override; int32_t GetHardwareCursorStats(int32_t pid, uint32_t &frameCount, uint32_t &vsyncCount) override; void SubscribeScreenModeChange() override; + void RegisterDisplayStatusReceiver() override; OLD::DisplayInfo GetCurrentDisplayInfo() override; #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR int32_t GetPointerSnapshot(void *pixelMapPtr) override; @@ -228,6 +229,7 @@ private: std::vector> GetMirrorScreenPointers(); std::shared_ptr GetScreenPointer(uint32_t screenId); void CreateRenderConfig(RenderConfig& cfg, std::shared_ptr sp, MOUSE_ICON mouseStyle, bool isHard); + Direction CalculateRenderDirection(const bool isHard, const bool isWindowRotation); void SoftwareCursorRender(MOUSE_ICON mouseStyle); void HardwareCursorRender(MOUSE_ICON mouseStyle); void SoftwareCursorMove(int32_t x, int32_t y, ICON_TYPE align); @@ -327,6 +329,7 @@ private: int32_t focusX_ { 0 }; int32_t focusY_ { 0 }; std::atomic initEventhandlerFlag_ { false }; + std::atomic initDisplayStatusReceiverFlag_ { false }; }; } // namespace MMI } // namespace OHOS diff --git a/service/window_manager/include/screen_pointer.h b/service/window_manager/include/screen_pointer.h index 27ea372f66..7ea7d79a66 100644 --- a/service/window_manager/include/screen_pointer.h +++ b/service/window_manager/include/screen_pointer.h @@ -143,6 +143,31 @@ public: return rotation_; } + void SetDisplayDirection(const Direction displayDirection) + { + switch (displayDirection) { + case DIRECTION0: + case DIRECTION90: + case DIRECTION180: + case DIRECTION270: + displayDirection_ = displayDirection; + break; + default: { + break; + } + } + } + + Direction GetDisplayDirection() + { + return displayDirection_; + } + + void SetIsWindowRotation(bool isWindowRotation) + { + isWindowRotation_ = isWindowRotation; + } + bool IsPositionOutScreen(int32_t x, int32_t y); uint32_t GetBufferId() diff --git a/service/window_manager/src/input_windows_manager.cpp b/service/window_manager/src/input_windows_manager.cpp index e1f2cb3df8..80c22fb8f1 100644 --- a/service/window_manager/src/input_windows_manager.cpp +++ b/service/window_manager/src/input_windows_manager.cpp @@ -6005,6 +6005,7 @@ void InputWindowsManager::CoordinateCorrection(int32_t width, int32_t height, in Direction InputWindowsManager::GetDisplayDirection(const OLD::DisplayInfo *displayInfo) { + CHKPR(displayInfo, DIRECTION0); Direction displayDirection = static_cast(( ((displayInfo->direction - displayInfo->displayDirection) * ANGLE_90 + ANGLE_360) % ANGLE_360) / ANGLE_90); if (GetHardCursorEnabled()) { diff --git a/service/window_manager/src/pointer_drawing_manager.cpp b/service/window_manager/src/pointer_drawing_manager.cpp index 34eb31a7fe..3ae4861e02 100644 --- a/service/window_manager/src/pointer_drawing_manager.cpp +++ b/service/window_manager/src/pointer_drawing_manager.cpp @@ -15,7 +15,6 @@ #include "pointer_drawing_manager.h" -#include #include #include #include @@ -53,8 +52,6 @@ #include "common_event_manager.h" #include "common_event_support.h" -#include "param/sys_param.h" - #undef MMI_LOG_DOMAIN #define MMI_LOG_DOMAIN MMI_LOG_CURSOR #undef MMI_LOG_TAG @@ -77,7 +74,6 @@ const char* POINTER_SIZE { "pointerSize" }; const char* MAGIC_POINTER_COLOR { "magicPointerColor" }; const char* MAGIC_POINTER_SIZE { "magicPointerSize"}; const char* POINTER_CURSOR_RENDER_RECEIVER_NAME { "PointerCursorReceiver" }; -const std::vector DEVICE_TYPES = {}; const int32_t ROTATE_POLICY = system::GetIntParameter("const.window.device.rotate_policy", 0); const std::string FOLDABLE_DEVICE_POLICY = system::GetParameter("const.window.foldabledevice.rotate_policy", ""); constexpr int32_t WINDOW_ROTATE { 0 }; @@ -149,15 +145,15 @@ const int32_t MULTIMODAL_INPUT_SERVICE_ID = 3101; namespace OHOS { namespace MMI { -class DisplyStatusReceiver : public EventFwk::CommonEventSubscriber { +class DisplayStatusReceiver : public EventFwk::CommonEventSubscriber { public: - explicit DisplyStatusReceiver(const OHOS::EventFwk::CommonEventSubscribeInfo& subscribeInfo) + explicit DisplayStatusReceiver(const OHOS::EventFwk::CommonEventSubscribeInfo& subscribeInfo) : OHOS::EventFwk::CommonEventSubscriber(subscribeInfo) { - MMI_HILOGI("DisplyStatusReceiver register"); + MMI_HILOGI("DisplayStatusReceiver register"); } - virtual ~DisplyStatusReceiver() = default; + virtual ~DisplayStatusReceiver() = default; void OnReceiveEvent(const EventFwk::CommonEventData &eventData) { @@ -230,13 +226,10 @@ void PointerDrawingManager::InitPointerCallback() } #endif // OHOS_BUILD_ENABLE_MAGICCURSOR if (GetHardCursorEnabled() && !initEventhandlerFlag_.load()) { - std::string productType = OHOS::system::GetParameter("const.build.product", "HYM"); - if (std::find(DEVICE_TYPES.begin(), DEVICE_TYPES.end(), productType) != DEVICE_TYPES.end()) { - renderThread_ = std::make_unique([this] { this->RenderThreadLoop(); }); - softCursorRenderThread_ = - std::make_unique([this] { this->SoftCursorRenderThreadLoop(); }); - moveRetryThread_ = std::make_unique([this] { this->MoveRetryThreadLoop(); }); - } + renderThread_ = std::make_unique([this] { this->RenderThreadLoop(); }); + softCursorRenderThread_ = + std::make_unique([this] { this->SoftCursorRenderThreadLoop(); }); + moveRetryThread_ = std::make_unique([this] { this->MoveRetryThreadLoop(); }); initEventhandlerFlag_.store(true); } } @@ -1492,6 +1485,7 @@ bool PointerDrawingManager::IsWindowRotation(const OLD::DisplayInfo *displayInfo { MMI_HILOGD("ROTATE_POLICY: %{public}d, FOLDABLE_DEVICE_POLICY:%{public}s", ROTATE_POLICY, FOLDABLE_DEVICE_POLICY.c_str()); + CHKPF(displayInfo); bool foldableDevicePolicyMain = false; bool foldableDevicePolicyFull = false; @@ -1510,6 +1504,7 @@ bool PointerDrawingManager::IsWindowRotation(const OLD::DisplayInfo *displayInfo Direction PointerDrawingManager::GetDisplayDirection(const OLD::DisplayInfo *displayInfo) { + CHKPR(displayInfo, DIRECTION0); Direction direction = static_cast(( ((displayInfo->direction - displayInfo->displayDirection) * ANGLE_90 + ANGLE_360) % ANGLE_360) / ANGLE_90); if (GetHardCursorEnabled()) { @@ -3009,13 +3004,24 @@ void PointerDrawingManager::SubscribeScreenModeChange() return; } MMI_HILOGI("SubscribeScreenModeChange success"); - +} + +void PointerDrawingManager::RegisterDisplayStatusReceiver() +{ + if (!GetHardCursorEnabled()) { + return; + } + if (initDisplayStatusReceiverFlag_) { + MMI_HILOGE("Display status receiver has subscribed"); + return; + } EventFwk::MatchingSkills matchingSkills; matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON); matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF); EventFwk::CommonEventSubscribeInfo commonEventSubscribeInfo(matchingSkills); - OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent( - std::make_shared(commonEventSubscribeInfo)); + initDisplayStatusReceiverFlag_ = OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent( + std::make_shared(commonEventSubscribeInfo)); + MMI_HILOGI("Register display status receiver result:%{public}d", initDisplayStatusReceiverFlag_.load()); } void PointerDrawingManager::InitStyle() @@ -3282,6 +3288,18 @@ void PointerDrawingManager::OnScreenModeChange(const std::vector((((displayInfo_.direction - displayInfo_.displayDirection) * + ANGLE_90 + ANGLE_360) % ANGLE_360) / ANGLE_90); + } + return direction; +} + void PointerDrawingManager::CreateRenderConfig(RenderConfig& cfg, std::shared_ptr sp, MOUSE_ICON mouseStyle, bool isHard) { @@ -3294,7 +3312,8 @@ void PointerDrawingManager::CreateRenderConfig(RenderConfig& cfg, std::shared_pt cfg.isHard = isHard; float scale = isHard ? sp->GetScale() : 1.0f; cfg.dpi = sp->GetDPI() * scale; - cfg.direction = sp->IsMirror() ? DIRECTION0 : displayInfo_.direction; + Direction direction = CalculateRenderDirection(isHard, IsWindowRotation(&displayInfo_)); + cfg.direction = sp->IsMirror() ? DIRECTION0 : direction; if (mouseStyle == MOUSE_ICON::DEVELOPER_DEFINED_ICON) { MMI_HILOGD("Set mouseIcon by userIcon_"); cfg.userIconPixelMap = GetUserIconCopy(); @@ -3424,6 +3443,7 @@ int32_t PointerDrawingManager::DrawHardCursor(std::shared_ptr sp, void PointerDrawingManager::UpdateMirrorScreens(std::shared_ptr sp, OLD::DisplayInfo displayInfo) { + CHKPV(sp); uint32_t mainWidth = sp->GetScreenWidth(); uint32_t mainHeight = sp->GetScreenHeight(); std::lock_guard lock(mtx_); @@ -3433,10 +3453,21 @@ void PointerDrawingManager::UpdateMirrorScreens(std::shared_ptr s } if (it.second->IsMirror()) { auto& mirrorScreen = it.second; + mirrorScreen->SetIsWindowRotation(IsWindowRotation(&displayInfo)); + bool isDirectionChanged = false; if (mirrorScreen->GetRotation() != static_cast(displayInfo.direction)) { - MMI_HILOGI("update rotation of mirror screen from %{public}u to %{public}d", + MMI_HILOGI("update mirror screen, rotation from %{public}u to %{public}d,", mirrorScreen->GetRotation(), displayInfo.direction); mirrorScreen->SetRotation(static_cast(displayInfo.direction)); + isDirectionChanged = true; + } + if (mirrorScreen->GetDisplayDirection() != displayInfo.displayDirection) { + MMI_HILOGI("update mirror screen, displayDirection from %{public}d to %{public}d", + mirrorScreen->GetDisplayDirection(), displayInfo.displayDirection); + mirrorScreen->SetDisplayDirection(displayInfo.displayDirection); + isDirectionChanged = true; + } + if (isDirectionChanged) { mirrorScreen->UpdatePadding(mainWidth, mainHeight); } MMI_HILOGD("update mirror screen dpi, mainScreen dpi: %{public}f, original mirrorScreen dpi: %{public}f", @@ -3775,20 +3806,6 @@ void PointerDrawingManager::AdjustMouseFocusToSoftRenderOrigin(Direction directi } } -int ConvertToInt(const char *originValue, int defaultValue) -{ - if (originValue == nullptr) { - return defaultValue; - } - int value; - auto result = std::from_chars(originValue, originValue + std::strlen(originValue), value); - if (result.ec == std::errc()) { - return value; - } else { - return defaultValue; - } -} - bool PointerDrawingManager::GetHardCursorEnabled() { bool isHardCursorEnabled = true; @@ -3799,12 +3816,6 @@ bool PointerDrawingManager::GetHardCursorEnabled() if (!hardwareCursorPointerManager_->IsSupported()) { isHardCursorEnabled = false; } - static CachedHandle g_handle = CachedParameterCreate("rosen.hardCursor.enabled", "1"); - int changed = 0; - const char *enable = CachedParameterGetChanged(g_handle, &changed); - if (ConvertToInt(enable, 1) == 0) { - isHardCursorEnabled = false; - } return isHardCursorEnabled; } } // namespace MMI diff --git a/service/window_manager/src/pointer_renderer.cpp b/service/window_manager/src/pointer_renderer.cpp index ba61fd95fa..6a0519d2ba 100644 --- a/service/window_manager/src/pointer_renderer.cpp +++ b/service/window_manager/src/pointer_renderer.cpp @@ -143,7 +143,7 @@ int32_t PointerRenderer::Render(uint8_t *addr, uint32_t width, uint32_t height, canvas.Bind(bitmap); canvas.Clear(OHOS::Rosen::Drawing::Color::COLOR_TRANSPARENT); if (cfg.direction) { - int32_t directionFlag = cfg.isHard ? -1 : 0; + int32_t directionFlag = -1; int32_t degree = static_cast(directionFlag * static_cast(cfg.direction) * ROTATION_ANGLE90); canvas.Rotate(degree, FOCUS_POINT, FOCUS_POINT); } diff --git a/service/window_manager/src/screen_pointer.cpp b/service/window_manager/src/screen_pointer.cpp index fd0ca3f7e7..035b346731 100644 --- a/service/window_manager/src/screen_pointer.cpp +++ b/service/window_manager/src/screen_pointer.cpp @@ -380,7 +380,8 @@ void ScreenPointer::Rotate(rotation_t rotation, int32_t& x, int32_t& y) if (IsMirror() && (rotation_ == rotation_t::ROTATION_90 || rotation_ == rotation_t::ROTATION_270)) { std::swap(width, height); } - if (IsMain() && isWindowRotation_ && (displayDirection_ == DIRECTION90 || displayDirection_ == DIRECTION270)) { + if ((IsMain() || IsMirror()) && isWindowRotation_ && + (displayDirection_ == DIRECTION90 || displayDirection_ == DIRECTION270)) { std::swap(width, height); } @@ -400,7 +401,14 @@ void ScreenPointer::CalculateHwcPositionForMirror(int32_t& x, int32_t& y) { x = x * scale_; y = y * scale_; - Rotate(rotation_, x, y); + Direction direction = DIRECTION0; + if (isWindowRotation_) { + direction = static_cast((((static_cast(rotation_) - displayDirection_) * + ANGLE_90 + ANGLE_360) % ANGLE_360) / ANGLE_90); + } else { + direction = static_cast(rotation_); + } + Rotate(rotation_t(direction), x, y); x += paddingLeft_; y += paddingTop_; diff --git a/service/window_manager/test/pointer_drawing_manager_test.cpp b/service/window_manager/test/pointer_drawing_manager_test.cpp index b1e571033d..92665ac095 100644 --- a/service/window_manager/test/pointer_drawing_manager_test.cpp +++ b/service/window_manager/test/pointer_drawing_manager_test.cpp @@ -2741,5 +2741,128 @@ HWTEST_F(PointerDrawingManagerTest, PointerDrawingManagerTest_ConvertToColorSpac colorSpace = Media::ColorSpace::ACES; ASSERT_NO_FATAL_FAILURE(pointerDrawingManager.ConvertToColorSpace(colorSpace)); } + +/** + * @tc.name: PointerDrawingManagerTest_RegisterDisplayStatusReceiver_001 + * @tc.desc: Test RegisterDisplayStatusReceiver + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(PointerDrawingManagerTest, RegisterDisplayStatusReceiver_001, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto *pointerDrawingManager = static_cast(IPointerDrawingManager::GetInstance()); + pointerDrawingManager->initDisplayStatusReceiverFlag_ = true; + EXPECT_NO_FATAL_FAILURE(pointerDrawingManager->RegisterDisplayStatusReceiver()); +} + +/** + * @tc.name: PointerDrawingManagerTest_RegisterDisplayStatusReceiver_002 + * @tc.desc: Test RegisterDisplayStatusReceiver + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(PointerDrawingManagerTest, RegisterDisplayStatusReceiver_002, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto *pointerDrawingManager = static_cast(IPointerDrawingManager::GetInstance()); + pointerDrawingManager->initDisplayStatusReceiverFlag_ = false; + EXPECT_NO_FATAL_FAILURE(pointerDrawingManager->RegisterDisplayStatusReceiver()); +} + +/** + * @tc.name: PointerDrawingManagerTest_CalculateRenderDirection_001 + * @tc.desc: Test CalculateRenderDirection + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(PointerDrawingManagerTest, CalculateRenderDirection_001, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto *pointerDrawingManager = static_cast(IPointerDrawingManager::GetInstance()); + pointerDrawingManager->displayInfo_.displayDirection = DIRECTION270; + pointerDrawingManager->displayInfo_.direction = DIRECTION90; + bool isHard = true; + bool isWindowRotate = true; + Direction ret = pointerDrawingManager->CalculateRenderDirection(isHard, isWindowRotate); + ASSERT_EQ(ret, DIRECTION90); + isHard = true; + isWindowRotate = false; + ret = pointerDrawingManager->CalculateRenderDirection(isHard, isWindowRotate); + ASSERT_EQ(ret, DIRECTION90); + isHard = false; + isWindowRotate = true; + ret = pointerDrawingManager->CalculateRenderDirection(isHard, isWindowRotate); + ASSERT_EQ(ret, DIRECTION180); + isHard = false; + isWindowRotate = false; + ret = pointerDrawingManager->CalculateRenderDirection(isHard, isWindowRotate); + ASSERT_EQ(ret, DIRECTION0); +} + +/** + * @tc.name: PointerDrawingManagerTest_CalculateRenderDirection_002 + * @tc.desc: Test CalculateRenderDirection + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(PointerDrawingManagerTest, CalculateRenderDirection_002, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto *pointerDrawingManager = static_cast(IPointerDrawingManager::GetInstance()); + pointerDrawingManager->displayInfo_.displayDirection = DIRECTION270; + pointerDrawingManager->displayInfo_.direction = DIRECTION90; + bool isHard = true; + bool isWindowRotate = true; + Direction ret = pointerDrawingManager->CalculateRenderDirection(isHard, isWindowRotate); + ASSERT_EQ(ret, DIRECTION90); + isHard = true; + isWindowRotate = false; + ret = pointerDrawingManager->CalculateRenderDirection(isHard, isWindowRotate); + ASSERT_EQ(ret, DIRECTION90); + isHard = false; + isWindowRotate = true; + ret = pointerDrawingManager->CalculateRenderDirection(isHard, isWindowRotate); + ASSERT_EQ(ret, DIRECTION180); + isHard = false; + isWindowRotate = false; + ret = pointerDrawingManager->CalculateRenderDirection(isHard, isWindowRotate); + ASSERT_EQ(ret, DIRECTION0); +} + +/** + * @tc.name: PointerDrawingManagerTest_UpdateMirrorScreens_001 + * @tc.desc: Test UpdateMirrorScreens + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(PointerDrawingManagerTest, UpdateMirrorScreens_001, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto *pointerDrawingManager = static_cast(IPointerDrawingManager::GetInstance()); + DisplayInfo displaysInfo; + displaysInfo.uniqueId = 102; + displaysInfo.direction = DIRECTION0; + displaysInfo.displayDirection = DIRECTION0; + displaysInfo.width = 400; + displaysInfo.height = 300; + pointerDrawingManager->displayInfo_.uniqueId = 100; + pointerDrawingManager->displayInfo_.direction = DIRECTION0; + pointerDrawingManager->displayInfo_.displayDirection = DIRECTION0; + pointerDrawingManager->displayInfo_.width = 600; + pointerDrawingManager->displayInfo_.height = 400; + auto spMirror = std::make_shared(pointerDrawingManager->hardwareCursorPointerManager_, + pointerDrawingManager->handler_, displaysInfo); + auto spMain = std::make_shared(pointerDrawingManager->hardwareCursorPointerManager_, + pointerDrawingManager->handler_, pointerDrawingManager->displayInfo_); + spMirror->mode_ = mode_t::SCREEN_MIRROR; + spMirror->displayDirection_ = DIRECTION0; + pointerDrawingManager->screenPointers_[displaysInfo.uniqueId] = spMirror; + pointerDrawingManager->screenPointers_[101] = nullptr; + EXPECT_NO_FATAL_FAILURE(pointerDrawingManager->UpdateMirrorScreens(spMain, pointerDrawingManager->displayInfo_)); + pointerDrawingManager->displayInfo_.direction = DIRECTION90; + pointerDrawingManager->displayInfo_.displayDirection = DIRECTION270; + EXPECT_NO_FATAL_FAILURE(pointerDrawingManager->UpdateMirrorScreens(spMain, pointerDrawingManager->displayInfo_)); +} } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/service/window_manager/test/screen_pointer_test.cpp b/service/window_manager/test/screen_pointer_test.cpp index 01dffc3e8d..7ed122ba86 100644 --- a/service/window_manager/test/screen_pointer_test.cpp +++ b/service/window_manager/test/screen_pointer_test.cpp @@ -193,6 +193,41 @@ HWTEST_F(ScreenPointerTest, ScreenPointerTest_Move_001, TestSize.Level1) EXPECT_EQ(ret, hwcmgr->IsSupported()); } +/** + * @tc.name: ScreenPointerTest_Move_002 + * @tc.desc: Test Move + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(ScreenPointerTest, ScreenPointerTest_Move_002, TestSize.Level1) +{ + CALL_TEST_DEBUG; + hwcmgr_ptr_t hwcmgr = std::make_shared(); + ASSERT_NE(hwcmgr, nullptr); + handler_ptr_t handler = nullptr; + DisplayInfo di; + ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); + ASSERT_NE(screenpointer, nullptr); + PointerRenderer renderer; + ASSERT_TRUE(screenpointer->Init(renderer)); + Rosen::RSSurfaceNodeConfig surfaceNodeConfig; + surfaceNodeConfig.SurfaceNodeName = "pointer window"; + screenpointer->surfaceNode_ = Rosen::RSSurfaceNode::Create(surfaceNodeConfig, + Rosen::RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE); + ASSERT_NE(screenpointer->surfaceNode_, nullptr); + screenpointer->mode_ = mode_t::SCREEN_MIRROR; + screenpointer->isWindowRotation_ = true; + ICON_TYPE align = ANGLE_W; + int32_t x = 0; + int32_t y = 0; + bool ret = screenpointer->Move(x, y, align); + EXPECT_FALSE(ret); + screenpointer->mode_ = mode_t::SCREEN_MAIN; + screenpointer->isWindowRotation_ = true; + ret = screenpointer->Move(x, y, align); + EXPECT_FALSE(ret); +} + /** * @tc.name: ScreenPointerTest_Rotate_001 * @tc.desc: Test Rotate @@ -289,6 +324,55 @@ HWTEST_F(ScreenPointerTest, ScreenPointerTest_Rotate_003, TestSize.Level1) EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); rotation = rotation_t(DIRECTION0); EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); + screenpointer->displayDirection_ = DIRECTION270; + rotation = rotation_t(DIRECTION90); + EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); + rotation = rotation_t(DIRECTION180); + EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); + rotation = rotation_t(DIRECTION270); + EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); + rotation = rotation_t(DIRECTION0); + EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); +} + +/** + * @tc.name: ScreenPointerTest_Rotate_004 + * @tc.desc: Test Rotate + * @tc.type: Function + * @tc.require: + */ +HWTEST_F(ScreenPointerTest, ScreenPointerTest_Rotate_004, TestSize.Level1) +{ + CALL_TEST_DEBUG; + hwcmgr_ptr_t hwcmgr = std::make_shared(); + ASSERT_NE(hwcmgr, nullptr); + handler_ptr_t handler = nullptr; + DisplayInfo di; + ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); + ASSERT_NE(screenpointer, nullptr); + int32_t x = 0; + int32_t y = 0; + screenpointer->mode_ = mode_t::SCREEN_MIRROR; + screenpointer->rotation_ = rotation_t::ROTATION_0; + screenpointer->isWindowRotation_ = true; + screenpointer->displayDirection_ = DIRECTION90; + rotation_t rotation = rotation_t(DIRECTION90); + EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); + rotation = rotation_t(DIRECTION180); + EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); + rotation = rotation_t(DIRECTION270); + EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); + rotation = rotation_t(DIRECTION0); + EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); + screenpointer->displayDirection_ = DIRECTION270; + rotation = rotation_t(DIRECTION90); + EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); + rotation = rotation_t(DIRECTION180); + EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); + rotation = rotation_t(DIRECTION270); + EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); + rotation = rotation_t(DIRECTION0); + EXPECT_NO_FATAL_FAILURE(screenpointer->Rotate(rotation, x, y)); } /** -- Gitee From 1d11d79de1ae49164439aac71bec7e953ea4593e Mon Sep 17 00:00:00 2001 From: likaiyuan Date: Mon, 30 Jun 2025 16:20:29 +0800 Subject: [PATCH 2/4] fix tablet hard curser pointer Change-Id: Iee30f29a57348f85d6a596160b7d80f892f82e2d Signed-off-by: likaiyuan --- service/module_loader/src/mmi_service.cpp | 2 +- .../window_manager/include/cursor_drawing_component.h | 1 + .../window_manager/src/cursor_drawing_component.cpp | 6 ++++++ service/window_manager/src/screen_pointer.cpp | 2 +- .../test/cursor_drawing_component_test.cpp | 11 +++++++++++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/service/module_loader/src/mmi_service.cpp b/service/module_loader/src/mmi_service.cpp index 0219970842..1f17cc36b9 100644 --- a/service/module_loader/src/mmi_service.cpp +++ b/service/module_loader/src/mmi_service.cpp @@ -2290,7 +2290,7 @@ void MMIService::OnAddSystemAbility(int32_t systemAbilityId, const std::string & WIN_MGR->InitializeAnco(); #endif // OHOS_BUILD_ENABLE_ANCO #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) - IPointerDrawingManager::GetInstance()->RegisterDisplayStatusReceiver(); + CursorDrawingComponent::GetInstance().RegisterDisplayStatusReceiver(); #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING } #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) diff --git a/service/window_manager/include/cursor_drawing_component.h b/service/window_manager/include/cursor_drawing_component.h index 55e06fb6fe..be5a59fb33 100644 --- a/service/window_manager/include/cursor_drawing_component.h +++ b/service/window_manager/include/cursor_drawing_component.h @@ -80,6 +80,7 @@ public: void DestroyPointerWindow(); void DrawScreenCenterPointer(const PointerStyle &pointerStyle); void SubscribeScreenModeChange(); + void RegisterDisplayStatusReceiver(); int32_t UpdateMouseLayer( const PointerStyle &pointerStyle, int32_t displayId, int32_t physicalX, int32_t physicalY); int32_t DrawNewDpiPointer(); diff --git a/service/window_manager/src/cursor_drawing_component.cpp b/service/window_manager/src/cursor_drawing_component.cpp index 86813c5e40..f16ba367bd 100644 --- a/service/window_manager/src/cursor_drawing_component.cpp +++ b/service/window_manager/src/cursor_drawing_component.cpp @@ -414,6 +414,12 @@ void CursorDrawingComponent::SubscribeScreenModeChange() pointerInstance_->SubscribeScreenModeChange(); } +void CursorDrawingComponent::RegisterDisplayStatusReceiver() +{ + CHK_IS_LOADV(isLoaded_, pointerInstance_) + pointerInstance_->RegisterDisplayStatusReceiver(); +} + int32_t CursorDrawingComponent::UpdateMouseLayer( const PointerStyle &pointerStyle, int32_t displayId, int32_t physicalX, int32_t physicalY) { diff --git a/service/window_manager/src/screen_pointer.cpp b/service/window_manager/src/screen_pointer.cpp index 035b346731..bda046a155 100644 --- a/service/window_manager/src/screen_pointer.cpp +++ b/service/window_manager/src/screen_pointer.cpp @@ -403,7 +403,7 @@ void ScreenPointer::CalculateHwcPositionForMirror(int32_t& x, int32_t& y) y = y * scale_; Direction direction = DIRECTION0; if (isWindowRotation_) { - direction = static_cast((((static_cast(rotation_) - displayDirection_) * + direction = static_cast((((static_cast(rotation_) - displayDirection_) * ANGLE_90 + ANGLE_360) % ANGLE_360) / ANGLE_90); } else { direction = static_cast(rotation_); diff --git a/service/window_manager/test/cursor_drawing_component_test.cpp b/service/window_manager/test/cursor_drawing_component_test.cpp index be0c5c0d3e..c2c5a91de0 100644 --- a/service/window_manager/test/cursor_drawing_component_test.cpp +++ b/service/window_manager/test/cursor_drawing_component_test.cpp @@ -566,6 +566,17 @@ HWTEST_F(CursorDrawingComponentTest, CursorDrawingComponentTest_SubscribeScreenM EXPECT_NO_FATAL_FAILURE(instance_->SubscribeScreenModeChange()); } +/** + * @tc.name: CursorDrawingComponentTest_RegisterDisplayStatusReceiver_001 + * @tc.desc: Test RegisterDisplayStatusReceiver + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(CursorDrawingComponentTest, CursorDrawingComponentTest_RegisterDisplayStatusReceiver_001, TestSize.Level1) +{ + EXPECT_NO_FATAL_FAILURE(instance_->RegisterDisplayStatusReceiver()); +} + /** * @tc.name: CursorDrawingComponentTest_UpdateMouseLayer_001 * @tc.desc: Test UpdateMouseLayer -- Gitee From c56e3f6efbb7eb9e3d83ebce19dca6349ada7b9f Mon Sep 17 00:00:00 2001 From: likaiyuan Date: Mon, 30 Jun 2025 16:20:29 +0800 Subject: [PATCH 3/4] fix tablet hard curser pointer Change-Id: Iee30f29a57348f85d6a596160b7d80f892f82e2d Signed-off-by: likaiyuan --- service/window_manager/test/pointer_drawing_manager_test.cpp | 2 +- service/window_manager/test/screen_pointer_test.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/service/window_manager/test/pointer_drawing_manager_test.cpp b/service/window_manager/test/pointer_drawing_manager_test.cpp index 92665ac095..8e3c5ac17f 100644 --- a/service/window_manager/test/pointer_drawing_manager_test.cpp +++ b/service/window_manager/test/pointer_drawing_manager_test.cpp @@ -2840,7 +2840,7 @@ HWTEST_F(PointerDrawingManagerTest, UpdateMirrorScreens_001, TestSize.Level1) { CALL_TEST_DEBUG; auto *pointerDrawingManager = static_cast(IPointerDrawingManager::GetInstance()); - DisplayInfo displaysInfo; + OLD::DisplayInfo displaysInfo; displaysInfo.uniqueId = 102; displaysInfo.direction = DIRECTION0; displaysInfo.displayDirection = DIRECTION0; diff --git a/service/window_manager/test/screen_pointer_test.cpp b/service/window_manager/test/screen_pointer_test.cpp index 7ed122ba86..3a1fe006f9 100644 --- a/service/window_manager/test/screen_pointer_test.cpp +++ b/service/window_manager/test/screen_pointer_test.cpp @@ -205,7 +205,7 @@ HWTEST_F(ScreenPointerTest, ScreenPointerTest_Move_002, TestSize.Level1) hwcmgr_ptr_t hwcmgr = std::make_shared(); ASSERT_NE(hwcmgr, nullptr); handler_ptr_t handler = nullptr; - DisplayInfo di; + OLD::DisplayInfo di; ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); ASSERT_NE(screenpointer, nullptr); PointerRenderer renderer; @@ -347,7 +347,7 @@ HWTEST_F(ScreenPointerTest, ScreenPointerTest_Rotate_004, TestSize.Level1) hwcmgr_ptr_t hwcmgr = std::make_shared(); ASSERT_NE(hwcmgr, nullptr); handler_ptr_t handler = nullptr; - DisplayInfo di; + OLD::DisplayInfo di; ScreenPointer* screenpointer = new ScreenPointer(hwcmgr, handler, di); ASSERT_NE(screenpointer, nullptr); int32_t x = 0; -- Gitee From 03e349a74c6a2748b34414e4cd2ac412da43ca06 Mon Sep 17 00:00:00 2001 From: likaiyuan Date: Mon, 30 Jun 2025 16:20:29 +0800 Subject: [PATCH 4/4] fix tablet hard curser pointer Change-Id: Iee30f29a57348f85d6a596160b7d80f892f82e2d Signed-off-by: likaiyuan --- .../window_manager/test/pointer_drawing_manager_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/service/window_manager/test/pointer_drawing_manager_test.cpp b/service/window_manager/test/pointer_drawing_manager_test.cpp index 8e3c5ac17f..f64e605842 100644 --- a/service/window_manager/test/pointer_drawing_manager_test.cpp +++ b/service/window_manager/test/pointer_drawing_manager_test.cpp @@ -2841,12 +2841,12 @@ HWTEST_F(PointerDrawingManagerTest, UpdateMirrorScreens_001, TestSize.Level1) CALL_TEST_DEBUG; auto *pointerDrawingManager = static_cast(IPointerDrawingManager::GetInstance()); OLD::DisplayInfo displaysInfo; - displaysInfo.uniqueId = 102; + displaysInfo.rsId = 102; displaysInfo.direction = DIRECTION0; displaysInfo.displayDirection = DIRECTION0; displaysInfo.width = 400; displaysInfo.height = 300; - pointerDrawingManager->displayInfo_.uniqueId = 100; + pointerDrawingManager->displayInfo_.rsId = 100; pointerDrawingManager->displayInfo_.direction = DIRECTION0; pointerDrawingManager->displayInfo_.displayDirection = DIRECTION0; pointerDrawingManager->displayInfo_.width = 600; @@ -2857,7 +2857,7 @@ HWTEST_F(PointerDrawingManagerTest, UpdateMirrorScreens_001, TestSize.Level1) pointerDrawingManager->handler_, pointerDrawingManager->displayInfo_); spMirror->mode_ = mode_t::SCREEN_MIRROR; spMirror->displayDirection_ = DIRECTION0; - pointerDrawingManager->screenPointers_[displaysInfo.uniqueId] = spMirror; + pointerDrawingManager->screenPointers_[displaysInfo.rsId] = spMirror; pointerDrawingManager->screenPointers_[101] = nullptr; EXPECT_NO_FATAL_FAILURE(pointerDrawingManager->UpdateMirrorScreens(spMain, pointerDrawingManager->displayInfo_)); pointerDrawingManager->displayInfo_.direction = DIRECTION90; -- Gitee