Update framework to use M34 version of Skia.

These changes are needed due to changes in the Skia API.

Depends on https://googleplex-android-review.git.corp.google.com/#/c/439626/1
(Ic3cf846b74d6f10ec30c477b50fd774cc30ad52c)

BitmapFactory.cpp:
Use SkColorType instead of SkBitmap::Config, where possible.
Call SkBitmap::info() instead of deprecated SkBitmap::asImageInfo().
Remove calls to deprecated SkBitmap::getSize64().

Canvas.cpp:
ColorFilter.cpp:
Matrix.cpp
Remove the deprecated SK_SCALAR_IS_FIXED path. Leave in an else case for
SK_SCALAR_IS_FLOAT, to allow for eventual SK_SCALAR_IS_DOUBLE path.

Graphics.cpp:
Like in BitmapFactory.cpp, use new methods for determining the size of
pixels.

Paint.cpp:
Use more precise SkScalar_ToInt versions of macros.

TextLayoutCache.cpp:
Fix bug in macro definition for HB_SurrogateToUcs4.
Use the new name for SkCreateTypefaceForScriptNG.

android_view_SurfaceControl.cpp:
Replace ScreenshotPixelRef with a Skia pixel ref.

This is a merge from master-skia branch:
https://googleplex-android-review.git.corp.google.com/#/c/430554/
(Ie11503bcefd3883c466279fde5ce147c8a72b452)

Change-Id: Idf15746f93dabeb7862ac02cc6bd925f0dcc68ba
diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp
index 2b9a5c4..b89dced 100644
--- a/core/jni/android/graphics/BitmapFactory.cpp
+++ b/core/jni/android/graphics/BitmapFactory.cpp
@@ -7,6 +7,7 @@
 #include "SkImageDecoder.h"
 #include "SkImageRef_ashmem.h"
 #include "SkImageRef_GlobalPool.h"
+#include "SkMath.h"
 #include "SkPixelRef.h"
 #include "SkStream.h"
 #include "SkTemplates.h"
@@ -146,15 +147,15 @@
     return pr;
 }
 
