diff --git a/service/module_loader/src/mmi_service.cpp b/service/module_loader/src/mmi_service.cpp index 2d0e5c0a60d61c33a6f5ff5ff4d1960dc1ed6413..1f17cc36b9618a66e8a6435af527811057bb660f 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) + 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) 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 05a389c4ff557181f6835a928702b4cca486dd64..a80370d5ae9449152fed9f0c7578b31e67d08d65 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/cursor_drawing_component.h b/service/window_manager/include/cursor_drawing_component.h index 55e06fb6fed0d5dbcba02b82ab4917d461bcf087..be5a59fb33df4a56e80cfaa784419eaaaafe995b 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/include/i_pointer_drawing_manager.h b/service/window_manager/include/i_pointer_drawing_manager.h index 17282f2d236b24b246e22abeaa0ea6632c45f445..a484f12dd2af980320db4d89cd30fadd284af617 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 847c139317ddc5899a7d1d23094df17cea36d9af..494f44b65844462ec5652ffa50c9e33041431819 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 27ea372f6635224975af4665f9e658811aa4775f..7ea7d79a66fa1a8026d7fde64a3db4e52ca9e5ba 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/cursor_drawing_component.cpp b/service/window_manager/src/cursor_drawing_component.cpp index 86813c5e40a6be0536032b92173fd5e3d1b04aae..f16ba367bd4d179ebc2b5238b36f9f75420b7d50 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/input_windows_manager.cpp b/service/window_manager/src/input_windows_manager.cpp index e1f2cb3df8181a3a0e3411e58f1b7c74bb7369dd..80c22fb8f1870c3b34bcd86b69474551230db57f 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 34eb31a7fe08904891bf4822f08ee60336342d5b..3ae4861e022ef4896276f866b2ed42f5b112a0dd 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 ba61fd95fa2167fa10ac59661a0a0fb43457609c..6a0519d2baad46ba84c97a8bff834da2ff5adc32 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 fd0ca3f7e7c5770f91c5bdc01b50699bd13c5ec4..bda046a1556088a4ba503199cfae4fdb5991cca9 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/cursor_drawing_component_test.cpp b/service/window_manager/test/cursor_drawing_component_test.cpp index be0c5c0d3e64819f9f2e3b6c2a504ae7c26d3059..c2c5a91de0e6d21fb73d6e762687b347809e7e30 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 diff --git a/service/window_manager/test/pointer_drawing_manager_test.cpp b/service/window_manager/test/pointer_drawing_manager_test.cpp index b1e571033dc3f4048f0e8603a4d84490f9ae91df..f64e605842c892e3daee0412e5f708650958d49a 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()); + OLD::DisplayInfo displaysInfo; + displaysInfo.rsId = 102; + displaysInfo.direction = DIRECTION0; + displaysInfo.displayDirection = DIRECTION0; + displaysInfo.width = 400; + displaysInfo.height = 300; + pointerDrawingManager->displayInfo_.rsId = 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.rsId] = 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 01dffc3e8d5f550d7e140111d7311958c44cd793..3a1fe006f93c10d7f1d22d0527438cd74a9a1ca4 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; + OLD::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; + OLD::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)); } /**