Create a skeleton VisualDebugModule
authorjoshualitt <joshualitt@chromium.org>
Fri, 4 Dec 2015 17:02:34 +0000 (09:02 -0800)
committerCommit bot <commit-bot@chromium.org>
Fri, 4 Dec 2015 17:02:34 +0000 (09:02 -0800)
BUG=skia:

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

tools/VisualBench/VisualBench.cpp
tools/VisualBench/VisualBenchmarkStream.cpp
tools/VisualBench/VisualBenchmarkStream.h
tools/VisualBench/VisualDebugModule.cpp [new file with mode: 0644]
tools/VisualBench/VisualDebugModule.h [new file with mode: 0644]

index 4b76307f984bfc83e572942cedc2f1766c059e29..476ac1654b9723a49fa494b78853e6532898ba55 100644 (file)
@@ -18,6 +18,7 @@
 #include "SkOSFile.h"
 #include "SkStream.h"
 #include "Stats.h"
+#include "VisualDebugModule.h"
 #include "VisualLightweightBenchModule.h"
 #include "VisualInteractiveModule.h"
 #include "gl/GrGLInterface.h"
 #include <stdlib.h>
 
 DEFINE_bool2(fullscreen, f, true, "Run fullscreen.");
-DEFINE_bool2(interactive, n, false, "Run in interactive mode.");
+DEFINE_string(mode, "classic", "one of: classic interactive debugger");
 DEFINE_bool2(dif, d, false, "Use device-independent fonts.");
 
 VisualBench::VisualBench(void* hwnd, int argc, char** argv)
     : INHERITED(hwnd) {
-    SkDebugf("Command line arguments:");
-    for (int i = 0; i < argc; ++i) {
-        SkDebugf("%s\n", argv[i]);
+    SkDebugf("Command line arguments: ");
+    for (int i = 1; i < argc; ++i) {
+        SkDebugf("%s ", argv[i]);
     }
+    SkDebugf("\n");
 
     SkCommandLineFlags::Parse(argc, argv);
 
@@ -49,8 +51,15 @@ VisualBench::VisualBench(void* hwnd, int argc, char** argv)
         INHERITED::setSurfaceProps(SkSurfaceProps(flags, props.pixelGeometry()));
     }
     fModule.reset(new VisualLightweightBenchModule(this));
-    if (FLAGS_interactive) {
-        fModule.reset(new VisualInteractiveModule(this));
+
+    if (FLAGS_mode.count()) {
+        SkASSERT(FLAGS_mode.count() == 1);
+        SkString mode(FLAGS_mode[0]);
+        if (mode == SkString("interactive")) {
+            fModule.reset(new VisualInteractiveModule(this));
+        } else if (mode == SkString("debugger")) {
+            fModule.reset(new VisualDebugModule(this));
+        }
     }
 
     this->setTitle();
index 183da75b50b45c03cb6d8710027730577dbd0a90..c4da7b51dc1b2f4a49fb5fcc000b0f6e7cfe58c0 100644 (file)
@@ -72,7 +72,7 @@ private:
     SkRect fPerlinRect;
 };
 
-VisualBenchmarkStream::VisualBenchmarkStream(const SkSurfaceProps& surfaceProps)
+VisualBenchmarkStream::VisualBenchmarkStream(const SkSurfaceProps& surfaceProps, bool justSKP)
     : fSurfaceProps(surfaceProps)
     , fBenches(BenchRegistry::Head())
     , fGMs(skiagm::GMRegistry::Head())
@@ -92,6 +92,11 @@ VisualBenchmarkStream::VisualBenchmarkStream(const SkSurfaceProps& surfaceProps)
         }
     }
 
+    if (justSKP) {
+       fGMs = nullptr;
+       fBenches = nullptr;
+    }
+
     // seed with an initial benchmark
     // NOTE the initial benchmark will not have preTimingHooks called, but that is okay because
     // it is the warmupbench
