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

Unified Diff: gm/mipmap.cpp

Issue 2087933002: Add new GM that exercises Gray 8 mipmapping and sRGB-ness (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/mipmap.cpp
diff --git a/gm/mipmap.cpp b/gm/mipmap.cpp
index 7a867d4225bde63fc458c18423faad3a40e9e8d3..baf5527556ea64ee7b3f4429a46e8989dcfbba29 100644
--- a/gm/mipmap.cpp
+++ b/gm/mipmap.cpp
@@ -97,3 +97,53 @@ DEF_SIMPLE_GM(mipmap_srgb, canvas, 260, 230) {
show_mips(canvas, simg.get());
}
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+// create a gradient image computed raw, so we can wrap it as a linear or srgb image
+static sk_sp<SkImage> make_g8_gradient(sk_sp<SkColorSpace> cs) {
+ const int N = 100;
+ SkImageInfo info = SkImageInfo::Make(N, N, kGray_8_SkColorType, kOpaque_SkAlphaType, cs);
+ SkBitmap bm;
+ bm.allocPixels(info);
+
+ for (int y = 0; y < N; ++y) {
+ for (int x = 0; x < N; ++x) {
+ *bm.getAddr8(x, y) = static_cast<uint8_t>(255.0f * ((x + y) / (2.0f * (N - 1))));
+ }
+ }
+ bm.setImmutable();
+ return SkImage::MakeFromBitmap(bm);
+}
+
+static void show_mips_only(SkCanvas* canvas, SkImage* img) {
+ SkPaint paint;
+ paint.setFilterQuality(kMedium_SkFilterQuality);
+
+ // Want to ensure we never draw fractional pixels, so we use an IRect
+ SkIRect dst = SkIRect::MakeWH(img->width() / 2, img->height() / 2);
+ while (dst.width() > 5) {
+ canvas->drawImageRect(img, SkRect::Make(dst), &paint);
+ dst.offset(dst.width() + 10, 0);
+ dst.fRight = dst.fLeft + dst.width() / 2;
+ dst.fBottom = dst.fTop + dst.height() / 2;
+ }
+}
+
+/*
+ * Ensure that in L32 drawing mode, both images/mips look the same as each other, and
+ * their mips are darker than the original (since the mips should ignore the gamma in L32).
+ *
+ * Ensure that in S32 drawing mode, all images/mips look the same, and look correct (i.e.
+ * the mip levels match the original in brightness).
+ *
+ * This test also verifies handling of Gray_8 data in Ganesh, which is not done natively.
+ */
+DEF_SIMPLE_GM(mipmap_gray8_srgb, canvas, 260, 230) {
+ sk_sp<SkImage> limg = make_g8_gradient(nullptr);
+ sk_sp<SkImage> simg = make_g8_gradient(SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named));
+
+ canvas->translate(10, 10);
+ show_mips_only(canvas, limg.get());
+ canvas->translate(0, limg->height() + 10.0f);
+ show_mips_only(canvas, simg.get());
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698