Add visualbench option for device-independent fonts
authorcdalton <cdalton@nvidia.com>
Mon, 26 Oct 2015 20:14:36 +0000 (13:14 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 26 Oct 2015 20:14:36 +0000 (13:14 -0700)
BUG=skia:

Review URL: https://codereview.chromium.org/1421723004

tools/VisualBench/VisualBench.cpp
tools/VisualBench/VisualBenchmarkStream.cpp
tools/VisualBench/VisualBenchmarkStream.h
tools/VisualBench/VisualStreamTimingModule.cpp
tools/VisualBench/WrappedBenchmark.h

index 893dba6..10fdbfe 100644 (file)
 
 DEFINE_bool2(fullscreen, f, true, "Run fullscreen.");
 DEFINE_bool2(interactive, n, false, "Run in interactive mode.");
+DEFINE_bool2(dif, d, false, "Use device-independent fonts.");
 
 VisualBench::VisualBench(void* hwnd, int argc, char** argv)
     : INHERITED(hwnd) {
     SkCommandLineFlags::Parse(argc, argv);
 
-    // this has to happen after commandline parsing
+    // these have to happen after commandline parsing
+    if (FLAGS_dif) {
+        const SkSurfaceProps& props(INHERITED::getSurfaceProps());
+        uint32_t flags = SkSurfaceProps::kUseDeviceIndependentFonts_Flag | props.flags();
+        INHERITED::setSurfaceProps(SkSurfaceProps(flags, props.pixelGeometry()));
+    }
     fModule.reset(new VisualLightweightBenchModule(this));
     if (FLAGS_interactive) {
         fModule.reset(new VisualInteractiveModule(this));
index 906aab2..66e7cb0 100644 (file)
@@ -57,8 +57,9 @@ private:
     SkPath fPath;
 };
 
-VisualBenchmarkStream::VisualBenchmarkStream()
-    : fBenches(BenchRegistry::Head())
+VisualBenchmarkStream::VisualBenchmarkStream(const SkSurfaceProps& surfaceProps)
+    : fSurfaceProps(surfaceProps)
+    , fBenches(BenchRegistry::Head())
     , fGMs(skiagm::GMRegistry::Head())
     , fSourceType(nullptr)
     , fBenchType(nullptr)
@@ -119,9 +120,9 @@ Benchmark* VisualBenchmarkStream::next() {
 
     // TODO move this all to --config
     if (bench && FLAGS_cpu) {
-        bench = new CpuWrappedBenchmark(bench);
+        bench = new CpuWrappedBenchmark(fSurfaceProps, bench);
     } else if (bench && FLAGS_nvpr) {
-        bench = new NvprWrappedBenchmark(bench, 4);
+        bench = new NvprWrappedBenchmark(fSurfaceProps, bench, 4);
     }
 
     fBenchmark.reset(bench);
index 89ca632..6718d3a 100644 (file)
@@ -18,7 +18,7 @@ DECLARE_string(match);
 
 class VisualBenchmarkStream {
 public:
-    VisualBenchmarkStream();
+    VisualBenchmarkStream(const SkSurfaceProps&);
 
     static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic);
 
@@ -28,6 +28,7 @@ public:
 private:
     Benchmark* innerNext();
 
+    SkSurfaceProps fSurfaceProps;
     const BenchRegistry* fBenches;
     const skiagm::GMRegistry* fGMs;
     SkTArray<SkString> fSKPs;
index cecc5ac..ad7c1d0 100644 (file)
@@ -13,7 +13,7 @@ VisualStreamTimingModule::VisualStreamTimingModule(VisualBench* owner, bool preW
     : fInitState(kReset_InitState)
     , fPreWarmBeforeSample(preWarmBeforeSample)
     , fOwner(owner) {
-    fBenchmarkStream.reset(new VisualBenchmarkStream);
+    fBenchmarkStream.reset(new VisualBenchmarkStream(owner->getSurfaceProps()));
 }
 
 inline void VisualStreamTimingModule::handleInitState(SkCanvas* canvas) {
index 6fac145..ffa0da3 100644 (file)
 class WrappedBenchmark : public Benchmark {
 public:
     // Takes ownership of caller's ref on `bench`.
-    explicit WrappedBenchmark(Benchmark* bench) : fBench(bench) {}
+    explicit WrappedBenchmark(const SkSurfaceProps& surfaceProps, Benchmark* bench)
+        : fSurfaceProps(surfaceProps)
+        , fBench(bench) {}
+
+    const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
 
     const char* onGetName()       override { return fBench->getName(); }
     const char* onGetUniqueName() override { return fBench->getUniqueName(); }
@@ -52,6 +56,7 @@ public:
 private:
     virtual SkSurface* setupOffScreen(SkCanvas*)=0;
 
+    SkSurfaceProps          fSurfaceProps;
     SkAutoTUnref<SkSurface> fOffScreen;
     SkAutoTUnref<Benchmark> fBench;
 };
@@ -59,11 +64,12 @@ private:
 // Create a raster surface for off screen rendering
 class CpuWrappedBenchmark : public WrappedBenchmark {
 public:
-    explicit CpuWrappedBenchmark(Benchmark* bench) : INHERITED(bench) {}
+    explicit CpuWrappedBenchmark(const SkSurfaceProps& surfaceProps, Benchmark* bench)
+        : INHERITED(surfaceProps, bench) {}
 
 private:
     SkSurface* setupOffScreen(SkCanvas* canvas) override {
-        return SkSurface::NewRaster(canvas->imageInfo());
+        return SkSurface::NewRaster(canvas->imageInfo(), &this->surfaceProps());
     }
 
     typedef WrappedBenchmark INHERITED;
@@ -72,8 +78,9 @@ private:
 // Create an MSAA & NVPR-enabled GPU backend
 class NvprWrappedBenchmark : public WrappedBenchmark {
 public:
-    explicit NvprWrappedBenchmark(Benchmark* bench, int numSamples)
-        : INHERITED(bench)
+    explicit NvprWrappedBenchmark(const SkSurfaceProps& surfaceProps, Benchmark* bench,
+                                  int numSamples)
+        : INHERITED(surfaceProps, bench)
         , fNumSamples(numSamples) {}
 
 private:
@@ -81,7 +88,8 @@ private:
         return SkSurface::NewRenderTarget(canvas->getGrContext(),
                                           SkSurface::kNo_Budgeted,
                                           canvas->imageInfo(),
-                                          fNumSamples);
+                                          fNumSamples,
+                                          &this->surfaceProps());
     }
 
     int fNumSamples;