From 6a5534a4373d441cae6f61663115fd784ba57b6d Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Wed, 22 Mar 2017 15:58:46 -0700 Subject: [PATCH] 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 --- .../src/flutter/include/minikin/FontFamily.h | 24 ------ .../flutter/include/minikin/SparseBitSet.h | 11 --- .../src/flutter/libs/minikin/FontFamily.cpp | 62 -------------- .../src/flutter/libs/minikin/SparseBitSet.cpp | 67 --------------- .../flutter/tests/perftests/FontFamily.cpp | 19 ----- .../flutter/tests/unittest/FontFamilyTest.cpp | 46 ---------- .../tests/unittest/SparseBitSetTest.cpp | 85 ------------------- 7 files changed, 314 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 18a75ee8ec..babed732f5 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -126,23 +126,6 @@ public: FontFamily(int variant, std::vector&& fonts); FontFamily(uint32_t langId, int variant, std::vector&& fonts); - // The accelerator table won't be copied. Do not release the memory until the created FontFamily - // is destructed. - FontFamily(std::vector&& fonts, const uint8_t* acceleratorTable, size_t tableSize); - FontFamily(int variant, std::vector&& fonts, const uint8_t* acceleratorTable, - size_t tableSize); - FontFamily(uint32_t langId, int variant, std::vector&& 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& 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; diff --git a/engine/src/flutter/include/minikin/SparseBitSet.h b/engine/src/flutter/include/minikin/SparseBitSet.h index 491e68ae7f..ba9d7797fb 100644 --- a/engine/src/flutter/include/minikin/SparseBitSet.h +++ b/engine/src/flutter/include/minikin/SparseBitSet.h @@ -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; diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 076dff2bcc..492db1e4f4 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -109,25 +109,6 @@ FontFamily::FontFamily(uint32_t langId, int variant, std::vector&& fonts) computeCoverage(); } -FontFamily::FontFamily(std::vector&& fonts, const uint8_t* acceleratorTable, size_t tableSize) - : FontFamily(0 /* variant */, std::move(fonts), acceleratorTable, tableSize) { -} - -FontFamily::FontFamily(int variant, std::vector&& 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&& 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& typeface, int* weight, bool* italic) { android::AutoMutex _l(gMinikinLock); @@ -263,47 +244,4 @@ std::shared_ptr FontFamily::createFamilyWithVariation( return std::shared_ptr(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(mSupportedAxes.size()); - if (out != nullptr) { - out[0] = axesCount; - AxisTag* axisTags = reinterpret_cast(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(in + 1); - mSupportedAxes.clear(); - for (uint8_t i = 0; i < axesCount; ++i) { - mSupportedAxes.insert(axisTags[i]); - } - return totalSize; -} } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/SparseBitSet.cpp b/engine/src/flutter/libs/minikin/SparseBitSet.cpp index a95af4d716..51557df9af 100644 --- a/engine/src/flutter/libs/minikin/SparseBitSet.cpp +++ b/engine/src/flutter/libs/minikin/SparseBitSet.cpp @@ -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(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(data); - data += indicesSizeInBytes; - mBitmaps = reinterpret_cast(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(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); diff --git a/engine/src/flutter/tests/perftests/FontFamily.cpp b/engine/src/flutter/tests/perftests/FontFamily.cpp index a731ef640f..9ab61e1fa7 100644 --- a/engine/src/flutter/tests/perftests/FontFamily.cpp +++ b/engine/src/flutter/tests/perftests/FontFamily.cpp @@ -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 minikinFont = - std::make_shared("/system/fonts/NotoSansCJK-Regular.ttc", 0); - - std::shared_ptr family = std::make_shared( - std::vector({Font(minikinFont, FontStyle())})); - - size_t bufSize = family->writeAcceleratorTable(nullptr); - std::unique_ptr buffer(new uint8_t[bufSize]); - family->writeAcceleratorTable(buffer.get()); - - while (state.KeepRunning()) { - std::shared_ptr family = std::make_shared( - std::vector({Font(minikinFont, FontStyle())}), buffer.get(), bufSize); - } -} - -BENCHMARK(BM_FontFamily_create_fromBuffer); - } // namespace minikin diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 0769aa4312..90cc794083 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -656,50 +656,4 @@ TEST_F(FontFamilyTest, createFamilyWithVariationTest) { } } -TEST_F(FontFamilyTest, supportedAxesRestoreFromSerializedBuffer) { - const char kFontPath[] = kTestFontDir "/MultiAxis.ttf"; - - std::shared_ptr font(new MinikinFontForTest(kFontPath)); - std::shared_ptr family = - std::make_shared(std::vector({Font(font, FontStyle())})); - - size_t necessaryBytes = family->writeAcceleratorTable(nullptr); - ASSERT_NE(0U, necessaryBytes); - std::vector buffer; - buffer.resize(necessaryBytes); - family->writeAcceleratorTable(buffer.data()); - - std::shared_ptr restoredMultiAxisFamily = - std::make_shared(std::vector({Font(font, FontStyle())}), - buffer.data(), buffer.size()); - - // This font has 'wdth' and 'wght' axes. - const std::unordered_set& 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 font(new MinikinFontForTest(kFontPath)); - std::shared_ptr family = - std::make_shared(std::vector({Font(font, FontStyle())})); - - size_t necessaryBytes = family->writeAcceleratorTable(nullptr); - ASSERT_NE(0U, necessaryBytes); - std::vector buffer; - buffer.resize(necessaryBytes); - family->writeAcceleratorTable(buffer.data()); - - std::shared_ptr restoredMultiAxisFamily = - std::make_shared(std::vector({Font(font, FontStyle())}), - buffer.data(), buffer.size()); - - // This font supports no axes. - const std::unordered_set& supportedAxes = family->supportedAxes(); - EXPECT_TRUE(supportedAxes.empty()); -} - } // namespace minikin diff --git a/engine/src/flutter/tests/unittest/SparseBitSetTest.cpp b/engine/src/flutter/tests/unittest/SparseBitSetTest.cpp index ab38f6ca75..cfb437f3f5 100644 --- a/engine/src/flutter/tests/unittest/SparseBitSetTest.cpp +++ b/engine/src/flutter/tests/unittest/SparseBitSetTest.cpp @@ -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 distribution(1, 512); - - std::vector 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 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(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(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(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(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(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(invalid_empty_bitset3), sizeof(invalid_empty_bitset3))); -} - } // namespace minikin