Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5f6aa983 authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

Fix FILTER_BITMAP_FLAG regression in DrawFilter.

Skia removed the corresponding kFilterBitmapFlag, replacing it with a
separate function: setFilterLevel. If the flag is set, turn it into a
call to setFilterLevel.

Corresponds to changes in I2736f3f68683651574d79a169ff0ab563e0a469e to
fix Paint.setFlags().

BUG:15112859
Change-Id: I269cbd7a624e5dde5688305e1ba97075ba73f4fd
parent 2416768a
Loading
Loading
Loading
Loading
+47 −5
Original line number Diff line number Diff line
@@ -30,6 +30,35 @@

namespace android {

// Custom version of SkPaintFlagsDrawFilter that also calls setFilterLevel.
class CompatFlagsDrawFilter : public SkPaintFlagsDrawFilter {
public:
    CompatFlagsDrawFilter(uint32_t clearFlags, uint32_t setFlags,
            SkPaint::FilterLevel desiredLevel)
    : SkPaintFlagsDrawFilter(clearFlags, setFlags)
    , fDesiredLevel(desiredLevel) {
    }

    virtual bool filter(SkPaint* paint, Type type) {
        SkPaintFlagsDrawFilter::filter(paint, type);
        paint->setFilterLevel(fDesiredLevel);
        return true;
    }

private:
    const SkPaint::FilterLevel fDesiredLevel;
};

// Returns whether flags contains FILTER_BITMAP_FLAG. If flags does, remove it.
static inline bool hadFiltering(jint& flags) {
    // Equivalent to the Java Paint's FILTER_BITMAP_FLAG.
    static const uint32_t sFilterBitmapFlag = 0x02;

    const bool result = (flags & sFilterBitmapFlag) != 0;
    flags &= ~sFilterBitmapFlag;
    return result;
}

class SkDrawFilterGlue {
public:

@@ -40,12 +69,25 @@ public:

    static jlong CreatePaintFlagsDF(JNIEnv* env, jobject clazz,
                                    jint clearFlags, jint setFlags) {
        // trim off any out-of-range bits
        clearFlags &= SkPaint::kAllFlags;
        setFlags &= SkPaint::kAllFlags;

        if (clearFlags | setFlags) {
            SkDrawFilter* filter = new SkPaintFlagsDrawFilter(clearFlags, setFlags);
            // Mask both groups of flags to remove FILTER_BITMAP_FLAG, which no
            // longer has a Skia equivalent flag (instead it corresponds to
            // calling setFilterLevel), and keep track of which group(s), if
            // any, had the flag set.
            const bool turnFilteringOn = hadFiltering(setFlags);
            const bool turnFilteringOff = hadFiltering(clearFlags);

            SkDrawFilter* filter;
            if (turnFilteringOn) {
                // Turning filtering on overrides turning it off.
                filter = new CompatFlagsDrawFilter(clearFlags, setFlags,
                        SkPaint::kLow_FilterLevel);
            } else if (turnFilteringOff) {
                filter = new CompatFlagsDrawFilter(clearFlags, setFlags,
                        SkPaint::kNone_FilterLevel);
            } else {
                filter = new SkPaintFlagsDrawFilter(clearFlags, setFlags);
            }
            return reinterpret_cast<jlong>(filter);
        } else {
            return NULL;