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> move_unique(T & v)19static std::unique_ptr<T> move_unique(T& v) { 20 return std::unique_ptr<T>{new T{std::move(v)}}; 21 } 22 23 struct Src { ~SrcSrc24 virtual ~Src() {} 25 virtual std::string name() = 0; 26 virtual SkISize size() = 0; 27 virtual bool draw(SkCanvas*) = 0; 28 }; 29 30 struct Stream { ~StreamStream31 virtual ~Stream() {} 32 virtual std::unique_ptr<Src> next() = 0; 33 }; 34 35 struct Dst { ~DstDst36 virtual ~Dst() {} 37 virtual bool draw(Src*) = 0; 38 virtual sk_sp<SkImage> image() = 0; 39 }; 40 41 class Options { 42 std::map<std::string, std::string> kv; 43 public: 44 explicit Options(std::string = ""); 45 std::string& operator[](std::string k); 46 std::string operator()(std::string k, std::string fallback = "") const; 47 }; 48 49 // Create globals to register your new type of Stream or Dst. 50 struct Register { 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>)); 54 }; 55 56 #endif//ok_DEFINED 57