From a2b9fdfe0b2dd3408064b7cfd1bf8677eaf06491 Mon Sep 17 00:00:00 2001 From: fmalita Date: Wed, 3 Aug 2016 19:53:36 -0700 Subject: Add an SVG DM source R=mtklein@google.com,robertphillips@google.com,stephana@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2209593004 Review-Url: https://codereview.chromium.org/2209593004 --- BUILD.gn | 22 ++++++++++++++++++++++ dm/DM.cpp | 39 +++++++++++++++++++-------------------- dm/DMSrcSink.cpp | 31 +++++++++++++++++++++++++++++++ dm/DMSrcSink.h | 15 +++++++++++++++ gyp/dm.gypi | 1 + 5 files changed, 88 insertions(+), 20 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 0d15f3169c..1286a068e0 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -501,6 +501,27 @@ test_lib("bench") { ] } +test_lib("experimental_svg_model") { + public_include_dirs = [ "experimental/svg/model" ] + sources = [ + "experimental/svg/model/SkSVGAttribute.cpp", + "experimental/svg/model/SkSVGAttributeParser.cpp", + "experimental/svg/model/SkSVGContainer.cpp", + "experimental/svg/model/SkSVGDOM.cpp", + "experimental/svg/model/SkSVGNode.cpp", + "experimental/svg/model/SkSVGPath.cpp", + "experimental/svg/model/SkSVGRect.cpp", + "experimental/svg/model/SkSVGRenderContext.cpp", + "experimental/svg/model/SkSVGSVG.cpp", + "experimental/svg/model/SkSVGShape.cpp", + "experimental/svg/model/SkSVGTransformableNode.cpp", + "experimental/svg/model/SkSVGValue.cpp", + ] + deps = [ + ":skia", + ] +} + if (!is_component_build) { # Our test tools use many non-SK_API APIs... executable("dm") { sources = [ @@ -510,6 +531,7 @@ if (!is_component_build) { # Our test tools use many non-SK_API APIs... ] include_dirs = [ "tests" ] deps = [ + ":experimental_svg_model", ":flags", ":gm", ":gpu_tool_utils", diff --git a/dm/DM.cpp b/dm/DM.cpp index 4387fde1e1..fcc3c552ea 100644 --- a/dm/DM.cpp +++ b/dm/DM.cpp @@ -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 +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(FLAGS_skps, "skp"); + gather_file_srcs(FLAGS_mskps, "mskp"); +#if defined(SK_XML) + gather_file_srcs(FLAGS_svgs, "svg"); +#endif + SkTArray 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 @@ -1024,6 +1025,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 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) { 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 { diff --git a/gyp/dm.gypi b/gyp/dm.gypi index 1e766e0c3a..fab2f917ff 100644 --- a/gyp/dm.gypi +++ b/gyp/dm.gypi @@ -24,6 +24,7 @@ 'skia_lib.gyp:skia_lib', 'sksl.gyp:sksl', 'svg.gyp:svg', + 'svg.gyp:svgdom', 'tools.gyp:crash_handler', 'tools.gyp:picture_utils', 'tools.gyp:proc_stats', -- cgit v1.2.3