forked from firka/flutter
Remove unused functions.
This CL is essentially reverting following changes: - "Serialize and deserialize supported axes." I4086fb887e13f872390b533584bce6f1d5598ea0 - "Make SparseBitSet serializable." I0463138adcf234739bb3ce1cdadf382021921f3e Bug: 36232655 Test: N/A Change-Id: I25c701e1805e92b01034142147a9925f86533819
This commit is contained in:
@@ -126,23 +126,6 @@ public:
|
||||
FontFamily(int variant, std::vector<Font>&& fonts);
|
||||
FontFamily(uint32_t langId, int variant, std::vector<Font>&& fonts);
|
||||
|
||||
// The accelerator table won't be copied. Do not release the memory until the created FontFamily
|
||||
// is destructed.
|
||||
FontFamily(std::vector<Font>&& fonts, const uint8_t* acceleratorTable, size_t tableSize);
|
||||
FontFamily(int variant, std::vector<Font>&& fonts, const uint8_t* acceleratorTable,
|
||||
size_t tableSize);
|
||||
FontFamily(uint32_t langId, int variant, std::vector<Font>&& fonts,
|
||||
const uint8_t* acceleratorTable, size_t tableSize);
|
||||
|
||||
~FontFamily();
|
||||
|
||||
// Writes internal accelerator tables into the 'out' buffer.
|
||||
//
|
||||
// This method returns the number of bytes written to the buffer. By calling the method with
|
||||
// 'out' set to nullptr, the method just returns the size needed, which the caller can then use
|
||||
// for allocating a buffer for a second call.
|
||||
size_t writeAcceleratorTable(uint8_t* out) const;
|
||||
|
||||
// TODO: Good to expose FontUtil.h.
|
||||
static bool analyzeStyle(const std::shared_ptr<MinikinFont>& typeface, int* weight,
|
||||
bool* italic);
|
||||
@@ -177,13 +160,6 @@ public:
|
||||
|
||||
private:
|
||||
void computeCoverage();
|
||||
void readAcceleratorTable(const uint8_t* data, size_t size);
|
||||
|
||||
size_t writeSupportedAxes(uint8_t* out) const;
|
||||
|
||||
// Reads supported axes values from 'in' buffer. This method reads up to
|
||||
// 'inSize' bytes and returns the number of bytes read.
|
||||
size_t readSupportedAxes(const uint8_t* in, size_t inSize);
|
||||
|
||||
uint32_t mLangId;
|
||||
int mVariant;
|
||||
|
||||
@@ -45,17 +45,6 @@ public:
|
||||
// inclusive of start, exclusive of end, laid out in a uint32 array.
|
||||
void initFromRanges(const uint32_t* ranges, size_t nRanges);
|
||||
|
||||
// Initializes the set with pre-calculted data. Returns false if the serialized data is invalid.
|
||||
// Even if this function returns false, the internal data is cleared.
|
||||
bool initFromBuffer(const uint8_t* data, size_t size);
|
||||
|
||||
// Serialize the set and write into out.
|
||||
//
|
||||
// This method returns the number of bytes written to the buffer. By calling the method with
|
||||
// 'out' set to nullptr, the method just returns the size needed, which the caller can then use
|
||||
// for allocating a buffer for a second call.
|
||||
size_t writeToBuffer(uint8_t* out) const;
|
||||
|
||||
// Determine whether the value is included in the set
|
||||
bool get(uint32_t ch) const {
|
||||
if (ch >= mMaxVal) return false;
|
||||
|
||||
@@ -109,25 +109,6 @@ FontFamily::FontFamily(uint32_t langId, int variant, std::vector<Font>&& fonts)
|
||||
computeCoverage();
|
||||
}
|
||||
|
||||
FontFamily::FontFamily(std::vector<Font>&& fonts, const uint8_t* acceleratorTable, size_t tableSize)
|
||||
: FontFamily(0 /* variant */, std::move(fonts), acceleratorTable, tableSize) {
|
||||
}
|
||||
|
||||
FontFamily::FontFamily(int variant, std::vector<Font>&& fonts, const uint8_t* acceleratorTable,
|
||||
size_t tableSize)
|
||||
: FontFamily(FontLanguageListCache::kEmptyListId, variant, std::move(fonts), acceleratorTable,
|
||||
tableSize) {
|
||||
}
|
||||
|
||||
FontFamily::FontFamily(uint32_t langId, int variant, std::vector<Font>&& fonts,
|
||||
const uint8_t* acceleratorTable, size_t tableSize)
|
||||
: mLangId(langId), mVariant(variant), mFonts(std::move(fonts)), mHasVSTable(false) {
|
||||
readAcceleratorTable(acceleratorTable, tableSize);
|
||||
}
|
||||
|
||||
FontFamily::~FontFamily() {
|
||||
}
|
||||
|
||||
bool FontFamily::analyzeStyle(const std::shared_ptr<MinikinFont>& typeface, int* weight,
|
||||
bool* italic) {
|
||||
android::AutoMutex _l(gMinikinLock);
|
||||
@@ -263,47 +244,4 @@ std::shared_ptr<FontFamily> FontFamily::createFamilyWithVariation(
|
||||
return std::shared_ptr<FontFamily>(new FontFamily(mLangId, mVariant, std::move(fonts)));
|
||||
}
|
||||
|
||||
size_t FontFamily::writeAcceleratorTable(uint8_t* out) const {
|
||||
const size_t axesTableSize = writeSupportedAxes(out);
|
||||
if (out != nullptr) {
|
||||
out += axesTableSize;
|
||||
}
|
||||
const size_t coverageTableSize = mCoverage.writeToBuffer(out);
|
||||
return axesTableSize + coverageTableSize;
|
||||
}
|
||||
|
||||
void FontFamily::readAcceleratorTable(const uint8_t* data, size_t size) {
|
||||
const size_t readSize = readSupportedAxes(data, size);
|
||||
data += readSize;
|
||||
size -= readSize;
|
||||
bool result = mCoverage.initFromBuffer(data, size);
|
||||
LOG_ALWAYS_FATAL_IF(!result, "Failed to reconstruct accelerator table from buffer");
|
||||
}
|
||||
|
||||
size_t FontFamily::writeSupportedAxes(uint8_t* out) const {
|
||||
LOG_ALWAYS_FATAL_IF(mSupportedAxes.size() > 255, "System fonts may only use up to 255 axes.");
|
||||
const uint8_t axesCount = static_cast<uint8_t>(mSupportedAxes.size());
|
||||
if (out != nullptr) {
|
||||
out[0] = axesCount;
|
||||
AxisTag* axisTags = reinterpret_cast<AxisTag*>(out + 1);
|
||||
for (const auto& tag : mSupportedAxes) {
|
||||
*axisTags++ = tag;
|
||||
}
|
||||
}
|
||||
const size_t axesSizeInbytes = sizeof(AxisTag) * axesCount;
|
||||
return axesSizeInbytes + 1 /* 1 for axes count */;
|
||||
}
|
||||
|
||||
size_t FontFamily::readSupportedAxes(const uint8_t* in, size_t inSize) {
|
||||
LOG_ALWAYS_FATAL_IF(inSize == 0);
|
||||
const uint8_t axesCount = in[0];
|
||||
const size_t totalSize = sizeof(AxisTag) * axesCount + 1 /* 1 for axes Count */;
|
||||
LOG_ALWAYS_FATAL_IF(inSize < totalSize);
|
||||
const AxisTag* axisTags = reinterpret_cast<const AxisTag*>(in + 1);
|
||||
mSupportedAxes.clear();
|
||||
for (uint8_t i = 0; i < axesCount; ++i) {
|
||||
mSupportedAxes.insert(axisTags[i]);
|
||||
}
|
||||
return totalSize;
|
||||
}
|
||||
} // namespace minikin
|
||||
|
||||
@@ -118,73 +118,6 @@ void SparseBitSet::initFromRanges(const uint32_t* ranges, size_t nRanges) {
|
||||
mIndices = indices;
|
||||
}
|
||||
|
||||
struct SparseBitSetHeader {
|
||||
uint32_t maxValue;
|
||||
uint32_t zeroPageIndex;
|
||||
uint32_t indexSize;
|
||||
uint32_t bitmapSize;
|
||||
};
|
||||
|
||||
bool SparseBitSet::initFromBuffer(const uint8_t* data, size_t size) {
|
||||
// No need to be concerned about endianness here since Intel x86 CPUs are little-endian. ARM
|
||||
// CPUs are bi-endian but the endianness is only changeable at reset time and is impossible to
|
||||
// change at runtime. Thus incoming data is guaranteed to have the same endianness as when it
|
||||
// was created.
|
||||
|
||||
if (data == nullptr || size < sizeof(SparseBitSetHeader)) {
|
||||
clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
// The serialized data starts with SparseBitSetHeader.
|
||||
const SparseBitSetHeader* header = reinterpret_cast<const SparseBitSetHeader*>(data);
|
||||
mMaxVal = header->maxValue;
|
||||
mZeroPageIndex = header->zeroPageIndex;
|
||||
mIndexSize = header->indexSize;
|
||||
mBitmapSize = header->bitmapSize;
|
||||
|
||||
mOwnIndicesAndBitmaps = false;
|
||||
if (mIndexSize == 0 || mBitmapSize == 0 || mMaxVal == 0) {
|
||||
const bool isValidEmptyBitSet = (mIndexSize == 0 && mBitmapSize == 0 && mMaxVal == 0);
|
||||
if (!isValidEmptyBitSet) {
|
||||
clear();
|
||||
}
|
||||
return isValidEmptyBitSet;
|
||||
}
|
||||
|
||||
const size_t indicesSizeInBytes = sizeof(mIndices[0]) * mIndexSize;
|
||||
const size_t bitmapsSizeInBytes = sizeof(mBitmaps[0]) * mBitmapSize;
|
||||
if (size != sizeof(SparseBitSetHeader) + indicesSizeInBytes + bitmapsSizeInBytes) {
|
||||
clear();
|
||||
return false;
|
||||
}
|
||||
data += sizeof(SparseBitSetHeader);
|
||||
mIndices = reinterpret_cast<decltype(mIndices)>(data);
|
||||
data += indicesSizeInBytes;
|
||||
mBitmaps = reinterpret_cast<decltype(mBitmaps)>(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t SparseBitSet::writeToBuffer(uint8_t* out) const{
|
||||
// See comments in SparseBitSet::initFromBuffer for the data structure.
|
||||
const size_t indicesSizeInBytes = sizeof(mIndices[0]) * mIndexSize;
|
||||
const size_t bitmapsSizeInBytes = sizeof(mBitmaps[0]) * mBitmapSize;
|
||||
size_t necessarySize = sizeof(SparseBitSetHeader) + indicesSizeInBytes + bitmapsSizeInBytes;
|
||||
if (out != nullptr) {
|
||||
SparseBitSetHeader* header = reinterpret_cast<SparseBitSetHeader*>(out);
|
||||
header->maxValue = mMaxVal;
|
||||
header->zeroPageIndex = mZeroPageIndex;
|
||||
header->indexSize = mIndexSize;
|
||||
header->bitmapSize = mBitmapSize;
|
||||
|
||||
out += sizeof(SparseBitSetHeader);
|
||||
memcpy(out, mIndices, indicesSizeInBytes);
|
||||
out += indicesSizeInBytes;
|
||||
memcpy(out, mBitmaps, bitmapsSizeInBytes);
|
||||
}
|
||||
return necessarySize;
|
||||
}
|
||||
|
||||
int SparseBitSet::CountLeadingZeros(element x) {
|
||||
// Note: GCC / clang builtin
|
||||
return sizeof(element) <= sizeof(int) ? __builtin_clz(x) : __builtin_clzl(x);
|
||||
|
||||
@@ -32,23 +32,4 @@ static void BM_FontFamily_create(benchmark::State& state) {
|
||||
|
||||
BENCHMARK(BM_FontFamily_create);
|
||||
|
||||
static void BM_FontFamily_create_fromBuffer(benchmark::State& state) {
|
||||
std::shared_ptr<MinikinFontForTest> minikinFont =
|
||||
std::make_shared<MinikinFontForTest>("/system/fonts/NotoSansCJK-Regular.ttc", 0);
|
||||
|
||||
std::shared_ptr<FontFamily> family = std::make_shared<FontFamily>(
|
||||
std::vector<Font>({Font(minikinFont, FontStyle())}));
|
||||
|
||||
size_t bufSize = family->writeAcceleratorTable(nullptr);
|
||||
std::unique_ptr<uint8_t[]> buffer(new uint8_t[bufSize]);
|
||||
family->writeAcceleratorTable(buffer.get());
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
std::shared_ptr<FontFamily> family = std::make_shared<FontFamily>(
|
||||
std::vector<Font>({Font(minikinFont, FontStyle())}), buffer.get(), bufSize);
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK(BM_FontFamily_create_fromBuffer);
|
||||
|
||||
} // namespace minikin
|
||||
|
||||
@@ -656,50 +656,4 @@ TEST_F(FontFamilyTest, createFamilyWithVariationTest) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(FontFamilyTest, supportedAxesRestoreFromSerializedBuffer) {
|
||||
const char kFontPath[] = kTestFontDir "/MultiAxis.ttf";
|
||||
|
||||
std::shared_ptr<MinikinFont> font(new MinikinFontForTest(kFontPath));
|
||||
std::shared_ptr<FontFamily> family =
|
||||
std::make_shared<FontFamily>(std::vector<Font>({Font(font, FontStyle())}));
|
||||
|
||||
size_t necessaryBytes = family->writeAcceleratorTable(nullptr);
|
||||
ASSERT_NE(0U, necessaryBytes);
|
||||
std::vector<uint8_t> buffer;
|
||||
buffer.resize(necessaryBytes);
|
||||
family->writeAcceleratorTable(buffer.data());
|
||||
|
||||
std::shared_ptr<FontFamily> restoredMultiAxisFamily =
|
||||
std::make_shared<FontFamily>(std::vector<Font>({Font(font, FontStyle())}),
|
||||
buffer.data(), buffer.size());
|
||||
|
||||
// This font has 'wdth' and 'wght' axes.
|
||||
const std::unordered_set<AxisTag>& supportedAxes = family->supportedAxes();
|
||||
ASSERT_EQ(2U, supportedAxes.size());
|
||||
EXPECT_NE(supportedAxes.end(), supportedAxes.find(MinikinFont::MakeTag('w', 'd', 't', 'h')));
|
||||
EXPECT_NE(supportedAxes.end(), supportedAxes.find(MinikinFont::MakeTag('w', 'g', 'h', 't')));
|
||||
}
|
||||
|
||||
TEST_F(FontFamilyTest, supportedAxesRestoreFromSerializedBuffer_NoAxisFont) {
|
||||
const char kFontPath[] = kTestFontDir "/Regular.ttf";
|
||||
|
||||
std::shared_ptr<MinikinFont> font(new MinikinFontForTest(kFontPath));
|
||||
std::shared_ptr<FontFamily> family =
|
||||
std::make_shared<FontFamily>(std::vector<Font>({Font(font, FontStyle())}));
|
||||
|
||||
size_t necessaryBytes = family->writeAcceleratorTable(nullptr);
|
||||
ASSERT_NE(0U, necessaryBytes);
|
||||
std::vector<uint8_t> buffer;
|
||||
buffer.resize(necessaryBytes);
|
||||
family->writeAcceleratorTable(buffer.data());
|
||||
|
||||
std::shared_ptr<FontFamily> restoredMultiAxisFamily =
|
||||
std::make_shared<FontFamily>(std::vector<Font>({Font(font, FontStyle())}),
|
||||
buffer.data(), buffer.size());
|
||||
|
||||
// This font supports no axes.
|
||||
const std::unordered_set<AxisTag>& supportedAxes = family->supportedAxes();
|
||||
EXPECT_TRUE(supportedAxes.empty());
|
||||
}
|
||||
|
||||
} // namespace minikin
|
||||
|
||||
@@ -52,89 +52,4 @@ TEST(SparseBitSetTest, randomTest) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SparseBitSetTest, randomTest_restoredFromBuffer) {
|
||||
const uint32_t kTestRangeNum = 4096;
|
||||
|
||||
std::mt19937 mt; // Fix seeds to be able to reproduce the result.
|
||||
std::uniform_int_distribution<uint16_t> distribution(1, 512);
|
||||
|
||||
std::vector<uint32_t> range { distribution(mt) };
|
||||
for (size_t i = 1; i < kTestRangeNum * 2; ++i) {
|
||||
range.push_back((range.back() - 1) + distribution(mt));
|
||||
}
|
||||
|
||||
SparseBitSet tmpBitset;
|
||||
tmpBitset.initFromRanges(range.data(), range.size() / 2);
|
||||
|
||||
size_t bufSize = tmpBitset.writeToBuffer(nullptr);
|
||||
ASSERT_NE(0U, bufSize);
|
||||
std::vector<uint8_t> buffer(bufSize);
|
||||
tmpBitset.writeToBuffer(buffer.data());
|
||||
|
||||
SparseBitSet bitset;
|
||||
bitset.initFromBuffer(buffer.data(), buffer.size());
|
||||
|
||||
uint32_t ch = 0;
|
||||
for (size_t i = 0; i < range.size() / 2; ++i) {
|
||||
uint32_t start = range[i * 2];
|
||||
uint32_t end = range[i * 2 + 1];
|
||||
|
||||
for (; ch < start; ch++) {
|
||||
ASSERT_FALSE(bitset.get(ch)) << std::hex << ch;
|
||||
}
|
||||
for (; ch < end; ch++) {
|
||||
ASSERT_TRUE(bitset.get(ch)) << std::hex << ch;
|
||||
}
|
||||
}
|
||||
for (; ch < 0x1FFFFFF; ++ch) {
|
||||
ASSERT_FALSE(bitset.get(ch)) << std::hex << ch;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SparseBitSetTest, emptyBitSet) {
|
||||
SparseBitSet bitset;
|
||||
uint32_t empty_bitset[4] = {
|
||||
0 /* max value */, 0 /* zero page index */, 0 /* index size */, 0 /* bitmap size */
|
||||
};
|
||||
EXPECT_TRUE(bitset.initFromBuffer(
|
||||
reinterpret_cast<uint8_t*>(empty_bitset), sizeof(empty_bitset)));
|
||||
}
|
||||
|
||||
TEST(SparseBitSetTest, invalidData) {
|
||||
SparseBitSet bitset;
|
||||
EXPECT_FALSE(bitset.initFromBuffer(nullptr, 0));
|
||||
|
||||
// Buffer is too small.
|
||||
uint32_t small_buffer[3] = { 0, 0, 0 };
|
||||
EXPECT_FALSE(bitset.initFromBuffer(
|
||||
reinterpret_cast<uint8_t*>(small_buffer), sizeof(small_buffer)));
|
||||
|
||||
// Buffer size does not match with necessary size.
|
||||
uint32_t invalid_size_buffer[4] = {
|
||||
0x12345678 /* max value */, 0 /* zero page index */, 0x50 /* index size*/,
|
||||
0x80 /* bitmap size */
|
||||
};
|
||||
EXPECT_FALSE(bitset.initFromBuffer(
|
||||
reinterpret_cast<uint8_t*>(invalid_size_buffer), sizeof(invalid_size_buffer)));
|
||||
|
||||
// max value, index size, bitmap size must be zero if the bitset is empty.
|
||||
uint32_t invalid_empty_bitset1[4] = {
|
||||
1 /* max value */, 0 /* zero page index */, 0 /* index size */, 0 /* bitmap size */
|
||||
};
|
||||
EXPECT_FALSE(bitset.initFromBuffer(
|
||||
reinterpret_cast<uint8_t*>(invalid_empty_bitset1), sizeof(invalid_empty_bitset1)));
|
||||
|
||||
uint32_t invalid_empty_bitset2[4] = {
|
||||
0 /* max value */, 0 /* zero page index */, 1 /* index size */, 0 /* bitmap size */
|
||||
};
|
||||
EXPECT_FALSE(bitset.initFromBuffer(
|
||||
reinterpret_cast<uint8_t*>(invalid_empty_bitset2), sizeof(invalid_empty_bitset2)));
|
||||
|
||||
uint32_t invalid_empty_bitset3[4] = {
|
||||
0 /* max value */, 0 /* zero page index */, 0 /* index size */, 1 /* bitmap size */
|
||||
};
|
||||
EXPECT_FALSE(bitset.initFromBuffer(
|
||||
reinterpret_cast<uint8_t*>(invalid_empty_bitset3), sizeof(invalid_empty_bitset3)));
|
||||
}
|
||||
|
||||
} // namespace minikin
|
||||
|
||||
Reference in New Issue
Block a user