!1492 Add ut and st for waterfall compression

Merge pull request !1492 from X PN/dev-compress
This commit is contained in:
openharmony_ci 2022-09-06 01:07:57 +00:00 committed by Gitee
commit fbdb359d25
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
10 changed files with 136 additions and 40 deletions

View File

@ -17,6 +17,7 @@
#include "display_manager.h"
#include "mock_display_manager_adapter.h"
#include "singleton_mocker.h"
#include "display_cutout_controller.h"
using namespace testing;
using namespace testing::ext;
@ -68,6 +69,71 @@ HWTEST_F(DisplayTest, GetCutoutInfo01, Function | SmallTest | Level1)
auto cutoutInfo = defaultDisplay_->GetCutoutInfo();
ASSERT_NE(nullptr, cutoutInfo);
}
/**
* @tc.name: SetWaterfallCompression01
* @tc.desc: Set waterfall compression related values with valid input.
* @tc.type: FUNC
* @tc.require: issueI5P8CI
*/
HWTEST_F(DisplayTest, SetWaterfallCompression01, Function | SmallTest | Level1)
{
bool isWaterfallDisplayOrigin = DisplayCutoutController::IsWaterfallDisplay();
DisplayCutoutController::SetIsWaterfallDisplay(true);
bool isCompressionEnableOrigin =
DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal();
DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(true);
uint32_t testSizeOrigin = DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal();
uint32_t testSize = 20;
DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(testSize);
ASSERT_EQ(true, DisplayCutoutController::IsWaterfallDisplay());
ASSERT_EQ(true, DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal());
ASSERT_EQ(testSize, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal());
DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(testSizeOrigin);
ASSERT_EQ(testSizeOrigin, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal());
DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(isCompressionEnableOrigin);
ASSERT_EQ(isWaterfallDisplayOrigin, DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal());
DisplayCutoutController::SetIsWaterfallDisplay(isWaterfallDisplayOrigin);
ASSERT_EQ(isWaterfallDisplayOrigin, DisplayCutoutController::IsWaterfallDisplay());
}
/**
* @tc.name: SetWaterfallCompression02
* @tc.desc: Set waterfall compression related values with invalid input.
* @tc.type: FUNC
* @tc.require: issueI5P8CI
*/
HWTEST_F(DisplayTest, SetWaterfallCompression02, Function | SmallTest | Level1)
{
bool isWaterfallDisplayOrigin = DisplayCutoutController::IsWaterfallDisplay();
DisplayCutoutController::SetIsWaterfallDisplay(true);
bool isCompressionEnableOrigin =
DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal();
DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(true);
uint32_t testSizeOrigin = DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal();
DisplayCutoutController::SetIsWaterfallDisplay(false);
DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(true);
ASSERT_EQ(false, DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal());
uint32_t testSize = 20;
DisplayCutoutController::SetIsWaterfallDisplay(true);
DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(false);
DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(testSize);
ASSERT_EQ(0, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal());
DisplayCutoutController::SetIsWaterfallDisplay(false);
DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(false);
DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(testSize);
ASSERT_EQ(0, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal());
DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(testSizeOrigin);
ASSERT_EQ(testSizeOrigin, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal());
DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(isCompressionEnableOrigin);
ASSERT_EQ(isWaterfallDisplayOrigin, DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal());
DisplayCutoutController::SetIsWaterfallDisplay(isWaterfallDisplayOrigin);
ASSERT_EQ(isWaterfallDisplayOrigin, DisplayCutoutController::IsWaterfallDisplay());
}
}
} // namespace Rosen
} // namespace OHOS

View File

