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