Spin off non-core parts of ok into their own files.
Now ok.cpp handles only the high level coordination of Srcs and Dsts,
without having to know or care what they are.
Some minor refactoring to things like Options.
Change-Id: I02df890b26d6d069e980a125b6a1ce1a7067b900
Reviewed-on: https://skia-review.googlesource.com/10173
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
diff --git a/tools/ok.h b/tools/ok.h
new file mode 100644
index 0000000..ab05074
--- /dev/null
+++ b/tools/ok.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef ok_DEFINED
+#define ok_DEFINED
+
+#include "SkCanvas.h"
+#include <functional>
+#include <map>
+#include <memory>
+#include <string>
+
+// Not really ok-specific, but just kind of generally handy.
+template <typename T>
+static std::unique_ptr<T> move_unique(T& v) {
+ return std::unique_ptr<T>{new T{std::move(v)}};
+}
+
+struct Src {
+ virtual ~Src() {}
+ virtual std::string name() = 0; // ok always calls Src methods in order:
+ virtual SkISize size() = 0; // name() -> size() -> draw(), possibly
+ virtual void draw(SkCanvas*) = 0; // stopping after calling name().
+};
+
+struct Stream {
+ virtual ~Stream() {}
+ virtual std::unique_ptr<Src> next() = 0;
+};
+
+struct Dst {
+ virtual ~Dst() {}
+ virtual SkCanvas* canvas() = 0;
+ virtual void write(std::string path_prefix) = 0; // All but the file extension.
+};
+
+class Options {
+ std::map<std::string, std::string> kv;
+public:
+ explicit Options(std::string str = "");
+ std::string operator()(std::string k, std::string fallback = "") const;
+};
+
+// Create globals to register your new type of Stream or Dst.
+struct Register {
+ Register(const char* name, std::unique_ptr<Stream> (*factory)(Options));
+ Register(const char* name, std::unique_ptr<Dst> (*factory)(SkISize, Options));
+};
+
+#endif//ok_DEFINED