GN: nanobench

Add nanobench, and while we're at it monobench to show off how cool
source_sets are... the bench files are only built once then linked
into both binaries.  With GYP we build them twice. :/  Same deal
for GMs between nanobench and DM... build once, link twice.

nanobench uses SkImageEncoder to encode its .pngs, which requires
we link in the image encoders, which requires we get them all in.
That's the bulk of this.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2193513002

Review-Url: https://codereview.chromium.org/2193513002
diff --git a/BUILD.gn b/BUILD.gn
index d4ccf63..d6e2562 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -49,6 +49,7 @@
     "src/lazy",
     "src/opts",
     "src/pathops",
+    "src/pdf",
     "src/ports",
     "src/sfnt",
     "src/utils",
@@ -202,6 +203,11 @@
     "src/codec/SkWebpCodec.cpp",
     "src/images/SkImageEncoder.cpp",
     "src/images/SkImageEncoder_Factory.cpp",
+    "src/images/SkJPEGImageEncoder.cpp",
+    "src/images/SkJPEGWriteUtility.cpp",
+    "src/images/SkKTXImageEncoder.cpp",
+    "src/images/SkPNGImageEncoder.cpp",
+    "src/images/SkWEBPImageEncoder.cpp",
     "src/ports/SkDiscardableMemory_none.cpp",
     "src/ports/SkGlobalInitialization_default.cpp",
     "src/ports/SkImageGenerator_skia.cpp",
@@ -249,9 +255,6 @@
     ]
     sources += [
       "src/fonts/SkFontMgr_fontconfig.cpp",
-      "src/images/SkJPEGImageEncoder.cpp",
-      "src/images/SkJPEGWriteUtility.cpp",
-      "src/images/SkPNGImageEncoder.cpp",
       "src/ports/SkFontConfigInterface_direct.cpp",
       "src/ports/SkFontConfigInterface_direct_factory.cpp",
       "src/ports/SkFontHost_FreeType.cpp",
@@ -368,9 +371,12 @@
     "tools/timer",
   ]
   sources = [
+    "src/images/SkForceLinking.cpp",
     "src/utils/SkMultiPictureDocumentReader.cpp",  # TODO(halcanary): move to tools?
+    "tools/CrashHandler.cpp",
     "tools/ProcStats.cpp",
     "tools/Resources.cpp",
+    "tools/ThermalManager.cpp",
     "tools/picture_utils.cpp",
     "tools/random_parse_path.cpp",
     "tools/sk_tool_utils.cpp",
@@ -399,26 +405,77 @@
   ]
 }
 
