已合并
fix snapshot with option #17611
xuweinan创建于 1月16日
fix snapshot with option #17611
已合并
共 4 个文件变更+122-7
| @@ -2811,10 +2811,16 @@ std::shared_ptr<Media::PixelMap> DisplayManager::GetScreenshotWithOption(const C | |||
| 2811 | TLOGE(WmsLogTag::DMS, "size invalid! w %{public}d, h %{public}d", size.width, size.height); | 2811 | TLOGE(WmsLogTag::DMS, "size invalid! w %{public}d, h %{public}d", size.width, size.height); |
| 2812 | return nullptr; | 2812 | return nullptr; |
| 2813 | } | 2813 | } |
| 2814 | + std::shared_ptr<Media::PixelMap> screenShot = nullptr; | ||
| 2814 | if (CheckUseGpuScreenshotWithOption(rect, size)) { | 2815 | if (CheckUseGpuScreenshotWithOption(rect, size)) { |
| 2815 | - return GetScreenshotWithOptionUseGpu(captureOption, rect, size, rotation, errorCode); | 2816 | + screenShot = GetScreenshotWithOptionUseGpu(captureOption, rect, size, rotation, errorCode); |
| 2817 | + if (screenShot != nullptr) { | ||
| 2818 | + TLOGI(WmsLogTag::DMS, "set snapshot with option by gpu success!"); | ||
| 2819 | + return screenShot; | ||
| 2820 | + } | ||
| 2821 | + TLOGI(WmsLogTag::DMS, "set snapshot with option by gpu failed, try to use cpu!"); | ||
| 2816 | } | 2822 | } |
| 2817 | - std::shared_ptr<Media::PixelMap> screenShot = GetScreenshotWithOption(captureOption, errorCode); | 2823 | + screenShot = GetScreenshotWithOption(captureOption, errorCode); |
| 2818 | if (screenShot == nullptr) { | 2824 | if (screenShot == nullptr) { |
| 2819 | TLOGE(WmsLogTag::DMS, "set snapshot with option failed!"); | 2825 | TLOGE(WmsLogTag::DMS, "set snapshot with option failed!"); |
| 2820 | return nullptr; | 2826 | return nullptr; |
| @@ -819,6 +819,7 @@ private: | |||
| 819 | float virtualPixelRatio); | 819 | float virtualPixelRatio); |
| 820 | void SwitchUserResetDisplayNodeScreenId(); | 820 | void SwitchUserResetDisplayNodeScreenId(); |
| 821 | void AodLibInit(); | 821 | void AodLibInit(); |
| 822 | + DMRect CalcRectsWithRotation(DisplayId displayId, const DMRect &rect); | ||
| 822 | std::shared_mutex rotationCorrectionExemptionMutex_; | 823 | std::shared_mutex rotationCorrectionExemptionMutex_; |
| 823 | std::vector<std::string> rotationCorrectionExemptionList_; | 824 | std::vector<std::string> rotationCorrectionExemptionList_; |
| 824 | bool needReinstallExemptionList_ = true; | 825 | bool needReinstallExemptionList_ = true; |
| @@ -174,6 +174,7 @@ ScreenCache<int32_t, std::string> g_uidVersionMap(MAP_SIZE, NO_EXIST_BUNDLE_MANE | |||
| 174 | 174 | ||
| 175 | const int32_t SCREEN_SCAN_TYPE = system::GetIntParameter<int32_t>("const.window.screen.scan_type", 0); | 175 | const int32_t SCREEN_SCAN_TYPE = system::GetIntParameter<int32_t>("const.window.screen.scan_type", 0); |
| 176 | constexpr int32_t SCAN_TYPE_VERTICAL = 1; | 176 | constexpr int32_t SCAN_TYPE_VERTICAL = 1; |
| 177 | +constexpr int32_t ROTATION_270_INT = 270; | ||
| 177 | constexpr uint32_t ROTATION_MOD = 4; | 178 | constexpr uint32_t ROTATION_MOD = 4; |
| 178 | 179 | ||
| 179 | 180 | ||
| @@ -8170,12 +8171,13 @@ std::shared_ptr<Media::PixelMap> ScreenSessionManager::GetScreenSnapshot(Display | |||
| 8170 | RSSurfaceCaptureConfig config; | 8171 | RSSurfaceCaptureConfig config; |
| 8171 | config.isHdrCapture = false; | 8172 | config.isHdrCapture = false; |
| 8172 | config.useDma = isUseDma; | 8173 | config.useDma = isUseDma; |
| 8174 | + | ||
| 8173 | config.scaleX = scaleInfo.scaleX; | 8175 | config.scaleX = scaleInfo.scaleX; |
| 8174 | config.scaleY = scaleInfo.scaleY; | 8176 | config.scaleY = scaleInfo.scaleY; |
| 8175 | config.mainScreenRect = scaleInfo.rect; | 8177 | config.mainScreenRect = scaleInfo.rect; |
| 8176 | - | ||
| 8177 | if (FoldScreenStateInternel::IsSuperFoldDisplayDevice() && | 8178 | if (FoldScreenStateInternel::IsSuperFoldDisplayDevice() && |
| 8178 | - SuperFoldPolicy::GetInstance().IsNeedSetSnapshotRect(displayId)) { | 8179 | + SuperFoldPolicy::GetInstance().IsNeedSetSnapshotRect(displayId) && |
| 8180 | + (config.mainScreenRect.right_ == 0 || config.mainScreenRect.bottom_ == 0)) { | ||
| 8179 | config.mainScreenRect = SuperFoldPolicy::GetInstance().GetSnapshotRect(displayId, isCaptureFullOfScreen); | 8181 | config.mainScreenRect = SuperFoldPolicy::GetInstance().GetSnapshotRect(displayId, isCaptureFullOfScreen); |
| 8180 | } | 8182 | } |
| 8181 | 8183 | ||
| @@ -8358,9 +8360,10 @@ std::shared_ptr<Media::PixelMap> ScreenSessionManager::GetDisplaySnapshotWithOpt | |||
| 8358 | if ((Permission::IsSystemCalling() && (Permission::CheckCallingPermission(SCREEN_CAPTURE_PERMISSION) || | 8360 | if ((Permission::IsSystemCalling() && (Permission::CheckCallingPermission(SCREEN_CAPTURE_PERMISSION) || |
| 8359 | Permission::CheckCallingPermission(CUSTOM_SCREEN_RECORDING_PERMISSION))) || SessionPermission::IsShellCall()) { | 8361 | Permission::CheckCallingPermission(CUSTOM_SCREEN_RECORDING_PERMISSION))) || SessionPermission::IsShellCall()) { |
| 8360 | HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:GetDisplaySnapshot(%" PRIu64")", option.displayId_); | 8362 | HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:GetDisplaySnapshot(%" PRIu64")", option.displayId_); |
| 8361 | - Drawing::Rect rect = { static_cast<float>(option.rect.posX_), static_cast<float>(option.rect.posY_), | 8363 | + DMRect orgRect = CalcRectsWithRotation(option.displayId_, option.rect); |
| 8362 | - static_cast<float>(option.rect.posX_ + option.rect.width_), | 8364 | + Drawing::Rect rect = { static_cast<float>(orgRect.posX_), static_cast<float>(orgRect.posY_), |
| 8363 | - static_cast<float>(option.rect.posY_ + option.rect.height_) }; | 8365 | + static_cast<float>(orgRect.posX_ + orgRect.width_), |
| 8366 | + static_cast<float>(orgRect.posY_ + orgRect.height_) }; | ||
| 8364 | SnapshotScaleInfo scaleInfo = {option.scaleX_, option.scaleY_, rect}; | 8367 | SnapshotScaleInfo scaleInfo = {option.scaleX_, option.scaleY_, rect}; |
| 8365 | auto res = GetScreenSnapshot(option.displayId_, true, option.isCaptureFullOfScreen_, option.surfaceNodesList_, | 8368 | auto res = GetScreenSnapshot(option.displayId_, true, option.isCaptureFullOfScreen_, option.surfaceNodesList_, |
| 8366 | scaleInfo); | 8369 | scaleInfo); |
| @@ -8382,6 +8385,71 @@ std::shared_ptr<Media::PixelMap> ScreenSessionManager::GetDisplaySnapshotWithOpt | |||
| 8382 | return nullptr; | 8385 | return nullptr; |
| 8383 | } | 8386 | } |
| 8384 | 8387 | ||
| 8388 | +// RS need to use the actual origin on the screen, | ||
| 8389 | +// while DMS needs to convert the logical origin to the physical origin. | ||
| 8390 | +DMRect ScreenSessionManager::CalcRectsWithRotation(DisplayId displayId, const DMRect &rect) | ||
| 8391 | +{ | ||
| 8392 | + auto displayInfo = GetDisplayInfoById(displayId); | ||
| 8393 | + if (displayInfo == nullptr) { | ||
| 8394 | + TLOGE(WmsLogTag::DMS, "can not get display!"); | ||
| 8395 | + return DMRect::NONE(); | ||
| 8396 | + } | ||
| 8397 | + std::vector<std::string> phyOffsets = FoldScreenStateInternel::GetPhyRotationOffset(); | ||
| 8398 | + int32_t rotationOffset = 0; | ||
| 8399 | + int32_t boundaryOffset = 0; | ||
| 8400 | + FoldDisplayMode displayMode = GetFoldDisplayMode(); | ||
| 8401 | + if (phyOffsets.size() > 0) { | ||
| 8402 | + if (!ScreenSettingHelper::ConvertStrToInt32(phyOffsets[0], rotationOffset)) { | ||
| 8403 | + TLOGNFE(WmsLogTag::DMS, "CalcRectsWithRotation transfer PhyRotationOffset[0] failed: %{public}s", | ||
| 8404 | + phyOffsets[0].c_str()); | ||
| 8405 | + } | ||
| 8406 | + } | ||
| 8407 | + if (g_foldScreenFlag) { | ||
| 8408 | + if (phyOffsets.size() > 1 && displayMode == FoldDisplayMode::FULL) { | ||
| 8409 | + if (!ScreenSettingHelper::ConvertStrToInt32(phyOffsets[1], rotationOffset)) { | ||
| 8410 | + TLOGNFE(WmsLogTag::DMS, "CalcRectsWithRotation transfer PhyRotationOffset[1] failed: %{public}s", | ||
| 8411 | + phyOffsets[1].c_str()); | ||
| 8412 | + } | ||
| 8413 | + } | ||
| 8414 | + if (FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) { | ||
| 8415 | + rotationOffset = ROTATION_270_INT; | ||
Z | |||
| 8416 | + if (displayMode == FoldDisplayMode::FULL) { | ||
| 8417 | + boundaryOffset = static_cast<int32_t>(screenParams_[FULL_STATUS_OFFSET_X]); | ||
| 8418 | + } | ||
| 8419 | + } | ||
| 8420 | + } | ||
| 8421 | + Rotation rotation = RemoveRotationCorrection(displayInfo->GetRotation(), displayMode); | ||
| 8422 | + rotation = static_cast<Rotation>( | ||
| 8423 | + (static_cast<uint32_t>(rotation) + static_cast<uint32_t>(rotationOffset) / 90) % | ||
| 8424 | + ROTATION_MOD); | ||
| 8425 | + int32_t screenWidth = displayInfo->GetWidth(); | ||
| 8426 | + int32_t screenHeigth = displayInfo->GetHeight(); | ||
| 8427 | + DMRect calRect = rect; | ||
| 8428 | + switch (rotation) { | ||
| 8429 | + case Rotation::ROTATION_0: | ||
| 8430 | + calRect = DMRect{ rect.posX_, rect.posY_ + boundaryOffset, rect.width_, rect.height_ }; | ||
| 8431 | + break; | ||
| 8432 | + case Rotation::ROTATION_90: | ||
| 8433 | + calRect = DMRect{ | ||
| 8434 | + rect.posY_, screenWidth - rect.posX_ - rect.width_ + boundaryOffset, rect.height_, rect.width_ | ||
| 8435 | + }; | ||
| 8436 | + break; | ||
| 8437 | + case Rotation::ROTATION_180: | ||
| 8438 | + calRect = DMRect{ screenWidth - rect.posX_ - rect.width_, | ||
| 8439 | + screenHeigth - rect.posY_ - rect.height_ + boundaryOffset, | ||
| 8440 | + rect.width_, rect.height_ }; | ||
| 8441 | + break; | ||
| 8442 | + case Rotation::ROTATION_270: | ||
| 8443 | + calRect = DMRect{ | ||
| 8444 | + screenHeigth - rect.posY_ - rect.height_, rect.posX_ + boundaryOffset, rect.height_, rect.width_ | ||
| 8445 | + }; | ||
| 8446 | + break; | ||
| 8447 | + default: | ||
| 8448 | + break; | ||
| 8449 | + } | ||
| 8450 | + return calRect; | ||
| 8451 | +} | ||
| 8452 | + | ||
| 8385 | std::vector<std::shared_ptr<Media::PixelMap>> ScreenSessionManager::GetDisplayHDRSnapshotWithOption( | 8453 | std::vector<std::shared_ptr<Media::PixelMap>> ScreenSessionManager::GetDisplayHDRSnapshotWithOption( |
| 8386 | const CaptureOption& option, DmErrorCode& errorCode) | 8454 | const CaptureOption& option, DmErrorCode& errorCode) |
| 8387 | { | 8455 | { |
| @@ -1359,6 +1359,46 @@ HWTEST_F(ScreenSessionManagerTest, NotifyRSCoordination, TestSize.Level1) | |||
| 1359 | g_logMsg.clear(); | 1359 | g_logMsg.clear(); |
| 1360 | LOG_SetCallback(nullptr); | 1360 | LOG_SetCallback(nullptr); |
| 1361 | } | 1361 | } |
| 1362 | + | ||
| 1363 | +/* | ||
| 1364 | + * @tc.name: TestCalcRectsWithRotation001 | ||
| 1365 | + * @tc.desc: TestCalcRectsWithRotation | ||
| 1366 | + * @tc.type: FUNC | ||
| 1367 | + */ | ||
| 1368 | +HWTEST_F(ScreenSessionManagerTest, TestCalcRectsWithRotation001, TestSize.Level1) | ||
| 1369 | +{ | ||
| 1370 | + DisplayId displayId = 0; | ||
| 1371 | + DMRect rect = { 0, 0, 800, 600 }; | ||
| 1372 | + DMRect res = ssm_->CalcRectsWithRotation(displayId, rect); | ||
| 1373 | + ASSERT_NE(res, DMRect::NONE()); | ||
| 1374 | +} | ||
| 1375 | + | ||
| 1376 | +/* | ||
| 1377 | + * @tc.name: TestCalcRectsWithRotation002 | ||
| 1378 | + * @tc.desc: TestCalcRectsWithRotation | ||
| 1379 | + * @tc.type: FUNC | ||
| 1380 | + */ | ||
| 1381 | +HWTEST_F(ScreenSessionManagerTest, TestCalcRectsWithRotation002, TestSize.Level1) | ||
| 1382 | +{ | ||
| 1383 | + DisplayId displayId = DISPLAY_ID_FAKE; | ||
| 1384 | + DMRect rect = { 0, 0, 800, 600 }; | ||
| 1385 | + DMRect res = ssm_->CalcRectsWithRotation(displayId, rect); | ||
| 1386 | + EXPECT_EQ(res, DMRect::NONE()); | ||
| 1387 | +} | ||
| 1388 | + | ||
| 1389 | +/* | ||
| 1390 | + * @tc.name: TestCalcRectsWithRotation003 | ||
| 1391 | + * @tc.desc: TestCalcRectsWithRotation | ||
| 1392 | + * @tc.type: FUNC | ||
| 1393 | + */ | ||
| 1394 | +HWTEST_F(ScreenSessionManagerTest, TestCalcRectsWithRotation003, TestSize.Level1) | ||
| 1395 | +{ | ||
| 1396 | + DisplayId displayId = 0; | ||
| 1397 | + DMRect rect = { 0, 0, 800, 600 }; | ||
| 1398 | + system::SetParameter("const.window.phyrotation.offset", "0"); | ||
| 1399 | + DMRect res = ssm_->CalcRectsWithRotation(displayId, rect); | ||
| 1400 | + ASSERT_NE(res, DMRect::NONE()); | ||
| 1401 | +} | ||
| 1362 | } | 1402 | } |
| 1363 | } // namespace Rosen | 1403 | } // namespace Rosen |
| 1364 | } // namespace OHOS | 1404 | } // namespace OHOS |


可以使用PhyRotationOffset[1]进行替换