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

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

Issue 1116123003: Improve caching of dashed paths in GrStencilAndCoverPathRenderer (Closed) Base URL: https://skia.googlesource.com/skia.git@dashing-nvpr-01
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 | « src/gpu/GrStencilAndCoverTextContext.cpp ('k') | 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 class GrUniqueKey;
15
14 /* 16 /*
15 * GrStrokeInfo encapsulates all the pertinent infomation regarding the stroke. The SkStrokeRec 17 * 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 18 * 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. 19 * about the dash like intervals, count, and phase.
18 */ 20 */
19 class GrStrokeInfo : public SkStrokeRec { 21 class GrStrokeInfo : public SkStrokeRec {
20 public: 22 public:
21 GrStrokeInfo(SkStrokeRec::InitStyle style) 23 GrStrokeInfo(SkStrokeRec::InitStyle style)
22 : INHERITED(style) 24 : INHERITED(style)
23 , fDashType(SkPathEffect::kNone_DashType) { 25 , fDashType(SkPathEffect::kNone_DashType) {
(...skipping 29 matching lines...) Expand all
53 fDashPhase = other.fDashPhase; 55 fDashPhase = other.fDashPhase;
54 fIntervals.reset(other.getDashCount()); 56 fIntervals.reset(other.getDashCount());
55 memcpy(fIntervals.get(), other.fIntervals.get(), fIntervals.count() * sizeof(SkScalar)); 57 memcpy(fIntervals.get(), other.fIntervals.get(), fIntervals.count() * sizeof(SkScalar));
56 } else { 58 } else {
57 this->removeDash(); 59 this->removeDash();
58 } 60 }
59 this->INHERITED::operator=(other); 61 this->INHERITED::operator=(other);
60 return *this; 62 return *this;
61 } 63 }
62 64
65 bool hasEqualEffect(const GrStrokeInfo& other) const {
66 if (this->isDashed() != other.isDashed()) {
67 return false;
68 }
69 if (this->isDashed()) {
70 if (fDashPhase != other.fDashPhase ||
71 fIntervals.count() != other.fIntervals.count() ||
72 memcmp(fIntervals.get(), other.fIntervals.get(),
73 fIntervals.count() * sizeof(SkScalar)) != 0) {
74 return false;
75 }
76 }
77 return this->INHERITED::hasEqualEffect(other);
78 }
79
63 /* 80 /*
64 * This functions takes in a patheffect and updates the dashing information if the path effect 81 * This functions takes in a patheffect and updates the dashing information if the path effect
65 * is a Dash type. Returns true if the path effect is a dashed effect and we are stroking, 82 * is a Dash type. Returns true if the path effect is a dashed effect and we are stroking,
66 * otherwise it returns false. 83 * otherwise it returns false.
67 */ 84 */
68 bool setDashInfo(const SkPathEffect* pe) { 85 bool setDashInfo(const SkPathEffect* pe) {
69 if (pe && !this->isFillStyle()) { 86 if (pe && !this->isFillStyle()) {
70 SkPathEffect::DashInfo dashInfo; 87 SkPathEffect::DashInfo dashInfo;
71 fDashType = pe->asADash(&dashInfo); 88 fDashType = pe->asADash(&dashInfo);
72 if (SkPathEffect::kDash_DashType == fDashType) { 89 if (SkPathEffect::kDash_DashType == fDashType) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 137 }
121 138
122 /** Applies the dash to a path, if the stroke info has dashing. 139 /** Applies the dash to a path, if the stroke info has dashing.
123 * @return true if the dashing was applied (dst and dstStrokeInfo will be mo dified). 140 * @return true if the dashing was applied (dst and dstStrokeInfo will be mo dified).
124 * false if the stroke info did not have dashing. The dst and dstStr okeInfo 141 * false if the stroke info did not have dashing. The dst and dstStr okeInfo
125 * will be unmodified. The stroking in the SkStrokeRec might s till 142 * will be unmodified. The stroking in the SkStrokeRec might s till
126 * be applicable. 143 * be applicable.
127 */ 144 */
128 bool applyDashToPath(SkPath* dst, GrStrokeInfo* dstStrokeInfo, const SkPath& src) const; 145 bool applyDashToPath(SkPath* dst, GrStrokeInfo* dstStrokeInfo, const SkPath& src) const;
129 146
147 /**
148 * Computes the length of the data that will be written by asUniqueKeyFragme nt() function.
149 */
150 int computeUniqueKeyFragmentData32Cnt() const {
151 const int kSkScalarData32Cnt = sizeof(SkScalar) / sizeof(uint32_t);
152 // SkStrokeRec data: 32 bits for style+join+cap and 2 scalars for miter and width.
153 int strokeKeyData32Cnt = 1 + 2 * kSkScalarData32Cnt;
154
155 if (this->isDashed()) {
156 // One scalar for dash phase and one for each dash value.
157 strokeKeyData32Cnt += (1 + this->getDashCount()) * kSkScalarData32Cn t;
158 }
159 return strokeKeyData32Cnt;
160 }
161
162 /**
163 * Writes the object contents as uint32_t data, to be used with GrUniqueKey.
164 * Note: the data written does not encode the length, so care must be taken to ensure
165 * that the full unique key data is encoded properly. For example, GrStrokeI nfo
166 * fragment can be placed last in the sequence, at fixed index.
167 */
168 void asUniqueKeyFragment(uint32_t*) const;
169
130 private: 170 private:
131 // Prevent accidental usage, not implemented for GrStrokeInfos. 171 // Prevent accidental usage, should use GrStrokeInfo::hasEqualEffect.
132 bool hasEqualEffect(const SkStrokeRec& other) const; 172 bool hasEqualEffect(const SkStrokeRec& other) const;
133 173
134 void init(const SkPaint& paint) { 174 void init(const SkPaint& paint) {
135 const SkPathEffect* pe = paint.getPathEffect(); 175 const SkPathEffect* pe = paint.getPathEffect();
136 this->setDashInfo(pe); 176 this->setDashInfo(pe);
137 } 177 }
138 178
139 SkPathEffect::DashType fDashType; 179 SkPathEffect::DashType fDashType;
140 SkScalar fDashPhase; 180 SkScalar fDashPhase;
141 SkAutoSTArray<2, SkScalar> fIntervals; 181 SkAutoSTArray<2, SkScalar> fIntervals;
142 typedef SkStrokeRec INHERITED; 182 typedef SkStrokeRec INHERITED;
143 }; 183 };
144 184
145 #endif 185 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrStencilAndCoverTextContext.cpp ('k') | src/gpu/GrStrokeInfo.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698