blob: 6458737d326d595c7062154c35151492e8e808ba [file] [log] [blame]
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001/*
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
17package android.view;
18
Jorim Jaggi21c39a72017-10-20 15:47:51 +020019import static android.graphics.Matrix.MSCALE_X;
20import static android.graphics.Matrix.MSCALE_Y;
21import static android.graphics.Matrix.MSKEW_X;
22import static android.graphics.Matrix.MSKEW_Y;
23import static android.graphics.Matrix.MTRANS_X;
24import static android.graphics.Matrix.MTRANS_Y;
Vishnu Nair04ab4392018-01-10 11:00:06 -080025import static android.view.Surface.ROTATION_270;
26import static android.view.Surface.ROTATION_90;
27import static android.view.SurfaceControlProto.HASH_CODE;
28import static android.view.SurfaceControlProto.NAME;
chaviwa69e0a72017-11-29 17:55:12 -080029
Robert Carr76907ee2019-01-11 13:38:19 -080030import android.annotation.FloatRange;
31import android.annotation.IntRange;
32import android.annotation.NonNull;
33import android.annotation.Nullable;
chaviw0dd03f52017-08-25 12:15:26 -070034import android.annotation.Size;
Mathew Inwooda570dee2018-08-17 14:56:00 +010035import android.annotation.UnsupportedAppUsage;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080036import android.graphics.Bitmap;
Peiyong Lin5f4a5682019-01-17 11:37:07 -080037import android.graphics.ColorSpace;
Robert Carr6486d312017-01-09 19:48:29 -080038import android.graphics.GraphicBuffer;
Jorim Jaggi21c39a72017-10-20 15:47:51 +020039import android.graphics.Matrix;
Vishnu Nair04ab4392018-01-10 11:00:06 -080040import android.graphics.PixelFormat;
Jorim Jaggia5e10572017-11-15 14:36:26 +010041import android.graphics.Point;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080042import android.graphics.Rect;
43import android.graphics.Region;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -070044import android.hardware.display.DisplayedContentSample;
45import android.hardware.display.DisplayedContentSamplingAttributes;
Mathew Inwood679c15e2019-02-06 15:36:04 +000046import android.os.Build;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080047import android.os.IBinder;
Jorim Jaggi06975df2017-12-01 14:52:13 +010048import android.os.Parcel;
49import android.os.Parcelable;
Jorim Jaggia5e10572017-11-15 14:36:26 +010050import android.util.ArrayMap;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080051import android.util.Log;
Evan Rosky485df202018-12-06 14:11:12 -080052import android.util.SparseIntArray;
Vishnu Nair04ab4392018-01-10 11:00:06 -080053import android.util.proto.ProtoOutputStream;
Igor Murashkina86ab6402013-08-30 12:58:36 -070054import android.view.Surface.OutOfResourcesException;
Jorim Jaggia5e10572017-11-15 14:36:26 +010055
56import com.android.internal.annotations.GuardedBy;
57
Aurimas Liutikas67e2ae82016-10-11 18:17:42 -070058import dalvik.system.CloseGuard;
Vishnu Nair04ab4392018-01-10 11:00:06 -080059
Robert Carre625fcf2017-09-01 12:36:28 -070060import libcore.util.NativeAllocationRegistry;
Aurimas Liutikas67e2ae82016-10-11 18:17:42 -070061
Robert Carre13b58e2017-08-31 14:50:44 -070062import java.io.Closeable;
Evan Rosky485df202018-12-06 14:11:12 -080063import java.nio.ByteBuffer;
Evan Roskyc12c9a32019-02-06 13:38:03 -080064import java.nio.ByteOrder;
Dan Gittik832b4972019-02-13 18:17:47 +000065import java.util.Objects;
Robert Carre13b58e2017-08-31 14:50:44 -070066
Mathias Agopian3866f0d2013-02-11 22:08:48 -080067/**
Robert Carr76907ee2019-01-11 13:38:19 -080068 * 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 Agopian3866f0d2013-02-11 22:08:48 -080076 */
Robert Carr76907ee2019-01-11 13:38:19 -080077public final class SurfaceControl implements Parcelable {
Mathias Agopian3866f0d2013-02-11 22:08:48 -080078 private static final String TAG = "SurfaceControl";
Mathias Agopian29479eb2013-02-14 14:36:04 -080079
Ashok Bhat36bef0b2014-01-20 20:08:01 +000080 private static native long nativeCreate(SurfaceSession session, String name,
Evan Rosky485df202018-12-06 14:11:12 -080081 int w, int h, int format, int flags, long parentObject, Parcel metadata)
Mathias Agopian29479eb2013-02-14 14:36:04 -080082 throws OutOfResourcesException;
Jorim Jaggi06975df2017-12-01 14:52:13 +010083 private static native long nativeReadFromParcel(Parcel in);
chaviwbeb7a0c2018-12-05 13:49:54 -080084 private static native long nativeCopyFromSurfaceControl(long nativeObject);
Jorim Jaggi06975df2017-12-01 14:52:13 +010085 private static native void nativeWriteToParcel(long nativeObject, Parcel out);
Ashok Bhat36bef0b2014-01-20 20:08:01 +000086 private static native void nativeRelease(long nativeObject);
Chong Zhang47e36a32016-02-29 16:44:33 -080087 private static native void nativeDisconnect(long nativeObject);
Mathias Agopian29479eb2013-02-14 14:36:04 -080088
Peiyong Line3e5efd2019-03-21 20:59:47 +000089 private static native ScreenshotGraphicBuffer nativeScreenshot(IBinder displayToken,
Robert Carr5c52b132019-02-15 15:48:11 -080090 Rect sourceCrop, int width, int height, boolean useIdentityTransform, int rotation,
91 boolean captureSecureLayers);
Peiyong Lin21e499a2019-04-03 16:37:46 -070092 private static native ScreenshotGraphicBuffer nativeCaptureLayers(IBinder displayToken,
Chiawei Wang02202d12019-01-03 18:12:13 +080093 long layerObject, Rect sourceCrop, float frameScale, long[] excludeLayerObjects,
94 int format);
chaviwa51724f2019-09-19 09:50:11 -070095 private static native long nativeMirrorSurface(long mirrorOfObject);
Robert Carre13b58e2017-08-31 14:50:44 -070096 private static native long nativeCreateTransaction();
97 private static native long nativeGetNativeTransactionFinalizer();
98 private static native void nativeApplyTransaction(long transactionObj, boolean sync);
Robert Carrb1579c82017-09-05 14:54:47 -070099 private static native void nativeMergeTransaction(long transactionObj,
100 long otherTransactionObj);
Robert Carre13b58e2017-08-31 14:50:44 -0700101 private static native void nativeSetAnimationTransaction(long transactionObj);
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100102 private static native void nativeSetEarlyWakeup(long transactionObj);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800103
Robert Carre13b58e2017-08-31 14:50:44 -0700104 private static native void nativeSetLayer(long transactionObj, long nativeObject, int zorder);
105 private static native void nativeSetRelativeLayer(long transactionObj, long nativeObject,
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700106 long relativeToObject, int zorder);
Robert Carre13b58e2017-08-31 14:50:44 -0700107 private static native void nativeSetPosition(long transactionObj, long nativeObject,
108 float x, float y);
Robert Carre13b58e2017-08-31 14:50:44 -0700109 private static native void nativeSetSize(long transactionObj, long nativeObject, int w, int h);
110 private static native void nativeSetTransparentRegionHint(long transactionObj,
111 long nativeObject, Region region);
112 private static native void nativeSetAlpha(long transactionObj, long nativeObject, float alpha);
113 private static native void nativeSetMatrix(long transactionObj, long nativeObject,
114 float dsdx, float dtdx,
Andrii Kulian283acd22017-08-03 04:03:51 -0700115 float dtdy, float dsdy);
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700116 private static native void nativeSetColorTransform(long transactionObj, long nativeObject,
117 float[] matrix, float[] translation);
Peiyong Linf4f0f642019-03-01 14:36:05 -0800118 private static native void nativeSetColorSpaceAgnostic(long transactionObj, long nativeObject,
119 boolean agnostic);
Robert Carr76907ee2019-01-11 13:38:19 -0800120 private static native void nativeSetGeometry(long transactionObj, long nativeObject,
121 Rect sourceCrop, Rect dest, long orientation);
Robert Carre13b58e2017-08-31 14:50:44 -0700122 private static native void nativeSetColor(long transactionObj, long nativeObject, float[] color);
123 private static native void nativeSetFlags(long transactionObj, long nativeObject,
124 int flags, int mask);
125 private static native void nativeSetWindowCrop(long transactionObj, long nativeObject,
126 int l, int t, int r, int b);
Lucas Dupinff9d6ab2018-10-16 18:05:50 -0700127 private static native void nativeSetCornerRadius(long transactionObj, long nativeObject,
128 float cornerRadius);
Robert Carre13b58e2017-08-31 14:50:44 -0700129 private static native void nativeSetLayerStack(long transactionObj, long nativeObject,
130 int layerStack);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800131
Svetoslav1376d602014-03-13 11:17:26 -0700132 private static native boolean nativeClearContentFrameStats(long nativeObject);
133 private static native boolean nativeGetContentFrameStats(long nativeObject, WindowContentFrameStats outStats);
134 private static native boolean nativeClearAnimationFrameStats();
135 private static native boolean nativeGetAnimationFrameStats(WindowAnimationFrameStats outStats);
136
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800137 private static native long[] nativeGetPhysicalDisplayIds();
138 private static native IBinder nativeGetPhysicalDisplayToken(long physicalDisplayId);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800139 private static native IBinder nativeCreateDisplay(String name, boolean secure);
Jesse Hall6a6bc212013-08-08 12:15:03 -0700140 private static native void nativeDestroyDisplay(IBinder displayToken);
Robert Carre13b58e2017-08-31 14:50:44 -0700141 private static native void nativeSetDisplaySurface(long transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000142 IBinder displayToken, long nativeSurfaceObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700143 private static native void nativeSetDisplayLayerStack(long transactionObj,
Mathias Agopian29479eb2013-02-14 14:36:04 -0800144 IBinder displayToken, int layerStack);
Robert Carre13b58e2017-08-31 14:50:44 -0700145 private static native void nativeSetDisplayProjection(long transactionObj,
Mathias Agopian29479eb2013-02-14 14:36:04 -0800146 IBinder displayToken, int orientation,
Jesse Hall6a6bc212013-08-08 12:15:03 -0700147 int l, int t, int r, int b,
Mathias Agopian29479eb2013-02-14 14:36:04 -0800148 int L, int T, int R, int B);
Robert Carre13b58e2017-08-31 14:50:44 -0700149 private static native void nativeSetDisplaySize(long transactionObj, IBinder displayToken,
150 int width, int height);
Dan Stoza00101052014-05-02 15:23:40 -0700151 private static native SurfaceControl.PhysicalDisplayInfo[] nativeGetDisplayConfigs(
152 IBinder displayToken);
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700153 private static native DisplayedContentSamplingAttributes
154 nativeGetDisplayedContentSamplingAttributes(IBinder displayToken);
155 private static native boolean nativeSetDisplayedContentSamplingEnabled(IBinder displayToken,
156 boolean enable, int componentMask, int maxFrames);
157 private static native DisplayedContentSample nativeGetDisplayedContentSample(
158 IBinder displayToken, long numFrames, long timestamp);
Dan Stoza00101052014-05-02 15:23:40 -0700159 private static native int nativeGetActiveConfig(IBinder displayToken);
160 private static native boolean nativeSetActiveConfig(IBinder displayToken, int id);
Ady Abraham6070ce12019-01-24 18:48:58 -0800161 private static native boolean nativeSetAllowedDisplayConfigs(IBinder displayToken,
162 int[] allowedConfigs);
Ady Abraham42f9a2fb2019-02-26 14:13:39 -0800163 private static native int[] nativeGetAllowedDisplayConfigs(IBinder displayToken);
Michael Wright1c9977b2016-07-12 13:30:10 -0700164 private static native int[] nativeGetDisplayColorModes(IBinder displayToken);
Daniel Solomon10e3b332019-01-20 21:09:11 -0800165 private static native SurfaceControl.DisplayPrimaries nativeGetDisplayNativePrimaries(
166 IBinder displayToken);
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800167 private static native int[] nativeGetCompositionDataspaces();
Michael Wright1c9977b2016-07-12 13:30:10 -0700168 private static native int nativeGetActiveColorMode(IBinder displayToken);
169 private static native boolean nativeSetActiveColorMode(IBinder displayToken,
170 int colorMode);
Prashant Malanic55929a2014-05-25 01:59:21 -0700171 private static native void nativeSetDisplayPowerMode(
172 IBinder displayToken, int mode);
Robert Carre13b58e2017-08-31 14:50:44 -0700173 private static native void nativeDeferTransactionUntil(long transactionObj, long nativeObject,
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700174 long barrierObject, long frame);
Robert Carre13b58e2017-08-31 14:50:44 -0700175 private static native void nativeDeferTransactionUntilSurface(long transactionObj,
176 long nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -0800177 long surfaceObject, long frame);
Robert Carre13b58e2017-08-31 14:50:44 -0700178 private static native void nativeReparentChildren(long transactionObj, long nativeObject,
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700179 long newParentObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700180 private static native void nativeReparent(long transactionObj, long nativeObject,
Robert Carr10584fa2019-01-14 15:55:19 -0800181 long newParentNativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700182 private static native void nativeSeverChildren(long transactionObj, long nativeObject);
183 private static native void nativeSetOverrideScalingMode(long transactionObj, long nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -0700184 int scalingMode);
Robert Carr6da3cc02016-06-16 15:17:07 -0700185
Michael Wright9ff94c02016-03-30 18:05:40 -0700186 private static native Display.HdrCapabilities nativeGetHdrCapabilities(IBinder displayToken);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800187
Robert Carr788f5742018-07-30 17:46:45 -0700188 private static native void nativeSetInputWindowInfo(long transactionObj, long nativeObject,
189 InputWindowHandle handle);
Arthur Hungc499ad32019-09-05 15:51:14 +0800190
Peiyong Lin0ddb7d42019-01-16 13:25:09 -0800191 private static native boolean nativeGetProtectedContentSupport();
Evan Roskyb51e2462019-04-03 19:27:18 -0700192 private static native void nativeSetMetadata(long transactionObj, long nativeObject, int key,
193 Parcel data);
chaviw319cd0782019-02-14 11:00:23 -0800194 private static native void nativeSyncInputWindows(long transactionObj);
Dan Gittik832b4972019-02-13 18:17:47 +0000195 private static native boolean nativeGetDisplayBrightnessSupport(IBinder displayToken);
196 private static native boolean nativeSetDisplayBrightness(IBinder displayToken,
197 float brightness);
Vishnu Nair629df2b2019-06-11 16:03:38 -0700198 private static native long nativeReadTransactionFromParcel(Parcel in);
199 private static native void nativeWriteTransactionToParcel(long nativeObject, Parcel out);
Vishnu Naird87984d2019-11-06 14:43:22 -0800200 private static native void nativeSetShadowRadius(long transactionObj, long nativeObject,
201 float shadowRadius);
Vishnu Nair4a067c52019-11-19 14:25:56 -0800202 private static native void nativeSetGlobalShadowSettings(@Size(4) float[] ambientColor,
203 @Size(4) float[] spotColor, float lightPosY, float lightPosZ, float lightRadius);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800204
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800205 private final CloseGuard mCloseGuard = CloseGuard.get();
chaviwbeb7a0c2018-12-05 13:49:54 -0800206 private String mName;
Robert Carr48ec4e02019-07-16 14:28:47 -0700207 /**
208 * @hide
209 */
210 public long mNativeObject;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800211
Jorim Jaggia5e10572017-11-15 14:36:26 +0100212 // TODO: Move this to native.
213 private final Object mSizeLock = new Object();
214 @GuardedBy("mSizeLock")
215 private int mWidth;
216 @GuardedBy("mSizeLock")
217 private int mHeight;
218
Robert Carre13b58e2017-08-31 14:50:44 -0700219 static Transaction sGlobalTransaction;
220 static long sTransactionNestCount = 0;
221
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800222 /* flags used in constructor (keep in sync with ISurfaceComposerClient.h) */
223
224 /**
225 * Surface creation flag: Surface is created hidden
Robert Carra7827f72019-01-11 12:53:37 -0800226 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800227 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100228 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800229 public static final int HIDDEN = 0x00000004;
230
231 /**
232 * Surface creation flag: The surface contains secure content, special
233 * measures will be taken to disallow the surface's content to be copied
234 * from another process. In particular, screenshots and VNC servers will
235 * be disabled, but other measures can take place, for instance the
Jesse Hall6a6bc212013-08-08 12:15:03 -0700236 * surface might not be hardware accelerated.
Robert Carra7827f72019-01-11 12:53:37 -0800237 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800238 */
239 public static final int SECURE = 0x00000080;
240
241 /**
242 * Surface creation flag: Creates a surface where color components are interpreted
243 * as "non pre-multiplied" by their alpha channel. Of course this flag is
244 * meaningless for surfaces without an alpha channel. By default
245 * surfaces are pre-multiplied, which means that each color component is
246 * already multiplied by its alpha value. In this case the blending
247 * equation used is:
Andy McFadden314405b2014-01-29 17:18:05 -0800248 * <p>
249 * <code>DEST = SRC + DEST * (1-SRC_ALPHA)</code>
250 * <p>
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800251 * By contrast, non pre-multiplied surfaces use the following equation:
Andy McFadden314405b2014-01-29 17:18:05 -0800252 * <p>
253 * <code>DEST = SRC * SRC_ALPHA * DEST * (1-SRC_ALPHA)</code>
254 * <p>
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800255 * pre-multiplied surfaces must always be used if transparent pixels are
256 * composited on top of each-other into the surface. A pre-multiplied
257 * surface can never lower the value of the alpha component of a given
258 * pixel.
Andy McFadden314405b2014-01-29 17:18:05 -0800259 * <p>
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800260 * In some rare situations, a non pre-multiplied surface is preferable.
Robert Carra7827f72019-01-11 12:53:37 -0800261 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800262 */
263 public static final int NON_PREMULTIPLIED = 0x00000100;
264
265 /**
266 * Surface creation flag: Indicates that the surface must be considered opaque,
Robert Carre625fcf2017-09-01 12:36:28 -0700267 * even if its pixel format contains an alpha channel. This can be useful if an
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800268 * application needs full RGBA 8888 support for instance but will
269 * still draw every pixel opaque.
Andy McFadden314405b2014-01-29 17:18:05 -0800270 * <p>
271 * This flag is ignored if setAlpha() is used to make the surface non-opaque.
272 * Combined effects are (assuming a buffer format with an alpha channel):
273 * <ul>
274 * <li>OPAQUE + alpha(1.0) == opaque composition
275 * <li>OPAQUE + alpha(0.x) == blended composition
276 * <li>!OPAQUE + alpha(1.0) == blended composition
277 * <li>!OPAQUE + alpha(0.x) == blended composition
278 * </ul>
279 * If the underlying buffer lacks an alpha channel, the OPAQUE flag is effectively
280 * set automatically.
Robert Carra7827f72019-01-11 12:53:37 -0800281 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800282 */
283 public static final int OPAQUE = 0x00000400;
284
285 /**
286 * Surface creation flag: Application requires a hardware-protected path to an
287 * external display sink. If a hardware-protected path is not available,
288 * then this surface will not be displayed on the external sink.
289 *
Robert Carra7827f72019-01-11 12:53:37 -0800290 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800291 */
292 public static final int PROTECTED_APP = 0x00000800;
293
294 // 0x1000 is reserved for an independent DRM protected flag in framework
295
296 /**
Riley Andrews68eccda2014-07-07 11:47:35 -0700297 * Surface creation flag: Window represents a cursor glyph.
Robert Carra7827f72019-01-11 12:53:37 -0800298 * @hide
Riley Andrews68eccda2014-07-07 11:47:35 -0700299 */
300 public static final int CURSOR_WINDOW = 0x00002000;
301
302 /**
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800303 * Surface creation flag: Creates a normal surface.
304 * This is the default.
305 *
Robert Carra7827f72019-01-11 12:53:37 -0800306 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800307 */
308 public static final int FX_SURFACE_NORMAL = 0x00000000;
309
310 /**
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800311 * Surface creation flag: Creates a Dim surface.
312 * Everything behind this surface is dimmed by the amount specified
chaviw619da692019-06-10 15:39:40 -0700313 * in {@link Transaction#setAlpha(SurfaceControl, float)}. It is an error to lock a Dim
314 * surface, since it doesn't have a backing store.
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800315 *
Robert Carra7827f72019-01-11 12:53:37 -0800316 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800317 */
318 public static final int FX_SURFACE_DIM = 0x00020000;
319
320 /**
Robert Carrb6cd6432018-08-13 13:01:47 -0700321 * Surface creation flag: Creates a container surface.
322 * This surface will have no buffers and will only be used
323 * as a container for other surfaces, or for its InputInfo.
Robert Carra7827f72019-01-11 12:53:37 -0800324 * @hide
Robert Carrb6cd6432018-08-13 13:01:47 -0700325 */
326 public static final int FX_SURFACE_CONTAINER = 0x00080000;
327
328 /**
Robert Carr48ec4e02019-07-16 14:28:47 -0700329 * @hide
330 */
331 public static final int FX_SURFACE_BLAST = 0x00040000;
332
333 /**
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800334 * Mask used for FX values above.
335 *
Robert Carra7827f72019-01-11 12:53:37 -0800336 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800337 */
338 public static final int FX_SURFACE_MASK = 0x000F0000;
339
340 /* flags used with setFlags() (keep in sync with ISurfaceComposer.h) */
341
342 /**
343 * Surface flag: Hide the surface.
344 * Equivalent to calling hide().
Andy McFadden314405b2014-01-29 17:18:05 -0800345 * Updates the value set during Surface creation (see {@link #HIDDEN}).
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800346 */
Andy McFadden40b9ef12014-01-30 13:44:47 -0800347 private static final int SURFACE_HIDDEN = 0x01;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800348
Andy McFadden314405b2014-01-29 17:18:05 -0800349 /**
350 * Surface flag: composite without blending when possible.
351 * Updates the value set during Surface creation (see {@link #OPAQUE}).
352 */
Andy McFadden40b9ef12014-01-30 13:44:47 -0800353 private static final int SURFACE_OPAQUE = 0x02;
Andy McFadden314405b2014-01-29 17:18:05 -0800354
Robert Carr76907ee2019-01-11 13:38:19 -0800355 // Display power modes.
Prashant Malanic55929a2014-05-25 01:59:21 -0700356 /**
357 * Display power mode off: used while blanking the screen.
Jeff Brown5dc21912014-07-17 18:50:18 -0700358 * Use only with {@link SurfaceControl#setDisplayPowerMode}.
Robert Carra7827f72019-01-11 12:53:37 -0800359 * @hide
Prashant Malanic55929a2014-05-25 01:59:21 -0700360 */
361 public static final int POWER_MODE_OFF = 0;
362
363 /**
364 * Display power mode doze: used while putting the screen into low power mode.
Jeff Brown5dc21912014-07-17 18:50:18 -0700365 * Use only with {@link SurfaceControl#setDisplayPowerMode}.
Robert Carra7827f72019-01-11 12:53:37 -0800366 * @hide
Prashant Malanic55929a2014-05-25 01:59:21 -0700367 */
368 public static final int POWER_MODE_DOZE = 1;
369
370 /**
371 * Display power mode normal: used while unblanking the screen.
Jeff Brown5dc21912014-07-17 18:50:18 -0700372 * Use only with {@link SurfaceControl#setDisplayPowerMode}.
Robert Carra7827f72019-01-11 12:53:37 -0800373 * @hide
Prashant Malanic55929a2014-05-25 01:59:21 -0700374 */
375 public static final int POWER_MODE_NORMAL = 2;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800376
Jeff Brown5dc21912014-07-17 18:50:18 -0700377 /**
378 * Display power mode doze: used while putting the screen into a suspended
379 * low power mode. Use only with {@link SurfaceControl#setDisplayPowerMode}.
Robert Carra7827f72019-01-11 12:53:37 -0800380 * @hide
Jeff Brown5dc21912014-07-17 18:50:18 -0700381 */
382 public static final int POWER_MODE_DOZE_SUSPEND = 3;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800383
384 /**
Chris Phoenix10a4a642017-09-25 13:21:00 -0700385 * Display power mode on: used while putting the screen into a suspended
386 * full power mode. Use only with {@link SurfaceControl#setDisplayPowerMode}.
Robert Carra7827f72019-01-11 12:53:37 -0800387 * @hide
Chris Phoenix10a4a642017-09-25 13:21:00 -0700388 */
389 public static final int POWER_MODE_ON_SUSPEND = 4;
390
391 /**
Robert Carr132c9f52017-07-31 17:02:30 -0700392 * A value for windowType used to indicate that the window should be omitted from screenshots
393 * and display mirroring. A temporary workaround until we express such things with
394 * the hierarchy.
395 * TODO: b/64227542
396 * @hide
397 */
398 public static final int WINDOW_TYPE_DONT_SCREENSHOT = 441731;
399
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800400 /**
401 * internal representation of how to interpret pixel value, used only to convert to ColorSpace.
402 */
403 private static final int INTERNAL_DATASPACE_SRGB = 142671872;
404 private static final int INTERNAL_DATASPACE_DISPLAY_P3 = 143261696;
405 private static final int INTERNAL_DATASPACE_SCRGB = 411107328;
406
Robert Carreb344c72019-01-07 18:35:30 -0800407 private void assignNativeObject(long nativeObject) {
408 if (mNativeObject != 0) {
409 release();
410 }
411 mNativeObject = nativeObject;
412 }
413
Robert Carra7827f72019-01-11 12:53:37 -0800414 /**
415 * @hide
416 */
chaviwbeb7a0c2018-12-05 13:49:54 -0800417 public void copyFrom(SurfaceControl other) {
418 mName = other.mName;
419 mWidth = other.mWidth;
420 mHeight = other.mHeight;
Robert Carreb344c72019-01-07 18:35:30 -0800421 assignNativeObject(nativeCopyFromSurfaceControl(other.mNativeObject));
chaviwbeb7a0c2018-12-05 13:49:54 -0800422 }
423
Robert Carr132c9f52017-07-31 17:02:30 -0700424 /**
Evan Rosky485df202018-12-06 14:11:12 -0800425 * owner UID.
426 * @hide
427 */
428 public static final int METADATA_OWNER_UID = 1;
429
430 /**
431 * Window type as per {@link WindowManager.LayoutParams}.
432 * @hide
433 */
434 public static final int METADATA_WINDOW_TYPE = 2;
435
436 /**
Evan Rosky9020c072018-12-06 14:11:12 -0800437 * Task id to allow association between surfaces and task.
438 * @hide
439 */
440 public static final int METADATA_TASK_ID = 3;
441
442 /**
Peiyong Line3e5efd2019-03-21 20:59:47 +0000443 * A wrapper around GraphicBuffer that contains extra information about how to
444 * interpret the screenshot GraphicBuffer.
445 * @hide
446 */
447 public static class ScreenshotGraphicBuffer {
448 private final GraphicBuffer mGraphicBuffer;
449 private final ColorSpace mColorSpace;
Robert Carr66b5664f2019-04-02 14:18:56 -0700450 private final boolean mContainsSecureLayers;
Peiyong Line3e5efd2019-03-21 20:59:47 +0000451
Robert Carr66b5664f2019-04-02 14:18:56 -0700452 public ScreenshotGraphicBuffer(GraphicBuffer graphicBuffer, ColorSpace colorSpace,
453 boolean containsSecureLayers) {
Peiyong Line3e5efd2019-03-21 20:59:47 +0000454 mGraphicBuffer = graphicBuffer;
455 mColorSpace = colorSpace;
Robert Carr66b5664f2019-04-02 14:18:56 -0700456 mContainsSecureLayers = containsSecureLayers;
Peiyong Line3e5efd2019-03-21 20:59:47 +0000457 }
458
459 /**
460 * Create ScreenshotGraphicBuffer from existing native GraphicBuffer object.
461 * @param width The width in pixels of the buffer
462 * @param height The height in pixels of the buffer
463 * @param format The format of each pixel as specified in {@link PixelFormat}
464 * @param usage Hint indicating how the buffer will be used
465 * @param unwrappedNativeObject The native object of GraphicBuffer
466 * @param namedColorSpace Integer value of a named color space {@link ColorSpace.Named}
Robert Carr66b5664f2019-04-02 14:18:56 -0700467 * @param containsSecureLayer Indicates whether this graphic buffer contains captured contents
468 * of secure layers, in which case the screenshot should not be persisted.
Peiyong Line3e5efd2019-03-21 20:59:47 +0000469 */
470 private static ScreenshotGraphicBuffer createFromNative(int width, int height, int format,
Robert Carr66b5664f2019-04-02 14:18:56 -0700471 int usage, long unwrappedNativeObject, int namedColorSpace,
472 boolean containsSecureLayers) {
Peiyong Line3e5efd2019-03-21 20:59:47 +0000473 GraphicBuffer graphicBuffer = GraphicBuffer.createFromExisting(width, height, format,
474 usage, unwrappedNativeObject);
475 ColorSpace colorSpace = ColorSpace.get(ColorSpace.Named.values()[namedColorSpace]);
Robert Carr66b5664f2019-04-02 14:18:56 -0700476 return new ScreenshotGraphicBuffer(graphicBuffer, colorSpace, containsSecureLayers);
Peiyong Line3e5efd2019-03-21 20:59:47 +0000477 }
478
479 public ColorSpace getColorSpace() {
480 return mColorSpace;
481 }
482
483 public GraphicBuffer getGraphicBuffer() {
484 return mGraphicBuffer;
485 }
Robert Carr66b5664f2019-04-02 14:18:56 -0700486
487 public boolean containsSecureLayers() {
488 return mContainsSecureLayers;
489 }
Peiyong Line3e5efd2019-03-21 20:59:47 +0000490 }
491
492 /**
Robert Carre625fcf2017-09-01 12:36:28 -0700493 * Builder class for {@link SurfaceControl} objects.
Robert Carr29fe58a2019-03-11 15:25:16 -0700494 *
495 * By default the surface will be hidden, and have "unset" bounds, meaning it can
496 * be as large as the bounds of its parent if a buffer or child so requires.
497 *
498 * It is necessary to set at least a name via {@link Builder#setName}
Robert Carre625fcf2017-09-01 12:36:28 -0700499 */
500 public static class Builder {
501 private SurfaceSession mSession;
502 private int mFlags = HIDDEN;
503 private int mWidth;
504 private int mHeight;
505 private int mFormat = PixelFormat.OPAQUE;
506 private String mName;
507 private SurfaceControl mParent;
Evan Rosky485df202018-12-06 14:11:12 -0800508 private SparseIntArray mMetadata;
Robert Carre625fcf2017-09-01 12:36:28 -0700509
510 /**
511 * Begin building a SurfaceControl with a given {@link SurfaceSession}.
512 *
513 * @param session The {@link SurfaceSession} with which to eventually construct the surface.
Robert Carra7827f72019-01-11 12:53:37 -0800514 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700515 */
516 public Builder(SurfaceSession session) {
517 mSession = session;
518 }
519
520 /**
Robert Carr76907ee2019-01-11 13:38:19 -0800521 * Begin building a SurfaceControl.
522 */
523 public Builder() {
524 }
525
526 /**
527 * Construct a new {@link SurfaceControl} with the set parameters. The builder
528 * remains valid.
Robert Carre625fcf2017-09-01 12:36:28 -0700529 */
Robert Carrda1d2422019-03-07 15:54:37 -0800530 @NonNull
Robert Carre625fcf2017-09-01 12:36:28 -0700531 public SurfaceControl build() {
Vishnu Naire86bd982018-11-28 13:23:17 -0800532 if (mWidth < 0 || mHeight < 0) {
Robert Carr29fe58a2019-03-11 15:25:16 -0700533 throw new IllegalStateException(
Vishnu Naire86bd982018-11-28 13:23:17 -0800534 "width and height must be positive or unset");
535 }
536 if ((mWidth > 0 || mHeight > 0) && (isColorLayerSet() || isContainerLayerSet())) {
Robert Carr29fe58a2019-03-11 15:25:16 -0700537 throw new IllegalStateException(
Vishnu Naire86bd982018-11-28 13:23:17 -0800538 "Only buffer layers can set a valid buffer size.");
Robert Carre625fcf2017-09-01 12:36:28 -0700539 }
Evan Rosky485df202018-12-06 14:11:12 -0800540 return new SurfaceControl(
541 mSession, mName, mWidth, mHeight, mFormat, mFlags, mParent, mMetadata);
Robert Carre625fcf2017-09-01 12:36:28 -0700542 }
543
544 /**
545 * Set a debugging-name for the SurfaceControl.
546 *
547 * @param name A name to identify the Surface in debugging.
548 */
Robert Carrda1d2422019-03-07 15:54:37 -0800549 @NonNull
550 public Builder setName(@NonNull String name) {
Robert Carre625fcf2017-09-01 12:36:28 -0700551 mName = name;
552 return this;
553 }
554
555 /**
556 * Set the initial size of the controlled surface's buffers in pixels.
557 *
558 * @param width The buffer width in pixels.
559 * @param height The buffer height in pixels.
560 */
Robert Carrda1d2422019-03-07 15:54:37 -0800561 @NonNull
Robert Carr76907ee2019-01-11 13:38:19 -0800562 public Builder setBufferSize(@IntRange(from = 0) int width,
563 @IntRange(from = 0) int height) {
Vishnu Naire86bd982018-11-28 13:23:17 -0800564 if (width < 0 || height < 0) {
Robert Carre625fcf2017-09-01 12:36:28 -0700565 throw new IllegalArgumentException(
566 "width and height must be positive");
567 }
568 mWidth = width;
569 mHeight = height;
Chavi Weingarten6ef9cc62019-02-07 16:28:45 +0000570 // set this as a buffer layer since we are specifying a buffer size.
571 return setFlags(FX_SURFACE_NORMAL, FX_SURFACE_MASK);
572 }
573
574 /**
575 * Set the initial size of the controlled surface's buffers in pixels.
576 */
577 private void unsetBufferSize() {
578 mWidth = 0;
579 mHeight = 0;
Robert Carre625fcf2017-09-01 12:36:28 -0700580 }
581
582 /**
583 * Set the pixel format of the controlled surface's buffers, using constants from
584 * {@link android.graphics.PixelFormat}.
585 */
Robert Carr76907ee2019-01-11 13:38:19 -0800586 @NonNull
Robert Carre625fcf2017-09-01 12:36:28 -0700587 public Builder setFormat(@PixelFormat.Format int format) {
588 mFormat = format;
589 return this;
590 }
591
592 /**
593 * Specify if the app requires a hardware-protected path to
594 * an external display sync. If protected content is enabled, but
595 * such a path is not available, then the controlled Surface will
596 * not be displayed.
597 *
598 * @param protectedContent Whether to require a protected sink.
Robert Carra7827f72019-01-11 12:53:37 -0800599 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700600 */
Robert Carr76907ee2019-01-11 13:38:19 -0800601 @NonNull
Robert Carre625fcf2017-09-01 12:36:28 -0700602 public Builder setProtected(boolean protectedContent) {
603 if (protectedContent) {
604 mFlags |= PROTECTED_APP;
605 } else {
606 mFlags &= ~PROTECTED_APP;
607 }
608 return this;
609 }
610
611 /**
612 * Specify whether the Surface contains secure content. If true, the system
613 * will prevent the surfaces content from being copied by another process. In
614 * particular screenshots and VNC servers will be disabled. This is however
615 * not a complete prevention of readback as {@link #setProtected}.
Robert Carra7827f72019-01-11 12:53:37 -0800616 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700617 */
Robert Carr76907ee2019-01-11 13:38:19 -0800618 @NonNull
Robert Carre625fcf2017-09-01 12:36:28 -0700619 public Builder setSecure(boolean secure) {
620 if (secure) {
621 mFlags |= SECURE;
622 } else {
623 mFlags &= ~SECURE;
624 }
625 return this;
626 }
627
628 /**
629 * Indicates whether the surface must be considered opaque,
630 * even if its pixel format is set to translucent. This can be useful if an
631 * application needs full RGBA 8888 support for instance but will
632 * still draw every pixel opaque.
633 * <p>
634 * This flag only determines whether opacity will be sampled from the alpha channel.
635 * Plane-alpha from calls to setAlpha() can still result in blended composition
636 * regardless of the opaque setting.
637 *
638 * Combined effects are (assuming a buffer format with an alpha channel):
639 * <ul>
640 * <li>OPAQUE + alpha(1.0) == opaque composition
641 * <li>OPAQUE + alpha(0.x) == blended composition
642 * <li>OPAQUE + alpha(0.0) == no composition
643 * <li>!OPAQUE + alpha(1.0) == blended composition
644 * <li>!OPAQUE + alpha(0.x) == blended composition
645 * <li>!OPAQUE + alpha(0.0) == no composition
646 * </ul>
647 * If the underlying buffer lacks an alpha channel, it is as if setOpaque(true)
648 * were set automatically.
649 * @param opaque Whether the Surface is OPAQUE.
650 */
Robert Carr76907ee2019-01-11 13:38:19 -0800651 @NonNull
Robert Carre625fcf2017-09-01 12:36:28 -0700652 public Builder setOpaque(boolean opaque) {
653 if (opaque) {
654 mFlags |= OPAQUE;
655 } else {
656 mFlags &= ~OPAQUE;
657 }
658 return this;
659 }
660
661 /**
662 * Set a parent surface for our new SurfaceControl.
663 *
664 * Child surfaces are constrained to the onscreen region of their parent.
665 * Furthermore they stack relatively in Z order, and inherit the transformation
666 * of the parent.
667 *
668 * @param parent The parent control.
669 */
Robert Carr76907ee2019-01-11 13:38:19 -0800670 @NonNull
671 public Builder setParent(@Nullable SurfaceControl parent) {
Robert Carre625fcf2017-09-01 12:36:28 -0700672 mParent = parent;
673 return this;
674 }
675
676 /**
Evan Rosky485df202018-12-06 14:11:12 -0800677 * Sets a metadata int.
Robert Carre625fcf2017-09-01 12:36:28 -0700678 *
Evan Rosky485df202018-12-06 14:11:12 -0800679 * @param key metadata key
680 * @param data associated data
Robert Carra7827f72019-01-11 12:53:37 -0800681 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700682 */
Evan Rosky485df202018-12-06 14:11:12 -0800683 public Builder setMetadata(int key, int data) {
684 if (mMetadata == null) {
685 mMetadata = new SparseIntArray();
Robert Carre625fcf2017-09-01 12:36:28 -0700686 }
Evan Rosky485df202018-12-06 14:11:12 -0800687 mMetadata.put(key, data);
Robert Carre625fcf2017-09-01 12:36:28 -0700688 return this;
689 }
690
691 /**
692 * Indicate whether a 'ColorLayer' is to be constructed.
693 *
694 * Color layers will not have an associated BufferQueue and will instead always render a
695 * solid color (that is, solid before plane alpha). Currently that color is black.
696 *
Robert Carra7827f72019-01-11 12:53:37 -0800697 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700698 */
Chavi Weingarten6ef9cc62019-02-07 16:28:45 +0000699 public Builder setColorLayer() {
700 unsetBufferSize();
701 return setFlags(FX_SURFACE_DIM, FX_SURFACE_MASK);
Robert Carre625fcf2017-09-01 12:36:28 -0700702 }
703
Vishnu Naire86bd982018-11-28 13:23:17 -0800704 private boolean isColorLayerSet() {
705 return (mFlags & FX_SURFACE_DIM) == FX_SURFACE_DIM;
706 }
707
Robert Carre625fcf2017-09-01 12:36:28 -0700708 /**
Robert Carr48ec4e02019-07-16 14:28:47 -0700709 * @hide
710 */
711 public Builder setBLASTLayer() {
712 unsetBufferSize();
713 return setFlags(FX_SURFACE_BLAST, FX_SURFACE_MASK);
714 }
715
716 /**
Robert Carrb6cd6432018-08-13 13:01:47 -0700717 * Indicates whether a 'ContainerLayer' is to be constructed.
718 *
719 * Container layers will not be rendered in any fashion and instead are used
720 * as a parent of renderable layers.
721 *
Robert Carra7827f72019-01-11 12:53:37 -0800722 * @hide
Robert Carrb6cd6432018-08-13 13:01:47 -0700723 */
Chavi Weingarten6ef9cc62019-02-07 16:28:45 +0000724 public Builder setContainerLayer() {
725 unsetBufferSize();
726 return setFlags(FX_SURFACE_CONTAINER, FX_SURFACE_MASK);
Robert Carrb6cd6432018-08-13 13:01:47 -0700727 }
728
Vishnu Naire86bd982018-11-28 13:23:17 -0800729 private boolean isContainerLayerSet() {
730 return (mFlags & FX_SURFACE_CONTAINER) == FX_SURFACE_CONTAINER;
731 }
732
Robert Carrb6cd6432018-08-13 13:01:47 -0700733 /**
Chavi Weingarten6ef9cc62019-02-07 16:28:45 +0000734 * Set 'Surface creation flags' such as {@link #HIDDEN}, {@link #SECURE}.
Robert Carre625fcf2017-09-01 12:36:28 -0700735 *
736 * TODO: Finish conversion to individual builder methods?
737 * @param flags The combined flags
Robert Carra7827f72019-01-11 12:53:37 -0800738 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700739 */
740 public Builder setFlags(int flags) {
741 mFlags = flags;
742 return this;
743 }
Chavi Weingarten6ef9cc62019-02-07 16:28:45 +0000744
745 private Builder setFlags(int flags, int mask) {
746 mFlags = (mFlags & ~mask) | flags;
747 return this;
748 }
Robert Carre625fcf2017-09-01 12:36:28 -0700749 }
750
751 /**
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800752 * Create a surface with a name.
Andy McFadden314405b2014-01-29 17:18:05 -0800753 * <p>
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800754 * The surface creation flags specify what kind of surface to create and
755 * certain options such as whether the surface can be assumed to be opaque
756 * and whether it should be initially hidden. Surfaces should always be
757 * created with the {@link #HIDDEN} flag set to ensure that they are not
758 * made visible prematurely before all of the surface's properties have been
759 * configured.
Andy McFadden314405b2014-01-29 17:18:05 -0800760 * <p>
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800761 * Good practice is to first create the surface with the {@link #HIDDEN} flag
762 * specified, open a transaction, set the surface layer, layer stack, alpha,
chaviw619da692019-06-10 15:39:40 -0700763 * and position, call {@link Transaction#show(SurfaceControl)} if appropriate, and close the
764 * transaction.
Vishnu Naird454442d2018-11-13 13:51:01 -0800765 * <p>
766 * Bounds of the surface is determined by its crop and its buffer size. If the
767 * surface has no buffer or crop, the surface is boundless and only constrained
768 * by the size of its parent bounds.
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800769 *
chaviw619da692019-06-10 15:39:40 -0700770 * @param session The surface session, must not be null.
771 * @param name The surface name, must not be null.
772 * @param w The surface initial width.
773 * @param h The surface initial height.
774 * @param flags The surface creation flags. Should always include {@link #HIDDEN}
775 * in the creation flags.
Evan Rosky485df202018-12-06 14:11:12 -0800776 * @param metadata Initial metadata.
Igor Murashkina86ab6402013-08-30 12:58:36 -0700777 * @throws throws OutOfResourcesException If the SurfaceControl cannot be created.
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800778 */
Robert Carre625fcf2017-09-01 12:36:28 -0700779 private SurfaceControl(SurfaceSession session, String name, int w, int h, int format, int flags,
Evan Rosky485df202018-12-06 14:11:12 -0800780 SurfaceControl parent, SparseIntArray metadata)
Robert Carrb0f39362018-03-14 13:52:25 -0700781 throws OutOfResourcesException, IllegalArgumentException {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800782 if (name == null) {
783 throw new IllegalArgumentException("name must not be null");
784 }
785
786 if ((flags & SurfaceControl.HIDDEN) == 0) {
787 Log.w(TAG, "Surfaces should always be created with the HIDDEN flag set "
788 + "to ensure that they are not made visible prematurely before "
789 + "all of the surface's properties have been configured. "
790 + "Set the other properties and make the surface visible within "
791 + "a transaction. New surface name: " + name,
792 new Throwable());
793 }
794
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800795 mName = name;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100796 mWidth = w;
797 mHeight = h;
Evan Rosky485df202018-12-06 14:11:12 -0800798 Parcel metaParcel = Parcel.obtain();
799 try {
800 if (metadata != null && metadata.size() > 0) {
801 metaParcel.writeInt(metadata.size());
802 for (int i = 0; i < metadata.size(); ++i) {
803 metaParcel.writeInt(metadata.keyAt(i));
804 metaParcel.writeByteArray(
Evan Roskyc12c9a32019-02-06 13:38:03 -0800805 ByteBuffer.allocate(4).order(ByteOrder.nativeOrder())
806 .putInt(metadata.valueAt(i)).array());
Evan Rosky485df202018-12-06 14:11:12 -0800807 }
Evan Roskyc12c9a32019-02-06 13:38:03 -0800808 metaParcel.setDataPosition(0);
Evan Rosky485df202018-12-06 14:11:12 -0800809 }
810 mNativeObject = nativeCreate(session, name, w, h, format, flags,
811 parent != null ? parent.mNativeObject : 0, metaParcel);
812 } finally {
813 metaParcel.recycle();
814 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800815 if (mNativeObject == 0) {
816 throw new OutOfResourcesException(
817 "Couldn't allocate SurfaceControl native object");
818 }
Jesse Hall6a6bc212013-08-08 12:15:03 -0700819
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800820 mCloseGuard.open("release");
821 }
Jesse Hall6a6bc212013-08-08 12:15:03 -0700822
Robert Carra7827f72019-01-11 12:53:37 -0800823 /** This is a transfer constructor, useful for transferring a live SurfaceControl native
824 * object to another Java wrapper which could have some different behavior, e.g.
825 * event logging.
826 * @hide
827 */
Robert Carr3b716242016-08-16 16:02:21 -0700828 public SurfaceControl(SurfaceControl other) {
829 mName = other.mName;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100830 mWidth = other.mWidth;
831 mHeight = other.mHeight;
Robert Carr3b716242016-08-16 16:02:21 -0700832 mNativeObject = other.mNativeObject;
833 other.mCloseGuard.close();
834 other.mNativeObject = 0;
835 mCloseGuard.open("release");
836 }
837
Jorim Jaggi06975df2017-12-01 14:52:13 +0100838 private SurfaceControl(Parcel in) {
chaviwbeb7a0c2018-12-05 13:49:54 -0800839 readFromParcel(in);
840 mCloseGuard.open("release");
841 }
842
Robert Carra7827f72019-01-11 12:53:37 -0800843 /**
844 * @hide
845 */
chaviwbeb7a0c2018-12-05 13:49:54 -0800846 public SurfaceControl() {
847 mCloseGuard.open("release");
848 }
849
850 public void readFromParcel(Parcel in) {
851 if (in == null) {
852 throw new IllegalArgumentException("source must not be null");
853 }
854
Jorim Jaggi06975df2017-12-01 14:52:13 +0100855 mName = in.readString();
Jorim Jaggia5e10572017-11-15 14:36:26 +0100856 mWidth = in.readInt();
857 mHeight = in.readInt();
Robert Carr5fea55b2018-12-10 13:05:52 -0800858
Robert Carreb344c72019-01-07 18:35:30 -0800859 long object = 0;
Robert Carr5fea55b2018-12-10 13:05:52 -0800860 if (in.readInt() != 0) {
Robert Carreb344c72019-01-07 18:35:30 -0800861 object = nativeReadFromParcel(in);
Jorim Jaggi06975df2017-12-01 14:52:13 +0100862 }
Robert Carreb344c72019-01-07 18:35:30 -0800863 assignNativeObject(object);
Jorim Jaggi06975df2017-12-01 14:52:13 +0100864 }
865
866 @Override
867 public int describeContents() {
868 return 0;
869 }
870
871 @Override
872 public void writeToParcel(Parcel dest, int flags) {
873 dest.writeString(mName);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100874 dest.writeInt(mWidth);
875 dest.writeInt(mHeight);
Robert Carr5fea55b2018-12-10 13:05:52 -0800876 if (mNativeObject == 0) {
877 dest.writeInt(0);
878 } else {
879 dest.writeInt(1);
880 }
Jorim Jaggi06975df2017-12-01 14:52:13 +0100881 nativeWriteToParcel(mNativeObject, dest);
Robert Carr5fea55b2018-12-10 13:05:52 -0800882
883 if ((flags & Parcelable.PARCELABLE_WRITE_RETURN_VALUE) != 0) {
884 release();
885 }
Jorim Jaggi06975df2017-12-01 14:52:13 +0100886 }
887
Vishnu Nair04ab4392018-01-10 11:00:06 -0800888 /**
889 * Write to a protocol buffer output stream. Protocol buffer message definition is at {@link
890 * android.view.SurfaceControlProto}.
891 *
892 * @param proto Stream to write the SurfaceControl object to.
893 * @param fieldId Field Id of the SurfaceControl as defined in the parent message.
894 * @hide
895 */
896 public void writeToProto(ProtoOutputStream proto, long fieldId) {
897 final long token = proto.start(fieldId);
898 proto.write(HASH_CODE, System.identityHashCode(this));
899 proto.write(NAME, mName);
900 proto.end(token);
901 }
902
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700903 public static final @android.annotation.NonNull Creator<SurfaceControl> CREATOR
Jorim Jaggi06975df2017-12-01 14:52:13 +0100904 = new Creator<SurfaceControl>() {
905 public SurfaceControl createFromParcel(Parcel in) {
906 return new SurfaceControl(in);
907 }
908
909 public SurfaceControl[] newArray(int size) {
910 return new SurfaceControl[size];
911 }
912 };
913
Robert Carra7827f72019-01-11 12:53:37 -0800914 /**
915 * @hide
916 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800917 @Override
918 protected void finalize() throws Throwable {
919 try {
920 if (mCloseGuard != null) {
921 mCloseGuard.warnIfOpen();
922 }
923 if (mNativeObject != 0) {
924 nativeRelease(mNativeObject);
925 }
926 } finally {
927 super.finalize();
928 }
929 }
930
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800931 /**
Robert Carr76907ee2019-01-11 13:38:19 -0800932 * Release the local reference to the server-side surface. The surface
933 * may continue to exist on-screen as long as its parent continues
934 * to exist. To explicitly remove a surface from the screen use
Robert Carr29fe58a2019-03-11 15:25:16 -0700935 * {@link Transaction#reparent} with a null-parent. After release,
936 * {@link #isValid} will return false and other methods will throw
937 * an exception.
Robert Carr76907ee2019-01-11 13:38:19 -0800938 *
939 * Always call release() when you're done with a SurfaceControl.
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800940 */
941 public void release() {
942 if (mNativeObject != 0) {
943 nativeRelease(mNativeObject);
944 mNativeObject = 0;
945 }
946 mCloseGuard.close();
947 }
948
949 /**
Chong Zhang47e36a32016-02-29 16:44:33 -0800950 * Disconnect any client still connected to the surface.
Robert Carra7827f72019-01-11 12:53:37 -0800951 * @hide
Chong Zhang47e36a32016-02-29 16:44:33 -0800952 */
953 public void disconnect() {
954 if (mNativeObject != 0) {
955 nativeDisconnect(mNativeObject);
956 }
957 }
958
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800959 private void checkNotReleased() {
960 if (mNativeObject == 0) throw new NullPointerException(
961 "mNativeObject is null. Have you called release() already?");
962 }
Jesse Hall6a6bc212013-08-08 12:15:03 -0700963
Robert Carra7827f72019-01-11 12:53:37 -0800964 /**
Robert Carr76907ee2019-01-11 13:38:19 -0800965 * Check whether this instance points to a valid layer with the system-compositor. For
Robert Carr29fe58a2019-03-11 15:25:16 -0700966 * example this may be false if construction failed, or the layer was released
967 * ({@link #release}).
Robert Carr76907ee2019-01-11 13:38:19 -0800968 *
969 * @return Whether this SurfaceControl is valid.
Robert Carra7827f72019-01-11 12:53:37 -0800970 */
Robert Carr5fea55b2018-12-10 13:05:52 -0800971 public boolean isValid() {
972 return mNativeObject != 0;
973 }
974
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800975 /*
976 * set surface parameters.
977 * needs to be inside open/closeTransaction block
978 */
979
Robert Carra7827f72019-01-11 12:53:37 -0800980 /** start a transaction
981 * @hide
982 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100983 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800984 public static void openTransaction() {
Robert Carre13b58e2017-08-31 14:50:44 -0700985 synchronized (SurfaceControl.class) {
986 if (sGlobalTransaction == null) {
987 sGlobalTransaction = new Transaction();
988 }
989 synchronized(SurfaceControl.class) {
990 sTransactionNestCount++;
991 }
992 }
993 }
994
Robert Carrb1579c82017-09-05 14:54:47 -0700995 /**
996 * Merge the supplied transaction in to the deprecated "global" transaction.
997 * This clears the supplied transaction in an identical fashion to {@link Transaction#merge}.
998 * <p>
999 * This is a utility for interop with legacy-code and will go away with the Global Transaction.
Robert Carra7827f72019-01-11 12:53:37 -08001000 * @hide
Robert Carrb1579c82017-09-05 14:54:47 -07001001 */
1002 @Deprecated
1003 public static void mergeToGlobalTransaction(Transaction t) {
Robert Carrc5fc4612017-12-05 11:55:40 -08001004 synchronized(SurfaceControl.class) {
Robert Carrb1579c82017-09-05 14:54:47 -07001005 sGlobalTransaction.merge(t);
1006 }
1007 }
1008
chaviwdaaeab02019-03-20 12:25:37 -07001009 /** end a transaction
1010 * @hide
Robert Carra7827f72019-01-11 12:53:37 -08001011 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001012 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001013 public static void closeTransaction() {
chaviwdaaeab02019-03-20 12:25:37 -07001014 synchronized(SurfaceControl.class) {
1015 if (sTransactionNestCount == 0) {
1016 Log.e(TAG,
1017 "Call to SurfaceControl.closeTransaction without matching openTransaction");
1018 } else if (--sTransactionNestCount > 0) {
1019 return;
1020 }
1021 sGlobalTransaction.apply();
1022 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001023 }
1024
Robert Carra7827f72019-01-11 12:53:37 -08001025 /**
1026 * @hide
1027 */
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001028 public void deferTransactionUntil(SurfaceControl barrier, long frame) {
Robert Carr024378c2018-02-27 11:21:05 -08001029 synchronized(SurfaceControl.class) {
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001030 sGlobalTransaction.deferTransactionUntil(this, barrier, frame);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001031 }
1032 }
1033
Robert Carra7827f72019-01-11 12:53:37 -08001034 /**
1035 * @hide
1036 */
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001037 public void reparentChildren(SurfaceControl newParent) {
Robert Carre13b58e2017-08-31 14:50:44 -07001038 synchronized(SurfaceControl.class) {
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001039 sGlobalTransaction.reparentChildren(this, newParent);
Robert Carre13b58e2017-08-31 14:50:44 -07001040 }
Robert Carrd5c7dd62017-03-08 10:39:30 -08001041 }
1042
Robert Carra7827f72019-01-11 12:53:37 -08001043 /**
1044 * @hide
1045 */
Robert Carrd5c7dd62017-03-08 10:39:30 -08001046 public void detachChildren() {
Robert Carre13b58e2017-08-31 14:50:44 -07001047 synchronized(SurfaceControl.class) {
1048 sGlobalTransaction.detachChildren(this);
1049 }
Rob Carr64e516f2015-10-29 00:20:45 +00001050 }
1051
Robert Carra7827f72019-01-11 12:53:37 -08001052 /**
1053 * @hide
1054 */
Robert Carr1ca6a332016-04-11 18:00:43 -07001055 public void setOverrideScalingMode(int scalingMode) {
1056 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001057 synchronized(SurfaceControl.class) {
1058 sGlobalTransaction.setOverrideScalingMode(this, scalingMode);
1059 }
Robert Carr1ca6a332016-04-11 18:00:43 -07001060 }
1061
Robert Carra7827f72019-01-11 12:53:37 -08001062 /**
1063 * @hide
1064 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001065 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001066 public void setLayer(int zorder) {
1067 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001068 synchronized(SurfaceControl.class) {
1069 sGlobalTransaction.setLayer(this, zorder);
1070 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001071 }
1072
Robert Carra7827f72019-01-11 12:53:37 -08001073 /**
1074 * @hide
1075 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001076 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001077 public void setPosition(float x, float y) {
1078 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001079 synchronized(SurfaceControl.class) {
1080 sGlobalTransaction.setPosition(this, x, y);
1081 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001082 }
1083
Robert Carra7827f72019-01-11 12:53:37 -08001084 /**
1085 * @hide
1086 */
Vishnu Naire86bd982018-11-28 13:23:17 -08001087 public void setBufferSize(int w, int h) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001088 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001089 synchronized(SurfaceControl.class) {
Vishnu Naire86bd982018-11-28 13:23:17 -08001090 sGlobalTransaction.setBufferSize(this, w, h);
Robert Carre13b58e2017-08-31 14:50:44 -07001091 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001092 }
1093
Robert Carra7827f72019-01-11 12:53:37 -08001094 /**
1095 * @hide
1096 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001097 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001098 public void hide() {
1099 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001100 synchronized(SurfaceControl.class) {
1101 sGlobalTransaction.hide(this);
1102 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001103 }
1104
Robert Carra7827f72019-01-11 12:53:37 -08001105 /**
1106 * @hide
1107 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001108 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001109 public void show() {
1110 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001111 synchronized(SurfaceControl.class) {
1112 sGlobalTransaction.show(this);
1113 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001114 }
1115
Robert Carra7827f72019-01-11 12:53:37 -08001116 /**
1117 * @hide
1118 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001119 public void setTransparentRegionHint(Region region) {
1120 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001121 synchronized(SurfaceControl.class) {
1122 sGlobalTransaction.setTransparentRegionHint(this, region);
1123 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001124 }
1125
Robert Carra7827f72019-01-11 12:53:37 -08001126 /**
1127 * @hide
1128 */
Svetoslav1376d602014-03-13 11:17:26 -07001129 public boolean clearContentFrameStats() {
1130 checkNotReleased();
1131 return nativeClearContentFrameStats(mNativeObject);
1132 }
1133
Robert Carra7827f72019-01-11 12:53:37 -08001134 /**
1135 * @hide
1136 */
Svetoslav1376d602014-03-13 11:17:26 -07001137 public boolean getContentFrameStats(WindowContentFrameStats outStats) {
1138 checkNotReleased();
1139 return nativeGetContentFrameStats(mNativeObject, outStats);
1140 }
1141
Robert Carra7827f72019-01-11 12:53:37 -08001142 /**
1143 * @hide
1144 */
Svetoslav1376d602014-03-13 11:17:26 -07001145 public static boolean clearAnimationFrameStats() {
1146 return nativeClearAnimationFrameStats();
1147 }
1148
Robert Carra7827f72019-01-11 12:53:37 -08001149 /**
1150 * @hide
1151 */
Svetoslav1376d602014-03-13 11:17:26 -07001152 public static boolean getAnimationFrameStats(WindowAnimationFrameStats outStats) {
1153 return nativeGetAnimationFrameStats(outStats);
1154 }
1155
Robert Carra7827f72019-01-11 12:53:37 -08001156 /**
1157 * @hide
1158 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001159 public void setAlpha(float alpha) {
1160 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001161 synchronized(SurfaceControl.class) {
1162 sGlobalTransaction.setAlpha(this, alpha);
1163 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001164 }
1165
Robert Carra7827f72019-01-11 12:53:37 -08001166 /**
1167 * @hide
1168 */
Robert Carr0edf18f2017-02-21 20:01:47 -08001169 public void setMatrix(float dsdx, float dtdx, float dtdy, float dsdy) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001170 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001171 synchronized(SurfaceControl.class) {
1172 sGlobalTransaction.setMatrix(this, dsdx, dtdx, dtdy, dsdy);
1173 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001174 }
1175
Jorim Jaggi21c39a72017-10-20 15:47:51 +02001176 /**
Peiyong Linf4f0f642019-03-01 14:36:05 -08001177 * Sets the Surface to be color space agnostic. If a surface is color space agnostic,
1178 * the color can be interpreted in any color space.
1179 * @param agnostic A boolean to indicate whether the surface is color space agnostic
1180 * @hide
1181 */
1182 public void setColorSpaceAgnostic(boolean agnostic) {
1183 checkNotReleased();
1184 synchronized (SurfaceControl.class) {
1185 sGlobalTransaction.setColorSpaceAgnostic(this, agnostic);
1186 }
1187 }
1188
1189 /**
Vishnu Naird454442d2018-11-13 13:51:01 -08001190 * Bounds the surface and its children to the bounds specified. Size of the surface will be
1191 * ignored and only the crop and buffer size will be used to determine the bounds of the
1192 * surface. If no crop is specified and the surface has no buffer, the surface bounds is only
1193 * constrained by the size of its parent bounds.
1194 *
1195 * @param crop Bounds of the crop to apply.
Robert Carra7827f72019-01-11 12:53:37 -08001196 * @hide
Vishnu Naird454442d2018-11-13 13:51:01 -08001197 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001198 public void setWindowCrop(Rect crop) {
1199 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001200 synchronized (SurfaceControl.class) {
1201 sGlobalTransaction.setWindowCrop(this, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001202 }
1203 }
1204
Vishnu Naird454442d2018-11-13 13:51:01 -08001205 /**
Robert Carra7827f72019-01-11 12:53:37 -08001206 * @hide
1207 */
Andy McFadden314405b2014-01-29 17:18:05 -08001208 public void setOpaque(boolean isOpaque) {
1209 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001210
1211 synchronized (SurfaceControl.class) {
1212 sGlobalTransaction.setOpaque(this, isOpaque);
Andy McFadden314405b2014-01-29 17:18:05 -08001213 }
1214 }
1215
Robert Carra7827f72019-01-11 12:53:37 -08001216 /**
1217 * @hide
1218 */
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001219 public void setSecure(boolean isSecure) {
1220 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001221
1222 synchronized (SurfaceControl.class) {
1223 sGlobalTransaction.setSecure(this, isSecure);
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001224 }
1225 }
1226
Robert Carra7827f72019-01-11 12:53:37 -08001227 /**
1228 * @hide
1229 */
Jorim Jaggia5e10572017-11-15 14:36:26 +01001230 public int getWidth() {
1231 synchronized (mSizeLock) {
1232 return mWidth;
1233 }
1234 }
1235
Robert Carra7827f72019-01-11 12:53:37 -08001236 /**
1237 * @hide
1238 */
Jorim Jaggia5e10572017-11-15 14:36:26 +01001239 public int getHeight() {
1240 synchronized (mSizeLock) {
1241 return mHeight;
1242 }
1243 }
1244
Robert Carre13b58e2017-08-31 14:50:44 -07001245 @Override
1246 public String toString() {
1247 return "Surface(name=" + mName + ")/@0x" +
1248 Integer.toHexString(System.identityHashCode(this));
1249 }
1250
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001251 /*
1252 * set display parameters.
1253 * needs to be inside open/closeTransaction block
1254 */
1255
1256 /**
1257 * Describes the properties of a physical display known to surface flinger.
Robert Carr76907ee2019-01-11 13:38:19 -08001258 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001259 */
1260 public static final class PhysicalDisplayInfo {
Robert Carra7827f72019-01-11 12:53:37 -08001261 /**
1262 * @hide
1263 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001264 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001265 public int width;
Robert Carra7827f72019-01-11 12:53:37 -08001266
1267 /**
1268 * @hide
1269 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001270 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001271 public int height;
Robert Carra7827f72019-01-11 12:53:37 -08001272
1273 /**
1274 * @hide
1275 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001276 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001277 public float refreshRate;
Robert Carra7827f72019-01-11 12:53:37 -08001278
1279 /**
1280 * @hide
1281 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001282 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001283 public float density;
Robert Carra7827f72019-01-11 12:53:37 -08001284
1285 /**
1286 * @hide
1287 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001288 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001289 public float xDpi;
Robert Carra7827f72019-01-11 12:53:37 -08001290
1291 /**
1292 * @hide
1293 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001294 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001295 public float yDpi;
Robert Carra7827f72019-01-11 12:53:37 -08001296
1297 /**
1298 * @hide
1299 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001300 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001301 public boolean secure;
Robert Carra7827f72019-01-11 12:53:37 -08001302
1303 /**
1304 * @hide
1305 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001306 @UnsupportedAppUsage
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001307 public long appVsyncOffsetNanos;
Robert Carra7827f72019-01-11 12:53:37 -08001308
1309 /**
1310 * @hide
1311 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001312 @UnsupportedAppUsage
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001313 public long presentationDeadlineNanos;
Jesse Hall6a6bc212013-08-08 12:15:03 -07001314
Robert Carra7827f72019-01-11 12:53:37 -08001315 /**
1316 * @hide
1317 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001318 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001319 public PhysicalDisplayInfo() {
1320 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001321
Robert Carra7827f72019-01-11 12:53:37 -08001322 /**
1323 * @hide
1324 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001325 public PhysicalDisplayInfo(PhysicalDisplayInfo other) {
1326 copyFrom(other);
1327 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001328
Robert Carra7827f72019-01-11 12:53:37 -08001329 /**
1330 * @hide
1331 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001332 @Override
1333 public boolean equals(Object o) {
1334 return o instanceof PhysicalDisplayInfo && equals((PhysicalDisplayInfo)o);
1335 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001336
Robert Carra7827f72019-01-11 12:53:37 -08001337 /**
1338 * @hide
1339 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001340 public boolean equals(PhysicalDisplayInfo other) {
1341 return other != null
1342 && width == other.width
1343 && height == other.height
1344 && refreshRate == other.refreshRate
1345 && density == other.density
1346 && xDpi == other.xDpi
1347 && yDpi == other.yDpi
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001348 && secure == other.secure
1349 && appVsyncOffsetNanos == other.appVsyncOffsetNanos
Michael Wright1c9977b2016-07-12 13:30:10 -07001350 && presentationDeadlineNanos == other.presentationDeadlineNanos;
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001351 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001352
Robert Carra7827f72019-01-11 12:53:37 -08001353 /**
1354 * @hide
1355 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001356 @Override
1357 public int hashCode() {
1358 return 0; // don't care
1359 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001360
Robert Carra7827f72019-01-11 12:53:37 -08001361 /**
1362 * @hide
1363 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001364 public void copyFrom(PhysicalDisplayInfo other) {
1365 width = other.width;
1366 height = other.height;
1367 refreshRate = other.refreshRate;
1368 density = other.density;
1369 xDpi = other.xDpi;
1370 yDpi = other.yDpi;
1371 secure = other.secure;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001372 appVsyncOffsetNanos = other.appVsyncOffsetNanos;
1373 presentationDeadlineNanos = other.presentationDeadlineNanos;
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001374 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001375
Robert Carra7827f72019-01-11 12:53:37 -08001376 /**
1377 * @hide
1378 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001379 @Override
1380 public String toString() {
1381 return "PhysicalDisplayInfo{" + width + " x " + height + ", " + refreshRate + " fps, "
1382 + "density " + density + ", " + xDpi + " x " + yDpi + " dpi, secure " + secure
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001383 + ", appVsyncOffset " + appVsyncOffsetNanos
Michael Wright1c9977b2016-07-12 13:30:10 -07001384 + ", bufferDeadline " + presentationDeadlineNanos + "}";
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001385 }
1386 }
1387
Robert Carra7827f72019-01-11 12:53:37 -08001388 /**
1389 * @hide
1390 */
Prashant Malanic55929a2014-05-25 01:59:21 -07001391 public static void setDisplayPowerMode(IBinder displayToken, int mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001392 if (displayToken == null) {
1393 throw new IllegalArgumentException("displayToken must not be null");
1394 }
Prashant Malanic55929a2014-05-25 01:59:21 -07001395 nativeSetDisplayPowerMode(displayToken, mode);
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001396 }
1397
Robert Carra7827f72019-01-11 12:53:37 -08001398 /**
1399 * @hide
1400 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001401 @UnsupportedAppUsage
Dan Stoza00101052014-05-02 15:23:40 -07001402 public static SurfaceControl.PhysicalDisplayInfo[] getDisplayConfigs(IBinder displayToken) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001403 if (displayToken == null) {
1404 throw new IllegalArgumentException("displayToken must not be null");
1405 }
Dan Stoza00101052014-05-02 15:23:40 -07001406 return nativeGetDisplayConfigs(displayToken);
1407 }
1408
Robert Carra7827f72019-01-11 12:53:37 -08001409 /**
1410 * @hide
1411 */
Dan Stoza00101052014-05-02 15:23:40 -07001412 public static int getActiveConfig(IBinder displayToken) {
1413 if (displayToken == null) {
1414 throw new IllegalArgumentException("displayToken must not be null");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001415 }
Dan Stoza00101052014-05-02 15:23:40 -07001416 return nativeGetActiveConfig(displayToken);
1417 }
1418
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001419 /**
1420 * @hide
1421 */
1422 public static DisplayedContentSamplingAttributes getDisplayedContentSamplingAttributes(
1423 IBinder displayToken) {
1424 if (displayToken == null) {
1425 throw new IllegalArgumentException("displayToken must not be null");
1426 }
1427 return nativeGetDisplayedContentSamplingAttributes(displayToken);
1428 }
1429
1430 /**
1431 * @hide
1432 */
1433 public static boolean setDisplayedContentSamplingEnabled(
1434 IBinder displayToken, boolean enable, int componentMask, int maxFrames) {
1435 if (displayToken == null) {
1436 throw new IllegalArgumentException("displayToken must not be null");
1437 }
1438 final int maxColorComponents = 4;
1439 if ((componentMask >> maxColorComponents) != 0) {
1440 throw new IllegalArgumentException("invalid componentMask when enabling sampling");
1441 }
1442 return nativeSetDisplayedContentSamplingEnabled(
1443 displayToken, enable, componentMask, maxFrames);
1444 }
1445
1446 /**
1447 * @hide
1448 */
1449 public static DisplayedContentSample getDisplayedContentSample(
1450 IBinder displayToken, long maxFrames, long timestamp) {
1451 if (displayToken == null) {
1452 throw new IllegalArgumentException("displayToken must not be null");
1453 }
1454 return nativeGetDisplayedContentSample(displayToken, maxFrames, timestamp);
1455 }
1456
1457
Robert Carra7827f72019-01-11 12:53:37 -08001458 /**
1459 * @hide
1460 */
Dan Stoza00101052014-05-02 15:23:40 -07001461 public static boolean setActiveConfig(IBinder displayToken, int id) {
1462 if (displayToken == null) {
1463 throw new IllegalArgumentException("displayToken must not be null");
1464 }
1465 return nativeSetActiveConfig(displayToken, id);
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001466 }
1467
Robert Carra7827f72019-01-11 12:53:37 -08001468 /**
1469 * @hide
1470 */
Ady Abraham6070ce12019-01-24 18:48:58 -08001471 public static boolean setAllowedDisplayConfigs(IBinder displayToken, int[] allowedConfigs) {
1472 if (displayToken == null) {
1473 throw new IllegalArgumentException("displayToken must not be null");
1474 }
1475 if (allowedConfigs == null) {
1476 throw new IllegalArgumentException("allowedConfigs must not be null");
1477 }
1478
1479 return nativeSetAllowedDisplayConfigs(displayToken, allowedConfigs);
1480 }
1481
1482 /**
1483 * @hide
1484 */
Ady Abraham42f9a2fb2019-02-26 14:13:39 -08001485 public static int[] getAllowedDisplayConfigs(IBinder displayToken) {
1486 if (displayToken == null) {
1487 throw new IllegalArgumentException("displayToken must not be null");
1488 }
1489 return nativeGetAllowedDisplayConfigs(displayToken);
1490 }
1491
1492 /**
1493 * @hide
1494 */
Michael Wright1c9977b2016-07-12 13:30:10 -07001495 public static int[] getDisplayColorModes(IBinder displayToken) {
1496 if (displayToken == null) {
1497 throw new IllegalArgumentException("displayToken must not be null");
1498 }
1499 return nativeGetDisplayColorModes(displayToken);
1500 }
1501
Robert Carra7827f72019-01-11 12:53:37 -08001502 /**
Daniel Solomon10e3b332019-01-20 21:09:11 -08001503 * Color coordinates in CIE1931 XYZ color space
1504 *
1505 * @hide
1506 */
1507 public static final class CieXyz {
1508 /**
1509 * @hide
1510 */
1511 public float X;
1512
1513 /**
1514 * @hide
1515 */
1516 public float Y;
1517
1518 /**
1519 * @hide
1520 */
1521 public float Z;
1522 }
1523
1524 /**
1525 * Contains a display's color primaries
1526 *
1527 * @hide
1528 */
1529 public static final class DisplayPrimaries {
1530 /**
1531 * @hide
1532 */
1533 public CieXyz red;
1534
1535 /**
1536 * @hide
1537 */
1538 public CieXyz green;
1539
1540 /**
1541 * @hide
1542 */
1543 public CieXyz blue;
1544
1545 /**
1546 * @hide
1547 */
1548 public CieXyz white;
1549
1550 /**
1551 * @hide
1552 */
1553 public DisplayPrimaries() {
1554 }
1555 }
1556
1557 /**
1558 * @hide
1559 */
1560 public static SurfaceControl.DisplayPrimaries getDisplayNativePrimaries(
1561 IBinder displayToken) {
1562 if (displayToken == null) {
1563 throw new IllegalArgumentException("displayToken must not be null");
1564 }
1565
1566 return nativeGetDisplayNativePrimaries(displayToken);
1567 }
1568
1569 /**
Robert Carra7827f72019-01-11 12:53:37 -08001570 * @hide
1571 */
Michael Wright1c9977b2016-07-12 13:30:10 -07001572 public static int getActiveColorMode(IBinder displayToken) {
1573 if (displayToken == null) {
1574 throw new IllegalArgumentException("displayToken must not be null");
1575 }
1576 return nativeGetActiveColorMode(displayToken);
1577 }
1578
Robert Carra7827f72019-01-11 12:53:37 -08001579 /**
1580 * @hide
1581 */
Michael Wright1c9977b2016-07-12 13:30:10 -07001582 public static boolean setActiveColorMode(IBinder displayToken, int colorMode) {
1583 if (displayToken == null) {
1584 throw new IllegalArgumentException("displayToken must not be null");
1585 }
1586 return nativeSetActiveColorMode(displayToken, colorMode);
1587 }
1588
Robert Carra7827f72019-01-11 12:53:37 -08001589 /**
Peiyong Lin5f4a5682019-01-17 11:37:07 -08001590 * Returns an array of color spaces with 2 elements. The first color space is the
1591 * default color space and second one is wide color gamut color space.
1592 * @hide
1593 */
1594 public static ColorSpace[] getCompositionColorSpaces() {
1595 int[] dataspaces = nativeGetCompositionDataspaces();
1596 ColorSpace srgb = ColorSpace.get(ColorSpace.Named.SRGB);
1597 ColorSpace[] colorSpaces = { srgb, srgb };
1598 if (dataspaces.length == 2) {
1599 for (int i = 0; i < 2; ++i) {
1600 switch(dataspaces[i]) {
1601 case INTERNAL_DATASPACE_DISPLAY_P3:
1602 colorSpaces[i] = ColorSpace.get(ColorSpace.Named.DISPLAY_P3);
1603 break;
1604 case INTERNAL_DATASPACE_SCRGB:
1605 colorSpaces[i] = ColorSpace.get(ColorSpace.Named.EXTENDED_SRGB);
1606 break;
1607 case INTERNAL_DATASPACE_SRGB:
1608 // Other dataspace is not recognized, use SRGB color space instead,
1609 // the default value of the array is already SRGB, thus do nothing.
1610 default:
1611 break;
1612 }
1613 }
1614 }
1615 return colorSpaces;
1616 }
1617
1618 /**
Robert Carra7827f72019-01-11 12:53:37 -08001619 * @hide
1620 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001621 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001622 public static void setDisplayProjection(IBinder displayToken,
1623 int orientation, Rect layerStackRect, Rect displayRect) {
Robert Carre13b58e2017-08-31 14:50:44 -07001624 synchronized (SurfaceControl.class) {
1625 sGlobalTransaction.setDisplayProjection(displayToken, orientation,
1626 layerStackRect, displayRect);
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001627 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001628 }
1629
Robert Carra7827f72019-01-11 12:53:37 -08001630 /**
1631 * @hide
1632 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001633 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001634 public static void setDisplayLayerStack(IBinder displayToken, int layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -07001635 synchronized (SurfaceControl.class) {
1636 sGlobalTransaction.setDisplayLayerStack(displayToken, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001637 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001638 }
1639
Robert Carra7827f72019-01-11 12:53:37 -08001640 /**
1641 * @hide
1642 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001643 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001644 public static void setDisplaySurface(IBinder displayToken, Surface surface) {
Robert Carre13b58e2017-08-31 14:50:44 -07001645 synchronized (SurfaceControl.class) {
1646 sGlobalTransaction.setDisplaySurface(displayToken, surface);
Jeff Brownfc0ebd72013-04-30 16:33:00 -07001647 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001648 }
1649
Robert Carra7827f72019-01-11 12:53:37 -08001650 /**
1651 * @hide
1652 */
Michael Wright01e840f2014-06-26 16:03:25 -07001653 public static void setDisplaySize(IBinder displayToken, int width, int height) {
Robert Carre13b58e2017-08-31 14:50:44 -07001654 synchronized (SurfaceControl.class) {
1655 sGlobalTransaction.setDisplaySize(displayToken, width, height);
Michael Wright01e840f2014-06-26 16:03:25 -07001656 }
Michael Wright01e840f2014-06-26 16:03:25 -07001657 }
1658
Robert Carra7827f72019-01-11 12:53:37 -08001659 /**
1660 * @hide
1661 */
Michael Wright9ff94c02016-03-30 18:05:40 -07001662 public static Display.HdrCapabilities getHdrCapabilities(IBinder displayToken) {
1663 if (displayToken == null) {
1664 throw new IllegalArgumentException("displayToken must not be null");
1665 }
1666 return nativeGetHdrCapabilities(displayToken);
1667 }
1668
Robert Carra7827f72019-01-11 12:53:37 -08001669 /**
1670 * @hide
1671 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001672 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001673 public static IBinder createDisplay(String name, boolean secure) {
1674 if (name == null) {
1675 throw new IllegalArgumentException("name must not be null");
1676 }
1677 return nativeCreateDisplay(name, secure);
1678 }
1679
Robert Carra7827f72019-01-11 12:53:37 -08001680 /**
1681 * @hide
1682 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001683 @UnsupportedAppUsage
Jesse Hall6a6bc212013-08-08 12:15:03 -07001684 public static void destroyDisplay(IBinder displayToken) {
1685 if (displayToken == null) {
1686 throw new IllegalArgumentException("displayToken must not be null");
1687 }
1688 nativeDestroyDisplay(displayToken);
1689 }
1690
Robert Carra7827f72019-01-11 12:53:37 -08001691 /**
1692 * @hide
1693 */
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001694 public static long[] getPhysicalDisplayIds() {
1695 return nativeGetPhysicalDisplayIds();
1696 }
1697
1698 /**
1699 * @hide
1700 */
1701 public static IBinder getPhysicalDisplayToken(long physicalDisplayId) {
1702 return nativeGetPhysicalDisplayToken(physicalDisplayId);
1703 }
1704
1705 /**
1706 * TODO(116025192): Remove this stopgap once framework is display-agnostic.
1707 *
1708 * @hide
1709 */
1710 public static IBinder getInternalDisplayToken() {
1711 final long[] physicalDisplayIds = getPhysicalDisplayIds();
1712 if (physicalDisplayIds.length == 0) {
1713 return null;
1714 }
1715 return getPhysicalDisplayToken(physicalDisplayIds[0]);
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001716 }
1717
Mathias Agopian0449a402013-03-01 23:01:51 -08001718 /**
chaviw08520a02018-09-10 16:44:56 -07001719 * @see SurfaceControl#screenshot(IBinder, Surface, Rect, int, int, boolean, int)
Robert Carra7827f72019-01-11 12:53:37 -08001720 * @hide
Mathias Agopian0449a402013-03-01 23:01:51 -08001721 */
1722 public static void screenshot(IBinder display, Surface consumer) {
chaviw08520a02018-09-10 16:44:56 -07001723 screenshot(display, consumer, new Rect(), 0, 0, false, 0);
1724 }
1725
1726 /**
1727 * Copy the current screen contents into the provided {@link Surface}
1728 *
1729 * @param consumer The {@link Surface} to take the screenshot into.
1730 * @see SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)
Robert Carra7827f72019-01-11 12:53:37 -08001731 * @hide
chaviw08520a02018-09-10 16:44:56 -07001732 */
1733 public static void screenshot(IBinder display, Surface consumer, Rect sourceCrop, int width,
1734 int height, boolean useIdentityTransform, int rotation) {
1735 if (consumer == null) {
1736 throw new IllegalArgumentException("consumer must not be null");
1737 }
1738
Peiyong Line3e5efd2019-03-21 20:59:47 +00001739 final ScreenshotGraphicBuffer buffer = screenshotToBuffer(display, sourceCrop, width,
1740 height, useIdentityTransform, rotation);
chaviw08520a02018-09-10 16:44:56 -07001741 try {
Peiyong Linccc06b62019-06-25 17:31:09 -07001742 consumer.attachAndQueueBufferWithColorSpace(buffer.getGraphicBuffer(),
1743 buffer.getColorSpace());
chaviw08520a02018-09-10 16:44:56 -07001744 } catch (RuntimeException e) {
1745 Log.w(TAG, "Failed to take screenshot - " + e.getMessage());
1746 }
1747 }
1748
1749 /**
1750 * @see SurfaceControl#screenshot(Rect, int, int, boolean, int)}
Robert Carra7827f72019-01-11 12:53:37 -08001751 * @hide
chaviw08520a02018-09-10 16:44:56 -07001752 */
1753 @UnsupportedAppUsage
1754 public static Bitmap screenshot(Rect sourceCrop, int width, int height, int rotation) {
1755 return screenshot(sourceCrop, width, height, false, rotation);
Mathias Agopian0449a402013-03-01 23:01:51 -08001756 }
1757
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001758 /**
chaviw1da9cd92017-12-06 10:48:11 -08001759 * Copy the current screen contents into a hardware bitmap and return it.
1760 * Note: If you want to modify the Bitmap in software, you will need to copy the Bitmap into
1761 * a software Bitmap using {@link Bitmap#copy(Bitmap.Config, boolean)}
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001762 *
chaviw08520a02018-09-10 16:44:56 -07001763 * CAVEAT: Versions of screenshot that return a {@link Bitmap} can be extremely slow; avoid use
1764 * unless absolutely necessary; prefer the versions that use a {@link Surface} such as
1765 * {@link SurfaceControl#screenshot(IBinder, Surface)} or {@link GraphicBuffer} such as
1766 * {@link SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)}.
Mathias Agopian0449a402013-03-01 23:01:51 -08001767 *
chaviw08520a02018-09-10 16:44:56 -07001768 * @see SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)}
Robert Carra7827f72019-01-11 12:53:37 -08001769 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001770 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001771 @UnsupportedAppUsage
Dan Stoza9890e3412014-05-22 16:12:54 -07001772 public static Bitmap screenshot(Rect sourceCrop, int width, int height,
chaviw08520a02018-09-10 16:44:56 -07001773 boolean useIdentityTransform, int rotation) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001774 // TODO: should take the display as a parameter
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001775 final IBinder displayToken = SurfaceControl.getInternalDisplayToken();
1776 if (displayToken == null) {
1777 Log.w(TAG, "Failed to take screenshot because internal display is disconnected");
1778 return null;
1779 }
1780
chaviwa69e0a72017-11-29 17:55:12 -08001781 if (rotation == ROTATION_90 || rotation == ROTATION_270) {
1782 rotation = (rotation == ROTATION_90) ? ROTATION_270 : ROTATION_90;
1783 }
1784
1785 SurfaceControl.rotateCropForSF(sourceCrop, rotation);
Peiyong Line3e5efd2019-03-21 20:59:47 +00001786 final ScreenshotGraphicBuffer buffer = screenshotToBuffer(displayToken, sourceCrop, width,
1787 height, useIdentityTransform, rotation);
chaviw08520a02018-09-10 16:44:56 -07001788
1789 if (buffer == null) {
1790 Log.w(TAG, "Failed to take screenshot");
1791 return null;
1792 }
Sunny Goyal62915b22019-04-10 12:28:47 -07001793 return Bitmap.wrapHardwareBuffer(buffer.getGraphicBuffer(), buffer.getColorSpace());
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001794 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001795
chaviw08520a02018-09-10 16:44:56 -07001796 /**
1797 * Captures all the surfaces in a display and returns a {@link GraphicBuffer} with the content.
1798 *
1799 * @param display The display to take the screenshot of.
1800 * @param sourceCrop The portion of the screen to capture into the Bitmap; caller may
1801 * pass in 'new Rect()' if no cropping is desired.
1802 * @param width The desired width of the returned bitmap; the raw screen will be
1803 * scaled down to this size; caller may pass in 0 if no scaling is
1804 * desired.
1805 * @param height The desired height of the returned bitmap; the raw screen will
1806 * be scaled down to this size; caller may pass in 0 if no scaling
1807 * is desired.
1808 * @param useIdentityTransform Replace whatever transformation (rotation, scaling, translation)
1809 * the surface layers are currently using with the identity
1810 * transformation while taking the screenshot.
1811 * @param rotation Apply a custom clockwise rotation to the screenshot, i.e.
1812 * Surface.ROTATION_0,90,180,270. SurfaceFlinger will always take
1813 * screenshots in its native portrait orientation by default, so
1814 * this is useful for returning screenshots that are independent of
1815 * device orientation.
1816 * @return Returns a GraphicBuffer that contains the captured content.
Robert Carra7827f72019-01-11 12:53:37 -08001817 * @hide
chaviw08520a02018-09-10 16:44:56 -07001818 */
Peiyong Line3e5efd2019-03-21 20:59:47 +00001819 public static ScreenshotGraphicBuffer screenshotToBuffer(IBinder display, Rect sourceCrop,
1820 int width, int height, boolean useIdentityTransform, int rotation) {
Mathias Agopian0449a402013-03-01 23:01:51 -08001821 if (display == null) {
1822 throw new IllegalArgumentException("displayToken must not be null");
1823 }
chaviw08520a02018-09-10 16:44:56 -07001824
Robert Carr5c52b132019-02-15 15:48:11 -08001825 return nativeScreenshot(display, sourceCrop, width, height, useIdentityTransform, rotation,
1826 false /* captureSecureLayers */);
1827 }
1828
1829 /**
1830 * Like screenshotToBuffer, but if the caller is AID_SYSTEM, allows
1831 * for the capture of secure layers. This is used for the screen rotation
1832 * animation where the system server takes screenshots but does
1833 * not persist them or allow them to leave the server. However in other
1834 * cases in the system server, we mostly want to omit secure layers
1835 * like when we take a screenshot on behalf of the assistant.
1836 *
1837 * @hide
1838 */
Peiyong Line3e5efd2019-03-21 20:59:47 +00001839 public static ScreenshotGraphicBuffer screenshotToBufferWithSecureLayersUnsafe(IBinder display,
Robert Carr5c52b132019-02-15 15:48:11 -08001840 Rect sourceCrop, int width, int height, boolean useIdentityTransform,
1841 int rotation) {
1842 if (display == null) {
1843 throw new IllegalArgumentException("displayToken must not be null");
1844 }
1845
1846 return nativeScreenshot(display, sourceCrop, width, height, useIdentityTransform, rotation,
1847 true /* captureSecureLayers */);
Mathias Agopian0449a402013-03-01 23:01:51 -08001848 }
Robert Carre13b58e2017-08-31 14:50:44 -07001849
chaviwa69e0a72017-11-29 17:55:12 -08001850 private static void rotateCropForSF(Rect crop, int rot) {
1851 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
1852 int tmp = crop.top;
1853 crop.top = crop.left;
1854 crop.left = tmp;
1855 tmp = crop.right;
1856 crop.right = crop.bottom;
1857 crop.bottom = tmp;
1858 }
1859 }
1860
chaviw1cda84c2017-10-23 16:47:10 -07001861 /**
chaviw1da9cd92017-12-06 10:48:11 -08001862 * Captures a layer and its children and returns a {@link GraphicBuffer} with the content.
chaviw1cda84c2017-10-23 16:47:10 -07001863 *
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001864 * @param layer The root layer to capture.
chaviwfbe47df2017-11-10 16:14:49 -08001865 * @param sourceCrop The portion of the root surface to capture; caller may pass in 'new
1866 * Rect()' or null if no cropping is desired.
1867 * @param frameScale The desired scale of the returned buffer; the raw
1868 * screen will be scaled up/down.
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001869 *
1870 * @return Returns a GraphicBuffer that contains the layer capture.
Robert Carra7827f72019-01-11 12:53:37 -08001871 * @hide
chaviw1cda84c2017-10-23 16:47:10 -07001872 */
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001873 public static ScreenshotGraphicBuffer captureLayers(SurfaceControl layer, Rect sourceCrop,
chaviwfbe47df2017-11-10 16:14:49 -08001874 float frameScale) {
Chiawei Wang02202d12019-01-03 18:12:13 +08001875 return captureLayers(layer, sourceCrop, frameScale, PixelFormat.RGBA_8888);
1876 }
1877
1878 /**
1879 * Captures a layer and its children and returns a {@link GraphicBuffer} with the content.
1880 *
1881 * @param layer The root layer to capture.
1882 * @param sourceCrop The portion of the root surface to capture; caller may pass in 'new
1883 * Rect()' or null if no cropping is desired.
1884 * @param frameScale The desired scale of the returned buffer; the raw
1885 * screen will be scaled up/down.
1886 * @param format The desired pixel format of the returned buffer.
1887 *
1888 * @return Returns a GraphicBuffer that contains the layer capture.
1889 * @hide
1890 */
1891 public static ScreenshotGraphicBuffer captureLayers(SurfaceControl layer, Rect sourceCrop,
1892 float frameScale, int format) {
Peiyong Lin21e499a2019-04-03 16:37:46 -07001893 final IBinder displayToken = SurfaceControl.getInternalDisplayToken();
Chiawei Wang02202d12019-01-03 18:12:13 +08001894 return nativeCaptureLayers(displayToken, layer.mNativeObject, sourceCrop, frameScale, null,
1895 format);
Robert Carrffcdc512019-04-02 11:51:11 -07001896 }
1897
1898 /**
1899 * Like {@link captureLayers} but with an array of layer handles to exclude.
1900 * @hide
1901 */
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001902 public static ScreenshotGraphicBuffer captureLayersExcluding(SurfaceControl layer,
1903 Rect sourceCrop, float frameScale, SurfaceControl[] exclude) {
Peiyong Lin21e499a2019-04-03 16:37:46 -07001904 final IBinder displayToken = SurfaceControl.getInternalDisplayToken();
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001905 long[] nativeExcludeObjects = new long[exclude.length];
1906 for (int i = 0; i < exclude.length; i++) {
1907 nativeExcludeObjects[i] = exclude[i].mNativeObject;
1908 }
1909 return nativeCaptureLayers(displayToken, layer.mNativeObject, sourceCrop, frameScale,
Chiawei Wang02202d12019-01-03 18:12:13 +08001910 nativeExcludeObjects, PixelFormat.RGBA_8888);
chaviw1cda84c2017-10-23 16:47:10 -07001911 }
1912
Robert Carra7827f72019-01-11 12:53:37 -08001913 /**
Peiyong Lin0ddb7d42019-01-16 13:25:09 -08001914 * Returns whether protected content is supported in GPU composition.
1915 * @hide
1916 */
1917 public static boolean getProtectedContentSupport() {
1918 return nativeGetProtectedContentSupport();
1919 }
1920
1921 /**
Dan Gittik832b4972019-02-13 18:17:47 +00001922 * Returns whether brightness operations are supported on a display.
1923 *
1924 * @param displayToken
1925 * The token for the display.
1926 *
1927 * @return Whether brightness operations are supported on the display.
1928 *
1929 * @hide
1930 */
1931 public static boolean getDisplayBrightnessSupport(IBinder displayToken) {
1932 return nativeGetDisplayBrightnessSupport(displayToken);
1933 }
1934
1935 /**
1936 * Sets the brightness of a display.
1937 *
1938 * @param displayToken
1939 * The token for the display whose brightness is set.
1940 * @param brightness
1941 * A number between 0.0f (minimum brightness) and 1.0f (maximum brightness), or -1.0f to
1942 * turn the backlight off.
1943 *
1944 * @return Whether the method succeeded or not.
1945 *
1946 * @throws IllegalArgumentException if:
1947 * - displayToken is null;
1948 * - brightness is NaN or greater than 1.0f.
1949 *
1950 * @hide
1951 */
1952 public static boolean setDisplayBrightness(IBinder displayToken, float brightness) {
1953 Objects.requireNonNull(displayToken);
1954 if (Float.isNaN(brightness) || brightness > 1.0f
1955 || (brightness < 0.0f && brightness != -1.0f)) {
1956 throw new IllegalArgumentException("brightness must be a number between 0.0f and 1.0f,"
1957 + " or -1 to turn the backlight off.");
1958 }
1959 return nativeSetDisplayBrightness(displayToken, brightness);
1960 }
1961
chaviwa51724f2019-09-19 09:50:11 -07001962 /**
1963 * Creates a mirrored hierarchy for the mirrorOf {@link SurfaceControl}
1964 *
1965 * Real Hierarchy Mirror
1966 * SC (value that's returned)
1967 * |
1968 * A A'
1969 * | |
1970 * B B'
1971 *
1972 * @param mirrorOf The root of the hierarchy that should be mirrored.
1973 * @return A SurfaceControl that's the parent of the root of the mirrored hierarchy.
1974 *
1975 * @hide
1976 */
1977 public static SurfaceControl mirrorSurface(SurfaceControl mirrorOf) {
1978 long nativeObj = nativeMirrorSurface(mirrorOf.mNativeObject);
1979 SurfaceControl sc = new SurfaceControl();
1980 sc.assignNativeObject(nativeObj);
1981 return sc;
1982 }
1983
Vishnu Nair4a067c52019-11-19 14:25:56 -08001984 private static void validateColorArg(@Size(4) float[] color) {
1985 final String msg = "Color must be specified as a float array with"
1986 + " four values to represent r, g, b, a in range [0..1]";
1987 if (color.length != 4) {
1988 throw new IllegalArgumentException(msg);
1989 }
1990 for (float c:color) {
1991 if ((c < 0.f) || (c > 1.f)) {
1992 throw new IllegalArgumentException(msg);
1993 }
1994 }
1995 }
1996
1997 /**
1998 * Sets the global configuration for all the shadows drawn by SurfaceFlinger. Shadow follows
1999 * material design guidelines.
2000 *
2001 * @param ambientColor Color applied to the ambient shadow. The alpha is premultiplied. A
2002 * float array with four values to represent r, g, b, a in range [0..1]
2003 * @param spotColor Color applied to the spot shadow. The alpha is premultiplied. The position
2004 * of the spot shadow depends on the light position. A float array with
2005 * four values to represent r, g, b, a in range [0..1]
2006 * @param lightPosY Y axis position of the light used to cast the spot shadow in pixels.
2007 * @param lightPosZ Z axis position of the light used to cast the spot shadow in pixels. The X
2008 * axis position is set to the display width / 2.
2009 * @param lightRadius Radius of the light casting the shadow in pixels.
2010 *[
2011 * @hide
2012 */
2013 public static void setGlobalShadowSettings(@Size(4) float[] ambientColor,
2014 @Size(4) float[] spotColor, float lightPosY, float lightPosZ, float lightRadius) {
2015 validateColorArg(ambientColor);
2016 validateColorArg(spotColor);
2017 nativeSetGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ, lightRadius);
2018 }
2019
Vishnu Nair629df2b2019-06-11 16:03:38 -07002020 /**
Robert Carr76907ee2019-01-11 13:38:19 -08002021 * An atomic set of changes to a set of SurfaceControl.
Robert Carra7827f72019-01-11 12:53:37 -08002022 */
Vishnu Nair629df2b2019-06-11 16:03:38 -07002023 public static class Transaction implements Closeable, Parcelable {
Robert Carr76907ee2019-01-11 13:38:19 -08002024 /**
2025 * @hide
2026 */
Robert Carre13b58e2017-08-31 14:50:44 -07002027 public static final NativeAllocationRegistry sRegistry = new NativeAllocationRegistry(
2028 Transaction.class.getClassLoader(),
2029 nativeGetNativeTransactionFinalizer(), 512);
Robert Carr48ec4e02019-07-16 14:28:47 -07002030 /**
2031 * @hide
2032 */
2033 public long mNativeObject;
Robert Carre13b58e2017-08-31 14:50:44 -07002034
Jorim Jaggia5e10572017-11-15 14:36:26 +01002035 private final ArrayMap<SurfaceControl, Point> mResizedSurfaces = new ArrayMap<>();
Robert Carre13b58e2017-08-31 14:50:44 -07002036 Runnable mFreeNativeResources;
2037
Robert Carra7827f72019-01-11 12:53:37 -08002038 /**
Robert Carr76907ee2019-01-11 13:38:19 -08002039 * Open a new transaction object. The transaction may be filed with commands to
2040 * manipulate {@link SurfaceControl} instances, and then applied atomically with
2041 * {@link #apply}. Eventually the user should invoke {@link #close}, when the object
2042 * is no longer required. Note however that re-using a transaction after a call to apply
2043 * is allowed as a convenience.
Robert Carra7827f72019-01-11 12:53:37 -08002044 */
Robert Carre13b58e2017-08-31 14:50:44 -07002045 public Transaction() {
2046 mNativeObject = nativeCreateTransaction();
2047 mFreeNativeResources
2048 = sRegistry.registerNativeAllocation(this, mNativeObject);
2049 }
2050
Vishnu Nair629df2b2019-06-11 16:03:38 -07002051 private Transaction(Parcel in) {
2052 readFromParcel(in);
2053 }
2054
Robert Carre13b58e2017-08-31 14:50:44 -07002055 /**
2056 * Apply the transaction, clearing it's state, and making it usable
2057 * as a new transaction.
2058 */
2059 public void apply() {
2060 apply(false);
2061 }
2062
2063 /**
Robert Carr29fe58a2019-03-11 15:25:16 -07002064 * Release the native transaction object, without applying it.
Robert Carre13b58e2017-08-31 14:50:44 -07002065 */
2066 @Override
2067 public void close() {
2068 mFreeNativeResources.run();
2069 mNativeObject = 0;
2070 }
2071
2072 /**
2073 * Jankier version of apply. Avoid use (b/28068298).
Robert Carra7827f72019-01-11 12:53:37 -08002074 * @hide
Robert Carre13b58e2017-08-31 14:50:44 -07002075 */
2076 public void apply(boolean sync) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002077 applyResizedSurfaces();
Robert Carre13b58e2017-08-31 14:50:44 -07002078 nativeApplyTransaction(mNativeObject, sync);
2079 }
2080
Jorim Jaggia5e10572017-11-15 14:36:26 +01002081 private void applyResizedSurfaces() {
2082 for (int i = mResizedSurfaces.size() - 1; i >= 0; i--) {
2083 final Point size = mResizedSurfaces.valueAt(i);
2084 final SurfaceControl surfaceControl = mResizedSurfaces.keyAt(i);
2085 synchronized (surfaceControl.mSizeLock) {
2086 surfaceControl.mWidth = size.x;
2087 surfaceControl.mHeight = size.y;
2088 }
2089 }
2090 mResizedSurfaces.clear();
2091 }
2092
Robert Carra7827f72019-01-11 12:53:37 -08002093 /**
Robert Carr76907ee2019-01-11 13:38:19 -08002094 * Toggle the visibility of a given Layer and it's sub-tree.
2095 *
2096 * @param sc The SurfaceControl for which to set the visibility
2097 * @param visible The new visibility
2098 * @return This transaction object.
2099 */
2100 @NonNull
2101 public Transaction setVisibility(@NonNull SurfaceControl sc, boolean visible) {
2102 sc.checkNotReleased();
2103 if (visible) {
2104 return show(sc);
2105 } else {
2106 return hide(sc);
2107 }
2108 }
2109
2110 /**
2111 * Request that a given surface and it's sub-tree be shown.
2112 *
2113 * @param sc The surface to show.
2114 * @return This transaction.
Robert Carra7827f72019-01-11 12:53:37 -08002115 * @hide
2116 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002117 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07002118 public Transaction show(SurfaceControl sc) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002119 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002120 nativeSetFlags(mNativeObject, sc.mNativeObject, 0, SURFACE_HIDDEN);
2121 return this;
2122 }
2123
Robert Carra7827f72019-01-11 12:53:37 -08002124 /**
Robert Carr76907ee2019-01-11 13:38:19 -08002125 * Request that a given surface and it's sub-tree be hidden.
2126 *
2127 * @param sc The surface to hidden.
2128 * @return This transaction.
Robert Carra7827f72019-01-11 12:53:37 -08002129 * @hide
2130 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002131 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07002132 public Transaction hide(SurfaceControl sc) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002133 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002134 nativeSetFlags(mNativeObject, sc.mNativeObject, SURFACE_HIDDEN, SURFACE_HIDDEN);
2135 return this;
2136 }
2137
Robert Carra7827f72019-01-11 12:53:37 -08002138 /**
2139 * @hide
2140 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002141 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07002142 public Transaction setPosition(SurfaceControl sc, float x, float y) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002143 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002144 nativeSetPosition(mNativeObject, sc.mNativeObject, x, y);
2145 return this;
2146 }
2147
Robert Carra7827f72019-01-11 12:53:37 -08002148 /**
Robert Carr29fe58a2019-03-11 15:25:16 -07002149 * Set the default buffer size for the SurfaceControl, if there is a
2150 * {@link Surface} associated with the control, then
Robert Carr76907ee2019-01-11 13:38:19 -08002151 * this will be the default size for buffers dequeued from it.
2152 * @param sc The surface to set the buffer size for.
2153 * @param w The default width
2154 * @param h The default height
2155 * @return This Transaction
Robert Carra7827f72019-01-11 12:53:37 -08002156 */
Robert Carr76907ee2019-01-11 13:38:19 -08002157 @NonNull
2158 public Transaction setBufferSize(@NonNull SurfaceControl sc,
2159 @IntRange(from = 0) int w, @IntRange(from = 0) int h) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002160 sc.checkNotReleased();
Jorim Jaggia5e10572017-11-15 14:36:26 +01002161 mResizedSurfaces.put(sc, new Point(w, h));
Jorim Jaggidfc27372017-10-27 17:47:49 +02002162 nativeSetSize(mNativeObject, sc.mNativeObject, w, h);
Robert Carre13b58e2017-08-31 14:50:44 -07002163 return this;
2164 }
2165
Robert Carra7827f72019-01-11 12:53:37 -08002166 /**
Robert Carr76907ee2019-01-11 13:38:19 -08002167 * Set the Z-order for a given SurfaceControl, relative to it's siblings.
2168 * If two siblings share the same Z order the ordering is undefined. Surfaces
2169 * with a negative Z will be placed below the parent surface.
2170 *
2171 * @param sc The SurfaceControl to set the Z order on
2172 * @param z The Z-order
2173 * @return This Transaction.
Robert Carra7827f72019-01-11 12:53:37 -08002174 */
Robert Carr76907ee2019-01-11 13:38:19 -08002175 @NonNull
2176 public Transaction setLayer(@NonNull SurfaceControl sc,
2177 @IntRange(from = Integer.MIN_VALUE, to = Integer.MAX_VALUE) int z) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002178 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002179 nativeSetLayer(mNativeObject, sc.mNativeObject, z);
2180 return this;
2181 }
2182
Robert Carra7827f72019-01-11 12:53:37 -08002183 /**
2184 * @hide
2185 */
Robert Carr77e34942017-10-18 19:13:56 -07002186 public Transaction setRelativeLayer(SurfaceControl sc, SurfaceControl relativeTo, int z) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002187 sc.checkNotReleased();
Vishnu Nairbc9beab2019-06-25 17:28:58 -07002188 nativeSetRelativeLayer(mNativeObject, sc.mNativeObject, relativeTo.mNativeObject, z);
Robert Carre13b58e2017-08-31 14:50:44 -07002189 return this;
2190 }
2191
Robert Carra7827f72019-01-11 12:53:37 -08002192 /**
2193 * @hide
2194 */
Robert Carre13b58e2017-08-31 14:50:44 -07002195 public Transaction setTransparentRegionHint(SurfaceControl sc, Region transparentRegion) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002196 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002197 nativeSetTransparentRegionHint(mNativeObject,
2198 sc.mNativeObject, transparentRegion);
2199 return this;
2200 }
2201
Robert Carra7827f72019-01-11 12:53:37 -08002202 /**
Robert Carr76907ee2019-01-11 13:38:19 -08002203 * Set the alpha for a given surface. If the alpha is non-zero the SurfaceControl
2204 * will be blended with the Surfaces under it according to the specified ratio.
2205 *
2206 * @param sc The given SurfaceControl.
2207 * @param alpha The alpha to set.
Robert Carra7827f72019-01-11 12:53:37 -08002208 */
Robert Carr76907ee2019-01-11 13:38:19 -08002209 @NonNull
2210 public Transaction setAlpha(@NonNull SurfaceControl sc,
2211 @FloatRange(from = 0.0, to = 1.0) float alpha) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002212 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002213 nativeSetAlpha(mNativeObject, sc.mNativeObject, alpha);
2214 return this;
2215 }
2216
Robert Carra7827f72019-01-11 12:53:37 -08002217 /**
2218 * @hide
2219 */
Robert Carr788f5742018-07-30 17:46:45 -07002220 public Transaction setInputWindowInfo(SurfaceControl sc, InputWindowHandle handle) {
2221 sc.checkNotReleased();
2222 nativeSetInputWindowInfo(mNativeObject, sc.mNativeObject, handle);
2223 return this;
2224 }
2225
chaviw59f532e2018-12-26 15:34:59 -08002226 /**
chaviw319cd0782019-02-14 11:00:23 -08002227 * Waits until any changes to input windows have been sent from SurfaceFlinger to
2228 * InputFlinger before returning.
2229 *
2230 * @hide
2231 */
2232 public Transaction syncInputWindows() {
2233 nativeSyncInputWindows(mNativeObject);
2234 return this;
2235 }
2236
2237 /**
Robert Carr76907ee2019-01-11 13:38:19 -08002238 * Specify how the buffer assosciated with this Surface is mapped in to the
2239 * parent coordinate space. The source frame will be scaled to fit the destination
2240 * frame, after being rotated according to the orientation parameter.
2241 *
2242 * @param sc The SurfaceControl to specify the geometry of
2243 * @param sourceCrop The source rectangle in buffer space. Or null for the entire buffer.
2244 * @param destFrame The destination rectangle in parent space. Or null for the source frame.
2245 * @param orientation The buffer rotation
2246 * @return This transaction object.
2247 */
2248 @NonNull
2249 public Transaction setGeometry(@NonNull SurfaceControl sc, @Nullable Rect sourceCrop,
2250 @Nullable Rect destFrame, @Surface.Rotation int orientation) {
2251 sc.checkNotReleased();
2252 nativeSetGeometry(mNativeObject, sc.mNativeObject, sourceCrop, destFrame, orientation);
2253 return this;
2254 }
2255
2256 /**
Robert Carra7827f72019-01-11 12:53:37 -08002257 * @hide
2258 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002259 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07002260 public Transaction setMatrix(SurfaceControl sc,
2261 float dsdx, float dtdx, float dtdy, float dsdy) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002262 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002263 nativeSetMatrix(mNativeObject, sc.mNativeObject,
2264 dsdx, dtdx, dtdy, dsdy);
2265 return this;
2266 }
2267
Robert Carra7827f72019-01-11 12:53:37 -08002268 /**
chaviw619da692019-06-10 15:39:40 -07002269 * Sets the transform and position of a {@link SurfaceControl} from a 3x3 transformation
2270 * matrix.
2271 *
2272 * @param sc SurfaceControl to set matrix of
2273 * @param matrix The matrix to apply.
2274 * @param float9 An array of 9 floats to be used to extract the values from the matrix.
Robert Carra7827f72019-01-11 12:53:37 -08002275 * @hide
2276 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002277 @UnsupportedAppUsage
Jorim Jaggi21c39a72017-10-20 15:47:51 +02002278 public Transaction setMatrix(SurfaceControl sc, Matrix matrix, float[] float9) {
2279 matrix.getValues(float9);
2280 setMatrix(sc, float9[MSCALE_X], float9[MSKEW_Y],
2281 float9[MSKEW_X], float9[MSCALE_Y]);
2282 setPosition(sc, float9[MTRANS_X], float9[MTRANS_Y]);
2283 return this;
2284 }
2285
Peiyong Lin52bb6b42018-10-01 11:40:50 -07002286 /**
2287 * Sets the color transform for the Surface.
chaviw619da692019-06-10 15:39:40 -07002288 *
2289 * @param sc SurfaceControl to set color transform of
2290 * @param matrix A float array with 9 values represents a 3x3 transform matrix
Peiyong Lin52bb6b42018-10-01 11:40:50 -07002291 * @param translation A float array with 3 values represents a translation vector
Robert Carra7827f72019-01-11 12:53:37 -08002292 * @hide
Peiyong Lin52bb6b42018-10-01 11:40:50 -07002293 */
2294 public Transaction setColorTransform(SurfaceControl sc, @Size(9) float[] matrix,
2295 @Size(3) float[] translation) {
2296 sc.checkNotReleased();
2297 nativeSetColorTransform(mNativeObject, sc.mNativeObject, matrix, translation);
2298 return this;
2299 }
2300
Robert Carra7827f72019-01-11 12:53:37 -08002301 /**
Peiyong Linf4f0f642019-03-01 14:36:05 -08002302 * Sets the Surface to be color space agnostic. If a surface is color space agnostic,
2303 * the color can be interpreted in any color space.
2304 * @param agnostic A boolean to indicate whether the surface is color space agnostic
2305 * @hide
2306 */
2307 public Transaction setColorSpaceAgnostic(SurfaceControl sc, boolean agnostic) {
2308 sc.checkNotReleased();
2309 nativeSetColorSpaceAgnostic(mNativeObject, sc.mNativeObject, agnostic);
2310 return this;
2311 }
2312
2313 /**
chaviw619da692019-06-10 15:39:40 -07002314 * Bounds the surface and its children to the bounds specified. Size of the surface will be
2315 * ignored and only the crop and buffer size will be used to determine the bounds of the
2316 * surface. If no crop is specified and the surface has no buffer, the surface bounds is
2317 * only constrained by the size of its parent bounds.
2318 *
2319 * @param sc SurfaceControl to set crop of.
2320 * @param crop Bounds of the crop to apply.
Robert Carra7827f72019-01-11 12:53:37 -08002321 * @hide
2322 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002323 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07002324 public Transaction setWindowCrop(SurfaceControl sc, Rect crop) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002325 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002326 if (crop != null) {
2327 nativeSetWindowCrop(mNativeObject, sc.mNativeObject,
2328 crop.left, crop.top, crop.right, crop.bottom);
2329 } else {
2330 nativeSetWindowCrop(mNativeObject, sc.mNativeObject, 0, 0, 0, 0);
2331 }
2332
2333 return this;
2334 }
2335
Robert Carra7827f72019-01-11 12:53:37 -08002336 /**
chaviw619da692019-06-10 15:39:40 -07002337 * Same as {@link Transaction#setWindowCrop(SurfaceControl, Rect)} but sets the crop rect
2338 * top left at 0, 0.
2339 *
2340 * @param sc SurfaceControl to set crop of.
2341 * @param width width of crop rect
2342 * @param height height of crop rect
Robert Carra7827f72019-01-11 12:53:37 -08002343 * @hide
2344 */
Vishnu Naird454442d2018-11-13 13:51:01 -08002345 public Transaction setWindowCrop(SurfaceControl sc, int width, int height) {
2346 sc.checkNotReleased();
2347 nativeSetWindowCrop(mNativeObject, sc.mNativeObject, 0, 0, width, height);
2348 return this;
2349 }
2350
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07002351 /**
2352 * Sets the corner radius of a {@link SurfaceControl}.
2353 * @param sc SurfaceControl
2354 * @param cornerRadius Corner radius in pixels.
2355 * @return Itself.
Robert Carra7827f72019-01-11 12:53:37 -08002356 * @hide
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07002357 */
2358 @UnsupportedAppUsage
2359 public Transaction setCornerRadius(SurfaceControl sc, float cornerRadius) {
2360 sc.checkNotReleased();
2361 nativeSetCornerRadius(mNativeObject, sc.mNativeObject, cornerRadius);
2362
2363 return this;
2364 }
2365
Robert Carra7827f72019-01-11 12:53:37 -08002366 /**
2367 * @hide
2368 */
Mathew Inwood679c15e2019-02-06 15:36:04 +00002369 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.O)
Robert Carre13b58e2017-08-31 14:50:44 -07002370 public Transaction setLayerStack(SurfaceControl sc, int layerStack) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002371 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002372 nativeSetLayerStack(mNativeObject, sc.mNativeObject, layerStack);
2373 return this;
2374 }
2375
Robert Carra7827f72019-01-11 12:53:37 -08002376 /**
2377 * @hide
2378 */
Robert Carr76907ee2019-01-11 13:38:19 -08002379 @UnsupportedAppUsage
Vishnu Nairbc9beab2019-06-25 17:28:58 -07002380 public Transaction deferTransactionUntil(SurfaceControl sc, SurfaceControl barrier,
Jorim Jaggidfc27372017-10-27 17:47:49 +02002381 long frameNumber) {
Robert Carr024378c2018-02-27 11:21:05 -08002382 if (frameNumber < 0) {
2383 return this;
2384 }
Jorim Jaggidfc27372017-10-27 17:47:49 +02002385 sc.checkNotReleased();
Vishnu Nairbc9beab2019-06-25 17:28:58 -07002386 nativeDeferTransactionUntil(mNativeObject, sc.mNativeObject, barrier.mNativeObject,
2387 frameNumber);
Robert Carre13b58e2017-08-31 14:50:44 -07002388 return this;
2389 }
2390
Robert Carra7827f72019-01-11 12:53:37 -08002391 /**
2392 * @hide
2393 */
Robert Carr76907ee2019-01-11 13:38:19 -08002394 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07002395 public Transaction deferTransactionUntilSurface(SurfaceControl sc, Surface barrierSurface,
2396 long frameNumber) {
Robert Carr024378c2018-02-27 11:21:05 -08002397 if (frameNumber < 0) {
2398 return this;
2399 }
Jorim Jaggidfc27372017-10-27 17:47:49 +02002400 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002401 nativeDeferTransactionUntilSurface(mNativeObject, sc.mNativeObject,
2402 barrierSurface.mNativeObject, frameNumber);
2403 return this;
2404 }
2405
Robert Carra7827f72019-01-11 12:53:37 -08002406 /**
2407 * @hide
2408 */
Vishnu Nairbc9beab2019-06-25 17:28:58 -07002409 public Transaction reparentChildren(SurfaceControl sc, SurfaceControl newParent) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002410 sc.checkNotReleased();
Vishnu Nairbc9beab2019-06-25 17:28:58 -07002411 nativeReparentChildren(mNativeObject, sc.mNativeObject, newParent.mNativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -07002412 return this;
2413 }
2414
Robert Carr10584fa2019-01-14 15:55:19 -08002415 /**
2416 * Re-parents a given layer to a new parent. Children inherit transform (position, scaling)
2417 * crop, visibility, and Z-ordering from their parents, as if the children were pixels within the
2418 * parent Surface.
2419 *
2420 * @param sc The SurfaceControl to reparent
2421 * @param newParent The new parent for the given control.
2422 * @return This Transaction
Robert Carra7827f72019-01-11 12:53:37 -08002423 */
Robert Carr76907ee2019-01-11 13:38:19 -08002424 @NonNull
2425 public Transaction reparent(@NonNull SurfaceControl sc,
2426 @Nullable SurfaceControl newParent) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002427 sc.checkNotReleased();
Robert Carr10584fa2019-01-14 15:55:19 -08002428 long otherObject = 0;
2429 if (newParent != null) {
2430 newParent.checkNotReleased();
2431 otherObject = newParent.mNativeObject;
2432 }
2433 nativeReparent(mNativeObject, sc.mNativeObject, otherObject);
Robert Carre13b58e2017-08-31 14:50:44 -07002434 return this;
2435 }
2436
Robert Carra7827f72019-01-11 12:53:37 -08002437 /**
2438 * @hide
2439 */
Robert Carre13b58e2017-08-31 14:50:44 -07002440 public Transaction detachChildren(SurfaceControl sc) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002441 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002442 nativeSeverChildren(mNativeObject, sc.mNativeObject);
2443 return this;
2444 }
2445
Robert Carra7827f72019-01-11 12:53:37 -08002446 /**
2447 * @hide
2448 */
Robert Carre13b58e2017-08-31 14:50:44 -07002449 public Transaction setOverrideScalingMode(SurfaceControl sc, int overrideScalingMode) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002450 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002451 nativeSetOverrideScalingMode(mNativeObject, sc.mNativeObject,
2452 overrideScalingMode);
2453 return this;
2454 }
2455
2456 /**
2457 * Sets a color for the Surface.
2458 * @param color A float array with three values to represent r, g, b in range [0..1]
Robert Carra7827f72019-01-11 12:53:37 -08002459 * @hide
Robert Carre13b58e2017-08-31 14:50:44 -07002460 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002461 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07002462 public Transaction setColor(SurfaceControl sc, @Size(3) float[] color) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002463 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002464 nativeSetColor(mNativeObject, sc.mNativeObject, color);
2465 return this;
2466 }
2467
2468 /**
Robert Carre13b58e2017-08-31 14:50:44 -07002469 * Sets the security of the surface. Setting the flag is equivalent to creating the
2470 * Surface with the {@link #SECURE} flag.
Robert Carra7827f72019-01-11 12:53:37 -08002471 * @hide
Robert Carre13b58e2017-08-31 14:50:44 -07002472 */
Robert Carrb1579c82017-09-05 14:54:47 -07002473 public Transaction setSecure(SurfaceControl sc, boolean isSecure) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002474 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002475 if (isSecure) {
2476 nativeSetFlags(mNativeObject, sc.mNativeObject, SECURE, SECURE);
2477 } else {
2478 nativeSetFlags(mNativeObject, sc.mNativeObject, 0, SECURE);
2479 }
2480 return this;
2481 }
2482
2483 /**
2484 * Sets the opacity of the surface. Setting the flag is equivalent to creating the
2485 * Surface with the {@link #OPAQUE} flag.
Robert Carra7827f72019-01-11 12:53:37 -08002486 * @hide
Robert Carre13b58e2017-08-31 14:50:44 -07002487 */
2488 public Transaction setOpaque(SurfaceControl sc, boolean isOpaque) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002489 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002490 if (isOpaque) {
Robert Carr2b8a5e12017-10-18 18:46:27 -07002491 nativeSetFlags(mNativeObject, sc.mNativeObject, SURFACE_OPAQUE, SURFACE_OPAQUE);
Robert Carre13b58e2017-08-31 14:50:44 -07002492 } else {
Robert Carr2b8a5e12017-10-18 18:46:27 -07002493 nativeSetFlags(mNativeObject, sc.mNativeObject, 0, SURFACE_OPAQUE);
Robert Carre13b58e2017-08-31 14:50:44 -07002494 }
2495 return this;
2496 }
2497
Robert Carra7827f72019-01-11 12:53:37 -08002498 /**
2499 * @hide
2500 */
Robert Carre13b58e2017-08-31 14:50:44 -07002501 public Transaction setDisplaySurface(IBinder displayToken, Surface surface) {
2502 if (displayToken == null) {
2503 throw new IllegalArgumentException("displayToken must not be null");
2504 }
2505
2506 if (surface != null) {
2507 synchronized (surface.mLock) {
2508 nativeSetDisplaySurface(mNativeObject, displayToken, surface.mNativeObject);
2509 }
2510 } else {
2511 nativeSetDisplaySurface(mNativeObject, displayToken, 0);
2512 }
2513 return this;
2514 }
2515
Robert Carra7827f72019-01-11 12:53:37 -08002516 /**
2517 * @hide
2518 */
Robert Carre13b58e2017-08-31 14:50:44 -07002519 public Transaction setDisplayLayerStack(IBinder displayToken, int layerStack) {
2520 if (displayToken == null) {
2521 throw new IllegalArgumentException("displayToken must not be null");
2522 }
2523 nativeSetDisplayLayerStack(mNativeObject, displayToken, layerStack);
2524 return this;
2525 }
2526
Robert Carra7827f72019-01-11 12:53:37 -08002527 /**
2528 * @hide
2529 */
Robert Carre13b58e2017-08-31 14:50:44 -07002530 public Transaction setDisplayProjection(IBinder displayToken,
2531 int orientation, Rect layerStackRect, Rect displayRect) {
2532 if (displayToken == null) {
2533 throw new IllegalArgumentException("displayToken must not be null");
2534 }
2535 if (layerStackRect == null) {
2536 throw new IllegalArgumentException("layerStackRect must not be null");
2537 }
2538 if (displayRect == null) {
2539 throw new IllegalArgumentException("displayRect must not be null");
2540 }
2541 nativeSetDisplayProjection(mNativeObject, displayToken, orientation,
2542 layerStackRect.left, layerStackRect.top, layerStackRect.right, layerStackRect.bottom,
2543 displayRect.left, displayRect.top, displayRect.right, displayRect.bottom);
2544 return this;
2545 }
2546
Robert Carra7827f72019-01-11 12:53:37 -08002547 /**
2548 * @hide
2549 */
Robert Carre13b58e2017-08-31 14:50:44 -07002550 public Transaction setDisplaySize(IBinder displayToken, int width, int height) {
2551 if (displayToken == null) {
2552 throw new IllegalArgumentException("displayToken must not be null");
2553 }
2554 if (width <= 0 || height <= 0) {
2555 throw new IllegalArgumentException("width and height must be positive");
2556 }
2557
2558 nativeSetDisplaySize(mNativeObject, displayToken, width, height);
2559 return this;
2560 }
2561
Vishnu Nair629df2b2019-06-11 16:03:38 -07002562 /** flag the transaction as an animation
Robert Carra7827f72019-01-11 12:53:37 -08002563 * @hide
2564 */
Robert Carre13b58e2017-08-31 14:50:44 -07002565 public Transaction setAnimationTransaction() {
2566 nativeSetAnimationTransaction(mNativeObject);
2567 return this;
2568 }
Robert Carrb1579c82017-09-05 14:54:47 -07002569
2570 /**
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01002571 * Indicate that SurfaceFlinger should wake up earlier than usual as a result of this
2572 * transaction. This should be used when the caller thinks that the scene is complex enough
2573 * that it's likely to hit GL composition, and thus, SurfaceFlinger needs to more time in
2574 * order not to miss frame deadlines.
2575 * <p>
2576 * Corresponds to setting ISurfaceComposer::eEarlyWakeup
Robert Carra7827f72019-01-11 12:53:37 -08002577 * @hide
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01002578 */
2579 public Transaction setEarlyWakeup() {
2580 nativeSetEarlyWakeup(mNativeObject);
2581 return this;
2582 }
2583
2584 /**
Evan Rosky485df202018-12-06 14:11:12 -08002585 * Sets an arbitrary piece of metadata on the surface. This is a helper for int data.
2586 * @hide
2587 */
Evan Roskyb51e2462019-04-03 19:27:18 -07002588 public Transaction setMetadata(SurfaceControl sc, int key, int data) {
Evan Rosky485df202018-12-06 14:11:12 -08002589 Parcel parcel = Parcel.obtain();
2590 parcel.writeInt(data);
2591 try {
Evan Roskyb51e2462019-04-03 19:27:18 -07002592 setMetadata(sc, key, parcel);
Evan Rosky485df202018-12-06 14:11:12 -08002593 } finally {
2594 parcel.recycle();
2595 }
2596 return this;
2597 }
2598
2599 /**
2600 * Sets an arbitrary piece of metadata on the surface.
2601 * @hide
2602 */
Evan Roskyb51e2462019-04-03 19:27:18 -07002603 public Transaction setMetadata(SurfaceControl sc, int key, Parcel data) {
2604 nativeSetMetadata(mNativeObject, sc.mNativeObject, key, data);
Evan Rosky485df202018-12-06 14:11:12 -08002605 return this;
2606 }
2607
Vishnu Naird87984d2019-11-06 14:43:22 -08002608 /**
2609 * Draws shadows of length {@code shadowRadius} around the surface {@link SurfaceControl}.
2610 * If the length is 0.0f then the shadows will not be drawn.
2611 *
2612 * Shadows are drawn around the screen bounds, these are the post transformed cropped
2613 * bounds. They can draw over their parent bounds and will be occluded by layers with a
2614 * higher z-order. The shadows will respect the surface's corner radius if the
2615 * rounded corner bounds (transformed source bounds) are within the screen bounds.
2616 *
2617 * A shadow will only be drawn on buffer and color layers. If the radius is applied on a
2618 * container layer, it will be passed down the hierarchy to be applied on buffer and color
2619 * layers but not its children. A scenario where this is useful is when SystemUI animates
2620 * a task by controlling a leash to it, can draw a shadow around the app surface by
2621 * setting a shadow on the leash. This is similar to how rounded corners are set.
2622 *
2623 * @hide
2624 */
2625 public Transaction setShadowRadius(SurfaceControl sc, float shadowRadius) {
2626 sc.checkNotReleased();
2627 nativeSetShadowRadius(mNativeObject, sc.mNativeObject, shadowRadius);
2628 return this;
2629 }
2630
Evan Rosky485df202018-12-06 14:11:12 -08002631 /**
Robert Carrb1579c82017-09-05 14:54:47 -07002632 * Merge the other transaction into this transaction, clearing the
2633 * other transaction as if it had been applied.
Robert Carr76907ee2019-01-11 13:38:19 -08002634 *
2635 * @param other The transaction to merge in to this one.
2636 * @return This transaction.
Robert Carrb1579c82017-09-05 14:54:47 -07002637 */
Robert Carr76907ee2019-01-11 13:38:19 -08002638 @NonNull
2639 public Transaction merge(@NonNull Transaction other) {
Tiger Huanged6794e2019-05-07 20:07:59 +08002640 if (this == other) {
2641 return this;
2642 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01002643 mResizedSurfaces.putAll(other.mResizedSurfaces);
2644 other.mResizedSurfaces.clear();
Robert Carrb1579c82017-09-05 14:54:47 -07002645 nativeMergeTransaction(mNativeObject, other.mNativeObject);
2646 return this;
2647 }
Robert Carr71200f22019-02-05 09:44:53 -08002648
2649 /**
2650 * Equivalent to reparent with a null parent, in that it removes
2651 * the SurfaceControl from the scene, but it also releases
2652 * the local resources (by calling {@link SurfaceControl#release})
2653 * after this method returns, {@link SurfaceControl#isValid} will return
2654 * false for the argument.
2655 *
2656 * @param sc The surface to remove and release.
2657 * @return This transaction
2658 * @hide
2659 */
2660 @NonNull
2661 public Transaction remove(@NonNull SurfaceControl sc) {
2662 reparent(sc, null);
2663 sc.release();
2664 return this;
2665 }
Vishnu Nair629df2b2019-06-11 16:03:38 -07002666
Vishnu Nairf7645aa2019-06-18 11:14:01 -07002667 /**
2668 * Writes the transaction to parcel, clearing the transaction as if it had been applied so
2669 * it can be used to store future transactions. It's the responsibility of the parcel
2670 * reader to apply the original transaction.
2671 *
2672 * @param dest parcel to write the transaction to
2673 * @param flags
2674 */
Vishnu Nair629df2b2019-06-11 16:03:38 -07002675 @Override
2676 public void writeToParcel(@NonNull Parcel dest, @WriteFlags int flags) {
2677 if (mNativeObject == 0) {
2678 dest.writeInt(0);
2679 } else {
2680 dest.writeInt(1);
2681 }
2682 nativeWriteTransactionToParcel(mNativeObject, dest);
2683 }
2684
2685 private void readFromParcel(Parcel in) {
2686 mNativeObject = 0;
2687 if (in.readInt() != 0) {
2688 mNativeObject = nativeReadTransactionFromParcel(in);
2689 mFreeNativeResources = sRegistry.registerNativeAllocation(this, mNativeObject);
2690 }
2691 }
2692
2693 @Override
2694 public int describeContents() {
2695 return 0;
2696 }
2697
2698 public static final @NonNull Creator<Transaction> CREATOR = new Creator<Transaction>() {
2699 @Override
2700 public Transaction createFromParcel(Parcel in) {
2701 return new Transaction(in);
2702 }
2703 @Override
2704 public Transaction[] newArray(int size) {
2705 return new Transaction[size];
2706 }
2707 };
Robert Carre13b58e2017-08-31 14:50:44 -07002708 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08002709}