OSDN Git Service

Remove obsolete interface GetTable.
authorSeigo Nonaka <nona@google.com>
Tue, 18 Oct 2016 06:10:08 +0000 (15:10 +0900)
committerSeigo Nonaka <nona@google.com>
Thu, 17 Nov 2016 09:26:41 +0000 (18:26 +0900)
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
libs/hwui/hwui/MinikinSkia.h
libs/hwui/hwui/Typeface.cpp

index a52abfc..f172473 100644 (file)
@@ -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();
 }
index 1ea99fd..3ee916c 100644 (file)
@@ -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<SkTypeface> RefSkTypeface() const;
 
index f95d98c..ca43156 100644 (file)
 #include "Typeface.h"
 
 #include <pthread.h>
+#include <fcntl.h>  // For tests.
+#include <sys/stat.h>  // For tests.
+#include <sys/mman.h>  // For tests.
 
 #include "MinikinSkia.h"
 #include "SkTypeface.h"
 #include "SkPaint.h"
+#include "SkStream.h"  // Fot tests.
 
 #include <minikin/FontCollection.h>
 #include <minikin/FontFamily.h>
@@ -116,11 +120,18 @@ void Typeface::setDefault(Typeface* face) {
 
 void Typeface::setRobotoTypefaceForTest() {
     const char* kRobotoFont = "/system/fonts/Roboto-Regular.ttf";
-    sk_sp<SkTypeface> 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<SkMemoryStream> fontData(new SkMemoryStream(data, st.st_size));
+    sk_sp<SkTypeface> 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();