aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/ok_vias.cpp
blob: f13bcc13a7e4782d55242b830d7eb5485bca8e2f (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
/*
 * 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 "SkPictureRecorder.h"

struct ViaPic : Dst {
    std::unique_ptr<Dst> target;
    SkPictureRecorder    rec;

    static std::unique_ptr<Dst> Create(Options options, SkISize size, std::unique_ptr<Dst> dst) {
        SkBBHFactory* bbh = nullptr;
        SkRTreeFactory rtree;

        if (options("bbh") == "rtree") { bbh = &rtree; }

        auto via = std::unique_ptr<ViaPic>(new ViaPic);
        via->target = std::move(dst);
        via->rec.beginRecording(SkRect::MakeSize(SkSize::Make(size)), bbh);
        return std::move(via);
    }

    SkCanvas* canvas() override {
        return rec.getRecordingCanvas();
    }

    void write(std::string path_prefix) override {
        auto pic = rec.finishRecordingAsPicture();
        pic->playback(target->canvas());
        target->write(path_prefix);
    }
};
static Register via_pic{"via_pic", ViaPic::Create};