blob: 20b66d5bcf61d84f37b833a89d08aacc77ac4c4d [file] [log] [blame]
Mike Klein7ac04832017-03-25 11:29:41 -04001/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "ok.h"
9#include "SkSurface.h"
10
11struct SWDst : Dst {
Mike Klein0222e702017-03-25 15:53:14 -040012 SkImageInfo info;
Mike Klein7ac04832017-03-25 11:29:41 -040013 sk_sp<SkSurface> surface;
14
Mike Klein0222e702017-03-25 15:53:14 -040015 static std::unique_ptr<Dst> Create(Options options) {
16 SkImageInfo info = SkImageInfo::MakeN32Premul(0,0);
Mike Klein7ac04832017-03-25 11:29:41 -040017 if (options("ct") == "565") { info = info.makeColorType(kRGB_565_SkColorType); }
18 if (options("ct") == "f16") { info = info.makeColorType(kRGBA_F16_SkColorType); }
Mike Klein0222e702017-03-25 15:53:14 -040019
Mike Klein7ac04832017-03-25 11:29:41 -040020 SWDst dst;
Mike Klein0222e702017-03-25 15:53:14 -040021 dst.info = info;
Mike Klein7ac04832017-03-25 11:29:41 -040022 return move_unique(dst);
23 }
24
Mike Kleine15a7b52017-03-29 12:41:13 -040025 Status draw(Src* src) override {
Mike Klein0222e702017-03-25 15:53:14 -040026 auto size = src->size();
27 surface = SkSurface::MakeRaster(info.makeWH(size.width(), size.height()));
28 return src->draw(surface->getCanvas());
Mike Klein7ac04832017-03-25 11:29:41 -040029 }
30
Mike Klein0222e702017-03-25 15:53:14 -040031 sk_sp<SkImage> image() override {
32 return surface->makeImageSnapshot();
Mike Klein7ac04832017-03-25 11:29:41 -040033 }
34};
Mike Kleine15a7b52017-03-29 12:41:13 -040035static Register sw{"sw", "draw with the software backend", SWDst::Create};
Mike Klein88f9c1e2017-03-27 12:43:44 -040036
Mike Kleine15a7b52017-03-29 12:41:13 -040037static Register _565{"565", "alias for sw:ct=565", [](Options options) {
Mike Klein88f9c1e2017-03-27 12:43:44 -040038 options["ct"] = "565";
39 return SWDst::Create(options);
40}};