aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2017-03-25 12:32:22 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-25 17:32:20 +0000
commitf5d1a5567e3df04c288dc6856a0b41a6a6be0a2d (patch)
tree5719f31bbc07e50322f4fa31cf6fde41ba4c10ca /tools
parent7ac04838c58eebbac477895fafdd4b0421727b9e (diff)
ok: basic Vias
Not sure if these simple Src/Dst interfaces will last. Vias are a little tricky, and some may be impossible. Change-Id: I42d19b1ee74b51a830bb781f25a888c0b32ba98c Reviewed-on: https://skia-review.googlesource.com/10174 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/ok.cpp78
-rw-r--r--tools/ok.h8
-rw-r--r--tools/ok_dsts.cpp2
-rw-r--r--tools/ok_vias.cpp37
4 files changed, 101 insertions, 24 deletions
diff --git a/tools/ok.cpp b/tools/ok.cpp
index bfef28f0a5..a8cf6f4866 100644
--- a/tools/ok.cpp
+++ b/tools/ok.cpp
@@ -163,10 +163,16 @@ static std::vector<StreamType> stream_types;
struct DstType {
const char* name;
- std::unique_ptr<Dst> (*factory)(SkISize, Options);
+ std::unique_ptr<Dst> (*factory)(Options, SkISize);
};
static std::vector<DstType> dst_types;
+struct ViaType {
+ const char* name;
+ std::unique_ptr<Dst> (*factory)(Options, SkISize, std::unique_ptr<Dst>);
+};
+static std::vector<ViaType> via_types;
+
int main(int argc, char** argv) {
SkGraphics::Init();
setup_crash_handler();
@@ -176,11 +182,12 @@ int main(int argc, char** argv) {
std::regex search {".*"};
std::string write_dir {""};
- std::unique_ptr<Stream> stream;
- std::function<std::unique_ptr<Dst> (SkISize)> dst_factory;
+ std::unique_ptr<Stream> stream;
+ std::function<std::unique_ptr<Dst> (SkISize)> dst_factory;
+ std::function<std::unique_ptr<Dst> (SkISize, std::unique_ptr<Dst>)> via_factory;
auto help = [&] {
- std::string stream_names, dst_names;
+ std::string stream_names, dst_names, via_names;
for (auto s : stream_types) {
if (!stream_names.empty()) {
stream_names += ", ";
@@ -193,20 +200,28 @@ int main(int argc, char** argv) {
}
dst_names += d.name;
}
+ for (auto v : via_types) {
+ if (!via_names.empty()) {
+ via_names += ", ";
+ }
+ via_names += v.name;
+ }
- printf("%s [-j N] [-m regex] [-s regex] [-w dir] [-h] src[:k=v,...] dst[:k=v,...] \n"
- " -j: Run at most N processes at any time. \n"
- " If <0, use -N threads instead. \n"
- " If 0, use one thread in one process. \n"
- " If 1 (default) or -1, auto-detect N. \n"
- " -m: Run only names matching regex exactly. \n"
- " -s: Run only names matching regex anywhere. \n"
- " -w: If set, write .pngs into dir. \n"
- " -h: Print this message and exit. \n"
- " src: content to draw: %s \n"
- " dst: how to draw that content: %s \n"
- " Some srcs and dsts have options, e.g. skp:dir=skps sw:ct=565 \n",
- argv[0], stream_names.c_str(), dst_names.c_str());
+ printf("%s [-j N] [-m regex] [-s regex] [-w dir] [-h] \n"
+ " src[:k=v,...] dst[:k=v,...] [via[:k=v,...]] \n"
+ " -j: Run at most N processes at any time. \n"
+ " If <0, use -N threads instead. \n"
+ " If 0, use one thread in one process. \n"
+ " If 1 (default) or -1, auto-detect N. \n"
+ " -m: Run only names matching regex exactly. \n"
+ " -s: Run only names matching regex anywhere. \n"
+ " -w: If set, write .pngs into dir. \n"
+ " -h: Print this message and exit. \n"
+ " src: content to draw: %s \n"
+ " dst: how to draw that content: %s \n"
+ " via: front-patch the dst: %s \n"
+ " Some srcs, dsts and vias have options, e.g. skp:dir=skps sw:ct=565 \n",
+ argv[0], stream_names.c_str(), dst_names.c_str(), via_names.c_str());
return 1;
};
@@ -232,7 +247,18 @@ int main(int argc, char** argv) {
switch (argv[i][len]) {
case ':': len++;
case '\0': dst_factory = [=](SkISize size){
- return d.factory(size, Options{argv[i]+len});
+ return d.factory(Options{argv[i]+len}, size);
+ };
+ }
+ }
+ }
+ for (auto v : via_types) {
+ size_t len = strlen(v.name);
+ if (0 == strncmp(v.name, argv[i], len)) {
+ switch (argv[i][len]) {
+ case ':': len++;
+ case '\0': via_factory = [=](SkISize size, std::unique_ptr<Dst> dst) {
+ return v.factory(Options{argv[i]+len}, size, std::move(dst));
};
}
}
@@ -296,7 +322,11 @@ int main(int argc, char** argv) {
return Status::Skipped;
}
- auto dst = dst_factory(src->size());
+ auto size = src->size();
+ auto dst = dst_factory(size);
+ if (via_factory) {
+ dst = via_factory(size, std::move(dst));
+ }
auto canvas = dst->canvas();
src->draw(canvas);
@@ -318,12 +348,18 @@ int main(int argc, char** argv) {
}
-Register::Register(const char* name, std::unique_ptr<Stream> (*factory)(Options)) {
+Register::Register(const char* name,
+ std::unique_ptr<Stream> (*factory)(Options)) {
stream_types.push_back(StreamType{name, factory});
}
-Register::Register(const char* name, std::unique_ptr<Dst> (*factory)(SkISize, Options)) {
+Register::Register(const char* name,
+ std::unique_ptr<Dst> (*factory)(Options, SkISize)) {
dst_types.push_back(DstType{name, factory});
}
+Register::Register(const char* name,
+ std::unique_ptr<Dst> (*factory)(Options, SkISize, std::unique_ptr<Dst>)) {
+ via_types.push_back(ViaType{name, factory});
+}
Options::Options(std::string str) {
std::string k,v, *curr = &k;
diff --git a/tools/ok.h b/tools/ok.h
index ab05074aac..99a5ca0b43 100644
--- a/tools/ok.h
+++ b/tools/ok.h
@@ -47,8 +47,12 @@ public:
// 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));
+ 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>));
};
#endif//ok_DEFINED
diff --git a/tools/ok_dsts.cpp b/tools/ok_dsts.cpp
index 143650c4d4..41dfdcf34a 100644
--- a/tools/ok_dsts.cpp
+++ b/tools/ok_dsts.cpp
@@ -11,7 +11,7 @@
struct SWDst : Dst {
sk_sp<SkSurface> surface;
- static std::unique_ptr<Dst> Create(SkISize size, Options options) {
+ static std::unique_ptr<Dst> Create(Options options, SkISize size) {
SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height());
if (options("ct") == "565") { info = info.makeColorType(kRGB_565_SkColorType); }
if (options("ct") == "f16") { info = info.makeColorType(kRGBA_F16_SkColorType); }
diff --git a/tools/ok_vias.cpp b/tools/ok_vias.cpp
new file mode 100644
index 0000000000..f13bcc13a7
--- /dev/null
+++ b/tools/ok_vias.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "ok.h"
+#include "SkPictureRecorder.h"
+
+struct ViaPic : Dst {
+ std::unique_ptr<Dst> target;
+ SkPictureRecorder rec;
+
+ static std::unique_ptr<Dst> Create(Options options, SkISize size, std::unique_ptr<Dst> dst) {
+ SkBBHFactory* bbh = nullptr;
+ SkRTreeFactory rtree;
+
+ if (options("bbh") == "rtree") { bbh = &rtree; }
+
+ auto via = std::unique_ptr<ViaPic>(new ViaPic);
+ via->target = std::move(dst);
+ via->rec.beginRecording(SkRect::MakeSize(SkSize::Make(size)), bbh);
+ return std::move(via);
+ }
+
+ SkCanvas* canvas() override {
+ return rec.getRecordingCanvas();
+ }
+
+ void write(std::string path_prefix) override {
+ auto pic = rec.finishRecordingAsPicture();
+ pic->playback(target->canvas());
+ target->write(path_prefix);
+ }
+};
+static Register via_pic{"via_pic", ViaPic::Create};