Home | History | Annotate | Download | only in effects
      1 /*
      2  * Copyright 2006 The Android Open Source Project
      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 Sk2DPathEffect_DEFINED
      9 #define Sk2DPathEffect_DEFINED
     10 
     11 #include "SkPath.h"
     12 #include "SkPathEffect.h"
     13 #include "SkMatrix.h"
     14 
     15 class SK_API Sk2DPathEffect : public SkPathEffect {
     16 public:
     17     virtual bool filterPath(SkPath*, const SkPath&, SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
     18 
     19     SK_DECLARE_UNFLATTENABLE_OBJECT()
     20 
     21 protected:
     22     /** New virtual, to be overridden by subclasses.
     23         This is called once from filterPath, and provides the
     24         uv parameter bounds for the path. Subsequent calls to
     25         next() will receive u and v values within these bounds,
     26         and then a call to end() will signal the end of processing.
     27     */
     28     virtual void begin(const SkIRect& uvBounds, SkPath* dst) const;
     29     virtual void next(const SkPoint& loc, int u, int v, SkPath* dst) const;
     30     virtual void end(SkPath* dst) const;
     31 
     32     /** Low-level virtual called per span of locations in the u-direction.
     33         The default implementation calls next() repeatedly with each
     34         location.
     35     */
     36     virtual void nextSpan(int u, int v, int ucount, SkPath* dst) const;
     37 
     38     const SkMatrix& getMatrix() const { return fMatrix; }
     39 
     40     // protected so that subclasses can call this during unflattening
     41     explicit Sk2DPathEffect(const SkMatrix& mat);
     42 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
     43     explicit Sk2DPathEffect(SkReadBuffer&);
     44 #endif
     45     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
     46 
     47 private:
     48     SkMatrix    fMatrix, fInverse;
     49     bool        fMatrixIsInvertible;
     50 
     51     // illegal
     52     Sk2DPathEffect(const Sk2DPathEffect&);
     53     Sk2DPathEffect& operator=(const Sk2DPathEffect&);
     54 
     55     friend class Sk2DPathEffectBlitter;
     56     typedef SkPathEffect INHERITED;
     57 };
     58 
     59 class SK_API SkLine2DPathEffect : public Sk2DPathEffect {
     60 public:
     61     static SkLine2DPathEffect* Create(SkScalar width, const SkMatrix& matrix) {
     62         return SkNEW_ARGS(SkLine2DPathEffect, (width, matrix));
     63     }
     64 
     65     virtual bool filterPath(SkPath* dst, const SkPath& src,
     66                             SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
     67 
     68     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLine2DPathEffect)
     69 
     70 protected:
     71     SkLine2DPathEffect(SkScalar width, const SkMatrix& matrix)
     72         : Sk2DPathEffect(matrix), fWidth(width) {}
     73 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
     74     explicit SkLine2DPathEffect(SkReadBuffer&);
     75 #endif
     76 
     77     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
     78 
     79     virtual void nextSpan(int u, int v, int ucount, SkPath*) const SK_OVERRIDE;
     80 
     81 private:
     82     SkScalar fWidth;
     83 
     84     typedef Sk2DPathEffect INHERITED;
     85 };
     86 
     87 class SK_API SkPath2DPathEffect : public Sk2DPathEffect {
     88 public:
     89     /**
     90      *  Stamp the specified path to fill the shape, using the matrix to define
     91      *  the latice.
     92      */
     93     static SkPath2DPathEffect* Create(const SkMatrix& matrix, const SkPath& path) {
     94         return SkNEW_ARGS(SkPath2DPathEffect, (matrix, path));
     95     }
     96 
     97     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPath2DPathEffect)
     98 
     99 protected:
    100     SkPath2DPathEffect(const SkMatrix&, const SkPath&);
    101 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
    102     explicit SkPath2DPathEffect(SkReadBuffer& buffer);
    103 #endif
    104     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
    105 
    106     virtual void next(const SkPoint&, int u, int v, SkPath*) const SK_OVERRIDE;
    107 
    108 private:
    109     SkPath  fPath;
    110 
    111     typedef Sk2DPathEffect INHERITED;
    112 };
    113 
    114 #endif
    115