Merge "Only clear SurfaceControl.Transaction when parcelling as a return value" into sc-dev

This commit is contained in:
Vishnu Nair
2021-04-14 15:27:18 +00:00
committed by Android (Google) Code Review
3 changed files with 33 additions and 3 deletions

View File

@@ -104,6 +104,7 @@ public final class SurfaceControl implements Parcelable {
private static native void nativeApplyTransaction(long transactionObj, boolean sync); private static native void nativeApplyTransaction(long transactionObj, boolean sync);
private static native void nativeMergeTransaction(long transactionObj, private static native void nativeMergeTransaction(long transactionObj,
long otherTransactionObj); long otherTransactionObj);
private static native void nativeClearTransaction(long transactionObj);
private static native void nativeSetAnimationTransaction(long transactionObj); private static native void nativeSetAnimationTransaction(long transactionObj);
private static native void nativeSetEarlyWakeupStart(long transactionObj); private static native void nativeSetEarlyWakeupStart(long transactionObj);
private static native void nativeSetEarlyWakeupEnd(long transactionObj); private static native void nativeSetEarlyWakeupEnd(long transactionObj);
@@ -2601,6 +2602,19 @@ public final class SurfaceControl implements Parcelable {
apply(false); apply(false);
} }
/**
* Clear the transaction object, without applying it.
*
* @hide
*/
public void clear() {
mResizedSurfaces.clear();
mReparentedSurfaces.clear();
if (mNativeObject != 0) {
nativeClearTransaction(mNativeObject);
}
}
/** /**
* Release the native transaction object, without applying it. * Release the native transaction object, without applying it.
*/ */
@@ -3411,10 +3425,14 @@ public final class SurfaceControl implements Parcelable {
public void writeToParcel(@NonNull Parcel dest, @WriteFlags int flags) { public void writeToParcel(@NonNull Parcel dest, @WriteFlags int flags) {
if (mNativeObject == 0) { if (mNativeObject == 0) {
dest.writeInt(0); dest.writeInt(0);
} else { return;
dest.writeInt(1);
} }
dest.writeInt(1);
nativeWriteTransactionToParcel(mNativeObject, dest); nativeWriteTransactionToParcel(mNativeObject, dest);
if ((flags & Parcelable.PARCELABLE_WRITE_RETURN_VALUE) != 0) {
nativeClearTransaction(mNativeObject);
}
} }
private void readFromParcel(Parcel in) { private void readFromParcel(Parcel in) {

View File

@@ -3906,7 +3906,10 @@ public final class ViewRootImpl implements ViewParent,
mDrawsNeededToReport = 0; mDrawsNeededToReport = 0;
mWindowSession.finishDrawing(mWindow, mSurfaceChangedTransaction); mWindowSession.finishDrawing(mWindow, mSurfaceChangedTransaction);
} catch (RemoteException e) { } catch (RemoteException e) {
// Have fun! Log.e(mTag, "Unable to report draw finished", e);
mSurfaceChangedTransaction.apply();
} finally {
mSurfaceChangedTransaction.clear();
} }
} }

View File

@@ -1562,6 +1562,13 @@ static void nativeWriteTransactionToParcel(JNIEnv* env, jclass clazz, jlong nati
reinterpret_cast<SurfaceComposerClient::Transaction *>(nativeObject); reinterpret_cast<SurfaceComposerClient::Transaction *>(nativeObject);
if (self != nullptr) { if (self != nullptr) {
self->writeToParcel(parcel); self->writeToParcel(parcel);
}
}
static void nativeClearTransaction(JNIEnv* env, jclass clazz, jlong nativeObject) {
SurfaceComposerClient::Transaction* const self =
reinterpret_cast<SurfaceComposerClient::Transaction*>(nativeObject);
if (self != nullptr) {
self->clear(); self->clear();
} }
} }
@@ -1880,6 +1887,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
(void*)nativeReadTransactionFromParcel }, (void*)nativeReadTransactionFromParcel },
{"nativeWriteTransactionToParcel", "(JLandroid/os/Parcel;)V", {"nativeWriteTransactionToParcel", "(JLandroid/os/Parcel;)V",
(void*)nativeWriteTransactionToParcel }, (void*)nativeWriteTransactionToParcel },
{"nativeClearTransaction", "(J)V",
(void*)nativeClearTransaction },
{"nativeMirrorSurface", "(J)J", {"nativeMirrorSurface", "(J)J",
(void*)nativeMirrorSurface }, (void*)nativeMirrorSurface },
{"nativeSetGlobalShadowSettings", "([F[FFFF)V", {"nativeSetGlobalShadowSettings", "([F[FFFF)V",