blob: 8061cc3bab7402ee6b1c57f7a011cc50bde704c2 [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;
Peiyong Lin9d427402019-01-23 18:39:06 -080044import android.hardware.HardwareBuffer;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -070045import android.hardware.display.DisplayedContentSample;
46import android.hardware.display.DisplayedContentSamplingAttributes;
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;
Robert Carre13b58e2017-08-31 14:50:44 -070064
Mathias Agopian3866f0d2013-02-11 22:08:48 -080065/**
Robert Carr76907ee2019-01-11 13:38:19 -080066 * Handle to an on-screen Surface managed by the system compositor. The SurfaceControl is
67 * a combination of a buffer source, and metadata about how to display the buffers.
68 * By constructing a {@link Surface} from this SurfaceControl you can submit buffers to be
69 * composited. Using {@link SurfaceControl.Transaction} you can manipulate various
70 * properties of how the buffer will be displayed on-screen. SurfaceControl's are
71 * arranged into a scene-graph like hierarchy, and as such any SurfaceControl may have
72 * a parent. Geometric properties like transform, crop, and Z-ordering will be inherited
73 * from the parent, as if the child were content in the parents buffer stream.
Mathias Agopian3866f0d2013-02-11 22:08:48 -080074 */
Robert Carr76907ee2019-01-11 13:38:19 -080075public final class SurfaceControl implements Parcelable {
Mathias Agopian3866f0d2013-02-11 22:08:48 -080076 private static final String TAG = "SurfaceControl";
Mathias Agopian29479eb2013-02-14 14:36:04 -080077
Ashok Bhat36bef0b2014-01-20 20:08:01 +000078 private static native long nativeCreate(SurfaceSession session, String name,
Evan Rosky485df202018-12-06 14:11:12 -080079 int w, int h, int format, int flags, long parentObject, Parcel metadata)
Mathias Agopian29479eb2013-02-14 14:36:04 -080080 throws OutOfResourcesException;
Jorim Jaggi06975df2017-12-01 14:52:13 +010081 private static native long nativeReadFromParcel(Parcel in);
chaviwbeb7a0c2018-12-05 13:49:54 -080082 private static native long nativeCopyFromSurfaceControl(long nativeObject);
Jorim Jaggi06975df2017-12-01 14:52:13 +010083 private static native void nativeWriteToParcel(long nativeObject, Parcel out);
Ashok Bhat36bef0b2014-01-20 20:08:01 +000084 private static native void nativeRelease(long nativeObject);
85 private static native void nativeDestroy(long nativeObject);
Chong Zhang47e36a32016-02-29 16:44:33 -080086 private static native void nativeDisconnect(long nativeObject);
Mathias Agopian29479eb2013-02-14 14:36:04 -080087
chaviw08520a02018-09-10 16:44:56 -070088 private static native GraphicBuffer nativeScreenshot(IBinder displayToken,
89 Rect sourceCrop, int width, int height, boolean useIdentityTransform, int rotation);
chaviwfbe47df2017-11-10 16:14:49 -080090 private static native GraphicBuffer nativeCaptureLayers(IBinder layerHandleToken,
91 Rect sourceCrop, float frameScale);
Mathias Agopian29479eb2013-02-14 14:36:04 -080092
Robert Carre13b58e2017-08-31 14:50:44 -070093 private static native long nativeCreateTransaction();
94 private static native long nativeGetNativeTransactionFinalizer();
95 private static native void nativeApplyTransaction(long transactionObj, boolean sync);
Robert Carrb1579c82017-09-05 14:54:47 -070096 private static native void nativeMergeTransaction(long transactionObj,
97 long otherTransactionObj);
Robert Carre13b58e2017-08-31 14:50:44 -070098 private static native void nativeSetAnimationTransaction(long transactionObj);
Jorim Jaggiaa763cd2018-03-22 23:20:36 +010099 private static native void nativeSetEarlyWakeup(long transactionObj);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800100
Robert Carre13b58e2017-08-31 14:50:44 -0700101 private static native void nativeSetLayer(long transactionObj, long nativeObject, int zorder);
102 private static native void nativeSetRelativeLayer(long transactionObj, long nativeObject,
103 IBinder relativeTo, int zorder);
104 private static native void nativeSetPosition(long transactionObj, long nativeObject,
105 float x, float y);
106 private static native void nativeSetGeometryAppliesWithResize(long transactionObj,
107 long nativeObject);
108 private static native void nativeSetSize(long transactionObj, long nativeObject, int w, int h);
109 private static native void nativeSetTransparentRegionHint(long transactionObj,
110 long nativeObject, Region region);
111 private static native void nativeSetAlpha(long transactionObj, long nativeObject, float alpha);
112 private static native void nativeSetMatrix(long transactionObj, long nativeObject,
113 float dsdx, float dtdx,
Andrii Kulian283acd22017-08-03 04:03:51 -0700114 float dtdy, float dsdy);
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700115 private static native void nativeSetColorTransform(long transactionObj, long nativeObject,
116 float[] matrix, float[] translation);
Robert Carr76907ee2019-01-11 13:38:19 -0800117 private static native void nativeSetGeometry(long transactionObj, long nativeObject,
118 Rect sourceCrop, Rect dest, long orientation);
Robert Carre13b58e2017-08-31 14:50:44 -0700119 private static native void nativeSetColor(long transactionObj, long nativeObject, float[] color);
120 private static native void nativeSetFlags(long transactionObj, long nativeObject,
121 int flags, int mask);
122 private static native void nativeSetWindowCrop(long transactionObj, long nativeObject,
123 int l, int t, int r, int b);
Lucas Dupinff9d6ab2018-10-16 18:05:50 -0700124 private static native void nativeSetCornerRadius(long transactionObj, long nativeObject,
125 float cornerRadius);
Robert Carre13b58e2017-08-31 14:50:44 -0700126 private static native void nativeSetLayerStack(long transactionObj, long nativeObject,
127 int layerStack);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800128
Svetoslav1376d602014-03-13 11:17:26 -0700129 private static native boolean nativeClearContentFrameStats(long nativeObject);
130 private static native boolean nativeGetContentFrameStats(long nativeObject, WindowContentFrameStats outStats);
131 private static native boolean nativeClearAnimationFrameStats();
132 private static native boolean nativeGetAnimationFrameStats(WindowAnimationFrameStats outStats);
133
Mathias Agopian29479eb2013-02-14 14:36:04 -0800134 private static native IBinder nativeGetBuiltInDisplay(int physicalDisplayId);
135 private static native IBinder nativeCreateDisplay(String name, boolean secure);
Jesse Hall6a6bc212013-08-08 12:15:03 -0700136 private static native void nativeDestroyDisplay(IBinder displayToken);
Robert Carre13b58e2017-08-31 14:50:44 -0700137 private static native void nativeSetDisplaySurface(long transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000138 IBinder displayToken, long nativeSurfaceObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700139 private static native void nativeSetDisplayLayerStack(long transactionObj,
Mathias Agopian29479eb2013-02-14 14:36:04 -0800140 IBinder displayToken, int layerStack);
Robert Carre13b58e2017-08-31 14:50:44 -0700141 private static native void nativeSetDisplayProjection(long transactionObj,
Mathias Agopian29479eb2013-02-14 14:36:04 -0800142 IBinder displayToken, int orientation,
Jesse Hall6a6bc212013-08-08 12:15:03 -0700143 int l, int t, int r, int b,
Mathias Agopian29479eb2013-02-14 14:36:04 -0800144 int L, int T, int R, int B);
Robert Carre13b58e2017-08-31 14:50:44 -0700145 private static native void nativeSetDisplaySize(long transactionObj, IBinder displayToken,
146 int width, int height);
Dan Stoza00101052014-05-02 15:23:40 -0700147 private static native SurfaceControl.PhysicalDisplayInfo[] nativeGetDisplayConfigs(
148 IBinder displayToken);
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700149 private static native DisplayedContentSamplingAttributes
150 nativeGetDisplayedContentSamplingAttributes(IBinder displayToken);
151 private static native boolean nativeSetDisplayedContentSamplingEnabled(IBinder displayToken,
152 boolean enable, int componentMask, int maxFrames);
153 private static native DisplayedContentSample nativeGetDisplayedContentSample(
154 IBinder displayToken, long numFrames, long timestamp);
Dan Stoza00101052014-05-02 15:23:40 -0700155 private static native int nativeGetActiveConfig(IBinder displayToken);
156 private static native boolean nativeSetActiveConfig(IBinder displayToken, int id);
Michael Wright1c9977b2016-07-12 13:30:10 -0700157 private static native int[] nativeGetDisplayColorModes(IBinder displayToken);
Daniel Solomon10e3b332019-01-20 21:09:11 -0800158 private static native SurfaceControl.DisplayPrimaries nativeGetDisplayNativePrimaries(
159 IBinder displayToken);
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800160 private static native int[] nativeGetCompositionDataspaces();
Michael Wright1c9977b2016-07-12 13:30:10 -0700161 private static native int nativeGetActiveColorMode(IBinder displayToken);
162 private static native boolean nativeSetActiveColorMode(IBinder displayToken,
163 int colorMode);
Prashant Malanic55929a2014-05-25 01:59:21 -0700164 private static native void nativeSetDisplayPowerMode(
165 IBinder displayToken, int mode);
Robert Carre13b58e2017-08-31 14:50:44 -0700166 private static native void nativeDeferTransactionUntil(long transactionObj, long nativeObject,
Rob Carr64e516f2015-10-29 00:20:45 +0000167 IBinder handle, long frame);
Robert Carre13b58e2017-08-31 14:50:44 -0700168 private static native void nativeDeferTransactionUntilSurface(long transactionObj,
169 long nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -0800170 long surfaceObject, long frame);
Robert Carre13b58e2017-08-31 14:50:44 -0700171 private static native void nativeReparentChildren(long transactionObj, long nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -0800172 IBinder handle);
Robert Carre13b58e2017-08-31 14:50:44 -0700173 private static native void nativeReparent(long transactionObj, long nativeObject,
Robert Carr10584fa2019-01-14 15:55:19 -0800174 long newParentNativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700175 private static native void nativeSeverChildren(long transactionObj, long nativeObject);
176 private static native void nativeSetOverrideScalingMode(long transactionObj, long nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -0700177 int scalingMode);
Rob Carr64e516f2015-10-29 00:20:45 +0000178 private static native IBinder nativeGetHandle(long nativeObject);
Robert Carr6da3cc02016-06-16 15:17:07 -0700179 private static native boolean nativeGetTransformToDisplayInverse(long nativeObject);
180
Michael Wright9ff94c02016-03-30 18:05:40 -0700181 private static native Display.HdrCapabilities nativeGetHdrCapabilities(IBinder displayToken);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800182
Robert Carr788f5742018-07-30 17:46:45 -0700183 private static native void nativeSetInputWindowInfo(long transactionObj, long nativeObject,
184 InputWindowHandle handle);
chaviw59f532e2018-12-26 15:34:59 -0800185 private static native void nativeTransferTouchFocus(long transactionObj, IBinder fromToken,
186 IBinder toToken);
Peiyong Lin0ddb7d42019-01-16 13:25:09 -0800187 private static native boolean nativeGetProtectedContentSupport();
Evan Rosky485df202018-12-06 14:11:12 -0800188 private static native void nativeSetMetadata(long transactionObj, int key, Parcel data);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800189
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800190 private final CloseGuard mCloseGuard = CloseGuard.get();
chaviwbeb7a0c2018-12-05 13:49:54 -0800191 private String mName;
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000192 long mNativeObject; // package visibility only for Surface.java access
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800193
Jorim Jaggia5e10572017-11-15 14:36:26 +0100194 // TODO: Move this to native.
195 private final Object mSizeLock = new Object();
196 @GuardedBy("mSizeLock")
197 private int mWidth;
198 @GuardedBy("mSizeLock")
199 private int mHeight;
200
Robert Carre13b58e2017-08-31 14:50:44 -0700201 static Transaction sGlobalTransaction;
202 static long sTransactionNestCount = 0;
203
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800204 /* flags used in constructor (keep in sync with ISurfaceComposerClient.h) */
205
206 /**
207 * Surface creation flag: Surface is created hidden
Robert Carra7827f72019-01-11 12:53:37 -0800208 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800209 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100210 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800211 public static final int HIDDEN = 0x00000004;
212
213 /**
214 * Surface creation flag: The surface contains secure content, special
215 * measures will be taken to disallow the surface's content to be copied
216 * from another process. In particular, screenshots and VNC servers will
217 * be disabled, but other measures can take place, for instance the
Jesse Hall6a6bc212013-08-08 12:15:03 -0700218 * surface might not be hardware accelerated.
Robert Carra7827f72019-01-11 12:53:37 -0800219 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800220 */
221 public static final int SECURE = 0x00000080;
222
223 /**
224 * Surface creation flag: Creates a surface where color components are interpreted
225 * as "non pre-multiplied" by their alpha channel. Of course this flag is
226 * meaningless for surfaces without an alpha channel. By default
227 * surfaces are pre-multiplied, which means that each color component is
228 * already multiplied by its alpha value. In this case the blending
229 * equation used is:
Andy McFadden314405b2014-01-29 17:18:05 -0800230 * <p>
231 * <code>DEST = SRC + DEST * (1-SRC_ALPHA)</code>
232 * <p>
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800233 * By contrast, non pre-multiplied surfaces use the following equation:
Andy McFadden314405b2014-01-29 17:18:05 -0800234 * <p>
235 * <code>DEST = SRC * SRC_ALPHA * DEST * (1-SRC_ALPHA)</code>
236 * <p>
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800237 * pre-multiplied surfaces must always be used if transparent pixels are
238 * composited on top of each-other into the surface. A pre-multiplied
239 * surface can never lower the value of the alpha component of a given
240 * pixel.
Andy McFadden314405b2014-01-29 17:18:05 -0800241 * <p>
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800242 * In some rare situations, a non pre-multiplied surface is preferable.
Robert Carra7827f72019-01-11 12:53:37 -0800243 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800244 */
245 public static final int NON_PREMULTIPLIED = 0x00000100;
246
247 /**
248 * Surface creation flag: Indicates that the surface must be considered opaque,
Robert Carre625fcf2017-09-01 12:36:28 -0700249 * even if its pixel format contains an alpha channel. This can be useful if an
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800250 * application needs full RGBA 8888 support for instance but will
251 * still draw every pixel opaque.
Andy McFadden314405b2014-01-29 17:18:05 -0800252 * <p>
253 * This flag is ignored if setAlpha() is used to make the surface non-opaque.
254 * Combined effects are (assuming a buffer format with an alpha channel):
255 * <ul>
256 * <li>OPAQUE + alpha(1.0) == opaque composition
257 * <li>OPAQUE + alpha(0.x) == blended composition
258 * <li>!OPAQUE + alpha(1.0) == blended composition
259 * <li>!OPAQUE + alpha(0.x) == blended composition
260 * </ul>
261 * If the underlying buffer lacks an alpha channel, the OPAQUE flag is effectively
262 * set automatically.
Robert Carra7827f72019-01-11 12:53:37 -0800263 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800264 */
265 public static final int OPAQUE = 0x00000400;
266
267 /**
268 * Surface creation flag: Application requires a hardware-protected path to an
269 * external display sink. If a hardware-protected path is not available,
270 * then this surface will not be displayed on the external sink.
271 *
Robert Carra7827f72019-01-11 12:53:37 -0800272 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800273 */
274 public static final int PROTECTED_APP = 0x00000800;
275
276 // 0x1000 is reserved for an independent DRM protected flag in framework
277
278 /**
Riley Andrews68eccda2014-07-07 11:47:35 -0700279 * Surface creation flag: Window represents a cursor glyph.
Robert Carra7827f72019-01-11 12:53:37 -0800280 * @hide
Riley Andrews68eccda2014-07-07 11:47:35 -0700281 */
282 public static final int CURSOR_WINDOW = 0x00002000;
283
284 /**
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800285 * Surface creation flag: Creates a normal surface.
286 * This is the default.
287 *
Robert Carra7827f72019-01-11 12:53:37 -0800288 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800289 */
290 public static final int FX_SURFACE_NORMAL = 0x00000000;
291
292 /**
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800293 * Surface creation flag: Creates a Dim surface.
294 * Everything behind this surface is dimmed by the amount specified
295 * in {@link #setAlpha}. It is an error to lock a Dim surface, since it
296 * doesn't have a backing store.
297 *
Robert Carra7827f72019-01-11 12:53:37 -0800298 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800299 */
300 public static final int FX_SURFACE_DIM = 0x00020000;
301
302 /**
Robert Carrb6cd6432018-08-13 13:01:47 -0700303 * Surface creation flag: Creates a container surface.
304 * This surface will have no buffers and will only be used
305 * as a container for other surfaces, or for its InputInfo.
Robert Carra7827f72019-01-11 12:53:37 -0800306 * @hide
Robert Carrb6cd6432018-08-13 13:01:47 -0700307 */
308 public static final int FX_SURFACE_CONTAINER = 0x00080000;
309
310 /**
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800311 * Mask used for FX values above.
312 *
Robert Carra7827f72019-01-11 12:53:37 -0800313 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800314 */
315 public static final int FX_SURFACE_MASK = 0x000F0000;
316
317 /* flags used with setFlags() (keep in sync with ISurfaceComposer.h) */
318
319 /**
320 * Surface flag: Hide the surface.
321 * Equivalent to calling hide().
Andy McFadden314405b2014-01-29 17:18:05 -0800322 * Updates the value set during Surface creation (see {@link #HIDDEN}).
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800323 */
Andy McFadden40b9ef12014-01-30 13:44:47 -0800324 private static final int SURFACE_HIDDEN = 0x01;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800325
Andy McFadden314405b2014-01-29 17:18:05 -0800326 /**
327 * Surface flag: composite without blending when possible.
328 * Updates the value set during Surface creation (see {@link #OPAQUE}).
329 */
Andy McFadden40b9ef12014-01-30 13:44:47 -0800330 private static final int SURFACE_OPAQUE = 0x02;
Andy McFadden314405b2014-01-29 17:18:05 -0800331
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800332
333 /* built-in physical display ids (keep in sync with ISurfaceComposer.h)
334 * these are different from the logical display ids used elsewhere in the framework */
335
336 /**
337 * Built-in physical display id: Main display.
Andy McFadden40b9ef12014-01-30 13:44:47 -0800338 * Use only with {@link SurfaceControl#getBuiltInDisplay(int)}.
Robert Carra7827f72019-01-11 12:53:37 -0800339 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800340 */
341 public static final int BUILT_IN_DISPLAY_ID_MAIN = 0;
342
343 /**
344 * Built-in physical display id: Attached HDMI display.
Andy McFadden40b9ef12014-01-30 13:44:47 -0800345 * Use only with {@link SurfaceControl#getBuiltInDisplay(int)}.
Robert Carra7827f72019-01-11 12:53:37 -0800346 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800347 */
348 public static final int BUILT_IN_DISPLAY_ID_HDMI = 1;
349
Robert Carr76907ee2019-01-11 13:38:19 -0800350 // Display power modes.
Prashant Malanic55929a2014-05-25 01:59:21 -0700351 /**
352 * Display power mode off: used while blanking the screen.
Jeff Brown5dc21912014-07-17 18:50:18 -0700353 * Use only with {@link SurfaceControl#setDisplayPowerMode}.
Robert Carra7827f72019-01-11 12:53:37 -0800354 * @hide
Prashant Malanic55929a2014-05-25 01:59:21 -0700355 */
356 public static final int POWER_MODE_OFF = 0;
357
358 /**
359 * Display power mode doze: used while putting the screen into low power mode.
Jeff Brown5dc21912014-07-17 18:50:18 -0700360 * Use only with {@link SurfaceControl#setDisplayPowerMode}.
Robert Carra7827f72019-01-11 12:53:37 -0800361 * @hide
Prashant Malanic55929a2014-05-25 01:59:21 -0700362 */
363 public static final int POWER_MODE_DOZE = 1;
364
365 /**
366 * Display power mode normal: used while unblanking the screen.
Jeff Brown5dc21912014-07-17 18:50:18 -0700367 * Use only with {@link SurfaceControl#setDisplayPowerMode}.
Robert Carra7827f72019-01-11 12:53:37 -0800368 * @hide
Prashant Malanic55929a2014-05-25 01:59:21 -0700369 */
370 public static final int POWER_MODE_NORMAL = 2;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800371
Jeff Brown5dc21912014-07-17 18:50:18 -0700372 /**
373 * Display power mode doze: used while putting the screen into a suspended
374 * low power mode. Use only with {@link SurfaceControl#setDisplayPowerMode}.
Robert Carra7827f72019-01-11 12:53:37 -0800375 * @hide
Jeff Brown5dc21912014-07-17 18:50:18 -0700376 */
377 public static final int POWER_MODE_DOZE_SUSPEND = 3;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800378
379 /**
Chris Phoenix10a4a642017-09-25 13:21:00 -0700380 * Display power mode on: used while putting the screen into a suspended
381 * full power mode. Use only with {@link SurfaceControl#setDisplayPowerMode}.
Robert Carra7827f72019-01-11 12:53:37 -0800382 * @hide
Chris Phoenix10a4a642017-09-25 13:21:00 -0700383 */
384 public static final int POWER_MODE_ON_SUSPEND = 4;
385
386 /**
Robert Carr132c9f52017-07-31 17:02:30 -0700387 * A value for windowType used to indicate that the window should be omitted from screenshots
388 * and display mirroring. A temporary workaround until we express such things with
389 * the hierarchy.
390 * TODO: b/64227542
391 * @hide
392 */
393 public static final int WINDOW_TYPE_DONT_SCREENSHOT = 441731;
394
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800395 /**
396 * internal representation of how to interpret pixel value, used only to convert to ColorSpace.
397 */
398 private static final int INTERNAL_DATASPACE_SRGB = 142671872;
399 private static final int INTERNAL_DATASPACE_DISPLAY_P3 = 143261696;
400 private static final int INTERNAL_DATASPACE_SCRGB = 411107328;
401
Robert Carreb344c72019-01-07 18:35:30 -0800402 private void assignNativeObject(long nativeObject) {
403 if (mNativeObject != 0) {
404 release();
405 }
406 mNativeObject = nativeObject;
407 }
408
Robert Carra7827f72019-01-11 12:53:37 -0800409 /**
410 * @hide
411 */
chaviwbeb7a0c2018-12-05 13:49:54 -0800412 public void copyFrom(SurfaceControl other) {
413 mName = other.mName;
414 mWidth = other.mWidth;
415 mHeight = other.mHeight;
Robert Carreb344c72019-01-07 18:35:30 -0800416 assignNativeObject(nativeCopyFromSurfaceControl(other.mNativeObject));
chaviwbeb7a0c2018-12-05 13:49:54 -0800417 }
418
Robert Carr132c9f52017-07-31 17:02:30 -0700419 /**
Evan Rosky485df202018-12-06 14:11:12 -0800420 * owner UID.
421 * @hide
422 */
423 public static final int METADATA_OWNER_UID = 1;
424
425 /**
426 * Window type as per {@link WindowManager.LayoutParams}.
427 * @hide
428 */
429 public static final int METADATA_WINDOW_TYPE = 2;
430
431 /**
Evan Rosky9020c072018-12-06 14:11:12 -0800432 * Task id to allow association between surfaces and task.
433 * @hide
434 */
435 public static final int METADATA_TASK_ID = 3;
436
437 /**
Robert Carre625fcf2017-09-01 12:36:28 -0700438 * Builder class for {@link SurfaceControl} objects.
439 */
440 public static class Builder {
441 private SurfaceSession mSession;
442 private int mFlags = HIDDEN;
443 private int mWidth;
444 private int mHeight;
445 private int mFormat = PixelFormat.OPAQUE;
446 private String mName;
447 private SurfaceControl mParent;
Evan Rosky485df202018-12-06 14:11:12 -0800448 private SparseIntArray mMetadata;
Robert Carre625fcf2017-09-01 12:36:28 -0700449
450 /**
451 * Begin building a SurfaceControl with a given {@link SurfaceSession}.
452 *
453 * @param session The {@link SurfaceSession} with which to eventually construct the surface.
Robert Carra7827f72019-01-11 12:53:37 -0800454 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700455 */
456 public Builder(SurfaceSession session) {
457 mSession = session;
458 }
459
460 /**
Robert Carr76907ee2019-01-11 13:38:19 -0800461 * Begin building a SurfaceControl.
462 */
463 public Builder() {
464 }
465
466 /**
467 * Construct a new {@link SurfaceControl} with the set parameters. The builder
468 * remains valid.
Robert Carre625fcf2017-09-01 12:36:28 -0700469 */
470 public SurfaceControl build() {
Vishnu Naire86bd982018-11-28 13:23:17 -0800471 if (mWidth < 0 || mHeight < 0) {
Robert Carre625fcf2017-09-01 12:36:28 -0700472 throw new IllegalArgumentException(
Vishnu Naire86bd982018-11-28 13:23:17 -0800473 "width and height must be positive or unset");
474 }
475 if ((mWidth > 0 || mHeight > 0) && (isColorLayerSet() || isContainerLayerSet())) {
476 throw new IllegalArgumentException(
477 "Only buffer layers can set a valid buffer size.");
Robert Carre625fcf2017-09-01 12:36:28 -0700478 }
Evan Rosky485df202018-12-06 14:11:12 -0800479 return new SurfaceControl(
480 mSession, mName, mWidth, mHeight, mFormat, mFlags, mParent, mMetadata);
Robert Carre625fcf2017-09-01 12:36:28 -0700481 }
482
483 /**
484 * Set a debugging-name for the SurfaceControl.
485 *
486 * @param name A name to identify the Surface in debugging.
487 */
488 public Builder setName(String name) {
489 mName = name;
490 return this;
491 }
492
493 /**
494 * Set the initial size of the controlled surface's buffers in pixels.
495 *
496 * @param width The buffer width in pixels.
497 * @param height The buffer height in pixels.
498 */
Robert Carr76907ee2019-01-11 13:38:19 -0800499 public Builder setBufferSize(@IntRange(from = 0) int width,
500 @IntRange(from = 0) int height) {
Vishnu Naire86bd982018-11-28 13:23:17 -0800501 if (width < 0 || height < 0) {
Robert Carre625fcf2017-09-01 12:36:28 -0700502 throw new IllegalArgumentException(
503 "width and height must be positive");
504 }
505 mWidth = width;
506 mHeight = height;
Jorim Jaggif6ef1832019-01-31 14:42:44 +0100507 return this;
Robert Carre625fcf2017-09-01 12:36:28 -0700508 }
509
510 /**
511 * Set the pixel format of the controlled surface's buffers, using constants from
512 * {@link android.graphics.PixelFormat}.
513 */
Robert Carr76907ee2019-01-11 13:38:19 -0800514 @NonNull
Robert Carre625fcf2017-09-01 12:36:28 -0700515 public Builder setFormat(@PixelFormat.Format int format) {
516 mFormat = format;
517 return this;
518 }
519
520 /**
521 * Specify if the app requires a hardware-protected path to
522 * an external display sync. If protected content is enabled, but
523 * such a path is not available, then the controlled Surface will
524 * not be displayed.
525 *
526 * @param protectedContent Whether to require a protected sink.
Robert Carra7827f72019-01-11 12:53:37 -0800527 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700528 */
Robert Carr76907ee2019-01-11 13:38:19 -0800529 @NonNull
Robert Carre625fcf2017-09-01 12:36:28 -0700530 public Builder setProtected(boolean protectedContent) {
531 if (protectedContent) {
532 mFlags |= PROTECTED_APP;
533 } else {
534 mFlags &= ~PROTECTED_APP;
535 }
536 return this;
537 }
538
539 /**
540 * Specify whether the Surface contains secure content. If true, the system
541 * will prevent the surfaces content from being copied by another process. In
542 * particular screenshots and VNC servers will be disabled. This is however
543 * not a complete prevention of readback as {@link #setProtected}.
Robert Carra7827f72019-01-11 12:53:37 -0800544 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700545 */
Robert Carr76907ee2019-01-11 13:38:19 -0800546 @NonNull
Robert Carre625fcf2017-09-01 12:36:28 -0700547 public Builder setSecure(boolean secure) {
548 if (secure) {
549 mFlags |= SECURE;
550 } else {
551 mFlags &= ~SECURE;
552 }
553 return this;
554 }
555
556 /**
557 * Indicates whether the surface must be considered opaque,
558 * even if its pixel format is set to translucent. This can be useful if an
559 * application needs full RGBA 8888 support for instance but will
560 * still draw every pixel opaque.
561 * <p>
562 * This flag only determines whether opacity will be sampled from the alpha channel.
563 * Plane-alpha from calls to setAlpha() can still result in blended composition
564 * regardless of the opaque setting.
565 *
566 * Combined effects are (assuming a buffer format with an alpha channel):
567 * <ul>
568 * <li>OPAQUE + alpha(1.0) == opaque composition
569 * <li>OPAQUE + alpha(0.x) == blended composition
570 * <li>OPAQUE + alpha(0.0) == no composition
571 * <li>!OPAQUE + alpha(1.0) == blended composition
572 * <li>!OPAQUE + alpha(0.x) == blended composition
573 * <li>!OPAQUE + alpha(0.0) == no composition
574 * </ul>
575 * If the underlying buffer lacks an alpha channel, it is as if setOpaque(true)
576 * were set automatically.
577 * @param opaque Whether the Surface is OPAQUE.
578 */
Robert Carr76907ee2019-01-11 13:38:19 -0800579 @NonNull
Robert Carre625fcf2017-09-01 12:36:28 -0700580 public Builder setOpaque(boolean opaque) {
581 if (opaque) {
582 mFlags |= OPAQUE;
583 } else {
584 mFlags &= ~OPAQUE;
585 }
586 return this;
587 }
588
589 /**
590 * Set a parent surface for our new SurfaceControl.
591 *
592 * Child surfaces are constrained to the onscreen region of their parent.
593 * Furthermore they stack relatively in Z order, and inherit the transformation
594 * of the parent.
595 *
596 * @param parent The parent control.
597 */
Robert Carr76907ee2019-01-11 13:38:19 -0800598 @NonNull
599 public Builder setParent(@Nullable SurfaceControl parent) {
Robert Carre625fcf2017-09-01 12:36:28 -0700600 mParent = parent;
601 return this;
602 }
603
604 /**
Evan Rosky485df202018-12-06 14:11:12 -0800605 * Sets a metadata int.
Robert Carre625fcf2017-09-01 12:36:28 -0700606 *
Evan Rosky485df202018-12-06 14:11:12 -0800607 * @param key metadata key
608 * @param data associated data
Robert Carra7827f72019-01-11 12:53:37 -0800609 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700610 */
Evan Rosky485df202018-12-06 14:11:12 -0800611 public Builder setMetadata(int key, int data) {
612 if (mMetadata == null) {
613 mMetadata = new SparseIntArray();
Robert Carre625fcf2017-09-01 12:36:28 -0700614 }
Evan Rosky485df202018-12-06 14:11:12 -0800615 mMetadata.put(key, data);
Robert Carre625fcf2017-09-01 12:36:28 -0700616 return this;
617 }
618
619 /**
620 * Indicate whether a 'ColorLayer' is to be constructed.
621 *
622 * Color layers will not have an associated BufferQueue and will instead always render a
623 * solid color (that is, solid before plane alpha). Currently that color is black.
624 *
Jorim Jaggif6ef1832019-01-31 14:42:44 +0100625 * @param isColorLayer Whether to create a color layer.
Robert Carra7827f72019-01-11 12:53:37 -0800626 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700627 */
Jorim Jaggif6ef1832019-01-31 14:42:44 +0100628 public Builder setColorLayer(boolean isColorLayer) {
629 if (isColorLayer) {
630 mFlags |= FX_SURFACE_DIM;
631 } else {
632 mFlags &= ~FX_SURFACE_DIM;
633 }
634 return this;
Robert Carre625fcf2017-09-01 12:36:28 -0700635 }
636
Vishnu Naire86bd982018-11-28 13:23:17 -0800637 private boolean isColorLayerSet() {
638 return (mFlags & FX_SURFACE_DIM) == FX_SURFACE_DIM;
639 }
640
Robert Carre625fcf2017-09-01 12:36:28 -0700641 /**
Robert Carrb6cd6432018-08-13 13:01:47 -0700642 * Indicates whether a 'ContainerLayer' is to be constructed.
643 *
644 * Container layers will not be rendered in any fashion and instead are used
645 * as a parent of renderable layers.
646 *
Jorim Jaggif6ef1832019-01-31 14:42:44 +0100647 * @param isContainerLayer Whether to create a container layer.
Robert Carra7827f72019-01-11 12:53:37 -0800648 * @hide
Robert Carrb6cd6432018-08-13 13:01:47 -0700649 */
Jorim Jaggif6ef1832019-01-31 14:42:44 +0100650 public Builder setContainerLayer(boolean isContainerLayer) {
651 if (isContainerLayer) {
652 mFlags |= FX_SURFACE_CONTAINER;
653 } else {
654 mFlags &= ~FX_SURFACE_CONTAINER;
655 }
656 return this;
Robert Carrb6cd6432018-08-13 13:01:47 -0700657 }
658
Vishnu Naire86bd982018-11-28 13:23:17 -0800659 private boolean isContainerLayerSet() {
660 return (mFlags & FX_SURFACE_CONTAINER) == FX_SURFACE_CONTAINER;
661 }
662
Robert Carrb6cd6432018-08-13 13:01:47 -0700663 /**
Jorim Jaggif6ef1832019-01-31 14:42:44 +0100664 * Set 'Surface creation flags' such as {@link HIDDEN}, {@link SECURE}.
Robert Carre625fcf2017-09-01 12:36:28 -0700665 *
666 * TODO: Finish conversion to individual builder methods?
667 * @param flags The combined flags
Robert Carra7827f72019-01-11 12:53:37 -0800668 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700669 */
670 public Builder setFlags(int flags) {
671 mFlags = flags;
672 return this;
673 }
674 }
675
676 /**
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800677 * Create a surface with a name.
Andy McFadden314405b2014-01-29 17:18:05 -0800678 * <p>
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800679 * The surface creation flags specify what kind of surface to create and
680 * certain options such as whether the surface can be assumed to be opaque
681 * and whether it should be initially hidden. Surfaces should always be
682 * created with the {@link #HIDDEN} flag set to ensure that they are not
683 * made visible prematurely before all of the surface's properties have been
684 * configured.
Andy McFadden314405b2014-01-29 17:18:05 -0800685 * <p>
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800686 * Good practice is to first create the surface with the {@link #HIDDEN} flag
687 * specified, open a transaction, set the surface layer, layer stack, alpha,
688 * and position, call {@link #show} if appropriate, and close the transaction.
Vishnu Naird454442d2018-11-13 13:51:01 -0800689 * <p>
690 * Bounds of the surface is determined by its crop and its buffer size. If the
691 * surface has no buffer or crop, the surface is boundless and only constrained
692 * by the size of its parent bounds.
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800693 *
694 * @param session The surface session, must not be null.
695 * @param name The surface name, must not be null.
696 * @param w The surface initial width.
697 * @param h The surface initial height.
698 * @param flags The surface creation flags. Should always include {@link #HIDDEN}
699 * in the creation flags.
Evan Rosky485df202018-12-06 14:11:12 -0800700 * @param metadata Initial metadata.
Igor Murashkina86ab6402013-08-30 12:58:36 -0700701 *
702 * @throws throws OutOfResourcesException If the SurfaceControl cannot be created.
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800703 */
Robert Carre625fcf2017-09-01 12:36:28 -0700704 private SurfaceControl(SurfaceSession session, String name, int w, int h, int format, int flags,
Evan Rosky485df202018-12-06 14:11:12 -0800705 SurfaceControl parent, SparseIntArray metadata)
Robert Carrb0f39362018-03-14 13:52:25 -0700706 throws OutOfResourcesException, IllegalArgumentException {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800707 if (name == null) {
708 throw new IllegalArgumentException("name must not be null");
709 }
710
711 if ((flags & SurfaceControl.HIDDEN) == 0) {
712 Log.w(TAG, "Surfaces should always be created with the HIDDEN flag set "
713 + "to ensure that they are not made visible prematurely before "
714 + "all of the surface's properties have been configured. "
715 + "Set the other properties and make the surface visible within "
716 + "a transaction. New surface name: " + name,
717 new Throwable());
718 }
719
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800720 mName = name;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100721 mWidth = w;
722 mHeight = h;
Evan Rosky485df202018-12-06 14:11:12 -0800723 Parcel metaParcel = Parcel.obtain();
724 try {
725 if (metadata != null && metadata.size() > 0) {
726 metaParcel.writeInt(metadata.size());
727 for (int i = 0; i < metadata.size(); ++i) {
728 metaParcel.writeInt(metadata.keyAt(i));
729 metaParcel.writeByteArray(
730 ByteBuffer.allocate(4).putInt(metadata.valueAt(i)).array());
731 }
732 }
733 mNativeObject = nativeCreate(session, name, w, h, format, flags,
734 parent != null ? parent.mNativeObject : 0, metaParcel);
735 } finally {
736 metaParcel.recycle();
737 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800738 if (mNativeObject == 0) {
739 throw new OutOfResourcesException(
740 "Couldn't allocate SurfaceControl native object");
741 }
Jesse Hall6a6bc212013-08-08 12:15:03 -0700742
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800743 mCloseGuard.open("release");
744 }
Jesse Hall6a6bc212013-08-08 12:15:03 -0700745
Robert Carra7827f72019-01-11 12:53:37 -0800746 /** This is a transfer constructor, useful for transferring a live SurfaceControl native
747 * object to another Java wrapper which could have some different behavior, e.g.
748 * event logging.
749 * @hide
750 */
Robert Carr3b716242016-08-16 16:02:21 -0700751 public SurfaceControl(SurfaceControl other) {
752 mName = other.mName;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100753 mWidth = other.mWidth;
754 mHeight = other.mHeight;
Robert Carr3b716242016-08-16 16:02:21 -0700755 mNativeObject = other.mNativeObject;
756 other.mCloseGuard.close();
757 other.mNativeObject = 0;
758 mCloseGuard.open("release");
759 }
760
Jorim Jaggi06975df2017-12-01 14:52:13 +0100761 private SurfaceControl(Parcel in) {
chaviwbeb7a0c2018-12-05 13:49:54 -0800762 readFromParcel(in);
763 mCloseGuard.open("release");
764 }
765
Robert Carra7827f72019-01-11 12:53:37 -0800766 /**
767 * @hide
768 */
chaviwbeb7a0c2018-12-05 13:49:54 -0800769 public SurfaceControl() {
770 mCloseGuard.open("release");
771 }
772
773 public void readFromParcel(Parcel in) {
774 if (in == null) {
775 throw new IllegalArgumentException("source must not be null");
776 }
777
Jorim Jaggi06975df2017-12-01 14:52:13 +0100778 mName = in.readString();
Jorim Jaggia5e10572017-11-15 14:36:26 +0100779 mWidth = in.readInt();
780 mHeight = in.readInt();
Robert Carr5fea55b2018-12-10 13:05:52 -0800781
Robert Carreb344c72019-01-07 18:35:30 -0800782 long object = 0;
Robert Carr5fea55b2018-12-10 13:05:52 -0800783 if (in.readInt() != 0) {
Robert Carreb344c72019-01-07 18:35:30 -0800784 object = nativeReadFromParcel(in);
Jorim Jaggi06975df2017-12-01 14:52:13 +0100785 }
Robert Carreb344c72019-01-07 18:35:30 -0800786 assignNativeObject(object);
Jorim Jaggi06975df2017-12-01 14:52:13 +0100787 }
788
789 @Override
790 public int describeContents() {
791 return 0;
792 }
793
794 @Override
795 public void writeToParcel(Parcel dest, int flags) {
796 dest.writeString(mName);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100797 dest.writeInt(mWidth);
798 dest.writeInt(mHeight);
Robert Carr5fea55b2018-12-10 13:05:52 -0800799 if (mNativeObject == 0) {
800 dest.writeInt(0);
801 } else {
802 dest.writeInt(1);
803 }
Jorim Jaggi06975df2017-12-01 14:52:13 +0100804 nativeWriteToParcel(mNativeObject, dest);
Robert Carr5fea55b2018-12-10 13:05:52 -0800805
806 if ((flags & Parcelable.PARCELABLE_WRITE_RETURN_VALUE) != 0) {
807 release();
808 }
Jorim Jaggi06975df2017-12-01 14:52:13 +0100809 }
810
Vishnu Nair04ab4392018-01-10 11:00:06 -0800811 /**
812 * Write to a protocol buffer output stream. Protocol buffer message definition is at {@link
813 * android.view.SurfaceControlProto}.
814 *
815 * @param proto Stream to write the SurfaceControl object to.
816 * @param fieldId Field Id of the SurfaceControl as defined in the parent message.
817 * @hide
818 */
819 public void writeToProto(ProtoOutputStream proto, long fieldId) {
820 final long token = proto.start(fieldId);
821 proto.write(HASH_CODE, System.identityHashCode(this));
822 proto.write(NAME, mName);
823 proto.end(token);
824 }
825
Jorim Jaggi06975df2017-12-01 14:52:13 +0100826 public static final Creator<SurfaceControl> CREATOR
827 = new Creator<SurfaceControl>() {
828 public SurfaceControl createFromParcel(Parcel in) {
829 return new SurfaceControl(in);
830 }
831
832 public SurfaceControl[] newArray(int size) {
833 return new SurfaceControl[size];
834 }
835 };
836
Robert Carra7827f72019-01-11 12:53:37 -0800837 /**
838 * @hide
839 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800840 @Override
841 protected void finalize() throws Throwable {
842 try {
843 if (mCloseGuard != null) {
844 mCloseGuard.warnIfOpen();
845 }
846 if (mNativeObject != 0) {
847 nativeRelease(mNativeObject);
848 }
849 } finally {
850 super.finalize();
851 }
852 }
853
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800854 /**
Robert Carr76907ee2019-01-11 13:38:19 -0800855 * Release the local reference to the server-side surface. The surface
856 * may continue to exist on-screen as long as its parent continues
857 * to exist. To explicitly remove a surface from the screen use
858 * {@link Transaction#reparent} with a null-parent.
859 *
860 * Always call release() when you're done with a SurfaceControl.
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800861 */
862 public void release() {
863 if (mNativeObject != 0) {
864 nativeRelease(mNativeObject);
865 mNativeObject = 0;
866 }
867 mCloseGuard.close();
868 }
869
870 /**
871 * Free all server-side state associated with this surface and
872 * release this object's reference. This method can only be
873 * called from the process that created the service.
Robert Carra7827f72019-01-11 12:53:37 -0800874 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800875 */
876 public void destroy() {
877 if (mNativeObject != 0) {
878 nativeDestroy(mNativeObject);
879 mNativeObject = 0;
880 }
881 mCloseGuard.close();
882 }
883
Chong Zhang47e36a32016-02-29 16:44:33 -0800884 /**
885 * Disconnect any client still connected to the surface.
Robert Carra7827f72019-01-11 12:53:37 -0800886 * @hide
Chong Zhang47e36a32016-02-29 16:44:33 -0800887 */
888 public void disconnect() {
889 if (mNativeObject != 0) {
890 nativeDisconnect(mNativeObject);
891 }
892 }
893
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800894 private void checkNotReleased() {
895 if (mNativeObject == 0) throw new NullPointerException(
896 "mNativeObject is null. Have you called release() already?");
897 }
Jesse Hall6a6bc212013-08-08 12:15:03 -0700898
Robert Carra7827f72019-01-11 12:53:37 -0800899 /**
Robert Carr76907ee2019-01-11 13:38:19 -0800900 * Check whether this instance points to a valid layer with the system-compositor. For
901 * example this may be false if construction failed, or the layer was released.
902 *
903 * @return Whether this SurfaceControl is valid.
Robert Carra7827f72019-01-11 12:53:37 -0800904 */
Robert Carr5fea55b2018-12-10 13:05:52 -0800905 public boolean isValid() {
906 return mNativeObject != 0;
907 }
908
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800909 /*
910 * set surface parameters.
911 * needs to be inside open/closeTransaction block
912 */
913
Robert Carra7827f72019-01-11 12:53:37 -0800914 /** start a transaction
915 * @hide
916 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100917 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800918 public static void openTransaction() {
Robert Carre13b58e2017-08-31 14:50:44 -0700919 synchronized (SurfaceControl.class) {
920 if (sGlobalTransaction == null) {
921 sGlobalTransaction = new Transaction();
922 }
923 synchronized(SurfaceControl.class) {
924 sTransactionNestCount++;
925 }
926 }
927 }
928
929 private static void closeTransaction(boolean sync) {
930 synchronized(SurfaceControl.class) {
931 if (sTransactionNestCount == 0) {
932 Log.e(TAG, "Call to SurfaceControl.closeTransaction without matching openTransaction");
933 } else if (--sTransactionNestCount > 0) {
934 return;
935 }
936 sGlobalTransaction.apply(sync);
937 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800938 }
939
Robert Carrb1579c82017-09-05 14:54:47 -0700940 /**
941 * Merge the supplied transaction in to the deprecated "global" transaction.
942 * This clears the supplied transaction in an identical fashion to {@link Transaction#merge}.
943 * <p>
944 * This is a utility for interop with legacy-code and will go away with the Global Transaction.
Robert Carra7827f72019-01-11 12:53:37 -0800945 * @hide
Robert Carrb1579c82017-09-05 14:54:47 -0700946 */
947 @Deprecated
948 public static void mergeToGlobalTransaction(Transaction t) {
Robert Carrc5fc4612017-12-05 11:55:40 -0800949 synchronized(SurfaceControl.class) {
Robert Carrb1579c82017-09-05 14:54:47 -0700950 sGlobalTransaction.merge(t);
951 }
952 }
953
Robert Carra7827f72019-01-11 12:53:37 -0800954 /** end a transaction
955 * @hide
956 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100957 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800958 public static void closeTransaction() {
Robert Carre13b58e2017-08-31 14:50:44 -0700959 closeTransaction(false);
Robert Carre9953b12016-05-23 20:52:04 -0700960 }
961
Robert Carra7827f72019-01-11 12:53:37 -0800962 /**
963 * @hide
964 */
Robert Carre9953b12016-05-23 20:52:04 -0700965 public static void closeTransactionSync() {
Robert Carre13b58e2017-08-31 14:50:44 -0700966 closeTransaction(true);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800967 }
968
Robert Carra7827f72019-01-11 12:53:37 -0800969 /**
970 * @hide
971 */
Rob Carr64e516f2015-10-29 00:20:45 +0000972 public void deferTransactionUntil(IBinder handle, long frame) {
Robert Carr024378c2018-02-27 11:21:05 -0800973 synchronized(SurfaceControl.class) {
974 sGlobalTransaction.deferTransactionUntil(this, handle, frame);
Robert Carrd5c7dd62017-03-08 10:39:30 -0800975 }
976 }
977
Robert Carra7827f72019-01-11 12:53:37 -0800978 /**
979 * @hide
980 */
Robert Carrd5c7dd62017-03-08 10:39:30 -0800981 public void deferTransactionUntil(Surface barrier, long frame) {
Robert Carr024378c2018-02-27 11:21:05 -0800982 synchronized(SurfaceControl.class) {
983 sGlobalTransaction.deferTransactionUntilSurface(this, barrier, frame);
Robert Carrd5c7dd62017-03-08 10:39:30 -0800984 }
985 }
986
Robert Carra7827f72019-01-11 12:53:37 -0800987 /**
988 * @hide
989 */
Robert Carrd5c7dd62017-03-08 10:39:30 -0800990 public void reparentChildren(IBinder newParentHandle) {
Robert Carre13b58e2017-08-31 14:50:44 -0700991 synchronized(SurfaceControl.class) {
992 sGlobalTransaction.reparentChildren(this, newParentHandle);
993 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800994 }
995
Robert Carra7827f72019-01-11 12:53:37 -0800996 /**
997 * @hide
998 */
Robert Carr10584fa2019-01-14 15:55:19 -0800999 public void reparent(SurfaceControl newParent) {
Robert Carre13b58e2017-08-31 14:50:44 -07001000 synchronized(SurfaceControl.class) {
Robert Carr10584fa2019-01-14 15:55:19 -08001001 sGlobalTransaction.reparent(this, newParent);
Robert Carre13b58e2017-08-31 14:50:44 -07001002 }
chaviw63542382017-08-17 17:39:29 -07001003 }
1004
Robert Carra7827f72019-01-11 12:53:37 -08001005 /**
1006 * @hide
1007 */
Robert Carrd5c7dd62017-03-08 10:39:30 -08001008 public void detachChildren() {
Robert Carre13b58e2017-08-31 14:50:44 -07001009 synchronized(SurfaceControl.class) {
1010 sGlobalTransaction.detachChildren(this);
1011 }
Rob Carr64e516f2015-10-29 00:20:45 +00001012 }
1013
Robert Carra7827f72019-01-11 12:53:37 -08001014 /**
1015 * @hide
1016 */
Robert Carr1ca6a332016-04-11 18:00:43 -07001017 public void setOverrideScalingMode(int scalingMode) {
1018 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001019 synchronized(SurfaceControl.class) {
1020 sGlobalTransaction.setOverrideScalingMode(this, scalingMode);
1021 }
Robert Carr1ca6a332016-04-11 18:00:43 -07001022 }
1023
Robert Carra7827f72019-01-11 12:53:37 -08001024 /**
1025 * @hide
1026 */
Rob Carr64e516f2015-10-29 00:20:45 +00001027 public IBinder getHandle() {
1028 return nativeGetHandle(mNativeObject);
1029 }
1030
Robert Carra7827f72019-01-11 12:53:37 -08001031 /**
1032 * @hide
1033 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001034 public static void setAnimationTransaction() {
Robert Carre13b58e2017-08-31 14:50:44 -07001035 synchronized (SurfaceControl.class) {
1036 sGlobalTransaction.setAnimationTransaction();
1037 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001038 }
1039
Robert Carra7827f72019-01-11 12:53:37 -08001040 /**
1041 * @hide
1042 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001043 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001044 public void setLayer(int zorder) {
1045 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001046 synchronized(SurfaceControl.class) {
1047 sGlobalTransaction.setLayer(this, zorder);
1048 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001049 }
1050
Robert Carra7827f72019-01-11 12:53:37 -08001051 /**
1052 * @hide
1053 */
Robert Carr77e34942017-10-18 19:13:56 -07001054 public void setRelativeLayer(SurfaceControl relativeTo, int zorder) {
Robert Carraf422a82017-04-10 18:34:33 -07001055 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001056 synchronized(SurfaceControl.class) {
1057 sGlobalTransaction.setRelativeLayer(this, relativeTo, zorder);
1058 }
Robert Carraf422a82017-04-10 18:34:33 -07001059 }
1060
Robert Carra7827f72019-01-11 12:53:37 -08001061 /**
1062 * @hide
1063 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001064 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001065 public void setPosition(float x, float y) {
1066 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001067 synchronized(SurfaceControl.class) {
1068 sGlobalTransaction.setPosition(this, x, y);
1069 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001070 }
1071
Robert Carra7827f72019-01-11 12:53:37 -08001072 /**
1073 * @hide
1074 */
Robert Carr6da3cc02016-06-16 15:17:07 -07001075 public void setGeometryAppliesWithResize() {
Robert Carra9408d42016-06-03 13:28:48 -07001076 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001077 synchronized(SurfaceControl.class) {
1078 sGlobalTransaction.setGeometryAppliesWithResize(this);
1079 }
Robert Carra9408d42016-06-03 13:28:48 -07001080 }
1081
Robert Carra7827f72019-01-11 12:53:37 -08001082 /**
1083 * @hide
1084 */
Vishnu Naire86bd982018-11-28 13:23:17 -08001085 public void setBufferSize(int w, int h) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001086 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001087 synchronized(SurfaceControl.class) {
Vishnu Naire86bd982018-11-28 13:23:17 -08001088 sGlobalTransaction.setBufferSize(this, w, h);
Robert Carre13b58e2017-08-31 14:50:44 -07001089 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001090 }
1091
Robert Carra7827f72019-01-11 12:53:37 -08001092 /**
1093 * @hide
1094 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001095 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001096 public void hide() {
1097 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001098 synchronized(SurfaceControl.class) {
1099 sGlobalTransaction.hide(this);
1100 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001101 }
1102
Robert Carra7827f72019-01-11 12:53:37 -08001103 /**
1104 * @hide
1105 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001106 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001107 public void show() {
1108 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001109 synchronized(SurfaceControl.class) {
1110 sGlobalTransaction.show(this);
1111 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001112 }
1113
Robert Carra7827f72019-01-11 12:53:37 -08001114 /**
1115 * @hide
1116 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001117 public void setTransparentRegionHint(Region region) {
1118 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001119 synchronized(SurfaceControl.class) {
1120 sGlobalTransaction.setTransparentRegionHint(this, region);
1121 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001122 }
1123
Robert Carra7827f72019-01-11 12:53:37 -08001124 /**
1125 * @hide
1126 */
Svetoslav1376d602014-03-13 11:17:26 -07001127 public boolean clearContentFrameStats() {
1128 checkNotReleased();
1129 return nativeClearContentFrameStats(mNativeObject);
1130 }
1131
Robert Carra7827f72019-01-11 12:53:37 -08001132 /**
1133 * @hide
1134 */
Svetoslav1376d602014-03-13 11:17:26 -07001135 public boolean getContentFrameStats(WindowContentFrameStats outStats) {
1136 checkNotReleased();
1137 return nativeGetContentFrameStats(mNativeObject, outStats);
1138 }
1139
Robert Carra7827f72019-01-11 12:53:37 -08001140 /**
1141 * @hide
1142 */
Svetoslav1376d602014-03-13 11:17:26 -07001143 public static boolean clearAnimationFrameStats() {
1144 return nativeClearAnimationFrameStats();
1145 }
1146
Robert Carra7827f72019-01-11 12:53:37 -08001147 /**
1148 * @hide
1149 */
Svetoslav1376d602014-03-13 11:17:26 -07001150 public static boolean getAnimationFrameStats(WindowAnimationFrameStats outStats) {
1151 return nativeGetAnimationFrameStats(outStats);
1152 }
1153
Robert Carra7827f72019-01-11 12:53:37 -08001154 /**
1155 * @hide
1156 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001157 public void setAlpha(float alpha) {
1158 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001159 synchronized(SurfaceControl.class) {
1160 sGlobalTransaction.setAlpha(this, alpha);
1161 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001162 }
1163
Robert Carra7827f72019-01-11 12:53:37 -08001164 /**
1165 * @hide
1166 */
chaviw0dd03f52017-08-25 12:15:26 -07001167 public void setColor(@Size(3) float[] color) {
1168 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001169 synchronized (SurfaceControl.class) {
1170 sGlobalTransaction.setColor(this, color);
1171 }
chaviw0dd03f52017-08-25 12:15:26 -07001172 }
1173
Robert Carra7827f72019-01-11 12:53:37 -08001174 /**
1175 * @hide
1176 */
Robert Carr0edf18f2017-02-21 20:01:47 -08001177 public void setMatrix(float dsdx, float dtdx, float dtdy, float dsdy) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001178 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001179 synchronized(SurfaceControl.class) {
1180 sGlobalTransaction.setMatrix(this, dsdx, dtdx, dtdy, dsdy);
1181 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001182 }
1183
Jorim Jaggi21c39a72017-10-20 15:47:51 +02001184 /**
1185 * Sets the transform and position of a {@link SurfaceControl} from a 3x3 transformation matrix.
1186 *
1187 * @param matrix The matrix to apply.
1188 * @param float9 An array of 9 floats to be used to extract the values from the matrix.
Robert Carra7827f72019-01-11 12:53:37 -08001189 * @hide
Jorim Jaggi21c39a72017-10-20 15:47:51 +02001190 */
1191 public void setMatrix(Matrix matrix, float[] float9) {
1192 checkNotReleased();
1193 matrix.getValues(float9);
1194 synchronized (SurfaceControl.class) {
1195 sGlobalTransaction.setMatrix(this, float9[MSCALE_X], float9[MSKEW_Y],
1196 float9[MSKEW_X], float9[MSCALE_Y]);
1197 sGlobalTransaction.setPosition(this, float9[MTRANS_X], float9[MTRANS_Y]);
1198 }
1199 }
1200
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001201 /**
1202 * Sets the color transform for the Surface.
1203 * @param matrix A float array with 9 values represents a 3x3 transform matrix
1204 * @param translation A float array with 3 values represents a translation vector
Robert Carra7827f72019-01-11 12:53:37 -08001205 * @hide
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001206 */
1207 public void setColorTransform(@Size(9) float[] matrix, @Size(3) float[] translation) {
1208 checkNotReleased();
1209 synchronized (SurfaceControl.class) {
1210 sGlobalTransaction.setColorTransform(this, matrix, translation);
1211 }
1212 }
1213
Vishnu Naird454442d2018-11-13 13:51:01 -08001214 /**
1215 * Bounds the surface and its children to the bounds specified. Size of the surface will be
1216 * ignored and only the crop and buffer size will be used to determine the bounds of the
1217 * surface. If no crop is specified and the surface has no buffer, the surface bounds is only
1218 * constrained by the size of its parent bounds.
1219 *
1220 * @param crop Bounds of the crop to apply.
Robert Carra7827f72019-01-11 12:53:37 -08001221 * @hide
Vishnu Naird454442d2018-11-13 13:51:01 -08001222 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001223 public void setWindowCrop(Rect crop) {
1224 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001225 synchronized (SurfaceControl.class) {
1226 sGlobalTransaction.setWindowCrop(this, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001227 }
1228 }
1229
Vishnu Naird454442d2018-11-13 13:51:01 -08001230 /**
1231 * Same as {@link SurfaceControl#setWindowCrop(Rect)} but sets the crop rect top left at 0, 0.
1232 *
1233 * @param width width of crop rect
1234 * @param height height of crop rect
Robert Carra7827f72019-01-11 12:53:37 -08001235 * @hide
Vishnu Naird454442d2018-11-13 13:51:01 -08001236 */
1237 public void setWindowCrop(int width, int height) {
1238 checkNotReleased();
1239 synchronized (SurfaceControl.class) {
1240 sGlobalTransaction.setWindowCrop(this, width, height);
1241 }
1242 }
1243
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001244 /**
1245 * Sets the corner radius of a {@link SurfaceControl}.
1246 *
1247 * @param cornerRadius Corner radius in pixels.
Robert Carra7827f72019-01-11 12:53:37 -08001248 * @hide
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001249 */
1250 public void setCornerRadius(float cornerRadius) {
1251 checkNotReleased();
1252 synchronized (SurfaceControl.class) {
1253 sGlobalTransaction.setCornerRadius(this, cornerRadius);
1254 }
1255 }
1256
Robert Carra7827f72019-01-11 12:53:37 -08001257 /**
1258 * @hide
1259 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001260 public void setLayerStack(int layerStack) {
1261 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001262 synchronized(SurfaceControl.class) {
1263 sGlobalTransaction.setLayerStack(this, layerStack);
1264 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001265 }
1266
Robert Carra7827f72019-01-11 12:53:37 -08001267 /**
1268 * @hide
1269 */
Andy McFadden314405b2014-01-29 17:18:05 -08001270 public void setOpaque(boolean isOpaque) {
1271 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001272
1273 synchronized (SurfaceControl.class) {
1274 sGlobalTransaction.setOpaque(this, isOpaque);
Andy McFadden314405b2014-01-29 17:18:05 -08001275 }
1276 }
1277
Robert Carra7827f72019-01-11 12:53:37 -08001278 /**
1279 * @hide
1280 */
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001281 public void setSecure(boolean isSecure) {
1282 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001283
1284 synchronized (SurfaceControl.class) {
1285 sGlobalTransaction.setSecure(this, isSecure);
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001286 }
1287 }
1288
Robert Carra7827f72019-01-11 12:53:37 -08001289 /**
1290 * @hide
1291 */
Jorim Jaggia5e10572017-11-15 14:36:26 +01001292 public int getWidth() {
1293 synchronized (mSizeLock) {
1294 return mWidth;
1295 }
1296 }
1297
Robert Carra7827f72019-01-11 12:53:37 -08001298 /**
1299 * @hide
1300 */
Jorim Jaggia5e10572017-11-15 14:36:26 +01001301 public int getHeight() {
1302 synchronized (mSizeLock) {
1303 return mHeight;
1304 }
1305 }
1306
Robert Carre13b58e2017-08-31 14:50:44 -07001307 @Override
1308 public String toString() {
1309 return "Surface(name=" + mName + ")/@0x" +
1310 Integer.toHexString(System.identityHashCode(this));
1311 }
1312
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001313 /*
1314 * set display parameters.
1315 * needs to be inside open/closeTransaction block
1316 */
1317
1318 /**
1319 * Describes the properties of a physical display known to surface flinger.
Robert Carr76907ee2019-01-11 13:38:19 -08001320 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001321 */
1322 public static final class PhysicalDisplayInfo {
Robert Carra7827f72019-01-11 12:53:37 -08001323 /**
1324 * @hide
1325 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001326 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001327 public int width;
Robert Carra7827f72019-01-11 12:53:37 -08001328
1329 /**
1330 * @hide
1331 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001332 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001333 public int height;
Robert Carra7827f72019-01-11 12:53:37 -08001334
1335 /**
1336 * @hide
1337 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001338 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001339 public float refreshRate;
Robert Carra7827f72019-01-11 12:53:37 -08001340
1341 /**
1342 * @hide
1343 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001344 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001345 public float density;
Robert Carra7827f72019-01-11 12:53:37 -08001346
1347 /**
1348 * @hide
1349 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001350 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001351 public float xDpi;
Robert Carra7827f72019-01-11 12:53:37 -08001352
1353 /**
1354 * @hide
1355 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001356 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001357 public float yDpi;
Robert Carra7827f72019-01-11 12:53:37 -08001358
1359 /**
1360 * @hide
1361 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001362 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001363 public boolean secure;
Robert Carra7827f72019-01-11 12:53:37 -08001364
1365 /**
1366 * @hide
1367 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001368 @UnsupportedAppUsage
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001369 public long appVsyncOffsetNanos;
Robert Carra7827f72019-01-11 12:53:37 -08001370
1371 /**
1372 * @hide
1373 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001374 @UnsupportedAppUsage
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001375 public long presentationDeadlineNanos;
Jesse Hall6a6bc212013-08-08 12:15:03 -07001376
Robert Carra7827f72019-01-11 12:53:37 -08001377 /**
1378 * @hide
1379 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001380 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001381 public PhysicalDisplayInfo() {
1382 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001383
Robert Carra7827f72019-01-11 12:53:37 -08001384 /**
1385 * @hide
1386 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001387 public PhysicalDisplayInfo(PhysicalDisplayInfo other) {
1388 copyFrom(other);
1389 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001390
Robert Carra7827f72019-01-11 12:53:37 -08001391 /**
1392 * @hide
1393 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001394 @Override
1395 public boolean equals(Object o) {
1396 return o instanceof PhysicalDisplayInfo && equals((PhysicalDisplayInfo)o);
1397 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001398
Robert Carra7827f72019-01-11 12:53:37 -08001399 /**
1400 * @hide
1401 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001402 public boolean equals(PhysicalDisplayInfo other) {
1403 return other != null
1404 && width == other.width
1405 && height == other.height
1406 && refreshRate == other.refreshRate
1407 && density == other.density
1408 && xDpi == other.xDpi
1409 && yDpi == other.yDpi
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001410 && secure == other.secure
1411 && appVsyncOffsetNanos == other.appVsyncOffsetNanos
Michael Wright1c9977b2016-07-12 13:30:10 -07001412 && presentationDeadlineNanos == other.presentationDeadlineNanos;
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001413 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001414
Robert Carra7827f72019-01-11 12:53:37 -08001415 /**
1416 * @hide
1417 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001418 @Override
1419 public int hashCode() {
1420 return 0; // don't care
1421 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001422
Robert Carra7827f72019-01-11 12:53:37 -08001423 /**
1424 * @hide
1425 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001426 public void copyFrom(PhysicalDisplayInfo other) {
1427 width = other.width;
1428 height = other.height;
1429 refreshRate = other.refreshRate;
1430 density = other.density;
1431 xDpi = other.xDpi;
1432 yDpi = other.yDpi;
1433 secure = other.secure;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001434 appVsyncOffsetNanos = other.appVsyncOffsetNanos;
1435 presentationDeadlineNanos = other.presentationDeadlineNanos;
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001436 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001437
Robert Carra7827f72019-01-11 12:53:37 -08001438 /**
1439 * @hide
1440 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001441 @Override
1442 public String toString() {
1443 return "PhysicalDisplayInfo{" + width + " x " + height + ", " + refreshRate + " fps, "
1444 + "density " + density + ", " + xDpi + " x " + yDpi + " dpi, secure " + secure
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001445 + ", appVsyncOffset " + appVsyncOffsetNanos
Michael Wright1c9977b2016-07-12 13:30:10 -07001446 + ", bufferDeadline " + presentationDeadlineNanos + "}";
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001447 }
1448 }
1449
Robert Carra7827f72019-01-11 12:53:37 -08001450 /**
1451 * @hide
1452 */
Prashant Malanic55929a2014-05-25 01:59:21 -07001453 public static void setDisplayPowerMode(IBinder displayToken, int mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001454 if (displayToken == null) {
1455 throw new IllegalArgumentException("displayToken must not be null");
1456 }
Prashant Malanic55929a2014-05-25 01:59:21 -07001457 nativeSetDisplayPowerMode(displayToken, mode);
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001458 }
1459
Robert Carra7827f72019-01-11 12:53:37 -08001460 /**
1461 * @hide
1462 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001463 @UnsupportedAppUsage
Dan Stoza00101052014-05-02 15:23:40 -07001464 public static SurfaceControl.PhysicalDisplayInfo[] getDisplayConfigs(IBinder displayToken) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001465 if (displayToken == null) {
1466 throw new IllegalArgumentException("displayToken must not be null");
1467 }
Dan Stoza00101052014-05-02 15:23:40 -07001468 return nativeGetDisplayConfigs(displayToken);
1469 }
1470
Robert Carra7827f72019-01-11 12:53:37 -08001471 /**
1472 * @hide
1473 */
Dan Stoza00101052014-05-02 15:23:40 -07001474 public static int getActiveConfig(IBinder displayToken) {
1475 if (displayToken == null) {
1476 throw new IllegalArgumentException("displayToken must not be null");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001477 }
Dan Stoza00101052014-05-02 15:23:40 -07001478 return nativeGetActiveConfig(displayToken);
1479 }
1480
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001481 /**
1482 * @hide
1483 */
1484 public static DisplayedContentSamplingAttributes getDisplayedContentSamplingAttributes(
1485 IBinder displayToken) {
1486 if (displayToken == null) {
1487 throw new IllegalArgumentException("displayToken must not be null");
1488 }
1489 return nativeGetDisplayedContentSamplingAttributes(displayToken);
1490 }
1491
1492 /**
1493 * @hide
1494 */
1495 public static boolean setDisplayedContentSamplingEnabled(
1496 IBinder displayToken, boolean enable, int componentMask, int maxFrames) {
1497 if (displayToken == null) {
1498 throw new IllegalArgumentException("displayToken must not be null");
1499 }
1500 final int maxColorComponents = 4;
1501 if ((componentMask >> maxColorComponents) != 0) {
1502 throw new IllegalArgumentException("invalid componentMask when enabling sampling");
1503 }
1504 return nativeSetDisplayedContentSamplingEnabled(
1505 displayToken, enable, componentMask, maxFrames);
1506 }
1507
1508 /**
1509 * @hide
1510 */
1511 public static DisplayedContentSample getDisplayedContentSample(
1512 IBinder displayToken, long maxFrames, long timestamp) {
1513 if (displayToken == null) {
1514 throw new IllegalArgumentException("displayToken must not be null");
1515 }
1516 return nativeGetDisplayedContentSample(displayToken, maxFrames, timestamp);
1517 }
1518
1519
Robert Carra7827f72019-01-11 12:53:37 -08001520 /**
1521 * @hide
1522 */
Dan Stoza00101052014-05-02 15:23:40 -07001523 public static boolean setActiveConfig(IBinder displayToken, int id) {
1524 if (displayToken == null) {
1525 throw new IllegalArgumentException("displayToken must not be null");
1526 }
1527 return nativeSetActiveConfig(displayToken, id);
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001528 }
1529
Robert Carra7827f72019-01-11 12:53:37 -08001530 /**
1531 * @hide
1532 */
Michael Wright1c9977b2016-07-12 13:30:10 -07001533 public static int[] getDisplayColorModes(IBinder displayToken) {
1534 if (displayToken == null) {
1535 throw new IllegalArgumentException("displayToken must not be null");
1536 }
1537 return nativeGetDisplayColorModes(displayToken);
1538 }
1539
Robert Carra7827f72019-01-11 12:53:37 -08001540 /**
Daniel Solomon10e3b332019-01-20 21:09:11 -08001541 * Color coordinates in CIE1931 XYZ color space
1542 *
1543 * @hide
1544 */
1545 public static final class CieXyz {
1546 /**
1547 * @hide
1548 */
1549 public float X;
1550
1551 /**
1552 * @hide
1553 */
1554 public float Y;
1555
1556 /**
1557 * @hide
1558 */
1559 public float Z;
1560 }
1561
1562 /**
1563 * Contains a display's color primaries
1564 *
1565 * @hide
1566 */
1567 public static final class DisplayPrimaries {
1568 /**
1569 * @hide
1570 */
1571 public CieXyz red;
1572
1573 /**
1574 * @hide
1575 */
1576 public CieXyz green;
1577
1578 /**
1579 * @hide
1580 */
1581 public CieXyz blue;
1582
1583 /**
1584 * @hide
1585 */
1586 public CieXyz white;
1587
1588 /**
1589 * @hide
1590 */
1591 public DisplayPrimaries() {
1592 }
1593 }
1594
1595 /**
1596 * @hide
1597 */
1598 public static SurfaceControl.DisplayPrimaries getDisplayNativePrimaries(
1599 IBinder displayToken) {
1600 if (displayToken == null) {
1601 throw new IllegalArgumentException("displayToken must not be null");
1602 }
1603
1604 return nativeGetDisplayNativePrimaries(displayToken);
1605 }
1606
1607 /**
Robert Carra7827f72019-01-11 12:53:37 -08001608 * @hide
1609 */
Michael Wright1c9977b2016-07-12 13:30:10 -07001610 public static int getActiveColorMode(IBinder displayToken) {
1611 if (displayToken == null) {
1612 throw new IllegalArgumentException("displayToken must not be null");
1613 }
1614 return nativeGetActiveColorMode(displayToken);
1615 }
1616
Robert Carra7827f72019-01-11 12:53:37 -08001617 /**
1618 * @hide
1619 */
Michael Wright1c9977b2016-07-12 13:30:10 -07001620 public static boolean setActiveColorMode(IBinder displayToken, int colorMode) {
1621 if (displayToken == null) {
1622 throw new IllegalArgumentException("displayToken must not be null");
1623 }
1624 return nativeSetActiveColorMode(displayToken, colorMode);
1625 }
1626
Robert Carra7827f72019-01-11 12:53:37 -08001627 /**
Peiyong Lin5f4a5682019-01-17 11:37:07 -08001628 * Returns an array of color spaces with 2 elements. The first color space is the
1629 * default color space and second one is wide color gamut color space.
1630 * @hide
1631 */
1632 public static ColorSpace[] getCompositionColorSpaces() {
1633 int[] dataspaces = nativeGetCompositionDataspaces();
1634 ColorSpace srgb = ColorSpace.get(ColorSpace.Named.SRGB);
1635 ColorSpace[] colorSpaces = { srgb, srgb };
1636 if (dataspaces.length == 2) {
1637 for (int i = 0; i < 2; ++i) {
1638 switch(dataspaces[i]) {
1639 case INTERNAL_DATASPACE_DISPLAY_P3:
1640 colorSpaces[i] = ColorSpace.get(ColorSpace.Named.DISPLAY_P3);
1641 break;
1642 case INTERNAL_DATASPACE_SCRGB:
1643 colorSpaces[i] = ColorSpace.get(ColorSpace.Named.EXTENDED_SRGB);
1644 break;
1645 case INTERNAL_DATASPACE_SRGB:
1646 // Other dataspace is not recognized, use SRGB color space instead,
1647 // the default value of the array is already SRGB, thus do nothing.
1648 default:
1649 break;
1650 }
1651 }
1652 }
1653 return colorSpaces;
1654 }
1655
1656 /**
Robert Carra7827f72019-01-11 12:53:37 -08001657 * @hide
1658 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001659 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001660 public static void setDisplayProjection(IBinder displayToken,
1661 int orientation, Rect layerStackRect, Rect displayRect) {
Robert Carre13b58e2017-08-31 14:50:44 -07001662 synchronized (SurfaceControl.class) {
1663 sGlobalTransaction.setDisplayProjection(displayToken, orientation,
1664 layerStackRect, displayRect);
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001665 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001666 }
1667
Robert Carra7827f72019-01-11 12:53:37 -08001668 /**
1669 * @hide
1670 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001671 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001672 public static void setDisplayLayerStack(IBinder displayToken, int layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -07001673 synchronized (SurfaceControl.class) {
1674 sGlobalTransaction.setDisplayLayerStack(displayToken, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001675 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001676 }
1677
Robert Carra7827f72019-01-11 12:53:37 -08001678 /**
1679 * @hide
1680 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001681 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001682 public static void setDisplaySurface(IBinder displayToken, Surface surface) {
Robert Carre13b58e2017-08-31 14:50:44 -07001683 synchronized (SurfaceControl.class) {
1684 sGlobalTransaction.setDisplaySurface(displayToken, surface);
Jeff Brownfc0ebd72013-04-30 16:33:00 -07001685 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001686 }
1687
Robert Carra7827f72019-01-11 12:53:37 -08001688 /**
1689 * @hide
1690 */
Michael Wright01e840f2014-06-26 16:03:25 -07001691 public static void setDisplaySize(IBinder displayToken, int width, int height) {
Robert Carre13b58e2017-08-31 14:50:44 -07001692 synchronized (SurfaceControl.class) {
1693 sGlobalTransaction.setDisplaySize(displayToken, width, height);
Michael Wright01e840f2014-06-26 16:03:25 -07001694 }
Michael Wright01e840f2014-06-26 16:03:25 -07001695 }
1696
Robert Carra7827f72019-01-11 12:53:37 -08001697 /**
1698 * @hide
1699 */
Michael Wright9ff94c02016-03-30 18:05:40 -07001700 public static Display.HdrCapabilities getHdrCapabilities(IBinder displayToken) {
1701 if (displayToken == null) {
1702 throw new IllegalArgumentException("displayToken must not be null");
1703 }
1704 return nativeGetHdrCapabilities(displayToken);
1705 }
1706
Robert Carra7827f72019-01-11 12:53:37 -08001707 /**
1708 * @hide
1709 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001710 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001711 public static IBinder createDisplay(String name, boolean secure) {
1712 if (name == null) {
1713 throw new IllegalArgumentException("name must not be null");
1714 }
1715 return nativeCreateDisplay(name, secure);
1716 }
1717
Robert Carra7827f72019-01-11 12:53:37 -08001718 /**
1719 * @hide
1720 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001721 @UnsupportedAppUsage
Jesse Hall6a6bc212013-08-08 12:15:03 -07001722 public static void destroyDisplay(IBinder displayToken) {
1723 if (displayToken == null) {
1724 throw new IllegalArgumentException("displayToken must not be null");
1725 }
1726 nativeDestroyDisplay(displayToken);
1727 }
1728
Robert Carra7827f72019-01-11 12:53:37 -08001729 /**
1730 * @hide
1731 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001732 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001733 public static IBinder getBuiltInDisplay(int builtInDisplayId) {
1734 return nativeGetBuiltInDisplay(builtInDisplayId);
1735 }
1736
Mathias Agopian0449a402013-03-01 23:01:51 -08001737 /**
chaviw08520a02018-09-10 16:44:56 -07001738 * @see SurfaceControl#screenshot(IBinder, Surface, Rect, int, int, boolean, int)
Robert Carra7827f72019-01-11 12:53:37 -08001739 * @hide
Mathias Agopian0449a402013-03-01 23:01:51 -08001740 */
1741 public static void screenshot(IBinder display, Surface consumer) {
chaviw08520a02018-09-10 16:44:56 -07001742 screenshot(display, consumer, new Rect(), 0, 0, false, 0);
1743 }
1744
1745 /**
1746 * Copy the current screen contents into the provided {@link Surface}
1747 *
1748 * @param consumer The {@link Surface} to take the screenshot into.
1749 * @see SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)
Robert Carra7827f72019-01-11 12:53:37 -08001750 * @hide
chaviw08520a02018-09-10 16:44:56 -07001751 */
1752 public static void screenshot(IBinder display, Surface consumer, Rect sourceCrop, int width,
1753 int height, boolean useIdentityTransform, int rotation) {
1754 if (consumer == null) {
1755 throw new IllegalArgumentException("consumer must not be null");
1756 }
1757
1758 final GraphicBuffer buffer = screenshotToBuffer(display, sourceCrop, width, height,
1759 useIdentityTransform, rotation);
1760 try {
1761 consumer.attachAndQueueBuffer(buffer);
1762 } catch (RuntimeException e) {
1763 Log.w(TAG, "Failed to take screenshot - " + e.getMessage());
1764 }
1765 }
1766
1767 /**
1768 * @see SurfaceControl#screenshot(Rect, int, int, boolean, int)}
Robert Carra7827f72019-01-11 12:53:37 -08001769 * @hide
chaviw08520a02018-09-10 16:44:56 -07001770 */
1771 @UnsupportedAppUsage
1772 public static Bitmap screenshot(Rect sourceCrop, int width, int height, int rotation) {
1773 return screenshot(sourceCrop, width, height, false, rotation);
Mathias Agopian0449a402013-03-01 23:01:51 -08001774 }
1775
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001776 /**
chaviw1da9cd92017-12-06 10:48:11 -08001777 * Copy the current screen contents into a hardware bitmap and return it.
1778 * Note: If you want to modify the Bitmap in software, you will need to copy the Bitmap into
1779 * a software Bitmap using {@link Bitmap#copy(Bitmap.Config, boolean)}
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001780 *
chaviw08520a02018-09-10 16:44:56 -07001781 * CAVEAT: Versions of screenshot that return a {@link Bitmap} can be extremely slow; avoid use
1782 * unless absolutely necessary; prefer the versions that use a {@link Surface} such as
1783 * {@link SurfaceControl#screenshot(IBinder, Surface)} or {@link GraphicBuffer} such as
1784 * {@link SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)}.
Mathias Agopian0449a402013-03-01 23:01:51 -08001785 *
chaviw08520a02018-09-10 16:44:56 -07001786 * @see SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)}
Robert Carra7827f72019-01-11 12:53:37 -08001787 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001788 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001789 @UnsupportedAppUsage
Dan Stoza9890e3412014-05-22 16:12:54 -07001790 public static Bitmap screenshot(Rect sourceCrop, int width, int height,
chaviw08520a02018-09-10 16:44:56 -07001791 boolean useIdentityTransform, int rotation) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001792 // TODO: should take the display as a parameter
Mathias Agopian0449a402013-03-01 23:01:51 -08001793 IBinder displayToken = SurfaceControl.getBuiltInDisplay(
1794 SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN);
chaviwa69e0a72017-11-29 17:55:12 -08001795 if (rotation == ROTATION_90 || rotation == ROTATION_270) {
1796 rotation = (rotation == ROTATION_90) ? ROTATION_270 : ROTATION_90;
1797 }
1798
1799 SurfaceControl.rotateCropForSF(sourceCrop, rotation);
chaviw08520a02018-09-10 16:44:56 -07001800 final GraphicBuffer buffer = screenshotToBuffer(displayToken, sourceCrop, width, height,
1801 useIdentityTransform, rotation);
1802
1803 if (buffer == null) {
1804 Log.w(TAG, "Failed to take screenshot");
1805 return null;
1806 }
Peiyong Lin9d427402019-01-23 18:39:06 -08001807 // TODO(b/116112787) Now that hardware bitmap creation can take color space, we
1808 // should continue to fix screenshot.
1809 return Bitmap.wrapHardwareBuffer(HardwareBuffer.createFromGraphicBuffer(buffer),
1810 ColorSpace.get(ColorSpace.Named.SRGB));
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001811 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001812
chaviw08520a02018-09-10 16:44:56 -07001813 /**
1814 * Captures all the surfaces in a display and returns a {@link GraphicBuffer} with the content.
1815 *
1816 * @param display The display to take the screenshot of.
1817 * @param sourceCrop The portion of the screen to capture into the Bitmap; caller may
1818 * pass in 'new Rect()' if no cropping is desired.
1819 * @param width The desired width of the returned bitmap; the raw screen will be
1820 * scaled down to this size; caller may pass in 0 if no scaling is
1821 * desired.
1822 * @param height The desired height of the returned bitmap; the raw screen will
1823 * be scaled down to this size; caller may pass in 0 if no scaling
1824 * is desired.
1825 * @param useIdentityTransform Replace whatever transformation (rotation, scaling, translation)
1826 * the surface layers are currently using with the identity
1827 * transformation while taking the screenshot.
1828 * @param rotation Apply a custom clockwise rotation to the screenshot, i.e.
1829 * Surface.ROTATION_0,90,180,270. SurfaceFlinger will always take
1830 * screenshots in its native portrait orientation by default, so
1831 * this is useful for returning screenshots that are independent of
1832 * device orientation.
1833 * @return Returns a GraphicBuffer that contains the captured content.
Robert Carra7827f72019-01-11 12:53:37 -08001834 * @hide
chaviw08520a02018-09-10 16:44:56 -07001835 */
1836 public static GraphicBuffer screenshotToBuffer(IBinder display, Rect sourceCrop, int width,
1837 int height, boolean useIdentityTransform, int rotation) {
Mathias Agopian0449a402013-03-01 23:01:51 -08001838 if (display == null) {
1839 throw new IllegalArgumentException("displayToken must not be null");
1840 }
chaviw08520a02018-09-10 16:44:56 -07001841
1842 return nativeScreenshot(display, sourceCrop, width, height, useIdentityTransform, rotation);
Mathias Agopian0449a402013-03-01 23:01:51 -08001843 }
Robert Carre13b58e2017-08-31 14:50:44 -07001844
chaviwa69e0a72017-11-29 17:55:12 -08001845 private static void rotateCropForSF(Rect crop, int rot) {
1846 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
1847 int tmp = crop.top;
1848 crop.top = crop.left;
1849 crop.left = tmp;
1850 tmp = crop.right;
1851 crop.right = crop.bottom;
1852 crop.bottom = tmp;
1853 }
1854 }
1855
chaviw1cda84c2017-10-23 16:47:10 -07001856 /**
chaviw1da9cd92017-12-06 10:48:11 -08001857 * Captures a layer and its children and returns a {@link GraphicBuffer} with the content.
chaviw1cda84c2017-10-23 16:47:10 -07001858 *
1859 * @param layerHandleToken The root layer to capture.
chaviwfbe47df2017-11-10 16:14:49 -08001860 * @param sourceCrop The portion of the root surface to capture; caller may pass in 'new
1861 * Rect()' or null if no cropping is desired.
1862 * @param frameScale The desired scale of the returned buffer; the raw
1863 * screen will be scaled up/down.
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001864 *
1865 * @return Returns a GraphicBuffer that contains the layer capture.
Robert Carra7827f72019-01-11 12:53:37 -08001866 * @hide
chaviw1cda84c2017-10-23 16:47:10 -07001867 */
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001868 public static GraphicBuffer captureLayers(IBinder layerHandleToken, Rect sourceCrop,
chaviwfbe47df2017-11-10 16:14:49 -08001869 float frameScale) {
1870 return nativeCaptureLayers(layerHandleToken, sourceCrop, frameScale);
chaviw1cda84c2017-10-23 16:47:10 -07001871 }
1872
Robert Carra7827f72019-01-11 12:53:37 -08001873 /**
Peiyong Lin0ddb7d42019-01-16 13:25:09 -08001874 * Returns whether protected content is supported in GPU composition.
1875 * @hide
1876 */
1877 public static boolean getProtectedContentSupport() {
1878 return nativeGetProtectedContentSupport();
1879 }
1880
1881 /**
Robert Carr76907ee2019-01-11 13:38:19 -08001882 * An atomic set of changes to a set of SurfaceControl.
Robert Carra7827f72019-01-11 12:53:37 -08001883 */
Robert Carre13b58e2017-08-31 14:50:44 -07001884 public static class Transaction implements Closeable {
Robert Carr76907ee2019-01-11 13:38:19 -08001885 /**
1886 * @hide
1887 */
Robert Carre13b58e2017-08-31 14:50:44 -07001888 public static final NativeAllocationRegistry sRegistry = new NativeAllocationRegistry(
1889 Transaction.class.getClassLoader(),
1890 nativeGetNativeTransactionFinalizer(), 512);
1891 private long mNativeObject;
1892
Jorim Jaggia5e10572017-11-15 14:36:26 +01001893 private final ArrayMap<SurfaceControl, Point> mResizedSurfaces = new ArrayMap<>();
Robert Carre13b58e2017-08-31 14:50:44 -07001894 Runnable mFreeNativeResources;
1895
Robert Carra7827f72019-01-11 12:53:37 -08001896 /**
Robert Carr76907ee2019-01-11 13:38:19 -08001897 * Open a new transaction object. The transaction may be filed with commands to
1898 * manipulate {@link SurfaceControl} instances, and then applied atomically with
1899 * {@link #apply}. Eventually the user should invoke {@link #close}, when the object
1900 * is no longer required. Note however that re-using a transaction after a call to apply
1901 * is allowed as a convenience.
Robert Carra7827f72019-01-11 12:53:37 -08001902 */
Robert Carre13b58e2017-08-31 14:50:44 -07001903 public Transaction() {
1904 mNativeObject = nativeCreateTransaction();
1905 mFreeNativeResources
1906 = sRegistry.registerNativeAllocation(this, mNativeObject);
1907 }
1908
1909 /**
1910 * Apply the transaction, clearing it's state, and making it usable
1911 * as a new transaction.
1912 */
1913 public void apply() {
1914 apply(false);
1915 }
1916
1917 /**
1918 * Close the transaction, if the transaction was not already applied this will cancel the
1919 * transaction.
1920 */
1921 @Override
1922 public void close() {
1923 mFreeNativeResources.run();
1924 mNativeObject = 0;
1925 }
1926
1927 /**
1928 * Jankier version of apply. Avoid use (b/28068298).
Robert Carra7827f72019-01-11 12:53:37 -08001929 * @hide
Robert Carre13b58e2017-08-31 14:50:44 -07001930 */
1931 public void apply(boolean sync) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01001932 applyResizedSurfaces();
Robert Carre13b58e2017-08-31 14:50:44 -07001933 nativeApplyTransaction(mNativeObject, sync);
1934 }
1935
Jorim Jaggia5e10572017-11-15 14:36:26 +01001936 private void applyResizedSurfaces() {
1937 for (int i = mResizedSurfaces.size() - 1; i >= 0; i--) {
1938 final Point size = mResizedSurfaces.valueAt(i);
1939 final SurfaceControl surfaceControl = mResizedSurfaces.keyAt(i);
1940 synchronized (surfaceControl.mSizeLock) {
1941 surfaceControl.mWidth = size.x;
1942 surfaceControl.mHeight = size.y;
1943 }
1944 }
1945 mResizedSurfaces.clear();
1946 }
1947
Robert Carra7827f72019-01-11 12:53:37 -08001948 /**
Robert Carr76907ee2019-01-11 13:38:19 -08001949 * Toggle the visibility of a given Layer and it's sub-tree.
1950 *
1951 * @param sc The SurfaceControl for which to set the visibility
1952 * @param visible The new visibility
1953 * @return This transaction object.
1954 */
1955 @NonNull
1956 public Transaction setVisibility(@NonNull SurfaceControl sc, boolean visible) {
1957 sc.checkNotReleased();
1958 if (visible) {
1959 return show(sc);
1960 } else {
1961 return hide(sc);
1962 }
1963 }
1964
1965 /**
1966 * Request that a given surface and it's sub-tree be shown.
1967 *
1968 * @param sc The surface to show.
1969 * @return This transaction.
Robert Carra7827f72019-01-11 12:53:37 -08001970 * @hide
1971 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001972 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07001973 public Transaction show(SurfaceControl sc) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02001974 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001975 nativeSetFlags(mNativeObject, sc.mNativeObject, 0, SURFACE_HIDDEN);
1976 return this;
1977 }
1978
Robert Carra7827f72019-01-11 12:53:37 -08001979 /**
Robert Carr76907ee2019-01-11 13:38:19 -08001980 * Request that a given surface and it's sub-tree be hidden.
1981 *
1982 * @param sc The surface to hidden.
1983 * @return This transaction.
Robert Carra7827f72019-01-11 12:53:37 -08001984 * @hide
1985 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001986 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07001987 public Transaction hide(SurfaceControl sc) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02001988 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001989 nativeSetFlags(mNativeObject, sc.mNativeObject, SURFACE_HIDDEN, SURFACE_HIDDEN);
1990 return this;
1991 }
1992
Robert Carra7827f72019-01-11 12:53:37 -08001993 /**
1994 * @hide
1995 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001996 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07001997 public Transaction setPosition(SurfaceControl sc, float x, float y) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02001998 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001999 nativeSetPosition(mNativeObject, sc.mNativeObject, x, y);
2000 return this;
2001 }
2002
Robert Carra7827f72019-01-11 12:53:37 -08002003 /**
Robert Carr76907ee2019-01-11 13:38:19 -08002004 * Set the default buffer size for the SurfaceControl, if there is an
2005 * {@link Surface} assosciated with the control, then
2006 * this will be the default size for buffers dequeued from it.
2007 * @param sc The surface to set the buffer size for.
2008 * @param w The default width
2009 * @param h The default height
2010 * @return This Transaction
Robert Carra7827f72019-01-11 12:53:37 -08002011 */
Robert Carr76907ee2019-01-11 13:38:19 -08002012 @NonNull
2013 public Transaction setBufferSize(@NonNull SurfaceControl sc,
2014 @IntRange(from = 0) int w, @IntRange(from = 0) int h) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002015 sc.checkNotReleased();
Jorim Jaggia5e10572017-11-15 14:36:26 +01002016 mResizedSurfaces.put(sc, new Point(w, h));
Jorim Jaggidfc27372017-10-27 17:47:49 +02002017 nativeSetSize(mNativeObject, sc.mNativeObject, w, h);
Robert Carre13b58e2017-08-31 14:50:44 -07002018 return this;
2019 }
2020
Robert Carra7827f72019-01-11 12:53:37 -08002021 /**
Robert Carr76907ee2019-01-11 13:38:19 -08002022 * Set the Z-order for a given SurfaceControl, relative to it's siblings.
2023 * If two siblings share the same Z order the ordering is undefined. Surfaces
2024 * with a negative Z will be placed below the parent surface.
2025 *
2026 * @param sc The SurfaceControl to set the Z order on
2027 * @param z The Z-order
2028 * @return This Transaction.
Robert Carra7827f72019-01-11 12:53:37 -08002029 */
Robert Carr76907ee2019-01-11 13:38:19 -08002030 @NonNull
2031 public Transaction setLayer(@NonNull SurfaceControl sc,
2032 @IntRange(from = Integer.MIN_VALUE, to = Integer.MAX_VALUE) int z) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002033 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002034 nativeSetLayer(mNativeObject, sc.mNativeObject, z);
2035 return this;
2036 }
2037
Robert Carra7827f72019-01-11 12:53:37 -08002038 /**
2039 * @hide
2040 */
Robert Carr77e34942017-10-18 19:13:56 -07002041 public Transaction setRelativeLayer(SurfaceControl sc, SurfaceControl relativeTo, int z) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002042 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002043 nativeSetRelativeLayer(mNativeObject, sc.mNativeObject,
Robert Carr77e34942017-10-18 19:13:56 -07002044 relativeTo.getHandle(), z);
Robert Carre13b58e2017-08-31 14:50:44 -07002045 return this;
2046 }
2047
Robert Carra7827f72019-01-11 12:53:37 -08002048 /**
2049 * @hide
2050 */
Robert Carre13b58e2017-08-31 14:50:44 -07002051 public Transaction setTransparentRegionHint(SurfaceControl sc, Region transparentRegion) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002052 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002053 nativeSetTransparentRegionHint(mNativeObject,
2054 sc.mNativeObject, transparentRegion);
2055 return this;
2056 }
2057
Robert Carra7827f72019-01-11 12:53:37 -08002058 /**
Robert Carr76907ee2019-01-11 13:38:19 -08002059 * Set the alpha for a given surface. If the alpha is non-zero the SurfaceControl
2060 * will be blended with the Surfaces under it according to the specified ratio.
2061 *
2062 * @param sc The given SurfaceControl.
2063 * @param alpha The alpha to set.
Robert Carra7827f72019-01-11 12:53:37 -08002064 */
Robert Carr76907ee2019-01-11 13:38:19 -08002065 @NonNull
2066 public Transaction setAlpha(@NonNull SurfaceControl sc,
2067 @FloatRange(from = 0.0, to = 1.0) float alpha) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002068 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002069 nativeSetAlpha(mNativeObject, sc.mNativeObject, alpha);
2070 return this;
2071 }
2072
Robert Carra7827f72019-01-11 12:53:37 -08002073 /**
2074 * @hide
2075 */
Robert Carr788f5742018-07-30 17:46:45 -07002076 public Transaction setInputWindowInfo(SurfaceControl sc, InputWindowHandle handle) {
2077 sc.checkNotReleased();
2078 nativeSetInputWindowInfo(mNativeObject, sc.mNativeObject, handle);
2079 return this;
2080 }
2081
chaviw59f532e2018-12-26 15:34:59 -08002082 /**
2083 * Transfers touch focus from one window to another. It is possible for multiple windows to
2084 * have touch focus if they support split touch dispatch
2085 * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this
2086 * method only transfers touch focus of the specified window without affecting
2087 * other windows that may also have touch focus at the same time.
2088 * @param fromToken The token of a window that currently has touch focus.
2089 * @param toToken The token of the window that should receive touch focus in
2090 * place of the first.
Robert Carra7827f72019-01-11 12:53:37 -08002091 * @hide
chaviw59f532e2018-12-26 15:34:59 -08002092 */
2093 public Transaction transferTouchFocus(IBinder fromToken, IBinder toToken) {
2094 nativeTransferTouchFocus(mNativeObject, fromToken, toToken);
2095 return this;
2096 }
2097
Robert Carra7827f72019-01-11 12:53:37 -08002098 /**
Robert Carr76907ee2019-01-11 13:38:19 -08002099 * Specify how the buffer assosciated with this Surface is mapped in to the
2100 * parent coordinate space. The source frame will be scaled to fit the destination
2101 * frame, after being rotated according to the orientation parameter.
2102 *
2103 * @param sc The SurfaceControl to specify the geometry of
2104 * @param sourceCrop The source rectangle in buffer space. Or null for the entire buffer.
2105 * @param destFrame The destination rectangle in parent space. Or null for the source frame.
2106 * @param orientation The buffer rotation
2107 * @return This transaction object.
2108 */
2109 @NonNull
2110 public Transaction setGeometry(@NonNull SurfaceControl sc, @Nullable Rect sourceCrop,
2111 @Nullable Rect destFrame, @Surface.Rotation int orientation) {
2112 sc.checkNotReleased();
2113 nativeSetGeometry(mNativeObject, sc.mNativeObject, sourceCrop, destFrame, orientation);
2114 return this;
2115 }
2116
2117 /**
Robert Carra7827f72019-01-11 12:53:37 -08002118 * @hide
2119 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002120 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07002121 public Transaction setMatrix(SurfaceControl sc,
2122 float dsdx, float dtdx, float dtdy, float dsdy) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002123 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002124 nativeSetMatrix(mNativeObject, sc.mNativeObject,
2125 dsdx, dtdx, dtdy, dsdy);
2126 return this;
2127 }
2128
Robert Carra7827f72019-01-11 12:53:37 -08002129 /**
2130 * @hide
2131 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002132 @UnsupportedAppUsage
Jorim Jaggi21c39a72017-10-20 15:47:51 +02002133 public Transaction setMatrix(SurfaceControl sc, Matrix matrix, float[] float9) {
2134 matrix.getValues(float9);
2135 setMatrix(sc, float9[MSCALE_X], float9[MSKEW_Y],
2136 float9[MSKEW_X], float9[MSCALE_Y]);
2137 setPosition(sc, float9[MTRANS_X], float9[MTRANS_Y]);
2138 return this;
2139 }
2140
Peiyong Lin52bb6b42018-10-01 11:40:50 -07002141 /**
2142 * Sets the color transform for the Surface.
2143 * @param matrix A float array with 9 values represents a 3x3 transform matrix
2144 * @param translation A float array with 3 values represents a translation vector
Robert Carra7827f72019-01-11 12:53:37 -08002145 * @hide
Peiyong Lin52bb6b42018-10-01 11:40:50 -07002146 */
2147 public Transaction setColorTransform(SurfaceControl sc, @Size(9) float[] matrix,
2148 @Size(3) float[] translation) {
2149 sc.checkNotReleased();
2150 nativeSetColorTransform(mNativeObject, sc.mNativeObject, matrix, translation);
2151 return this;
2152 }
2153
Robert Carra7827f72019-01-11 12:53:37 -08002154 /**
2155 * @hide
2156 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002157 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07002158 public Transaction setWindowCrop(SurfaceControl sc, Rect crop) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002159 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002160 if (crop != null) {
2161 nativeSetWindowCrop(mNativeObject, sc.mNativeObject,
2162 crop.left, crop.top, crop.right, crop.bottom);
2163 } else {
2164 nativeSetWindowCrop(mNativeObject, sc.mNativeObject, 0, 0, 0, 0);
2165 }
2166
2167 return this;
2168 }
2169
Robert Carra7827f72019-01-11 12:53:37 -08002170 /**
2171 * @hide
2172 */
Vishnu Naird454442d2018-11-13 13:51:01 -08002173 public Transaction setWindowCrop(SurfaceControl sc, int width, int height) {
2174 sc.checkNotReleased();
2175 nativeSetWindowCrop(mNativeObject, sc.mNativeObject, 0, 0, width, height);
2176 return this;
2177 }
2178
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07002179 /**
2180 * Sets the corner radius of a {@link SurfaceControl}.
2181 * @param sc SurfaceControl
2182 * @param cornerRadius Corner radius in pixels.
2183 * @return Itself.
Robert Carra7827f72019-01-11 12:53:37 -08002184 * @hide
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07002185 */
2186 @UnsupportedAppUsage
2187 public Transaction setCornerRadius(SurfaceControl sc, float cornerRadius) {
2188 sc.checkNotReleased();
2189 nativeSetCornerRadius(mNativeObject, sc.mNativeObject, cornerRadius);
2190
2191 return this;
2192 }
2193
Robert Carra7827f72019-01-11 12:53:37 -08002194 /**
2195 * @hide
2196 */
Robert Carr76907ee2019-01-11 13:38:19 -08002197 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07002198 public Transaction setLayerStack(SurfaceControl sc, int layerStack) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002199 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002200 nativeSetLayerStack(mNativeObject, sc.mNativeObject, layerStack);
2201 return this;
2202 }
2203
Robert Carra7827f72019-01-11 12:53:37 -08002204 /**
2205 * @hide
2206 */
Robert Carr76907ee2019-01-11 13:38:19 -08002207 @UnsupportedAppUsage
Jorim Jaggidfc27372017-10-27 17:47:49 +02002208 public Transaction deferTransactionUntil(SurfaceControl sc, IBinder handle,
2209 long frameNumber) {
Robert Carr024378c2018-02-27 11:21:05 -08002210 if (frameNumber < 0) {
2211 return this;
2212 }
Jorim Jaggidfc27372017-10-27 17:47:49 +02002213 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002214 nativeDeferTransactionUntil(mNativeObject, sc.mNativeObject, handle, frameNumber);
2215 return this;
2216 }
2217
Robert Carra7827f72019-01-11 12:53:37 -08002218 /**
2219 * @hide
2220 */
Robert Carr76907ee2019-01-11 13:38:19 -08002221 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07002222 public Transaction deferTransactionUntilSurface(SurfaceControl sc, Surface barrierSurface,
2223 long frameNumber) {
Robert Carr024378c2018-02-27 11:21:05 -08002224 if (frameNumber < 0) {
2225 return this;
2226 }
Jorim Jaggidfc27372017-10-27 17:47:49 +02002227 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002228 nativeDeferTransactionUntilSurface(mNativeObject, sc.mNativeObject,
2229 barrierSurface.mNativeObject, frameNumber);
2230 return this;
2231 }
2232
Robert Carra7827f72019-01-11 12:53:37 -08002233 /**
2234 * @hide
2235 */
Robert Carre13b58e2017-08-31 14:50:44 -07002236 public Transaction reparentChildren(SurfaceControl sc, IBinder newParentHandle) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002237 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002238 nativeReparentChildren(mNativeObject, sc.mNativeObject, newParentHandle);
2239 return this;
2240 }
2241
Robert Carr10584fa2019-01-14 15:55:19 -08002242 /**
2243 * Re-parents a given layer to a new parent. Children inherit transform (position, scaling)
2244 * crop, visibility, and Z-ordering from their parents, as if the children were pixels within the
2245 * parent Surface.
2246 *
2247 * @param sc The SurfaceControl to reparent
2248 * @param newParent The new parent for the given control.
2249 * @return This Transaction
Robert Carra7827f72019-01-11 12:53:37 -08002250 */
Robert Carr76907ee2019-01-11 13:38:19 -08002251 @NonNull
2252 public Transaction reparent(@NonNull SurfaceControl sc,
2253 @Nullable SurfaceControl newParent) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002254 sc.checkNotReleased();
Robert Carr10584fa2019-01-14 15:55:19 -08002255 long otherObject = 0;
2256 if (newParent != null) {
2257 newParent.checkNotReleased();
2258 otherObject = newParent.mNativeObject;
2259 }
2260 nativeReparent(mNativeObject, sc.mNativeObject, otherObject);
Robert Carre13b58e2017-08-31 14:50:44 -07002261 return this;
2262 }
2263
Robert Carra7827f72019-01-11 12:53:37 -08002264 /**
2265 * @hide
2266 */
Robert Carre13b58e2017-08-31 14:50:44 -07002267 public Transaction detachChildren(SurfaceControl sc) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002268 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002269 nativeSeverChildren(mNativeObject, sc.mNativeObject);
2270 return this;
2271 }
2272
Robert Carra7827f72019-01-11 12:53:37 -08002273 /**
2274 * @hide
2275 */
Robert Carre13b58e2017-08-31 14:50:44 -07002276 public Transaction setOverrideScalingMode(SurfaceControl sc, int overrideScalingMode) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002277 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002278 nativeSetOverrideScalingMode(mNativeObject, sc.mNativeObject,
2279 overrideScalingMode);
2280 return this;
2281 }
2282
2283 /**
2284 * Sets a color for the Surface.
2285 * @param color A float array with three values to represent r, g, b in range [0..1]
Robert Carra7827f72019-01-11 12:53:37 -08002286 * @hide
Robert Carre13b58e2017-08-31 14:50:44 -07002287 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002288 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07002289 public Transaction setColor(SurfaceControl sc, @Size(3) float[] color) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002290 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002291 nativeSetColor(mNativeObject, sc.mNativeObject, color);
2292 return this;
2293 }
2294
2295 /**
2296 * If the buffer size changes in this transaction, position and crop updates specified
2297 * in this transaction will not complete until a buffer of the new size
2298 * arrives. As transform matrix and size are already frozen in this fashion,
2299 * this enables totally freezing the surface until the resize has completed
2300 * (at which point the geometry influencing aspects of this transaction will then occur)
Robert Carra7827f72019-01-11 12:53:37 -08002301 * @hide
Robert Carre13b58e2017-08-31 14:50:44 -07002302 */
2303 public Transaction setGeometryAppliesWithResize(SurfaceControl sc) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002304 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002305 nativeSetGeometryAppliesWithResize(mNativeObject, sc.mNativeObject);
2306 return this;
2307 }
2308
2309 /**
2310 * Sets the security of the surface. Setting the flag is equivalent to creating the
2311 * Surface with the {@link #SECURE} flag.
Robert Carra7827f72019-01-11 12:53:37 -08002312 * @hide
Robert Carre13b58e2017-08-31 14:50:44 -07002313 */
Robert Carrb1579c82017-09-05 14:54:47 -07002314 public Transaction setSecure(SurfaceControl sc, boolean isSecure) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002315 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002316 if (isSecure) {
2317 nativeSetFlags(mNativeObject, sc.mNativeObject, SECURE, SECURE);
2318 } else {
2319 nativeSetFlags(mNativeObject, sc.mNativeObject, 0, SECURE);
2320 }
2321 return this;
2322 }
2323
2324 /**
2325 * Sets the opacity of the surface. Setting the flag is equivalent to creating the
2326 * Surface with the {@link #OPAQUE} flag.
Robert Carra7827f72019-01-11 12:53:37 -08002327 * @hide
Robert Carre13b58e2017-08-31 14:50:44 -07002328 */
2329 public Transaction setOpaque(SurfaceControl sc, boolean isOpaque) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002330 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002331 if (isOpaque) {
Robert Carr2b8a5e12017-10-18 18:46:27 -07002332 nativeSetFlags(mNativeObject, sc.mNativeObject, SURFACE_OPAQUE, SURFACE_OPAQUE);
Robert Carre13b58e2017-08-31 14:50:44 -07002333 } else {
Robert Carr2b8a5e12017-10-18 18:46:27 -07002334 nativeSetFlags(mNativeObject, sc.mNativeObject, 0, SURFACE_OPAQUE);
Robert Carre13b58e2017-08-31 14:50:44 -07002335 }
2336 return this;
2337 }
2338
Robert Carra7827f72019-01-11 12:53:37 -08002339 /**
2340 * @hide
2341 */
Robert Carre13b58e2017-08-31 14:50:44 -07002342 public Transaction setDisplaySurface(IBinder displayToken, Surface surface) {
2343 if (displayToken == null) {
2344 throw new IllegalArgumentException("displayToken must not be null");
2345 }
2346
2347 if (surface != null) {
2348 synchronized (surface.mLock) {
2349 nativeSetDisplaySurface(mNativeObject, displayToken, surface.mNativeObject);
2350 }
2351 } else {
2352 nativeSetDisplaySurface(mNativeObject, displayToken, 0);
2353 }
2354 return this;
2355 }
2356
Robert Carra7827f72019-01-11 12:53:37 -08002357 /**
2358 * @hide
2359 */
Robert Carre13b58e2017-08-31 14:50:44 -07002360 public Transaction setDisplayLayerStack(IBinder displayToken, int layerStack) {
2361 if (displayToken == null) {
2362 throw new IllegalArgumentException("displayToken must not be null");
2363 }
2364 nativeSetDisplayLayerStack(mNativeObject, displayToken, layerStack);
2365 return this;
2366 }
2367
Robert Carra7827f72019-01-11 12:53:37 -08002368 /**
2369 * @hide
2370 */
Robert Carre13b58e2017-08-31 14:50:44 -07002371 public Transaction setDisplayProjection(IBinder displayToken,
2372 int orientation, Rect layerStackRect, Rect displayRect) {
2373 if (displayToken == null) {
2374 throw new IllegalArgumentException("displayToken must not be null");
2375 }
2376 if (layerStackRect == null) {
2377 throw new IllegalArgumentException("layerStackRect must not be null");
2378 }
2379 if (displayRect == null) {
2380 throw new IllegalArgumentException("displayRect must not be null");
2381 }
2382 nativeSetDisplayProjection(mNativeObject, displayToken, orientation,
2383 layerStackRect.left, layerStackRect.top, layerStackRect.right, layerStackRect.bottom,
2384 displayRect.left, displayRect.top, displayRect.right, displayRect.bottom);
2385 return this;
2386 }
2387
Robert Carra7827f72019-01-11 12:53:37 -08002388 /**
2389 * @hide
2390 */
Robert Carre13b58e2017-08-31 14:50:44 -07002391 public Transaction setDisplaySize(IBinder displayToken, int width, int height) {
2392 if (displayToken == null) {
2393 throw new IllegalArgumentException("displayToken must not be null");
2394 }
2395 if (width <= 0 || height <= 0) {
2396 throw new IllegalArgumentException("width and height must be positive");
2397 }
2398
2399 nativeSetDisplaySize(mNativeObject, displayToken, width, height);
2400 return this;
2401 }
2402
Robert Carra7827f72019-01-11 12:53:37 -08002403 /** flag the transaction as an animation
2404 * @hide
2405 */
Robert Carre13b58e2017-08-31 14:50:44 -07002406 public Transaction setAnimationTransaction() {
2407 nativeSetAnimationTransaction(mNativeObject);
2408 return this;
2409 }
Robert Carrb1579c82017-09-05 14:54:47 -07002410
2411 /**
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01002412 * Indicate that SurfaceFlinger should wake up earlier than usual as a result of this
2413 * transaction. This should be used when the caller thinks that the scene is complex enough
2414 * that it's likely to hit GL composition, and thus, SurfaceFlinger needs to more time in
2415 * order not to miss frame deadlines.
2416 * <p>
2417 * Corresponds to setting ISurfaceComposer::eEarlyWakeup
Robert Carra7827f72019-01-11 12:53:37 -08002418 * @hide
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01002419 */
2420 public Transaction setEarlyWakeup() {
2421 nativeSetEarlyWakeup(mNativeObject);
2422 return this;
2423 }
2424
2425 /**
Evan Rosky485df202018-12-06 14:11:12 -08002426 * Sets an arbitrary piece of metadata on the surface. This is a helper for int data.
2427 * @hide
2428 */
2429 public Transaction setMetadata(int key, int data) {
2430 Parcel parcel = Parcel.obtain();
2431 parcel.writeInt(data);
2432 try {
2433 setMetadata(key, parcel);
2434 } finally {
2435 parcel.recycle();
2436 }
2437 return this;
2438 }
2439
2440 /**
2441 * Sets an arbitrary piece of metadata on the surface.
2442 * @hide
2443 */
2444 public Transaction setMetadata(int key, Parcel data) {
2445 nativeSetMetadata(mNativeObject, key, data);
2446 return this;
2447 }
2448
2449 /**
Robert Carrb1579c82017-09-05 14:54:47 -07002450 * Merge the other transaction into this transaction, clearing the
2451 * other transaction as if it had been applied.
Robert Carr76907ee2019-01-11 13:38:19 -08002452 *
2453 * @param other The transaction to merge in to this one.
2454 * @return This transaction.
Robert Carrb1579c82017-09-05 14:54:47 -07002455 */
Robert Carr76907ee2019-01-11 13:38:19 -08002456 @NonNull
2457 public Transaction merge(@NonNull Transaction other) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002458 mResizedSurfaces.putAll(other.mResizedSurfaces);
2459 other.mResizedSurfaces.clear();
Robert Carrb1579c82017-09-05 14:54:47 -07002460 nativeMergeTransaction(mNativeObject, other.mNativeObject);
2461 return this;
2462 }
Robert Carre13b58e2017-08-31 14:50:44 -07002463 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08002464}