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 | |
Pablo Ceballos | 27982e6 | 2016-03-09 10:50:45 -0800 | [diff] [blame^] | 312 | static void nativeSetFinalCrop(JNIEnv* env, jclass clazz, jlong nativeObject, |
| 313 | jint l, jint t, jint r, jint b) { |
| 314 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 315 | Rect crop(l, t, r, b); |
| 316 | status_t err = ctrl->setFinalCrop(crop); |
| 317 | if (err < 0 && err != NO_INIT) { |
| 318 | doThrowIAE(env); |
| 319 | } |
| 320 | } |
| 321 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 322 | static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong nativeObject, jint layerStack) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 323 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 324 | status_t err = ctrl->setLayerStack(layerStack); |
| 325 | if (err < 0 && err != NO_INIT) { |
| 326 | doThrowIAE(env); |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) { |
| 331 | sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id)); |
| 332 | return javaObjectForIBinder(env, token); |
| 333 | } |
| 334 | |
| 335 | static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj, |
| 336 | jboolean secure) { |
| 337 | ScopedUtfChars name(env, nameObj); |
| 338 | sp<IBinder> token(SurfaceComposerClient::createDisplay( |
| 339 | String8(name.c_str()), bool(secure))); |
| 340 | return javaObjectForIBinder(env, token); |
| 341 | } |
| 342 | |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 343 | static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) { |
| 344 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 345 | if (token == NULL) return; |
| 346 | SurfaceComposerClient::destroyDisplay(token); |
| 347 | } |
| 348 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 349 | static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 350 | jobject tokenObj, jlong nativeSurfaceObject) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 351 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 352 | if (token == NULL) return; |
Mathias Agopian | ffddc9b | 2013-02-25 15:56:31 -0800 | [diff] [blame] | 353 | sp<IGraphicBufferProducer> bufferProducer; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 354 | sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject)); |
Mathias Agopian | ffddc9b | 2013-02-25 15:56:31 -0800 | [diff] [blame] | 355 | if (sur != NULL) { |
| 356 | bufferProducer = sur->getIGraphicBufferProducer(); |
| 357 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 358 | SurfaceComposerClient::setDisplaySurface(token, bufferProducer); |
| 359 | } |
| 360 | |
| 361 | static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz, |
| 362 | jobject tokenObj, jint layerStack) { |
| 363 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 364 | if (token == NULL) return; |
| 365 | |
| 366 | SurfaceComposerClient::setDisplayLayerStack(token, layerStack); |
| 367 | } |
| 368 | |
| 369 | static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz, |
| 370 | jobject tokenObj, jint orientation, |
| 371 | jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom, |
| 372 | jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) { |
| 373 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 374 | if (token == NULL) return; |
| 375 | Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom); |
| 376 | Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom); |
| 377 | SurfaceComposerClient::setDisplayProjection(token, orientation, layerStackRect, displayRect); |
| 378 | } |
| 379 | |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 380 | static void nativeSetDisplaySize(JNIEnv* env, jclass clazz, |
| 381 | jobject tokenObj, jint width, jint height) { |
| 382 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 383 | if (token == NULL) return; |
| 384 | SurfaceComposerClient::setDisplaySize(token, width, height); |
| 385 | } |
| 386 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 387 | static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz, |
| 388 | jobject tokenObj) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 389 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 390 | if (token == NULL) return NULL; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 391 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 392 | Vector<DisplayInfo> configs; |
| 393 | if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR || |
| 394 | configs.size() == 0) { |
| 395 | return NULL; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 396 | } |
| 397 | |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 398 | jobjectArray configArray = env->NewObjectArray(configs.size(), |
| 399 | gPhysicalDisplayInfoClassInfo.clazz, NULL); |
| 400 | |
| 401 | for (size_t c = 0; c < configs.size(); ++c) { |
| 402 | const DisplayInfo& info = configs[c]; |
| 403 | jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz, |
| 404 | gPhysicalDisplayInfoClassInfo.ctor); |
| 405 | env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w); |
| 406 | env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h); |
| 407 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps); |
| 408 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density); |
| 409 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi); |
| 410 | env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi); |
| 411 | env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure); |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 412 | env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos, |
| 413 | info.appVsyncOffset); |
| 414 | env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos, |
| 415 | info.presentationDeadline); |
Dan Stoza | 904f485 | 2015-08-31 12:01:48 -0700 | [diff] [blame] | 416 | env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.colorTransform, |
| 417 | info.colorTransform); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 418 | env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj); |
| 419 | env->DeleteLocalRef(infoObj); |
| 420 | } |
| 421 | |
| 422 | return configArray; |
| 423 | } |
| 424 | |
| 425 | static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) { |
| 426 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 427 | if (token == NULL) return -1; |
| 428 | return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token)); |
| 429 | } |
| 430 | |
| 431 | static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) { |
| 432 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 433 | if (token == NULL) return JNI_FALSE; |
| 434 | status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id)); |
| 435 | return err == NO_ERROR ? JNI_TRUE : JNI_FALSE; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 436 | } |
| 437 | |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 438 | static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 439 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 440 | if (token == NULL) return; |
| 441 | |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 442 | ALOGD_IF_SLOW(100, "Excessive delay in setPowerMode()"); |
| 443 | SurfaceComposerClient::setDisplayPowerMode(token, mode); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 444 | } |
| 445 | |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 446 | static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 447 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 448 | status_t err = ctrl->clearLayerFrameStats(); |
| 449 | |
| 450 | if (err < 0 && err != NO_INIT) { |
| 451 | doThrowIAE(env); |
| 452 | } |
| 453 | |
| 454 | // The other end is not ready, just report we failed. |
| 455 | if (err == NO_INIT) { |
| 456 | return JNI_FALSE; |
| 457 | } |
| 458 | |
| 459 | return JNI_TRUE; |
| 460 | } |
| 461 | |
| 462 | static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject, |
| 463 | jobject outStats) { |
| 464 | FrameStats stats; |
| 465 | |
| 466 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 467 | status_t err = ctrl->getLayerFrameStats(&stats); |
| 468 | if (err < 0 && err != NO_INIT) { |
| 469 | doThrowIAE(env); |
| 470 | } |
| 471 | |
| 472 | // The other end is not ready, fine just return empty stats. |
| 473 | if (err == NO_INIT) { |
| 474 | return JNI_FALSE; |
| 475 | } |
| 476 | |
| 477 | jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano); |
| 478 | size_t frameCount = stats.desiredPresentTimesNano.size(); |
| 479 | |
| 480 | jlongArray postedTimesNanoDst = env->NewLongArray(frameCount); |
| 481 | if (postedTimesNanoDst == NULL) { |
| 482 | return JNI_FALSE; |
| 483 | } |
| 484 | |
| 485 | jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount); |
| 486 | if (presentedTimesNanoDst == NULL) { |
| 487 | return JNI_FALSE; |
| 488 | } |
| 489 | |
| 490 | jlongArray readyTimesNanoDst = env->NewLongArray(frameCount); |
| 491 | if (readyTimesNanoDst == NULL) { |
| 492 | return JNI_FALSE; |
| 493 | } |
| 494 | |
| 495 | nsecs_t postedTimesNanoSrc[frameCount]; |
| 496 | nsecs_t presentedTimesNanoSrc[frameCount]; |
| 497 | nsecs_t readyTimesNanoSrc[frameCount]; |
| 498 | |
| 499 | for (size_t i = 0; i < frameCount; i++) { |
| 500 | nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i]; |
| 501 | if (postedTimeNano == INT64_MAX) { |
| 502 | postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 503 | } |
| 504 | postedTimesNanoSrc[i] = postedTimeNano; |
| 505 | |
| 506 | nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i]; |
| 507 | if (presentedTimeNano == INT64_MAX) { |
| 508 | presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 509 | } |
| 510 | presentedTimesNanoSrc[i] = presentedTimeNano; |
| 511 | |
| 512 | nsecs_t readyTimeNano = stats.frameReadyTimesNano[i]; |
| 513 | if (readyTimeNano == INT64_MAX) { |
| 514 | readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 515 | } |
| 516 | readyTimesNanoSrc[i] = readyTimeNano; |
| 517 | } |
| 518 | |
| 519 | env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc); |
| 520 | env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc); |
| 521 | env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc); |
| 522 | |
| 523 | env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano, |
| 524 | postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst); |
| 525 | |
| 526 | if (env->ExceptionCheck()) { |
| 527 | return JNI_FALSE; |
| 528 | } |
| 529 | |
| 530 | return JNI_TRUE; |
| 531 | } |
| 532 | |
| 533 | static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) { |
| 534 | status_t err = SurfaceComposerClient::clearAnimationFrameStats(); |
| 535 | |
| 536 | if (err < 0 && err != NO_INIT) { |
| 537 | doThrowIAE(env); |
| 538 | } |
| 539 | |
| 540 | // The other end is not ready, just report we failed. |
| 541 | if (err == NO_INIT) { |
| 542 | return JNI_FALSE; |
| 543 | } |
| 544 | |
| 545 | return JNI_TRUE; |
| 546 | } |
| 547 | |
| 548 | static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) { |
| 549 | FrameStats stats; |
| 550 | |
| 551 | status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats); |
| 552 | if (err < 0 && err != NO_INIT) { |
| 553 | doThrowIAE(env); |
| 554 | } |
| 555 | |
| 556 | // The other end is not ready, fine just return empty stats. |
| 557 | if (err == NO_INIT) { |
| 558 | return JNI_FALSE; |
| 559 | } |
| 560 | |
| 561 | jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano); |
| 562 | size_t frameCount = stats.desiredPresentTimesNano.size(); |
| 563 | |
| 564 | jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount); |
| 565 | if (presentedTimesNanoDst == NULL) { |
| 566 | return JNI_FALSE; |
| 567 | } |
| 568 | |
| 569 | nsecs_t presentedTimesNanoSrc[frameCount]; |
| 570 | |
| 571 | for (size_t i = 0; i < frameCount; i++) { |
Allen Hair | ac5eda3 | 2014-04-24 11:50:37 -0700 | [diff] [blame] | 572 | nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i]; |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 573 | if (presentedTimeNano == INT64_MAX) { |
| 574 | presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 575 | } |
| 576 | presentedTimesNanoSrc[i] = presentedTimeNano; |
| 577 | } |
| 578 | |
| 579 | env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc); |
| 580 | |
| 581 | env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano, |
| 582 | presentedTimesNanoDst); |
| 583 | |
| 584 | if (env->ExceptionCheck()) { |
| 585 | return JNI_FALSE; |
| 586 | } |
| 587 | |
| 588 | return JNI_TRUE; |
| 589 | } |
| 590 | |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 591 | |
| 592 | static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong nativeObject, |
| 593 | jobject handleObject, jlong frameNumber) { |
| 594 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 595 | sp<IBinder> handle = ibinderForJavaObject(env, handleObject); |
| 596 | |
| 597 | ctrl->deferTransactionUntil(handle, frameNumber); |
| 598 | } |
| 599 | |
| 600 | static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 601 | auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 602 | |
| 603 | return javaObjectForIBinder(env, ctrl->getHandle()); |
| 604 | } |
| 605 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 606 | // ---------------------------------------------------------------------------- |
| 607 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 608 | static const JNINativeMethod sSurfaceControlMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 609 | {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIII)J", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 610 | (void*)nativeCreate }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 611 | {"nativeRelease", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 612 | (void*)nativeRelease }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 613 | {"nativeDestroy", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 614 | (void*)nativeDestroy }, |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 615 | {"nativeDisconnect", "(J)V", |
| 616 | (void*)nativeDisconnect }, |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame] | 617 | {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;", |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 618 | (void*)nativeScreenshotBitmap }, |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 619 | {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 620 | (void*)nativeScreenshot }, |
| 621 | {"nativeOpenTransaction", "()V", |
| 622 | (void*)nativeOpenTransaction }, |
| 623 | {"nativeCloseTransaction", "()V", |
| 624 | (void*)nativeCloseTransaction }, |
| 625 | {"nativeSetAnimationTransaction", "()V", |
| 626 | (void*)nativeSetAnimationTransaction }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 627 | {"nativeSetLayer", "(JI)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 628 | (void*)nativeSetLayer }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 629 | {"nativeSetPosition", "(JFF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 630 | (void*)nativeSetPosition }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 631 | {"nativeSetSize", "(JII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 632 | (void*)nativeSetSize }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 633 | {"nativeSetTransparentRegionHint", "(JLandroid/graphics/Region;)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 634 | (void*)nativeSetTransparentRegionHint }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 635 | {"nativeSetAlpha", "(JF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 636 | (void*)nativeSetAlpha }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 637 | {"nativeSetMatrix", "(JFFFF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 638 | (void*)nativeSetMatrix }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 639 | {"nativeSetFlags", "(JII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 640 | (void*)nativeSetFlags }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 641 | {"nativeSetWindowCrop", "(JIIII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 642 | (void*)nativeSetWindowCrop }, |
Pablo Ceballos | 27982e6 | 2016-03-09 10:50:45 -0800 | [diff] [blame^] | 643 | {"nativeSetFinalCrop", "(JIIII)V", |
| 644 | (void*)nativeSetFinalCrop }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 645 | {"nativeSetLayerStack", "(JI)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 646 | (void*)nativeSetLayerStack }, |
| 647 | {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;", |
| 648 | (void*)nativeGetBuiltInDisplay }, |
| 649 | {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;", |
| 650 | (void*)nativeCreateDisplay }, |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 651 | {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V", |
| 652 | (void*)nativeDestroyDisplay }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 653 | {"nativeSetDisplaySurface", "(Landroid/os/IBinder;J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 654 | (void*)nativeSetDisplaySurface }, |
| 655 | {"nativeSetDisplayLayerStack", "(Landroid/os/IBinder;I)V", |
| 656 | (void*)nativeSetDisplayLayerStack }, |
| 657 | {"nativeSetDisplayProjection", "(Landroid/os/IBinder;IIIIIIIII)V", |
| 658 | (void*)nativeSetDisplayProjection }, |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 659 | {"nativeSetDisplaySize", "(Landroid/os/IBinder;II)V", |
| 660 | (void*)nativeSetDisplaySize }, |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 661 | {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;", |
| 662 | (void*)nativeGetDisplayConfigs }, |
| 663 | {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I", |
| 664 | (void*)nativeGetActiveConfig }, |
| 665 | {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z", |
| 666 | (void*)nativeSetActiveConfig }, |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 667 | {"nativeClearContentFrameStats", "(J)Z", |
| 668 | (void*)nativeClearContentFrameStats }, |
| 669 | {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z", |
| 670 | (void*)nativeGetContentFrameStats }, |
| 671 | {"nativeClearAnimationFrameStats", "()Z", |
| 672 | (void*)nativeClearAnimationFrameStats }, |
| 673 | {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z", |
| 674 | (void*)nativeGetAnimationFrameStats }, |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 675 | {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V", |
| 676 | (void*)nativeSetDisplayPowerMode }, |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 677 | {"nativeDeferTransactionUntil", "(JLandroid/os/IBinder;J)V", |
| 678 | (void*)nativeDeferTransactionUntil }, |
| 679 | {"nativeGetHandle", "(J)Landroid/os/IBinder;", |
| 680 | (void*)nativeGetHandle } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 681 | }; |
| 682 | |
| 683 | int register_android_view_SurfaceControl(JNIEnv* env) |
| 684 | { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 685 | int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 686 | sSurfaceControlMethods, NELEM(sSurfaceControlMethods)); |
| 687 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 688 | jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo"); |
| 689 | gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz); |
| 690 | gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env, |
| 691 | gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V"); |
| 692 | gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I"); |
| 693 | gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I"); |
| 694 | gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F"); |
| 695 | gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F"); |
| 696 | gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F"); |
| 697 | gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F"); |
| 698 | gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z"); |
| 699 | gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env, |
| 700 | clazz, "appVsyncOffsetNanos", "J"); |
| 701 | gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env, |
| 702 | clazz, "presentationDeadlineNanos", "J"); |
Dan Stoza | 904f485 | 2015-08-31 12:01:48 -0700 | [diff] [blame] | 703 | gPhysicalDisplayInfoClassInfo.colorTransform = GetFieldIDOrDie(env, clazz, |
| 704 | "colorTransform", "I"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 705 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 706 | jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect"); |
| 707 | gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I"); |
| 708 | gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I"); |
| 709 | gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I"); |
| 710 | gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I"); |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 711 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 712 | jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats"); |
| 713 | jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env, |
| 714 | frameStatsClazz, "UNDEFINED_TIME_NANO", "J"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 715 | nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field); |
| 716 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 717 | jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats"); |
| 718 | gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env, |
| 719 | contFrameStatsClazz, "init", "(J[J[J[J)V"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 720 | gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; |
| 721 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 722 | jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats"); |
| 723 | gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env, |
| 724 | animFrameStatsClazz, "init", "(J[J)V"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 725 | gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; |
| 726 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 727 | return err; |
| 728 | } |
| 729 | |
| 730 | }; |