skia2/experimental/svg/model/SkSVGNode.h
fmalita 397a517d1a [SVGDom] Add viewBox support
The main feature is <svg> viewBox and proper viewport support, but the CL
touches a few other things:

* refactor SkSVGRenderContext to auto-restore canvas state, and split the
  presentation bits into a separate CoW SkSVGPresentationContext

* introduce SkSVGNode::onPrepareToRender(), as a way for nodes to push their
  custom state before the actual onRender() call (instead of relying on
  non-virtual SkSVGNode to know about all possible state bits)

* add a "Type" suffix to SVG types, to disambiguate (e.g. SkSVGRectType vs.
  SkSVGRect)

R=robertphillips@google.com,stephana@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2222793002

Review-Url: https://codereview.chromium.org/2222793002
2016-08-08 11:38:55 -07:00

63 lines
1.5 KiB
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkSVGNode_DEFINED
#define SkSVGNode_DEFINED
#include "SkRefCnt.h"
#include "SkSVGAttribute.h"
class SkCanvas;
class SkMatrix;
class SkSVGRenderContext;
class SkSVGValue;
enum class SkSVGTag {
kG,
kPath,
kRect,
kSvg
};
class SkSVGNode : public SkRefCnt {
public:
virtual ~SkSVGNode();
SkSVGTag tag() const { return fTag; }
virtual void appendChild(sk_sp<SkSVGNode>) = 0;
void render(const SkSVGRenderContext&) const;
void setAttribute(SkSVGAttribute, const SkSVGValue&);
protected:
SkSVGNode(SkSVGTag);
// Called before onRender(), to apply local attributes to the context. Unlike onRender(),
// onPrepareToRender() bubbles up the inheritance chain: overriders should always call
// INHERITED::onPrepareToRender(), unless they intend to short-circuit rendering
// (return false).
// Implementations are expected to return true if rendering is to continue, or false if
// the node/subtree rendering is disabled.
virtual bool onPrepareToRender(SkSVGRenderContext*) const;
virtual void onRender(const SkSVGRenderContext&) const = 0;
virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&);
private:
SkSVGTag fTag;
// FIXME: this should be sparse
SkSVGPresentationAttributes fPresentationAttributes;
typedef SkRefCnt INHERITED;
};
#endif // SkSVGNode_DEFINED