When Android 12+, `ASystemFontIterator_open` doesn't read font configuration XML file directly to support font update. So it causes that first call of it becomes too slow. So I would like to call it on background thread at start up to initialize internal data in Android. This fox improves 50-100ms on `gfxPlatform::Init`. Gecko already uses similar to it for macOS and Windows (DirectWrite). Differential Revision: https://phabricator.services.mozilla.com/D224896
66 lines
1.5 KiB
C++
66 lines
1.5 KiB
C++
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#ifndef AndroidSystemFontIterator_h__
|
|
#define AndroidSystemFontIterator_h__
|
|
|
|
#include "mozilla/Maybe.h"
|
|
|
|
namespace mozilla {
|
|
|
|
typedef void* (*_ASystemFontIterator_open)();
|
|
typedef void* (*_ASystemFontIterator_next)(void*);
|
|
typedef void (*_ASystemFontIterator_close)(void*);
|
|
|
|
typedef const char* (*_AFont_getFontFilePath)(const void*);
|
|
typedef void (*_AFont_close)(void*);
|
|
|
|
class AndroidFont final {
|
|
public:
|
|
explicit AndroidFont(void* aFont) : mFont(aFont) {};
|
|
|
|
AndroidFont() = delete;
|
|
AndroidFont(AndroidFont&) = delete;
|
|
|
|
AndroidFont(AndroidFont&& aSrc) {
|
|
mFont = aSrc.mFont;
|
|
aSrc.mFont = nullptr;
|
|
}
|
|
|
|
~AndroidFont();
|
|
|
|
const char* GetFontFilePath();
|
|
|
|
private:
|
|
void* mFont;
|
|
|
|
static _AFont_getFontFilePath sFont_getFontFilePath;
|
|
static _AFont_close sFont_close;
|
|
|
|
friend class AndroidSystemFontIterator;
|
|
};
|
|
|
|
class AndroidSystemFontIterator final {
|
|
public:
|
|
AndroidSystemFontIterator() = default;
|
|
|
|
~AndroidSystemFontIterator();
|
|
|
|
bool Init();
|
|
|
|
Maybe<AndroidFont> Next();
|
|
|
|
private:
|
|
void* mIterator = nullptr;
|
|
|
|
static _ASystemFontIterator_open sSystemFontIterator_open;
|
|
static _ASystemFontIterator_next sSystemFontIterator_next;
|
|
static _ASystemFontIterator_close sSystemFontIterator_close;
|
|
};
|
|
|
|
} // namespace mozilla
|
|
|
|
#endif
|