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 | #define LOG_TAG "SurfaceControl" |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 18 | #define LOG_NDEBUG 0 |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 19 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 20 | #include "android_os_Parcel.h" |
| 21 | #include "android_util_Binder.h" |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 22 | #include "android/graphics/Bitmap.h" |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 23 | #include "android/graphics/GraphicsJNI.h" |
| 24 | #include "android/graphics/Region.h" |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 25 | #include "core_jni_helpers.h" |
Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame] | 26 | |
Tom Cherry | 8ed74bb | 2017-07-10 14:31:18 -0700 | [diff] [blame] | 27 | #include <android-base/chrono_utils.h> |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 28 | #include <nativehelper/JNIHelp.h> |
| 29 | #include <nativehelper/ScopedUtfChars.h> |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 30 | #include <android_runtime/android_view_Surface.h> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 31 | #include <android_runtime/android_view_SurfaceSession.h> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 32 | #include <gui/Surface.h> |
| 33 | #include <gui/SurfaceComposerClient.h> |
Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame] | 34 | #include <jni.h> |
| 35 | #include <memory> |
| 36 | #include <stdio.h> |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 37 | #include <system/graphics.h> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 38 | #include <ui/DisplayInfo.h> |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 39 | #include <ui/HdrCapabilities.h> |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 40 | #include <ui/FrameStats.h> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 41 | #include <ui/Rect.h> |
| 42 | #include <ui/Region.h> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 43 | #include <utils/Log.h> |
| 44 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 45 | // ---------------------------------------------------------------------------- |
| 46 | |
| 47 | namespace android { |
| 48 | |
| 49 | static const char* const OutOfResourcesException = |
| 50 | "android/view/Surface$OutOfResourcesException"; |
| 51 | |
| 52 | static struct { |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 53 | jclass clazz; |
| 54 | jmethodID ctor; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 55 | jfieldID width; |
| 56 | jfieldID height; |
| 57 | jfieldID refreshRate; |
| 58 | jfieldID density; |
| 59 | jfieldID xDpi; |
| 60 | jfieldID yDpi; |
| 61 | jfieldID secure; |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 62 | jfieldID appVsyncOffsetNanos; |
| 63 | jfieldID presentationDeadlineNanos; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 64 | } gPhysicalDisplayInfoClassInfo; |
| 65 | |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 66 | static struct { |
| 67 | jfieldID bottom; |
| 68 | jfieldID left; |
| 69 | jfieldID right; |
| 70 | jfieldID top; |
| 71 | } gRectClassInfo; |
| 72 | |
Leon Scroggins | 46cb9bd | 2014-03-06 15:36:39 -0500 | [diff] [blame] | 73 | // Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref. |
| 74 | void DeleteScreenshot(void* addr, void* context) { |
| 75 | SkASSERT(addr == ((ScreenshotClient*) context)->getPixels()); |
| 76 | delete ((ScreenshotClient*) context); |
| 77 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 78 | |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 79 | static struct { |
| 80 | nsecs_t UNDEFINED_TIME_NANO; |
| 81 | jmethodID init; |
| 82 | } gWindowContentFrameStatsClassInfo; |
| 83 | |
| 84 | static struct { |
| 85 | nsecs_t UNDEFINED_TIME_NANO; |
| 86 | jmethodID init; |
| 87 | } gWindowAnimationFrameStatsClassInfo; |
| 88 | |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 89 | static struct { |
| 90 | jclass clazz; |
| 91 | jmethodID ctor; |
| 92 | } gHdrCapabilitiesClassInfo; |
| 93 | |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 94 | static struct { |
| 95 | jclass clazz; |
| 96 | jmethodID builder; |
| 97 | } gGraphicBufferClassInfo; |
| 98 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 99 | // ---------------------------------------------------------------------------- |
| 100 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 101 | static jlong nativeCreateTransaction(JNIEnv* env, jclass clazz) { |
| 102 | return reinterpret_cast<jlong>(new SurfaceComposerClient::Transaction); |
| 103 | } |
| 104 | |
| 105 | static void releaseTransaction(SurfaceComposerClient::Transaction* t) { |
| 106 | delete t; |
| 107 | } |
| 108 | |
| 109 | static jlong nativeGetNativeTransactionFinalizer(JNIEnv* env, jclass clazz) { |
| 110 | return static_cast<jlong>(reinterpret_cast<uintptr_t>(&releaseTransaction)); |
| 111 | } |
| 112 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 113 | static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj, |
Albert Chaulk | 3bf2e57 | 2016-11-22 13:59:19 -0500 | [diff] [blame] | 114 | jstring nameStr, jint w, jint h, jint format, jint flags, jlong parentObject, |
| 115 | jint windowType, jint ownerUid) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 116 | ScopedUtfChars name(env, nameStr); |
| 117 | sp<SurfaceComposerClient> client(android_view_SurfaceSession_getClient(env, sessionObj)); |
Robert Carr | 838120c | 2016-11-01 18:31:12 -0700 | [diff] [blame] | 118 | SurfaceControl *parent = reinterpret_cast<SurfaceControl*>(parentObject); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 119 | sp<SurfaceControl> surface = client->createSurface( |
Albert Chaulk | 3bf2e57 | 2016-11-22 13:59:19 -0500 | [diff] [blame] | 120 | String8(name.c_str()), w, h, format, flags, parent, windowType, ownerUid); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 121 | if (surface == NULL) { |
| 122 | jniThrowException(env, OutOfResourcesException, NULL); |
| 123 | return 0; |
| 124 | } |
Albert Chaulk | 3bf2e57 | 2016-11-22 13:59:19 -0500 | [diff] [blame] | 125 | |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 126 | surface->incStrong((void *)nativeCreate); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 127 | return reinterpret_cast<jlong>(surface.get()); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 128 | } |
| 129 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 130 | static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 131 | sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject)); |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 132 | ctrl->decStrong((void *)nativeCreate); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 133 | } |
| 134 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 135 | static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 136 | sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject)); |
| 137 | ctrl->clear(); |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 138 | ctrl->decStrong((void *)nativeCreate); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 141 | static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 142 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 143 | if (ctrl != NULL) { |
| 144 | ctrl->disconnect(); |
| 145 | } |
| 146 | } |
| 147 | |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 148 | static Rect rectFromObj(JNIEnv* env, jobject rectObj) { |
| 149 | int left = env->GetIntField(rectObj, gRectClassInfo.left); |
| 150 | int top = env->GetIntField(rectObj, gRectClassInfo.top); |
| 151 | int right = env->GetIntField(rectObj, gRectClassInfo.right); |
| 152 | int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom); |
| 153 | return Rect(left, top, right, bottom); |
| 154 | } |
| 155 | |
| 156 | static jobject nativeScreenshotToBuffer(JNIEnv* env, jclass clazz, |
| 157 | jobject displayTokenObj, jobject sourceCropObj, jint width, jint height, |
| 158 | jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform, |
| 159 | int rotation) { |
| 160 | sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj); |
| 161 | if (displayToken == NULL) { |
| 162 | return NULL; |
| 163 | } |
| 164 | Rect sourceCrop = rectFromObj(env, sourceCropObj); |
| 165 | if (allLayers) { |
Robert Carr | fb09bcf | 2017-01-26 11:52:35 -0800 | [diff] [blame] | 166 | minLayer = INT32_MIN; |
| 167 | maxLayer = INT32_MAX; |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 168 | } |
| 169 | sp<GraphicBuffer> buffer; |
Chavi Weingarten | ea2eb5a | 2017-11-29 21:26:24 +0000 | [diff] [blame] | 170 | status_t res = ScreenshotClient::captureToBuffer(displayToken, |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 171 | sourceCrop, width, height, minLayer, maxLayer, useIdentityTransform, |
| 172 | rotation, &buffer); |
| 173 | if (res != NO_ERROR) { |
| 174 | return NULL; |
| 175 | } |
| 176 | |
| 177 | return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz, |
| 178 | gGraphicBufferClassInfo.builder, |
| 179 | buffer->getWidth(), |
| 180 | buffer->getHeight(), |
| 181 | buffer->getPixelFormat(), |
Mathias Agopian | 113fd30 | 2017-05-25 18:31:04 -0700 | [diff] [blame] | 182 | (jint)buffer->getUsage(), |
Patrik Torstensson | 511a808 | 2017-03-27 15:04:11 +0100 | [diff] [blame] | 183 | (jlong)buffer.get()); |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 184 | } |
| 185 | |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 186 | static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz, |
| 187 | jobject displayTokenObj, jobject sourceCropObj, jint width, jint height, |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame] | 188 | jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform, |
| 189 | int rotation) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 190 | sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj); |
| 191 | if (displayToken == NULL) { |
| 192 | return NULL; |
| 193 | } |
| 194 | |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 195 | Rect sourceCrop = rectFromObj(env, sourceCropObj); |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 196 | |
Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame] | 197 | std::unique_ptr<ScreenshotClient> screenshot(new ScreenshotClient()); |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 198 | status_t res; |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame] | 199 | if (allLayers) { |
Robert Carr | fb09bcf | 2017-01-26 11:52:35 -0800 | [diff] [blame] | 200 | minLayer = INT32_MIN; |
| 201 | maxLayer = INT32_MAX; |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 202 | } |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame] | 203 | |
Chavi Weingarten | ea2eb5a | 2017-11-29 21:26:24 +0000 | [diff] [blame] | 204 | res = screenshot->update(displayToken, sourceCrop, width, height, |
| 205 | minLayer, maxLayer, useIdentityTransform, static_cast<uint32_t>(rotation)); |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 206 | if (res != NO_ERROR) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 207 | return NULL; |
| 208 | } |
| 209 | |
Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 210 | SkColorType colorType; |
| 211 | SkAlphaType alphaType; |
Chavi Weingarten | ea2eb5a | 2017-11-29 21:26:24 +0000 | [diff] [blame] | 212 | switch (screenshot->getFormat()) { |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 213 | case PIXEL_FORMAT_RGBX_8888: { |
Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 214 | colorType = kRGBA_8888_SkColorType; |
| 215 | alphaType = kOpaque_SkAlphaType; |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 216 | break; |
| 217 | } |
| 218 | case PIXEL_FORMAT_RGBA_8888: { |
Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 219 | colorType = kRGBA_8888_SkColorType; |
| 220 | alphaType = kPremul_SkAlphaType; |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 221 | break; |
| 222 | } |
Romain Guy | 9505a65 | 2016-12-14 09:43:50 -0800 | [diff] [blame] | 223 | case PIXEL_FORMAT_RGBA_FP16: { |
| 224 | colorType = kRGBA_F16_SkColorType; |
| 225 | alphaType = kPremul_SkAlphaType; |
| 226 | break; |
| 227 | } |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 228 | case PIXEL_FORMAT_RGB_565: { |
Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 229 | colorType = kRGB_565_SkColorType; |
| 230 | alphaType = kOpaque_SkAlphaType; |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 231 | break; |
| 232 | } |
| 233 | default: { |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 234 | return NULL; |
| 235 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 236 | } |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 237 | |
Chavi Weingarten | ea2eb5a | 2017-11-29 21:26:24 +0000 | [diff] [blame] | 238 | sk_sp<SkColorSpace> colorSpace; |
| 239 | if (screenshot->getDataSpace() == HAL_DATASPACE_DISPLAY_P3) { |
| 240 | colorSpace = SkColorSpace::MakeRGB( |
| 241 | SkColorSpace::kSRGB_RenderTargetGamma, SkColorSpace::kDCIP3_D65_Gamut); |
| 242 | } else { |
| 243 | colorSpace = SkColorSpace::MakeSRGB(); |
| 244 | } |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 245 | |
Chavi Weingarten | ea2eb5a | 2017-11-29 21:26:24 +0000 | [diff] [blame] | 246 | SkImageInfo screenshotInfo = SkImageInfo::Make(screenshot->getWidth(), |
| 247 | screenshot->getHeight(), |
| 248 | colorType, |
| 249 | alphaType, |
| 250 | colorSpace); |
| 251 | |
| 252 | const size_t rowBytes = |
| 253 | screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat()); |
| 254 | |
| 255 | if (!screenshotInfo.width() || !screenshotInfo.height()) { |
| 256 | return NULL; |
| 257 | } |
| 258 | |
| 259 | auto bitmap = new Bitmap( |
| 260 | (void*) screenshot->getPixels(), (void*) screenshot.get(), DeleteScreenshot, |
| 261 | screenshotInfo, rowBytes); |
| 262 | screenshot.release(); |
| 263 | bitmap->setImmutable(); |
| 264 | return bitmap::createBitmap(env, bitmap, |
| 265 | android::bitmap::kBitmapCreateFlag_Premultiplied, NULL); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 266 | } |
| 267 | |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 268 | static void nativeScreenshot(JNIEnv* env, jclass clazz, jobject displayTokenObj, |
| 269 | jobject surfaceObj, jobject sourceCropObj, jint width, jint height, |
| 270 | jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform) { |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 271 | sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj); |
Chavi Weingarten | ea2eb5a | 2017-11-29 21:26:24 +0000 | [diff] [blame] | 272 | if (displayToken != NULL) { |
| 273 | sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj); |
| 274 | if (consumer != NULL) { |
| 275 | int left = env->GetIntField(sourceCropObj, gRectClassInfo.left); |
| 276 | int top = env->GetIntField(sourceCropObj, gRectClassInfo.top); |
| 277 | int right = env->GetIntField(sourceCropObj, gRectClassInfo.right); |
| 278 | int bottom = env->GetIntField(sourceCropObj, gRectClassInfo.bottom); |
| 279 | Rect sourceCrop(left, top, right, bottom); |
| 280 | |
| 281 | if (allLayers) { |
| 282 | minLayer = INT32_MIN; |
| 283 | maxLayer = INT32_MAX; |
| 284 | } |
| 285 | ScreenshotClient::capture(displayToken, |
| 286 | consumer->getIGraphicBufferProducer(), sourceCrop, |
| 287 | width, height, minLayer, maxLayer, |
| 288 | useIdentityTransform); |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | static void nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject layerHandleToken, |
| 294 | jobject surfaceObj, jobject sourceCropObj, jfloat frameScale) { |
| 295 | |
| 296 | sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken); |
| 297 | if (layerHandle == NULL) { |
chaviw | 1cda84c | 2017-10-23 16:47:10 -0700 | [diff] [blame] | 298 | return; |
| 299 | } |
| 300 | |
| 301 | sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj); |
| 302 | if (consumer == NULL) { |
| 303 | return; |
| 304 | } |
| 305 | |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 306 | Rect sourceCrop; |
| 307 | if (sourceCropObj != NULL) { |
| 308 | sourceCrop = rectFromObj(env, sourceCropObj); |
| 309 | } |
| 310 | |
Chavi Weingarten | ea2eb5a | 2017-11-29 21:26:24 +0000 | [diff] [blame] | 311 | ScreenshotClient::captureLayers(layerHandle, consumer->getIGraphicBufferProducer(), sourceCrop, |
| 312 | frameScale); |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Chavi Weingarten | ea2eb5a | 2017-11-29 21:26:24 +0000 | [diff] [blame] | 315 | static jobject nativeCaptureLayersToBuffer(JNIEnv* env, jclass clazz, jobject layerHandleToken, |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 316 | jobject sourceCropObj, jfloat frameScale) { |
| 317 | |
| 318 | sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken); |
| 319 | if (layerHandle == NULL) { |
| 320 | return NULL; |
| 321 | } |
| 322 | |
| 323 | Rect sourceCrop; |
| 324 | if (sourceCropObj != NULL) { |
| 325 | sourceCrop = rectFromObj(env, sourceCropObj); |
| 326 | } |
| 327 | |
| 328 | sp<GraphicBuffer> buffer; |
Chavi Weingarten | ea2eb5a | 2017-11-29 21:26:24 +0000 | [diff] [blame] | 329 | status_t res = ScreenshotClient::captureLayersToBuffer(layerHandle, sourceCrop, frameScale, |
| 330 | &buffer); |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 331 | if (res != NO_ERROR) { |
| 332 | return NULL; |
| 333 | } |
| 334 | |
| 335 | return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz, |
| 336 | gGraphicBufferClassInfo.builder, |
| 337 | buffer->getWidth(), |
| 338 | buffer->getHeight(), |
| 339 | buffer->getPixelFormat(), |
| 340 | (jint)buffer->getUsage(), |
| 341 | (jlong)buffer.get()); |
chaviw | 1cda84c | 2017-10-23 16:47:10 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 344 | static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) { |
| 345 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 346 | transaction->apply(sync); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 347 | } |
| 348 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 349 | static void nativeMergeTransaction(JNIEnv* env, jclass clazz, |
| 350 | jlong transactionObj, jlong otherTransactionObj) { |
| 351 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 352 | auto otherTransaction = reinterpret_cast<SurfaceComposerClient::Transaction*>( |
| 353 | otherTransactionObj); |
| 354 | transaction->merge(std::move(*otherTransaction)); |
| 355 | } |
| 356 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 357 | static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) { |
| 358 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 359 | transaction->setAnimationTransaction(); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 360 | } |
| 361 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 362 | static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 363 | jlong nativeObject, jint zorder) { |
| 364 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 365 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 366 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 367 | transaction->setLayer(ctrl, zorder); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 368 | } |
| 369 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 370 | static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 371 | jlong nativeObject, |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 372 | jobject relativeTo, jint zorder) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 373 | |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 374 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 375 | sp<IBinder> handle = ibinderForJavaObject(env, relativeTo); |
| 376 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 377 | { |
| 378 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 379 | transaction->setRelativeLayer(ctrl, handle, zorder); |
| 380 | } |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 383 | static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 384 | jlong nativeObject, jfloat x, jfloat y) { |
| 385 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 386 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 387 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 388 | transaction->setPosition(ctrl, x, y); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 389 | } |
| 390 | |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 391 | static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 392 | jlong transactionObj, |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 393 | jlong nativeObject) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 394 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 395 | |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 396 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 397 | transaction->setGeometryAppliesWithResize(ctrl); |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 400 | static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 401 | jlong nativeObject, jint w, jint h) { |
| 402 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 403 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 404 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 405 | transaction->setSize(ctrl, w, h); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 406 | } |
| 407 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 408 | static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 409 | jlong nativeObject, jint flags, jint mask) { |
| 410 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 411 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 412 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 413 | transaction->setFlags(ctrl, flags, mask); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 414 | } |
| 415 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 416 | static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 417 | jlong nativeObject, jobject regionObj) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 418 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 419 | SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj); |
| 420 | if (!region) { |
| 421 | doThrowIAE(env); |
| 422 | return; |
| 423 | } |
| 424 | |
| 425 | const SkIRect& b(region->getBounds()); |
| 426 | Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom)); |
| 427 | if (region->isComplex()) { |
| 428 | SkRegion::Iterator it(*region); |
| 429 | while (!it.done()) { |
| 430 | const SkIRect& r(it.rect()); |
| 431 | reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom); |
| 432 | it.next(); |
| 433 | } |
| 434 | } |
| 435 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 436 | { |
| 437 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 438 | transaction->setTransparentRegionHint(ctrl, reg); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 439 | } |
| 440 | } |
| 441 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 442 | static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 443 | jlong nativeObject, jfloat alpha) { |
| 444 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 445 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 446 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 447 | transaction->setAlpha(ctrl, alpha); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 448 | } |
| 449 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 450 | static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 451 | jlong nativeObject, jfloatArray fColor) { |
| 452 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
chaviw | 0dd03f5 | 2017-08-25 12:15:26 -0700 | [diff] [blame] | 453 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 454 | |
chaviw | 0dd03f5 | 2017-08-25 12:15:26 -0700 | [diff] [blame] | 455 | float* floatColors = env->GetFloatArrayElements(fColor, 0); |
| 456 | half3 color(floatColors[0], floatColors[1], floatColors[2]); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 457 | transaction->setColor(ctrl, color); |
chaviw | 0dd03f5 | 2017-08-25 12:15:26 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 460 | static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 461 | jlong nativeObject, |
Robert Carr | 0edf18f | 2017-02-21 20:01:47 -0800 | [diff] [blame] | 462 | jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 463 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 464 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 465 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 466 | transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 467 | } |
| 468 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 469 | static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 470 | jlong nativeObject, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 471 | jint l, jint t, jint r, jint b) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 472 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 473 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 474 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 475 | Rect crop(l, t, r, b); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 476 | transaction->setCrop(ctrl, crop); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 477 | } |
| 478 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 479 | static void nativeSetFinalCrop(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 480 | jlong nativeObject, |
Pablo Ceballos | 27982e6 | 2016-03-09 10:50:45 -0800 | [diff] [blame] | 481 | jint l, jint t, jint r, jint b) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 482 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 483 | |
Pablo Ceballos | 27982e6 | 2016-03-09 10:50:45 -0800 | [diff] [blame] | 484 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 485 | Rect crop(l, t, r, b); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 486 | transaction->setFinalCrop(ctrl, crop); |
Pablo Ceballos | 27982e6 | 2016-03-09 10:50:45 -0800 | [diff] [blame] | 487 | } |
| 488 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 489 | static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 490 | jlong nativeObject, jint layerStack) { |
| 491 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 492 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 493 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 494 | transaction->setLayerStack(ctrl, layerStack); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) { |
| 498 | sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id)); |
| 499 | return javaObjectForIBinder(env, token); |
| 500 | } |
| 501 | |
| 502 | static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj, |
| 503 | jboolean secure) { |
| 504 | ScopedUtfChars name(env, nameObj); |
| 505 | sp<IBinder> token(SurfaceComposerClient::createDisplay( |
| 506 | String8(name.c_str()), bool(secure))); |
| 507 | return javaObjectForIBinder(env, token); |
| 508 | } |
| 509 | |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 510 | static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) { |
| 511 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 512 | if (token == NULL) return; |
| 513 | SurfaceComposerClient::destroyDisplay(token); |
| 514 | } |
| 515 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 516 | static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 517 | jlong transactionObj, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 518 | jobject tokenObj, jlong nativeSurfaceObject) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 519 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 520 | if (token == NULL) return; |
Mathias Agopian | ffddc9b | 2013-02-25 15:56:31 -0800 | [diff] [blame] | 521 | sp<IGraphicBufferProducer> bufferProducer; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 522 | sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject)); |
Mathias Agopian | ffddc9b | 2013-02-25 15:56:31 -0800 | [diff] [blame] | 523 | if (sur != NULL) { |
| 524 | bufferProducer = sur->getIGraphicBufferProducer(); |
| 525 | } |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 526 | |
| 527 | |
| 528 | status_t err = NO_ERROR; |
| 529 | { |
| 530 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 531 | err = transaction->setDisplaySurface(token, |
| 532 | bufferProducer); |
| 533 | } |
Pablo Ceballos | aff2f94 | 2016-07-29 14:49:55 -0700 | [diff] [blame] | 534 | if (err != NO_ERROR) { |
| 535 | doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this" |
| 536 | " Surface created with singleBufferMode?"); |
| 537 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 541 | jlong transactionObj, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 542 | jobject tokenObj, jint layerStack) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 543 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 544 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 545 | if (token == NULL) return; |
| 546 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 547 | { |
| 548 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 549 | transaction->setDisplayLayerStack(token, layerStack); |
| 550 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 554 | jlong transactionObj, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 555 | jobject tokenObj, jint orientation, |
| 556 | jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom, |
| 557 | jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) { |
| 558 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 559 | if (token == NULL) return; |
| 560 | Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom); |
| 561 | Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 562 | |
| 563 | { |
| 564 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 565 | transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect); |
| 566 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 567 | } |
| 568 | |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 569 | static void nativeSetDisplaySize(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 570 | jlong transactionObj, |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 571 | jobject tokenObj, jint width, jint height) { |
| 572 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 573 | if (token == NULL) return; |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 574 | |
| 575 | { |
| 576 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 577 | transaction->setDisplaySize(token, width, height); |
| 578 | } |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 581 | static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz, |
| 582 | jobject tokenObj) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 583 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 584 | if (token == NULL) return NULL; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 585 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 586 | Vector<DisplayInfo> configs; |
| 587 | if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR || |
| 588 | configs.size() == 0) { |
| 589 | return NULL; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 590 | } |
| 591 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 592 | jobjectArray configArray = env->NewObjectArray(configs.size(), |
| 593 | gPhysicalDisplayInfoClassInfo.clazz, NULL); |
| 594 | |
| 595 | for (size_t c = 0; c < configs.size(); ++c) { |
| 596 | const DisplayInfo& info = configs[c]; |
| 597 | jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz, |
| 598 | gPhysicalDisplayInfoClassInfo.ctor); |
| 599 | env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w); |
| 600 | env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h); |
| 601 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps); |
| 602 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density); |
| 603 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi); |
| 604 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi); |
| 605 | env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure); |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 606 | env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos, |
| 607 | info.appVsyncOffset); |
| 608 | env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos, |
| 609 | info.presentationDeadline); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 610 | env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj); |
| 611 | env->DeleteLocalRef(infoObj); |
| 612 | } |
| 613 | |
| 614 | return configArray; |
| 615 | } |
| 616 | |
| 617 | static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) { |
| 618 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 619 | if (token == NULL) return -1; |
| 620 | return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token)); |
| 621 | } |
| 622 | |
| 623 | static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) { |
| 624 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 625 | if (token == NULL) return JNI_FALSE; |
| 626 | status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id)); |
| 627 | return err == NO_ERROR ? JNI_TRUE : JNI_FALSE; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 628 | } |
| 629 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 630 | static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) { |
| 631 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 632 | if (token == NULL) return NULL; |
| 633 | Vector<android_color_mode_t> colorModes; |
| 634 | if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR || |
| 635 | colorModes.isEmpty()) { |
| 636 | return NULL; |
| 637 | } |
| 638 | |
| 639 | jintArray colorModesArray = env->NewIntArray(colorModes.size()); |
| 640 | if (colorModesArray == NULL) { |
| 641 | jniThrowException(env, "java/lang/OutOfMemoryError", NULL); |
| 642 | return NULL; |
| 643 | } |
| 644 | jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0); |
| 645 | for (size_t i = 0; i < colorModes.size(); i++) { |
| 646 | colorModesArrayValues[i] = static_cast<jint>(colorModes[i]); |
| 647 | } |
| 648 | env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0); |
| 649 | return colorModesArray; |
| 650 | } |
| 651 | |
| 652 | static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) { |
| 653 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 654 | if (token == NULL) return -1; |
| 655 | return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token)); |
| 656 | } |
| 657 | |
| 658 | static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass, |
| 659 | jobject tokenObj, jint colorMode) { |
| 660 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 661 | if (token == NULL) return JNI_FALSE; |
| 662 | status_t err = SurfaceComposerClient::setActiveColorMode(token, |
| 663 | static_cast<android_color_mode_t>(colorMode)); |
| 664 | return err == NO_ERROR ? JNI_TRUE : JNI_FALSE; |
| 665 | } |
| 666 | |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 667 | static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 668 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 669 | if (token == NULL) return; |
| 670 | |
Tom Cherry | 8ed74bb | 2017-07-10 14:31:18 -0700 | [diff] [blame] | 671 | android::base::Timer t; |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 672 | SurfaceComposerClient::setDisplayPowerMode(token, mode); |
Tom Cherry | 8ed74bb | 2017-07-10 14:31:18 -0700 | [diff] [blame] | 673 | if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()"); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 674 | } |
| 675 | |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 676 | static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 677 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 678 | status_t err = ctrl->clearLayerFrameStats(); |
| 679 | |
| 680 | if (err < 0 && err != NO_INIT) { |
| 681 | doThrowIAE(env); |
| 682 | } |
| 683 | |
| 684 | // The other end is not ready, just report we failed. |
| 685 | if (err == NO_INIT) { |
| 686 | return JNI_FALSE; |
| 687 | } |
| 688 | |
| 689 | return JNI_TRUE; |
| 690 | } |
| 691 | |
| 692 | static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject, |
| 693 | jobject outStats) { |
| 694 | FrameStats stats; |
| 695 | |
| 696 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 697 | status_t err = ctrl->getLayerFrameStats(&stats); |
| 698 | if (err < 0 && err != NO_INIT) { |
| 699 | doThrowIAE(env); |
| 700 | } |
| 701 | |
| 702 | // The other end is not ready, fine just return empty stats. |
| 703 | if (err == NO_INIT) { |
| 704 | return JNI_FALSE; |
| 705 | } |
| 706 | |
| 707 | jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano); |
| 708 | size_t frameCount = stats.desiredPresentTimesNano.size(); |
| 709 | |
| 710 | jlongArray postedTimesNanoDst = env->NewLongArray(frameCount); |
| 711 | if (postedTimesNanoDst == NULL) { |
| 712 | return JNI_FALSE; |
| 713 | } |
| 714 | |
| 715 | jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount); |
| 716 | if (presentedTimesNanoDst == NULL) { |
| 717 | return JNI_FALSE; |
| 718 | } |
| 719 | |
| 720 | jlongArray readyTimesNanoDst = env->NewLongArray(frameCount); |
| 721 | if (readyTimesNanoDst == NULL) { |
| 722 | return JNI_FALSE; |
| 723 | } |
| 724 | |
| 725 | nsecs_t postedTimesNanoSrc[frameCount]; |
| 726 | nsecs_t presentedTimesNanoSrc[frameCount]; |
| 727 | nsecs_t readyTimesNanoSrc[frameCount]; |
| 728 | |
| 729 | for (size_t i = 0; i < frameCount; i++) { |
| 730 | nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i]; |
| 731 | if (postedTimeNano == INT64_MAX) { |
| 732 | postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 733 | } |
| 734 | postedTimesNanoSrc[i] = postedTimeNano; |
| 735 | |
| 736 | nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i]; |
| 737 | if (presentedTimeNano == INT64_MAX) { |
| 738 | presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 739 | } |
| 740 | presentedTimesNanoSrc[i] = presentedTimeNano; |
| 741 | |
| 742 | nsecs_t readyTimeNano = stats.frameReadyTimesNano[i]; |
| 743 | if (readyTimeNano == INT64_MAX) { |
| 744 | readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 745 | } |
| 746 | readyTimesNanoSrc[i] = readyTimeNano; |
| 747 | } |
| 748 | |
| 749 | env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc); |
| 750 | env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc); |
| 751 | env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc); |
| 752 | |
| 753 | env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano, |
| 754 | postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst); |
| 755 | |
| 756 | if (env->ExceptionCheck()) { |
| 757 | return JNI_FALSE; |
| 758 | } |
| 759 | |
| 760 | return JNI_TRUE; |
| 761 | } |
| 762 | |
| 763 | static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) { |
| 764 | status_t err = SurfaceComposerClient::clearAnimationFrameStats(); |
| 765 | |
| 766 | if (err < 0 && err != NO_INIT) { |
| 767 | doThrowIAE(env); |
| 768 | } |
| 769 | |
| 770 | // The other end is not ready, just report we failed. |
| 771 | if (err == NO_INIT) { |
| 772 | return JNI_FALSE; |
| 773 | } |
| 774 | |
| 775 | return JNI_TRUE; |
| 776 | } |
| 777 | |
| 778 | static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) { |
| 779 | FrameStats stats; |
| 780 | |
| 781 | status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats); |
| 782 | if (err < 0 && err != NO_INIT) { |
| 783 | doThrowIAE(env); |
| 784 | } |
| 785 | |
| 786 | // The other end is not ready, fine just return empty stats. |
| 787 | if (err == NO_INIT) { |
| 788 | return JNI_FALSE; |
| 789 | } |
| 790 | |
| 791 | jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano); |
| 792 | size_t frameCount = stats.desiredPresentTimesNano.size(); |
| 793 | |
| 794 | jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount); |
| 795 | if (presentedTimesNanoDst == NULL) { |
| 796 | return JNI_FALSE; |
| 797 | } |
| 798 | |
| 799 | nsecs_t presentedTimesNanoSrc[frameCount]; |
| 800 | |
| 801 | for (size_t i = 0; i < frameCount; i++) { |
Allen Hair | ac5eda3 | 2014-04-24 11:50:37 -0700 | [diff] [blame] | 802 | nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i]; |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 803 | if (presentedTimeNano == INT64_MAX) { |
| 804 | presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 805 | } |
| 806 | presentedTimesNanoSrc[i] = presentedTimeNano; |
| 807 | } |
| 808 | |
| 809 | env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc); |
| 810 | |
| 811 | env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano, |
| 812 | presentedTimesNanoDst); |
| 813 | |
| 814 | if (env->ExceptionCheck()) { |
| 815 | return JNI_FALSE; |
| 816 | } |
| 817 | |
| 818 | return JNI_TRUE; |
| 819 | } |
| 820 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 821 | static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 822 | jlong nativeObject, |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 823 | jobject handleObject, jlong frameNumber) { |
| 824 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 825 | sp<IBinder> handle = ibinderForJavaObject(env, handleObject); |
| 826 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 827 | { |
| 828 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 829 | transaction->deferTransactionUntil(ctrl, handle, frameNumber); |
| 830 | } |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 831 | } |
| 832 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 833 | static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 834 | jlong nativeObject, |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 835 | jlong surfaceObject, jlong frameNumber) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 836 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 837 | |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 838 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 839 | sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject); |
| 840 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 841 | transaction->deferTransactionUntil(ctrl, barrier, frameNumber); |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 842 | } |
| 843 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 844 | static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 845 | jlong nativeObject, |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 846 | jobject newParentObject) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 847 | |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 848 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 849 | sp<IBinder> handle = ibinderForJavaObject(env, newParentObject); |
| 850 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 851 | { |
| 852 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 853 | transaction->reparentChildren(ctrl, handle); |
| 854 | } |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 855 | } |
| 856 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 857 | static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 858 | jlong nativeObject, |
chaviw | 7643140 | 2017-09-18 16:50:05 -0700 | [diff] [blame] | 859 | jobject newParentObject) { |
chaviw | 6354238 | 2017-08-17 17:39:29 -0700 | [diff] [blame] | 860 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 861 | sp<IBinder> parentHandle = ibinderForJavaObject(env, newParentObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 862 | |
| 863 | { |
| 864 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 865 | transaction->reparent(ctrl, parentHandle); |
| 866 | } |
chaviw | 6354238 | 2017-08-17 17:39:29 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 869 | static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 870 | jlong nativeObject) { |
| 871 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 872 | |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 873 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 874 | transaction->detachChildren(ctrl); |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 875 | } |
| 876 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 877 | static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 878 | jlong nativeObject, |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 879 | jint scalingMode) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 880 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 881 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 882 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 883 | transaction->setOverrideScalingMode(ctrl, scalingMode); |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 886 | static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 887 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 888 | return javaObjectForIBinder(env, ctrl->getHandle()); |
| 889 | } |
| 890 | |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 891 | static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) { |
| 892 | sp<IBinder> token(ibinderForJavaObject(env, tokenObject)); |
| 893 | if (token == NULL) return NULL; |
| 894 | |
| 895 | HdrCapabilities capabilities; |
| 896 | SurfaceComposerClient::getHdrCapabilities(token, &capabilities); |
| 897 | |
| 898 | const auto& types = capabilities.getSupportedHdrTypes(); |
| 899 | auto typesArray = env->NewIntArray(types.size()); |
| 900 | env->SetIntArrayRegion(typesArray, 0, types.size(), types.data()); |
| 901 | |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 902 | return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor, |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 903 | typesArray, capabilities.getDesiredMaxLuminance(), |
| 904 | capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance()); |
| 905 | } |
| 906 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 907 | // ---------------------------------------------------------------------------- |
| 908 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 909 | static const JNINativeMethod sSurfaceControlMethods[] = { |
Albert Chaulk | 3bf2e57 | 2016-11-22 13:59:19 -0500 | [diff] [blame] | 910 | {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJII)J", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 911 | (void*)nativeCreate }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 912 | {"nativeRelease", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 913 | (void*)nativeRelease }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 914 | {"nativeDestroy", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 915 | (void*)nativeDestroy }, |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 916 | {"nativeDisconnect", "(J)V", |
| 917 | (void*)nativeDisconnect }, |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame] | 918 | {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;", |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 919 | (void*)nativeScreenshotBitmap }, |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 920 | {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 921 | (void*)nativeScreenshot }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 922 | {"nativeCreateTransaction", "()J", |
| 923 | (void*)nativeCreateTransaction }, |
| 924 | {"nativeApplyTransaction", "(JZ)V", |
| 925 | (void*)nativeApplyTransaction }, |
| 926 | {"nativeGetNativeTransactionFinalizer", "()J", |
| 927 | (void*)nativeGetNativeTransactionFinalizer }, |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 928 | {"nativeMergeTransaction", "(JJ)V", |
| 929 | (void*)nativeMergeTransaction }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 930 | {"nativeSetAnimationTransaction", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 931 | (void*)nativeSetAnimationTransaction }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 932 | {"nativeSetLayer", "(JJI)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 933 | (void*)nativeSetLayer }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 934 | {"nativeSetRelativeLayer", "(JJLandroid/os/IBinder;I)V", |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 935 | (void*)nativeSetRelativeLayer }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 936 | {"nativeSetPosition", "(JJFF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 937 | (void*)nativeSetPosition }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 938 | {"nativeSetGeometryAppliesWithResize", "(JJ)V", |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 939 | (void*)nativeSetGeometryAppliesWithResize }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 940 | {"nativeSetSize", "(JJII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 941 | (void*)nativeSetSize }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 942 | {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 943 | (void*)nativeSetTransparentRegionHint }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 944 | {"nativeSetAlpha", "(JJF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 945 | (void*)nativeSetAlpha }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 946 | {"nativeSetColor", "(JJ[F)V", |
chaviw | 0dd03f5 | 2017-08-25 12:15:26 -0700 | [diff] [blame] | 947 | (void*)nativeSetColor }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 948 | {"nativeSetMatrix", "(JJFFFF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 949 | (void*)nativeSetMatrix }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 950 | {"nativeSetFlags", "(JJII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 951 | (void*)nativeSetFlags }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 952 | {"nativeSetWindowCrop", "(JJIIII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 953 | (void*)nativeSetWindowCrop }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 954 | {"nativeSetFinalCrop", "(JJIIII)V", |
Pablo Ceballos | 27982e6 | 2016-03-09 10:50:45 -0800 | [diff] [blame] | 955 | (void*)nativeSetFinalCrop }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 956 | {"nativeSetLayerStack", "(JJI)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 957 | (void*)nativeSetLayerStack }, |
| 958 | {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;", |
| 959 | (void*)nativeGetBuiltInDisplay }, |
| 960 | {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;", |
| 961 | (void*)nativeCreateDisplay }, |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 962 | {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V", |
| 963 | (void*)nativeDestroyDisplay }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 964 | {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 965 | (void*)nativeSetDisplaySurface }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 966 | {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 967 | (void*)nativeSetDisplayLayerStack }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 968 | {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 969 | (void*)nativeSetDisplayProjection }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 970 | {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V", |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 971 | (void*)nativeSetDisplaySize }, |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 972 | {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;", |
| 973 | (void*)nativeGetDisplayConfigs }, |
| 974 | {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I", |
| 975 | (void*)nativeGetActiveConfig }, |
| 976 | {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z", |
| 977 | (void*)nativeSetActiveConfig }, |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 978 | {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I", |
| 979 | (void*)nativeGetDisplayColorModes}, |
| 980 | {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I", |
| 981 | (void*)nativeGetActiveColorMode}, |
| 982 | {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z", |
| 983 | (void*)nativeSetActiveColorMode}, |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 984 | {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;", |
| 985 | (void*)nativeGetHdrCapabilities }, |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 986 | {"nativeClearContentFrameStats", "(J)Z", |
| 987 | (void*)nativeClearContentFrameStats }, |
| 988 | {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z", |
| 989 | (void*)nativeGetContentFrameStats }, |
| 990 | {"nativeClearAnimationFrameStats", "()Z", |
| 991 | (void*)nativeClearAnimationFrameStats }, |
| 992 | {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z", |
| 993 | (void*)nativeGetAnimationFrameStats }, |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 994 | {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V", |
| 995 | (void*)nativeSetDisplayPowerMode }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 996 | {"nativeDeferTransactionUntil", "(JJLandroid/os/IBinder;J)V", |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 997 | (void*)nativeDeferTransactionUntil }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 998 | {"nativeDeferTransactionUntilSurface", "(JJJJ)V", |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 999 | (void*)nativeDeferTransactionUntilSurface }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1000 | {"nativeReparentChildren", "(JJLandroid/os/IBinder;)V", |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 1001 | (void*)nativeReparentChildren } , |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1002 | {"nativeReparent", "(JJLandroid/os/IBinder;)V", |
chaviw | 7643140 | 2017-09-18 16:50:05 -0700 | [diff] [blame] | 1003 | (void*)nativeReparent }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1004 | {"nativeSeverChildren", "(JJ)V", |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 1005 | (void*)nativeSeverChildren } , |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1006 | {"nativeSetOverrideScalingMode", "(JJI)V", |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1007 | (void*)nativeSetOverrideScalingMode }, |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 1008 | {"nativeGetHandle", "(J)Landroid/os/IBinder;", |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1009 | (void*)nativeGetHandle }, |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 1010 | {"nativeScreenshotToBuffer", |
| 1011 | "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/GraphicBuffer;", |
| 1012 | (void*)nativeScreenshotToBuffer }, |
Chavi Weingarten | ea2eb5a | 2017-11-29 21:26:24 +0000 | [diff] [blame] | 1013 | {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;F)V", |
chaviw | 689e091c | 2017-11-20 18:33:05 -0800 | [diff] [blame] | 1014 | (void*)nativeCaptureLayers }, |
Chavi Weingarten | ea2eb5a | 2017-11-29 21:26:24 +0000 | [diff] [blame] | 1015 | {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/graphics/Rect;F)Landroid/graphics/GraphicBuffer;", |
| 1016 | (void*)nativeCaptureLayersToBuffer }, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1017 | }; |
| 1018 | |
| 1019 | int register_android_view_SurfaceControl(JNIEnv* env) |
| 1020 | { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1021 | int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1022 | sSurfaceControlMethods, NELEM(sSurfaceControlMethods)); |
| 1023 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1024 | jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo"); |
| 1025 | gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz); |
| 1026 | gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env, |
| 1027 | gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V"); |
| 1028 | gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I"); |
| 1029 | gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I"); |
| 1030 | gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F"); |
| 1031 | gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F"); |
| 1032 | gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F"); |
| 1033 | gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F"); |
| 1034 | gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z"); |
| 1035 | gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env, |
| 1036 | clazz, "appVsyncOffsetNanos", "J"); |
| 1037 | gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env, |
| 1038 | clazz, "presentationDeadlineNanos", "J"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 1039 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1040 | jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect"); |
| 1041 | gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I"); |
| 1042 | gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I"); |
| 1043 | gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I"); |
| 1044 | gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I"); |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 1045 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1046 | jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats"); |
| 1047 | jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env, |
| 1048 | frameStatsClazz, "UNDEFINED_TIME_NANO", "J"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 1049 | nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field); |
| 1050 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1051 | jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats"); |
| 1052 | gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env, |
| 1053 | contFrameStatsClazz, "init", "(J[J[J[J)V"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 1054 | gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; |
| 1055 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1056 | jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats"); |
| 1057 | gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env, |
| 1058 | animFrameStatsClazz, "init", "(J[J)V"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 1059 | gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; |
| 1060 | |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 1061 | jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities"); |
| 1062 | gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz); |
| 1063 | gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>", |
| 1064 | "([IFFF)V"); |
| 1065 | |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 1066 | jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer"); |
| 1067 | gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz); |
| 1068 | gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz, |
| 1069 | "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;"); |
| 1070 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1071 | return err; |
| 1072 | } |
| 1073 | |
| 1074 | }; |