Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.view; |
| 18 | |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 19 | import static android.graphics.Matrix.MSCALE_X; |
| 20 | import static android.graphics.Matrix.MSCALE_Y; |
| 21 | import static android.graphics.Matrix.MSKEW_X; |
| 22 | import static android.graphics.Matrix.MSKEW_Y; |
| 23 | import static android.graphics.Matrix.MTRANS_X; |
| 24 | import static android.graphics.Matrix.MTRANS_Y; |
Vishnu Nair | 04ab439 | 2018-01-10 11:00:06 -0800 | [diff] [blame] | 25 | import static android.view.Surface.ROTATION_270; |
| 26 | import static android.view.Surface.ROTATION_90; |
| 27 | import static android.view.SurfaceControlProto.HASH_CODE; |
| 28 | import static android.view.SurfaceControlProto.NAME; |
chaviw | a69e0a7 | 2017-11-29 17:55:12 -0800 | [diff] [blame] | 29 | |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 30 | import android.annotation.FloatRange; |
| 31 | import android.annotation.IntRange; |
| 32 | import android.annotation.NonNull; |
| 33 | import android.annotation.Nullable; |
chaviw | 0dd03f5 | 2017-08-25 12:15:26 -0700 | [diff] [blame] | 34 | import android.annotation.Size; |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 35 | import android.annotation.UnsupportedAppUsage; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 36 | import android.graphics.Bitmap; |
Peiyong Lin | 5f4a568 | 2019-01-17 11:37:07 -0800 | [diff] [blame] | 37 | import android.graphics.ColorSpace; |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 38 | import android.graphics.GraphicBuffer; |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 39 | import android.graphics.Matrix; |
Vishnu Nair | 04ab439 | 2018-01-10 11:00:06 -0800 | [diff] [blame] | 40 | import android.graphics.PixelFormat; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 41 | import android.graphics.Point; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 42 | import android.graphics.Rect; |
| 43 | import android.graphics.Region; |
Kevin DuBois | bf76b11b | 2018-09-04 09:14:15 -0700 | [diff] [blame] | 44 | import android.hardware.display.DisplayedContentSample; |
| 45 | import android.hardware.display.DisplayedContentSamplingAttributes; |
Mathew Inwood | 679c15e | 2019-02-06 15:36:04 +0000 | [diff] [blame] | 46 | import android.os.Build; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 47 | import android.os.IBinder; |
Jorim Jaggi | 06975df | 2017-12-01 14:52:13 +0100 | [diff] [blame] | 48 | import android.os.Parcel; |
| 49 | import android.os.Parcelable; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 50 | import android.util.ArrayMap; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 51 | import android.util.Log; |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 52 | import android.util.SparseIntArray; |
Vishnu Nair | 04ab439 | 2018-01-10 11:00:06 -0800 | [diff] [blame] | 53 | import android.util.proto.ProtoOutputStream; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 54 | import android.view.Surface.OutOfResourcesException; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 55 | |
| 56 | import com.android.internal.annotations.GuardedBy; |
| 57 | |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 58 | import dalvik.system.CloseGuard; |
Vishnu Nair | 04ab439 | 2018-01-10 11:00:06 -0800 | [diff] [blame] | 59 | |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 60 | import libcore.util.NativeAllocationRegistry; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 61 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 62 | import java.io.Closeable; |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 63 | import java.nio.ByteBuffer; |
Evan Rosky | c12c9a3 | 2019-02-06 13:38:03 -0800 | [diff] [blame] | 64 | import java.nio.ByteOrder; |
Dan Gittik | 832b497 | 2019-02-13 18:17:47 +0000 | [diff] [blame] | 65 | import java.util.Objects; |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 66 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 67 | /** |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 68 | * Handle to an on-screen Surface managed by the system compositor. The SurfaceControl is |
| 69 | * a combination of a buffer source, and metadata about how to display the buffers. |
| 70 | * By constructing a {@link Surface} from this SurfaceControl you can submit buffers to be |
| 71 | * composited. Using {@link SurfaceControl.Transaction} you can manipulate various |
| 72 | * properties of how the buffer will be displayed on-screen. SurfaceControl's are |
| 73 | * arranged into a scene-graph like hierarchy, and as such any SurfaceControl may have |
| 74 | * a parent. Geometric properties like transform, crop, and Z-ordering will be inherited |
| 75 | * from the parent, as if the child were content in the parents buffer stream. |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 76 | */ |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 77 | public final class SurfaceControl implements Parcelable { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 78 | private static final String TAG = "SurfaceControl"; |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 79 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 80 | private static native long nativeCreate(SurfaceSession session, String name, |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 81 | int w, int h, int format, int flags, long parentObject, Parcel metadata) |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 82 | throws OutOfResourcesException; |
Jorim Jaggi | 06975df | 2017-12-01 14:52:13 +0100 | [diff] [blame] | 83 | private static native long nativeReadFromParcel(Parcel in); |
chaviw | beb7a0c | 2018-12-05 13:49:54 -0800 | [diff] [blame] | 84 | private static native long nativeCopyFromSurfaceControl(long nativeObject); |
Jorim Jaggi | 06975df | 2017-12-01 14:52:13 +0100 | [diff] [blame] | 85 | private static native void nativeWriteToParcel(long nativeObject, Parcel out); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 86 | private static native void nativeRelease(long nativeObject); |
| 87 | private static native void nativeDestroy(long nativeObject); |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 88 | private static native void nativeDisconnect(long nativeObject); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 89 | |
Peiyong Lin | e3e5efd | 2019-03-21 20:59:47 +0000 | [diff] [blame] | 90 | private static native ScreenshotGraphicBuffer nativeScreenshot(IBinder displayToken, |
Robert Carr | 5c52b13 | 2019-02-15 15:48:11 -0800 | [diff] [blame] | 91 | Rect sourceCrop, int width, int height, boolean useIdentityTransform, int rotation, |
| 92 | boolean captureSecureLayers); |
Peiyong Lin | 21e499a | 2019-04-03 16:37:46 -0700 | [diff] [blame] | 93 | private static native ScreenshotGraphicBuffer nativeCaptureLayers(IBinder displayToken, |
| 94 | IBinder layerHandleToken, Rect sourceCrop, float frameScale, IBinder[] excludeLayers); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 95 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 96 | private static native long nativeCreateTransaction(); |
| 97 | private static native long nativeGetNativeTransactionFinalizer(); |
| 98 | private static native void nativeApplyTransaction(long transactionObj, boolean sync); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 99 | private static native void nativeMergeTransaction(long transactionObj, |
| 100 | long otherTransactionObj); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 101 | private static native void nativeSetAnimationTransaction(long transactionObj); |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 102 | private static native void nativeSetEarlyWakeup(long transactionObj); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 103 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 104 | private static native void nativeSetLayer(long transactionObj, long nativeObject, int zorder); |
| 105 | private static native void nativeSetRelativeLayer(long transactionObj, long nativeObject, |
| 106 | IBinder relativeTo, int zorder); |
| 107 | private static native void nativeSetPosition(long transactionObj, long nativeObject, |
| 108 | float x, float y); |
| 109 | private static native void nativeSetGeometryAppliesWithResize(long transactionObj, |
| 110 | long nativeObject); |
| 111 | private static native void nativeSetSize(long transactionObj, long nativeObject, int w, int h); |
| 112 | private static native void nativeSetTransparentRegionHint(long transactionObj, |
| 113 | long nativeObject, Region region); |
| 114 | private static native void nativeSetAlpha(long transactionObj, long nativeObject, float alpha); |
| 115 | private static native void nativeSetMatrix(long transactionObj, long nativeObject, |
| 116 | float dsdx, float dtdx, |
Andrii Kulian | 283acd2 | 2017-08-03 04:03:51 -0700 | [diff] [blame] | 117 | float dtdy, float dsdy); |
Peiyong Lin | 52bb6b4 | 2018-10-01 11:40:50 -0700 | [diff] [blame] | 118 | private static native void nativeSetColorTransform(long transactionObj, long nativeObject, |
| 119 | float[] matrix, float[] translation); |
Peiyong Lin | f4f0f64 | 2019-03-01 14:36:05 -0800 | [diff] [blame] | 120 | private static native void nativeSetColorSpaceAgnostic(long transactionObj, long nativeObject, |
| 121 | boolean agnostic); |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 122 | private static native void nativeSetGeometry(long transactionObj, long nativeObject, |
| 123 | Rect sourceCrop, Rect dest, long orientation); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 124 | private static native void nativeSetColor(long transactionObj, long nativeObject, float[] color); |
| 125 | private static native void nativeSetFlags(long transactionObj, long nativeObject, |
| 126 | int flags, int mask); |
| 127 | private static native void nativeSetWindowCrop(long transactionObj, long nativeObject, |
| 128 | int l, int t, int r, int b); |
Lucas Dupin | ff9d6ab | 2018-10-16 18:05:50 -0700 | [diff] [blame] | 129 | private static native void nativeSetCornerRadius(long transactionObj, long nativeObject, |
| 130 | float cornerRadius); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 131 | private static native void nativeSetLayerStack(long transactionObj, long nativeObject, |
| 132 | int layerStack); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 133 | |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 134 | private static native boolean nativeClearContentFrameStats(long nativeObject); |
| 135 | private static native boolean nativeGetContentFrameStats(long nativeObject, WindowContentFrameStats outStats); |
| 136 | private static native boolean nativeClearAnimationFrameStats(); |
| 137 | private static native boolean nativeGetAnimationFrameStats(WindowAnimationFrameStats outStats); |
| 138 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 139 | private static native long[] nativeGetPhysicalDisplayIds(); |
| 140 | private static native IBinder nativeGetPhysicalDisplayToken(long physicalDisplayId); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 141 | private static native IBinder nativeCreateDisplay(String name, boolean secure); |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 142 | private static native void nativeDestroyDisplay(IBinder displayToken); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 143 | private static native void nativeSetDisplaySurface(long transactionObj, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 144 | IBinder displayToken, long nativeSurfaceObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 145 | private static native void nativeSetDisplayLayerStack(long transactionObj, |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 146 | IBinder displayToken, int layerStack); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 147 | private static native void nativeSetDisplayProjection(long transactionObj, |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 148 | IBinder displayToken, int orientation, |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 149 | int l, int t, int r, int b, |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 150 | int L, int T, int R, int B); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 151 | private static native void nativeSetDisplaySize(long transactionObj, IBinder displayToken, |
| 152 | int width, int height); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 153 | private static native SurfaceControl.PhysicalDisplayInfo[] nativeGetDisplayConfigs( |
| 154 | IBinder displayToken); |
Kevin DuBois | bf76b11b | 2018-09-04 09:14:15 -0700 | [diff] [blame] | 155 | private static native DisplayedContentSamplingAttributes |
| 156 | nativeGetDisplayedContentSamplingAttributes(IBinder displayToken); |
| 157 | private static native boolean nativeSetDisplayedContentSamplingEnabled(IBinder displayToken, |
| 158 | boolean enable, int componentMask, int maxFrames); |
| 159 | private static native DisplayedContentSample nativeGetDisplayedContentSample( |
| 160 | IBinder displayToken, long numFrames, long timestamp); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 161 | private static native int nativeGetActiveConfig(IBinder displayToken); |
| 162 | private static native boolean nativeSetActiveConfig(IBinder displayToken, int id); |
Ady Abraham | 6070ce1 | 2019-01-24 18:48:58 -0800 | [diff] [blame] | 163 | private static native boolean nativeSetAllowedDisplayConfigs(IBinder displayToken, |
| 164 | int[] allowedConfigs); |
Ady Abraham | 42f9a2fb | 2019-02-26 14:13:39 -0800 | [diff] [blame] | 165 | private static native int[] nativeGetAllowedDisplayConfigs(IBinder displayToken); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 166 | private static native int[] nativeGetDisplayColorModes(IBinder displayToken); |
Daniel Solomon | 10e3b33 | 2019-01-20 21:09:11 -0800 | [diff] [blame] | 167 | private static native SurfaceControl.DisplayPrimaries nativeGetDisplayNativePrimaries( |
| 168 | IBinder displayToken); |
Peiyong Lin | 5f4a568 | 2019-01-17 11:37:07 -0800 | [diff] [blame] | 169 | private static native int[] nativeGetCompositionDataspaces(); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 170 | private static native int nativeGetActiveColorMode(IBinder displayToken); |
| 171 | private static native boolean nativeSetActiveColorMode(IBinder displayToken, |
| 172 | int colorMode); |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 173 | private static native void nativeSetDisplayPowerMode( |
| 174 | IBinder displayToken, int mode); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 175 | private static native void nativeDeferTransactionUntil(long transactionObj, long nativeObject, |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 176 | IBinder handle, long frame); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 177 | private static native void nativeDeferTransactionUntilSurface(long transactionObj, |
| 178 | long nativeObject, |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 179 | long surfaceObject, long frame); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 180 | private static native void nativeReparentChildren(long transactionObj, long nativeObject, |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 181 | IBinder handle); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 182 | private static native void nativeReparent(long transactionObj, long nativeObject, |
Robert Carr | 10584fa | 2019-01-14 15:55:19 -0800 | [diff] [blame] | 183 | long newParentNativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 184 | private static native void nativeSeverChildren(long transactionObj, long nativeObject); |
| 185 | private static native void nativeSetOverrideScalingMode(long transactionObj, long nativeObject, |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 186 | int scalingMode); |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 187 | private static native IBinder nativeGetHandle(long nativeObject); |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 188 | private static native boolean nativeGetTransformToDisplayInverse(long nativeObject); |
| 189 | |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 190 | private static native Display.HdrCapabilities nativeGetHdrCapabilities(IBinder displayToken); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 191 | |
Robert Carr | 788f574 | 2018-07-30 17:46:45 -0700 | [diff] [blame] | 192 | private static native void nativeSetInputWindowInfo(long transactionObj, long nativeObject, |
| 193 | InputWindowHandle handle); |
chaviw | 59f532e | 2018-12-26 15:34:59 -0800 | [diff] [blame] | 194 | private static native void nativeTransferTouchFocus(long transactionObj, IBinder fromToken, |
| 195 | IBinder toToken); |
Peiyong Lin | 0ddb7d4 | 2019-01-16 13:25:09 -0800 | [diff] [blame] | 196 | private static native boolean nativeGetProtectedContentSupport(); |
Evan Rosky | b51e246 | 2019-04-03 19:27:18 -0700 | [diff] [blame] | 197 | private static native void nativeSetMetadata(long transactionObj, long nativeObject, int key, |
| 198 | Parcel data); |
chaviw | 319cd078 | 2019-02-14 11:00:23 -0800 | [diff] [blame] | 199 | private static native void nativeSyncInputWindows(long transactionObj); |
Dan Gittik | 832b497 | 2019-02-13 18:17:47 +0000 | [diff] [blame] | 200 | private static native boolean nativeGetDisplayBrightnessSupport(IBinder displayToken); |
| 201 | private static native boolean nativeSetDisplayBrightness(IBinder displayToken, |
| 202 | float brightness); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 203 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 204 | private final CloseGuard mCloseGuard = CloseGuard.get(); |
chaviw | beb7a0c | 2018-12-05 13:49:54 -0800 | [diff] [blame] | 205 | private String mName; |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 206 | long mNativeObject; // package visibility only for Surface.java access |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 207 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 208 | // TODO: Move this to native. |
| 209 | private final Object mSizeLock = new Object(); |
| 210 | @GuardedBy("mSizeLock") |
| 211 | private int mWidth; |
| 212 | @GuardedBy("mSizeLock") |
| 213 | private int mHeight; |
| 214 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 215 | static Transaction sGlobalTransaction; |
| 216 | static long sTransactionNestCount = 0; |
| 217 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 218 | /* flags used in constructor (keep in sync with ISurfaceComposerClient.h) */ |
| 219 | |
| 220 | /** |
| 221 | * Surface creation flag: Surface is created hidden |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 222 | * @hide |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 223 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 224 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 225 | public static final int HIDDEN = 0x00000004; |
| 226 | |
| 227 | /** |
| 228 | * Surface creation flag: The surface contains secure content, special |
| 229 | * measures will be taken to disallow the surface's content to be copied |
| 230 | * from another process. In particular, screenshots and VNC servers will |
| 231 | * be disabled, but other measures can take place, for instance the |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 232 | * surface might not be hardware accelerated. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 233 | * @hide |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 234 | */ |
| 235 | public static final int SECURE = 0x00000080; |
| 236 | |
| 237 | /** |
| 238 | * Surface creation flag: Creates a surface where color components are interpreted |
| 239 | * as "non pre-multiplied" by their alpha channel. Of course this flag is |
| 240 | * meaningless for surfaces without an alpha channel. By default |
| 241 | * surfaces are pre-multiplied, which means that each color component is |
| 242 | * already multiplied by its alpha value. In this case the blending |
| 243 | * equation used is: |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 244 | * <p> |
| 245 | * <code>DEST = SRC + DEST * (1-SRC_ALPHA)</code> |
| 246 | * <p> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 247 | * By contrast, non pre-multiplied surfaces use the following equation: |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 248 | * <p> |
| 249 | * <code>DEST = SRC * SRC_ALPHA * DEST * (1-SRC_ALPHA)</code> |
| 250 | * <p> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 251 | * pre-multiplied surfaces must always be used if transparent pixels are |
| 252 | * composited on top of each-other into the surface. A pre-multiplied |
| 253 | * surface can never lower the value of the alpha component of a given |
| 254 | * pixel. |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 255 | * <p> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 256 | * In some rare situations, a non pre-multiplied surface is preferable. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 257 | * @hide |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 258 | */ |
| 259 | public static final int NON_PREMULTIPLIED = 0x00000100; |
| 260 | |
| 261 | /** |
| 262 | * Surface creation flag: Indicates that the surface must be considered opaque, |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 263 | * even if its pixel format contains an alpha channel. This can be useful if an |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 264 | * application needs full RGBA 8888 support for instance but will |
| 265 | * still draw every pixel opaque. |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 266 | * <p> |
| 267 | * This flag is ignored if setAlpha() is used to make the surface non-opaque. |
| 268 | * Combined effects are (assuming a buffer format with an alpha channel): |
| 269 | * <ul> |
| 270 | * <li>OPAQUE + alpha(1.0) == opaque composition |
| 271 | * <li>OPAQUE + alpha(0.x) == blended composition |
| 272 | * <li>!OPAQUE + alpha(1.0) == blended composition |
| 273 | * <li>!OPAQUE + alpha(0.x) == blended composition |
| 274 | * </ul> |
| 275 | * If the underlying buffer lacks an alpha channel, the OPAQUE flag is effectively |
| 276 | * set automatically. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 277 | * @hide |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 278 | */ |
| 279 | public static final int OPAQUE = 0x00000400; |
| 280 | |
| 281 | /** |
| 282 | * Surface creation flag: Application requires a hardware-protected path to an |
| 283 | * external display sink. If a hardware-protected path is not available, |
| 284 | * then this surface will not be displayed on the external sink. |
| 285 | * |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 286 | * @hide |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 287 | */ |
| 288 | public static final int PROTECTED_APP = 0x00000800; |
| 289 | |
| 290 | // 0x1000 is reserved for an independent DRM protected flag in framework |
| 291 | |
| 292 | /** |
Riley Andrews | 68eccda | 2014-07-07 11:47:35 -0700 | [diff] [blame] | 293 | * Surface creation flag: Window represents a cursor glyph. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 294 | * @hide |
Riley Andrews | 68eccda | 2014-07-07 11:47:35 -0700 | [diff] [blame] | 295 | */ |
| 296 | public static final int CURSOR_WINDOW = 0x00002000; |
| 297 | |
| 298 | /** |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 299 | * Surface creation flag: Creates a normal surface. |
| 300 | * This is the default. |
| 301 | * |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 302 | * @hide |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 303 | */ |
| 304 | public static final int FX_SURFACE_NORMAL = 0x00000000; |
| 305 | |
| 306 | /** |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 307 | * Surface creation flag: Creates a Dim surface. |
| 308 | * Everything behind this surface is dimmed by the amount specified |
| 309 | * in {@link #setAlpha}. It is an error to lock a Dim surface, since it |
| 310 | * doesn't have a backing store. |
| 311 | * |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 312 | * @hide |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 313 | */ |
| 314 | public static final int FX_SURFACE_DIM = 0x00020000; |
| 315 | |
| 316 | /** |
Robert Carr | b6cd643 | 2018-08-13 13:01:47 -0700 | [diff] [blame] | 317 | * Surface creation flag: Creates a container surface. |
| 318 | * This surface will have no buffers and will only be used |
| 319 | * as a container for other surfaces, or for its InputInfo. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 320 | * @hide |
Robert Carr | b6cd643 | 2018-08-13 13:01:47 -0700 | [diff] [blame] | 321 | */ |
| 322 | public static final int FX_SURFACE_CONTAINER = 0x00080000; |
| 323 | |
| 324 | /** |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 325 | * Mask used for FX values above. |
| 326 | * |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 327 | * @hide |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 328 | */ |
| 329 | public static final int FX_SURFACE_MASK = 0x000F0000; |
| 330 | |
| 331 | /* flags used with setFlags() (keep in sync with ISurfaceComposer.h) */ |
| 332 | |
| 333 | /** |
| 334 | * Surface flag: Hide the surface. |
| 335 | * Equivalent to calling hide(). |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 336 | * Updates the value set during Surface creation (see {@link #HIDDEN}). |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 337 | */ |
Andy McFadden | 40b9ef1 | 2014-01-30 13:44:47 -0800 | [diff] [blame] | 338 | private static final int SURFACE_HIDDEN = 0x01; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 339 | |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 340 | /** |
| 341 | * Surface flag: composite without blending when possible. |
| 342 | * Updates the value set during Surface creation (see {@link #OPAQUE}). |
| 343 | */ |
Andy McFadden | 40b9ef1 | 2014-01-30 13:44:47 -0800 | [diff] [blame] | 344 | private static final int SURFACE_OPAQUE = 0x02; |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 345 | |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 346 | // Display power modes. |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 347 | /** |
| 348 | * Display power mode off: used while blanking the screen. |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 349 | * Use only with {@link SurfaceControl#setDisplayPowerMode}. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 350 | * @hide |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 351 | */ |
| 352 | public static final int POWER_MODE_OFF = 0; |
| 353 | |
| 354 | /** |
| 355 | * Display power mode doze: used while putting the screen into low power mode. |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 356 | * Use only with {@link SurfaceControl#setDisplayPowerMode}. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 357 | * @hide |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 358 | */ |
| 359 | public static final int POWER_MODE_DOZE = 1; |
| 360 | |
| 361 | /** |
| 362 | * Display power mode normal: used while unblanking the screen. |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 363 | * Use only with {@link SurfaceControl#setDisplayPowerMode}. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 364 | * @hide |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 365 | */ |
| 366 | public static final int POWER_MODE_NORMAL = 2; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 367 | |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 368 | /** |
| 369 | * Display power mode doze: used while putting the screen into a suspended |
| 370 | * low power mode. Use only with {@link SurfaceControl#setDisplayPowerMode}. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 371 | * @hide |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 372 | */ |
| 373 | public static final int POWER_MODE_DOZE_SUSPEND = 3; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 374 | |
| 375 | /** |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 376 | * Display power mode on: used while putting the screen into a suspended |
| 377 | * full power mode. Use only with {@link SurfaceControl#setDisplayPowerMode}. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 378 | * @hide |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 379 | */ |
| 380 | public static final int POWER_MODE_ON_SUSPEND = 4; |
| 381 | |
| 382 | /** |
Robert Carr | 132c9f5 | 2017-07-31 17:02:30 -0700 | [diff] [blame] | 383 | * A value for windowType used to indicate that the window should be omitted from screenshots |
| 384 | * and display mirroring. A temporary workaround until we express such things with |
| 385 | * the hierarchy. |
| 386 | * TODO: b/64227542 |
| 387 | * @hide |
| 388 | */ |
| 389 | public static final int WINDOW_TYPE_DONT_SCREENSHOT = 441731; |
| 390 | |
Peiyong Lin | 5f4a568 | 2019-01-17 11:37:07 -0800 | [diff] [blame] | 391 | /** |
| 392 | * internal representation of how to interpret pixel value, used only to convert to ColorSpace. |
| 393 | */ |
| 394 | private static final int INTERNAL_DATASPACE_SRGB = 142671872; |
| 395 | private static final int INTERNAL_DATASPACE_DISPLAY_P3 = 143261696; |
| 396 | private static final int INTERNAL_DATASPACE_SCRGB = 411107328; |
| 397 | |
Robert Carr | eb344c7 | 2019-01-07 18:35:30 -0800 | [diff] [blame] | 398 | private void assignNativeObject(long nativeObject) { |
| 399 | if (mNativeObject != 0) { |
| 400 | release(); |
| 401 | } |
| 402 | mNativeObject = nativeObject; |
| 403 | } |
| 404 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 405 | /** |
| 406 | * @hide |
| 407 | */ |
chaviw | beb7a0c | 2018-12-05 13:49:54 -0800 | [diff] [blame] | 408 | public void copyFrom(SurfaceControl other) { |
| 409 | mName = other.mName; |
| 410 | mWidth = other.mWidth; |
| 411 | mHeight = other.mHeight; |
Robert Carr | eb344c7 | 2019-01-07 18:35:30 -0800 | [diff] [blame] | 412 | assignNativeObject(nativeCopyFromSurfaceControl(other.mNativeObject)); |
chaviw | beb7a0c | 2018-12-05 13:49:54 -0800 | [diff] [blame] | 413 | } |
| 414 | |
Robert Carr | 132c9f5 | 2017-07-31 17:02:30 -0700 | [diff] [blame] | 415 | /** |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 416 | * owner UID. |
| 417 | * @hide |
| 418 | */ |
| 419 | public static final int METADATA_OWNER_UID = 1; |
| 420 | |
| 421 | /** |
| 422 | * Window type as per {@link WindowManager.LayoutParams}. |
| 423 | * @hide |
| 424 | */ |
| 425 | public static final int METADATA_WINDOW_TYPE = 2; |
| 426 | |
| 427 | /** |
Evan Rosky | 9020c07 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 428 | * Task id to allow association between surfaces and task. |
| 429 | * @hide |
| 430 | */ |
| 431 | public static final int METADATA_TASK_ID = 3; |
| 432 | |
| 433 | /** |
Peiyong Lin | e3e5efd | 2019-03-21 20:59:47 +0000 | [diff] [blame] | 434 | * A wrapper around GraphicBuffer that contains extra information about how to |
| 435 | * interpret the screenshot GraphicBuffer. |
| 436 | * @hide |
| 437 | */ |
| 438 | public static class ScreenshotGraphicBuffer { |
| 439 | private final GraphicBuffer mGraphicBuffer; |
| 440 | private final ColorSpace mColorSpace; |
Robert Carr | 66b5664f | 2019-04-02 14:18:56 -0700 | [diff] [blame] | 441 | private final boolean mContainsSecureLayers; |
Peiyong Lin | e3e5efd | 2019-03-21 20:59:47 +0000 | [diff] [blame] | 442 | |
Robert Carr | 66b5664f | 2019-04-02 14:18:56 -0700 | [diff] [blame] | 443 | public ScreenshotGraphicBuffer(GraphicBuffer graphicBuffer, ColorSpace colorSpace, |
| 444 | boolean containsSecureLayers) { |
Peiyong Lin | e3e5efd | 2019-03-21 20:59:47 +0000 | [diff] [blame] | 445 | mGraphicBuffer = graphicBuffer; |
| 446 | mColorSpace = colorSpace; |
Robert Carr | 66b5664f | 2019-04-02 14:18:56 -0700 | [diff] [blame] | 447 | mContainsSecureLayers = containsSecureLayers; |
Peiyong Lin | e3e5efd | 2019-03-21 20:59:47 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | /** |
| 451 | * Create ScreenshotGraphicBuffer from existing native GraphicBuffer object. |
| 452 | * @param width The width in pixels of the buffer |
| 453 | * @param height The height in pixels of the buffer |
| 454 | * @param format The format of each pixel as specified in {@link PixelFormat} |
| 455 | * @param usage Hint indicating how the buffer will be used |
| 456 | * @param unwrappedNativeObject The native object of GraphicBuffer |
| 457 | * @param namedColorSpace Integer value of a named color space {@link ColorSpace.Named} |
Robert Carr | 66b5664f | 2019-04-02 14:18:56 -0700 | [diff] [blame] | 458 | * @param containsSecureLayer Indicates whether this graphic buffer contains captured contents |
| 459 | * of secure layers, in which case the screenshot should not be persisted. |
Peiyong Lin | e3e5efd | 2019-03-21 20:59:47 +0000 | [diff] [blame] | 460 | */ |
| 461 | private static ScreenshotGraphicBuffer createFromNative(int width, int height, int format, |
Robert Carr | 66b5664f | 2019-04-02 14:18:56 -0700 | [diff] [blame] | 462 | int usage, long unwrappedNativeObject, int namedColorSpace, |
| 463 | boolean containsSecureLayers) { |
Peiyong Lin | e3e5efd | 2019-03-21 20:59:47 +0000 | [diff] [blame] | 464 | GraphicBuffer graphicBuffer = GraphicBuffer.createFromExisting(width, height, format, |
| 465 | usage, unwrappedNativeObject); |
| 466 | ColorSpace colorSpace = ColorSpace.get(ColorSpace.Named.values()[namedColorSpace]); |
Robert Carr | 66b5664f | 2019-04-02 14:18:56 -0700 | [diff] [blame] | 467 | return new ScreenshotGraphicBuffer(graphicBuffer, colorSpace, containsSecureLayers); |
Peiyong Lin | e3e5efd | 2019-03-21 20:59:47 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | public ColorSpace getColorSpace() { |
| 471 | return mColorSpace; |
| 472 | } |
| 473 | |
| 474 | public GraphicBuffer getGraphicBuffer() { |
| 475 | return mGraphicBuffer; |
| 476 | } |
Robert Carr | 66b5664f | 2019-04-02 14:18:56 -0700 | [diff] [blame] | 477 | |
| 478 | public boolean containsSecureLayers() { |
| 479 | return mContainsSecureLayers; |
| 480 | } |
Peiyong Lin | e3e5efd | 2019-03-21 20:59:47 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | /** |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 484 | * Builder class for {@link SurfaceControl} objects. |
Robert Carr | 29fe58a | 2019-03-11 15:25:16 -0700 | [diff] [blame] | 485 | * |
| 486 | * By default the surface will be hidden, and have "unset" bounds, meaning it can |
| 487 | * be as large as the bounds of its parent if a buffer or child so requires. |
| 488 | * |
| 489 | * It is necessary to set at least a name via {@link Builder#setName} |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 490 | */ |
| 491 | public static class Builder { |
| 492 | private SurfaceSession mSession; |
| 493 | private int mFlags = HIDDEN; |
| 494 | private int mWidth; |
| 495 | private int mHeight; |
| 496 | private int mFormat = PixelFormat.OPAQUE; |
| 497 | private String mName; |
| 498 | private SurfaceControl mParent; |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 499 | private SparseIntArray mMetadata; |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 500 | |
| 501 | /** |
| 502 | * Begin building a SurfaceControl with a given {@link SurfaceSession}. |
| 503 | * |
| 504 | * @param session The {@link SurfaceSession} with which to eventually construct the surface. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 505 | * @hide |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 506 | */ |
| 507 | public Builder(SurfaceSession session) { |
| 508 | mSession = session; |
| 509 | } |
| 510 | |
| 511 | /** |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 512 | * Begin building a SurfaceControl. |
| 513 | */ |
| 514 | public Builder() { |
| 515 | } |
| 516 | |
| 517 | /** |
| 518 | * Construct a new {@link SurfaceControl} with the set parameters. The builder |
| 519 | * remains valid. |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 520 | */ |
Robert Carr | da1d242 | 2019-03-07 15:54:37 -0800 | [diff] [blame] | 521 | @NonNull |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 522 | public SurfaceControl build() { |
Vishnu Nair | e86bd98 | 2018-11-28 13:23:17 -0800 | [diff] [blame] | 523 | if (mWidth < 0 || mHeight < 0) { |
Robert Carr | 29fe58a | 2019-03-11 15:25:16 -0700 | [diff] [blame] | 524 | throw new IllegalStateException( |
Vishnu Nair | e86bd98 | 2018-11-28 13:23:17 -0800 | [diff] [blame] | 525 | "width and height must be positive or unset"); |
| 526 | } |
| 527 | if ((mWidth > 0 || mHeight > 0) && (isColorLayerSet() || isContainerLayerSet())) { |
Robert Carr | 29fe58a | 2019-03-11 15:25:16 -0700 | [diff] [blame] | 528 | throw new IllegalStateException( |
Vishnu Nair | e86bd98 | 2018-11-28 13:23:17 -0800 | [diff] [blame] | 529 | "Only buffer layers can set a valid buffer size."); |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 530 | } |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 531 | return new SurfaceControl( |
| 532 | mSession, mName, mWidth, mHeight, mFormat, mFlags, mParent, mMetadata); |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | /** |
| 536 | * Set a debugging-name for the SurfaceControl. |
| 537 | * |
| 538 | * @param name A name to identify the Surface in debugging. |
| 539 | */ |
Robert Carr | da1d242 | 2019-03-07 15:54:37 -0800 | [diff] [blame] | 540 | @NonNull |
| 541 | public Builder setName(@NonNull String name) { |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 542 | mName = name; |
| 543 | return this; |
| 544 | } |
| 545 | |
| 546 | /** |
| 547 | * Set the initial size of the controlled surface's buffers in pixels. |
| 548 | * |
| 549 | * @param width The buffer width in pixels. |
| 550 | * @param height The buffer height in pixels. |
| 551 | */ |
Robert Carr | da1d242 | 2019-03-07 15:54:37 -0800 | [diff] [blame] | 552 | @NonNull |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 553 | public Builder setBufferSize(@IntRange(from = 0) int width, |
| 554 | @IntRange(from = 0) int height) { |
Vishnu Nair | e86bd98 | 2018-11-28 13:23:17 -0800 | [diff] [blame] | 555 | if (width < 0 || height < 0) { |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 556 | throw new IllegalArgumentException( |
| 557 | "width and height must be positive"); |
| 558 | } |
| 559 | mWidth = width; |
| 560 | mHeight = height; |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 561 | // set this as a buffer layer since we are specifying a buffer size. |
| 562 | return setFlags(FX_SURFACE_NORMAL, FX_SURFACE_MASK); |
| 563 | } |
| 564 | |
| 565 | /** |
| 566 | * Set the initial size of the controlled surface's buffers in pixels. |
| 567 | */ |
| 568 | private void unsetBufferSize() { |
| 569 | mWidth = 0; |
| 570 | mHeight = 0; |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | /** |
| 574 | * Set the pixel format of the controlled surface's buffers, using constants from |
| 575 | * {@link android.graphics.PixelFormat}. |
| 576 | */ |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 577 | @NonNull |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 578 | public Builder setFormat(@PixelFormat.Format int format) { |
| 579 | mFormat = format; |
| 580 | return this; |
| 581 | } |
| 582 | |
| 583 | /** |
| 584 | * Specify if the app requires a hardware-protected path to |
| 585 | * an external display sync. If protected content is enabled, but |
| 586 | * such a path is not available, then the controlled Surface will |
| 587 | * not be displayed. |
| 588 | * |
| 589 | * @param protectedContent Whether to require a protected sink. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 590 | * @hide |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 591 | */ |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 592 | @NonNull |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 593 | public Builder setProtected(boolean protectedContent) { |
| 594 | if (protectedContent) { |
| 595 | mFlags |= PROTECTED_APP; |
| 596 | } else { |
| 597 | mFlags &= ~PROTECTED_APP; |
| 598 | } |
| 599 | return this; |
| 600 | } |
| 601 | |
| 602 | /** |
| 603 | * Specify whether the Surface contains secure content. If true, the system |
| 604 | * will prevent the surfaces content from being copied by another process. In |
| 605 | * particular screenshots and VNC servers will be disabled. This is however |
| 606 | * not a complete prevention of readback as {@link #setProtected}. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 607 | * @hide |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 608 | */ |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 609 | @NonNull |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 610 | public Builder setSecure(boolean secure) { |
| 611 | if (secure) { |
| 612 | mFlags |= SECURE; |
| 613 | } else { |
| 614 | mFlags &= ~SECURE; |
| 615 | } |
| 616 | return this; |
| 617 | } |
| 618 | |
| 619 | /** |
| 620 | * Indicates whether the surface must be considered opaque, |
| 621 | * even if its pixel format is set to translucent. This can be useful if an |
| 622 | * application needs full RGBA 8888 support for instance but will |
| 623 | * still draw every pixel opaque. |
| 624 | * <p> |
| 625 | * This flag only determines whether opacity will be sampled from the alpha channel. |
| 626 | * Plane-alpha from calls to setAlpha() can still result in blended composition |
| 627 | * regardless of the opaque setting. |
| 628 | * |
| 629 | * Combined effects are (assuming a buffer format with an alpha channel): |
| 630 | * <ul> |
| 631 | * <li>OPAQUE + alpha(1.0) == opaque composition |
| 632 | * <li>OPAQUE + alpha(0.x) == blended composition |
| 633 | * <li>OPAQUE + alpha(0.0) == no composition |
| 634 | * <li>!OPAQUE + alpha(1.0) == blended composition |
| 635 | * <li>!OPAQUE + alpha(0.x) == blended composition |
| 636 | * <li>!OPAQUE + alpha(0.0) == no composition |
| 637 | * </ul> |
| 638 | * If the underlying buffer lacks an alpha channel, it is as if setOpaque(true) |
| 639 | * were set automatically. |
| 640 | * @param opaque Whether the Surface is OPAQUE. |
| 641 | */ |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 642 | @NonNull |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 643 | public Builder setOpaque(boolean opaque) { |
| 644 | if (opaque) { |
| 645 | mFlags |= OPAQUE; |
| 646 | } else { |
| 647 | mFlags &= ~OPAQUE; |
| 648 | } |
| 649 | return this; |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * Set a parent surface for our new SurfaceControl. |
| 654 | * |
| 655 | * Child surfaces are constrained to the onscreen region of their parent. |
| 656 | * Furthermore they stack relatively in Z order, and inherit the transformation |
| 657 | * of the parent. |
| 658 | * |
| 659 | * @param parent The parent control. |
| 660 | */ |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 661 | @NonNull |
| 662 | public Builder setParent(@Nullable SurfaceControl parent) { |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 663 | mParent = parent; |
| 664 | return this; |
| 665 | } |
| 666 | |
| 667 | /** |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 668 | * Sets a metadata int. |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 669 | * |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 670 | * @param key metadata key |
| 671 | * @param data associated data |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 672 | * @hide |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 673 | */ |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 674 | public Builder setMetadata(int key, int data) { |
| 675 | if (mMetadata == null) { |
| 676 | mMetadata = new SparseIntArray(); |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 677 | } |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 678 | mMetadata.put(key, data); |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 679 | return this; |
| 680 | } |
| 681 | |
| 682 | /** |
| 683 | * Indicate whether a 'ColorLayer' is to be constructed. |
| 684 | * |
| 685 | * Color layers will not have an associated BufferQueue and will instead always render a |
| 686 | * solid color (that is, solid before plane alpha). Currently that color is black. |
| 687 | * |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 688 | * @hide |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 689 | */ |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 690 | public Builder setColorLayer() { |
| 691 | unsetBufferSize(); |
| 692 | return setFlags(FX_SURFACE_DIM, FX_SURFACE_MASK); |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 693 | } |
| 694 | |
Vishnu Nair | e86bd98 | 2018-11-28 13:23:17 -0800 | [diff] [blame] | 695 | private boolean isColorLayerSet() { |
| 696 | return (mFlags & FX_SURFACE_DIM) == FX_SURFACE_DIM; |
| 697 | } |
| 698 | |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 699 | /** |
Robert Carr | b6cd643 | 2018-08-13 13:01:47 -0700 | [diff] [blame] | 700 | * Indicates whether a 'ContainerLayer' is to be constructed. |
| 701 | * |
| 702 | * Container layers will not be rendered in any fashion and instead are used |
| 703 | * as a parent of renderable layers. |
| 704 | * |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 705 | * @hide |
Robert Carr | b6cd643 | 2018-08-13 13:01:47 -0700 | [diff] [blame] | 706 | */ |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 707 | public Builder setContainerLayer() { |
| 708 | unsetBufferSize(); |
| 709 | return setFlags(FX_SURFACE_CONTAINER, FX_SURFACE_MASK); |
Robert Carr | b6cd643 | 2018-08-13 13:01:47 -0700 | [diff] [blame] | 710 | } |
| 711 | |
Vishnu Nair | e86bd98 | 2018-11-28 13:23:17 -0800 | [diff] [blame] | 712 | private boolean isContainerLayerSet() { |
| 713 | return (mFlags & FX_SURFACE_CONTAINER) == FX_SURFACE_CONTAINER; |
| 714 | } |
| 715 | |
Robert Carr | b6cd643 | 2018-08-13 13:01:47 -0700 | [diff] [blame] | 716 | /** |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 717 | * Set 'Surface creation flags' such as {@link #HIDDEN}, {@link #SECURE}. |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 718 | * |
| 719 | * TODO: Finish conversion to individual builder methods? |
| 720 | * @param flags The combined flags |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 721 | * @hide |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 722 | */ |
| 723 | public Builder setFlags(int flags) { |
| 724 | mFlags = flags; |
| 725 | return this; |
| 726 | } |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 727 | |
| 728 | private Builder setFlags(int flags, int mask) { |
| 729 | mFlags = (mFlags & ~mask) | flags; |
| 730 | return this; |
| 731 | } |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | /** |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 735 | * Create a surface with a name. |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 736 | * <p> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 737 | * The surface creation flags specify what kind of surface to create and |
| 738 | * certain options such as whether the surface can be assumed to be opaque |
| 739 | * and whether it should be initially hidden. Surfaces should always be |
| 740 | * created with the {@link #HIDDEN} flag set to ensure that they are not |
| 741 | * made visible prematurely before all of the surface's properties have been |
| 742 | * configured. |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 743 | * <p> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 744 | * Good practice is to first create the surface with the {@link #HIDDEN} flag |
| 745 | * specified, open a transaction, set the surface layer, layer stack, alpha, |
| 746 | * and position, call {@link #show} if appropriate, and close the transaction. |
Vishnu Nair | d454442d | 2018-11-13 13:51:01 -0800 | [diff] [blame] | 747 | * <p> |
| 748 | * Bounds of the surface is determined by its crop and its buffer size. If the |
| 749 | * surface has no buffer or crop, the surface is boundless and only constrained |
| 750 | * by the size of its parent bounds. |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 751 | * |
| 752 | * @param session The surface session, must not be null. |
| 753 | * @param name The surface name, must not be null. |
| 754 | * @param w The surface initial width. |
| 755 | * @param h The surface initial height. |
| 756 | * @param flags The surface creation flags. Should always include {@link #HIDDEN} |
| 757 | * in the creation flags. |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 758 | * @param metadata Initial metadata. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 759 | * |
| 760 | * @throws throws OutOfResourcesException If the SurfaceControl cannot be created. |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 761 | */ |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 762 | private SurfaceControl(SurfaceSession session, String name, int w, int h, int format, int flags, |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 763 | SurfaceControl parent, SparseIntArray metadata) |
Robert Carr | b0f3936 | 2018-03-14 13:52:25 -0700 | [diff] [blame] | 764 | throws OutOfResourcesException, IllegalArgumentException { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 765 | if (name == null) { |
| 766 | throw new IllegalArgumentException("name must not be null"); |
| 767 | } |
| 768 | |
| 769 | if ((flags & SurfaceControl.HIDDEN) == 0) { |
| 770 | Log.w(TAG, "Surfaces should always be created with the HIDDEN flag set " |
| 771 | + "to ensure that they are not made visible prematurely before " |
| 772 | + "all of the surface's properties have been configured. " |
| 773 | + "Set the other properties and make the surface visible within " |
| 774 | + "a transaction. New surface name: " + name, |
| 775 | new Throwable()); |
| 776 | } |
| 777 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 778 | mName = name; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 779 | mWidth = w; |
| 780 | mHeight = h; |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 781 | Parcel metaParcel = Parcel.obtain(); |
| 782 | try { |
| 783 | if (metadata != null && metadata.size() > 0) { |
| 784 | metaParcel.writeInt(metadata.size()); |
| 785 | for (int i = 0; i < metadata.size(); ++i) { |
| 786 | metaParcel.writeInt(metadata.keyAt(i)); |
| 787 | metaParcel.writeByteArray( |
Evan Rosky | c12c9a3 | 2019-02-06 13:38:03 -0800 | [diff] [blame] | 788 | ByteBuffer.allocate(4).order(ByteOrder.nativeOrder()) |
| 789 | .putInt(metadata.valueAt(i)).array()); |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 790 | } |
Evan Rosky | c12c9a3 | 2019-02-06 13:38:03 -0800 | [diff] [blame] | 791 | metaParcel.setDataPosition(0); |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 792 | } |
| 793 | mNativeObject = nativeCreate(session, name, w, h, format, flags, |
| 794 | parent != null ? parent.mNativeObject : 0, metaParcel); |
| 795 | } finally { |
| 796 | metaParcel.recycle(); |
| 797 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 798 | if (mNativeObject == 0) { |
| 799 | throw new OutOfResourcesException( |
| 800 | "Couldn't allocate SurfaceControl native object"); |
| 801 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 802 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 803 | mCloseGuard.open("release"); |
| 804 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 805 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 806 | /** This is a transfer constructor, useful for transferring a live SurfaceControl native |
| 807 | * object to another Java wrapper which could have some different behavior, e.g. |
| 808 | * event logging. |
| 809 | * @hide |
| 810 | */ |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 811 | public SurfaceControl(SurfaceControl other) { |
| 812 | mName = other.mName; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 813 | mWidth = other.mWidth; |
| 814 | mHeight = other.mHeight; |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 815 | mNativeObject = other.mNativeObject; |
| 816 | other.mCloseGuard.close(); |
| 817 | other.mNativeObject = 0; |
| 818 | mCloseGuard.open("release"); |
| 819 | } |
| 820 | |
Jorim Jaggi | 06975df | 2017-12-01 14:52:13 +0100 | [diff] [blame] | 821 | private SurfaceControl(Parcel in) { |
chaviw | beb7a0c | 2018-12-05 13:49:54 -0800 | [diff] [blame] | 822 | readFromParcel(in); |
| 823 | mCloseGuard.open("release"); |
| 824 | } |
| 825 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 826 | /** |
| 827 | * @hide |
| 828 | */ |
chaviw | beb7a0c | 2018-12-05 13:49:54 -0800 | [diff] [blame] | 829 | public SurfaceControl() { |
| 830 | mCloseGuard.open("release"); |
| 831 | } |
| 832 | |
| 833 | public void readFromParcel(Parcel in) { |
| 834 | if (in == null) { |
| 835 | throw new IllegalArgumentException("source must not be null"); |
| 836 | } |
| 837 | |
Jorim Jaggi | 06975df | 2017-12-01 14:52:13 +0100 | [diff] [blame] | 838 | mName = in.readString(); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 839 | mWidth = in.readInt(); |
| 840 | mHeight = in.readInt(); |
Robert Carr | 5fea55b | 2018-12-10 13:05:52 -0800 | [diff] [blame] | 841 | |
Robert Carr | eb344c7 | 2019-01-07 18:35:30 -0800 | [diff] [blame] | 842 | long object = 0; |
Robert Carr | 5fea55b | 2018-12-10 13:05:52 -0800 | [diff] [blame] | 843 | if (in.readInt() != 0) { |
Robert Carr | eb344c7 | 2019-01-07 18:35:30 -0800 | [diff] [blame] | 844 | object = nativeReadFromParcel(in); |
Jorim Jaggi | 06975df | 2017-12-01 14:52:13 +0100 | [diff] [blame] | 845 | } |
Robert Carr | eb344c7 | 2019-01-07 18:35:30 -0800 | [diff] [blame] | 846 | assignNativeObject(object); |
Jorim Jaggi | 06975df | 2017-12-01 14:52:13 +0100 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | @Override |
| 850 | public int describeContents() { |
| 851 | return 0; |
| 852 | } |
| 853 | |
| 854 | @Override |
| 855 | public void writeToParcel(Parcel dest, int flags) { |
| 856 | dest.writeString(mName); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 857 | dest.writeInt(mWidth); |
| 858 | dest.writeInt(mHeight); |
Robert Carr | 5fea55b | 2018-12-10 13:05:52 -0800 | [diff] [blame] | 859 | if (mNativeObject == 0) { |
| 860 | dest.writeInt(0); |
| 861 | } else { |
| 862 | dest.writeInt(1); |
| 863 | } |
Jorim Jaggi | 06975df | 2017-12-01 14:52:13 +0100 | [diff] [blame] | 864 | nativeWriteToParcel(mNativeObject, dest); |
Robert Carr | 5fea55b | 2018-12-10 13:05:52 -0800 | [diff] [blame] | 865 | |
| 866 | if ((flags & Parcelable.PARCELABLE_WRITE_RETURN_VALUE) != 0) { |
| 867 | release(); |
| 868 | } |
Jorim Jaggi | 06975df | 2017-12-01 14:52:13 +0100 | [diff] [blame] | 869 | } |
| 870 | |
Vishnu Nair | 04ab439 | 2018-01-10 11:00:06 -0800 | [diff] [blame] | 871 | /** |
| 872 | * Write to a protocol buffer output stream. Protocol buffer message definition is at {@link |
| 873 | * android.view.SurfaceControlProto}. |
| 874 | * |
| 875 | * @param proto Stream to write the SurfaceControl object to. |
| 876 | * @param fieldId Field Id of the SurfaceControl as defined in the parent message. |
| 877 | * @hide |
| 878 | */ |
| 879 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 880 | final long token = proto.start(fieldId); |
| 881 | proto.write(HASH_CODE, System.identityHashCode(this)); |
| 882 | proto.write(NAME, mName); |
| 883 | proto.end(token); |
| 884 | } |
| 885 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 886 | public static final @android.annotation.NonNull Creator<SurfaceControl> CREATOR |
Jorim Jaggi | 06975df | 2017-12-01 14:52:13 +0100 | [diff] [blame] | 887 | = new Creator<SurfaceControl>() { |
| 888 | public SurfaceControl createFromParcel(Parcel in) { |
| 889 | return new SurfaceControl(in); |
| 890 | } |
| 891 | |
| 892 | public SurfaceControl[] newArray(int size) { |
| 893 | return new SurfaceControl[size]; |
| 894 | } |
| 895 | }; |
| 896 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 897 | /** |
| 898 | * @hide |
| 899 | */ |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 900 | @Override |
| 901 | protected void finalize() throws Throwable { |
| 902 | try { |
| 903 | if (mCloseGuard != null) { |
| 904 | mCloseGuard.warnIfOpen(); |
| 905 | } |
| 906 | if (mNativeObject != 0) { |
| 907 | nativeRelease(mNativeObject); |
| 908 | } |
| 909 | } finally { |
| 910 | super.finalize(); |
| 911 | } |
| 912 | } |
| 913 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 914 | /** |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 915 | * Release the local reference to the server-side surface. The surface |
| 916 | * may continue to exist on-screen as long as its parent continues |
| 917 | * to exist. To explicitly remove a surface from the screen use |
Robert Carr | 29fe58a | 2019-03-11 15:25:16 -0700 | [diff] [blame] | 918 | * {@link Transaction#reparent} with a null-parent. After release, |
| 919 | * {@link #isValid} will return false and other methods will throw |
| 920 | * an exception. |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 921 | * |
| 922 | * Always call release() when you're done with a SurfaceControl. |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 923 | */ |
| 924 | public void release() { |
| 925 | if (mNativeObject != 0) { |
| 926 | nativeRelease(mNativeObject); |
| 927 | mNativeObject = 0; |
| 928 | } |
| 929 | mCloseGuard.close(); |
| 930 | } |
| 931 | |
| 932 | /** |
Robert Carr | 5ea304d | 2019-02-04 16:04:55 -0800 | [diff] [blame] | 933 | * Release the local resources like {@link #release} but also |
| 934 | * remove the Surface from the screen. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 935 | * @hide |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 936 | */ |
Robert Carr | 5ea304d | 2019-02-04 16:04:55 -0800 | [diff] [blame] | 937 | public void remove() { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 938 | if (mNativeObject != 0) { |
| 939 | nativeDestroy(mNativeObject); |
| 940 | mNativeObject = 0; |
| 941 | } |
| 942 | mCloseGuard.close(); |
| 943 | } |
| 944 | |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 945 | /** |
| 946 | * Disconnect any client still connected to the surface. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 947 | * @hide |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 948 | */ |
| 949 | public void disconnect() { |
| 950 | if (mNativeObject != 0) { |
| 951 | nativeDisconnect(mNativeObject); |
| 952 | } |
| 953 | } |
| 954 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 955 | private void checkNotReleased() { |
| 956 | if (mNativeObject == 0) throw new NullPointerException( |
| 957 | "mNativeObject is null. Have you called release() already?"); |
| 958 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 959 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 960 | /** |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 961 | * Check whether this instance points to a valid layer with the system-compositor. For |
Robert Carr | 29fe58a | 2019-03-11 15:25:16 -0700 | [diff] [blame] | 962 | * example this may be false if construction failed, or the layer was released |
| 963 | * ({@link #release}). |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 964 | * |
| 965 | * @return Whether this SurfaceControl is valid. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 966 | */ |
Robert Carr | 5fea55b | 2018-12-10 13:05:52 -0800 | [diff] [blame] | 967 | public boolean isValid() { |
| 968 | return mNativeObject != 0; |
| 969 | } |
| 970 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 971 | /* |
| 972 | * set surface parameters. |
| 973 | * needs to be inside open/closeTransaction block |
| 974 | */ |
| 975 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 976 | /** start a transaction |
| 977 | * @hide |
| 978 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 979 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 980 | public static void openTransaction() { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 981 | synchronized (SurfaceControl.class) { |
| 982 | if (sGlobalTransaction == null) { |
| 983 | sGlobalTransaction = new Transaction(); |
| 984 | } |
| 985 | synchronized(SurfaceControl.class) { |
| 986 | sTransactionNestCount++; |
| 987 | } |
| 988 | } |
| 989 | } |
| 990 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 991 | /** |
| 992 | * Merge the supplied transaction in to the deprecated "global" transaction. |
| 993 | * This clears the supplied transaction in an identical fashion to {@link Transaction#merge}. |
| 994 | * <p> |
| 995 | * This is a utility for interop with legacy-code and will go away with the Global Transaction. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 996 | * @hide |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 997 | */ |
| 998 | @Deprecated |
| 999 | public static void mergeToGlobalTransaction(Transaction t) { |
Robert Carr | c5fc461 | 2017-12-05 11:55:40 -0800 | [diff] [blame] | 1000 | synchronized(SurfaceControl.class) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1001 | sGlobalTransaction.merge(t); |
| 1002 | } |
| 1003 | } |
| 1004 | |
chaviw | daaeab0 | 2019-03-20 12:25:37 -0700 | [diff] [blame] | 1005 | /** end a transaction |
| 1006 | * @hide |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1007 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1008 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1009 | public static void closeTransaction() { |
chaviw | daaeab0 | 2019-03-20 12:25:37 -0700 | [diff] [blame] | 1010 | synchronized(SurfaceControl.class) { |
| 1011 | if (sTransactionNestCount == 0) { |
| 1012 | Log.e(TAG, |
| 1013 | "Call to SurfaceControl.closeTransaction without matching openTransaction"); |
| 1014 | } else if (--sTransactionNestCount > 0) { |
| 1015 | return; |
| 1016 | } |
| 1017 | sGlobalTransaction.apply(); |
| 1018 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1019 | } |
| 1020 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1021 | /** |
| 1022 | * @hide |
| 1023 | */ |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 1024 | public void deferTransactionUntil(IBinder handle, long frame) { |
Robert Carr | 024378c | 2018-02-27 11:21:05 -0800 | [diff] [blame] | 1025 | synchronized(SurfaceControl.class) { |
| 1026 | sGlobalTransaction.deferTransactionUntil(this, handle, frame); |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1030 | /** |
| 1031 | * @hide |
| 1032 | */ |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 1033 | public void deferTransactionUntil(Surface barrier, long frame) { |
Robert Carr | 024378c | 2018-02-27 11:21:05 -0800 | [diff] [blame] | 1034 | synchronized(SurfaceControl.class) { |
| 1035 | sGlobalTransaction.deferTransactionUntilSurface(this, barrier, frame); |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 1036 | } |
| 1037 | } |
| 1038 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1039 | /** |
| 1040 | * @hide |
| 1041 | */ |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 1042 | public void reparentChildren(IBinder newParentHandle) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1043 | synchronized(SurfaceControl.class) { |
| 1044 | sGlobalTransaction.reparentChildren(this, newParentHandle); |
| 1045 | } |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 1046 | } |
| 1047 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1048 | /** |
| 1049 | * @hide |
| 1050 | */ |
Robert Carr | 10584fa | 2019-01-14 15:55:19 -0800 | [diff] [blame] | 1051 | public void reparent(SurfaceControl newParent) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1052 | synchronized(SurfaceControl.class) { |
Robert Carr | 10584fa | 2019-01-14 15:55:19 -0800 | [diff] [blame] | 1053 | sGlobalTransaction.reparent(this, newParent); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1054 | } |
chaviw | 6354238 | 2017-08-17 17:39:29 -0700 | [diff] [blame] | 1055 | } |
| 1056 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1057 | /** |
| 1058 | * @hide |
| 1059 | */ |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 1060 | public void detachChildren() { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1061 | synchronized(SurfaceControl.class) { |
| 1062 | sGlobalTransaction.detachChildren(this); |
| 1063 | } |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1066 | /** |
| 1067 | * @hide |
| 1068 | */ |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1069 | public void setOverrideScalingMode(int scalingMode) { |
| 1070 | checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1071 | synchronized(SurfaceControl.class) { |
| 1072 | sGlobalTransaction.setOverrideScalingMode(this, scalingMode); |
| 1073 | } |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1074 | } |
| 1075 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1076 | /** |
| 1077 | * @hide |
| 1078 | */ |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 1079 | public IBinder getHandle() { |
| 1080 | return nativeGetHandle(mNativeObject); |
| 1081 | } |
| 1082 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1083 | /** |
| 1084 | * @hide |
| 1085 | */ |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1086 | public static void setAnimationTransaction() { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1087 | synchronized (SurfaceControl.class) { |
| 1088 | sGlobalTransaction.setAnimationTransaction(); |
| 1089 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1090 | } |
| 1091 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1092 | /** |
| 1093 | * @hide |
| 1094 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1095 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1096 | public void setLayer(int zorder) { |
| 1097 | checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1098 | synchronized(SurfaceControl.class) { |
| 1099 | sGlobalTransaction.setLayer(this, zorder); |
| 1100 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1101 | } |
| 1102 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1103 | /** |
| 1104 | * @hide |
| 1105 | */ |
Robert Carr | 77e3494 | 2017-10-18 19:13:56 -0700 | [diff] [blame] | 1106 | public void setRelativeLayer(SurfaceControl relativeTo, int zorder) { |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 1107 | checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1108 | synchronized(SurfaceControl.class) { |
| 1109 | sGlobalTransaction.setRelativeLayer(this, relativeTo, zorder); |
| 1110 | } |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1113 | /** |
| 1114 | * @hide |
| 1115 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1116 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1117 | public void setPosition(float x, float y) { |
| 1118 | checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1119 | synchronized(SurfaceControl.class) { |
| 1120 | sGlobalTransaction.setPosition(this, x, y); |
| 1121 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1122 | } |
| 1123 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1124 | /** |
| 1125 | * @hide |
| 1126 | */ |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1127 | public void setGeometryAppliesWithResize() { |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 1128 | checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1129 | synchronized(SurfaceControl.class) { |
| 1130 | sGlobalTransaction.setGeometryAppliesWithResize(this); |
| 1131 | } |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1134 | /** |
| 1135 | * @hide |
| 1136 | */ |
Vishnu Nair | e86bd98 | 2018-11-28 13:23:17 -0800 | [diff] [blame] | 1137 | public void setBufferSize(int w, int h) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1138 | checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1139 | synchronized(SurfaceControl.class) { |
Vishnu Nair | e86bd98 | 2018-11-28 13:23:17 -0800 | [diff] [blame] | 1140 | sGlobalTransaction.setBufferSize(this, w, h); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1141 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1142 | } |
| 1143 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1144 | /** |
| 1145 | * @hide |
| 1146 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1147 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1148 | public void hide() { |
| 1149 | checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1150 | synchronized(SurfaceControl.class) { |
| 1151 | sGlobalTransaction.hide(this); |
| 1152 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1153 | } |
| 1154 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1155 | /** |
| 1156 | * @hide |
| 1157 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1158 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1159 | public void show() { |
| 1160 | checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1161 | synchronized(SurfaceControl.class) { |
| 1162 | sGlobalTransaction.show(this); |
| 1163 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1164 | } |
| 1165 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1166 | /** |
| 1167 | * @hide |
| 1168 | */ |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1169 | public void setTransparentRegionHint(Region region) { |
| 1170 | checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1171 | synchronized(SurfaceControl.class) { |
| 1172 | sGlobalTransaction.setTransparentRegionHint(this, region); |
| 1173 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1174 | } |
| 1175 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1176 | /** |
| 1177 | * @hide |
| 1178 | */ |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 1179 | public boolean clearContentFrameStats() { |
| 1180 | checkNotReleased(); |
| 1181 | return nativeClearContentFrameStats(mNativeObject); |
| 1182 | } |
| 1183 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1184 | /** |
| 1185 | * @hide |
| 1186 | */ |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 1187 | public boolean getContentFrameStats(WindowContentFrameStats outStats) { |
| 1188 | checkNotReleased(); |
| 1189 | return nativeGetContentFrameStats(mNativeObject, outStats); |
| 1190 | } |
| 1191 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1192 | /** |
| 1193 | * @hide |
| 1194 | */ |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 1195 | public static boolean clearAnimationFrameStats() { |
| 1196 | return nativeClearAnimationFrameStats(); |
| 1197 | } |
| 1198 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1199 | /** |
| 1200 | * @hide |
| 1201 | */ |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 1202 | public static boolean getAnimationFrameStats(WindowAnimationFrameStats outStats) { |
| 1203 | return nativeGetAnimationFrameStats(outStats); |
| 1204 | } |
| 1205 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1206 | /** |
| 1207 | * @hide |
| 1208 | */ |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1209 | public void setAlpha(float alpha) { |
| 1210 | checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1211 | synchronized(SurfaceControl.class) { |
| 1212 | sGlobalTransaction.setAlpha(this, alpha); |
| 1213 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1214 | } |
| 1215 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1216 | /** |
| 1217 | * @hide |
| 1218 | */ |
chaviw | 0dd03f5 | 2017-08-25 12:15:26 -0700 | [diff] [blame] | 1219 | public void setColor(@Size(3) float[] color) { |
| 1220 | checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1221 | synchronized (SurfaceControl.class) { |
| 1222 | sGlobalTransaction.setColor(this, color); |
| 1223 | } |
chaviw | 0dd03f5 | 2017-08-25 12:15:26 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1226 | /** |
| 1227 | * @hide |
| 1228 | */ |
Robert Carr | 0edf18f | 2017-02-21 20:01:47 -0800 | [diff] [blame] | 1229 | public void setMatrix(float dsdx, float dtdx, float dtdy, float dsdy) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1230 | checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1231 | synchronized(SurfaceControl.class) { |
| 1232 | sGlobalTransaction.setMatrix(this, dsdx, dtdx, dtdy, dsdy); |
| 1233 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1234 | } |
| 1235 | |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 1236 | /** |
| 1237 | * Sets the transform and position of a {@link SurfaceControl} from a 3x3 transformation matrix. |
| 1238 | * |
| 1239 | * @param matrix The matrix to apply. |
| 1240 | * @param float9 An array of 9 floats to be used to extract the values from the matrix. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1241 | * @hide |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 1242 | */ |
| 1243 | public void setMatrix(Matrix matrix, float[] float9) { |
| 1244 | checkNotReleased(); |
| 1245 | matrix.getValues(float9); |
| 1246 | synchronized (SurfaceControl.class) { |
| 1247 | sGlobalTransaction.setMatrix(this, float9[MSCALE_X], float9[MSKEW_Y], |
| 1248 | float9[MSKEW_X], float9[MSCALE_Y]); |
| 1249 | sGlobalTransaction.setPosition(this, float9[MTRANS_X], float9[MTRANS_Y]); |
| 1250 | } |
| 1251 | } |
| 1252 | |
Peiyong Lin | 52bb6b4 | 2018-10-01 11:40:50 -0700 | [diff] [blame] | 1253 | /** |
| 1254 | * Sets the color transform for the Surface. |
| 1255 | * @param matrix A float array with 9 values represents a 3x3 transform matrix |
| 1256 | * @param translation A float array with 3 values represents a translation vector |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1257 | * @hide |
Peiyong Lin | 52bb6b4 | 2018-10-01 11:40:50 -0700 | [diff] [blame] | 1258 | */ |
| 1259 | public void setColorTransform(@Size(9) float[] matrix, @Size(3) float[] translation) { |
| 1260 | checkNotReleased(); |
| 1261 | synchronized (SurfaceControl.class) { |
| 1262 | sGlobalTransaction.setColorTransform(this, matrix, translation); |
| 1263 | } |
| 1264 | } |
| 1265 | |
Vishnu Nair | d454442d | 2018-11-13 13:51:01 -0800 | [diff] [blame] | 1266 | /** |
Peiyong Lin | f4f0f64 | 2019-03-01 14:36:05 -0800 | [diff] [blame] | 1267 | * Sets the Surface to be color space agnostic. If a surface is color space agnostic, |
| 1268 | * the color can be interpreted in any color space. |
| 1269 | * @param agnostic A boolean to indicate whether the surface is color space agnostic |
| 1270 | * @hide |
| 1271 | */ |
| 1272 | public void setColorSpaceAgnostic(boolean agnostic) { |
| 1273 | checkNotReleased(); |
| 1274 | synchronized (SurfaceControl.class) { |
| 1275 | sGlobalTransaction.setColorSpaceAgnostic(this, agnostic); |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | /** |
Vishnu Nair | d454442d | 2018-11-13 13:51:01 -0800 | [diff] [blame] | 1280 | * Bounds the surface and its children to the bounds specified. Size of the surface will be |
| 1281 | * ignored and only the crop and buffer size will be used to determine the bounds of the |
| 1282 | * surface. If no crop is specified and the surface has no buffer, the surface bounds is only |
| 1283 | * constrained by the size of its parent bounds. |
| 1284 | * |
| 1285 | * @param crop Bounds of the crop to apply. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1286 | * @hide |
Vishnu Nair | d454442d | 2018-11-13 13:51:01 -0800 | [diff] [blame] | 1287 | */ |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1288 | public void setWindowCrop(Rect crop) { |
| 1289 | checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1290 | synchronized (SurfaceControl.class) { |
| 1291 | sGlobalTransaction.setWindowCrop(this, crop); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1292 | } |
| 1293 | } |
| 1294 | |
Vishnu Nair | d454442d | 2018-11-13 13:51:01 -0800 | [diff] [blame] | 1295 | /** |
| 1296 | * Same as {@link SurfaceControl#setWindowCrop(Rect)} but sets the crop rect top left at 0, 0. |
| 1297 | * |
| 1298 | * @param width width of crop rect |
| 1299 | * @param height height of crop rect |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1300 | * @hide |
Vishnu Nair | d454442d | 2018-11-13 13:51:01 -0800 | [diff] [blame] | 1301 | */ |
| 1302 | public void setWindowCrop(int width, int height) { |
| 1303 | checkNotReleased(); |
| 1304 | synchronized (SurfaceControl.class) { |
| 1305 | sGlobalTransaction.setWindowCrop(this, width, height); |
| 1306 | } |
| 1307 | } |
| 1308 | |
Lucas Dupin | ff9d6ab | 2018-10-16 18:05:50 -0700 | [diff] [blame] | 1309 | /** |
| 1310 | * Sets the corner radius of a {@link SurfaceControl}. |
| 1311 | * |
| 1312 | * @param cornerRadius Corner radius in pixels. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1313 | * @hide |
Lucas Dupin | ff9d6ab | 2018-10-16 18:05:50 -0700 | [diff] [blame] | 1314 | */ |
| 1315 | public void setCornerRadius(float cornerRadius) { |
| 1316 | checkNotReleased(); |
| 1317 | synchronized (SurfaceControl.class) { |
| 1318 | sGlobalTransaction.setCornerRadius(this, cornerRadius); |
| 1319 | } |
| 1320 | } |
| 1321 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1322 | /** |
| 1323 | * @hide |
| 1324 | */ |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1325 | public void setLayerStack(int layerStack) { |
| 1326 | checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1327 | synchronized(SurfaceControl.class) { |
| 1328 | sGlobalTransaction.setLayerStack(this, layerStack); |
| 1329 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1330 | } |
| 1331 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1332 | /** |
| 1333 | * @hide |
| 1334 | */ |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 1335 | public void setOpaque(boolean isOpaque) { |
| 1336 | checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1337 | |
| 1338 | synchronized (SurfaceControl.class) { |
| 1339 | sGlobalTransaction.setOpaque(this, isOpaque); |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 1340 | } |
| 1341 | } |
| 1342 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1343 | /** |
| 1344 | * @hide |
| 1345 | */ |
Wale Ogunwale | f5ad42f | 2015-06-12 13:59:03 -0700 | [diff] [blame] | 1346 | public void setSecure(boolean isSecure) { |
| 1347 | checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1348 | |
| 1349 | synchronized (SurfaceControl.class) { |
| 1350 | sGlobalTransaction.setSecure(this, isSecure); |
Wale Ogunwale | f5ad42f | 2015-06-12 13:59:03 -0700 | [diff] [blame] | 1351 | } |
| 1352 | } |
| 1353 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1354 | /** |
| 1355 | * @hide |
| 1356 | */ |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1357 | public int getWidth() { |
| 1358 | synchronized (mSizeLock) { |
| 1359 | return mWidth; |
| 1360 | } |
| 1361 | } |
| 1362 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1363 | /** |
| 1364 | * @hide |
| 1365 | */ |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1366 | public int getHeight() { |
| 1367 | synchronized (mSizeLock) { |
| 1368 | return mHeight; |
| 1369 | } |
| 1370 | } |
| 1371 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1372 | @Override |
| 1373 | public String toString() { |
| 1374 | return "Surface(name=" + mName + ")/@0x" + |
| 1375 | Integer.toHexString(System.identityHashCode(this)); |
| 1376 | } |
| 1377 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1378 | /* |
| 1379 | * set display parameters. |
| 1380 | * needs to be inside open/closeTransaction block |
| 1381 | */ |
| 1382 | |
| 1383 | /** |
| 1384 | * Describes the properties of a physical display known to surface flinger. |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 1385 | * @hide |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1386 | */ |
| 1387 | public static final class PhysicalDisplayInfo { |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1388 | /** |
| 1389 | * @hide |
| 1390 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1391 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1392 | public int width; |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1393 | |
| 1394 | /** |
| 1395 | * @hide |
| 1396 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1397 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1398 | public int height; |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1399 | |
| 1400 | /** |
| 1401 | * @hide |
| 1402 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1403 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1404 | public float refreshRate; |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1405 | |
| 1406 | /** |
| 1407 | * @hide |
| 1408 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1409 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1410 | public float density; |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1411 | |
| 1412 | /** |
| 1413 | * @hide |
| 1414 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1415 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1416 | public float xDpi; |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1417 | |
| 1418 | /** |
| 1419 | * @hide |
| 1420 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1421 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1422 | public float yDpi; |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1423 | |
| 1424 | /** |
| 1425 | * @hide |
| 1426 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1427 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1428 | public boolean secure; |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1429 | |
| 1430 | /** |
| 1431 | * @hide |
| 1432 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1433 | @UnsupportedAppUsage |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 1434 | public long appVsyncOffsetNanos; |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1435 | |
| 1436 | /** |
| 1437 | * @hide |
| 1438 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1439 | @UnsupportedAppUsage |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 1440 | public long presentationDeadlineNanos; |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 1441 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1442 | /** |
| 1443 | * @hide |
| 1444 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1445 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1446 | public PhysicalDisplayInfo() { |
| 1447 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 1448 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1449 | /** |
| 1450 | * @hide |
| 1451 | */ |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1452 | public PhysicalDisplayInfo(PhysicalDisplayInfo other) { |
| 1453 | copyFrom(other); |
| 1454 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 1455 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1456 | /** |
| 1457 | * @hide |
| 1458 | */ |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1459 | @Override |
| 1460 | public boolean equals(Object o) { |
| 1461 | return o instanceof PhysicalDisplayInfo && equals((PhysicalDisplayInfo)o); |
| 1462 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 1463 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1464 | /** |
| 1465 | * @hide |
| 1466 | */ |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1467 | public boolean equals(PhysicalDisplayInfo other) { |
| 1468 | return other != null |
| 1469 | && width == other.width |
| 1470 | && height == other.height |
| 1471 | && refreshRate == other.refreshRate |
| 1472 | && density == other.density |
| 1473 | && xDpi == other.xDpi |
| 1474 | && yDpi == other.yDpi |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 1475 | && secure == other.secure |
| 1476 | && appVsyncOffsetNanos == other.appVsyncOffsetNanos |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1477 | && presentationDeadlineNanos == other.presentationDeadlineNanos; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1478 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 1479 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1480 | /** |
| 1481 | * @hide |
| 1482 | */ |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1483 | @Override |
| 1484 | public int hashCode() { |
| 1485 | return 0; // don't care |
| 1486 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 1487 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1488 | /** |
| 1489 | * @hide |
| 1490 | */ |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1491 | public void copyFrom(PhysicalDisplayInfo other) { |
| 1492 | width = other.width; |
| 1493 | height = other.height; |
| 1494 | refreshRate = other.refreshRate; |
| 1495 | density = other.density; |
| 1496 | xDpi = other.xDpi; |
| 1497 | yDpi = other.yDpi; |
| 1498 | secure = other.secure; |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 1499 | appVsyncOffsetNanos = other.appVsyncOffsetNanos; |
| 1500 | presentationDeadlineNanos = other.presentationDeadlineNanos; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1501 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 1502 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1503 | /** |
| 1504 | * @hide |
| 1505 | */ |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1506 | @Override |
| 1507 | public String toString() { |
| 1508 | return "PhysicalDisplayInfo{" + width + " x " + height + ", " + refreshRate + " fps, " |
| 1509 | + "density " + density + ", " + xDpi + " x " + yDpi + " dpi, secure " + secure |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 1510 | + ", appVsyncOffset " + appVsyncOffsetNanos |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1511 | + ", bufferDeadline " + presentationDeadlineNanos + "}"; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1512 | } |
| 1513 | } |
| 1514 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1515 | /** |
| 1516 | * @hide |
| 1517 | */ |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 1518 | public static void setDisplayPowerMode(IBinder displayToken, int mode) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1519 | if (displayToken == null) { |
| 1520 | throw new IllegalArgumentException("displayToken must not be null"); |
| 1521 | } |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 1522 | nativeSetDisplayPowerMode(displayToken, mode); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1523 | } |
| 1524 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1525 | /** |
| 1526 | * @hide |
| 1527 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1528 | @UnsupportedAppUsage |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 1529 | public static SurfaceControl.PhysicalDisplayInfo[] getDisplayConfigs(IBinder displayToken) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1530 | if (displayToken == null) { |
| 1531 | throw new IllegalArgumentException("displayToken must not be null"); |
| 1532 | } |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 1533 | return nativeGetDisplayConfigs(displayToken); |
| 1534 | } |
| 1535 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1536 | /** |
| 1537 | * @hide |
| 1538 | */ |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 1539 | public static int getActiveConfig(IBinder displayToken) { |
| 1540 | if (displayToken == null) { |
| 1541 | throw new IllegalArgumentException("displayToken must not be null"); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1542 | } |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 1543 | return nativeGetActiveConfig(displayToken); |
| 1544 | } |
| 1545 | |
Kevin DuBois | bf76b11b | 2018-09-04 09:14:15 -0700 | [diff] [blame] | 1546 | /** |
| 1547 | * @hide |
| 1548 | */ |
| 1549 | public static DisplayedContentSamplingAttributes getDisplayedContentSamplingAttributes( |
| 1550 | IBinder displayToken) { |
| 1551 | if (displayToken == null) { |
| 1552 | throw new IllegalArgumentException("displayToken must not be null"); |
| 1553 | } |
| 1554 | return nativeGetDisplayedContentSamplingAttributes(displayToken); |
| 1555 | } |
| 1556 | |
| 1557 | /** |
| 1558 | * @hide |
| 1559 | */ |
| 1560 | public static boolean setDisplayedContentSamplingEnabled( |
| 1561 | IBinder displayToken, boolean enable, int componentMask, int maxFrames) { |
| 1562 | if (displayToken == null) { |
| 1563 | throw new IllegalArgumentException("displayToken must not be null"); |
| 1564 | } |
| 1565 | final int maxColorComponents = 4; |
| 1566 | if ((componentMask >> maxColorComponents) != 0) { |
| 1567 | throw new IllegalArgumentException("invalid componentMask when enabling sampling"); |
| 1568 | } |
| 1569 | return nativeSetDisplayedContentSamplingEnabled( |
| 1570 | displayToken, enable, componentMask, maxFrames); |
| 1571 | } |
| 1572 | |
| 1573 | /** |
| 1574 | * @hide |
| 1575 | */ |
| 1576 | public static DisplayedContentSample getDisplayedContentSample( |
| 1577 | IBinder displayToken, long maxFrames, long timestamp) { |
| 1578 | if (displayToken == null) { |
| 1579 | throw new IllegalArgumentException("displayToken must not be null"); |
| 1580 | } |
| 1581 | return nativeGetDisplayedContentSample(displayToken, maxFrames, timestamp); |
| 1582 | } |
| 1583 | |
| 1584 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1585 | /** |
| 1586 | * @hide |
| 1587 | */ |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 1588 | public static boolean setActiveConfig(IBinder displayToken, int id) { |
| 1589 | if (displayToken == null) { |
| 1590 | throw new IllegalArgumentException("displayToken must not be null"); |
| 1591 | } |
| 1592 | return nativeSetActiveConfig(displayToken, id); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1593 | } |
| 1594 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1595 | /** |
| 1596 | * @hide |
| 1597 | */ |
Ady Abraham | 6070ce1 | 2019-01-24 18:48:58 -0800 | [diff] [blame] | 1598 | public static boolean setAllowedDisplayConfigs(IBinder displayToken, int[] allowedConfigs) { |
| 1599 | if (displayToken == null) { |
| 1600 | throw new IllegalArgumentException("displayToken must not be null"); |
| 1601 | } |
| 1602 | if (allowedConfigs == null) { |
| 1603 | throw new IllegalArgumentException("allowedConfigs must not be null"); |
| 1604 | } |
| 1605 | |
| 1606 | return nativeSetAllowedDisplayConfigs(displayToken, allowedConfigs); |
| 1607 | } |
| 1608 | |
| 1609 | /** |
| 1610 | * @hide |
| 1611 | */ |
Ady Abraham | 42f9a2fb | 2019-02-26 14:13:39 -0800 | [diff] [blame] | 1612 | public static int[] getAllowedDisplayConfigs(IBinder displayToken) { |
| 1613 | if (displayToken == null) { |
| 1614 | throw new IllegalArgumentException("displayToken must not be null"); |
| 1615 | } |
| 1616 | return nativeGetAllowedDisplayConfigs(displayToken); |
| 1617 | } |
| 1618 | |
| 1619 | /** |
| 1620 | * @hide |
| 1621 | */ |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1622 | public static int[] getDisplayColorModes(IBinder displayToken) { |
| 1623 | if (displayToken == null) { |
| 1624 | throw new IllegalArgumentException("displayToken must not be null"); |
| 1625 | } |
| 1626 | return nativeGetDisplayColorModes(displayToken); |
| 1627 | } |
| 1628 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1629 | /** |
Daniel Solomon | 10e3b33 | 2019-01-20 21:09:11 -0800 | [diff] [blame] | 1630 | * Color coordinates in CIE1931 XYZ color space |
| 1631 | * |
| 1632 | * @hide |
| 1633 | */ |
| 1634 | public static final class CieXyz { |
| 1635 | /** |
| 1636 | * @hide |
| 1637 | */ |
| 1638 | public float X; |
| 1639 | |
| 1640 | /** |
| 1641 | * @hide |
| 1642 | */ |
| 1643 | public float Y; |
| 1644 | |
| 1645 | /** |
| 1646 | * @hide |
| 1647 | */ |
| 1648 | public float Z; |
| 1649 | } |
| 1650 | |
| 1651 | /** |
| 1652 | * Contains a display's color primaries |
| 1653 | * |
| 1654 | * @hide |
| 1655 | */ |
| 1656 | public static final class DisplayPrimaries { |
| 1657 | /** |
| 1658 | * @hide |
| 1659 | */ |
| 1660 | public CieXyz red; |
| 1661 | |
| 1662 | /** |
| 1663 | * @hide |
| 1664 | */ |
| 1665 | public CieXyz green; |
| 1666 | |
| 1667 | /** |
| 1668 | * @hide |
| 1669 | */ |
| 1670 | public CieXyz blue; |
| 1671 | |
| 1672 | /** |
| 1673 | * @hide |
| 1674 | */ |
| 1675 | public CieXyz white; |
| 1676 | |
| 1677 | /** |
| 1678 | * @hide |
| 1679 | */ |
| 1680 | public DisplayPrimaries() { |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | /** |
| 1685 | * @hide |
| 1686 | */ |
| 1687 | public static SurfaceControl.DisplayPrimaries getDisplayNativePrimaries( |
| 1688 | IBinder displayToken) { |
| 1689 | if (displayToken == null) { |
| 1690 | throw new IllegalArgumentException("displayToken must not be null"); |
| 1691 | } |
| 1692 | |
| 1693 | return nativeGetDisplayNativePrimaries(displayToken); |
| 1694 | } |
| 1695 | |
| 1696 | /** |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1697 | * @hide |
| 1698 | */ |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1699 | public static int getActiveColorMode(IBinder displayToken) { |
| 1700 | if (displayToken == null) { |
| 1701 | throw new IllegalArgumentException("displayToken must not be null"); |
| 1702 | } |
| 1703 | return nativeGetActiveColorMode(displayToken); |
| 1704 | } |
| 1705 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1706 | /** |
| 1707 | * @hide |
| 1708 | */ |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1709 | public static boolean setActiveColorMode(IBinder displayToken, int colorMode) { |
| 1710 | if (displayToken == null) { |
| 1711 | throw new IllegalArgumentException("displayToken must not be null"); |
| 1712 | } |
| 1713 | return nativeSetActiveColorMode(displayToken, colorMode); |
| 1714 | } |
| 1715 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1716 | /** |
Peiyong Lin | 5f4a568 | 2019-01-17 11:37:07 -0800 | [diff] [blame] | 1717 | * Returns an array of color spaces with 2 elements. The first color space is the |
| 1718 | * default color space and second one is wide color gamut color space. |
| 1719 | * @hide |
| 1720 | */ |
| 1721 | public static ColorSpace[] getCompositionColorSpaces() { |
| 1722 | int[] dataspaces = nativeGetCompositionDataspaces(); |
| 1723 | ColorSpace srgb = ColorSpace.get(ColorSpace.Named.SRGB); |
| 1724 | ColorSpace[] colorSpaces = { srgb, srgb }; |
| 1725 | if (dataspaces.length == 2) { |
| 1726 | for (int i = 0; i < 2; ++i) { |
| 1727 | switch(dataspaces[i]) { |
| 1728 | case INTERNAL_DATASPACE_DISPLAY_P3: |
| 1729 | colorSpaces[i] = ColorSpace.get(ColorSpace.Named.DISPLAY_P3); |
| 1730 | break; |
| 1731 | case INTERNAL_DATASPACE_SCRGB: |
| 1732 | colorSpaces[i] = ColorSpace.get(ColorSpace.Named.EXTENDED_SRGB); |
| 1733 | break; |
| 1734 | case INTERNAL_DATASPACE_SRGB: |
| 1735 | // Other dataspace is not recognized, use SRGB color space instead, |
| 1736 | // the default value of the array is already SRGB, thus do nothing. |
| 1737 | default: |
| 1738 | break; |
| 1739 | } |
| 1740 | } |
| 1741 | } |
| 1742 | return colorSpaces; |
| 1743 | } |
| 1744 | |
| 1745 | /** |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1746 | * @hide |
| 1747 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1748 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1749 | public static void setDisplayProjection(IBinder displayToken, |
| 1750 | int orientation, Rect layerStackRect, Rect displayRect) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1751 | synchronized (SurfaceControl.class) { |
| 1752 | sGlobalTransaction.setDisplayProjection(displayToken, orientation, |
| 1753 | layerStackRect, displayRect); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1754 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1755 | } |
| 1756 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1757 | /** |
| 1758 | * @hide |
| 1759 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1760 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1761 | public static void setDisplayLayerStack(IBinder displayToken, int layerStack) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1762 | synchronized (SurfaceControl.class) { |
| 1763 | sGlobalTransaction.setDisplayLayerStack(displayToken, layerStack); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1764 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1765 | } |
| 1766 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1767 | /** |
| 1768 | * @hide |
| 1769 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1770 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1771 | public static void setDisplaySurface(IBinder displayToken, Surface surface) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1772 | synchronized (SurfaceControl.class) { |
| 1773 | sGlobalTransaction.setDisplaySurface(displayToken, surface); |
Jeff Brown | fc0ebd7 | 2013-04-30 16:33:00 -0700 | [diff] [blame] | 1774 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1775 | } |
| 1776 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1777 | /** |
| 1778 | * @hide |
| 1779 | */ |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 1780 | public static void setDisplaySize(IBinder displayToken, int width, int height) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1781 | synchronized (SurfaceControl.class) { |
| 1782 | sGlobalTransaction.setDisplaySize(displayToken, width, height); |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 1783 | } |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 1784 | } |
| 1785 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1786 | /** |
| 1787 | * @hide |
| 1788 | */ |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 1789 | public static Display.HdrCapabilities getHdrCapabilities(IBinder displayToken) { |
| 1790 | if (displayToken == null) { |
| 1791 | throw new IllegalArgumentException("displayToken must not be null"); |
| 1792 | } |
| 1793 | return nativeGetHdrCapabilities(displayToken); |
| 1794 | } |
| 1795 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1796 | /** |
| 1797 | * @hide |
| 1798 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1799 | @UnsupportedAppUsage |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1800 | public static IBinder createDisplay(String name, boolean secure) { |
| 1801 | if (name == null) { |
| 1802 | throw new IllegalArgumentException("name must not be null"); |
| 1803 | } |
| 1804 | return nativeCreateDisplay(name, secure); |
| 1805 | } |
| 1806 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1807 | /** |
| 1808 | * @hide |
| 1809 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1810 | @UnsupportedAppUsage |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 1811 | public static void destroyDisplay(IBinder displayToken) { |
| 1812 | if (displayToken == null) { |
| 1813 | throw new IllegalArgumentException("displayToken must not be null"); |
| 1814 | } |
| 1815 | nativeDestroyDisplay(displayToken); |
| 1816 | } |
| 1817 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1818 | /** |
| 1819 | * @hide |
| 1820 | */ |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 1821 | public static long[] getPhysicalDisplayIds() { |
| 1822 | return nativeGetPhysicalDisplayIds(); |
| 1823 | } |
| 1824 | |
| 1825 | /** |
| 1826 | * @hide |
| 1827 | */ |
| 1828 | public static IBinder getPhysicalDisplayToken(long physicalDisplayId) { |
| 1829 | return nativeGetPhysicalDisplayToken(physicalDisplayId); |
| 1830 | } |
| 1831 | |
| 1832 | /** |
| 1833 | * TODO(116025192): Remove this stopgap once framework is display-agnostic. |
| 1834 | * |
| 1835 | * @hide |
| 1836 | */ |
| 1837 | public static IBinder getInternalDisplayToken() { |
| 1838 | final long[] physicalDisplayIds = getPhysicalDisplayIds(); |
| 1839 | if (physicalDisplayIds.length == 0) { |
| 1840 | return null; |
| 1841 | } |
| 1842 | return getPhysicalDisplayToken(physicalDisplayIds[0]); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1843 | } |
| 1844 | |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 1845 | /** |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 1846 | * @see SurfaceControl#screenshot(IBinder, Surface, Rect, int, int, boolean, int) |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1847 | * @hide |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 1848 | */ |
| 1849 | public static void screenshot(IBinder display, Surface consumer) { |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 1850 | screenshot(display, consumer, new Rect(), 0, 0, false, 0); |
| 1851 | } |
| 1852 | |
| 1853 | /** |
| 1854 | * Copy the current screen contents into the provided {@link Surface} |
| 1855 | * |
| 1856 | * @param consumer The {@link Surface} to take the screenshot into. |
| 1857 | * @see SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int) |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1858 | * @hide |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 1859 | */ |
| 1860 | public static void screenshot(IBinder display, Surface consumer, Rect sourceCrop, int width, |
| 1861 | int height, boolean useIdentityTransform, int rotation) { |
| 1862 | if (consumer == null) { |
| 1863 | throw new IllegalArgumentException("consumer must not be null"); |
| 1864 | } |
| 1865 | |
Peiyong Lin | e3e5efd | 2019-03-21 20:59:47 +0000 | [diff] [blame] | 1866 | final ScreenshotGraphicBuffer buffer = screenshotToBuffer(display, sourceCrop, width, |
| 1867 | height, useIdentityTransform, rotation); |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 1868 | try { |
Peiyong Lin | ccc06b6 | 2019-06-25 17:31:09 -0700 | [diff] [blame] | 1869 | consumer.attachAndQueueBufferWithColorSpace(buffer.getGraphicBuffer(), |
| 1870 | buffer.getColorSpace()); |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 1871 | } catch (RuntimeException e) { |
| 1872 | Log.w(TAG, "Failed to take screenshot - " + e.getMessage()); |
| 1873 | } |
| 1874 | } |
| 1875 | |
| 1876 | /** |
| 1877 | * @see SurfaceControl#screenshot(Rect, int, int, boolean, int)} |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1878 | * @hide |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 1879 | */ |
| 1880 | @UnsupportedAppUsage |
| 1881 | public static Bitmap screenshot(Rect sourceCrop, int width, int height, int rotation) { |
| 1882 | return screenshot(sourceCrop, width, height, false, rotation); |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 1883 | } |
| 1884 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1885 | /** |
chaviw | 1da9cd9 | 2017-12-06 10:48:11 -0800 | [diff] [blame] | 1886 | * Copy the current screen contents into a hardware bitmap and return it. |
| 1887 | * Note: If you want to modify the Bitmap in software, you will need to copy the Bitmap into |
| 1888 | * a software Bitmap using {@link Bitmap#copy(Bitmap.Config, boolean)} |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1889 | * |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 1890 | * CAVEAT: Versions of screenshot that return a {@link Bitmap} can be extremely slow; avoid use |
| 1891 | * unless absolutely necessary; prefer the versions that use a {@link Surface} such as |
| 1892 | * {@link SurfaceControl#screenshot(IBinder, Surface)} or {@link GraphicBuffer} such as |
| 1893 | * {@link SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)}. |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 1894 | * |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 1895 | * @see SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)} |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1896 | * @hide |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1897 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1898 | @UnsupportedAppUsage |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 1899 | public static Bitmap screenshot(Rect sourceCrop, int width, int height, |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 1900 | boolean useIdentityTransform, int rotation) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1901 | // TODO: should take the display as a parameter |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 1902 | final IBinder displayToken = SurfaceControl.getInternalDisplayToken(); |
| 1903 | if (displayToken == null) { |
| 1904 | Log.w(TAG, "Failed to take screenshot because internal display is disconnected"); |
| 1905 | return null; |
| 1906 | } |
| 1907 | |
chaviw | a69e0a7 | 2017-11-29 17:55:12 -0800 | [diff] [blame] | 1908 | if (rotation == ROTATION_90 || rotation == ROTATION_270) { |
| 1909 | rotation = (rotation == ROTATION_90) ? ROTATION_270 : ROTATION_90; |
| 1910 | } |
| 1911 | |
| 1912 | SurfaceControl.rotateCropForSF(sourceCrop, rotation); |
Peiyong Lin | e3e5efd | 2019-03-21 20:59:47 +0000 | [diff] [blame] | 1913 | final ScreenshotGraphicBuffer buffer = screenshotToBuffer(displayToken, sourceCrop, width, |
| 1914 | height, useIdentityTransform, rotation); |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 1915 | |
| 1916 | if (buffer == null) { |
| 1917 | Log.w(TAG, "Failed to take screenshot"); |
| 1918 | return null; |
| 1919 | } |
Sunny Goyal | 62915b2 | 2019-04-10 12:28:47 -0700 | [diff] [blame] | 1920 | return Bitmap.wrapHardwareBuffer(buffer.getGraphicBuffer(), buffer.getColorSpace()); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1921 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 1922 | |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 1923 | /** |
| 1924 | * Captures all the surfaces in a display and returns a {@link GraphicBuffer} with the content. |
| 1925 | * |
| 1926 | * @param display The display to take the screenshot of. |
| 1927 | * @param sourceCrop The portion of the screen to capture into the Bitmap; caller may |
| 1928 | * pass in 'new Rect()' if no cropping is desired. |
| 1929 | * @param width The desired width of the returned bitmap; the raw screen will be |
| 1930 | * scaled down to this size; caller may pass in 0 if no scaling is |
| 1931 | * desired. |
| 1932 | * @param height The desired height of the returned bitmap; the raw screen will |
| 1933 | * be scaled down to this size; caller may pass in 0 if no scaling |
| 1934 | * is desired. |
| 1935 | * @param useIdentityTransform Replace whatever transformation (rotation, scaling, translation) |
| 1936 | * the surface layers are currently using with the identity |
| 1937 | * transformation while taking the screenshot. |
| 1938 | * @param rotation Apply a custom clockwise rotation to the screenshot, i.e. |
| 1939 | * Surface.ROTATION_0,90,180,270. SurfaceFlinger will always take |
| 1940 | * screenshots in its native portrait orientation by default, so |
| 1941 | * this is useful for returning screenshots that are independent of |
| 1942 | * device orientation. |
| 1943 | * @return Returns a GraphicBuffer that contains the captured content. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1944 | * @hide |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 1945 | */ |
Peiyong Lin | e3e5efd | 2019-03-21 20:59:47 +0000 | [diff] [blame] | 1946 | public static ScreenshotGraphicBuffer screenshotToBuffer(IBinder display, Rect sourceCrop, |
| 1947 | int width, int height, boolean useIdentityTransform, int rotation) { |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 1948 | if (display == null) { |
| 1949 | throw new IllegalArgumentException("displayToken must not be null"); |
| 1950 | } |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 1951 | |
Robert Carr | 5c52b13 | 2019-02-15 15:48:11 -0800 | [diff] [blame] | 1952 | return nativeScreenshot(display, sourceCrop, width, height, useIdentityTransform, rotation, |
| 1953 | false /* captureSecureLayers */); |
| 1954 | } |
| 1955 | |
| 1956 | /** |
| 1957 | * Like screenshotToBuffer, but if the caller is AID_SYSTEM, allows |
| 1958 | * for the capture of secure layers. This is used for the screen rotation |
| 1959 | * animation where the system server takes screenshots but does |
| 1960 | * not persist them or allow them to leave the server. However in other |
| 1961 | * cases in the system server, we mostly want to omit secure layers |
| 1962 | * like when we take a screenshot on behalf of the assistant. |
| 1963 | * |
| 1964 | * @hide |
| 1965 | */ |
Peiyong Lin | e3e5efd | 2019-03-21 20:59:47 +0000 | [diff] [blame] | 1966 | public static ScreenshotGraphicBuffer screenshotToBufferWithSecureLayersUnsafe(IBinder display, |
Robert Carr | 5c52b13 | 2019-02-15 15:48:11 -0800 | [diff] [blame] | 1967 | Rect sourceCrop, int width, int height, boolean useIdentityTransform, |
| 1968 | int rotation) { |
| 1969 | if (display == null) { |
| 1970 | throw new IllegalArgumentException("displayToken must not be null"); |
| 1971 | } |
| 1972 | |
| 1973 | return nativeScreenshot(display, sourceCrop, width, height, useIdentityTransform, rotation, |
| 1974 | true /* captureSecureLayers */); |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 1975 | } |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1976 | |
chaviw | a69e0a7 | 2017-11-29 17:55:12 -0800 | [diff] [blame] | 1977 | private static void rotateCropForSF(Rect crop, int rot) { |
| 1978 | if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) { |
| 1979 | int tmp = crop.top; |
| 1980 | crop.top = crop.left; |
| 1981 | crop.left = tmp; |
| 1982 | tmp = crop.right; |
| 1983 | crop.right = crop.bottom; |
| 1984 | crop.bottom = tmp; |
| 1985 | } |
| 1986 | } |
| 1987 | |
chaviw | 1cda84c | 2017-10-23 16:47:10 -0700 | [diff] [blame] | 1988 | /** |
chaviw | 1da9cd9 | 2017-12-06 10:48:11 -0800 | [diff] [blame] | 1989 | * Captures a layer and its children and returns a {@link GraphicBuffer} with the content. |
chaviw | 1cda84c | 2017-10-23 16:47:10 -0700 | [diff] [blame] | 1990 | * |
| 1991 | * @param layerHandleToken The root layer to capture. |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 1992 | * @param sourceCrop The portion of the root surface to capture; caller may pass in 'new |
| 1993 | * Rect()' or null if no cropping is desired. |
| 1994 | * @param frameScale The desired scale of the returned buffer; the raw |
| 1995 | * screen will be scaled up/down. |
Chavi Weingarten | d7ec64c | 2017-11-30 01:52:01 +0000 | [diff] [blame] | 1996 | * |
| 1997 | * @return Returns a GraphicBuffer that contains the layer capture. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 1998 | * @hide |
chaviw | 1cda84c | 2017-10-23 16:47:10 -0700 | [diff] [blame] | 1999 | */ |
Peiyong Lin | e3e5efd | 2019-03-21 20:59:47 +0000 | [diff] [blame] | 2000 | public static ScreenshotGraphicBuffer captureLayers(IBinder layerHandleToken, Rect sourceCrop, |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 2001 | float frameScale) { |
Peiyong Lin | 21e499a | 2019-04-03 16:37:46 -0700 | [diff] [blame] | 2002 | final IBinder displayToken = SurfaceControl.getInternalDisplayToken(); |
| 2003 | return nativeCaptureLayers(displayToken, layerHandleToken, sourceCrop, frameScale, null); |
Robert Carr | ffcdc51 | 2019-04-02 11:51:11 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | /** |
| 2007 | * Like {@link captureLayers} but with an array of layer handles to exclude. |
| 2008 | * @hide |
| 2009 | */ |
| 2010 | public static ScreenshotGraphicBuffer captureLayersExcluding(IBinder layerHandleToken, |
| 2011 | Rect sourceCrop, float frameScale, IBinder[] exclude) { |
Peiyong Lin | 21e499a | 2019-04-03 16:37:46 -0700 | [diff] [blame] | 2012 | final IBinder displayToken = SurfaceControl.getInternalDisplayToken(); |
| 2013 | return nativeCaptureLayers(displayToken, layerHandleToken, sourceCrop, frameScale, exclude); |
chaviw | 1cda84c | 2017-10-23 16:47:10 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2016 | /** |
Peiyong Lin | 0ddb7d4 | 2019-01-16 13:25:09 -0800 | [diff] [blame] | 2017 | * Returns whether protected content is supported in GPU composition. |
| 2018 | * @hide |
| 2019 | */ |
| 2020 | public static boolean getProtectedContentSupport() { |
| 2021 | return nativeGetProtectedContentSupport(); |
| 2022 | } |
| 2023 | |
| 2024 | /** |
Dan Gittik | 832b497 | 2019-02-13 18:17:47 +0000 | [diff] [blame] | 2025 | * Returns whether brightness operations are supported on a display. |
| 2026 | * |
| 2027 | * @param displayToken |
| 2028 | * The token for the display. |
| 2029 | * |
| 2030 | * @return Whether brightness operations are supported on the display. |
| 2031 | * |
| 2032 | * @hide |
| 2033 | */ |
| 2034 | public static boolean getDisplayBrightnessSupport(IBinder displayToken) { |
| 2035 | return nativeGetDisplayBrightnessSupport(displayToken); |
| 2036 | } |
| 2037 | |
| 2038 | /** |
| 2039 | * Sets the brightness of a display. |
| 2040 | * |
| 2041 | * @param displayToken |
| 2042 | * The token for the display whose brightness is set. |
| 2043 | * @param brightness |
| 2044 | * A number between 0.0f (minimum brightness) and 1.0f (maximum brightness), or -1.0f to |
| 2045 | * turn the backlight off. |
| 2046 | * |
| 2047 | * @return Whether the method succeeded or not. |
| 2048 | * |
| 2049 | * @throws IllegalArgumentException if: |
| 2050 | * - displayToken is null; |
| 2051 | * - brightness is NaN or greater than 1.0f. |
| 2052 | * |
| 2053 | * @hide |
| 2054 | */ |
| 2055 | public static boolean setDisplayBrightness(IBinder displayToken, float brightness) { |
| 2056 | Objects.requireNonNull(displayToken); |
| 2057 | if (Float.isNaN(brightness) || brightness > 1.0f |
| 2058 | || (brightness < 0.0f && brightness != -1.0f)) { |
| 2059 | throw new IllegalArgumentException("brightness must be a number between 0.0f and 1.0f," |
| 2060 | + " or -1 to turn the backlight off."); |
| 2061 | } |
| 2062 | return nativeSetDisplayBrightness(displayToken, brightness); |
| 2063 | } |
| 2064 | |
| 2065 | /** |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 2066 | * An atomic set of changes to a set of SurfaceControl. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2067 | */ |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2068 | public static class Transaction implements Closeable { |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 2069 | /** |
| 2070 | * @hide |
| 2071 | */ |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2072 | public static final NativeAllocationRegistry sRegistry = new NativeAllocationRegistry( |
| 2073 | Transaction.class.getClassLoader(), |
| 2074 | nativeGetNativeTransactionFinalizer(), 512); |
| 2075 | private long mNativeObject; |
| 2076 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 2077 | private final ArrayMap<SurfaceControl, Point> mResizedSurfaces = new ArrayMap<>(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2078 | Runnable mFreeNativeResources; |
| 2079 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2080 | /** |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 2081 | * Open a new transaction object. The transaction may be filed with commands to |
| 2082 | * manipulate {@link SurfaceControl} instances, and then applied atomically with |
| 2083 | * {@link #apply}. Eventually the user should invoke {@link #close}, when the object |
| 2084 | * is no longer required. Note however that re-using a transaction after a call to apply |
| 2085 | * is allowed as a convenience. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2086 | */ |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2087 | public Transaction() { |
| 2088 | mNativeObject = nativeCreateTransaction(); |
| 2089 | mFreeNativeResources |
| 2090 | = sRegistry.registerNativeAllocation(this, mNativeObject); |
| 2091 | } |
| 2092 | |
| 2093 | /** |
| 2094 | * Apply the transaction, clearing it's state, and making it usable |
| 2095 | * as a new transaction. |
| 2096 | */ |
| 2097 | public void apply() { |
| 2098 | apply(false); |
| 2099 | } |
| 2100 | |
| 2101 | /** |
Robert Carr | 29fe58a | 2019-03-11 15:25:16 -0700 | [diff] [blame] | 2102 | * Release the native transaction object, without applying it. |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2103 | */ |
| 2104 | @Override |
| 2105 | public void close() { |
| 2106 | mFreeNativeResources.run(); |
| 2107 | mNativeObject = 0; |
| 2108 | } |
| 2109 | |
| 2110 | /** |
| 2111 | * Jankier version of apply. Avoid use (b/28068298). |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2112 | * @hide |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2113 | */ |
| 2114 | public void apply(boolean sync) { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 2115 | applyResizedSurfaces(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2116 | nativeApplyTransaction(mNativeObject, sync); |
| 2117 | } |
| 2118 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 2119 | private void applyResizedSurfaces() { |
| 2120 | for (int i = mResizedSurfaces.size() - 1; i >= 0; i--) { |
| 2121 | final Point size = mResizedSurfaces.valueAt(i); |
| 2122 | final SurfaceControl surfaceControl = mResizedSurfaces.keyAt(i); |
| 2123 | synchronized (surfaceControl.mSizeLock) { |
| 2124 | surfaceControl.mWidth = size.x; |
| 2125 | surfaceControl.mHeight = size.y; |
| 2126 | } |
| 2127 | } |
| 2128 | mResizedSurfaces.clear(); |
| 2129 | } |
| 2130 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2131 | /** |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 2132 | * Toggle the visibility of a given Layer and it's sub-tree. |
| 2133 | * |
| 2134 | * @param sc The SurfaceControl for which to set the visibility |
| 2135 | * @param visible The new visibility |
| 2136 | * @return This transaction object. |
| 2137 | */ |
| 2138 | @NonNull |
| 2139 | public Transaction setVisibility(@NonNull SurfaceControl sc, boolean visible) { |
| 2140 | sc.checkNotReleased(); |
| 2141 | if (visible) { |
| 2142 | return show(sc); |
| 2143 | } else { |
| 2144 | return hide(sc); |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | /** |
| 2149 | * Request that a given surface and it's sub-tree be shown. |
| 2150 | * |
| 2151 | * @param sc The surface to show. |
| 2152 | * @return This transaction. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2153 | * @hide |
| 2154 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 2155 | @UnsupportedAppUsage |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2156 | public Transaction show(SurfaceControl sc) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2157 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2158 | nativeSetFlags(mNativeObject, sc.mNativeObject, 0, SURFACE_HIDDEN); |
| 2159 | return this; |
| 2160 | } |
| 2161 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2162 | /** |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 2163 | * Request that a given surface and it's sub-tree be hidden. |
| 2164 | * |
| 2165 | * @param sc The surface to hidden. |
| 2166 | * @return This transaction. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2167 | * @hide |
| 2168 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 2169 | @UnsupportedAppUsage |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2170 | public Transaction hide(SurfaceControl sc) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2171 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2172 | nativeSetFlags(mNativeObject, sc.mNativeObject, SURFACE_HIDDEN, SURFACE_HIDDEN); |
| 2173 | return this; |
| 2174 | } |
| 2175 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2176 | /** |
| 2177 | * @hide |
| 2178 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 2179 | @UnsupportedAppUsage |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2180 | public Transaction setPosition(SurfaceControl sc, float x, float y) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2181 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2182 | nativeSetPosition(mNativeObject, sc.mNativeObject, x, y); |
| 2183 | return this; |
| 2184 | } |
| 2185 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2186 | /** |
Robert Carr | 29fe58a | 2019-03-11 15:25:16 -0700 | [diff] [blame] | 2187 | * Set the default buffer size for the SurfaceControl, if there is a |
| 2188 | * {@link Surface} associated with the control, then |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 2189 | * this will be the default size for buffers dequeued from it. |
| 2190 | * @param sc The surface to set the buffer size for. |
| 2191 | * @param w The default width |
| 2192 | * @param h The default height |
| 2193 | * @return This Transaction |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2194 | */ |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 2195 | @NonNull |
| 2196 | public Transaction setBufferSize(@NonNull SurfaceControl sc, |
| 2197 | @IntRange(from = 0) int w, @IntRange(from = 0) int h) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2198 | sc.checkNotReleased(); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 2199 | mResizedSurfaces.put(sc, new Point(w, h)); |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2200 | nativeSetSize(mNativeObject, sc.mNativeObject, w, h); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2201 | return this; |
| 2202 | } |
| 2203 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2204 | /** |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 2205 | * Set the Z-order for a given SurfaceControl, relative to it's siblings. |
| 2206 | * If two siblings share the same Z order the ordering is undefined. Surfaces |
| 2207 | * with a negative Z will be placed below the parent surface. |
| 2208 | * |
| 2209 | * @param sc The SurfaceControl to set the Z order on |
| 2210 | * @param z The Z-order |
| 2211 | * @return This Transaction. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2212 | */ |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 2213 | @NonNull |
| 2214 | public Transaction setLayer(@NonNull SurfaceControl sc, |
| 2215 | @IntRange(from = Integer.MIN_VALUE, to = Integer.MAX_VALUE) int z) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2216 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2217 | nativeSetLayer(mNativeObject, sc.mNativeObject, z); |
| 2218 | return this; |
| 2219 | } |
| 2220 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2221 | /** |
| 2222 | * @hide |
| 2223 | */ |
Robert Carr | 77e3494 | 2017-10-18 19:13:56 -0700 | [diff] [blame] | 2224 | public Transaction setRelativeLayer(SurfaceControl sc, SurfaceControl relativeTo, int z) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2225 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2226 | nativeSetRelativeLayer(mNativeObject, sc.mNativeObject, |
Robert Carr | 77e3494 | 2017-10-18 19:13:56 -0700 | [diff] [blame] | 2227 | relativeTo.getHandle(), z); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2228 | return this; |
| 2229 | } |
| 2230 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2231 | /** |
| 2232 | * @hide |
| 2233 | */ |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2234 | public Transaction setTransparentRegionHint(SurfaceControl sc, Region transparentRegion) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2235 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2236 | nativeSetTransparentRegionHint(mNativeObject, |
| 2237 | sc.mNativeObject, transparentRegion); |
| 2238 | return this; |
| 2239 | } |
| 2240 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2241 | /** |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 2242 | * Set the alpha for a given surface. If the alpha is non-zero the SurfaceControl |
| 2243 | * will be blended with the Surfaces under it according to the specified ratio. |
| 2244 | * |
| 2245 | * @param sc The given SurfaceControl. |
| 2246 | * @param alpha The alpha to set. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2247 | */ |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 2248 | @NonNull |
| 2249 | public Transaction setAlpha(@NonNull SurfaceControl sc, |
| 2250 | @FloatRange(from = 0.0, to = 1.0) float alpha) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2251 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2252 | nativeSetAlpha(mNativeObject, sc.mNativeObject, alpha); |
| 2253 | return this; |
| 2254 | } |
| 2255 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2256 | /** |
| 2257 | * @hide |
| 2258 | */ |
Robert Carr | 788f574 | 2018-07-30 17:46:45 -0700 | [diff] [blame] | 2259 | public Transaction setInputWindowInfo(SurfaceControl sc, InputWindowHandle handle) { |
| 2260 | sc.checkNotReleased(); |
| 2261 | nativeSetInputWindowInfo(mNativeObject, sc.mNativeObject, handle); |
| 2262 | return this; |
| 2263 | } |
| 2264 | |
chaviw | 59f532e | 2018-12-26 15:34:59 -0800 | [diff] [blame] | 2265 | /** |
| 2266 | * Transfers touch focus from one window to another. It is possible for multiple windows to |
| 2267 | * have touch focus if they support split touch dispatch |
| 2268 | * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this |
| 2269 | * method only transfers touch focus of the specified window without affecting |
| 2270 | * other windows that may also have touch focus at the same time. |
| 2271 | * @param fromToken The token of a window that currently has touch focus. |
| 2272 | * @param toToken The token of the window that should receive touch focus in |
| 2273 | * place of the first. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2274 | * @hide |
chaviw | 59f532e | 2018-12-26 15:34:59 -0800 | [diff] [blame] | 2275 | */ |
| 2276 | public Transaction transferTouchFocus(IBinder fromToken, IBinder toToken) { |
| 2277 | nativeTransferTouchFocus(mNativeObject, fromToken, toToken); |
| 2278 | return this; |
| 2279 | } |
| 2280 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2281 | /** |
chaviw | 319cd078 | 2019-02-14 11:00:23 -0800 | [diff] [blame] | 2282 | * Waits until any changes to input windows have been sent from SurfaceFlinger to |
| 2283 | * InputFlinger before returning. |
| 2284 | * |
| 2285 | * @hide |
| 2286 | */ |
| 2287 | public Transaction syncInputWindows() { |
| 2288 | nativeSyncInputWindows(mNativeObject); |
| 2289 | return this; |
| 2290 | } |
| 2291 | |
| 2292 | /** |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 2293 | * Specify how the buffer assosciated with this Surface is mapped in to the |
| 2294 | * parent coordinate space. The source frame will be scaled to fit the destination |
| 2295 | * frame, after being rotated according to the orientation parameter. |
| 2296 | * |
| 2297 | * @param sc The SurfaceControl to specify the geometry of |
| 2298 | * @param sourceCrop The source rectangle in buffer space. Or null for the entire buffer. |
| 2299 | * @param destFrame The destination rectangle in parent space. Or null for the source frame. |
| 2300 | * @param orientation The buffer rotation |
| 2301 | * @return This transaction object. |
| 2302 | */ |
| 2303 | @NonNull |
| 2304 | public Transaction setGeometry(@NonNull SurfaceControl sc, @Nullable Rect sourceCrop, |
| 2305 | @Nullable Rect destFrame, @Surface.Rotation int orientation) { |
| 2306 | sc.checkNotReleased(); |
| 2307 | nativeSetGeometry(mNativeObject, sc.mNativeObject, sourceCrop, destFrame, orientation); |
| 2308 | return this; |
| 2309 | } |
| 2310 | |
| 2311 | /** |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2312 | * @hide |
| 2313 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 2314 | @UnsupportedAppUsage |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2315 | public Transaction setMatrix(SurfaceControl sc, |
| 2316 | float dsdx, float dtdx, float dtdy, float dsdy) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2317 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2318 | nativeSetMatrix(mNativeObject, sc.mNativeObject, |
| 2319 | dsdx, dtdx, dtdy, dsdy); |
| 2320 | return this; |
| 2321 | } |
| 2322 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2323 | /** |
| 2324 | * @hide |
| 2325 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 2326 | @UnsupportedAppUsage |
Jorim Jaggi | 21c39a7 | 2017-10-20 15:47:51 +0200 | [diff] [blame] | 2327 | public Transaction setMatrix(SurfaceControl sc, Matrix matrix, float[] float9) { |
| 2328 | matrix.getValues(float9); |
| 2329 | setMatrix(sc, float9[MSCALE_X], float9[MSKEW_Y], |
| 2330 | float9[MSKEW_X], float9[MSCALE_Y]); |
| 2331 | setPosition(sc, float9[MTRANS_X], float9[MTRANS_Y]); |
| 2332 | return this; |
| 2333 | } |
| 2334 | |
Peiyong Lin | 52bb6b4 | 2018-10-01 11:40:50 -0700 | [diff] [blame] | 2335 | /** |
| 2336 | * Sets the color transform for the Surface. |
| 2337 | * @param matrix A float array with 9 values represents a 3x3 transform matrix |
| 2338 | * @param translation A float array with 3 values represents a translation vector |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2339 | * @hide |
Peiyong Lin | 52bb6b4 | 2018-10-01 11:40:50 -0700 | [diff] [blame] | 2340 | */ |
| 2341 | public Transaction setColorTransform(SurfaceControl sc, @Size(9) float[] matrix, |
| 2342 | @Size(3) float[] translation) { |
| 2343 | sc.checkNotReleased(); |
| 2344 | nativeSetColorTransform(mNativeObject, sc.mNativeObject, matrix, translation); |
| 2345 | return this; |
| 2346 | } |
| 2347 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2348 | /** |
Peiyong Lin | f4f0f64 | 2019-03-01 14:36:05 -0800 | [diff] [blame] | 2349 | * Sets the Surface to be color space agnostic. If a surface is color space agnostic, |
| 2350 | * the color can be interpreted in any color space. |
| 2351 | * @param agnostic A boolean to indicate whether the surface is color space agnostic |
| 2352 | * @hide |
| 2353 | */ |
| 2354 | public Transaction setColorSpaceAgnostic(SurfaceControl sc, boolean agnostic) { |
| 2355 | sc.checkNotReleased(); |
| 2356 | nativeSetColorSpaceAgnostic(mNativeObject, sc.mNativeObject, agnostic); |
| 2357 | return this; |
| 2358 | } |
| 2359 | |
| 2360 | /** |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2361 | * @hide |
| 2362 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 2363 | @UnsupportedAppUsage |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2364 | public Transaction setWindowCrop(SurfaceControl sc, Rect crop) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2365 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2366 | if (crop != null) { |
| 2367 | nativeSetWindowCrop(mNativeObject, sc.mNativeObject, |
| 2368 | crop.left, crop.top, crop.right, crop.bottom); |
| 2369 | } else { |
| 2370 | nativeSetWindowCrop(mNativeObject, sc.mNativeObject, 0, 0, 0, 0); |
| 2371 | } |
| 2372 | |
| 2373 | return this; |
| 2374 | } |
| 2375 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2376 | /** |
| 2377 | * @hide |
| 2378 | */ |
Vishnu Nair | d454442d | 2018-11-13 13:51:01 -0800 | [diff] [blame] | 2379 | public Transaction setWindowCrop(SurfaceControl sc, int width, int height) { |
| 2380 | sc.checkNotReleased(); |
| 2381 | nativeSetWindowCrop(mNativeObject, sc.mNativeObject, 0, 0, width, height); |
| 2382 | return this; |
| 2383 | } |
| 2384 | |
Lucas Dupin | ff9d6ab | 2018-10-16 18:05:50 -0700 | [diff] [blame] | 2385 | /** |
| 2386 | * Sets the corner radius of a {@link SurfaceControl}. |
| 2387 | * @param sc SurfaceControl |
| 2388 | * @param cornerRadius Corner radius in pixels. |
| 2389 | * @return Itself. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2390 | * @hide |
Lucas Dupin | ff9d6ab | 2018-10-16 18:05:50 -0700 | [diff] [blame] | 2391 | */ |
| 2392 | @UnsupportedAppUsage |
| 2393 | public Transaction setCornerRadius(SurfaceControl sc, float cornerRadius) { |
| 2394 | sc.checkNotReleased(); |
| 2395 | nativeSetCornerRadius(mNativeObject, sc.mNativeObject, cornerRadius); |
| 2396 | |
| 2397 | return this; |
| 2398 | } |
| 2399 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2400 | /** |
| 2401 | * @hide |
| 2402 | */ |
Mathew Inwood | 679c15e | 2019-02-06 15:36:04 +0000 | [diff] [blame] | 2403 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.O) |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2404 | public Transaction setLayerStack(SurfaceControl sc, int layerStack) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2405 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2406 | nativeSetLayerStack(mNativeObject, sc.mNativeObject, layerStack); |
| 2407 | return this; |
| 2408 | } |
| 2409 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2410 | /** |
| 2411 | * @hide |
| 2412 | */ |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 2413 | @UnsupportedAppUsage |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2414 | public Transaction deferTransactionUntil(SurfaceControl sc, IBinder handle, |
| 2415 | long frameNumber) { |
Robert Carr | 024378c | 2018-02-27 11:21:05 -0800 | [diff] [blame] | 2416 | if (frameNumber < 0) { |
| 2417 | return this; |
| 2418 | } |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2419 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2420 | nativeDeferTransactionUntil(mNativeObject, sc.mNativeObject, handle, frameNumber); |
| 2421 | return this; |
| 2422 | } |
| 2423 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2424 | /** |
| 2425 | * @hide |
| 2426 | */ |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 2427 | @UnsupportedAppUsage |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2428 | public Transaction deferTransactionUntilSurface(SurfaceControl sc, Surface barrierSurface, |
| 2429 | long frameNumber) { |
Robert Carr | 024378c | 2018-02-27 11:21:05 -0800 | [diff] [blame] | 2430 | if (frameNumber < 0) { |
| 2431 | return this; |
| 2432 | } |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2433 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2434 | nativeDeferTransactionUntilSurface(mNativeObject, sc.mNativeObject, |
| 2435 | barrierSurface.mNativeObject, frameNumber); |
| 2436 | return this; |
| 2437 | } |
| 2438 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2439 | /** |
| 2440 | * @hide |
| 2441 | */ |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2442 | public Transaction reparentChildren(SurfaceControl sc, IBinder newParentHandle) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2443 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2444 | nativeReparentChildren(mNativeObject, sc.mNativeObject, newParentHandle); |
| 2445 | return this; |
| 2446 | } |
| 2447 | |
Robert Carr | 10584fa | 2019-01-14 15:55:19 -0800 | [diff] [blame] | 2448 | /** |
| 2449 | * Re-parents a given layer to a new parent. Children inherit transform (position, scaling) |
| 2450 | * crop, visibility, and Z-ordering from their parents, as if the children were pixels within the |
| 2451 | * parent Surface. |
| 2452 | * |
| 2453 | * @param sc The SurfaceControl to reparent |
| 2454 | * @param newParent The new parent for the given control. |
| 2455 | * @return This Transaction |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2456 | */ |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 2457 | @NonNull |
| 2458 | public Transaction reparent(@NonNull SurfaceControl sc, |
| 2459 | @Nullable SurfaceControl newParent) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2460 | sc.checkNotReleased(); |
Robert Carr | 10584fa | 2019-01-14 15:55:19 -0800 | [diff] [blame] | 2461 | long otherObject = 0; |
| 2462 | if (newParent != null) { |
| 2463 | newParent.checkNotReleased(); |
| 2464 | otherObject = newParent.mNativeObject; |
| 2465 | } |
| 2466 | nativeReparent(mNativeObject, sc.mNativeObject, otherObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2467 | return this; |
| 2468 | } |
| 2469 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2470 | /** |
| 2471 | * @hide |
| 2472 | */ |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2473 | public Transaction detachChildren(SurfaceControl sc) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2474 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2475 | nativeSeverChildren(mNativeObject, sc.mNativeObject); |
| 2476 | return this; |
| 2477 | } |
| 2478 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2479 | /** |
| 2480 | * @hide |
| 2481 | */ |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2482 | public Transaction setOverrideScalingMode(SurfaceControl sc, int overrideScalingMode) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2483 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2484 | nativeSetOverrideScalingMode(mNativeObject, sc.mNativeObject, |
| 2485 | overrideScalingMode); |
| 2486 | return this; |
| 2487 | } |
| 2488 | |
| 2489 | /** |
| 2490 | * Sets a color for the Surface. |
| 2491 | * @param color A float array with three values to represent r, g, b in range [0..1] |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2492 | * @hide |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2493 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 2494 | @UnsupportedAppUsage |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2495 | public Transaction setColor(SurfaceControl sc, @Size(3) float[] color) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2496 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2497 | nativeSetColor(mNativeObject, sc.mNativeObject, color); |
| 2498 | return this; |
| 2499 | } |
| 2500 | |
| 2501 | /** |
| 2502 | * If the buffer size changes in this transaction, position and crop updates specified |
| 2503 | * in this transaction will not complete until a buffer of the new size |
| 2504 | * arrives. As transform matrix and size are already frozen in this fashion, |
| 2505 | * this enables totally freezing the surface until the resize has completed |
| 2506 | * (at which point the geometry influencing aspects of this transaction will then occur) |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2507 | * @hide |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2508 | */ |
| 2509 | public Transaction setGeometryAppliesWithResize(SurfaceControl sc) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2510 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2511 | nativeSetGeometryAppliesWithResize(mNativeObject, sc.mNativeObject); |
| 2512 | return this; |
| 2513 | } |
| 2514 | |
| 2515 | /** |
| 2516 | * Sets the security of the surface. Setting the flag is equivalent to creating the |
| 2517 | * Surface with the {@link #SECURE} flag. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2518 | * @hide |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2519 | */ |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 2520 | public Transaction setSecure(SurfaceControl sc, boolean isSecure) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2521 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2522 | if (isSecure) { |
| 2523 | nativeSetFlags(mNativeObject, sc.mNativeObject, SECURE, SECURE); |
| 2524 | } else { |
| 2525 | nativeSetFlags(mNativeObject, sc.mNativeObject, 0, SECURE); |
| 2526 | } |
| 2527 | return this; |
| 2528 | } |
| 2529 | |
| 2530 | /** |
| 2531 | * Sets the opacity of the surface. Setting the flag is equivalent to creating the |
| 2532 | * Surface with the {@link #OPAQUE} flag. |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2533 | * @hide |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2534 | */ |
| 2535 | public Transaction setOpaque(SurfaceControl sc, boolean isOpaque) { |
Jorim Jaggi | dfc2737 | 2017-10-27 17:47:49 +0200 | [diff] [blame] | 2536 | sc.checkNotReleased(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2537 | if (isOpaque) { |
Robert Carr | 2b8a5e1 | 2017-10-18 18:46:27 -0700 | [diff] [blame] | 2538 | nativeSetFlags(mNativeObject, sc.mNativeObject, SURFACE_OPAQUE, SURFACE_OPAQUE); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2539 | } else { |
Robert Carr | 2b8a5e1 | 2017-10-18 18:46:27 -0700 | [diff] [blame] | 2540 | nativeSetFlags(mNativeObject, sc.mNativeObject, 0, SURFACE_OPAQUE); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2541 | } |
| 2542 | return this; |
| 2543 | } |
| 2544 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2545 | /** |
| 2546 | * @hide |
| 2547 | */ |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2548 | public Transaction setDisplaySurface(IBinder displayToken, Surface surface) { |
| 2549 | if (displayToken == null) { |
| 2550 | throw new IllegalArgumentException("displayToken must not be null"); |
| 2551 | } |
| 2552 | |
| 2553 | if (surface != null) { |
| 2554 | synchronized (surface.mLock) { |
| 2555 | nativeSetDisplaySurface(mNativeObject, displayToken, surface.mNativeObject); |
| 2556 | } |
| 2557 | } else { |
| 2558 | nativeSetDisplaySurface(mNativeObject, displayToken, 0); |
| 2559 | } |
| 2560 | return this; |
| 2561 | } |
| 2562 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2563 | /** |
| 2564 | * @hide |
| 2565 | */ |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2566 | public Transaction setDisplayLayerStack(IBinder displayToken, int layerStack) { |
| 2567 | if (displayToken == null) { |
| 2568 | throw new IllegalArgumentException("displayToken must not be null"); |
| 2569 | } |
| 2570 | nativeSetDisplayLayerStack(mNativeObject, displayToken, layerStack); |
| 2571 | return this; |
| 2572 | } |
| 2573 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2574 | /** |
| 2575 | * @hide |
| 2576 | */ |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2577 | public Transaction setDisplayProjection(IBinder displayToken, |
| 2578 | int orientation, Rect layerStackRect, Rect displayRect) { |
| 2579 | if (displayToken == null) { |
| 2580 | throw new IllegalArgumentException("displayToken must not be null"); |
| 2581 | } |
| 2582 | if (layerStackRect == null) { |
| 2583 | throw new IllegalArgumentException("layerStackRect must not be null"); |
| 2584 | } |
| 2585 | if (displayRect == null) { |
| 2586 | throw new IllegalArgumentException("displayRect must not be null"); |
| 2587 | } |
| 2588 | nativeSetDisplayProjection(mNativeObject, displayToken, orientation, |
| 2589 | layerStackRect.left, layerStackRect.top, layerStackRect.right, layerStackRect.bottom, |
| 2590 | displayRect.left, displayRect.top, displayRect.right, displayRect.bottom); |
| 2591 | return this; |
| 2592 | } |
| 2593 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2594 | /** |
| 2595 | * @hide |
| 2596 | */ |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2597 | public Transaction setDisplaySize(IBinder displayToken, int width, int height) { |
| 2598 | if (displayToken == null) { |
| 2599 | throw new IllegalArgumentException("displayToken must not be null"); |
| 2600 | } |
| 2601 | if (width <= 0 || height <= 0) { |
| 2602 | throw new IllegalArgumentException("width and height must be positive"); |
| 2603 | } |
| 2604 | |
| 2605 | nativeSetDisplaySize(mNativeObject, displayToken, width, height); |
| 2606 | return this; |
| 2607 | } |
| 2608 | |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2609 | /** flag the transaction as an animation |
| 2610 | * @hide |
| 2611 | */ |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2612 | public Transaction setAnimationTransaction() { |
| 2613 | nativeSetAnimationTransaction(mNativeObject); |
| 2614 | return this; |
| 2615 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 2616 | |
| 2617 | /** |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 2618 | * Indicate that SurfaceFlinger should wake up earlier than usual as a result of this |
| 2619 | * transaction. This should be used when the caller thinks that the scene is complex enough |
| 2620 | * that it's likely to hit GL composition, and thus, SurfaceFlinger needs to more time in |
| 2621 | * order not to miss frame deadlines. |
| 2622 | * <p> |
| 2623 | * Corresponds to setting ISurfaceComposer::eEarlyWakeup |
Robert Carr | a7827f7 | 2019-01-11 12:53:37 -0800 | [diff] [blame] | 2624 | * @hide |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 2625 | */ |
| 2626 | public Transaction setEarlyWakeup() { |
| 2627 | nativeSetEarlyWakeup(mNativeObject); |
| 2628 | return this; |
| 2629 | } |
| 2630 | |
| 2631 | /** |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 2632 | * Sets an arbitrary piece of metadata on the surface. This is a helper for int data. |
| 2633 | * @hide |
| 2634 | */ |
Evan Rosky | b51e246 | 2019-04-03 19:27:18 -0700 | [diff] [blame] | 2635 | public Transaction setMetadata(SurfaceControl sc, int key, int data) { |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 2636 | Parcel parcel = Parcel.obtain(); |
| 2637 | parcel.writeInt(data); |
| 2638 | try { |
Evan Rosky | b51e246 | 2019-04-03 19:27:18 -0700 | [diff] [blame] | 2639 | setMetadata(sc, key, parcel); |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 2640 | } finally { |
| 2641 | parcel.recycle(); |
| 2642 | } |
| 2643 | return this; |
| 2644 | } |
| 2645 | |
| 2646 | /** |
| 2647 | * Sets an arbitrary piece of metadata on the surface. |
| 2648 | * @hide |
| 2649 | */ |
Evan Rosky | b51e246 | 2019-04-03 19:27:18 -0700 | [diff] [blame] | 2650 | public Transaction setMetadata(SurfaceControl sc, int key, Parcel data) { |
| 2651 | nativeSetMetadata(mNativeObject, sc.mNativeObject, key, data); |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 2652 | return this; |
| 2653 | } |
| 2654 | |
| 2655 | /** |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 2656 | * Merge the other transaction into this transaction, clearing the |
| 2657 | * other transaction as if it had been applied. |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 2658 | * |
| 2659 | * @param other The transaction to merge in to this one. |
| 2660 | * @return This transaction. |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 2661 | */ |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 2662 | @NonNull |
| 2663 | public Transaction merge(@NonNull Transaction other) { |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 2664 | if (this == other) { |
| 2665 | return this; |
| 2666 | } |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 2667 | mResizedSurfaces.putAll(other.mResizedSurfaces); |
| 2668 | other.mResizedSurfaces.clear(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 2669 | nativeMergeTransaction(mNativeObject, other.mNativeObject); |
| 2670 | return this; |
| 2671 | } |
Robert Carr | 71200f2 | 2019-02-05 09:44:53 -0800 | [diff] [blame] | 2672 | |
| 2673 | /** |
| 2674 | * Equivalent to reparent with a null parent, in that it removes |
| 2675 | * the SurfaceControl from the scene, but it also releases |
| 2676 | * the local resources (by calling {@link SurfaceControl#release}) |
| 2677 | * after this method returns, {@link SurfaceControl#isValid} will return |
| 2678 | * false for the argument. |
| 2679 | * |
| 2680 | * @param sc The surface to remove and release. |
| 2681 | * @return This transaction |
| 2682 | * @hide |
| 2683 | */ |
| 2684 | @NonNull |
| 2685 | public Transaction remove(@NonNull SurfaceControl sc) { |
| 2686 | reparent(sc, null); |
| 2687 | sc.release(); |
| 2688 | return this; |
| 2689 | } |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 2690 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 2691 | } |