#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);
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();
SkRect fPerlinRect;
};
-VisualBenchmarkStream::VisualBenchmarkStream(const SkSurfaceProps& surfaceProps)
+VisualBenchmarkStream::VisualBenchmarkStream(const SkSurfaceProps& surfaceProps, bool justSKP)
: fSurfaceProps(surfaceProps)
, fBenches(BenchRegistry::Head())
, fGMs(skiagm::GMRegistry::Head())
}
}
+ 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
class VisualBenchmarkStream {
public:
- VisualBenchmarkStream(const SkSurfaceProps&);
+ VisualBenchmarkStream(const SkSurfaceProps&, bool justSKP = false);
static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic);
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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