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

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: SkLeftShift 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
« no previous file with comments | « 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 86
93 SkMatrix mat; 87 SkMatrix mat;
94 SkISize size; 88 SkISize size;
95 SkRandom rand; 89 SkRandom rand;
96 90
97 // assert: translate-only no-filter can always be treated as sprite 91 SkPaint noaaPaint;
92 SkPaint aaPaint;
93 aaPaint.setAntiAlias(true);
94
95 // assert: translate-only no-aa can always be treated as sprite
98 for (int i = 0; i < 1000; ++i) { 96 for (int i = 0; i < 1000; ++i) {
99 rand_matrix(&mat, rand, SkMatrix::kTranslate_Mask); 97 rand_matrix(&mat, rand, SkMatrix::kTranslate_Mask);
100 for (int j = 0; j < 1000; ++j) { 98 for (int j = 0; j < 1000; ++j) {
101 rand_size(&size, rand); 99 rand_size(&size, rand);
102 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, 0)); 100 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, noaaPaint));
103 } 101 }
104 } 102 }
105 103
106 // assert: rotate/perspect is never treated as sprite 104 // assert: rotate/perspect is never treated as sprite
107 for (int i = 0; i < 1000; ++i) { 105 for (int i = 0; i < 1000; ++i) {
108 rand_matrix(&mat, rand, SkMatrix::kAffine_Mask | SkMatrix::kPerspective_ Mask); 106 rand_matrix(&mat, rand, SkMatrix::kAffine_Mask | SkMatrix::kPerspective_ Mask);
109 for (int j = 0; j < 1000; ++j) { 107 for (int j = 0; j < 1000; ++j) {
110 rand_size(&size, rand); 108 rand_size(&size, rand);
111 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, 0)); 109 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, noaaPaint));
112 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); 110 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint));
113 } 111 }
114 } 112 }
115 113
116 size.set(500, 600); 114 size.set(500, 600);
117 115
118 const SkScalar tooMuchSubpixel = 100.1f; 116 const SkScalar tooMuchSubpixel = 100.1f;
119 mat.setTranslate(tooMuchSubpixel, 0); 117 mat.setTranslate(tooMuchSubpixel, 0);
120 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); 118 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint));
121 mat.setTranslate(0, tooMuchSubpixel); 119 mat.setTranslate(0, tooMuchSubpixel);
122 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); 120 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint));
123 121
124 const SkScalar tinySubPixel = 100.02f; 122 const SkScalar tinySubPixel = 100.02f;
125 mat.setTranslate(tinySubPixel, 0); 123 mat.setTranslate(tinySubPixel, 0);
126 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits)); 124 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, aaPaint));
127 mat.setTranslate(0, tinySubPixel); 125 mat.setTranslate(0, tinySubPixel);
128 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits)); 126 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, aaPaint));
129 127
130 const SkScalar twoThirds = SK_Scalar1 * 2 / 3; 128 const SkScalar twoThirds = SK_Scalar1 * 2 / 3;
131 const SkScalar bigScale = (size.width() + twoThirds) / size.width(); 129 const SkScalar bigScale = (size.width() + twoThirds) / size.width();
132 mat.setScale(bigScale, bigScale); 130 mat.setScale(bigScale, bigScale);
133 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, false)); 131 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, noaaPaint));
134 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); 132 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint));
135 133
136 const SkScalar oneThird = SK_Scalar1 / 3; 134 const SkScalar oneThird = SK_Scalar1 / 3;
137 const SkScalar smallScale = (size.width() + oneThird) / size.width(); 135 const SkScalar smallScale = (size.width() + oneThird) / size.width();
138 mat.setScale(smallScale, smallScale); 136 mat.setScale(smallScale, smallScale);
139 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, false)); 137 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, noaaPaint));
140 REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); 138 REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint));
141 139
142 const SkScalar oneFortyth = SK_Scalar1 / 40; 140 const SkScalar oneFortyth = SK_Scalar1 / 40;
143 const SkScalar tinyScale = (size.width() + oneFortyth) / size.width(); 141 const SkScalar tinyScale = (size.width() + oneFortyth) / size.width();
144 mat.setScale(tinyScale, tinyScale); 142 mat.setScale(tinyScale, tinyScale);
145 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, false)); 143 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, noaaPaint));
146 REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits)); 144 REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, aaPaint));
147 } 145 }
148 146
149 static void assert_ifDrawnTo(skiatest::Reporter* reporter, 147 static void assert_ifDrawnTo(skiatest::Reporter* reporter,
150 const SkBitmap& bm, bool shouldBeDrawn) { 148 const SkBitmap& bm, bool shouldBeDrawn) {
151 for (int y = 0; y < bm.height(); ++y) { 149 for (int y = 0; y < bm.height(); ++y) {
152 for (int x = 0; x < bm.width(); ++x) { 150 for (int x = 0; x < bm.width(); ++x) {
153 if (shouldBeDrawn) { 151 if (shouldBeDrawn) {
154 if (SK_ColorTRANSPARENT == *bm.getAddr32(x, y)) { 152 if (SK_ColorTRANSPARENT == *bm.getAddr32(x, y)) {
155 REPORTER_ASSERT(reporter, false); 153 REPORTER_ASSERT(reporter, false);
156 return; 154 return;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 305
308 // ensure that we draw nothing if srcR does not intersect the bitmap 306 // ensure that we draw nothing if srcR does not intersect the bitmap
309 REPORTER_ASSERT(reporter, check_for_all_zeros(dst)); 307 REPORTER_ASSERT(reporter, check_for_all_zeros(dst));
310 308
311 test_nan_antihair(); 309 test_nan_antihair();
312 test_giantrepeat_crbug118018(reporter); 310 test_giantrepeat_crbug118018(reporter);
313 311
314 test_treatAsSprite(reporter); 312 test_treatAsSprite(reporter);
315 test_faulty_pixelref(reporter); 313 test_faulty_pixelref(reporter);
316 } 314 }
OLDNEW
« no previous file with comments | « src/core/SkMatrixUtils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698