Skia Filter Quality and Scaling Metrics
authorericrk <ericrk@chromium.org>
Mon, 18 Apr 2016 16:14:00 +0000 (09:14 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 18 Apr 2016 16:14:00 +0000 (09:14 -0700)
Adds histogram metrics to log the filter quality and scale factor of
each image draw. To make the data easier to consume, this is broken
down into a number of individual histograms:
- Filter quality across all draw calls
- Scale amount across all draw calls
- Scale amount per filter quality (4 histograms total)

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1686203002

Committed: https://skia.googlesource.com/skia/+/f57b3a6e4a002caf01378832cbd756c6c163a783

Review URL: https://codereview.chromium.org/1686203002

include/core/SkDevice.h
include/core/SkFilterQuality.h
include/core/SkPostConfig.h
src/core/SkBitmapDevice.cpp
src/core/SkDevice.cpp
src/gpu/SkGpuDevice.cpp
src/gpu/SkGpuDevice_drawTexture.cpp

index c15aecc..3a6d6ea 100644 (file)
@@ -387,6 +387,9 @@ protected:
     virtual void drawSpriteWithFilter(const SkDraw&, const SkBitmap&,
                                       int x, int y, const SkPaint&);
 
+    // A helper function used by derived classes to log the scale factor of a bitmap or image draw.
+    static void LogDrawScaleFactor(const SkMatrix&, SkFilterQuality);
+
 private:
     friend class SkCanvas;
     friend struct DeviceCM; //for setMatrixClip
index db0597e..54fae51 100644 (file)
@@ -18,7 +18,9 @@ enum SkFilterQuality {
     kNone_SkFilterQuality,      //!< fastest but lowest quality, typically nearest-neighbor
     kLow_SkFilterQuality,       //!< typically bilerp
     kMedium_SkFilterQuality,    //!< typically bilerp + mipmaps for down-scaling
-    kHigh_SkFilterQuality       //!< slowest but highest quality, typically bicubic or better
+    kHigh_SkFilterQuality,      //!< slowest but highest quality, typically bicubic or better
+
+    kLast_SkFilterQuality = kHigh_SkFilterQuality
 };
 
 #endif
index a7fbba7..c3255b8 100644 (file)
 
 //////////////////////////////////////////////////////////////////////
 
+#if defined(SK_HISTOGRAM_ENUMERATION) && defined(SK_HISTOGRAM_BOOLEAN)
+#  define SK_HISTOGRAMS_ENABLED 1
+#else
+#  define SK_HISTOGRAMS_ENABLED 0
+#endif
+
 #ifndef SK_HISTOGRAM_BOOLEAN
 #  define SK_HISTOGRAM_BOOLEAN(name, value)
 #endif
index c8ac8d2..8a517a6 100644 (file)
@@ -237,6 +237,7 @@ void SkBitmapDevice::drawPath(const SkDraw& draw, const SkPath& path,
 
 void SkBitmapDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap,
                                 const SkMatrix& matrix, const SkPaint& paint) {
+    LogDrawScaleFactor(SkMatrix::Concat(*draw.fMatrix, matrix), paint.getFilterQuality());
     draw.drawBitmap(bitmap, matrix, nullptr, paint);
 }
 
@@ -257,6 +258,8 @@ void SkBitmapDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
     }
     matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit);
 
+    LogDrawScaleFactor(SkMatrix::Concat(*draw.fMatrix, matrix), paint.getFilterQuality());
+
     const SkRect* dstPtr = &dst;
     const SkBitmap* bitmapPtr = &bitmap;
 
index 1b22856..da120f0 100644 (file)
@@ -459,3 +459,58 @@ uint32_t SkBaseDevice::filterTextFlags(const SkPaint& paint) const {
 sk_sp<SkSurface> SkBaseDevice::makeSurface(SkImageInfo const&, SkSurfaceProps const&) {
     return nullptr;
 }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+
+void SkBaseDevice::LogDrawScaleFactor(const SkMatrix& matrix, SkFilterQuality filterQuality) {
+#if SK_HISTOGRAMS_ENABLED
+    enum ScaleFactor {
+        kUpscale_ScaleFactor,
+        kNoScale_ScaleFactor,
+        kDownscale_ScaleFactor,
+        kLargeDownscale_ScaleFactor,
+
+        kLast_ScaleFactor = kLargeDownscale_ScaleFactor
+    };
+
+    float rawScaleFactor = matrix.getMinScale();
+
+    ScaleFactor scaleFactor;
+    if (rawScaleFactor < 0.5f) {
+        scaleFactor = kLargeDownscale_ScaleFactor;
+    } else if (rawScaleFactor < 1.0f) {
+        scaleFactor = kDownscale_ScaleFactor;
+    } else if (rawScaleFactor > 1.0f) {
+        scaleFactor = kUpscale_ScaleFactor;
+    } else {
+        scaleFactor = kNoScale_ScaleFactor;
+    }
+
+    switch (filterQuality) {
+        case kNone_SkFilterQuality:
+            SK_HISTOGRAM_ENUMERATION("DrawScaleFactor.NoneFilterQuality", scaleFactor,
+                                     kLast_ScaleFactor + 1);
+            break;
+        case kLow_SkFilterQuality:
+            SK_HISTOGRAM_ENUMERATION("DrawScaleFactor.LowFilterQuality", scaleFactor,
+                                     kLast_ScaleFactor + 1);
+            break;
+        case kMedium_SkFilterQuality:
+            SK_HISTOGRAM_ENUMERATION("DrawScaleFactor.MediumFilterQuality", scaleFactor,
+                                     kLast_ScaleFactor + 1);
+            break;
+        case kHigh_SkFilterQuality:
+            SK_HISTOGRAM_ENUMERATION("DrawScaleFactor.HighFilterQuality", scaleFactor,
+                                     kLast_ScaleFactor + 1);
+            break;
+    }
+
+    // Also log filter quality independent scale factor.
+    SK_HISTOGRAM_ENUMERATION("DrawScaleFactor.AnyFilterQuality", scaleFactor,
+                             kLast_ScaleFactor + 1);
+
+    // Also log an overall histogram of filter quality.
+    SK_HISTOGRAM_ENUMERATION("FilterQuality", filterQuality, kLast_SkFilterQuality + 1);
+#endif
+}
+
index 08eab55..e49c578 100644 (file)
@@ -968,8 +968,9 @@ void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap,
                                   bool bicubic) {
     ASSERT_SINGLE_OWNER
 
-    // This is the funnel for all paths that draw tiled bitmaps/images. Log histogram entry.
+    // This is the funnel for all paths that draw tiled bitmaps/images. Log histogram entries.
     SK_HISTOGRAM_BOOLEAN("DrawTiled", true);
+    LogDrawScaleFactor(viewMatrix, origPaint.getFilterQuality());
 
     // The following pixel lock is technically redundant, but it is desirable
     // to lock outside of the tile loop to prevent redecoding the whole image
index 9b197ef..7abe49c 100644 (file)
@@ -137,6 +137,9 @@ void SkGpuDevice::drawTextureProducer(GrTextureProducer* producer,
         }
     }
 
+    // Now that we have both the view and srcToDst matrices, log our scale factor.
+    LogDrawScaleFactor(SkMatrix::Concat(viewMatrix, srcToDstMatrix), paint.getFilterQuality());
+
     this->drawTextureProducerImpl(producer, clippedSrcRect, clippedDstRect, constraint, viewMatrix,
                                   srcToDstMatrix, clip, paint);
 }