Force pending transactions to flush before screenshot.
Following 14e54ba747 (ag/1043009) we need to push an empty
synchronous transaction if we want to ensure all previous
transactions have occured before taking a screenshot. In
light of Bug 7552304 it seems wise to do this before screenshoting
applications.
Bug: 27098060
Bug: 7552304
Change-Id: I6d7dfbe634a288c55449d2f1d6fbbfc13bab08ad
diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java
index 7b01267..b4131b4 100644
--- a/core/java/android/view/SurfaceControl.java
+++ b/core/java/android/view/SurfaceControl.java
@@ -46,7 +46,7 @@
boolean allLayers, boolean useIdentityTransform);
private static native void nativeOpenTransaction();
- private static native void nativeCloseTransaction();
+ private static native void nativeCloseTransaction(boolean sync);
private static native void nativeSetAnimationTransaction();
private static native void nativeSetLayer(long nativeObject, int zorder);
@@ -372,7 +372,11 @@
/** end a transaction */
public static void closeTransaction() {
- nativeCloseTransaction();
+ nativeCloseTransaction(false);
+ }
+
+ public static void closeTransactionSync() {
+ nativeCloseTransaction(true);
}
public void deferTransactionUntil(IBinder handle, long frame) {
diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp
index 864a0bf..a9ed9dc 100644
--- a/core/jni/android_view_SurfaceControl.cpp
+++ b/core/jni/android_view_SurfaceControl.cpp
@@ -223,8 +223,9 @@
SurfaceComposerClient::openGlobalTransaction();
}
-static void nativeCloseTransaction(JNIEnv* env, jclass clazz) {
- SurfaceComposerClient::closeGlobalTransaction();
+
+static void nativeCloseTransaction(JNIEnv* env, jclass clazz, jboolean sync) {
+ SurfaceComposerClient::closeGlobalTransaction(sync);
}
static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz) {
@@ -649,7 +650,7 @@
(void*)nativeScreenshot },
{"nativeOpenTransaction", "()V",
(void*)nativeOpenTransaction },
- {"nativeCloseTransaction", "()V",
+ {"nativeCloseTransaction", "(Z)V",
(void*)nativeCloseTransaction },
{"nativeSetAnimationTransaction", "()V",
(void*)nativeSetAnimationTransaction },