OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkRect.h" | 9 #include "SkRect.h" |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... | |
38 | 38 |
39 void SkRect::toQuad(SkPoint quad[4]) const { | 39 void SkRect::toQuad(SkPoint quad[4]) const { |
40 SkASSERT(quad); | 40 SkASSERT(quad); |
41 | 41 |
42 quad[0].set(fLeft, fTop); | 42 quad[0].set(fLeft, fTop); |
43 quad[1].set(fRight, fTop); | 43 quad[1].set(fRight, fTop); |
44 quad[2].set(fRight, fBottom); | 44 quad[2].set(fRight, fBottom); |
45 quad[3].set(fLeft, fBottom); | 45 quad[3].set(fLeft, fBottom); |
46 } | 46 } |
47 | 47 |
48 //#include "Sk2x.h" | |
49 #include "Sk4x.h" | |
50 | |
51 static inline bool is_finite(const Sk4f& value) { | |
52 Sk4i finite = value * Sk4f(0) == Sk4f(0); | |
53 return finite.allTrue(); | |
54 } | |
55 | |
48 bool SkRect::setBoundsCheck(const SkPoint pts[], int count) { | 56 bool SkRect::setBoundsCheck(const SkPoint pts[], int count) { |
49 SkASSERT((pts && count > 0) || count == 0); | 57 SkASSERT((pts && count > 0) || count == 0); |
50 | 58 |
51 bool isFinite = true; | 59 bool isFinite = true; |
52 | 60 |
53 if (count <= 0) { | 61 if (count <= 0) { |
54 sk_bzero(this, sizeof(SkRect)); | 62 sk_bzero(this, sizeof(SkRect)); |
55 } else { | 63 } else { |
64 #if 0 | |
56 SkScalar l, t, r, b; | 65 SkScalar l, t, r, b; |
57 | 66 |
58 l = r = pts[0].fX; | 67 l = r = pts[0].fX; |
59 t = b = pts[0].fY; | 68 t = b = pts[0].fY; |
60 | 69 |
61 // If all of the points are finite, accum should stay 0. If we encounter | 70 // If all of the points are finite, accum should stay 0. If we encounter |
62 // a NaN or infinity, then accum should become NaN. | 71 // a NaN or infinity, then accum should become NaN. |
63 float accum = 0; | 72 float accum = 0; |
64 accum *= l; accum *= t; | 73 accum *= l; accum *= t; |
65 | 74 |
66 for (int i = 1; i < count; i++) { | 75 for (int i = 1; i < count; i++) { |
67 SkScalar x = pts[i].fX; | 76 SkScalar x = pts[i].fX; |
68 SkScalar y = pts[i].fY; | 77 SkScalar y = pts[i].fY; |
69 | 78 |
70 accum *= x; accum *= y; | 79 accum *= x; accum *= y; |
71 | 80 |
72 // we use if instead of if/else, so we can generate min/max | 81 // we use if instead of if/else, so we can generate min/max |
73 // float instructions (at least on SSE) | 82 // float instructions (at least on SSE) |
74 if (x < l) l = x; | 83 if (x < l) l = x; |
75 if (x > r) r = x; | 84 if (x > r) r = x; |
76 | 85 |
77 if (y < t) t = y; | 86 if (y < t) t = y; |
78 if (y > b) b = y; | 87 if (y > b) b = y; |
79 } | 88 } |
80 | 89 |
81 SkASSERT(!accum || !SkScalarIsFinite(accum)); | 90 SkASSERT(!accum || !SkScalarIsFinite(accum)); |
91 accum = 0; | |
82 if (accum) { | 92 if (accum) { |
83 l = t = r = b = 0; | 93 l = t = r = b = 0; |
84 isFinite = false; | 94 isFinite = false; |
85 } | 95 } |
86 this->set(l, t, r, b); | 96 this->set(l, t, r, b); |
97 #else | |
98 Sk4f min, max, accum; | |
99 | |
100 if (count & 1) { | |
101 min = Sk4f(pts[0].fX, pts[0].fY, pts[0].fX, pts[0].fY); | |
102 pts += 1; | |
103 count -= 1; | |
104 } else { | |
105 min = Sk4f::Load(&pts[0].fX); | |
106 pts += 2; | |
107 count -= 2; | |
108 } | |
109 accum = max = min; | |
110 accum *= Sk4f(0); | |
mtklein
2015/03/25 18:35:55
// See is_finite(). ?
| |
111 | |
112 count >>= 1; | |
113 for (int i = 0; i < count; ++i) { | |
114 Sk4f xy = Sk4f::Load(&pts->fX); | |
115 accum *= xy; | |
116 min = Sk4f::Min(min, xy); | |
mtklein
2015/03/25 18:35:55
Add a note about NaN + accum?
| |
117 max = Sk4f::Max(max, xy); | |
118 pts += 2; | |
119 } | |
120 | |
121 if (is_finite(accum)) { | |
122 float minArray[4], maxArray[4]; | |
123 min.store(minArray); | |
124 max.store(maxArray); | |
125 this->set(SkTMin(minArray[0], minArray[2]), SkTMin(minArray[1], minA rray[3]), | |
126 SkTMax(maxArray[0], maxArray[2]), SkTMax(maxArray[1], maxA rray[3])); | |
127 } else { | |
128 // we hit a non-finite value, so zero everything and return false | |
129 this->setEmpty(); | |
130 isFinite = false; | |
131 } | |
132 #endif | |
87 } | 133 } |
88 | 134 |
89 return isFinite; | 135 return isFinite; |
90 } | 136 } |
91 | 137 |
92 #define CHECK_INTERSECT(al, at, ar, ab, bl, bt, br, bb) \ | 138 #define CHECK_INTERSECT(al, at, ar, ab, bl, bt, br, bb) \ |
93 SkScalar L = SkMaxScalar(al, bl); \ | 139 SkScalar L = SkMaxScalar(al, bl); \ |
94 SkScalar R = SkMinScalar(ar, br); \ | 140 SkScalar R = SkMinScalar(ar, br); \ |
95 SkScalar T = SkMaxScalar(at, bt); \ | 141 SkScalar T = SkMaxScalar(at, bt); \ |
96 SkScalar B = SkMinScalar(ab, bb); \ | 142 SkScalar B = SkMinScalar(ab, bb); \ |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 SkString strL, strT, strR, strB; | 200 SkString strL, strT, strR, strB; |
155 SkAppendScalarDec(&strL, fLeft); | 201 SkAppendScalarDec(&strL, fLeft); |
156 SkAppendScalarDec(&strT, fTop); | 202 SkAppendScalarDec(&strT, fTop); |
157 SkAppendScalarDec(&strR, fRight); | 203 SkAppendScalarDec(&strR, fRight); |
158 SkAppendScalarDec(&strB, fBottom); | 204 SkAppendScalarDec(&strB, fBottom); |
159 line.printf("SkRect::MakeLTRB(%s, %s, %s, %s);", | 205 line.printf("SkRect::MakeLTRB(%s, %s, %s, %s);", |
160 strL.c_str(), strT.c_str(), strR.c_str(), strB.c_str()); | 206 strL.c_str(), strT.c_str(), strR.c_str(), strB.c_str()); |
161 } | 207 } |
162 SkDebugf("%s\n", line.c_str()); | 208 SkDebugf("%s\n", line.c_str()); |
163 } | 209 } |
OLD | NEW |