SkImageEncoder: simplify API

(re-land 248ff02 & 2cb6cb7, with changes)

  - Hide SkImageEncoder class in private header.
  - SkImageEncoder::Type becomes SkEncodedImageFormat
  - SkEncodedFormat becomes SkEncodedImageFormat
  - SkImageEncoder static functions replaced with
    single function EncodeImage()
  - utility wrappers for EncodeImage() are in
    sk_tool_utils.h

TODO: remove link-time registration mechanism.
TODO: clean up clients use of API and flip the flag.
TODO: implement EncodeImage() in chromeium/skia/ext

Change-Id: I47d451e50be4d5c6c130869c7fa7c2857243d9f0
Reviewed-on: https://skia-review.googlesource.com/4909
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Leon Scroggins <scroggo@google.com>
Reviewed-on: https://skia-review.googlesource.com/5186
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Hal Canary <halcanary@google.com>
diff --git a/tests/BlitRowTest.cpp b/tests/BlitRowTest.cpp
index b4a4a64..3439a5e 100644
--- a/tests/BlitRowTest.cpp
+++ b/tests/BlitRowTest.cpp
@@ -12,6 +12,8 @@
 #include "SkRect.h"
 #include "Test.h"
 
+#include "sk_tool_utils.h"
+
 // these are in the same order as the SkColorType enum
 static const char* gColorTypeName[] = {
     "None", "A8", "565", "4444", "RGBA", "BGRA", "Index8"
@@ -178,7 +180,7 @@
 
 #include "SkImageEncoder.h"
 static void save_bm(const SkBitmap& bm, const char name[]) {
-    SkImageEncoder::EncodeFile(name, bm, SkImageEncoder::kPNG_Type, 100);
+    sk_tool_utils::EncodeImageToFile(name, bm, SkEncodedImageFormat::kPNG, 100);
 }
 
 static bool gOnce;
diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp
index dacabca..d15c710 100644
--- a/tests/CodecTest.cpp
+++ b/tests/CodecTest.cpp
@@ -23,6 +23,8 @@
 
 #include "png.h"
 
+#include "sk_tool_utils.h"
+
 #if PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR < 5
     // FIXME (scroggo): Google3 needs to be updated to use a newer version of libpng. In
     // the meantime, we had to break some pieces of SkPngCodec in order to support Google3.
@@ -1102,7 +1104,7 @@
 
     // Encode the image to png.
     sk_sp<SkData> data =
-            sk_sp<SkData>(SkImageEncoder::EncodeData(bm1, SkImageEncoder::kPNG_Type, 100));
+            sk_sp<SkData>(sk_tool_utils::EncodeImageToData(bm1, SkEncodedImageFormat::kPNG, 100));
 
     std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
     REPORTER_ASSERT(r, color_type_match(info.colorType(), codec->getInfo().colorType()));
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index 18883fe..020e322 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -26,6 +26,8 @@
 #include "SkUtils.h"
 #include "Test.h"
 
+#include "sk_tool_utils.h"
+
 #if SK_SUPPORT_GPU
 #include "GrGpu.h"
 #endif
@@ -153,7 +155,7 @@
     sk_sp<SkData> data(create_image_data(&info));
     SkBitmap bitmap;
     bitmap.installPixels(info, data->writable_data(), info.minRowBytes());
-    sk_sp<SkData> src(SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 100));
+    sk_sp<SkData> src(sk_tool_utils::EncodeImageToData(bitmap, SkEncodedImageFormat::kPNG, 100));
     return SkImage::MakeFromEncoded(std::move(src));
 }
 #if SK_SUPPORT_GPU
@@ -1026,7 +1028,7 @@
     make_all_premul(&bm0);
 
     auto img0 = SkImage::MakeFromBitmap(bm0);
-    sk_sp<SkData> data(img0->encode(SkImageEncoder::kPNG_Type, 100));
+    sk_sp<SkData> data(img0->encode(SkEncodedImageFormat::kPNG, 100));
     auto img1 = SkImage::MakeFromEncoded(data);
 
     SkBitmap bm1;
diff --git a/tests/PDFDocumentTest.cpp b/tests/PDFDocumentTest.cpp
index fca8496..b320015 100644
--- a/tests/PDFDocumentTest.cpp
+++ b/tests/PDFDocumentTest.cpp
@@ -14,6 +14,8 @@
 #include "SkStream.h"
 #include "SkPixelSerializer.h"
 
