Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(697)

Side by Side Diff: samplecode/SampleSVGFile.cpp

Issue 2245993002: [SVGDom] Deferred SampleApp parsing (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: review Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkDOM.h" 10 #include "SkDOM.h"
11 #include "SkOSFile.h" 11 #include "SkOSFile.h"
12 #include "SkStream.h" 12 #include "SkStream.h"
13 #include "SkSVGDOM.h" 13 #include "SkSVGDOM.h"
14 #include "SkView.h" 14 #include "SkView.h"
15 15
16 namespace { 16 namespace {
17 17
18 class SVGFileView : public SampleView { 18 class SVGFileView : public SampleView {
19 public: 19 public:
20 SVGFileView(const char path[]) 20 SVGFileView(const SkString& path)
21 : fLabel(SkStringPrintf("[%s]", SkOSPath::Basename(path).c_str())) { 21 : fPath(path), fLabel(SkStringPrintf("[%s]", SkOSPath::Basename(path.c_s tr()).c_str())) {}
22 SkFILEStream svgStream(path); 22 virtual ~SVGFileView() = default;
23
24 protected:
25 void onOnceBeforeDraw() override {
26 SkFILEStream svgStream(fPath.c_str());
23 if (!svgStream.isValid()) { 27 if (!svgStream.isValid()) {
24 SkDebugf("file not found: \"path\"\n", path); 28 SkDebugf("file not found: \"path\"\n", fPath.c_str());
25 return; 29 return;
26 } 30 }
27 31
28 SkDOM xmlDom; 32 SkDOM xmlDom;
29 if (!xmlDom.build(svgStream)) { 33 if (!xmlDom.build(svgStream)) {
30 SkDebugf("XML parsing failed: \"path\"\n", path); 34 SkDebugf("XML parsing failed: \"path\"\n", fPath.c_str());
31 return; 35 return;
32 } 36 }
33 37
34 fDom = SkSVGDOM::MakeFromDOM(xmlDom, SkSize::Make(this->width(), this->h eight())); 38 fDom = SkSVGDOM::MakeFromDOM(xmlDom, SkSize::Make(this->width(), this->h eight()));
35 } 39 }
36 40
37 virtual ~SVGFileView() = default;
38
39 protected:
40 void onDrawContent(SkCanvas* canvas) override { 41 void onDrawContent(SkCanvas* canvas) override {
41 if (fDom) { 42 if (fDom) {
42 fDom->render(canvas); 43 fDom->render(canvas);
43 } 44 }
44 } 45 }
45 46
46 void onSizeChange() override { 47 void onSizeChange() override {
47 if (fDom) { 48 if (fDom) {
48 fDom->setContainerSize(SkSize::Make(this->width(), this->height())); 49 fDom->setContainerSize(SkSize::Make(this->width(), this->height()));
49 } 50 }
50 51
51 this->INHERITED::onSizeChange(); 52 this->INHERITED::onSizeChange();
52 } 53 }
53 54
54 bool onQuery(SkEvent* evt) override { 55 bool onQuery(SkEvent* evt) override {
55 if (SampleCode::TitleQ(*evt)) { 56 if (SampleCode::TitleQ(*evt)) {
56 SampleCode::TitleR(evt, fLabel.c_str()); 57 SampleCode::TitleR(evt, fLabel.c_str());
57 return true; 58 return true;
58 } 59 }
59 60
60 return this->INHERITED::onQuery(evt); 61 return this->INHERITED::onQuery(evt);
61 } 62 }
62 private: 63 private:
63 sk_sp<SkSVGDOM> fDom; 64 sk_sp<SkSVGDOM> fDom;
65 SkString fPath;
64 SkString fLabel; 66 SkString fLabel;
65 67
66 typedef SampleView INHERITED; 68 typedef SampleView INHERITED;
67 }; 69 };
68 70
69 } // anonymous namespace 71 } // anonymous namespace
70 72
71 SampleView* CreateSampleSVGFileView(const char filename[]); 73 SampleView* CreateSampleSVGFileView(const SkString& filename);
72 SampleView* CreateSampleSVGFileView(const char filename[]) { 74 SampleView* CreateSampleSVGFileView(const SkString& filename) {
73 return new SVGFileView(filename); 75 return new SVGFileView(filename);
74 } 76 }
OLDNEW
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698