-static SkBitmap::Config configForScaledOutput(SkBitmap::Config config) {
-    switch (config) {
-        case SkBitmap::kNo_Config:
-        case SkBitmap::kIndex8_Config:
-            return SkBitmap::kARGB_8888_Config;
+static SkColorType colorTypeForScaledOutput(SkColorType colorType) {
+    switch (colorType) {
+        case kUnknown_SkColorType:
+        case kIndex_8_SkColorType:
+            return kPMColor_SkColorType;
         default:
             break;
     }
-    return config;
+    return colorType;
 }
 
 class ScaleCheckingAllocator : public SkBitmap::HeapAllocator {
@@ -165,8 +166,8 @@
 
     virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
         // accounts for scale in final allocation, using eventual size and config
-        const int bytesPerPixel = SkBitmap::ComputeBytesPerPixel(
-                configForScaledOutput(bitmap->config()));
+        const int bytesPerPixel = SkColorTypeBytesPerPixel(
+                colorTypeForScaledOutput(bitmap->colorType()));
         const int requestedSize = bytesPerPixel *
                 int(bitmap->width() * mScale + 0.5f) *
                 int(bitmap->height() * mScale + 0.5f);
@@ -194,21 +195,28 @@
     }
 
     virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
-        if (!bitmap->getSize64().is32() || bitmap->getSize() > mSize) {
-            ALOGW("bitmap marked for reuse (%d bytes) can't fit new bitmap (%d bytes)",
-                    mSize, bitmap->getSize());
+        const SkImageInfo& info = bitmap->info();
+        if (info.fColorType == kUnknown_SkColorType) {
+            ALOGW("unable to reuse a bitmap as the target has an unknown bitmap configuration");
             return false;
         }
 
-        SkImageInfo bitmapInfo;
-        if (!bitmap->asImageInfo(&bitmapInfo)) {
-            ALOGW("unable to reuse a bitmap as the target has an unknown bitmap configuration");
+        const int64_t size64 = info.getSafeSize64(bitmap->rowBytes());
+        if (!sk_64_isS32(size64)) {
+            ALOGW("bitmap is too large");
+            return false;
+        }
+
+        const size_t size = sk_64_asS32(size64);
+        if (size > mSize) {
+            ALOGW("bitmap marked for reuse (%d bytes) can't fit new bitmap (%d bytes)",
+                    mSize, size);
             return false;
         }
 
         // Create a new pixelref with the new ctable that wraps the previous pixelref
         SkPixelRef* pr = new AndroidPixelRef(*static_cast<AndroidPixelRef*>(mPixelRef),
-                bitmapInfo, bitmap->rowBytes(), ctable);
+                info, bitmap->rowBytes(), ctable);
 
         bitmap->setPixelRef(pr)->unref();
         // since we're already allocated, we lockPixels right away
@@ -416,12 +424,12 @@
         const float sy = scaledHeight / float(decodingBitmap.height());
 
         // TODO: avoid copying when scaled size equals decodingBitmap size
-        SkBitmap::Config config = configForScaledOutput(decodingBitmap.config());
+        SkColorType colorType = colorTypeForScaledOutput(decodingBitmap.colorType());
         // FIXME: If the alphaType is kUnpremul and the image has alpha, the
         // colors may not be correct, since Skia does not yet support drawing
         // to/from unpremultiplied bitmaps.
-        outputBitmap->setConfig(config, scaledWidth, scaledHeight, 0,
-                                decodingBitmap.alphaType());
+        outputBitmap->setConfig(SkImageInfo::Make(scaledWidth, scaledHeight,
+                colorType, decodingBitmap.alphaType()));
         if (!outputBitmap->allocPixels(outputAllocator, NULL)) {
             return nullObjectReturn("allocation failed for scaled bitmap");
         }
diff --git a/core/jni/android/graphics/Canvas.cpp b/core/jni/android/graphics/Canvas.cpp
index 7420055..946b898 100644
--- a/core/jni/android/graphics/Canvas.cpp
+++ b/core/jni/android/graphics/Canvas.cpp
@@ -680,9 +680,6 @@
             indices [ptCount * sizeof(uint16_t)]
         */
         ssize_t storageSize = ptCount * sizeof(SkPoint); // texs[]
-#ifdef SK_SCALAR_IS_FIXED
-        storageSize += ptCount * sizeof(SkPoint);  // storage for verts
-#endif
         storageSize += indexCount * sizeof(uint16_t);  // indices[]
 
         SkAutoMalloc storage(storageSize);
@@ -693,16 +690,7 @@
         verts = (SkPoint*)(vertA.ptr() + vertIndex);
         indices = (uint16_t*)(texs + ptCount);
 #else
-        verts = texs + ptCount;
-        indices = (uint16_t*)(verts + ptCount);
-        // convert floats to fixed
-        {
-            const float* src = vertA.ptr() + vertIndex;
-            for (int i = 0; i < ptCount; i++) {
-                verts[i].set(SkFloatToFixed(src[0]), SkFloatToFixed(src[1]));
-                src += 2;
-            }
-        }
+        SkASSERT(false);
 #endif
 
         // cons up texture coordinates and indices
@@ -804,25 +792,7 @@
             texs = (SkPoint*)(texA.ptr() + texIndex);
         }
 #else
-        int count = ptCount;    // for verts
-        if (jtexs != NULL) {
-            count += ptCount;   // += for texs
-        }
-        SkAutoMalloc storage(count * sizeof(SkPoint));
-        verts = (SkPoint*)storage.get();
-        const float* src = vertA.ptr() + vertIndex;
-        for (int i = 0; i < ptCount; i++) {
-            verts[i].set(SkFloatToFixed(src[0]), SkFloatToFixed(src[1]));
-            src += 2;
-        }
-        if (jtexs != NULL) {
-            texs = verts + ptCount;
-            src = texA.ptr() + texIndex;
-            for (int i = 0; i < ptCount; i++) {
-                texs[i].set(SkFloatToFixed(src[0]), SkFloatToFixed(src[1]));
-                src += 2;
-            }
-        }
+        SkASSERT(false);
 #endif
 
         const SkColor* colors = NULL;
diff --git a/core/jni/android/graphics/ColorFilter.cpp b/core/jni/android/graphics/ColorFilter.cpp
index 09589bd..a59ed19 100644
--- a/core/jni/android/graphics/ColorFilter.cpp
+++ b/core/jni/android/graphics/ColorFilter.cpp
@@ -50,14 +50,10 @@
         AutoJavaFloatArray autoArray(env, jarray, 20);
         const float* src = autoArray.ptr();
 
-#ifdef SK_SCALAR_IS_FIXED
-        SkFixed array[20];
-        for (int i = 0; i < 20; i++) {
-            array[i] = SkFloatToScalar(src[i]);
-        }
-        return reinterpret_cast<jlong>(new SkColorMatrixFilter(array));
-#else
+#ifdef SK_SCALAR_IS_FLOAT
         return reinterpret_cast<jlong>(new SkColorMatrixFilter(src));
+#else
+        SkASSERT(false);
 #endif
     }
 };
diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp
index 98edbdb..2883be9 100644
--- a/core/jni/android/graphics/Graphics.cpp
+++ b/core/jni/android/graphics/Graphics.cpp
@@ -6,6 +6,7 @@
 
 #include "SkCanvas.h"
 #include "SkDevice.h"
+#include "SkMath.h"
 #include "SkPicture.h"
 #include "SkRegion.h"
 #include <android_runtime/AndroidRuntime.h>
@@ -564,21 +565,20 @@
 
 jbyteArray GraphicsJNI::allocateJavaPixelRef(JNIEnv* env, SkBitmap* bitmap,
                                              SkColorTable* ctable) {
-    Sk64 size64 = bitmap->getSize64();
-    if (size64.isNeg() || !size64.is32()) {
-        jniThrowException(env, "java/lang/IllegalArgumentException",
-                          "bitmap size exceeds 32bits");
+    const SkImageInfo& info = bitmap->info();
+    if (info.fColorType == kUnknown_SkColorType) {
+        doThrowIAE(env, "unknown bitmap configuration");
         return NULL;
     }
 
-    SkImageInfo bitmapInfo;
-    if (!bitmap->asImageInfo(&bitmapInfo)) {
-        jniThrowException(env, "java/lang/IllegalArgumentException",
-                "unknown bitmap configuration");
+    const int64_t size64 = info.getSafeSize64(bitmap->rowBytes());
+    if (!sk_64_isS32(size64)) {
+        doThrowIAE(env, "bitmap size exceeds 32bits");
         return NULL;
     }
+    const size_t size = sk_64_asS32(size64);
+    SkASSERT(size == info.getSafeSize(bitmap->rowBytes()));
 
-    size_t size = size64.get32();
     jbyteArray arrayObj = (jbyteArray) env->CallObjectMethod(gVMRuntime,
                                                              gVMRuntime_newNonMovableArray,
                                                              gByte_class, size);
@@ -591,7 +591,7 @@
         return NULL;
     }
     SkASSERT(addr);
-    SkPixelRef* pr = new AndroidPixelRef(env, bitmapInfo, (void*) addr,
+    SkPixelRef* pr = new AndroidPixelRef(env, info, (void*) addr,
             bitmap->rowBytes(), arrayObj, ctable);
     bitmap->setPixelRef(pr)->unref();
     // since we're already allocated, we lockPixels right away
diff --git a/core/jni/android/graphics/Matrix.cpp b/core/jni/android/graphics/Matrix.cpp
index 6ae9fea..c400c57 100644
--- a/core/jni/android/graphics/Matrix.cpp
+++ b/core/jni/android/graphics/Matrix.cpp
@@ -272,18 +272,11 @@
         float* dst = autoDst.ptr() + dstIndex;
         bool result;
 
-#ifdef SK_SCALAR_IS_FIXED        
-        SkPoint srcPt[4], dstPt[4];
-        for (int i = 0; i < ptCount; i++) {
-            int x = i << 1;
-            int y = x + 1;
-            srcPt[i].set(SkFloatToScalar(src[x]), SkFloatToScalar(src[y]));
-            dstPt[i].set(SkFloatToScalar(dst[x]), SkFloatToScalar(dst[y]));
-        }
-        result = matrix->setPolyToPoly(srcPt, dstPt, ptCount);
-#else
+#ifdef SK_SCALAR_IS_FLOAT
         result = matrix->setPolyToPoly((const SkPoint*)src, (const SkPoint*)dst,
                                      ptCount);
+#else
+        SkASSERT(false);
 #endif
         return result ? JNI_TRUE : JNI_FALSE;
     }
@@ -304,36 +297,15 @@
         AutoJavaFloatArray autoDst(env, dst, dstIndex + (ptCount << 1), kRW_JNIAccess);
         float* srcArray = autoSrc.ptr() + srcIndex;
         float* dstArray = autoDst.ptr() + dstIndex;
-        
-#ifdef SK_SCALAR_IS_FIXED        
-        // we allocate twice the count, 1 set for src, 1 for dst
-        SkAutoSTMalloc<32, SkPoint> storage(ptCount * 2);
-        SkPoint* pts = storage.get();
-        SkPoint* srcPt = pts;
-        SkPoint* dstPt = pts + ptCount;
-        
-        int i;
-        for (i = 0; i < ptCount; i++) {
-            srcPt[i].set(SkFloatToScalar(srcArray[i << 1]),
-                         SkFloatToScalar(srcArray[(i << 1) + 1]));
-        }
-        
-        if (isPts)
-            matrix->mapPoints(dstPt, srcPt, ptCount);
-        else
-            matrix->mapVectors(dstPt, srcPt, ptCount);
-        
-        for (i = 0; i < ptCount; i++) {
-            dstArray[i << 1]  = SkScalarToFloat(dstPt[i].fX);
-            dstArray[(i << 1) + 1]  = SkScalarToFloat(dstPt[i].fY);
-        }
-#else
+#ifdef SK_SCALAR_IS_FLOAT
         if (isPts)
             matrix->mapPoints((SkPoint*)dstArray, (const SkPoint*)srcArray,
                               ptCount);
         else
             matrix->mapVectors((SkVector*)dstArray, (const SkVector*)srcArray,
                                ptCount);
+#else
+        SkASSERT(false);
 #endif
     }
 
@@ -356,18 +328,12 @@
         SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
         AutoJavaFloatArray autoValues(env, values, 9, kRW_JNIAccess);
         float* dst = autoValues.ptr();
-
-#ifdef SK_SCALAR_IS_FIXED
-        for (int i = 0; i < 6; i++) {
-            dst[i] = SkFixedToFloat(matrix->get(i));
-        }
-        for (int j = 6; j < 9; j++) {
-            dst[j] = SkFractToFloat(matrix->get(j));
-        }
-#else
+#ifdef SK_SCALAR_IS_FLOAT
         for (int i = 0; i < 9; i++) {
             dst[i] = matrix->get(i);
         }
+#else
+        SkASSERT(false);
 #endif
     }
 
