aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/ok_dsts.cpp
blob: 20b66d5bcf61d84f37b833a89d08aacc77ac4c4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "ok.h"
#include "SkSurface.h"

struct SWDst : Dst {
    SkImageInfo      info;
    sk_sp<SkSurface> surface;

    static std::unique_ptr<Dst> Create(Options options) {
        SkImageInfo info = SkImageInfo::MakeN32Premul(0,0);
        if (options("ct") == "565") { info = info.makeColorType(kRGB_565_SkColorType); }
        if (options("ct") == "f16") { info = info.makeColorType(kRGBA_F16_SkColorType); }

        SWDst dst;
        dst.info = info;
        return move_unique(dst);
    }

    Status draw(Src* src) override {
        auto size = src->size();
        surface = SkSurface::MakeRaster(info.makeWH(size.width(), size.height()));
        return src->draw(surface->getCanvas());
    }

    sk_sp<SkImage> image() override {
        return surface->makeImageSnapshot();
    }
};
static Register sw{"sw", "draw with the software backend", SWDst::Create};

static Register _565{"565", "alias for sw:ct=565", [](Options options) {
    options["ct"] = "565";
    return SWDst::Create(options);
}};