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

Commit d66a8719 authored by Leon Scroggins III's avatar Leon Scroggins III Committed by Android (Google) Code Review
Browse files

Merge "Simplify Shader.setLocalMatrix."

parents 219cca78 ab87983a
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -14948,6 +14948,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);
        }
@@ -14956,6 +14957,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);
        }
@@ -14964,6 +14966,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);
        }
@@ -14972,6 +14975,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