epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #include "SkDrawExtraPathEffect.h" |
| 9 | #include "SkDrawPath.h" |
| 10 | #include "Sk1DPathEffect.h" |
| 11 | #include "Sk2DPathEffect.h" |
| 12 | #include "SkMemberInfo.h" |
reed@google.com | 8d4dc71 | 2014-04-18 15:14:25 +0000 | [diff] [blame] | 13 | #include "SkPaintPart.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 14 | #include "SkPathEffect.h" |
| 15 | #include "SkCornerPathEffect.h" |
| 16 | |
| 17 | #include "SkDashPathEffect.h" |
| 18 | |
| 19 | class SkDrawShapePathEffect : public SkDrawPathEffect { |
| 20 | DECLARE_PRIVATE_MEMBER_INFO(DrawShapePathEffect); |
| 21 | SkDrawShapePathEffect(); |
| 22 | virtual ~SkDrawShapePathEffect(); |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 23 | bool addChild(SkAnimateMaker& , SkDisplayable* ) SK_OVERRIDE; |
| 24 | SkPathEffect* getPathEffect() SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | protected: |
reed | 986ca61 | 2014-11-26 08:50:45 -0800 | [diff] [blame] | 26 | SkADrawable* addPath; |
| 27 | SkADrawable* addMatrix; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | SkDrawPath* path; |
| 29 | SkPathEffect* fPathEffect; |
| 30 | friend class SkShape1DPathEffect; |
| 31 | friend class SkShape2DPathEffect; |
| 32 | }; |
| 33 | |
| 34 | class SkDrawShape1DPathEffect : public SkDrawShapePathEffect { |
| 35 | DECLARE_EXTRAS_MEMBER_INFO(SkDrawShape1DPathEffect); |
| 36 | SkDrawShape1DPathEffect(SkDisplayTypes ); |
| 37 | virtual ~SkDrawShape1DPathEffect(); |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 38 | void onEndElement(SkAnimateMaker& ) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 39 | private: |
| 40 | SkString phase; |
| 41 | SkString spacing; |
| 42 | friend class SkShape1DPathEffect; |
| 43 | typedef SkDrawShapePathEffect INHERITED; |
| 44 | }; |
| 45 | |
| 46 | class SkDrawShape2DPathEffect : public SkDrawShapePathEffect { |
| 47 | DECLARE_EXTRAS_MEMBER_INFO(SkDrawShape2DPathEffect); |
| 48 | SkDrawShape2DPathEffect(SkDisplayTypes ); |
| 49 | virtual ~SkDrawShape2DPathEffect(); |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 50 | void onEndElement(SkAnimateMaker& ) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 51 | private: |
| 52 | SkDrawMatrix* matrix; |
| 53 | friend class SkShape2DPathEffect; |
| 54 | typedef SkDrawShapePathEffect INHERITED; |
| 55 | }; |
| 56 | |
| 57 | class SkDrawComposePathEffect : public SkDrawPathEffect { |
| 58 | DECLARE_EXTRAS_MEMBER_INFO(SkDrawComposePathEffect); |
| 59 | SkDrawComposePathEffect(SkDisplayTypes ); |
| 60 | virtual ~SkDrawComposePathEffect(); |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 61 | bool addChild(SkAnimateMaker& , SkDisplayable* ) SK_OVERRIDE; |
| 62 | SkPathEffect* getPathEffect() SK_OVERRIDE; |
| 63 | bool isPaint() const SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 64 | private: |
| 65 | SkDrawPathEffect* effect1; |
| 66 | SkDrawPathEffect* effect2; |
| 67 | }; |
| 68 | |
| 69 | class SkDrawCornerPathEffect : public SkDrawPathEffect { |
| 70 | DECLARE_EXTRAS_MEMBER_INFO(SkDrawCornerPathEffect); |
| 71 | SkDrawCornerPathEffect(SkDisplayTypes ); |
| 72 | virtual ~SkDrawCornerPathEffect(); |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 73 | SkPathEffect* getPathEffect() SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 74 | private: |
| 75 | SkScalar radius; |
| 76 | }; |
| 77 | |
| 78 | //////////// SkShape1DPathEffect |
| 79 | |
| 80 | #include "SkAnimateMaker.h" |
| 81 | #include "SkAnimatorScript.h" |
| 82 | #include "SkDisplayApply.h" |
| 83 | #include "SkDrawMatrix.h" |
| 84 | #include "SkPaint.h" |
| 85 | |
| 86 | class SkShape1DPathEffect : public Sk1DPathEffect { |
| 87 | public: |
| 88 | SkShape1DPathEffect(SkDrawShape1DPathEffect* draw, SkAnimateMaker* maker) : |
| 89 | fDraw(draw), fMaker(maker) { |
| 90 | } |
| 91 | |
mtklein | 7e44bb1 | 2015-01-07 09:06:08 -0800 | [diff] [blame] | 92 | // For serialization. This will never be called. |
| 93 | Factory getFactory() const SK_OVERRIDE { sk_throw(); return NULL; } |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 94 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 95 | protected: |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 96 | SkScalar begin(SkScalar contourLength) const SK_OVERRIDE { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 97 | SkScriptValue value; |
| 98 | SkAnimatorScript engine(*fMaker, NULL, SkType_Float); |
| 99 | engine.propertyCallBack(GetContourLength, &contourLength); |
| 100 | value.fOperand.fScalar = 0; |
| 101 | engine.evaluate(fDraw->phase.c_str(), &value, SkType_Float); |
| 102 | return value.fOperand.fScalar; |
| 103 | } |
| 104 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 105 | SkScalar next(SkPath* dst, SkScalar distance, SkPathMeasure&) const SK_OVERRIDE { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 106 | fMaker->setExtraPropertyCallBack(fDraw->fType, GetDistance, &distance); |
| 107 | SkDrawPath* drawPath = NULL; |
| 108 | if (fDraw->addPath->isPath()) { |
| 109 | drawPath = (SkDrawPath*) fDraw->addPath; |
| 110 | } else { |
| 111 | SkApply* apply = (SkApply*) fDraw->addPath; |
| 112 | apply->refresh(*fMaker); |
| 113 | apply->activate(*fMaker); |
reed@google.com | 8015cdd | 2013-12-18 15:49:32 +0000 | [diff] [blame] | 114 | apply->interpolate(*fMaker, SkScalarRoundToInt(distance * 1000)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 115 | drawPath = (SkDrawPath*) apply->getScope(); |
| 116 | } |
| 117 | SkMatrix m; |
| 118 | m.reset(); |
| 119 | if (fDraw->addMatrix) { |
| 120 | SkDrawMatrix* matrix; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 121 | if (fDraw->addMatrix->getType() == SkType_Matrix) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 122 | matrix = (SkDrawMatrix*) fDraw->addMatrix; |
| 123 | else { |
| 124 | SkApply* apply = (SkApply*) fDraw->addMatrix; |
| 125 | apply->refresh(*fMaker); |
| 126 | apply->activate(*fMaker); |
reed@google.com | 8015cdd | 2013-12-18 15:49:32 +0000 | [diff] [blame] | 127 | apply->interpolate(*fMaker, SkScalarRoundToInt(distance * 1000)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 128 | matrix = (SkDrawMatrix*) apply->getScope(); |
| 129 | } |
sugoi@google.com | dfc867b | 2013-03-11 18:45:12 +0000 | [diff] [blame] | 130 | if (matrix) { |
| 131 | m = matrix->getMatrix(); |
| 132 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 133 | } |
| 134 | SkScalar result = 0; |
| 135 | SkAnimatorScript::EvaluateFloat(*fMaker, NULL, fDraw->spacing.c_str(), &result); |
| 136 | if (drawPath) |
| 137 | dst->addPath(drawPath->getPath(), m); |
| 138 | fMaker->clearExtraPropertyCallBack(fDraw->fType); |
| 139 | return result; |
| 140 | } |
| 141 | |
| 142 | private: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 143 | static bool GetContourLength(const char* token, size_t len, void* clen, SkScriptValue* value) { |
| 144 | if (SK_LITERAL_STR_EQUAL("contourLength", token, len)) { |
| 145 | value->fOperand.fScalar = *(SkScalar*) clen; |
| 146 | value->fType = SkType_Float; |
| 147 | return true; |
| 148 | } |
| 149 | return false; |
| 150 | } |
| 151 | |
| 152 | static bool GetDistance(const char* token, size_t len, void* dist, SkScriptValue* value) { |
| 153 | if (SK_LITERAL_STR_EQUAL("distance", token, len)) { |
| 154 | value->fOperand.fScalar = *(SkScalar*) dist; |
| 155 | value->fType = SkType_Float; |
| 156 | return true; |
| 157 | } |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | SkDrawShape1DPathEffect* fDraw; |
| 162 | SkAnimateMaker* fMaker; |
| 163 | }; |
| 164 | |
| 165 | //////////// SkDrawShapePathEffect |
| 166 | |
| 167 | #if SK_USE_CONDENSED_INFO == 0 |
| 168 | |
| 169 | const SkMemberInfo SkDrawShapePathEffect::fInfo[] = { |
| 170 | SK_MEMBER(addMatrix, Drawable), // either matrix or apply |
| 171 | SK_MEMBER(addPath, Drawable), // either path or apply |
| 172 | SK_MEMBER(path, Path), |
| 173 | }; |
| 174 | |
| 175 | #endif |
| 176 | |
| 177 | DEFINE_GET_MEMBER(SkDrawShapePathEffect); |
| 178 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 179 | SkDrawShapePathEffect::SkDrawShapePathEffect() : |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 180 | addPath(NULL), addMatrix(NULL), path(NULL), fPathEffect(NULL) { |
| 181 | } |
| 182 | |
| 183 | SkDrawShapePathEffect::~SkDrawShapePathEffect() { |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 184 | SkSafeUnref(fPathEffect); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 185 | } |
| 186 | |
tfarina@chromium.org | 1d3c411 | 2012-12-03 14:38:08 +0000 | [diff] [blame] | 187 | bool SkDrawShapePathEffect::addChild(SkAnimateMaker& , SkDisplayable* child) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 188 | path = (SkDrawPath*) child; |
| 189 | return true; |
| 190 | } |
| 191 | |
| 192 | SkPathEffect* SkDrawShapePathEffect::getPathEffect() { |
| 193 | fPathEffect->ref(); |
| 194 | return fPathEffect; |
| 195 | } |
| 196 | |
| 197 | //////////// SkDrawShape1DPathEffect |
| 198 | |
| 199 | #if SK_USE_CONDENSED_INFO == 0 |
| 200 | |
| 201 | const SkMemberInfo SkDrawShape1DPathEffect::fInfo[] = { |
| 202 | SK_MEMBER_INHERITED, |
| 203 | SK_MEMBER(phase, String), |
| 204 | SK_MEMBER(spacing, String), |
| 205 | }; |
| 206 | |
| 207 | #endif |
| 208 | |
| 209 | DEFINE_GET_MEMBER(SkDrawShape1DPathEffect); |
| 210 | |
| 211 | SkDrawShape1DPathEffect::SkDrawShape1DPathEffect(SkDisplayTypes type) : fType(type) { |
| 212 | } |
| 213 | |
| 214 | SkDrawShape1DPathEffect::~SkDrawShape1DPathEffect() { |
| 215 | } |
| 216 | |
| 217 | void SkDrawShape1DPathEffect::onEndElement(SkAnimateMaker& maker) { |
| 218 | if (addPath == NULL || (addPath->isPath() == false && addPath->isApply() == false)) |
| 219 | maker.setErrorCode(SkDisplayXMLParserError::kUnknownError); // !!! add error |
| 220 | else |
| 221 | fPathEffect = new SkShape1DPathEffect(this, &maker); |
| 222 | } |
| 223 | |
| 224 | ////////// SkShape2DPathEffect |
| 225 | |
| 226 | class SkShape2DPathEffect : public Sk2DPathEffect { |
| 227 | public: |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 228 | SkShape2DPathEffect(SkDrawShape2DPathEffect* draw, SkAnimateMaker* maker, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 229 | const SkMatrix& matrix) : Sk2DPathEffect(matrix), fDraw(draw), fMaker(maker) { |
| 230 | } |
| 231 | |
mtklein | 7e44bb1 | 2015-01-07 09:06:08 -0800 | [diff] [blame] | 232 | // For serialization. This will never be called. |
| 233 | Factory getFactory() const SK_OVERRIDE { sk_throw(); return NULL; } |
| 234 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 235 | protected: |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 236 | void begin(const SkIRect& uvBounds, SkPath*) const SK_OVERRIDE { |
sugoi@google.com | dfc867b | 2013-03-11 18:45:12 +0000 | [diff] [blame] | 237 | const_cast<SkShape2DPathEffect*>(this)->setUVBounds(uvBounds); |
| 238 | } |
| 239 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 240 | void next(const SkPoint& loc, int u, int v, SkPath* dst) const SK_OVERRIDE { |
sugoi@google.com | dfc867b | 2013-03-11 18:45:12 +0000 | [diff] [blame] | 241 | const_cast<SkShape2DPathEffect*>(this)->addPath(loc, u, v, dst); |
| 242 | } |
| 243 | |
| 244 | private: |
| 245 | void setUVBounds(const SkIRect& uvBounds) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 246 | fUVBounds.set(SkIntToScalar(uvBounds.fLeft), SkIntToScalar(uvBounds.fTop), |
| 247 | SkIntToScalar(uvBounds.fRight), SkIntToScalar(uvBounds.fBottom)); |
| 248 | } |
| 249 | |
sugoi@google.com | dfc867b | 2013-03-11 18:45:12 +0000 | [diff] [blame] | 250 | void addPath(const SkPoint& loc, int u, int v, SkPath* dst) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 251 | fLoc = loc; |
| 252 | fU = u; |
| 253 | fV = v; |
| 254 | SkDrawPath* drawPath; |
| 255 | fMaker->setExtraPropertyCallBack(fDraw->fType, Get2D, this); |
| 256 | if (fDraw->addPath->isPath()) { |
| 257 | drawPath = (SkDrawPath*) fDraw->addPath; |
| 258 | } else { |
| 259 | SkApply* apply = (SkApply*) fDraw->addPath; |
| 260 | apply->refresh(*fMaker); |
| 261 | apply->activate(*fMaker); |
| 262 | apply->interpolate(*fMaker, v); |
| 263 | drawPath = (SkDrawPath*) apply->getScope(); |
| 264 | } |
| 265 | if (drawPath == NULL) |
| 266 | goto clearCallBack; |
| 267 | if (fDraw->matrix) { |
| 268 | SkDrawMatrix* matrix; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 269 | if (fDraw->matrix->getType() == SkType_Matrix) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 270 | matrix = (SkDrawMatrix*) fDraw->matrix; |
| 271 | else { |
| 272 | SkApply* apply = (SkApply*) fDraw->matrix; |
| 273 | apply->activate(*fMaker); |
| 274 | apply->interpolate(*fMaker, v); |
| 275 | matrix = (SkDrawMatrix*) apply->getScope(); |
| 276 | } |
| 277 | if (matrix) { |
| 278 | dst->addPath(drawPath->getPath(), matrix->getMatrix()); |
| 279 | goto clearCallBack; |
| 280 | } |
| 281 | } |
| 282 | dst->addPath(drawPath->getPath()); |
| 283 | clearCallBack: |
| 284 | fMaker->clearExtraPropertyCallBack(fDraw->fType); |
| 285 | } |
| 286 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 287 | static bool Get2D(const char* token, size_t len, void* s2D, SkScriptValue* value) { |
| 288 | static const char match[] = "locX|locY|left|top|right|bottom|u|v" ; |
| 289 | SkShape2DPathEffect* shape2D = (SkShape2DPathEffect*) s2D; |
| 290 | int index; |
| 291 | if (SkAnimatorScript::MapEnums(match, token, len, &index) == false) |
| 292 | return false; |
| 293 | SkASSERT((sizeof(SkPoint) + sizeof(SkRect)) / sizeof(SkScalar) == 6); |
| 294 | if (index < 6) { |
| 295 | value->fType = SkType_Float; |
| 296 | value->fOperand.fScalar = (&shape2D->fLoc.fX)[index]; |
| 297 | } else { |
| 298 | value->fType = SkType_Int; |
| 299 | value->fOperand.fS32 = (&shape2D->fU)[index - 6]; |
| 300 | } |
| 301 | return true; |
| 302 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 303 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 304 | SkPoint fLoc; |
| 305 | SkRect fUVBounds; |
| 306 | int32_t fU; |
| 307 | int32_t fV; |
| 308 | SkDrawShape2DPathEffect* fDraw; |
| 309 | SkAnimateMaker* fMaker; |
| 310 | |
| 311 | // illegal |
| 312 | SkShape2DPathEffect(const SkShape2DPathEffect&); |
| 313 | SkShape2DPathEffect& operator=(const SkShape2DPathEffect&); |
| 314 | }; |
| 315 | |
| 316 | ////////// SkDrawShape2DPathEffect |
| 317 | |
| 318 | #if SK_USE_CONDENSED_INFO == 0 |
| 319 | |
| 320 | const SkMemberInfo SkDrawShape2DPathEffect::fInfo[] = { |
| 321 | SK_MEMBER_INHERITED, |
| 322 | SK_MEMBER(matrix, Matrix) |
| 323 | }; |
| 324 | |
| 325 | #endif |
| 326 | |
| 327 | DEFINE_GET_MEMBER(SkDrawShape2DPathEffect); |
| 328 | |
| 329 | SkDrawShape2DPathEffect::SkDrawShape2DPathEffect(SkDisplayTypes type) : fType(type) { |
| 330 | } |
| 331 | |
| 332 | SkDrawShape2DPathEffect::~SkDrawShape2DPathEffect() { |
| 333 | } |
| 334 | |
| 335 | void SkDrawShape2DPathEffect::onEndElement(SkAnimateMaker& maker) { |
| 336 | if (addPath == NULL || (addPath->isPath() == false && addPath->isApply() == false) || |
| 337 | matrix == NULL) |
| 338 | maker.setErrorCode(SkDisplayXMLParserError::kUnknownError); // !!! add error |
| 339 | else |
| 340 | fPathEffect = new SkShape2DPathEffect(this, &maker, matrix->getMatrix()); |
| 341 | } |
| 342 | |
| 343 | ////////// SkDrawComposePathEffect |
| 344 | |
| 345 | #if SK_USE_CONDENSED_INFO == 0 |
| 346 | |
| 347 | const SkMemberInfo SkDrawComposePathEffect::fInfo[] = { |
| 348 | SK_MEMBER(effect1, PathEffect), |
| 349 | SK_MEMBER(effect2, PathEffect) |
| 350 | }; |
| 351 | |
| 352 | #endif |
| 353 | |
| 354 | DEFINE_GET_MEMBER(SkDrawComposePathEffect); |
| 355 | |
| 356 | SkDrawComposePathEffect::SkDrawComposePathEffect(SkDisplayTypes type) : fType(type), |
| 357 | effect1(NULL), effect2(NULL) { |
| 358 | } |
| 359 | |
| 360 | SkDrawComposePathEffect::~SkDrawComposePathEffect() { |
| 361 | delete effect1; |
| 362 | delete effect2; |
| 363 | } |
| 364 | |
tfarina@chromium.org | 1d3c411 | 2012-12-03 14:38:08 +0000 | [diff] [blame] | 365 | bool SkDrawComposePathEffect::addChild(SkAnimateMaker& , SkDisplayable* child) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 366 | if (effect1 == NULL) |
| 367 | effect1 = (SkDrawPathEffect*) child; |
| 368 | else |
| 369 | effect2 = (SkDrawPathEffect*) child; |
| 370 | return true; |
| 371 | } |
| 372 | |
| 373 | SkPathEffect* SkDrawComposePathEffect::getPathEffect() { |
| 374 | SkPathEffect* e1 = effect1->getPathEffect(); |
| 375 | SkPathEffect* e2 = effect2->getPathEffect(); |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 376 | SkPathEffect* composite = SkComposePathEffect::Create(e1, e2); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 377 | e1->unref(); |
| 378 | e2->unref(); |
| 379 | return composite; |
| 380 | } |
| 381 | |
| 382 | bool SkDrawComposePathEffect::isPaint() const { |
| 383 | return true; |
| 384 | } |
| 385 | |
| 386 | //////////// SkDrawCornerPathEffect |
| 387 | |
| 388 | #if SK_USE_CONDENSED_INFO == 0 |
| 389 | |
| 390 | const SkMemberInfo SkDrawCornerPathEffect::fInfo[] = { |
| 391 | SK_MEMBER(radius, Float) |
| 392 | }; |
| 393 | |
| 394 | #endif |
| 395 | |
| 396 | DEFINE_GET_MEMBER(SkDrawCornerPathEffect); |
| 397 | |
| 398 | SkDrawCornerPathEffect::SkDrawCornerPathEffect(SkDisplayTypes type): |
| 399 | fType(type), radius(0) { |
| 400 | } |
| 401 | |
| 402 | SkDrawCornerPathEffect::~SkDrawCornerPathEffect() { |
| 403 | } |
| 404 | |
| 405 | SkPathEffect* SkDrawCornerPathEffect::getPathEffect() { |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 406 | return SkCornerPathEffect::Create(radius); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | ///////// |
| 410 | |
| 411 | #include "SkExtras.h" |
| 412 | |
| 413 | const char kDrawShape1DPathEffectName[] = "pathEffect:shape1D"; |
| 414 | const char kDrawShape2DPathEffectName[] = "pathEffect:shape2D"; |
| 415 | const char kDrawComposePathEffectName[] = "pathEffect:compose"; |
| 416 | const char kDrawCornerPathEffectName[] = "pathEffect:corner"; |
| 417 | |
| 418 | class SkExtraPathEffects : public SkExtras { |
| 419 | public: |
sugoi@google.com | 93c7ee3 | 2013-03-12 14:36:57 +0000 | [diff] [blame] | 420 | SkExtraPathEffects() : |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 421 | skDrawShape1DPathEffectType(SkType_Unknown), |
| 422 | skDrawShape2DPathEffectType(SkType_Unknown), |
| 423 | skDrawComposePathEffectType(SkType_Unknown), |
| 424 | skDrawCornerPathEffectType(SkType_Unknown) { |
| 425 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 426 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 427 | virtual SkDisplayable* createInstance(SkDisplayTypes type) { |
| 428 | SkDisplayable* result = NULL; |
| 429 | if (skDrawShape1DPathEffectType == type) |
| 430 | result = new SkDrawShape1DPathEffect(type); |
| 431 | else if (skDrawShape2DPathEffectType == type) |
| 432 | result = new SkDrawShape2DPathEffect(type); |
| 433 | else if (skDrawComposePathEffectType == type) |
| 434 | result = new SkDrawComposePathEffect(type); |
| 435 | else if (skDrawCornerPathEffectType == type) |
| 436 | result = new SkDrawCornerPathEffect(type); |
| 437 | return result; |
| 438 | } |
| 439 | |
| 440 | virtual bool definesType(SkDisplayTypes type) { |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 441 | return type == skDrawShape1DPathEffectType || |
| 442 | type == skDrawShape2DPathEffectType || |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 443 | type == skDrawComposePathEffectType || |
| 444 | type == skDrawCornerPathEffectType; |
| 445 | } |
| 446 | |
| 447 | #if SK_USE_CONDENSED_INFO == 0 |
| 448 | virtual const SkMemberInfo* getMembers(SkDisplayTypes type, int* infoCountPtr) { |
| 449 | const SkMemberInfo* info = NULL; |
| 450 | int infoCount = 0; |
| 451 | if (skDrawShape1DPathEffectType == type) { |
| 452 | info = SkDrawShape1DPathEffect::fInfo; |
| 453 | infoCount = SkDrawShape1DPathEffect::fInfoCount; |
| 454 | } else if (skDrawShape2DPathEffectType == type) { |
| 455 | info = SkDrawShape2DPathEffect::fInfo; |
| 456 | infoCount = SkDrawShape2DPathEffect::fInfoCount; |
| 457 | } else if (skDrawComposePathEffectType == type) { |
| 458 | info = SkDrawComposePathEffect::fInfo; |
| 459 | infoCount = SkDrawShape1DPathEffect::fInfoCount; |
| 460 | } else if (skDrawCornerPathEffectType == type) { |
| 461 | info = SkDrawCornerPathEffect::fInfo; |
| 462 | infoCount = SkDrawCornerPathEffect::fInfoCount; |
| 463 | } |
| 464 | if (infoCountPtr) |
| 465 | *infoCountPtr = infoCount; |
| 466 | return info; |
| 467 | } |
| 468 | #endif |
| 469 | |
| 470 | #ifdef SK_DEBUG |
| 471 | virtual const char* getName(SkDisplayTypes type) { |
| 472 | if (skDrawShape1DPathEffectType == type) |
| 473 | return kDrawShape1DPathEffectName; |
| 474 | else if (skDrawShape2DPathEffectType == type) |
| 475 | return kDrawShape2DPathEffectName; |
| 476 | else if (skDrawComposePathEffectType == type) |
| 477 | return kDrawComposePathEffectName; |
| 478 | else if (skDrawCornerPathEffectType == type) |
| 479 | return kDrawCornerPathEffectName; |
| 480 | return NULL; |
| 481 | } |
| 482 | #endif |
| 483 | |
| 484 | virtual SkDisplayTypes getType(const char name[], size_t len ) { |
| 485 | SkDisplayTypes* type = NULL; |
| 486 | if (SK_LITERAL_STR_EQUAL(kDrawShape1DPathEffectName, name, len)) |
| 487 | type = &skDrawShape1DPathEffectType; |
| 488 | else if (SK_LITERAL_STR_EQUAL(kDrawShape2DPathEffectName, name, len)) |
| 489 | type = &skDrawShape2DPathEffectType; |
| 490 | else if (SK_LITERAL_STR_EQUAL(kDrawComposePathEffectName, name, len)) |
| 491 | type = &skDrawComposePathEffectType; |
| 492 | else if (SK_LITERAL_STR_EQUAL(kDrawCornerPathEffectName, name, len)) |
| 493 | type = &skDrawCornerPathEffectType; |
| 494 | if (type) { |
| 495 | if (*type == SkType_Unknown) |
| 496 | *type = SkDisplayType::RegisterNewType(); |
| 497 | return *type; |
| 498 | } |
| 499 | return SkType_Unknown; |
| 500 | } |
| 501 | |
| 502 | private: |
| 503 | SkDisplayTypes skDrawShape1DPathEffectType; |
| 504 | SkDisplayTypes skDrawShape2DPathEffectType; |
| 505 | SkDisplayTypes skDrawComposePathEffectType; |
| 506 | SkDisplayTypes skDrawCornerPathEffectType; |
| 507 | }; |
| 508 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 509 | void InitializeSkExtraPathEffects(SkAnimator* animator) { |
sugoi@google.com | 93c7ee3 | 2013-03-12 14:36:57 +0000 | [diff] [blame] | 510 | animator->addExtras(new SkExtraPathEffects()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | //////////////// |
| 514 | |
| 515 | |
| 516 | SkExtras::SkExtras() : fExtraCallBack(NULL), fExtraStorage(NULL) { |
| 517 | } |