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" |
Robert Carr | 788f574 | 2018-07-30 17:46:45 -0700 | [diff] [blame] | 22 | #include "android_hardware_input_InputWindowHandle.h" |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 23 | #include "android/graphics/Bitmap.h" |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 24 | #include "android/graphics/GraphicsJNI.h" |
| 25 | #include "android/graphics/Region.h" |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 26 | #include "core_jni_helpers.h" |
Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame] | 27 | |
Tom Cherry | 8ed74bb | 2017-07-10 14:31:18 -0700 | [diff] [blame] | 28 | #include <android-base/chrono_utils.h> |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 29 | #include <nativehelper/JNIHelp.h> |
| 30 | #include <nativehelper/ScopedUtfChars.h> |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 31 | #include <android_runtime/android_view_Surface.h> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 32 | #include <android_runtime/android_view_SurfaceSession.h> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 33 | #include <gui/Surface.h> |
| 34 | #include <gui/SurfaceComposerClient.h> |
Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame] | 35 | #include <jni.h> |
| 36 | #include <memory> |
| 37 | #include <stdio.h> |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 38 | #include <system/graphics.h> |
Daniel Solomon | 10e3b33 | 2019-01-20 21:09:11 -0800 | [diff] [blame^] | 39 | #include <ui/ConfigStoreTypes.h> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 40 | #include <ui/DisplayInfo.h> |
Kevin DuBois | bf76b11b | 2018-09-04 09:14:15 -0700 | [diff] [blame] | 41 | #include <ui/DisplayedFrameStats.h> |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 42 | #include <ui/FrameStats.h> |
Peiyong Lin | b88549e | 2018-03-28 12:03:45 -0700 | [diff] [blame] | 43 | #include <ui/GraphicTypes.h> |
Peiyong Lin | 371b98f | 2018-03-14 17:29:10 -0700 | [diff] [blame] | 44 | #include <ui/HdrCapabilities.h> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 45 | #include <ui/Rect.h> |
| 46 | #include <ui/Region.h> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 47 | #include <utils/Log.h> |
| 48 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 49 | // ---------------------------------------------------------------------------- |
| 50 | |
| 51 | namespace android { |
| 52 | |
| 53 | static const char* const OutOfResourcesException = |
| 54 | "android/view/Surface$OutOfResourcesException"; |
| 55 | |
| 56 | static struct { |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 57 | jclass clazz; |
| 58 | jmethodID ctor; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 59 | jfieldID width; |
| 60 | jfieldID height; |
| 61 | jfieldID refreshRate; |
| 62 | jfieldID density; |
| 63 | jfieldID xDpi; |
| 64 | jfieldID yDpi; |
| 65 | jfieldID secure; |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 66 | jfieldID appVsyncOffsetNanos; |
| 67 | jfieldID presentationDeadlineNanos; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 68 | } gPhysicalDisplayInfoClassInfo; |
| 69 | |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 70 | static struct { |
| 71 | jfieldID bottom; |
| 72 | jfieldID left; |
| 73 | jfieldID right; |
| 74 | jfieldID top; |
| 75 | } gRectClassInfo; |
| 76 | |
Leon Scroggins | 46cb9bd | 2014-03-06 15:36:39 -0500 | [diff] [blame] | 77 | // Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref. |
| 78 | void DeleteScreenshot(void* addr, void* context) { |
Leon Scroggins | 46cb9bd | 2014-03-06 15:36:39 -0500 | [diff] [blame] | 79 | delete ((ScreenshotClient*) context); |
| 80 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 81 | |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 82 | static struct { |
| 83 | nsecs_t UNDEFINED_TIME_NANO; |
| 84 | jmethodID init; |
| 85 | } gWindowContentFrameStatsClassInfo; |
| 86 | |
| 87 | static struct { |
| 88 | nsecs_t UNDEFINED_TIME_NANO; |
| 89 | jmethodID init; |
| 90 | } gWindowAnimationFrameStatsClassInfo; |
| 91 | |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 92 | static struct { |
| 93 | jclass clazz; |
| 94 | jmethodID ctor; |
| 95 | } gHdrCapabilitiesClassInfo; |
| 96 | |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 97 | static struct { |
| 98 | jclass clazz; |
| 99 | jmethodID builder; |
| 100 | } gGraphicBufferClassInfo; |
| 101 | |
Kevin DuBois | bf76b11b | 2018-09-04 09:14:15 -0700 | [diff] [blame] | 102 | static struct { |
| 103 | jclass clazz; |
| 104 | jmethodID ctor; |
| 105 | } gDisplayedContentSampleClassInfo; |
| 106 | |
| 107 | static struct { |
| 108 | jclass clazz; |
| 109 | jmethodID ctor; |
| 110 | } gDisplayedContentSamplingAttributesClassInfo; |
| 111 | |
Daniel Solomon | 10e3b33 | 2019-01-20 21:09:11 -0800 | [diff] [blame^] | 112 | static struct { |
| 113 | jclass clazz; |
| 114 | jmethodID ctor; |
| 115 | jfieldID X; |
| 116 | jfieldID Y; |
| 117 | jfieldID Z; |
| 118 | } gCieXyzClassInfo; |
| 119 | |
| 120 | static struct { |
| 121 | jclass clazz; |
| 122 | jmethodID ctor; |
| 123 | jfieldID red; |
| 124 | jfieldID green; |
| 125 | jfieldID blue; |
| 126 | jfieldID white; |
| 127 | } gDisplayPrimariesClassInfo; |
| 128 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 129 | // ---------------------------------------------------------------------------- |
| 130 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 131 | static jlong nativeCreateTransaction(JNIEnv* env, jclass clazz) { |
| 132 | return reinterpret_cast<jlong>(new SurfaceComposerClient::Transaction); |
| 133 | } |
| 134 | |
| 135 | static void releaseTransaction(SurfaceComposerClient::Transaction* t) { |
| 136 | delete t; |
| 137 | } |
| 138 | |
| 139 | static jlong nativeGetNativeTransactionFinalizer(JNIEnv* env, jclass clazz) { |
| 140 | return static_cast<jlong>(reinterpret_cast<uintptr_t>(&releaseTransaction)); |
| 141 | } |
| 142 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 143 | static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj, |
Albert Chaulk | 3bf2e57 | 2016-11-22 13:59:19 -0500 | [diff] [blame] | 144 | jstring nameStr, jint w, jint h, jint format, jint flags, jlong parentObject, |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 145 | jobject metadataParcel) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 146 | ScopedUtfChars name(env, nameStr); |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 147 | sp<SurfaceComposerClient> client; |
| 148 | if (sessionObj != NULL) { |
| 149 | client = android_view_SurfaceSession_getClient(env, sessionObj); |
| 150 | } else { |
| 151 | client = SurfaceComposerClient::getDefault(); |
| 152 | } |
Robert Carr | 838120c | 2016-11-01 18:31:12 -0700 | [diff] [blame] | 153 | SurfaceControl *parent = reinterpret_cast<SurfaceControl*>(parentObject); |
Robert Carr | b0f3936 | 2018-03-14 13:52:25 -0700 | [diff] [blame] | 154 | sp<SurfaceControl> surface; |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 155 | LayerMetadata metadata; |
| 156 | Parcel* parcel = parcelForJavaObject(env, metadataParcel); |
| 157 | if (parcel && !parcel->objectsCount()) { |
| 158 | status_t err = metadata.readFromParcel(parcel); |
| 159 | if (err != NO_ERROR) { |
| 160 | jniThrowException(env, "java/lang/IllegalArgumentException", |
| 161 | "Metadata parcel has wrong format"); |
| 162 | } |
| 163 | } |
| 164 | |
Robert Carr | b0f3936 | 2018-03-14 13:52:25 -0700 | [diff] [blame] | 165 | status_t err = client->createSurfaceChecked( |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 166 | String8(name.c_str()), w, h, format, &surface, flags, parent, std::move(metadata)); |
Robert Carr | b0f3936 | 2018-03-14 13:52:25 -0700 | [diff] [blame] | 167 | if (err == NAME_NOT_FOUND) { |
| 168 | jniThrowException(env, "java/lang/IllegalArgumentException", NULL); |
| 169 | return 0; |
| 170 | } else if (err != NO_ERROR) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 171 | jniThrowException(env, OutOfResourcesException, NULL); |
| 172 | return 0; |
| 173 | } |
Albert Chaulk | 3bf2e57 | 2016-11-22 13:59:19 -0500 | [diff] [blame] | 174 | |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 175 | surface->incStrong((void *)nativeCreate); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 176 | return reinterpret_cast<jlong>(surface.get()); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 179 | static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 180 | sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject)); |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 181 | ctrl->decStrong((void *)nativeCreate); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 184 | static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 185 | sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject)); |
| 186 | ctrl->clear(); |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 187 | ctrl->decStrong((void *)nativeCreate); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 188 | } |
| 189 | |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 190 | static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 191 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 192 | if (ctrl != NULL) { |
| 193 | ctrl->disconnect(); |
| 194 | } |
| 195 | } |
| 196 | |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 197 | static Rect rectFromObj(JNIEnv* env, jobject rectObj) { |
| 198 | int left = env->GetIntField(rectObj, gRectClassInfo.left); |
| 199 | int top = env->GetIntField(rectObj, gRectClassInfo.top); |
| 200 | int right = env->GetIntField(rectObj, gRectClassInfo.right); |
| 201 | int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom); |
| 202 | return Rect(left, top, right, bottom); |
| 203 | } |
| 204 | |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 205 | static jobject nativeScreenshot(JNIEnv* env, jclass clazz, |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 206 | jobject displayTokenObj, jobject sourceCropObj, jint width, jint height, |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 207 | bool useIdentityTransform, int rotation) { |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 208 | sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj); |
| 209 | if (displayToken == NULL) { |
| 210 | return NULL; |
| 211 | } |
| 212 | Rect sourceCrop = rectFromObj(env, sourceCropObj); |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 213 | sp<GraphicBuffer> buffer; |
Peiyong Lin | 10a34d1 | 2018-09-19 13:56:12 -0700 | [diff] [blame] | 214 | status_t res = ScreenshotClient::capture(displayToken, ui::Dataspace::V0_SRGB, |
| 215 | ui::PixelFormat::RGBA_8888, |
| 216 | sourceCrop, width, height, |
| 217 | useIdentityTransform, rotation, &buffer); |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 218 | if (res != NO_ERROR) { |
| 219 | return NULL; |
| 220 | } |
| 221 | |
| 222 | return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz, |
| 223 | gGraphicBufferClassInfo.builder, |
| 224 | buffer->getWidth(), |
| 225 | buffer->getHeight(), |
| 226 | buffer->getPixelFormat(), |
Mathias Agopian | 113fd30 | 2017-05-25 18:31:04 -0700 | [diff] [blame] | 227 | (jint)buffer->getUsage(), |
Patrik Torstensson | 511a808 | 2017-03-27 15:04:11 +0100 | [diff] [blame] | 228 | (jlong)buffer.get()); |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 229 | } |
| 230 | |
Chavi Weingarten | d7ec64c | 2017-11-30 01:52:01 +0000 | [diff] [blame] | 231 | static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject layerHandleToken, |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 232 | jobject sourceCropObj, jfloat frameScale) { |
| 233 | |
| 234 | sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken); |
| 235 | if (layerHandle == NULL) { |
| 236 | return NULL; |
| 237 | } |
| 238 | |
| 239 | Rect sourceCrop; |
| 240 | if (sourceCropObj != NULL) { |
| 241 | sourceCrop = rectFromObj(env, sourceCropObj); |
| 242 | } |
| 243 | |
| 244 | sp<GraphicBuffer> buffer; |
Peiyong Lin | 10a34d1 | 2018-09-19 13:56:12 -0700 | [diff] [blame] | 245 | status_t res = ScreenshotClient::captureChildLayers(layerHandle, ui::Dataspace::V0_SRGB, |
| 246 | ui::PixelFormat::RGBA_8888, sourceCrop, |
| 247 | frameScale, &buffer); |
chaviw | fbe47df | 2017-11-10 16:14:49 -0800 | [diff] [blame] | 248 | if (res != NO_ERROR) { |
| 249 | return NULL; |
| 250 | } |
| 251 | |
| 252 | return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz, |
| 253 | gGraphicBufferClassInfo.builder, |
| 254 | buffer->getWidth(), |
| 255 | buffer->getHeight(), |
| 256 | buffer->getPixelFormat(), |
| 257 | (jint)buffer->getUsage(), |
| 258 | (jlong)buffer.get()); |
chaviw | 1cda84c | 2017-10-23 16:47:10 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 261 | static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) { |
| 262 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 263 | transaction->apply(sync); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 264 | } |
| 265 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 266 | static void nativeMergeTransaction(JNIEnv* env, jclass clazz, |
| 267 | jlong transactionObj, jlong otherTransactionObj) { |
| 268 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 269 | auto otherTransaction = reinterpret_cast<SurfaceComposerClient::Transaction*>( |
| 270 | otherTransactionObj); |
| 271 | transaction->merge(std::move(*otherTransaction)); |
| 272 | } |
| 273 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 274 | static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) { |
| 275 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 276 | transaction->setAnimationTransaction(); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 279 | static void nativeSetEarlyWakeup(JNIEnv* env, jclass clazz, jlong transactionObj) { |
| 280 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 281 | transaction->setEarlyWakeup(); |
| 282 | } |
| 283 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 284 | static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 285 | jlong nativeObject, jint zorder) { |
| 286 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 287 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 288 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 289 | transaction->setLayer(ctrl, zorder); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 290 | } |
| 291 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 292 | static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 293 | jlong nativeObject, |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 294 | jobject relativeTo, jint zorder) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 295 | |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 296 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 297 | sp<IBinder> handle = ibinderForJavaObject(env, relativeTo); |
| 298 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 299 | { |
| 300 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 301 | transaction->setRelativeLayer(ctrl, handle, zorder); |
| 302 | } |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 305 | static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 306 | jlong nativeObject, jfloat x, jfloat y) { |
| 307 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 308 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 309 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 310 | transaction->setPosition(ctrl, x, y); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 313 | static void nativeSetGeometry(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject, |
| 314 | jobject sourceObj, jobject dstObj, jlong orientation) { |
| 315 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 316 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 317 | |
| 318 | Rect source, dst; |
| 319 | if (sourceObj != NULL) { |
| 320 | source = rectFromObj(env, sourceObj); |
| 321 | } |
| 322 | if (dstObj != NULL) { |
| 323 | dst = rectFromObj(env, dstObj); |
| 324 | } |
| 325 | transaction->setGeometry(ctrl, source, dst, orientation); |
| 326 | } |
| 327 | |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 328 | static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 329 | jlong transactionObj, |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 330 | jlong nativeObject) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 331 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 332 | |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 333 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 334 | transaction->setGeometryAppliesWithResize(ctrl); |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 337 | static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 338 | jlong nativeObject, jint w, jint h) { |
| 339 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 340 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 341 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 342 | transaction->setSize(ctrl, w, h); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 343 | } |
| 344 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 345 | static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 346 | jlong nativeObject, jint flags, jint mask) { |
| 347 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 348 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 349 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 350 | transaction->setFlags(ctrl, flags, mask); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 351 | } |
| 352 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 353 | static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 354 | jlong nativeObject, jobject regionObj) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 355 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 356 | SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj); |
| 357 | if (!region) { |
| 358 | doThrowIAE(env); |
| 359 | return; |
| 360 | } |
| 361 | |
| 362 | const SkIRect& b(region->getBounds()); |
| 363 | Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom)); |
| 364 | if (region->isComplex()) { |
| 365 | SkRegion::Iterator it(*region); |
| 366 | while (!it.done()) { |
| 367 | const SkIRect& r(it.rect()); |
| 368 | reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom); |
| 369 | it.next(); |
| 370 | } |
| 371 | } |
| 372 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 373 | { |
| 374 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 375 | transaction->setTransparentRegionHint(ctrl, reg); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 379 | static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 380 | jlong nativeObject, jfloat alpha) { |
| 381 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 382 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 383 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 384 | transaction->setAlpha(ctrl, alpha); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 385 | } |
| 386 | |
Robert Carr | 788f574 | 2018-07-30 17:46:45 -0700 | [diff] [blame] | 387 | static void nativeSetInputWindowInfo(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 388 | jlong nativeObject, jobject inputWindow) { |
| 389 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 390 | |
Riddle Hsu | cd958bc | 2019-01-23 15:40:26 +0800 | [diff] [blame] | 391 | sp<NativeInputWindowHandle> handle = android_view_InputWindowHandle_getHandle( |
Robert Carr | 788f574 | 2018-07-30 17:46:45 -0700 | [diff] [blame] | 392 | env, inputWindow); |
| 393 | handle->updateInfo(); |
| 394 | |
| 395 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 396 | transaction->setInputWindowInfo(ctrl, *handle->getInfo()); |
| 397 | } |
| 398 | |
chaviw | 59f532e | 2018-12-26 15:34:59 -0800 | [diff] [blame] | 399 | static void nativeTransferTouchFocus(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 400 | jobject fromTokenObj, jobject toTokenObj) { |
| 401 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 402 | |
| 403 | sp<IBinder> fromToken(ibinderForJavaObject(env, fromTokenObj)); |
| 404 | sp<IBinder> toToken(ibinderForJavaObject(env, toTokenObj)); |
| 405 | transaction->transferTouchFocus(fromToken, toToken); |
| 406 | } |
| 407 | |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 408 | static void nativeSetMetadata(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 409 | jlong nativeObject, jint id, jobject parcelObj) { |
| 410 | Parcel* parcel = parcelForJavaObject(env, parcelObj); |
| 411 | if (!parcel) { |
| 412 | jniThrowNullPointerException(env, "attribute data"); |
| 413 | return; |
| 414 | } |
| 415 | if (parcel->objectsCount()) { |
| 416 | jniThrowException(env, "java/lang/RuntimeException", |
| 417 | "Tried to marshall a Parcel that contained Binder objects."); |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 422 | |
| 423 | std::vector<uint8_t> byteData(parcel->dataSize()); |
| 424 | memcpy(byteData.data(), parcel->data(), parcel->dataSize()); |
| 425 | |
| 426 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl*>(nativeObject); |
| 427 | transaction->setMetadata(ctrl, id, std::move(byteData)); |
| 428 | } |
| 429 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 430 | static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 431 | jlong nativeObject, jfloatArray fColor) { |
| 432 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
chaviw | 0dd03f5 | 2017-08-25 12:15:26 -0700 | [diff] [blame] | 433 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 434 | |
chaviw | 0dd03f5 | 2017-08-25 12:15:26 -0700 | [diff] [blame] | 435 | float* floatColors = env->GetFloatArrayElements(fColor, 0); |
| 436 | half3 color(floatColors[0], floatColors[1], floatColors[2]); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 437 | transaction->setColor(ctrl, color); |
chaviw | 0dd03f5 | 2017-08-25 12:15:26 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 440 | static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 441 | jlong nativeObject, |
Robert Carr | 0edf18f | 2017-02-21 20:01:47 -0800 | [diff] [blame] | 442 | jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 443 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 444 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 445 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 446 | transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 447 | } |
| 448 | |
Peiyong Lin | 52bb6b4 | 2018-10-01 11:40:50 -0700 | [diff] [blame] | 449 | static void nativeSetColorTransform(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 450 | jlong nativeObject, jfloatArray fMatrix, jfloatArray fTranslation) { |
| 451 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 452 | SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject); |
| 453 | float* floatMatrix = env->GetFloatArrayElements(fMatrix, 0); |
| 454 | mat3 matrix(static_cast<float const*>(floatMatrix)); |
| 455 | float* floatTranslation = env->GetFloatArrayElements(fTranslation, 0); |
| 456 | vec3 translation(floatTranslation[0], floatTranslation[1], floatTranslation[2]); |
| 457 | transaction->setColorTransform(surfaceControl, matrix, translation); |
| 458 | } |
| 459 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 460 | static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 461 | jlong nativeObject, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 462 | jint l, jint t, jint r, jint b) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 463 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 464 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 465 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 466 | Rect crop(l, t, r, b); |
Marissa Wall | cb32fdd | 2018-07-24 09:53:30 -0700 | [diff] [blame] | 467 | transaction->setCrop_legacy(ctrl, crop); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 468 | } |
| 469 | |
Lucas Dupin | ff9d6ab | 2018-10-16 18:05:50 -0700 | [diff] [blame] | 470 | static void nativeSetCornerRadius(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 471 | jlong nativeObject, jfloat cornerRadius) { |
| 472 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 473 | |
| 474 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 475 | transaction->setCornerRadius(ctrl, cornerRadius); |
| 476 | } |
| 477 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 478 | static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 479 | jlong nativeObject, jint layerStack) { |
| 480 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 481 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 482 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 483 | transaction->setLayerStack(ctrl, layerStack); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) { |
| 487 | sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id)); |
| 488 | return javaObjectForIBinder(env, token); |
| 489 | } |
| 490 | |
Kevin DuBois | bf76b11b | 2018-09-04 09:14:15 -0700 | [diff] [blame] | 491 | static jobject nativeGetDisplayedContentSamplingAttributes(JNIEnv* env, jclass clazz, |
| 492 | jobject tokenObj) { |
| 493 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 494 | |
| 495 | ui::PixelFormat format; |
| 496 | ui::Dataspace dataspace; |
| 497 | uint8_t componentMask; |
| 498 | status_t err = SurfaceComposerClient::getDisplayedContentSamplingAttributes( |
| 499 | token, &format, &dataspace, &componentMask); |
| 500 | if (err != OK) { |
| 501 | return nullptr; |
| 502 | } |
| 503 | return env->NewObject(gDisplayedContentSamplingAttributesClassInfo.clazz, |
| 504 | gDisplayedContentSamplingAttributesClassInfo.ctor, |
| 505 | format, dataspace, componentMask); |
| 506 | } |
| 507 | |
| 508 | static jboolean nativeSetDisplayedContentSamplingEnabled(JNIEnv* env, jclass clazz, |
| 509 | jobject tokenObj, jboolean enable, jint componentMask, jint maxFrames) { |
| 510 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
Kevin DuBois | 205a680 | 2019-01-07 17:04:46 -0800 | [diff] [blame] | 511 | status_t rc = SurfaceComposerClient::setDisplayContentSamplingEnabled( |
Kevin DuBois | bf76b11b | 2018-09-04 09:14:15 -0700 | [diff] [blame] | 512 | token, enable, componentMask, maxFrames); |
Kevin DuBois | 205a680 | 2019-01-07 17:04:46 -0800 | [diff] [blame] | 513 | return rc == OK; |
Kevin DuBois | bf76b11b | 2018-09-04 09:14:15 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | static jobject nativeGetDisplayedContentSample(JNIEnv* env, jclass clazz, jobject tokenObj, |
| 517 | jlong maxFrames, jlong timestamp) { |
| 518 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 519 | |
| 520 | DisplayedFrameStats stats; |
| 521 | status_t err = SurfaceComposerClient::getDisplayedContentSample( |
| 522 | token, maxFrames, timestamp, &stats); |
| 523 | if (err != OK) { |
| 524 | return nullptr; |
| 525 | } |
| 526 | |
| 527 | jlongArray histogramComponent0 = env->NewLongArray(stats.component_0_sample.size()); |
| 528 | jlongArray histogramComponent1 = env->NewLongArray(stats.component_1_sample.size()); |
| 529 | jlongArray histogramComponent2 = env->NewLongArray(stats.component_2_sample.size()); |
| 530 | jlongArray histogramComponent3 = env->NewLongArray(stats.component_3_sample.size()); |
| 531 | if ((histogramComponent0 == nullptr) || |
| 532 | (histogramComponent1 == nullptr) || |
| 533 | (histogramComponent2 == nullptr) || |
| 534 | (histogramComponent3 == nullptr)) { |
| 535 | return JNI_FALSE; |
| 536 | } |
| 537 | |
| 538 | env->SetLongArrayRegion(histogramComponent0, 0, |
| 539 | stats.component_0_sample.size(), |
| 540 | reinterpret_cast<jlong*>(stats.component_0_sample.data())); |
| 541 | env->SetLongArrayRegion(histogramComponent1, 0, |
| 542 | stats.component_1_sample.size(), |
| 543 | reinterpret_cast<jlong*>(stats.component_1_sample.data())); |
| 544 | env->SetLongArrayRegion(histogramComponent2, 0, |
| 545 | stats.component_2_sample.size(), |
| 546 | reinterpret_cast<jlong*>(stats.component_2_sample.data())); |
| 547 | env->SetLongArrayRegion(histogramComponent3, 0, |
| 548 | stats.component_3_sample.size(), |
| 549 | reinterpret_cast<jlong*>(stats.component_3_sample.data())); |
| 550 | return env->NewObject(gDisplayedContentSampleClassInfo.clazz, |
| 551 | gDisplayedContentSampleClassInfo.ctor, |
| 552 | stats.numFrames, |
| 553 | histogramComponent0, |
| 554 | histogramComponent1, |
| 555 | histogramComponent2, |
| 556 | histogramComponent3); |
| 557 | } |
| 558 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 559 | static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj, |
| 560 | jboolean secure) { |
| 561 | ScopedUtfChars name(env, nameObj); |
| 562 | sp<IBinder> token(SurfaceComposerClient::createDisplay( |
| 563 | String8(name.c_str()), bool(secure))); |
| 564 | return javaObjectForIBinder(env, token); |
| 565 | } |
| 566 | |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 567 | static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) { |
| 568 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 569 | if (token == NULL) return; |
| 570 | SurfaceComposerClient::destroyDisplay(token); |
| 571 | } |
| 572 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 573 | static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 574 | jlong transactionObj, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 575 | jobject tokenObj, jlong nativeSurfaceObject) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 576 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 577 | if (token == NULL) return; |
Mathias Agopian | ffddc9b | 2013-02-25 15:56:31 -0800 | [diff] [blame] | 578 | sp<IGraphicBufferProducer> bufferProducer; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 579 | sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject)); |
Mathias Agopian | ffddc9b | 2013-02-25 15:56:31 -0800 | [diff] [blame] | 580 | if (sur != NULL) { |
| 581 | bufferProducer = sur->getIGraphicBufferProducer(); |
| 582 | } |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 583 | |
| 584 | |
| 585 | status_t err = NO_ERROR; |
| 586 | { |
| 587 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 588 | err = transaction->setDisplaySurface(token, |
| 589 | bufferProducer); |
| 590 | } |
Pablo Ceballos | aff2f94 | 2016-07-29 14:49:55 -0700 | [diff] [blame] | 591 | if (err != NO_ERROR) { |
| 592 | doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this" |
| 593 | " Surface created with singleBufferMode?"); |
| 594 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 598 | jlong transactionObj, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 599 | jobject tokenObj, jint layerStack) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 600 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 601 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 602 | if (token == NULL) return; |
| 603 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 604 | { |
| 605 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 606 | transaction->setDisplayLayerStack(token, layerStack); |
| 607 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 611 | jlong transactionObj, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 612 | jobject tokenObj, jint orientation, |
| 613 | jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom, |
| 614 | jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) { |
| 615 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 616 | if (token == NULL) return; |
| 617 | Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom); |
| 618 | Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 619 | |
| 620 | { |
| 621 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 622 | transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect); |
| 623 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 624 | } |
| 625 | |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 626 | static void nativeSetDisplaySize(JNIEnv* env, jclass clazz, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 627 | jlong transactionObj, |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 628 | jobject tokenObj, jint width, jint height) { |
| 629 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 630 | if (token == NULL) return; |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 631 | |
| 632 | { |
| 633 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 634 | transaction->setDisplaySize(token, width, height); |
| 635 | } |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 638 | static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz, |
| 639 | jobject tokenObj) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 640 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 641 | if (token == NULL) return NULL; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 642 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 643 | Vector<DisplayInfo> configs; |
| 644 | if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR || |
| 645 | configs.size() == 0) { |
| 646 | return NULL; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 647 | } |
| 648 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 649 | jobjectArray configArray = env->NewObjectArray(configs.size(), |
| 650 | gPhysicalDisplayInfoClassInfo.clazz, NULL); |
| 651 | |
| 652 | for (size_t c = 0; c < configs.size(); ++c) { |
| 653 | const DisplayInfo& info = configs[c]; |
| 654 | jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz, |
| 655 | gPhysicalDisplayInfoClassInfo.ctor); |
| 656 | env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w); |
| 657 | env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h); |
| 658 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps); |
| 659 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density); |
| 660 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi); |
| 661 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi); |
| 662 | env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure); |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 663 | env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos, |
| 664 | info.appVsyncOffset); |
| 665 | env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos, |
| 666 | info.presentationDeadline); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 667 | env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj); |
| 668 | env->DeleteLocalRef(infoObj); |
| 669 | } |
| 670 | |
| 671 | return configArray; |
| 672 | } |
| 673 | |
| 674 | static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) { |
| 675 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 676 | if (token == NULL) return -1; |
| 677 | return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token)); |
| 678 | } |
| 679 | |
| 680 | static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) { |
| 681 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 682 | if (token == NULL) return JNI_FALSE; |
| 683 | status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id)); |
| 684 | return err == NO_ERROR ? JNI_TRUE : JNI_FALSE; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 685 | } |
| 686 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 687 | static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) { |
| 688 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 689 | if (token == NULL) return NULL; |
Peiyong Lin | b88549e | 2018-03-28 12:03:45 -0700 | [diff] [blame] | 690 | Vector<ui::ColorMode> colorModes; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 691 | if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR || |
| 692 | colorModes.isEmpty()) { |
| 693 | return NULL; |
| 694 | } |
| 695 | |
| 696 | jintArray colorModesArray = env->NewIntArray(colorModes.size()); |
| 697 | if (colorModesArray == NULL) { |
| 698 | jniThrowException(env, "java/lang/OutOfMemoryError", NULL); |
| 699 | return NULL; |
| 700 | } |
| 701 | jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0); |
| 702 | for (size_t i = 0; i < colorModes.size(); i++) { |
| 703 | colorModesArrayValues[i] = static_cast<jint>(colorModes[i]); |
| 704 | } |
| 705 | env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0); |
| 706 | return colorModesArray; |
| 707 | } |
| 708 | |
Daniel Solomon | 10e3b33 | 2019-01-20 21:09:11 -0800 | [diff] [blame^] | 709 | static jobject nativeGetDisplayNativePrimaries(JNIEnv* env, jclass, jobject tokenObj) { |
| 710 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 711 | if (token == NULL) return NULL; |
| 712 | |
| 713 | ui::DisplayPrimaries primaries; |
| 714 | if (SurfaceComposerClient::getDisplayNativePrimaries(token, primaries) != NO_ERROR) { |
| 715 | return NULL; |
| 716 | } |
| 717 | |
| 718 | jobject jred = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor); |
| 719 | if (jred == NULL) { |
| 720 | jniThrowException(env, "java/lang/OutOfMemoryError", NULL); |
| 721 | return NULL; |
| 722 | } |
| 723 | |
| 724 | jobject jgreen = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor); |
| 725 | if (jgreen == NULL) { |
| 726 | jniThrowException(env, "java/lang/OutOfMemoryError", NULL); |
| 727 | return NULL; |
| 728 | } |
| 729 | |
| 730 | jobject jblue = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor); |
| 731 | if (jblue == NULL) { |
| 732 | jniThrowException(env, "java/lang/OutOfMemoryError", NULL); |
| 733 | return NULL; |
| 734 | } |
| 735 | |
| 736 | jobject jwhite = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor); |
| 737 | if (jwhite == NULL) { |
| 738 | jniThrowException(env, "java/lang/OutOfMemoryError", NULL); |
| 739 | return NULL; |
| 740 | } |
| 741 | |
| 742 | jobject jprimaries = env->NewObject(gDisplayPrimariesClassInfo.clazz, |
| 743 | gDisplayPrimariesClassInfo.ctor); |
| 744 | if (jprimaries == NULL) { |
| 745 | jniThrowException(env, "java/lang/OutOfMemoryError", NULL); |
| 746 | return NULL; |
| 747 | } |
| 748 | |
| 749 | env->SetFloatField(jred, gCieXyzClassInfo.X, primaries.red.X); |
| 750 | env->SetFloatField(jred, gCieXyzClassInfo.Y, primaries.red.Y); |
| 751 | env->SetFloatField(jred, gCieXyzClassInfo.Z, primaries.red.Z); |
| 752 | env->SetFloatField(jgreen, gCieXyzClassInfo.X, primaries.green.X); |
| 753 | env->SetFloatField(jgreen, gCieXyzClassInfo.Y, primaries.green.Y); |
| 754 | env->SetFloatField(jgreen, gCieXyzClassInfo.Z, primaries.green.Z); |
| 755 | env->SetFloatField(jblue, gCieXyzClassInfo.X, primaries.blue.X); |
| 756 | env->SetFloatField(jblue, gCieXyzClassInfo.Y, primaries.blue.Y); |
| 757 | env->SetFloatField(jblue, gCieXyzClassInfo.Z, primaries.blue.Z); |
| 758 | env->SetFloatField(jwhite, gCieXyzClassInfo.X, primaries.white.X); |
| 759 | env->SetFloatField(jwhite, gCieXyzClassInfo.Y, primaries.white.Y); |
| 760 | env->SetFloatField(jwhite, gCieXyzClassInfo.Z, primaries.white.Z); |
| 761 | env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.red, jred); |
| 762 | env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.green, jgreen); |
| 763 | env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.blue, jblue); |
| 764 | env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.white, jwhite); |
| 765 | |
| 766 | return jprimaries; |
| 767 | } |
| 768 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 769 | static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) { |
| 770 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 771 | if (token == NULL) return -1; |
| 772 | return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token)); |
| 773 | } |
| 774 | |
Peiyong Lin | 5f4a568 | 2019-01-17 11:37:07 -0800 | [diff] [blame] | 775 | static jintArray nativeGetCompositionDataspaces(JNIEnv* env, jclass) { |
| 776 | ui::Dataspace defaultDataspace, wcgDataspace; |
| 777 | ui::PixelFormat defaultPixelFormat, wcgPixelFormat; |
| 778 | if (SurfaceComposerClient::getCompositionPreference(&defaultDataspace, |
| 779 | &defaultPixelFormat, |
| 780 | &wcgDataspace, |
| 781 | &wcgPixelFormat) != NO_ERROR) { |
| 782 | return nullptr; |
| 783 | } |
| 784 | jintArray array = env->NewIntArray(2); |
| 785 | if (array == nullptr) { |
| 786 | jniThrowException(env, "java/lang/OutOfMemoryError", nullptr); |
| 787 | return nullptr; |
| 788 | } |
| 789 | jint* arrayValues = env->GetIntArrayElements(array, 0); |
| 790 | arrayValues[0] = static_cast<jint>(defaultDataspace); |
| 791 | arrayValues[1] = static_cast<jint>(wcgDataspace); |
| 792 | env->ReleaseIntArrayElements(array, arrayValues, 0); |
| 793 | return array; |
| 794 | } |
| 795 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 796 | static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass, |
| 797 | jobject tokenObj, jint colorMode) { |
| 798 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 799 | if (token == NULL) return JNI_FALSE; |
| 800 | status_t err = SurfaceComposerClient::setActiveColorMode(token, |
Peiyong Lin | b88549e | 2018-03-28 12:03:45 -0700 | [diff] [blame] | 801 | static_cast<ui::ColorMode>(colorMode)); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 802 | return err == NO_ERROR ? JNI_TRUE : JNI_FALSE; |
| 803 | } |
| 804 | |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 805 | static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 806 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 807 | if (token == NULL) return; |
| 808 | |
Tom Cherry | 8ed74bb | 2017-07-10 14:31:18 -0700 | [diff] [blame] | 809 | android::base::Timer t; |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 810 | SurfaceComposerClient::setDisplayPowerMode(token, mode); |
Tom Cherry | 8ed74bb | 2017-07-10 14:31:18 -0700 | [diff] [blame] | 811 | if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()"); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 812 | } |
| 813 | |
Peiyong Lin | 0ddb7d4 | 2019-01-16 13:25:09 -0800 | [diff] [blame] | 814 | static jboolean nativeGetProtectedContentSupport(JNIEnv* env, jclass) { |
| 815 | return static_cast<jboolean>(SurfaceComposerClient::getProtectedContentSupport()); |
| 816 | } |
| 817 | |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 818 | static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 819 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 820 | status_t err = ctrl->clearLayerFrameStats(); |
| 821 | |
| 822 | if (err < 0 && err != NO_INIT) { |
| 823 | doThrowIAE(env); |
| 824 | } |
| 825 | |
| 826 | // The other end is not ready, just report we failed. |
| 827 | if (err == NO_INIT) { |
| 828 | return JNI_FALSE; |
| 829 | } |
| 830 | |
| 831 | return JNI_TRUE; |
| 832 | } |
| 833 | |
| 834 | static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject, |
| 835 | jobject outStats) { |
| 836 | FrameStats stats; |
| 837 | |
| 838 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 839 | status_t err = ctrl->getLayerFrameStats(&stats); |
| 840 | if (err < 0 && err != NO_INIT) { |
| 841 | doThrowIAE(env); |
| 842 | } |
| 843 | |
| 844 | // The other end is not ready, fine just return empty stats. |
| 845 | if (err == NO_INIT) { |
| 846 | return JNI_FALSE; |
| 847 | } |
| 848 | |
| 849 | jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano); |
| 850 | size_t frameCount = stats.desiredPresentTimesNano.size(); |
| 851 | |
| 852 | jlongArray postedTimesNanoDst = env->NewLongArray(frameCount); |
| 853 | if (postedTimesNanoDst == NULL) { |
| 854 | return JNI_FALSE; |
| 855 | } |
| 856 | |
| 857 | jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount); |
| 858 | if (presentedTimesNanoDst == NULL) { |
| 859 | return JNI_FALSE; |
| 860 | } |
| 861 | |
| 862 | jlongArray readyTimesNanoDst = env->NewLongArray(frameCount); |
| 863 | if (readyTimesNanoDst == NULL) { |
| 864 | return JNI_FALSE; |
| 865 | } |
| 866 | |
| 867 | nsecs_t postedTimesNanoSrc[frameCount]; |
| 868 | nsecs_t presentedTimesNanoSrc[frameCount]; |
| 869 | nsecs_t readyTimesNanoSrc[frameCount]; |
| 870 | |
| 871 | for (size_t i = 0; i < frameCount; i++) { |
| 872 | nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i]; |
| 873 | if (postedTimeNano == INT64_MAX) { |
| 874 | postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 875 | } |
| 876 | postedTimesNanoSrc[i] = postedTimeNano; |
| 877 | |
| 878 | nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i]; |
| 879 | if (presentedTimeNano == INT64_MAX) { |
| 880 | presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 881 | } |
| 882 | presentedTimesNanoSrc[i] = presentedTimeNano; |
| 883 | |
| 884 | nsecs_t readyTimeNano = stats.frameReadyTimesNano[i]; |
| 885 | if (readyTimeNano == INT64_MAX) { |
| 886 | readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 887 | } |
| 888 | readyTimesNanoSrc[i] = readyTimeNano; |
| 889 | } |
| 890 | |
| 891 | env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc); |
| 892 | env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc); |
| 893 | env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc); |
| 894 | |
| 895 | env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano, |
| 896 | postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst); |
| 897 | |
| 898 | if (env->ExceptionCheck()) { |
| 899 | return JNI_FALSE; |
| 900 | } |
| 901 | |
| 902 | return JNI_TRUE; |
| 903 | } |
| 904 | |
| 905 | static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) { |
| 906 | status_t err = SurfaceComposerClient::clearAnimationFrameStats(); |
| 907 | |
| 908 | if (err < 0 && err != NO_INIT) { |
| 909 | doThrowIAE(env); |
| 910 | } |
| 911 | |
| 912 | // The other end is not ready, just report we failed. |
| 913 | if (err == NO_INIT) { |
| 914 | return JNI_FALSE; |
| 915 | } |
| 916 | |
| 917 | return JNI_TRUE; |
| 918 | } |
| 919 | |
| 920 | static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) { |
| 921 | FrameStats stats; |
| 922 | |
| 923 | status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats); |
| 924 | if (err < 0 && err != NO_INIT) { |
| 925 | doThrowIAE(env); |
| 926 | } |
| 927 | |
| 928 | // The other end is not ready, fine just return empty stats. |
| 929 | if (err == NO_INIT) { |
| 930 | return JNI_FALSE; |
| 931 | } |
| 932 | |
| 933 | jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano); |
| 934 | size_t frameCount = stats.desiredPresentTimesNano.size(); |
| 935 | |
| 936 | jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount); |
| 937 | if (presentedTimesNanoDst == NULL) { |
| 938 | return JNI_FALSE; |
| 939 | } |
| 940 | |
| 941 | nsecs_t presentedTimesNanoSrc[frameCount]; |
| 942 | |
| 943 | for (size_t i = 0; i < frameCount; i++) { |
Allen Hair | ac5eda3 | 2014-04-24 11:50:37 -0700 | [diff] [blame] | 944 | nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i]; |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 945 | if (presentedTimeNano == INT64_MAX) { |
| 946 | presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 947 | } |
| 948 | presentedTimesNanoSrc[i] = presentedTimeNano; |
| 949 | } |
| 950 | |
| 951 | env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc); |
| 952 | |
| 953 | env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano, |
| 954 | presentedTimesNanoDst); |
| 955 | |
| 956 | if (env->ExceptionCheck()) { |
| 957 | return JNI_FALSE; |
| 958 | } |
| 959 | |
| 960 | return JNI_TRUE; |
| 961 | } |
| 962 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 963 | static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 964 | jlong nativeObject, |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 965 | jobject handleObject, jlong frameNumber) { |
| 966 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 967 | sp<IBinder> handle = ibinderForJavaObject(env, handleObject); |
| 968 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 969 | { |
| 970 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
Marissa Wall | cb32fdd | 2018-07-24 09:53:30 -0700 | [diff] [blame] | 971 | transaction->deferTransactionUntil_legacy(ctrl, handle, frameNumber); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 972 | } |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 973 | } |
| 974 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 975 | static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 976 | jlong nativeObject, |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 977 | jlong surfaceObject, jlong frameNumber) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 978 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 979 | |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 980 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 981 | sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject); |
| 982 | |
Marissa Wall | cb32fdd | 2018-07-24 09:53:30 -0700 | [diff] [blame] | 983 | transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber); |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 984 | } |
| 985 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 986 | static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 987 | jlong nativeObject, |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 988 | jobject newParentObject) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 989 | |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 990 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 991 | sp<IBinder> handle = ibinderForJavaObject(env, newParentObject); |
| 992 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 993 | { |
| 994 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 995 | transaction->reparentChildren(ctrl, handle); |
| 996 | } |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 997 | } |
| 998 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 999 | static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 1000 | jlong nativeObject, |
Robert Carr | 10584fa | 2019-01-14 15:55:19 -0800 | [diff] [blame] | 1001 | jlong newParentObject) { |
chaviw | 6354238 | 2017-08-17 17:39:29 -0700 | [diff] [blame] | 1002 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | 10584fa | 2019-01-14 15:55:19 -0800 | [diff] [blame] | 1003 | auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1004 | |
| 1005 | { |
| 1006 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
Robert Carr | 10584fa | 2019-01-14 15:55:19 -0800 | [diff] [blame] | 1007 | transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1008 | } |
chaviw | 6354238 | 2017-08-17 17:39:29 -0700 | [diff] [blame] | 1009 | } |
| 1010 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1011 | static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 1012 | jlong nativeObject) { |
| 1013 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
| 1014 | |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 1015 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1016 | transaction->detachChildren(ctrl); |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 1017 | } |
| 1018 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1019 | static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj, |
| 1020 | jlong nativeObject, |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1021 | jint scalingMode) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1022 | auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1023 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1024 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 1025 | transaction->setOverrideScalingMode(ctrl, scalingMode); |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 1028 | static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 1029 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 1030 | return javaObjectForIBinder(env, ctrl->getHandle()); |
| 1031 | } |
| 1032 | |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 1033 | static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) { |
| 1034 | sp<IBinder> token(ibinderForJavaObject(env, tokenObject)); |
| 1035 | if (token == NULL) return NULL; |
| 1036 | |
| 1037 | HdrCapabilities capabilities; |
| 1038 | SurfaceComposerClient::getHdrCapabilities(token, &capabilities); |
| 1039 | |
| 1040 | const auto& types = capabilities.getSupportedHdrTypes(); |
Peiyong Lin | 3a0c6e1 | 2018-04-16 11:05:29 -0700 | [diff] [blame] | 1041 | std::vector<int32_t> intTypes; |
| 1042 | for (auto type : types) { |
| 1043 | intTypes.push_back(static_cast<int32_t>(type)); |
| 1044 | } |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 1045 | auto typesArray = env->NewIntArray(types.size()); |
Peiyong Lin | 3a0c6e1 | 2018-04-16 11:05:29 -0700 | [diff] [blame] | 1046 | env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data()); |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 1047 | |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 1048 | return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor, |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 1049 | typesArray, capabilities.getDesiredMaxLuminance(), |
| 1050 | capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance()); |
| 1051 | } |
| 1052 | |
Jorim Jaggi | 06975df | 2017-12-01 14:52:13 +0100 | [diff] [blame] | 1053 | static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) { |
| 1054 | Parcel* parcel = parcelForJavaObject(env, parcelObj); |
| 1055 | if (parcel == NULL) { |
| 1056 | doThrowNPE(env); |
| 1057 | return 0; |
| 1058 | } |
| 1059 | sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel); |
| 1060 | if (surface == nullptr) { |
| 1061 | return 0; |
| 1062 | } |
| 1063 | surface->incStrong((void *)nativeCreate); |
| 1064 | return reinterpret_cast<jlong>(surface.get()); |
| 1065 | } |
| 1066 | |
chaviw | beb7a0c | 2018-12-05 13:49:54 -0800 | [diff] [blame] | 1067 | static jlong nativeCopyFromSurfaceControl(JNIEnv* env, jclass clazz, jlong surfaceControlNativeObj) { |
| 1068 | sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj)); |
| 1069 | if (surface == nullptr) { |
| 1070 | return 0; |
| 1071 | } |
Robert Carr | 5fea55b | 2018-12-10 13:05:52 -0800 | [diff] [blame] | 1072 | |
| 1073 | sp<SurfaceControl> newSurface = new SurfaceControl(surface); |
| 1074 | newSurface->incStrong((void *)nativeCreate); |
| 1075 | return reinterpret_cast<jlong>(newSurface.get()); |
chaviw | beb7a0c | 2018-12-05 13:49:54 -0800 | [diff] [blame] | 1076 | } |
| 1077 | |
Jorim Jaggi | 06975df | 2017-12-01 14:52:13 +0100 | [diff] [blame] | 1078 | static void nativeWriteToParcel(JNIEnv* env, jclass clazz, |
| 1079 | jlong nativeObject, jobject parcelObj) { |
| 1080 | Parcel* parcel = parcelForJavaObject(env, parcelObj); |
| 1081 | if (parcel == NULL) { |
| 1082 | doThrowNPE(env); |
| 1083 | return; |
| 1084 | } |
| 1085 | SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject); |
chaviw | beb7a0c | 2018-12-05 13:49:54 -0800 | [diff] [blame] | 1086 | if (self != nullptr) { |
| 1087 | self->writeToParcel(parcel); |
| 1088 | } |
Jorim Jaggi | 06975df | 2017-12-01 14:52:13 +0100 | [diff] [blame] | 1089 | } |
| 1090 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1091 | // ---------------------------------------------------------------------------- |
| 1092 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 1093 | static const JNINativeMethod sSurfaceControlMethods[] = { |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 1094 | {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJLandroid/os/Parcel;)J", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1095 | (void*)nativeCreate }, |
Jorim Jaggi | 06975df | 2017-12-01 14:52:13 +0100 | [diff] [blame] | 1096 | {"nativeReadFromParcel", "(Landroid/os/Parcel;)J", |
| 1097 | (void*)nativeReadFromParcel }, |
chaviw | beb7a0c | 2018-12-05 13:49:54 -0800 | [diff] [blame] | 1098 | {"nativeCopyFromSurfaceControl", "(J)J" , |
| 1099 | (void*)nativeCopyFromSurfaceControl }, |
Jorim Jaggi | 06975df | 2017-12-01 14:52:13 +0100 | [diff] [blame] | 1100 | {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V", |
| 1101 | (void*)nativeWriteToParcel }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1102 | {"nativeRelease", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1103 | (void*)nativeRelease }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1104 | {"nativeDestroy", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1105 | (void*)nativeDestroy }, |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 1106 | {"nativeDisconnect", "(J)V", |
| 1107 | (void*)nativeDisconnect }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1108 | {"nativeCreateTransaction", "()J", |
| 1109 | (void*)nativeCreateTransaction }, |
| 1110 | {"nativeApplyTransaction", "(JZ)V", |
| 1111 | (void*)nativeApplyTransaction }, |
| 1112 | {"nativeGetNativeTransactionFinalizer", "()J", |
| 1113 | (void*)nativeGetNativeTransactionFinalizer }, |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1114 | {"nativeMergeTransaction", "(JJ)V", |
| 1115 | (void*)nativeMergeTransaction }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1116 | {"nativeSetAnimationTransaction", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1117 | (void*)nativeSetAnimationTransaction }, |
Jorim Jaggi | aa763cd | 2018-03-22 23:20:36 +0100 | [diff] [blame] | 1118 | {"nativeSetEarlyWakeup", "(J)V", |
| 1119 | (void*)nativeSetEarlyWakeup }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1120 | {"nativeSetLayer", "(JJI)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1121 | (void*)nativeSetLayer }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1122 | {"nativeSetRelativeLayer", "(JJLandroid/os/IBinder;I)V", |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 1123 | (void*)nativeSetRelativeLayer }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1124 | {"nativeSetPosition", "(JJFF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1125 | (void*)nativeSetPosition }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1126 | {"nativeSetGeometryAppliesWithResize", "(JJ)V", |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1127 | (void*)nativeSetGeometryAppliesWithResize }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1128 | {"nativeSetSize", "(JJII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1129 | (void*)nativeSetSize }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1130 | {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1131 | (void*)nativeSetTransparentRegionHint }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1132 | {"nativeSetAlpha", "(JJF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1133 | (void*)nativeSetAlpha }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1134 | {"nativeSetColor", "(JJ[F)V", |
chaviw | 0dd03f5 | 2017-08-25 12:15:26 -0700 | [diff] [blame] | 1135 | (void*)nativeSetColor }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1136 | {"nativeSetMatrix", "(JJFFFF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1137 | (void*)nativeSetMatrix }, |
Peiyong Lin | 52bb6b4 | 2018-10-01 11:40:50 -0700 | [diff] [blame] | 1138 | {"nativeSetColorTransform", "(JJ[F[F)V", |
| 1139 | (void*)nativeSetColorTransform }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1140 | {"nativeSetFlags", "(JJII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1141 | (void*)nativeSetFlags }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1142 | {"nativeSetWindowCrop", "(JJIIII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1143 | (void*)nativeSetWindowCrop }, |
Lucas Dupin | ff9d6ab | 2018-10-16 18:05:50 -0700 | [diff] [blame] | 1144 | {"nativeSetCornerRadius", "(JJF)V", |
| 1145 | (void*)nativeSetCornerRadius }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1146 | {"nativeSetLayerStack", "(JJI)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1147 | (void*)nativeSetLayerStack }, |
| 1148 | {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;", |
| 1149 | (void*)nativeGetBuiltInDisplay }, |
| 1150 | {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;", |
| 1151 | (void*)nativeCreateDisplay }, |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 1152 | {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V", |
| 1153 | (void*)nativeDestroyDisplay }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1154 | {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1155 | (void*)nativeSetDisplaySurface }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1156 | {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1157 | (void*)nativeSetDisplayLayerStack }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1158 | {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1159 | (void*)nativeSetDisplayProjection }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1160 | {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V", |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 1161 | (void*)nativeSetDisplaySize }, |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 1162 | {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;", |
| 1163 | (void*)nativeGetDisplayConfigs }, |
| 1164 | {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I", |
| 1165 | (void*)nativeGetActiveConfig }, |
| 1166 | {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z", |
| 1167 | (void*)nativeSetActiveConfig }, |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1168 | {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I", |
| 1169 | (void*)nativeGetDisplayColorModes}, |
Daniel Solomon | 10e3b33 | 2019-01-20 21:09:11 -0800 | [diff] [blame^] | 1170 | {"nativeGetDisplayNativePrimaries", "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DisplayPrimaries;", |
| 1171 | (void*)nativeGetDisplayNativePrimaries }, |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 1172 | {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I", |
| 1173 | (void*)nativeGetActiveColorMode}, |
| 1174 | {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z", |
| 1175 | (void*)nativeSetActiveColorMode}, |
Peiyong Lin | 5f4a568 | 2019-01-17 11:37:07 -0800 | [diff] [blame] | 1176 | {"nativeGetCompositionDataspaces", "()[I", |
| 1177 | (void*)nativeGetCompositionDataspaces}, |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 1178 | {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;", |
| 1179 | (void*)nativeGetHdrCapabilities }, |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 1180 | {"nativeClearContentFrameStats", "(J)Z", |
| 1181 | (void*)nativeClearContentFrameStats }, |
| 1182 | {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z", |
| 1183 | (void*)nativeGetContentFrameStats }, |
| 1184 | {"nativeClearAnimationFrameStats", "()Z", |
| 1185 | (void*)nativeClearAnimationFrameStats }, |
| 1186 | {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z", |
| 1187 | (void*)nativeGetAnimationFrameStats }, |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 1188 | {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V", |
| 1189 | (void*)nativeSetDisplayPowerMode }, |
Peiyong Lin | 0ddb7d4 | 2019-01-16 13:25:09 -0800 | [diff] [blame] | 1190 | {"nativeGetProtectedContentSupport", "()Z", |
| 1191 | (void*)nativeGetProtectedContentSupport }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1192 | {"nativeDeferTransactionUntil", "(JJLandroid/os/IBinder;J)V", |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 1193 | (void*)nativeDeferTransactionUntil }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1194 | {"nativeDeferTransactionUntilSurface", "(JJJJ)V", |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 1195 | (void*)nativeDeferTransactionUntilSurface }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1196 | {"nativeReparentChildren", "(JJLandroid/os/IBinder;)V", |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 1197 | (void*)nativeReparentChildren } , |
Robert Carr | 10584fa | 2019-01-14 15:55:19 -0800 | [diff] [blame] | 1198 | {"nativeReparent", "(JJJ)V", |
chaviw | 7643140 | 2017-09-18 16:50:05 -0700 | [diff] [blame] | 1199 | (void*)nativeReparent }, |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1200 | {"nativeSeverChildren", "(JJ)V", |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 1201 | (void*)nativeSeverChildren } , |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1202 | {"nativeSetOverrideScalingMode", "(JJI)V", |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 1203 | (void*)nativeSetOverrideScalingMode }, |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 1204 | {"nativeGetHandle", "(J)Landroid/os/IBinder;", |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1205 | (void*)nativeGetHandle }, |
chaviw | 08520a0 | 2018-09-10 16:44:56 -0700 | [diff] [blame] | 1206 | {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZI)Landroid/graphics/GraphicBuffer;", |
| 1207 | (void*)nativeScreenshot }, |
Chavi Weingarten | ea2eb5a | 2017-11-29 21:26:24 +0000 | [diff] [blame] | 1208 | {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/graphics/Rect;F)Landroid/graphics/GraphicBuffer;", |
Chavi Weingarten | d7ec64c | 2017-11-30 01:52:01 +0000 | [diff] [blame] | 1209 | (void*)nativeCaptureLayers }, |
Robert Carr | 788f574 | 2018-07-30 17:46:45 -0700 | [diff] [blame] | 1210 | {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V", |
chaviw | 59f532e | 2018-12-26 15:34:59 -0800 | [diff] [blame] | 1211 | (void*)nativeSetInputWindowInfo }, |
| 1212 | {"nativeTransferTouchFocus", "(JLandroid/os/IBinder;Landroid/os/IBinder;)V", |
| 1213 | (void*)nativeTransferTouchFocus }, |
Evan Rosky | 485df20 | 2018-12-06 14:11:12 -0800 | [diff] [blame] | 1214 | {"nativeSetMetadata", "(JILandroid/os/Parcel;)V", |
| 1215 | (void*)nativeSetMetadata }, |
Kevin DuBois | bf76b11b | 2018-09-04 09:14:15 -0700 | [diff] [blame] | 1216 | {"nativeGetDisplayedContentSamplingAttributes", |
| 1217 | "(Landroid/os/IBinder;)Landroid/hardware/display/DisplayedContentSamplingAttributes;", |
| 1218 | (void*)nativeGetDisplayedContentSamplingAttributes }, |
| 1219 | {"nativeSetDisplayedContentSamplingEnabled", "(Landroid/os/IBinder;ZII)Z", |
| 1220 | (void*)nativeSetDisplayedContentSamplingEnabled }, |
| 1221 | {"nativeGetDisplayedContentSample", |
| 1222 | "(Landroid/os/IBinder;JJ)Landroid/hardware/display/DisplayedContentSample;", |
| 1223 | (void*)nativeGetDisplayedContentSample }, |
Robert Carr | 76907ee | 2019-01-11 13:38:19 -0800 | [diff] [blame] | 1224 | {"nativeSetGeometry", "(JJLandroid/graphics/Rect;Landroid/graphics/Rect;J)V", |
| 1225 | (void*)nativeSetGeometry } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1226 | }; |
| 1227 | |
| 1228 | int register_android_view_SurfaceControl(JNIEnv* env) |
| 1229 | { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1230 | int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1231 | sSurfaceControlMethods, NELEM(sSurfaceControlMethods)); |
| 1232 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1233 | jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo"); |
| 1234 | gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz); |
| 1235 | gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env, |
| 1236 | gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V"); |
| 1237 | gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I"); |
| 1238 | gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I"); |
| 1239 | gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F"); |
| 1240 | gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F"); |
| 1241 | gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F"); |
| 1242 | gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F"); |
| 1243 | gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z"); |
| 1244 | gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env, |
| 1245 | clazz, "appVsyncOffsetNanos", "J"); |
| 1246 | gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env, |
| 1247 | clazz, "presentationDeadlineNanos", "J"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 1248 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1249 | jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect"); |
| 1250 | gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I"); |
| 1251 | gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I"); |
| 1252 | gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I"); |
| 1253 | gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I"); |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 1254 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1255 | jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats"); |
| 1256 | jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env, |
| 1257 | frameStatsClazz, "UNDEFINED_TIME_NANO", "J"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 1258 | nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field); |
| 1259 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1260 | jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats"); |
| 1261 | gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env, |
| 1262 | contFrameStatsClazz, "init", "(J[J[J[J)V"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 1263 | gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; |
| 1264 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1265 | jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats"); |
| 1266 | gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env, |
| 1267 | animFrameStatsClazz, "init", "(J[J)V"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 1268 | gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; |
| 1269 | |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 1270 | jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities"); |
| 1271 | gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz); |
| 1272 | gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>", |
| 1273 | "([IFFF)V"); |
| 1274 | |
Robert Carr | 6486d31 | 2017-01-09 19:48:29 -0800 | [diff] [blame] | 1275 | jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer"); |
| 1276 | gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz); |
| 1277 | gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz, |
| 1278 | "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;"); |
| 1279 | |
Kevin DuBois | bf76b11b | 2018-09-04 09:14:15 -0700 | [diff] [blame] | 1280 | jclass displayedContentSampleClazz = FindClassOrDie(env, |
| 1281 | "android/hardware/display/DisplayedContentSample"); |
| 1282 | gDisplayedContentSampleClassInfo.clazz = MakeGlobalRefOrDie(env, displayedContentSampleClazz); |
| 1283 | gDisplayedContentSampleClassInfo.ctor = GetMethodIDOrDie(env, |
| 1284 | displayedContentSampleClazz, "<init>", "(J[J[J[J[J)V"); |
| 1285 | |
| 1286 | jclass displayedContentSamplingAttributesClazz = FindClassOrDie(env, |
| 1287 | "android/hardware/display/DisplayedContentSamplingAttributes"); |
| 1288 | gDisplayedContentSamplingAttributesClassInfo.clazz = MakeGlobalRefOrDie(env, |
| 1289 | displayedContentSamplingAttributesClazz); |
| 1290 | gDisplayedContentSamplingAttributesClassInfo.ctor = GetMethodIDOrDie(env, |
| 1291 | displayedContentSamplingAttributesClazz, "<init>", "(III)V"); |
Daniel Solomon | 10e3b33 | 2019-01-20 21:09:11 -0800 | [diff] [blame^] | 1292 | |
| 1293 | jclass cieXyzClazz = FindClassOrDie(env, "android/view/SurfaceControl$CieXyz"); |
| 1294 | gCieXyzClassInfo.clazz = MakeGlobalRefOrDie(env, cieXyzClazz); |
| 1295 | gCieXyzClassInfo.ctor = GetMethodIDOrDie(env, gCieXyzClassInfo.clazz, "<init>", "()V"); |
| 1296 | gCieXyzClassInfo.X = GetFieldIDOrDie(env, cieXyzClazz, "X", "F"); |
| 1297 | gCieXyzClassInfo.Y = GetFieldIDOrDie(env, cieXyzClazz, "Y", "F"); |
| 1298 | gCieXyzClassInfo.Z = GetFieldIDOrDie(env, cieXyzClazz, "Z", "F"); |
| 1299 | |
| 1300 | jclass displayPrimariesClazz = FindClassOrDie(env, |
| 1301 | "android/view/SurfaceControl$DisplayPrimaries"); |
| 1302 | gDisplayPrimariesClassInfo.clazz = MakeGlobalRefOrDie(env, displayPrimariesClazz); |
| 1303 | gDisplayPrimariesClassInfo.ctor = GetMethodIDOrDie(env, gDisplayPrimariesClassInfo.clazz, |
| 1304 | "<init>", "()V"); |
| 1305 | gDisplayPrimariesClassInfo.red = GetFieldIDOrDie(env, displayPrimariesClazz, "red", |
| 1306 | "Landroid/view/SurfaceControl$CieXyz;"); |
| 1307 | gDisplayPrimariesClassInfo.green = GetFieldIDOrDie(env, displayPrimariesClazz, "green", |
| 1308 | "Landroid/view/SurfaceControl$CieXyz;"); |
| 1309 | gDisplayPrimariesClassInfo.blue = GetFieldIDOrDie(env, displayPrimariesClazz, "blue", |
| 1310 | "Landroid/view/SurfaceControl$CieXyz;"); |
| 1311 | gDisplayPrimariesClassInfo.white = GetFieldIDOrDie(env, displayPrimariesClazz, "white", |
| 1312 | "Landroid/view/SurfaceControl$CieXyz;"); |
| 1313 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1314 | return err; |
| 1315 | } |
| 1316 | |
| 1317 | }; |