From c9683151367b2033a26b1e2ebe6b3902d2064bdb Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Thu, 18 Jul 2013 13:47:01 +0000 Subject: [PATCH] add FilterLevel API to SkPaint, replacing various Flag bits BUG= R=bsalomon@google.com Review URL: https://codereview.chromium.org/19769005 git-svn-id: http://skia.googlecode.com/svn/trunk@10138 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/core/SkPaint.h | 44 ++++++++++++++++++++++++++++++++++++++---- src/core/SkPaint.cpp | 27 ++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h index 2d7b3fa54..e39f49942 100644 --- a/include/core/SkPaint.h +++ b/include/core/SkPaint.h @@ -98,7 +98,10 @@ public: */ enum Flags { kAntiAlias_Flag = 0x01, //!< mask to enable antialiasing - kFilterBitmap_Flag = 0x02, //!< mask to enable bitmap filtering + + // DEPRECATED -- use setFilterLevel instead + kFilterBitmap_Flag = 0x02, // temporary flag + kDither_Flag = 0x04, //!< mask to enable dithering kUnderlineText_Flag = 0x08, //!< mask to enable underline text kStrikeThruText_Flag = 0x10, //!< mask to enable strike-thru text @@ -111,7 +114,10 @@ public: kAutoHinting_Flag = 0x800, //!< mask to force Freetype's autohinter kVerticalText_Flag = 0x1000, kGenA8FromLCD_Flag = 0x2000, // hack for GDI -- do not use if you can help it + + // DEPRECATED -- use setFilterLevel instead kHighQualityFilterBitmap_Flag = 0x4000, // temporary flag + // DEPRECATED -- use setFilterLevel instead kHighQualityDownsampleBitmap_Flag = 0x8000, // temporary flag // when adding extra flags, note that the fFlags member is specified @@ -280,11 +286,41 @@ public: */ void setDevKernText(bool devKernText); - bool isFilterBitmap() const { - return SkToBool(this->getFlags() & kFilterBitmap_Flag); + enum FilterLevel { + kNone_FilterLevel, + kLow_FilterLevel, + kMedium_FilterLevel, + kHigh_FilterLevel + }; + + /** + * Return the filter level. This affects the quality (and performance) of + * drawing scaled images. + */ + FilterLevel getFilterLevel() const; + + /** + * Set the filter level. This affects the quality (and performance) of + * drawing scaled images. + */ + void setFilterLevel(FilterLevel); + + /** + * DEPRECATED: use setFilterLevel instead. + * If the predicate is true, set the filterLevel to Low, else set it to + * None. + */ + void setFilterBitmap(bool doFilter) { + this->setFilterLevel(doFilter ? kLow_FilterLevel : kNone_FilterLevel); } - void setFilterBitmap(bool filterBitmap); + /** + * DEPRECATED: call getFilterLevel() instead. + * Returns true if getFilterLevel() returns anything other than None. + */ + bool isFilterBitmap() const { + return kNone_FilterLevel != this->getFilterLevel(); + } /** Styles apply to rect, oval, path, and text. Bitmaps are always drawn in "fill", and lines are always drawn in diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 886794c47..372e68051 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -205,6 +205,29 @@ void SkPaint::setPaintOptionsAndroid(const SkPaintOptionsAndroid& options) { } #endif +SkPaint::FilterLevel SkPaint::getFilterLevel() const { + int level = 0; + if (fFlags & kFilterBitmap_Flag) { + level |= 1; + } + if (fFlags & kHighQualityFilterBitmap_Flag) { + level |= 2; + } + return (FilterLevel)level; +} + +void SkPaint::setFilterLevel(FilterLevel level) { + unsigned mask = kFilterBitmap_Flag | kHighQualityFilterBitmap_Flag; + unsigned flags = 0; + if (level & 1) { + flags |= kFilterBitmap_Flag; + } + if (level & 2) { + flags |= kHighQualityFilterBitmap_Flag; + } + this->setFlags((fFlags & ~mask) | flags); +} + void SkPaint::setHinting(Hinting hintingLevel) { GEN_ID_INC_EVAL((unsigned) hintingLevel != fHinting); fHinting = hintingLevel; @@ -263,10 +286,6 @@ void SkPaint::setDevKernText(bool doDevKern) { this->setFlags(SkSetClearMask(fFlags, doDevKern, kDevKernText_Flag)); } -void SkPaint::setFilterBitmap(bool doFilter) { - this->setFlags(SkSetClearMask(fFlags, doFilter, kFilterBitmap_Flag)); -} - void SkPaint::setStyle(Style style) { if ((unsigned)style < kStyleCount) { GEN_ID_INC_EVAL((unsigned)style != fStyle);