aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-17 19:47:40 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-17 19:47:40 +0000
commitbab3fc4c90c4369c5d77d8da86d9f117ee54e0bc (patch)
tree12a8a698fcc7e3c7136a367a0fd4972cdad74562
parentecb745dba75dde72e5edde72e4b309120e66033b (diff)
Revert of Add nine patch type to SkRRect. (https://codereview.chromium.org/196343015/)
Reason for revert: causes tests to have infinite loop Original issue's description: > Add nine patch type to SkRRect. > > BUG=skia:2181 > > Committed: http://code.google.com/p/skia/source/detail?r=13833 R=robertphillips@google.com, reed@google.com TBR=reed@google.com, robertphillips@google.com NOTREECHECKS=true NOTRY=true BUG=skia:2181 Author: bsalomon@google.com Review URL: https://codereview.chromium.org/202163004 git-svn-id: http://skia.googlecode.com/svn/trunk@13837 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--include/core/SkRRect.h26
-rw-r--r--src/core/SkRRect.cpp75
-rw-r--r--src/effects/SkBlurMaskFilter.cpp4
-rw-r--r--src/utils/SkLua.cpp1
-rw-r--r--src/utils/debugger/SkObjectParser.cpp2
-rw-r--r--tests/RoundRectTest.cpp39
6 files changed, 19 insertions, 128 deletions
diff --git a/include/core/SkRRect.h b/include/core/SkRRect.h
index 5223ae7072..c09d2d46fe 100644
--- a/include/core/SkRRect.h
+++ b/include/core/SkRRect.h
@@ -71,14 +71,6 @@ public:
//!< the curves) nor a rect (i.e., both radii are non-zero)
kSimple_Type,
- //!< The RR is non-empty and the two left x radii are equal, the two top
- //!< y radii are equal, and the same for the right and bottom but it is
- //!< neither an rect, oval, nor a simple RR. It is called "nine patch"
- //!< because the centers of the corner ellipses form an axis aligned
- //!< rect with edges that divide the RR into an 9 rectangular patches:
- //!< an interior patch, four edge patches, and four corner patches.
- kNinePatch_Type,
-
//!< A fully general (non-empty) RR. Some of the x and/or y radii are
//!< different from the others and there must be one corner where
//!< both radii are non-zero.
@@ -107,11 +99,21 @@ public:
inline bool isSimpleCircular() const {
return this->isSimple() && fRadii[0].fX == fRadii[0].fY;
}
- inline bool isNinePatch() const { return kNinePatch_Type == this->getType(); }
inline bool isComplex() const { return kComplex_Type == this->getType(); }
bool allCornersCircular() const;
+ /**
+ * Are both x-radii the same on the two left corners, and similar for the top, right, and
+ * bottom. When this is the case the four ellipse centers form a rectangle.
+ */
+ bool isNinePatch() const {
+ return fRadii[kUpperLeft_Corner].fX == fRadii[kLowerLeft_Corner].fX &&
+ fRadii[kUpperRight_Corner].fX == fRadii[kLowerRight_Corner].fX &&
+ fRadii[kUpperLeft_Corner].fY == fRadii[kUpperRight_Corner].fY &&
+ fRadii[kLowerLeft_Corner].fY == fRadii[kLowerRight_Corner].fY;
+ }
+
SkScalar width() const { return fRect.width(); }
SkScalar height() const { return fRect.height(); }
@@ -170,12 +172,6 @@ public:
void setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad);
/**
- * Initialize the rr with one radius per-side.
- */
- void setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad,
- SkScalar rightRad, SkScalar bottomRad);
-
- /**
* Initialize the RR with potentially different radii for all four corners.
*/
void setRectRadii(const SkRect& rect, const SkVector radii[4]);
diff --git a/src/core/SkRRect.cpp b/src/core/SkRRect.cpp
index 082646c2a7..915ed75327 100644
--- a/src/core/SkRRect.cpp
+++ b/src/core/SkRRect.cpp
@@ -43,61 +43,6 @@ void SkRRect::setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad) {
SkDEBUGCODE(this->validate();)
}
-void SkRRect::setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad,
- SkScalar rightRad, SkScalar bottomRad) {
- if (rect.isEmpty()) {
- this->setEmpty();
- return;
- }
-
- leftRad = SkMaxScalar(leftRad, 0);
- topRad = SkMaxScalar(topRad, 0);
- rightRad = SkMaxScalar(rightRad, 0);
- bottomRad = SkMaxScalar(bottomRad, 0);
-
- SkScalar scale = SK_Scalar1;
- if (leftRad + rightRad > rect.width()) {
- scale = SkScalarDiv(rect.width(), leftRad + rightRad);
- }
- if (topRad + bottomRad > rect.height()) {
- scale = SkMinScalar(scale, SkScalarDiv(rect.width(), leftRad + rightRad));
- }
-
- if (scale < SK_Scalar1) {
- leftRad = SkScalarMul(leftRad, scale);
- topRad = SkScalarMul(topRad, scale);
- rightRad = SkScalarMul(rightRad, scale);
- bottomRad = SkScalarMul(bottomRad, scale);
- }
-
- if (leftRad == rightRad && topRad == bottomRad) {
- if (leftRad >= SkScalarHalf(rect.width()) && topRad >= SkScalarHalf(rect.height())) {
- fType = kOval_Type;
- } else if (0 == leftRad || 0 == topRad) {
- // If the left and (by equality check above) right radii are zero then it is a rect.
- // Same goes for top/bottom.
- fType = kRect_Type;
- leftRad = 0;
- topRad = 0;
- rightRad = 0;
- bottomRad = 0;
- } else {
- fType = kSimple_Type;
- }
- } else {
- fType = kNinePatch_Type;
- }
-
- fRect = rect;
- fRadii[kUpperLeft_Corner].set(leftRad, topRad);
- fRadii[kUpperRight_Corner].set(rightRad, topRad);
- fRadii[kLowerRight_Corner].set(rightRad, bottomRad);
- fRadii[kLowerLeft_Corner].set(leftRad, bottomRad);
-
- SkDEBUGCODE(this->validate();)
-}
-
-
void SkRRect::setRectRadii(const SkRect& rect, const SkVector radii[4]) {
if (rect.isEmpty()) {
this->setEmpty();
@@ -255,13 +200,6 @@ bool SkRRect::contains(const SkRect& rect) const {
this->checkCornerContainment(rect.fLeft, rect.fBottom);
}
-static bool radii_are_nine_patch(const SkVector radii[4]) {
- return radii[SkRRect::kUpperLeft_Corner].fX == radii[SkRRect::kLowerLeft_Corner].fX &&
- radii[SkRRect::kUpperLeft_Corner].fY == radii[SkRRect::kUpperRight_Corner].fY &&
- radii[SkRRect::kUpperRight_Corner].fX == radii[SkRRect::kLowerRight_Corner].fX &&
- radii[SkRRect::kLowerLeft_Corner].fY == radii[SkRRect::kLowerRight_Corner].fY;
-}
-
// There is a simplified version of this method in setRectXY
void SkRRect::computeType() const {
SkDEBUGCODE(this->validate();)
@@ -300,11 +238,7 @@ void SkRRect::computeType() const {
return;
}
- if (radii_are_nine_patch(fRadii)) {
- fType = kNinePatch_Type;
- } else {
- fType = kComplex_Type;
- }
+ fType = kComplex_Type;
}
static bool matrix_only_scale_and_translate(const SkMatrix& matrix) {
@@ -457,7 +391,6 @@ void SkRRect::validate() const {
allCornersSquare = false;
}
}
- bool patchesOfNine = radii_are_nine_patch(fRadii);
switch (fType) {
case kEmpty_Type:
@@ -484,15 +417,9 @@ void SkRRect::validate() const {
SkASSERT(!fRect.isEmpty());
SkASSERT(!allRadiiZero && allRadiiSame && !allCornersSquare);
break;
- case kNinePatch_Type:
- SkASSERT(!fRect.isEmpty());
- SkASSERT(!allRadiiZero && !allRadiiSame && !allCornersSquare);
- SkASSERT(patchesOfNine);
- break;
case kComplex_Type:
SkASSERT(!fRect.isEmpty());
SkASSERT(!allRadiiZero && !allRadiiSame && !allCornersSquare);
- SkASSERT(!patchesOfNine);
break;
case kUnknown_Type:
// no limits on this
diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp
index ff98daf048..a5cdc4f703 100644
--- a/src/effects/SkBlurMaskFilter.cpp
+++ b/src/effects/SkBlurMaskFilter.cpp
@@ -288,10 +288,10 @@ SkBlurMaskFilterImpl::filterRRectToNine(const SkRRect& rrect, const SkMatrix& ma
// already have code for rectangles.
return kUnimplemented_FilterReturn;
- // These three can take advantage of this fast path.
case SkRRect::kSimple_Type:
- case SkRRect::kNinePatch_Type:
+ // Fall through.
case SkRRect::kComplex_Type:
+ // These can take advantage of this fast path.
break;
}
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index 44f2211b8f..4b87458923 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -1208,7 +1208,6 @@ static const char* rrect_type(const SkRRect& rr) {
case SkRRect::kRect_Type: return "rect";
case SkRRect::kOval_Type: return "oval";
case SkRRect::kSimple_Type: return "simple";
- case SkRRect::kNinePatch_Type: return "nine-patch";
case SkRRect::kComplex_Type: return "complex";
}
SkDEBUGFAIL("never get here");
diff --git a/src/utils/debugger/SkObjectParser.cpp b/src/utils/debugger/SkObjectParser.cpp
index a3b208544e..028300c5a5 100644
--- a/src/utils/debugger/SkObjectParser.cpp
+++ b/src/utils/debugger/SkObjectParser.cpp
@@ -241,8 +241,6 @@ SkString* SkObjectParser::RRectToString(const SkRRect& rrect, const char* title)
mRRect->append("oval");
} else if (rrect.isSimple()) {
mRRect->append("simple");
- } else if (rrect.isNinePatch()) {
- mRRect->append("nine-patch");
} else {
SkASSERT(rrect.isComplex());
mRRect->append("complex");
diff --git a/tests/RoundRectTest.cpp b/tests/RoundRectTest.cpp
index 0a528a6535..9b2eecd19c 100644
--- a/tests/RoundRectTest.cpp
+++ b/tests/RoundRectTest.cpp
@@ -60,13 +60,6 @@ static void test_round_rect_basic(skiatest::Reporter* reporter) {
for (int i = 0; i < 4; ++i) {
REPORTER_ASSERT(reporter, zeroPt == rr1.radii((SkRRect::Corner) i));
}
- SkRRect rr1_2; // construct the same RR using the most general set function
- SkVector rr1_2_radii[4] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } };
- rr1_2.setRectRadii(rect, rr1_2_radii);
- REPORTER_ASSERT(reporter, rr1_2 == rr1 && rr1_2.getType() == rr1.getType());
- SkRRect rr1_3; // construct the same RR using the nine patch set function
- rr1_3.setNinePatch(rect, 0, 0, 0, 0);
- REPORTER_ASSERT(reporter, rr1_3 == rr1 && rr1_3.getType() == rr1.getType());
//----
SkPoint halfPoint = { SkScalarHalf(kWidth), SkScalarHalf(kHeight) };
@@ -80,14 +73,6 @@ static void test_round_rect_basic(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter,
rr2.radii((SkRRect::Corner) i).equalsWithinTolerance(halfPoint));
}
- SkRRect rr2_2; // construct the same RR using the most general set function
- SkVector rr2_2_radii[4] = { { halfPoint.fX, halfPoint.fY }, { halfPoint.fX, halfPoint.fY },
- { halfPoint.fX, halfPoint.fY }, { halfPoint.fX, halfPoint.fY } };
- rr2_2.setRectRadii(rect, rr2_2_radii);
- REPORTER_ASSERT(reporter, rr2_2 == rr2 && rr2_2.getType() == rr2.getType());
- SkRRect rr2_3; // construct the same RR using the nine patch set function
- rr2_3.setNinePatch(rect, halfPoint.fX, halfPoint.fY, halfPoint.fX, halfPoint.fY);
- REPORTER_ASSERT(reporter, rr2_3 == rr2 && rr2_3.getType() == rr2.getType());
//----
SkPoint p = { 5, 5 };
@@ -100,33 +85,19 @@ static void test_round_rect_basic(skiatest::Reporter* reporter) {
for (int i = 0; i < 4; ++i) {
REPORTER_ASSERT(reporter, p == rr3.radii((SkRRect::Corner) i));
}
- SkRRect rr3_2; // construct the same RR using the most general set function
- SkVector rr3_2_radii[4] = { { 5, 5 }, { 5, 5 }, { 5, 5 }, { 5, 5 } };
- rr3_2.setRectRadii(rect, rr3_2_radii);
- REPORTER_ASSERT(reporter, rr3_2 == rr3 && rr3_2.getType() == rr3.getType());
- SkRRect rr3_3; // construct the same RR using the nine patch set function
- rr3_3.setNinePatch(rect, 5, 5, 5, 5);
- REPORTER_ASSERT(reporter, rr3_3 == rr3 && rr3_3.getType() == rr3.getType());
//----
- SkRect ninePatchRadii = { 10, 9, 8, 7 };
+ SkPoint radii[4] = { { 5, 5 }, { 5, 5 }, { 5, 5 }, { 5, 5 } };
SkRRect rr4;
- rr4.setNinePatch(rect, ninePatchRadii.fLeft, ninePatchRadii.fTop, ninePatchRadii.fRight,
- ninePatchRadii.fBottom);
+ rr4.setRectRadii(rect, radii);
- REPORTER_ASSERT(reporter, SkRRect::kNinePatch_Type == rr4.type());
+ REPORTER_ASSERT(reporter, SkRRect::kSimple_Type == rr4.type());
REPORTER_ASSERT(reporter, rr4.rect() == rect);
- SkPoint rquad[4];
- ninePatchRadii.toQuad(rquad);
for (int i = 0; i < 4; ++i) {
- REPORTER_ASSERT(reporter, rquad[i] == rr4.radii((SkRRect::Corner) i));
+ REPORTER_ASSERT(reporter, radii[i] == rr4.radii((SkRRect::Corner) i));
}
- SkRRect rr4_2; // construct the same RR using the most general set function
- SkVector rr4_2_radii[4] = { { 10, 9 }, { 8, 9 }, {8, 7 }, { 10, 7 } };
- rr4_2.setRectRadii(rect, rr4_2_radii);
- REPORTER_ASSERT(reporter, rr4_2 == rr4 && rr4_2.getType() == rr4.getType());
//----
SkPoint radii2[4] = { { 0, 0 }, { 0, 0 }, { 50, 50 }, { 20, 50 } };
@@ -143,7 +114,7 @@ static void test_round_rect_basic(skiatest::Reporter* reporter) {
// Test out == & !=
REPORTER_ASSERT(reporter, empty != rr3);
- REPORTER_ASSERT(reporter, rr3 != rr4);
+ REPORTER_ASSERT(reporter, rr3 == rr4);
REPORTER_ASSERT(reporter, rr4 != rr5);
}