skia2/tools/ok_vias.cpp
Florin Malita ab244f045a Revert "Revert "Reland: Remove SkLights include from SkCanvas.h""
This reverts commit 9d5f66d9c2.

Reason for revert: Leon landed Android fixes.

Original change's description:
> Revert "Reland: Remove SkLights include from SkCanvas.h"
> 
> This reverts commit fed00319c9.
> 
> Reason for revert: breaking the Android roll.
> 
> Original change's description:
> > Reland: Remove SkLights include from SkCanvas.h
> > 
> > SkLights.h pulls in a bunch of other headers and is not needed (fwdecl
> > works fine).
> > 
> > Change-Id: I3ed97cd7861e51dcb7cfa7950a97b420dbc6fbfb
> > TBR=reed@google.com
> > Reviewed-on: https://skia-review.googlesource.com/15143
> > Commit-Queue: Florin Malita <fmalita@chromium.org>
> > Reviewed-by: Florin Malita <fmalita@chromium.org>
> > 
> 
> TBR=fmalita@chromium.org,reed@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> 
> Change-Id: I3b0e69f1d04d160f16a5567b09982d35cc9ca84e
> Reviewed-on: https://skia-review.googlesource.com/15195
> Reviewed-by: Florin Malita <fmalita@chromium.org>
> Commit-Queue: Florin Malita <fmalita@chromium.org>
> 

TBR=msarett@google.com,reviews@skia.org,fmalita@chromium.org,reed@google.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Change-Id: I0a1c2f9df61f16987ab72dfb4f3a205fbcc37667
Reviewed-on: https://skia-review.googlesource.com/15229
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
2017-05-03 19:17:11 +00:00

121 lines
3.4 KiB
C++

/*
* 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 "SkImage.h"
#include "SkOSFile.h"
#include "SkPictureRecorder.h"
#include "ok.h"
#include <regex>
static std::unique_ptr<Src> proxy(Src* original, std::function<Status(SkCanvas*)> fn) {
struct : Src {
Src* original;
std::function<Status(SkCanvas*)> fn;
std::string name() override { return original->name(); }
SkISize size() override { return original->size(); }
Status draw(SkCanvas* canvas) override { return fn(canvas); }
} src;
src.original = original;
src.fn = fn;
return move_unique(src);
}
struct ViaPic : Dst {
std::unique_ptr<Dst> target;
bool rtree = false;
static std::unique_ptr<Dst> Create(Options options, std::unique_ptr<Dst> dst) {
ViaPic via;
via.target = std::move(dst);
if (options("bbh") == "rtree") { via.rtree = true; }
return move_unique(via);
}
Status draw(Src* src) override {
SkRTreeFactory factory;
SkPictureRecorder rec;
rec.beginRecording(SkRect::MakeSize(SkSize::Make(src->size())),
rtree ? &factory : nullptr);
for (auto status = src->draw(rec.getRecordingCanvas()); status != Status::OK; ) {
return status;
}
auto pic = rec.finishRecordingAsPicture();
return target->draw(proxy(src, [=](SkCanvas* canvas) {
pic->playback(canvas);
return Status::OK;
}).get());
}
sk_sp<SkImage> image() override {
return target->image();
}
};
static Register via_pic{"via_pic", "record then play back an SkPicture", ViaPic::Create};
struct Png : Dst {
std::unique_ptr<Dst> target;
std::string dir;
static std::unique_ptr<Dst> Create(Options options, std::unique_ptr<Dst> dst) {
Png via;
via.target = std::move(dst);
via.dir = options("dir", "ok");
return move_unique(via);
}
Status draw(Src* src) override {
for (auto status = target->draw(src); status != Status::OK; ) {
return status;
}
auto image = target->image();
sk_sp<SkData> png{image->encode()};
sk_mkdir(dir.c_str());
SkFILEWStream{(dir + "/" + src->name() + ".png").c_str()}
.write(png->data(), png->size());
return Status::OK;
}
sk_sp<SkImage> image() override {
return target->image();
}
};
static Register png{"png", "dump PNGs to dir=ok" , Png::Create};
struct Filter : Dst {
std::unique_ptr<Dst> target;
std::regex match, search;
static std::unique_ptr<Dst> Create(Options options, std::unique_ptr<Dst> dst) {
Filter via;
via.target = std::move(dst);
via.match = options("match", ".*");
via.search = options("search", ".*");
return move_unique(via);
}
Status draw(Src* src) override {
auto name = src->name();
if (!std::regex_match (name, match) ||
!std::regex_search(name, search)) {
return Status::Skipped;
}
return target->draw(src);
}
sk_sp<SkImage> image() override {
return target->image();
}
};
struct Register filter{"filter",
"run only srcs matching match=.* exactly and search=.* somewhere",
Filter::Create};