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" |
| 18 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 19 | #include "android_os_Parcel.h" |
| 20 | #include "android_util_Binder.h" |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 21 | #include "android/graphics/Bitmap.h" |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 22 | #include "android/graphics/GraphicsJNI.h" |
| 23 | #include "android/graphics/Region.h" |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 24 | #include "core_jni_helpers.h" |
Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame] | 25 | |
| 26 | #include <JNIHelp.h> |
| 27 | #include <ScopedUtfChars.h> |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 28 | #include <android_runtime/android_view_Surface.h> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 29 | #include <android_runtime/android_view_SurfaceSession.h> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 30 | #include <gui/Surface.h> |
| 31 | #include <gui/SurfaceComposerClient.h> |
Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame] | 32 | #include <jni.h> |
| 33 | #include <memory> |
| 34 | #include <stdio.h> |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 35 | #include <system/graphics.h> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 36 | #include <ui/DisplayInfo.h> |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 37 | #include <ui/HdrCapabilities.h> |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 38 | #include <ui/FrameStats.h> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 39 | #include <ui/Rect.h> |
| 40 | #include <ui/Region.h> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 41 | #include <utils/Log.h> |
| 42 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 43 | // ---------------------------------------------------------------------------- |
| 44 | |
| 45 | namespace android { |
| 46 | |
| 47 | static const char* const OutOfResourcesException = |
| 48 | "android/view/Surface$OutOfResourcesException"; |
| 49 | |
| 50 | static struct { |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 51 | jclass clazz; |
| 52 | jmethodID ctor; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 53 | jfieldID width; |
| 54 | jfieldID height; |
| 55 | jfieldID refreshRate; |
| 56 | jfieldID density; |
| 57 | jfieldID xDpi; |
| 58 | jfieldID yDpi; |
| 59 | jfieldID secure; |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 60 | jfieldID appVsyncOffsetNanos; |
| 61 | jfieldID presentationDeadlineNanos; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 62 | } gPhysicalDisplayInfoClassInfo; |
| 63 | |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 64 | static struct { |
| 65 | jfieldID bottom; |
| 66 | jfieldID left; |
| 67 | jfieldID right; |
| 68 | jfieldID top; |
| 69 | } gRectClassInfo; |
| 70 | |
Leon Scroggins | 46cb9bd | 2014-03-06 15:36:39 -0500 | [diff] [blame] | 71 | // Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref. |
| 72 | void DeleteScreenshot(void* addr, void* context) { |
| 73 | SkASSERT(addr == ((ScreenshotClient*) context)->getPixels()); |
| 74 | delete ((ScreenshotClient*) context); |
| 75 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 76 | |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 77 | static struct { |
| 78 | nsecs_t UNDEFINED_TIME_NANO; |
| 79 | jmethodID init; |
| 80 | } gWindowContentFrameStatsClassInfo; |
| 81 | |
| 82 | static struct { |
| 83 | nsecs_t UNDEFINED_TIME_NANO; |
| 84 | jmethodID init; |
| 85 | } gWindowAnimationFrameStatsClassInfo; |
| 86 | |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 87 | static struct { |
| 88 | jclass clazz; |
| 89 | jmethodID ctor; |
| 90 | } gHdrCapabilitiesClassInfo; |
| 91 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 92 | // ---------------------------------------------------------------------------- |
| 93 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 94 | static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 95 | jstring nameStr, jint w, jint h, jint format, jint flags) { |
| 96 | ScopedUtfChars name(env, nameStr); |
| 97 | sp<SurfaceComposerClient> client(android_view_SurfaceSession_getClient(env, sessionObj)); |
| 98 | sp<SurfaceControl> surface = client->createSurface( |
| 99 | String8(name.c_str()), w, h, format, flags); |
| 100 | if (surface == NULL) { |
| 101 | jniThrowException(env, OutOfResourcesException, NULL); |
| 102 | return 0; |
| 103 | } |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 104 | surface->incStrong((void *)nativeCreate); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 105 | return reinterpret_cast<jlong>(surface.get()); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 108 | static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 109 | sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject)); |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 110 | ctrl->decStrong((void *)nativeCreate); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 111 | } |
| 112 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 113 | static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 114 | sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject)); |
| 115 | ctrl->clear(); |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 116 | ctrl->decStrong((void *)nativeCreate); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 117 | } |
| 118 | |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 119 | static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 120 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 121 | if (ctrl != NULL) { |
| 122 | ctrl->disconnect(); |
| 123 | } |
| 124 | } |
| 125 | |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 126 | static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz, |
| 127 | jobject displayTokenObj, jobject sourceCropObj, jint width, jint height, |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame] | 128 | jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform, |
| 129 | int rotation) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 130 | sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj); |
| 131 | if (displayToken == NULL) { |
| 132 | return NULL; |
| 133 | } |
| 134 | |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 135 | int left = env->GetIntField(sourceCropObj, gRectClassInfo.left); |
| 136 | int top = env->GetIntField(sourceCropObj, gRectClassInfo.top); |
| 137 | int right = env->GetIntField(sourceCropObj, gRectClassInfo.right); |
| 138 | int bottom = env->GetIntField(sourceCropObj, gRectClassInfo.bottom); |
| 139 | Rect sourceCrop(left, top, right, bottom); |
| 140 | |
Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame] | 141 | std::unique_ptr<ScreenshotClient> screenshot(new ScreenshotClient()); |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 142 | status_t res; |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame] | 143 | if (allLayers) { |
| 144 | minLayer = 0; |
Andreas Gampe | 0f0b491 | 2014-11-12 08:03:48 -0800 | [diff] [blame] | 145 | maxLayer = -1; |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 146 | } |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame] | 147 | |
| 148 | res = screenshot->update(displayToken, sourceCrop, width, height, |
| 149 | minLayer, maxLayer, useIdentityTransform, static_cast<uint32_t>(rotation)); |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 150 | if (res != NO_ERROR) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 151 | return NULL; |
| 152 | } |
| 153 | |
Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 154 | SkColorType colorType; |
| 155 | SkAlphaType alphaType; |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 156 | switch (screenshot->getFormat()) { |
| 157 | case PIXEL_FORMAT_RGBX_8888: { |
Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 158 | colorType = kRGBA_8888_SkColorType; |
| 159 | alphaType = kOpaque_SkAlphaType; |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 160 | break; |
| 161 | } |
| 162 | case PIXEL_FORMAT_RGBA_8888: { |
Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 163 | colorType = kRGBA_8888_SkColorType; |
| 164 | alphaType = kPremul_SkAlphaType; |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 165 | break; |
| 166 | } |
Romain Guy | 9505a65 | 2016-12-14 09:43:50 -0800 | [diff] [blame] | 167 | case PIXEL_FORMAT_RGBA_FP16: { |
| 168 | colorType = kRGBA_F16_SkColorType; |
| 169 | alphaType = kPremul_SkAlphaType; |
| 170 | break; |
| 171 | } |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 172 | case PIXEL_FORMAT_RGB_565: { |
Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 173 | colorType = kRGB_565_SkColorType; |
| 174 | alphaType = kOpaque_SkAlphaType; |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 175 | break; |
| 176 | } |
| 177 | default: { |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 178 | return NULL; |
| 179 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 180 | } |
Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 181 | SkImageInfo screenshotInfo = SkImageInfo::Make(screenshot->getWidth(), |
| 182 | screenshot->getHeight(), |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 183 | colorType, |
| 184 | alphaType, |
| 185 | GraphicsJNI::defaultColorSpace()); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 186 | |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 187 | const size_t rowBytes = |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 188 | screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat()); |
| 189 | |
Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 190 | if (!screenshotInfo.width() || !screenshotInfo.height()) { |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 191 | return NULL; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 192 | } |
| 193 | |
sergeyv | c1c5406 | 2016-10-19 18:47:26 -0700 | [diff] [blame] | 194 | auto bitmap = new Bitmap( |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 195 | (void*) screenshot->getPixels(), (void*) screenshot.get(), DeleteScreenshot, |
| 196 | screenshotInfo, rowBytes, nullptr); |
Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame] | 197 | screenshot.release(); |
sergeyv | c1c5406 | 2016-10-19 18:47:26 -0700 | [diff] [blame] | 198 | bitmap->setImmutable(); |
| 199 | return bitmap::createBitmap(env, bitmap, |
| 200 | android::bitmap::kBitmapCreateFlag_Premultiplied, NULL); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 203 | static void nativeScreenshot(JNIEnv* env, jclass clazz, jobject displayTokenObj, |
| 204 | jobject surfaceObj, jobject sourceCropObj, jint width, jint height, |
| 205 | jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform) { |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 206 | sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj); |
| 207 | if (displayToken != NULL) { |
| 208 | sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj); |
| 209 | if (consumer != NULL) { |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 210 | int left = env->GetIntField(sourceCropObj, gRectClassInfo.left); |
| 211 | int top = env->GetIntField(sourceCropObj, gRectClassInfo.top); |
| 212 | int right = env->GetIntField(sourceCropObj, gRectClassInfo.right); |
| 213 | int bottom = env->GetIntField(sourceCropObj, gRectClassInfo.bottom); |
| 214 | Rect sourceCrop(left, top, right, bottom); |
| 215 | |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 216 | if (allLayers) { |
| 217 | minLayer = 0; |
| 218 | maxLayer = -1; |
| 219 | } |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 220 | ScreenshotClient::capture(displayToken, |
| 221 | consumer->getIGraphicBufferProducer(), sourceCrop, |
Dan Stoza | 16ec12a | 2014-02-14 15:06:55 -0800 | [diff] [blame] | 222 | width, height, uint32_t(minLayer), uint32_t(maxLayer), |
| 223 | useIdentityTransform); |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | } |
| 227 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 228 | static void nativeOpenTransaction(JNIEnv* env, jclass clazz) { |
| 229 | SurfaceComposerClient::openGlobalTransaction(); |
| 230 | } |
| 231 | |
Robert Carr | e9953b1 | 2016-05-23 20:52:04 -0700 | [diff] [blame] | 232 | |
| 233 | static void nativeCloseTransaction(JNIEnv* env, jclass clazz, jboolean sync) { |
| 234 | SurfaceComposerClient::closeGlobalTransaction(sync); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz) { |
| 238 | SurfaceComposerClient::setAnimationTransaction(); |
| 239 | } |
| 240 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 241 | static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong nativeObject, jint zorder) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 242 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 243 | status_t err = ctrl->setLayer(zorder); |
| 244 | if (err < 0 && err != NO_INIT) { |
| 245 | doThrowIAE(env); |
| 246 | } |
| 247 | } |
| 248 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 249 | static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat x, jfloat y) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 250 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 251 | status_t err = ctrl->setPosition(x, y); |
| 252 | if (err < 0 && err != NO_INIT) { |
| 253 | doThrowIAE(env); |
| 254 | } |
| 255 | } |
| 256 | |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 257 | static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz, |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 258 | jlong nativeObject) { |
| 259 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 260 | status_t err = ctrl->setGeometryAppliesWithResize(); |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 261 | if (err < 0 && err != NO_INIT) { |
| 262 | doThrowIAE(env); |
| 263 | } |
| 264 | } |
| 265 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 266 | static void nativeSetSize(JNIEnv* env, jclass clazz, jlong nativeObject, jint w, jint h) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 267 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 268 | status_t err = ctrl->setSize(w, h); |
| 269 | if (err < 0 && err != NO_INIT) { |
| 270 | doThrowIAE(env); |
| 271 | } |
| 272 | } |
| 273 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 274 | static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong nativeObject, jint flags, jint mask) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 275 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 276 | status_t err = ctrl->setFlags(flags, mask); |
| 277 | if (err < 0 && err != NO_INIT) { |
| 278 | doThrowIAE(env); |
| 279 | } |
| 280 | } |
| 281 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 282 | static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong nativeObject, jobject regionObj) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 283 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 284 | SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj); |
| 285 | if (!region) { |
| 286 | doThrowIAE(env); |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | const SkIRect& b(region->getBounds()); |
| 291 | Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom)); |
| 292 | if (region->isComplex()) { |
| 293 | SkRegion::Iterator it(*region); |
| 294 | while (!it.done()) { |
| 295 | const SkIRect& r(it.rect()); |
| 296 | reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom); |
| 297 | it.next(); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | status_t err = ctrl->setTransparentRegionHint(reg); |
| 302 | if (err < 0 && err != NO_INIT) { |
| 303 | doThrowIAE(env); |
| 304 | } |
| 305 | } |
| 306 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 307 | static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat alpha) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 308 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 309 | status_t err = ctrl->setAlpha(alpha); |
| 310 | if (err < 0 && err != NO_INIT) { |
| 311 | doThrowIAE(env); |
| 312 | } |
| 313 | } |
| 314 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 315 | static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong nativeObject, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 316 | jfloat dsdx, jfloat dtdx, jfloat dsdy, jfloat dtdy) { |
| 317 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 318 | status_t err = ctrl->setMatrix(dsdx, dtdx, dsdy, dtdy); |
| 319 | if (err < 0 && err != NO_INIT) { |
| 320 | doThrowIAE(env); |
| 321 | } |
| 322 | } |
| 323 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 324 | static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong nativeObject, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 325 | jint l, jint t, jint r, jint b) { |
| 326 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 327 | Rect crop(l, t, r, b); |
| 328 | status_t err = ctrl->setCrop(crop); |
| 329 | if (err < 0 && err != NO_INIT) { |
| 330 | doThrowIAE(env); |
| 331 | } |
| 332 | } |
| 333 | |
Pablo Ceballos | 27982e6 | 2016-03-09 10:50:45 -0800 | [diff] [blame] | 334 | static void nativeSetFinalCrop(JNIEnv* env, jclass clazz, jlong nativeObject, |
| 335 | jint l, jint t, jint r, jint b) { |
| 336 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 337 | Rect crop(l, t, r, b); |
| 338 | status_t err = ctrl->setFinalCrop(crop); |
| 339 | if (err < 0 && err != NO_INIT) { |
| 340 | doThrowIAE(env); |
| 341 | } |
| 342 | } |
| 343 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 344 | static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong nativeObject, jint layerStack) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 345 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 346 | status_t err = ctrl->setLayerStack(layerStack); |
| 347 | if (err < 0 && err != NO_INIT) { |
| 348 | doThrowIAE(env); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) { |
| 353 | sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id)); |
| 354 | return javaObjectForIBinder(env, token); |
| 355 | } |
| 356 | |
| 357 | static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj, |
| 358 | jboolean secure) { |
| 359 | ScopedUtfChars name(env, nameObj); |
| 360 | sp<IBinder> token(SurfaceComposerClient::createDisplay( |
| 361 | String8(name.c_str()), bool(secure))); |
| 362 | return javaObjectForIBinder(env, token); |
| 363 | } |
| 364 | |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 365 | static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) { |
| 366 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 367 | if (token == NULL) return; |
| 368 | SurfaceComposerClient::destroyDisplay(token); |
| 369 | } |
| 370 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 371 | static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 372 | jobject tokenObj, jlong nativeSurfaceObject) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 373 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 374 | if (token == NULL) return; |
Mathias Agopian | ffddc9b | 2013-02-25 15:56:31 -0800 | [diff] [blame] | 375 | sp<IGraphicBufferProducer> bufferProducer; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 376 | sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject)); |
Mathias Agopian | ffddc9b | 2013-02-25 15:56:31 -0800 | [diff] [blame] | 377 | if (sur != NULL) { |
| 378 | bufferProducer = sur->getIGraphicBufferProducer(); |
| 379 | } |
Pablo Ceballos | aff2f94 | 2016-07-29 14:49:55 -0700 | [diff] [blame] | 380 | status_t err = SurfaceComposerClient::setDisplaySurface(token, |
| 381 | bufferProducer); |
| 382 | if (err != NO_ERROR) { |
| 383 | doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this" |
| 384 | " Surface created with singleBufferMode?"); |
| 385 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz, |
| 389 | jobject tokenObj, jint layerStack) { |
| 390 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 391 | if (token == NULL) return; |
| 392 | |
| 393 | SurfaceComposerClient::setDisplayLayerStack(token, layerStack); |
| 394 | } |
| 395 | |
| 396 | static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz, |
| 397 | jobject tokenObj, jint orientation, |
| 398 | jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom, |
| 399 | jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) { |
| 400 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 401 | if (token == NULL) return; |
| 402 | Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom); |
| 403 | Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom); |
| 404 | SurfaceComposerClient::setDisplayProjection(token, orientation, layerStackRect, displayRect); |
| 405 | } |
| 406 | |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 407 | static void nativeSetDisplaySize(JNIEnv* env, jclass clazz, |
| 408 | jobject tokenObj, jint width, jint height) { |
| 409 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 410 | if (token == NULL) return; |
| 411 | SurfaceComposerClient::setDisplaySize(token, width, height); |
| 412 | } |
| 413 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 414 | static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz, |
| 415 | jobject tokenObj) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 416 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 417 | if (token == NULL) return NULL; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 418 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 419 | Vector<DisplayInfo> configs; |
| 420 | if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR || |
| 421 | configs.size() == 0) { |
| 422 | return NULL; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 423 | } |
| 424 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 425 | jobjectArray configArray = env->NewObjectArray(configs.size(), |
| 426 | gPhysicalDisplayInfoClassInfo.clazz, NULL); |
| 427 | |
| 428 | for (size_t c = 0; c < configs.size(); ++c) { |
| 429 | const DisplayInfo& info = configs[c]; |
| 430 | jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz, |
| 431 | gPhysicalDisplayInfoClassInfo.ctor); |
| 432 | env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w); |
| 433 | env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h); |
| 434 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps); |
| 435 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density); |
| 436 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi); |
| 437 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi); |
| 438 | env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure); |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 439 | env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos, |
| 440 | info.appVsyncOffset); |
| 441 | env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos, |
| 442 | info.presentationDeadline); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 443 | env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj); |
| 444 | env->DeleteLocalRef(infoObj); |
| 445 | } |
| 446 | |
| 447 | return configArray; |
| 448 | } |
| 449 | |
| 450 | static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) { |
| 451 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 452 | if (token == NULL) return -1; |
| 453 | return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token)); |
| 454 | } |
| 455 | |
| 456 | static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) { |
| 457 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 458 | if (token == NULL) return JNI_FALSE; |
| 459 | status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id)); |
| 460 | return err == NO_ERROR ? JNI_TRUE : JNI_FALSE; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 461 | } |
| 462 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 463 | static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) { |
| 464 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 465 | if (token == NULL) return NULL; |
| 466 | Vector<android_color_mode_t> colorModes; |
| 467 | if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR || |
| 468 | colorModes.isEmpty()) { |
| 469 | return NULL; |
| 470 | } |
| 471 | |
| 472 | jintArray colorModesArray = env->NewIntArray(colorModes.size()); |
| 473 | if (colorModesArray == NULL) { |
| 474 | jniThrowException(env, "java/lang/OutOfMemoryError", NULL); |
| 475 | return NULL; |
| 476 | } |
| 477 | jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0); |
| 478 | for (size_t i = 0; i < colorModes.size(); i++) { |
| 479 | colorModesArrayValues[i] = static_cast<jint>(colorModes[i]); |
| 480 | } |
| 481 | env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0); |
| 482 | return colorModesArray; |
| 483 | } |
| 484 | |
| 485 | static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) { |
| 486 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 487 | if (token == NULL) return -1; |
| 488 | return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token)); |
| 489 | } |
| 490 | |
| 491 | static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass, |
| 492 | jobject tokenObj, jint colorMode) { |
| 493 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 494 | if (token == NULL) return JNI_FALSE; |
| 495 | status_t err = SurfaceComposerClient::setActiveColorMode(token, |
| 496 | static_cast<android_color_mode_t>(colorMode)); |
| 497 | return err == NO_ERROR ? JNI_TRUE : JNI_FALSE; |
| 498 | } |
| 499 | |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 500 | static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 501 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 502 | if (token == NULL) return; |
| 503 | |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 504 | ALOGD_IF_SLOW(100, "Excessive delay in setPowerMode()"); |
| 505 | SurfaceComposerClient::setDisplayPowerMode(token, mode); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 506 | } |
| 507 | |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 508 | static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 509 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 510 | status_t err = ctrl->clearLayerFrameStats(); |
| 511 | |
| 512 | if (err < 0 && err != NO_INIT) { |
| 513 | doThrowIAE(env); |
| 514 | } |
| 515 | |
| 516 | // The other end is not ready, just report we failed. |
| 517 | if (err == NO_INIT) { |
| 518 | return JNI_FALSE; |
| 519 | } |
| 520 | |
| 521 | return JNI_TRUE; |
| 522 | } |
| 523 | |
| 524 | static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject, |
| 525 | jobject outStats) { |
| 526 | FrameStats stats; |
| 527 | |
| 528 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 529 | status_t err = ctrl->getLayerFrameStats(&stats); |
| 530 | if (err < 0 && err != NO_INIT) { |
| 531 | doThrowIAE(env); |
| 532 | } |
| 533 | |
| 534 | // The other end is not ready, fine just return empty stats. |
| 535 | if (err == NO_INIT) { |
| 536 | return JNI_FALSE; |
| 537 | } |
| 538 | |
| 539 | jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano); |
| 540 | size_t frameCount = stats.desiredPresentTimesNano.size(); |
| 541 | |
| 542 | jlongArray postedTimesNanoDst = env->NewLongArray(frameCount); |
| 543 | if (postedTimesNanoDst == NULL) { |
| 544 | return JNI_FALSE; |
| 545 | } |
| 546 | |
| 547 | jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount); |
| 548 | if (presentedTimesNanoDst == NULL) { |
| 549 | return JNI_FALSE; |
| 550 | } |
| 551 | |
| 552 | jlongArray readyTimesNanoDst = env->NewLongArray(frameCount); |
| 553 | if (readyTimesNanoDst == NULL) { |
| 554 | return JNI_FALSE; |
| 555 | } |
| 556 | |
| 557 | nsecs_t postedTimesNanoSrc[frameCount]; |
| 558 | nsecs_t presentedTimesNanoSrc[frameCount]; |
| 559 | nsecs_t readyTimesNanoSrc[frameCount]; |
| 560 | |
| 561 | for (size_t i = 0; i < frameCount; i++) { |
| 562 | nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i]; |
| 563 | if (postedTimeNano == INT64_MAX) { |
| 564 | postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 565 | } |
| 566 | postedTimesNanoSrc[i] = postedTimeNano; |
| 567 | |
| 568 | nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i]; |
| 569 | if (presentedTimeNano == INT64_MAX) { |
| 570 | presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 571 | } |
| 572 | presentedTimesNanoSrc[i] = presentedTimeNano; |
| 573 | |
| 574 | nsecs_t readyTimeNano = stats.frameReadyTimesNano[i]; |
| 575 | if (readyTimeNano == INT64_MAX) { |
| 576 | readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 577 | } |
| 578 | readyTimesNanoSrc[i] = readyTimeNano; |
| 579 | } |
| 580 | |
| 581 | env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc); |
| 582 | env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc); |
| 583 | env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc); |
| 584 | |
| 585 | env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano, |
| 586 | postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst); |
| 587 | |
| 588 | if (env->ExceptionCheck()) { |
| 589 | return JNI_FALSE; |
| 590 | } |
| 591 | |
| 592 | return JNI_TRUE; |
| 593 | } |
| 594 | |
| 595 | static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) { |
| 596 | status_t err = SurfaceComposerClient::clearAnimationFrameStats(); |
| 597 | |
| 598 | if (err < 0 && err != NO_INIT) { |
| 599 | doThrowIAE(env); |
| 600 | } |
| 601 | |
| 602 | // The other end is not ready, just report we failed. |
| 603 | if (err == NO_INIT) { |
| 604 | return JNI_FALSE; |
| 605 | } |
| 606 | |
| 607 | return JNI_TRUE; |
| 608 | } |
| 609 | |
| 610 | static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) { |
| 611 | FrameStats stats; |
| 612 | |
| 613 | status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats); |
| 614 | if (err < 0 && err != NO_INIT) { |
| 615 | doThrowIAE(env); |
| 616 | } |
| 617 | |
| 618 | // The other end is not ready, fine just return empty stats. |
| 619 | if (err == NO_INIT) { |
| 620 | return JNI_FALSE; |
| 621 | } |
| 622 | |
| 623 | jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano); |
| 624 | size_t frameCount = stats.desiredPresentTimesNano.size(); |
| 625 | |
| 626 | jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount); |
| 627 | if (presentedTimesNanoDst == NULL) { |
| 628 | return JNI_FALSE; |
| 629 | } |
| 630 | |
| 631 | nsecs_t presentedTimesNanoSrc[frameCount]; |
| 632 | |
| 633 | for (size_t i = 0; i < frameCount; i++) { |
Allen Hair | ac5eda3 | 2014-04-24 11:50:37 -0700 | [diff] [blame] | 634 | nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i]; |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 635 | if (presentedTimeNano == INT64_MAX) { |
| 636 | presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 637 | } |
| 638 | presentedTimesNanoSrc[i] = presentedTimeNano; |
| 639 | } |
| 640 | |
| 641 | env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc); |
| 642 | |
| 643 | env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano, |
| 644 | presentedTimesNanoDst); |
| 645 | |
| 646 | if (env->ExceptionCheck()) { |
| 647 | return JNI_FALSE; |
| 648 | } |
| 649 | |
| 650 | return JNI_TRUE; |
| 651 | } |
| 652 | |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 653 | |
| 654 | static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong nativeObject, |
| 655 | jobject handleObject, jlong frameNumber) { |
| 656 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 657 | sp<IBinder> handle = ibinderForJavaObject(env, handleObject); |
| 658 | |
| 659 | ctrl->deferTransactionUntil(handle, frameNumber); |
| 660 | } |
| 661 | |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 662 | static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong nativeObject, |
| 663 | jint scalingMode) { |
| 664 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 665 | |
| 666 | ctrl->setOverrideScalingMode(scalingMode); |
| 667 | } |
| 668 | |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 669 | static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 670 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 671 | |
| 672 | return javaObjectForIBinder(env, ctrl->getHandle()); |
| 673 | } |
| 674 | |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 675 | static jboolean nativeGetTransformToDisplayInverse(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 676 | bool out = false; |
| 677 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 678 | status_t status = ctrl->getTransformToDisplayInverse(&out); |
| 679 | if (status != NO_ERROR) { |
| 680 | return false; |
| 681 | } |
| 682 | return out; |
| 683 | } |
| 684 | |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 685 | static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) { |
| 686 | sp<IBinder> token(ibinderForJavaObject(env, tokenObject)); |
| 687 | if (token == NULL) return NULL; |
| 688 | |
| 689 | HdrCapabilities capabilities; |
| 690 | SurfaceComposerClient::getHdrCapabilities(token, &capabilities); |
| 691 | |
| 692 | const auto& types = capabilities.getSupportedHdrTypes(); |
| 693 | auto typesArray = env->NewIntArray(types.size()); |
| 694 | env->SetIntArrayRegion(typesArray, 0, types.size(), types.data()); |
| 695 | |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 696 | return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor, |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 697 | typesArray, capabilities.getDesiredMaxLuminance(), |
| 698 | capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance()); |
| 699 | } |
| 700 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 701 | // ---------------------------------------------------------------------------- |
| 702 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 703 | static const JNINativeMethod sSurfaceControlMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 704 | {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIII)J", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 705 | (void*)nativeCreate }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 706 | {"nativeRelease", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 707 | (void*)nativeRelease }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 708 | {"nativeDestroy", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 709 | (void*)nativeDestroy }, |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 710 | {"nativeDisconnect", "(J)V", |
| 711 | (void*)nativeDisconnect }, |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame] | 712 | {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;", |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 713 | (void*)nativeScreenshotBitmap }, |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 714 | {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 715 | (void*)nativeScreenshot }, |
| 716 | {"nativeOpenTransaction", "()V", |
| 717 | (void*)nativeOpenTransaction }, |
Robert Carr | e9953b1 | 2016-05-23 20:52:04 -0700 | [diff] [blame] | 718 | {"nativeCloseTransaction", "(Z)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 719 | (void*)nativeCloseTransaction }, |
| 720 | {"nativeSetAnimationTransaction", "()V", |
| 721 | (void*)nativeSetAnimationTransaction }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 722 | {"nativeSetLayer", "(JI)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 723 | (void*)nativeSetLayer }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 724 | {"nativeSetPosition", "(JFF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 725 | (void*)nativeSetPosition }, |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 726 | {"nativeSetGeometryAppliesWithResize", "(J)V", |
| 727 | (void*)nativeSetGeometryAppliesWithResize }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 728 | {"nativeSetSize", "(JII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 729 | (void*)nativeSetSize }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 730 | {"nativeSetTransparentRegionHint", "(JLandroid/graphics/Region;)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 731 | (void*)nativeSetTransparentRegionHint }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 732 | {"nativeSetAlpha", "(JF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 733 | (void*)nativeSetAlpha }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 734 | {"nativeSetMatrix", "(JFFFF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 735 | (void*)nativeSetMatrix }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 736 | {"nativeSetFlags", "(JII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 737 | (void*)nativeSetFlags }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 738 | {"nativeSetWindowCrop", "(JIIII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 739 | (void*)nativeSetWindowCrop }, |
Pablo Ceballos | 27982e6 | 2016-03-09 10:50:45 -0800 | [diff] [blame] | 740 | {"nativeSetFinalCrop", "(JIIII)V", |
| 741 | (void*)nativeSetFinalCrop }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 742 | {"nativeSetLayerStack", "(JI)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 743 | (void*)nativeSetLayerStack }, |
| 744 | {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;", |
| 745 | (void*)nativeGetBuiltInDisplay }, |
| 746 | {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;", |
| 747 | (void*)nativeCreateDisplay }, |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 748 | {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V", |
| 749 | (void*)nativeDestroyDisplay }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 750 | {"nativeSetDisplaySurface", "(Landroid/os/IBinder;J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 751 | (void*)nativeSetDisplaySurface }, |
| 752 | {"nativeSetDisplayLayerStack", "(Landroid/os/IBinder;I)V", |
| 753 | (void*)nativeSetDisplayLayerStack }, |
| 754 | {"nativeSetDisplayProjection", "(Landroid/os/IBinder;IIIIIIIII)V", |
| 755 | (void*)nativeSetDisplayProjection }, |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 756 | {"nativeSetDisplaySize", "(Landroid/os/IBinder;II)V", |
| 757 | (void*)nativeSetDisplaySize }, |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 758 | {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;", |
| 759 | (void*)nativeGetDisplayConfigs }, |
| 760 | {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I", |
| 761 | (void*)nativeGetActiveConfig }, |
| 762 | {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z", |
| 763 | (void*)nativeSetActiveConfig }, |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 764 | {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I", |
| 765 | (void*)nativeGetDisplayColorModes}, |
| 766 | {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I", |
| 767 | (void*)nativeGetActiveColorMode}, |
| 768 | {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z", |
| 769 | (void*)nativeSetActiveColorMode}, |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 770 | {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;", |
| 771 | (void*)nativeGetHdrCapabilities }, |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 772 | {"nativeClearContentFrameStats", "(J)Z", |
| 773 | (void*)nativeClearContentFrameStats }, |
| 774 | {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z", |
| 775 | (void*)nativeGetContentFrameStats }, |
| 776 | {"nativeClearAnimationFrameStats", "()Z", |
| 777 | (void*)nativeClearAnimationFrameStats }, |
| 778 | {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z", |
| 779 | (void*)nativeGetAnimationFrameStats }, |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 780 | {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V", |
| 781 | (void*)nativeSetDisplayPowerMode }, |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 782 | {"nativeDeferTransactionUntil", "(JLandroid/os/IBinder;J)V", |
| 783 | (void*)nativeDeferTransactionUntil }, |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 784 | {"nativeSetOverrideScalingMode", "(JI)V", |
| 785 | (void*)nativeSetOverrideScalingMode }, |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 786 | {"nativeGetHandle", "(J)Landroid/os/IBinder;", |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 787 | (void*)nativeGetHandle }, |
| 788 | {"nativeGetTransformToDisplayInverse", "(J)Z", |
| 789 | (void*)nativeGetTransformToDisplayInverse }, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 790 | }; |
| 791 | |
| 792 | int register_android_view_SurfaceControl(JNIEnv* env) |
| 793 | { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 794 | int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 795 | sSurfaceControlMethods, NELEM(sSurfaceControlMethods)); |
| 796 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 797 | jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo"); |
| 798 | gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz); |
| 799 | gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env, |
| 800 | gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V"); |
| 801 | gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I"); |
| 802 | gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I"); |
| 803 | gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F"); |
| 804 | gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F"); |
| 805 | gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F"); |
| 806 | gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F"); |
| 807 | gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z"); |
| 808 | gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env, |
| 809 | clazz, "appVsyncOffsetNanos", "J"); |
| 810 | gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env, |
| 811 | clazz, "presentationDeadlineNanos", "J"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 812 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 813 | jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect"); |
| 814 | gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I"); |
| 815 | gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I"); |
| 816 | gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I"); |
| 817 | gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I"); |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 818 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 819 | jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats"); |
| 820 | jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env, |
| 821 | frameStatsClazz, "UNDEFINED_TIME_NANO", "J"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 822 | nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field); |
| 823 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 824 | jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats"); |
| 825 | gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env, |
| 826 | contFrameStatsClazz, "init", "(J[J[J[J)V"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 827 | gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; |
| 828 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 829 | jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats"); |
| 830 | gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env, |
| 831 | animFrameStatsClazz, "init", "(J[J)V"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 832 | gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; |
| 833 | |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 834 | jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities"); |
| 835 | gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz); |
| 836 | gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>", |
| 837 | "([IFFF)V"); |
| 838 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 839 | return err; |
| 840 | } |
| 841 | |
| 842 | }; |