Bug 1966310 - Use weak android symbol instead of dlopen/dlsym for AndroidPerformanceHintManager..cpp r=geckoview-reviewers,m_kato
Differential Revision: https://phabricator.services.mozilla.com/D249225
This commit is contained in:
committed by
sguelton@mozilla.com
parent
5c575caf38
commit
801ade11ce
@@ -10,26 +10,18 @@
|
|||||||
|
|
||||||
#include "AndroidBuild.h"
|
#include "AndroidBuild.h"
|
||||||
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <android/performance_hint.h>
|
||||||
|
|
||||||
typedef struct APerformanceHintManager APerformanceHintManager;
|
typedef struct APerformanceHintManager APerformanceHintManager;
|
||||||
typedef struct APerformanceHintSession APerformanceHintSession;
|
typedef struct APerformanceHintSession APerformanceHintSession;
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace hal_impl {
|
namespace hal_impl {
|
||||||
|
|
||||||
#define LOAD_FN(api, lib, name) \
|
|
||||||
do { \
|
|
||||||
api->m##name = reinterpret_cast<Fn##name>(dlsym(handle, #name)); \
|
|
||||||
if (!api->m##name) { \
|
|
||||||
HAL_ERR("Failed to load %s", #name); \
|
|
||||||
return nullptr; \
|
|
||||||
} \
|
|
||||||
} while (false)
|
|
||||||
|
|
||||||
class PerformanceHintManagerApi final {
|
class PerformanceHintManagerApi final {
|
||||||
public:
|
public:
|
||||||
static PerformanceHintManagerApi* Get() {
|
static PerformanceHintManagerApi* Get() {
|
||||||
@@ -73,20 +65,21 @@ class PerformanceHintManagerApi final {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* const handle = dlopen("libandroid.so", RTLD_LAZY | RTLD_LOCAL);
|
if (__builtin_available(android 33, *)) {
|
||||||
if (!handle) {
|
|
||||||
HAL_ERR("Failed to open libandroid.so");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto api = WrapUnique(new PerformanceHintManagerApi());
|
auto api = WrapUnique(new PerformanceHintManagerApi());
|
||||||
LOAD_FN(api, handle, APerformanceHint_getManager);
|
api->mAPerformanceHint_getManager = ::APerformanceHint_getManager;
|
||||||
LOAD_FN(api, handle, APerformanceHint_createSession);
|
api->mAPerformanceHint_createSession = ::APerformanceHint_createSession;
|
||||||
LOAD_FN(api, handle, APerformanceHint_updateTargetWorkDuration);
|
api->mAPerformanceHint_updateTargetWorkDuration =
|
||||||
LOAD_FN(api, handle, APerformanceHint_reportActualWorkDuration);
|
::APerformanceHint_updateTargetWorkDuration;
|
||||||
LOAD_FN(api, handle, APerformanceHint_closeSession);
|
api->mAPerformanceHint_reportActualWorkDuration =
|
||||||
|
::APerformanceHint_reportActualWorkDuration;
|
||||||
|
api->mAPerformanceHint_closeSession = ::APerformanceHint_closeSession;
|
||||||
|
|
||||||
return api;
|
return api;
|
||||||
|
} else {
|
||||||
|
HAL_ERR("Failed to load PerformanceHintManager symbols");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using FnAPerformanceHint_getManager = APerformanceHintManager* (*)();
|
using FnAPerformanceHint_getManager = APerformanceHintManager* (*)();
|
||||||
|
|||||||
Reference in New Issue
Block a user