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; |
| 170 | status_t res = ScreenshotClient::captureToBuffer(displayToken, |
| 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 | |
| 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; |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 212 | switch (screenshot->getFormat()) { |
| 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 | |
| 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 | } |
| 245 | |
Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 246 | SkImageInfo screenshotInfo = SkImageInfo::Make(screenshot->getWidth(), |
| 247 | screenshot->getHeight(), |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 248 | colorType, |
| 249 | alphaType, |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 250 | colorSpace); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 251 | |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 252 | const size_t rowBytes = |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 253 | screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat()); |
| 254 | |
Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 255 | if (!screenshotInfo.width() || !screenshotInfo.height()) { |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 256 | return NULL; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 257 | } |
| 258 | |
sergeyv | c1c5406 | 2016-10-19 18:47:26 -0700 | [diff] [blame] | 259 | auto bitmap = new Bitmap( |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 260 | (void*) screenshot->getPixels(), (void*) screenshot.get(), DeleteScreenshot, |
Leon Scroggins III | f51a80d | 2017-07-12 10:46:35 -0400 | [diff] [blame] | 261 | screenshotInfo, rowBytes); |
Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame] | 262 | screenshot.release(); |
sergeyv | c1c5406 | 2016-10-19 18:47:26 -0700 | [diff] [blame] | 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); |
| 272 | if (displayToken != NULL) { |
| 273 | sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj); |
| 274 | if (consumer != NULL) { |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 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 | |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 281 | if (allLayers) { |
Robert Carr | fb09bcf | 2017-01-26 11:52:35 -0800 | [diff] [blame] | 282 | minLayer = INT32_MIN; |
| 283 | maxLayer = INT32_MAX; |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 284 | } |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 285 | ScreenshotClient::capture(displayToken, |
| 286 | consumer->getIGraphicBufferProducer(), sourceCrop, |
Robert Carr | 7f6e986 | 2017-01-31 09:22:14 -0800 | [diff] [blame] | 287 | width, height, minLayer, maxLayer, |
Dan Stoza | 16ec12a | 2014-02-14 15:06:55 -0800 | [diff] [blame] | 288 | useIdentityTransform); |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | } |
| 292 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 293 | static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) { |
| 294 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 295 | transaction->apply(sync); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 296 | } |
| 297 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 298 | static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) { |
| 299 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 300 | transaction->setAnimationTransaction(); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 301 | } |
| 302 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 303 | static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 304 | jlong nativeObject, jint zorder) { |
| 305 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 306 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 307 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 308 | transaction->setLayer(ctrl, zorder); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 309 | } |
| 310 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 311 | static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 312 | jlong nativeObject, |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 313 | jobject relativeTo, jint zorder) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 314 | |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 315 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 316 | sp<IBinder> handle = ibinderForJavaObject(env, relativeTo); |
| 317 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 318 | { |
| 319 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 320 | transaction->setRelativeLayer(ctrl, handle, zorder); |
| 321 | } |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 324 | static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 325 | jlong nativeObject, jfloat x, jfloat y) { |
| 326 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 327 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 328 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 329 | transaction->setPosition(ctrl, x, y); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 330 | } |
| 331 | |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 332 | static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 333 | jlong transactionObj, |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 334 | jlong nativeObject) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 335 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 336 | |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 337 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 338 | transaction->setGeometryAppliesWithResize(ctrl); |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 341 | static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 342 | jlong nativeObject, jint w, jint h) { |
| 343 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 344 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 345 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 346 | transaction->setSize(ctrl, w, h); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 347 | } |
| 348 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 349 | static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 350 | jlong nativeObject, jint flags, jint mask) { |
| 351 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 352 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 353 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 354 | transaction->setFlags(ctrl, flags, mask); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 355 | } |
| 356 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 357 | static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 358 | jlong nativeObject, jobject regionObj) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 359 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 360 | SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj); |
| 361 | if (!region) { |
| 362 | doThrowIAE(env); |
| 363 | return; |
| 364 | } |
| 365 | |
| 366 | const SkIRect& b(region->getBounds()); |
| 367 | Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom)); |
| 368 | if (region->isComplex()) { |
| 369 | SkRegion::Iterator it(*region); |
| 370 | while (!it.done()) { |
| 371 | const SkIRect& r(it.rect()); |
| 372 | reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom); |
| 373 | it.next(); |
| 374 | } |
| 375 | } |
| 376 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 377 | { |
| 378 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 379 | transaction->setTransparentRegionHint(ctrl, reg); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 383 | static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 384 | jlong nativeObject, jfloat alpha) { |
| 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->setAlpha(ctrl, alpha); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 389 | } |
| 390 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 391 | static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 392 | jlong nativeObject, jfloatArray fColor) { |
| 393 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
chaviw | 0dd03f5 | 2017-08-25 12:15:26 -0700 | [diff] [blame] | 394 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 395 | |
chaviw | 0dd03f5 | 2017-08-25 12:15:26 -0700 | [diff] [blame] | 396 | float* floatColors = env->GetFloatArrayElements(fColor, 0); |
| 397 | half3 color(floatColors[0], floatColors[1], floatColors[2]); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 398 | transaction->setColor(ctrl, color); |
chaviw | 0dd03f5 | 2017-08-25 12:15:26 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 401 | static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 402 | jlong nativeObject, |
Robert Carr | 0edf18f | 2017-02-21 20:01:47 -0800 | [diff] [blame] | 403 | jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 404 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 405 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 406 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 407 | transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 408 | } |
| 409 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 410 | static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 411 | jlong nativeObject, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 412 | jint l, jint t, jint r, jint b) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 413 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 414 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 415 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 416 | Rect crop(l, t, r, b); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 417 | transaction->setCrop(ctrl, crop); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 418 | } |
| 419 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 420 | static void nativeSetFinalCrop(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 421 | jlong nativeObject, |
Pablo Ceballos | 27982e6 | 2016-03-09 10:50:45 -0800 | [diff] [blame] | 422 | jint l, jint t, jint r, jint b) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 423 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 424 | |
Pablo Ceballos | 27982e6 | 2016-03-09 10:50:45 -0800 | [diff] [blame] | 425 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 426 | Rect crop(l, t, r, b); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 427 | transaction->setFinalCrop(ctrl, crop); |
Pablo Ceballos | 27982e6 | 2016-03-09 10:50:45 -0800 | [diff] [blame] | 428 | } |
| 429 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 430 | static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 431 | jlong nativeObject, jint layerStack) { |
| 432 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 433 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 434 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 435 | transaction->setLayerStack(ctrl, layerStack); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) { |
| 439 | sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id)); |
| 440 | return javaObjectForIBinder(env, token); |
| 441 | } |
| 442 | |
| 443 | static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj, |
| 444 | jboolean secure) { |
| 445 | ScopedUtfChars name(env, nameObj); |
| 446 | sp<IBinder> token(SurfaceComposerClient::createDisplay( |
| 447 | String8(name.c_str()), bool(secure))); |
| 448 | return javaObjectForIBinder(env, token); |
| 449 | } |
| 450 | |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 451 | static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) { |
| 452 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 453 | if (token == NULL) return; |
| 454 | SurfaceComposerClient::destroyDisplay(token); |
| 455 | } |
| 456 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 457 | static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 458 | jlong transactionObj, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 459 | jobject tokenObj, jlong nativeSurfaceObject) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 460 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 461 | if (token == NULL) return; |
Mathias Agopian | ffddc9b | 2013-02-25 15:56:31 -0800 | [diff] [blame] | 462 | sp<IGraphicBufferProducer> bufferProducer; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 463 | sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject)); |
Mathias Agopian | ffddc9b | 2013-02-25 15:56:31 -0800 | [diff] [blame] | 464 | if (sur != NULL) { |
| 465 | bufferProducer = sur->getIGraphicBufferProducer(); |
| 466 | } |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 467 | |
| 468 | |
| 469 | status_t err = NO_ERROR; |
| 470 | { |
| 471 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 472 | err = transaction->setDisplaySurface(token, |
| 473 | bufferProducer); |
| 474 | } |
Pablo Ceballos | aff2f94 | 2016-07-29 14:49:55 -0700 | [diff] [blame] | 475 | if (err != NO_ERROR) { |
| 476 | doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this" |
| 477 | " Surface created with singleBufferMode?"); |
| 478 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 482 | jlong transactionObj, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 483 | jobject tokenObj, jint layerStack) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 484 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 485 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 486 | if (token == NULL) return; |
| 487 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 488 | { |
| 489 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 490 | transaction->setDisplayLayerStack(token, layerStack); |
| 491 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 495 | jlong transactionObj, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 496 | jobject tokenObj, jint orientation, |
| 497 | jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom, |
| 498 | jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) { |
| 499 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 500 | if (token == NULL) return; |
| 501 | Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom); |
| 502 | Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 503 | |
| 504 | { |
| 505 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 506 | transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect); |
| 507 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 508 | } |
| 509 | |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 510 | static void nativeSetDisplaySize(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 511 | jlong transactionObj, |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 512 | jobject tokenObj, jint width, jint height) { |
| 513 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 514 | if (token == NULL) return; |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 515 | |
| 516 | { |
| 517 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 518 | transaction->setDisplaySize(token, width, height); |
| 519 | } |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 522 | static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz, |
| 523 | jobject tokenObj) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 524 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 525 | if (token == NULL) return NULL; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 526 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 527 | Vector<DisplayInfo> configs; |
| 528 | if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR || |
| 529 | configs.size() == 0) { |
| 530 | return NULL; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 531 | } |
| 532 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 533 | jobjectArray configArray = env->NewObjectArray(configs.size(), |
| 534 | gPhysicalDisplayInfoClassInfo.clazz, NULL); |
| 535 | |
| 536 | for (size_t c = 0; c < configs.size(); ++c) { |
| 537 | const DisplayInfo& info = configs[c]; |
| 538 | jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz, |
| 539 | gPhysicalDisplayInfoClassInfo.ctor); |
| 540 | env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w); |
| 541 | env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h); |
| 542 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps); |
| 543 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density); |
| 544 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi); |
| 545 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi); |
| 546 | env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure); |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 547 | env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos, |
| 548 | info.appVsyncOffset); |
| 549 | env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos, |
| 550 | info.presentationDeadline); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 551 | env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj); |
| 552 | env->DeleteLocalRef(infoObj); |
| 553 | } |
| 554 | |
| 555 | return configArray; |
| 556 | } |
| 557 | |
| 558 | static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) { |
| 559 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 560 | if (token == NULL) return -1; |
| 561 | return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token)); |
| 562 | } |
| 563 | |
| 564 | static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) { |
| 565 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 566 | if (token == NULL) return JNI_FALSE; |
| 567 | status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id)); |
| 568 | return err == NO_ERROR ? JNI_TRUE : JNI_FALSE; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 569 | } |
| 570 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 571 | static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) { |
| 572 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 573 | if (token == NULL) return NULL; |
| 574 | Vector<android_color_mode_t> colorModes; |
| 575 | if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR || |
| 576 | colorModes.isEmpty()) { |
| 577 | return NULL; |
| 578 | } |
| 579 | |
| 580 | jintArray colorModesArray = env->NewIntArray(colorModes.size()); |
| 581 | if (colorModesArray == NULL) { |
| 582 | jniThrowException(env, "java/lang/OutOfMemoryError", NULL); |
| 583 | return NULL; |
| 584 | } |
| 585 | jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0); |
| 586 | for (size_t i = 0; i < colorModes.size(); i++) { |
| 587 | colorModesArrayValues[i] = static_cast<jint>(colorModes[i]); |
| 588 | } |
| 589 | env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0); |
| 590 | return colorModesArray; |
| 591 | } |
| 592 | |
| 593 | static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) { |
| 594 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 595 | if (token == NULL) return -1; |
| 596 | return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token)); |
| 597 | } |
| 598 | |
| 599 | static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass, |
| 600 | jobject tokenObj, jint colorMode) { |
| 601 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 602 | if (token == NULL) return JNI_FALSE; |
| 603 | status_t err = SurfaceComposerClient::setActiveColorMode(token, |
| 604 | static_cast<android_color_mode_t>(colorMode)); |
| 605 | return err == NO_ERROR ? JNI_TRUE : JNI_FALSE; |
| 606 | } |
| 607 | |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 608 | static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 609 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 610 | if (token == NULL) return; |
| 611 | |
Tom Cherry | 8ed74bb | 2017-07-10 14:31:18 -0700 | [diff] [blame] | 612 | android::base::Timer t; |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 613 | SurfaceComposerClient::setDisplayPowerMode(token, mode); |
Tom Cherry | 8ed74bb | 2017-07-10 14:31:18 -0700 | [diff] [blame] | 614 | if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()"); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 615 | } |
| 616 | |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 617 | static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 618 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 619 | status_t err = ctrl->clearLayerFrameStats(); |
| 620 | |
| 621 | if (err < 0 && err != NO_INIT) { |
| 622 | doThrowIAE(env); |
| 623 | } |
| 624 | |
| 625 | // The other end is not ready, just report we failed. |
| 626 | if (err == NO_INIT) { |
| 627 | return JNI_FALSE; |
| 628 | } |
| 629 | |
| 630 | return JNI_TRUE; |
| 631 | } |
| 632 | |
| 633 | static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject, |
| 634 | jobject outStats) { |
| 635 | FrameStats stats; |
| 636 | |
| 637 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 638 | status_t err = ctrl->getLayerFrameStats(&stats); |
| 639 | if (err < 0 && err != NO_INIT) { |
| 640 | doThrowIAE(env); |
| 641 | } |
| 642 | |
| 643 | // The other end is not ready, fine just return empty stats. |
| 644 | if (err == NO_INIT) { |
| 645 | return JNI_FALSE; |
| 646 | } |
| 647 | |
| 648 | jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano); |
| 649 | size_t frameCount = stats.desiredPresentTimesNano.size(); |
| 650 | |
| 651 | jlongArray postedTimesNanoDst = env->NewLongArray(frameCount); |
| 652 | if (postedTimesNanoDst == NULL) { |
| 653 | return JNI_FALSE; |
| 654 | } |
| 655 | |
| 656 | jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount); |
| 657 | if (presentedTimesNanoDst == NULL) { |
| 658 | return JNI_FALSE; |
| 659 | } |
| 660 | |
| 661 | jlongArray readyTimesNanoDst = env->NewLongArray(frameCount); |
| 662 | if (readyTimesNanoDst == NULL) { |
| 663 | return JNI_FALSE; |
| 664 | } |
| 665 | |
| 666 | nsecs_t postedTimesNanoSrc[frameCount]; |
| 667 | nsecs_t presentedTimesNanoSrc[frameCount]; |
| 668 | nsecs_t readyTimesNanoSrc[frameCount]; |
| 669 | |
| 670 | for (size_t i = 0; i < frameCount; i++) { |
| 671 | nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i]; |
| 672 | if (postedTimeNano == INT64_MAX) { |
| 673 | postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 674 | } |
| 675 | postedTimesNanoSrc[i] = postedTimeNano; |
| 676 | |
| 677 | nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i]; |
| 678 | if (presentedTimeNano == INT64_MAX) { |
| 679 | presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 680 | } |
| 681 | presentedTimesNanoSrc[i] = presentedTimeNano; |
| 682 | |
| 683 | nsecs_t readyTimeNano = stats.frameReadyTimesNano[i]; |
| 684 | if (readyTimeNano == INT64_MAX) { |
| 685 | readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 686 | } |
| 687 | readyTimesNanoSrc[i] = readyTimeNano; |
| 688 | } |
| 689 | |
| 690 | env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc); |
| 691 | env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc); |
| 692 | env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc); |
| 693 | |
| 694 | env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano, |
| 695 | postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst); |
| 696 | |
| 697 | if (env->ExceptionCheck()) { |
| 698 | return JNI_FALSE; |
| 699 | } |
| 700 | |
| 701 | return JNI_TRUE; |
| 702 | } |
| 703 | |
| 704 | static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) { |
| 705 | status_t err = SurfaceComposerClient::clearAnimationFrameStats(); |
| 706 | |
| 707 | if (err < 0 && err != NO_INIT) { |
| 708 | doThrowIAE(env); |
| 709 | } |
| 710 | |
| 711 | // The other end is not ready, just report we failed. |
| 712 | if (err == NO_INIT) { |
| 713 | return JNI_FALSE; |
| 714 | } |
| 715 | |
| 716 | return JNI_TRUE; |
| 717 | } |
| 718 | |
| 719 | static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) { |
| 720 | FrameStats stats; |
| 721 | |
| 722 | status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats); |
| 723 | if (err < 0 && err != NO_INIT) { |
| 724 | doThrowIAE(env); |
| 725 | } |
| 726 | |
| 727 | // The other end is not ready, fine just return empty stats. |
| 728 | if (err == NO_INIT) { |
| 729 | return JNI_FALSE; |
| 730 | } |
| 731 | |
| 732 | jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano); |
| 733 | size_t frameCount = stats.desiredPresentTimesNano.size(); |
| 734 | |
| 735 | jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount); |
| 736 | if (presentedTimesNanoDst == NULL) { |
| 737 | return JNI_FALSE; |
| 738 | } |
| 739 | |
| 740 | nsecs_t presentedTimesNanoSrc[frameCount]; |
| 741 | |
| 742 | for (size_t i = 0; i < frameCount; i++) { |
Allen Hair | ac5eda3 | 2014-04-24 11:50:37 -0700 | [diff] [blame] | 743 | nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i]; |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 744 | if (presentedTimeNano == INT64_MAX) { |
| 745 | presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 746 | } |
| 747 | presentedTimesNanoSrc[i] = presentedTimeNano; |
| 748 | } |
| 749 | |
| 750 | env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc); |
| 751 | |
| 752 | env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano, |
| 753 | presentedTimesNanoDst); |
| 754 | |
| 755 | if (env->ExceptionCheck()) { |
| 756 | return JNI_FALSE; |
| 757 | } |
| 758 | |
| 759 | return JNI_TRUE; |
| 760 | } |
| 761 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 762 | static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 763 | jlong nativeObject, |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 764 | jobject handleObject, jlong frameNumber) { |
| 765 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 766 | sp<IBinder> handle = ibinderForJavaObject(env, handleObject); |
| 767 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 768 | { |
| 769 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 770 | transaction->deferTransactionUntil(ctrl, handle, frameNumber); |
| 771 | } |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 772 | } |
| 773 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 774 | static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 775 | jlong nativeObject, |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 776 | jlong surfaceObject, jlong frameNumber) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 777 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 778 | |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 779 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 780 | sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject); |
| 781 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 782 | transaction->deferTransactionUntil(ctrl, barrier, frameNumber); |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 783 | } |
| 784 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 785 | static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 786 | jlong nativeObject, |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 787 | jobject newParentObject) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 788 | |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 789 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 790 | sp<IBinder> handle = ibinderForJavaObject(env, newParentObject); |
| 791 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 792 | { |
| 793 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 794 | transaction->reparentChildren(ctrl, handle); |
| 795 | } |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 796 | } |
| 797 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 798 | static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 799 | jlong nativeObject, |
chaviw | 7643140 | 2017-09-18 16:50:05 -0700 | [diff] [blame] | 800 | jobject newParentObject) { |
chaviw | 6354238 | 2017-08-17 17:39:29 -0700 | [diff] [blame] | 801 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 802 | sp<IBinder> parentHandle = ibinderForJavaObject(env, newParentObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 803 | |
| 804 | { |
| 805 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 806 | transaction->reparent(ctrl, parentHandle); |
| 807 | } |
chaviw | 6354238 | 2017-08-17 17:39:29 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 810 | static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 811 | jlong nativeObject) { |
| 812 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 813 | |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 814 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 815 | transaction->detachChildren(ctrl); |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 816 | } |
| 817 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 818 | static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 819 | jlong nativeObject, |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 820 | jint scalingMode) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 821 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 822 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 823 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 824 | transaction->setOverrideScalingMode(ctrl, scalingMode); |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 825 | } |
| 826 | |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 827 | static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 828 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 829 | return javaObjectForIBinder(env, ctrl->getHandle()); |
| 830 | } |
| 831 | |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 832 | static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) { |
| 833 | sp<IBinder> token(ibinderForJavaObject(env, tokenObject)); |
| 834 | if (token == NULL) return NULL; |
| 835 | |
| 836 | HdrCapabilities capabilities; |
| 837 | SurfaceComposerClient::getHdrCapabilities(token, &capabilities); |
| 838 | |
| 839 | const auto& types = capabilities.getSupportedHdrTypes(); |
| 840 | auto typesArray = env->NewIntArray(types.size()); |
| 841 | env->SetIntArrayRegion(typesArray, 0, types.size(), types.data()); |
| 842 | |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 843 | return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor, |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 844 | typesArray, capabilities.getDesiredMaxLuminance(), |
| 845 | capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance()); |
| 846 | } |
| 847 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 848 | // ---------------------------------------------------------------------------- |
| 849 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 850 | static const JNINativeMethod sSurfaceControlMethods[] = { |
Albert Chaulk | 3bf2e57 | 2016-11-22 13:59:19 -0500 | [diff] [blame] | 851 | {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJII)J", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 852 | (void*)nativeCreate }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 853 | {"nativeRelease", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 854 | (void*)nativeRelease }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 855 | {"nativeDestroy", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 856 | (void*)nativeDestroy }, |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 857 | {"nativeDisconnect", "(J)V", |
| 858 | (void*)nativeDisconnect }, |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame] | 859 | {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;", |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 860 | (void*)nativeScreenshotBitmap }, |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 861 | {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 862 | (void*)nativeScreenshot }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 863 | {"nativeCreateTransaction", "()J", |
| 864 | (void*)nativeCreateTransaction }, |
| 865 | {"nativeApplyTransaction", "(JZ)V", |
| 866 | (void*)nativeApplyTransaction }, |
| 867 | {"nativeGetNativeTransactionFinalizer", "()J", |
| 868 | (void*)nativeGetNativeTransactionFinalizer }, |
| 869 | {"nativeSetAnimationTransaction", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 870 | (void*)nativeSetAnimationTransaction }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 871 | {"nativeSetLayer", "(JJI)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 872 | (void*)nativeSetLayer }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 873 | {"nativeSetRelativeLayer", "(JJLandroid/os/IBinder;I)V", |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 874 | (void*)nativeSetRelativeLayer }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 875 | {"nativeSetPosition", "(JJFF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 876 | (void*)nativeSetPosition }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 877 | {"nativeSetGeometryAppliesWithResize", "(JJ)V", |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 878 | (void*)nativeSetGeometryAppliesWithResize }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 879 | {"nativeSetSize", "(JJII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 880 | (void*)nativeSetSize }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 881 | {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 882 | (void*)nativeSetTransparentRegionHint }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 883 | {"nativeSetAlpha", "(JJF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 884 | (void*)nativeSetAlpha }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 885 | {"nativeSetColor", "(JJ[F)V", |
chaviw | 0dd03f5 | 2017-08-25 12:15:26 -0700 | [diff] [blame] | 886 | (void*)nativeSetColor }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 887 | {"nativeSetMatrix", "(JJFFFF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 888 | (void*)nativeSetMatrix }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 889 | {"nativeSetFlags", "(JJII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 890 | (void*)nativeSetFlags }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 891 | {"nativeSetWindowCrop", "(JJIIII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 892 | (void*)nativeSetWindowCrop }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 893 | {"nativeSetFinalCrop", "(JJIIII)V", |
Pablo Ceballos | 27982e6 | 2016-03-09 10:50:45 -0800 | [diff] [blame] | 894 | (void*)nativeSetFinalCrop }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 895 | {"nativeSetLayerStack", "(JJI)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 896 | (void*)nativeSetLayerStack }, |
| 897 | {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;", |
| 898 | (void*)nativeGetBuiltInDisplay }, |
| 899 | {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;", |
| 900 | (void*)nativeCreateDisplay }, |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 901 | {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V", |
| 902 | (void*)nativeDestroyDisplay }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 903 | {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 904 | (void*)nativeSetDisplaySurface }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 905 | {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 906 | (void*)nativeSetDisplayLayerStack }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 907 | {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 908 | (void*)nativeSetDisplayProjection }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 909 | {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V", |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 910 | (void*)nativeSetDisplaySize }, |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 911 | {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;", |
| 912 | (void*)nativeGetDisplayConfigs }, |
| 913 | {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I", |
| 914 | (void*)nativeGetActiveConfig }, |
| 915 | {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z", |
| 916 | (void*)nativeSetActiveConfig }, |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 917 | {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I", |
| 918 | (void*)nativeGetDisplayColorModes}, |
| 919 | {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I", |
| 920 | (void*)nativeGetActiveColorMode}, |
| 921 | {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z", |
| 922 | (void*)nativeSetActiveColorMode}, |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 923 | {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;", |
| 924 | (void*)nativeGetHdrCapabilities }, |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 925 | {"nativeClearContentFrameStats", "(J)Z", |
| 926 | (void*)nativeClearContentFrameStats }, |
| 927 | {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z", |
| 928 | (void*)nativeGetContentFrameStats }, |
| 929 | {"nativeClearAnimationFrameStats", "()Z", |
| 930 | (void*)nativeClearAnimationFrameStats }, |
| 931 | {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z", |
| 932 | (void*)nativeGetAnimationFrameStats }, |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 933 | {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V", |
| 934 | (void*)nativeSetDisplayPowerMode }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 935 | {"nativeDeferTransactionUntil", "(JJLandroid/os/IBinder;J)V", |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 936 | (void*)nativeDeferTransactionUntil }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 937 | {"nativeDeferTransactionUntilSurface", "(JJJJ)V", |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 938 | (void*)nativeDeferTransactionUntilSurface }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 939 | {"nativeReparentChildren", "(JJLandroid/os/IBinder;)V", |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 940 | (void*)nativeReparentChildren } , |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 941 | {"nativeReparent", "(JJLandroid/os/IBinder;)V", |
chaviw | 7643140 | 2017-09-18 16:50:05 -0700 | [diff] [blame] | 942 | (void*)nativeReparent }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 943 | {"nativeSeverChildren", "(JJ)V", |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 944 | (void*)nativeSeverChildren } , |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 945 | {"nativeSetOverrideScalingMode", "(JJI)V", |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 946 | (void*)nativeSetOverrideScalingMode }, |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 947 | {"nativeGetHandle", "(J)Landroid/os/IBinder;", |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 948 | (void*)nativeGetHandle }, |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 949 | {"nativeScreenshotToBuffer", |
| 950 | "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/GraphicBuffer;", |
| 951 | (void*)nativeScreenshotToBuffer }, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 952 | }; |
| 953 | |
| 954 | int register_android_view_SurfaceControl(JNIEnv* env) |
| 955 | { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 956 | int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 957 | sSurfaceControlMethods, NELEM(sSurfaceControlMethods)); |
| 958 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 959 | jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo"); |
| 960 | gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz); |
| 961 | gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env, |
| 962 | gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V"); |
| 963 | gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I"); |
| 964 | gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I"); |
| 965 | gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F"); |
| 966 | gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F"); |
| 967 | gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F"); |
| 968 | gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F"); |
| 969 | gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z"); |
| 970 | gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env, |
| 971 | clazz, "appVsyncOffsetNanos", "J"); |
| 972 | gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env, |
| 973 | clazz, "presentationDeadlineNanos", "J"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 974 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 975 | jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect"); |
| 976 | gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I"); |
| 977 | gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I"); |
| 978 | gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I"); |
| 979 | gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I"); |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 980 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 981 | jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats"); |
| 982 | jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env, |
| 983 | frameStatsClazz, "UNDEFINED_TIME_NANO", "J"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 984 | nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field); |
| 985 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 986 | jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats"); |
| 987 | gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env, |
| 988 | contFrameStatsClazz, "init", "(J[J[J[J)V"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 989 | gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; |
| 990 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 991 | jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats"); |
| 992 | gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env, |
| 993 | animFrameStatsClazz, "init", "(J[J)V"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 994 | gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; |
| 995 | |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 996 | jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities"); |
| 997 | gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz); |
| 998 | gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>", |
| 999 | "([IFFF)V"); |
| 1000 | |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 1001 | jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer"); |
| 1002 | gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz); |
| 1003 | gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz, |
| 1004 | "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;"); |
| 1005 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1006 | return err; |
| 1007 | } |
| 1008 | |
| 1009 | }; |