blob: 034ca4564d9a71516901be2fb81618614724ab27 [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 Klein0222e702017-03-25 15:53:14 -040025 bool draw(Src* src) override {
26 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};
35static Register sw{"sw", SWDst::Create};
Mike Klein88f9c1e2017-03-27 12:43:44 -040036
37static Register _565{"565", [](Options options) {
38 options["ct"] = "565";
39 return SWDst::Create(options);
40}};