Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(612)

Side by Side Diff: src/gpu/GrStrokeInfo.h

Issue 1110093002: Avoid using SkPathEffect::DashInfo in GrStrokeInfo (Closed) Base URL: https://skia.googlesource.com/skia.git@dashing-nvpr
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/gpu/GrStrokeInfo.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 all the pertinent infomation regarding the stroke. The SkStrokeRec
16 * regarding the stroke. The two objects are SkStrokeRec which holds information on fill style, 16 * which holds information on fill style, width, miter, cap, and join. It also h olds information
17 * width, miter, cap, and join. The second object is DashInfo. This holds inform ation about the 17 * about the dash like intervals, count, and phase.
18 * dash like intervals, count, and phase.
19 */ 18 */
20 class GrStrokeInfo { 19 class GrStrokeInfo {
21 public: 20 public:
22 GrStrokeInfo(SkStrokeRec::InitStyle style) : 21 GrStrokeInfo(SkStrokeRec::InitStyle style) :
23 fStroke(style), fDashType(SkPathEffect::kNone_DashType) {} 22 fStroke(style), fDashType(SkPathEffect::kNone_DashType) {}
24 23
25 GrStrokeInfo(const GrStrokeInfo& src, bool includeDash = true) : fStroke(src .fStroke) { 24 GrStrokeInfo(const GrStrokeInfo& src, bool includeDash = true) : fStroke(src .fStroke) {
26 if (includeDash) { 25 if (includeDash && src.isDashed()) {
27 fDashInfo = src.fDashInfo;
28 fDashType = src.fDashType; 26 fDashType = src.fDashType;
29 fIntervals.reset(src.dashCount()); 27 fDashPhase = src.fDashPhase;
30 memcpy(fIntervals.get(), src.fIntervals.get(), src.dashCount() * siz eof(SkScalar)); 28 fIntervals.reset(src.getDashCount());
29 memcpy(fIntervals.get(), src.fIntervals.get(), fIntervals.count() * sizeof(SkScalar));
31 } else { 30 } else {
32 fDashType = SkPathEffect::kNone_DashType; 31 fDashType = SkPathEffect::kNone_DashType;
33 } 32 }
34 } 33 }
35 34
36 GrStrokeInfo(const SkPaint& paint, SkPaint::Style styleOverride) : 35 GrStrokeInfo(const SkPaint& paint, SkPaint::Style styleOverride) :
37 fStroke(paint, styleOverride), fDashType(SkPathEffect::kNone_DashType) { 36 fStroke(paint, styleOverride), fDashType(SkPathEffect::kNone_DashType) {
38 this->init(paint); 37 this->init(paint);
39 } 38 }
40 39
41 explicit GrStrokeInfo(const SkPaint& paint) : 40 explicit GrStrokeInfo(const SkPaint& paint) :
42 fStroke(paint), fDashType(SkPathEffect::kNone_DashType) { 41 fStroke(paint), fDashType(SkPathEffect::kNone_DashType) {
43 this->init(paint); 42 this->init(paint);
44 } 43 }
45 44
46 GrStrokeInfo& operator=(const GrStrokeInfo& other) { 45 GrStrokeInfo& operator=(const GrStrokeInfo& other) {
46 if (other.isDashed()) {
47 fDashType = other.fDashType;
48 fDashPhase = other.fDashPhase;
49 fIntervals.reset(other.getDashCount());
50 memcpy(fIntervals.get(), other.fIntervals.get(), fIntervals.count() * sizeof(SkScalar));
51 } else {
52 this->removeDash();
53 }
47 fStroke = other.fStroke; 54 fStroke = other.fStroke;
48 fDashInfo = other.fDashInfo;
49 fDashType = other.fDashType;
50 fIntervals.reset(other.dashCount());
51 memcpy(fIntervals.get(), other.fIntervals.get(), other.dashCount() * siz eof(SkScalar));
52 return *this; 55 return *this;
53 } 56 }
54 57
55 const SkStrokeRec& getStrokeRec() const { return fStroke; } 58 const SkStrokeRec& getStrokeRec() const { return fStroke; }
56 59
57 SkStrokeRec* getStrokeRecPtr() { return &fStroke; } 60 SkStrokeRec* getStrokeRecPtr() { return &fStroke; }
58 61
59 void setFillStyle() { fStroke.setFillStyle(); } 62 void setFillStyle() { fStroke.setFillStyle(); }
60 63
61 /* 64 /*
62 * This functions takes in a patheffect and fills in fDashInfo with the vari ous dashing 65 * This functions takes in a patheffect and updates the dashing information if the path effect
63 * information if the path effect is a Dash type. Returns true if the path e ffect is a 66 * is a Dash type. Returns true if the path effect is a dashed effect and we are stroking,
64 * dashed effect and we are stroking, otherwise it retruns false. 67 * otherwise it returns false.
65 */ 68 */
66 bool setDashInfo(const SkPathEffect* pe) { 69 bool setDashInfo(const SkPathEffect* pe) {
67 if (pe && !fStroke.isFillStyle()) { 70 if (pe && !fStroke.isFillStyle()) {
68 fDashInfo.fIntervals = NULL; 71 SkPathEffect::DashInfo dashInfo;
69 fDashType = pe->asADash(&fDashInfo); 72 fDashType = pe->asADash(&dashInfo);
70 if (SkPathEffect::kDash_DashType == fDashType) { 73 if (SkPathEffect::kDash_DashType == fDashType) {
71 fIntervals.reset(fDashInfo.fCount); 74 fIntervals.reset(dashInfo.fCount);
72 fDashInfo.fIntervals = fIntervals.get(); 75 dashInfo.fIntervals = fIntervals.get();
73 pe->asADash(&fDashInfo); 76 pe->asADash(&dashInfo);
77 fDashPhase = dashInfo.fPhase;
74 return true; 78 return true;
75 } 79 }
76 } 80 }
77 return false; 81 return false;
78 } 82 }
79 83
80 /* 84 /*
81 * Like the above, but sets with an explicit SkPathEffect::DashInfo 85 * Like the above, but sets with an explicit SkPathEffect::DashInfo
82 */ 86 */
83 bool setDashInfo(const SkPathEffect::DashInfo& info) { 87 bool setDashInfo(const SkPathEffect::DashInfo& info) {
84 if (!fStroke.isFillStyle()) { 88 if (!fStroke.isFillStyle()) {
85 SkASSERT(!fStroke.isFillStyle()); 89 SkASSERT(!fStroke.isFillStyle());
86 fDashInfo.fCount = info.fCount; 90 fDashType = SkPathEffect::kDash_DashType;
87 fDashInfo.fPhase = info.fPhase; 91 fDashPhase = info.fPhase;
88 fIntervals.reset(info.fCount); 92 fIntervals.reset(info.fCount);
89 for (int i = 0; i < info.fCount; i++) { 93 for (int i = 0; i < fIntervals.count(); i++) {
90 fIntervals[i] = info.fIntervals[i]; 94 fIntervals[i] = info.fIntervals[i];
91 } 95 }
92 fDashInfo.fIntervals = fIntervals.get();
93 return true; 96 return true;
94 } 97 }
95 return false; 98 return false;
96 } 99 }
97 100
98 bool isDashed() const { 101 bool isDashed() const {
99 return (!fStroke.isFillStyle() && SkPathEffect::kDash_DashType == fDashT ype); 102 return (!fStroke.isFillStyle() && SkPathEffect::kDash_DashType == fDashT ype);
100 } 103 }
101 104
102 bool isFillStyle() const { return fStroke.isFillStyle(); } 105 bool isFillStyle() const { return fStroke.isFillStyle(); }
103 106
104 int32_t dashCount() const { 107 int32_t getDashCount() const {
105 return fDashInfo.fCount; 108 SkASSERT(this->isDashed());
109 return fIntervals.count();
110 }
111
112 SkScalar getDashPhase() const {
113 SkASSERT(this->isDashed());
114 return fDashPhase;
115 }
116
117 const SkScalar* getDashIntervals() const {
118 SkASSERT(this->isDashed());
119 return fIntervals.get();
106 } 120 }
107 121
108 void removeDash() { 122 void removeDash() {
109 fDashType = SkPathEffect::kNone_DashType; 123 fDashType = SkPathEffect::kNone_DashType;
110 } 124 }
111
112 const SkPathEffect::DashInfo& getDashInfo() const { return fDashInfo; }
113 125
114 /** Applies the dash to a path, if the stroke info has dashing. 126 /** Applies the dash to a path, if the stroke info has dashing.
115 * @return true if the dash ingwas applied (dst and dstStrokeInfo will be mo dified). 127 * @return true if the dashing was applied (dst and dstStrokeInfo will be mo dified).
116 * false if the stroke info did not have dashing. The dst and dstStr okeInfo 128 * false if the stroke info did not have dashing. The dst and dstStr okeInfo
117 * will be unmodified. The stroking in the SkStrokeRec might s till 129 * will be unmodified. The stroking in the SkStrokeRec might s till
118 * be applicable. 130 * be applicable.
119 */ 131 */
120 bool applyDash(SkPath* dst, GrStrokeInfo* dstStrokeInfo, const SkPath& src) const; 132 bool applyDash(SkPath* dst, GrStrokeInfo* dstStrokeInfo, const SkPath& src) const;
121 133
122 private: 134 private:
123 135
124 void init(const SkPaint& paint) { 136 void init(const SkPaint& paint) {
125 const SkPathEffect* pe = paint.getPathEffect(); 137 const SkPathEffect* pe = paint.getPathEffect();
126 this->setDashInfo(pe); 138 this->setDashInfo(pe);
127 } 139 }
128 140
129 SkStrokeRec fStroke; 141 SkStrokeRec fStroke;
130 SkPathEffect::DashType fDashType; 142 SkPathEffect::DashType fDashType;
131 SkPathEffect::DashInfo fDashInfo; 143 SkScalar fDashPhase;
132 SkAutoSTArray<2, SkScalar> fIntervals; 144 SkAutoSTArray<2, SkScalar> fIntervals;
133 }; 145 };
134 146
135 #endif 147 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrStrokeInfo.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698