OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 Google Inc. |
| 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 GrStrokeInfo_DEFINED |
| 9 #define GrStrokeInfo_DEFINED |
| 10 |
| 11 #include "SkStrokeRec.h" |
| 12 #include "SkPathEffect.h" |
| 13 |
| 14 /* |
| 15 * GrStrokeInfo encapsulates the data objects that hold all the pertinent infoma
tion |
| 16 * regarding the stroke. The two objects are SkStrokeRec which holds information
on fill style, |
| 17 * width, miter, cap, and join. The second object is DashInfo. This holds inform
ation about the |
| 18 * dash like intervals, count, and phase. |
| 19 */ |
| 20 class GrStrokeInfo { |
| 21 public: |
| 22 GrStrokeInfo(SkStrokeRec::InitStyle style) : |
| 23 fStroke(style), fDashType(SkPathEffect::kNone_DashType) {} |
| 24 |
| 25 GrStrokeInfo(const GrStrokeInfo& src, bool includeDash = true) : fStroke(src
.fStroke) { |
| 26 if (includeDash) { |
| 27 fDashInfo = src.fDashInfo; |
| 28 fDashType = src.fDashType; |
| 29 fIntervals.reset(src.dashCount()); |
| 30 memcpy(fIntervals.get(), src.fIntervals.get(), src.dashCount() * siz
eof(SkScalar)); |
| 31 } else { |
| 32 fDashType = SkPathEffect::kNone_DashType; |
| 33 } |
| 34 } |
| 35 |
| 36 explicit GrStrokeInfo(const SkPaint& paint) : |
| 37 fStroke(paint), fDashType(SkPathEffect::kNone_DashType) { |
| 38 const SkPathEffect* pe = paint.getPathEffect(); |
| 39 this->setDashInfo(pe); |
| 40 } |
| 41 |
| 42 const SkStrokeRec& getStrokeRec() const { return fStroke; } |
| 43 |
| 44 SkStrokeRec* getStrokeRecPtr() { return &fStroke; } |
| 45 |
| 46 void setFillStyle() { fStroke.setFillStyle(); } |
| 47 |
| 48 /* |
| 49 * This functions takes in a patheffect and fills in fDashInfo with the vari
ous dashing |
| 50 * information if the path effect is a Dash type. Returns true if the path e
ffect is a |
| 51 * dashed effect and we are stroking, otherwise it retruns false. |
| 52 */ |
| 53 bool setDashInfo(const SkPathEffect* pe) { |
| 54 if (NULL != pe && !fStroke.isFillStyle()) { |
| 55 fDashInfo.fIntervals = NULL; |
| 56 fDashType = pe->asADash(&fDashInfo); |
| 57 if (SkPathEffect::kDash_DashType == fDashType) { |
| 58 fIntervals.reset(fDashInfo.fCount); |
| 59 fDashInfo.fIntervals = fIntervals.get(); |
| 60 pe->asADash(&fDashInfo); |
| 61 return true; |
| 62 } |
| 63 } |
| 64 return false; |
| 65 } |
| 66 |
| 67 bool isDashed() const { |
| 68 return (!fStroke.isFillStyle() && SkPathEffect::kDash_DashType == fDashT
ype); |
| 69 } |
| 70 |
| 71 int32_t dashCount() const { |
| 72 return fDashInfo.fCount; |
| 73 } |
| 74 |
| 75 void removeDash() { |
| 76 fDashType = SkPathEffect::kNone_DashType; |
| 77 } |
| 78 |
| 79 const SkPathEffect::DashInfo& getDashInfo() const { return fDashInfo; } |
| 80 |
| 81 private: |
| 82 SkStrokeRec fStroke; |
| 83 SkPathEffect::DashType fDashType; |
| 84 SkPathEffect::DashInfo fDashInfo; |
| 85 SkAutoSTArray<2, SkScalar> fIntervals; |
| 86 }; |
| 87 |
| 88 #endif |
OLD | NEW |