-if (!is_component_build) {   # DM uses many non-SK_API APIs...
-    executable("dm") {
-      sources = [
-        "dm/DM.cpp",
-        "dm/DMJsonWriter.cpp",
-        "dm/DMSrcSink.cpp",
+bench_sources = exec_script("gyp/find.py",
+                            [
+                              rebase_path("bench"),
+                              "*.c*",
+                            ],
+                            "list lines",
+                            [])
 
-        # TODO: tests for real
-        "tests/Test.cpp",
-      ]
-      include_dirs = [ "tests" ]
-      deps = [
-        ":flags",
-        ":gm",
-        ":gpu_tool_utils",
-        ":skia",
-        ":tool_utils",
-        "//third_party/jsoncpp",
-        "//third_party/libpng",
-      ]
-      testonly = true
-    }
+test_lib("bench") {
+  public_include_dirs = [ "bench" ]
+  sources = bench_sources
+  sources -= [
+    rebase_path("bench/nanobench.cpp"),
+    rebase_path("bench/nanobenchAndroid.cpp"),
+  ]
+  deps = [
+    ":flags",
+    ":gm",
+    ":gpu_tool_utils",
+    ":skia",
+    ":tool_utils",
+  ]
+}
+
+if (!is_component_build) {  # Our test tools use many non-SK_API APIs...
+  executable("dm") {
+    sources = [
+      "dm/DM.cpp",
+      "dm/DMJsonWriter.cpp",
+      "dm/DMSrcSink.cpp",
+
+      # TODO: tests for real
+      "tests/Test.cpp",
+    ]
+    include_dirs = [ "tests" ]
+    deps = [
+      ":flags",
+      ":gm",
+      ":gpu_tool_utils",
+      ":skia",
+      ":tool_utils",
+      "//third_party/jsoncpp",
+      "//third_party/libpng",
+    ]
+    testonly = true
+  }
+
+  executable("monobench") {
+    sources = [
+      "tools/monobench.cpp",
+    ]
+    deps = [
+      ":bench",
+      ":skia",
+    ]
+    testonly = true
+  }
+
+  executable("nanobench") {
+    sources = [
+      "bench/nanobench.cpp",
+    ]
+    deps = [
+      ":bench",
+      ":flags",
+      ":gm",
+      ":gpu_tool_utils",
+      ":skia",
+      ":tool_utils",
+      "//third_party/jsoncpp",
+    ]
+    testonly = true
+  }
 }
diff --git a/third_party/libwebp/BUILD.gn b/third_party/libwebp/BUILD.gn
index 1ad734f..d27004b 100644
--- a/third_party/libwebp/BUILD.gn
+++ b/third_party/libwebp/BUILD.gn
@@ -26,16 +26,25 @@
     "../externals/libwebp/src/dsp/alpha_processing.c",
     "../externals/libwebp/src/dsp/alpha_processing_sse2.c",
     "../externals/libwebp/src/dsp/alpha_processing_sse41.c",
+    "../externals/libwebp/src/dsp/argb.c",
+    "../externals/libwebp/src/dsp/argb_sse2.c",
+    "../externals/libwebp/src/dsp/cost.c",
+    "../externals/libwebp/src/dsp/cost_sse2.c",
     "../externals/libwebp/src/dsp/cpu.c",
     "../externals/libwebp/src/dsp/dec.c",
     "../externals/libwebp/src/dsp/dec_clip_tables.c",
     "../externals/libwebp/src/dsp/dec_sse2.c",
     "../externals/libwebp/src/dsp/dec_sse41.c",
     "../externals/libwebp/src/dsp/enc.c",
+    "../externals/libwebp/src/dsp/enc_avx2.c",
     "../externals/libwebp/src/dsp/enc_sse2.c",
+    "../externals/libwebp/src/dsp/enc_sse41.c",
     "../externals/libwebp/src/dsp/filters.c",
     "../externals/libwebp/src/dsp/filters_sse2.c",
     "../externals/libwebp/src/dsp/lossless.c",
+    "../externals/libwebp/src/dsp/lossless_enc.c",
+    "../externals/libwebp/src/dsp/lossless_enc_sse2.c",
+    "../externals/libwebp/src/dsp/lossless_enc_sse41.c",
     "../externals/libwebp/src/dsp/lossless_sse2.c",
     "../externals/libwebp/src/dsp/rescaler.c",
     "../externals/libwebp/src/dsp/rescaler_sse2.c",
@@ -43,6 +52,27 @@
     "../externals/libwebp/src/dsp/upsampling_sse2.c",
     "../externals/libwebp/src/dsp/yuv.c",
     "../externals/libwebp/src/dsp/yuv_sse2.c",
+    "../externals/libwebp/src/enc/alpha.c",
+    "../externals/libwebp/src/enc/analysis.c",
+    "../externals/libwebp/src/enc/backward_references.c",
+    "../externals/libwebp/src/enc/config.c",
+    "../externals/libwebp/src/enc/cost.c",
+    "../externals/libwebp/src/enc/filter.c",
+    "../externals/libwebp/src/enc/frame.c",
+    "../externals/libwebp/src/enc/histogram.c",
+    "../externals/libwebp/src/enc/iterator.c",
+    "../externals/libwebp/src/enc/near_lossless.c",
+    "../externals/libwebp/src/enc/picture.c",
+    "../externals/libwebp/src/enc/picture_csp.c",
+    "../externals/libwebp/src/enc/picture_psnr.c",
+    "../externals/libwebp/src/enc/picture_rescale.c",
+    "../externals/libwebp/src/enc/picture_tools.c",
+    "../externals/libwebp/src/enc/quant.c",
+    "../externals/libwebp/src/enc/syntax.c",
+    "../externals/libwebp/src/enc/token.c",
+    "../externals/libwebp/src/enc/tree.c",
+    "../externals/libwebp/src/enc/vp8l.c",
+    "../externals/libwebp/src/enc/webpenc.c",
     "../externals/libwebp/src/utils/bit_reader.c",
     "../externals/libwebp/src/utils/bit_writer.c",
     "../externals/libwebp/src/utils/color_cache.c",