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