aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2015-04-14 08:19:01 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-04-14 08:19:01 -0700
commitf5ac972207228e288ff084ff4a94dd7f89c4ba72 (patch)
tree38885afad1258ab842564e0b5874b13a8b68a4b7
parent86e5ab633865be3336ca266bd60131832cd8ab28 (diff)
Add GM to exercise high quality anisotropic scaling
High quality anisotropic is an interesting edge case for the gpu backend. For scales that are both minimizing and maximizing Ganesh falls back to MipMaps which can turn out too blurry. BUG=472864 Review URL: https://codereview.chromium.org/1058133003
-rw-r--r--gm/anisotropic.cpp114
-rw-r--r--gyp/gmslides.gypi1
2 files changed, 115 insertions, 0 deletions
diff --git a/gm/anisotropic.cpp b/gm/anisotropic.cpp
new file mode 100644
index 0000000000..a004d750e1
--- /dev/null
+++ b/gm/anisotropic.cpp
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+
+namespace skiagm {
+
+// This GM exercises HighQuality anisotropic filtering.
+class AnisotropicGM : public GM {
+public:
+ AnisotropicGM() : fFilterQuality(kHigh_SkFilterQuality) {
+ this->setBGColor(0xFFCCCCCC);
+ }
+
+protected:
+
+ SkString onShortName() override { return SkString("anisotropic_hq"); }
+
+ SkISize onISize() override {
+ return SkISize::Make(2*kImageSize + 3*kSpacer,
+ kNumVertImages*kImageSize + (kNumVertImages+1)*kSpacer);
+ }
+
+ // Create an image consisting of lines radiating from its center
+ void onOnceBeforeDraw() override {
+ static const int kNumLines = 100;
+ static const SkScalar kAngleStep = 360.0f / kNumLines;
+ static const int kInnerOffset = 10;
+
+ fBM.allocN32Pixels(kImageSize, kImageSize, true);
+
+ SkCanvas canvas(fBM);
+
+ canvas.clear(SK_ColorWHITE);
+
+ SkPaint p;
+ p.setAntiAlias(true);
+
+ SkScalar angle = 0.0f, sin, cos;
+
+ canvas.translate(kImageSize/2.0f, kImageSize/2.0f);
+ for (int i = 0; i < kNumLines; ++i, angle += kAngleStep) {
+ sin = SkScalarSinCos(angle, &cos);
+ canvas.drawLine(cos * kInnerOffset, sin * kInnerOffset,
+ cos * kImageSize/2, sin * kImageSize/2, p);
+ }
+ }
+
+ void draw(SkCanvas* canvas, int x, int y, int xSize, int ySize) {
+ SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
+ SkIntToScalar(xSize), SkIntToScalar(ySize));
+ SkPaint p;
+ p.setFilterQuality(fFilterQuality);
+ canvas->drawBitmapRect(fBM, r, &p);
+ }
+
+ void onDraw(SkCanvas* canvas) override {
+ SkScalar gScales[] = { 0.9f, 0.8f, 0.75f, 0.6f, 0.5f, 0.4f, 0.25f, 0.2f, 0.1f };
+
+ SkASSERT(kNumVertImages-1 == (int)SK_ARRAY_COUNT(gScales)/2);
+
+ // Minimize vertically
+ for (int i = 0; i < (int)SK_ARRAY_COUNT(gScales); ++i) {
+ int height = SkScalarFloorToInt(fBM.height() * gScales[i]);
+
+ int yOff;
+ if (i <= (int)SK_ARRAY_COUNT(gScales)/2) {
+ yOff = kSpacer + i * (fBM.height() + kSpacer);
+ } else {
+ // Position the more highly squashed images with their less squashed counterparts
+ yOff = (SK_ARRAY_COUNT(gScales) - i) * (fBM.height() + kSpacer) - height;
+ }
+
+ this->draw(canvas, kSpacer, yOff, fBM.width(), height);
+ }
+
+ // Minimize horizontally
+ for (int i = 0; i < (int)SK_ARRAY_COUNT(gScales); ++i) {
+ int width = SkScalarFloorToInt(fBM.width() * gScales[i]);
+
+ int xOff, yOff;
+ if (i <= (int)SK_ARRAY_COUNT(gScales)/2) {
+ xOff = fBM.width() + 2*kSpacer;
+ yOff = kSpacer + i * (fBM.height() + kSpacer);
+ } else {
+ // Position the more highly squashed images with their less squashed counterparts
+ xOff = fBM.width() + 2*kSpacer + fBM.width() - width;
+ yOff = kSpacer + (SK_ARRAY_COUNT(gScales) - i - 1) * (fBM.height() + kSpacer);
+ }
+
+ this->draw(canvas, xOff, yOff, width, fBM.height());
+ }
+ }
+
+private:
+ static const int kImageSize = 256;
+ static const int kSpacer = 10;
+ static const int kNumVertImages = 5;
+
+ SkBitmap fBM;
+ SkFilterQuality fFilterQuality;
+
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+DEF_GM( return SkNEW(AnisotropicGM); )
+
+}
diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi
index d2db10690b..02297c32b3 100644
--- a/gyp/gmslides.gypi
+++ b/gyp/gmslides.gypi
@@ -22,6 +22,7 @@
'../gm/addarc.cpp',
'../gm/all_bitmap_configs.cpp',
'../gm/alphagradients.cpp',
+ '../gm/anisotropic.cpp',
'../gm/arcofzorro.cpp',
'../gm/arithmode.cpp',
'../gm/astcbitmap.cpp',