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

Unified Diff: tests/DrawBitmapRectTest.cpp

Issue 306013010: allow subpixel positioning w/ bitmap filtering Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkMatrixUtils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/DrawBitmapRectTest.cpp
diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp
index 6dca98b527207a086178b07199d6cd839e8c6dc8..23878d30201e83f010f5d57120d5035ca1e3ed70 100644
--- a/tests/DrawBitmapRectTest.cpp
+++ b/tests/DrawBitmapRectTest.cpp
@@ -94,6 +94,7 @@ static bool treat_as_sprite(const SkMatrix& mat, const SkISize& size,
static void test_treatAsSprite(skiatest::Reporter* reporter) {
const unsigned bilerBits = kSkSubPixelBitsForBilerp;
+ const unsigned nearestNeighborBits = 0;
SkMatrix mat;
SkISize size;
@@ -135,19 +136,19 @@ static void test_treatAsSprite(skiatest::Reporter* reporter) {
const SkScalar twoThirds = SK_Scalar1 * 2 / 3;
const SkScalar bigScale = SkScalarDiv(size.width() + twoThirds, size.width());
mat.setScale(bigScale, bigScale);
- REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, false));
+ REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, nearestNeighborBits));
REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits));
const SkScalar oneThird = SK_Scalar1 / 3;
const SkScalar smallScale = SkScalarDiv(size.width() + oneThird, size.width());
mat.setScale(smallScale, smallScale);
- REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, false));
+ REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, nearestNeighborBits));
REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits));
const SkScalar oneFortyth = SK_Scalar1 / 40;
const SkScalar tinyScale = SkScalarDiv(size.width() + oneFortyth, size.width());
mat.setScale(tinyScale, tinyScale);
- REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, false));
+ REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, nearestNeighborBits));
REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits));
}
@@ -287,6 +288,44 @@ static bool check_for_all_zeros(const SkBitmap& bm) {
return true;
}
+static void test_on_grid(skiatest::Reporter* reporter, int w, int h, const SkRect& r,
+ SkScalar delta, int bits, bool expected) {
+ REPORTER_ASSERT(reporter, SkRectIsOnGrid(w, h, r.makeInset(delta, 0), bits) == expected);
+ REPORTER_ASSERT(reporter, SkRectIsOnGrid(w, h, r.makeInset(-delta, 0), bits) == expected);
+ REPORTER_ASSERT(reporter, SkRectIsOnGrid(w, h, r.makeInset(0, delta), bits) == expected);
+ REPORTER_ASSERT(reporter, SkRectIsOnGrid(w, h, r.makeInset(0, -delta), bits) == expected);
+
+ if (0 == bits) {
+ expected = true;
+ }
+ REPORTER_ASSERT(reporter, SkRectIsOnGrid(w, h, r.makeOffset(delta, 0), bits) == expected);
+ REPORTER_ASSERT(reporter, SkRectIsOnGrid(w, h, r.makeOffset(-delta, 0), bits) == expected);
+ REPORTER_ASSERT(reporter, SkRectIsOnGrid(w, h, r.makeOffset(0, delta), bits) == expected);
+ REPORTER_ASSERT(reporter, SkRectIsOnGrid(w, h, r.makeOffset(0, -delta), bits) == expected);
+
+}
+
+static void test_on_grid(skiatest::Reporter* reporter, int bits, SkScalar cutOff) {
+ const int width = 100;
+ const int height = 100;
+ const SkScalar eps = 0.00001f;
+
+ SkRect r;
+ r.setWH(SkIntToScalar(width), SkIntToScalar(height));
+ REPORTER_ASSERT(reporter, SkRectIsOnGrid(width, height, r, bits));
+
+ test_on_grid(reporter, width, height, r, cutOff - eps, bits, true);
+ test_on_grid(reporter, width, height, r, cutOff + eps, bits, false);
+}
+
+static void test_on_grid(skiatest::Reporter* reporter) {
+ for (int bits = 0; bits <= 8; ++bits) {
+ // The cutoff for being on the grid is 0.5 * (1/grid_size)
+ const SkScalar cutOff = SkScalarInvert(1 << (bits + 1));
+ test_on_grid(reporter, bits, cutOff);
+ }
+}
+
static const int gWidth = 256;
static const int gHeight = 256;
@@ -296,6 +335,8 @@ static void create(SkBitmap* bm, SkColor color) {
}
DEF_TEST(DrawBitmapRect, reporter) {
+ test_on_grid(reporter);
+
SkBitmap src, dst;
create(&src, 0xFFFFFFFF);
« 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