text绘制性能优化,无隐私遮罩时不获取遮罩区

Signed-off-by: lijuan <lijuan124@huawei.com>
This commit is contained in:
lijuan 2024-07-31 05:51:43 +00:00
parent 4c3a64de63
commit 2d08c6f418
7 changed files with 61 additions and 149 deletions

View File

@ -346,8 +346,6 @@ void TextContentModifier::onDraw(DrawingContext& drawingContext)
{
auto textPattern = DynamicCast<TextPattern>(pattern_.Upgrade());
CHECK_NULL_VOID(textPattern);
bool ifPaintObscuration = std::any_of(obscuredReasons_.begin(), obscuredReasons_.end(),
[](const auto& reason) { return reason == ObscuredReasons::PLACEHOLDER; });
auto pManager = textPattern->GetParagraphManager();
CHECK_NULL_VOID(pManager);
CHECK_NULL_VOID(!pManager->GetParagraphs().empty());
@ -355,7 +353,7 @@ void TextContentModifier::onDraw(DrawingContext& drawingContext)
CHECK_NULL_VOID(host);
ACE_SCOPED_TRACE("[Text][id:%d] paint[offset:%f,%f]", host->GetId(), paintOffset_.GetX(), paintOffset_.GetY());
if (!ifPaintObscuration || ifHaveSpanItemChildren_) {
if (!ifPaintObscuration_) {
auto& canvas = drawingContext.canvas;
auto contentSize = contentSize_->Get();
auto contentOffset = contentOffset_->Get();

View File

@ -70,14 +70,9 @@ public:
paintOffset_ = paintOffset;
}
void SetObscured(const std::vector<ObscuredReasons>& reasons)
void SetIfPaintObscuration(bool value)
{
obscuredReasons_ = reasons;
}
void SetIfHaveSpanItemChildren(bool value)
{
ifHaveSpanItemChildren_ = value;
ifPaintObscuration_ = value;
}
void SetDrawObscuredRects(const std::vector<RectF>& drawObscuredRects)
@ -197,8 +192,7 @@ private:
OffsetF paintOffset_;
float textRaceSpaceWidth_ = 0;
std::vector<ObscuredReasons> obscuredReasons_;
bool ifHaveSpanItemChildren_ = false;
bool ifPaintObscuration_ = false;
std::vector<RectF> drawObscuredRects_;
std::vector<WeakPtr<FrameNode>> imageNodeList_;
MarqueeState marqueeState_ = MarqueeState::IDLE;

View File

@ -70,16 +70,17 @@ void TextPaintMethod::UpdateContentModifier(PaintWrapper* paintWrapper)
} else {
textContentModifier_->StopTextRace();
}
// Privacy masking.
auto reasons = renderContext->GetObscured().value_or(std::vector<ObscuredReasons>());
textContentModifier_->SetObscured(reasons);
auto spanItemChildren = pattern->GetSpanItemChildren();
textContentModifier_->SetIfHaveSpanItemChildren(!spanItemChildren.empty());
auto wideTextLength = pattern->GetDisplayWideTextLength();
std::vector<RectF> drawObscuredRects;
if (wideTextLength != 0) {
drawObscuredRects = pManager->GetRects(0, wideTextLength);
bool ifPaintObscuration = std::any_of(reasons.begin(), reasons.end(),
[](const auto& reason) { return reason == ObscuredReasons::PLACEHOLDER; });
if (ifPaintObscuration) {
UpdateObscuredRects();
} else {
textContentModifier_->SetIfPaintObscuration(false);
}
textContentModifier_->SetDrawObscuredRects(drawObscuredRects);
if (renderContext->GetClipEdge().has_value()) {
textContentModifier_->SetClip(renderContext->GetClipEdge().value());
}
@ -89,6 +90,26 @@ void TextPaintMethod::UpdateContentModifier(PaintWrapper* paintWrapper)
}
}
void TextPaintMethod::UpdateObscuredRects()
{
auto pattern = DynamicCast<TextPattern>(pattern_.Upgrade());
CHECK_NULL_VOID(pattern);
auto pManager = pattern->GetParagraphManager();
CHECK_NULL_VOID(pManager);
auto spanItemChildren = pattern->GetSpanItemChildren();
auto ifPaintObscuration = spanItemChildren.empty();
textContentModifier_->SetIfPaintObscuration(ifPaintObscuration);
CHECK_NULL_VOID(ifPaintObscuration);
auto wideTextLength = pattern->GetDisplayWideTextLength();
std::vector<RectF> drawObscuredRects;
if (wideTextLength != 0 && ifPaintObscuration) {
drawObscuredRects = pManager->GetRects(0, wideTextLength);
}
textContentModifier_->SetDrawObscuredRects(drawObscuredRects);
}
RefPtr<Modifier> TextPaintMethod::GetOverlayModifier(PaintWrapper* paintWrapper)
{
return textOverlayModifier_;

View File

@ -51,8 +51,8 @@ protected:
private:
void UpdateParagraphAndImageSpanNodeList();
void UpdateObscuredRects();
private:
WeakPtr<Pattern> pattern_;
float baselineOffset_;

View File

@ -2635,7 +2635,7 @@ HWTEST_F(TextTestFiveNg, onDraw001, TestSize.Level1)
textContentModifier->animatableTextColor_ =
AceType::MakeRefPtr<AnimatablePropertyColor>(LinearColor(Color::TRANSPARENT));
textContentModifier->obscuredReasons_.emplace_back(ObscuredReasons::PLACEHOLDER);
textContentModifier->ifPaintObscuration_ = true;
textContentModifier->drawObscuredRects_.emplace_back(RectF(0, 0, 10, 10));
textContentModifier->onDraw(drawingContext);

View File

@ -451,58 +451,41 @@ HWTEST_F(TextTestFourNg, TextContentModifier003, TestSize.Level1)
/**
* @tc.steps: step3. call onDraw function of textContentModifier.
* @tc.expected: The obscuredReasons_ of textContentModifier is empty.
* The ifHaveSpanItemChildren_ of textContentModifier is false.
* The ifPaintObscuration_ of textContentModifier is false.
*/
textContentModifier->onDraw(context);
EXPECT_EQ(textContentModifier->obscuredReasons_, std::vector<ObscuredReasons>());
EXPECT_EQ(textContentModifier->ifHaveSpanItemChildren_, false);
EXPECT_EQ(textContentModifier->ifPaintObscuration_, false);
/**
* @tc.steps: step4. set ifHaveSpanItemChildren_ to true.
* @tc.steps: step4. set ifPaintObscuration_ to true.
*/
textContentModifier->SetIfHaveSpanItemChildren(true);
textContentModifier->SetIfPaintObscuration(true);
/**
* @tc.steps: step5. call onDraw function of textContentModifier.
* @tc.expected: The obscuredReasons_ of textContentModifier is empty.
* The ifHaveSpanItemChildren_ of textContentModifier is true.
* The ifPaintObscuration_ of textContentModifier is true.
*/
textContentModifier->onDraw(context);
EXPECT_EQ(textContentModifier->obscuredReasons_, std::vector<ObscuredReasons>());
EXPECT_EQ(textContentModifier->ifHaveSpanItemChildren_, true);
EXPECT_EQ(textContentModifier->ifPaintObscuration_, true);
/**
* @tc.steps: step6. push UNKNOWN_REASON and PLACEHOLDER to reasons.
* set obscuredReasons_ to reasons.
*/
std::vector<ObscuredReasons> reasons;
reasons.push_back((ObscuredReasons)UNKNOWN_REASON);
reasons.push_back(ObscuredReasons::PLACEHOLDER);
textContentModifier->SetObscured(reasons);
/**
* @tc.steps: step7. call onDraw function of textContentModifier.
* @tc.expected: The obscuredReasons_ of textContentModifier is reasons.
* The ifHaveSpanItemChildren_ of textContentModifier is true.
* @tc.steps: step6. call onDraw function of textContentModifier.
* The ifPaintObscuration_ of textContentModifier is true.
*/
textContentModifier->onDraw(context);
EXPECT_EQ(textContentModifier->obscuredReasons_, reasons);
EXPECT_EQ(textContentModifier->ifHaveSpanItemChildren_, true);
EXPECT_EQ(textContentModifier->ifPaintObscuration_, true);
/**
* @tc.steps: step8. set ifHaveSpanItemChildren_ to false.
* @tc.steps: step7. set ifPaintObscuration_ to false.
*/
textContentModifier->SetIfHaveSpanItemChildren(false);
textContentModifier->SetIfPaintObscuration(false);
/**
* @tc.steps: step9. call onDraw function of textContentModifier.
* @tc.expected: The obscuredReasons_ of textContentModifier is reasons.
* The ifHaveSpanItemChildren_ of textContentModifier is false.
* @tc.steps: step8. call onDraw function of textContentModifier.
* The ifPaintObscuration_ of textContentModifier is false.
*/
textContentModifier->onDraw(context);
EXPECT_EQ(textContentModifier->obscuredReasons_, reasons);
EXPECT_EQ(textContentModifier->ifHaveSpanItemChildren_, false);
EXPECT_EQ(textContentModifier->ifPaintObscuration_, false);
}
/**

View File

@ -1885,7 +1885,16 @@ HWTEST_F(TextTestTwoNg, TextPaintMethodTest003, TestSize.Level1)
pattern->textForDisplay_ = EMPTY_TEXT;
/**
* @tc.steps: step3. create textPaintMethod and call UpdateContentModifier function.
* @tc.steps: step3. push UNKNOWN_REASON and PLACEHOLDER to reasons.
* set obscured of renderContext to reasons.
*/
std::vector<ObscuredReasons> reasons;
reasons.push_back((ObscuredReasons)UNKNOWN_REASON);
reasons.push_back(ObscuredReasons::PLACEHOLDER);
renderContext->UpdateObscured(reasons);
/**
* @tc.steps: step4. create textPaintMethod and call UpdateContentModifier function.
* @tc.expected: The drawObscuredRects_ of textContentModifier is empty.
*/
RefPtr<TextContentModifier> textContentModifier =
@ -1897,12 +1906,12 @@ HWTEST_F(TextTestTwoNg, TextPaintMethodTest003, TestSize.Level1)
EXPECT_EQ(textContentModifier->drawObscuredRects_, std::vector<RectF>());
/**
* @tc.steps: step4. set textForDisplay_ to CREATE_VALUE.
* @tc.steps: step5. set textForDisplay_ to CREATE_VALUE.
*/
pattern->textForDisplay_ = CREATE_VALUE;
/**
* @tc.steps: step5. call UpdateContentModifier function.
* @tc.steps: step6. call UpdateContentModifier function.
* @tc.expected: The drawObscuredRects_ of textContentModifier is not empty.
*/
renderContext = host->GetRenderContext();
@ -1912,15 +1921,6 @@ HWTEST_F(TextTestTwoNg, TextPaintMethodTest003, TestSize.Level1)
textPaintMethod1.UpdateContentModifier(AceType::RawPtr(paintWrapper));
EXPECT_NE(textContentModifier->drawObscuredRects_, std::vector<RectF>());
/**
* @tc.steps: step6. push UNKNOWN_REASON and PLACEHOLDER to reasons.
* set obscured of renderContext to reasons.
*/
std::vector<ObscuredReasons> reasons;
reasons.push_back((ObscuredReasons)UNKNOWN_REASON);
reasons.push_back(ObscuredReasons::PLACEHOLDER);
renderContext->UpdateObscured(reasons);
/**
* @tc.steps: step7. call OnModifyDone function.
* @tc.expected: The obscured of renderContext is reasons.
@ -1930,90 +1930,6 @@ HWTEST_F(TextTestTwoNg, TextPaintMethodTest003, TestSize.Level1)
pattern->pManager_->Reset();
}
/**
* @tc.name: TextContentModifier003
* @tc.desc: test text_content_modifier.cpp onDraw function
* @tc.type: FUNC
*/
HWTEST_F(TextTestTwoNg, TextContentModifier003, TestSize.Level1)
{
/**
* @tc.steps: step1. create textFrameNode and geometryNode.
*/
auto textFrameNode = FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, 0, AceType::MakeRefPtr<TextPattern>());
ASSERT_NE(textFrameNode, nullptr);
RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
ASSERT_NE(geometryNode, nullptr);
auto textPattern = textFrameNode->GetPattern<TextPattern>();
ASSERT_NE(textPattern, nullptr);
auto textPaintMethod = textPattern->CreateNodePaintMethod();
ASSERT_NE(textPaintMethod, nullptr);
auto textContentModifier = textPattern->GetContentModifier();
ASSERT_NE(textContentModifier, nullptr);
/**
* @tc.steps: step2. set context.
*/
Testing::MockCanvas canvas;
EXPECT_CALL(canvas, ClipRect(_, _, _)).WillRepeatedly(Return());
DrawingContext context { canvas, CONTEXT_WIDTH_VALUE, CONTEXT_HEIGHT_VALUE };
/**
* @tc.steps: step3. call onDraw function of textContentModifier.
* @tc.expected: The obscuredReasons_ of textContentModifier is empty.
* The ifHaveSpanItemChildren_ of textContentModifier is false.
*/
textContentModifier->onDraw(context);
EXPECT_EQ(textContentModifier->obscuredReasons_, std::vector<ObscuredReasons>());
EXPECT_EQ(textContentModifier->ifHaveSpanItemChildren_, false);
/**
* @tc.steps: step4. set ifHaveSpanItemChildren_ to true.
*/
textContentModifier->SetIfHaveSpanItemChildren(true);
/**
* @tc.steps: step5. call onDraw function of textContentModifier.
* @tc.expected: The obscuredReasons_ of textContentModifier is empty.
* The ifHaveSpanItemChildren_ of textContentModifier is true.
*/
textContentModifier->onDraw(context);
EXPECT_EQ(textContentModifier->obscuredReasons_, std::vector<ObscuredReasons>());
EXPECT_EQ(textContentModifier->ifHaveSpanItemChildren_, true);
/**
* @tc.steps: step6. push UNKNOWN_REASON and PLACEHOLDER to reasons.
* set obscuredReasons_ to reasons.
*/
std::vector<ObscuredReasons> reasons;
reasons.push_back((ObscuredReasons)UNKNOWN_REASON);
reasons.push_back(ObscuredReasons::PLACEHOLDER);
textContentModifier->SetObscured(reasons);
/**
* @tc.steps: step7. call onDraw function of textContentModifier.
* @tc.expected: The obscuredReasons_ of textContentModifier is reasons.
* The ifHaveSpanItemChildren_ of textContentModifier is true.
*/
textContentModifier->onDraw(context);
EXPECT_EQ(textContentModifier->obscuredReasons_, reasons);
EXPECT_EQ(textContentModifier->ifHaveSpanItemChildren_, true);
/**
* @tc.steps: step8. set ifHaveSpanItemChildren_ to false.
*/
textContentModifier->SetIfHaveSpanItemChildren(false);
/**
* @tc.steps: step9. call onDraw function of textContentModifier.
* @tc.expected: The obscuredReasons_ of textContentModifier is reasons.
* The ifHaveSpanItemChildren_ of textContentModifier is false.
*/
textContentModifier->onDraw(context);
EXPECT_EQ(textContentModifier->obscuredReasons_, reasons);
EXPECT_EQ(textContentModifier->ifHaveSpanItemChildren_, false);
}
/**
* @tc.name: TextContentModifier004
* @tc.desc: test text_content_modifier.cpp DrawObscuration function