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

Side by Side Diff: src/effects/SkDashPathEffect.cpp

Issue 379813004: Always initialize SkDashPathEffect fields. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 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 | no next file » | 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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 #include "SkDashPathEffect.h" 8 #include "SkDashPathEffect.h"
9 9
10 #include "SkDashPathPriv.h" 10 #include "SkDashPathPriv.h"
11 #include "SkReadBuffer.h" 11 #include "SkReadBuffer.h"
12 #include "SkWriteBuffer.h" 12 #include "SkWriteBuffer.h"
13 13
14 SkDashPathEffect::SkDashPathEffect(const SkScalar intervals[], int count, 14 SkDashPathEffect::SkDashPathEffect(const SkScalar intervals[], int count, SkScal ar phase)
15 SkScalar phase) { 15 : fPhase(0)
16 , fInitialDashLength(0)
17 , fInitialDashIndex(0)
18 , fIntervalLength(0) {
16 SkASSERT(intervals); 19 SkASSERT(intervals);
17 SkASSERT(count > 1 && SkAlign2(count) == count); 20 SkASSERT(count > 1 && SkAlign2(count) == count);
18 21
19 fIntervals = (SkScalar*)sk_malloc_throw(sizeof(SkScalar) * count); 22 fIntervals = (SkScalar*)sk_malloc_throw(sizeof(SkScalar) * count);
20 fCount = count; 23 fCount = count;
21 for (int i = 0; i < count; i++) { 24 for (int i = 0; i < count; i++) {
22 SkASSERT(intervals[i] >= 0); 25 SkASSERT(intervals[i] >= 0);
23 fIntervals[i] = intervals[i]; 26 fIntervals[i] = intervals[i];
24 } 27 }
25 28
26 // set the internal data members 29 // set the internal data members
27 SkDashPath::CalcDashParameters(phase, fIntervals, fCount, &fInitialDashLengt h, 30 SkDashPath::CalcDashParameters(phase, fIntervals, fCount,
28 &fInitialDashIndex, &fIntervalLength, &fPhase ); 31 &fInitialDashLength, &fInitialDashIndex, &fIntervalLength, &fPhase);
29 } 32 }
30 33
31 SkDashPathEffect::~SkDashPathEffect() { 34 SkDashPathEffect::~SkDashPathEffect() {
32 sk_free(fIntervals); 35 sk_free(fIntervals);
33 } 36 }
34 37
35 bool SkDashPathEffect::filterPath(SkPath* dst, const SkPath& src, 38 bool SkDashPathEffect::filterPath(SkPath* dst, const SkPath& src,
36 SkStrokeRec* rec, const SkRect* cullRect) const { 39 SkStrokeRec* rec, const SkRect* cullRect) const {
37 return SkDashPath::FilterDashPath(dst, src, rec, cullRect, fIntervals, fCoun t, 40 return SkDashPath::FilterDashPath(dst, src, rec, cullRect, fIntervals, fCoun t,
38 fInitialDashLength, fInitialDashIndex, fIn tervalLength); 41 fInitialDashLength, fInitialDashIndex, fIn tervalLength);
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 void SkDashPathEffect::flatten(SkWriteBuffer& buffer) const { 245 void SkDashPathEffect::flatten(SkWriteBuffer& buffer) const {
243 this->INHERITED::flatten(buffer); 246 this->INHERITED::flatten(buffer);
244 buffer.writeScalar(fPhase); 247 buffer.writeScalar(fPhase);
245 buffer.writeScalarArray(fIntervals, fCount); 248 buffer.writeScalarArray(fIntervals, fCount);
246 } 249 }
247 250
248 SkFlattenable* SkDashPathEffect::CreateProc(SkReadBuffer& buffer) { 251 SkFlattenable* SkDashPathEffect::CreateProc(SkReadBuffer& buffer) {
249 return SkNEW_ARGS(SkDashPathEffect, (buffer)); 252 return SkNEW_ARGS(SkDashPathEffect, (buffer));
250 } 253 }
251 254
252 SkDashPathEffect::SkDashPathEffect(SkReadBuffer& buffer) : INHERITED(buffer) { 255 SkDashPathEffect::SkDashPathEffect(SkReadBuffer& buffer)
256 : INHERITED(buffer)
257 , fPhase(0)
258 , fInitialDashLength(0)
259 , fInitialDashIndex(0)
260 , fIntervalLength(0) {
253 bool useOldPic = buffer.isVersionLT(SkReadBuffer::kDashWritesPhaseIntervals_ Version); 261 bool useOldPic = buffer.isVersionLT(SkReadBuffer::kDashWritesPhaseIntervals_ Version);
254 if (useOldPic) { 262 if (useOldPic) {
255 fInitialDashIndex = buffer.readInt(); 263 fInitialDashIndex = buffer.readInt();
256 fInitialDashLength = buffer.readScalar(); 264 fInitialDashLength = buffer.readScalar();
257 fIntervalLength = buffer.readScalar(); 265 fIntervalLength = buffer.readScalar();
258 buffer.readBool(); // Dummy for old ScalarToFit field 266 buffer.readBool(); // Dummy for old ScalarToFit field
259 } else { 267 } else {
260 fPhase = buffer.readScalar(); 268 fPhase = buffer.readScalar();
261 } 269 }
262 270
(...skipping 10 matching lines...) Expand all
273 fPhase = 0; 281 fPhase = 0;
274 if (fInitialDashLength != -1) { // Signal for bad dash interval 282 if (fInitialDashLength != -1) { // Signal for bad dash interval
275 for (int i = 0; i < fInitialDashIndex; ++i) { 283 for (int i = 0; i < fInitialDashIndex; ++i) {
276 fPhase += fIntervals[i]; 284 fPhase += fIntervals[i];
277 } 285 }
278 fPhase += fIntervals[fInitialDashIndex] - fInitialDashLength; 286 fPhase += fIntervals[fInitialDashIndex] - fInitialDashLength;
279 } 287 }
280 } else { 288 } else {
281 // set the internal data members, fPhase should have been between 0 and intervalLength 289 // set the internal data members, fPhase should have been between 0 and intervalLength
282 // when written to buffer so no need to adjust it 290 // when written to buffer so no need to adjust it
283 SkDashPath::CalcDashParameters(fPhase, fIntervals, fCount, &fInitialDash Length, 291 SkDashPath::CalcDashParameters(fPhase, fIntervals, fCount,
284 &fInitialDashIndex, &fIntervalLength); 292 &fInitialDashLength, &fInitialDashIndex, &fIntervalLength);
285 } 293 }
286 } 294 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698