skia2/tools/ok_dsts.cpp
Mike Klein 88f9c1eff9 ok: alias 565 -> sw:ct=565
This is mostly a demo, and to make sure it's easy.
If I'm thinking right, other non-ct options should Just Work.

Change-Id: I295db0fa04921ccdd766e1870e367594ca802462
Reviewed-on: https://skia-review.googlesource.com/10190
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
2017-03-27 17:24:35 +00:00

41 lines
1.1 KiB
C++

/*
* 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 {
SkImageInfo info;
sk_sp<SkSurface> surface;
static std::unique_ptr<Dst> Create(Options options) {
SkImageInfo info = SkImageInfo::MakeN32Premul(0,0);
if (options("ct") == "565") { info = info.makeColorType(kRGB_565_SkColorType); }
if (options("ct") == "f16") { info = info.makeColorType(kRGBA_F16_SkColorType); }
SWDst dst;
dst.info = info;
return move_unique(dst);
}
bool draw(Src* src) override {
auto size = src->size();
surface = SkSurface::MakeRaster(info.makeWH(size.width(), size.height()));
return src->draw(surface->getCanvas());
}
sk_sp<SkImage> image() override {
return surface->makeImageSnapshot();
}
};
static Register sw{"sw", SWDst::Create};
static Register _565{"565", [](Options options) {
options["ct"] = "565";
return SWDst::Create(options);
}};