Merge "Fix compose shader child local matrix mutation" into oc-dev

am: 611fae13df

Change-Id: I76a5398f300ccac27fe70e7f7377d0ea8c779cbe
This commit is contained in:
Chris Craik
2017-04-19 21:25:59 +00:00
committed by android-build-merger
2 changed files with 21 additions and 1 deletions

View File

@@ -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
*/

View File

@@ -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);