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