diff options
Diffstat (limited to 'dm')
-rw-r--r-- | dm/DM.cpp | 39 | ||||
-rw-r--r-- | dm/DMSrcSink.cpp | 31 | ||||
-rw-r--r-- | dm/DMSrcSink.h | 15 |
3 files changed, 65 insertions, 20 deletions
@@ -73,6 +73,8 @@ DEFINE_int32(shard, 0, "Which shard do I run?"); DEFINE_string(mskps, "", "Directory to read mskps from, or a single mskp file."); +DEFINE_string(svgs, "", "Directory to read SVGs from, or a single SVG file."); + using namespace DM; using sk_gpu_test::GrContextFactory; using sk_gpu_test::GLTestContext; @@ -710,35 +712,32 @@ static bool brd_supported(const char* ext) { return false; } -static bool gather_srcs() { - for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) { - push_src("gm", "", new GMSrc(r->factory())); - } - for (int i = 0; i < FLAGS_skps.count(); i++) { - const char* path = FLAGS_skps[i]; +template <typename T> +void gather_file_srcs(const SkCommandLineFlags::StringArray& flags, const char* ext) { + for (int i = 0; i < flags.count(); i++) { + const char* path = flags[i]; if (sk_isdir(path)) { - SkOSFile::Iter it(path, "skp"); + SkOSFile::Iter it(path, ext); for (SkString file; it.next(&file); ) { - push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str()))); + push_src(ext, "", new T(SkOSPath::Join(path, file.c_str()))); } } else { - push_src("skp", "", new SKPSrc(path)); + push_src(ext, "", new T(path)); } } +} - for (int i = 0; i < FLAGS_mskps.count(); i++) { - const char* path = FLAGS_mskps[i]; - if (sk_isdir(path)) { - SkOSFile::Iter it(path, "mskp"); - for (SkString file; it.next(&file);) { - push_src("mskp", "", - new MSKPSrc(SkOSPath::Join(path, file.c_str()))); - } - } else { - push_src("mskp", "", new MSKPSrc(path)); - } +static bool gather_srcs() { + for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) { + push_src("gm", "", new GMSrc(r->factory())); } + gather_file_srcs<SKPSrc>(FLAGS_skps, "skp"); + gather_file_srcs<MSKPSrc>(FLAGS_mskps, "mskp"); +#if defined(SK_XML) + gather_file_srcs<SVGSrc>(FLAGS_svgs, "svg"); +#endif + SkTArray<SkString> images; if (!CollectImages(FLAGS_images, &images)) { return false; diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index a00f468a3f..f821616281 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -34,6 +34,7 @@ #include "SkSVGCanvas.h" #include "SkStream.h" #include "SkTLogic.h" +#include "SkSVGDOM.h" #include "SkSwizzler.h" #include <functional> @@ -1025,6 +1026,36 @@ SkISize SKPSrc::size() const { Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +#if defined(SK_XML) +// Should we try to use the SVG intrinsic size instead? +static const SkSize kSVGSize = SkSize::Make(1000, 1000); + +SVGSrc::SVGSrc(Path path) : fPath(path) {} + +Error SVGSrc::draw(SkCanvas* canvas) const { + SkFILEStream stream(fPath.c_str()); + if (!stream.isValid()) { + return SkStringPrintf("Unable to open file: %s", fPath.c_str()); + } + + sk_sp<SkSVGDOM> dom = SkSVGDOM::MakeFromStream(stream, kSVGSize); + if (!dom) { + return SkStringPrintf("Unable to parse file: %s", fPath.c_str()); + } + + dom->render(canvas); + + return ""; +} + +SkISize SVGSrc::size() const { + return kSVGSize.toRound(); +} + +Name SVGSrc::name() const { return SkOSPath::Basename(fPath.c_str()); } + +#endif // defined(SK_XML) +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ MSKPSrc::MSKPSrc(Path path) : fPath(path) { std::unique_ptr<SkStreamAsset> stream(SkStream::NewFromFile(fPath.c_str())); diff --git a/dm/DMSrcSink.h b/dm/DMSrcSink.h index b05fdb0439..a54ddb8d7f 100644 --- a/dm/DMSrcSink.h +++ b/dm/DMSrcSink.h @@ -248,6 +248,21 @@ private: Path fPath; }; +#if defined(SK_XML) +class SVGSrc : public Src { +public: + explicit SVGSrc(Path path); + + Error draw(SkCanvas*) const override; + SkISize size() const override; + Name name() const override; + +private: + Path fPath; + + typedef Src INHERITED; +}; +#endif // SK_XML /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ class MSKPSrc : public Src { |