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

Side by Side Diff: tests/MatrixTest.cpp

Issue 105353002: Do not use GrBicubic effect when downscaling. Also, don't use glTexStorage as it interferes with de… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: address comments Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/GrGpuGL.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "Test.h" 8 #include "Test.h"
9 #include "SkMath.h" 9 #include "SkMath.h"
10 #include "SkMatrix.h" 10 #include "SkMatrix.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 size_t size3 = m2.readFromMemory(buffer, kBufferSize); 123 size_t size3 = m2.readFromMemory(buffer, kBufferSize);
124 REPORTER_ASSERT(reporter, size1 == size3); 124 REPORTER_ASSERT(reporter, size1 == size3);
125 REPORTER_ASSERT(reporter, are_equal(reporter, m, m2)); 125 REPORTER_ASSERT(reporter, are_equal(reporter, m, m2));
126 126
127 char buffer2[kBufferSize]; 127 char buffer2[kBufferSize];
128 size3 = m2.writeToMemory(buffer2); 128 size3 = m2.writeToMemory(buffer2);
129 REPORTER_ASSERT(reporter, size1 == size3); 129 REPORTER_ASSERT(reporter, size1 == size3);
130 REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0); 130 REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0);
131 } 131 }
132 132
133 static void test_matrix_max_stretch(skiatest::Reporter* reporter) { 133 static void test_matrix_min_max_stretch(skiatest::Reporter* reporter) {
134 SkMatrix identity; 134 SkMatrix identity;
135 identity.reset(); 135 identity.reset();
136 REPORTER_ASSERT(reporter, SK_Scalar1 == identity.getMinStretch());
136 REPORTER_ASSERT(reporter, SK_Scalar1 == identity.getMaxStretch()); 137 REPORTER_ASSERT(reporter, SK_Scalar1 == identity.getMaxStretch());
137 138
138 SkMatrix scale; 139 SkMatrix scale;
139 scale.setScale(SK_Scalar1 * 2, SK_Scalar1 * 4); 140 scale.setScale(SK_Scalar1 * 2, SK_Scalar1 * 4);
141 REPORTER_ASSERT(reporter, SK_Scalar1 * 2 == scale.getMinStretch());
140 REPORTER_ASSERT(reporter, SK_Scalar1 * 4 == scale.getMaxStretch()); 142 REPORTER_ASSERT(reporter, SK_Scalar1 * 4 == scale.getMaxStretch());
141 143
142 SkMatrix rot90Scale; 144 SkMatrix rot90Scale;
143 rot90Scale.setRotate(90 * SK_Scalar1); 145 rot90Scale.setRotate(90 * SK_Scalar1);
144 rot90Scale.postScale(SK_Scalar1 / 4, SK_Scalar1 / 2); 146 rot90Scale.postScale(SK_Scalar1 / 4, SK_Scalar1 / 2);
147 REPORTER_ASSERT(reporter, SK_Scalar1 / 4 == rot90Scale.getMinStretch());
145 REPORTER_ASSERT(reporter, SK_Scalar1 / 2 == rot90Scale.getMaxStretch()); 148 REPORTER_ASSERT(reporter, SK_Scalar1 / 2 == rot90Scale.getMaxStretch());
146 149
147 SkMatrix rotate; 150 SkMatrix rotate;
148 rotate.setRotate(128 * SK_Scalar1); 151 rotate.setRotate(128 * SK_Scalar1);
149 REPORTER_ASSERT(reporter, SkScalarAbs(SK_Scalar1 - rotate.getMaxStretch()) < = SK_ScalarNearlyZero); 152 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, rotate.getMinStret ch() ,SK_ScalarNearlyZero));
153 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, rotate.getMaxStret ch(), SK_ScalarNearlyZero));
150 154
151 SkMatrix translate; 155 SkMatrix translate;
152 translate.setTranslate(10 * SK_Scalar1, -5 * SK_Scalar1); 156 translate.setTranslate(10 * SK_Scalar1, -5 * SK_Scalar1);
157 REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMinStretch());
153 REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMaxStretch()); 158 REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMaxStretch());
154 159
155 SkMatrix perspX; 160 SkMatrix perspX;
156 perspX.reset(); 161 perspX.reset();
157 perspX.setPerspX(SkScalarToPersp(SK_Scalar1 / 1000)); 162 perspX.setPerspX(SkScalarToPersp(SK_Scalar1 / 1000));
163 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMinStretch());
158 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMaxStretch()); 164 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMaxStretch());
159 165
160 SkMatrix perspY; 166 SkMatrix perspY;
161 perspY.reset(); 167 perspY.reset();
162 perspY.setPerspX(SkScalarToPersp(-SK_Scalar1 / 500)); 168 perspY.setPerspY(SkScalarToPersp(-SK_Scalar1 / 500));
169 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMinStretch());
163 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMaxStretch()); 170 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMaxStretch());
164 171
165 SkMatrix baseMats[] = {scale, rot90Scale, rotate, 172 SkMatrix baseMats[] = {scale, rot90Scale, rotate,
166 translate, perspX, perspY}; 173 translate, perspX, perspY};
167 SkMatrix mats[2*SK_ARRAY_COUNT(baseMats)]; 174 SkMatrix mats[2*SK_ARRAY_COUNT(baseMats)];
168 for (size_t i = 0; i < SK_ARRAY_COUNT(baseMats); ++i) { 175 for (size_t i = 0; i < SK_ARRAY_COUNT(baseMats); ++i) {
169 mats[i] = baseMats[i]; 176 mats[i] = baseMats[i];
170 bool invertable = mats[i].invert(&mats[i + SK_ARRAY_COUNT(baseMats)]); 177 bool invertable = mats[i].invert(&mats[i + SK_ARRAY_COUNT(baseMats)]);
171 REPORTER_ASSERT(reporter, invertable); 178 REPORTER_ASSERT(reporter, invertable);
172 } 179 }
173 SkRandom rand; 180 SkRandom rand;
174 for (int m = 0; m < 1000; ++m) { 181 for (int m = 0; m < 1000; ++m) {
175 SkMatrix mat; 182 SkMatrix mat;
176 mat.reset(); 183 mat.reset();
177 for (int i = 0; i < 4; ++i) { 184 for (int i = 0; i < 4; ++i) {
178 int x = rand.nextU() % SK_ARRAY_COUNT(mats); 185 int x = rand.nextU() % SK_ARRAY_COUNT(mats);
179 mat.postConcat(mats[x]); 186 mat.postConcat(mats[x]);
180 } 187 }
181 SkScalar stretch = mat.getMaxStretch();
182 188
183 if ((stretch < 0) != mat.hasPerspective()) { 189 SkScalar minStretch = mat.getMinStretch();
184 stretch = mat.getMaxStretch(); 190 SkScalar maxStretch = mat.getMaxStretch();
185 } 191 REPORTER_ASSERT(reporter, (minStretch < 0) == (maxStretch < 0));
186 192 REPORTER_ASSERT(reporter, (maxStretch < 0) == mat.hasPerspective());
187 REPORTER_ASSERT(reporter, (stretch < 0) == mat.hasPerspective());
188 193
189 if (mat.hasPerspective()) { 194 if (mat.hasPerspective()) {
190 m -= 1; // try another non-persp matrix 195 m -= 1; // try another non-persp matrix
191 continue; 196 continue;
192 } 197 }
193 198
194 // test a bunch of vectors. None should be scaled by more than stretch 199 // test a bunch of vectors. All should be scaled by between minStretch a nd maxStretch
195 // (modulo some error) and we should find a vector that is scaled by 200 // (modulo some error) and we should find a vector that is scaled by alm ost each.
196 // almost stretch. 201 static const SkScalar gVectorStretchTol = (105 * SK_Scalar1) / 100;
197 static const SkScalar gStretchTol = (105 * SK_Scalar1) / 100; 202 static const SkScalar gClosestStretchTol = (97 * SK_Scalar1) / 100;
198 static const SkScalar gMaxStretchTol = (97 * SK_Scalar1) / 100; 203 SkScalar max = 0, min = SK_ScalarMax;
199 SkScalar max = 0;
200 SkVector vectors[1000]; 204 SkVector vectors[1000];
201 for (size_t i = 0; i < SK_ARRAY_COUNT(vectors); ++i) { 205 for (size_t i = 0; i < SK_ARRAY_COUNT(vectors); ++i) {
202 vectors[i].fX = rand.nextSScalar1(); 206 vectors[i].fX = rand.nextSScalar1();
203 vectors[i].fY = rand.nextSScalar1(); 207 vectors[i].fY = rand.nextSScalar1();
204 if (!vectors[i].normalize()) { 208 if (!vectors[i].normalize()) {
205 i -= 1; 209 i -= 1;
206 continue; 210 continue;
207 } 211 }
208 } 212 }
209 mat.mapVectors(vectors, SK_ARRAY_COUNT(vectors)); 213 mat.mapVectors(vectors, SK_ARRAY_COUNT(vectors));
210 for (size_t i = 0; i < SK_ARRAY_COUNT(vectors); ++i) { 214 for (size_t i = 0; i < SK_ARRAY_COUNT(vectors); ++i) {
211 SkScalar d = vectors[i].length(); 215 SkScalar d = vectors[i].length();
212 REPORTER_ASSERT(reporter, SkScalarDiv(d, stretch) < gStretchTol); 216 REPORTER_ASSERT(reporter, SkScalarDiv(d, maxStretch) < gVectorStretc hTol);
217 REPORTER_ASSERT(reporter, SkScalarDiv(minStretch, d) < gVectorStretc hTol);
213 if (max < d) { 218 if (max < d) {
214 max = d; 219 max = d;
215 } 220 }
221 if (min > d) {
222 min = d;
223 }
216 } 224 }
217 REPORTER_ASSERT(reporter, SkScalarDiv(max, stretch) >= gMaxStretchTol); 225 REPORTER_ASSERT(reporter, SkScalarDiv(max, maxStretch) >= gClosestStretc hTol);
226 REPORTER_ASSERT(reporter, SkScalarDiv(minStretch, min) >= gClosestStretc hTol);
218 } 227 }
219 } 228 }
220 229
221 static void test_matrix_is_similarity(skiatest::Reporter* reporter) { 230 static void test_matrix_is_similarity(skiatest::Reporter* reporter) {
222 SkMatrix mat; 231 SkMatrix mat;
223 232
224 // identity 233 // identity
225 mat.setIdentity(); 234 mat.setIdentity();
226 REPORTER_ASSERT(reporter, mat.isSimilarity()); 235 REPORTER_ASSERT(reporter, mat.isSimilarity());
227 236
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 mat.reset(); 799 mat.reset();
791 mat.set(SkMatrix::kMSkewX, SK_ScalarNaN); 800 mat.set(SkMatrix::kMSkewX, SK_ScalarNaN);
792 mat2.set(SkMatrix::kMSkewX, SK_ScalarNaN); 801 mat2.set(SkMatrix::kMSkewX, SK_ScalarNaN);
793 // fixed pt doesn't have the property that NaN does not equal itself. 802 // fixed pt doesn't have the property that NaN does not equal itself.
794 #ifdef SK_SCALAR_IS_FIXED 803 #ifdef SK_SCALAR_IS_FIXED
795 REPORTER_ASSERT(reporter, are_equal(reporter, mat, mat2)); 804 REPORTER_ASSERT(reporter, are_equal(reporter, mat, mat2));
796 #else 805 #else
797 REPORTER_ASSERT(reporter, !are_equal(reporter, mat, mat2)); 806 REPORTER_ASSERT(reporter, !are_equal(reporter, mat, mat2));
798 #endif 807 #endif
799 808
800 test_matrix_max_stretch(reporter); 809 test_matrix_min_max_stretch(reporter);
801 test_matrix_is_similarity(reporter); 810 test_matrix_is_similarity(reporter);
802 test_matrix_recttorect(reporter); 811 test_matrix_recttorect(reporter);
803 test_matrix_decomposition(reporter); 812 test_matrix_decomposition(reporter);
804 test_matrix_homogeneous(reporter); 813 test_matrix_homogeneous(reporter);
805 } 814 }
806 815
807 #include "TestClassDef.h" 816 #include "TestClassDef.h"
808 DEFINE_TESTCLASS("Matrix", MatrixTestClass, TestMatrix) 817 DEFINE_TESTCLASS("Matrix", MatrixTestClass, TestMatrix)
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGpuGL.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698