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

Commit 09c2d4fe authored by Derek Sollenberger's avatar Derek Sollenberger
Browse files

Refactor HWUI to better handle Canvas DrawFilters.

First, this CL removes the need to decompose the DrawFilters
in Java and instead passes the SkDrawFilter to HWUI directly.
This also allows the removal of duplicated logic between HWUI
and other Canvas implementations regarding Paint filter levels.

Second, the DrawFilter is now stored in the DisplayListRenderer
where we apply it to every paint BEFORE it is stored in the
DisplayList.  This eliminates the need to filter all Paints on
playback and removes additional complexity at playback.

Finally, as a result of storing the filtered paint we can now
do a better job caching the paints.  This takes advantage of
recent changes in Skia to quickly enable quick hashing and
comparison of paint objects.

Change-Id: Iec507a2d894827975cc4f1d22241542bb0534b4e
parent de2dc4e1
Loading
Loading
Loading
Loading
+2 −8
Original line number Original line Diff line number Diff line
@@ -517,16 +517,10 @@ class GLES20Canvas extends HardwareCanvas {
    @Override
    @Override
    public void setDrawFilter(DrawFilter filter) {
    public void setDrawFilter(DrawFilter filter) {
        mFilter = filter;
        mFilter = filter;
        if (filter == null) {
        nSetDrawFilter(mRenderer, (filter != null) ? filter.mNativeInt : 0);
            nResetPaintFilter(mRenderer);
        } else if (filter instanceof PaintFlagsDrawFilter) {
            PaintFlagsDrawFilter flagsFilter = (PaintFlagsDrawFilter) filter;
            nSetupPaintFilter(mRenderer, flagsFilter.clearBits, flagsFilter.setBits);
        }
    }
    }


    private static native void nResetPaintFilter(long renderer);
    private static native void nSetDrawFilter(long renderer, long nativeFilter);
    private static native void nSetupPaintFilter(long renderer, int clearBits, int setBits);


    @Override
    @Override
    public DrawFilter getDrawFilter() {
    public DrawFilter getDrawFilter() {
+5 −11
Original line number Original line Diff line number Diff line
@@ -587,16 +587,11 @@ static void android_view_GLES20Canvas_drawLines(JNIEnv* env, jobject clazz,
// Draw filters
// Draw filters
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


static void android_view_GLES20Canvas_setupPaintFilter(JNIEnv* env, jobject clazz,
static void android_view_GLES20Canvas_setDrawFilter(JNIEnv* env, jobject clazz,
        jlong rendererPtr, jint clearBits, jint setBits) {
        jlong rendererPtr, jlong filterPtr) {
    DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
    DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
    renderer->setupPaintFilter(clearBits, setBits);
    SkDrawFilter* filter = reinterpret_cast<SkDrawFilter*>(filterPtr);
}
    renderer->setDrawFilter(filter);

static void android_view_GLES20Canvas_resetPaintFilter(JNIEnv* env, jobject clazz,
        jlong rendererPtr) {
    DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
    renderer->resetPaintFilter();
}
}


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
@@ -936,8 +931,7 @@ static JNINativeMethod gMethods[] = {
    { "nDrawPath",          "(JJJ)V",          (void*) android_view_GLES20Canvas_drawPath },
    { "nDrawPath",          "(JJJ)V",          (void*) android_view_GLES20Canvas_drawPath },
    { "nDrawLines",         "(J[FIIJ)V",       (void*) android_view_GLES20Canvas_drawLines },
    { "nDrawLines",         "(J[FIIJ)V",       (void*) android_view_GLES20Canvas_drawLines },


    { "nSetupPaintFilter",  "(JII)V",          (void*) android_view_GLES20Canvas_setupPaintFilter },
    { "nSetDrawFilter",     "(JJ)V",           (void*) android_view_GLES20Canvas_setDrawFilter },
    { "nResetPaintFilter",  "(J)V",            (void*) android_view_GLES20Canvas_resetPaintFilter },


    { "nDrawText",          "(J[CIIFFIJJ)V",   (void*) android_view_GLES20Canvas_drawTextArray },
    { "nDrawText",          "(J[CIIFFIJJ)V",   (void*) android_view_GLES20Canvas_drawTextArray },
    { "nDrawText",          "(JLjava/lang/String;IIFFIJJ)V",
    { "nDrawText",          "(JLjava/lang/String;IIFFIJJ)V",
+5 −2
Original line number Original line Diff line number Diff line
@@ -24,8 +24,11 @@ package android.graphics;
 */
 */
public class DrawFilter {
public class DrawFilter {


    // this is set by subclasses, but don't make it public
    /**
    /* package */ long mNativeInt;    // pointer to native object
     * this is set by subclasses
     * @hide
     */
    public long mNativeInt;


    protected void finalize() throws Throwable {
    protected void finalize() throws Throwable {
        try {
        try {
+0 −7
Original line number Original line Diff line number Diff line
@@ -17,11 +17,6 @@
package android.graphics;
package android.graphics;


public class PaintFlagsDrawFilter extends DrawFilter {
public class PaintFlagsDrawFilter extends DrawFilter {
    /** @hide **/
    public final int clearBits;
    /** @hide **/
    public final int setBits;

    /**
    /**
     * Subclass of DrawFilter that affects every paint by first clearing
     * Subclass of DrawFilter that affects every paint by first clearing
     * the specified clearBits in the paint's flags, and then setting the
     * the specified clearBits in the paint's flags, and then setting the
@@ -31,8 +26,6 @@ public class PaintFlagsDrawFilter extends DrawFilter {
     * @param setBits These bits will be set in the paint's flags
     * @param setBits These bits will be set in the paint's flags
     */
     */
    public PaintFlagsDrawFilter(int clearBits, int setBits) {
    public PaintFlagsDrawFilter(int clearBits, int setBits) {
        this.clearBits = clearBits;
        this.setBits = setBits;
        // our native constructor can return 0, if the specified bits
        // our native constructor can return 0, if the specified bits
        // are effectively a no-op
        // are effectively a no-op
        mNativeInt = nativeConstructor(clearBits, setBits);
        mNativeInt = nativeConstructor(clearBits, setBits);
+0 −20
Original line number Original line Diff line number Diff line
@@ -235,26 +235,6 @@ public:
            return false;
            return false;
        }
        }


        /* Draw Modifiers compatibility check
         *
         * Shadows are ignored, as only text uses them, and in that case they are drawn
         * per-DrawTextOp, before the unified text draw. Because of this, it's always safe to merge
         * text UNLESS a later draw's shadow should overlays a previous draw's text. This is covered
         * above with the intersection check.
         *
         * OverrideLayerAlpha is also ignored, as it's only used for drawing layers, which are never
         * merged.
         *
         * These ignore cases prevent us from simply memcmp'ing the drawModifiers
         */
        const DrawModifiers& lhsMod = lhs->mDrawModifiers;
        const DrawModifiers& rhsMod = rhs->mDrawModifiers;

        // Draw filter testing expects bit fields to be clear if filter not set.
        if (lhsMod.mHasDrawFilter != rhsMod.mHasDrawFilter) return false;
        if (lhsMod.mPaintFilterClearBits != rhsMod.mPaintFilterClearBits) return false;
        if (lhsMod.mPaintFilterSetBits != rhsMod.mPaintFilterSetBits) return false;

        return true;
        return true;
    }
    }


Loading