| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrStrokeInfo_DEFINED | 8 #ifndef GrStrokeInfo_DEFINED |
| 9 #define GrStrokeInfo_DEFINED | 9 #define GrStrokeInfo_DEFINED |
| 10 | 10 |
| 11 #include "SkStrokeRec.h" | 11 #include "SkStrokeRec.h" |
| 12 #include "SkPathEffect.h" | 12 #include "SkPathEffect.h" |
| 13 | 13 |
| 14 /* | 14 /* |
| 15 * GrStrokeInfo encapsulates all the pertinent infomation regarding the stroke.
The SkStrokeRec | 15 * GrStrokeInfo encapsulates all the pertinent infomation regarding the stroke.
The SkStrokeRec |
| 16 * which holds information on fill style, width, miter, cap, and join. It also h
olds information | 16 * which holds information on fill style, width, miter, cap, and join. It also h
olds information |
| 17 * about the dash like intervals, count, and phase. | 17 * about the dash like intervals, count, and phase. |
| 18 */ | 18 */ |
| 19 class GrStrokeInfo { | 19 class GrStrokeInfo : public SkStrokeRec { |
| 20 public: | 20 public: |
| 21 GrStrokeInfo(SkStrokeRec::InitStyle style) : | 21 GrStrokeInfo(SkStrokeRec::InitStyle style) |
| 22 fStroke(style), fDashType(SkPathEffect::kNone_DashType) {} | 22 : INHERITED(style) |
| 23 , fDashType(SkPathEffect::kNone_DashType) { |
| 24 } |
| 23 | 25 |
| 24 GrStrokeInfo(const GrStrokeInfo& src, bool includeDash = true) : fStroke(src
.fStroke) { | 26 GrStrokeInfo(const GrStrokeInfo& src, bool includeDash = true) |
| 27 : INHERITED(src) { |
| 25 if (includeDash && src.isDashed()) { | 28 if (includeDash && src.isDashed()) { |
| 26 fDashType = src.fDashType; | 29 fDashType = src.fDashType; |
| 27 fDashPhase = src.fDashPhase; | 30 fDashPhase = src.fDashPhase; |
| 28 fIntervals.reset(src.getDashCount()); | 31 fIntervals.reset(src.getDashCount()); |
| 29 memcpy(fIntervals.get(), src.fIntervals.get(), fIntervals.count() *
sizeof(SkScalar)); | 32 memcpy(fIntervals.get(), src.fIntervals.get(), fIntervals.count() *
sizeof(SkScalar)); |
| 30 } else { | 33 } else { |
| 31 fDashType = SkPathEffect::kNone_DashType; | 34 fDashType = SkPathEffect::kNone_DashType; |
| 32 } | 35 } |
| 33 } | 36 } |
| 34 | 37 |
| 35 GrStrokeInfo(const SkPaint& paint, SkPaint::Style styleOverride) : | 38 GrStrokeInfo(const SkPaint& paint, SkPaint::Style styleOverride) |
| 36 fStroke(paint, styleOverride), fDashType(SkPathEffect::kNone_DashType) { | 39 : INHERITED(paint, styleOverride) |
| 40 , fDashType(SkPathEffect::kNone_DashType) { |
| 37 this->init(paint); | 41 this->init(paint); |
| 38 } | 42 } |
| 39 | 43 |
| 40 explicit GrStrokeInfo(const SkPaint& paint) : | 44 explicit GrStrokeInfo(const SkPaint& paint) |
| 41 fStroke(paint), fDashType(SkPathEffect::kNone_DashType) { | 45 : INHERITED(paint) |
| 46 , fDashType(SkPathEffect::kNone_DashType) { |
| 42 this->init(paint); | 47 this->init(paint); |
| 43 } | 48 } |
| 44 | 49 |
| 45 GrStrokeInfo& operator=(const GrStrokeInfo& other) { | 50 GrStrokeInfo& operator=(const GrStrokeInfo& other) { |
| 46 if (other.isDashed()) { | 51 if (other.isDashed()) { |
| 47 fDashType = other.fDashType; | 52 fDashType = other.fDashType; |
| 48 fDashPhase = other.fDashPhase; | 53 fDashPhase = other.fDashPhase; |
| 49 fIntervals.reset(other.getDashCount()); | 54 fIntervals.reset(other.getDashCount()); |
| 50 memcpy(fIntervals.get(), other.fIntervals.get(), fIntervals.count()
* sizeof(SkScalar)); | 55 memcpy(fIntervals.get(), other.fIntervals.get(), fIntervals.count()
* sizeof(SkScalar)); |
| 51 } else { | 56 } else { |
| 52 this->removeDash(); | 57 this->removeDash(); |
| 53 } | 58 } |
| 54 fStroke = other.fStroke; | 59 this->INHERITED::operator=(other); |
| 55 return *this; | 60 return *this; |
| 56 } | 61 } |
| 57 | 62 |
| 58 const SkStrokeRec& getStrokeRec() const { return fStroke; } | |
| 59 | |
| 60 SkStrokeRec* getStrokeRecPtr() { return &fStroke; } | |
| 61 | |
| 62 void setFillStyle() { fStroke.setFillStyle(); } | |
| 63 | |
| 64 /* | 63 /* |
| 65 * This functions takes in a patheffect and updates the dashing information
if the path effect | 64 * This functions takes in a patheffect and updates the dashing information
if the path effect |
| 66 * is a Dash type. Returns true if the path effect is a dashed effect and we
are stroking, | 65 * is a Dash type. Returns true if the path effect is a dashed effect and we
are stroking, |
| 67 * otherwise it returns false. | 66 * otherwise it returns false. |
| 68 */ | 67 */ |
| 69 bool setDashInfo(const SkPathEffect* pe) { | 68 bool setDashInfo(const SkPathEffect* pe) { |
| 70 if (pe && !fStroke.isFillStyle()) { | 69 if (pe && !this->isFillStyle()) { |
| 71 SkPathEffect::DashInfo dashInfo; | 70 SkPathEffect::DashInfo dashInfo; |
| 72 fDashType = pe->asADash(&dashInfo); | 71 fDashType = pe->asADash(&dashInfo); |
| 73 if (SkPathEffect::kDash_DashType == fDashType) { | 72 if (SkPathEffect::kDash_DashType == fDashType) { |
| 74 fIntervals.reset(dashInfo.fCount); | 73 fIntervals.reset(dashInfo.fCount); |
| 75 dashInfo.fIntervals = fIntervals.get(); | 74 dashInfo.fIntervals = fIntervals.get(); |
| 76 pe->asADash(&dashInfo); | 75 pe->asADash(&dashInfo); |
| 77 fDashPhase = dashInfo.fPhase; | 76 fDashPhase = dashInfo.fPhase; |
| 78 return true; | 77 return true; |
| 79 } | 78 } |
| 80 } | 79 } |
| 81 return false; | 80 return false; |
| 82 } | 81 } |
| 83 | 82 |
| 84 /* | 83 /* |
| 85 * Like the above, but sets with an explicit SkPathEffect::DashInfo | 84 * Like the above, but sets with an explicit SkPathEffect::DashInfo |
| 86 */ | 85 */ |
| 87 bool setDashInfo(const SkPathEffect::DashInfo& info) { | 86 bool setDashInfo(const SkPathEffect::DashInfo& info) { |
| 88 if (!fStroke.isFillStyle()) { | 87 if (!this->isFillStyle()) { |
| 89 SkASSERT(!fStroke.isFillStyle()); | |
| 90 fDashType = SkPathEffect::kDash_DashType; | 88 fDashType = SkPathEffect::kDash_DashType; |
| 91 fDashPhase = info.fPhase; | 89 fDashPhase = info.fPhase; |
| 92 fIntervals.reset(info.fCount); | 90 fIntervals.reset(info.fCount); |
| 93 for (int i = 0; i < fIntervals.count(); i++) { | 91 for (int i = 0; i < fIntervals.count(); i++) { |
| 94 fIntervals[i] = info.fIntervals[i]; | 92 fIntervals[i] = info.fIntervals[i]; |
| 95 } | 93 } |
| 96 return true; | 94 return true; |
| 97 } | 95 } |
| 98 return false; | 96 return false; |
| 99 } | 97 } |
| 100 | 98 |
| 101 bool isDashed() const { | 99 bool isDashed() const { |
| 102 return (!fStroke.isFillStyle() && SkPathEffect::kDash_DashType == fDashT
ype); | 100 return (!this->isFillStyle() && SkPathEffect::kDash_DashType == fDashTyp
e); |
| 103 } | 101 } |
| 104 | 102 |
| 105 bool isFillStyle() const { return fStroke.isFillStyle(); } | |
| 106 | |
| 107 int32_t getDashCount() const { | 103 int32_t getDashCount() const { |
| 108 SkASSERT(this->isDashed()); | 104 SkASSERT(this->isDashed()); |
| 109 return fIntervals.count(); | 105 return fIntervals.count(); |
| 110 } | 106 } |
| 111 | 107 |
| 112 SkScalar getDashPhase() const { | 108 SkScalar getDashPhase() const { |
| 113 SkASSERT(this->isDashed()); | 109 SkASSERT(this->isDashed()); |
| 114 return fDashPhase; | 110 return fDashPhase; |
| 115 } | 111 } |
| 116 | 112 |
| 117 const SkScalar* getDashIntervals() const { | 113 const SkScalar* getDashIntervals() const { |
| 118 SkASSERT(this->isDashed()); | 114 SkASSERT(this->isDashed()); |
| 119 return fIntervals.get(); | 115 return fIntervals.get(); |
| 120 } | 116 } |
| 121 | 117 |
| 122 void removeDash() { | 118 void removeDash() { |
| 123 fDashType = SkPathEffect::kNone_DashType; | 119 fDashType = SkPathEffect::kNone_DashType; |
| 124 } | 120 } |
| 125 | 121 |
| 126 /** Applies the dash to a path, if the stroke info has dashing. | 122 /** Applies the dash to a path, if the stroke info has dashing. |
| 127 * @return true if the dashing was applied (dst and dstStrokeInfo will be mo
dified). | 123 * @return true if the dashing was applied (dst and dstStrokeInfo will be mo
dified). |
| 128 * false if the stroke info did not have dashing. The dst and dstStr
okeInfo | 124 * false if the stroke info did not have dashing. The dst and dstStr
okeInfo |
| 129 * will be unmodified. The stroking in the SkStrokeRec might s
till | 125 * will be unmodified. The stroking in the SkStrokeRec might s
till |
| 130 * be applicable. | 126 * be applicable. |
| 131 */ | 127 */ |
| 132 bool applyDash(SkPath* dst, GrStrokeInfo* dstStrokeInfo, const SkPath& src)
const; | 128 bool applyDashToPath(SkPath* dst, GrStrokeInfo* dstStrokeInfo, const SkPath&
src) const; |
| 133 | 129 |
| 134 private: | 130 private: |
| 131 // Prevent accidental usage, not implemented for GrStrokeInfos. |
| 132 bool hasEqualEffect(const SkStrokeRec& other) const; |
| 135 | 133 |
| 136 void init(const SkPaint& paint) { | 134 void init(const SkPaint& paint) { |
| 137 const SkPathEffect* pe = paint.getPathEffect(); | 135 const SkPathEffect* pe = paint.getPathEffect(); |
| 138 this->setDashInfo(pe); | 136 this->setDashInfo(pe); |
| 139 } | 137 } |
| 140 | 138 |
| 141 SkStrokeRec fStroke; | |
| 142 SkPathEffect::DashType fDashType; | 139 SkPathEffect::DashType fDashType; |
| 143 SkScalar fDashPhase; | 140 SkScalar fDashPhase; |
| 144 SkAutoSTArray<2, SkScalar> fIntervals; | 141 SkAutoSTArray<2, SkScalar> fIntervals; |
| 142 typedef SkStrokeRec INHERITED; |
| 145 }; | 143 }; |
| 146 | 144 |
| 147 #endif | 145 #endif |
| OLD | NEW |