blob: d03c95009de72be5ca72523315549db4105b59c7 [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 Klein16a61442017-05-02 21:04:34 -040020 if (options("cs") == "srgb") {
21 auto cs = info.colorType() == kRGBA_F16_SkColorType ? SkColorSpace::MakeSRGBLinear()
22 : SkColorSpace::MakeSRGB();
23 info = info.makeColorSpace(std::move(cs));
24 }
25
Mike Klein7ac04832017-03-25 11:29:41 -040026 SWDst dst;
Mike Klein0222e702017-03-25 15:53:14 -040027 dst.info = info;
Mike Klein7ac04832017-03-25 11:29:41 -040028 return move_unique(dst);
29 }
30
Mike Kleine15a7b52017-03-29 12:41:13 -040031 Status draw(Src* src) override {
Mike Klein0222e702017-03-25 15:53:14 -040032 auto size = src->size();
33 surface = SkSurface::MakeRaster(info.makeWH(size.width(), size.height()));
34 return src->draw(surface->getCanvas());
Mike Klein7ac04832017-03-25 11:29:41 -040035 }
36
Mike Klein0222e702017-03-25 15:53:14 -040037 sk_sp<SkImage> image() override {
38 return surface->makeImageSnapshot();
Mike Klein7ac04832017-03-25 11:29:41 -040039 }
40};
Mike Kleine15a7b52017-03-29 12:41:13 -040041static Register sw{"sw", "draw with the software backend", SWDst::Create};
Mike Klein88f9c1e2017-03-27 12:43:44 -040042
Mike Kleine15a7b52017-03-29 12:41:13 -040043static Register _565{"565", "alias for sw:ct=565", [](Options options) {
Mike Klein88f9c1e2017-03-27 12:43:44 -040044 options["ct"] = "565";
45 return SWDst::Create(options);
46}};
Mike Klein16a61442017-05-02 21:04:34 -040047
48static Register srgb{"srgb", "alias for sw:cs=srgb", [](Options options) {
49 options["cs"] = "srgb";
50 return SWDst::Create(options);
51}};
52
53static Register f16{"f16", "alias for sw:ct=f16,cs=srgb", [](Options options) {
54 options["ct"] = "f16";
55 options["cs"] = "srgb";
56 return SWDst::Create(options);
57}};