fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkSVGNode_DEFINED |
| 9 | #define SkSVGNode_DEFINED |
| 10 | |
| 11 | #include "SkRefCnt.h" |
| 12 | #include "SkSVGAttribute.h" |
| 13 | |
| 14 | class SkCanvas; |
| 15 | class SkMatrix; |
| 16 | class SkSVGRenderContext; |
| 17 | class SkSVGValue; |
| 18 | |
| 19 | enum class SkSVGTag { |
fmalita | 58649cc | 2016-07-29 08:52:03 -0700 | [diff] [blame] | 20 | kG, |
| 21 | kPath, |
fmalita | bffc256 | 2016-08-03 10:21:11 -0700 | [diff] [blame] | 22 | kRect, |
fmalita | 58649cc | 2016-07-29 08:52:03 -0700 | [diff] [blame] | 23 | kSvg |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | class SkSVGNode : public SkRefCnt { |
| 27 | public: |
| 28 | virtual ~SkSVGNode(); |
| 29 | |
| 30 | SkSVGTag tag() const { return fTag; } |
| 31 | |
| 32 | virtual void appendChild(sk_sp<SkSVGNode>) = 0; |
| 33 | |
fmalita | 397a517 | 2016-08-08 11:38:55 -0700 | [diff] [blame] | 34 | void render(const SkSVGRenderContext&) const; |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 35 | |
| 36 | void setAttribute(SkSVGAttribute, const SkSVGValue&); |
| 37 | |
| 38 | protected: |
| 39 | SkSVGNode(SkSVGTag); |
| 40 | |
fmalita | 397a517 | 2016-08-08 11:38:55 -0700 | [diff] [blame] | 41 | // Called before onRender(), to apply local attributes to the context. Unlike onRender(), |
| 42 | // onPrepareToRender() bubbles up the inheritance chain: overriders should always call |
| 43 | // INHERITED::onPrepareToRender(), unless they intend to short-circuit rendering |
| 44 | // (return false). |
| 45 | // Implementations are expected to return true if rendering is to continue, or false if |
| 46 | // the node/subtree rendering is disabled. |
| 47 | virtual bool onPrepareToRender(SkSVGRenderContext*) const; |
| 48 | |
| 49 | virtual void onRender(const SkSVGRenderContext&) const = 0; |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 50 | |
| 51 | virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&); |
| 52 | |
fmalita | 6ceef3d | 2016-07-26 18:46:34 -0700 | [diff] [blame] | 53 | private: |
| 54 | SkSVGTag fTag; |
| 55 | |
| 56 | // FIXME: this should be sparse |
| 57 | SkSVGPresentationAttributes fPresentationAttributes; |
| 58 | |
| 59 | typedef SkRefCnt INHERITED; |
| 60 | }; |
| 61 | |
| 62 | #endif // SkSVGNode_DEFINED |