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