Flutter Engine
The Flutter Engine
Functions
RectTest.cpp File Reference
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkM44.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "src/core/SkRectPriv.h"
#include "tests/Test.h"
#include <climits>
#include <initializer_list>
#include <string>

Go to the source code of this file.

Functions

static bool has_green_pixels (const SkBitmap &bm)
 
static void test_stroke_width_clipping (skiatest::Reporter *reporter)
 
static void test_skbug4406 (skiatest::Reporter *reporter)
 
 DEF_TEST (Rect, reporter)
 
 DEF_TEST (Rect_grow, reporter)
 
 DEF_TEST (Rect_path_nan, reporter)
 
 DEF_TEST (Rect_largest, reporter)
 
 DEF_TEST (Rect_setbounds, reporter)
 
static float make_big_value (skiatest::Reporter *reporter)
 
 DEF_TEST (Rect_whOverflow, reporter)
 
 DEF_TEST (Rect_subtract, reporter)
 
 DEF_TEST (Rect_subtract_overflow, reporter)
 
 DEF_TEST (Rect_QuadContainsRect, reporter)
 
 DEF_TEST (Rect_ClosestDisjointEdge, r)
 
 DEF_TEST (big_tiled_rect_crbug_927075, reporter)
 

Function Documentation

◆ DEF_TEST() [1/11]

DEF_TEST ( big_tiled_rect_crbug_927075  ,
reporter   
)

Definition at line 442 of file RectTest.cpp.

442 {
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 };
456 paint.setAntiAlias(true);
457
458 canvas->translate(-r.fLeft, -r.fTop);
459 canvas->drawRect(r, paint);
460 }
461}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
const Paint & paint
Definition: color_source.cc:38
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SkScalar w
SkScalar h
static SkImageInfo MakeN32Premul(int width, int height)
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15

◆ DEF_TEST() [2/11]

DEF_TEST ( Rect  ,
reporter   
)

Definition at line 103 of file RectTest.cpp.

103 {
106}
reporter
Definition: FontMgrTest.cpp:39
static void test_stroke_width_clipping(skiatest::Reporter *reporter)
Definition: RectTest.cpp:41
static void test_skbug4406(skiatest::Reporter *reporter)
Definition: RectTest.cpp:65

◆ DEF_TEST() [3/11]

DEF_TEST ( Rect_ClosestDisjointEdge  ,
 
)

Definition at line 400 of file RectTest.cpp.

400 {
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
437 REPORTER_ASSERT(r, SkRectPriv::ClosestDisjointEdge({10,10,-1,2}, {15,8,-2,20}).isEmpty());
438}
static BlurTest tests[]
Definition: BlurTest.cpp:84
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
static SkIRect ClosestDisjointEdge(const SkIRect &src, const SkIRect &dst)
Definition: SkRect.cpp:323
dst
Definition: cp.py:12
Definition: SkRect.h:32
static constexpr SkIRect MakeEmpty()
Definition: SkRect.h:45

◆ DEF_TEST() [4/11]

DEF_TEST ( Rect_grow  ,
reporter   
)

Definition at line 108 of file RectTest.cpp.

◆ DEF_TEST() [5/11]

DEF_TEST ( Rect_largest  ,
reporter   
)

Definition at line 121 of file RectTest.cpp.

121 {
124
128}
static SkIRect MakeILarge()
Definition: SkRectPriv.h:22
static SkRect MakeLargeS32()
Definition: SkRectPriv.h:33
static constexpr SkRect MakeLargestInverted()
Definition: SkRectPriv.h:43
static SkRect MakeLargest()
Definition: SkRectPriv.h:39
static SkIRect MakeILargestInverted()
Definition: SkRectPriv.h:29

◆ DEF_TEST() [6/11]

DEF_TEST ( Rect_path_nan  ,
reporter   
)

Definition at line 113 of file RectTest.cpp.

113 {
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}
#define SK_ScalarNaN
Definition: SkScalar.h:28
Definition: SkPath.h:59

◆ DEF_TEST() [7/11]

DEF_TEST ( Rect_QuadContainsRect  ,
reporter   
)

Definition at line 283 of file RectTest.cpp.

283 {
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) {
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);
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);
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}
#define SK_ScalarPI
Definition: SkScalar.h:21
Definition: SkM44.h:150
static SkM44 Rotate(SkV3 axis, SkScalar radians)
Definition: SkM44.h:239
static SkM44 Perspective(float near, float far, float angle)
Definition: SkM44.cpp:343
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
static SkMatrix RotateDeg(SkScalar deg)
Definition: SkMatrix.h:104
static SkMatrix MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
Definition: SkMatrix.h:179
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
SkMatrix & preTranslate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.cpp:263
static bool QuadContainsRect(const SkMatrix &m, const SkIRect &a, const SkIRect &b, float tol=0.f)
Definition: SkRect.cpp:261
static bool b
struct MyStruct a[10]
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
constexpr SkRect makeOffset(float dx, float dy) const
Definition: SkRect.h:965
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646

