2017-03-25 15:29:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ok_DEFINED
|
|
|
|
#define ok_DEFINED
|
|
|
|
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include <functional>
|
2017-07-26 19:13:47 +00:00
|
|
|
#include <future>
|
2017-03-25 15:29:41 +00:00
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
// Not really ok-specific, but just kind of generally handy.
|
|
|
|
template <typename T>
|
|
|
|
static std::unique_ptr<T> move_unique(T& v) {
|
|
|
|
return std::unique_ptr<T>{new T{std::move(v)}};
|
|
|
|
}
|
|
|
|
|
2017-03-28 13:30:11 +00:00
|
|
|
void ok_log(const char*);
|
|
|
|
|
2017-03-29 16:41:13 +00:00
|
|
|
enum class Status { OK, Failed, Crashed, Skipped, None };
|
|
|
|
|
2017-07-26 19:13:47 +00:00
|
|
|
struct Engine {
|
|
|
|
virtual ~Engine() {}
|
|
|
|
virtual bool crashproof() = 0;
|
|
|
|
virtual std::future<Status> spawn(std::function<Status(void)>) = 0;
|
|
|
|
};
|
|
|
|
|
2017-03-25 15:29:41 +00:00
|
|
|
struct Src {
|
|
|
|
virtual ~Src() {}
|
2017-03-29 16:41:13 +00:00
|
|
|
virtual std::string name() = 0;
|
|
|
|
virtual SkISize size() = 0;
|
|
|
|
virtual Status draw(SkCanvas*) = 0;
|
2017-03-25 15:29:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Stream {
|
|
|
|
virtual ~Stream() {}
|
|
|
|
virtual std::unique_ptr<Src> next() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Dst {
|
|
|
|
virtual ~Dst() {}
|
2017-03-29 16:41:13 +00:00
|
|
|
virtual Status draw(Src*) = 0;
|
2017-03-25 19:53:14 +00:00
|
|
|
virtual sk_sp<SkImage> image() = 0;
|
2017-03-25 15:29:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Options {
|
|
|
|
std::map<std::string, std::string> kv;
|
|
|
|
public:
|
2017-03-27 16:43:44 +00:00
|
|
|
explicit Options(std::string = "");
|
|
|
|
std::string& operator[](std::string k);
|
|
|
|
std::string operator()(std::string k, std::string fallback = "") const;
|
2017-03-25 15:29:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Create globals to register your new type of Stream or Dst.
|
|
|
|
struct Register {
|
2017-07-26 19:13:47 +00:00
|
|
|
Register(const char* name, const char* help, std::unique_ptr<Engine> (*factory)(Options));
|
2017-03-29 16:41:13 +00:00
|
|
|
Register(const char* name, const char* help, std::unique_ptr<Stream> (*factory)(Options));
|
|
|
|
Register(const char* name, const char* help, std::unique_ptr<Dst> (*factory)(Options));
|
|
|
|
Register(const char* name, const char* help,
|
|
|
|
std::unique_ptr<Dst>(*factory)(Options, std::unique_ptr<Dst>));
|
2017-03-25 15:29:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif//ok_DEFINED
|