Merge latest Skia into master (1 commits)

https://skia.googlesource.com/skia.git/+log/1517224..4897fb8

Test: Presubmit checks will test this change.
Change-Id: Ia62b8a9b650a056bbfc1ab56683a63bfe1d1bd8a
diff --git a/gm/filterbitmap.cpp b/gm/filterbitmap.cpp
index ec20e6e..c9ff295 100644
--- a/gm/filterbitmap.cpp
+++ b/gm/filterbitmap.cpp
@@ -11,6 +11,7 @@
 #include "SkGradientShader.h"
 #include "SkStream.h"
 #include "SkTypeface.h"
+#include "sk_tool_utils.h"
 
 static void setTypeface(SkPaint* paint, const char name[], SkFontStyle style) {
     sk_tool_utils::set_portable_typeface(paint, name, style);
@@ -169,7 +170,7 @@
           }
           if (fConvertToG8) {
               SkBitmap tmp;
-              fBM.copyTo(&tmp, kGray_8_SkColorType);
+              sk_tool_utils::copy_to_g8(&tmp, fBM);
               fBM = tmp;
           }
       }
@@ -203,7 +204,7 @@
 
         if (fConvertToG8) {
             SkBitmap tmp;
-            fBM.copyTo(&tmp, kGray_8_SkColorType);
+            sk_tool_utils::copy_to_g8(&tmp, fBM);
             fBM = tmp;
         }
       }
diff --git a/gm/showmiplevels.cpp b/gm/showmiplevels.cpp
index 0394b57..36e8101 100644
--- a/gm/showmiplevels.cpp
+++ b/gm/showmiplevels.cpp
@@ -216,41 +216,9 @@
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-static void copy_32_to_g8(void* dst, size_t dstRB, const void* src, const SkImageInfo& srcInfo,
-                          size_t srcRB) {
-    uint8_t* dst8 = (uint8_t*)dst;
-    const uint32_t* src32 = (const uint32_t*)src;
-
-    const int w = srcInfo.width();
-    const int h = srcInfo.height();
-    const bool isBGRA = (kBGRA_8888_SkColorType == srcInfo.colorType());
-
-    for (int y = 0; y < h; ++y) {
-        if (isBGRA) {
-            // BGRA
-            for (int x = 0; x < w; ++x) {
-                uint32_t s = src32[x];
-                dst8[x] = SkComputeLuminance((s >> 16) & 0xFF, (s >> 8) & 0xFF, s & 0xFF);
-            }
-        } else {
-            // RGBA
-            for (int x = 0; x < w; ++x) {
-                uint32_t s = src32[x];
-                dst8[x] = SkComputeLuminance(s & 0xFF, (s >> 8) & 0xFF, (s >> 16) & 0xFF);
-            }
-        }
-        src32 = (const uint32_t*)((const char*)src32 + srcRB);
-        dst8 += dstRB;
-    }
-}
-
 void copy_to(SkBitmap* dst, SkColorType dstColorType, const SkBitmap& src) {
     if (kGray_8_SkColorType == dstColorType) {
-        SkImageInfo grayInfo = src.info().makeColorType(kGray_8_SkColorType);
-        dst->allocPixels(grayInfo);
-        copy_32_to_g8(dst->getPixels(), dst->rowBytes(), src.getPixels(), src.info(),
-                      src.rowBytes());
-        return;
+        return sk_tool_utils::copy_to_g8(dst, src);
     }
 
     src.copyTo(dst, dstColorType);
diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp
index 3e38cc4..93f5b10 100644
--- a/tools/sk_tool_utils.cpp
+++ b/tools/sk_tool_utils.cpp
@@ -555,5 +555,35 @@
     return SkRect::MakeLTRB(r.fLeft + maxL, r.fTop, r.fRight - maxR, r.fBottom);
 }
 
+void copy_to_g8(SkBitmap* dst, const SkBitmap& src) {
+    SkASSERT(kBGRA_8888_SkColorType == src.colorType() ||
+             kRGBA_8888_SkColorType == src.colorType());
+
+    SkImageInfo grayInfo = src.info().makeColorType(kGray_8_SkColorType);
+    dst->allocPixels(grayInfo);
+    uint8_t* dst8 = (uint8_t*)dst->getPixels();
+    const uint32_t* src32 = (const uint32_t*)src.getPixels();
+
+    const int w = src.width();
+    const int h = src.height();
+    const bool isBGRA = (kBGRA_8888_SkColorType == src.colorType());
+    for (int y = 0; y < h; ++y) {
+        if (isBGRA) {
+            // BGRA
+            for (int x = 0; x < w; ++x) {
+                uint32_t s = src32[x];
+                dst8[x] = SkComputeLuminance((s >> 16) & 0xFF, (s >> 8) & 0xFF, s & 0xFF);
+            }
+        } else {
+            // RGBA
+            for (int x = 0; x < w; ++x) {
+                uint32_t s = src32[x];
+                dst8[x] = SkComputeLuminance(s & 0xFF, (s >> 8) & 0xFF, (s >> 16) & 0xFF);
+            }
+        }
+        src32 = (const uint32_t*)((const char*)src32 + src.rowBytes());
+        dst8 += dst->rowBytes();
+    }
+}
 
 }  // namespace sk_tool_utils
diff --git a/tools/sk_tool_utils.h b/tools/sk_tool_utils.h
index b097757..ffe8084 100644
--- a/tools/sk_tool_utils.h
+++ b/tools/sk_tool_utils.h
@@ -251,6 +251,9 @@
         };
         return sk_make_sp<EncodeImagePixelSerializer>();
     }
+
+    void copy_to_g8(SkBitmap* dst, const SkBitmap& src);
+
 }  // namespace sk_tool_utils
 
 #endif  // sk_tool_utils_DEFINED