1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/core/SkPathEffect.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,219 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2006 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#ifndef SkPathEffect_DEFINED 1.14 +#define SkPathEffect_DEFINED 1.15 + 1.16 +#include "SkFlattenable.h" 1.17 +#include "SkPath.h" 1.18 +#include "SkPoint.h" 1.19 +#include "SkRect.h" 1.20 +#include "SkStrokeRec.h" 1.21 +#include "SkTDArray.h" 1.22 + 1.23 +class SkPath; 1.24 + 1.25 +/** \class SkPathEffect 1.26 + 1.27 + SkPathEffect is the base class for objects in the SkPaint that affect 1.28 + the geometry of a drawing primitive before it is transformed by the 1.29 + canvas' matrix and drawn. 1.30 + 1.31 + Dashing is implemented as a subclass of SkPathEffect. 1.32 +*/ 1.33 +class SK_API SkPathEffect : public SkFlattenable { 1.34 +public: 1.35 + SK_DECLARE_INST_COUNT(SkPathEffect) 1.36 + 1.37 + /** 1.38 + * Given a src path (input) and a stroke-rec (input and output), apply 1.39 + * this effect to the src path, returning the new path in dst, and return 1.40 + * true. If this effect cannot be applied, return false and ignore dst 1.41 + * and stroke-rec. 1.42 + * 1.43 + * The stroke-rec specifies the initial request for stroking (if any). 1.44 + * The effect can treat this as input only, or it can choose to change 1.45 + * the rec as well. For example, the effect can decide to change the 1.46 + * stroke's width or join, or the effect can change the rec from stroke 1.47 + * to fill (or fill to stroke) in addition to returning a new (dst) path. 1.48 + * 1.49 + * If this method returns true, the caller will apply (as needed) the 1.50 + * resulting stroke-rec to dst and then draw. 1.51 + */ 1.52 + virtual bool filterPath(SkPath* dst, const SkPath& src, 1.53 + SkStrokeRec*, const SkRect* cullR) const = 0; 1.54 + 1.55 + /** 1.56 + * Compute a conservative bounds for its effect, given the src bounds. 1.57 + * The baseline implementation just assigns src to dst. 1.58 + */ 1.59 + virtual void computeFastBounds(SkRect* dst, const SkRect& src) const; 1.60 + 1.61 + /** \class PointData 1.62 + 1.63 + PointData aggregates all the information needed to draw the point 1.64 + primitives returned by an 'asPoints' call. 1.65 + */ 1.66 + class PointData { 1.67 + public: 1.68 + PointData() 1.69 + : fFlags(0) 1.70 + , fPoints(NULL) 1.71 + , fNumPoints(0) { 1.72 + fSize.set(SK_Scalar1, SK_Scalar1); 1.73 + // 'asPoints' needs to initialize/fill-in 'fClipRect' if it sets 1.74 + // the kUseClip flag 1.75 + }; 1.76 + ~PointData() { 1.77 + delete [] fPoints; 1.78 + } 1.79 + 1.80 + // TODO: consider using passed-in flags to limit the work asPoints does. 1.81 + // For example, a kNoPath flag could indicate don't bother generating 1.82 + // stamped solutions. 1.83 + 1.84 + // Currently none of these flags are supported. 1.85 + enum PointFlags { 1.86 + kCircles_PointFlag = 0x01, // draw points as circles (instead of rects) 1.87 + kUsePath_PointFlag = 0x02, // draw points as stamps of the returned path 1.88 + kUseClip_PointFlag = 0x04, // apply 'fClipRect' before drawing the points 1.89 + }; 1.90 + 1.91 + uint32_t fFlags; // flags that impact the drawing of the points 1.92 + SkPoint* fPoints; // the center point of each generated point 1.93 + int fNumPoints; // number of points in fPoints 1.94 + SkVector fSize; // the size to draw the points 1.95 + SkRect fClipRect; // clip required to draw the points (if kUseClip is set) 1.96 + SkPath fPath; // 'stamp' to be used at each point (if kUsePath is set) 1.97 + 1.98 + SkPath fFirst; // If not empty, contains geometry for first point 1.99 + SkPath fLast; // If not empty, contains geometry for last point 1.100 + }; 1.101 + 1.102 + /** 1.103 + * Does applying this path effect to 'src' yield a set of points? If so, 1.104 + * optionally return the points in 'results'. 1.105 + */ 1.106 + virtual bool asPoints(PointData* results, const SkPath& src, 1.107 + const SkStrokeRec&, const SkMatrix&, 1.108 + const SkRect* cullR) const; 1.109 + 1.110 + SK_DEFINE_FLATTENABLE_TYPE(SkPathEffect) 1.111 + 1.112 +protected: 1.113 + SkPathEffect() {} 1.114 + SkPathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {} 1.115 + 1.116 +private: 1.117 + // illegal 1.118 + SkPathEffect(const SkPathEffect&); 1.119 + SkPathEffect& operator=(const SkPathEffect&); 1.120 + 1.121 + typedef SkFlattenable INHERITED; 1.122 +}; 1.123 + 1.124 +/** \class SkPairPathEffect 1.125 + 1.126 + Common baseclass for Compose and Sum. This subclass manages two pathEffects, 1.127 + including flattening them. It does nothing in filterPath, and is only useful 1.128 + for managing the lifetimes of its two arguments. 1.129 +*/ 1.130 +class SkPairPathEffect : public SkPathEffect { 1.131 +public: 1.132 + virtual ~SkPairPathEffect(); 1.133 + 1.134 +protected: 1.135 + SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1); 1.136 + SkPairPathEffect(SkReadBuffer&); 1.137 + virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; 1.138 + 1.139 + // these are visible to our subclasses 1.140 + SkPathEffect* fPE0, *fPE1; 1.141 + 1.142 +private: 1.143 + typedef SkPathEffect INHERITED; 1.144 +}; 1.145 + 1.146 +/** \class SkComposePathEffect 1.147 + 1.148 + This subclass of SkPathEffect composes its two arguments, to create 1.149 + a compound pathEffect. 1.150 +*/ 1.151 +class SkComposePathEffect : public SkPairPathEffect { 1.152 +public: 1.153 + /** Construct a pathEffect whose effect is to apply first the inner pathEffect 1.154 + and the the outer pathEffect (e.g. outer(inner(path))) 1.155 + The reference counts for outer and inner are both incremented in the constructor, 1.156 + and decremented in the destructor. 1.157 + */ 1.158 + static SkComposePathEffect* Create(SkPathEffect* outer, SkPathEffect* inner) { 1.159 + return SkNEW_ARGS(SkComposePathEffect, (outer, inner)); 1.160 + } 1.161 + 1.162 + virtual bool filterPath(SkPath* dst, const SkPath& src, 1.163 + SkStrokeRec*, const SkRect*) const SK_OVERRIDE; 1.164 + 1.165 + SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposePathEffect) 1.166 + 1.167 +protected: 1.168 + SkComposePathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {} 1.169 + 1.170 +#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS 1.171 +public: 1.172 +#endif 1.173 + SkComposePathEffect(SkPathEffect* outer, SkPathEffect* inner) 1.174 + : INHERITED(outer, inner) {} 1.175 + 1.176 +private: 1.177 + // illegal 1.178 + SkComposePathEffect(const SkComposePathEffect&); 1.179 + SkComposePathEffect& operator=(const SkComposePathEffect&); 1.180 + 1.181 + typedef SkPairPathEffect INHERITED; 1.182 +}; 1.183 + 1.184 +/** \class SkSumPathEffect 1.185 + 1.186 + This subclass of SkPathEffect applies two pathEffects, one after the other. 1.187 + Its filterPath() returns true if either of the effects succeeded. 1.188 +*/ 1.189 +class SkSumPathEffect : public SkPairPathEffect { 1.190 +public: 1.191 + /** Construct a pathEffect whose effect is to apply two effects, in sequence. 1.192 + (e.g. first(path) + second(path)) 1.193 + The reference counts for first and second are both incremented in the constructor, 1.194 + and decremented in the destructor. 1.195 + */ 1.196 + static SkSumPathEffect* Create(SkPathEffect* first, SkPathEffect* second) { 1.197 + return SkNEW_ARGS(SkSumPathEffect, (first, second)); 1.198 + } 1.199 + 1.200 + virtual bool filterPath(SkPath* dst, const SkPath& src, 1.201 + SkStrokeRec*, const SkRect*) const SK_OVERRIDE; 1.202 + 1.203 + SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSumPathEffect) 1.204 + 1.205 +protected: 1.206 + SkSumPathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {} 1.207 + 1.208 +#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS 1.209 +public: 1.210 +#endif 1.211 + SkSumPathEffect(SkPathEffect* first, SkPathEffect* second) 1.212 + : INHERITED(first, second) {} 1.213 + 1.214 +private: 1.215 + // illegal 1.216 + SkSumPathEffect(const SkSumPathEffect&); 1.217 + SkSumPathEffect& operator=(const SkSumPathEffect&); 1.218 + 1.219 + typedef SkPairPathEffect INHERITED; 1.220 +}; 1.221 + 1.222 +#endif