2 * Copyright 2016 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 // Draws big rects with clip (0, 0, 35, 35). The size of the rects is given by big.
11 static void draw_big_rect(SkCanvas* canvas, SkScalar big, const SkPaint& rectPaint) {
25 canvas->clipRect({0, 0, 35, 35});
27 // Align to pixel boundaries.
28 canvas->translate(0.5, 0.5);
30 SkRect horiz = SkRect::MakeLTRB(-big, 5, big, 10);
31 canvas->drawRect(horiz, rectPaint);
33 SkRect vert = SkRect::MakeLTRB(5, -big, 10, big);
34 canvas->drawRect(vert, rectPaint);
36 SkRect fromLeft = SkRect::MakeLTRB(-big, 20, 17, 25);
37 canvas->drawRect(fromLeft, rectPaint);
39 SkRect fromTop = SkRect::MakeLTRB(20, -big, 25, 17);
40 canvas->drawRect(fromTop, rectPaint);
42 SkRect fromRight = SkRect::MakeLTRB(28, 20, big, 25);
43 canvas->drawRect(fromRight, rectPaint);
45 SkRect fromBottom = SkRect::MakeLTRB(20, 28, 25, big);
46 canvas->drawRect(fromBottom, rectPaint);
48 SkRect leftBorder = SkRect::MakeLTRB(-2, -1, 0, 35);
49 canvas->drawRect(leftBorder, rectPaint);
51 SkRect topBorder = SkRect::MakeLTRB(-1, -2, 35, 0);
52 canvas->drawRect(topBorder, rectPaint);
54 SkRect rightBorder = SkRect::MakeLTRB(34, -1, 36, 35);
55 canvas->drawRect(rightBorder, rectPaint);
57 SkRect bottomBorder = SkRect::MakeLTRB(-1, 34, 35, 36);
58 canvas->drawRect(bottomBorder, rectPaint);
60 SkPaint outOfBoundsPaint;
61 outOfBoundsPaint.setColor(SK_ColorRED);
62 outOfBoundsPaint.setStyle(SkPaint::kStroke_Style);
63 outOfBoundsPaint.setStrokeWidth(0);
65 SkRect outOfBounds = SkRect::MakeLTRB(-1, -1, 35, 35);
66 canvas->drawRect(outOfBounds, outOfBoundsPaint);
69 DEF_SIMPLE_GM(bigrect, canvas, 325, 125) {
71 // - reasonable size (for comparison),
72 // - outside the range of int32, and
73 // - outside the range of SkFixed.
74 static const SkScalar sizes[] = {SkIntToScalar(100), 5e10f, 1e6f};
76 for (int i = 0; i < 8; i++) {
77 for (int j = 0; j < 3; j++) {
79 canvas->translate(SkIntToScalar(i*40+5), SkIntToScalar(j*40+5));
82 paint.setColor(SK_ColorBLUE);
83 // These are the three parameters that affect the behavior of SkDraw::drawRect.
85 paint.setStyle(SkPaint::kFill_Style);
87 paint.setStyle(SkPaint::kStroke_Style);
90 paint.setStrokeWidth(1);
92 paint.setStrokeWidth(0);
95 paint.setAntiAlias(true);
97 paint.setAntiAlias(false);
100 const SkScalar big = SkFloatToScalar(sizes[j]);
101 draw_big_rect(canvas, big, paint);