Chromium Code Reviews| Index: samplecode/SampleSVGFile.cpp |
| diff --git a/samplecode/SampleSVGFile.cpp b/samplecode/SampleSVGFile.cpp |
| index 12c91a95fe1055f878d79eba41e6fdb2b791f7ae..a1b4bf9e7a66c349b133685900911236729814b3 100644 |
| --- a/samplecode/SampleSVGFile.cpp |
| +++ b/samplecode/SampleSVGFile.cpp |
| @@ -17,26 +17,30 @@ 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 { |
|
robertphillips
2016/08/14 20:15:29
Do you need this if check? Shouldn't 'fDom' always
f(malita)
2016/08/15 13:18:56
I was thinking it may trigger when navigating back
|
| + if (fDom) { |
| + return; |
| + } |
| + 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 +65,7 @@ protected: |
| } |
| private: |
| sk_sp<SkSVGDOM> fDom; |
| + SkString fPath; |
| SkString fLabel; |
| typedef SampleView INHERITED; |
| @@ -68,7 +73,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); |
| } |