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 | |
| 23 | struct Src { |
| 24 | virtual ~Src() {} |
Mike Klein | 0222e70 | 2017-03-25 15:53:14 -0400 | [diff] [blame] | 25 | virtual std::string name() = 0; |
| 26 | virtual SkISize size() = 0; |
| 27 | virtual bool draw(SkCanvas*) = 0; |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | struct Stream { |
| 31 | virtual ~Stream() {} |
| 32 | virtual std::unique_ptr<Src> next() = 0; |
| 33 | }; |
| 34 | |
| 35 | struct Dst { |
| 36 | virtual ~Dst() {} |
Mike Klein | 0222e70 | 2017-03-25 15:53:14 -0400 | [diff] [blame] | 37 | virtual bool draw(Src*) = 0; |
| 38 | virtual sk_sp<SkImage> image() = 0; |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | class Options { |
| 42 | std::map<std::string, std::string> kv; |
| 43 | public: |
Mike Klein | 88f9c1e | 2017-03-27 12:43:44 -0400 | [diff] [blame^] | 44 | explicit Options(std::string = ""); |
| 45 | std::string& operator[](std::string k); |
| 46 | std::string operator()(std::string k, std::string fallback = "") const; |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | // Create globals to register your new type of Stream or Dst. |
| 50 | struct Register { |
Mike Klein | 0222e70 | 2017-03-25 15:53:14 -0400 | [diff] [blame] | 51 | Register(const char* name, std::unique_ptr<Stream> (*factory)(Options)); |
| 52 | Register(const char* name, std::unique_ptr<Dst> (*factory)(Options)); |
| 53 | Register(const char* name, std::unique_ptr<Dst> (*factory)(Options, std::unique_ptr<Dst>)); |
Mike Klein | 7ac0483 | 2017-03-25 11:29:41 -0400 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | #endif//ok_DEFINED |