Home | History | Annotate | Download | only in effects
      1 
      2 /*
      3  * Copyright 2006 The Android Open Source Project
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 #ifndef Sk2DPathEffect_DEFINED
     11 #define Sk2DPathEffect_DEFINED
     12 
     13 #include "SkPath.h"
     14 #include "SkPathEffect.h"
     15 #include "SkMatrix.h"
     16 
     17 class Sk2DPathEffect : public SkPathEffect {
     18 public:
     19     Sk2DPathEffect(const SkMatrix& mat);
     20 
     21     // overrides
     22     virtual bool filterPath(SkPath*, const SkPath&, SkScalar* width) SK_OVERRIDE;
     23 
     24     // overrides from SkFlattenable
     25     virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
     26     virtual Factory getFactory() SK_OVERRIDE;
     27 
     28 protected:
     29     /** New virtual, to be overridden by subclasses.
     30         This is called once from filterPath, and provides the
     31         uv parameter bounds for the path. Subsequent calls to
     32         next() will receive u and v values within these bounds,
     33         and then a call to end() will signal the end of processing.
     34     */
     35     virtual void begin(const SkIRect& uvBounds, SkPath* dst);
     36     virtual void next(const SkPoint& loc, int u, int v, SkPath* dst);
     37     virtual void end(SkPath* dst);
     38 
     39     /** Low-level virtual called per span of locations in the u-direction.
     40         The default implementation calls next() repeatedly with each
     41         location.
     42     */
     43     virtual void nextSpan(int u, int v, int ucount, SkPath* dst);
     44 
     45     const SkMatrix& getMatrix() const { return fMatrix; }
     46 
     47     // protected so that subclasses can call this during unflattening
     48     Sk2DPathEffect(SkFlattenableReadBuffer&);
     49 
     50     SK_DECLARE_FLATTENABLE_REGISTRAR()
     51 
     52 private:
     53     SkMatrix    fMatrix, fInverse;
     54     // illegal
     55     Sk2DPathEffect(const Sk2DPathEffect&);
     56     Sk2DPathEffect& operator=(const Sk2DPathEffect&);
     57 
     58     static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
     59 
     60     friend class Sk2DPathEffectBlitter;
     61     typedef SkPathEffect INHERITED;
     62 };
     63 
     64 class SkPath2DPathEffect : public Sk2DPathEffect {
     65 public:
     66     /**
     67      *  Stamp the specified path to fill the shape, using the matrix to define
     68      *  the latice.
     69      */
     70     SkPath2DPathEffect(const SkMatrix&, const SkPath&);
     71 
     72     static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
     73 
     74     SK_DECLARE_FLATTENABLE_REGISTRAR()
     75 
     76 protected:
     77     SkPath2DPathEffect(SkFlattenableReadBuffer& buffer);
     78 
     79     virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
     80     virtual Factory getFactory() SK_OVERRIDE;
     81     virtual void next(const SkPoint&, int u, int v, SkPath* dst) SK_OVERRIDE;
     82 
     83 private:
     84     SkPath  fPath;
     85 
     86     typedef Sk2DPathEffect INHERITED;
     87 };
     88 
     89 
     90 #endif
     91