Clean up and rename TypefaceImpl

bug:25865834
Change-Id: I77e8a627163e040a5c25865054a8a936052af367
diff --git a/libs/hwui/Android.mk b/libs/hwui/Android.mk
index 26b4c4e..516591b 100644
--- a/libs/hwui/Android.mk
+++ b/libs/hwui/Android.mk
@@ -16,7 +16,7 @@
     hwui/MinikinSkia.cpp \
     hwui/MinikinUtils.cpp \
     hwui/PaintImpl.cpp \
-    hwui/TypefaceImpl.cpp \
+    hwui/Typeface.cpp \
     renderstate/Blend.cpp \
     renderstate/MeshState.cpp \
     renderstate/OffscreenBufferPool.cpp \
diff --git a/libs/hwui/hwui/Canvas.cpp b/libs/hwui/hwui/Canvas.cpp
index 04e3af6..8c3eea3 100644
--- a/libs/hwui/hwui/Canvas.cpp
+++ b/libs/hwui/hwui/Canvas.cpp
@@ -20,7 +20,7 @@
 #include "RecordingCanvas.h"
 #include "MinikinUtils.h"
 #include "Paint.h"
-#include "TypefaceImpl.h"
+#include "Typeface.h"
 
 #include <SkDrawFilter.h>
 
@@ -147,7 +147,7 @@
 };
 
 void Canvas::drawText(const uint16_t* text, int start, int count, int contextCount,
-        float x, float y, int bidiFlags, const Paint& origPaint, TypefaceImpl* typeface) {
+        float x, float y, int bidiFlags, const Paint& origPaint, Typeface* typeface) {
     // minikin may modify the original paint
     Paint paint(origPaint);
 
@@ -202,7 +202,7 @@
 };
 
 void Canvas::drawTextOnPath(const uint16_t* text, int count, int bidiFlags, const SkPath& path,
-        float hOffset, float vOffset, const Paint& paint, TypefaceImpl* typeface) {
+        float hOffset, float vOffset, const Paint& paint, Typeface* typeface) {
     Paint paintCopy(paint);
     Layout layout;
     MinikinUtils::doLayout(&layout, &paintCopy, bidiFlags, typeface, text, 0, count, count);
diff --git a/libs/hwui/hwui/Canvas.h b/libs/hwui/hwui/Canvas.h
index d5f7053..dc669f0 100644
--- a/libs/hwui/hwui/Canvas.h
+++ b/libs/hwui/hwui/Canvas.h
@@ -60,7 +60,7 @@
 typedef uirenderer::VectorDrawable::Tree VectorDrawableRoot;
 
 class Paint;
-struct TypefaceImpl;
+struct Typeface;
 
 class ANDROID_API Canvas {
 public:
@@ -237,10 +237,10 @@
      * and delegating the final draw to virtual drawGlyphs method.
      */
     void drawText(const uint16_t* text, int start, int count, int contextCount,
-            float x, float y, int bidiFlags, const Paint& origPaint, TypefaceImpl* typeface);
+            float x, float y, int bidiFlags, const Paint& origPaint, Typeface* typeface);
 
     void drawTextOnPath(const uint16_t* text, int count, int bidiFlags, const SkPath& path,
-            float hOffset, float vOffset, const Paint& paint, TypefaceImpl* typeface);
+            float hOffset, float vOffset, const Paint& paint, Typeface* typeface);
 
 protected:
     void drawTextDecorations(float x, float y, float length, const SkPaint& paint);
diff --git a/libs/hwui/hwui/MinikinUtils.cpp b/libs/hwui/hwui/MinikinUtils.cpp
index f4feee2..67b775d 100644
--- a/libs/hwui/hwui/MinikinUtils.cpp
+++ b/libs/hwui/hwui/MinikinUtils.cpp
@@ -17,7 +17,7 @@
 
 #include "Paint.h"
 #include "SkPathMeasure.h"
-#include "TypefaceImpl.h"
+#include "Typeface.h"
 
 #include <cutils/log.h>
 #include <string>