@@ -376,17 +342,12 @@
         AutoJavaFloatArray autoValues(env, values, 9, kRO_JNIAccess);
         const float* src = autoValues.ptr();
 
-#ifdef SK_SCALAR_IS_FIXED
-        for (int i = 0; i < 6; i++) {
-            matrix->set(i, SkFloatToFixed(src[i]));
-        }
-        for (int j = 6; j < 9; j++) {
-            matrix->set(j, SkFloatToFract(src[j]));
-        }
-#else
+#ifdef SK_SCALAR_IS_FLOAT
         for (int i = 0; i < 9; i++) {
             matrix->set(i, src[i]);
         }
+#else
+        SkASSERT(false);
 #endif
     }
 
diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp
index 51990d5..1167bfe 100644
--- a/core/jni/android/graphics/Paint.cpp
+++ b/core/jni/android/graphics/Paint.cpp
@@ -422,16 +422,16 @@
         SkPaint::FontMetrics metrics;
 
         GraphicsJNI::getNativePaint(env, paint)->getFontMetrics(&metrics);
-        int ascent = SkScalarRound(metrics.fAscent);
-        int descent = SkScalarRound(metrics.fDescent);
-        int leading = SkScalarRound(metrics.fLeading);
+        int ascent = SkScalarRoundToInt(metrics.fAscent);
+        int descent = SkScalarRoundToInt(metrics.fDescent);
+        int leading = SkScalarRoundToInt(metrics.fLeading);
 
         if (metricsObj) {
             SkASSERT(env->IsInstanceOf(metricsObj, gFontMetricsInt_class));
-            env->SetIntField(metricsObj, gFontMetricsInt_fieldID.top, SkScalarFloor(metrics.fTop));
+            env->SetIntField(metricsObj, gFontMetricsInt_fieldID.top, SkScalarFloorToInt(metrics.fTop));
             env->SetIntField(metricsObj, gFontMetricsInt_fieldID.ascent, ascent);
             env->SetIntField(metricsObj, gFontMetricsInt_fieldID.descent, descent);
-            env->SetIntField(metricsObj, gFontMetricsInt_fieldID.bottom, SkScalarCeil(metrics.fBottom));
+            env->SetIntField(metricsObj, gFontMetricsInt_fieldID.bottom, SkScalarCeilToInt(metrics.fBottom));
             env->SetIntField(metricsObj, gFontMetricsInt_fieldID.leading, leading);
         }
         return descent - ascent + leading;
diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp
index 144ac39..a49c151 100644
--- a/core/jni/android/graphics/TextLayoutCache.cpp
+++ b/core/jni/android/graphics/TextLayoutCache.cpp
@@ -492,7 +492,7 @@
     (((ucs) & 0xfc00) == 0xdc00)
 
 #ifndef HB_SurrogateToUcs4
-#define HB_SurrogateToUcs4_(high, low) \
+#define HB_SurrogateToUcs4(high, low) \
     (((hb_codepoint_t)(high))<<10) + (low) - 0x35fdc00;
 #endif
 
@@ -784,7 +784,7 @@
     if (typeface) {
         currentStyle = typeface->style();
     }
-    typeface = SkCreateTypefaceForScriptNG(script, currentStyle);
+    typeface = SkCreateTypefaceForScript(script, currentStyle);
 #if DEBUG_GLYPHS
     ALOGD("Using Harfbuzz Script %c%c%c%c, Style %d", HB_UNTAG(script), currentStyle);
 #endif
diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp
index c5ab284..159ffb2 100644
--- a/core/jni/android_view_SurfaceControl.cpp
+++ b/core/jni/android_view_SurfaceControl.cpp
@@ -58,36 +58,11 @@
     jfieldID secure;
 } gPhysicalDisplayInfoClassInfo;
 
-
-class ScreenshotPixelRef : public SkPixelRef {
-public:
-    ScreenshotPixelRef(const SkImageInfo& info, ScreenshotClient* screenshot) :
-      SkPixelRef(info),
-      mScreenshot(screenshot) {
-        setImmutable();
-    }
-
-    virtual ~ScreenshotPixelRef() {
-        delete mScreenshot;
-    }
-
-protected:
-    // overrides from SkPixelRef
-    virtual void* onLockPixels(SkColorTable** ct) {
-        *ct = NULL;
-        return (void*)mScreenshot->getPixels();
-    }
-
-    virtual void onUnlockPixels() {
-    }
-
-    SK_DECLARE_UNFLATTENABLE_OBJECT()
-private:
-    ScreenshotClient* mScreenshot;
-
-    typedef SkPixelRef INHERITED;
-};
-
+// Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref.
+void DeleteScreenshot(void* addr, void* context) {
+    SkASSERT(addr == ((ScreenshotClient*) context)->getPixels());
+    delete ((ScreenshotClient*) context);
+}
 
 // ----------------------------------------------------------------------------
 
@@ -167,20 +142,19 @@
         }
     }
 
-    // takes ownership of ScreenshotClient
-    ScreenshotPixelRef* pixels = new ScreenshotPixelRef(screenshotInfo, screenshot);
     const ssize_t rowBytes =
             screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat());
 
     SkBitmap* bitmap = new SkBitmap();
     bitmap->setConfig(screenshotInfo, (size_t)rowBytes);
     if (screenshotInfo.fWidth > 0 && screenshotInfo.fHeight > 0) {
+        // takes ownership of ScreenshotClient
+        SkMallocPixelRef* pixels = SkMallocPixelRef::NewWithProc(screenshotInfo,
+                (size_t) rowBytes, NULL, (void*) screenshot->getPixels(), &DeleteScreenshot,
+                (void*) screenshot);
+        pixels->setImmutable();
         bitmap->setPixelRef(pixels)->unref();
         bitmap->lockPixels();
-    } else {
-        // be safe with an empty bitmap.
-        delete pixels;
-        bitmap->setPixels(NULL);
     }
 
     return GraphicsJNI::createBitmap(env, bitmap,