From eac0370cddb884b4b9b0eeccc9d152708b9772a4 Mon Sep 17 00:00:00 2001 From: yeyinglong_admin Date: Fri, 1 Mar 2024 20:59:41 +0800 Subject: [PATCH] =?UTF-8?q?List=20Grid=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yeyinglong_admin --- .../pattern/grid/grid_layout_info.h | 1 + .../grid_scroll_layout_algorithm.cpp | 22 +++- .../grid_scroll_layout_algorithm.h | 1 + .../list/list_lanes_layout_algorithm.cpp | 14 ++- .../pattern/list/list_layout_algorithm.cpp | 39 ++++-- .../pattern/list/list_layout_algorithm.h | 7 ++ .../pattern/list/list_pattern.cpp | 1 + .../components_ng/pattern/list/list_pattern.h | 5 + .../render/adapter/rosen_render_context.cpp | 116 ++++++++++++++---- .../render/adapter/rosen_render_context.h | 2 + .../core/pipeline_ng/ui_task_scheduler.cpp | 1 + 11 files changed, 161 insertions(+), 48 deletions(-) diff --git a/frameworks/core/components_ng/pattern/grid/grid_layout_info.h b/frameworks/core/components_ng/pattern/grid/grid_layout_info.h index ba73af0f370..ecc060249c6 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_layout_info.h +++ b/frameworks/core/components_ng/pattern/grid/grid_layout_info.h @@ -244,6 +244,7 @@ struct GridLayoutInfo { float currentOffset_ = 0.0f; // offset on the current top GridItem on [startMainLineIndex_] float prevOffset_ = 0.0f; float lastMainSize_ = 0.0f; + float lastCrossSize_ = 0.0f; float totalHeightOfItemsInView_ = 0.0f; // additional padding to accommodate navigation bar when SafeArea is expanded diff --git a/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.cpp index e33f3f81802..09110d254bc 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.cpp @@ -63,6 +63,8 @@ void GridScrollLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) // Step2: Measure children that can be displayed in viewport of Grid float mainSize = GetMainAxisSize(idealSize, axis); float crossSize = GetCrossAxisSize(idealSize, axis); + canSkipMeasure_ = (gridLayoutInfo_.lastCrossSize_ == crossSize) && (gridLayoutInfo_.lastMainSize_ == mainSize) && + (gridLayoutProperty->GetPropertyChangeFlag() == PROPERTY_UPDATE_MEASURE_SELF); if (!NearEqual(mainSize, gridLayoutInfo_.lastMainSize_)) { gridLayoutInfo_.ResetPositionFlags(); UpdateOffsetOnVirtualKeyboardHeightChange(layoutWrapper, mainSize); @@ -73,6 +75,8 @@ void GridScrollLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) // update cache info. layoutWrapper->SetCacheCount(static_cast(gridLayoutProperty->GetCachedCountValue(1) * crossCount_)); + gridLayoutInfo_.lastMainSize_ = mainSize; + gridLayoutInfo_.lastCrossSize_ = crossSize; AdaptToChildMainSize(layoutWrapper, gridLayoutProperty, mainSize, idealSize); // reset offsetEnd after scroll to moveToEndLineIndex_ @@ -133,7 +137,6 @@ void GridScrollLayoutAlgorithm::UpdateOffsetOnVirtualKeyboardHeightChange(Layout void GridScrollLayoutAlgorithm::AdaptToChildMainSize(LayoutWrapper* layoutWrapper, RefPtr& gridLayoutProperty, float mainSize, const SizeF& idealSize) { - gridLayoutInfo_.lastMainSize_ = mainSize; // grid with columnsTemplate/rowsTemplate and maxCount if (!gridLayoutProperty->HasMaxCount()) { return; @@ -193,7 +196,8 @@ void GridScrollLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) : OffsetF(gridLayoutInfo_.currentOffset_, 0.0f); float prevLineHeight = 0.0f; - layoutWrapper->RemoveAllChildInRenderTree(); + int32_t startIndex = -1; + int32_t endIndex = -1; LargeItemForwardLineHeight(gridLayoutInfo_.startMainLineIndex_, layoutWrapper); for (auto i = gridLayoutInfo_.startMainLineIndex_; i <= gridLayoutInfo_.endMainLineIndex_; i++) { const auto& line = gridLayoutInfo_.gridMatrix_.find(i); @@ -235,13 +239,19 @@ void GridScrollLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) if (!wrapper) { continue; } + startIndex = startIndex == -1 ? itemIdex : startIndex; + endIndex = itemIdex; auto frSize = itemsCrossSize_.at(iter->first); SizeF blockSize = gridLayoutProperty->IsVertical() ? SizeF(frSize, lineHeight) : SizeF(lineHeight, frSize); auto translate = OffsetF(0.0f, 0.0f); translate = Alignment::GetAlignPosition(blockSize, wrapper->GetGeometryNode()->GetMarginFrameSize(), align); wrapper->GetGeometryNode()->SetMarginFrameOffset(offset + translate); - wrapper->Layout(); + if (wrapper->CheckNeedForceMeasureAndLayout()) { + wrapper->Layout(); + } else { + SyncGeometry(wrapper); + } auto layoutProperty = wrapper->GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); auto gridItemLayoutProperty = AceType::DynamicCast(layoutProperty); @@ -252,6 +262,7 @@ void GridScrollLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) } prevLineHeight += gridLayoutInfo_.lineHeightMap_[line->first] + mainGap_; } + layoutWrapper->SetActiveChildRange(startIndex, endIndex); gridLayoutInfo_.totalHeightOfItemsInView_ = gridLayoutInfo_.GetTotalHeightOfItemsInView(mainGap_); if (SystemProperties::GetGridCacheEnabled()) { @@ -327,7 +338,6 @@ void GridScrollLayoutAlgorithm::LayoutBackwardCachedLine(LayoutWrapper* layoutWr translate = Alignment::GetAlignPosition(blockSize, wrapper->GetGeometryNode()->GetMarginFrameSize(), align); wrapper->GetGeometryNode()->SetMarginFrameOffset(offset + translate); - wrapper->Layout(); SyncGeometry(wrapper); wrapper->SetActive(false); } @@ -392,7 +402,6 @@ void GridScrollLayoutAlgorithm::LayoutForwardCachedLine(LayoutWrapper* layoutWra translate = Alignment::GetAlignPosition(blockSize, wrapper->GetGeometryNode()->GetMarginFrameSize(), align); wrapper->GetGeometryNode()->SetMarginFrameOffset(offset + translate); - wrapper->Layout(); SyncGeometry(wrapper); wrapper->SetActive(false); } @@ -1643,6 +1652,9 @@ int32_t GridScrollLayoutAlgorithm::MeasureChildPlaced(const SizeF& frameSize, in void GridScrollLayoutAlgorithm::MeasureChild(LayoutWrapper* layoutWrapper, const SizeF& frameSize, const RefPtr& childLayoutWrapper, int32_t crossStart, int32_t crossSpan) { + if (canSkipMeasure_ && !childLayoutWrapper->CheckNeedForceMeasureAndLayout()) { + return; + } auto gridLayoutProperty = DynamicCast(layoutWrapper->GetLayoutProperty()); auto mainSize = GetMainAxisSize(frameSize, gridLayoutInfo_.axis_); auto crossSize = GetCrossAxisSize(frameSize, gridLayoutInfo_.axis_); diff --git a/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.h b/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.h index e68bdef8e3f..dcac69e7c25 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.h @@ -193,6 +193,7 @@ private: float crossPaddingOffset_ = 0; int32_t lastCross_ = 0; bool isChildrenUpdated_ = false; + bool canSkipMeasure_ = false; bool canOverScroll_ = false; bool enableSkipping_ = true; // enables skipping lines on a large offset change. GridLayoutInfo scrollGridLayoutInfo_; diff --git a/frameworks/core/components_ng/pattern/list/list_lanes_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/list/list_lanes_layout_algorithm.cpp index bc24d05b7a9..0d4355360ba 100644 --- a/frameworks/core/components_ng/pattern/list/list_lanes_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/list/list_lanes_layout_algorithm.cpp @@ -102,7 +102,7 @@ int32_t ListLanesLayoutAlgorithm::LayoutALineForward(LayoutWrapper* layoutWrappe auto listLayoutProperty = AceType::DynamicCast(layoutWrapper->GetLayoutProperty()); SetListItemGroupParam(wrapper, currentIndex, startPos, true, listLayoutProperty, false); wrapper->Measure(groupLayoutConstraint_); - } else { + } else if (constraintChanged_ || wrapper->CheckNeedForceMeasureAndLayout()) { if (wrapper->GetHostNode()) { ACE_SCOPED_TRACE("[MeasureListForwardItem:%d][self:%d][parent:%d]", currentIndex, wrapper->GetHostNode()->GetId(), wrapper->GetHostNode()->GetParent() ? @@ -162,7 +162,7 @@ int32_t ListLanesLayoutAlgorithm::LayoutALineBackward(LayoutWrapper* layoutWrapp auto listLayoutProperty = AceType::DynamicCast(layoutWrapper->GetLayoutProperty()); SetListItemGroupParam(wrapper, currentIndex, endPos, false, listLayoutProperty, false); wrapper->Measure(groupLayoutConstraint_); - } else { + } else if (constraintChanged_ || wrapper->CheckNeedForceMeasureAndLayout()) { if (wrapper->GetHostNode()) { ACE_SCOPED_TRACE("[MeasureListBackwardItem:%d][self:%d][parent:%d]", currentIndex, wrapper->GetHostNode()->GetId(), wrapper->GetHostNode()->GetParent() ? @@ -410,15 +410,16 @@ std::list ListLanesLayoutAlgorithm::LayoutCachedALineForward(LayoutWrap if (cnt > 0) { auto endPos = startPos + mainLen; for (int32_t i = 0; i < cnt; i++) { - posMap[index + i] = { startPos, endPos, isGroup }; + posMap[index + i] = { 0, startPos, endPos, isGroup }; } startPos = endPos + GetSpaceWidth(); auto startIndex = index; - for (const auto& pos: posMap) { + for (auto& pos: posMap) { auto wrapper = layoutWrapper->GetChildByIndex(pos.first); if (!wrapper) { break; } + pos.second.id = wrapper->GetHostNode()->GetId(); LayoutItem(wrapper, pos.first, pos.second, startIndex, crossSize); SyncGeometry(wrapper); wrapper->SetActive(false); @@ -459,15 +460,16 @@ std::list ListLanesLayoutAlgorithm::LayoutCachedALineBackward(LayoutWra if (cnt > 0) { auto startPos = endPos - mainLen; for (int32_t i = 0; i < cnt; i++) { - posMap[index - i] = { startPos, endPos, isGroup }; + posMap[index - i] = { 0, startPos, endPos, isGroup }; } endPos = startPos - GetSpaceWidth(); auto startIndex = index - cnt + 1; - for (const auto& pos: posMap) { + for (auto& pos: posMap) { auto wrapper = layoutWrapper->GetChildByIndex(pos.first); if (!wrapper) { break; } + pos.second.id = wrapper->GetHostNode()->GetId(); LayoutItem(wrapper, pos.first, pos.second, startIndex, crossSize); SyncGeometry(wrapper); wrapper->SetActive(false); diff --git a/frameworks/core/components_ng/pattern/list/list_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/list/list_layout_algorithm.cpp index aee07670b80..4d57edebf7f 100644 --- a/frameworks/core/components_ng/pattern/list/list_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/list/list_layout_algorithm.cpp @@ -134,10 +134,16 @@ void ListLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) listItemAlign_ = listLayoutProperty->GetListItemAlign().value_or(V2::ListItemAlign::START); // calculate child layout constraint. UpdateListItemConstraint(axis_, contentIdealSize, childLayoutConstraint_); + constraintChanged_ = IsConstraintChanged(layoutWrapper); MeasureList(layoutWrapper); } else { itemPosition_.clear(); - layoutWrapper->RemoveAllChildInRenderTree(); + } + + if (itemPosition_.empty()) { + layoutWrapper->SetActiveChildRange(-1, -1); + } else { + layoutWrapper->SetActiveChildRange(itemPosition_.begin()->first, itemPosition_.rbegin()->first); } auto crossSize = contentIdealSize.CrossSize(axis_); @@ -163,6 +169,15 @@ void ListLayoutAlgorithm::SetCacheCount(LayoutWrapper* layoutWrapper, int32_t ca layoutWrapper->SetCacheCount(cacheCount); } +bool ListLayoutAlgorithm::IsConstraintChanged(LayoutWrapper* layoutWrapper) const +{ + auto host = layoutWrapper->GetHostNode(); + CHECK_NULL_RETURN(host, false); + auto pattern = host->GetPattern(); + CHECK_NULL_RETURN(pattern, false); + return pattern->GetLayoutConstraint() != childLayoutConstraint_; +} + float ListLayoutAlgorithm::GetChildMaxCrossSize(LayoutWrapper* layoutWrapper, Axis axis) const { if (GetItemPosition().empty()) { @@ -210,7 +225,6 @@ void ListLayoutAlgorithm::ClearAllItemPosition(LayoutWrapper* layoutWrapper) groupAlgorithm->ClearItemPosition(&(*wrapper)); } itemPosition_.clear(); - layoutWrapper->RemoveAllChildInRenderTree(); } void ListLayoutAlgorithm::BeginLayoutForward(float startPos, LayoutWrapper* layoutWrapper) @@ -699,7 +713,6 @@ void ListLayoutAlgorithm::MeasureList(LayoutWrapper* layoutWrapper) } OffScreenLayoutDirection(); itemPosition_.clear(); - layoutWrapper->RemoveAllChildInRenderTree(); } if (jumpIndex_ && scrollAlign_ == ScrollAlign::AUTO && NoNeedJump(layoutWrapper, startPos, endPos, startIndex, endIndex, jumpIndex, jumpIndexStartPos)) { @@ -788,9 +801,10 @@ int32_t ListLayoutAlgorithm::LayoutALineForward(LayoutWrapper* layoutWrapper, bool isGroup = wrapper->GetHostTag() == V2::LIST_ITEM_GROUP_ETS_TAG; if (isGroup) { auto listLayoutProperty = AceType::DynamicCast(layoutWrapper->GetLayoutProperty()); + ACE_SCOPED_TRACE("ListLayoutAlgorithm::MeasureListItemGroup:%d", currentIndex); SetListItemGroupParam(wrapper, currentIndex, startPos, true, listLayoutProperty, false); - } - { + wrapper->Measure(childLayoutConstraint_); + } else if (constraintChanged_ || wrapper->CheckNeedForceMeasureAndLayout()) { ACE_SCOPED_TRACE("ListLayoutAlgorithm::MeasureListItem:%d", currentIndex); wrapper->Measure(childLayoutConstraint_); } @@ -815,8 +829,9 @@ int32_t ListLayoutAlgorithm::LayoutALineBackward(LayoutWrapper* layoutWrapper, if (isGroup) { auto listLayoutProperty = AceType::DynamicCast(layoutWrapper->GetLayoutProperty()); SetListItemGroupParam(wrapper, currentIndex, endPos, false, listLayoutProperty, false); - } - { + ACE_SCOPED_TRACE("ListLayoutAlgorithm::MeasureListItemGroup:%d", currentIndex); + wrapper->Measure(childLayoutConstraint_); + } else if (constraintChanged_ || wrapper->CheckNeedForceMeasureAndLayout()) { ACE_SCOPED_TRACE("ListLayoutAlgorithm::MeasureListItem:%d", currentIndex); wrapper->Measure(childLayoutConstraint_); } @@ -900,7 +915,6 @@ void ListLayoutAlgorithm::LayoutForward(LayoutWrapper* layoutWrapper, int32_t st } break; } - layoutWrapper->RemoveChildInRenderTree(pos->first); itemPosition_.erase(pos++); } } @@ -971,7 +985,6 @@ void ListLayoutAlgorithm::LayoutBackward(LayoutWrapper* layoutWrapper, int32_t e } break; } - layoutWrapper->RemoveChildInRenderTree(pos->first); removeIndexes.emplace_back(pos->first); } for (const auto& index : removeIndexes) { @@ -1203,7 +1216,11 @@ void ListLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) pos.second.startPos -= currentOffset_; pos.second.endPos -= currentOffset_; LayoutItem(wrapper, pos.first, pos.second, startIndex, crossSize); - wrapper->Layout(); + if (wrapper->CheckNeedForceMeasureAndLayout()) { + wrapper->Layout(); + } else { + SyncGeometry(wrapper); + } } auto cacheCount = listLayoutProperty->GetCachedCountValue(1); if (!itemPosition_.empty() && cacheCount > 0) { @@ -1374,7 +1391,7 @@ void ListLayoutAlgorithm::AdjustPostionForListItemGroup(LayoutWrapper* layoutWra { auto wrapper = layoutWrapper->GetOrCreateChildByIndex(index); CHECK_NULL_VOID(wrapper); - auto algorithmWrapper = wrapper->GetLayoutAlgorithm(); + auto algorithmWrapper = wrapper->GetLayoutAlgorithm(true); CHECK_NULL_VOID(algorithmWrapper); auto itemGroup = AceType::DynamicCast(algorithmWrapper->GetLayoutAlgorithm()); CHECK_NULL_VOID(itemGroup); diff --git a/frameworks/core/components_ng/pattern/list/list_layout_algorithm.h b/frameworks/core/components_ng/pattern/list/list_layout_algorithm.h index 4ad77632e52..f4e56d6e89a 100644 --- a/frameworks/core/components_ng/pattern/list/list_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/list/list_layout_algorithm.h @@ -325,6 +325,11 @@ public: return childLayoutConstraint_; } + const LayoutConstraintF& GetLayoutConstraint() const + { + return childLayoutConstraint_; + } + void OnItemPositionAddOrUpdate(LayoutWrapper* layoutWrapper, uint32_t index); protected: @@ -361,9 +366,11 @@ protected: int32_t& startIndex, float crossSize); static void SyncGeometry(RefPtr& wrapper); ListItemInfo GetListItemGroupPosition(const RefPtr& layoutWrapper, int32_t index); + bool IsConstraintChanged(LayoutWrapper* layoutWrapper) const; Axis axis_ = Axis::VERTICAL; LayoutConstraintF childLayoutConstraint_; + bool constraintChanged_ = true; private: void MeasureList(LayoutWrapper* layoutWrapper); void CheckJumpToIndex(); diff --git a/frameworks/core/components_ng/pattern/list/list_pattern.cpp b/frameworks/core/components_ng/pattern/list/list_pattern.cpp index 1f22e37a9c3..088d52e4410 100644 --- a/frameworks/core/components_ng/pattern/list/list_pattern.cpp +++ b/frameworks/core/components_ng/pattern/list/list_pattern.cpp @@ -197,6 +197,7 @@ bool ListPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, c startMainPos_ = listLayoutAlgorithm->GetStartPosition(); endMainPos_ = listLayoutAlgorithm->GetEndPosition(); crossMatchChild_ = listLayoutAlgorithm->IsCrossMatchChild(); + layoutConstraint_ = listLayoutAlgorithm->GetLayoutConstraint(); bool sizeDiminished = LessNotEqual(endMainPos_ - startMainPos_, contentMainSize_ - contentStartOffset_ - contentEndOffset_) && GreatOrEqual(prevTotalSize, prevContentSize) && LessNotEqual(endMainPos_ - startMainPos_, prevTotalSize); diff --git a/frameworks/core/components_ng/pattern/list/list_pattern.h b/frameworks/core/components_ng/pattern/list/list_pattern.h index 6d524cf73f3..643f8604a99 100644 --- a/frameworks/core/components_ng/pattern/list/list_pattern.h +++ b/frameworks/core/components_ng/pattern/list/list_pattern.h @@ -211,6 +211,10 @@ public: { return predictLayoutParam_; } + const LayoutConstraintF& GetLayoutConstraint() const + { + return layoutConstraint_; + } void CloseAllSwipeActions(OnFinishFunc&&); @@ -346,6 +350,7 @@ private: bool isScrollEnd_ = false; std::optional predictLayoutParam_; + LayoutConstraintF layoutConstraint_; bool isNeedToUpdateListDirection_ = false; diff --git a/frameworks/core/components_ng/render/adapter/rosen_render_context.cpp b/frameworks/core/components_ng/render/adapter/rosen_render_context.cpp index 230a98ff292..5e800440c3a 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_render_context.cpp +++ b/frameworks/core/components_ng/render/adapter/rosen_render_context.cpp @@ -444,7 +444,11 @@ void RosenRenderContext::SyncGeometryProperties(GeometryNode* /*geometryNode*/, auto geometryNode = host->GetGeometryNode(); CHECK_NULL_VOID(geometryNode); auto paintRect = AdjustPaintRect(); - RoundToPixelGrid(isRound, flag); + if (isRound && flag == 0) { + RoundToPixelGrid(); // call RoundToPixelGrid without param to improve performance + } else { + RoundToPixelGrid(isRound, flag); + } paintRect.SetRect(geometryNode->GetPixelGridRoundOffset(), geometryNode->GetPixelGridRoundSize()); SyncGeometryProperties(paintRect); host->OnPixelRoundFinish(geometryNode->GetPixelGridRoundSize()); @@ -2335,6 +2339,11 @@ RectF RosenRenderContext::AdjustPaintRect() return rect; } } + bool hasPosition = HasPosition() && IsUsingPosition(frameNode); + if (!HasAnchor() && !HasOffset() && !hasPosition) { + geometryNode->SetPixelGridRoundOffset(rect.GetOffset()); + return rect; + } const auto& layoutConstraint = frameNode->GetGeometryNode()->GetParentLayoutConstraint(); auto widthPercentReference = layoutConstraint.has_value() ? layoutConstraint->percentReference.Width() : PipelineContext::GetCurrentRootWidth(); @@ -2351,7 +2360,7 @@ RectF RosenRenderContext::AdjustPaintRect() Dimension parentPaddingTop; GetPaddingOfFirstFrameNodeParent(parentPaddingLeft, parentPaddingTop); // Position properties take precedence over offset locations. - if (HasPosition() && IsUsingPosition(frameNode)) { + if (hasPosition) { CombineMarginAndPosition( resultX, resultY, parentPaddingLeft, parentPaddingTop, widthPercentReference, heightPercentReference); rect.SetLeft(resultX.ConvertToPx() - anchorX.value_or(0)); @@ -2378,6 +2387,21 @@ RectF RosenRenderContext::AdjustPaintRect() return rect; } +float RosenRenderContext::RoundValueToPixelGrid(float value) +{ + float fractials = fmod(value, 1.0f); + if (fractials < 0.0f) { + ++fractials; + } + if (NearEqual(fractials, 1.0f) || GreatOrEqual(fractials, 0.75f)) { + return (value - fractials + 1.0f); + } else if (NearEqual(fractials, 0.0f) || !GreatOrEqual(fractials, 0.25f)) { + return (value - fractials); + } else { + return (value - fractials + 0.5f); + } +} + float RosenRenderContext::RoundValueToPixelGrid(float value, bool isRound, bool forceCeil, bool forceFloor) { float fractials = fmod(value, 1.0f); @@ -2400,6 +2424,46 @@ float RosenRenderContext::RoundValueToPixelGrid(float value, bool isRound, bool return value; } +void RosenRenderContext::RoundToPixelGrid() +{ + auto frameNode = GetHost(); + CHECK_NULL_VOID(frameNode); + auto geometryNode = frameNode->GetGeometryNode(); + float relativeLeft = geometryNode->GetPixelGridRoundOffset().GetX(); + float relativeTop = geometryNode->GetPixelGridRoundOffset().GetY(); + float nodeWidth = geometryNode->GetFrameSize().Width(); + float nodeHeight = geometryNode->GetFrameSize().Height(); + float absoluteRight = relativeLeft + nodeWidth; + float absoluteBottom = relativeTop + nodeHeight; + // round node + float nodeLeftI = RoundValueToPixelGrid(relativeLeft); + float nodeTopI = RoundValueToPixelGrid(relativeTop); + geometryNode->SetPixelGridRoundOffset(OffsetF(nodeLeftI, nodeTopI)); + float nodeWidthI = RoundValueToPixelGrid(absoluteRight) - nodeLeftI; + float nodeHeightI = RoundValueToPixelGrid(absoluteBottom) - nodeTopI; + geometryNode->SetPixelGridRoundSize(SizeF(nodeWidthI, nodeHeightI)); + if (borderWidth_ != Rosen::Vector4f(0.0f, 0.0f, 0.0f, 0.0f)) { + // round inner + float innerLeft = relativeLeft + borderWidth_[0]; + float innerRight = relativeLeft + nodeWidth - borderWidth_[2]; + float innerTop = relativeTop + borderWidth_[1]; + float innerBottom = relativeTop + nodeHeight - borderWidth_[3]; + float innerWidthI = RoundValueToPixelGrid(innerRight) - RoundValueToPixelGrid(innerLeft); + float innerHeightI = RoundValueToPixelGrid(innerBottom) - RoundValueToPixelGrid(innerTop); + // update border + float borderLeftI = RoundValueToPixelGrid(borderWidth_[0]); + float borderTopI = RoundValueToPixelGrid(borderWidth_[1]); + float borderRightI = nodeWidthI - innerWidthI - borderLeftI; + float borderBottomI = nodeHeightI - innerHeightI - borderTopI; + BorderWidthPropertyF borderWidthPropertyF; + borderWidthPropertyF.leftDimen = borderLeftI; + borderWidthPropertyF.topDimen = borderTopI; + borderWidthPropertyF.rightDimen = borderRightI; + borderWidthPropertyF.bottomDimen = borderBottomI; + UpdateBorderWidthF(borderWidthPropertyF); + } +} + void RosenRenderContext::RoundToPixelGrid(bool isRound, uint8_t flag) { CHECK_NULL_VOID(rsNode_); @@ -2424,31 +2488,31 @@ void RosenRenderContext::RoundToPixelGrid(bool isRound, uint8_t flag) float nodeLeftI = RoundValueToPixelGrid(relativeLeft, isRound, ceilLeft, floorLeft); float nodeTopI = RoundValueToPixelGrid(relativeTop, isRound, ceilTop, floorTop); geometryNode->SetPixelGridRoundOffset(OffsetF(nodeLeftI, nodeTopI)); - float nodeWidthI = RoundValueToPixelGrid(absoluteRight, isRound, ceilRight, floorRight) - - RoundValueToPixelGrid(relativeLeft, isRound, ceilLeft, floorLeft); - float nodeHeightI = RoundValueToPixelGrid(absoluteBottom, isRound, ceilBottom, floorBottom) - - RoundValueToPixelGrid(relativeTop, isRound, ceilTop, floorTop); + float nodeWidthI = RoundValueToPixelGrid(absoluteRight, isRound, ceilRight, floorRight) - nodeLeftI; + float nodeHeightI = RoundValueToPixelGrid(absoluteBottom, isRound, ceilBottom, floorBottom) - nodeTopI; geometryNode->SetPixelGridRoundSize(SizeF(nodeWidthI, nodeHeightI)); - // round inner - float innerLeft = relativeLeft + borderWidth_[0]; - float innerRight = relativeLeft + nodeWidth - borderWidth_[2]; - float innerTop = relativeTop + borderWidth_[1]; - float innerBottom = relativeTop + nodeHeight - borderWidth_[3]; - float innerWidthI = RoundValueToPixelGrid(innerRight, isRound, ceilRight, floorRight) - - RoundValueToPixelGrid(innerLeft, isRound, ceilLeft, floorLeft); - float innerHeightI = RoundValueToPixelGrid(innerBottom, isRound, ceilBottom, floorBottom) - - RoundValueToPixelGrid(innerTop, isRound, ceilTop, floorTop); - // update border - float borderLeftI = RoundValueToPixelGrid(borderWidth_[0], isRound, ceilLeft, floorLeft); - float borderTopI = RoundValueToPixelGrid(borderWidth_[1], isRound, ceilTop, floorTop); - float borderRightI = nodeWidthI - innerWidthI - borderLeftI; - float borderBottomI = nodeHeightI - innerHeightI - borderTopI; - BorderWidthPropertyF borderWidthPropertyF; - borderWidthPropertyF.leftDimen = borderLeftI; - borderWidthPropertyF.topDimen = borderTopI; - borderWidthPropertyF.rightDimen = borderRightI; - borderWidthPropertyF.bottomDimen = borderBottomI; - UpdateBorderWidthF(borderWidthPropertyF); + if (borderWidth_ != Rosen::Vector4f(0.0f, 0.0f, 0.0f, 0.0f)) { + // round inner + float innerLeft = relativeLeft + borderWidth_[0]; + float innerRight = relativeLeft + nodeWidth - borderWidth_[2]; + float innerTop = relativeTop + borderWidth_[1]; + float innerBottom = relativeTop + nodeHeight - borderWidth_[3]; + float innerWidthI = RoundValueToPixelGrid(innerRight, isRound, ceilRight, floorRight) - + RoundValueToPixelGrid(innerLeft, isRound, ceilLeft, floorLeft); + float innerHeightI = RoundValueToPixelGrid(innerBottom, isRound, ceilBottom, floorBottom) - + RoundValueToPixelGrid(innerTop, isRound, ceilTop, floorTop); + // update border + float borderLeftI = RoundValueToPixelGrid(borderWidth_[0], isRound, ceilLeft, floorLeft); + float borderTopI = RoundValueToPixelGrid(borderWidth_[1], isRound, ceilTop, floorTop); + float borderRightI = nodeWidthI - innerWidthI - borderLeftI; + float borderBottomI = nodeHeightI - innerHeightI - borderTopI; + BorderWidthPropertyF borderWidthPropertyF; + borderWidthPropertyF.leftDimen = borderLeftI; + borderWidthPropertyF.topDimen = borderTopI; + borderWidthPropertyF.rightDimen = borderRightI; + borderWidthPropertyF.bottomDimen = borderBottomI; + UpdateBorderWidthF(borderWidthPropertyF); + } } void RosenRenderContext::CombineMarginAndPosition(Dimension& resultX, Dimension& resultY, diff --git a/frameworks/core/components_ng/render/adapter/rosen_render_context.h b/frameworks/core/components_ng/render/adapter/rosen_render_context.h index eac65fb092f..f9b21350afc 100755 --- a/frameworks/core/components_ng/render/adapter/rosen_render_context.h +++ b/frameworks/core/components_ng/render/adapter/rosen_render_context.h @@ -518,7 +518,9 @@ private: void SetContentRectToFrame(RectF rect) override; + float RoundValueToPixelGrid(float value); float RoundValueToPixelGrid(float value, bool isRound, bool forceCeil, bool forceFloor); + void RoundToPixelGrid(); void RoundToPixelGrid(bool isRound, uint8_t flag); Matrix4 GetRevertMatrix(); Matrix4 GetMatrix(); diff --git a/frameworks/core/pipeline_ng/ui_task_scheduler.cpp b/frameworks/core/pipeline_ng/ui_task_scheduler.cpp index 53918e3f007..00ae2576933 100644 --- a/frameworks/core/pipeline_ng/ui_task_scheduler.cpp +++ b/frameworks/core/pipeline_ng/ui_task_scheduler.cpp @@ -135,6 +135,7 @@ void UITaskScheduler::FlushLayoutTask(bool forceUseMainThread) continue; } time = GetSysTimestamp(); + frameId_++; node->CreateLayoutTask(forceUseMainThread); time = GetSysTimestamp() - time; if (frameInfo_ != nullptr) { -- Gitee