blob: 345465badac3c95c82f9e27a9d1b0a6795969508 [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 Klein7ac04832017-03-25 11:29:41 -040025struct Src {
26 virtual ~Src() {}
Mike Klein0222e702017-03-25 15:53:14 -040027 virtual std::string name() = 0;
28 virtual SkISize size() = 0;
29 virtual bool draw(SkCanvas*) = 0;
Mike Klein7ac04832017-03-25 11:29:41 -040030};
31
32struct Stream {
33 virtual ~Stream() {}
34 virtual std::unique_ptr<Src> next() = 0;
35};
36
37struct Dst {
38 virtual ~Dst() {}
Mike Klein0222e702017-03-25 15:53:14 -040039 virtual bool draw(Src*) = 0;
40 virtual sk_sp<SkImage> image() = 0;
Mike Klein7ac04832017-03-25 11:29:41 -040041};
42
43class Options {
44 std::map<std::string, std::string> kv;
45public:
Mike Klein88f9c1e2017-03-27 12:43:44 -040046 explicit Options(std::string = "");
47 std::string& operator[](std::string k);
48 std::string operator()(std::string k, std::string fallback = "") const;
Mike Klein7ac04832017-03-25 11:29:41 -040049};
50
51// Create globals to register your new type of Stream or Dst.
52struct Register {
Mike Klein0222e702017-03-25 15:53:14 -040053 Register(const char* name, std::unique_ptr<Stream> (*factory)(Options));
54 Register(const char* name, std::unique_ptr<Dst> (*factory)(Options));
55 Register(const char* name, std::unique_ptr<Dst> (*factory)(Options, std::unique_ptr<Dst>));
Mike Klein7ac04832017-03-25 11:29:41 -040056};
57
58#endif//ok_DEFINED