blob: 863b717008d2951f5b8f1907abb2faae66393542 [file] [log] [blame]
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.view;
18
Jorim Jaggi21c39a72017-10-20 15:47:51 +020019import static android.graphics.Matrix.MSCALE_X;
20import static android.graphics.Matrix.MSCALE_Y;
21import static android.graphics.Matrix.MSKEW_X;
22import static android.graphics.Matrix.MSKEW_Y;
23import static android.graphics.Matrix.MTRANS_X;
24import static android.graphics.Matrix.MTRANS_Y;
Vishnu Nair04ab4392018-01-10 11:00:06 -080025import static android.view.Surface.ROTATION_270;
26import static android.view.Surface.ROTATION_90;
27import static android.view.SurfaceControlProto.HASH_CODE;
28import static android.view.SurfaceControlProto.NAME;
chaviwa69e0a72017-11-29 17:55:12 -080029
Robert Carr76907ee2019-01-11 13:38:19 -080030import android.annotation.FloatRange;
31import android.annotation.IntRange;
32import android.annotation.NonNull;
33import android.annotation.Nullable;
chaviw0dd03f52017-08-25 12:15:26 -070034import android.annotation.Size;
Mathew Inwooda570dee2018-08-17 14:56:00 +010035import android.annotation.UnsupportedAppUsage;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080036import android.graphics.Bitmap;
Peiyong Lin5f4a5682019-01-17 11:37:07 -080037import android.graphics.ColorSpace;
Robert Carr6486d312017-01-09 19:48:29 -080038import android.graphics.GraphicBuffer;
Jorim Jaggi21c39a72017-10-20 15:47:51 +020039import android.graphics.Matrix;
Vishnu Nair04ab4392018-01-10 11:00:06 -080040import android.graphics.PixelFormat;
Jorim Jaggia5e10572017-11-15 14:36:26 +010041import android.graphics.Point;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080042import android.graphics.Rect;
43import android.graphics.Region;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -070044import android.hardware.display.DisplayedContentSample;
45import android.hardware.display.DisplayedContentSamplingAttributes;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080046import android.os.IBinder;
Jorim Jaggi06975df2017-12-01 14:52:13 +010047import android.os.Parcel;
48import android.os.Parcelable;
Robert Carre625fcf2017-09-01 12:36:28 -070049import android.os.Process;
50import android.os.UserHandle;
Jorim Jaggia5e10572017-11-15 14:36:26 +010051import android.util.ArrayMap;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080052import android.util.Log;
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;
63
Mathias Agopian3866f0d2013-02-11 22:08:48 -080064/**
Robert Carr76907ee2019-01-11 13:38:19 -080065 * Handle to an on-screen Surface managed by the system compositor. The SurfaceControl is
66 * a combination of a buffer source, and metadata about how to display the buffers.
67 * By constructing a {@link Surface} from this SurfaceControl you can submit buffers to be
68 * composited. Using {@link SurfaceControl.Transaction} you can manipulate various
69 * properties of how the buffer will be displayed on-screen. SurfaceControl's are
70 * arranged into a scene-graph like hierarchy, and as such any SurfaceControl may have
71 * a parent. Geometric properties like transform, crop, and Z-ordering will be inherited
72 * from the parent, as if the child were content in the parents buffer stream.
Mathias Agopian3866f0d2013-02-11 22:08:48 -080073 */
Robert Carr76907ee2019-01-11 13:38:19 -080074public final class SurfaceControl implements Parcelable {
Mathias Agopian3866f0d2013-02-11 22:08:48 -080075 private static final String TAG = "SurfaceControl";
Mathias Agopian29479eb2013-02-14 14:36:04 -080076
Ashok Bhat36bef0b2014-01-20 20:08:01 +000077 private static native long nativeCreate(SurfaceSession session, String name,
Albert Chaulk3bf2e572016-11-22 13:59:19 -050078 int w, int h, int format, int flags, long parentObject, int windowType, int ownerUid)
Mathias Agopian29479eb2013-02-14 14:36:04 -080079 throws OutOfResourcesException;
Jorim Jaggi06975df2017-12-01 14:52:13 +010080 private static native long nativeReadFromParcel(Parcel in);
chaviwbeb7a0c2018-12-05 13:49:54 -080081 private static native long nativeCopyFromSurfaceControl(long nativeObject);
Jorim Jaggi06975df2017-12-01 14:52:13 +010082 private static native void nativeWriteToParcel(long nativeObject, Parcel out);
Ashok Bhat36bef0b2014-01-20 20:08:01 +000083 private static native void nativeRelease(long nativeObject);
84 private static native void nativeDestroy(long nativeObject);
Chong Zhang47e36a32016-02-29 16:44:33 -080085 private static native void nativeDisconnect(long nativeObject);
Mathias Agopian29479eb2013-02-14 14:36:04 -080086
chaviw08520a02018-09-10 16:44:56 -070087 private static native GraphicBuffer nativeScreenshot(IBinder displayToken,
88 Rect sourceCrop, int width, int height, boolean useIdentityTransform, int rotation);
chaviwfbe47df2017-11-10 16:14:49 -080089 private static native GraphicBuffer nativeCaptureLayers(IBinder layerHandleToken,
90 Rect sourceCrop, float frameScale);
Mathias Agopian29479eb2013-02-14 14:36:04 -080091
Robert Carre13b58e2017-08-31 14:50:44 -070092 private static native long nativeCreateTransaction();
93 private static native long nativeGetNativeTransactionFinalizer();
94 private static native void nativeApplyTransaction(long transactionObj, boolean sync);
Robert Carrb1579c82017-09-05 14:54:47 -070095 private static native void nativeMergeTransaction(long transactionObj,
96 long otherTransactionObj);
Robert Carre13b58e2017-08-31 14:50:44 -070097 private static native void nativeSetAnimationTransaction(long transactionObj);
Jorim Jaggiaa763cd2018-03-22 23:20:36 +010098 private static native void nativeSetEarlyWakeup(long transactionObj);
Mathias Agopian29479eb2013-02-14 14:36:04 -080099
Robert Carre13b58e2017-08-31 14:50:44 -0700100 private static native void nativeSetLayer(long transactionObj, long nativeObject, int zorder);
101 private static native void nativeSetRelativeLayer(long transactionObj, long nativeObject,
102 IBinder relativeTo, int zorder);
103 private static native void nativeSetPosition(long transactionObj, long nativeObject,
104 float x, float y);
105 private static native void nativeSetGeometryAppliesWithResize(long transactionObj,
106 long nativeObject);
107 private static native void nativeSetSize(long transactionObj, long nativeObject, int w, int h);
108 private static native void nativeSetTransparentRegionHint(long transactionObj,
109 long nativeObject, Region region);
110 private static native void nativeSetAlpha(long transactionObj, long nativeObject, float alpha);
111 private static native void nativeSetMatrix(long transactionObj, long nativeObject,
112 float dsdx, float dtdx,
Andrii Kulian283acd22017-08-03 04:03:51 -0700113 float dtdy, float dsdy);
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700114 private static native void nativeSetColorTransform(long transactionObj, long nativeObject,
115 float[] matrix, float[] translation);
Robert Carr76907ee2019-01-11 13:38:19 -0800116 private static native void nativeSetGeometry(long transactionObj, long nativeObject,
117 Rect sourceCrop, Rect dest, long orientation);
Robert Carre13b58e2017-08-31 14:50:44 -0700118 private static native void nativeSetColor(long transactionObj, long nativeObject, float[] color);
119 private static native void nativeSetFlags(long transactionObj, long nativeObject,
120 int flags, int mask);
121 private static native void nativeSetWindowCrop(long transactionObj, long nativeObject,
122 int l, int t, int r, int b);
Lucas Dupinff9d6ab2018-10-16 18:05:50 -0700123 private static native void nativeSetCornerRadius(long transactionObj, long nativeObject,
124 float cornerRadius);
Robert Carre13b58e2017-08-31 14:50:44 -0700125 private static native void nativeSetLayerStack(long transactionObj, long nativeObject,
126 int layerStack);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800127
Svetoslav1376d602014-03-13 11:17:26 -0700128 private static native boolean nativeClearContentFrameStats(long nativeObject);
129 private static native boolean nativeGetContentFrameStats(long nativeObject, WindowContentFrameStats outStats);
130 private static native boolean nativeClearAnimationFrameStats();
131 private static native boolean nativeGetAnimationFrameStats(WindowAnimationFrameStats outStats);
132
Mathias Agopian29479eb2013-02-14 14:36:04 -0800133 private static native IBinder nativeGetBuiltInDisplay(int physicalDisplayId);
134 private static native IBinder nativeCreateDisplay(String name, boolean secure);
Jesse Hall6a6bc212013-08-08 12:15:03 -0700135 private static native void nativeDestroyDisplay(IBinder displayToken);
Robert Carre13b58e2017-08-31 14:50:44 -0700136 private static native void nativeSetDisplaySurface(long transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000137 IBinder displayToken, long nativeSurfaceObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700138 private static native void nativeSetDisplayLayerStack(long transactionObj,
Mathias Agopian29479eb2013-02-14 14:36:04 -0800139 IBinder displayToken, int layerStack);
Robert Carre13b58e2017-08-31 14:50:44 -0700140 private static native void nativeSetDisplayProjection(long transactionObj,
Mathias Agopian29479eb2013-02-14 14:36:04 -0800141 IBinder displayToken, int orientation,
Jesse Hall6a6bc212013-08-08 12:15:03 -0700142 int l, int t, int r, int b,
Mathias Agopian29479eb2013-02-14 14:36:04 -0800143 int L, int T, int R, int B);
Robert Carre13b58e2017-08-31 14:50:44 -0700144 private static native void nativeSetDisplaySize(long transactionObj, IBinder displayToken,
145 int width, int height);
Dan Stoza00101052014-05-02 15:23:40 -0700146 private static native SurfaceControl.PhysicalDisplayInfo[] nativeGetDisplayConfigs(
147 IBinder displayToken);
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700148 private static native DisplayedContentSamplingAttributes
149 nativeGetDisplayedContentSamplingAttributes(IBinder displayToken);
150 private static native boolean nativeSetDisplayedContentSamplingEnabled(IBinder displayToken,
151 boolean enable, int componentMask, int maxFrames);
152 private static native DisplayedContentSample nativeGetDisplayedContentSample(
153 IBinder displayToken, long numFrames, long timestamp);
Dan Stoza00101052014-05-02 15:23:40 -0700154 private static native int nativeGetActiveConfig(IBinder displayToken);
155 private static native boolean nativeSetActiveConfig(IBinder displayToken, int id);
Michael Wright1c9977b2016-07-12 13:30:10 -0700156 private static native int[] nativeGetDisplayColorModes(IBinder displayToken);
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800157 private static native int[] nativeGetCompositionDataspaces();
Michael Wright1c9977b2016-07-12 13:30:10 -0700158 private static native int nativeGetActiveColorMode(IBinder displayToken);
159 private static native boolean nativeSetActiveColorMode(IBinder displayToken,
160 int colorMode);
Prashant Malanic55929a2014-05-25 01:59:21 -0700161 private static native void nativeSetDisplayPowerMode(
162 IBinder displayToken, int mode);
Robert Carre13b58e2017-08-31 14:50:44 -0700163 private static native void nativeDeferTransactionUntil(long transactionObj, long nativeObject,
Rob Carr64e516f2015-10-29 00:20:45 +0000164 IBinder handle, long frame);
Robert Carre13b58e2017-08-31 14:50:44 -0700165 private static native void nativeDeferTransactionUntilSurface(long transactionObj,
166 long nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -0800167 long surfaceObject, long frame);
Robert Carre13b58e2017-08-31 14:50:44 -0700168 private static native void nativeReparentChildren(long transactionObj, long nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -0800169 IBinder handle);
Robert Carre13b58e2017-08-31 14:50:44 -0700170 private static native void nativeReparent(long transactionObj, long nativeObject,
Robert Carr10584fa2019-01-14 15:55:19 -0800171 long newParentNativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700172 private static native void nativeSeverChildren(long transactionObj, long nativeObject);
173 private static native void nativeSetOverrideScalingMode(long transactionObj, long nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -0700174 int scalingMode);
Rob Carr64e516f2015-10-29 00:20:45 +0000175 private static native IBinder nativeGetHandle(long nativeObject);
Robert Carr6da3cc02016-06-16 15:17:07 -0700176 private static native boolean nativeGetTransformToDisplayInverse(long nativeObject);
177
Michael Wright9ff94c02016-03-30 18:05:40 -0700178 private static native Display.HdrCapabilities nativeGetHdrCapabilities(IBinder displayToken);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800179
Robert Carr788f5742018-07-30 17:46:45 -0700180 private static native void nativeSetInputWindowInfo(long transactionObj, long nativeObject,
181 InputWindowHandle handle);
chaviw59f532e2018-12-26 15:34:59 -0800182 private static native void nativeTransferTouchFocus(long transactionObj, IBinder fromToken,
183 IBinder toToken);
Peiyong Lin0ddb7d42019-01-16 13:25:09 -0800184 private static native boolean nativeGetProtectedContentSupport();
Mathias Agopian29479eb2013-02-14 14:36:04 -0800185
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800186 private final CloseGuard mCloseGuard = CloseGuard.get();
chaviwbeb7a0c2018-12-05 13:49:54 -0800187 private String mName;
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000188 long mNativeObject; // package visibility only for Surface.java access
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800189
Jorim Jaggia5e10572017-11-15 14:36:26 +0100190 // TODO: Move this to native.
191 private final Object mSizeLock = new Object();
192 @GuardedBy("mSizeLock")
193 private int mWidth;
194 @GuardedBy("mSizeLock")
195 private int mHeight;
196
Robert Carre13b58e2017-08-31 14:50:44 -0700197 static Transaction sGlobalTransaction;
198 static long sTransactionNestCount = 0;
199
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800200 /* flags used in constructor (keep in sync with ISurfaceComposerClient.h) */
201
202 /**
203 * Surface creation flag: Surface is created hidden
Robert Carra7827f72019-01-11 12:53:37 -0800204 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800205 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100206 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800207 public static final int HIDDEN = 0x00000004;
208
209 /**
210 * Surface creation flag: The surface contains secure content, special
211 * measures will be taken to disallow the surface's content to be copied
212 * from another process. In particular, screenshots and VNC servers will
213 * be disabled, but other measures can take place, for instance the
Jesse Hall6a6bc212013-08-08 12:15:03 -0700214 * surface might not be hardware accelerated.
Robert Carra7827f72019-01-11 12:53:37 -0800215 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800216 */
217 public static final int SECURE = 0x00000080;
218
219 /**
220 * Surface creation flag: Creates a surface where color components are interpreted
221 * as "non pre-multiplied" by their alpha channel. Of course this flag is
222 * meaningless for surfaces without an alpha channel. By default
223 * surfaces are pre-multiplied, which means that each color component is
224 * already multiplied by its alpha value. In this case the blending
225 * equation used is:
Andy McFadden314405b2014-01-29 17:18:05 -0800226 * <p>
227 * <code>DEST = SRC + DEST * (1-SRC_ALPHA)</code>
228 * <p>
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800229 * By contrast, non pre-multiplied surfaces use the following equation:
Andy McFadden314405b2014-01-29 17:18:05 -0800230 * <p>
231 * <code>DEST = SRC * SRC_ALPHA * DEST * (1-SRC_ALPHA)</code>
232 * <p>
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800233 * pre-multiplied surfaces must always be used if transparent pixels are
234 * composited on top of each-other into the surface. A pre-multiplied
235 * surface can never lower the value of the alpha component of a given
236 * pixel.
Andy McFadden314405b2014-01-29 17:18:05 -0800237 * <p>
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800238 * In some rare situations, a non pre-multiplied surface is preferable.
Robert Carra7827f72019-01-11 12:53:37 -0800239 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800240 */
241 public static final int NON_PREMULTIPLIED = 0x00000100;
242
243 /**
244 * Surface creation flag: Indicates that the surface must be considered opaque,
Robert Carre625fcf2017-09-01 12:36:28 -0700245 * even if its pixel format contains an alpha channel. This can be useful if an
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800246 * application needs full RGBA 8888 support for instance but will
247 * still draw every pixel opaque.
Andy McFadden314405b2014-01-29 17:18:05 -0800248 * <p>
249 * This flag is ignored if setAlpha() is used to make the surface non-opaque.
250 * Combined effects are (assuming a buffer format with an alpha channel):
251 * <ul>
252 * <li>OPAQUE + alpha(1.0) == opaque composition
253 * <li>OPAQUE + alpha(0.x) == blended composition
254 * <li>!OPAQUE + alpha(1.0) == blended composition
255 * <li>!OPAQUE + alpha(0.x) == blended composition
256 * </ul>
257 * If the underlying buffer lacks an alpha channel, the OPAQUE flag is effectively
258 * set automatically.
Robert Carra7827f72019-01-11 12:53:37 -0800259 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800260 */
261 public static final int OPAQUE = 0x00000400;
262
263 /**
264 * Surface creation flag: Application requires a hardware-protected path to an
265 * external display sink. If a hardware-protected path is not available,
266 * then this surface will not be displayed on the external sink.
267 *
Robert Carra7827f72019-01-11 12:53:37 -0800268 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800269 */
270 public static final int PROTECTED_APP = 0x00000800;
271
272 // 0x1000 is reserved for an independent DRM protected flag in framework
273
274 /**
Riley Andrews68eccda2014-07-07 11:47:35 -0700275 * Surface creation flag: Window represents a cursor glyph.
Robert Carra7827f72019-01-11 12:53:37 -0800276 * @hide
Riley Andrews68eccda2014-07-07 11:47:35 -0700277 */
278 public static final int CURSOR_WINDOW = 0x00002000;
279
280 /**
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800281 * Surface creation flag: Creates a normal surface.
282 * This is the default.
283 *
Robert Carra7827f72019-01-11 12:53:37 -0800284 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800285 */
286 public static final int FX_SURFACE_NORMAL = 0x00000000;
287
288 /**
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800289 * Surface creation flag: Creates a Dim surface.
290 * Everything behind this surface is dimmed by the amount specified
291 * in {@link #setAlpha}. It is an error to lock a Dim surface, since it
292 * doesn't have a backing store.
293 *
Robert Carra7827f72019-01-11 12:53:37 -0800294 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800295 */
296 public static final int FX_SURFACE_DIM = 0x00020000;
297
298 /**
Robert Carrb6cd6432018-08-13 13:01:47 -0700299 * Surface creation flag: Creates a container surface.
300 * This surface will have no buffers and will only be used
301 * as a container for other surfaces, or for its InputInfo.
Robert Carra7827f72019-01-11 12:53:37 -0800302 * @hide
Robert Carrb6cd6432018-08-13 13:01:47 -0700303 */
304 public static final int FX_SURFACE_CONTAINER = 0x00080000;
305
306 /**
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800307 * Mask used for FX values above.
308 *
Robert Carra7827f72019-01-11 12:53:37 -0800309 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800310 */
311 public static final int FX_SURFACE_MASK = 0x000F0000;
312
313 /* flags used with setFlags() (keep in sync with ISurfaceComposer.h) */
314
315 /**
316 * Surface flag: Hide the surface.
317 * Equivalent to calling hide().
Andy McFadden314405b2014-01-29 17:18:05 -0800318 * Updates the value set during Surface creation (see {@link #HIDDEN}).
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800319 */
Andy McFadden40b9ef12014-01-30 13:44:47 -0800320 private static final int SURFACE_HIDDEN = 0x01;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800321
Andy McFadden314405b2014-01-29 17:18:05 -0800322 /**
323 * Surface flag: composite without blending when possible.
324 * Updates the value set during Surface creation (see {@link #OPAQUE}).
325 */
Andy McFadden40b9ef12014-01-30 13:44:47 -0800326 private static final int SURFACE_OPAQUE = 0x02;
Andy McFadden314405b2014-01-29 17:18:05 -0800327
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800328
329 /* built-in physical display ids (keep in sync with ISurfaceComposer.h)
330 * these are different from the logical display ids used elsewhere in the framework */
331
332 /**
333 * Built-in physical display id: Main display.
Andy McFadden40b9ef12014-01-30 13:44:47 -0800334 * Use only with {@link SurfaceControl#getBuiltInDisplay(int)}.
Robert Carra7827f72019-01-11 12:53:37 -0800335 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800336 */
337 public static final int BUILT_IN_DISPLAY_ID_MAIN = 0;
338
339 /**
340 * Built-in physical display id: Attached HDMI display.
Andy McFadden40b9ef12014-01-30 13:44:47 -0800341 * Use only with {@link SurfaceControl#getBuiltInDisplay(int)}.
Robert Carra7827f72019-01-11 12:53:37 -0800342 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800343 */
344 public static final int BUILT_IN_DISPLAY_ID_HDMI = 1;
345
Robert Carr76907ee2019-01-11 13:38:19 -0800346 // Display power modes.
Prashant Malanic55929a2014-05-25 01:59:21 -0700347 /**
348 * Display power mode off: used while blanking the screen.
Jeff Brown5dc21912014-07-17 18:50:18 -0700349 * Use only with {@link SurfaceControl#setDisplayPowerMode}.
Robert Carra7827f72019-01-11 12:53:37 -0800350 * @hide
Prashant Malanic55929a2014-05-25 01:59:21 -0700351 */
352 public static final int POWER_MODE_OFF = 0;
353
354 /**
355 * Display power mode doze: used while putting the screen into low power mode.
Jeff Brown5dc21912014-07-17 18:50:18 -0700356 * Use only with {@link SurfaceControl#setDisplayPowerMode}.
Robert Carra7827f72019-01-11 12:53:37 -0800357 * @hide
Prashant Malanic55929a2014-05-25 01:59:21 -0700358 */
359 public static final int POWER_MODE_DOZE = 1;
360
361 /**
362 * Display power mode normal: used while unblanking the screen.
Jeff Brown5dc21912014-07-17 18:50:18 -0700363 * Use only with {@link SurfaceControl#setDisplayPowerMode}.
Robert Carra7827f72019-01-11 12:53:37 -0800364 * @hide
Prashant Malanic55929a2014-05-25 01:59:21 -0700365 */
366 public static final int POWER_MODE_NORMAL = 2;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800367
Jeff Brown5dc21912014-07-17 18:50:18 -0700368 /**
369 * Display power mode doze: used while putting the screen into a suspended
370 * low power mode. Use only with {@link SurfaceControl#setDisplayPowerMode}.
Robert Carra7827f72019-01-11 12:53:37 -0800371 * @hide
Jeff Brown5dc21912014-07-17 18:50:18 -0700372 */
373 public static final int POWER_MODE_DOZE_SUSPEND = 3;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800374
375 /**
Chris Phoenix10a4a642017-09-25 13:21:00 -0700376 * Display power mode on: used while putting the screen into a suspended
377 * full power mode. Use only with {@link SurfaceControl#setDisplayPowerMode}.
Robert Carra7827f72019-01-11 12:53:37 -0800378 * @hide
Chris Phoenix10a4a642017-09-25 13:21:00 -0700379 */
380 public static final int POWER_MODE_ON_SUSPEND = 4;
381
382 /**
Robert Carr132c9f52017-07-31 17:02:30 -0700383 * A value for windowType used to indicate that the window should be omitted from screenshots
384 * and display mirroring. A temporary workaround until we express such things with
385 * the hierarchy.
386 * TODO: b/64227542
387 * @hide
388 */
389 public static final int WINDOW_TYPE_DONT_SCREENSHOT = 441731;
390
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800391 /**
392 * internal representation of how to interpret pixel value, used only to convert to ColorSpace.
393 */
394 private static final int INTERNAL_DATASPACE_SRGB = 142671872;
395 private static final int INTERNAL_DATASPACE_DISPLAY_P3 = 143261696;
396 private static final int INTERNAL_DATASPACE_SCRGB = 411107328;
397
Robert Carreb344c72019-01-07 18:35:30 -0800398 private void assignNativeObject(long nativeObject) {
399 if (mNativeObject != 0) {
400 release();
401 }
402 mNativeObject = nativeObject;
403 }
404
Robert Carra7827f72019-01-11 12:53:37 -0800405 /**
406 * @hide
407 */
chaviwbeb7a0c2018-12-05 13:49:54 -0800408 public void copyFrom(SurfaceControl other) {
409 mName = other.mName;
410 mWidth = other.mWidth;
411 mHeight = other.mHeight;
Robert Carreb344c72019-01-07 18:35:30 -0800412 assignNativeObject(nativeCopyFromSurfaceControl(other.mNativeObject));
chaviwbeb7a0c2018-12-05 13:49:54 -0800413 }
414
Robert Carr132c9f52017-07-31 17:02:30 -0700415 /**
Robert Carre625fcf2017-09-01 12:36:28 -0700416 * Builder class for {@link SurfaceControl} objects.
417 */
418 public static class Builder {
419 private SurfaceSession mSession;
420 private int mFlags = HIDDEN;
421 private int mWidth;
422 private int mHeight;
423 private int mFormat = PixelFormat.OPAQUE;
424 private String mName;
425 private SurfaceControl mParent;
rongliu3dac23b2018-03-14 15:43:40 -0700426 private int mWindowType = -1;
427 private int mOwnerUid = -1;
Robert Carre625fcf2017-09-01 12:36:28 -0700428
429 /**
430 * Begin building a SurfaceControl with a given {@link SurfaceSession}.
431 *
432 * @param session The {@link SurfaceSession} with which to eventually construct the surface.
Robert Carra7827f72019-01-11 12:53:37 -0800433 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700434 */
435 public Builder(SurfaceSession session) {
436 mSession = session;
437 }
438
439 /**
Robert Carr76907ee2019-01-11 13:38:19 -0800440 * Begin building a SurfaceControl.
441 */
442 public Builder() {
443 }
444
445 /**
446 * Construct a new {@link SurfaceControl} with the set parameters. The builder
447 * remains valid.
Robert Carre625fcf2017-09-01 12:36:28 -0700448 */
449 public SurfaceControl build() {
Vishnu Naire86bd982018-11-28 13:23:17 -0800450 if (mWidth < 0 || mHeight < 0) {
Robert Carre625fcf2017-09-01 12:36:28 -0700451 throw new IllegalArgumentException(
Vishnu Naire86bd982018-11-28 13:23:17 -0800452 "width and height must be positive or unset");
453 }
454 if ((mWidth > 0 || mHeight > 0) && (isColorLayerSet() || isContainerLayerSet())) {
455 throw new IllegalArgumentException(
456 "Only buffer layers can set a valid buffer size.");
Robert Carre625fcf2017-09-01 12:36:28 -0700457 }
458 return new SurfaceControl(mSession, mName, mWidth, mHeight, mFormat,
459 mFlags, mParent, mWindowType, mOwnerUid);
460 }
461
462 /**
463 * Set a debugging-name for the SurfaceControl.
464 *
465 * @param name A name to identify the Surface in debugging.
466 */
467 public Builder setName(String name) {
468 mName = name;
469 return this;
470 }
471
472 /**
473 * Set the initial size of the controlled surface's buffers in pixels.
474 *
475 * @param width The buffer width in pixels.
476 * @param height The buffer height in pixels.
477 */
Robert Carr76907ee2019-01-11 13:38:19 -0800478 public Builder setBufferSize(@IntRange(from = 0) int width,
479 @IntRange(from = 0) int height) {
Vishnu Naire86bd982018-11-28 13:23:17 -0800480 if (width < 0 || height < 0) {
Robert Carre625fcf2017-09-01 12:36:28 -0700481 throw new IllegalArgumentException(
482 "width and height must be positive");
483 }
484 mWidth = width;
485 mHeight = height;
486 return this;
487 }
488
489 /**
490 * Set the pixel format of the controlled surface's buffers, using constants from
491 * {@link android.graphics.PixelFormat}.
492 */
Robert Carr76907ee2019-01-11 13:38:19 -0800493 @NonNull
Robert Carre625fcf2017-09-01 12:36:28 -0700494 public Builder setFormat(@PixelFormat.Format int format) {
495 mFormat = format;
496 return this;
497 }
498
499 /**
500 * Specify if the app requires a hardware-protected path to
501 * an external display sync. If protected content is enabled, but
502 * such a path is not available, then the controlled Surface will
503 * not be displayed.
504 *
505 * @param protectedContent Whether to require a protected sink.
Robert Carra7827f72019-01-11 12:53:37 -0800506 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700507 */
Robert Carr76907ee2019-01-11 13:38:19 -0800508 @NonNull
Robert Carre625fcf2017-09-01 12:36:28 -0700509 public Builder setProtected(boolean protectedContent) {
510 if (protectedContent) {
511 mFlags |= PROTECTED_APP;
512 } else {
513 mFlags &= ~PROTECTED_APP;
514 }
515 return this;
516 }
517
518 /**
519 * Specify whether the Surface contains secure content. If true, the system
520 * will prevent the surfaces content from being copied by another process. In
521 * particular screenshots and VNC servers will be disabled. This is however
522 * not a complete prevention of readback as {@link #setProtected}.
Robert Carra7827f72019-01-11 12:53:37 -0800523 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700524 */
Robert Carr76907ee2019-01-11 13:38:19 -0800525 @NonNull
Robert Carre625fcf2017-09-01 12:36:28 -0700526 public Builder setSecure(boolean secure) {
527 if (secure) {
528 mFlags |= SECURE;
529 } else {
530 mFlags &= ~SECURE;
531 }
532 return this;
533 }
534
535 /**
536 * Indicates whether the surface must be considered opaque,
537 * even if its pixel format is set to translucent. This can be useful if an
538 * application needs full RGBA 8888 support for instance but will
539 * still draw every pixel opaque.
540 * <p>
541 * This flag only determines whether opacity will be sampled from the alpha channel.
542 * Plane-alpha from calls to setAlpha() can still result in blended composition
543 * regardless of the opaque setting.
544 *
545 * Combined effects are (assuming a buffer format with an alpha channel):
546 * <ul>
547 * <li>OPAQUE + alpha(1.0) == opaque composition
548 * <li>OPAQUE + alpha(0.x) == blended composition
549 * <li>OPAQUE + alpha(0.0) == no composition
550 * <li>!OPAQUE + alpha(1.0) == blended composition
551 * <li>!OPAQUE + alpha(0.x) == blended composition
552 * <li>!OPAQUE + alpha(0.0) == no composition
553 * </ul>
554 * If the underlying buffer lacks an alpha channel, it is as if setOpaque(true)
555 * were set automatically.
556 * @param opaque Whether the Surface is OPAQUE.
557 */
Robert Carr76907ee2019-01-11 13:38:19 -0800558 @NonNull
Robert Carre625fcf2017-09-01 12:36:28 -0700559 public Builder setOpaque(boolean opaque) {
560 if (opaque) {
561 mFlags |= OPAQUE;
562 } else {
563 mFlags &= ~OPAQUE;
564 }
565 return this;
566 }
567
568 /**
569 * Set a parent surface for our new SurfaceControl.
570 *
571 * Child surfaces are constrained to the onscreen region of their parent.
572 * Furthermore they stack relatively in Z order, and inherit the transformation
573 * of the parent.
574 *
575 * @param parent The parent control.
576 */
Robert Carr76907ee2019-01-11 13:38:19 -0800577 @NonNull
578 public Builder setParent(@Nullable SurfaceControl parent) {
Robert Carre625fcf2017-09-01 12:36:28 -0700579 mParent = parent;
580 return this;
581 }
582
583 /**
584 * Set surface metadata.
585 *
586 * Currently these are window-types as per {@link WindowManager.LayoutParams} and
587 * owner UIDs. Child surfaces inherit their parents
588 * metadata so only the WindowManager needs to set this on root Surfaces.
589 *
590 * @param windowType A window-type
591 * @param ownerUid UID of the window owner.
Robert Carra7827f72019-01-11 12:53:37 -0800592 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700593 */
594 public Builder setMetadata(int windowType, int ownerUid) {
595 if (UserHandle.getAppId(Process.myUid()) != Process.SYSTEM_UID) {
596 throw new UnsupportedOperationException(
597 "It only makes sense to set Surface metadata from the WindowManager");
598 }
599 mWindowType = windowType;
600 mOwnerUid = ownerUid;
601 return this;
602 }
603
604 /**
605 * Indicate whether a 'ColorLayer' is to be constructed.
606 *
607 * Color layers will not have an associated BufferQueue and will instead always render a
608 * solid color (that is, solid before plane alpha). Currently that color is black.
609 *
610 * @param isColorLayer Whether to create a color layer.
Robert Carra7827f72019-01-11 12:53:37 -0800611 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700612 */
613 public Builder setColorLayer(boolean isColorLayer) {
614 if (isColorLayer) {
615 mFlags |= FX_SURFACE_DIM;
616 } else {
617 mFlags &= ~FX_SURFACE_DIM;
618 }
619 return this;
620 }
621
Vishnu Naire86bd982018-11-28 13:23:17 -0800622 private boolean isColorLayerSet() {
623 return (mFlags & FX_SURFACE_DIM) == FX_SURFACE_DIM;
624 }
625
Robert Carre625fcf2017-09-01 12:36:28 -0700626 /**
Robert Carrb6cd6432018-08-13 13:01:47 -0700627 * Indicates whether a 'ContainerLayer' is to be constructed.
628 *
629 * Container layers will not be rendered in any fashion and instead are used
630 * as a parent of renderable layers.
631 *
632 * @param isContainerLayer Whether to create a container layer.
Robert Carra7827f72019-01-11 12:53:37 -0800633 * @hide
Robert Carrb6cd6432018-08-13 13:01:47 -0700634 */
635 public Builder setContainerLayer(boolean isContainerLayer) {
636 if (isContainerLayer) {
637 mFlags |= FX_SURFACE_CONTAINER;
638 } else {
639 mFlags &= ~FX_SURFACE_CONTAINER;
640 }
641 return this;
642 }
643
Vishnu Naire86bd982018-11-28 13:23:17 -0800644 private boolean isContainerLayerSet() {
645 return (mFlags & FX_SURFACE_CONTAINER) == FX_SURFACE_CONTAINER;
646 }
647
Robert Carrb6cd6432018-08-13 13:01:47 -0700648 /**
Robert Carre625fcf2017-09-01 12:36:28 -0700649 * Set 'Surface creation flags' such as {@link HIDDEN}, {@link SECURE}.
650 *
651 * TODO: Finish conversion to individual builder methods?
652 * @param flags The combined flags
Robert Carra7827f72019-01-11 12:53:37 -0800653 * @hide
Robert Carre625fcf2017-09-01 12:36:28 -0700654 */
655 public Builder setFlags(int flags) {
656 mFlags = flags;
657 return this;
658 }
659 }
660
661 /**
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800662 * Create a surface with a name.
Andy McFadden314405b2014-01-29 17:18:05 -0800663 * <p>
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800664 * The surface creation flags specify what kind of surface to create and
665 * certain options such as whether the surface can be assumed to be opaque
666 * and whether it should be initially hidden. Surfaces should always be
667 * created with the {@link #HIDDEN} flag set to ensure that they are not
668 * made visible prematurely before all of the surface's properties have been
669 * configured.
Andy McFadden314405b2014-01-29 17:18:05 -0800670 * <p>
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800671 * Good practice is to first create the surface with the {@link #HIDDEN} flag
672 * specified, open a transaction, set the surface layer, layer stack, alpha,
673 * and position, call {@link #show} if appropriate, and close the transaction.
Vishnu Naird454442d2018-11-13 13:51:01 -0800674 * <p>
675 * Bounds of the surface is determined by its crop and its buffer size. If the
676 * surface has no buffer or crop, the surface is boundless and only constrained
677 * by the size of its parent bounds.
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800678 *
679 * @param session The surface session, must not be null.
680 * @param name The surface name, must not be null.
681 * @param w The surface initial width.
682 * @param h The surface initial height.
683 * @param flags The surface creation flags. Should always include {@link #HIDDEN}
684 * in the creation flags.
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500685 * @param windowType The type of the window as specified in WindowManager.java.
686 * @param ownerUid A unique per-app ID.
Igor Murashkina86ab6402013-08-30 12:58:36 -0700687 *
688 * @throws throws OutOfResourcesException If the SurfaceControl cannot be created.
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800689 */
Robert Carre625fcf2017-09-01 12:36:28 -0700690 private SurfaceControl(SurfaceSession session, String name, int w, int h, int format, int flags,
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500691 SurfaceControl parent, int windowType, int ownerUid)
Robert Carrb0f39362018-03-14 13:52:25 -0700692 throws OutOfResourcesException, IllegalArgumentException {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800693 if (name == null) {
694 throw new IllegalArgumentException("name must not be null");
695 }
696
697 if ((flags & SurfaceControl.HIDDEN) == 0) {
698 Log.w(TAG, "Surfaces should always be created with the HIDDEN flag set "
699 + "to ensure that they are not made visible prematurely before "
700 + "all of the surface's properties have been configured. "
701 + "Set the other properties and make the surface visible within "
702 + "a transaction. New surface name: " + name,
703 new Throwable());
704 }
705
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800706 mName = name;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100707 mWidth = w;
708 mHeight = h;
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500709 mNativeObject = nativeCreate(session, name, w, h, format, flags,
710 parent != null ? parent.mNativeObject : 0, windowType, ownerUid);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800711 if (mNativeObject == 0) {
712 throw new OutOfResourcesException(
713 "Couldn't allocate SurfaceControl native object");
714 }
Jesse Hall6a6bc212013-08-08 12:15:03 -0700715
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800716 mCloseGuard.open("release");
717 }
Jesse Hall6a6bc212013-08-08 12:15:03 -0700718
Robert Carra7827f72019-01-11 12:53:37 -0800719 /** This is a transfer constructor, useful for transferring a live SurfaceControl native
720 * object to another Java wrapper which could have some different behavior, e.g.
721 * event logging.
722 * @hide
723 */
Robert Carr3b716242016-08-16 16:02:21 -0700724 public SurfaceControl(SurfaceControl other) {
725 mName = other.mName;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100726 mWidth = other.mWidth;
727 mHeight = other.mHeight;
Robert Carr3b716242016-08-16 16:02:21 -0700728 mNativeObject = other.mNativeObject;
729 other.mCloseGuard.close();
730 other.mNativeObject = 0;
731 mCloseGuard.open("release");
732 }
733
Jorim Jaggi06975df2017-12-01 14:52:13 +0100734 private SurfaceControl(Parcel in) {
chaviwbeb7a0c2018-12-05 13:49:54 -0800735 readFromParcel(in);
736 mCloseGuard.open("release");
737 }
738
Robert Carra7827f72019-01-11 12:53:37 -0800739 /**
740 * @hide
741 */
chaviwbeb7a0c2018-12-05 13:49:54 -0800742 public SurfaceControl() {
743 mCloseGuard.open("release");
744 }
745
746 public void readFromParcel(Parcel in) {
747 if (in == null) {
748 throw new IllegalArgumentException("source must not be null");
749 }
750
Jorim Jaggi06975df2017-12-01 14:52:13 +0100751 mName = in.readString();
Jorim Jaggia5e10572017-11-15 14:36:26 +0100752 mWidth = in.readInt();
753 mHeight = in.readInt();
Robert Carr5fea55b2018-12-10 13:05:52 -0800754
Robert Carreb344c72019-01-07 18:35:30 -0800755 long object = 0;
Robert Carr5fea55b2018-12-10 13:05:52 -0800756 if (in.readInt() != 0) {
Robert Carreb344c72019-01-07 18:35:30 -0800757 object = nativeReadFromParcel(in);
Jorim Jaggi06975df2017-12-01 14:52:13 +0100758 }
Robert Carreb344c72019-01-07 18:35:30 -0800759 assignNativeObject(object);
Jorim Jaggi06975df2017-12-01 14:52:13 +0100760 }
761
762 @Override
763 public int describeContents() {
764 return 0;
765 }
766
767 @Override
768 public void writeToParcel(Parcel dest, int flags) {
769 dest.writeString(mName);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100770 dest.writeInt(mWidth);
771 dest.writeInt(mHeight);
Robert Carr5fea55b2018-12-10 13:05:52 -0800772 if (mNativeObject == 0) {
773 dest.writeInt(0);
774 } else {
775 dest.writeInt(1);
776 }
Jorim Jaggi06975df2017-12-01 14:52:13 +0100777 nativeWriteToParcel(mNativeObject, dest);
Robert Carr5fea55b2018-12-10 13:05:52 -0800778
779 if ((flags & Parcelable.PARCELABLE_WRITE_RETURN_VALUE) != 0) {
780 release();
781 }
Jorim Jaggi06975df2017-12-01 14:52:13 +0100782 }
783
Vishnu Nair04ab4392018-01-10 11:00:06 -0800784 /**
785 * Write to a protocol buffer output stream. Protocol buffer message definition is at {@link
786 * android.view.SurfaceControlProto}.
787 *
788 * @param proto Stream to write the SurfaceControl object to.
789 * @param fieldId Field Id of the SurfaceControl as defined in the parent message.
790 * @hide
791 */
792 public void writeToProto(ProtoOutputStream proto, long fieldId) {
793 final long token = proto.start(fieldId);
794 proto.write(HASH_CODE, System.identityHashCode(this));
795 proto.write(NAME, mName);
796 proto.end(token);
797 }
798
Jorim Jaggi06975df2017-12-01 14:52:13 +0100799 public static final Creator<SurfaceControl> CREATOR
800 = new Creator<SurfaceControl>() {
801 public SurfaceControl createFromParcel(Parcel in) {
802 return new SurfaceControl(in);
803 }
804
805 public SurfaceControl[] newArray(int size) {
806 return new SurfaceControl[size];
807 }
808 };
809
Robert Carra7827f72019-01-11 12:53:37 -0800810 /**
811 * @hide
812 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800813 @Override
814 protected void finalize() throws Throwable {
815 try {
816 if (mCloseGuard != null) {
817 mCloseGuard.warnIfOpen();
818 }
819 if (mNativeObject != 0) {
820 nativeRelease(mNativeObject);
821 }
822 } finally {
823 super.finalize();
824 }
825 }
826
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800827 /**
Robert Carr76907ee2019-01-11 13:38:19 -0800828 * Release the local reference to the server-side surface. The surface
829 * may continue to exist on-screen as long as its parent continues
830 * to exist. To explicitly remove a surface from the screen use
831 * {@link Transaction#reparent} with a null-parent.
832 *
833 * Always call release() when you're done with a SurfaceControl.
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800834 */
835 public void release() {
836 if (mNativeObject != 0) {
837 nativeRelease(mNativeObject);
838 mNativeObject = 0;
839 }
840 mCloseGuard.close();
841 }
842
843 /**
844 * Free all server-side state associated with this surface and
845 * release this object's reference. This method can only be
846 * called from the process that created the service.
Robert Carra7827f72019-01-11 12:53:37 -0800847 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800848 */
849 public void destroy() {
850 if (mNativeObject != 0) {
851 nativeDestroy(mNativeObject);
852 mNativeObject = 0;
853 }
854 mCloseGuard.close();
855 }
856
Chong Zhang47e36a32016-02-29 16:44:33 -0800857 /**
858 * Disconnect any client still connected to the surface.
Robert Carra7827f72019-01-11 12:53:37 -0800859 * @hide
Chong Zhang47e36a32016-02-29 16:44:33 -0800860 */
861 public void disconnect() {
862 if (mNativeObject != 0) {
863 nativeDisconnect(mNativeObject);
864 }
865 }
866
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800867 private void checkNotReleased() {
868 if (mNativeObject == 0) throw new NullPointerException(
869 "mNativeObject is null. Have you called release() already?");
870 }
Jesse Hall6a6bc212013-08-08 12:15:03 -0700871
Robert Carra7827f72019-01-11 12:53:37 -0800872 /**
Robert Carr76907ee2019-01-11 13:38:19 -0800873 * Check whether this instance points to a valid layer with the system-compositor. For
874 * example this may be false if construction failed, or the layer was released.
875 *
876 * @return Whether this SurfaceControl is valid.
Robert Carra7827f72019-01-11 12:53:37 -0800877 */
Robert Carr5fea55b2018-12-10 13:05:52 -0800878 public boolean isValid() {
879 return mNativeObject != 0;
880 }
881
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800882 /*
883 * set surface parameters.
884 * needs to be inside open/closeTransaction block
885 */
886
Robert Carra7827f72019-01-11 12:53:37 -0800887 /** start a transaction
888 * @hide
889 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100890 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800891 public static void openTransaction() {
Robert Carre13b58e2017-08-31 14:50:44 -0700892 synchronized (SurfaceControl.class) {
893 if (sGlobalTransaction == null) {
894 sGlobalTransaction = new Transaction();
895 }
896 synchronized(SurfaceControl.class) {
897 sTransactionNestCount++;
898 }
899 }
900 }
901
902 private static void closeTransaction(boolean sync) {
903 synchronized(SurfaceControl.class) {
904 if (sTransactionNestCount == 0) {
905 Log.e(TAG, "Call to SurfaceControl.closeTransaction without matching openTransaction");
906 } else if (--sTransactionNestCount > 0) {
907 return;
908 }
909 sGlobalTransaction.apply(sync);
910 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800911 }
912
Robert Carrb1579c82017-09-05 14:54:47 -0700913 /**
914 * Merge the supplied transaction in to the deprecated "global" transaction.
915 * This clears the supplied transaction in an identical fashion to {@link Transaction#merge}.
916 * <p>
917 * This is a utility for interop with legacy-code and will go away with the Global Transaction.
Robert Carra7827f72019-01-11 12:53:37 -0800918 * @hide
Robert Carrb1579c82017-09-05 14:54:47 -0700919 */
920 @Deprecated
921 public static void mergeToGlobalTransaction(Transaction t) {
Robert Carrc5fc4612017-12-05 11:55:40 -0800922 synchronized(SurfaceControl.class) {
Robert Carrb1579c82017-09-05 14:54:47 -0700923 sGlobalTransaction.merge(t);
924 }
925 }
926
Robert Carra7827f72019-01-11 12:53:37 -0800927 /** end a transaction
928 * @hide
929 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100930 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800931 public static void closeTransaction() {
Robert Carre13b58e2017-08-31 14:50:44 -0700932 closeTransaction(false);
Robert Carre9953b12016-05-23 20:52:04 -0700933 }
934
Robert Carra7827f72019-01-11 12:53:37 -0800935 /**
936 * @hide
937 */
Robert Carre9953b12016-05-23 20:52:04 -0700938 public static void closeTransactionSync() {
Robert Carre13b58e2017-08-31 14:50:44 -0700939 closeTransaction(true);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800940 }
941
Robert Carra7827f72019-01-11 12:53:37 -0800942 /**
943 * @hide
944 */
Rob Carr64e516f2015-10-29 00:20:45 +0000945 public void deferTransactionUntil(IBinder handle, long frame) {
Robert Carr024378c2018-02-27 11:21:05 -0800946 synchronized(SurfaceControl.class) {
947 sGlobalTransaction.deferTransactionUntil(this, handle, frame);
Robert Carrd5c7dd62017-03-08 10:39:30 -0800948 }
949 }
950
Robert Carra7827f72019-01-11 12:53:37 -0800951 /**
952 * @hide
953 */
Robert Carrd5c7dd62017-03-08 10:39:30 -0800954 public void deferTransactionUntil(Surface barrier, long frame) {
Robert Carr024378c2018-02-27 11:21:05 -0800955 synchronized(SurfaceControl.class) {
956 sGlobalTransaction.deferTransactionUntilSurface(this, barrier, frame);
Robert Carrd5c7dd62017-03-08 10:39:30 -0800957 }
958 }
959
Robert Carra7827f72019-01-11 12:53:37 -0800960 /**
961 * @hide
962 */
Robert Carrd5c7dd62017-03-08 10:39:30 -0800963 public void reparentChildren(IBinder newParentHandle) {
Robert Carre13b58e2017-08-31 14:50:44 -0700964 synchronized(SurfaceControl.class) {
965 sGlobalTransaction.reparentChildren(this, newParentHandle);
966 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800967 }
968
Robert Carra7827f72019-01-11 12:53:37 -0800969 /**
970 * @hide
971 */
Robert Carr10584fa2019-01-14 15:55:19 -0800972 public void reparent(SurfaceControl newParent) {
Robert Carre13b58e2017-08-31 14:50:44 -0700973 synchronized(SurfaceControl.class) {
Robert Carr10584fa2019-01-14 15:55:19 -0800974 sGlobalTransaction.reparent(this, newParent);
Robert Carre13b58e2017-08-31 14:50:44 -0700975 }
chaviw63542382017-08-17 17:39:29 -0700976 }
977
Robert Carra7827f72019-01-11 12:53:37 -0800978 /**
979 * @hide
980 */
Robert Carrd5c7dd62017-03-08 10:39:30 -0800981 public void detachChildren() {
Robert Carre13b58e2017-08-31 14:50:44 -0700982 synchronized(SurfaceControl.class) {
983 sGlobalTransaction.detachChildren(this);
984 }
Rob Carr64e516f2015-10-29 00:20:45 +0000985 }
986
Robert Carra7827f72019-01-11 12:53:37 -0800987 /**
988 * @hide
989 */
Robert Carr1ca6a332016-04-11 18:00:43 -0700990 public void setOverrideScalingMode(int scalingMode) {
991 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -0700992 synchronized(SurfaceControl.class) {
993 sGlobalTransaction.setOverrideScalingMode(this, scalingMode);
994 }
Robert Carr1ca6a332016-04-11 18:00:43 -0700995 }
996
Robert Carra7827f72019-01-11 12:53:37 -0800997 /**
998 * @hide
999 */
Rob Carr64e516f2015-10-29 00:20:45 +00001000 public IBinder getHandle() {
1001 return nativeGetHandle(mNativeObject);
1002 }
1003
Robert Carra7827f72019-01-11 12:53:37 -08001004 /**
1005 * @hide
1006 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001007 public static void setAnimationTransaction() {
Robert Carre13b58e2017-08-31 14:50:44 -07001008 synchronized (SurfaceControl.class) {
1009 sGlobalTransaction.setAnimationTransaction();
1010 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001011 }
1012
Robert Carra7827f72019-01-11 12:53:37 -08001013 /**
1014 * @hide
1015 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001016 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001017 public void setLayer(int zorder) {
1018 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001019 synchronized(SurfaceControl.class) {
1020 sGlobalTransaction.setLayer(this, zorder);
1021 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001022 }
1023
Robert Carra7827f72019-01-11 12:53:37 -08001024 /**
1025 * @hide
1026 */
Robert Carr77e34942017-10-18 19:13:56 -07001027 public void setRelativeLayer(SurfaceControl relativeTo, int zorder) {
Robert Carraf422a82017-04-10 18:34:33 -07001028 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001029 synchronized(SurfaceControl.class) {
1030 sGlobalTransaction.setRelativeLayer(this, relativeTo, zorder);
1031 }
Robert Carraf422a82017-04-10 18:34:33 -07001032 }
1033
Robert Carra7827f72019-01-11 12:53:37 -08001034 /**
1035 * @hide
1036 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001037 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001038 public void setPosition(float x, float y) {
1039 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001040 synchronized(SurfaceControl.class) {
1041 sGlobalTransaction.setPosition(this, x, y);
1042 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001043 }
1044
Robert Carra7827f72019-01-11 12:53:37 -08001045 /**
1046 * @hide
1047 */
Robert Carr6da3cc02016-06-16 15:17:07 -07001048 public void setGeometryAppliesWithResize() {
Robert Carra9408d42016-06-03 13:28:48 -07001049 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001050 synchronized(SurfaceControl.class) {
1051 sGlobalTransaction.setGeometryAppliesWithResize(this);
1052 }
Robert Carra9408d42016-06-03 13:28:48 -07001053 }
1054
Robert Carra7827f72019-01-11 12:53:37 -08001055 /**
1056 * @hide
1057 */
Vishnu Naire86bd982018-11-28 13:23:17 -08001058 public void setBufferSize(int w, int h) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001059 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001060 synchronized(SurfaceControl.class) {
Vishnu Naire86bd982018-11-28 13:23:17 -08001061 sGlobalTransaction.setBufferSize(this, w, h);
Robert Carre13b58e2017-08-31 14:50:44 -07001062 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001063 }
1064
Robert Carra7827f72019-01-11 12:53:37 -08001065 /**
1066 * @hide
1067 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001068 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001069 public void hide() {
1070 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001071 synchronized(SurfaceControl.class) {
1072 sGlobalTransaction.hide(this);
1073 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001074 }
1075
Robert Carra7827f72019-01-11 12:53:37 -08001076 /**
1077 * @hide
1078 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001079 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001080 public void show() {
1081 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001082 synchronized(SurfaceControl.class) {
1083 sGlobalTransaction.show(this);
1084 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001085 }
1086
Robert Carra7827f72019-01-11 12:53:37 -08001087 /**
1088 * @hide
1089 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001090 public void setTransparentRegionHint(Region region) {
1091 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001092 synchronized(SurfaceControl.class) {
1093 sGlobalTransaction.setTransparentRegionHint(this, region);
1094 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001095 }
1096
Robert Carra7827f72019-01-11 12:53:37 -08001097 /**
1098 * @hide
1099 */
Svetoslav1376d602014-03-13 11:17:26 -07001100 public boolean clearContentFrameStats() {
1101 checkNotReleased();
1102 return nativeClearContentFrameStats(mNativeObject);
1103 }
1104
Robert Carra7827f72019-01-11 12:53:37 -08001105 /**
1106 * @hide
1107 */
Svetoslav1376d602014-03-13 11:17:26 -07001108 public boolean getContentFrameStats(WindowContentFrameStats outStats) {
1109 checkNotReleased();
1110 return nativeGetContentFrameStats(mNativeObject, outStats);
1111 }
1112
Robert Carra7827f72019-01-11 12:53:37 -08001113 /**
1114 * @hide
1115 */
Svetoslav1376d602014-03-13 11:17:26 -07001116 public static boolean clearAnimationFrameStats() {
1117 return nativeClearAnimationFrameStats();
1118 }
1119
Robert Carra7827f72019-01-11 12:53:37 -08001120 /**
1121 * @hide
1122 */
Svetoslav1376d602014-03-13 11:17:26 -07001123 public static boolean getAnimationFrameStats(WindowAnimationFrameStats outStats) {
1124 return nativeGetAnimationFrameStats(outStats);
1125 }
1126
Robert Carra7827f72019-01-11 12:53:37 -08001127 /**
1128 * @hide
1129 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001130 public void setAlpha(float alpha) {
1131 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001132 synchronized(SurfaceControl.class) {
1133 sGlobalTransaction.setAlpha(this, alpha);
1134 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001135 }
1136
Robert Carra7827f72019-01-11 12:53:37 -08001137 /**
1138 * @hide
1139 */
chaviw0dd03f52017-08-25 12:15:26 -07001140 public void setColor(@Size(3) float[] color) {
1141 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001142 synchronized (SurfaceControl.class) {
1143 sGlobalTransaction.setColor(this, color);
1144 }
chaviw0dd03f52017-08-25 12:15:26 -07001145 }
1146
Robert Carra7827f72019-01-11 12:53:37 -08001147 /**
1148 * @hide
1149 */
Robert Carr0edf18f2017-02-21 20:01:47 -08001150 public void setMatrix(float dsdx, float dtdx, float dtdy, float dsdy) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001151 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001152 synchronized(SurfaceControl.class) {
1153 sGlobalTransaction.setMatrix(this, dsdx, dtdx, dtdy, dsdy);
1154 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001155 }
1156
Jorim Jaggi21c39a72017-10-20 15:47:51 +02001157 /**
1158 * Sets the transform and position of a {@link SurfaceControl} from a 3x3 transformation matrix.
1159 *
1160 * @param matrix The matrix to apply.
1161 * @param float9 An array of 9 floats to be used to extract the values from the matrix.
Robert Carra7827f72019-01-11 12:53:37 -08001162 * @hide
Jorim Jaggi21c39a72017-10-20 15:47:51 +02001163 */
1164 public void setMatrix(Matrix matrix, float[] float9) {
1165 checkNotReleased();
1166 matrix.getValues(float9);
1167 synchronized (SurfaceControl.class) {
1168 sGlobalTransaction.setMatrix(this, float9[MSCALE_X], float9[MSKEW_Y],
1169 float9[MSKEW_X], float9[MSCALE_Y]);
1170 sGlobalTransaction.setPosition(this, float9[MTRANS_X], float9[MTRANS_Y]);
1171 }
1172 }
1173
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001174 /**
1175 * Sets the color transform for the Surface.
1176 * @param matrix A float array with 9 values represents a 3x3 transform matrix
1177 * @param translation A float array with 3 values represents a translation vector
Robert Carra7827f72019-01-11 12:53:37 -08001178 * @hide
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001179 */
1180 public void setColorTransform(@Size(9) float[] matrix, @Size(3) float[] translation) {
1181 checkNotReleased();
1182 synchronized (SurfaceControl.class) {
1183 sGlobalTransaction.setColorTransform(this, matrix, translation);
1184 }
1185 }
1186
Vishnu Naird454442d2018-11-13 13:51:01 -08001187 /**
1188 * Bounds the surface and its children to the bounds specified. Size of the surface will be
1189 * ignored and only the crop and buffer size will be used to determine the bounds of the
1190 * surface. If no crop is specified and the surface has no buffer, the surface bounds is only
1191 * constrained by the size of its parent bounds.
1192 *
1193 * @param crop Bounds of the crop to apply.
Robert Carra7827f72019-01-11 12:53:37 -08001194 * @hide
Vishnu Naird454442d2018-11-13 13:51:01 -08001195 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001196 public void setWindowCrop(Rect crop) {
1197 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001198 synchronized (SurfaceControl.class) {
1199 sGlobalTransaction.setWindowCrop(this, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001200 }
1201 }
1202
Vishnu Naird454442d2018-11-13 13:51:01 -08001203 /**
1204 * Same as {@link SurfaceControl#setWindowCrop(Rect)} but sets the crop rect top left at 0, 0.
1205 *
1206 * @param width width of crop rect
1207 * @param height height of crop rect
Robert Carra7827f72019-01-11 12:53:37 -08001208 * @hide
Vishnu Naird454442d2018-11-13 13:51:01 -08001209 */
1210 public void setWindowCrop(int width, int height) {
1211 checkNotReleased();
1212 synchronized (SurfaceControl.class) {
1213 sGlobalTransaction.setWindowCrop(this, width, height);
1214 }
1215 }
1216
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001217 /**
1218 * Sets the corner radius of a {@link SurfaceControl}.
1219 *
1220 * @param cornerRadius Corner radius in pixels.
Robert Carra7827f72019-01-11 12:53:37 -08001221 * @hide
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001222 */
1223 public void setCornerRadius(float cornerRadius) {
1224 checkNotReleased();
1225 synchronized (SurfaceControl.class) {
1226 sGlobalTransaction.setCornerRadius(this, cornerRadius);
1227 }
1228 }
1229
Robert Carra7827f72019-01-11 12:53:37 -08001230 /**
1231 * @hide
1232 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001233 public void setLayerStack(int layerStack) {
1234 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001235 synchronized(SurfaceControl.class) {
1236 sGlobalTransaction.setLayerStack(this, layerStack);
1237 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001238 }
1239
Robert Carra7827f72019-01-11 12:53:37 -08001240 /**
1241 * @hide
1242 */
Andy McFadden314405b2014-01-29 17:18:05 -08001243 public void setOpaque(boolean isOpaque) {
1244 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001245
1246 synchronized (SurfaceControl.class) {
1247 sGlobalTransaction.setOpaque(this, isOpaque);
Andy McFadden314405b2014-01-29 17:18:05 -08001248 }
1249 }
1250
Robert Carra7827f72019-01-11 12:53:37 -08001251 /**
1252 * @hide
1253 */
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001254 public void setSecure(boolean isSecure) {
1255 checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001256
1257 synchronized (SurfaceControl.class) {
1258 sGlobalTransaction.setSecure(this, isSecure);
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001259 }
1260 }
1261
Robert Carra7827f72019-01-11 12:53:37 -08001262 /**
1263 * @hide
1264 */
Jorim Jaggia5e10572017-11-15 14:36:26 +01001265 public int getWidth() {
1266 synchronized (mSizeLock) {
1267 return mWidth;
1268 }
1269 }
1270
Robert Carra7827f72019-01-11 12:53:37 -08001271 /**
1272 * @hide
1273 */
Jorim Jaggia5e10572017-11-15 14:36:26 +01001274 public int getHeight() {
1275 synchronized (mSizeLock) {
1276 return mHeight;
1277 }
1278 }
1279
Robert Carre13b58e2017-08-31 14:50:44 -07001280 @Override
1281 public String toString() {
1282 return "Surface(name=" + mName + ")/@0x" +
1283 Integer.toHexString(System.identityHashCode(this));
1284 }
1285
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001286 /*
1287 * set display parameters.
1288 * needs to be inside open/closeTransaction block
1289 */
1290
1291 /**
1292 * Describes the properties of a physical display known to surface flinger.
Robert Carr76907ee2019-01-11 13:38:19 -08001293 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001294 */
1295 public static final class PhysicalDisplayInfo {
Robert Carra7827f72019-01-11 12:53:37 -08001296 /**
1297 * @hide
1298 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001299 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001300 public int width;
Robert Carra7827f72019-01-11 12:53:37 -08001301
1302 /**
1303 * @hide
1304 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001305 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001306 public int height;
Robert Carra7827f72019-01-11 12:53:37 -08001307
1308 /**
1309 * @hide
1310 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001311 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001312 public float refreshRate;
Robert Carra7827f72019-01-11 12:53:37 -08001313
1314 /**
1315 * @hide
1316 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001317 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001318 public float density;
Robert Carra7827f72019-01-11 12:53:37 -08001319
1320 /**
1321 * @hide
1322 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001323 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001324 public float xDpi;
Robert Carra7827f72019-01-11 12:53:37 -08001325
1326 /**
1327 * @hide
1328 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001329 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001330 public float yDpi;
Robert Carra7827f72019-01-11 12:53:37 -08001331
1332 /**
1333 * @hide
1334 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001335 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001336 public boolean secure;
Robert Carra7827f72019-01-11 12:53:37 -08001337
1338 /**
1339 * @hide
1340 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001341 @UnsupportedAppUsage
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001342 public long appVsyncOffsetNanos;
Robert Carra7827f72019-01-11 12:53:37 -08001343
1344 /**
1345 * @hide
1346 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001347 @UnsupportedAppUsage
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001348 public long presentationDeadlineNanos;
Jesse Hall6a6bc212013-08-08 12:15:03 -07001349
Robert Carra7827f72019-01-11 12:53:37 -08001350 /**
1351 * @hide
1352 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001353 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001354 public PhysicalDisplayInfo() {
1355 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001356
Robert Carra7827f72019-01-11 12:53:37 -08001357 /**
1358 * @hide
1359 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001360 public PhysicalDisplayInfo(PhysicalDisplayInfo other) {
1361 copyFrom(other);
1362 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001363
Robert Carra7827f72019-01-11 12:53:37 -08001364 /**
1365 * @hide
1366 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001367 @Override
1368 public boolean equals(Object o) {
1369 return o instanceof PhysicalDisplayInfo && equals((PhysicalDisplayInfo)o);
1370 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001371
Robert Carra7827f72019-01-11 12:53:37 -08001372 /**
1373 * @hide
1374 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001375 public boolean equals(PhysicalDisplayInfo other) {
1376 return other != null
1377 && width == other.width
1378 && height == other.height
1379 && refreshRate == other.refreshRate
1380 && density == other.density
1381 && xDpi == other.xDpi
1382 && yDpi == other.yDpi
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001383 && secure == other.secure
1384 && appVsyncOffsetNanos == other.appVsyncOffsetNanos
Michael Wright1c9977b2016-07-12 13:30:10 -07001385 && presentationDeadlineNanos == other.presentationDeadlineNanos;
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001386 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001387
Robert Carra7827f72019-01-11 12:53:37 -08001388 /**
1389 * @hide
1390 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001391 @Override
1392 public int hashCode() {
1393 return 0; // don't care
1394 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001395
Robert Carra7827f72019-01-11 12:53:37 -08001396 /**
1397 * @hide
1398 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001399 public void copyFrom(PhysicalDisplayInfo other) {
1400 width = other.width;
1401 height = other.height;
1402 refreshRate = other.refreshRate;
1403 density = other.density;
1404 xDpi = other.xDpi;
1405 yDpi = other.yDpi;
1406 secure = other.secure;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001407 appVsyncOffsetNanos = other.appVsyncOffsetNanos;
1408 presentationDeadlineNanos = other.presentationDeadlineNanos;
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001409 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001410
Robert Carra7827f72019-01-11 12:53:37 -08001411 /**
1412 * @hide
1413 */
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001414 @Override
1415 public String toString() {
1416 return "PhysicalDisplayInfo{" + width + " x " + height + ", " + refreshRate + " fps, "
1417 + "density " + density + ", " + xDpi + " x " + yDpi + " dpi, secure " + secure
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001418 + ", appVsyncOffset " + appVsyncOffsetNanos
Michael Wright1c9977b2016-07-12 13:30:10 -07001419 + ", bufferDeadline " + presentationDeadlineNanos + "}";
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001420 }
1421 }
1422
Robert Carra7827f72019-01-11 12:53:37 -08001423 /**
1424 * @hide
1425 */
Prashant Malanic55929a2014-05-25 01:59:21 -07001426 public static void setDisplayPowerMode(IBinder displayToken, int mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001427 if (displayToken == null) {
1428 throw new IllegalArgumentException("displayToken must not be null");
1429 }
Prashant Malanic55929a2014-05-25 01:59:21 -07001430 nativeSetDisplayPowerMode(displayToken, mode);
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001431 }
1432
Robert Carra7827f72019-01-11 12:53:37 -08001433 /**
1434 * @hide
1435 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001436 @UnsupportedAppUsage
Dan Stoza00101052014-05-02 15:23:40 -07001437 public static SurfaceControl.PhysicalDisplayInfo[] getDisplayConfigs(IBinder displayToken) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001438 if (displayToken == null) {
1439 throw new IllegalArgumentException("displayToken must not be null");
1440 }
Dan Stoza00101052014-05-02 15:23:40 -07001441 return nativeGetDisplayConfigs(displayToken);
1442 }
1443
Robert Carra7827f72019-01-11 12:53:37 -08001444 /**
1445 * @hide
1446 */
Dan Stoza00101052014-05-02 15:23:40 -07001447 public static int getActiveConfig(IBinder displayToken) {
1448 if (displayToken == null) {
1449 throw new IllegalArgumentException("displayToken must not be null");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001450 }
Dan Stoza00101052014-05-02 15:23:40 -07001451 return nativeGetActiveConfig(displayToken);
1452 }
1453
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001454 /**
1455 * @hide
1456 */
1457 public static DisplayedContentSamplingAttributes getDisplayedContentSamplingAttributes(
1458 IBinder displayToken) {
1459 if (displayToken == null) {
1460 throw new IllegalArgumentException("displayToken must not be null");
1461 }
1462 return nativeGetDisplayedContentSamplingAttributes(displayToken);
1463 }
1464
1465 /**
1466 * @hide
1467 */
1468 public static boolean setDisplayedContentSamplingEnabled(
1469 IBinder displayToken, boolean enable, int componentMask, int maxFrames) {
1470 if (displayToken == null) {
1471 throw new IllegalArgumentException("displayToken must not be null");
1472 }
1473 final int maxColorComponents = 4;
1474 if ((componentMask >> maxColorComponents) != 0) {
1475 throw new IllegalArgumentException("invalid componentMask when enabling sampling");
1476 }
1477 return nativeSetDisplayedContentSamplingEnabled(
1478 displayToken, enable, componentMask, maxFrames);
1479 }
1480
1481 /**
1482 * @hide
1483 */
1484 public static DisplayedContentSample getDisplayedContentSample(
1485 IBinder displayToken, long maxFrames, long timestamp) {
1486 if (displayToken == null) {
1487 throw new IllegalArgumentException("displayToken must not be null");
1488 }
1489 return nativeGetDisplayedContentSample(displayToken, maxFrames, timestamp);
1490 }
1491
1492
Robert Carra7827f72019-01-11 12:53:37 -08001493 /**
1494 * @hide
1495 */
Dan Stoza00101052014-05-02 15:23:40 -07001496 public static boolean setActiveConfig(IBinder displayToken, int id) {
1497 if (displayToken == null) {
1498 throw new IllegalArgumentException("displayToken must not be null");
1499 }
1500 return nativeSetActiveConfig(displayToken, id);
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001501 }
1502
Robert Carra7827f72019-01-11 12:53:37 -08001503 /**
1504 * @hide
1505 */
Michael Wright1c9977b2016-07-12 13:30:10 -07001506 public static int[] getDisplayColorModes(IBinder displayToken) {
1507 if (displayToken == null) {
1508 throw new IllegalArgumentException("displayToken must not be null");
1509 }
1510 return nativeGetDisplayColorModes(displayToken);
1511 }
1512
Robert Carra7827f72019-01-11 12:53:37 -08001513 /**
1514 * @hide
1515 */
Michael Wright1c9977b2016-07-12 13:30:10 -07001516 public static int getActiveColorMode(IBinder displayToken) {
1517 if (displayToken == null) {
1518 throw new IllegalArgumentException("displayToken must not be null");
1519 }
1520 return nativeGetActiveColorMode(displayToken);
1521 }
1522
Robert Carra7827f72019-01-11 12:53:37 -08001523 /**
1524 * @hide
1525 */
Michael Wright1c9977b2016-07-12 13:30:10 -07001526 public static boolean setActiveColorMode(IBinder displayToken, int colorMode) {
1527 if (displayToken == null) {
1528 throw new IllegalArgumentException("displayToken must not be null");
1529 }
1530 return nativeSetActiveColorMode(displayToken, colorMode);
1531 }
1532
Robert Carra7827f72019-01-11 12:53:37 -08001533 /**
Peiyong Lin5f4a5682019-01-17 11:37:07 -08001534 * Returns an array of color spaces with 2 elements. The first color space is the
1535 * default color space and second one is wide color gamut color space.
1536 * @hide
1537 */
1538 public static ColorSpace[] getCompositionColorSpaces() {
1539 int[] dataspaces = nativeGetCompositionDataspaces();
1540 ColorSpace srgb = ColorSpace.get(ColorSpace.Named.SRGB);
1541 ColorSpace[] colorSpaces = { srgb, srgb };
1542 if (dataspaces.length == 2) {
1543 for (int i = 0; i < 2; ++i) {
1544 switch(dataspaces[i]) {
1545 case INTERNAL_DATASPACE_DISPLAY_P3:
1546 colorSpaces[i] = ColorSpace.get(ColorSpace.Named.DISPLAY_P3);
1547 break;
1548 case INTERNAL_DATASPACE_SCRGB:
1549 colorSpaces[i] = ColorSpace.get(ColorSpace.Named.EXTENDED_SRGB);
1550 break;
1551 case INTERNAL_DATASPACE_SRGB:
1552 // Other dataspace is not recognized, use SRGB color space instead,
1553 // the default value of the array is already SRGB, thus do nothing.
1554 default:
1555 break;
1556 }
1557 }
1558 }
1559 return colorSpaces;
1560 }
1561
1562 /**
Robert Carra7827f72019-01-11 12:53:37 -08001563 * @hide
1564 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001565 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001566 public static void setDisplayProjection(IBinder displayToken,
1567 int orientation, Rect layerStackRect, Rect displayRect) {
Robert Carre13b58e2017-08-31 14:50:44 -07001568 synchronized (SurfaceControl.class) {
1569 sGlobalTransaction.setDisplayProjection(displayToken, orientation,
1570 layerStackRect, displayRect);
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001571 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001572 }
1573
Robert Carra7827f72019-01-11 12:53:37 -08001574 /**
1575 * @hide
1576 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001577 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001578 public static void setDisplayLayerStack(IBinder displayToken, int layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -07001579 synchronized (SurfaceControl.class) {
1580 sGlobalTransaction.setDisplayLayerStack(displayToken, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001581 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001582 }
1583
Robert Carra7827f72019-01-11 12:53:37 -08001584 /**
1585 * @hide
1586 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001587 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001588 public static void setDisplaySurface(IBinder displayToken, Surface surface) {
Robert Carre13b58e2017-08-31 14:50:44 -07001589 synchronized (SurfaceControl.class) {
1590 sGlobalTransaction.setDisplaySurface(displayToken, surface);
Jeff Brownfc0ebd72013-04-30 16:33:00 -07001591 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001592 }
1593
Robert Carra7827f72019-01-11 12:53:37 -08001594 /**
1595 * @hide
1596 */
Michael Wright01e840f2014-06-26 16:03:25 -07001597 public static void setDisplaySize(IBinder displayToken, int width, int height) {
Robert Carre13b58e2017-08-31 14:50:44 -07001598 synchronized (SurfaceControl.class) {
1599 sGlobalTransaction.setDisplaySize(displayToken, width, height);
Michael Wright01e840f2014-06-26 16:03:25 -07001600 }
Michael Wright01e840f2014-06-26 16:03:25 -07001601 }
1602
Robert Carra7827f72019-01-11 12:53:37 -08001603 /**
1604 * @hide
1605 */
Michael Wright9ff94c02016-03-30 18:05:40 -07001606 public static Display.HdrCapabilities getHdrCapabilities(IBinder displayToken) {
1607 if (displayToken == null) {
1608 throw new IllegalArgumentException("displayToken must not be null");
1609 }
1610 return nativeGetHdrCapabilities(displayToken);
1611 }
1612
Robert Carra7827f72019-01-11 12:53:37 -08001613 /**
1614 * @hide
1615 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001616 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001617 public static IBinder createDisplay(String name, boolean secure) {
1618 if (name == null) {
1619 throw new IllegalArgumentException("name must not be null");
1620 }
1621 return nativeCreateDisplay(name, secure);
1622 }
1623
Robert Carra7827f72019-01-11 12:53:37 -08001624 /**
1625 * @hide
1626 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001627 @UnsupportedAppUsage
Jesse Hall6a6bc212013-08-08 12:15:03 -07001628 public static void destroyDisplay(IBinder displayToken) {
1629 if (displayToken == null) {
1630 throw new IllegalArgumentException("displayToken must not be null");
1631 }
1632 nativeDestroyDisplay(displayToken);
1633 }
1634
Robert Carra7827f72019-01-11 12:53:37 -08001635 /**
1636 * @hide
1637 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001638 @UnsupportedAppUsage
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001639 public static IBinder getBuiltInDisplay(int builtInDisplayId) {
1640 return nativeGetBuiltInDisplay(builtInDisplayId);
1641 }
1642
Mathias Agopian0449a402013-03-01 23:01:51 -08001643 /**
chaviw08520a02018-09-10 16:44:56 -07001644 * @see SurfaceControl#screenshot(IBinder, Surface, Rect, int, int, boolean, int)
Robert Carra7827f72019-01-11 12:53:37 -08001645 * @hide
Mathias Agopian0449a402013-03-01 23:01:51 -08001646 */
1647 public static void screenshot(IBinder display, Surface consumer) {
chaviw08520a02018-09-10 16:44:56 -07001648 screenshot(display, consumer, new Rect(), 0, 0, false, 0);
1649 }
1650
1651 /**
1652 * Copy the current screen contents into the provided {@link Surface}
1653 *
1654 * @param consumer The {@link Surface} to take the screenshot into.
1655 * @see SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)
Robert Carra7827f72019-01-11 12:53:37 -08001656 * @hide
chaviw08520a02018-09-10 16:44:56 -07001657 */
1658 public static void screenshot(IBinder display, Surface consumer, Rect sourceCrop, int width,
1659 int height, boolean useIdentityTransform, int rotation) {
1660 if (consumer == null) {
1661 throw new IllegalArgumentException("consumer must not be null");
1662 }
1663
1664 final GraphicBuffer buffer = screenshotToBuffer(display, sourceCrop, width, height,
1665 useIdentityTransform, rotation);
1666 try {
1667 consumer.attachAndQueueBuffer(buffer);
1668 } catch (RuntimeException e) {
1669 Log.w(TAG, "Failed to take screenshot - " + e.getMessage());
1670 }
1671 }
1672
1673 /**
1674 * @see SurfaceControl#screenshot(Rect, int, int, boolean, int)}
Robert Carra7827f72019-01-11 12:53:37 -08001675 * @hide
chaviw08520a02018-09-10 16:44:56 -07001676 */
1677 @UnsupportedAppUsage
1678 public static Bitmap screenshot(Rect sourceCrop, int width, int height, int rotation) {
1679 return screenshot(sourceCrop, width, height, false, rotation);
Mathias Agopian0449a402013-03-01 23:01:51 -08001680 }
1681
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001682 /**
chaviw1da9cd92017-12-06 10:48:11 -08001683 * Copy the current screen contents into a hardware bitmap and return it.
1684 * Note: If you want to modify the Bitmap in software, you will need to copy the Bitmap into
1685 * a software Bitmap using {@link Bitmap#copy(Bitmap.Config, boolean)}
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001686 *
chaviw08520a02018-09-10 16:44:56 -07001687 * CAVEAT: Versions of screenshot that return a {@link Bitmap} can be extremely slow; avoid use
1688 * unless absolutely necessary; prefer the versions that use a {@link Surface} such as
1689 * {@link SurfaceControl#screenshot(IBinder, Surface)} or {@link GraphicBuffer} such as
1690 * {@link SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)}.
Mathias Agopian0449a402013-03-01 23:01:51 -08001691 *
chaviw08520a02018-09-10 16:44:56 -07001692 * @see SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)}
Robert Carra7827f72019-01-11 12:53:37 -08001693 * @hide
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001694 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001695 @UnsupportedAppUsage
Dan Stoza9890e3412014-05-22 16:12:54 -07001696 public static Bitmap screenshot(Rect sourceCrop, int width, int height,
chaviw08520a02018-09-10 16:44:56 -07001697 boolean useIdentityTransform, int rotation) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001698 // TODO: should take the display as a parameter
Mathias Agopian0449a402013-03-01 23:01:51 -08001699 IBinder displayToken = SurfaceControl.getBuiltInDisplay(
1700 SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN);
chaviwa69e0a72017-11-29 17:55:12 -08001701 if (rotation == ROTATION_90 || rotation == ROTATION_270) {
1702 rotation = (rotation == ROTATION_90) ? ROTATION_270 : ROTATION_90;
1703 }
1704
1705 SurfaceControl.rotateCropForSF(sourceCrop, rotation);
chaviw08520a02018-09-10 16:44:56 -07001706 final GraphicBuffer buffer = screenshotToBuffer(displayToken, sourceCrop, width, height,
1707 useIdentityTransform, rotation);
1708
1709 if (buffer == null) {
1710 Log.w(TAG, "Failed to take screenshot");
1711 return null;
1712 }
1713 return Bitmap.createHardwareBitmap(buffer);
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001714 }
Jesse Hall6a6bc212013-08-08 12:15:03 -07001715
chaviw08520a02018-09-10 16:44:56 -07001716 /**
1717 * Captures all the surfaces in a display and returns a {@link GraphicBuffer} with the content.
1718 *
1719 * @param display The display to take the screenshot of.
1720 * @param sourceCrop The portion of the screen to capture into the Bitmap; caller may
1721 * pass in 'new Rect()' if no cropping is desired.
1722 * @param width The desired width of the returned bitmap; the raw screen will be
1723 * scaled down to this size; caller may pass in 0 if no scaling is
1724 * desired.
1725 * @param height The desired height of the returned bitmap; the raw screen will
1726 * be scaled down to this size; caller may pass in 0 if no scaling
1727 * is desired.
1728 * @param useIdentityTransform Replace whatever transformation (rotation, scaling, translation)
1729 * the surface layers are currently using with the identity
1730 * transformation while taking the screenshot.
1731 * @param rotation Apply a custom clockwise rotation to the screenshot, i.e.
1732 * Surface.ROTATION_0,90,180,270. SurfaceFlinger will always take
1733 * screenshots in its native portrait orientation by default, so
1734 * this is useful for returning screenshots that are independent of
1735 * device orientation.
1736 * @return Returns a GraphicBuffer that contains the captured content.
Robert Carra7827f72019-01-11 12:53:37 -08001737 * @hide
chaviw08520a02018-09-10 16:44:56 -07001738 */
1739 public static GraphicBuffer screenshotToBuffer(IBinder display, Rect sourceCrop, int width,
1740 int height, boolean useIdentityTransform, int rotation) {
Mathias Agopian0449a402013-03-01 23:01:51 -08001741 if (display == null) {
1742 throw new IllegalArgumentException("displayToken must not be null");
1743 }
chaviw08520a02018-09-10 16:44:56 -07001744
1745 return nativeScreenshot(display, sourceCrop, width, height, useIdentityTransform, rotation);
Mathias Agopian0449a402013-03-01 23:01:51 -08001746 }
Robert Carre13b58e2017-08-31 14:50:44 -07001747
chaviwa69e0a72017-11-29 17:55:12 -08001748 private static void rotateCropForSF(Rect crop, int rot) {
1749 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
1750 int tmp = crop.top;
1751 crop.top = crop.left;
1752 crop.left = tmp;
1753 tmp = crop.right;
1754 crop.right = crop.bottom;
1755 crop.bottom = tmp;
1756 }
1757 }
1758
chaviw1cda84c2017-10-23 16:47:10 -07001759 /**
chaviw1da9cd92017-12-06 10:48:11 -08001760 * Captures a layer and its children and returns a {@link GraphicBuffer} with the content.
chaviw1cda84c2017-10-23 16:47:10 -07001761 *
1762 * @param layerHandleToken The root layer to capture.
chaviwfbe47df2017-11-10 16:14:49 -08001763 * @param sourceCrop The portion of the root surface to capture; caller may pass in 'new
1764 * Rect()' or null if no cropping is desired.
1765 * @param frameScale The desired scale of the returned buffer; the raw
1766 * screen will be scaled up/down.
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001767 *
1768 * @return Returns a GraphicBuffer that contains the layer capture.
Robert Carra7827f72019-01-11 12:53:37 -08001769 * @hide
chaviw1cda84c2017-10-23 16:47:10 -07001770 */
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001771 public static GraphicBuffer captureLayers(IBinder layerHandleToken, Rect sourceCrop,
chaviwfbe47df2017-11-10 16:14:49 -08001772 float frameScale) {
1773 return nativeCaptureLayers(layerHandleToken, sourceCrop, frameScale);
chaviw1cda84c2017-10-23 16:47:10 -07001774 }
1775
Robert Carra7827f72019-01-11 12:53:37 -08001776 /**
Peiyong Lin0ddb7d42019-01-16 13:25:09 -08001777 * Returns whether protected content is supported in GPU composition.
1778 * @hide
1779 */
1780 public static boolean getProtectedContentSupport() {
1781 return nativeGetProtectedContentSupport();
1782 }
1783
1784 /**
Robert Carr76907ee2019-01-11 13:38:19 -08001785 * An atomic set of changes to a set of SurfaceControl.
Robert Carra7827f72019-01-11 12:53:37 -08001786 */
Robert Carre13b58e2017-08-31 14:50:44 -07001787 public static class Transaction implements Closeable {
Robert Carr76907ee2019-01-11 13:38:19 -08001788 /**
1789 * @hide
1790 */
Robert Carre13b58e2017-08-31 14:50:44 -07001791 public static final NativeAllocationRegistry sRegistry = new NativeAllocationRegistry(
1792 Transaction.class.getClassLoader(),
1793 nativeGetNativeTransactionFinalizer(), 512);
1794 private long mNativeObject;
1795
Jorim Jaggia5e10572017-11-15 14:36:26 +01001796 private final ArrayMap<SurfaceControl, Point> mResizedSurfaces = new ArrayMap<>();
Robert Carre13b58e2017-08-31 14:50:44 -07001797 Runnable mFreeNativeResources;
1798
Robert Carra7827f72019-01-11 12:53:37 -08001799 /**
Robert Carr76907ee2019-01-11 13:38:19 -08001800 * Open a new transaction object. The transaction may be filed with commands to
1801 * manipulate {@link SurfaceControl} instances, and then applied atomically with
1802 * {@link #apply}. Eventually the user should invoke {@link #close}, when the object
1803 * is no longer required. Note however that re-using a transaction after a call to apply
1804 * is allowed as a convenience.
Robert Carra7827f72019-01-11 12:53:37 -08001805 */
Robert Carre13b58e2017-08-31 14:50:44 -07001806 public Transaction() {
1807 mNativeObject = nativeCreateTransaction();
1808 mFreeNativeResources
1809 = sRegistry.registerNativeAllocation(this, mNativeObject);
1810 }
1811
1812 /**
1813 * Apply the transaction, clearing it's state, and making it usable
1814 * as a new transaction.
1815 */
1816 public void apply() {
1817 apply(false);
1818 }
1819
1820 /**
1821 * Close the transaction, if the transaction was not already applied this will cancel the
1822 * transaction.
1823 */
1824 @Override
1825 public void close() {
1826 mFreeNativeResources.run();
1827 mNativeObject = 0;
1828 }
1829
1830 /**
1831 * Jankier version of apply. Avoid use (b/28068298).
Robert Carra7827f72019-01-11 12:53:37 -08001832 * @hide
Robert Carre13b58e2017-08-31 14:50:44 -07001833 */
1834 public void apply(boolean sync) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01001835 applyResizedSurfaces();
Robert Carre13b58e2017-08-31 14:50:44 -07001836 nativeApplyTransaction(mNativeObject, sync);
1837 }
1838
Jorim Jaggia5e10572017-11-15 14:36:26 +01001839 private void applyResizedSurfaces() {
1840 for (int i = mResizedSurfaces.size() - 1; i >= 0; i--) {
1841 final Point size = mResizedSurfaces.valueAt(i);
1842 final SurfaceControl surfaceControl = mResizedSurfaces.keyAt(i);
1843 synchronized (surfaceControl.mSizeLock) {
1844 surfaceControl.mWidth = size.x;
1845 surfaceControl.mHeight = size.y;
1846 }
1847 }
1848 mResizedSurfaces.clear();
1849 }
1850
Robert Carra7827f72019-01-11 12:53:37 -08001851 /**
Robert Carr76907ee2019-01-11 13:38:19 -08001852 * Toggle the visibility of a given Layer and it's sub-tree.
1853 *
1854 * @param sc The SurfaceControl for which to set the visibility
1855 * @param visible The new visibility
1856 * @return This transaction object.
1857 */
1858 @NonNull
1859 public Transaction setVisibility(@NonNull SurfaceControl sc, boolean visible) {
1860 sc.checkNotReleased();
1861 if (visible) {
1862 return show(sc);
1863 } else {
1864 return hide(sc);
1865 }
1866 }
1867
1868 /**
1869 * Request that a given surface and it's sub-tree be shown.
1870 *
1871 * @param sc The surface to show.
1872 * @return This transaction.
Robert Carra7827f72019-01-11 12:53:37 -08001873 * @hide
1874 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001875 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07001876 public Transaction show(SurfaceControl sc) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02001877 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001878 nativeSetFlags(mNativeObject, sc.mNativeObject, 0, SURFACE_HIDDEN);
1879 return this;
1880 }
1881
Robert Carra7827f72019-01-11 12:53:37 -08001882 /**
Robert Carr76907ee2019-01-11 13:38:19 -08001883 * Request that a given surface and it's sub-tree be hidden.
1884 *
1885 * @param sc The surface to hidden.
1886 * @return This transaction.
Robert Carra7827f72019-01-11 12:53:37 -08001887 * @hide
1888 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001889 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07001890 public Transaction hide(SurfaceControl sc) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02001891 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001892 nativeSetFlags(mNativeObject, sc.mNativeObject, SURFACE_HIDDEN, SURFACE_HIDDEN);
1893 return this;
1894 }
1895
Robert Carra7827f72019-01-11 12:53:37 -08001896 /**
1897 * @hide
1898 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001899 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07001900 public Transaction setPosition(SurfaceControl sc, float x, float y) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02001901 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001902 nativeSetPosition(mNativeObject, sc.mNativeObject, x, y);
1903 return this;
1904 }
1905
Robert Carra7827f72019-01-11 12:53:37 -08001906 /**
Robert Carr76907ee2019-01-11 13:38:19 -08001907 * Set the default buffer size for the SurfaceControl, if there is an
1908 * {@link Surface} assosciated with the control, then
1909 * this will be the default size for buffers dequeued from it.
1910 * @param sc The surface to set the buffer size for.
1911 * @param w The default width
1912 * @param h The default height
1913 * @return This Transaction
Robert Carra7827f72019-01-11 12:53:37 -08001914 */
Robert Carr76907ee2019-01-11 13:38:19 -08001915 @NonNull
1916 public Transaction setBufferSize(@NonNull SurfaceControl sc,
1917 @IntRange(from = 0) int w, @IntRange(from = 0) int h) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02001918 sc.checkNotReleased();
Jorim Jaggia5e10572017-11-15 14:36:26 +01001919 mResizedSurfaces.put(sc, new Point(w, h));
Jorim Jaggidfc27372017-10-27 17:47:49 +02001920 nativeSetSize(mNativeObject, sc.mNativeObject, w, h);
Robert Carre13b58e2017-08-31 14:50:44 -07001921 return this;
1922 }
1923
Robert Carra7827f72019-01-11 12:53:37 -08001924 /**
Robert Carr76907ee2019-01-11 13:38:19 -08001925 * Set the Z-order for a given SurfaceControl, relative to it's siblings.
1926 * If two siblings share the same Z order the ordering is undefined. Surfaces
1927 * with a negative Z will be placed below the parent surface.
1928 *
1929 * @param sc The SurfaceControl to set the Z order on
1930 * @param z The Z-order
1931 * @return This Transaction.
Robert Carra7827f72019-01-11 12:53:37 -08001932 */
Robert Carr76907ee2019-01-11 13:38:19 -08001933 @NonNull
1934 public Transaction setLayer(@NonNull SurfaceControl sc,
1935 @IntRange(from = Integer.MIN_VALUE, to = Integer.MAX_VALUE) int z) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02001936 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001937 nativeSetLayer(mNativeObject, sc.mNativeObject, z);
1938 return this;
1939 }
1940
Robert Carra7827f72019-01-11 12:53:37 -08001941 /**
1942 * @hide
1943 */
Robert Carr77e34942017-10-18 19:13:56 -07001944 public Transaction setRelativeLayer(SurfaceControl sc, SurfaceControl relativeTo, int z) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02001945 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001946 nativeSetRelativeLayer(mNativeObject, sc.mNativeObject,
Robert Carr77e34942017-10-18 19:13:56 -07001947 relativeTo.getHandle(), z);
Robert Carre13b58e2017-08-31 14:50:44 -07001948 return this;
1949 }
1950
Robert Carra7827f72019-01-11 12:53:37 -08001951 /**
1952 * @hide
1953 */
Robert Carre13b58e2017-08-31 14:50:44 -07001954 public Transaction setTransparentRegionHint(SurfaceControl sc, Region transparentRegion) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02001955 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001956 nativeSetTransparentRegionHint(mNativeObject,
1957 sc.mNativeObject, transparentRegion);
1958 return this;
1959 }
1960
Robert Carra7827f72019-01-11 12:53:37 -08001961 /**
Robert Carr76907ee2019-01-11 13:38:19 -08001962 * Set the alpha for a given surface. If the alpha is non-zero the SurfaceControl
1963 * will be blended with the Surfaces under it according to the specified ratio.
1964 *
1965 * @param sc The given SurfaceControl.
1966 * @param alpha The alpha to set.
Robert Carra7827f72019-01-11 12:53:37 -08001967 */
Robert Carr76907ee2019-01-11 13:38:19 -08001968 @NonNull
1969 public Transaction setAlpha(@NonNull SurfaceControl sc,
1970 @FloatRange(from = 0.0, to = 1.0) float alpha) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02001971 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07001972 nativeSetAlpha(mNativeObject, sc.mNativeObject, alpha);
1973 return this;
1974 }
1975
Robert Carra7827f72019-01-11 12:53:37 -08001976 /**
1977 * @hide
1978 */
Robert Carr788f5742018-07-30 17:46:45 -07001979 public Transaction setInputWindowInfo(SurfaceControl sc, InputWindowHandle handle) {
1980 sc.checkNotReleased();
1981 nativeSetInputWindowInfo(mNativeObject, sc.mNativeObject, handle);
1982 return this;
1983 }
1984
chaviw59f532e2018-12-26 15:34:59 -08001985 /**
1986 * Transfers touch focus from one window to another. It is possible for multiple windows to
1987 * have touch focus if they support split touch dispatch
1988 * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this
1989 * method only transfers touch focus of the specified window without affecting
1990 * other windows that may also have touch focus at the same time.
1991 * @param fromToken The token of a window that currently has touch focus.
1992 * @param toToken The token of the window that should receive touch focus in
1993 * place of the first.
Robert Carra7827f72019-01-11 12:53:37 -08001994 * @hide
chaviw59f532e2018-12-26 15:34:59 -08001995 */
1996 public Transaction transferTouchFocus(IBinder fromToken, IBinder toToken) {
1997 nativeTransferTouchFocus(mNativeObject, fromToken, toToken);
1998 return this;
1999 }
2000
Robert Carra7827f72019-01-11 12:53:37 -08002001 /**
Robert Carr76907ee2019-01-11 13:38:19 -08002002 * Specify how the buffer assosciated with this Surface is mapped in to the
2003 * parent coordinate space. The source frame will be scaled to fit the destination
2004 * frame, after being rotated according to the orientation parameter.
2005 *
2006 * @param sc The SurfaceControl to specify the geometry of
2007 * @param sourceCrop The source rectangle in buffer space. Or null for the entire buffer.
2008 * @param destFrame The destination rectangle in parent space. Or null for the source frame.
2009 * @param orientation The buffer rotation
2010 * @return This transaction object.
2011 */
2012 @NonNull
2013 public Transaction setGeometry(@NonNull SurfaceControl sc, @Nullable Rect sourceCrop,
2014 @Nullable Rect destFrame, @Surface.Rotation int orientation) {
2015 sc.checkNotReleased();
2016 nativeSetGeometry(mNativeObject, sc.mNativeObject, sourceCrop, destFrame, orientation);
2017 return this;
2018 }
2019
2020 /**
Robert Carra7827f72019-01-11 12:53:37 -08002021 * @hide
2022 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002023 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07002024 public Transaction setMatrix(SurfaceControl sc,
2025 float dsdx, float dtdx, float dtdy, float dsdy) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002026 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002027 nativeSetMatrix(mNativeObject, sc.mNativeObject,
2028 dsdx, dtdx, dtdy, dsdy);
2029 return this;
2030 }
2031
Robert Carra7827f72019-01-11 12:53:37 -08002032 /**
2033 * @hide
2034 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002035 @UnsupportedAppUsage
Jorim Jaggi21c39a72017-10-20 15:47:51 +02002036 public Transaction setMatrix(SurfaceControl sc, Matrix matrix, float[] float9) {
2037 matrix.getValues(float9);
2038 setMatrix(sc, float9[MSCALE_X], float9[MSKEW_Y],
2039 float9[MSKEW_X], float9[MSCALE_Y]);
2040 setPosition(sc, float9[MTRANS_X], float9[MTRANS_Y]);
2041 return this;
2042 }
2043
Peiyong Lin52bb6b42018-10-01 11:40:50 -07002044 /**
2045 * Sets the color transform for the Surface.
2046 * @param matrix A float array with 9 values represents a 3x3 transform matrix
2047 * @param translation A float array with 3 values represents a translation vector
Robert Carra7827f72019-01-11 12:53:37 -08002048 * @hide
Peiyong Lin52bb6b42018-10-01 11:40:50 -07002049 */
2050 public Transaction setColorTransform(SurfaceControl sc, @Size(9) float[] matrix,
2051 @Size(3) float[] translation) {
2052 sc.checkNotReleased();
2053 nativeSetColorTransform(mNativeObject, sc.mNativeObject, matrix, translation);
2054 return this;
2055 }
2056
Robert Carra7827f72019-01-11 12:53:37 -08002057 /**
2058 * @hide
2059 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002060 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07002061 public Transaction setWindowCrop(SurfaceControl sc, Rect crop) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002062 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002063 if (crop != null) {
2064 nativeSetWindowCrop(mNativeObject, sc.mNativeObject,
2065 crop.left, crop.top, crop.right, crop.bottom);
2066 } else {
2067 nativeSetWindowCrop(mNativeObject, sc.mNativeObject, 0, 0, 0, 0);
2068 }
2069
2070 return this;
2071 }
2072
Robert Carra7827f72019-01-11 12:53:37 -08002073 /**
2074 * @hide
2075 */
Vishnu Naird454442d2018-11-13 13:51:01 -08002076 public Transaction setWindowCrop(SurfaceControl sc, int width, int height) {
2077 sc.checkNotReleased();
2078 nativeSetWindowCrop(mNativeObject, sc.mNativeObject, 0, 0, width, height);
2079 return this;
2080 }
2081
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07002082 /**
2083 * Sets the corner radius of a {@link SurfaceControl}.
2084 * @param sc SurfaceControl
2085 * @param cornerRadius Corner radius in pixels.
2086 * @return Itself.
Robert Carra7827f72019-01-11 12:53:37 -08002087 * @hide
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07002088 */
2089 @UnsupportedAppUsage
2090 public Transaction setCornerRadius(SurfaceControl sc, float cornerRadius) {
2091 sc.checkNotReleased();
2092 nativeSetCornerRadius(mNativeObject, sc.mNativeObject, cornerRadius);
2093
2094 return this;
2095 }
2096
Robert Carra7827f72019-01-11 12:53:37 -08002097 /**
2098 * @hide
2099 */
Robert Carr76907ee2019-01-11 13:38:19 -08002100 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07002101 public Transaction setLayerStack(SurfaceControl sc, int layerStack) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002102 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002103 nativeSetLayerStack(mNativeObject, sc.mNativeObject, layerStack);
2104 return this;
2105 }
2106
Robert Carra7827f72019-01-11 12:53:37 -08002107 /**
2108 * @hide
2109 */
Robert Carr76907ee2019-01-11 13:38:19 -08002110 @UnsupportedAppUsage
Jorim Jaggidfc27372017-10-27 17:47:49 +02002111 public Transaction deferTransactionUntil(SurfaceControl sc, IBinder handle,
2112 long frameNumber) {
Robert Carr024378c2018-02-27 11:21:05 -08002113 if (frameNumber < 0) {
2114 return this;
2115 }
Jorim Jaggidfc27372017-10-27 17:47:49 +02002116 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002117 nativeDeferTransactionUntil(mNativeObject, sc.mNativeObject, handle, frameNumber);
2118 return this;
2119 }
2120
Robert Carra7827f72019-01-11 12:53:37 -08002121 /**
2122 * @hide
2123 */
Robert Carr76907ee2019-01-11 13:38:19 -08002124 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07002125 public Transaction deferTransactionUntilSurface(SurfaceControl sc, Surface barrierSurface,
2126 long frameNumber) {
Robert Carr024378c2018-02-27 11:21:05 -08002127 if (frameNumber < 0) {
2128 return this;
2129 }
Jorim Jaggidfc27372017-10-27 17:47:49 +02002130 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002131 nativeDeferTransactionUntilSurface(mNativeObject, sc.mNativeObject,
2132 barrierSurface.mNativeObject, frameNumber);
2133 return this;
2134 }
2135
Robert Carra7827f72019-01-11 12:53:37 -08002136 /**
2137 * @hide
2138 */
Robert Carre13b58e2017-08-31 14:50:44 -07002139 public Transaction reparentChildren(SurfaceControl sc, IBinder newParentHandle) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002140 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002141 nativeReparentChildren(mNativeObject, sc.mNativeObject, newParentHandle);
2142 return this;
2143 }
2144
Robert Carr10584fa2019-01-14 15:55:19 -08002145 /**
2146 * Re-parents a given layer to a new parent. Children inherit transform (position, scaling)
2147 * crop, visibility, and Z-ordering from their parents, as if the children were pixels within the
2148 * parent Surface.
2149 *
2150 * @param sc The SurfaceControl to reparent
2151 * @param newParent The new parent for the given control.
2152 * @return This Transaction
Robert Carra7827f72019-01-11 12:53:37 -08002153 */
Robert Carr76907ee2019-01-11 13:38:19 -08002154 @NonNull
2155 public Transaction reparent(@NonNull SurfaceControl sc,
2156 @Nullable SurfaceControl newParent) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002157 sc.checkNotReleased();
Robert Carr10584fa2019-01-14 15:55:19 -08002158 long otherObject = 0;
2159 if (newParent != null) {
2160 newParent.checkNotReleased();
2161 otherObject = newParent.mNativeObject;
2162 }
2163 nativeReparent(mNativeObject, sc.mNativeObject, otherObject);
Robert Carre13b58e2017-08-31 14:50:44 -07002164 return this;
2165 }
2166
Robert Carra7827f72019-01-11 12:53:37 -08002167 /**
2168 * @hide
2169 */
Robert Carre13b58e2017-08-31 14:50:44 -07002170 public Transaction detachChildren(SurfaceControl sc) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002171 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002172 nativeSeverChildren(mNativeObject, sc.mNativeObject);
2173 return this;
2174 }
2175
Robert Carra7827f72019-01-11 12:53:37 -08002176 /**
2177 * @hide
2178 */
Robert Carre13b58e2017-08-31 14:50:44 -07002179 public Transaction setOverrideScalingMode(SurfaceControl sc, int overrideScalingMode) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002180 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002181 nativeSetOverrideScalingMode(mNativeObject, sc.mNativeObject,
2182 overrideScalingMode);
2183 return this;
2184 }
2185
2186 /**
2187 * Sets a color for the Surface.
2188 * @param color A float array with three values to represent r, g, b in range [0..1]
Robert Carra7827f72019-01-11 12:53:37 -08002189 * @hide
Robert Carre13b58e2017-08-31 14:50:44 -07002190 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002191 @UnsupportedAppUsage
Robert Carre13b58e2017-08-31 14:50:44 -07002192 public Transaction setColor(SurfaceControl sc, @Size(3) float[] color) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002193 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002194 nativeSetColor(mNativeObject, sc.mNativeObject, color);
2195 return this;
2196 }
2197
2198 /**
2199 * If the buffer size changes in this transaction, position and crop updates specified
2200 * in this transaction will not complete until a buffer of the new size
2201 * arrives. As transform matrix and size are already frozen in this fashion,
2202 * this enables totally freezing the surface until the resize has completed
2203 * (at which point the geometry influencing aspects of this transaction will then occur)
Robert Carra7827f72019-01-11 12:53:37 -08002204 * @hide
Robert Carre13b58e2017-08-31 14:50:44 -07002205 */
2206 public Transaction setGeometryAppliesWithResize(SurfaceControl sc) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002207 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002208 nativeSetGeometryAppliesWithResize(mNativeObject, sc.mNativeObject);
2209 return this;
2210 }
2211
2212 /**
2213 * Sets the security of the surface. Setting the flag is equivalent to creating the
2214 * Surface with the {@link #SECURE} flag.
Robert Carra7827f72019-01-11 12:53:37 -08002215 * @hide
Robert Carre13b58e2017-08-31 14:50:44 -07002216 */
Robert Carrb1579c82017-09-05 14:54:47 -07002217 public Transaction setSecure(SurfaceControl sc, boolean isSecure) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002218 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002219 if (isSecure) {
2220 nativeSetFlags(mNativeObject, sc.mNativeObject, SECURE, SECURE);
2221 } else {
2222 nativeSetFlags(mNativeObject, sc.mNativeObject, 0, SECURE);
2223 }
2224 return this;
2225 }
2226
2227 /**
2228 * Sets the opacity of the surface. Setting the flag is equivalent to creating the
2229 * Surface with the {@link #OPAQUE} flag.
Robert Carra7827f72019-01-11 12:53:37 -08002230 * @hide
Robert Carre13b58e2017-08-31 14:50:44 -07002231 */
2232 public Transaction setOpaque(SurfaceControl sc, boolean isOpaque) {
Jorim Jaggidfc27372017-10-27 17:47:49 +02002233 sc.checkNotReleased();
Robert Carre13b58e2017-08-31 14:50:44 -07002234 if (isOpaque) {
Robert Carr2b8a5e12017-10-18 18:46:27 -07002235 nativeSetFlags(mNativeObject, sc.mNativeObject, SURFACE_OPAQUE, SURFACE_OPAQUE);
Robert Carre13b58e2017-08-31 14:50:44 -07002236 } else {
Robert Carr2b8a5e12017-10-18 18:46:27 -07002237 nativeSetFlags(mNativeObject, sc.mNativeObject, 0, SURFACE_OPAQUE);
Robert Carre13b58e2017-08-31 14:50:44 -07002238 }
2239 return this;
2240 }
2241
Robert Carra7827f72019-01-11 12:53:37 -08002242 /**
2243 * @hide
2244 */
Robert Carre13b58e2017-08-31 14:50:44 -07002245 public Transaction setDisplaySurface(IBinder displayToken, Surface surface) {
2246 if (displayToken == null) {
2247 throw new IllegalArgumentException("displayToken must not be null");
2248 }
2249
2250 if (surface != null) {
2251 synchronized (surface.mLock) {
2252 nativeSetDisplaySurface(mNativeObject, displayToken, surface.mNativeObject);
2253 }
2254 } else {
2255 nativeSetDisplaySurface(mNativeObject, displayToken, 0);
2256 }
2257 return this;
2258 }
2259
Robert Carra7827f72019-01-11 12:53:37 -08002260 /**
2261 * @hide
2262 */
Robert Carre13b58e2017-08-31 14:50:44 -07002263 public Transaction setDisplayLayerStack(IBinder displayToken, int layerStack) {
2264 if (displayToken == null) {
2265 throw new IllegalArgumentException("displayToken must not be null");
2266 }
2267 nativeSetDisplayLayerStack(mNativeObject, displayToken, layerStack);
2268 return this;
2269 }
2270
Robert Carra7827f72019-01-11 12:53:37 -08002271 /**
2272 * @hide
2273 */
Robert Carre13b58e2017-08-31 14:50:44 -07002274 public Transaction setDisplayProjection(IBinder displayToken,
2275 int orientation, Rect layerStackRect, Rect displayRect) {
2276 if (displayToken == null) {
2277 throw new IllegalArgumentException("displayToken must not be null");
2278 }
2279 if (layerStackRect == null) {
2280 throw new IllegalArgumentException("layerStackRect must not be null");
2281 }
2282 if (displayRect == null) {
2283 throw new IllegalArgumentException("displayRect must not be null");
2284 }
2285 nativeSetDisplayProjection(mNativeObject, displayToken, orientation,
2286 layerStackRect.left, layerStackRect.top, layerStackRect.right, layerStackRect.bottom,
2287 displayRect.left, displayRect.top, displayRect.right, displayRect.bottom);
2288 return this;
2289 }
2290
Robert Carra7827f72019-01-11 12:53:37 -08002291 /**
2292 * @hide
2293 */
Robert Carre13b58e2017-08-31 14:50:44 -07002294 public Transaction setDisplaySize(IBinder displayToken, int width, int height) {
2295 if (displayToken == null) {
2296 throw new IllegalArgumentException("displayToken must not be null");
2297 }
2298 if (width <= 0 || height <= 0) {
2299 throw new IllegalArgumentException("width and height must be positive");
2300 }
2301
2302 nativeSetDisplaySize(mNativeObject, displayToken, width, height);
2303 return this;
2304 }
2305
Robert Carra7827f72019-01-11 12:53:37 -08002306 /** flag the transaction as an animation
2307 * @hide
2308 */
Robert Carre13b58e2017-08-31 14:50:44 -07002309 public Transaction setAnimationTransaction() {
2310 nativeSetAnimationTransaction(mNativeObject);
2311 return this;
2312 }
Robert Carrb1579c82017-09-05 14:54:47 -07002313
2314 /**
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01002315 * Indicate that SurfaceFlinger should wake up earlier than usual as a result of this
2316 * transaction. This should be used when the caller thinks that the scene is complex enough
2317 * that it's likely to hit GL composition, and thus, SurfaceFlinger needs to more time in
2318 * order not to miss frame deadlines.
2319 * <p>
2320 * Corresponds to setting ISurfaceComposer::eEarlyWakeup
Robert Carra7827f72019-01-11 12:53:37 -08002321 * @hide
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01002322 */
2323 public Transaction setEarlyWakeup() {
2324 nativeSetEarlyWakeup(mNativeObject);
2325 return this;
2326 }
2327
2328 /**
Robert Carrb1579c82017-09-05 14:54:47 -07002329 * Merge the other transaction into this transaction, clearing the
2330 * other transaction as if it had been applied.
Robert Carr76907ee2019-01-11 13:38:19 -08002331 *
2332 * @param other The transaction to merge in to this one.
2333 * @return This transaction.
Robert Carrb1579c82017-09-05 14:54:47 -07002334 */
Robert Carr76907ee2019-01-11 13:38:19 -08002335 @NonNull
2336 public Transaction merge(@NonNull Transaction other) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002337 mResizedSurfaces.putAll(other.mResizedSurfaces);
2338 other.mResizedSurfaces.clear();
Robert Carrb1579c82017-09-05 14:54:47 -07002339 nativeMergeTransaction(mNativeObject, other.mNativeObject);
2340 return this;
2341 }
Robert Carre13b58e2017-08-31 14:50:44 -07002342 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08002343}