OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkRect.h" | 10 #include "SkRect.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 paint.setColor(0xff000000); | 81 paint.setColor(0xff000000); |
82 paint.setStrokeWidth(0.99f); | 82 paint.setStrokeWidth(0.99f); |
83 canvas.drawRect(r, paint); | 83 canvas.drawRect(r, paint); |
84 REPORTER_ASSERT(reporter, has_green_pixels(bm)); | 84 REPORTER_ASSERT(reporter, has_green_pixels(bm)); |
85 } | 85 } |
86 | 86 |
87 DEF_TEST(Rect, reporter) { | 87 DEF_TEST(Rect, reporter) { |
88 test_stroke_width_clipping(reporter); | 88 test_stroke_width_clipping(reporter); |
89 test_skbug4406(reporter); | 89 test_skbug4406(reporter); |
90 } | 90 } |
| 91 |
| 92 DEF_TEST(Rect_round, reporter) { |
| 93 SkRandom rand; |
| 94 |
| 95 for (int i = 0; i < 100000; ++i) { |
| 96 SkRect src = SkRect::MakeXYWH(rand.nextSScalar1() * 1000, |
| 97 rand.nextSScalar1() * 1000, |
| 98 rand.nextUScalar1() * 1000, |
| 99 rand.nextUScalar1() * 1000); |
| 100 SkRect rd0 = { |
| 101 SkScalarRoundToScalar(src.fLeft), |
| 102 SkScalarRoundToScalar(src.fTop), |
| 103 SkScalarRoundToScalar(src.fRight), |
| 104 SkScalarRoundToScalar(src.fBottom) |
| 105 }; |
| 106 SkRect rd1 = src.round2s(); |
| 107 |
| 108 REPORTER_ASSERT(reporter, rd0 == rd1); |
| 109 |
| 110 SkIRect ir0 = { |
| 111 SkScalarRoundToInt(src.fLeft), |
| 112 SkScalarRoundToInt(src.fTop), |
| 113 SkScalarRoundToInt(src.fRight), |
| 114 SkScalarRoundToInt(src.fBottom) |
| 115 }; |
| 116 SkIRect ir1 = src.round(); |
| 117 SkIRect ir2 = src.round2i(); |
| 118 |
| 119 REPORTER_ASSERT(reporter, ir0 == ir1); |
| 120 REPORTER_ASSERT(reporter, ir0 == ir2); |
| 121 } |
| 122 } |
OLD | NEW |