Revert "Revert "Delete copyTo(Allocator), hide copyTo() behind flag""

This reverts commit 0122af08f6af0dee490e1a4f35b552377d0d4753.

Reason for revert: Fixed Android callsite

Original change's description:
> Revert "Delete copyTo(Allocator), hide copyTo() behind flag"
> 
> This reverts commit d4a338f4d0a0cdc08d7d3668931c60997f0fa971.
> 
> Reason for revert: Looks like I missed something I was supposed to delete in Android.
> 
> Original change's description:
> > Delete copyTo(Allocator), hide copyTo() behind flag
> > 
> > Replace uses of copyTo() in Skia.
> > 
> > Bug: skia:6464
> > Change-Id: I921dc53a1c29a5176d18f05741f7c0b5a008e548
> > Reviewed-on: https://skia-review.googlesource.com/14502
> > Commit-Queue: Matt Sarett <msarett@google.com>
> > Reviewed-by: Mike Reed <reed@google.com>
> > 
> 
> TBR=msarett@google.com,reed@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> 
> Change-Id: I4d252940cc6a2462b030007055ea6c229471fc6e
> Reviewed-on: https://skia-review.googlesource.com/14602
> Reviewed-by: Matt Sarett <msarett@google.com>
> Commit-Queue: Matt Sarett <msarett@google.com>
> 

TBR=msarett@google.com,reviews@skia.org,reed@google.com

Change-Id: I81659a820f79f1958fda23cb62513065b57db99d
Reviewed-on: https://skia-review.googlesource.com/14640
Commit-Queue: Matt Sarett <msarett@google.com>
Reviewed-by: Matt Sarett <msarett@google.com>
diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp
index 9a4bb2b..c69b17d 100644
--- a/tools/sk_tool_utils.cpp
+++ b/tools/sk_tool_utils.cpp
@@ -586,6 +586,44 @@
     return SkRect::MakeLTRB(r.fLeft + maxL, r.fTop, r.fRight - maxR, r.fBottom);
 }
 
+bool copy_to(SkBitmap* dst, SkColorType dstColorType, const SkBitmap& src) {
+    SkPixmap srcPM;
+    if (!src.peekPixels(&srcPM)) {
+        return false;
+    }
+
+    SkBitmap tmpDst;
+    SkImageInfo dstInfo = srcPM.info().makeColorType(dstColorType);
+    if (!tmpDst.setInfo(dstInfo)) {
+        return false;
+    }
+
+    // allocate colortable if srcConfig == kIndex8_Config
+    sk_sp<SkColorTable> ctable = nullptr;
+    if (dstColorType == kIndex_8_SkColorType) {
+        if (src.colorType() != kIndex_8_SkColorType) {
+            return false;
+        }
+
+        ctable = sk_ref_sp(srcPM.ctable());
+    }
+    if (!tmpDst.tryAllocPixels(ctable.get())) {
+        return false;
+    }
+
+    SkPixmap dstPM;
+    if (!tmpDst.peekPixels(&dstPM)) {
+        return false;
+    }
+
+    if (!srcPM.readPixels(dstPM)) {
+        return false;
+    }
+
+    dst->swap(tmpDst);
+    return true;
+}
+
 void copy_to_g8(SkBitmap* dst, const SkBitmap& src) {
     SkASSERT(kBGRA_8888_SkColorType == src.colorType() ||
              kRGBA_8888_SkColorType == src.colorType());