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