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