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