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