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-09-29 19:43:28 +00:00
|
|
|
if (options("ct") == "a8") { info = info.makeColorType(kAlpha_8_SkColorType); }
|
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-05-03 01:04:34 +00:00
|
|
|
if (options("cs") == "srgb") {
|
|
|
|
auto cs = info.colorType() == kRGBA_F16_SkColorType ? SkColorSpace::MakeSRGBLinear()
|
|
|
|
: SkColorSpace::MakeSRGB();
|
|
|
|
info = info.makeColorSpace(std::move(cs));
|
|
|
|
}
|
|
|
|
|
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-06-13 11:56:40 +00:00
|
|
|
static Register _8888{"8888", "alias for sw", SWDst::Create};
|
2017-03-27 16:43:44 +00:00
|
|
|
|
2017-09-29 19:43:28 +00:00
|
|
|
static Register a8{"a8", "alias for sw:ct=a8", [](Options options) {
|
|
|
|
options["ct"] = "a8";
|
|
|
|
return SWDst::Create(options);
|
|
|
|
}};
|
|
|
|
|
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);
|
|
|
|
}};
|
2017-05-03 01:04:34 +00:00
|
|
|
|
|
|
|
static Register srgb{"srgb", "alias for sw:cs=srgb", [](Options options) {
|
|
|
|
options["cs"] = "srgb";
|
|
|
|
return SWDst::Create(options);
|
|
|
|
}};
|
|
|
|
|
|
|
|
static Register f16{"f16", "alias for sw:ct=f16,cs=srgb", [](Options options) {
|
|
|
|
options["ct"] = "f16";
|
|
|
|
options["cs"] = "srgb";
|
|
|
|
return SWDst::Create(options);
|
|
|
|
}};
|
2017-06-13 11:56:40 +00:00
|
|
|
|
|
|
|
extern bool gSkForceRasterPipelineBlitter;
|
|
|
|
static Register rp{"rp", "draw forcing SkRasterPipelineBlitter", [](Options options) {
|
|
|
|
gSkForceRasterPipelineBlitter = true;
|
|
|
|
return SWDst::Create(options);
|
|
|
|
}};
|