diff options
author | fmalita <fmalita@chromium.org> | 2016-08-15 07:48:47 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-15 07:48:47 -0700 |
commit | 851d68aa5692103db67433354c7421863d01dbda (patch) | |
tree | 88a51afdda0c854928958d0f2017e1b3e97caee4 /samplecode | |
parent | d5d3287fe210d74f147e90a3906f5d1eaeb17dbf (diff) |
[SVGDom] Deferred SampleApp parsing
Parse SVG files in onOnceBeforeDraw() rather than ctor, to avoid
front-loading a bunch of work when passed a loarge number of SVGs.
R=stephana@google.com,robertphillips@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2245993002
Review-Url: https://codereview.chromium.org/2245993002
Diffstat (limited to 'samplecode')
-rw-r--r-- | samplecode/SampleApp.cpp | 4 | ||||
-rw-r--r-- | samplecode/SampleSVGFile.cpp | 22 |
2 files changed, 14 insertions, 12 deletions
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 439b699c38..62970302df 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -80,14 +80,14 @@ public: } }; -extern SampleView* CreateSampleSVGFileView(const char filename[]); +extern SampleView* CreateSampleSVGFileView(const SkString& filename); class SVGFileFactory : public SkViewFactory { SkString fFilename; public: SVGFileFactory(const SkString& filename) : fFilename(filename) {} SkView* operator() () const override { - return CreateSampleSVGFileView(fFilename.c_str()); + return CreateSampleSVGFileView(fFilename); } }; diff --git a/samplecode/SampleSVGFile.cpp b/samplecode/SampleSVGFile.cpp index 12c91a95fe..a4b5b34d7d 100644 --- a/samplecode/SampleSVGFile.cpp +++ b/samplecode/SampleSVGFile.cpp @@ -17,26 +17,27 @@ namespace { class SVGFileView : public SampleView { public: - SVGFileView(const char path[]) - : fLabel(SkStringPrintf("[%s]", SkOSPath::Basename(path).c_str())) { - SkFILEStream svgStream(path); + SVGFileView(const SkString& path) + : fPath(path), fLabel(SkStringPrintf("[%s]", SkOSPath::Basename(path.c_str()).c_str())) {} + virtual ~SVGFileView() = default; + +protected: + void onOnceBeforeDraw() override { + SkFILEStream svgStream(fPath.c_str()); if (!svgStream.isValid()) { - SkDebugf("file not found: \"path\"\n", path); + SkDebugf("file not found: \"path\"\n", fPath.c_str()); return; } SkDOM xmlDom; if (!xmlDom.build(svgStream)) { - SkDebugf("XML parsing failed: \"path\"\n", path); + SkDebugf("XML parsing failed: \"path\"\n", fPath.c_str()); return; } fDom = SkSVGDOM::MakeFromDOM(xmlDom, SkSize::Make(this->width(), this->height())); } - virtual ~SVGFileView() = default; - -protected: void onDrawContent(SkCanvas* canvas) override { if (fDom) { fDom->render(canvas); @@ -61,6 +62,7 @@ protected: } private: sk_sp<SkSVGDOM> fDom; + SkString fPath; SkString fLabel; typedef SampleView INHERITED; @@ -68,7 +70,7 @@ private: } // anonymous namespace -SampleView* CreateSampleSVGFileView(const char filename[]); -SampleView* CreateSampleSVGFileView(const char filename[]) { +SampleView* CreateSampleSVGFileView(const SkString& filename); +SampleView* CreateSampleSVGFileView(const SkString& filename) { return new SVGFileView(filename); } |