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

Side by Side Diff: src/core/SkRRect.cpp

Issue 801693003: Fill SkRRect::fType proactively. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: debug only Created 6 years 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 | « include/core/SkRRect.h ('k') | src/effects/SkBlurMaskFilter.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 2012 Google Inc. 2 * Copyright 2012 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 "SkRRect.h" 8 #include "SkRRect.h"
9 #include "SkMatrix.h" 9 #include "SkMatrix.h"
10 10
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // rrect.rect() != path.getBounds() 199 // rrect.rect() != path.getBounds()
200 fRadii[0].fX = clamp_radius_add(fRadii[0].fX, rect.fLeft, rect.fRight); 200 fRadii[0].fX = clamp_radius_add(fRadii[0].fX, rect.fLeft, rect.fRight);
201 fRadii[0].fY = clamp_radius_add(fRadii[0].fY, rect.fTop, rect.fBottom); 201 fRadii[0].fY = clamp_radius_add(fRadii[0].fY, rect.fTop, rect.fBottom);
202 fRadii[1].fX = clamp_radius_sub(fRadii[1].fX, rect.fLeft, rect.fRight); 202 fRadii[1].fX = clamp_radius_sub(fRadii[1].fX, rect.fLeft, rect.fRight);
203 fRadii[1].fY = clamp_radius_add(fRadii[1].fY, rect.fTop, rect.fBottom); 203 fRadii[1].fY = clamp_radius_add(fRadii[1].fY, rect.fTop, rect.fBottom);
204 fRadii[2].fX = clamp_radius_sub(fRadii[2].fX, rect.fLeft, rect.fRight); 204 fRadii[2].fX = clamp_radius_sub(fRadii[2].fX, rect.fLeft, rect.fRight);
205 fRadii[2].fY = clamp_radius_sub(fRadii[2].fY, rect.fTop, rect.fBottom); 205 fRadii[2].fY = clamp_radius_sub(fRadii[2].fY, rect.fTop, rect.fBottom);
206 fRadii[3].fX = clamp_radius_add(fRadii[3].fX, rect.fLeft, rect.fRight); 206 fRadii[3].fX = clamp_radius_add(fRadii[3].fX, rect.fLeft, rect.fRight);
207 fRadii[3].fY = clamp_radius_sub(fRadii[3].fY, rect.fTop, rect.fBottom); 207 fRadii[3].fY = clamp_radius_sub(fRadii[3].fY, rect.fTop, rect.fBottom);
208 208
209 // At this point we're either oval, simple, or complex (not empty or rect) 209 // At this point we're either oval, simple, or complex (not empty or rect).
210 // but we lazily resolve the type to avoid the work if the information 210 this->computeType();
211 // isn't required.
212 fType = (SkRRect::Type) kUnknown_Type;
213 211
214 SkDEBUGCODE(this->validate();) 212 SkDEBUGCODE(this->validate();)
215 } 213 }
216 214
217 // This method determines if a point known to be inside the RRect's bounds is 215 // This method determines if a point known to be inside the RRect's bounds is
218 // inside all the corners. 216 // inside all the corners.
219 bool SkRRect::checkCornerContainment(SkScalar x, SkScalar y) const { 217 bool SkRRect::checkCornerContainment(SkScalar x, SkScalar y) const {
220 SkPoint canonicalPt; // (x,y) translated to one of the quadrants 218 SkPoint canonicalPt; // (x,y) translated to one of the quadrants
221 int index; 219 int index;
222 220
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 296 }
299 297
300 static bool radii_are_nine_patch(const SkVector radii[4]) { 298 static bool radii_are_nine_patch(const SkVector radii[4]) {
301 return radii[SkRRect::kUpperLeft_Corner].fX == radii[SkRRect::kLowerLeft_Cor ner].fX && 299 return radii[SkRRect::kUpperLeft_Corner].fX == radii[SkRRect::kLowerLeft_Cor ner].fX &&
302 radii[SkRRect::kUpperLeft_Corner].fY == radii[SkRRect::kUpperRight_Co rner].fY && 300 radii[SkRRect::kUpperLeft_Corner].fY == radii[SkRRect::kUpperRight_Co rner].fY &&
303 radii[SkRRect::kUpperRight_Corner].fX == radii[SkRRect::kLowerRight_C orner].fX && 301 radii[SkRRect::kUpperRight_Corner].fX == radii[SkRRect::kLowerRight_C orner].fX &&
304 radii[SkRRect::kLowerLeft_Corner].fY == radii[SkRRect::kLowerRight_Co rner].fY; 302 radii[SkRRect::kLowerLeft_Corner].fY == radii[SkRRect::kLowerRight_Co rner].fY;
305 } 303 }
306 304
307 // There is a simplified version of this method in setRectXY 305 // There is a simplified version of this method in setRectXY
308 void SkRRect::computeType() const { 306 void SkRRect::computeType() {
309 SkDEBUGCODE(this->validate();) 307 struct Validator {
308 Validator(const SkRRect* r) : fR(r) {}
309 ~Validator() { SkDEBUGCODE(fR->validate();) }
310 const SkRRect* fR;
311 } autoValidate(this);
310 312
311 if (fRect.isEmpty()) { 313 if (fRect.isEmpty()) {
312 fType = kEmpty_Type; 314 fType = kEmpty_Type;
313 return; 315 return;
314 } 316 }
315 317
316 bool allRadiiEqual = true; // are all x radii equal and all y radii? 318 bool allRadiiEqual = true; // are all x radii equal and all y radii?
317 bool allCornersSquare = 0 == fRadii[0].fX || 0 == fRadii[0].fY; 319 bool allCornersSquare = 0 == fRadii[0].fX || 0 == fRadii[0].fY;
318 320
319 for (int i = 1; i < 4; ++i) { 321 for (int i = 1; i < 4; ++i) {
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 case kNinePatch_Type: 559 case kNinePatch_Type:
558 SkASSERT(!fRect.isEmpty()); 560 SkASSERT(!fRect.isEmpty());
559 SkASSERT(!allRadiiZero && !allRadiiSame && !allCornersSquare); 561 SkASSERT(!allRadiiZero && !allRadiiSame && !allCornersSquare);
560 SkASSERT(patchesOfNine); 562 SkASSERT(patchesOfNine);
561 break; 563 break;
562 case kComplex_Type: 564 case kComplex_Type:
563 SkASSERT(!fRect.isEmpty()); 565 SkASSERT(!fRect.isEmpty());
564 SkASSERT(!allRadiiZero && !allRadiiSame && !allCornersSquare); 566 SkASSERT(!allRadiiZero && !allRadiiSame && !allCornersSquare);
565 SkASSERT(!patchesOfNine); 567 SkASSERT(!patchesOfNine);
566 break; 568 break;
567 case kUnknown_Type:
568 // no limits on this
569 break;
570 } 569 }
571 } 570 }
572 #endif // SK_DEBUG 571 #endif // SK_DEBUG
573 572
574 /////////////////////////////////////////////////////////////////////////////// 573 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « include/core/SkRRect.h ('k') | src/effects/SkBlurMaskFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698