1/*
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 {
12    SkImageInfo      info;
13    sk_sp<SkSurface> surface;
14
15    static std::unique_ptr<Dst> Create(Options options) {
16        SkImageInfo info = SkImageInfo::MakeN32Premul(0,0);
17        if (options("ct") == "565") { info = info.makeColorType(kRGB_565_SkColorType); }
18        if (options("ct") == "f16") { info = info.makeColorType(kRGBA_F16_SkColorType); }
19
20        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
26        SWDst dst;
27        dst.info = info;
28        return move_unique(dst);
29    }
30
31    Status draw(Src* src) override {
32        auto size = src->size();
33        surface = SkSurface::MakeRaster(info.makeWH(size.width(), size.height()));
34        return src->draw(surface->getCanvas());
35    }
36
37    sk_sp<SkImage> image() override {
38        return surface->makeImageSnapshot();
39    }
40};
41static Register sw{"sw", "draw with the software backend", SWDst::Create};
42static Register _8888{"8888", "alias for sw", SWDst::Create};
43
44static Register _565{"565", "alias for sw:ct=565", [](Options options) {
45    options["ct"] = "565";
46    return SWDst::Create(options);
47}};
48
49static Register srgb{"srgb", "alias for sw:cs=srgb", [](Options options) {
50    options["cs"] = "srgb";
51    return SWDst::Create(options);
52}};
53
54static Register f16{"f16", "alias for sw:ct=f16,cs=srgb", [](Options options) {
55    options["ct"] = "f16";
56    options["cs"] = "srgb";
57    return SWDst::Create(options);
58}};
59
60extern bool gSkForceRasterPipelineBlitter;
61static Register rp{"rp", "draw forcing SkRasterPipelineBlitter", [](Options options) {
62    gSkForceRasterPipelineBlitter = true;
63    return SWDst::Create(options);
64}};
65