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