@ -299,21 +299,29 @@ void AbstractDisplayController::ProcessDisplayCompression(sptr<AbstractScreen> a
if (absDisplay->GetId() != defaultDisplayId) {
return;
}
if (!DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal() ||
DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal() == 0) {
uint32_t sizeInVp = DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal();
if (!DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal() || sizeInVp == 0) {
WLOGFI("Not enable waterfall display area compression.");
return;
}
Rotation rotation = absDisplay->GetRotation();
auto mode = absScreen->GetActiveScreenMode();
if (mode == nullptr) {
WLOGFE("ScreenMode is nullptr");
WLOGFW("SupportedScreenModes is null");
return;
}
uint32_t screenHeight = mode->height_;
uint32_t screenWidth = mode->width_;
uint32_t sizeInPx = static_cast<uint32_t>(sizeInVp * absDisplay->GetVirtualPixelRatio());
// 4: Compression size shall less than 1/4 of the screen size.
if (sizeInPx >= screenHeight / 4 || sizeInPx >= screenWidth / 4) {
WLOGFW("Invalid value for waterfall display curved area avoid size of each sides");
return;
}
WLOGFI("ProcessWaterfallCompression, sizeInPx: %{public}u", sizeInPx);
Rotation rotation = absDisplay->GetRotation();
bool isDefaultRotationVertical = mode->height_ > mode->width_ ? true : false;
if (ScreenRotationController::IsDisplayRotationHorizontal(rotation)) {
uint32_t offsetY = DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal();
uint32_t offsetY = sizeInPx;
uint32_t totalCompressedSize = offsetY * 2; // *2 for both sides.
uint32_t displayHeightAfter = isDefaultRotationVertical ? mode->width_ - totalCompressedSize :
mode->height_ - totalCompressedSize;
@ -331,7 +339,7 @@ void AbstractDisplayController::ProcessDisplayCompression(sptr<AbstractScreen> a
absDisplay->SetWidth(isDefaultRotationVertical ? mode->width_ : mode->height_);
absDisplay->SetWaterfallDisplayCompressionStatus(false);
}
SetDisplayStateChangeListener(absDisplay, DisplayStateChangeType::LAYOUT_COMPRESS);
SetDisplayStateChangeListener(absDisplay, DisplayStateChangeType::DISPLAY_COMPRESS);
DisplayManagerAgentController::GetInstance().OnDisplayChange(
absDisplay->ConvertToDisplayInfo(), DisplayChangeEvent::DISPLAY_SIZE_CHANGED);
}

View File

@ -21,7 +21,7 @@ namespace OHOS {
namespace Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayCutoutController"};
const uint32_t NO_WATERFALL_LAYOUT_COMPRESSION_SIZE = 0;
const uint32_t NO_WATERFALL_DISPLAY_COMPRESSION_SIZE = 0;
}
bool DisplayCutoutController::isWaterfallDisplay_ = false;
@ -301,25 +301,9 @@ uint32_t DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal(
{
if (!isWaterfallDisplay_ || !isWaterfallAreaCompressionEnableWhenHorizontal_) {
WLOGFW("Not waterfall display or not enable waterfall compression");
return NO_WATERFALL_LAYOUT_COMPRESSION_SIZE;
return NO_WATERFALL_DISPLAY_COMPRESSION_SIZE;
}
auto& dms = DisplayManagerServiceInner::GetInstance();
auto mode = dms.GetScreenModesByDisplayId(dms.GetDefaultDisplayId());
if (mode == nullptr) {
WLOGFW("SupportedScreenModes is null");
return NO_WATERFALL_LAYOUT_COMPRESSION_SIZE;
}
uint32_t screenHeight = mode->height_;
uint32_t screenWidth = mode->width_;
float vpr = dms.GetDefaultDisplay()->GetVirtualPixelRatio();
uint32_t sizeInPx = static_cast<uint32_t>(waterfallAreaCompressionSizeWhenHorizontal_ * vpr);
WLOGFD("Compression size in Px: %{public}u", sizeInPx);
// 4: Compression size shall less than 1/4 of the screen size.
if (sizeInPx >= screenHeight / 4 || sizeInPx >= screenWidth / 4) {
WLOGFW("Invalid value for waterfall display curved area avoid size of each sides");
return NO_WATERFALL_LAYOUT_COMPRESSION_SIZE;
}
return sizeInPx;
return waterfallAreaCompressionSizeWhenHorizontal_;
}
} // Rosen
} // OHOS

View File

@ -15,6 +15,7 @@
#include <gtest/gtest.h>
#include "display_cutout_controller.h"
#include "display_info.h"
#include "display_manager.h"
#include "screen_manager.h"
@ -381,6 +382,43 @@ HWTEST_F(DisplayChangeTest, CheckScreenDensityChange05, Function | SmallTest | L
ASSERT_EQ(true, defaultScreen_->SetDensityDpi(DisplayChangeTest::originalDisplayDpi));
sleep(SPLIT_TEST_SLEEP_S);
}
/**
* @tc.name: CheckWaterfallCompression01
* @tc.desc: check function of waterfall display compression.
* @tc.type: FUNC
*/
HWTEST_F(DisplayChangeTest, CheckWaterfallCompression01, Function | SmallTest | Level2)
{
bool originWaterfallEnable = DisplayCutoutController::IsWaterfallDisplay();
DisplayCutoutController::SetIsWaterfallDisplay(true);
bool originStatus = DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal();
DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(true);
uint32_t originSize = DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal();
uint32_t testSizeInVp = 24;
DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(testSizeInVp);
ASSERT_EQ(true, DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal());
ASSERT_EQ(testSizeInVp, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal());
Orientation originOrientation = defaultScreen_->GetOrientation();
defaultScreen_->SetOrientation(Orientation::VERTICAL);
sleep(SPLIT_TEST_SLEEP_S);
defaultScreen_->SetOrientation(Orientation::HORIZONTAL);
sleep(SPLIT_TEST_SLEEP_S);
defaultScreen_->SetOrientation(Orientation::VERTICAL);
sleep(SPLIT_TEST_SLEEP_S);
DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(originSize);
ASSERT_EQ(originSize, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal());
DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(originStatus);
ASSERT_EQ(originStatus, DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal());
DisplayCutoutController::SetIsWaterfallDisplay(originWaterfallEnable);
defaultScreen_->SetOrientation(originOrientation);
sleep(SPLIT_TEST_SLEEP_S);
ASSERT_EQ(originOrientation, defaultScreen_->GetOrientation());
}
}
} // namespace Rosen
} // namespace OHOS

