diff --git a/shell/platform/ohos/ohos_display.cpp b/shell/platform/ohos/ohos_display.cpp index 3f23e95b007803dcf71befb620d0a0043e46a6ba..2b9b823df5c6a4d7b654d6122ab528c8495336b3 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 873f2cff90e15467199eda7890a68b7c66229b62..4bf5600e13afb5b138f5e321347599282f5c92cf 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 2cb763fc04889ce0342e708451dc485f04bfc023..980c63fee54fa67b7a5c7e1dcef6d5138ddf6c61 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,8 @@ 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"; return platform_view_OHOS; }; @@ -155,6 +144,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 7c60239e2de2765aef18d8a0ff7d16cbd5dcfb3e..b1a201941332123f4b6a3459be914a8edba59acc 100644 --- a/shell/platform/ohos/vsync_waiter_ohos.cpp +++ b/shell/platform/ohos/vsync_waiter_ohos.cpp @@ -100,6 +100,11 @@ void VsyncWaiterOHOS::OnUpdateRefreshRate(long long refresh_rate) { g_refresh_rate_ = static_cast(refresh_rate); } +int VsyncWaiterOHOS::GetRefreshRate(void) +{ + return g_refresh_rate_; +} + void VsyncWaiterOHOS::DisableDVsync() { if (dvsyncEnabled.load()) { SetDvsyncSwitch(false); diff --git a/shell/platform/ohos/vsync_waiter_ohos.h b/shell/platform/ohos/vsync_waiter_ohos.h index 28fbff2d58a0fb96e3f3ca5389c2be4b04e0d929..020b804cdf1c2571391d888738f4c6a6c02b7d36 100644 --- a/shell/platform/ohos/vsync_waiter_ohos.h +++ b/shell/platform/ohos/vsync_waiter_ohos.h @@ -27,32 +27,35 @@ namespace flutter { using NativeDvsyncFunc = int (*)(OH_NativeVSync* nativeVSync, bool enable); 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); - void DisableDVsync() override; - void EnableDVsync() override; + int GetRefreshRate(void); + void DisableDVsync() override; + void EnableDVsync() override; - private: - std::atomic dvsyncEnabled{false}; - thread_local static bool firstCall; - // |VsyncWaiter| - void AwaitVSync() override; +private: + // |VsyncWaiter| + void AwaitVSync() override; - static void OnVsyncFromOHOS(long long timestamp, void* data); - static void ConsumePendingCallback(std::weak_ptr* weak_this, + 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); - void SetDvsyncSwitch(bool enableDvsync); - - OH_NativeVSync* vsyncHandle; - NativeDvsyncFunc nativeDvsyncFunc_ = nullptr; - void *handle_ = nullptr; - int32_t apiVersion_ = 0; - FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiterOHOS); + void SetDvsyncSwitch(bool enableDvsync); + std::atomic dvsyncEnabled{false}; + + thread_local static bool firstCall; + OH_NativeVSync* vsyncHandle; + FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiterOHOS); + OH_NativeVSync* vsyncHandle; + NativeDvsyncFunc nativeDvsyncFunc_ = nullptr; + void *handle_ = nullptr; + int32_t apiVersion_ = 0; + FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiterOHOS); }; -} // namespace flutter +} // namespace flutter #endif