Remove SurfaceControl#getHandle from JAVA apis 2/2

Holding on to a reference of the handle in Java will keep the server-side surface alive until
the reference is removed by GC. This may cause surfaces to be kept alive longer than necessary.
Instead hold on the surface control and call SurfaceControl#release which will release the local
reference to the server-side surface.

Bug: 136004147
Test: go/wm-smoke

Change-Id: Iff7d48ae1593cea2e188aa07c417f4c5a98887d5
This commit is contained in:
Vishnu Nair
2019-06-25 17:28:58 -07:00
parent 4bcd152a3a
commit bc9beab8fe
12 changed files with 109 additions and 125 deletions

View File

@@ -109,10 +109,10 @@ public final class InputWindowHandle {
* bounds of a parent window. That is the window should receive touch events outside its
* window but be limited to its stack bounds, such as in the case of split screen.
*/
public WeakReference<IBinder> touchableRegionCropHandle = new WeakReference<>(null);
public WeakReference<SurfaceControl> touchableRegionSurfaceControl = new WeakReference<>(null);
/**
* Replace {@link touchableRegion} with the bounds of {@link touchableRegionCropHandle}. If
* Replace {@link touchableRegion} with the bounds of {@link touchableRegionSurfaceControl}. If
* the handle is {@code null}, the bounds of the surface associated with this window is used
* as the touchable region.
*/
@@ -164,8 +164,6 @@ public final class InputWindowHandle {
* Crop the window touchable region to the bounds of the surface provided.
*/
public void setTouchableRegionCrop(@Nullable SurfaceControl bounds) {
if (bounds != null) {
touchableRegionCropHandle = new WeakReference<>(bounds.getHandle());
}
touchableRegionSurfaceControl = new WeakReference<>(bounds);
}
}

View File

@@ -91,7 +91,7 @@ public final class SurfaceControl implements Parcelable {
Rect sourceCrop, int width, int height, boolean useIdentityTransform, int rotation,
boolean captureSecureLayers);
private static native ScreenshotGraphicBuffer nativeCaptureLayers(IBinder displayToken,
IBinder layerHandleToken, Rect sourceCrop, float frameScale, IBinder[] excludeLayers);
long layerObject, Rect sourceCrop, float frameScale, long[] excludeLayerObjects);
private static native long nativeCreateTransaction();
private static native long nativeGetNativeTransactionFinalizer();
@@ -103,7 +103,7 @@ public final class SurfaceControl implements Parcelable {
private static native void nativeSetLayer(long transactionObj, long nativeObject, int zorder);
private static native void nativeSetRelativeLayer(long transactionObj, long nativeObject,
IBinder relativeTo, int zorder);
long relativeToObject, int zorder);
private static native void nativeSetPosition(long transactionObj, long nativeObject,
float x, float y);
private static native void nativeSetGeometryAppliesWithResize(long transactionObj,
@@ -173,18 +173,17 @@ public final class SurfaceControl implements Parcelable {
private static native void nativeSetDisplayPowerMode(
IBinder displayToken, int mode);
private static native void nativeDeferTransactionUntil(long transactionObj, long nativeObject,
IBinder handle, long frame);
long barrierObject, long frame);
private static native void nativeDeferTransactionUntilSurface(long transactionObj,
long nativeObject,
long surfaceObject, long frame);
private static native void nativeReparentChildren(long transactionObj, long nativeObject,
IBinder handle);
long newParentObject);
private static native void nativeReparent(long transactionObj, long nativeObject,
long newParentNativeObject);
private static native void nativeSeverChildren(long transactionObj, long nativeObject);
private static native void nativeSetOverrideScalingMode(long transactionObj, long nativeObject,
int scalingMode);
private static native IBinder nativeGetHandle(long nativeObject);
private static native boolean nativeGetTransformToDisplayInverse(long nativeObject);
private static native Display.HdrCapabilities nativeGetHdrCapabilities(IBinder displayToken);
@@ -1023,9 +1022,9 @@ public final class SurfaceControl implements Parcelable {
/**
* @hide
*/
public void deferTransactionUntil(IBinder handle, long frame) {
public void deferTransactionUntil(SurfaceControl barrier, long frame) {
synchronized(SurfaceControl.class) {
sGlobalTransaction.deferTransactionUntil(this, handle, frame);
sGlobalTransaction.deferTransactionUntil(this, barrier, frame);
}
}
@@ -1041,9 +1040,9 @@ public final class SurfaceControl implements Parcelable {
/**
* @hide
*/
public void reparentChildren(IBinder newParentHandle) {
public void reparentChildren(SurfaceControl newParent) {
synchronized(SurfaceControl.class) {
sGlobalTransaction.reparentChildren(this, newParentHandle);
sGlobalTransaction.reparentChildren(this, newParent);
}
}
@@ -1075,13 +1074,6 @@ public final class SurfaceControl implements Parcelable {
}
}
/**
* @hide
*/
public IBinder getHandle() {
return nativeGetHandle(mNativeObject);
}
/**
* @hide
*/
@@ -1989,7 +1981,7 @@ public final class SurfaceControl implements Parcelable {
/**
* Captures a layer and its children and returns a {@link GraphicBuffer} with the content.
*
* @param layerHandleToken The root layer to capture.
* @param layer The root layer to capture.
* @param sourceCrop The portion of the root surface to capture; caller may pass in 'new
* Rect()' or null if no cropping is desired.
* @param frameScale The desired scale of the returned buffer; the raw
@@ -1998,20 +1990,25 @@ public final class SurfaceControl implements Parcelable {
* @return Returns a GraphicBuffer that contains the layer capture.
* @hide
*/
public static ScreenshotGraphicBuffer captureLayers(IBinder layerHandleToken, Rect sourceCrop,
public static ScreenshotGraphicBuffer captureLayers(SurfaceControl layer, Rect sourceCrop,
float frameScale) {
final IBinder displayToken = SurfaceControl.getInternalDisplayToken();
return nativeCaptureLayers(displayToken, layerHandleToken, sourceCrop, frameScale, null);
return nativeCaptureLayers(displayToken, layer.mNativeObject, sourceCrop, frameScale, null);
}
/**
* Like {@link captureLayers} but with an array of layer handles to exclude.
* @hide
*/
public static ScreenshotGraphicBuffer captureLayersExcluding(IBinder layerHandleToken,
Rect sourceCrop, float frameScale, IBinder[] exclude) {
public static ScreenshotGraphicBuffer captureLayersExcluding(SurfaceControl layer,
Rect sourceCrop, float frameScale, SurfaceControl[] exclude) {
final IBinder displayToken = SurfaceControl.getInternalDisplayToken();
return nativeCaptureLayers(displayToken, layerHandleToken, sourceCrop, frameScale, exclude);
long[] nativeExcludeObjects = new long[exclude.length];
for (int i = 0; i < exclude.length; i++) {
nativeExcludeObjects[i] = exclude[i].mNativeObject;
}
return nativeCaptureLayers(displayToken, layer.mNativeObject, sourceCrop, frameScale,
nativeExcludeObjects);
}
/**
@@ -2228,8 +2225,7 @@ public final class SurfaceControl implements Parcelable {
*/
public Transaction setRelativeLayer(SurfaceControl sc, SurfaceControl relativeTo, int z) {
sc.checkNotReleased();
nativeSetRelativeLayer(mNativeObject, sc.mNativeObject,
relativeTo.getHandle(), z);
nativeSetRelativeLayer(mNativeObject, sc.mNativeObject, relativeTo.mNativeObject, z);
return this;
}
@@ -2416,13 +2412,14 @@ public final class SurfaceControl implements Parcelable {
* @hide
*/
@UnsupportedAppUsage
public Transaction deferTransactionUntil(SurfaceControl sc, IBinder handle,
public Transaction deferTransactionUntil(SurfaceControl sc, SurfaceControl barrier,
long frameNumber) {
if (frameNumber < 0) {
return this;
}
sc.checkNotReleased();
nativeDeferTransactionUntil(mNativeObject, sc.mNativeObject, handle, frameNumber);
nativeDeferTransactionUntil(mNativeObject, sc.mNativeObject, barrier.mNativeObject,
frameNumber);
return this;
}
@@ -2444,9 +2441,9 @@ public final class SurfaceControl implements Parcelable {
/**
* @hide
*/
public Transaction reparentChildren(SurfaceControl sc, IBinder newParentHandle) {
public Transaction reparentChildren(SurfaceControl sc, SurfaceControl newParent) {
sc.checkNotReleased();
nativeReparentChildren(mNativeObject, sc.mNativeObject, newParentHandle);
nativeReparentChildren(mNativeObject, sc.mNativeObject, newParent.mNativeObject);
return this;
}