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