Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.view; |
| 18 | |
| 19 | import dalvik.system.CloseGuard; |
| 20 | import android.graphics.Bitmap; |
| 21 | import android.graphics.Rect; |
| 22 | import android.graphics.Region; |
| 23 | import android.os.IBinder; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 24 | import android.util.Log; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 25 | import android.view.Surface.OutOfResourcesException; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * SurfaceControl |
| 29 | * @hide |
| 30 | */ |
| 31 | public class SurfaceControl { |
| 32 | private static final String TAG = "SurfaceControl"; |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 33 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 34 | private static native long nativeCreate(SurfaceSession session, String name, |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 35 | int w, int h, int format, int flags) |
| 36 | throws OutOfResourcesException; |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 37 | private static native void nativeRelease(long nativeObject); |
| 38 | private static native void nativeDestroy(long nativeObject); |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 39 | private static native void nativeDisconnect(long nativeObject); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 40 | |
| 41 | private static native Bitmap nativeScreenshot(IBinder displayToken, |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 42 | Rect sourceCrop, int width, int height, int minLayer, int maxLayer, |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame] | 43 | boolean allLayers, boolean useIdentityTransform, int rotation); |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 44 | private static native void nativeScreenshot(IBinder displayToken, Surface consumer, |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 45 | Rect sourceCrop, int width, int height, int minLayer, int maxLayer, |
| 46 | boolean allLayers, boolean useIdentityTransform); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 47 | |
| 48 | private static native void nativeOpenTransaction(); |
| 49 | private static native void nativeCloseTransaction(); |
| 50 | private static native void nativeSetAnimationTransaction(); |
| 51 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 52 | private static native void nativeSetLayer(long nativeObject, int zorder); |
| 53 | private static native void nativeSetPosition(long nativeObject, float x, float y); |
| 54 | private static native void nativeSetSize(long nativeObject, int w, int h); |
| 55 | private static native void nativeSetTransparentRegionHint(long nativeObject, Region region); |
| 56 | private static native void nativeSetAlpha(long nativeObject, float alpha); |
| 57 | private static native void nativeSetMatrix(long nativeObject, float dsdx, float dtdx, float dsdy, float dtdy); |
| 58 | private static native void nativeSetFlags(long nativeObject, int flags, int mask); |
| 59 | private static native void nativeSetWindowCrop(long nativeObject, int l, int t, int r, int b); |
| 60 | private static native void nativeSetLayerStack(long nativeObject, int layerStack); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 61 | |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 62 | private static native boolean nativeClearContentFrameStats(long nativeObject); |
| 63 | private static native boolean nativeGetContentFrameStats(long nativeObject, WindowContentFrameStats outStats); |
| 64 | private static native boolean nativeClearAnimationFrameStats(); |
| 65 | private static native boolean nativeGetAnimationFrameStats(WindowAnimationFrameStats outStats); |
| 66 | |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 67 | private static native IBinder nativeGetBuiltInDisplay(int physicalDisplayId); |
| 68 | private static native IBinder nativeCreateDisplay(String name, boolean secure); |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 69 | private static native void nativeDestroyDisplay(IBinder displayToken); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 70 | private static native void nativeSetDisplaySurface( |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 71 | IBinder displayToken, long nativeSurfaceObject); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 72 | private static native void nativeSetDisplayLayerStack( |
| 73 | IBinder displayToken, int layerStack); |
| 74 | private static native void nativeSetDisplayProjection( |
| 75 | IBinder displayToken, int orientation, |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 76 | int l, int t, int r, int b, |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 77 | int L, int T, int R, int B); |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 78 | private static native void nativeSetDisplaySize(IBinder displayToken, int width, int height); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 79 | private static native SurfaceControl.PhysicalDisplayInfo[] nativeGetDisplayConfigs( |
| 80 | IBinder displayToken); |
| 81 | private static native int nativeGetActiveConfig(IBinder displayToken); |
| 82 | private static native boolean nativeSetActiveConfig(IBinder displayToken, int id); |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 83 | private static native void nativeSetDisplayPowerMode( |
| 84 | IBinder displayToken, int mode); |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 85 | private static native void nativeDeferTransactionUntil(long nativeObject, |
| 86 | IBinder handle, long frame); |
| 87 | private static native IBinder nativeGetHandle(long nativeObject); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 88 | |
| 89 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 90 | private final CloseGuard mCloseGuard = CloseGuard.get(); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 91 | private final String mName; |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 92 | long mNativeObject; // package visibility only for Surface.java access |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 93 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 94 | /* flags used in constructor (keep in sync with ISurfaceComposerClient.h) */ |
| 95 | |
| 96 | /** |
| 97 | * Surface creation flag: Surface is created hidden |
| 98 | */ |
| 99 | public static final int HIDDEN = 0x00000004; |
| 100 | |
| 101 | /** |
| 102 | * Surface creation flag: The surface contains secure content, special |
| 103 | * measures will be taken to disallow the surface's content to be copied |
| 104 | * from another process. In particular, screenshots and VNC servers will |
| 105 | * be disabled, but other measures can take place, for instance the |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 106 | * surface might not be hardware accelerated. |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 107 | * |
| 108 | */ |
| 109 | public static final int SECURE = 0x00000080; |
| 110 | |
| 111 | /** |
| 112 | * Surface creation flag: Creates a surface where color components are interpreted |
| 113 | * as "non pre-multiplied" by their alpha channel. Of course this flag is |
| 114 | * meaningless for surfaces without an alpha channel. By default |
| 115 | * surfaces are pre-multiplied, which means that each color component is |
| 116 | * already multiplied by its alpha value. In this case the blending |
| 117 | * equation used is: |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 118 | * <p> |
| 119 | * <code>DEST = SRC + DEST * (1-SRC_ALPHA)</code> |
| 120 | * <p> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 121 | * By contrast, non pre-multiplied surfaces use the following equation: |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 122 | * <p> |
| 123 | * <code>DEST = SRC * SRC_ALPHA * DEST * (1-SRC_ALPHA)</code> |
| 124 | * <p> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 125 | * pre-multiplied surfaces must always be used if transparent pixels are |
| 126 | * composited on top of each-other into the surface. A pre-multiplied |
| 127 | * surface can never lower the value of the alpha component of a given |
| 128 | * pixel. |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 129 | * <p> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 130 | * In some rare situations, a non pre-multiplied surface is preferable. |
| 131 | * |
| 132 | */ |
| 133 | public static final int NON_PREMULTIPLIED = 0x00000100; |
| 134 | |
| 135 | /** |
| 136 | * Surface creation flag: Indicates that the surface must be considered opaque, |
| 137 | * even if its pixel format is set to translucent. This can be useful if an |
| 138 | * application needs full RGBA 8888 support for instance but will |
| 139 | * still draw every pixel opaque. |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 140 | * <p> |
| 141 | * This flag is ignored if setAlpha() is used to make the surface non-opaque. |
| 142 | * Combined effects are (assuming a buffer format with an alpha channel): |
| 143 | * <ul> |
| 144 | * <li>OPAQUE + alpha(1.0) == opaque composition |
| 145 | * <li>OPAQUE + alpha(0.x) == blended composition |
| 146 | * <li>!OPAQUE + alpha(1.0) == blended composition |
| 147 | * <li>!OPAQUE + alpha(0.x) == blended composition |
| 148 | * </ul> |
| 149 | * If the underlying buffer lacks an alpha channel, the OPAQUE flag is effectively |
| 150 | * set automatically. |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 151 | */ |
| 152 | public static final int OPAQUE = 0x00000400; |
| 153 | |
| 154 | /** |
| 155 | * Surface creation flag: Application requires a hardware-protected path to an |
| 156 | * external display sink. If a hardware-protected path is not available, |
| 157 | * then this surface will not be displayed on the external sink. |
| 158 | * |
| 159 | */ |
| 160 | public static final int PROTECTED_APP = 0x00000800; |
| 161 | |
| 162 | // 0x1000 is reserved for an independent DRM protected flag in framework |
| 163 | |
| 164 | /** |
Riley Andrews | 68eccda | 2014-07-07 11:47:35 -0700 | [diff] [blame] | 165 | * Surface creation flag: Window represents a cursor glyph. |
| 166 | */ |
| 167 | public static final int CURSOR_WINDOW = 0x00002000; |
| 168 | |
| 169 | /** |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 170 | * Surface creation flag: Creates a normal surface. |
| 171 | * This is the default. |
| 172 | * |
| 173 | */ |
| 174 | public static final int FX_SURFACE_NORMAL = 0x00000000; |
| 175 | |
| 176 | /** |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 177 | * Surface creation flag: Creates a Dim surface. |
| 178 | * Everything behind this surface is dimmed by the amount specified |
| 179 | * in {@link #setAlpha}. It is an error to lock a Dim surface, since it |
| 180 | * doesn't have a backing store. |
| 181 | * |
| 182 | */ |
| 183 | public static final int FX_SURFACE_DIM = 0x00020000; |
| 184 | |
| 185 | /** |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 186 | * Mask used for FX values above. |
| 187 | * |
| 188 | */ |
| 189 | public static final int FX_SURFACE_MASK = 0x000F0000; |
| 190 | |
| 191 | /* flags used with setFlags() (keep in sync with ISurfaceComposer.h) */ |
| 192 | |
| 193 | /** |
| 194 | * Surface flag: Hide the surface. |
| 195 | * Equivalent to calling hide(). |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 196 | * Updates the value set during Surface creation (see {@link #HIDDEN}). |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 197 | */ |
Andy McFadden | 40b9ef1 | 2014-01-30 13:44:47 -0800 | [diff] [blame] | 198 | private static final int SURFACE_HIDDEN = 0x01; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 199 | |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 200 | /** |
| 201 | * Surface flag: composite without blending when possible. |
| 202 | * Updates the value set during Surface creation (see {@link #OPAQUE}). |
| 203 | */ |
Andy McFadden | 40b9ef1 | 2014-01-30 13:44:47 -0800 | [diff] [blame] | 204 | private static final int SURFACE_OPAQUE = 0x02; |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 205 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 206 | |
| 207 | /* built-in physical display ids (keep in sync with ISurfaceComposer.h) |
| 208 | * these are different from the logical display ids used elsewhere in the framework */ |
| 209 | |
| 210 | /** |
| 211 | * Built-in physical display id: Main display. |
Andy McFadden | 40b9ef1 | 2014-01-30 13:44:47 -0800 | [diff] [blame] | 212 | * Use only with {@link SurfaceControl#getBuiltInDisplay(int)}. |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 213 | */ |
| 214 | public static final int BUILT_IN_DISPLAY_ID_MAIN = 0; |
| 215 | |
| 216 | /** |
| 217 | * Built-in physical display id: Attached HDMI display. |
Andy McFadden | 40b9ef1 | 2014-01-30 13:44:47 -0800 | [diff] [blame] | 218 | * Use only with {@link SurfaceControl#getBuiltInDisplay(int)}. |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 219 | */ |
| 220 | public static final int BUILT_IN_DISPLAY_ID_HDMI = 1; |
| 221 | |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 222 | /* Display power modes * / |
| 223 | |
| 224 | /** |
| 225 | * Display power mode off: used while blanking the screen. |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 226 | * Use only with {@link SurfaceControl#setDisplayPowerMode}. |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 227 | */ |
| 228 | public static final int POWER_MODE_OFF = 0; |
| 229 | |
| 230 | /** |
| 231 | * Display power mode doze: used while putting the screen into low power mode. |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 232 | * Use only with {@link SurfaceControl#setDisplayPowerMode}. |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 233 | */ |
| 234 | public static final int POWER_MODE_DOZE = 1; |
| 235 | |
| 236 | /** |
| 237 | * Display power mode normal: used while unblanking the screen. |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 238 | * Use only with {@link SurfaceControl#setDisplayPowerMode}. |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 239 | */ |
| 240 | public static final int POWER_MODE_NORMAL = 2; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 241 | |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 242 | /** |
| 243 | * Display power mode doze: used while putting the screen into a suspended |
| 244 | * low power mode. Use only with {@link SurfaceControl#setDisplayPowerMode}. |
| 245 | */ |
| 246 | public static final int POWER_MODE_DOZE_SUSPEND = 3; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 247 | |
| 248 | /** |
| 249 | * Create a surface with a name. |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 250 | * <p> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 251 | * The surface creation flags specify what kind of surface to create and |
| 252 | * certain options such as whether the surface can be assumed to be opaque |
| 253 | * and whether it should be initially hidden. Surfaces should always be |
| 254 | * created with the {@link #HIDDEN} flag set to ensure that they are not |
| 255 | * made visible prematurely before all of the surface's properties have been |
| 256 | * configured. |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 257 | * <p> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 258 | * Good practice is to first create the surface with the {@link #HIDDEN} flag |
| 259 | * specified, open a transaction, set the surface layer, layer stack, alpha, |
| 260 | * and position, call {@link #show} if appropriate, and close the transaction. |
| 261 | * |
| 262 | * @param session The surface session, must not be null. |
| 263 | * @param name The surface name, must not be null. |
| 264 | * @param w The surface initial width. |
| 265 | * @param h The surface initial height. |
| 266 | * @param flags The surface creation flags. Should always include {@link #HIDDEN} |
| 267 | * in the creation flags. |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 268 | * |
| 269 | * @throws throws OutOfResourcesException If the SurfaceControl cannot be created. |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 270 | */ |
| 271 | public SurfaceControl(SurfaceSession session, |
| 272 | String name, int w, int h, int format, int flags) |
| 273 | throws OutOfResourcesException { |
| 274 | if (session == null) { |
| 275 | throw new IllegalArgumentException("session must not be null"); |
| 276 | } |
| 277 | if (name == null) { |
| 278 | throw new IllegalArgumentException("name must not be null"); |
| 279 | } |
| 280 | |
| 281 | if ((flags & SurfaceControl.HIDDEN) == 0) { |
| 282 | Log.w(TAG, "Surfaces should always be created with the HIDDEN flag set " |
| 283 | + "to ensure that they are not made visible prematurely before " |
| 284 | + "all of the surface's properties have been configured. " |
| 285 | + "Set the other properties and make the surface visible within " |
| 286 | + "a transaction. New surface name: " + name, |
| 287 | new Throwable()); |
| 288 | } |
| 289 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 290 | mName = name; |
| 291 | mNativeObject = nativeCreate(session, name, w, h, format, flags); |
| 292 | if (mNativeObject == 0) { |
| 293 | throw new OutOfResourcesException( |
| 294 | "Couldn't allocate SurfaceControl native object"); |
| 295 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 296 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 297 | mCloseGuard.open("release"); |
| 298 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 299 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 300 | @Override |
| 301 | protected void finalize() throws Throwable { |
| 302 | try { |
| 303 | if (mCloseGuard != null) { |
| 304 | mCloseGuard.warnIfOpen(); |
| 305 | } |
| 306 | if (mNativeObject != 0) { |
| 307 | nativeRelease(mNativeObject); |
| 308 | } |
| 309 | } finally { |
| 310 | super.finalize(); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | @Override |
| 315 | public String toString() { |
| 316 | return "Surface(name=" + mName + ")"; |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * Release the local reference to the server-side surface. |
| 321 | * Always call release() when you're done with a Surface. |
| 322 | * This will make the surface invalid. |
| 323 | */ |
| 324 | public void release() { |
| 325 | if (mNativeObject != 0) { |
| 326 | nativeRelease(mNativeObject); |
| 327 | mNativeObject = 0; |
| 328 | } |
| 329 | mCloseGuard.close(); |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Free all server-side state associated with this surface and |
| 334 | * release this object's reference. This method can only be |
| 335 | * called from the process that created the service. |
| 336 | */ |
| 337 | public void destroy() { |
| 338 | if (mNativeObject != 0) { |
| 339 | nativeDestroy(mNativeObject); |
| 340 | mNativeObject = 0; |
| 341 | } |
| 342 | mCloseGuard.close(); |
| 343 | } |
| 344 | |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 345 | /** |
| 346 | * Disconnect any client still connected to the surface. |
| 347 | */ |
| 348 | public void disconnect() { |
| 349 | if (mNativeObject != 0) { |
| 350 | nativeDisconnect(mNativeObject); |
| 351 | } |
| 352 | } |
| 353 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 354 | private void checkNotReleased() { |
| 355 | if (mNativeObject == 0) throw new NullPointerException( |
| 356 | "mNativeObject is null. Have you called release() already?"); |
| 357 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 358 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 359 | /* |
| 360 | * set surface parameters. |
| 361 | * needs to be inside open/closeTransaction block |
| 362 | */ |
| 363 | |
| 364 | /** start a transaction */ |
| 365 | public static void openTransaction() { |
| 366 | nativeOpenTransaction(); |
| 367 | } |
| 368 | |
| 369 | /** end a transaction */ |
| 370 | public static void closeTransaction() { |
| 371 | nativeCloseTransaction(); |
| 372 | } |
| 373 | |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 374 | public void deferTransactionUntil(IBinder handle, long frame) { |
| 375 | nativeDeferTransactionUntil(mNativeObject, handle, frame); |
| 376 | } |
| 377 | |
| 378 | public IBinder getHandle() { |
| 379 | return nativeGetHandle(mNativeObject); |
| 380 | } |
| 381 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 382 | /** flag the transaction as an animation */ |
| 383 | public static void setAnimationTransaction() { |
| 384 | nativeSetAnimationTransaction(); |
| 385 | } |
| 386 | |
| 387 | public void setLayer(int zorder) { |
| 388 | checkNotReleased(); |
| 389 | nativeSetLayer(mNativeObject, zorder); |
| 390 | } |
| 391 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 392 | public void setPosition(float x, float y) { |
| 393 | checkNotReleased(); |
| 394 | nativeSetPosition(mNativeObject, x, y); |
| 395 | } |
| 396 | |
| 397 | public void setSize(int w, int h) { |
| 398 | checkNotReleased(); |
| 399 | nativeSetSize(mNativeObject, w, h); |
| 400 | } |
| 401 | |
| 402 | public void hide() { |
| 403 | checkNotReleased(); |
| 404 | nativeSetFlags(mNativeObject, SURFACE_HIDDEN, SURFACE_HIDDEN); |
| 405 | } |
| 406 | |
| 407 | public void show() { |
| 408 | checkNotReleased(); |
| 409 | nativeSetFlags(mNativeObject, 0, SURFACE_HIDDEN); |
| 410 | } |
| 411 | |
| 412 | public void setTransparentRegionHint(Region region) { |
| 413 | checkNotReleased(); |
| 414 | nativeSetTransparentRegionHint(mNativeObject, region); |
| 415 | } |
| 416 | |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 417 | public boolean clearContentFrameStats() { |
| 418 | checkNotReleased(); |
| 419 | return nativeClearContentFrameStats(mNativeObject); |
| 420 | } |
| 421 | |
| 422 | public boolean getContentFrameStats(WindowContentFrameStats outStats) { |
| 423 | checkNotReleased(); |
| 424 | return nativeGetContentFrameStats(mNativeObject, outStats); |
| 425 | } |
| 426 | |
| 427 | public static boolean clearAnimationFrameStats() { |
| 428 | return nativeClearAnimationFrameStats(); |
| 429 | } |
| 430 | |
| 431 | public static boolean getAnimationFrameStats(WindowAnimationFrameStats outStats) { |
| 432 | return nativeGetAnimationFrameStats(outStats); |
| 433 | } |
| 434 | |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 435 | /** |
| 436 | * Sets an alpha value for the entire Surface. This value is combined with the |
| 437 | * per-pixel alpha. It may be used with opaque Surfaces. |
| 438 | */ |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 439 | public void setAlpha(float alpha) { |
| 440 | checkNotReleased(); |
| 441 | nativeSetAlpha(mNativeObject, alpha); |
| 442 | } |
| 443 | |
| 444 | public void setMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 445 | checkNotReleased(); |
| 446 | nativeSetMatrix(mNativeObject, dsdx, dtdx, dsdy, dtdy); |
| 447 | } |
| 448 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 449 | public void setWindowCrop(Rect crop) { |
| 450 | checkNotReleased(); |
| 451 | if (crop != null) { |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 452 | nativeSetWindowCrop(mNativeObject, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 453 | crop.left, crop.top, crop.right, crop.bottom); |
| 454 | } else { |
| 455 | nativeSetWindowCrop(mNativeObject, 0, 0, 0, 0); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | public void setLayerStack(int layerStack) { |
| 460 | checkNotReleased(); |
| 461 | nativeSetLayerStack(mNativeObject, layerStack); |
| 462 | } |
| 463 | |
Andy McFadden | 314405b | 2014-01-29 17:18:05 -0800 | [diff] [blame] | 464 | /** |
| 465 | * Sets the opacity of the surface. Setting the flag is equivalent to creating the |
| 466 | * Surface with the {@link #OPAQUE} flag. |
| 467 | */ |
| 468 | public void setOpaque(boolean isOpaque) { |
| 469 | checkNotReleased(); |
| 470 | if (isOpaque) { |
| 471 | nativeSetFlags(mNativeObject, SURFACE_OPAQUE, SURFACE_OPAQUE); |
| 472 | } else { |
| 473 | nativeSetFlags(mNativeObject, 0, SURFACE_OPAQUE); |
| 474 | } |
| 475 | } |
| 476 | |
Wale Ogunwale | f5ad42f | 2015-06-12 13:59:03 -0700 | [diff] [blame] | 477 | /** |
| 478 | * Sets the security of the surface. Setting the flag is equivalent to creating the |
| 479 | * Surface with the {@link #SECURE} flag. |
| 480 | */ |
| 481 | public void setSecure(boolean isSecure) { |
| 482 | checkNotReleased(); |
| 483 | if (isSecure) { |
| 484 | nativeSetFlags(mNativeObject, SECURE, SECURE); |
| 485 | } else { |
| 486 | nativeSetFlags(mNativeObject, 0, SECURE); |
| 487 | } |
| 488 | } |
| 489 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 490 | /* |
| 491 | * set display parameters. |
| 492 | * needs to be inside open/closeTransaction block |
| 493 | */ |
| 494 | |
| 495 | /** |
| 496 | * Describes the properties of a physical display known to surface flinger. |
| 497 | */ |
| 498 | public static final class PhysicalDisplayInfo { |
| 499 | public int width; |
| 500 | public int height; |
| 501 | public float refreshRate; |
| 502 | public float density; |
| 503 | public float xDpi; |
| 504 | public float yDpi; |
| 505 | public boolean secure; |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 506 | public long appVsyncOffsetNanos; |
| 507 | public long presentationDeadlineNanos; |
Dan Stoza | 904f485 | 2015-08-31 12:01:48 -0700 | [diff] [blame] | 508 | public int colorTransform; |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 509 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 510 | public PhysicalDisplayInfo() { |
| 511 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 512 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 513 | public PhysicalDisplayInfo(PhysicalDisplayInfo other) { |
| 514 | copyFrom(other); |
| 515 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 516 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 517 | @Override |
| 518 | public boolean equals(Object o) { |
| 519 | return o instanceof PhysicalDisplayInfo && equals((PhysicalDisplayInfo)o); |
| 520 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 521 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 522 | public boolean equals(PhysicalDisplayInfo other) { |
| 523 | return other != null |
| 524 | && width == other.width |
| 525 | && height == other.height |
| 526 | && refreshRate == other.refreshRate |
| 527 | && density == other.density |
| 528 | && xDpi == other.xDpi |
| 529 | && yDpi == other.yDpi |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 530 | && secure == other.secure |
| 531 | && appVsyncOffsetNanos == other.appVsyncOffsetNanos |
Dan Stoza | 904f485 | 2015-08-31 12:01:48 -0700 | [diff] [blame] | 532 | && presentationDeadlineNanos == other.presentationDeadlineNanos |
| 533 | && colorTransform == other.colorTransform; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 534 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 535 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 536 | @Override |
| 537 | public int hashCode() { |
| 538 | return 0; // don't care |
| 539 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 540 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 541 | public void copyFrom(PhysicalDisplayInfo other) { |
| 542 | width = other.width; |
| 543 | height = other.height; |
| 544 | refreshRate = other.refreshRate; |
| 545 | density = other.density; |
| 546 | xDpi = other.xDpi; |
| 547 | yDpi = other.yDpi; |
| 548 | secure = other.secure; |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 549 | appVsyncOffsetNanos = other.appVsyncOffsetNanos; |
| 550 | presentationDeadlineNanos = other.presentationDeadlineNanos; |
Dan Stoza | 904f485 | 2015-08-31 12:01:48 -0700 | [diff] [blame] | 551 | colorTransform = other.colorTransform; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 552 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 553 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 554 | // For debugging purposes |
| 555 | @Override |
| 556 | public String toString() { |
| 557 | return "PhysicalDisplayInfo{" + width + " x " + height + ", " + refreshRate + " fps, " |
| 558 | + "density " + density + ", " + xDpi + " x " + yDpi + " dpi, secure " + secure |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 559 | + ", appVsyncOffset " + appVsyncOffsetNanos |
Dan Stoza | 904f485 | 2015-08-31 12:01:48 -0700 | [diff] [blame] | 560 | + ", bufferDeadline " + presentationDeadlineNanos |
| 561 | + ", colorTransform " + colorTransform + "}"; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 562 | } |
| 563 | } |
| 564 | |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 565 | public static void setDisplayPowerMode(IBinder displayToken, int mode) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 566 | if (displayToken == null) { |
| 567 | throw new IllegalArgumentException("displayToken must not be null"); |
| 568 | } |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 569 | nativeSetDisplayPowerMode(displayToken, mode); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 570 | } |
| 571 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 572 | public static SurfaceControl.PhysicalDisplayInfo[] getDisplayConfigs(IBinder displayToken) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 573 | if (displayToken == null) { |
| 574 | throw new IllegalArgumentException("displayToken must not be null"); |
| 575 | } |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 576 | return nativeGetDisplayConfigs(displayToken); |
| 577 | } |
| 578 | |
| 579 | public static int getActiveConfig(IBinder displayToken) { |
| 580 | if (displayToken == null) { |
| 581 | throw new IllegalArgumentException("displayToken must not be null"); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 582 | } |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 583 | return nativeGetActiveConfig(displayToken); |
| 584 | } |
| 585 | |
| 586 | public static boolean setActiveConfig(IBinder displayToken, int id) { |
| 587 | if (displayToken == null) { |
| 588 | throw new IllegalArgumentException("displayToken must not be null"); |
| 589 | } |
| 590 | return nativeSetActiveConfig(displayToken, id); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | public static void setDisplayProjection(IBinder displayToken, |
| 594 | int orientation, Rect layerStackRect, Rect displayRect) { |
| 595 | if (displayToken == null) { |
| 596 | throw new IllegalArgumentException("displayToken must not be null"); |
| 597 | } |
| 598 | if (layerStackRect == null) { |
| 599 | throw new IllegalArgumentException("layerStackRect must not be null"); |
| 600 | } |
| 601 | if (displayRect == null) { |
| 602 | throw new IllegalArgumentException("displayRect must not be null"); |
| 603 | } |
| 604 | nativeSetDisplayProjection(displayToken, orientation, |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 605 | layerStackRect.left, layerStackRect.top, layerStackRect.right, layerStackRect.bottom, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 606 | displayRect.left, displayRect.top, displayRect.right, displayRect.bottom); |
| 607 | } |
| 608 | |
| 609 | public static void setDisplayLayerStack(IBinder displayToken, int layerStack) { |
| 610 | if (displayToken == null) { |
| 611 | throw new IllegalArgumentException("displayToken must not be null"); |
| 612 | } |
| 613 | nativeSetDisplayLayerStack(displayToken, layerStack); |
| 614 | } |
| 615 | |
| 616 | public static void setDisplaySurface(IBinder displayToken, Surface surface) { |
| 617 | if (displayToken == null) { |
| 618 | throw new IllegalArgumentException("displayToken must not be null"); |
| 619 | } |
Jeff Brown | fc0ebd7 | 2013-04-30 16:33:00 -0700 | [diff] [blame] | 620 | |
| 621 | if (surface != null) { |
| 622 | synchronized (surface.mLock) { |
| 623 | nativeSetDisplaySurface(displayToken, surface.mNativeObject); |
| 624 | } |
| 625 | } else { |
| 626 | nativeSetDisplaySurface(displayToken, 0); |
| 627 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 628 | } |
| 629 | |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 630 | public static void setDisplaySize(IBinder displayToken, int width, int height) { |
| 631 | if (displayToken == null) { |
| 632 | throw new IllegalArgumentException("displayToken must not be null"); |
| 633 | } |
| 634 | if (width <= 0 || height <= 0) { |
| 635 | throw new IllegalArgumentException("width and height must be positive"); |
| 636 | } |
| 637 | |
| 638 | nativeSetDisplaySize(displayToken, width, height); |
| 639 | } |
| 640 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 641 | public static IBinder createDisplay(String name, boolean secure) { |
| 642 | if (name == null) { |
| 643 | throw new IllegalArgumentException("name must not be null"); |
| 644 | } |
| 645 | return nativeCreateDisplay(name, secure); |
| 646 | } |
| 647 | |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 648 | public static void destroyDisplay(IBinder displayToken) { |
| 649 | if (displayToken == null) { |
| 650 | throw new IllegalArgumentException("displayToken must not be null"); |
| 651 | } |
| 652 | nativeDestroyDisplay(displayToken); |
| 653 | } |
| 654 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 655 | public static IBinder getBuiltInDisplay(int builtInDisplayId) { |
| 656 | return nativeGetBuiltInDisplay(builtInDisplayId); |
| 657 | } |
| 658 | |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 659 | /** |
| 660 | * Copy the current screen contents into the provided {@link Surface} |
| 661 | * |
| 662 | * @param display The display to take the screenshot of. |
| 663 | * @param consumer The {@link Surface} to take the screenshot into. |
| 664 | * @param width The desired width of the returned bitmap; the raw |
| 665 | * screen will be scaled down to this size. |
| 666 | * @param height The desired height of the returned bitmap; the raw |
| 667 | * screen will be scaled down to this size. |
| 668 | * @param minLayer The lowest (bottom-most Z order) surface layer to |
| 669 | * include in the screenshot. |
| 670 | * @param maxLayer The highest (top-most Z order) surface layer to |
| 671 | * include in the screenshot. |
Dan Stoza | 16ec12a | 2014-02-14 15:06:55 -0800 | [diff] [blame] | 672 | * @param useIdentityTransform Replace whatever transformation (rotation, |
| 673 | * scaling, translation) the surface layers are currently using with the |
| 674 | * identity transformation while taking the screenshot. |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 675 | */ |
| 676 | public static void screenshot(IBinder display, Surface consumer, |
Dan Stoza | 16ec12a | 2014-02-14 15:06:55 -0800 | [diff] [blame] | 677 | int width, int height, int minLayer, int maxLayer, |
| 678 | boolean useIdentityTransform) { |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 679 | screenshot(display, consumer, new Rect(), width, height, minLayer, maxLayer, |
| 680 | false, useIdentityTransform); |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | /** |
| 684 | * Copy the current screen contents into the provided {@link Surface} |
| 685 | * |
| 686 | * @param display The display to take the screenshot of. |
| 687 | * @param consumer The {@link Surface} to take the screenshot into. |
| 688 | * @param width The desired width of the returned bitmap; the raw |
| 689 | * screen will be scaled down to this size. |
| 690 | * @param height The desired height of the returned bitmap; the raw |
| 691 | * screen will be scaled down to this size. |
| 692 | */ |
| 693 | public static void screenshot(IBinder display, Surface consumer, |
| 694 | int width, int height) { |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 695 | screenshot(display, consumer, new Rect(), width, height, 0, 0, true, false); |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | /** |
| 699 | * Copy the current screen contents into the provided {@link Surface} |
| 700 | * |
| 701 | * @param display The display to take the screenshot of. |
| 702 | * @param consumer The {@link Surface} to take the screenshot into. |
| 703 | */ |
| 704 | public static void screenshot(IBinder display, Surface consumer) { |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 705 | screenshot(display, consumer, new Rect(), 0, 0, 0, 0, true, false); |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 706 | } |
| 707 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 708 | /** |
| 709 | * Copy the current screen contents into a bitmap and return it. |
| 710 | * |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 711 | * CAVEAT: Versions of screenshot that return a {@link Bitmap} can |
| 712 | * be extremely slow; avoid use unless absolutely necessary; prefer |
| 713 | * the versions that use a {@link Surface} instead, such as |
| 714 | * {@link SurfaceControl#screenshot(IBinder, Surface)}. |
| 715 | * |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 716 | * @param sourceCrop The portion of the screen to capture into the Bitmap; |
| 717 | * caller may pass in 'new Rect()' if no cropping is desired. |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 718 | * @param width The desired width of the returned bitmap; the raw |
| 719 | * screen will be scaled down to this size. |
| 720 | * @param height The desired height of the returned bitmap; the raw |
| 721 | * screen will be scaled down to this size. |
| 722 | * @param minLayer The lowest (bottom-most Z order) surface layer to |
| 723 | * include in the screenshot. |
| 724 | * @param maxLayer The highest (top-most Z order) surface layer to |
| 725 | * include in the screenshot. |
Dan Stoza | 16ec12a | 2014-02-14 15:06:55 -0800 | [diff] [blame] | 726 | * @param useIdentityTransform Replace whatever transformation (rotation, |
| 727 | * scaling, translation) the surface layers are currently using with the |
| 728 | * identity transformation while taking the screenshot. |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame] | 729 | * @param rotation Apply a custom clockwise rotation to the screenshot, i.e. |
| 730 | * Surface.ROTATION_0,90,180,270. Surfaceflinger will always take |
| 731 | * screenshots in its native portrait orientation by default, so this is |
| 732 | * useful for returning screenshots that are independent of device |
| 733 | * orientation. |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 734 | * @return Returns a Bitmap containing the screen contents, or null |
Mathias Agopian | 49ff2c6 | 2013-03-17 01:05:21 -0700 | [diff] [blame] | 735 | * if an error occurs. Make sure to call Bitmap.recycle() as soon as |
| 736 | * possible, once its content is not needed anymore. |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 737 | */ |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 738 | public static Bitmap screenshot(Rect sourceCrop, int width, int height, |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame] | 739 | int minLayer, int maxLayer, boolean useIdentityTransform, |
| 740 | int rotation) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 741 | // TODO: should take the display as a parameter |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 742 | IBinder displayToken = SurfaceControl.getBuiltInDisplay( |
| 743 | SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN); |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 744 | return nativeScreenshot(displayToken, sourceCrop, width, height, |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame] | 745 | minLayer, maxLayer, false, useIdentityTransform, rotation); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | /** |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 749 | * Like {@link SurfaceControl#screenshot(int, int, int, int, boolean)} but |
| 750 | * includes all Surfaces in the screenshot. |
Mathias Agopian | 49ff2c6 | 2013-03-17 01:05:21 -0700 | [diff] [blame] | 751 | * |
| 752 | * @param width The desired width of the returned bitmap; the raw |
| 753 | * screen will be scaled down to this size. |
| 754 | * @param height The desired height of the returned bitmap; the raw |
| 755 | * screen will be scaled down to this size. |
| 756 | * @return Returns a Bitmap containing the screen contents, or null |
| 757 | * if an error occurs. Make sure to call Bitmap.recycle() as soon as |
| 758 | * possible, once its content is not needed anymore. |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 759 | */ |
| 760 | public static Bitmap screenshot(int width, int height) { |
| 761 | // TODO: should take the display as a parameter |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 762 | IBinder displayToken = SurfaceControl.getBuiltInDisplay( |
| 763 | SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN); |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame] | 764 | return nativeScreenshot(displayToken, new Rect(), width, height, 0, 0, true, |
| 765 | false, Surface.ROTATION_0); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 766 | } |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 767 | |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 768 | private static void screenshot(IBinder display, Surface consumer, Rect sourceCrop, |
Dan Stoza | 16ec12a | 2014-02-14 15:06:55 -0800 | [diff] [blame] | 769 | int width, int height, int minLayer, int maxLayer, boolean allLayers, |
| 770 | boolean useIdentityTransform) { |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 771 | if (display == null) { |
| 772 | throw new IllegalArgumentException("displayToken must not be null"); |
| 773 | } |
| 774 | if (consumer == null) { |
| 775 | throw new IllegalArgumentException("consumer must not be null"); |
| 776 | } |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 777 | nativeScreenshot(display, consumer, sourceCrop, width, height, |
| 778 | minLayer, maxLayer, allLayers, useIdentityTransform); |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 779 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 780 | } |