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

Commit f6b0e60b authored by Chris Craik's avatar Chris Craik
Browse files

Fix compose shader child local matrix mutation

Bug: 37495696
Test: cts-tradefed run singleCommand cts-dev --module CtsGraphicsTestCases --test android.graphics.cts.ComposeShaderTest

Adds back the verify step that discards a stale native ComposeShader if a child
changes.

Change-Id: I44f40c1edfdb7633994a69efb583cf28ee2c26b2
parent 8b4cca11
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -76,6 +76,16 @@ public class ComposeShader extends Shader {
                mShaderA.getNativeInstance(), mShaderB.getNativeInstance(), mPorterDuffMode);
                mShaderA.getNativeInstance(), mShaderB.getNativeInstance(), mPorterDuffMode);
    }
    }


    @Override
    void verifyNativeInstance() {
        if (mShaderA.getNativeInstance() != mNativeInstanceShaderA
                || mShaderB.getNativeInstance() != mNativeInstanceShaderB) {
            // Child shader native instance has been updated,
            // so our cached native instance is no longer valid - discard it
            discardNativeInstance();
        }
    }

    /**
    /**
     * @hide
     * @hide
     */
     */
+11 −1
Original line number Original line Diff line number Diff line
@@ -105,13 +105,20 @@ public class Shader {
        return 0;
        return 0;
    }
    }


    private void discardNativeInstance() {
    void discardNativeInstance() {
        if (mNativeInstance != 0) {
        if (mNativeInstance != 0) {
            nativeSafeUnref(mNativeInstance);
            nativeSafeUnref(mNativeInstance);
            mNativeInstance = 0;
            mNativeInstance = 0;
        }
        }
    }
    }


    /**
     * Callback for subclasses to call {@link #discardNativeInstance()} if the most recently
     * constructed native instance is no longer valid.
     */
    void verifyNativeInstance() {
    }

    @Override
    @Override
    protected void finalize() throws Throwable {
    protected void finalize() throws Throwable {
        try {
        try {
@@ -148,6 +155,9 @@ public class Shader {
            throw new IllegalStateException("attempting to use a finalized Shader");
            throw new IllegalStateException("attempting to use a finalized Shader");
        }
        }


        // verify mNativeInstance is valid
        verifyNativeInstance();

        if (mNativeInstance == 0) {
        if (mNativeInstance == 0) {
            mNativeInstance = createNativeInstance(mLocalMatrix == null
            mNativeInstance = createNativeInstance(mLocalMatrix == null
                    ? 0 : mLocalMatrix.native_instance);
                    ? 0 : mLocalMatrix.native_instance);