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

Commit ab87983a authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

Simplify Shader.setLocalMatrix.

Previously, calling setLocalMatrix updated any Paint that had the
Shader attached. This depended on deprecated behavior in Skia. Use
new Skia APIs, and do not modify any Paints that use the Shader.

In addition, update callers to call setShader (again) after modifying
the Shader.

Sample app at ag/499573 for testing.

Depends on I673801444f0a8fd4f192b5b7effdde1aa83e702b in external/skia.

BUG:14315916
Change-Id: I3c3316377874e89fccc85afb864bc038b0ef3890
parent 3ff3db5f
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -14947,6 +14947,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            matrix.setScale(1, fadeHeight * topFadeStrength);
            matrix.postTranslate(left, top);
            fade.setLocalMatrix(matrix);
            p.setShader(fade);
            canvas.drawRect(left, top, right, top + length, p);
        }
@@ -14955,6 +14956,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            matrix.postRotate(180);
            matrix.postTranslate(left, bottom);
            fade.setLocalMatrix(matrix);
            p.setShader(fade);
            canvas.drawRect(left, bottom - length, right, bottom, p);
        }
@@ -14963,6 +14965,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            matrix.postRotate(-90);
            matrix.postTranslate(left, top);
            fade.setLocalMatrix(matrix);
            p.setShader(fade);
            canvas.drawRect(left, top, left + length, bottom, p);
        }
@@ -14971,6 +14974,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            matrix.postRotate(90);
            matrix.postTranslate(right, top);
            fade.setLocalMatrix(matrix);
            p.setShader(fade);
            canvas.drawRect(right - length, top, right, bottom, p);
        }
+7 −6
Original line number Diff line number Diff line
@@ -56,19 +56,20 @@ static void Shader_destructor(JNIEnv* env, jobject o, jlong shaderHandle)
    SkSafeUnref(shader);
}

static void Shader_setLocalMatrix(JNIEnv* env, jobject o, jlong shaderHandle,
static jlong Shader_setLocalMatrix(JNIEnv* env, jobject o, jlong shaderHandle,
        jlong matrixHandle)
{
    SkShader* shader       = reinterpret_cast<SkShader*>(shaderHandle);
    const SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
    if (shader) {
        if (NULL == matrix) {
            shader->resetLocalMatrix();
        }
        else {
            shader->setLocalMatrix(*matrix);
            matrix = &SkMatrix::I();
        }
        SkShader* newShader = SkShader::CreateLocalMatrixShader(shader, *matrix);
        shader->unref();
        shader = newShader;
    }
    return reinterpret_cast<jlong>(shader);
}

///////////////////////////////////////////////////////////////////////////////////////////////
@@ -239,7 +240,7 @@ static JNINativeMethod gColorMethods[] = {

static JNINativeMethod gShaderMethods[] = {
    { "nativeDestructor",        "(J)V",    (void*)Shader_destructor        },
    { "nativeSetLocalMatrix",    "(JJ)V",   (void*)Shader_setLocalMatrix    }
    { "nativeSetLocalMatrix",    "(JJ)J",   (void*)Shader_setLocalMatrix    }
};

static JNINativeMethod gBitmapShaderMethods[] = {
+8 −3
Original line number Diff line number Diff line
@@ -69,12 +69,17 @@ public class Shader {

    /**
     * Set the shader's local matrix. Passing null will reset the shader's
     * matrix to identity
     * matrix to identity.
     *
     * Starting with {@link android.os.Build.VERSION_CODES#L}, this does not
     * modify any Paints which use this Shader. In order to modify the Paint,
     * you need to call {@link Paint#setShader} again.
     *
     * @param localM The shader's new local matrix, or null to specify identity
     */
    public void setLocalMatrix(Matrix localM) {
        mLocalMatrix = localM;
        nativeSetLocalMatrix(native_instance,
        native_instance = nativeSetLocalMatrix(native_instance,
                localM == null ? 0 : localM.native_instance);
    }

@@ -109,6 +114,6 @@ public class Shader {
    }

    private static native void nativeDestructor(long native_shader);
    private static native void nativeSetLocalMatrix(long native_shader,
    private static native long nativeSetLocalMatrix(long native_shader,
            long matrix_instance);
}
+4 −0
Original line number Diff line number Diff line
@@ -467,10 +467,12 @@ public class BitmapDrawable extends Drawable {
            if (needMirroring()) {
                updateMirrorMatrix(bounds.right - bounds.left);
                shader.setLocalMatrix(mMirrorMatrix);
                mBitmapState.mPaint.setShader(shader);
            } else {
                if (mMirrorMatrix != null) {
                    mMirrorMatrix = null;
                    shader.setLocalMatrix(Matrix.IDENTITY_MATRIX);
                    mBitmapState.mPaint.setShader(shader);
                }
            }
        }
@@ -547,10 +549,12 @@ public class BitmapDrawable extends Drawable {
                // Mirror the bitmap
                updateMirrorMatrix(mDstRect.right - mDstRect.left);
                shader.setLocalMatrix(mMirrorMatrix);
                paint.setShader(shader);
            } else {
                if (mMirrorMatrix != null) {
                    mMirrorMatrix = null;
                    shader.setLocalMatrix(Matrix.IDENTITY_MATRIX);
                    paint.setShader(shader);
                }
            }

+4 −0
Original line number Diff line number Diff line
@@ -142,6 +142,7 @@ public class FadedEdgeDrawHelper {
                mFadeMatrix.setScale(1, fadeHeight * topFadeStrength);
                mFadeMatrix.postTranslate(left, top);
                mFade.setLocalMatrix(mFadeMatrix);
                mFadePaint.setShader(mFade);
                canvas.drawRect(left, top, right, top + length, mFadePaint);

                if (mBlackPaint == null) {
@@ -157,6 +158,7 @@ public class FadedEdgeDrawHelper {
                mFadeMatrix.postRotate(180);
                mFadeMatrix.postTranslate(left, bottom);
                mFade.setLocalMatrix(mFadeMatrix);
                mFadePaint.setShader(mFade);
                canvas.drawRect(left, bottom - length, right, bottom, mFadePaint);
            }

@@ -165,6 +167,7 @@ public class FadedEdgeDrawHelper {
                mFadeMatrix.postRotate(-90);
                mFadeMatrix.postTranslate(left, top);
                mFade.setLocalMatrix(mFadeMatrix);
                mFadePaint.setShader(mFade);
                canvas.drawRect(left, top, left + length, bottom, mFadePaint);
            }

@@ -173,6 +176,7 @@ public class FadedEdgeDrawHelper {
                mFadeMatrix.postRotate(90);
                mFadeMatrix.postTranslate(right, top);
                mFade.setLocalMatrix(mFadeMatrix);
                mFadePaint.setShader(mFade);
                canvas.drawRect(right - length, top, right, bottom, mFadePaint);
            }
        }
Loading