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