@@ -25,8 +25,8 @@
 namespace android {
 
 FontStyle MinikinUtils::prepareMinikinPaint(MinikinPaint* minikinPaint, FontCollection** pFont,
-        const Paint* paint, TypefaceImpl* typeface) {
-    const TypefaceImpl* resolvedFace = TypefaceImpl_resolveDefault(typeface);
+        const Paint* paint, Typeface* typeface) {
+    const Typeface* resolvedFace = Typeface::resolveDefault(typeface);
     *pFont = resolvedFace->fFontCollection;
     FontStyle resolved = resolvedFace->fStyle;
 
@@ -51,7 +51,7 @@
 }
 
 void MinikinUtils::doLayout(Layout* layout, const Paint* paint, int bidiFlags,
-        TypefaceImpl* typeface, const uint16_t* buf, size_t start, size_t count,
+        Typeface* typeface, const uint16_t* buf, size_t start, size_t count,
         size_t bufSize) {
     FontCollection *font;
     MinikinPaint minikinPaint;
@@ -60,7 +60,7 @@
     layout->doLayout(buf, start, count, bufSize, bidiFlags, minikinStyle, minikinPaint);
 }
 
-float MinikinUtils::measureText(const Paint* paint, int bidiFlags, TypefaceImpl* typeface,
+float MinikinUtils::measureText(const Paint* paint, int bidiFlags, Typeface* typeface,
         const uint16_t* buf, size_t start, size_t count, size_t bufSize, float *advances) {
     FontCollection *font;
     MinikinPaint minikinPaint;
@@ -69,8 +69,8 @@
             font, advances);
 }
 
-bool MinikinUtils::hasVariationSelector(TypefaceImpl* typeface, uint32_t codepoint, uint32_t vs) {
-    const TypefaceImpl* resolvedFace = TypefaceImpl_resolveDefault(typeface);
+bool MinikinUtils::hasVariationSelector(Typeface* typeface, uint32_t codepoint, uint32_t vs) {
+    const Typeface* resolvedFace = Typeface::resolveDefault(typeface);
     return resolvedFace->fFontCollection->hasVariationSelector(codepoint, vs);
 }
 
diff --git a/libs/hwui/hwui/MinikinUtils.h b/libs/hwui/hwui/MinikinUtils.h
index 4a49581..cfaa961 100644
--- a/libs/hwui/hwui/MinikinUtils.h
+++ b/libs/hwui/hwui/MinikinUtils.h
@@ -28,23 +28,23 @@
 #include <minikin/Layout.h>
 #include "Paint.h"
 #include "MinikinSkia.h"
-#include "TypefaceImpl.h"
+#include "Typeface.h"
 
 namespace android {
 
 class MinikinUtils {
 public:
     ANDROID_API static FontStyle prepareMinikinPaint(MinikinPaint* minikinPaint, FontCollection** pFont,
-            const Paint* paint, TypefaceImpl* typeface);
+            const Paint* paint, Typeface* typeface);
 
     ANDROID_API static void doLayout(Layout* layout, const Paint* paint, int bidiFlags,
-            TypefaceImpl* typeface, const uint16_t* buf, size_t start, size_t count,
+            Typeface* typeface, const uint16_t* buf, size_t start, size_t count,
             size_t bufSize);
 
-    ANDROID_API static float measureText(const Paint* paint, int bidiFlags, TypefaceImpl* typeface,
+    ANDROID_API static float measureText(const Paint* paint, int bidiFlags, Typeface* typeface,
             const uint16_t* buf, size_t start, size_t count, size_t bufSize, float *advances);
 
-    ANDROID_API static bool hasVariationSelector(TypefaceImpl* typeface, uint32_t codepoint, uint32_t vs);
+    ANDROID_API static bool hasVariationSelector(Typeface* typeface, uint32_t codepoint, uint32_t vs);
 
     ANDROID_API static float xOffsetForTextAlign(Paint* paint, const Layout& layout);
 
diff --git a/libs/hwui/hwui/TypefaceImpl.cpp b/libs/hwui/hwui/Typeface.cpp
similarity index 81%
rename from libs/hwui/hwui/TypefaceImpl.cpp
rename to libs/hwui/hwui/Typeface.cpp
index f14381b..fa8ad5d 100644
--- a/libs/hwui/hwui/TypefaceImpl.cpp
+++ b/libs/hwui/hwui/Typeface.cpp
@@ -20,7 +20,7 @@
  * being, that choice is hidden under the USE_MINIKIN compile-time flag.
  */
 
-#include "TypefaceImpl.h"
+#include "Typeface.h"
 
 #include "MinikinSkia.h"
 #include "SkTypeface.h"
@@ -34,7 +34,7 @@
 namespace android {
 
 // Resolve the 1..9 weight based on base weight and bold flag
-static void resolveStyle(TypefaceImpl* typeface) {
+static void resolveStyle(Typeface* typeface) {
     int weight = typeface->fBaseWeight / 100;
     if (typeface->fSkiaStyle & SkTypeface::kBold) {
         weight += 3;
@@ -46,7 +46,7 @@
     typeface->fStyle = FontStyle(weight, italic);
 }
 
-TypefaceImpl* gDefaultTypeface = NULL;
+Typeface* gDefaultTypeface = NULL;
 pthread_once_t gDefaultTypefaceOnce = PTHREAD_ONCE_INIT;
 
 // This installs a default typeface (from a hardcoded path) that allows
@@ -85,7 +85,7 @@
     if (gDefaultTypeface == NULL) {
         // We expect the client to set a default typeface, but provide a
         // default so we can make progress before that happens.
-        gDefaultTypeface = new TypefaceImpl;
+        gDefaultTypeface = new Typeface;
         gDefaultTypeface->fFontCollection = makeFontCollection();
         gDefaultTypeface->fSkiaStyle = SkTypeface::kNormal;
         gDefaultTypeface->fBaseWeight = 400;
@@ -93,7 +93,7 @@
     }
 }
 
-TypefaceImpl* TypefaceImpl_resolveDefault(TypefaceImpl* src) {
+Typeface* Typeface::resolveDefault(Typeface* src) {
     if (src == NULL) {
         pthread_once(&gDefaultTypefaceOnce, getDefaultTypefaceOnce);
         return gDefaultTypeface;
@@ -102,9 +102,9 @@
     }
 }
 
-TypefaceImpl* TypefaceImpl_createFromTypeface(TypefaceImpl* src, SkTypeface::Style style) {
-    TypefaceImpl* resolvedFace = TypefaceImpl_resolveDefault(src);
-    TypefaceImpl* result = new TypefaceImpl;
+Typeface* Typeface::createFromTypeface(Typeface* src, SkTypeface::Style style) {
+    Typeface* resolvedFace = Typeface::resolveDefault(src);
+    Typeface* result = new Typeface;
     if (result != 0) {
         result->fFontCollection = resolvedFace->fFontCollection;
         result->fFontCollection->Ref();
@@ -115,9 +115,9 @@
     return result;
 }
 
-TypefaceImpl* TypefaceImpl_createWeightAlias(TypefaceImpl* src, int weight) {
-    TypefaceImpl* resolvedFace = TypefaceImpl_resolveDefault(src);
-    TypefaceImpl* result = new TypefaceImpl;
+Typeface* Typeface::createWeightAlias(Typeface* src, int weight) {
+    Typeface* resolvedFace = Typeface::resolveDefault(src);
+    Typeface* result = new Typeface;
     if (result != 0) {
         result->fFontCollection = resolvedFace->fFontCollection;
         result->fFontCollection->Ref();
@@ -128,8 +128,8 @@
     return result;
 }
 
-TypefaceImpl* TypefaceImpl_createFromFamilies(const std::vector<FontFamily*>& families) {
-    TypefaceImpl* result = new TypefaceImpl;
+Typeface* Typeface::createFromFamilies(const std::vector<FontFamily*>& families) {
+    Typeface* result = new Typeface;
     result->fFontCollection = new FontCollection(families);
     if (families.empty()) {
         ALOGW("createFromFamilies creating empty collection");
@@ -152,18 +152,12 @@
     return result;
 }
 
-void TypefaceImpl_unref(TypefaceImpl* face) {
-    if (face != NULL) {
-        face->fFontCollection->Unref();
-    }
-    delete face;
+void Typeface::unref() {
+    fFontCollection->Unref();
+    delete this;
 }
 
-int TypefaceImpl_getStyle(TypefaceImpl* face) {
-    return face->fSkiaStyle;
-}
-
-void TypefaceImpl_setDefault(TypefaceImpl* face) {
+void Typeface::setDefault(Typeface* face) {
     gDefaultTypeface = face;
 }
 
diff --git a/libs/hwui/hwui/Typeface.h b/libs/hwui/hwui/Typeface.h
new file mode 100644
index 0000000..8862e5a
--- /dev/null
+++ b/libs/hwui/hwui/Typeface.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef _ANDROID_GRAPHICS_TYPEFACE_IMPL_H_
+#define _ANDROID_GRAPHICS_TYPEFACE_IMPL_H_
+
+#include "SkTypeface.h"
+
+#include <cutils/compiler.h>
+#include <minikin/FontCollection.h>
+#include <vector>
+
+namespace android {
+
+struct ANDROID_API Typeface {
+    FontCollection *fFontCollection;
+
+    // style used for constructing and querying Typeface objects
+    SkTypeface::Style fSkiaStyle;
+    // base weight in CSS-style units, 100..900
+    int fBaseWeight;
+
+    // resolved style actually used for rendering
+    FontStyle fStyle;
+
+    void unref();
+
+    static Typeface* resolveDefault(Typeface* src);
+
+    static Typeface* createFromTypeface(Typeface* src, SkTypeface::Style style);
+
+    static Typeface* createWeightAlias(Typeface* src, int baseweight);
+
+    static Typeface* createFromFamilies(const std::vector<FontFamily*>& families);
+
+    static void setDefault(Typeface* face);
+};
+
+}
+
+#endif  // _ANDROID_GRAPHICS_TYPEFACE_IMPL_H_
diff --git a/libs/hwui/hwui/TypefaceImpl.h b/libs/hwui/hwui/TypefaceImpl.h
deleted file mode 100644
index 01f1e83..0000000
--- a/libs/hwui/hwui/TypefaceImpl.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef _ANDROID_GRAPHICS_TYPEFACE_IMPL_H_
-#define _ANDROID_GRAPHICS_TYPEFACE_IMPL_H_
-
-#include "SkTypeface.h"
-
-#include <cutils/compiler.h>
-#include <minikin/FontCollection.h>
-#include <vector>
-
-namespace android {
-
-struct ANDROID_API TypefaceImpl {
-    FontCollection *fFontCollection;
-
-    // style used for constructing and querying Typeface objects
-    SkTypeface::Style fSkiaStyle;
-    // base weight in CSS-style units, 100..900
-    int fBaseWeight;
-
-    // resolved style actually used for rendering
-    FontStyle fStyle;
-};
-
-// Note: it would be cleaner if the following functions were member
-// functions (static or otherwise) of the TypefaceImpl class. However,
-// that can't be easily accommodated in the case where TypefaceImpl
-// is just a pointer to SkTypeface, in the non-USE_MINIKIN case.
-// TODO: when #ifdef USE_MINIKIN is removed, move to member functions.
-
-ANDROID_API TypefaceImpl* TypefaceImpl_resolveDefault(TypefaceImpl* src);
-
-ANDROID_API TypefaceImpl* TypefaceImpl_createFromTypeface(TypefaceImpl* src, SkTypeface::Style style);
-
-ANDROID_API TypefaceImpl* TypefaceImpl_createWeightAlias(TypefaceImpl* src, int baseweight);
-
-ANDROID_API TypefaceImpl* TypefaceImpl_createFromFamilies(const std::vector<FontFamily*>& families);
-
-ANDROID_API void TypefaceImpl_unref(TypefaceImpl* face);
-
-ANDROID_API int TypefaceImpl_getStyle(TypefaceImpl* face);
-
-ANDROID_API void TypefaceImpl_setDefault(TypefaceImpl* face);
-
-}
-
-#endif  // _ANDROID_GRAPHICS_TYPEFACE_IMPL_H_