Add --bbh (default true) to nanobench.

Chrome's using a bounding box, so it's a good idea for our
bots to do so too.

When set, we'll create an SkTileGrid to match the
parameters of --clip, and so should always hit its fast
path.

This will impose a small overhead (querying the BBH) on all
SKPs, but make large SKPs render more quickly.  E.g. on
GPU desk_pokemonwiki should show about a 30% improvement,
tabl_mozilla about 40%, and one very long page from my
personal suite, askmefast.com, gets 5x faster.

(The performance changes are not the point of the CL, but
something we should be aware of.)

BUG=
R=bsalomon@google.com, mtklein@google.com, robertphillips@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/497493003
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp
index 6968d6d..8961916 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -16,11 +16,13 @@
 #include "Stats.h"
 #include "Timer.h"
 
-#include "SkOSFile.h"
+#include "SkBBHFactory.h"
 #include "SkCanvas.h"
 #include "SkCommonFlags.h"
 #include "SkForceLinking.h"
 #include "SkGraphics.h"
+#include "SkOSFile.h"
+#include "SkPictureRecorder.h"
 #include "SkString.h"
 #include "SkSurface.h"
 
@@ -71,6 +73,7 @@
 
 DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs.");
 DEFINE_string(scales, "1.0", "Space-separated scales for SKPs.");
+DEFINE_bool(bbh, true, "Build a BBH for SKPs?");
 
 static SkString humanize(double ms) {
     if (ms > 1e+3) return SkStringPrintf("%.3gs",  ms/1e3);
@@ -481,6 +484,20 @@
 
                 SkString name = SkOSPath::Basename(path.c_str());
 
+                if (FLAGS_bbh) {
+                    // The SKP we read off disk doesn't have a BBH.  Re-record so it grows one.
+                    // Here we use an SkTileGrid with parameters optimized for FLAGS_clip.
+                    const SkTileGridFactory::TileGridInfo info = {
+                        SkISize::Make(fClip.width(), fClip.height()),  // tile interval
+                        SkISize::Make(0,0),                            // margin
+                        SkIPoint::Make(fClip.left(), fClip.top()),     // offset
+                    };
+                    SkTileGridFactory factory(info);
+                    SkPictureRecorder recorder;
+                    pic->draw(recorder.beginRecording(pic->width(), pic->height(), &factory));
+                    pic.reset(recorder.endRecording());
+                }
+
                 fSourceType = "skp";
                 return SkNEW_ARGS(SKPBench,
                         (name.c_str(), pic.get(), fClip, fScales[fCurrentScale]));