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