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