blob: 502df23b4aa9cb5bae02f5cb024b4a0e976967ac [file] [log] [blame]
Mike Klein7ac04832017-03-25 11:29:41 -04001/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef ok_DEFINED
9#define ok_DEFINED
10
11#include "SkCanvas.h"
12#include <functional>
Mike Klein154e6da2017-07-26 15:13:47 -040013#include <future>
Mike Klein7ac04832017-03-25 11:29:41 -040014#include <map>
15#include <memory>
16#include <string>
17
18// Not really ok-specific, but just kind of generally handy.
19template <typename T>
20static std::unique_ptr<T> move_unique(T& v) {
21 return std::unique_ptr<T>{new T{std::move(v)}};
22}
23
Mike Klein200f6da2017-03-28 09:30:11 -040024void ok_log(const char*);
25
Mike Kleine15a7b52017-03-29 12:41:13 -040026enum class Status { OK, Failed, Crashed, Skipped, None };
27
Mike Klein154e6da2017-07-26 15:13:47 -040028struct Engine {
29 virtual ~Engine() {}
30 virtual bool crashproof() = 0;
31 virtual std::future<Status> spawn(std::function<Status(void)>) = 0;
32};
33
Mike Klein7ac04832017-03-25 11:29:41 -040034struct Src {
35 virtual ~Src() {}
Mike Kleine15a7b52017-03-29 12:41:13 -040036 virtual std::string name() = 0;
37 virtual SkISize size() = 0;
38 virtual Status draw(SkCanvas*) = 0;
Mike Klein7ac04832017-03-25 11:29:41 -040039};
40
41struct Stream {
42 virtual ~Stream() {}
43 virtual std::unique_ptr<Src> next() = 0;
44};
45
46struct Dst {
47 virtual ~Dst() {}
Mike Kleine15a7b52017-03-29 12:41:13 -040048 virtual Status draw(Src*) = 0;
Mike Klein0222e702017-03-25 15:53:14 -040049 virtual sk_sp<SkImage> image() = 0;
Mike Klein7ac04832017-03-25 11:29:41 -040050};
51
52class Options {
53 std::map<std::string, std::string> kv;
54public:
Mike Klein88f9c1e2017-03-27 12:43:44 -040055 explicit Options(std::string = "");
56 std::string& operator[](std::string k);
57 std::string operator()(std::string k, std::string fallback = "") const;
Mike Klein7ac04832017-03-25 11:29:41 -040058};
59
60// Create globals to register your new type of Stream or Dst.
61struct Register {
Mike Klein154e6da2017-07-26 15:13:47 -040062 Register(const char* name, const char* help, std::unique_ptr<Engine> (*factory)(Options));
Mike Kleine15a7b52017-03-29 12:41:13 -040063 Register(const char* name, const char* help, std::unique_ptr<Stream> (*factory)(Options));
64 Register(const char* name, const char* help, std::unique_ptr<Dst> (*factory)(Options));
65 Register(const char* name, const char* help,
66 std::unique_ptr<Dst>(*factory)(Options, std::unique_ptr<Dst>));
Mike Klein7ac04832017-03-25 11:29:41 -040067};
68
69#endif//ok_DEFINED