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