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