18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project
38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef Sk2DPathEffect_DEFINED
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define Sk2DPathEffect_DEFINED
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1118dc47731f4b37d8896b51f1b92ab31abd78b5a0reed@google.com#include "SkPath.h"
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPathEffect.h"
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkMatrix.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
156806fe87e0b39e283291c1a1c7d1d864230aa2aatfarina@chromium.orgclass SK_API Sk2DPathEffect : public SkPathEffect {
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
173f8540346df30f2b681bcffd42edac15d609aec4reed    virtual bool filterPath(SkPath*, const SkPath&, SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
193f8540346df30f2b681bcffd42edac15d609aec4reed    SK_DECLARE_UNFLATTENABLE_OBJECT()
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** New virtual, to be overridden by subclasses.
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        This is called once from filterPath, and provides the
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        uv parameter bounds for the path. Subsequent calls to
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        next() will receive u and v values within these bounds,
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        and then a call to end() will signal the end of processing.
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
28548a1f321011292359ef163f78c8a1d4871b3b7freed@google.com    virtual void begin(const SkIRect& uvBounds, SkPath* dst) const;
29548a1f321011292359ef163f78c8a1d4871b3b7freed@google.com    virtual void next(const SkPoint& loc, int u, int v, SkPath* dst) const;
30548a1f321011292359ef163f78c8a1d4871b3b7freed@google.com    virtual void end(SkPath* dst) const;
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Low-level virtual called per span of locations in the u-direction.
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        The default implementation calls next() repeatedly with each
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        location.
358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
36548a1f321011292359ef163f78c8a1d4871b3b7freed@google.com    virtual void nextSpan(int u, int v, int ucount, SkPath* dst) const;
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    const SkMatrix& getMatrix() const { return fMatrix; }
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // protected so that subclasses can call this during unflattening
41bd0be25074e53a6d1abc284562568c9745191984commit-bot@chromium.org    explicit Sk2DPathEffect(const SkMatrix& mat);
429fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
43bd0be25074e53a6d1abc284562568c9745191984commit-bot@chromium.org    explicit Sk2DPathEffect(SkReadBuffer&);
449fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed#endif
458b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org    virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkMatrix    fMatrix, fInverse;
4990bf427001fd4f6d9fcee88911deb015aeb4ab7cmike@reedtribe.org    bool        fMatrixIsInvertible;
5090bf427001fd4f6d9fcee88911deb015aeb4ab7cmike@reedtribe.org
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // illegal
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    Sk2DPathEffect(const Sk2DPathEffect&);
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    Sk2DPathEffect& operator=(const Sk2DPathEffect&);
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class Sk2DPathEffectBlitter;
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    typedef SkPathEffect INHERITED;
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
596806fe87e0b39e283291c1a1c7d1d864230aa2aatfarina@chromium.orgclass SK_API SkLine2DPathEffect : public Sk2DPathEffect {
60d8a6cc814f1a0a8faaddad05ae765ad2f6b11aacscroggo@google.compublic:
610a2bf90dccba3bde188e0386a7f0c60e6dde1ae9commit-bot@chromium.org    static SkLine2DPathEffect* Create(SkScalar width, const SkMatrix& matrix) {
620a2bf90dccba3bde188e0386a7f0c60e6dde1ae9commit-bot@chromium.org        return SkNEW_ARGS(SkLine2DPathEffect, (width, matrix));
630a2bf90dccba3bde188e0386a7f0c60e6dde1ae9commit-bot@chromium.org    }
64d8a6cc814f1a0a8faaddad05ae765ad2f6b11aacscroggo@google.com
65548a1f321011292359ef163f78c8a1d4871b3b7freed@google.com    virtual bool filterPath(SkPath* dst, const SkPath& src,
664bbdeac58cc928dc66296bde3bd06e78070d96b7reed@google.com                            SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
67d8a6cc814f1a0a8faaddad05ae765ad2f6b11aacscroggo@google.com
68d8a6cc814f1a0a8faaddad05ae765ad2f6b11aacscroggo@google.com    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLine2DPathEffect)
69d8a6cc814f1a0a8faaddad05ae765ad2f6b11aacscroggo@google.com
70d8a6cc814f1a0a8faaddad05ae765ad2f6b11aacscroggo@google.comprotected:
71bd0be25074e53a6d1abc284562568c9745191984commit-bot@chromium.org    SkLine2DPathEffect(SkScalar width, const SkMatrix& matrix)
72bd0be25074e53a6d1abc284562568c9745191984commit-bot@chromium.org        : Sk2DPathEffect(matrix), fWidth(width) {}
739fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
74bd0be25074e53a6d1abc284562568c9745191984commit-bot@chromium.org    explicit SkLine2DPathEffect(SkReadBuffer&);
759fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed#endif
76d8a6cc814f1a0a8faaddad05ae765ad2f6b11aacscroggo@google.com
778b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org    virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
78d8a6cc814f1a0a8faaddad05ae765ad2f6b11aacscroggo@google.com
79bd0be25074e53a6d1abc284562568c9745191984commit-bot@chromium.org    virtual void nextSpan(int u, int v, int ucount, SkPath*) const SK_OVERRIDE;
800a2bf90dccba3bde188e0386a7f0c60e6dde1ae9commit-bot@chromium.org
81d8a6cc814f1a0a8faaddad05ae765ad2f6b11aacscroggo@google.comprivate:
82d8a6cc814f1a0a8faaddad05ae765ad2f6b11aacscroggo@google.com    SkScalar fWidth;
83d8a6cc814f1a0a8faaddad05ae765ad2f6b11aacscroggo@google.com
84d8a6cc814f1a0a8faaddad05ae765ad2f6b11aacscroggo@google.com    typedef Sk2DPathEffect INHERITED;
85d8a6cc814f1a0a8faaddad05ae765ad2f6b11aacscroggo@google.com};
86d8a6cc814f1a0a8faaddad05ae765ad2f6b11aacscroggo@google.com
876806fe87e0b39e283291c1a1c7d1d864230aa2aatfarina@chromium.orgclass SK_API SkPath2DPathEffect : public Sk2DPathEffect {
8818dc47731f4b37d8896b51f1b92ab31abd78b5a0reed@google.compublic:
8918dc47731f4b37d8896b51f1b92ab31abd78b5a0reed@google.com    /**
9018dc47731f4b37d8896b51f1b92ab31abd78b5a0reed@google.com     *  Stamp the specified path to fill the shape, using the matrix to define
9118dc47731f4b37d8896b51f1b92ab31abd78b5a0reed@google.com     *  the latice.
9218dc47731f4b37d8896b51f1b92ab31abd78b5a0reed@google.com     */
930a2bf90dccba3bde188e0386a7f0c60e6dde1ae9commit-bot@chromium.org    static SkPath2DPathEffect* Create(const SkMatrix& matrix, const SkPath& path) {
940a2bf90dccba3bde188e0386a7f0c60e6dde1ae9commit-bot@chromium.org        return SkNEW_ARGS(SkPath2DPathEffect, (matrix, path));
950a2bf90dccba3bde188e0386a7f0c60e6dde1ae9commit-bot@chromium.org    }
96fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
97ba28d03e94dc221d6a803bf2a84a420b9159255cdjsollen@google.com    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPath2DPathEffect)
9818dc47731f4b37d8896b51f1b92ab31abd78b5a0reed@google.com
9918dc47731f4b37d8896b51f1b92ab31abd78b5a0reed@google.comprotected:
100bd0be25074e53a6d1abc284562568c9745191984commit-bot@chromium.org    SkPath2DPathEffect(const SkMatrix&, const SkPath&);
1019fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
102bd0be25074e53a6d1abc284562568c9745191984commit-bot@chromium.org    explicit SkPath2DPathEffect(SkReadBuffer& buffer);
1039fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed#endif
1048b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org    virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
10518dc47731f4b37d8896b51f1b92ab31abd78b5a0reed@google.com
106548a1f321011292359ef163f78c8a1d4871b3b7freed@google.com    virtual void next(const SkPoint&, int u, int v, SkPath*) const SK_OVERRIDE;
10718dc47731f4b37d8896b51f1b92ab31abd78b5a0reed@google.com
10818dc47731f4b37d8896b51f1b92ab31abd78b5a0reed@google.comprivate:
10918dc47731f4b37d8896b51f1b92ab31abd78b5a0reed@google.com    SkPath  fPath;
11018dc47731f4b37d8896b51f1b92ab31abd78b5a0reed@google.com
11118dc47731f4b37d8896b51f1b92ab31abd78b5a0reed@google.com    typedef Sk2DPathEffect INHERITED;
11218dc47731f4b37d8896b51f1b92ab31abd78b5a0reed@google.com};
11318dc47731f4b37d8896b51f1b92ab31abd78b5a0reed@google.com
1148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
115