diff options
-rw-r--r-- | docs/SkIRect_Reference.bmh | 129 | ||||
-rw-r--r-- | gm/windowrectangles.cpp | 5 | ||||
-rw-r--r-- | include/core/SkRect.h | 45 | ||||
-rw-r--r-- | src/core/SkRectPriv.h | 5 | ||||
-rw-r--r-- | src/core/SkScalerContext.cpp | 5 | ||||
-rw-r--r-- | tests/BlurTest.cpp | 6 | ||||
-rw-r--r-- | tests/InfRectTest.cpp | 35 | ||||
-rw-r--r-- | tools/fonts/SkRandomScalerContext.cpp | 3 |
8 files changed, 16 insertions, 217 deletions
diff --git a/docs/SkIRect_Reference.bmh b/docs/SkIRect_Reference.bmh index 1e59578310..578949a3b1 100644 --- a/docs/SkIRect_Reference.bmh +++ b/docs/SkIRect_Reference.bmh @@ -519,65 +519,6 @@ original rect: 20, 30, 40, 50 size: 20, 20 # ------------------------------------------------------------------------------ -#Method int32_t centerX() const - -#In Property -#Line # returns midpoint in x ## -Returns average of left edge and right edge. Result does not change if IRect -is sorted. - -Result is rounded down. - -#Return midpoint in x ## - -#Example -#Description -Dividing by two rounds towards zero. centerX uses a bit shift and rounds down. -## - SkIRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}, {-10, -10, 11, 11}}; - for (auto rect : tests) { - SkDebugf("left: %3d right: %3d centerX: %3d ", rect.left(), rect.right(), rect.centerX()); - SkDebugf("div2: %3d\n", (rect.left() + rect.right()) / 2); - } -#StdOut -left: 20 right: 41 centerX: 30 div2: 30 -left: -20 right: -41 centerX: -31 div2: -30 -left: -10 right: 11 centerX: 0 div2: 0 -## -## - -#SeeAlso centerY SkRect::centerX - -## - -# ------------------------------------------------------------------------------ - -#Method int32_t centerY() const - -#In Property -#Line # returns midpoint in y ## -Returns average of top edge and bottom edge. Result does not change if IRect -is sorted. - -Result is rounded down. - -#Return midpoint in y ## - -#Example - SkIRect rect = { 0, 0, 2, 2 }; - rect.offset(0x40000000, 0x40000000); - SkDebugf("left: %d right: %d centerX: %d ", rect.left(), rect.right(), rect.centerX()); -#StdOut -left: 1073741824 right: 1073741826 centerX: 1073741825 -## -## - -#SeeAlso centerX SkRect::centerY - -## - -# ------------------------------------------------------------------------------ - #Method bool isEmpty() const #In Property @@ -701,32 +642,6 @@ test != sorted # ------------------------------------------------------------------------------ -#Method bool is16Bit() const - -#In Property -#Line # returns true if members fit in 16-bit word ## -Returns true if all members: fLeft, fTop, fRight, and fBottom; values are -equal to or larger than -32768 and equal to or smaller than 32767. - -#Return true if members fit in 16-bit word ## - -#Example - SkIRect tests[] = {{-32768, -32768, 32767, 32767}, {-32768, -32768, 32768, 32768}}; - for (auto rect : tests) { - SkDebugf("{%d, %d, %d, %d} %s in 16 bits\n", rect.fLeft, rect.fTop, rect.fRight, - rect.fBottom, rect.is16Bit() ? "fits" : "does not fit"); -} -#StdOut -{-32768, -32768, 32767, 32767} fits in 16 bits -{-32768, -32768, 32768, 32768} does not fit in 16 bits -## -## - -#SeeAlso SkTFitsIn - -## - -# ------------------------------------------------------------------------------ #Subtopic Set #Line # replaces all values ## #Populate @@ -1128,50 +1043,6 @@ describes an area: fLeft is less than fRight, and fTop is less than fBottom. # ------------------------------------------------------------------------------ -#Method bool quickReject(int l, int t, int r, int b) const - -#In Intersection -#Line # returns true if rectangles do not intersect ## -Constructs IRect (l, t, r, b) and returns true if constructed IRect does not -intersect IRect. Does not check to see if construction or IRect is empty. - -Is implemented with short circuit logic so that true can be returned after -a single compare. - -#Param l x minimum of constructed IRect ## -#Param t y minimum of constructed IRect ## -#Param r x maximum of constructed IRect ## -#Param b y maximum of constructed IRect ## - -#Return true if construction and IRect have no area in common ## - -#Example -#Description -quickReject is the complement of Intersects. -## - const SkIRect rect = {7, 11, 13, 17}; - const int32_t* r = &rect.fLeft; - const SkIRect tests[] = { {13, 11, 15, 17}, { 7, 7, 13, 11 }, { 12, 16, 14, 18 } }; - for (auto& test : tests) { - const int32_t* t = &test.fLeft; - SkDebugf("rect (%d, %d, %d, %d) test(%d, %d, %d, %d) quickReject %s; intersects %s\n", - r[0], r[1], r[2], r[3], t[0], t[1], t[2], t[3], - rect.quickReject(t[0], t[1], t[2], t[3]) ? "true" : "false", - SkIRect::Intersects(rect, test) ? "true" : "false"); - } -#StdOut -rect (7, 11, 13, 17) test(13, 11, 15, 17) quickReject true; intersects false -rect (7, 11, 13, 17) test(7, 7, 13, 11) quickReject true; intersects false -rect (7, 11, 13, 17) test(12, 16, 14, 18) quickReject false; intersects true -## -## - -#SeeAlso Intersects - -## - -# ------------------------------------------------------------------------------ - #Method bool contains(int32_t x, int32_t y) const #In Intersection diff --git a/gm/windowrectangles.cpp b/gm/windowrectangles.cpp index 931a154df4..c427b1af27 100644 --- a/gm/windowrectangles.cpp +++ b/gm/windowrectangles.cpp @@ -277,8 +277,9 @@ void WindowRectanglesMaskGM::fail(SkCanvas* canvas) { canvas->clipRect(SkRect::Make(kCoverRect)); canvas->clear(SK_ColorWHITE); - canvas->drawString(errorMsg, SkIntToScalar(kCoverRect.centerX()), - SkIntToScalar(kCoverRect.centerY() - 10), paint); + + canvas->drawString(errorMsg, SkIntToScalar((kCoverRect.left() + kCoverRect.right())/2), + SkIntToScalar((kCoverRect.top() + kCoverRect.bottom())/2 - 10), paint); } DEF_GM( return new WindowRectanglesMaskGM(); ) diff --git a/include/core/SkRect.h b/include/core/SkRect.h index d94b358255..4bf84d91e8 100644 --- a/include/core/SkRect.h +++ b/include/core/SkRect.h @@ -11,7 +11,6 @@ #include "SkPoint.h" #include "SkSize.h" #include "../private/SkSafe32.h" -#include "../private/SkTFitsIn.h" struct SkRect; @@ -175,24 +174,6 @@ struct SK_API SkIRect { */ SkISize size() const { return SkISize::Make(this->width(), this->height()); } - /** Returns average of left edge and right edge. Result does not change if SkIRect - is sorted. - - Result is rounded down. - - @return midpoint in x - */ - int32_t centerX() const { return SkToS32(((int64_t)fRight + fLeft) >> 1); } - - /** Returns average of top edge and bottom edge. Result does not change if SkIRect - is sorted. - - Result is rounded down. - - @return midpoint in y - */ - int32_t centerY() const { return SkToS32(((int64_t)fBottom + fTop) >> 1); } - /** Returns span on the x-axis. This does not check if SkIRect is sorted, so the result may be negative. This is safer than calling width() since width() might overflow in its calculation. @@ -253,16 +234,6 @@ struct SK_API SkIRect { return !(a == b); } - /** Returns true if all members: fLeft, fTop, fRight, and fBottom; values are - equal to or larger than -32768 and equal to or smaller than 32767. - - @return true if members fit in 16-bit word - */ - bool is16Bit() const { - return SkTFitsIn<int16_t>(fLeft) && SkTFitsIn<int16_t>(fTop) && - SkTFitsIn<int16_t>(fRight) && SkTFitsIn<int16_t>(fBottom); - } - /** Sets SkIRect to (0, 0, 0, 0). Many other rectangles are empty; if left is equal to or greater than right, @@ -442,22 +413,6 @@ struct SK_API SkIRect { */ void outset(int32_t dx, int32_t dy) { this->inset(-dx, -dy); } - /** Constructs SkIRect (l, t, r, b) and returns true if constructed SkIRect does not - intersect SkIRect. Does not check to see if construction or SkIRect is empty. - - Is implemented with short circuit logic so that true can be returned after - a single compare. - - @param l x minimum of constructed SkIRect - @param t y minimum of constructed SkIRect - @param r x maximum of constructed SkIRect - @param b y maximum of constructed SkIRect - @return true if construction and SkIRect have no area in common - */ - bool quickReject(int l, int t, int r, int b) const { - return l >= fRight || fLeft >= r || t >= fBottom || fTop >= b; - } - /** Returns true if: fLeft <= x < fRight && fTop <= y < fBottom. Returns false if SkIRect is empty. diff --git a/src/core/SkRectPriv.h b/src/core/SkRectPriv.h index 3bf90f8be7..d817591bb9 100644 --- a/src/core/SkRectPriv.h +++ b/src/core/SkRectPriv.h @@ -53,6 +53,11 @@ public: return SkFitsInFixed(r.fLeft) && SkFitsInFixed(r.fTop) && SkFitsInFixed(r.fRight) && SkFitsInFixed(r.fBottom); } + + static bool Is16Bit(const SkIRect& r) { + return SkTFitsIn<int16_t>(r.fLeft) && SkTFitsIn<int16_t>(r.fTop) && + SkTFitsIn<int16_t>(r.fRight) && SkTFitsIn<int16_t>(r.fBottom); + } }; diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp index 600163910a..5923e4a98a 100644 --- a/src/core/SkScalerContext.cpp +++ b/src/core/SkScalerContext.cpp @@ -23,6 +23,7 @@ #include "SkPathEffect.h" #include "SkRasterClip.h" #include "SkReadBuffer.h" +#include "SkRectPriv.h" #include "SkStroke.h" #include "SkStrokeRec.h" #include "SkSurfacePriv.h" @@ -85,7 +86,7 @@ void SkScalerContext::getMetrics(SkGlyph* glyph) { generateAdvance(glyph); const SkIRect ir = devPath.getBounds().roundOut(); - if (ir.isEmpty() || !ir.is16Bit()) { + if (ir.isEmpty() || !SkRectPriv::Is16Bit(ir)) { goto SK_ERROR; } glyph->fLeft = ir.fLeft; @@ -143,7 +144,7 @@ void SkScalerContext::getMetrics(SkGlyph* glyph) { src.fImage = nullptr; // only want the bounds from the filter if (as_MFB(fMaskFilter)->filterMask(&dst, src, matrix, nullptr)) { - if (dst.fBounds.isEmpty() || !dst.fBounds.is16Bit()) { + if (dst.fBounds.isEmpty() || !SkRectPriv::Is16Bit(dst.fBounds)) { goto SK_ERROR; } SkASSERT(dst.fImage == nullptr); diff --git a/tests/BlurTest.cpp b/tests/BlurTest.cpp index b606064448..e0ce22e3d6 100644 --- a/tests/BlurTest.cpp +++ b/tests/BlurTest.cpp @@ -29,7 +29,7 @@ #include "SkPixmap.h" #include "SkPoint.h" #include "SkRRect.h" -#include "SkRect.h" +#include "SkRectPriv.h" #include "SkRefCnt.h" #include "SkScalar.h" #include "SkShader.h" @@ -192,8 +192,8 @@ static void ground_truth_2d(int width, int height, return; } - int midX = dst.fBounds.centerX(); - int midY = dst.fBounds.centerY(); + int midX = dst.fBounds.x() + dst.fBounds.width()/2; + int midY = dst.fBounds.y() + dst.fBounds.height()/2; uint8_t* bytes = dst.getAddr8(midX, midY); int i; for (i = 0; i < dst.fBounds.width()-(midX-dst.fBounds.fLeft); ++i) { diff --git a/tests/InfRectTest.cpp b/tests/InfRectTest.cpp index 3da0e5e902..966f67f8f4 100644 --- a/tests/InfRectTest.cpp +++ b/tests/InfRectTest.cpp @@ -13,39 +13,6 @@ static float make_zero() { return sk_float_sin(0); } -struct RectCenter { - SkIRect fRect; - SkIPoint fCenter; -}; - -static void test_center(skiatest::Reporter* reporter) { - static const RectCenter gData[] = { - { { 0, 0, 0, 0 }, { 0, 0 } }, - { { 0, 0, 1, 1 }, { 0, 0 } }, - { { -1, -1, 0, 0 }, { -1, -1 } }, - { { 0, 0, 10, 7 }, { 5, 3 } }, - { { 0, 0, 11, 6 }, { 5, 3 } }, - }; - for (size_t index = 0; index < SK_ARRAY_COUNT(gData); ++index) { - REPORTER_ASSERT(reporter, - gData[index].fRect.centerX() == gData[index].fCenter.x()); - REPORTER_ASSERT(reporter, - gData[index].fRect.centerY() == gData[index].fCenter.y()); - } - - SkRandom rand; - for (int i = 0; i < 10000; ++i) { - SkIRect r; - - r.set(rand.nextS() >> 2, rand.nextS() >> 2, - rand.nextS() >> 2, rand.nextS() >> 2); - int cx = r.centerX(); - int cy = r.centerY(); - REPORTER_ASSERT(reporter, ((r.left() + r.right()) >> 1) == cx); - REPORTER_ASSERT(reporter, ((r.top() + r.bottom()) >> 1) == cy); - } -} - static void check_invalid(skiatest::Reporter* reporter, SkScalar l, SkScalar t, SkScalar r, SkScalar b) { SkRect rect; @@ -74,8 +41,6 @@ DEF_TEST(InfRect, reporter) { check_invalid(reporter, small, invalid[i], big, big); check_invalid(reporter, invalid[i], small, big, big); } - - test_center(reporter); } // need tests for SkStrSearch diff --git a/tools/fonts/SkRandomScalerContext.cpp b/tools/fonts/SkRandomScalerContext.cpp index 24dcb02feb..a8a8821a45 100644 --- a/tools/fonts/SkRandomScalerContext.cpp +++ b/tools/fonts/SkRandomScalerContext.cpp @@ -12,6 +12,7 @@ #include "SkMakeUnique.h" #include "SkPath.h" #include "SkRandomScalerContext.h" +#include "SkRectPriv.h" class SkDescriptor; @@ -107,7 +108,7 @@ void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) { // just use devPath const SkIRect ir = devPath.getBounds().roundOut(); - if (ir.isEmpty() || !ir.is16Bit()) { + if (ir.isEmpty() || !SkRectPriv::Is16Bit(ir)) { glyph->fLeft = 0; glyph->fTop = 0; glyph->fWidth = 0; |