aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/viewer
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2018-04-05 14:34:45 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-04-05 19:05:28 +0000
commit0ffa322ecd313badaa006d950d64d2efad6185f9 (patch)
tree10fb97b15692d461c5fb42e26d633b88a6df8646 /tools/viewer
parent03d4f19558d3569495aa5d4b0683d84b5ad74ce6 (diff)
[viewer] Consolidate external slide loading
Handle all external slides (.skp, .jpg, .json, .svg) consistently: * support both single-file/directory flags * add "directory" slides for all types Change-Id: I4881c51f597ed4cb2a5b4c61706a168c754a5a8f Reviewed-on: https://skia-review.googlesource.com/119020 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'tools/viewer')
-rw-r--r--tools/viewer/Viewer.cpp124
1 files changed, 52 insertions, 72 deletions
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index fb659555e2..9b6a89adf1 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -511,86 +511,66 @@ void Viewer::initSlides() {
reg = reg->next();
}
- // SKPs
- for (int i = 0; i < FLAGS_skps.count(); i++) {
- if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
- if (SkCommandLineFlags::ShouldSkip(FLAGS_match, FLAGS_skps[i])) {
- continue;
- }
-
- SkString path(FLAGS_skps[i]);
- sk_sp<SKPSlide> slide(new SKPSlide(SkOSPath::Basename(path.c_str()), path));
- if (slide) {
- fSlides.push_back(slide);
- }
- } else {
- SkOSFile::Iter it(FLAGS_skps[i], ".skp");
- SkString skpName;
- while (it.next(&skpName)) {
- if (SkCommandLineFlags::ShouldSkip(FLAGS_match, skpName.c_str())) {
- continue;
- }
-
- SkString path = SkOSPath::Join(FLAGS_skps[i], skpName.c_str());
- sk_sp<SKPSlide> slide(new SKPSlide(skpName, path));
- if (slide) {
- fSlides.push_back(slide);
- }
- }
- }
- }
-
- // JPGs
- for (int i = 0; i < FLAGS_jpgs.count(); i++) {
- SkOSFile::Iter it(FLAGS_jpgs[i], ".jpg");
- SkString jpgName;
- while (it.next(&jpgName)) {
- if (SkCommandLineFlags::ShouldSkip(FLAGS_match, jpgName.c_str())) {
- continue;
- }
-
- SkString path = SkOSPath::Join(FLAGS_jpgs[i], jpgName.c_str());
- sk_sp<ImageSlide> slide(new ImageSlide(jpgName, path));
- if (slide) {
- fSlides.push_back(slide);
- }
+ using SlideFactory = sk_sp<Slide>(*)(const SkString& name, const SkString& path);
+ static const struct {
+ const char* fExtension;
+ const char* fDirName;
+ const SkCommandLineFlags::StringArray& fFlags;
+ const SlideFactory fFactory;
+ } gExternalSlidesInfo[] = {
+ { ".skp", "skp-dir", FLAGS_skps,
+ [](const SkString& name, const SkString& path) -> sk_sp<Slide> {
+ return sk_make_sp<SKPSlide>(name, path);}
+ },
+ { ".jpg", "jpg-dir", FLAGS_jpgs,
+ [](const SkString& name, const SkString& path) -> sk_sp<Slide> {
+ return sk_make_sp<ImageSlide>(name, path);}
+ },
+ { ".json", "skottie-dir", FLAGS_jsons,
+ [](const SkString& name, const SkString& path) -> sk_sp<Slide> {
+ return sk_make_sp<SkottieSlide>(name, path);}
+ },
+ { ".svg", "svg-dir", FLAGS_svgs,
+ [](const SkString& name, const SkString& path) -> sk_sp<Slide> {
+ return sk_make_sp<SvgSlide>(name, path);}
+ },
+ };
+
+ SkTArray<sk_sp<Slide>, true> dirSlides;
+
+ const auto addSlide = [&](const SkString& name,
+ const SkString& path,
+ const SlideFactory& fact) {
+ if (SkCommandLineFlags::ShouldSkip(FLAGS_match, name.c_str())) {
+ return;
}
- }
- // JSONs
- for (const auto& json : FLAGS_jsons) {
- SkTArray<sk_sp<Slide>, true> dirSlides;
-
- SkOSFile::Iter it(json.c_str(), ".json");
- SkString jsonName;
- while (it.next(&jsonName)) {
- if (SkCommandLineFlags::ShouldSkip(FLAGS_match, jsonName.c_str())) {
- continue;
- }
- auto slide = sk_make_sp<SkottieSlide>(jsonName, SkOSPath::Join(json.c_str(),
- jsonName.c_str()));
+ if (auto slide = fact(name, path)) {
dirSlides.push_back(slide);
fSlides.push_back(std::move(slide));
}
+ };
- if (!dirSlides.empty()) {
- fSlides.push_back(sk_make_sp<SlideDir>(SkStringPrintf("skottie-dir[%s]", json.c_str()),
- std::move(dirSlides)));
- }
- }
-
- // SVGs
- for (const auto& svg : FLAGS_svgs) {
- SkOSFile::Iter it(svg.c_str(), ".svg");
+ for (const auto& info : gExternalSlidesInfo) {
+ for (const auto& flag : info.fFlags) {
+ if (SkStrEndsWith(flag.c_str(), info.fExtension)) {
+ // single file
+ addSlide(SkOSPath::Basename(flag.c_str()), flag, info.fFactory);
+ } else {
+ // directory
+ SkOSFile::Iter it(flag.c_str(), info.fExtension);
+ SkString name;
+ while (it.next(&name)) {
+ addSlide(name, SkOSPath::Join(flag.c_str(), name.c_str()), info.fFactory);
+ }
+ }
- SkString svgName;
- while (it.next(&svgName)) {
- if (SkCommandLineFlags::ShouldSkip(FLAGS_match, svgName.c_str())) {
- continue;
+ if (!dirSlides.empty()) {
+ fSlides.push_back(
+ sk_make_sp<SlideDir>(SkStringPrintf("%s[%s]", info.fDirName, flag.c_str()),
+ std::move(dirSlides)));
+ dirSlides.reset();
}
- auto slide = sk_make_sp<SvgSlide>(svgName, SkOSPath::Join(svg.c_str(),
- svgName.c_str()));
- fSlides.push_back(std::move(slide));
}
}
}