blob: e2a6a344ee5df5a2703ac8953cc82a685bc048fe [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
23struct Src {
24 virtual ~Src() {}
Mike Klein0222e702017-03-25 15:53:14 -040025 virtual std::string name() = 0;
26 virtual SkISize size() = 0;
27 virtual bool draw(SkCanvas*) = 0;
Mike Klein7ac04832017-03-25 11:29:41 -040028};
29
30struct Stream {
31 virtual ~Stream() {}
32 virtual std::unique_ptr<Src> next() = 0;
33};
34
35struct Dst {
36 virtual ~Dst() {}
Mike Klein0222e702017-03-25 15:53:14 -040037 virtual bool draw(Src*) = 0;
38 virtual sk_sp<SkImage> image() = 0;
Mike Klein7ac04832017-03-25 11:29:41 -040039};
40
41class Options {
42 std::map<std::string, std::string> kv;
43public:
44 explicit Options(std::string str = "");
45 std::string operator()(std::string k, std::string fallback = "") const;
46};
47
48// Create globals to register your new type of Stream or Dst.
49struct Register {
Mike Klein0222e702017-03-25 15:53:14 -040050 Register(const char* name, std::unique_ptr<Stream> (*factory)(Options));
51 Register(const char* name, std::unique_ptr<Dst> (*factory)(Options));
52 Register(const char* name, std::unique_ptr<Dst> (*factory)(Options, std::unique_ptr<Dst>));
Mike Klein7ac04832017-03-25 11:29:41 -040053};
54
55#endif//ok_DEFINED