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