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