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