ok: refactor Src/Dst interactions
This makes everything a lot more like DM, for the same reason:
it's the best way to make Vias work.
Instead of exposing a canvas, Dsts take a Src to draw. Vias still are
Dsts that wrap Dsts. They do their internal work in draw() then pass a
proxy Src encapsulating that work to the next Dst's draw().
A little refactoring in ok.cpp allows arbitrary chains of Vias.
I removed the guarantee that Src methods are called in strict order.
It's easy enough to make each Src initialize itself as needed.
I moved the .png encoding back to ok.cpp. It seemed weird for Dsts to
have to think about files and paths. One day Dst will want a data()
method for non-image output (.pdf, .skp), and then we'll want ok.cpp to
be the one to coordinate what to write where.
Change-Id: Id4a3674b2d05aef2b5f10e0077df0a8407c07b61
Reviewed-on: https://skia-review.googlesource.com/10175
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
diff --git a/tools/ok.h b/tools/ok.h
index 99a5ca0..e2a6a34 100644
--- a/tools/ok.h
+++ b/tools/ok.h
@@ -22,9 +22,9 @@
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().
+ virtual std::string name() = 0;
+ virtual SkISize size() = 0;
+ virtual bool draw(SkCanvas*) = 0;
};
struct Stream {
@@ -34,8 +34,8 @@
struct Dst {
virtual ~Dst() {}
- virtual SkCanvas* canvas() = 0;
- virtual void write(std::string path_prefix) = 0; // All but the file extension.
+ virtual bool draw(Src*) = 0;
+ virtual sk_sp<SkImage> image() = 0;
};
class Options {
@@ -47,12 +47,9 @@
// 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)(Options, SkISize));
- Register(const char* name,
- std::unique_ptr<Dst> (*factory)(Options, SkISize, std::unique_ptr<Dst>));
+ Register(const char* name, std::unique_ptr<Stream> (*factory)(Options));
+ Register(const char* name, std::unique_ptr<Dst> (*factory)(Options));
+ Register(const char* name, std::unique_ptr<Dst> (*factory)(Options, std::unique_ptr<Dst>));
};
#endif//ok_DEFINED