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