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