Chromium Code Reviews| 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 the data objects that hold all the pertinent infoma tion | 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, | 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 | 17 * width, miter, cap, and join. The second object is DashInfo. This holds inform ation about the |
| 18 * dash like intervals, count, and phase. | 18 * dash like intervals, count, and phase. |
| 19 */ | 19 */ |
| 20 class GrStrokeInfo { | 20 class GrStrokeInfo { |
| 21 public: | 21 public: |
| 22 GrStrokeInfo(SkStrokeRec::InitStyle style) : | 22 GrStrokeInfo(SkStrokeRec::InitStyle style) : |
| 23 fStroke(style), fDashType(SkPathEffect::kNone_DashType) {} | 23 fStroke(style), fPathEffect(NULL), fDashType(SkPathEffect::kNone_DashTyp e) {} |
| 24 | 24 |
| 25 GrStrokeInfo(const GrStrokeInfo& src, bool includeDash = true) : fStroke(src .fStroke) { | 25 GrStrokeInfo(const GrStrokeInfo& src, bool includeDash = true) : |
| 26 fStroke(src.fStroke), fPathEffect(NULL) { | |
| 26 if (includeDash) { | 27 if (includeDash) { |
| 27 fDashInfo = src.fDashInfo; | 28 fDashInfo = src.fDashInfo; |
| 28 fDashType = src.fDashType; | 29 fDashType = src.fDashType; |
| 29 fIntervals.reset(src.dashCount()); | 30 fIntervals.reset(src.dashCount()); |
| 30 memcpy(fIntervals.get(), src.fIntervals.get(), src.dashCount() * siz eof(SkScalar)); | 31 memcpy(fIntervals.get(), src.fIntervals.get(), src.dashCount() * siz eof(SkScalar)); |
| 31 } else { | 32 } else { |
| 32 fDashType = SkPathEffect::kNone_DashType; | 33 fDashType = SkPathEffect::kNone_DashType; |
| 33 } | 34 } |
| 35 SkRefCnt_SafeAssign(fPathEffect, src.fPathEffect); | |
| 36 } | |
| 37 | |
| 38 ~GrStrokeInfo() { | |
| 39 SkSafeUnref(fPathEffect); | |
| 34 } | 40 } |
| 35 | 41 |
| 36 GrStrokeInfo(const SkPaint& paint, SkPaint::Style styleOverride) : | 42 GrStrokeInfo(const SkPaint& paint, SkPaint::Style styleOverride) : |
| 37 fStroke(paint, styleOverride), fDashType(SkPathEffect::kNone_DashType) { | 43 fStroke(paint, styleOverride), fPathEffect(NULL), fDashType(SkPathEffect ::kNone_DashType) { |
| 38 this->init(paint); | 44 this->init(paint); |
| 39 } | 45 } |
| 40 | 46 |
| 41 | 47 |
| 42 explicit GrStrokeInfo(const SkPaint& paint) : | 48 explicit GrStrokeInfo(const SkPaint& paint) : |
| 43 fStroke(paint), fDashType(SkPathEffect::kNone_DashType) { | 49 fStroke(paint), fPathEffect(NULL), fDashType(SkPathEffect::kNone_DashTyp e) { |
| 44 this->init(paint); | 50 this->init(paint); |
| 45 } | 51 } |
| 46 | 52 |
| 47 const SkStrokeRec& getStrokeRec() const { return fStroke; } | 53 const SkStrokeRec& getStrokeRec() const { return fStroke; } |
| 48 | 54 |
| 49 SkStrokeRec* getStrokeRecPtr() { return &fStroke; } | 55 SkStrokeRec* getStrokeRecPtr() { return &fStroke; } |
| 50 | 56 |
| 51 void setFillStyle() { fStroke.setFillStyle(); } | 57 void setFillStyle() { fStroke.setFillStyle(); } |
| 52 | 58 |
| 53 /* | 59 /* |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 76 int32_t dashCount() const { | 82 int32_t dashCount() const { |
| 77 return fDashInfo.fCount; | 83 return fDashInfo.fCount; |
| 78 } | 84 } |
| 79 | 85 |
| 80 void removeDash() { | 86 void removeDash() { |
| 81 fDashType = SkPathEffect::kNone_DashType; | 87 fDashType = SkPathEffect::kNone_DashType; |
| 82 } | 88 } |
| 83 | 89 |
| 84 const SkPathEffect::DashInfo& getDashInfo() const { return fDashInfo; } | 90 const SkPathEffect::DashInfo& getDashInfo() const { return fDashInfo; } |
| 85 | 91 |
| 92 SkPathEffect* getPathEffect() const { return fPathEffect; } | |
|
bsalomon
2015/04/16 17:52:18
can this be const?
| |
| 93 | |
| 86 private: | 94 private: |
| 87 | 95 |
| 88 void init(const SkPaint& paint) { | 96 void init(const SkPaint& paint) { |
| 89 const SkPathEffect* pe = paint.getPathEffect(); | 97 SkPathEffect* pe = paint.getPathEffect(); |
| 90 this->setDashInfo(pe); | 98 this->setDashInfo(pe); |
| 99 SkRefCnt_SafeAssign(fPathEffect, pe); | |
| 91 } | 100 } |
| 92 | 101 |
| 93 SkStrokeRec fStroke; | 102 SkStrokeRec fStroke; |
| 103 SkPathEffect* fPathEffect; | |
|
bsalomon
2015/04/16 17:52:18
can this be const?
| |
| 94 SkPathEffect::DashType fDashType; | 104 SkPathEffect::DashType fDashType; |
| 95 SkPathEffect::DashInfo fDashInfo; | 105 SkPathEffect::DashInfo fDashInfo; |
| 96 SkAutoSTArray<2, SkScalar> fIntervals; | 106 SkAutoSTArray<2, SkScalar> fIntervals; |
| 97 }; | 107 }; |
| 98 | 108 |
| 99 #endif | 109 #endif |
| OLD | NEW |