SkPathEffect.h revision ba28d03e94dc221d6a803bf2a84a420b9159255c
1cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com
2cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com/*
38cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com * Copyright 2006 The Android Open Source Project
4cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com *
5cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com * Use of this source code is governed by a BSD-style license that can be
6cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com * found in the LICENSE file.
78cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com */
8cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com
98cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
10cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com#ifndef SkPathEffect_DEFINED
118cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#define SkPathEffect_DEFINED
128cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
138cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "SkFlattenable.h"
148cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
158cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass SkPath;
168cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
178cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com/** \class SkPathEffect
188cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
198cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SkPathEffect is the base class for objects in the SkPaint that affect
208cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    the geometry of a drawing primitive before it is transformed by the
218cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    canvas' matrix and drawn.
228cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
238cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    Dashing is implemented as a subclass of SkPathEffect.
248cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com*/
258cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass SK_API SkPathEffect : public SkFlattenable {
268cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.compublic:
278cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SkPathEffect() {}
288cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
298cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    /** Given a src path and a width value, return true if the patheffect
308cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com        has produced a new path (dst) and a new width value. If false is returned,
318cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com        ignore dst and width.
328cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com        On input, width >= 0 means the src should be stroked
338cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com        On output, width >= 0 means the dst should be stroked
348cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    */
358cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width) = 0;
368cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
378cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comprotected:
388cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SkPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
398cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
408cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comprivate:
418cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    // illegal
428cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SkPathEffect(const SkPathEffect&);
438cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SkPathEffect& operator=(const SkPathEffect&);
448cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
458cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    typedef SkFlattenable INHERITED;
468cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com};
478cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
488cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com/** \class SkPairPathEffect
498cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
508cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    Common baseclass for Compose and Sum. This subclass manages two pathEffects,
518cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    including flattening them. It does nothing in filterPath, and is only useful
528cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    for managing the lifetimes of its two arguments.
538cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com*/
548cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass SkPairPathEffect : public SkPathEffect {
558cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.compublic:
568cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1);
578cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    virtual ~SkPairPathEffect();
588cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
598cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comprotected:
608cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SkPairPathEffect(SkFlattenableReadBuffer&);
618cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
628cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    // these are visible to our subclasses
638cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SkPathEffect* fPE0, *fPE1;
648cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
658cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comprivate:
668cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    typedef SkPathEffect INHERITED;
678cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com};
688cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
698cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com/** \class SkComposePathEffect
708cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
718cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    This subclass of SkPathEffect composes its two arguments, to create
728cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    a compound pathEffect.
738cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com*/
748cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass SkComposePathEffect : public SkPairPathEffect {
758cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.compublic:
768cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    /** Construct a pathEffect whose effect is to apply first the inner pathEffect
778cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com        and the the outer pathEffect (e.g. outer(inner(path)))
788cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com        The reference counts for outer and inner are both incremented in the constructor,
798cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com        and decremented in the destructor.
808cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    */
818cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SkComposePathEffect(SkPathEffect* outer, SkPathEffect* inner)
828cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com        : INHERITED(outer, inner) {}
838cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
848cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    // overrides
858cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
868cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width);
878cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
888cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposePathEffect)
898cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
908cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comprivate:
918cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SkComposePathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
928cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
938cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    // illegal
948cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SkComposePathEffect(const SkComposePathEffect&);
958cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SkComposePathEffect& operator=(const SkComposePathEffect&);
968cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
978cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    typedef SkPairPathEffect INHERITED;
988cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com};
998cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1008cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com/** \class SkSumPathEffect
1018cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1028cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    This subclass of SkPathEffect applies two pathEffects, one after the other.
1038cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    Its filterPath() returns true if either of the effects succeeded.
1048cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com*/
1058cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass SkSumPathEffect : public SkPairPathEffect {
1068cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.compublic:
1078cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    /** Construct a pathEffect whose effect is to apply two effects, in sequence.
1088cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com        (e.g. first(path) + second(path))
1098cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com        The reference counts for first and second are both incremented in the constructor,
1108cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com        and decremented in the destructor.
1118cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    */
1128cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SkSumPathEffect(SkPathEffect* first, SkPathEffect* second)
1138cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com        : INHERITED(first, second) {}
1148cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1158cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    // overrides
1168cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width);
1178cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1188cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSumPathEffect)
1198cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1208cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comprivate:
1218cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SkSumPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
1228cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1238cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    // illegal
1248cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SkSumPathEffect(const SkSumPathEffect&);
1258cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SkSumPathEffect& operator=(const SkSumPathEffect&);
1268cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1278cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    typedef SkPairPathEffect INHERITED;
1288cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com};
1298cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1308cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#endif
1318cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1328cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com