From f6b0e60bd07436edb033ffe975030b7c1ee91626 Mon Sep 17 00:00:00 2001 From: Chris Craik Date: Wed, 19 Apr 2017 10:38:14 -0700 Subject: [PATCH] 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 --- graphics/java/android/graphics/ComposeShader.java | 10 ++++++++++ graphics/java/android/graphics/Shader.java | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/graphics/java/android/graphics/ComposeShader.java b/graphics/java/android/graphics/ComposeShader.java index e107ea724377d..0b1141a0e5052 100644 --- a/graphics/java/android/graphics/ComposeShader.java +++ b/graphics/java/android/graphics/ComposeShader.java @@ -76,6 +76,16 @@ public class ComposeShader extends Shader { 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 */ diff --git a/graphics/java/android/graphics/Shader.java b/graphics/java/android/graphics/Shader.java index c7447575bd8f2..8410ab2a1e028 100644 --- a/graphics/java/android/graphics/Shader.java +++ b/graphics/java/android/graphics/Shader.java @@ -105,13 +105,20 @@ public class Shader { return 0; } - private void discardNativeInstance() { + void discardNativeInstance() { if (mNativeInstance != 0) { nativeSafeUnref(mNativeInstance); mNativeInstance = 0; } } + /** + * Callback for subclasses to call {@link #discardNativeInstance()} if the most recently + * constructed native instance is no longer valid. + */ + void verifyNativeInstance() { + } + @Override protected void finalize() throws Throwable { try { @@ -148,6 +155,9 @@ public class Shader { throw new IllegalStateException("attempting to use a finalized Shader"); } + // verify mNativeInstance is valid + verifyNativeInstance(); + if (mNativeInstance == 0) { mNativeInstance = createNativeInstance(mLocalMatrix == null ? 0 : mLocalMatrix.native_instance);