From b7e33a09843302c578e433a06e56583f0ff241d2 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 18 Oct 2016 15:10:08 +0900 Subject: [PATCH] Remove obsolete interface GetTable. GetTable is only used in test. To use production interface, need to pass the raw buffer and size to the MinikinSkia. This CL does not change any production behaviors. Test: ran hwui microbench, macrobench, hwui_unit_tests Change-Id: Ia657a0d061984d705f333ed3944effb1eba8ca4d --- libs/hwui/hwui/MinikinSkia.cpp | 17 ----------------- libs/hwui/hwui/MinikinSkia.h | 2 -- libs/hwui/hwui/Typeface.cpp | 15 +++++++++++++-- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/libs/hwui/hwui/MinikinSkia.cpp b/libs/hwui/hwui/MinikinSkia.cpp index a52abfc9888a5..f172473d16524 100644 --- a/libs/hwui/hwui/MinikinSkia.cpp +++ b/libs/hwui/hwui/MinikinSkia.cpp @@ -65,23 +65,6 @@ void MinikinFontSkia::GetBounds(minikin::MinikinRect* bounds, uint32_t glyph_id, bounds->mBottom = skBounds.fBottom; } -const void* MinikinFontSkia::GetTable(uint32_t tag, size_t* size, - minikin::MinikinDestroyFunc* destroy) { - // we don't have a buffer to the font data, copy to own buffer - const size_t tableSize = mTypeface->getTableSize(tag); - *size = tableSize; - if (tableSize == 0) { - return nullptr; - } - void* buf = malloc(tableSize); - if (buf == nullptr) { - return nullptr; - } - mTypeface->getTableData(tag, 0, tableSize, buf); - *destroy = free; - return buf; -} - SkTypeface *MinikinFontSkia::GetSkTypeface() const { return mTypeface.get(); } diff --git a/libs/hwui/hwui/MinikinSkia.h b/libs/hwui/hwui/MinikinSkia.h index 1ea99fd899a95..3ee916c6e8b11 100644 --- a/libs/hwui/hwui/MinikinSkia.h +++ b/libs/hwui/hwui/MinikinSkia.h @@ -37,8 +37,6 @@ public: void GetBounds(minikin::MinikinRect* bounds, uint32_t glyph_id, const minikin::MinikinPaint &paint) const; - const void* GetTable(uint32_t tag, size_t* size, minikin::MinikinDestroyFunc* destroy); - SkTypeface* GetSkTypeface() const; sk_sp RefSkTypeface() const; diff --git a/libs/hwui/hwui/Typeface.cpp b/libs/hwui/hwui/Typeface.cpp index f95d98cac8d66..ca43156e88a15 100644 --- a/libs/hwui/hwui/Typeface.cpp +++ b/libs/hwui/hwui/Typeface.cpp @@ -23,10 +23,14 @@ #include "Typeface.h" #include +#include // For tests. +#include // For tests. +#include // For tests. #include "MinikinSkia.h" #include "SkTypeface.h" #include "SkPaint.h" +#include "SkStream.h" // Fot tests. #include #include @@ -116,11 +120,18 @@ void Typeface::setDefault(Typeface* face) { void Typeface::setRobotoTypefaceForTest() { const char* kRobotoFont = "/system/fonts/Roboto-Regular.ttf"; - sk_sp typeface = SkTypeface::MakeFromFile(kRobotoFont); + + int fd = open(kRobotoFont, O_RDONLY); + LOG_ALWAYS_FATAL_IF(fd == -1, "Failed to open file %s", kRobotoFont); + struct stat st = {}; + LOG_ALWAYS_FATAL_IF(fstat(fd, &st) == -1, "Failed to stat file %s", kRobotoFont); + void* data = mmap(nullptr, st.st_size, PROT_READ, MAP_SHARED, fd, 0); + std::unique_ptr fontData(new SkMemoryStream(data, st.st_size)); + sk_sp typeface = SkTypeface::MakeFromStream(fontData.release()); LOG_ALWAYS_FATAL_IF(typeface == nullptr, "Failed to make typeface from %s", kRobotoFont); minikin::FontFamily* family = new minikin::FontFamily(); - minikin::MinikinFont* font = new MinikinFontSkia(std::move(typeface), nullptr, 0, 0); + minikin::MinikinFont* font = new MinikinFontSkia(std::move(typeface), data, st.st_size, 0); family->addFont(font); font->Unref();