View File

@ -30,7 +30,7 @@ enum class DisplayStateChangeType : uint32_t {
FREEZE,
UNFREEZE,
VIRTUAL_PIXEL_RATIO_CHANGE,
LAYOUT_COMPRESS,
DISPLAY_COMPRESS,
};
class IDisplayChangeListener : public RefBase {
public:

View File

@ -41,8 +41,8 @@ public:
std::shared_ptr<Media::PixelMap> pixelMap, uint32_t bkgColor);
static bool GetSurfaceSnapshot(const std::shared_ptr<RSSurfaceNode> surfaceNode,
std::shared_ptr<Media::PixelMap>& pixelMap, int32_t timeoutMs, float scaleW = 0.5, float scaleH = 0.5);
static bool DrawMasking(std::shared_ptr<RSSurfaceNode> surfaceNode, const Rect screenRect,
const Rect transparentRect);
static bool DrawMasking(std::shared_ptr<RSSurfaceNode> surfaceNode, Rect screenRect,
Rect transparentRect);
private:
static bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const std::string& imagePath);

View File

@ -358,8 +358,8 @@ bool SurfaceDraw::GetSurfaceSnapshot(const std::shared_ptr<RSSurfaceNode> surfac
return true;
}
bool SurfaceDraw::DrawMasking(std::shared_ptr<RSSurfaceNode> surfaceNode, const Rect screenRect,
const Rect transparentRect)
bool SurfaceDraw::DrawMasking(std::shared_ptr<RSSurfaceNode> surfaceNode, Rect screenRect,
Rect transparentRect)
{
int32_t screenHeight = static_cast<int32_t>(screenRect.height_);
int32_t screenWidth = static_cast<int32_t>(screenRect.width_);

View File

@ -103,7 +103,7 @@ private:
void NotifyWindowPropertyChanged(const sptr<WindowNode>& node);
WMError GetFocusWindowNode(DisplayId displayId, sptr<WindowNode>& windowNode);
void SetDefaultDisplayInfo(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo);
void ProcessDisplayCompression(const sptr<DisplayInfo>& displayInfo);
void ProcessDisplayCompression(DisplayId defaultDisplayId, const sptr<DisplayInfo>& displayInfo);
sptr<WindowRoot> windowRoot_;
sptr<InputWindowMonitor> inputWindowMonitor_;

View File

@ -118,7 +118,7 @@ void DisplayGroupController::ProcessCrossNodes(DisplayId defaultDisplayId, Displ
DisplayId newDisplayId;
if (type == DisplayStateChangeType::SIZE_CHANGE || type == DisplayStateChangeType::UPDATE_ROTATION ||
type == DisplayStateChangeType::LAYOUT_COMPRESS) {
type == DisplayStateChangeType::DISPLAY_COMPRESS) {
newDisplayId = node->GetDisplayId();
} else {
newDisplayId = defaultDisplayId;
@ -437,7 +437,7 @@ void DisplayGroupController::ProcessDisplayChange(DisplayId defaultDisplayId, sp
displayGroupInfo_->SetDisplayRotation(displayId, displayInfo->GetRotation());
[[fallthrough]];
}
case DisplayStateChangeType::LAYOUT_COMPRESS:
case DisplayStateChangeType::DISPLAY_COMPRESS:
case DisplayStateChangeType::SIZE_CHANGE: {
ProcessDisplaySizeChangeOrRotation(defaultDisplayId, displayId, displayRectMap, type);
break;

View File

@ -508,7 +508,7 @@ void WindowController::NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr
FlushWindowInfoWithDisplayId(displayInfo->GetDisplayId());
break;
}
case DisplayStateChangeType::LAYOUT_COMPRESS:
case DisplayStateChangeType::DISPLAY_COMPRESS:
case DisplayStateChangeType::SIZE_CHANGE:
case DisplayStateChangeType::UPDATE_ROTATION:
case DisplayStateChangeType::VIRTUAL_PIXEL_RATIO_CHANGE: {
@ -570,8 +570,8 @@ void WindowController::ProcessDisplayChange(DisplayId defaultDisplayId, sptr<Dis
windowNodeContainer->UpdateDisplayInfo(displayInfo);
}
switch (type) {
case DisplayStateChangeType::LAYOUT_COMPRESS:
ProcessDisplayCompression(displayInfo);
case DisplayStateChangeType::DISPLAY_COMPRESS:
ProcessDisplayCompression(defaultDisplayId, displayInfo);
[[fallthrough]];
case DisplayStateChangeType::SIZE_CHANGE:
case DisplayStateChangeType::UPDATE_ROTATION:
@ -595,15 +595,15 @@ void WindowController::ProcessDisplayChange(DisplayId defaultDisplayId, sptr<Dis
}
}
void WindowController::ProcessDisplayCompression(const sptr<DisplayInfo>& displayInfo)
void WindowController::ProcessDisplayCompression(DisplayId defaultDisplayId, const sptr<DisplayInfo>& displayInfo)
{
WLOGFI("Enter processDisplayCompress");
auto& dms = DisplayManagerServiceInner::GetInstance();
DisplayId displayId = displayInfo->GetDisplayId();
if (displayId != dms.GetDefaultDisplayId()) {
if (displayId != defaultDisplayId) {
WLOGFI("Not default display");
return;
}
auto& dms = DisplayManagerServiceInner::GetInstance();
if (!displayInfo->GetWaterfallDisplayCompressionStatus()) {
if (maskingSurfaceNode_ == nullptr) {
WLOGFD("MaskingSurfaceNode is not created");