revert 8204 -- what is happening???
authorreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 18 Mar 2013 20:53:49 +0000 (20:53 +0000)
committerreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 18 Mar 2013 20:53:49 +0000 (20:53 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@8205 2bbb7eff-a529-9590-31e7-b0007b416f81

14 files changed:
gyp/core.gyp
gyp/core.gypi
include/core/SkData.h
include/core/SkMMapStream.h [new file with mode: 0644]
include/core/SkPreConfig.h
include/core/SkStream.h
src/core/SkData.cpp
src/core/SkMMapStream.cpp [new file with mode: 0644]
src/core/SkStream.cpp
src/ports/SkFontHost_android.cpp
src/ports/SkFontHost_ascender.cpp
src/ports/SkFontHost_freetype_mac.cpp
src/ports/SkFontHost_linux.cpp
src/ports/SkFontHost_simple.cpp

index 5f99fd911ef4f52887dcca051c1f97426887ef8e..57f31ba566aa9231ce7eb8596c83a8d2eaa684c1 100644 (file)
           'include_dirs': [
             'config/win',
           ],
+          'sources!': [
+            '../include/core/SkMMapStream.h',
+            '../src/core/SkMMapStream.cpp',
+          ],
         }],
         [ 'skia_os in ("android", "nacl")', {
           'dependencies': [
index 23a652acb8a196fa11b33acfe11e75b29612ffdf..3c2be39c05fb5e673e2ec972f0c8c0aa31eda26a 100644 (file)
         '<(skia_src_path)/core/SkMath.cpp',
         '<(skia_src_path)/core/SkMatrix.cpp',
         '<(skia_src_path)/core/SkMetaData.cpp',
+        '<(skia_src_path)/core/SkMMapStream.cpp',
         '<(skia_src_path)/core/SkOrderedReadBuffer.cpp',
         '<(skia_src_path)/core/SkOrderedWriteBuffer.cpp',
         '<(skia_src_path)/core/SkPackBits.cpp',
index 6b09119fc5b3ac42343ba51a3340bbed4575200f..9a0cb09b60bfe17d8a7dc6a7b190fa69fcc4d3fb 100644 (file)
@@ -88,12 +88,6 @@ public:
      */
     static SkData* NewFromMalloc(const void* data, size_t length);
 
-    /**
-     *  Create a new dataref from a pointer allocated by mmap. The Data object
-     *  will handle calling munmap().
-     */
-    static SkData* NewFromMMap(const void* data, size_t length);
-    
     /**
      *  Create a new dataref using a subset of the data in the specified
      *  src dataref.
diff --git a/include/core/SkMMapStream.h b/include/core/SkMMapStream.h
new file mode 100644 (file)
index 0000000..a3b35f2
--- /dev/null
@@ -0,0 +1,30 @@
+
+/*
+ * Copyright 2008 The Android Open Source Project
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#ifndef SkMMapStream_DEFINED
+#define SkMMapStream_DEFINED
+
+#include "SkStream.h"
+
+class SkMMAPStream : public SkMemoryStream {
+public:
+    SkMMAPStream(const char filename[]);
+    virtual ~SkMMAPStream();
+
+    virtual void setMemory(const void* data, size_t length, bool);
+private:
+    void*   fAddr;
+    size_t  fSize;
+
+    void closeMMap();
+
+    typedef SkMemoryStream INHERITED;
+};
+
+#endif
index 11cb2235a71999c9f7cf45123776413acea21429..2246b63f599f239dbd005e35f5299aa5875b3f6c 100644 (file)
 
 //////////////////////////////////////////////////////////////////////
 
-#ifndef SK_MMAP_SUPPORT
-    #ifdef SK_BUILD_FOR_WIN32
-        // by default, if we're windows, we assume we don't have mmap
-        #define SK_MMAP_SUPPORT 0
-    #else
-        #define SK_MMAP_SUPPORT 1
-    #endif
-#endif
-
-//////////////////////////////////////////////////////////////////////
-
 /**
  *  SK_CPU_SSE_LEVEL
  *
index eb0cd4757f12cd51938e5f12b2e600c3346529c9..7e3c1a370bc264946cadf2bdd7f111c03dbdbb9d 100644 (file)
@@ -17,13 +17,6 @@ class SkData;
 
 class SK_API SkStream : public SkRefCnt {
 public:
-    /**
-     *  Attempts to open the specified file, and return a stream to it (using
-     *  mmap if available). On success, the caller must call unref() on the
-     *  returned object. On failure, returns NULL.
-     */
-    static SkStream* NewFromFile(const char path[]);
-    
     SK_DECLARE_INST_COUNT(SkStream)
 
     /** Called to rewind to the beginning of the stream. If this cannot be
index 8fbca7af5fbc00d28b99f7a89660b6363d68dc12..3e0c71a0e863def77767d86f1fa035fecb043387 100644 (file)
@@ -8,13 +8,6 @@
 #include "SkData.h"
 #include "SkFlattenableBuffers.h"
 
-#if SK_MMAP_SUPPORT
-    #include <unistd.h>
-    #include <sys/mman.h>
-    #include <fcntl.h>
-    #include <errno.h>
-#endif
-
 SK_DEFINE_INST_COUNT(SkData)
 
 SkData::SkData(const void* ptr, size_t size, ReleaseProc proc, void* context) {
@@ -127,20 +120,6 @@ SkData* SkData::NewWithCString(const char cstr[]) {
     return NewWithCopy(cstr, size);
 }
 
-#if SK_MMAP_SUPPORT
-static void sk_munmap_releaseproc(const void* addr, size_t length, void*) {
-    munmap(const_cast<void*>(addr), length);
-}
-
-SkData* SkData::NewFromMMap(const void* addr, size_t length) {
-    return SkNEW_ARGS(SkData, (addr, length, sk_munmap_releaseproc, NULL));
-}
-#else
-SkData* SkData::NewFromMMap(const void* addr, size_t length) {
-    return NULL;
-}
-#endif
-
 ///////////////////////////////////////////////////////////////////////////////
 
 void SkData::flatten(SkFlattenableWriteBuffer& buffer) const {
@@ -321,4 +300,3 @@ SkDataSet* SkDataSet::NewEmpty() {
     gEmptySet->ref();
     return gEmptySet;
 }
-
diff --git a/src/core/SkMMapStream.cpp b/src/core/SkMMapStream.cpp
new file mode 100644 (file)
index 0000000..7388e81
--- /dev/null
@@ -0,0 +1,77 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkMMapStream.h"
+
+#include <unistd.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <errno.h>
+
+SkMMAPStream::SkMMAPStream(const char filename[])
+{
+    fAddr = NULL;   // initialize to failure case
+    fSize = 0;
+
+    int fildes = open(filename, O_RDONLY);
+    if (fildes < 0)
+    {
+        SkDEBUGF(("---- failed to open(%s) for mmap stream error=%d\n", filename, errno));
+        return;
+    }
+
+    off_t offset = lseek(fildes, 0, SEEK_END);    // find the file size
+    if (offset == -1)
+    {
+        SkDEBUGF(("---- failed to lseek(%s) for mmap stream error=%d\n", filename, errno));
+        close(fildes);
+        return;
+    }
+    (void)lseek(fildes, 0, SEEK_SET);   // restore file offset to beginning
+
+    // to avoid a 64bit->32bit warning, I explicitly create a size_t size
+    size_t size = static_cast<size_t>(offset);
+
+    void* addr = mmap(NULL, size, PROT_READ, MAP_SHARED, fildes, 0);
+
+    // According to the POSIX documentation of mmap it adds an extra reference
+    // to the file associated with the fildes which is not removed by a
+    // subsequent close() on that fildes. This reference is removed when there
+    // are no more mappings to the file.
+    close(fildes);
+
+    if (MAP_FAILED == addr)
+    {
+        SkDEBUGF(("---- failed to mmap(%s) for mmap stream error=%d\n", filename, errno));
+        return;
+    }
+
+    this->INHERITED::setMemory(addr, size);
+
+    fAddr = addr;
+    fSize = size;
+}
+
+SkMMAPStream::~SkMMAPStream()
+{
+    this->closeMMap();
+}
+
+void SkMMAPStream::setMemory(const void* data, size_t length, bool copyData)
+{
+    this->closeMMap();
+    this->INHERITED::setMemory(data, length, copyData);
+}
+
+void SkMMAPStream::closeMMap()
+{
+    if (fAddr)
+    {
+        munmap(fAddr, fSize);
+        fAddr = NULL;
+    }
+}
index acbcfbc53dc3025b44f466e019f040b18e39675f..fb343ea76a77128a4efe9304488ce1af0d8a7e2c 100644 (file)
 #include "SkString.h"
 #include "SkOSFile.h"
 
-#if SK_MMAP_SUPPORT
-    #include <unistd.h>
-    #include <sys/mman.h>
-    #include <fcntl.h>
-    #include <errno.h>
-    #include <unistd.h>
-#endif
-
 SK_DEFINE_INST_COUNT(SkStream)
 SK_DEFINE_INST_COUNT(SkWStream)
 SK_DEFINE_INST_COUNT(SkFILEStream)
@@ -797,59 +789,3 @@ bool SkDebugWStream::write(const void* buffer, size_t size)
 #endif
     return true;
 }
-
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-
-static bool mmap_filename(const char path[], void** addrPtr, size_t* sizePtr) {
-#if SK_MMAP_SUPPORT
-    int fd = open(path, O_RDONLY);
-    if (fd < 0) {
-        return false;
-    }
-    
-    off_t offset = lseek(fd, 0, SEEK_END);    // find the file size
-    if (offset == -1) {
-        close(fd);
-        return false;
-    }
-    (void)lseek(fd, 0, SEEK_SET);   // restore file offset to beginning
-    
-    // to avoid a 64bit->32bit warning, I explicitly create a size_t size
-    size_t size = static_cast<size_t>(offset);
-    
-    void* addr = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
-    close(fd);
-    
-    if (MAP_FAILED == addr) {
-        return false;
-    }
-    
-    *addrPtr = addr;
-    *sizePtr = size;
-    return true;
-#else
-    return false;
-#endif
-}
-
-SkStream* SkStream::NewFromFile(const char path[]) {
-    void* addr;
-    size_t size;
-    if (mmap_filename(path, &addr, &size)) {
-        SkAutoTUnref<SkData> data(SkData::NewFromMMap(addr, size));
-        if (data.get()) {
-            return SkNEW_ARGS(SkMemoryStream, (data.get()));
-        }
-    }
-    
-    // If we get here, then our attempt at using mmap failed, so try normal
-    // file access.
-    SkFILEStream* stream = SkNEW_ARGS(SkFILEStream, (path));
-    if (!stream->isValid()) {
-        stream->unref();
-        stream = NULL;
-    }
-    return stream;
-}
-
index 416d61d6616e9ec29e2c972ab8d32758760e7f00..e1d6cf471e1684e5549d5e5c1dc8728a08845a47 100644 (file)
@@ -6,10 +6,10 @@
  */
 
 #include "SkFontHost.h"
-#include "SkFontHost_FreeType_common.h"
 #include "SkFontDescriptor.h"
 #include "SkGraphics.h"
 #include "SkDescriptor.h"
+#include "SkMMapStream.h"
 #include "SkPaint.h"
 #include "SkString.h"
 #include "SkStream.h"
@@ -281,11 +281,11 @@ static void remove_from_names(FamilyRec* emptyFamily) {
 
 ///////////////////////////////////////////////////////////////////////////////
 
-class FamilyTypeface : public SkTypeface_FreeType {
+class FamilyTypeface : public SkTypeface {
 public:
     FamilyTypeface(Style style, bool sysFont, SkTypeface* familyMember,
                    bool isFixedWidth)
-    : INHERITED(style, sk_atomic_inc(&gUniqueFontID) + 1, isFixedWidth) {
+    : SkTypeface(style, sk_atomic_inc(&gUniqueFontID) + 1, isFixedWidth) {
         fIsSysFont = sysFont;
 
         // our caller has acquired the gFamilyHeadAndNameListMutex so this is safe
@@ -320,7 +320,7 @@ public:
 private:
     bool    fIsSysFont;
 
-    typedef SkTypeface_FreeType INHERITED;
+    typedef SkTypeface INHERITED;
 };
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -370,19 +370,30 @@ public:
         fPath.set(path);
     }
 
-    virtual SkStream* openStream() SK_OVERRIDE {
-        return SkStream::NewFromFile(fPath.c_str());
+    // overrides
+    virtual SkStream* openStream() {
+        SkStream* stream = SkNEW_ARGS(SkMMAPStream, (fPath.c_str()));
+
+        // check for failure
+        if (stream->getLength() <= 0) {
+            SkDELETE(stream);
+            // maybe MMAP isn't supported. try FILE
+            stream = SkNEW_ARGS(SkFILEStream, (fPath.c_str()));
+            if (stream->getLength() <= 0) {
+                SkDELETE(stream);
+                stream = NULL;
+            }
+        }
+        return stream;
     }
-
-    virtual const char* getUniqueString() const SK_OVERRIDE {
+    virtual const char* getUniqueString() const {
         const char* str = strrchr(fPath.c_str(), '/');
         if (str) {
             str += 1;   // skip the '/'
         }
         return str;
     }
-
-    virtual const char* getFilePath() const SK_OVERRIDE {
+    virtual const char* getFilePath() const {
         return fPath.c_str();
     }
 
@@ -401,15 +412,21 @@ static bool get_name_and_style(const char path[], SkString* name,
     SkString        fullpath;
     GetFullPathForSysFonts(&fullpath, path);
 
-    SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(fullpath.c_str()));
-    if (stream.get()) {
-        return find_name_and_attributes(stream, name, style, isFixedWidth);
-    } else {
-        if (isExpected) {
-            SkDebugf("---- failed to open <%s> as a font", fullpath.c_str());
+    SkMMAPStream stream(fullpath.c_str());
+    if (stream.getLength() > 0) {
+        return find_name_and_attributes(&stream, name, style, isFixedWidth);
+    }
+    else {
+        SkFILEStream stream(fullpath.c_str());
+        if (stream.getLength() > 0) {
+            return find_name_and_attributes(&stream, name, style, isFixedWidth);
         }
-        return false;
     }
+
+    if (isExpected) {
+        SkDebugf("---- failed to open <%s> as a font", fullpath.c_str());
+    }
+    return false;
 }
 
 // used to record our notion of the pre-existing fonts
@@ -867,13 +884,13 @@ size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
     }
 }
 
-SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFontID) {
+SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
 #if defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
     // Skia does not support font fallback for ndk applications in order to
     // enable clients such as WebKit to customize their font selection.
     // Clients can use GetFallbackFamilyNameForChar() to get the fallback
     // font for individual characters.
-    return NULL;
+    return 0;
 #else
     SkAutoMutexAcquire  ac(gFamilyHeadAndNameListMutex);
 
@@ -899,9 +916,9 @@ SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFo
     for (int i = 0; list[i] != 0; i++) {
         if (list[i] == currFontID) {
             if (list[i+1] == 0)
-                return NULL;
+                return 0;
             const SkTypeface* nextTypeface = find_from_uniqueID(list[i+1]);
-            return SkRef(find_typeface(nextTypeface, origTypeface->style()));
+            return find_typeface(nextTypeface, origTypeface->style())->uniqueID();
         }
     }
 
@@ -909,7 +926,7 @@ SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFo
     // beginning of our list. Assuming there is at least one fallback font,
     // i.e. gFallbackFonts[0] != 0.
     const SkTypeface* firstTypeface = find_from_uniqueID(list[0]);
-    return SkRef(find_typeface(firstTypeface, origTypeface->style()));
+    return find_typeface(firstTypeface, origTypeface->style())->uniqueID();
 #endif
 }
 
@@ -935,8 +952,11 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
 }
 
 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
-    SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
-    return stream.get() ? SkFontHost::CreateTypefaceFromStream(stream) : NULL;
+    SkStream* stream = SkNEW_ARGS(SkMMAPStream, (path));
+    SkTypeface* face = SkFontHost::CreateTypefaceFromStream(stream);
+    // since we created the stream, we let go of our ref() here
+    stream->unref();
+    return face;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
index 51210d9642861f92742637ca875b0725358af342..d20cc825cd67614e3a724c676642077a322d8876 100644 (file)
@@ -21,6 +21,8 @@
 
 //////////////////////////////////////////////////////////////////////////
 
+#include "SkMMapStream.h"
+
 class SkScalerContext_Ascender : public SkScalerContext {
 public:
     SkScalerContext_Ascender(const SkDescriptor* desc);
index 3d89bc613aa3e829f48ab2656a9e64d1c9290c5e..bc197d68727042a8a05806789006cd6f781a0bbf 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include "SkFontHost.h"
+#include "SkMMapStream.h"
 #include "SkTypefaceCache.h"
 
 #define FONT_PATH   "/Library/Fonts/Skia.ttf"
@@ -25,11 +26,7 @@ public:
 };
 
 static FTMacTypeface* create_from_path(const char path[]) {
-    SkStream* stream = SkStream::NewFromFile(path);
-    if (!stream) {
-        return NULL;
-    }
-
+    SkStream* stream = new SkMMAPStream(path);
     size_t size = stream->getLength();
     SkASSERT(size);
     FTMacTypeface* tf = new FTMacTypeface(SkTypeface::kNormal,
index 25ae7effe242586a75a15d99401403a735b53ed9..07235c875f07b38d9fd1e99fb1b22be8485a37f4 100644 (file)
@@ -10,6 +10,7 @@
 #include "SkFontHost.h"
 #include "SkFontDescriptor.h"
 #include "SkDescriptor.h"
+#include "SkMMapStream.h"
 #include "SkOSFile.h"
 #include "SkPaint.h"
 #include "SkString.h"
@@ -279,8 +280,8 @@ public:
     EmptyTypeface() : INHERITED(SkTypeface::kNormal, true, NULL, false) {}
 
     // overrides
-    virtual SkStream* openStream() SK_OVERRIDE { return NULL; }
-    virtual const char* getUniqueString() SK_OVERRIDE const { return NULL; }
+    virtual SkStream* openStream() { return NULL; }
+    virtual const char* getUniqueString() const { return NULL; }
 
 private:
     typedef FamilyTypeface INHERITED;
@@ -298,12 +299,14 @@ public:
         fStream->unref();
     }
 
-    virtual SkStream* openStream() SK_OVERRIDE {
+    // overrides
+    virtual SkStream* openStream()
+    {
       // openStream returns a refed stream.
       fStream->ref();
       return fStream;
     }
-    virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; }
+    virtual const char* getUniqueString() const { return NULL; }
 
 private:
     SkStream* fStream;
@@ -319,11 +322,25 @@ public:
         fPath.set(path);
     }
 
-    virtual SkStream* openStream() SK_OVERRIDE {
-        return SkStream::NewFromFile(fPath.c_str());
+    // overrides
+    virtual SkStream* openStream()
+    {
+        SkStream* stream = SkNEW_ARGS(SkMMAPStream, (fPath.c_str()));
+
+        // check for failure
+        if (stream->getLength() <= 0) {
+            SkDELETE(stream);
+            // maybe MMAP isn't supported. try FILE
+            stream = SkNEW_ARGS(SkFILEStream, (fPath.c_str()));
+            if (stream->getLength() <= 0) {
+                SkDELETE(stream);
+                stream = NULL;
+            }
+        }
+        return stream;
     }
 
-    virtual const char* getUniqueString() const SK_OVERRIDE {
+    virtual const char* getUniqueString() const {
         const char* str = strrchr(fPath.c_str(), '/');
         if (str) {
             str += 1;   // skip the '/'
@@ -342,13 +359,19 @@ private:
 
 static bool get_name_and_style(const char path[], SkString* name,
                                SkTypeface::Style* style, bool* isFixedWidth) {
-    SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
-    if (stream.get()) {
-        return find_name_and_attributes(stream, name, style, isFixedWidth);
-    } else {
-        SkDebugf("---- failed to open <%s> as a font\n", path);
-        return false;
+    SkMMAPStream stream(path);
+    if (stream.getLength() > 0) {
+        return find_name_and_attributes(&stream, name, style, isFixedWidth);
+    }
+    else {
+        SkFILEStream stream(path);
+        if (stream.getLength() > 0) {
+            return find_name_and_attributes(&stream, name, style, isFixedWidth);
+        }
     }
+
+    SkDebugf("---- failed to open <%s> as a font\n", path);
+    return false;
 }
 
 // these globals are assigned (once) by load_system_fonts()
index 7d9cf6d7ffdcb973fcf4e7408123da57f66a91de..101d5761d2ba977c187d4929c84e204512152435 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "SkFontHost.h"
 #include "SkDescriptor.h"
+#include "SkMMapStream.h"
 #include "SkPaint.h"
 #include "SkString.h"
 #include "SkStream.h"
@@ -311,18 +312,30 @@ public:
         fPath.set(path);
     }
 
-    virtual SkStream* openStream() SK_OVERRIDE {
-        return SkStream::NewFromFile(fPath.c_str());
+    // overrides
+    virtual SkStream* openStream() {
+        SkStream* stream = SkNEW_ARGS(SkMMAPStream, (fPath.c_str()));
+
+        // check for failure
+        if (stream->getLength() <= 0) {
+            SkDELETE(stream);
+            // maybe MMAP isn't supported. try FILE
+            stream = SkNEW_ARGS(SkFILEStream, (fPath.c_str()));
+            if (stream->getLength() <= 0) {
+                SkDELETE(stream);
+                stream = NULL;
+            }
+        }
+        return stream;
     }
-
-    virtual const char* getUniqueString() const SK_OVERRIDE {
+    virtual const char* getUniqueString() const {
         const char* str = strrchr(fPath.c_str(), '/');
         if (str) {
             str += 1;   // skip the '/'
         }
         return str;
     }
-    virtual const char* getFilePath() const SK_OVERRIDE {
+    virtual const char* getFilePath() const {
         return fPath.c_str();
     }
 
@@ -340,15 +353,21 @@ static bool get_name_and_style(const char path[], SkString* name,
     SkString        fullpath;
     GetFullPathForSysFonts(&fullpath, path);
 
-    SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(fullpath.c_str()));
-    if (stream.get()) {
+    SkMMAPStream stream(fullpath.c_str());
+    if (stream.getLength() > 0) {
         return find_name_and_attributes(&stream, name, style, NULL);
-    } else {
-        if (isExpected) {
-            SkDebugf("---- failed to open <%s> as a font\n", fullpath.c_str());
+    }
+    else {
+        SkFILEStream stream(fullpath.c_str());
+        if (stream.getLength() > 0) {
+            return find_name_and_attributes(&stream, name, style, NULL);
         }
-        return false;
     }
+
+    if (isExpected) {
+        SkDebugf("---- failed to open <%s> as a font\n", fullpath.c_str());
+    }
+    return false;
 }
 
 // used to record our notion of the pre-existing fonts
@@ -394,7 +413,7 @@ static SkTypeface* gDefaultNormal;
     fontIDs that can be used for fallback consideration, in sorted order (sorted
     meaning element[0] should be used first, then element[1], etc. When we hit
     a fontID==0 in the array, the list is done, hence our allocation size is
-    +1 the total number of possible system fonts. Also see NextLogicalTypeface().
+    +1 the total number of possible system fonts. Also see NextLogicalFont().
  */
 static uint32_t gFallbackFonts[SK_ARRAY_COUNT(gSystemFonts)+1];
 
@@ -584,7 +603,7 @@ size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
     }
 }
 
-SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFontID) {
+SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
     load_system_fonts();
 
     /*  First see if fontID is already one of our fallbacks. If so, return
@@ -595,10 +614,10 @@ SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFo
     const uint32_t* list = gFallbackFonts;
     for (int i = 0; list[i] != 0; i++) {
         if (list[i] == currFontID) {
-            return SkSafeRef(find_from_uniqueID(list[i+1]));
+            return list[i+1];
         }
     }
-    return SkSafeRef(list[0]);
+    return list[0];
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -617,6 +636,9 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
 }
 
 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
-    SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
-    return stream.get() ? SkFontHost::CreateTypefaceFromStream(stream) : NULL;
+    SkStream* stream = SkNEW_ARGS(SkMMAPStream, (path));
+    SkTypeface* face = SkFontHost::CreateTypefaceFromStream(stream);
+    // since we created the stream, we let go of our ref() here
+    stream->unref();
+    return face;
 }