index 6718d3a936f7d6fbd644229946785a34d5a1bc70..b1fd0f08c722dbcc60814b80b2ecb7c165809ec9 100644 (file)
@@ -18,7 +18,7 @@ DECLARE_string(match);
 
 class VisualBenchmarkStream {
 public:
-    VisualBenchmarkStream(const SkSurfaceProps&);
+    VisualBenchmarkStream(const SkSurfaceProps&, bool justSKP = false);
 
     static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic);
 
diff --git a/tools/VisualBench/VisualDebugModule.cpp b/tools/VisualBench/VisualDebugModule.cpp
new file mode 100644 (file)
index 0000000..e4e70dd
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "VisualDebugModule.h"
+
+#include "SkCanvas.h"
+
+VisualDebugModule::VisualDebugModule(VisualBench* owner)
+    : fState(kInit_State)
+    , fIndex(0)
+    , fOwner(owner) {
+    // VisualDebugModule only really makes sense for SKPs
+    fBenchmarkStream.reset(new VisualBenchmarkStream(owner->getSurfaceProps(), true));
+}
+
+bool VisualDebugModule::advanceIfNecessary(SkCanvas* canvas) {
+    Benchmark* benchmark = fBenchmarkStream->current();
+    switch (fState) {
+        case kInit_State: {
+            // setup new benchmark
+            benchmark->delayedSetup();
+            fOwner->clear(canvas, SK_ColorWHITE, 3);
+            benchmark->preTimingHooks(canvas);
+
+            // reset debug canvas
+            SkIPoint size = benchmark->getSize();
+            fDebugCanvas.reset(new SkDebugCanvas(size.fX, size.fY));
+
+            // pour benchmark into canvas
+            benchmark->draw(1, fDebugCanvas);
+            fIndex = fDebugCanvas->getSize() - 1;
+            fState = kPlay_State;
+            break;
+        }
+        case kPlay_State: break;
+        case kNext_State:
+            // cleanup after the last SKP
+            benchmark->postTimingHooks(canvas);
+            fOwner->reset();
+            if (!fBenchmarkStream->next()) {
+                SkDebugf("Exiting VisualBench successfully\n");
+                fOwner->closeWindow();
+                return false;
+            }
+            fState = kInit_State;
+            break;
+    }
+    return true;
+}
+
+void VisualDebugModule::draw(SkCanvas* canvas) {
+    if (!fBenchmarkStream->current() || !this->advanceIfNecessary(canvas)) {
+        return;
+    }
+
+    fDebugCanvas->drawTo(canvas, fIndex);
+    canvas->flush();
+    fOwner->present();
+}
+
+bool VisualDebugModule::onHandleChar(SkUnichar c) {
+    switch (c) {
+        case ' ': fState = kNext_State; break;
+        case 'a': fIndex = (fIndex + 1) % (fDebugCanvas->getSize() - 1); break;
+        case 's': fIndex = fIndex <= 0 ? fDebugCanvas->getSize() - 1 : fIndex - 1; break;
+        default: break;
+    }
+
+    return true;
+}
diff --git a/tools/VisualBench/VisualDebugModule.h b/tools/VisualBench/VisualDebugModule.h
new file mode 100644 (file)
index 0000000..26385c3
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef VisualDebugModule_DEFINED
+#define VisualDebugModule_DEFINED
+
+#include "VisualModule.h"
+
+#include "SkDebugCanvas.h"
+#include "VisualBench.h"
+#include "VisualBenchmarkStream.h"
+
+class VisualDebugModule : public VisualModule {
+public:
+    VisualDebugModule(VisualBench* owner);
+    void draw(SkCanvas* canvas) override;
+    bool onHandleChar(SkUnichar unichar) override;
+
+private:
+    enum State {
+        kInit_State,
+        kPlay_State,
+        kNext_State,
+    };
+
+    bool advanceIfNecessary(SkCanvas*);
+
+    State fState;
+    SkAutoTUnref<SkDebugCanvas> fDebugCanvas;
+    int fIndex;
+
+    // support framework
+    VisualBench* fOwner;
+    SkAutoTDelete<VisualBenchmarkStream> fBenchmarkStream;
+
+    typedef VisualModule INHERITED;
+};
+
+#endif