blob: 1f4fe42a4b63d7353f47ee389179d6ebc1c06bd5 [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 Klein9a3478b2017-09-29 15:43:28 -040017 if (options("ct") == "a8") { info = info.makeColorType(kAlpha_8_SkColorType); }
Mike Klein7ac04832017-03-25 11:29:41 -040018 if (options("ct") == "565") { info = info.makeColorType(kRGB_565_SkColorType); }
19 if (options("ct") == "f16") { info = info.makeColorType(kRGBA_F16_SkColorType); }
Mike Klein0222e702017-03-25 15:53:14 -040020
Mike Klein16a61442017-05-02 21:04:34 -040021 if (options("cs") == "srgb") {
22 auto cs = info.colorType() == kRGBA_F16_SkColorType ? SkColorSpace::MakeSRGBLinear()
23 : SkColorSpace::MakeSRGB();
24 info = info.makeColorSpace(std::move(cs));
25 }
26
Mike Klein7ac04832017-03-25 11:29:41 -040027 SWDst dst;
Mike Klein0222e702017-03-25 15:53:14 -040028 dst.info = info;
Mike Klein7ac04832017-03-25 11:29:41 -040029 return move_unique(dst);
30 }
31
Mike Kleine15a7b52017-03-29 12:41:13 -040032 Status draw(Src* src) override {
Mike Klein0222e702017-03-25 15:53:14 -040033 auto size = src->size();
34 surface = SkSurface::MakeRaster(info.makeWH(size.width(), size.height()));
35 return src->draw(surface->getCanvas());
Mike Klein7ac04832017-03-25 11:29:41 -040036 }
37
Mike Klein0222e702017-03-25 15:53:14 -040038 sk_sp<SkImage> image() override {
39 return surface->makeImageSnapshot();
Mike Klein7ac04832017-03-25 11:29:41 -040040 }
41};
Mike Kleine15a7b52017-03-29 12:41:13 -040042static Register sw{"sw", "draw with the software backend", SWDst::Create};
Mike Kleina611be82017-06-13 07:56:40 -040043static Register _8888{"8888", "alias for sw", SWDst::Create};
Mike Klein88f9c1e2017-03-27 12:43:44 -040044
Mike Klein9a3478b2017-09-29 15:43:28 -040045static Register a8{"a8", "alias for sw:ct=a8", [](Options options) {
46 options["ct"] = "a8";
47 return SWDst::Create(options);
48}};
49
Mike Kleine15a7b52017-03-29 12:41:13 -040050static Register _565{"565", "alias for sw:ct=565", [](Options options) {
Mike Klein88f9c1e2017-03-27 12:43:44 -040051 options["ct"] = "565";
52 return SWDst::Create(options);
53}};
Mike Klein16a61442017-05-02 21:04:34 -040054
55static Register srgb{"srgb", "alias for sw:cs=srgb", [](Options options) {
56 options["cs"] = "srgb";
57 return SWDst::Create(options);
58}};
59
60static Register f16{"f16", "alias for sw:ct=f16,cs=srgb", [](Options options) {
61 options["ct"] = "f16";
62 options["cs"] = "srgb";
63 return SWDst::Create(options);
64}};
Mike Kleina611be82017-06-13 07:56:40 -040065
66extern bool gSkForceRasterPipelineBlitter;
67static Register rp{"rp", "draw forcing SkRasterPipelineBlitter", [](Options options) {
68 gSkForceRasterPipelineBlitter = true;
69 return SWDst::Create(options);
70}};