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

Commit f8ac3643 authored by Derek Sollenberger's avatar Derek Sollenberger Committed by Android (Google) Code Review
Browse files

Merge "Restore old behavior of setLocalMatrix"

parents 4bfa55d4 c95d2d1b
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -60,6 +60,27 @@ static jlong Shader_setLocalMatrix(JNIEnv* env, jobject o, jlong shaderHandle, j
    // as all the data needed is contained within the newly created LocalMatrixShader.
    SkASSERT(shaderHandle);
    SkAutoTUnref<SkShader> currentShader(reinterpret_cast<SkShader*>(shaderHandle));

    // Attempt to peel off an existing proxy shader and get the proxy's matrix. If
    // the proxy existed and it's matrix equals the desired matrix then just return
    // the proxy, otherwise replace it with a new proxy containing the desired matrix.
    //
    // refAsALocalMatrixShader(): if the shader contains a proxy then it unwraps the proxy
    //                            returning both the underlying shader and the proxy's matrix.
    // newWithLocalMatrix(): will return a proxy shader that wraps the provided shader and
    //                       concats the provided local matrix with the shader's matrix.
    //
    // WARNING: This proxy replacement only behaves like a setter because the Java
    //          API enforces that all local matrices are set using this call and
    //          not passed to the constructor of the Shader.
    SkMatrix proxyMatrix;
    SkAutoTUnref<SkShader> baseShader(currentShader->refAsALocalMatrixShader(&proxyMatrix));
    if (baseShader.get()) {
        if (proxyMatrix == *matrix) {
            return reinterpret_cast<jlong>(currentShader.detach());
        }
        return reinterpret_cast<jlong>(baseShader->newWithLocalMatrix(*matrix));
    }
    return reinterpret_cast<jlong>(currentShader->newWithLocalMatrix(*matrix));
}