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