aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/ok_srcs.cpp
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2017-03-25 11:29:41 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-25 16:13:20 +0000
commit7ac04838c58eebbac477895fafdd4b0421727b9e (patch)
tree2630f44c14617feb41b43710b6b092da57027b47 /tools/ok_srcs.cpp
parent5fa3d6d4b15fd6417de877561f5e4bca422e383c (diff)
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>
Diffstat (limited to 'tools/ok_srcs.cpp')
-rw-r--r--tools/ok_srcs.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/tools/ok_srcs.cpp b/tools/ok_srcs.cpp
new file mode 100644
index 0000000000..ce3e653d92
--- /dev/null
+++ b/tools/ok_srcs.cpp
@@ -0,0 +1,99 @@
+/*
+ * 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 "gm.h"
+#include "SkOSFile.h"
+#include "SkPicture.h"
+#include <vector>
+
+struct GMStream : Stream {
+ const skiagm::GMRegistry* registry = skiagm::GMRegistry::Head();
+
+ static std::unique_ptr<Stream> Create(Options) {
+ GMStream stream;
+ return move_unique(stream);
+ }
+
+ struct GMSrc : Src {
+ skiagm::GM* (*factory)(void*);
+ std::unique_ptr<skiagm::GM> gm;
+
+ std::string name() override {
+ gm.reset(factory(nullptr));
+ return gm->getName();
+ }
+
+ SkISize size() override {
+ return gm->getISize();
+ }
+
+ void draw(SkCanvas* canvas) override {
+ canvas->clear(0xffffffff);
+ canvas->concat(gm->getInitialTransform());
+ gm->draw(canvas);
+ }
+ };
+
+ std::unique_ptr<Src> next() override {
+ if (!registry) {
+ return nullptr;
+ }
+ GMSrc src;
+ src.factory = registry->factory();
+ registry = registry->next();
+ return move_unique(src);
+ }
+};
+static Register gm{"gm", GMStream::Create};
+
+struct SKPStream : Stream {
+ std::string dir;
+ std::vector<std::string> skps;
+
+ static std::unique_ptr<Stream> Create(Options options) {
+ SKPStream stream;
+ stream.dir = options("dir", "skps");
+ SkOSFile::Iter it{stream.dir.c_str(), ".skp"};
+ for (SkString path; it.next(&path); ) {
+ stream.skps.push_back(path.c_str());
+ }
+ return move_unique(stream);
+ }
+
+ struct SKPSrc : Src {
+ std::string dir, path;
+ sk_sp<SkPicture> pic;
+
+ std::string name() override {
+ return path;
+ }
+
+ SkISize size() override {
+ auto skp = SkData::MakeFromFileName((dir+"/"+path).c_str());
+ pic = SkPicture::MakeFromData(skp.get());
+ return pic->cullRect().roundOut().size();
+ }
+
+ void draw(SkCanvas* canvas) override {
+ canvas->clear(0xffffffff);
+ pic->playback(canvas);
+ }
+ };
+
+ std::unique_ptr<Src> next() override {
+ if (skps.empty()) {
+ return nullptr;
+ }
+ SKPSrc src;
+ src.dir = dir;
+ src.path = skps.back();
+ skps.pop_back();
+ return move_unique(src);
+ }
+};
+static Register skp{"skp", SKPStream::Create};