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 | |
Peiyong Lin | 52bb6b4 | 2018-10-01 11:40:50 -0700 | [diff] [blame^] | 342 | static void nativeSetColorTransform(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 343 | jlong nativeObject, jfloatArray fMatrix, jfloatArray fTranslation) { |
| 344 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 345 | SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject); |
| 346 | float* floatMatrix = env->GetFloatArrayElements(fMatrix, 0); |
| 347 | mat3 matrix(static_cast<float const*>(floatMatrix)); |
| 348 | float* floatTranslation = env->GetFloatArrayElements(fTranslation, 0); |
| 349 | vec3 translation(floatTranslation[0], floatTranslation[1], floatTranslation[2]); |
| 350 | transaction->setColorTransform(surfaceControl, matrix, translation); |
| 351 | } |
| 352 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 353 | static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 354 | jlong nativeObject, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 355 | jint l, jint t, jint r, jint b) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 356 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 357 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 358 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 359 | Rect crop(l, t, r, b); |
Marissa Wall | cb32fdd | 2018-07-24 09:53:30 -0700 | [diff] [blame] | 360 | transaction->setCrop_legacy(ctrl, crop); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 361 | } |
| 362 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 363 | static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 364 | jlong nativeObject, jint layerStack) { |
| 365 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 366 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 367 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 368 | transaction->setLayerStack(ctrl, layerStack); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) { |
| 372 | sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id)); |
| 373 | return javaObjectForIBinder(env, token); |
| 374 | } |
| 375 | |
| 376 | static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj, |
| 377 | jboolean secure) { |
| 378 | ScopedUtfChars name(env, nameObj); |
| 379 | sp<IBinder> token(SurfaceComposerClient::createDisplay( |
| 380 | String8(name.c_str()), bool(secure))); |
| 381 | return javaObjectForIBinder(env, token); |
| 382 | } |
| 383 | |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 384 | static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) { |
| 385 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 386 | if (token == NULL) return; |
| 387 | SurfaceComposerClient::destroyDisplay(token); |
| 388 | } |
| 389 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 390 | static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 391 | jlong transactionObj, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 392 | jobject tokenObj, jlong nativeSurfaceObject) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 393 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 394 | if (token == NULL) return; |
Mathias Agopian | ffddc9b | 2013-02-25 15:56:31 -0800 | [diff] [blame] | 395 | sp<IGraphicBufferProducer> bufferProducer; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 396 | sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject)); |
Mathias Agopian | ffddc9b | 2013-02-25 15:56:31 -0800 | [diff] [blame] | 397 | if (sur != NULL) { |
| 398 | bufferProducer = sur->getIGraphicBufferProducer(); |
| 399 | } |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 400 | |
| 401 | |
| 402 | status_t err = NO_ERROR; |
| 403 | { |
| 404 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 405 | err = transaction->setDisplaySurface(token, |
| 406 | bufferProducer); |
| 407 | } |
Pablo Ceballos | aff2f94 | 2016-07-29 14:49:55 -0700 | [diff] [blame] | 408 | if (err != NO_ERROR) { |
| 409 | doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this" |
| 410 | " Surface created with singleBufferMode?"); |
| 411 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 415 | jlong transactionObj, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 416 | jobject tokenObj, jint layerStack) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 417 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 418 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 419 | if (token == NULL) return; |
| 420 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 421 | { |
| 422 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 423 | transaction->setDisplayLayerStack(token, layerStack); |
| 424 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 428 | jlong transactionObj, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 429 | jobject tokenObj, jint orientation, |
| 430 | jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom, |
| 431 | jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) { |
| 432 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 433 | if (token == NULL) return; |
| 434 | Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom); |
| 435 | Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 436 | |
| 437 | { |
| 438 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 439 | transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect); |
| 440 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 441 | } |
| 442 | |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 443 | static void nativeSetDisplaySize(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 444 | jlong transactionObj, |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 445 | jobject tokenObj, jint width, jint height) { |
| 446 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 447 | if (token == NULL) return; |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 448 | |
| 449 | { |
| 450 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 451 | transaction->setDisplaySize(token, width, height); |
| 452 | } |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 455 | static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz, |
| 456 | jobject tokenObj) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 457 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 458 | if (token == NULL) return NULL; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 459 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 460 | Vector<DisplayInfo> configs; |
| 461 | if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR || |
| 462 | configs.size() == 0) { |
| 463 | return NULL; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 464 | } |
| 465 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 466 | jobjectArray configArray = env->NewObjectArray(configs.size(), |
| 467 | gPhysicalDisplayInfoClassInfo.clazz, NULL); |
| 468 | |
| 469 | for (size_t c = 0; c < configs.size(); ++c) { |
| 470 | const DisplayInfo& info = configs[c]; |
| 471 | jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz, |
| 472 | gPhysicalDisplayInfoClassInfo.ctor); |
| 473 | env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w); |
| 474 | env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h); |
| 475 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps); |
| 476 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density); |
| 477 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi); |
| 478 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi); |
| 479 | env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure); |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 480 | env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos, |
| 481 | info.appVsyncOffset); |
| 482 | env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos, |
| 483 | info.presentationDeadline); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 484 | env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj); |
| 485 | env->DeleteLocalRef(infoObj); |
| 486 | } |
| 487 | |
| 488 | return configArray; |
| 489 | } |
| 490 | |
| 491 | static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) { |
| 492 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 493 | if (token == NULL) return -1; |
| 494 | return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token)); |
| 495 | } |
| 496 | |
| 497 | static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) { |
| 498 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 499 | if (token == NULL) return JNI_FALSE; |
| 500 | status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id)); |
| 501 | return err == NO_ERROR ? JNI_TRUE : JNI_FALSE; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 502 | } |
| 503 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 504 | static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) { |
| 505 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 506 | if (token == NULL) return NULL; |
Peiyong Lin | b88549e | 2018-03-28 12:03:45 -0700 | [diff] [blame] | 507 | Vector<ui::ColorMode> colorModes; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 508 | if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR || |
| 509 | colorModes.isEmpty()) { |
| 510 | return NULL; |
| 511 | } |
| 512 | |
| 513 | jintArray colorModesArray = env->NewIntArray(colorModes.size()); |
| 514 | if (colorModesArray == NULL) { |
| 515 | jniThrowException(env, "java/lang/OutOfMemoryError", NULL); |
| 516 | return NULL; |
| 517 | } |
| 518 | jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0); |
| 519 | for (size_t i = 0; i < colorModes.size(); i++) { |
| 520 | colorModesArrayValues[i] = static_cast<jint>(colorModes[i]); |
| 521 | } |
| 522 | env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0); |
| 523 | return colorModesArray; |
| 524 | } |
| 525 | |
| 526 | static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) { |
| 527 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 528 | if (token == NULL) return -1; |
| 529 | return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token)); |
| 530 | } |
| 531 | |
| 532 | static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass, |
| 533 | jobject tokenObj, jint colorMode) { |
| 534 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 535 | if (token == NULL) return JNI_FALSE; |
| 536 | status_t err = SurfaceComposerClient::setActiveColorMode(token, |
Peiyong Lin | b88549e | 2018-03-28 12:03:45 -0700 | [diff] [blame] | 537 | static_cast<ui::ColorMode>(colorMode)); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 538 | return err == NO_ERROR ? JNI_TRUE : JNI_FALSE; |
| 539 | } |
| 540 | |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 541 | static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 542 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 543 | if (token == NULL) return; |
| 544 | |
Tom Cherry | 8ed74bb | 2017-07-10 14:31:18 -0700 | [diff] [blame] | 545 | android::base::Timer t; |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 546 | SurfaceComposerClient::setDisplayPowerMode(token, mode); |
Tom Cherry | 8ed74bb | 2017-07-10 14:31:18 -0700 | [diff] [blame] | 547 | if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()"); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 548 | } |
| 549 | |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 550 | static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 551 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 552 | status_t err = ctrl->clearLayerFrameStats(); |
| 553 | |
| 554 | if (err < 0 && err != NO_INIT) { |
| 555 | doThrowIAE(env); |
| 556 | } |
| 557 | |
| 558 | // The other end is not ready, just report we failed. |
| 559 | if (err == NO_INIT) { |
| 560 | return JNI_FALSE; |
| 561 | } |
| 562 | |
| 563 | return JNI_TRUE; |
| 564 | } |
| 565 | |
| 566 | static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject, |
| 567 | jobject outStats) { |
| 568 | FrameStats stats; |
| 569 | |
| 570 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 571 | status_t err = ctrl->getLayerFrameStats(&stats); |
| 572 | if (err < 0 && err != NO_INIT) { |
| 573 | doThrowIAE(env); |
| 574 | } |
| 575 | |
| 576 | // The other end is not ready, fine just return empty stats. |
| 577 | if (err == NO_INIT) { |
| 578 | return JNI_FALSE; |
| 579 | } |
| 580 | |
| 581 | jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano); |
| 582 | size_t frameCount = stats.desiredPresentTimesNano.size(); |
| 583 | |
| 584 | jlongArray postedTimesNanoDst = env->NewLongArray(frameCount); |
| 585 | if (postedTimesNanoDst == NULL) { |
| 586 | return JNI_FALSE; |
| 587 | } |
| 588 | |
| 589 | jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount); |
| 590 | if (presentedTimesNanoDst == NULL) { |
| 591 | return JNI_FALSE; |
| 592 | } |
| 593 | |
| 594 | jlongArray readyTimesNanoDst = env->NewLongArray(frameCount); |
| 595 | if (readyTimesNanoDst == NULL) { |
| 596 | return JNI_FALSE; |
| 597 | } |
| 598 | |
| 599 | nsecs_t postedTimesNanoSrc[frameCount]; |
| 600 | nsecs_t presentedTimesNanoSrc[frameCount]; |
| 601 | nsecs_t readyTimesNanoSrc[frameCount]; |
| 602 | |
| 603 | for (size_t i = 0; i < frameCount; i++) { |
| 604 | nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i]; |
| 605 | if (postedTimeNano == INT64_MAX) { |
| 606 | postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 607 | } |
| 608 | postedTimesNanoSrc[i] = postedTimeNano; |
| 609 | |
| 610 | nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i]; |
| 611 | if (presentedTimeNano == INT64_MAX) { |
| 612 | presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 613 | } |
| 614 | presentedTimesNanoSrc[i] = presentedTimeNano; |
| 615 | |
| 616 | nsecs_t readyTimeNano = stats.frameReadyTimesNano[i]; |
| 617 | if (readyTimeNano == INT64_MAX) { |
| 618 | readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 619 | } |
| 620 | readyTimesNanoSrc[i] = readyTimeNano; |
| 621 | } |
| 622 | |
| 623 | env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc); |
| 624 | env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc); |
| 625 | env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc); |
| 626 | |
| 627 | env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano, |
| 628 | postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst); |
| 629 | |
| 630 | if (env->ExceptionCheck()) { |
| 631 | return JNI_FALSE; |
| 632 | } |
| 633 | |
| 634 | return JNI_TRUE; |
| 635 | } |
| 636 | |
| 637 | static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) { |
| 638 | status_t err = SurfaceComposerClient::clearAnimationFrameStats(); |
| 639 | |
| 640 | if (err < 0 && err != NO_INIT) { |
| 641 | doThrowIAE(env); |
| 642 | } |
| 643 | |
| 644 | // The other end is not ready, just report we failed. |
| 645 | if (err == NO_INIT) { |
| 646 | return JNI_FALSE; |
| 647 | } |
| 648 | |
| 649 | return JNI_TRUE; |
| 650 | } |
| 651 | |
| 652 | static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) { |
| 653 | FrameStats stats; |
| 654 | |
| 655 | status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats); |
| 656 | if (err < 0 && err != NO_INIT) { |
| 657 | doThrowIAE(env); |
| 658 | } |
| 659 | |
| 660 | // The other end is not ready, fine just return empty stats. |
| 661 | if (err == NO_INIT) { |
| 662 | return JNI_FALSE; |
| 663 | } |
| 664 | |
| 665 | jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano); |
| 666 | size_t frameCount = stats.desiredPresentTimesNano.size(); |
| 667 | |
| 668 | jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount); |
| 669 | if (presentedTimesNanoDst == NULL) { |
| 670 | return JNI_FALSE; |
| 671 | } |
| 672 | |
| 673 | nsecs_t presentedTimesNanoSrc[frameCount]; |
| 674 | |
| 675 | for (size_t i = 0; i < frameCount; i++) { |
Allen Hair | ac5eda3 | 2014-04-24 11:50:37 -0700 | [diff] [blame] | 676 | nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i]; |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 677 | if (presentedTimeNano == INT64_MAX) { |
| 678 | presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 679 | } |
| 680 | presentedTimesNanoSrc[i] = presentedTimeNano; |
| 681 | } |
| 682 | |
| 683 | env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc); |
| 684 | |
| 685 | env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano, |
| 686 | presentedTimesNanoDst); |
| 687 | |
| 688 | if (env->ExceptionCheck()) { |
| 689 | return JNI_FALSE; |
| 690 | } |
| 691 | |
| 692 | return JNI_TRUE; |
| 693 | } |
| 694 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 695 | static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 696 | jlong nativeObject, |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 697 | jobject handleObject, jlong frameNumber) { |
| 698 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 699 | sp<IBinder> handle = ibinderForJavaObject(env, handleObject); |
| 700 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 701 | { |
| 702 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
Marissa Wall | cb32fdd | 2018-07-24 09:53:30 -0700 | [diff] [blame] | 703 | transaction->deferTransactionUntil_legacy(ctrl, handle, frameNumber); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 704 | } |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 705 | } |
| 706 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 707 | static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 708 | jlong nativeObject, |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 709 | jlong surfaceObject, jlong frameNumber) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 710 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 711 | |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 712 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 713 | sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject); |
| 714 | |
Marissa Wall | cb32fdd | 2018-07-24 09:53:30 -0700 | [diff] [blame] | 715 | transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber); |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 716 | } |
| 717 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 718 | static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 719 | jlong nativeObject, |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 720 | jobject newParentObject) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 721 | |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 722 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 723 | sp<IBinder> handle = ibinderForJavaObject(env, newParentObject); |
| 724 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 725 | { |
| 726 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 727 | transaction->reparentChildren(ctrl, handle); |
| 728 | } |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 729 | } |
| 730 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 731 | static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 732 | jlong nativeObject, |
chaviw | 7643140 | 2017-09-18 16:50:05 -0700 | [diff] [blame] | 733 | jobject newParentObject) { |
chaviw | 6354238 | 2017-08-17 17:39:29 -0700 | [diff] [blame] | 734 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 735 | sp<IBinder> parentHandle = ibinderForJavaObject(env, newParentObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 736 | |
| 737 | { |
| 738 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 739 | transaction->reparent(ctrl, parentHandle); |
| 740 | } |
chaviw | 6354238 | 2017-08-17 17:39:29 -0700 | [diff] [blame] | 741 | } |
| 742 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 743 | static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 744 | jlong nativeObject) { |
| 745 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 746 | |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 747 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 748 | transaction->detachChildren(ctrl); |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 749 | } |
| 750 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 751 | static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 752 | jlong nativeObject, |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 753 | jint scalingMode) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 754 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 755 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 756 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 757 | transaction->setOverrideScalingMode(ctrl, scalingMode); |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Chavi Weingarten | b736e32 | 2018-02-23 00:27:54 +0000 | [diff] [blame] | 760 | static void nativeDestroyInTransaction(JNIEnv* env, jclass clazz, |
| 761 | jlong transactionObj, |
| 762 | jlong nativeObject) { |
| 763 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 764 | auto ctrl = reinterpret_cast<SurfaceControl*>(nativeObject); |
| 765 | transaction->destroySurface(ctrl); |
| 766 | } |
| 767 | |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 768 | static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 769 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 770 | return javaObjectForIBinder(env, ctrl->getHandle()); |
| 771 | } |
| 772 | |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 773 | static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) { |
| 774 | sp<IBinder> token(ibinderForJavaObject(env, tokenObject)); |
| 775 | if (token == NULL) return NULL; |
| 776 | |
| 777 | HdrCapabilities capabilities; |
| 778 | SurfaceComposerClient::getHdrCapabilities(token, &capabilities); |
| 779 | |
| 780 | const auto& types = capabilities.getSupportedHdrTypes(); |
Peiyong Lin | 3a0c6e1 | 2018-04-16 11:05:29 -0700 | [diff] [blame] | 781 | std::vector<int32_t> intTypes; |
| 782 | for (auto type : types) { |
| 783 | intTypes.push_back(static_cast<int32_t>(type)); |
| 784 | } |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 785 | auto typesArray = env->NewIntArray(types.size()); |
Peiyong Lin | 3a0c6e1 | 2018-04-16 11:05:29 -0700 | [diff] [blame] | 786 | env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data()); |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 787 | |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 788 | return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor, |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 789 | typesArray, capabilities.getDesiredMaxLuminance(), |
| 790 | capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance()); |
| 791 | } |
| 792 | |
Jorim Jaggi | 06975df | 2017-12-01 14:52:13 +0100 | [diff] [blame] | 793 | static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) { |
| 794 | Parcel* parcel = parcelForJavaObject(env, parcelObj); |
| 795 | if (parcel == NULL) { |
| 796 | doThrowNPE(env); |
| 797 | return 0; |
| 798 | } |
| 799 | sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel); |
| 800 | if (surface == nullptr) { |
| 801 | return 0; |
| 802 | } |
| 803 | surface->incStrong((void *)nativeCreate); |
| 804 | return reinterpret_cast<jlong>(surface.get()); |
| 805 | } |
| 806 | |
| 807 | static void nativeWriteToParcel(JNIEnv* env, jclass clazz, |
| 808 | jlong nativeObject, jobject parcelObj) { |
| 809 | Parcel* parcel = parcelForJavaObject(env, parcelObj); |
| 810 | if (parcel == NULL) { |
| 811 | doThrowNPE(env); |
| 812 | return; |
| 813 | } |
| 814 | SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 815 | self->writeToParcel(parcel); |
| 816 | } |
| 817 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 818 | // ---------------------------------------------------------------------------- |
| 819 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 820 | static const JNINativeMethod sSurfaceControlMethods[] = { |
Albert Chaulk | 3bf2e57 | 2016-11-22 13:59:19 -0500 | [diff] [blame] | 821 | {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJII)J", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 822 | (void*)nativeCreate }, |
Jorim Jaggi | 06975df | 2017-12-01 14:52:13 +0100 | [diff] [blame] | 823 | {"nativeReadFromParcel", "(Landroid/os/Parcel;)J", |
| 824 | (void*)nativeReadFromParcel }, |
| 825 | {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V", |
| 826 | (void*)nativeWriteToParcel }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 827 | {"nativeRelease", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 828 | (void*)nativeRelease }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 829 | {"nativeDestroy", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 830 | (void*)nativeDestroy }, |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 831 | {"nativeDisconnect", "(J)V", |
| 832 | (void*)nativeDisconnect }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 833 | {"nativeCreateTransaction", "()J", |
| 834 | (void*)nativeCreateTransaction }, |
| 835 | {"nativeApplyTransaction", "(JZ)V", |
| 836 | (void*)nativeApplyTransaction }, |
| 837 | {"nativeGetNativeTransactionFinalizer", "()J", |
| 838 | (void*)nativeGetNativeTransactionFinalizer }, |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 839 | {"nativeMergeTransaction", "(JJ)V", |
| 840 | (void*)nativeMergeTransaction }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 841 | {"nativeSetAnimationTransaction", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 842 | (void*)nativeSetAnimationTransaction }, |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 843 | {"nativeSetEarlyWakeup", "(J)V", |
| 844 | (void*)nativeSetEarlyWakeup }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 845 | {"nativeSetLayer", "(JJI)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 846 | (void*)nativeSetLayer }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 847 | {"nativeSetRelativeLayer", "(JJLandroid/os/IBinder;I)V", |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 848 | (void*)nativeSetRelativeLayer }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 849 | {"nativeSetPosition", "(JJFF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 850 | (void*)nativeSetPosition }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 851 | {"nativeSetGeometryAppliesWithResize", "(JJ)V", |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 852 | (void*)nativeSetGeometryAppliesWithResize }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 853 | {"nativeSetSize", "(JJII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 854 | (void*)nativeSetSize }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 855 | {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 856 | (void*)nativeSetTransparentRegionHint }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 857 | {"nativeSetAlpha", "(JJF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 858 | (void*)nativeSetAlpha }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 859 | {"nativeSetColor", "(JJ[F)V", |
chaviw | 0dd03f5 | 2017-08-25 12:15:26 -0700 | [diff] [blame] | 860 | (void*)nativeSetColor }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 861 | {"nativeSetMatrix", "(JJFFFF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 862 | (void*)nativeSetMatrix }, |
Peiyong Lin | 52bb6b4 | 2018-10-01 11:40:50 -0700 | [diff] [blame^] | 863 | {"nativeSetColorTransform", "(JJ[F[F)V", |
| 864 | (void*)nativeSetColorTransform }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 865 | {"nativeSetFlags", "(JJII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 866 | (void*)nativeSetFlags }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 867 | {"nativeSetWindowCrop", "(JJIIII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 868 | (void*)nativeSetWindowCrop }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 869 | {"nativeSetLayerStack", "(JJI)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 870 | (void*)nativeSetLayerStack }, |
| 871 | {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;", |
| 872 | (void*)nativeGetBuiltInDisplay }, |
| 873 | {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;", |
| 874 | (void*)nativeCreateDisplay }, |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 875 | {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V", |
| 876 | (void*)nativeDestroyDisplay }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 877 | {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 878 | (void*)nativeSetDisplaySurface }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 879 | {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 880 | (void*)nativeSetDisplayLayerStack }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 881 | {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 882 | (void*)nativeSetDisplayProjection }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 883 | {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V", |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 884 | (void*)nativeSetDisplaySize }, |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 885 | {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;", |
| 886 | (void*)nativeGetDisplayConfigs }, |
| 887 | {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I", |
| 888 | (void*)nativeGetActiveConfig }, |
| 889 | {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z", |
| 890 | (void*)nativeSetActiveConfig }, |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 891 | {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I", |
| 892 | (void*)nativeGetDisplayColorModes}, |
| 893 | {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I", |
| 894 | (void*)nativeGetActiveColorMode}, |
| 895 | {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z", |
| 896 | (void*)nativeSetActiveColorMode}, |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 897 | {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;", |
| 898 | (void*)nativeGetHdrCapabilities }, |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 899 | {"nativeClearContentFrameStats", "(J)Z", |
| 900 | (void*)nativeClearContentFrameStats }, |
| 901 | {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z", |
| 902 | (void*)nativeGetContentFrameStats }, |
| 903 | {"nativeClearAnimationFrameStats", "()Z", |
| 904 | (void*)nativeClearAnimationFrameStats }, |
| 905 | {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z", |
| 906 | (void*)nativeGetAnimationFrameStats }, |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 907 | {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V", |
| 908 | (void*)nativeSetDisplayPowerMode }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 909 | {"nativeDeferTransactionUntil", "(JJLandroid/os/IBinder;J)V", |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 910 | (void*)nativeDeferTransactionUntil }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 911 | {"nativeDeferTransactionUntilSurface", "(JJJJ)V", |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 912 | (void*)nativeDeferTransactionUntilSurface }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 913 | {"nativeReparentChildren", "(JJLandroid/os/IBinder;)V", |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 914 | (void*)nativeReparentChildren } , |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 915 | {"nativeReparent", "(JJLandroid/os/IBinder;)V", |
chaviw | 7643140 | 2017-09-18 16:50:05 -0700 | [diff] [blame] | 916 | (void*)nativeReparent }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 917 | {"nativeSeverChildren", "(JJ)V", |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 918 | (void*)nativeSeverChildren } , |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 919 | {"nativeSetOverrideScalingMode", "(JJI)V", |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 920 | (void*)nativeSetOverrideScalingMode }, |
Chavi Weingarten | b736e32 | 2018-02-23 00:27:54 +0000 | [diff] [blame] | 921 | {"nativeDestroy", "(JJ)V", |
| 922 | (void*)nativeDestroyInTransaction }, |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 923 | {"nativeGetHandle", "(J)Landroid/os/IBinder;", |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 924 | (void*)nativeGetHandle }, |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 925 | {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZI)Landroid/graphics/GraphicBuffer;", |
| 926 | (void*)nativeScreenshot }, |
Chavi Weingarten | ea2eb5a | 2017-11-29 21:26:24 +0000 | [diff] [blame] | 927 | {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/graphics/Rect;F)Landroid/graphics/GraphicBuffer;", |
Chavi Weingarten | d7ec64c | 2017-11-30 01:52:01 +0000 | [diff] [blame] | 928 | (void*)nativeCaptureLayers }, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 929 | }; |
| 930 | |
| 931 | int register_android_view_SurfaceControl(JNIEnv* env) |
| 932 | { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 933 | int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 934 | sSurfaceControlMethods, NELEM(sSurfaceControlMethods)); |
| 935 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 936 | jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo"); |
| 937 | gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz); |
| 938 | gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env, |
| 939 | gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V"); |
| 940 | gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I"); |
| 941 | gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I"); |
| 942 | gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F"); |
| 943 | gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F"); |
| 944 | gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F"); |
| 945 | gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F"); |
| 946 | gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z"); |
| 947 | gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env, |
| 948 | clazz, "appVsyncOffsetNanos", "J"); |
| 949 | gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env, |
| 950 | clazz, "presentationDeadlineNanos", "J"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 951 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 952 | jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect"); |
| 953 | gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I"); |
| 954 | gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I"); |
| 955 | gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I"); |
| 956 | gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I"); |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 957 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 958 | jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats"); |
| 959 | jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env, |
| 960 | frameStatsClazz, "UNDEFINED_TIME_NANO", "J"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 961 | nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field); |
| 962 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 963 | jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats"); |
| 964 | gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env, |
| 965 | contFrameStatsClazz, "init", "(J[J[J[J)V"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 966 | gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; |
| 967 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 968 | jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats"); |
| 969 | gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env, |
| 970 | animFrameStatsClazz, "init", "(J[J)V"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 971 | gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; |
| 972 | |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 973 | jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities"); |
| 974 | gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz); |
| 975 | gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>", |
| 976 | "([IFFF)V"); |
| 977 | |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 978 | jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer"); |
| 979 | gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz); |
| 980 | gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz, |
| 981 | "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;"); |
| 982 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 983 | return err; |
| 984 | } |
| 985 | |
| 986 | }; |