blob: f55842b3d9ca11d8e8595fb7067044c4bebd72dc [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>
13#include <map>
14#include <memory>
15#include <string>
16
17// Not really ok-specific, but just kind of generally handy.
18template <typename T>
19static std::unique_ptr<T> move_unique(T& v) {
20 return std::unique_ptr<T>{new T{std::move(v)}};
21}
22
Mike Klein200f6da2017-03-28 09:30:11 -040023void ok_log(const char*);
24
Mike Kleine15a7b52017-03-29 12:41:13 -040025enum class Status { OK, Failed, Crashed, Skipped, None };
26
Mike Klein7ac04832017-03-25 11:29:41 -040027struct Src {
28 virtual ~Src() {}
Mike Kleine15a7b52017-03-29 12:41:13 -040029 virtual std::string name() = 0;
30 virtual SkISize size() = 0;
31 virtual Status draw(SkCanvas*) = 0;
Mike Klein7ac04832017-03-25 11:29:41 -040032};
33
34struct Stream {
35 virtual ~Stream() {}
36 virtual std::unique_ptr<Src> next() = 0;
37};
38
39struct Dst {
40 virtual ~Dst() {}
Mike Kleine15a7b52017-03-29 12:41:13 -040041 virtual Status draw(Src*) = 0;
Mike Klein0222e702017-03-25 15:53:14 -040042 virtual sk_sp<SkImage> image() = 0;
Mike Klein7ac04832017-03-25 11:29:41 -040043};
44
45class Options {
46 std::map<std::string, std::string> kv;
47public:
Mike Klein88f9c1e2017-03-27 12:43:44 -040048 explicit Options(std::string = "");
49 std::string& operator[](std::string k);
50 std::string operator()(std::string k, std::string fallback = "") const;
Mike Klein7ac04832017-03-25 11:29:41 -040051};
52
53// Create globals to register your new type of Stream or Dst.
54struct Register {
Mike Kleine15a7b52017-03-29 12:41:13 -040055 Register(const char* name, const char* help, std::unique_ptr<Stream> (*factory)(Options));
56 Register(const char* name, const char* help, std::unique_ptr<Dst> (*factory)(Options));
57 Register(const char* name, const char* help,
58 std::unique_ptr<Dst>(*factory)(Options, std::unique_ptr<Dst>));
Mike Klein7ac04832017-03-25 11:29:41 -040059};
60
61#endif//ok_DEFINED