Revert "Bug 1966311 - Use weak android symbol instead of dlopen/dlsym for android/Ashmem.cpp r=glandium" for causing multiple Android failures.
This reverts commitf5a2f8839a. This reverts commit801ade11ce. This reverts commit5c575caf38. This reverts commit0336e618cb.
This commit is contained in:
committed by
sstanca@mozilla.com
parent
20ad00a0fe
commit
0ae173924f
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include "AndroidHardwareBuffer.h"
|
#include "AndroidHardwareBuffer.h"
|
||||||
|
|
||||||
|
#include <dlfcn.h>
|
||||||
|
|
||||||
#include "mozilla/gfx/2D.h"
|
#include "mozilla/gfx/2D.h"
|
||||||
#include "mozilla/gfx/gfxVars.h"
|
#include "mozilla/gfx/gfxVars.h"
|
||||||
#include "mozilla/layers/ImageBridgeChild.h"
|
#include "mozilla/layers/ImageBridgeChild.h"
|
||||||
@@ -53,22 +55,41 @@ void AndroidHardwareBufferApi::Shutdown() { sInstance = nullptr; }
|
|||||||
AndroidHardwareBufferApi::AndroidHardwareBufferApi() {}
|
AndroidHardwareBufferApi::AndroidHardwareBufferApi() {}
|
||||||
|
|
||||||
bool AndroidHardwareBufferApi::Load() {
|
bool AndroidHardwareBufferApi::Load() {
|
||||||
if (__builtin_available(android 26, *)) {
|
void* handle = dlopen("libandroid.so", RTLD_LAZY | RTLD_LOCAL);
|
||||||
mAHardwareBuffer_allocate = AHardwareBuffer_allocate; // API 26
|
MOZ_ASSERT(handle);
|
||||||
mAHardwareBuffer_acquire = AHardwareBuffer_acquire; // API 26
|
if (!handle) {
|
||||||
mAHardwareBuffer_release = AHardwareBuffer_release; // API 26
|
gfxCriticalNote << "Failed to load libandroid.so";
|
||||||
mAHardwareBuffer_describe = AHardwareBuffer_describe; // API 26
|
return false;
|
||||||
mAHardwareBuffer_lock = AHardwareBuffer_lock; // API 26
|
}
|
||||||
mAHardwareBuffer_unlock = AHardwareBuffer_unlock; // API 26
|
|
||||||
|
mAHardwareBuffer_allocate =
|
||||||
|
(_AHardwareBuffer_allocate)dlsym(handle, "AHardwareBuffer_allocate");
|
||||||
|
mAHardwareBuffer_acquire =
|
||||||
|
(_AHardwareBuffer_acquire)dlsym(handle, "AHardwareBuffer_acquire");
|
||||||
|
mAHardwareBuffer_release =
|
||||||
|
(_AHardwareBuffer_release)dlsym(handle, "AHardwareBuffer_release");
|
||||||
|
mAHardwareBuffer_describe =
|
||||||
|
(_AHardwareBuffer_describe)dlsym(handle, "AHardwareBuffer_describe");
|
||||||
|
mAHardwareBuffer_lock =
|
||||||
|
(_AHardwareBuffer_lock)dlsym(handle, "AHardwareBuffer_lock");
|
||||||
|
mAHardwareBuffer_unlock =
|
||||||
|
(_AHardwareBuffer_unlock)dlsym(handle, "AHardwareBuffer_unlock");
|
||||||
mAHardwareBuffer_sendHandleToUnixSocket =
|
mAHardwareBuffer_sendHandleToUnixSocket =
|
||||||
AHardwareBuffer_sendHandleToUnixSocket; // API 26
|
(_AHardwareBuffer_sendHandleToUnixSocket)dlsym(
|
||||||
|
handle, "AHardwareBuffer_sendHandleToUnixSocket");
|
||||||
mAHardwareBuffer_recvHandleFromUnixSocket =
|
mAHardwareBuffer_recvHandleFromUnixSocket =
|
||||||
AHardwareBuffer_recvHandleFromUnixSocket; // API 26
|
(_AHardwareBuffer_recvHandleFromUnixSocket)dlsym(
|
||||||
return true;
|
handle, "AHardwareBuffer_recvHandleFromUnixSocket");
|
||||||
} else {
|
|
||||||
|
if (!mAHardwareBuffer_allocate || !mAHardwareBuffer_acquire ||
|
||||||
|
!mAHardwareBuffer_release || !mAHardwareBuffer_describe ||
|
||||||
|
!mAHardwareBuffer_lock || !mAHardwareBuffer_unlock ||
|
||||||
|
!mAHardwareBuffer_sendHandleToUnixSocket ||
|
||||||
|
!mAHardwareBuffer_recvHandleFromUnixSocket) {
|
||||||
gfxCriticalNote << "Failed to load AHardwareBuffer";
|
gfxCriticalNote << "Failed to load AHardwareBuffer";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AndroidHardwareBufferApi::Allocate(const AHardwareBuffer_Desc* aDesc,
|
void AndroidHardwareBufferApi::Allocate(const AHardwareBuffer_Desc* aDesc,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include "mozilla/Assertions.h"
|
#include "mozilla/Assertions.h"
|
||||||
#include "nsDebug.h"
|
#include "nsDebug.h"
|
||||||
|
|
||||||
#include <android/system_fonts.h>
|
#include <dlfcn.h>
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
@@ -36,14 +36,26 @@ AndroidSystemFontIterator::~AndroidSystemFontIterator() {
|
|||||||
|
|
||||||
bool AndroidSystemFontIterator::Init() {
|
bool AndroidSystemFontIterator::Init() {
|
||||||
if (!sSystemFontIterator_open) {
|
if (!sSystemFontIterator_open) {
|
||||||
if (__builtin_available(android 29, *)) {
|
void* handle = dlopen("libandroid.so", RTLD_LAZY | RTLD_LOCAL);
|
||||||
sSystemFontIterator_open = ASystemFontIterator_open;
|
MOZ_ASSERT(handle);
|
||||||
sSystemFontIterator_next = ASystemFontIterator_next;
|
|
||||||
sSystemFontIterator_close = ASystemFontIterator_close;
|
sSystemFontIterator_open =
|
||||||
AndroidFont::sFont_getFontFilePath = AFont_getFontFilePath;
|
(_ASystemFontIterator_open)dlsym(handle, "ASystemFontIterator_open");
|
||||||
AndroidFont::sFont_close = AFont_close;
|
sSystemFontIterator_next =
|
||||||
} else {
|
(_ASystemFontIterator_next)dlsym(handle, "ASystemFontIterator_next");
|
||||||
return NS_WARN_IF(false);
|
sSystemFontIterator_close =
|
||||||
|
(_ASystemFontIterator_close)dlsym(handle, "ASystemFontIterator_close");
|
||||||
|
AndroidFont::sFont_getFontFilePath =
|
||||||
|
(_AFont_getFontFilePath)dlsym(handle, "AFont_getFontFilePath");
|
||||||
|
AndroidFont::sFont_close = (_AFont_close)dlsym(handle, "AFont_close");
|
||||||
|
|
||||||
|
if (NS_WARN_IF(!sSystemFontIterator_open) ||
|
||||||
|
NS_WARN_IF(!sSystemFontIterator_next) ||
|
||||||
|
NS_WARN_IF(!sSystemFontIterator_close) ||
|
||||||
|
NS_WARN_IF(!AndroidFont::sFont_getFontFilePath) ||
|
||||||
|
NS_WARN_IF(!AndroidFont::sFont_close)) {
|
||||||
|
sSystemFontIterator_open = nullptr;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +73,7 @@ Maybe<AndroidFont> AndroidSystemFontIterator::Next() {
|
|||||||
return Nothing();
|
return Nothing();
|
||||||
}
|
}
|
||||||
|
|
||||||
AFont* font = sSystemFontIterator_next(mIterator);
|
void* font = sSystemFontIterator_next(mIterator);
|
||||||
if (!font) {
|
if (!font) {
|
||||||
sSystemFontIterator_close(mIterator);
|
sSystemFontIterator_close(mIterator);
|
||||||
mIterator = nullptr;
|
mIterator = nullptr;
|
||||||
|
|||||||
@@ -7,23 +7,19 @@
|
|||||||
#define AndroidSystemFontIterator_h__
|
#define AndroidSystemFontIterator_h__
|
||||||
|
|
||||||
#include "mozilla/Maybe.h"
|
#include "mozilla/Maybe.h"
|
||||||
#include <android/font.h>
|
|
||||||
#include <android/system_fonts.h>
|
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
typedef ASystemFontIterator* _Nullable (*_ASystemFontIterator_open)();
|
typedef void* (*_ASystemFontIterator_open)();
|
||||||
typedef AFont* _Nullable (*_ASystemFontIterator_next)(
|
typedef void* (*_ASystemFontIterator_next)(void*);
|
||||||
ASystemFontIterator* _Nonnull iterator);
|
typedef void (*_ASystemFontIterator_close)(void*);
|
||||||
typedef void (*_ASystemFontIterator_close)(
|
|
||||||
ASystemFontIterator* _Nullable iterator);
|
typedef const char* (*_AFont_getFontFilePath)(const void*);
|
||||||
typedef const char* _Nonnull (*_AFont_getFontFilePath)(
|
typedef void (*_AFont_close)(void*);
|
||||||
const AFont* _Nonnull font);
|
|
||||||
typedef void (*_AFont_close)(AFont* _Nullable font);
|
|
||||||
|
|
||||||
class AndroidFont final {
|
class AndroidFont final {
|
||||||
public:
|
public:
|
||||||
explicit AndroidFont(AFont* _Nullable aFont) : mFont(aFont) {};
|
explicit AndroidFont(void* aFont) : mFont(aFont) {};
|
||||||
|
|
||||||
AndroidFont() = delete;
|
AndroidFont() = delete;
|
||||||
AndroidFont(AndroidFont&) = delete;
|
AndroidFont(AndroidFont&) = delete;
|
||||||
@@ -35,13 +31,13 @@ class AndroidFont final {
|
|||||||
|
|
||||||
~AndroidFont();
|
~AndroidFont();
|
||||||
|
|
||||||
const char* _Nullable GetFontFilePath();
|
const char* GetFontFilePath();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AFont* _Nullable mFont;
|
void* mFont;
|
||||||
|
|
||||||
static _AFont_getFontFilePath _Nullable sFont_getFontFilePath;
|
static _AFont_getFontFilePath sFont_getFontFilePath;
|
||||||
static _AFont_close _Nullable sFont_close;
|
static _AFont_close sFont_close;
|
||||||
|
|
||||||
friend class AndroidSystemFontIterator;
|
friend class AndroidSystemFontIterator;
|
||||||
};
|
};
|
||||||
@@ -57,11 +53,11 @@ class AndroidSystemFontIterator final {
|
|||||||
Maybe<AndroidFont> Next();
|
Maybe<AndroidFont> Next();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ASystemFontIterator* _Nullable mIterator = nullptr;
|
void* mIterator = nullptr;
|
||||||
|
|
||||||
static _ASystemFontIterator_open _Nullable sSystemFontIterator_open;
|
static _ASystemFontIterator_open sSystemFontIterator_open;
|
||||||
static _ASystemFontIterator_next _Nullable sSystemFontIterator_next;
|
static _ASystemFontIterator_next sSystemFontIterator_next;
|
||||||
static _ASystemFontIterator_close _Nullable sSystemFontIterator_close;
|
static _ASystemFontIterator_close sSystemFontIterator_close;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|||||||
@@ -10,18 +10,26 @@
|
|||||||
|
|
||||||
#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() {
|
||||||
@@ -65,21 +73,20 @@ class PerformanceHintManagerApi final {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__builtin_available(android 33, *)) {
|
void* const handle = dlopen("libandroid.so", RTLD_LAZY | RTLD_LOCAL);
|
||||||
auto api = WrapUnique(new PerformanceHintManagerApi());
|
if (!handle) {
|
||||||
api->mAPerformanceHint_getManager = ::APerformanceHint_getManager;
|
HAL_ERR("Failed to open libandroid.so");
|
||||||
api->mAPerformanceHint_createSession = ::APerformanceHint_createSession;
|
|
||||||
api->mAPerformanceHint_updateTargetWorkDuration =
|
|
||||||
::APerformanceHint_updateTargetWorkDuration;
|
|
||||||
api->mAPerformanceHint_reportActualWorkDuration =
|
|
||||||
::APerformanceHint_reportActualWorkDuration;
|
|
||||||
api->mAPerformanceHint_closeSession = ::APerformanceHint_closeSession;
|
|
||||||
|
|
||||||
return api;
|
|
||||||
} else {
|
|
||||||
HAL_ERR("Failed to load PerformanceHintManager symbols");
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto api = WrapUnique(new PerformanceHintManagerApi());
|
||||||
|
LOAD_FN(api, handle, APerformanceHint_getManager);
|
||||||
|
LOAD_FN(api, handle, APerformanceHint_createSession);
|
||||||
|
LOAD_FN(api, handle, APerformanceHint_updateTargetWorkDuration);
|
||||||
|
LOAD_FN(api, handle, APerformanceHint_reportActualWorkDuration);
|
||||||
|
LOAD_FN(api, handle, APerformanceHint_closeSession);
|
||||||
|
|
||||||
|
return api;
|
||||||
}
|
}
|
||||||
|
|
||||||
using FnAPerformanceHint_getManager = APerformanceHintManager* (*)();
|
using FnAPerformanceHint_getManager = APerformanceHintManager* (*)();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <dlfcn.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <linux/ashmem.h>
|
#include <linux/ashmem.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -11,16 +12,22 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <android/sharedmem.h>
|
|
||||||
|
|
||||||
#include "Ashmem.h"
|
#include "Ashmem.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace android {
|
namespace android {
|
||||||
|
|
||||||
|
static void* libhandle() {
|
||||||
|
static void* handle = dlopen("libandroid.so", RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
int ashmem_create(const char* name, size_t size) {
|
int ashmem_create(const char* name, size_t size) {
|
||||||
if (__builtin_available(android 26, *)) {
|
static auto fCreate =
|
||||||
return ASharedMemory_create(name, size);
|
(int (*)(const char*, size_t))dlsym(libhandle(), "ASharedMemory_create");
|
||||||
|
|
||||||
|
if (fCreate) {
|
||||||
|
return fCreate(name, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd = open("/" ASHMEM_NAME_DEF, O_RDWR);
|
int fd = open("/" ASHMEM_NAME_DEF, O_RDWR);
|
||||||
@@ -43,16 +50,20 @@ int ashmem_create(const char* name, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t ashmem_getSize(int fd) {
|
size_t ashmem_getSize(int fd) {
|
||||||
if (__builtin_available(android 26, *)) {
|
static auto fGetSize =
|
||||||
return ASharedMemory_getSize(fd);
|
(size_t(*)(int))dlsym(libhandle(), "ASharedMemory_getSize");
|
||||||
|
if (fGetSize) {
|
||||||
|
return fGetSize(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (size_t)ioctl(fd, ASHMEM_GET_SIZE, nullptr);
|
return (size_t)ioctl(fd, ASHMEM_GET_SIZE, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ashmem_setProt(int fd, int prot) {
|
int ashmem_setProt(int fd, int prot) {
|
||||||
if (__builtin_available(android 26, *)) {
|
static auto fSetProt =
|
||||||
return ASharedMemory_setProt(fd, prot);
|
(int (*)(int, int))dlsym(libhandle(), "ASharedMemory_setProt");
|
||||||
|
if (fSetProt) {
|
||||||
|
return fSetProt(fd, prot);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ioctl(fd, ASHMEM_SET_PROT_MASK, prot);
|
return ioctl(fd, ASHMEM_SET_PROT_MASK, prot);
|
||||||
|
|||||||
Reference in New Issue
Block a user