diff --git a/shell/common/animator.cc b/shell/common/animator.cc index a0704c7b8d26f09bd45098b246f4ae9255ade2c4..a464af48b58597ff6fdfa66d7872b9b3feb4904a 100644 --- a/shell/common/animator.cc +++ b/shell/common/animator.cc @@ -90,6 +90,7 @@ void Animator::BeginFrame( // full because the consumer is being too slow. Try again at the next // frame interval. TRACE_EVENT0("flutter", "PipelineFull"); + waiter_->DisableDVsync(); RequestFrame(); return; } @@ -124,6 +125,7 @@ void Animator::BeginFrame( TRACE_EVENT0("flutter", "BeginFrame idle callback"); self->delegate_.OnAnimatorNotifyIdle( now + fml::TimeDelta::FromMilliseconds(100)); + self->waiter_->DisableDVsync(); } }, kNotifyIdleTaskWaitTime); diff --git a/shell/common/vsync_waiter.h b/shell/common/vsync_waiter.h index cfce4524df4d7a59c90ff8a1fb3ce459b61ca9c9..423136ceba8dff6e257951be121148b6f9b48cb4 100644 --- a/shell/common/vsync_waiter.h +++ b/shell/common/vsync_waiter.h @@ -32,6 +32,8 @@ class VsyncWaiter : public std::enable_shared_from_this { /// |Animator::ScheduleMaybeClearTraceFlowIds|. void ScheduleSecondaryCallback(uintptr_t id, const fml::closure& callback); + // disable dvsync + virtual void DisableDVsync() {} protected: // On some backends, the |FireCallback| needs to be made from a static C // method. diff --git a/shell/platform/ohos/ohos_shell_holder.h b/shell/platform/ohos/ohos_shell_holder.h index 4a87730862c4ded233a6f08ace2154ae3eba29cb..286249e1e0e82138ed63808f2c590d9d2620f703 100644 --- a/shell/platform/ohos/ohos_shell_holder.h +++ b/shell/platform/ohos/ohos_shell_holder.h @@ -68,6 +68,10 @@ class OHOSShellHolder { return shell_->GetPlatformMessageHandler(); } + const std::weak_ptr GetVsyncWaiter() const { + return shell_->GetVsyncWaiter(); + } + private: std::optional BuildRunConfiguration( const std::string& entrypoint, diff --git a/shell/platform/ohos/ohos_touch_processor.cpp b/shell/platform/ohos/ohos_touch_processor.cpp index 4849075ba095c396720b2a04fbf3d9a7e644978d..8c129f404c1881969fe679b66e763b5cf81afdf0 100644 --- a/shell/platform/ohos/ohos_touch_processor.cpp +++ b/shell/platform/ohos/ohos_touch_processor.cpp @@ -12,13 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include "flutter/shell/platform/ohos/ohos_touch_processor.h" #include "flutter/lib/ui/window/pointer_data_packet.h" #include "flutter/shell/platform/ohos/ohos_shell_holder.h" -namespace flutter { +#include "flutter/fml/logging.h" + +namespace flutter { constexpr int MSEC_PER_SECOND = 1000; constexpr int PER_POINTER_MEMBER = 10; constexpr int CHANGES_POINTER_MEMBER = 10; @@ -143,6 +144,17 @@ void OhosTouchProcessor::HandleTouchEvent( int64_t shell_holderID, OH_NativeXComponent* component, OH_NativeXComponent_TouchEvent* touchEvent) { + auto ohos_shell_holder = reinterpret_cast(shell_holderID); + + auto vsync_waiter = std::shared_ptr(ohos_shell_holder->GetVsyncWaiter().lock()); + auto vsync_waiter_ohos = std::static_pointer_cast(vsync_waiter); + if (vsync_waiter_ohos->dvsyncCounter > 0) { + --(vsync_waiter_ohos->dvsyncCounter); + } + int aa = vsync_waiter_ohos->dvsyncCounter; + TRACE_EVENT0("flutterVsyncCounter", std::to_string(aa).c_str()); + TRACE_EVENT0("flutter", "OhosTouchProcessor::HandleTouchEvent"); + if (touchEvent == nullptr) { return; } @@ -188,7 +200,6 @@ void OhosTouchProcessor::HandleTouchEvent( pointerData.scale = 1.0; pointerData.rotation = 0.0; packet->SetPointerData(0, pointerData); - auto ohos_shell_holder = reinterpret_cast(shell_holderID); ohos_shell_holder->GetPlatformView()->DispatchPointerDataPacket( std::move(packet)); @@ -260,4 +271,4 @@ void OhosTouchProcessor::HandleMouseEvent( ohos_shell_holder->GetPlatformView()->DispatchPointerDataPacket(std::move(packet)); return; } -} // namespace flutter \ No newline at end of file +} // namespace flutter diff --git a/shell/platform/ohos/vsync_waiter_ohos.cpp b/shell/platform/ohos/vsync_waiter_ohos.cpp index 1330506a8a08223fee39ccb5f4b86da21e49a99c..1222f5e1d40191a49a113c706044b76fde39b071 100644 --- a/shell/platform/ohos/vsync_waiter_ohos.cpp +++ b/shell/platform/ohos/vsync_waiter_ohos.cpp @@ -19,7 +19,6 @@ #include namespace flutter { - static std::atomic_uint g_refresh_rate_ = 60; const char* flutterSyncName = "flutter_connect"; @@ -45,7 +44,19 @@ void VsyncWaiterOHOS::AwaitVSync() { } auto* weak_this = new std::weak_ptr(shared_from_this()); OH_NativeVSync* handle = vsyncHandle; - + if (dvsyncCounter < 1) { + ++dvsyncCounter; + if (dvsyncStatus == true) { + dvsyncStatus = false; + OH_NativeVSync_DVSyncSwitch(vsyncHandle, false, 0); + } + } else if (dvsyncStatus == false) { + dvsyncStatus = true; + OH_NativeVSync_DVSyncSwitch(vsyncHandle, true, 0); + } + int aa = dvsyncCounter; + TRACE_EVENT0("flutterVsyncCounter", std::to_string(aa).c_str()); + TRACE_EVENT0("flutterDvsyncStatus", std::to_string(dvsyncStatus).c_str()); fml::TaskRunner::RunNowOrPostTask( task_runners_.GetUITaskRunner(), [weak_this, handle]() { int32_t ret = 0; @@ -96,4 +107,15 @@ void VsyncWaiterOHOS::OnUpdateRefreshRate(long long refresh_rate) { g_refresh_rate_ = static_cast(refresh_rate); } +void VsyncWaiterOHOS::DisableDVsync() { + dvsyncCounter = 0; + if (dvsyncStatus == true) { + dvsyncStatus = false; + OH_NativeVSync_DVSyncSwitch(vsyncHandle, false, 0); + } + + int aa = dvsyncCounter; + TRACE_EVENT0("flutterVsyncCounter", std::to_string(aa).c_str()); + TRACE_EVENT0("flutterDvsyncStatus", std::to_string(dvsyncStatus).c_str()); +} } // namespace flutter diff --git a/shell/platform/ohos/vsync_waiter_ohos.h b/shell/platform/ohos/vsync_waiter_ohos.h index e9aac66c852b888b7495c27d0843fe777e3af169..a878c8975aa268dbc7a5fcc59e7f8b1949cd83cf 100644 --- a/shell/platform/ohos/vsync_waiter_ohos.h +++ b/shell/platform/ohos/vsync_waiter_ohos.h @@ -16,6 +16,7 @@ #ifndef VSYNC_WAITER_OHOS_H #define VSYNC_WAITER_OHOS_H #include +#include #include #include "flutter/fml/macros.h" @@ -30,6 +31,11 @@ class VsyncWaiterOHOS final : public VsyncWaiter { ~VsyncWaiterOHOS() override; + std::atomic dvsyncCounter{0}; + bool dvsyncStatus = false; + + void DisableDVsync() override; + private: thread_local static bool firstCall; // |VsyncWaiter|