◆ DEF_TEST() [8/11]

DEF_TEST ( Rect_setbounds  ,
reporter   
)

Definition at line 135 of file RectTest.cpp.

135 {
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);
147 REPORTER_ASSERT(reporter, r == zeror);
148
149 r.setBoundsNoCheck(pts, n);
150 if (r.isFinite())
151 r.setBoundsNoCheck(pts, n);
153 }
154 }
155}
#define SK_ScalarInfinity
Definition: SkScalar.h:26
SINT bool isfinite(const Vec< N, T > &v)
Definition: SkVx.h:1003
bool isFinite() const
Definition: SkRect.h:711
bool setBoundsCheck(const SkPoint pts[], int count)
Definition: SkRect.cpp:61
void setBoundsNoCheck(const SkPoint pts[], int count)
Definition: SkRect.cpp:100

◆ DEF_TEST() [9/11]

DEF_TEST ( Rect_subtract  ,
reporter   
)

Definition at line 184 of file RectTest.cpp.

184 {
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
200 // A is not empty, B is empty == a
201 {a, SkIRect::MakeEmpty(), a, true},
202 // A and B are empty == empty
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) {
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}
static size_t difference(size_t minuend, size_t subtrahend)
static bool Subtract(const SkRect &a, const SkRect &b, SkRect *out)
Definition: SkRect.cpp:252
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition: SkRect.h:91
void offset(float dx, float dy)
Definition: SkRect.h:1016
bool isEmpty() const
Definition: SkRect.h:693

◆ DEF_TEST() [10/11]

DEF_TEST ( Rect_subtract_overflow  ,
reporter   
)

Definition at line 257 of file RectTest.cpp.

257 {
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.
272 bool exact = SkRectPriv::Subtract(reallyBig, reasonable, &difference);
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);
280 REPORTER_ASSERT(reporter, difference == reasonable);
281}

◆ DEF_TEST() [11/11]

DEF_TEST ( Rect_whOverflow  ,
reporter   
)

Definition at line 165 of file RectTest.cpp.

165 {
166 const SkScalar big = make_big_value(reporter);
167 const SkRect r = { -big, -big, big, big };
168
172
173 // ensure we can compute center even when the width/height might overflow
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.
182}
static float make_big_value(skiatest::Reporter *reporter)
Definition: RectTest.cpp:157
static bool SkIsFinite(T x, Pack... values)
static constexpr float HalfWidth(const SkRect &r)
Definition: SkRectPriv.h:62
static constexpr float HalfHeight(const SkRect &r)
Definition: SkRectPriv.h:66
float SkScalar
Definition: extension.cpp:12
constexpr float centerX() const
Definition: SkRect.h:776
constexpr float height() const
Definition: SkRect.h:769
constexpr float centerY() const
Definition: SkRect.h:785
constexpr float width() const
Definition: SkRect.h:762

◆ has_green_pixels()

static bool has_green_pixels ( const SkBitmap bm)
static

Definition at line 29 of file RectTest.cpp.

29 {
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}
#define SkColorGetG(color)
Definition: SkColor.h:69
SkColor getColor(int x, int y) const
Definition: SkBitmap.h:874
int width() const
Definition: SkBitmap.h:149
int height() const
Definition: SkBitmap.h:158

◆ make_big_value()

static float make_big_value ( skiatest::Reporter reporter)
static

Definition at line 157 of file RectTest.cpp.

157 {
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.
162 return reporter ? SK_ScalarMax * 0.75f : 0;
163}
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SK_ScalarMax
Definition: SkScalar.h:24

◆ test_skbug4406()

static void test_skbug4406 ( skiatest::Reporter reporter)
static

Definition at line 65 of file RectTest.cpp.

65 {
66 SkBitmap bm;
67 bm.allocN32Pixels(10, 10);
69
70 SkCanvas canvas(bm);
71 const SkRect r = { 1.5f, 1, 3.5f, 3 };
72 // draw filled green rect first
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
83 paint.setColor(0xff000000);
84 paint.setStrokeWidth(1);
85 canvas.drawRect(r, paint);
87
88 // do it again with thinner stroke
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
97 paint.setColor(0xff000000);
98 paint.setStrokeWidth(0.99f);
99 canvas.drawRect(r, paint);
101}
static bool has_green_pixels(const SkBitmap &bm)
Definition: RectTest.cpp:29
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193

◆ test_stroke_width_clipping()

static void test_stroke_width_clipping ( skiatest::Reporter reporter)
static

Definition at line 41 of file RectTest.cpp.

41 {
42 SkBitmap bm;
43 bm.allocN32Pixels(100, 10);
45
46 SkCanvas canvas(bm);
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);
58
59 // right stroke edge should bleed into the visible area
60 canvas.scale(2, 2);
61 canvas.drawRect(SkRect::MakeWH(22, 50), paint);
63}
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609