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
*/
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 {
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);