1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "include/core/SkBitmap.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkColor.h"
11 #include "include/core/SkImageInfo.h"
12 #include "include/core/SkM44.h"
13 #include "include/core/SkMatrix.h"
14 #include "include/core/SkPaint.h"
15 #include "include/core/SkPath.h"
16 #include "include/core/SkPoint.h"
17 #include "include/core/SkRect.h"
18 #include "include/core/SkRefCnt.h"
19 #include "include/core/SkScalar.h"
20 #include "include/core/SkSurface.h"
21 #include "include/core/SkTypes.h"
22 #include "src/core/SkRectPriv.h"
23 #include "tests/Test.h"
24
25 #include <climits>
26 #include <initializer_list>
27 #include <string>
28
has_green_pixels(const SkBitmap & bm)29 static bool has_green_pixels(const SkBitmap& bm) {
30 for (int j = 0; j < bm.height(); ++j) {
31 for (int i = 0; i < bm.width(); ++i) {
32 if (SkColorGetG(bm.getColor(i, j))) {
33 return true;
34 }
35 }
36 }
37
38 return false;
39 }
40
test_stroke_width_clipping(skiatest::Reporter * reporter)41 static void test_stroke_width_clipping(skiatest::Reporter* reporter) {
42 SkBitmap bm;
43 bm.allocN32Pixels(100, 10);
44 bm.eraseColor(SK_ColorTRANSPARENT);
45
46 SkCanvas canvas(bm);
47 SkPaint paint;
48 paint.setStyle(SkPaint::kStroke_Style);
49 paint.setStrokeWidth(10);
50 paint.setColor(0xff00ff00);
51
52 // clip out the left half of our canvas
53 canvas.clipRect(SkRect::MakeXYWH(51, 0, 49, 100));
54
55 // no stroke bleed should be visible
56 canvas.drawRect(SkRect::MakeWH(44, 100), paint);
57 REPORTER_ASSERT(reporter, !has_green_pixels(bm));
58
59 // right stroke edge should bleed into the visible area
60 canvas.scale(2, 2);
61 canvas.drawRect(SkRect::MakeWH(22, 50), paint);
62 REPORTER_ASSERT(reporter, has_green_pixels(bm));
63 }
64
test_skbug4406(skiatest::Reporter * reporter)65 static void test_skbug4406(skiatest::Reporter* reporter) {
66 SkBitmap bm;
67 bm.allocN32Pixels(10, 10);
68 bm.eraseColor(SK_ColorTRANSPARENT);
69
70 SkCanvas canvas(bm);
71 const SkRect r = { 1.5f, 1, 3.5f, 3 };
72 // draw filled green rect first
73 SkPaint paint;
74 paint.setStyle(SkPaint::kFill_Style);
75 paint.setColor(0xff00ff00);
76 paint.setStrokeWidth(1);
77 paint.setAntiAlias(true);
78 canvas.drawRect(r, paint);
79
80 // paint black with stroke rect (that asserts in bug 4406)
81 // over the filled rect, it should cover it
82 paint.setStyle(SkPaint::kStroke_Style);
83 paint.setColor(0xff000000);
84 paint.setStrokeWidth(1);
85 canvas.drawRect(r, paint);
86 REPORTER_ASSERT(reporter, !has_green_pixels(bm));
87
88 // do it again with thinner stroke
89 paint.setStyle(SkPaint::kFill_Style);
90 paint.setColor(0xff00ff00);
91 paint.setStrokeWidth(1);
92 paint.setAntiAlias(true);
93 canvas.drawRect(r, paint);
94 // paint black with stroke rect (that asserts in bug 4406)
95 // over the filled rect, it doesnt cover it completelly with thinner stroke
96 paint.setStyle(SkPaint::kStroke_Style);
97 paint.setColor(0xff000000);
98 paint.setStrokeWidth(0.99f);
99 canvas.drawRect(r, paint);
100 REPORTER_ASSERT(reporter, has_green_pixels(bm));
101 }
102
DEF_TEST(Rect,reporter)103 DEF_TEST(Rect, reporter) {
104 test_stroke_width_clipping(reporter);
105 test_skbug4406(reporter);
106 }
107
DEF_TEST(Rect_grow,reporter)108 DEF_TEST(Rect_grow, reporter) {
109 test_stroke_width_clipping(reporter);
110 test_skbug4406(reporter);
111 }
112
DEF_TEST(Rect_path_nan,reporter)113 DEF_TEST(Rect_path_nan, reporter) {
114 SkRect r = { 0, 0, SK_ScalarNaN, 100 };
115 SkPath p;
116 p.addRect(r);
117 // path normally just jams its bounds to be r, but it must notice that r is non-finite
118 REPORTER_ASSERT(reporter, !p.isFinite());
119 }
120
DEF_TEST(Rect_largest,reporter)121 DEF_TEST(Rect_largest, reporter) {
122 REPORTER_ASSERT(reporter, !SkRectPriv::MakeILarge().isEmpty());
123 REPORTER_ASSERT(reporter, SkRectPriv::MakeILargestInverted().isEmpty());
124
125 REPORTER_ASSERT(reporter, !SkRectPriv::MakeLargest().isEmpty());
126 REPORTER_ASSERT(reporter, !SkRectPriv::MakeLargeS32().isEmpty());
127 REPORTER_ASSERT(reporter, SkRectPriv::MakeLargestInverted().isEmpty());
128 }
129
130 /*
131 * Test the setBounds always handles non-finite values correctly:
132 * - setBoundsCheck should return false, and set the rect to all zeros
133 * - setBoundsNoCheck should ensure that rect.isFinite() is false (definitely NOT all zeros)
134 */
DEF_TEST(Rect_setbounds,reporter)135 DEF_TEST(Rect_setbounds, reporter) {
136 const SkPoint p0[] = { { SK_ScalarInfinity, 0 }, { 1, 1 }, { 2, 2 }, { 3, 3 } };
137 const SkPoint p1[] = { { 0, SK_ScalarInfinity }, { 1, 1 }, { 2, 2 }, { 3, 3 } };
138 const SkPoint p2[] = { { SK_ScalarNaN, 0 }, { 1, 1 }, { 2, 2 }, { 3, 3 } };
139 const SkPoint p3[] = { { 0, SK_ScalarNaN }, { 1, 1 }, { 2, 2 }, { 3, 3 } };
140
141 SkRect r;
142 const SkRect zeror = { 0, 0, 0, 0 };
143 for (const SkPoint* pts : { p0, p1, p2, p3 }) {
144 for (int n = 1; n <= 4; ++n) {
145 bool isfinite = r.setBoundsCheck(pts, n);
146 REPORTER_ASSERT(reporter, !isfinite);
147 REPORTER_ASSERT(reporter, r == zeror);
148
149 r.setBoundsNoCheck(pts, n);
150 if (r.isFinite())
151 r.setBoundsNoCheck(pts, n);
152 REPORTER_ASSERT(reporter, !r.isFinite());
153 }
154 }
155 }
156
make_big_value(skiatest::Reporter * reporter)157 static float make_big_value(skiatest::Reporter* reporter) {
158 // need to make a big value, one that will cause rect.width() to overflow to inf.
159 // however, the windows compiler wants about this if it can see the big value inlined.
160 // hence, this stupid trick to try to fool their compiler.
161 SkASSERT(reporter);
162 return reporter ? SK_ScalarMax * 0.75f : 0;
163 }
164
DEF_TEST(Rect_whOverflow,reporter)165 DEF_TEST(Rect_whOverflow, reporter) {
166 const SkScalar big = make_big_value(reporter);
167 const SkRect r = { -big, -big, big, big };
168
169 REPORTER_ASSERT(reporter, r.isFinite());
170 REPORTER_ASSERT(reporter, !SkIsFinite(r.width()));
171 REPORTER_ASSERT(reporter, !SkIsFinite(r.height()));
172
173 // ensure we can compute center even when the width/height might overflow
174 REPORTER_ASSERT(reporter, SkIsFinite(r.centerX()));
175 REPORTER_ASSERT(reporter, SkIsFinite(r.centerY()));
176
177
178 // ensure we can compute halfWidth and halfHeight even when width/height might overflow,
179 // i.e. for use computing the radii filling a rectangle.
180 REPORTER_ASSERT(reporter, SkIsFinite(SkRectPriv::HalfWidth(r)));
181 REPORTER_ASSERT(reporter, SkIsFinite(SkRectPriv::HalfHeight(r)));
182 }
183
DEF_TEST(Rect_subtract,reporter)184 DEF_TEST(Rect_subtract, reporter) {
185 struct Expectation {
186 SkIRect fA;
187 SkIRect fB;
188 SkIRect fExpected;
189 bool fExact;
190 };
191
192 SkIRect a = SkIRect::MakeLTRB(2, 3, 12, 15);
193 Expectation tests[] = {
194 // B contains A == empty rect
195 {a, a.makeOutset(2, 2), SkIRect::MakeEmpty(), true},
196 // A contains B, producing 4x12 (left), 2x12 (right), 4x10(top), and 5x10(bottom)
197 {a, {6, 6, 10, 10}, {2, 10, 12, 15}, false},
198 // A is empty, B is not == empty rect
199 {SkIRect::MakeEmpty(), a, SkIRect::MakeEmpty(), true},
200 // A is not empty, B is empty == a
201 {a, SkIRect::MakeEmpty(), a, true},
202 // A and B are empty == empty
203 {SkIRect::MakeEmpty(), SkIRect::MakeEmpty(), SkIRect::MakeEmpty(), true},
204 // A and B do not intersect == a
205 {a, {15, 17, 20, 40}, a, true},
206 // B cuts off left side of A, producing 6x12 (right)
207 {a, {0, 0, 6, 20}, {6, 3, 12, 15}, true},
208 // B cuts off right side of A, producing 4x12 (left)
209 {a, {6, 0, 20, 20}, {2, 3, 6, 15}, true},
210 // B cuts off top side of A, producing 10x9 (bottom)
211 {a, {0, 0, 20, 6}, {2, 6, 12, 15}, true},
212 // B cuts off bottom side of A, producing 10x7 (top)
213 {a, {0, 10, 20, 20}, {2, 3, 12, 10}, true},
214 // B splits A horizontally, producing 10x3 (top) or 10x5 (bottom)
215 {a, {0, 6, 20, 10}, {2, 10, 12, 15}, false},
216 // B splits A vertically, producing 4x12 (left) or 2x12 (right)
217 {a, {6, 0, 10, 20}, {2, 3, 6, 15}, false},
218 // B cuts top-left of A, producing 8x12 (right) or 10x11 (bottom)
219 {a, {0, 0, 4, 4}, {2, 4, 12, 15}, false},
220 // B cuts top-right of A, producing 8x12 (left) or 10x8 (bottom)
221 {a, {10, 0, 14, 7}, {2, 3, 10, 15}, false},
222 // B cuts bottom-left of A, producing 7x12 (right) or 10x9 (top)
223 {a, {0, 12, 5, 20}, {2, 3, 12, 12}, false},
224 // B cuts bottom-right of A, producing 8x12 (left) or 10x9 (top)
225 {a, {10, 12, 20, 20}, {2, 3, 10, 15}, false},
226 // B crosses the left of A, producing 4x12 (right) or 10x3 (top) or 10x5 (bottom)
227 {a, {0, 6, 8, 10}, {2, 10, 12, 15}, false},
228 // B crosses the right side of A, producing 6x12 (left) or 10x3 (top) or 10x5 (bottom)
229 {a, {8, 6, 20, 10}, {2, 3, 8, 15}, false},
230 // B crosses the top side of A, producing 4x12 (left) or 2x12 (right) or 10x8 (bottom)
231 {a, {6, 0, 10, 7}, {2, 7, 12, 15}, false},
232 // B crosses the bottom side of A, producing 1x12 (left) or 4x12 (right) or 10x3 (top)
233 {a, {4, 6, 8, 20}, {8, 3, 12, 15}, false}
234 };
235
236 for (const Expectation& e : tests) {
237 SkIRect difference;
238 bool exact = SkRectPriv::Subtract(e.fA, e.fB, &difference);
239 REPORTER_ASSERT(reporter, exact == e.fExact);
240 REPORTER_ASSERT(reporter, difference == e.fExpected);
241
242 // Generate equivalent tests for the SkRect case by moving the input rects by 0.5px
243 SkRect af = SkRect::Make(e.fA);
244 SkRect bf = SkRect::Make(e.fB);
245 SkRect ef = SkRect::Make(e.fExpected);
246 af.offset(0.5f, 0.5f);
247 bf.offset(0.5f, 0.5f);
248 ef.offset(0.5f, 0.5f);
249
250 SkRect df;
251 exact = SkRectPriv::Subtract(af, bf, &df);
252 REPORTER_ASSERT(reporter, exact == e.fExact);
253 REPORTER_ASSERT(reporter, (df.isEmpty() && ef.isEmpty()) || (df == ef));
254 }
255 }
256
DEF_TEST(Rect_subtract_overflow,reporter)257 DEF_TEST(Rect_subtract_overflow, reporter) {
258 // This rectangle is sorted but whose int32 width overflows and appears negative (so
259 // isEmpty() returns true).
260 SkIRect reallyBig = SkIRect::MakeLTRB(-INT_MAX + 1000, 0, INT_MAX - 1000, 100);
261 // However, because it's sorted, an intersection with a reasonably sized rectangle is still
262 // valid so the assumption that SkIRect::Intersects() returns false when either input is
263 // empty is invalid, leading to incorrect use of negative width (see crbug.com/1243206)
264 SkIRect reasonable = SkIRect::MakeLTRB(-50, -5, 50, 125);
265
266 // Ignoring overflow, "reallyBig - reasonable" should report exact = false and select either the
267 // left or right portion of 'reallyBig' that excludes 'reasonable', e.g.
268 // {-INT_MAX+1000, 0, -50, 100} or {150, 0, INT_MAX-1000, 100}.
269 // This used to assert, but now it should be detected that 'reallyBig' overflows and is
270 // technically empty, so the result should be itself and exact.
271 SkIRect difference;
272 bool exact = SkRectPriv::Subtract(reallyBig, reasonable, &difference);
273 REPORTER_ASSERT(reporter, exact);
274 REPORTER_ASSERT(reporter, difference == reallyBig);
275
276 // Similarly, if we subtract 'reallyBig', since it's technically empty then we expect the
277 // answer to remain 'reasonable'.
278 exact = SkRectPriv::Subtract(reasonable, reallyBig, &difference);
279 REPORTER_ASSERT(reporter, exact);
280 REPORTER_ASSERT(reporter, difference == reasonable);
281 }
282
DEF_TEST(Rect_QuadContainsRect,reporter)283 DEF_TEST(Rect_QuadContainsRect, reporter) {
284 struct TestCase {
285 std::string label;
286 bool expect;
287 SkMatrix m;
288 SkIRect a;
289 SkIRect b;
290 float tol = 0.f;
291 };
292
293 TestCase tests[] = {
294 { "Identity matrix contains success", /*expect=*/true,
295 /*m=*/SkMatrix::I(), /*a=*/{0,0,15,15}, /*b=*/{2,2,10,10} },
296
297 { "Identity matrix contains failure", /*expect=*/false,
298 /*m=*/SkMatrix::I(), /*a=*/{0,0,15,15}, /*b=*/{-2,-2,10,10} },
299
300 { "Identity mapped rect contains itself", /*expect=*/true,
301 /*m=*/SkMatrix::I(), /*a=*/{0,0,10,10}, /*b=*/{ 0,0,10,10} },
302
303 { "Scaled rect contains success", /*expect=*/true,
304 /*m=*/SkMatrix::Scale(2.f, 3.4f), /*a=*/{0,0,4,4}, /*b=*/{1,1,6,6}},
305
306 { "Scaled rect contains failure", /*expect=*/false,
307 /*m=*/SkMatrix::Scale(0.25f, 0.3f), /*a=*/{0,0,8,8}, /*b=*/{0,0,5,5}},
308
309 { "Rotate rect contains success", /*expect=*/true,
310 /*m=*/SkMatrix::RotateDeg(45.f, {10.f, 10.f}), /*a=*/{0,0,20,20}, /*b=*/{3,3,17,17}},
311
312 { "Rotate rect contains failure", /*expect=*/false,
313 /*m=*/SkMatrix::RotateDeg(45.f, {10.f, 10.f}), /*a=*/{0,0,20,20}, /*b=*/{2,2,18,18}},
314
315 { "Negative scale contains success", /*expect=*/true,
316 /*m=*/SkMatrix::Scale(-1.f, 1.f), /*a=*/{0,0,10,10}, /*b=*/{-9,1,-1,9}},
317
318 { "Empty rect contains nothing", /*expect=*/false,
319 /*m=*/SkMatrix::RotateDeg(45.f, {0.f, 0.f}), /*a=*/{10,10,10,20}, /*b=*/{10,14,10,16}},
320
321 { "MakeEmpty() contains nothing", /*expect=*/false,
322 /*m=*/SkMatrix::RotateDeg(45.f, {0.f, 0.f}), /*a=*/SkIRect::MakeEmpty(), /*b=*/{0,0,1,1}},
323
324 { "Unsorted rect contains nothing", /*expect=*/false,
325 /*m=*/SkMatrix::I(), /*a=*/{10,10,0,0}, /*b=*/{2,2,8,8}},
326
327 { "Unsorted rect is contained", /*expect=*/true,
328 /*m=*/SkMatrix::I(), /*a=*/{0,0,10,10}, /*b=*/{8,8,2,2}},
329
330 // NOTE: preTranslate(65.f, 0.f) gives enough of a different matrix that the contains()
331 // passes even without the epsilon allowance.
332 { "Epsilon not contained", /*expect=*/true,
333 /*m=*/SkMatrix::MakeAll( 0.984808f, 0.173648f, -98.4808f,
334 -0.173648f, 0.984808f, 17.3648f,
335 0.000000f, 0.000000f, 1.0000f)
336 .preTranslate(65.f, 0.f),
337 /*a=*/{0, 0, 134, 215}, /*b=*/{0, 0, 100, 200}, /*tol=*/0.001f},
338 };
339
340 for (const TestCase& t : tests) {
341 skiatest::ReporterContext c{reporter, t.label};
342 REPORTER_ASSERT(reporter, SkRectPriv::QuadContainsRect(t.m, t.a, t.b, t.tol) == t.expect);
343
344 // Generate equivalent tests for SkRect and SkM44 by translating a by 1/2px and 'b' by
345 // 1/2px in post-transform space
346 SkVector bOffset = t.m.mapVector(0.5f, 0.5f);
347 SkRect af = SkRect::Make(t.a).makeOffset(0.5f, 0.5f);
348 SkRect bf = SkRect::Make(t.b).makeOffset(bOffset.fX, bOffset.fY);
349 REPORTER_ASSERT(reporter,
350 SkRectPriv::QuadContainsRect(SkM44(t.m), af, bf, t.tol) == t.expect);
351
352 if (t.tol != 0.f) {
353 // Expect the opposite result if we do not provide any tol.
354 REPORTER_ASSERT(reporter, SkRectPriv::QuadContainsRect(t.m, t.a, t.b) == !t.expect);
355
356 bOffset = t.m.mapVector(0.5f, 0.5f);
357 af = SkRect::Make(t.a).makeOffset(0.5f, 0.5f);
358 bf = SkRect::Make(t.b).makeOffset(bOffset.fX, bOffset.fY);
359 REPORTER_ASSERT(reporter,
360 SkRectPriv::QuadContainsRect(SkM44(t.m), af, bf) == !t.expect);
361 }
362 }
363
364 // Test some more complicated scenarios with perspective that don't fit into the TestCase
365 // structure as nicely.
366 const SkRect a = SkRect::MakeLTRB(1.83f, -0.48f, 15.53f, 30.68f); // arbitrary
367
368 // Perspective matrix where the mapped A has all corners' W > 0
369 {
370 skiatest::ReporterContext c{reporter, "Perspective, W > 0"};
371 SkM44 p = SkM44::Perspective(0.01f, 10.f, SK_ScalarPI / 3.f);
372 p.preTranslate(0.f, 5.f, -0.1f);
373 p.preConcat(SkM44::Rotate({0.f, 1.f, 0.f}, 0.008f /* radians */));
374 REPORTER_ASSERT(reporter, SkRectPriv::QuadContainsRect(p, a, {4.f,10.f,20.f,45.f}));
375 REPORTER_ASSERT(reporter, !SkRectPriv::QuadContainsRect(p, a, {2.f,6.f,23.f,50.f}));
376 }
377 // Perspective matrix where the mapped A has some corners' W < 0
378 {
379 skiatest::ReporterContext c{reporter, "Perspective, some W > 0"};
380 SkM44 p;
381 p.setRow(3, {-.2f, -.6f, 0.f, 8.f});
382 REPORTER_ASSERT(reporter, SkRectPriv::QuadContainsRect(p, a, {10.f,50.f,20.f,60.f}));
383 REPORTER_ASSERT(reporter, !SkRectPriv::QuadContainsRect(p, a, {0.f,1.f,10.f,10.f}));
384 }
385 // Perspective matrix where the mapped A has all corners' W < 0)
386 // For B, we use the previous success contains query above; a rectangle that is inside the
387 // convex hull of the mapped corners of A, projecting each corner with its negative W; and a
388 // rectangle that contains said convex hull.
389 {
390 skiatest::ReporterContext c{reporter, "Perspective, no W > 0"};
391 SkM44 p;
392 p.setRow(3, {-.2f, -.6f, 0.f, 8.f});
393 const SkRect na = a.makeOffset(16.f, 31.f);
394 REPORTER_ASSERT(reporter, !SkRectPriv::QuadContainsRect(p, na, {10.f,50.f,20.f,60.f}));
395 REPORTER_ASSERT(reporter, !SkRectPriv::QuadContainsRect(p, na, {-1.1f,-1.8f,-1.f,-1.79f}));
396 REPORTER_ASSERT(reporter, !SkRectPriv::QuadContainsRect(p, na, {-1.9f,-2.3f,-0.4f,-1.6f}));
397 }
398 }
399
DEF_TEST(Rect_ClosestDisjointEdge,r)400 DEF_TEST(Rect_ClosestDisjointEdge, r) {
401 struct TestCase {
402 std::string label;
403 SkIRect dst;
404 SkIRect expect;
405 };
406
407 // All test cases will use this rect for the src, so dst can be conveniently relative to it.
408 static constexpr SkIRect kSrc = {0,0,10,10};
409 TestCase tests[] = {
410 { "src left edge", /*dst=*/{-15, -5, -2, 15}, /*expected=*/{0, 0, 1, 10}},
411 { "src left edge clipped to dst", /*dst=*/{-15, 2, -2, 8}, /*expected=*/{0, 2, 1, 8}},
412 { "src top-left corner", /*dst=*/{-15,-15, -2, -2}, /*expected=*/{0, 0, 1, 1}},
413 { "src top edge", /*dst=*/{ -5,-10, 15, -2}, /*expected=*/{0, 0, 10, 1}},
414 { "src top edge clipped to dst", /*dst=*/{ 2,-10, 8, -2}, /*expected=*/{2, 0, 8, 1}},
415 { "src top-right corner", /*dst=*/{ 15,-15, 20, -2}, /*expected=*/{9, 0, 10, 1}},
416 { "src right edge", /*dst=*/{ 15, -5, 20, 15}, /*expected=*/{9, 0, 10, 10}},
417 { "src right edge clipped to dst", /*dst=*/{ 15, 2, 20, 8}, /*expected=*/{9, 2, 10, 8}},
418 { "src bottom-right corner", /*dst=*/{ 15, 15, 20, 20}, /*expected=*/{9, 9, 10, 10}},
419 { "src bottom edge", /*dst=*/{ -5, 15, 15, 20}, /*expected=*/{0, 9, 10, 10}},
420 { "src bottom edge clipped to dst", /*dst=*/{ 2, 15, 8, 20}, /*expected=*/{2, 9, 8, 10}},
421 { "src bottom-left corner", /*dst=*/{-15, 15, -2, 20}, /*expected=*/{0, 9, 1, 10}},
422 { "src intersects dst high", /*dst=*/{ 2, 2, 15, 15}, /*expected=*/{2, 2, 10, 10}},
423 { "src intersects dst low", /*dst=*/{ -5, -5, 8, 8}, /*expected=*/{0, 0, 8, 8}},
424 { "src contains dst", /*dst=*/{ 2, 2, 8, 8}, /*expected=*/{2, 2, 8, 8}},
425 { "src contained in dst", /*dst=*/{ -5, -5, 15, 15}, /*expected=*/{0, 0, 10, 10}}
426 };
427
428 for (const TestCase& t : tests) {
429 skiatest::ReporterContext c{r, t.label};
430 SkIRect actual = SkRectPriv::ClosestDisjointEdge(kSrc, t.dst);
431 REPORTER_ASSERT(r, actual == t.expect);
432 }
433
434 // Test emptiness of src and dst
435 REPORTER_ASSERT(r, SkRectPriv::ClosestDisjointEdge(SkIRect::MakeEmpty(), {0,0,8,8}).isEmpty());
436 REPORTER_ASSERT(r, SkRectPriv::ClosestDisjointEdge({0,0,8,8}, SkIRect::MakeEmpty()).isEmpty());
437 REPORTER_ASSERT(r, SkRectPriv::ClosestDisjointEdge({10,10,-1,2}, {15,8,-2,20}).isEmpty());
438 }
439
440 // Before the fix, this sequence would trigger a release_assert in the Tiler
441 // in SkBitmapDevice.cpp
DEF_TEST(big_tiled_rect_crbug_927075,reporter)442 DEF_TEST(big_tiled_rect_crbug_927075, reporter) {
443 // since part of the regression test allocates a huge buffer, don't bother trying on
444 // 32-bit devices (e.g. chromecast) so we avoid them failing to allocated.
445
446 if (sizeof(void*) == 8) {
447 const int w = 67108863;
448 const int h = 1;
449 const auto info = SkImageInfo::MakeN32Premul(w, h);
450
451 auto surf = SkSurfaces::Raster(info);
452 auto canvas = surf->getCanvas();
453
454 const SkRect r = { 257, 213, 67109120, 214 };
455 SkPaint paint;
456 paint.setAntiAlias(true);
457
458 canvas->translate(-r.fLeft, -r.fTop);
459 canvas->drawRect(r, paint);
460 }
461 }
462