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