+#include "sk_tool_utils.h"
+
 static void test_empty(skiatest::Reporter* reporter) {
     SkDynamicMemoryWStream stream;
 
@@ -119,14 +121,7 @@
 class JPEGSerializer final : public SkPixelSerializer {
     bool onUseEncodedData(const void*, size_t) override { return true; }
     SkData* onEncode(const SkPixmap& pixmap) override {
-        SkBitmap bm;
-        return bm.installPixels(pixmap.info(),
-                                pixmap.writable_addr(),
-                                pixmap.rowBytes(),
-                                pixmap.ctable(),
-                                nullptr, nullptr)
-            ? SkImageEncoder::EncodeData(bm, SkImageEncoder::kJPEG_Type, 85)
-            : nullptr;
+        return sk_tool_utils::EncodeImageToData(pixmap, SkEncodedImageFormat::kJPEG, 85).release();
     }
 };
 }  // namespace
diff --git a/tests/PathOpsConicIntersectionTest.cpp b/tests/PathOpsConicIntersectionTest.cpp
index 41c0acb..1de1583 100644
--- a/tests/PathOpsConicIntersectionTest.cpp
+++ b/tests/PathOpsConicIntersectionTest.cpp
@@ -110,8 +110,8 @@
     canvas.drawPath(path, paint);
     SkString filename("c:\\Users\\caryclark\\Documents\\");
     filename.appendf("%s.png", name);
-    SkImageEncoder::EncodeFile(filename.c_str(), bitmap,
-            SkImageEncoder::kPNG_Type, 100);
+    sk_tool_utils::EncodeImageToFile(filename.c_str(), bitmap,
+            SkEncodedImageFormat::kPNG, 100);
 }
 
 static void writeDPng(const SkDConic& dC, const char* name) {
@@ -152,8 +152,8 @@
     canvas.drawPath(path, paint);
     SkString filename("c:\\Users\\caryclark\\Documents\\");
     filename.appendf("%s.png", name);
-    SkImageEncoder::EncodeFile(filename.c_str(), bitmap,
-            SkImageEncoder::kPNG_Type, 100);
+    sk_tool_utils::EncodeImageToFile(filename.c_str(), bitmap,
+            SkEncodedImageFormat::kPNG, 100);
 }
 #endif
 
@@ -290,7 +290,7 @@
         }
         SkString filename("c:\\Users\\caryclark\\Documents\\");
         filename.appendf("f%d.png", index);
-        SkImageEncoder::EncodeFile(filename.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100);
+        sk_tool_utils::EncodeImageToFile(filename.c_str(), bitmap, SkEncodedImageFormat::kPNG, 100);
     }
 }
 #endif
diff --git a/tests/PathOpsSkpClipTest.cpp b/tests/PathOpsSkpClipTest.cpp
index 3cbe7ef..57e9bd1 100644
--- a/tests/PathOpsSkpClipTest.cpp
+++ b/tests/PathOpsSkpClipTest.cpp
@@ -429,7 +429,7 @@
 static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pngName) {
     SkString outFile = get_sum_path(outDir);
     outFile.appendf("%s%s", PATH_SLASH, pngName);
-    if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100)) {
+    if (!sk_tool_utils::EncodeImageToFile(outFile.c_str(), bitmap, SkEncodedImageFormat::kPNG, 100)) {
         SkDebugf("unable to encode gr %s (width=%d height=%d)\n", pngName,
                     bitmap.width(), bitmap.height());
     }
diff --git a/tests/SkpSkGrTest.cpp b/tests/SkpSkGrTest.cpp
index c87926e..0e425a0 100644
--- a/tests/SkpSkGrTest.cpp
+++ b/tests/SkpSkGrTest.cpp
@@ -368,8 +368,8 @@
 
 static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pngName) {
     SkString outFile = make_filepath(0, outDir, pngName);
-    if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap,
-            SkImageEncoder::kPNG_Type, 100)) {
+    if (!sk_tool_utils::EncodeImageToFile(outFile.c_str(), bitmap,
+            SkEncodedImageFormat::kPNG, 100)) {
         SkDebugf("unable to encode gr %s (width=%d height=%d)br \n", pngName,
                     bitmap.width(), bitmap.height());
     }