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