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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ok.h"
|
|
|
|
#include "SkSurface.h"
|
|
|
|
|
|
|
|
struct SWDst : Dst {
|
2017-03-25 19:53:14 +00:00
|
|
|
SkImageInfo info;
|
2017-03-25 15:29:41 +00:00
|
|
|
sk_sp<SkSurface> surface;
|
|
|
|
|
2017-03-25 19:53:14 +00:00
|
|
|
static std::unique_ptr<Dst> Create(Options options) {
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(0,0);
|
2017-03-25 15:29:41 +00:00
|
|
|
if (options("ct") == "565") { info = info.makeColorType(kRGB_565_SkColorType); }
|
|
|
|
if (options("ct") == "f16") { info = info.makeColorType(kRGBA_F16_SkColorType); }
|
2017-03-25 19:53:14 +00:00
|
|
|
|
2017-03-25 15:29:41 +00:00
|
|
|
SWDst dst;
|
2017-03-25 19:53:14 +00:00
|
|
|
dst.info = info;
|
2017-03-25 15:29:41 +00:00
|
|
|
return move_unique(dst);
|
|
|
|
}
|
|
|
|
|
2017-03-29 16:41:13 +00:00
|
|
|
Status draw(Src* src) override {
|
2017-03-25 19:53:14 +00:00
|
|
|
auto size = src->size();
|
|
|
|
surface = SkSurface::MakeRaster(info.makeWH(size.width(), size.height()));
|
|
|
|
return src->draw(surface->getCanvas());
|
2017-03-25 15:29:41 +00:00
|
|
|
}
|
|
|
|
|
2017-03-25 19:53:14 +00:00
|
|
|
sk_sp<SkImage> image() override {
|
|
|
|
return surface->makeImageSnapshot();
|
2017-03-25 15:29:41 +00:00
|
|
|
}
|
|
|
|
};
|
2017-03-29 16:41:13 +00:00
|
|
|
static Register sw{"sw", "draw with the software backend", SWDst::Create};
|
2017-03-27 16:43:44 +00:00
|
|
|
|
2017-03-29 16:41:13 +00:00
|
|
|
static Register _565{"565", "alias for sw:ct=565", [](Options options) {
|
2017-03-27 16:43:44 +00:00
|
|
|
options["ct"] = "565";
|
|
|
|
return SWDst::Create(options);
|
|
|
|
}};
|