diff --git a/adapter/ohos/entrance/flutter_ace_view.cpp b/adapter/ohos/entrance/flutter_ace_view.cpp index 6f48f442a0a629aba2b7215f6c23cd5e494c515e..bf205a7f4e9998df7bb4f8425efc5e90a3090725 100644 --- a/adapter/ohos/entrance/flutter_ace_view.cpp +++ b/adapter/ohos/entrance/flutter_ace_view.cpp @@ -282,7 +282,7 @@ void LogPointInfo(const std::shared_ptr& pointerEvent) } // namespace -FlutterAceView* FlutterAceView::CreateView(int32_t instanceId, bool useCurrentEventRunner, bool usePlatfromThread) +FlutterAceView* FlutterAceView::CreateView(int32_t instanceId, bool useCurrentEventRunner, bool usePlatformThread) { FlutterAceView* aceSurface = new Platform::FlutterAceView(instanceId); flutter::Settings settings; @@ -293,7 +293,7 @@ FlutterAceView* FlutterAceView::CreateView(int32_t instanceId, bool useCurrentEv #else settings.enable_software_rendering = true; #endif - settings.platform_as_ui_thread = usePlatfromThread; + settings.platform_as_ui_thread = usePlatformThread; settings.use_current_event_runner = useCurrentEventRunner; LOGI("software render: %{public}s", settings.enable_software_rendering ? "true" : "false"); LOGI("use platform as ui thread: %{public}s", settings.platform_as_ui_thread ? "true" : "false"); diff --git a/adapter/ohos/entrance/flutter_ace_view.h b/adapter/ohos/entrance/flutter_ace_view.h index 16f457f04c554792fea45860184f835364ae3d59..4ed31be57008dff511ac08baa30d4a5541c5ccbf 100755 --- a/adapter/ohos/entrance/flutter_ace_view.h +++ b/adapter/ohos/entrance/flutter_ace_view.h @@ -39,7 +39,7 @@ public: explicit FlutterAceView(int32_t id) : instanceId_(id) {} ~FlutterAceView() override = default; static FlutterAceView* CreateView( - int32_t instanceId, bool useCurrentEventRunner = false, bool usePlatfromThread = false); + int32_t instanceId, bool useCurrentEventRunner = false, bool usePlatformThread = false); static void SurfaceCreated(FlutterAceView* view, OHOS::sptr window); static void SurfaceChanged(FlutterAceView* view, int32_t width, int32_t height, int32_t orientation, WindowSizeChangeReason type = WindowSizeChangeReason::UNDEFINED); diff --git a/frameworks/core/components/scroll/render_multi_child_scroll.cpp b/frameworks/core/components/scroll/render_multi_child_scroll.cpp index d778ab9fb4d51585b5c13d9ff8f8f9d4b8eb7aa6..1783487201192540b16a9fcfc5111a3903c3795e 100644 --- a/frameworks/core/components/scroll/render_multi_child_scroll.cpp +++ b/frameworks/core/components/scroll/render_multi_child_scroll.cpp @@ -343,7 +343,7 @@ bool RenderMultiChildScroll::ReachMaxCount() const return reached; } -void RenderMultiChildScroll::OnPredictLayout(int64_t targetTimestamp) +void RenderMultiChildScroll::OnPredictLayout(int64_t deadline) { int32_t childrenSize = GetChildren().size(); if (currentIndex_ < 0 || currentIndex_ >= childrenSize || childrenSize == 0) { diff --git a/frameworks/core/components/scroll/render_multi_child_scroll.h b/frameworks/core/components/scroll/render_multi_child_scroll.h index 70fb16a759bcea95f44292decffdffb80f703987..242839fc5a4ffd00ca0d42fde8f46699a0e9559d 100644 --- a/frameworks/core/components/scroll/render_multi_child_scroll.h +++ b/frameworks/core/components/scroll/render_multi_child_scroll.h @@ -95,7 +95,7 @@ public: } protected: - void OnPredictLayout(int64_t targetTimestamp) override; + void OnPredictLayout(int64_t deadline) override; void PerformLayout() override; void Update(const RefPtr& component) override; bool ReachMaxCount() const override; diff --git a/frameworks/core/components_v2/grid/render_grid_scroll.cpp b/frameworks/core/components_v2/grid/render_grid_scroll.cpp index 4b873b95299150a0eb380a5c95e0e09d3f1b9d96..3fa38eace1b0f2ac25a226ec26fdcf70af6a1cd8 100644 --- a/frameworks/core/components_v2/grid/render_grid_scroll.cpp +++ b/frameworks/core/components_v2/grid/render_grid_scroll.cpp @@ -33,7 +33,8 @@ namespace { const char UNIT_PERCENT[] = "%"; const char UNIT_RATIO[] = "fr"; -constexpr int32_t TIMETHRESHOLD = 2 * 1000000; // microsecond +constexpr int32_t TIMETHRESHOLD = 3 * 1000000; // 3 millisecond +constexpr int32_t MICROSEC_TO_NANOSEC = 1000; } // namespace @@ -832,8 +833,8 @@ void RenderGridScroll::PerformLayout() if (item != items_.end()) { childrenInRect_.push_back(item->second); int32_t itemMainSpan = GetItemSpan(item->second, useScrollable_ != SCROLLABLE::HORIZONTAL); - int32_t itemCrosspan = GetItemSpan(item->second, useScrollable_ == SCROLLABLE::HORIZONTAL); - SetChildPosition(item->second, main, cross, itemMainSpan, itemCrosspan); + int32_t itemCrossSpan = GetItemSpan(item->second, useScrollable_ == SCROLLABLE::HORIZONTAL); + SetChildPosition(item->second, main, cross, itemMainSpan, itemCrossSpan); } } } @@ -1016,7 +1017,7 @@ void RenderGridScroll::OnDataSourceUpdated(int32_t index) } ACE_SCOPED_TRACE("OnDataSourceUpdated %d", index); auto items = gridMatrix_.find(startIndex_); - if (items != gridMatrix_.end() && items->second.size() > 0) { + if (items != gridMatrix_.end() && !items->second.empty()) { currentItemIndex_ = items->second.begin()->second; } startRankItemIndex_ = GetStartingItem(currentItemIndex_); @@ -1404,8 +1405,9 @@ void RenderGridScroll::OnPaintFinish() } } -void RenderGridScroll::OnPredictLayout(int64_t targetTimestamp) +void RenderGridScroll::OnPredictLayout(int64_t deadline) { + auto startTime = GetSysTimestamp(); // unit: ns auto context = context_.Upgrade(); if (!context) { return; @@ -1434,7 +1436,8 @@ void RenderGridScroll::OnPredictLayout(int64_t targetTimestamp) break; } } - if (GetSysTimestamp() + TIMETHRESHOLD > targetTimestamp) { + // Stop predictLayout less than 3 milliseconds before the next vsync arrives. + if (GetSysTimestamp() - startTime + TIMETHRESHOLD > deadline * MICROSEC_TO_NANOSEC) { MarkNeedPredictLayout(); return; } diff --git a/frameworks/core/components_v2/grid/render_grid_scroll.h b/frameworks/core/components_v2/grid/render_grid_scroll.h index e0375c31e0fb71316ac5dbb580f8ccec2d79e07f..ac0c02d8d4820849deec5be94d7cca95b13bdae7 100644 --- a/frameworks/core/components_v2/grid/render_grid_scroll.h +++ b/frameworks/core/components_v2/grid/render_grid_scroll.h @@ -67,7 +67,7 @@ public: void Update(const RefPtr& component) override; void PerformLayout() override; - void OnPredictLayout(int64_t targetTimestamp) override; + void OnPredictLayout(int64_t deadline) override; const std::list>& GetChildren() const override { diff --git a/frameworks/core/pipeline/base/render_node.h b/frameworks/core/pipeline/base/render_node.h index 595b390c03f79e9f64c9b21cd19805a301eb3fc8..b41258df68b33bad756528ad5596051b5bdb0b7d 100644 --- a/frameworks/core/pipeline/base/render_node.h +++ b/frameworks/core/pipeline/base/render_node.h @@ -159,7 +159,8 @@ public: void OnLayout(); - virtual void OnPredictLayout(int64_t targetTimestamp) {} + // deadline : The remaining time until the next vsync. (unit: microsecond) + virtual void OnPredictLayout(int64_t deadline) {} virtual Size GetChildViewPort() { diff --git a/frameworks/core/pipeline/pipeline_context.cpp b/frameworks/core/pipeline/pipeline_context.cpp index 6e39d6eeebdf3ae61937f9dab17f3bf41e489a96..08fe6ffd7f16856ba3613235424234f1cdfe47a8 100644 --- a/frameworks/core/pipeline/pipeline_context.cpp +++ b/frameworks/core/pipeline/pipeline_context.cpp @@ -255,7 +255,7 @@ void PipelineContext::FlushBuild() } } -void PipelineContext::FlushPredictLayout(int64_t targetTimestamp) +void PipelineContext::FlushPredictLayout(int64_t deadline) { CHECK_RUN_ON(UI); if (predictLayoutNodes_.empty()) { @@ -264,7 +264,7 @@ void PipelineContext::FlushPredictLayout(int64_t targetTimestamp) ACE_FUNCTION_TRACE(); decltype(predictLayoutNodes_) dirtyNodes(std::move(predictLayoutNodes_)); for (const auto& dirtyNode : dirtyNodes) { - dirtyNode->OnPredictLayout(targetTimestamp); + dirtyNode->OnPredictLayout(deadline); } } diff --git a/frameworks/core/pipeline/pipeline_context.h b/frameworks/core/pipeline/pipeline_context.h index dc0ed721a7d2865d7d421fb69bbac15381905876..a3d14f6125719a70e0cec1f01f19956fe7c203da 100644 --- a/frameworks/core/pipeline/pipeline_context.h +++ b/frameworks/core/pipeline/pipeline_context.h @@ -1222,7 +1222,7 @@ private: void FlushMessages(); void FlushRenderFinish(); void FireVisibleChangeEvent(); - void FlushPredictLayout(int64_t targetTimestamp); + void FlushPredictLayout(int64_t deadline); void FlushAnimation(uint64_t nanoTimestamp); void FlushPostAnimation(); void FlushPageUpdateTasks();