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 | |
| 19 | #include <stdio.h> |
| 20 | |
| 21 | #include "jni.h" |
| 22 | #include "JNIHelp.h" |
| 23 | |
| 24 | #include "android_os_Parcel.h" |
| 25 | #include "android_util_Binder.h" |
| 26 | #include "android/graphics/GraphicsJNI.h" |
| 27 | #include "android/graphics/Region.h" |
| 28 | |
| 29 | #include <android_runtime/AndroidRuntime.h> |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 30 | #include <android_runtime/android_view_Surface.h> |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 31 | #include <android_runtime/android_view_SurfaceSession.h> |
| 32 | |
| 33 | #include <gui/Surface.h> |
| 34 | #include <gui/SurfaceComposerClient.h> |
| 35 | |
| 36 | #include <ui/DisplayInfo.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> |
| 40 | |
| 41 | #include <utils/Log.h> |
| 42 | |
| 43 | #include <ScopedUtfChars.h> |
| 44 | |
Leon Scroggins III | e3f9800 | 2014-06-10 13:19:35 -0400 | [diff] [blame] | 45 | #include "SkTemplates.h" |
| 46 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 47 | // ---------------------------------------------------------------------------- |
| 48 | |
| 49 | namespace android { |
| 50 | |
| 51 | static const char* const OutOfResourcesException = |
| 52 | "android/view/Surface$OutOfResourcesException"; |
| 53 | |
| 54 | static struct { |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 55 | jclass clazz; |
| 56 | jmethodID ctor; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 57 | jfieldID width; |
| 58 | jfieldID height; |
| 59 | jfieldID refreshRate; |
| 60 | jfieldID density; |
| 61 | jfieldID xDpi; |
| 62 | jfieldID yDpi; |
| 63 | jfieldID secure; |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 64 | jfieldID appVsyncOffsetNanos; |
| 65 | jfieldID presentationDeadlineNanos; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 66 | } gPhysicalDisplayInfoClassInfo; |
| 67 | |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 68 | static struct { |
| 69 | jfieldID bottom; |
| 70 | jfieldID left; |
| 71 | jfieldID right; |
| 72 | jfieldID top; |
| 73 | } gRectClassInfo; |
| 74 | |
Leon Scroggins | 46cb9bd | 2014-03-06 15:36:39 -0500 | [diff] [blame] | 75 | // Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref. |
| 76 | void DeleteScreenshot(void* addr, void* context) { |
| 77 | SkASSERT(addr == ((ScreenshotClient*) context)->getPixels()); |
| 78 | delete ((ScreenshotClient*) context); |
| 79 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 80 | |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 81 | static struct { |
| 82 | nsecs_t UNDEFINED_TIME_NANO; |
| 83 | jmethodID init; |
| 84 | } gWindowContentFrameStatsClassInfo; |
| 85 | |
| 86 | static struct { |
| 87 | nsecs_t UNDEFINED_TIME_NANO; |
| 88 | jmethodID init; |
| 89 | } gWindowAnimationFrameStatsClassInfo; |
| 90 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 91 | // ---------------------------------------------------------------------------- |
| 92 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 93 | static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 94 | jstring nameStr, jint w, jint h, jint format, jint flags) { |
| 95 | ScopedUtfChars name(env, nameStr); |
| 96 | sp<SurfaceComposerClient> client(android_view_SurfaceSession_getClient(env, sessionObj)); |
| 97 | sp<SurfaceControl> surface = client->createSurface( |
| 98 | String8(name.c_str()), w, h, format, flags); |
| 99 | if (surface == NULL) { |
| 100 | jniThrowException(env, OutOfResourcesException, NULL); |
| 101 | return 0; |
| 102 | } |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 103 | surface->incStrong((void *)nativeCreate); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 104 | return reinterpret_cast<jlong>(surface.get()); |
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 nativeRelease(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)); |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 109 | ctrl->decStrong((void *)nativeCreate); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 110 | } |
| 111 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 112 | static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 113 | sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject)); |
| 114 | ctrl->clear(); |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 115 | ctrl->decStrong((void *)nativeCreate); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 118 | static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz, |
| 119 | jobject displayTokenObj, jobject sourceCropObj, jint width, jint height, |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame^] | 120 | jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform, |
| 121 | int rotation) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 122 | sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj); |
| 123 | if (displayToken == NULL) { |
| 124 | return NULL; |
| 125 | } |
| 126 | |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 127 | int left = env->GetIntField(sourceCropObj, gRectClassInfo.left); |
| 128 | int top = env->GetIntField(sourceCropObj, gRectClassInfo.top); |
| 129 | int right = env->GetIntField(sourceCropObj, gRectClassInfo.right); |
| 130 | int bottom = env->GetIntField(sourceCropObj, gRectClassInfo.bottom); |
| 131 | Rect sourceCrop(left, top, right, bottom); |
| 132 | |
Leon Scroggins III | e3f9800 | 2014-06-10 13:19:35 -0400 | [diff] [blame] | 133 | SkAutoTDelete<ScreenshotClient> screenshot(new ScreenshotClient()); |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 134 | status_t res; |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame^] | 135 | if (allLayers) { |
| 136 | minLayer = 0; |
| 137 | maxLayer = -1UL; |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 138 | } |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame^] | 139 | |
| 140 | res = screenshot->update(displayToken, sourceCrop, width, height, |
| 141 | minLayer, maxLayer, useIdentityTransform, static_cast<uint32_t>(rotation)); |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 142 | if (res != NO_ERROR) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 143 | return NULL; |
| 144 | } |
| 145 | |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 146 | SkImageInfo screenshotInfo; |
| 147 | screenshotInfo.fWidth = screenshot->getWidth(); |
| 148 | screenshotInfo.fHeight = screenshot->getHeight(); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 149 | |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 150 | switch (screenshot->getFormat()) { |
| 151 | case PIXEL_FORMAT_RGBX_8888: { |
| 152 | screenshotInfo.fColorType = kRGBA_8888_SkColorType; |
| 153 | screenshotInfo.fAlphaType = kIgnore_SkAlphaType; |
| 154 | break; |
| 155 | } |
| 156 | case PIXEL_FORMAT_RGBA_8888: { |
| 157 | screenshotInfo.fColorType = kRGBA_8888_SkColorType; |
| 158 | screenshotInfo.fAlphaType = kPremul_SkAlphaType; |
| 159 | break; |
| 160 | } |
| 161 | case PIXEL_FORMAT_RGB_565: { |
| 162 | screenshotInfo.fColorType = kRGB_565_SkColorType; |
| 163 | screenshotInfo.fAlphaType = kIgnore_SkAlphaType; |
| 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 | } |
| 170 | |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 171 | const ssize_t rowBytes = |
| 172 | screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat()); |
| 173 | |
| 174 | SkBitmap* bitmap = new SkBitmap(); |
Mike Reed | b933055 | 2014-06-16 17:31:48 -0400 | [diff] [blame] | 175 | bitmap->setInfo(screenshotInfo, (size_t)rowBytes); |
Derek Sollenberger | b644a3b | 2014-01-17 15:45:10 -0500 | [diff] [blame] | 176 | if (screenshotInfo.fWidth > 0 && screenshotInfo.fHeight > 0) { |
Leon Scroggins | 46cb9bd | 2014-03-06 15:36:39 -0500 | [diff] [blame] | 177 | // takes ownership of ScreenshotClient |
| 178 | SkMallocPixelRef* pixels = SkMallocPixelRef::NewWithProc(screenshotInfo, |
| 179 | (size_t) rowBytes, NULL, (void*) screenshot->getPixels(), &DeleteScreenshot, |
Thierry Strudel | 5474f33 | 2014-08-22 11:19:09 -0700 | [diff] [blame] | 180 | (void*) (screenshot.get())); |
| 181 | screenshot.detach(); |
Leon Scroggins | 46cb9bd | 2014-03-06 15:36:39 -0500 | [diff] [blame] | 182 | pixels->setImmutable(); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 183 | bitmap->setPixelRef(pixels)->unref(); |
| 184 | bitmap->lockPixels(); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 185 | } |
| 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 | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 406 | env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj); |
| 407 | env->DeleteLocalRef(infoObj); |
| 408 | } |
| 409 | |
| 410 | return configArray; |
| 411 | } |
| 412 | |
| 413 | static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) { |
| 414 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 415 | if (token == NULL) return -1; |
| 416 | return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token)); |
| 417 | } |
| 418 | |
| 419 | static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) { |
| 420 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 421 | if (token == NULL) return JNI_FALSE; |
| 422 | status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id)); |
| 423 | return err == NO_ERROR ? JNI_TRUE : JNI_FALSE; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 424 | } |
| 425 | |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 426 | static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 427 | sp<IBinder> token(ibinderForJavaObject(env, tokenObj)); |
| 428 | if (token == NULL) return; |
| 429 | |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 430 | ALOGD_IF_SLOW(100, "Excessive delay in setPowerMode()"); |
| 431 | SurfaceComposerClient::setDisplayPowerMode(token, mode); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 434 | static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 435 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 436 | status_t err = ctrl->clearLayerFrameStats(); |
| 437 | |
| 438 | if (err < 0 && err != NO_INIT) { |
| 439 | doThrowIAE(env); |
| 440 | } |
| 441 | |
| 442 | // The other end is not ready, just report we failed. |
| 443 | if (err == NO_INIT) { |
| 444 | return JNI_FALSE; |
| 445 | } |
| 446 | |
| 447 | return JNI_TRUE; |
| 448 | } |
| 449 | |
| 450 | static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject, |
| 451 | jobject outStats) { |
| 452 | FrameStats stats; |
| 453 | |
| 454 | SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject); |
| 455 | status_t err = ctrl->getLayerFrameStats(&stats); |
| 456 | if (err < 0 && err != NO_INIT) { |
| 457 | doThrowIAE(env); |
| 458 | } |
| 459 | |
| 460 | // The other end is not ready, fine just return empty stats. |
| 461 | if (err == NO_INIT) { |
| 462 | return JNI_FALSE; |
| 463 | } |
| 464 | |
| 465 | jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano); |
| 466 | size_t frameCount = stats.desiredPresentTimesNano.size(); |
| 467 | |
| 468 | jlongArray postedTimesNanoDst = env->NewLongArray(frameCount); |
| 469 | if (postedTimesNanoDst == NULL) { |
| 470 | return JNI_FALSE; |
| 471 | } |
| 472 | |
| 473 | jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount); |
| 474 | if (presentedTimesNanoDst == NULL) { |
| 475 | return JNI_FALSE; |
| 476 | } |
| 477 | |
| 478 | jlongArray readyTimesNanoDst = env->NewLongArray(frameCount); |
| 479 | if (readyTimesNanoDst == NULL) { |
| 480 | return JNI_FALSE; |
| 481 | } |
| 482 | |
| 483 | nsecs_t postedTimesNanoSrc[frameCount]; |
| 484 | nsecs_t presentedTimesNanoSrc[frameCount]; |
| 485 | nsecs_t readyTimesNanoSrc[frameCount]; |
| 486 | |
| 487 | for (size_t i = 0; i < frameCount; i++) { |
| 488 | nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i]; |
| 489 | if (postedTimeNano == INT64_MAX) { |
| 490 | postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 491 | } |
| 492 | postedTimesNanoSrc[i] = postedTimeNano; |
| 493 | |
| 494 | nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i]; |
| 495 | if (presentedTimeNano == INT64_MAX) { |
| 496 | presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 497 | } |
| 498 | presentedTimesNanoSrc[i] = presentedTimeNano; |
| 499 | |
| 500 | nsecs_t readyTimeNano = stats.frameReadyTimesNano[i]; |
| 501 | if (readyTimeNano == INT64_MAX) { |
| 502 | readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 503 | } |
| 504 | readyTimesNanoSrc[i] = readyTimeNano; |
| 505 | } |
| 506 | |
| 507 | env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc); |
| 508 | env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc); |
| 509 | env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc); |
| 510 | |
| 511 | env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano, |
| 512 | postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst); |
| 513 | |
| 514 | if (env->ExceptionCheck()) { |
| 515 | return JNI_FALSE; |
| 516 | } |
| 517 | |
| 518 | return JNI_TRUE; |
| 519 | } |
| 520 | |
| 521 | static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) { |
| 522 | status_t err = SurfaceComposerClient::clearAnimationFrameStats(); |
| 523 | |
| 524 | if (err < 0 && err != NO_INIT) { |
| 525 | doThrowIAE(env); |
| 526 | } |
| 527 | |
| 528 | // The other end is not ready, just report we failed. |
| 529 | if (err == NO_INIT) { |
| 530 | return JNI_FALSE; |
| 531 | } |
| 532 | |
| 533 | return JNI_TRUE; |
| 534 | } |
| 535 | |
| 536 | static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) { |
| 537 | FrameStats stats; |
| 538 | |
| 539 | status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats); |
| 540 | if (err < 0 && err != NO_INIT) { |
| 541 | doThrowIAE(env); |
| 542 | } |
| 543 | |
| 544 | // The other end is not ready, fine just return empty stats. |
| 545 | if (err == NO_INIT) { |
| 546 | return JNI_FALSE; |
| 547 | } |
| 548 | |
| 549 | jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano); |
| 550 | size_t frameCount = stats.desiredPresentTimesNano.size(); |
| 551 | |
| 552 | jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount); |
| 553 | if (presentedTimesNanoDst == NULL) { |
| 554 | return JNI_FALSE; |
| 555 | } |
| 556 | |
| 557 | nsecs_t presentedTimesNanoSrc[frameCount]; |
| 558 | |
| 559 | for (size_t i = 0; i < frameCount; i++) { |
Allen Hair | ac5eda3 | 2014-04-24 11:50:37 -0700 | [diff] [blame] | 560 | nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i]; |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 561 | if (presentedTimeNano == INT64_MAX) { |
| 562 | presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO; |
| 563 | } |
| 564 | presentedTimesNanoSrc[i] = presentedTimeNano; |
| 565 | } |
| 566 | |
| 567 | env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc); |
| 568 | |
| 569 | env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano, |
| 570 | presentedTimesNanoDst); |
| 571 | |
| 572 | if (env->ExceptionCheck()) { |
| 573 | return JNI_FALSE; |
| 574 | } |
| 575 | |
| 576 | return JNI_TRUE; |
| 577 | } |
| 578 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 579 | // ---------------------------------------------------------------------------- |
| 580 | |
| 581 | static JNINativeMethod sSurfaceControlMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 582 | {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIII)J", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 583 | (void*)nativeCreate }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 584 | {"nativeRelease", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 585 | (void*)nativeRelease }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 586 | {"nativeDestroy", "(J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 587 | (void*)nativeDestroy }, |
Riley Andrews | 1d13406 | 2014-08-21 15:47:07 -0700 | [diff] [blame^] | 588 | {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;", |
Mathias Agopian | 0449a40 | 2013-03-01 23:01:51 -0800 | [diff] [blame] | 589 | (void*)nativeScreenshotBitmap }, |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 590 | {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 591 | (void*)nativeScreenshot }, |
| 592 | {"nativeOpenTransaction", "()V", |
| 593 | (void*)nativeOpenTransaction }, |
| 594 | {"nativeCloseTransaction", "()V", |
| 595 | (void*)nativeCloseTransaction }, |
| 596 | {"nativeSetAnimationTransaction", "()V", |
| 597 | (void*)nativeSetAnimationTransaction }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 598 | {"nativeSetLayer", "(JI)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 599 | (void*)nativeSetLayer }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 600 | {"nativeSetPosition", "(JFF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 601 | (void*)nativeSetPosition }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 602 | {"nativeSetSize", "(JII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 603 | (void*)nativeSetSize }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 604 | {"nativeSetTransparentRegionHint", "(JLandroid/graphics/Region;)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 605 | (void*)nativeSetTransparentRegionHint }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 606 | {"nativeSetAlpha", "(JF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 607 | (void*)nativeSetAlpha }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 608 | {"nativeSetMatrix", "(JFFFF)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 609 | (void*)nativeSetMatrix }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 610 | {"nativeSetFlags", "(JII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 611 | (void*)nativeSetFlags }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 612 | {"nativeSetWindowCrop", "(JIIII)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 613 | (void*)nativeSetWindowCrop }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 614 | {"nativeSetLayerStack", "(JI)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 615 | (void*)nativeSetLayerStack }, |
| 616 | {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;", |
| 617 | (void*)nativeGetBuiltInDisplay }, |
| 618 | {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;", |
| 619 | (void*)nativeCreateDisplay }, |
Jesse Hall | 6a6bc21 | 2013-08-08 12:15:03 -0700 | [diff] [blame] | 620 | {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V", |
| 621 | (void*)nativeDestroyDisplay }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 622 | {"nativeSetDisplaySurface", "(Landroid/os/IBinder;J)V", |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 623 | (void*)nativeSetDisplaySurface }, |
| 624 | {"nativeSetDisplayLayerStack", "(Landroid/os/IBinder;I)V", |
| 625 | (void*)nativeSetDisplayLayerStack }, |
| 626 | {"nativeSetDisplayProjection", "(Landroid/os/IBinder;IIIIIIIII)V", |
| 627 | (void*)nativeSetDisplayProjection }, |
Michael Wright | 01e840f | 2014-06-26 16:03:25 -0700 | [diff] [blame] | 628 | {"nativeSetDisplaySize", "(Landroid/os/IBinder;II)V", |
| 629 | (void*)nativeSetDisplaySize }, |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 630 | {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;", |
| 631 | (void*)nativeGetDisplayConfigs }, |
| 632 | {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I", |
| 633 | (void*)nativeGetActiveConfig }, |
| 634 | {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z", |
| 635 | (void*)nativeSetActiveConfig }, |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 636 | {"nativeClearContentFrameStats", "(J)Z", |
| 637 | (void*)nativeClearContentFrameStats }, |
| 638 | {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z", |
| 639 | (void*)nativeGetContentFrameStats }, |
| 640 | {"nativeClearAnimationFrameStats", "()Z", |
| 641 | (void*)nativeClearAnimationFrameStats }, |
| 642 | {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z", |
| 643 | (void*)nativeGetAnimationFrameStats }, |
Prashant Malani | c55929a | 2014-05-25 01:59:21 -0700 | [diff] [blame] | 644 | {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V", |
| 645 | (void*)nativeSetDisplayPowerMode }, |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 646 | }; |
| 647 | |
| 648 | int register_android_view_SurfaceControl(JNIEnv* env) |
| 649 | { |
| 650 | int err = AndroidRuntime::registerNativeMethods(env, "android/view/SurfaceControl", |
| 651 | sSurfaceControlMethods, NELEM(sSurfaceControlMethods)); |
| 652 | |
| 653 | jclass clazz = env->FindClass("android/view/SurfaceControl$PhysicalDisplayInfo"); |
Dan Stoza | 0010105 | 2014-05-02 15:23:40 -0700 | [diff] [blame] | 654 | gPhysicalDisplayInfoClassInfo.clazz = static_cast<jclass>(env->NewGlobalRef(clazz)); |
| 655 | gPhysicalDisplayInfoClassInfo.ctor = env->GetMethodID(gPhysicalDisplayInfoClassInfo.clazz, |
| 656 | "<init>", "()V"); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 657 | gPhysicalDisplayInfoClassInfo.width = env->GetFieldID(clazz, "width", "I"); |
| 658 | gPhysicalDisplayInfoClassInfo.height = env->GetFieldID(clazz, "height", "I"); |
| 659 | gPhysicalDisplayInfoClassInfo.refreshRate = env->GetFieldID(clazz, "refreshRate", "F"); |
| 660 | gPhysicalDisplayInfoClassInfo.density = env->GetFieldID(clazz, "density", "F"); |
| 661 | gPhysicalDisplayInfoClassInfo.xDpi = env->GetFieldID(clazz, "xDpi", "F"); |
| 662 | gPhysicalDisplayInfoClassInfo.yDpi = env->GetFieldID(clazz, "yDpi", "F"); |
| 663 | gPhysicalDisplayInfoClassInfo.secure = env->GetFieldID(clazz, "secure", "Z"); |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 664 | gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = env->GetFieldID(clazz, |
| 665 | "appVsyncOffsetNanos", "J"); |
| 666 | gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = env->GetFieldID(clazz, |
| 667 | "presentationDeadlineNanos", "J"); |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 668 | |
Dan Stoza | 9890e341 | 2014-05-22 16:12:54 -0700 | [diff] [blame] | 669 | jclass rectClazz = env->FindClass("android/graphics/Rect"); |
| 670 | gRectClassInfo.bottom = env->GetFieldID(rectClazz, "bottom", "I"); |
| 671 | gRectClassInfo.left = env->GetFieldID(rectClazz, "left", "I"); |
| 672 | gRectClassInfo.right = env->GetFieldID(rectClazz, "right", "I"); |
| 673 | gRectClassInfo.top = env->GetFieldID(rectClazz, "top", "I"); |
| 674 | |
Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 675 | jclass frameStatsClazz = env->FindClass("android/view/FrameStats"); |
| 676 | jfieldID undefined_time_nano_field = env->GetStaticFieldID(frameStatsClazz, "UNDEFINED_TIME_NANO", "J"); |
| 677 | nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field); |
| 678 | |
| 679 | jclass contFrameStatsClazz = env->FindClass("android/view/WindowContentFrameStats"); |
| 680 | gWindowContentFrameStatsClassInfo.init = env->GetMethodID(contFrameStatsClazz, "init", "(J[J[J[J)V"); |
| 681 | gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; |
| 682 | |
| 683 | jclass animFrameStatsClazz = env->FindClass("android/view/WindowAnimationFrameStats"); |
| 684 | gWindowAnimationFrameStatsClassInfo.init = env->GetMethodID(animFrameStatsClazz, "init", "(J[J)V"); |
| 685 | gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; |
| 686 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 687 | return err; |
| 688 | } |
| 689 | |
| 690 | }; |