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

Side by Side Diff: src/gpu/GrShape.cpp

Issue 2359933002: Use sk_careful_memcpy when writing optional conic weights for GrShape path data key. (Closed)
Patch Set: actually remove dependency Created 4 years, 2 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 2016 Google Inc. 2 * Copyright 2016 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 #include "GrShape.h" 8 #include "GrShape.h"
9 9
10 GrShape& GrShape::operator=(const GrShape& that) { 10 GrShape& GrShape::operator=(const GrShape& that) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 const int conicWeightCnt = SkPathPriv::ConicWeightCnt(path); 82 const int conicWeightCnt = SkPathPriv::ConicWeightCnt(path);
83 83
84 GR_STATIC_ASSERT(sizeof(SkPoint) == 2 * sizeof(uint32_t)); 84 GR_STATIC_ASSERT(sizeof(SkPoint) == 2 * sizeof(uint32_t));
85 GR_STATIC_ASSERT(sizeof(SkScalar) == sizeof(uint32_t)); 85 GR_STATIC_ASSERT(sizeof(SkScalar) == sizeof(uint32_t));
86 // 2 is for the verb cnt and a fill type. Each verb is a byte but we'll pad the verb data out to 86 // 2 is for the verb cnt and a fill type. Each verb is a byte but we'll pad the verb data out to
87 // a uint32_t length. 87 // a uint32_t length.
88 return 2 + (SkAlign4(verbCnt) >> 2) + 2 * pointCnt + conicWeightCnt; 88 return 2 + (SkAlign4(verbCnt) >> 2) + 2 * pointCnt + conicWeightCnt;
89 } 89 }
90 90
91 // Writes the path data key into the passed pointer. 91 // Writes the path data key into the passed pointer.
92 static void write_path_key_from(const SkPath& path, uint32_t* origKey) { 92 static void write_path_key_from_data(const SkPath& path, uint32_t* origKey) {
93 uint32_t* key = origKey; 93 uint32_t* key = origKey;
94 // The check below should take care of negative values casted positive. 94 // The check below should take care of negative values casted positive.
95 const int verbCnt = path.countVerbs(); 95 const int verbCnt = path.countVerbs();
96 const int pointCnt = path.countPoints(); 96 const int pointCnt = path.countPoints();
97 const int conicWeightCnt = SkPathPriv::ConicWeightCnt(path); 97 const int conicWeightCnt = SkPathPriv::ConicWeightCnt(path);
98 SkASSERT(verbCnt <= GrShape::kMaxKeyFromDataVerbCnt); 98 SkASSERT(verbCnt <= GrShape::kMaxKeyFromDataVerbCnt);
99 SkASSERT(pointCnt && verbCnt); 99 SkASSERT(pointCnt && verbCnt);
100 *key++ = path.getFillType(); 100 *key++ = path.getFillType();
101 *key++ = verbCnt; 101 *key++ = verbCnt;
102 memcpy(key, SkPathPriv::VerbData(path), verbCnt * sizeof(uint8_t)); 102 memcpy(key, SkPathPriv::VerbData(path), verbCnt * sizeof(uint8_t));
103 int verbKeySize = SkAlign4(verbCnt); 103 int verbKeySize = SkAlign4(verbCnt);
104 // pad out to uint32_t alignment using value that will stand out when debugg ing. 104 // pad out to uint32_t alignment using value that will stand out when debugg ing.
105 uint8_t* pad = reinterpret_cast<uint8_t*>(key)+ verbCnt; 105 uint8_t* pad = reinterpret_cast<uint8_t*>(key)+ verbCnt;
106 memset(pad, 0xDE, verbKeySize - verbCnt); 106 memset(pad, 0xDE, verbKeySize - verbCnt);
107 key += verbKeySize >> 2; 107 key += verbKeySize >> 2;
108 108
109 memcpy(key, SkPathPriv::PointData(path), sizeof(SkPoint) * pointCnt); 109 memcpy(key, SkPathPriv::PointData(path), sizeof(SkPoint) * pointCnt);
110 GR_STATIC_ASSERT(sizeof(SkPoint) == 2 * sizeof(uint32_t)); 110 GR_STATIC_ASSERT(sizeof(SkPoint) == 2 * sizeof(uint32_t));
111 key += 2 * pointCnt; 111 key += 2 * pointCnt;
112 memcpy(key, SkPathPriv::ConicWeightData(path), sizeof(SkScalar) * conicWeigh tCnt); 112 sk_careful_memcpy(key, SkPathPriv::ConicWeightData(path), sizeof(SkScalar) * conicWeightCnt);
113 GR_STATIC_ASSERT(sizeof(SkScalar) == sizeof(uint32_t)); 113 GR_STATIC_ASSERT(sizeof(SkScalar) == sizeof(uint32_t));
114 SkDEBUGCODE(key += conicWeightCnt); 114 SkDEBUGCODE(key += conicWeightCnt);
115 SkASSERT(key - origKey == path_key_from_data_size(path)); 115 SkASSERT(key - origKey == path_key_from_data_size(path));
116 } 116 }
117 117
118 int GrShape::unstyledKeySize() const { 118 int GrShape::unstyledKeySize() const {
119 if (fInheritedKey.count()) { 119 if (fInheritedKey.count()) {
120 return fInheritedKey.count(); 120 return fInheritedKey.count();
121 } 121 }
122 switch (fType) { 122 switch (fType) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 SkASSERT(fRRectData.fStart < 8); 167 SkASSERT(fRRectData.fStart < 8);
168 break; 168 break;
169 case Type::kLine: 169 case Type::kLine:
170 memcpy(key, fLineData.fPts, 2 * sizeof(SkPoint)); 170 memcpy(key, fLineData.fPts, 2 * sizeof(SkPoint));
171 key += 4; 171 key += 4;
172 *key++ = fLineData.fInverted ? 1 : 0; 172 *key++ = fLineData.fInverted ? 1 : 0;
173 break; 173 break;
174 case Type::kPath: { 174 case Type::kPath: {
175 int dataKeySize = path_key_from_data_size(fPathData.fPath); 175 int dataKeySize = path_key_from_data_size(fPathData.fPath);
176 if (dataKeySize >= 0) { 176 if (dataKeySize >= 0) {
177 write_path_key_from(fPathData.fPath, key); 177 write_path_key_from_data(fPathData.fPath, key);
178 return; 178 return;
179 } 179 }
180 SkASSERT(fPathData.fGenID); 180 SkASSERT(fPathData.fGenID);
181 *key++ = fPathData.fGenID; 181 *key++ = fPathData.fGenID;
182 // We could canonicalize the fill rule for paths that don't diff erentiate between 182 // We could canonicalize the fill rule for paths that don't diff erentiate between
183 // even/odd or winding fill (e.g. convex). 183 // even/odd or winding fill (e.g. convex).
184 *key++ = this->path().getFillType(); 184 *key++ = this->path().getFillType();
185 break; 185 break;
186 } 186 }
187 } 187 }
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 fStyle = GrStyle::SimpleFill(); 531 fStyle = GrStyle::SimpleFill();
532 return; 532 return;
533 } 533 }
534 } 534 }
535 // Only path effects could care about the order of the points. Otherwise can onicalize 535 // Only path effects could care about the order of the points. Otherwise can onicalize
536 // the point order. 536 // the point order.
537 if (pts[1].fY < pts[0].fY || (pts[1].fY == pts[0].fY && pts[1].fX < pts[0].f X)) { 537 if (pts[1].fY < pts[0].fY || (pts[1].fY == pts[0].fY && pts[1].fX < pts[0].f X)) {
538 SkTSwap(pts[0], pts[1]); 538 SkTSwap(pts[0], pts[1]);
539 } 539 }
540 } 540 }
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