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