From efdffb0aea757cc2b8a3df408b56b4d2b7766b00 Mon Sep 17 00:00:00 2001 From: keminLuo Date: Mon, 13 Jan 2025 10:12:27 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E7=8E=87=E8=8E=B7=E5=8F=96=E9=94=99=E8=AF=AF=EF=BC=8C=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E8=AE=A1=E7=AE=97=E5=8D=95=E5=B8=A7=E4=B8=A2=E5=B8=A7?= =?UTF-8?q?=E6=95=B0=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: keminLuo --- shell/platform/ohos/ohos_display.cpp | 9 +++++--- shell/platform/ohos/ohos_display.h | 5 ++-- shell/platform/ohos/ohos_shell_holder.cpp | 26 ++++++++++----------- shell/platform/ohos/vsync_waiter_ohos.cpp | 5 ++++ shell/platform/ohos/vsync_waiter_ohos.h | 28 ++++++++++++----------- 5 files changed, 42 insertions(+), 31 deletions(-) diff --git a/shell/platform/ohos/ohos_display.cpp b/shell/platform/ohos/ohos_display.cpp index 3f23e95b00..2b9b823df5 100644 --- a/shell/platform/ohos/ohos_display.cpp +++ b/shell/platform/ohos/ohos_display.cpp @@ -19,11 +19,14 @@ namespace flutter { const double defaultFPS = 60; -OHOSDisplay::OHOSDisplay(std::shared_ptr napi_facade) - : Display(defaultFPS), napi_facade_(std::move(napi_facade)) {} +OHOSDisplay::OHOSDisplay(std::shared_ptr vsync_waiter_ohos) + : Display(defaultFPS), vsync_waiter_ohos_(std::move(vsync_waiter_ohos)) {} double OHOSDisplay::GetRefreshRate() const { - return defaultFPS; + if (vsync_waiter_ohos_ != nullptr) { + return (double)vsync_waiter_ohos_->GetRefreshRate(); + } + return defaultFPS; } } // namespace flutter \ No newline at end of file diff --git a/shell/platform/ohos/ohos_display.h b/shell/platform/ohos/ohos_display.h index 873f2cff90..4bf5600e13 100644 --- a/shell/platform/ohos/ohos_display.h +++ b/shell/platform/ohos/ohos_display.h @@ -21,17 +21,18 @@ #include "flutter/fml/macros.h" #include "flutter/shell/common/display.h" #include "flutter/shell/platform/ohos/napi/platform_view_ohos_napi.h" +#include "flutter/shell/platform/ohos/vsync_waiter_ohos.h" namespace flutter { class OHOSDisplay : public Display { public: - explicit OHOSDisplay(std::shared_ptr napi_facade_); + explicit OHOSDisplay(std::shared_ptr vsync_waiter_ohos); ~OHOSDisplay() = default; double GetRefreshRate() const override; private: - std::shared_ptr napi_facade_; + std::shared_ptr vsync_waiter_ohos_; FML_DISALLOW_COPY_AND_ASSIGN(OHOSDisplay); }; } // namespace flutter diff --git a/shell/platform/ohos/ohos_shell_holder.cpp b/shell/platform/ohos/ohos_shell_holder.cpp index 2cb763fc04..0b048365d1 100644 --- a/shell/platform/ohos/ohos_shell_holder.cpp +++ b/shell/platform/ohos/ohos_shell_holder.cpp @@ -94,7 +94,7 @@ OHOSShellHolder::OHOSShellHolder( Shell::CreateCallback on_create_platform_view = [&napi_facade, &weak_platform_view](Shell& shell) { - FML_DLOG(INFO) << "on_create_platform_view"; + FML_LOG(INFO) << "on_create_platform_view"; std::unique_ptr platform_view_OHOS; platform_view_OHOS = std::make_unique( shell, // delegate @@ -104,19 +104,12 @@ OHOSShellHolder::OHOSShellHolder( .enable_software_rendering, // use software rendering shell.GetSettings().msaa_samples // msaa sample count ); - LOGI("on_create_platform_view LOGI"); - FML_LOG(INFO) << "on_create_platform_view end"; weak_platform_view = platform_view_OHOS->GetWeakPtr(); - LOGI("on_create_platform_view LOGI2"); - FML_LOG(INFO) << "on_create_platform_view end1"; - std::vector> displays; - displays.push_back(std::make_unique(napi_facade)); - FML_DLOG(INFO) << "on_create_platform_view LOGI3"; - FML_LOG(INFO) << "on_create_platform_view end3"; - shell.OnDisplayUpdates(DisplayUpdateType::kStartup, - std::move(displays)); - LOGI("on_create_platform_view LOGI4"); - FML_LOG(INFO) << "on_create_platform_view end3"; + FML_LOG(INFO) << "on_create_platform_view end"; + // std::vector> displays; + // displays.push_back(std::make_unique(napi_facade)); + // shell.OnDisplayUpdates(DisplayUpdateType::kStartup, + // std::move(displays)); return platform_view_OHOS; }; @@ -155,6 +148,13 @@ OHOSShellHolder::OHOSShellHolder( ); FML_DLOG(INFO) << "shell create end"; if (shell_) { + // For getting the RefreshRate of display + std::vector> displays; + auto vsync_waiter = std::shared_ptr(shell_->GetVsyncWaiter().lock()); + auto vsync_waiter_ohos = std::static_pointer_cast(vsync_waiter); + displays.push_back(std::make_unique(vsync_waiter_ohos)); + shell_->OnDisplayUpdates(DisplayUpdateType::kStartUp, std::move(displays)); + shell_->GetDartVM()->GetConcurrentMessageLoop()->PostTaskToAllWorkers([]() { if (::setpriority(PRIO_PROCESS, gettid(), 1) != 0) { FML_DLOG(ERROR) << "Failed to set Workers task runner priority"; diff --git a/shell/platform/ohos/vsync_waiter_ohos.cpp b/shell/platform/ohos/vsync_waiter_ohos.cpp index 1330506a8a..42319aee5e 100644 --- a/shell/platform/ohos/vsync_waiter_ohos.cpp +++ b/shell/platform/ohos/vsync_waiter_ohos.cpp @@ -96,4 +96,9 @@ void VsyncWaiterOHOS::OnUpdateRefreshRate(long long refresh_rate) { g_refresh_rate_ = static_cast(refresh_rate); } +int VsyncWaiterOHOS::GetRefreshRate(void) +{ + return g_refresh_rate_; +} + } // namespace flutter diff --git a/shell/platform/ohos/vsync_waiter_ohos.h b/shell/platform/ohos/vsync_waiter_ohos.h index e9aac66c85..5d9065d48c 100644 --- a/shell/platform/ohos/vsync_waiter_ohos.h +++ b/shell/platform/ohos/vsync_waiter_ohos.h @@ -24,24 +24,26 @@ namespace flutter { class VsyncWaiterOHOS final : public VsyncWaiter { - public: - explicit VsyncWaiterOHOS(const flutter::TaskRunners& task_runners); - static void OnUpdateRefreshRate(long long refresh_rate); +public: + explicit VsyncWaiterOHOS(const flutter::TaskRunners& task_runners); + ~VsyncWaiterOHOS() override; - ~VsyncWaiterOHOS() override; + static void OnUpdateRefreshRate(long long refresh_rate); - private: - thread_local static bool firstCall; - // |VsyncWaiter| - void AwaitVSync() override; + int GetRefreshRate(void); - static void OnVsyncFromOHOS(long long timestamp, void* data); - static void ConsumePendingCallback(std::weak_ptr* weak_this, +private: + // |VsyncWaiter| + void AwaitVSync() override; + + static void OnVsyncFromOHOS(long long timestamp, void* data); + static void ConsumePendingCallback(std::weak_ptr* weak_this, fml::TimePoint frame_start_time, fml::TimePoint frame_target_time); - OH_NativeVSync* vsyncHandle; - FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiterOHOS); + thread_local static bool firstCall; + OH_NativeVSync* vsyncHandle; + FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiterOHOS); }; -} // namespace flutter +} // namespace flutter #endif -- Gitee From c8d765c78e9c429b5fc06e25a02d94f93949480e Mon Sep 17 00:00:00 2001 From: keminLuo Date: Mon, 13 Jan 2025 10:20:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: keminLuo --- shell/platform/ohos/ohos_shell_holder.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/shell/platform/ohos/ohos_shell_holder.cpp b/shell/platform/ohos/ohos_shell_holder.cpp index 0b048365d1..980c63fee5 100644 --- a/shell/platform/ohos/ohos_shell_holder.cpp +++ b/shell/platform/ohos/ohos_shell_holder.cpp @@ -106,10 +106,6 @@ OHOSShellHolder::OHOSShellHolder( ); weak_platform_view = platform_view_OHOS->GetWeakPtr(); FML_LOG(INFO) << "on_create_platform_view end"; - // std::vector> displays; - // displays.push_back(std::make_unique(napi_facade)); - // shell.OnDisplayUpdates(DisplayUpdateType::kStartup, - // std::move(displays)); return platform_view_OHOS; }; -- Gitee