Ben Wagner | 912876b | 2017-05-04 18:04:53 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 6a34f3a | 2019-05-01 10:59:30 -0400 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkColor.h" |
| 11 | #include "include/core/SkPaint.h" |
| 12 | #include "include/core/SkRect.h" |
| 13 | #include "include/core/SkScalar.h" |
Ben Wagner | 912876b | 2017-05-04 18:04:53 -0400 | [diff] [blame] | 14 | |
| 15 | // Draws big rects with clip (0, 0, 35, 35). The size of the rects is given by big. |
| 16 | static void draw_big_rect(SkCanvas* canvas, SkScalar big, const SkPaint& rectPaint) { |
| 17 | // Looks like this: |
| 18 | // +--+-+----+-+----+ |
| 19 | // | | | | | | |
| 20 | // |--+-+----+-+----+ |
| 21 | // |--+-+----+-+----+ |
| 22 | // | | | | | | |
| 23 | // | | | +-+ | |
| 24 | // +--+-+--+ +--+ |
| 25 | // +--+-+--+ +--+ |
| 26 | // | | | +-+ | |
| 27 | // | | | | | | |
| 28 | // +--+-+----+-+----+ |
| 29 | |
| 30 | canvas->clipRect({0, 0, 35, 35}); |
| 31 | |
| 32 | // Align to pixel boundaries. |
| 33 | canvas->translate(0.5, 0.5); |
| 34 | |
| 35 | SkRect horiz = SkRect::MakeLTRB(-big, 5, big, 10); |
| 36 | canvas->drawRect(horiz, rectPaint); |
| 37 | |
| 38 | SkRect vert = SkRect::MakeLTRB(5, -big, 10, big); |
| 39 | canvas->drawRect(vert, rectPaint); |
| 40 | |
| 41 | SkRect fromLeft = SkRect::MakeLTRB(-big, 20, 17, 25); |
| 42 | canvas->drawRect(fromLeft, rectPaint); |
| 43 | |
| 44 | SkRect fromTop = SkRect::MakeLTRB(20, -big, 25, 17); |
| 45 | canvas->drawRect(fromTop, rectPaint); |
| 46 | |
| 47 | SkRect fromRight = SkRect::MakeLTRB(28, 20, big, 25); |
| 48 | canvas->drawRect(fromRight, rectPaint); |
| 49 | |
| 50 | SkRect fromBottom = SkRect::MakeLTRB(20, 28, 25, big); |
| 51 | canvas->drawRect(fromBottom, rectPaint); |
| 52 | |
| 53 | SkRect leftBorder = SkRect::MakeLTRB(-2, -1, 0, 35); |
| 54 | canvas->drawRect(leftBorder, rectPaint); |
| 55 | |
| 56 | SkRect topBorder = SkRect::MakeLTRB(-1, -2, 35, 0); |
| 57 | canvas->drawRect(topBorder, rectPaint); |
| 58 | |
| 59 | SkRect rightBorder = SkRect::MakeLTRB(34, -1, 36, 35); |
| 60 | canvas->drawRect(rightBorder, rectPaint); |
| 61 | |
| 62 | SkRect bottomBorder = SkRect::MakeLTRB(-1, 34, 35, 36); |
| 63 | canvas->drawRect(bottomBorder, rectPaint); |
| 64 | |
| 65 | SkPaint outOfBoundsPaint; |
| 66 | outOfBoundsPaint.setColor(SK_ColorRED); |
| 67 | outOfBoundsPaint.setStyle(SkPaint::kStroke_Style); |
| 68 | outOfBoundsPaint.setStrokeWidth(0); |
| 69 | |
| 70 | SkRect outOfBounds = SkRect::MakeLTRB(-1, -1, 35, 35); |
| 71 | canvas->drawRect(outOfBounds, outOfBoundsPaint); |
| 72 | } |
| 73 | |
| 74 | DEF_SIMPLE_GM(bigrect, canvas, 325, 125) { |
| 75 | // Test with sizes: |
| 76 | // - reasonable size (for comparison), |
| 77 | // - outside the range of int32, and |
| 78 | // - outside the range of SkFixed. |
| 79 | static const SkScalar sizes[] = {SkIntToScalar(100), 5e10f, 1e6f}; |
| 80 | |
| 81 | for (int i = 0; i < 8; i++) { |
| 82 | for (int j = 0; j < 3; j++) { |
| 83 | canvas->save(); |
| 84 | canvas->translate(SkIntToScalar(i*40+5), SkIntToScalar(j*40+5)); |
| 85 | |
| 86 | SkPaint paint; |
| 87 | paint.setColor(SK_ColorBLUE); |
| 88 | // These are the three parameters that affect the behavior of SkDraw::drawRect. |
| 89 | if (i & 1) { |
| 90 | paint.setStyle(SkPaint::kFill_Style); |
| 91 | } else { |
| 92 | paint.setStyle(SkPaint::kStroke_Style); |
| 93 | } |
| 94 | if (i & 2) { |
| 95 | paint.setStrokeWidth(1); |
| 96 | } else { |
| 97 | paint.setStrokeWidth(0); |
| 98 | } |
| 99 | if (i & 4) { |
| 100 | paint.setAntiAlias(true); |
| 101 | } else { |
| 102 | paint.setAntiAlias(false); |
| 103 | } |
| 104 | |
| 105 | const SkScalar big = SkFloatToScalar(sizes[j]); |
| 106 | draw_big_rect(canvas, big, paint); |
| 107 | canvas->restore(); |
| 108 | } |
| 109 | } |
| 110 | } |