skia2/tools/ok_dsts.cpp
Mike Klein 7ac04838c5 Spin off non-core parts of ok into their own files.
Now ok.cpp handles only the high level coordination of Srcs and Dsts,
without having to know or care what they are.

Some minor refactoring to things like Options.

Change-Id: I02df890b26d6d069e980a125b6a1ce1a7067b900
Reviewed-on: https://skia-review.googlesource.com/10173
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
2017-03-25 16:13:20 +00:00

34 lines
1.0 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 {
sk_sp<SkSurface> surface;
static std::unique_ptr<Dst> Create(SkISize size, Options options) {
SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height());
if (options("ct") == "565") { info = info.makeColorType(kRGB_565_SkColorType); }
if (options("ct") == "f16") { info = info.makeColorType(kRGBA_F16_SkColorType); }
SWDst dst;
dst.surface = SkSurface::MakeRaster(info);
return move_unique(dst);
}
SkCanvas* canvas() override {
return surface->getCanvas();
}
void write(std::string path_prefix) override {
auto image = surface->makeImageSnapshot();
sk_sp<SkData> png{image->encode()};
SkFILEWStream{(path_prefix + ".png").c_str()}.write(png->data(), png->size());
}
};
static Register sw{"sw", SWDst::Create};