diff --git a/shell/platform/ohos/BUILD.gn b/shell/platform/ohos/BUILD.gn index c9c6d05810ce04ff4450baed87c2699694181c44..417e741443d7157b075d117b71b985ec89269dbb 100644 --- a/shell/platform/ohos/BUILD.gn +++ b/shell/platform/ohos/BUILD.gn @@ -232,6 +232,7 @@ shared_library("flutter_shell_native") { ldflags += ["-lm"] ldflags += ["-lpthread"] ldflags += ["-lpixelmap_ndk.z"] + ldflags += ["-lqos"] public_configs = [ "//flutter:config" ] } diff --git a/shell/platform/ohos/ohos_shell_holder.cpp b/shell/platform/ohos/ohos_shell_holder.cpp index cbc08c05a68fd33c96102c547b6fde23c9796fc7..c995a841934c750f627ae5709d1b0b827c18ce2e 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,23 @@ 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"; - } - break; + 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"; - } - break; + 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"; - } - } - break; + int ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_USER_INTERACTIVE); + FML_DLOG(INFO) << "qos set raster 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(); } }