Chromium Code Reviews| 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 "GrTestUtils.h" | 8 #include "GrTestUtils.h" |
| 9 #include "GrStyle.h" | 9 #include "GrStyle.h" |
| 10 #include "SkDashPathPriv.h" | 10 #include "SkDashPathPriv.h" |
| 11 #include "SkMatrix.h" | 11 #include "SkMatrix.h" |
| 12 #include "SkPath.h" | 12 #include "SkPath.h" |
| 13 #include "SkRRect.h" | 13 #include "SkRRect.h" |
| 14 | 14 |
| 15 #ifdef GR_TEST_UTILS | 15 #ifdef GR_TEST_UTILS |
| 16 | 16 |
| 17 static const SkMatrix& test_matrix(SkRandom* random, bool includePerspective) { | 17 static const SkMatrix& test_matrix(SkRandom* random, bool includeNonPerspective, bool includePerspective) { |
|
bsalomon
2016/07/02 00:45:28
wrap?
robertphillips
2016/07/06 15:23:50
Done.
| |
| 18 static SkMatrix gMatrices[5]; | 18 static SkMatrix gMatrices[5]; |
| 19 static const int kPerspectiveCount = 1; | 19 static const int kPerspectiveCount = 1; |
| 20 static bool gOnce; | 20 static bool gOnce; |
| 21 if (!gOnce) { | 21 if (!gOnce) { |
| 22 gOnce = true; | 22 gOnce = true; |
| 23 gMatrices[0].reset(); | 23 gMatrices[0].reset(); |
| 24 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); | 24 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); |
| 25 gMatrices[2].setRotate(SkIntToScalar(17)); | 25 gMatrices[2].setRotate(SkIntToScalar(17)); |
| 26 gMatrices[3].setRotate(SkIntToScalar(185)); | 26 gMatrices[3].setRotate(SkIntToScalar(185)); |
| 27 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); | 27 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); |
| 28 gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf); | 28 gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf); |
| 29 | 29 |
| 30 // Perspective matrices | 30 // Perspective matrices |
| 31 gMatrices[4].setRotate(SkIntToScalar(215)); | 31 gMatrices[4].setRotate(SkIntToScalar(215)); |
| 32 gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f); | 32 gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f); |
| 33 gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f); | 33 gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f); |
| 34 } | 34 } |
| 35 | 35 |
| 36 uint32_t count = static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)); | 36 uint32_t count = static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)); |
| 37 if (includePerspective) { | 37 if (includeNonPerspective && includePerspective) { |
| 38 return gMatrices[random->nextULessThan(count)]; | 38 return gMatrices[random->nextULessThan(count)]; |
| 39 } else if (!includeNonPerspective) { | |
| 40 return gMatrices[count - 1 - random->nextULessThan(kPerspectiveCount)]; | |
| 39 } else { | 41 } else { |
| 42 SkASSERT(includeNonPerspective && !includePerspective); | |
| 40 return gMatrices[random->nextULessThan(count - kPerspectiveCount)]; | 43 return gMatrices[random->nextULessThan(count - kPerspectiveCount)]; |
| 41 } | 44 } |
| 42 } | 45 } |
| 43 | 46 |
| 44 namespace GrTest { | 47 namespace GrTest { |
| 45 const SkMatrix& TestMatrix(SkRandom* random) { return test_matrix(random, true); } | 48 const SkMatrix& TestMatrix(SkRandom* random) { return test_matrix(random, true, true); } |
| 46 | 49 |
| 47 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom* random) { | 50 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom* random) { |
| 48 static SkMatrix gMatrices[5]; | 51 static SkMatrix gMatrices[5]; |
| 49 static bool gOnce; | 52 static bool gOnce; |
| 50 if (!gOnce) { | 53 if (!gOnce) { |
| 51 gOnce = true; | 54 gOnce = true; |
| 52 // identity | 55 // identity |
| 53 gMatrices[0].reset(); | 56 gMatrices[0].reset(); |
| 54 // translation | 57 // translation |
| 55 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); | 58 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 // 90 degress rotation | 92 // 90 degress rotation |
| 90 gMatrices[5].setRotate(90); | 93 gMatrices[5].setRotate(90); |
| 91 | 94 |
| 92 for (size_t i = 0; i < SK_ARRAY_COUNT(gMatrices); i++) { | 95 for (size_t i = 0; i < SK_ARRAY_COUNT(gMatrices); i++) { |
| 93 SkASSERT(gMatrices[i].rectStaysRect()); | 96 SkASSERT(gMatrices[i].rectStaysRect()); |
| 94 } | 97 } |
| 95 } | 98 } |
| 96 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT( gMatrices)))]; | 99 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT( gMatrices)))]; |
| 97 } | 100 } |
| 98 | 101 |
| 99 const SkMatrix& TestMatrixInvertible(SkRandom* random) { return test_matrix(rand om, false); } | 102 const SkMatrix& TestMatrixInvertible(SkRandom* random) { return test_matrix(rand om, true, false); } |
| 103 const SkMatrix& TestMatrixPerspective(SkRandom* random) { return test_matrix(ran dom, false, true); } | |
| 100 | 104 |
| 101 const SkRect& TestRect(SkRandom* random) { | 105 const SkRect& TestRect(SkRandom* random) { |
| 102 static SkRect gRects[7]; | 106 static SkRect gRects[7]; |
| 103 static bool gOnce; | 107 static bool gOnce; |
| 104 if (!gOnce) { | 108 if (!gOnce) { |
| 105 gOnce = true; | 109 gOnce = true; |
| 106 gRects[0] = SkRect::MakeWH(1.f, 1.f); | 110 gRects[0] = SkRect::MakeWH(1.f, 1.f); |
| 107 gRects[1] = SkRect::MakeWH(1.0f, 256.0f); | 111 gRects[1] = SkRect::MakeWH(1.0f, 256.0f); |
| 108 gRects[2] = SkRect::MakeWH(256.0f, 1.0f); | 112 gRects[2] = SkRect::MakeWH(256.0f, 1.0f); |
| 109 gRects[3] = SkRect::MakeLargest(); | 113 gRects[3] = SkRect::MakeLargest(); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 info->fCount = fCount; | 284 info->fCount = fCount; |
| 281 info->fPhase = fPhase; | 285 info->fPhase = fPhase; |
| 282 } | 286 } |
| 283 return kDash_DashType; | 287 return kDash_DashType; |
| 284 } | 288 } |
| 285 | 289 |
| 286 | 290 |
| 287 } // namespace GrTest | 291 } // namespace GrTest |
| 288 | 292 |
| 289 #endif | 293 #endif |
| OLD | NEW |