Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 1 | /* |
| 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. |
| 18 | template <typename T> |
| 19 | static std::unique_ptr<T> move_unique(T& v) { |
| 20 | return std::unique_ptr<T>{new T{std::move(v)}}; |
| 21 | } |
| 22 | |
Mike Klein | 200f6da | 2017-03-28 09:30:11 -0400 | [diff] [blame] | 23 | void ok_log(const char*); |
| 24 | |
Mike Klein | e15a7b5 | 2017-03-29 12:41:13 -0400 | [diff] [blame] | 25 | enum class Status { OK, Failed, Crashed, Skipped, None }; |
| 26 | |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 27 | struct Src { |
| 28 | virtual ~Src() {} |
Mike Klein | e15a7b5 | 2017-03-29 12:41:13 -0400 | [diff] [blame] | 29 | virtual std::string name() = 0; |
| 30 | virtual SkISize size() = 0; |
| 31 | virtual Status draw(SkCanvas*) = 0; |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | struct Stream { |
| 35 | virtual ~Stream() {} |
| 36 | virtual std::unique_ptr<Src> next() = 0; |
| 37 | }; |
| 38 | |
| 39 | struct Dst { |
| 40 | virtual ~Dst() {} |
Mike Klein | e15a7b5 | 2017-03-29 12:41:13 -0400 | [diff] [blame] | 41 | virtual Status draw(Src*) = 0; |
Mike Klein | 0222e70 | 2017-03-25 15:53:14 -0400 | [diff] [blame] | 42 | virtual sk_sp<SkImage> image() = 0; |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | class Options { |
| 46 | std::map<std::string, std::string> kv; |
| 47 | public: |
Mike Klein | 88f9c1e | 2017-03-27 12:43:44 -0400 | [diff] [blame] | 48 | explicit Options(std::string = ""); |
| 49 | std::string& operator[](std::string k); |
| 50 | std::string operator()(std::string k, std::string fallback = "") const; |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | // Create globals to register your new type of Stream or Dst. |
| 54 | struct Register { |
Mike Klein | e15a7b5 | 2017-03-29 12:41:13 -0400 | [diff] [blame] | 55 | 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 Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | #endif//ok_DEFINED |