From 63ab0f607c95b1eac414a3ca3ea8bc1c7fa052c9 Mon Sep 17 00:00:00 2001 From: zmf <279822581@qq.com> Date: Thu, 7 Mar 2024 11:52:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0qos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zmf <279822581@qq.com> --- shell/platform/ohos/BUILD.gn | 2 ++ shell/platform/ohos/ohos_shell_holder.cpp | 33 ++++++++++------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/shell/platform/ohos/BUILD.gn b/shell/platform/ohos/BUILD.gn index 7b888c0d6e..fb9bda794d 100644 --- a/shell/platform/ohos/BUILD.gn +++ b/shell/platform/ohos/BUILD.gn @@ -234,6 +234,8 @@ shared_library("flutter_shell_native") { ldflags += ["-lpthread"] ldflags += ["-lpixelmap_ndk.z"] + ldflags += ["-lqos_ndk.z"] + public_configs = [ "//flutter:config" ] } diff --git a/shell/platform/ohos/ohos_shell_holder.cpp b/shell/platform/ohos/ohos_shell_holder.cpp index cbc08c05a6..4e02f49568 100644 --- a/shell/platform/ohos/ohos_shell_holder.cpp +++ b/shell/platform/ohos/ohos_shell_holder.cpp @@ -24,6 +24,7 @@ #include #include +#include namespace flutter { @@ -33,34 +34,28 @@ static void OHOSPlatformThreadConfigSetter( // set thread priority switch (config.priority) { case fml::Thread::ThreadPriority::BACKGROUND: { - if (::setpriority(PRIO_PROCESS, 0, 10) != 0) { - FML_DLOG(ERROR) << "Failed to set IO task runner priority"; - } + int ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_BACKGROUND); + FML_DLOG(INFO) << "qos set background result:" << ret << ",tid:" << gettid(); break; } case fml::Thread::ThreadPriority::DISPLAY: { - if (::setpriority(PRIO_PROCESS, 0, -1) != 0) { - FML_DLOG(ERROR) << "Failed to set UI task runner priority"; - } + int ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_USER_INTERACTIVE); + FML_DLOG(INFO) << "qos set display result:" << ret << ",tid:" << gettid(); break; } case fml::Thread::ThreadPriority::RASTER: { - // Android describes -8 as "most important display threads, for - // compositing the screen and retrieving input events". Conservatively - // set the raster thread to slightly lower priority than it. - if (::setpriority(PRIO_PROCESS, 0, -5) != 0) { - // Defensive fallback. Depending on the OEM, it may not be possible - // to set priority to -5. - if (::setpriority(PRIO_PROCESS, 0, -2) != 0) { - FML_DLOG(ERROR) << "Failed to set raster task runner priority"; - } - } + int ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_USER_INTERACTIVE); + FML_DLOG(INFO) << "qos set raster result:" << ret << ",tid:" << gettid(); + break; + } + case fml::Thread::ThreadPriority::NORMAL: { + int ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_DEFAULT); + FML_DLOG(INFO) << "qos set io result:" << ret << ",tid:" << gettid(); break; } default: - if (::setpriority(PRIO_PROCESS, 0, 0) != 0) { - FML_DLOG(ERROR) << "Failed to set priority"; - } + int ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_DEFAULT); + FML_DLOG(INFO) << "qos set default result:" << ret << ",tid:" << gettid(); } } -- Gitee