Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: src/gpu/GrTestUtils.cpp

Issue 1108403005: Add batch unit tests for ovals (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrOvalRenderer.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkMatrix.h" 9 #include "SkMatrix.h"
10 #include "SkRRect.h"
10 11
11 #ifdef GR_TEST_UTILS 12 #ifdef GR_TEST_UTILS
12 13
13 namespace GrTest { 14 namespace GrTest {
14 const SkMatrix& TestMatrix(SkRandom* random) { 15 const SkMatrix& TestMatrix(SkRandom* random) {
15 static SkMatrix gMatrices[5]; 16 static SkMatrix gMatrices[5];
16 static bool gOnce; 17 static bool gOnce;
17 if (!gOnce) { 18 if (!gOnce) {
19 gOnce = true;
18 gMatrices[0].reset(); 20 gMatrices[0].reset();
19 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); 21 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100));
20 gMatrices[2].setRotate(SkIntToScalar(17)); 22 gMatrices[2].setRotate(SkIntToScalar(17));
21 gMatrices[3].setRotate(SkIntToScalar(185)); 23 gMatrices[3].setRotate(SkIntToScalar(185));
22 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); 24 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33));
23 gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf); 25 gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf);
24 gMatrices[4].setRotate(SkIntToScalar(215)); 26 gMatrices[4].setRotate(SkIntToScalar(215));
25 gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f); 27 gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f);
26 gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f); 28 gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f);
27 gOnce = true;
28 } 29 }
29 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT( gMatrices)))]; 30 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT( gMatrices)))];
30 } 31 }
31 32
32 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom* random) { 33 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom* random) {
33 static SkMatrix gMatrices[4]; 34 static SkMatrix gMatrices[5];
34 static bool gOnce; 35 static bool gOnce;
35 if (!gOnce) { 36 if (!gOnce) {
37 gOnce = true;
36 // identity 38 // identity
37 gMatrices[0].reset(); 39 gMatrices[0].reset();
38 // translation 40 // translation
39 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); 41 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100));
40 // scale 42 // scale
41 gMatrices[2].setScale(SkIntToScalar(17), SkIntToScalar(17)); 43 gMatrices[2].setScale(SkIntToScalar(17), SkIntToScalar(17));
42 // scale + translation 44 // scale + translation
43 gMatrices[3].setScale(SkIntToScalar(-17), SkIntToScalar(-17)); 45 gMatrices[3].setScale(SkIntToScalar(-17), SkIntToScalar(-17));
44 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); 46 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33));
45 // orthogonal basis vectors 47 // orthogonal basis vectors
46 gMatrices[4].reset(); 48 gMatrices[4].reset();
47 gMatrices[4].setScale(SkIntToScalar(-1), SkIntToScalar(-1)); 49 gMatrices[4].setScale(SkIntToScalar(-1), SkIntToScalar(-1));
48 gMatrices[4].setRotate(47); 50 gMatrices[4].setRotate(47);
49 gOnce = true;
50 51
51 for (size_t i = 0; i < SK_ARRAY_COUNT(gMatrices); i++) { 52 for (size_t i = 0; i < SK_ARRAY_COUNT(gMatrices); i++) {
52 SkASSERT(gMatrices[i].preservesRightAngles()); 53 SkASSERT(gMatrices[i].preservesRightAngles());
53 } 54 }
54 } 55 }
55 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT( gMatrices)))]; 56 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT( gMatrices)))];
56 } 57 }
57 58
59 const SkMatrix& TestMatrixRectStaysRect(SkRandom* random) {
60 static SkMatrix gMatrices[6];
61 static bool gOnce;
62 if (!gOnce) {
63 gOnce = true;
64 // identity
65 gMatrices[0].reset();
66 // translation
67 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100));
68 // scale
69 gMatrices[2].setScale(SkIntToScalar(17), SkIntToScalar(17));
70 // scale + translation
71 gMatrices[3].setScale(SkIntToScalar(-17), SkIntToScalar(-17));
72 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33));
73 // reflection
74 gMatrices[4].setScale(SkIntToScalar(-1), SkIntToScalar(-1));
75 // 90 degress rotation
76 gMatrices[5].setRotate(90);
77
78 for (size_t i = 0; i < SK_ARRAY_COUNT(gMatrices); i++) {
79 SkASSERT(gMatrices[i].rectStaysRect());
80 }
81 }
82 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT( gMatrices)))];
83 }
84
58 const SkRect& TestRect(SkRandom* random) { 85 const SkRect& TestRect(SkRandom* random) {
59 static SkRect gRects[1]; 86 static SkRect gRects[7];
60 static bool gOnce; 87 static bool gOnce;
61 if (!gOnce) { 88 if (!gOnce) {
89 gOnce = true;
62 gRects[0] = SkRect::MakeWH(1.f, 1.f); 90 gRects[0] = SkRect::MakeWH(1.f, 1.f);
63 gRects[1] = SkRect::MakeWH(1.0f, 256.0f); 91 gRects[1] = SkRect::MakeWH(1.0f, 256.0f);
64 gRects[2] = SkRect::MakeWH(256.0f, 1.0f); 92 gRects[2] = SkRect::MakeWH(256.0f, 1.0f);
65 gRects[4] = SkRect::MakeLargest(); 93 gRects[4] = SkRect::MakeLargest();
66 gRects[5] = SkRect::MakeLTRB(-65535.0f, -65535.0f, 65535.0f, 65535.0f); 94 gRects[5] = SkRect::MakeLTRB(-65535.0f, -65535.0f, 65535.0f, 65535.0f);
67 gRects[6] = SkRect::MakeLTRB(10.0f, 10.0f, -10.0f, -10.0f); 95 gRects[6] = SkRect::MakeLTRB(10.0f, 10.0f, -10.0f, -10.0f);
68 gOnce = true;
69 } 96 }
70 return gRects[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gRe cts)))]; 97 return gRects[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gRe cts)))];
71 } 98 }
99
100 const SkRRect& TestRRectSimple(SkRandom* random) {
101 static SkRRect gRRect[4];
102 static bool gOnce;
103 if (!gOnce) {
104 gOnce = true;
105 SkRect square = SkRect::MakeWH(10.f, 10.f);
106 SkRect rectangle = SkRect::MakeWH(10.f, 20.f);
107 // rect
108 gRRect[0].setRect(square);
109 // oval
110 gRRect[1].setOval(rectangle);
111 // true round rect with circular corners
112 gRRect[2].setRectXY(rectangle, 1.f, 1.f);
113 // true round rect with elliptical corners
114 gRRect[3].setRectXY(rectangle, 2.0f, 1.0f);
115
116 for (size_t i = 0; i < SK_ARRAY_COUNT(gRRect); i++) {
117 SkASSERT(gRRect[i].isSimple());
118 }
119 }
120 return gRRect[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gRR ect)))];
121 }
122
72 }; 123 };
73 124
74 #endif 125 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrOvalRenderer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698