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

Side by Side Diff: tests/DrawBitmapRectTest.cpp

Issue 1566943002: SkTreatAsSprite should take AA into account (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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
« src/core/SkMatrix.cpp ('K') | « src/core/SkMatrixUtils.h ('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 2011 Google Inc. 2 * Copyright 2011 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 "SkData.h" 10 #include "SkData.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 if (mask & SkMatrix::kPerspective_Mask) { 75 if (mask & SkMatrix::kPerspective_Mask) {
76 mat->setPerspX(rand.nextSScalar1()); 76 mat->setPerspX(rand.nextSScalar1());
77 mat->setPerspY(rand.nextSScalar1()); 77 mat->setPerspY(rand.nextSScalar1());
78 } 78 }
79 } 79 }
80 80
81 static void rand_size(SkISize* size, SkRandom& rand) { 81 static void rand_size(SkISize* size, SkRandom& rand) {
82 size->set(rand.nextU() & 0xFFFF, rand.nextU() & 0xFFFF); 82 size->set(rand.nextU() & 0xFFFF, rand.nextU() & 0xFFFF);
83 } 83 }
84 84
85 static bool treat_as_sprite(const SkMatrix& mat, const SkISize& size,
86 unsigned bits) {
87 return SkTreatAsSprite(mat, size.width(), size.height(), bits);
88 }
89
90 static void test_treatAsSprite(skiatest::Reporter* reporter) { 85 static void test_treatAsSprite(skiatest::Reporter* reporter) {
91 const unsigned bilerBits = kSkSubPixelBitsForBilerp;
92
93 SkMatrix mat; 86 SkMatrix mat;
94 SkISize size; 87 SkISize size;
95 SkRandom rand; 88 SkRandom rand;
96 89
97 // assert: translate-only no-filter can always be treated as sprite 90 SkPaint noaaPaint;
91 SkPaint aaPaint;
92 aaPaint.setAntiAlias(true);
93
94 // assert: translate-only no-aa can always be treated as sprite
98 for (int i = 0; i < 1000; ++i) { 95 for (int i = 0; i < 1000; ++i) {
99 rand_matrix(&mat, rand, SkMatrix::kTranslate_Mask); 96 rand_matrix(&mat, rand, SkMatrix::kTranslate_Mask);
100 for (int j = 0; j < 1000; ++j) { 97 for (int j = 0; j < 1000; ++j) {
101 rand_size(&size, rand); 98 rand_size(&size, rand);
102 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, 0)); 99 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, noaaPaint));
103 } 100 }
104 } 101 }
105 102
106 // assert: rotate/perspect is never treated as sprite 103 // assert: rotate/perspect is never treated as sprite
107 for (int i = 0; i < 1000; ++i) { 104 for (int i = 0; i < 1000; ++i) {
108 rand_matrix(&mat, rand, SkMatrix::kAffine_Mask | SkMatrix::kPerspective_ Mask); 105 rand_matrix(&mat, rand, SkMatrix::kAffine_Mask | SkMatrix::kPerspective_ Mask);
109 for (int j = 0; j < 1000; ++j) { 106 for (int j = 0; j < 1000; ++j) {
110 rand_size(&size, rand); 107 rand_size(&size, rand);
111 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, 0)); 108 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint));
112 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); 109 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, noaaPaint));
113 } 110 }
114 } 111 }
115 112
116 size.set(500, 600); 113 size.set(500, 600);
117 114
118 const SkScalar tooMuchSubpixel = 100.1f; 115 const SkScalar tooMuchSubpixel = 100.1f;
119 mat.setTranslate(tooMuchSubpixel, 0); 116 mat.setTranslate(tooMuchSubpixel, 0);
120 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); 117 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint));
121 mat.setTranslate(0, tooMuchSubpixel); 118 mat.setTranslate(0, tooMuchSubpixel);
122 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); 119 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint));
123 120
124 const SkScalar tinySubPixel = 100.02f; 121 const SkScalar tinySubPixel = 100.001f;
125 mat.setTranslate(tinySubPixel, 0); 122 mat.setTranslate(tinySubPixel, 0);
126 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits)); 123 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, aaPaint));
127 mat.setTranslate(0, tinySubPixel); 124 mat.setTranslate(0, tinySubPixel);
128 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits)); 125 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, aaPaint));
129 126
130 const SkScalar twoThirds = SK_Scalar1 * 2 / 3; 127 const SkScalar twoThirds = SK_Scalar1 * 2 / 3;
131 const SkScalar bigScale = (size.width() + twoThirds) / size.width(); 128 const SkScalar bigScale = (size.width() + twoThirds) / size.width();
132 mat.setScale(bigScale, bigScale); 129 mat.setScale(bigScale, bigScale);
133 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, false)); 130 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, noaaPaint));
134 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); 131 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint));
135 132
136 const SkScalar oneThird = SK_Scalar1 / 3; 133 const SkScalar oneThird = SK_Scalar1 / 3;
137 const SkScalar smallScale = (size.width() + oneThird) / size.width(); 134 const SkScalar smallScale = (size.width() + oneThird) / size.width();
138 mat.setScale(smallScale, smallScale); 135 mat.setScale(smallScale, smallScale);
139 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, false)); 136 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, noaaPaint));
140 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); 137 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint));
141 138
142 const SkScalar oneFortyth = SK_Scalar1 / 40; 139 const SkScalar tinyScale = (size.width() + 0.001f) / size.width();
143 const SkScalar tinyScale = (size.width() + oneFortyth) / size.width();
144 mat.setScale(tinyScale, tinyScale); 140 mat.setScale(tinyScale, tinyScale);
145 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, false)); 141 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, noaaPaint));
146 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits)); 142 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, aaPaint));
147 } 143 }
148 144
149 static void assert_ifDrawnTo(skiatest::Reporter* reporter, 145 static void assert_ifDrawnTo(skiatest::Reporter* reporter,
150 const SkBitmap& bm, bool shouldBeDrawn) { 146 const SkBitmap& bm, bool shouldBeDrawn) {
151 for (int y = 0; y < bm.height(); ++y) { 147 for (int y = 0; y < bm.height(); ++y) {
152 for (int x = 0; x < bm.width(); ++x) { 148 for (int x = 0; x < bm.width(); ++x) {
153 if (shouldBeDrawn) { 149 if (shouldBeDrawn) {
154 if (SK_ColorTRANSPARENT == *bm.getAddr32(x, y)) { 150 if (SK_ColorTRANSPARENT == *bm.getAddr32(x, y)) {
155 REPORTER_ASSERT(reporter, false); 151 REPORTER_ASSERT(reporter, false);
156 return; 152 return;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 303
308 // ensure that we draw nothing if srcR does not intersect the bitmap 304 // ensure that we draw nothing if srcR does not intersect the bitmap
309 REPORTER_ASSERT(reporter, check_for_all_zeros(dst)); 305 REPORTER_ASSERT(reporter, check_for_all_zeros(dst));
310 306
311 test_nan_antihair(); 307 test_nan_antihair();
312 test_giantrepeat_crbug118018(reporter); 308 test_giantrepeat_crbug118018(reporter);
313 309
314 test_treatAsSprite(reporter); 310 test_treatAsSprite(reporter);
315 test_faulty_pixelref(reporter); 311 test_faulty_pixelref(reporter);
316 } 312 }
OLDNEW
« src/core/SkMatrix.cpp ('K') | « src/core/SkMatrixUtils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698