blob: 46da83ff0e83b8bdc9d5068e64133dcdf2e631bb [file] [log] [blame]
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001/*
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"
Robert Carr6486d312017-01-09 19:48:29 -080018#define LOG_NDEBUG 0
Mathias Agopian3866f0d2013-02-11 22:08:48 -080019
Mathias Agopian3866f0d2013-02-11 22:08:48 -080020#include "android_os_Parcel.h"
21#include "android_util_Binder.h"
John Reckf29ed282015-04-07 07:32:03 -070022#include "android/graphics/Bitmap.h"
Mathias Agopian3866f0d2013-02-11 22:08:48 -080023#include "android/graphics/GraphicsJNI.h"
24#include "android/graphics/Region.h"
Andreas Gampeed6b9df2014-11-20 22:02:20 -080025#include "core_jni_helpers.h"
Ben Wagner60126ef2015-08-07 12:13:48 -040026
27#include <JNIHelp.h>
28#include <ScopedUtfChars.h>
Mathias Agopian0449a402013-03-01 23:01:51 -080029#include <android_runtime/android_view_Surface.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080030#include <android_runtime/android_view_SurfaceSession.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080031#include <gui/Surface.h>
32#include <gui/SurfaceComposerClient.h>
Ben Wagner60126ef2015-08-07 12:13:48 -040033#include <jni.h>
34#include <memory>
35#include <stdio.h>
Michael Wright1c9977b2016-07-12 13:30:10 -070036#include <system/graphics.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080037#include <ui/DisplayInfo.h>
Hangyu Kuang54ac2192016-04-25 13:22:02 -070038#include <ui/HdrCapabilities.h>
Svetoslav1376d602014-03-13 11:17:26 -070039#include <ui/FrameStats.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080040#include <ui/Rect.h>
41#include <ui/Region.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080042#include <utils/Log.h>
43
Mathias Agopian3866f0d2013-02-11 22:08:48 -080044// ----------------------------------------------------------------------------
45
46namespace android {
47
48static const char* const OutOfResourcesException =
49 "android/view/Surface$OutOfResourcesException";
50
51static struct {
Dan Stoza00101052014-05-02 15:23:40 -070052 jclass clazz;
53 jmethodID ctor;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080054 jfieldID width;
55 jfieldID height;
56 jfieldID refreshRate;
57 jfieldID density;
58 jfieldID xDpi;
59 jfieldID yDpi;
60 jfieldID secure;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -070061 jfieldID appVsyncOffsetNanos;
62 jfieldID presentationDeadlineNanos;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080063} gPhysicalDisplayInfoClassInfo;
64
Dan Stoza9890e3412014-05-22 16:12:54 -070065static struct {
66 jfieldID bottom;
67 jfieldID left;
68 jfieldID right;
69 jfieldID top;
70} gRectClassInfo;
71
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050072// Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref.
73void DeleteScreenshot(void* addr, void* context) {
74 SkASSERT(addr == ((ScreenshotClient*) context)->getPixels());
75 delete ((ScreenshotClient*) context);
76}
Mathias Agopian3866f0d2013-02-11 22:08:48 -080077
Svetoslav1376d602014-03-13 11:17:26 -070078static struct {
79 nsecs_t UNDEFINED_TIME_NANO;
80 jmethodID init;
81} gWindowContentFrameStatsClassInfo;
82
83static struct {
84 nsecs_t UNDEFINED_TIME_NANO;
85 jmethodID init;
86} gWindowAnimationFrameStatsClassInfo;
87
Hangyu Kuang54ac2192016-04-25 13:22:02 -070088static struct {
89 jclass clazz;
90 jmethodID ctor;
91} gHdrCapabilitiesClassInfo;
92
Robert Carr6486d312017-01-09 19:48:29 -080093static struct {
94 jclass clazz;
95 jmethodID builder;
96} gGraphicBufferClassInfo;
97
Mathias Agopian3866f0d2013-02-11 22:08:48 -080098// ----------------------------------------------------------------------------
99
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000100static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
Robert Carr838120c2016-11-01 18:31:12 -0700101 jstring nameStr, jint w, jint h, jint format, jint flags, jlong parentObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800102 ScopedUtfChars name(env, nameStr);
103 sp<SurfaceComposerClient> client(android_view_SurfaceSession_getClient(env, sessionObj));
Robert Carr838120c2016-11-01 18:31:12 -0700104 SurfaceControl *parent = reinterpret_cast<SurfaceControl*>(parentObject);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800105 sp<SurfaceControl> surface = client->createSurface(
Robert Carr838120c2016-11-01 18:31:12 -0700106 String8(name.c_str()), w, h, format, flags, parent);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800107 if (surface == NULL) {
108 jniThrowException(env, OutOfResourcesException, NULL);
109 return 0;
110 }
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800111 surface->incStrong((void *)nativeCreate);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000112 return reinterpret_cast<jlong>(surface.get());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800113}
114
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000115static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800116 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800117 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800118}
119
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000120static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800121 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
122 ctrl->clear();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800123 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800124}
125
Chong Zhang47e36a32016-02-29 16:44:33 -0800126static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
127 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
128 if (ctrl != NULL) {
129 ctrl->disconnect();
130 }
131}
132
Robert Carr6486d312017-01-09 19:48:29 -0800133static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
134 int left = env->GetIntField(rectObj, gRectClassInfo.left);
135 int top = env->GetIntField(rectObj, gRectClassInfo.top);
136 int right = env->GetIntField(rectObj, gRectClassInfo.right);
137 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
138 return Rect(left, top, right, bottom);
139}
140
141static jobject nativeScreenshotToBuffer(JNIEnv* env, jclass clazz,
142 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
143 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform,
144 int rotation) {
145 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
146 if (displayToken == NULL) {
147 return NULL;
148 }
149 Rect sourceCrop = rectFromObj(env, sourceCropObj);
150 if (allLayers) {
151 minLayer = 0;
152 maxLayer = -1;
153 }
154 sp<GraphicBuffer> buffer;
155 status_t res = ScreenshotClient::captureToBuffer(displayToken,
156 sourceCrop, width, height, minLayer, maxLayer, useIdentityTransform,
157 rotation, &buffer);
158 if (res != NO_ERROR) {
159 return NULL;
160 }
161
162 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
163 gGraphicBufferClassInfo.builder,
164 buffer->getWidth(),
165 buffer->getHeight(),
166 buffer->getPixelFormat(),
167 buffer->getUsage(),
168 (void*)buffer.get());
169}
170
Dan Stoza9890e3412014-05-22 16:12:54 -0700171static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz,
172 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
Riley Andrews1d134062014-08-21 15:47:07 -0700173 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform,
174 int rotation) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800175 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
176 if (displayToken == NULL) {
177 return NULL;
178 }
179
Robert Carr6486d312017-01-09 19:48:29 -0800180 Rect sourceCrop = rectFromObj(env, sourceCropObj);
Dan Stoza9890e3412014-05-22 16:12:54 -0700181
Ben Wagner60126ef2015-08-07 12:13:48 -0400182 std::unique_ptr<ScreenshotClient> screenshot(new ScreenshotClient());
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500183 status_t res;
Riley Andrews1d134062014-08-21 15:47:07 -0700184 if (allLayers) {
185 minLayer = 0;
Andreas Gampe0f0b4912014-11-12 08:03:48 -0800186 maxLayer = -1;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500187 }
Riley Andrews1d134062014-08-21 15:47:07 -0700188
189 res = screenshot->update(displayToken, sourceCrop, width, height,
190 minLayer, maxLayer, useIdentityTransform, static_cast<uint32_t>(rotation));
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500191 if (res != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800192 return NULL;
193 }
194
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400195 SkColorType colorType;
196 SkAlphaType alphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500197 switch (screenshot->getFormat()) {
198 case PIXEL_FORMAT_RGBX_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400199 colorType = kRGBA_8888_SkColorType;
200 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500201 break;
202 }
203 case PIXEL_FORMAT_RGBA_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400204 colorType = kRGBA_8888_SkColorType;
205 alphaType = kPremul_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500206 break;
207 }
Romain Guy9505a652016-12-14 09:43:50 -0800208 case PIXEL_FORMAT_RGBA_FP16: {
209 colorType = kRGBA_F16_SkColorType;
210 alphaType = kPremul_SkAlphaType;
211 break;
212 }
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500213 case PIXEL_FORMAT_RGB_565: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400214 colorType = kRGB_565_SkColorType;
215 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500216 break;
217 }
218 default: {
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500219 return NULL;
220 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800221 }
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400222 SkImageInfo screenshotInfo = SkImageInfo::Make(screenshot->getWidth(),
223 screenshot->getHeight(),
Romain Guy253f2c22016-09-28 17:34:42 -0700224 colorType,
225 alphaType,
226 GraphicsJNI::defaultColorSpace());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800227
John Reckf29ed282015-04-07 07:32:03 -0700228 const size_t rowBytes =
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500229 screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat());
230
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400231 if (!screenshotInfo.width() || !screenshotInfo.height()) {
John Reckf29ed282015-04-07 07:32:03 -0700232 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800233 }
234
sergeyvc1c54062016-10-19 18:47:26 -0700235 auto bitmap = new Bitmap(
John Reckf29ed282015-04-07 07:32:03 -0700236 (void*) screenshot->getPixels(), (void*) screenshot.get(), DeleteScreenshot,
237 screenshotInfo, rowBytes, nullptr);
Ben Wagner60126ef2015-08-07 12:13:48 -0400238 screenshot.release();
sergeyvc1c54062016-10-19 18:47:26 -0700239 bitmap->setImmutable();
240 return bitmap::createBitmap(env, bitmap,
241 android::bitmap::kBitmapCreateFlag_Premultiplied, NULL);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800242}
243
Dan Stoza9890e3412014-05-22 16:12:54 -0700244static void nativeScreenshot(JNIEnv* env, jclass clazz, jobject displayTokenObj,
245 jobject surfaceObj, jobject sourceCropObj, jint width, jint height,
246 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform) {
Mathias Agopian0449a402013-03-01 23:01:51 -0800247 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
248 if (displayToken != NULL) {
249 sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj);
250 if (consumer != NULL) {
Dan Stoza9890e3412014-05-22 16:12:54 -0700251 int left = env->GetIntField(sourceCropObj, gRectClassInfo.left);
252 int top = env->GetIntField(sourceCropObj, gRectClassInfo.top);
253 int right = env->GetIntField(sourceCropObj, gRectClassInfo.right);
254 int bottom = env->GetIntField(sourceCropObj, gRectClassInfo.bottom);
255 Rect sourceCrop(left, top, right, bottom);
256
Mathias Agopian0449a402013-03-01 23:01:51 -0800257 if (allLayers) {
258 minLayer = 0;
259 maxLayer = -1;
260 }
Dan Stoza9890e3412014-05-22 16:12:54 -0700261 ScreenshotClient::capture(displayToken,
262 consumer->getIGraphicBufferProducer(), sourceCrop,
Dan Stoza16ec12a2014-02-14 15:06:55 -0800263 width, height, uint32_t(minLayer), uint32_t(maxLayer),
264 useIdentityTransform);
Mathias Agopian0449a402013-03-01 23:01:51 -0800265 }
266 }
267}
268
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800269static void nativeOpenTransaction(JNIEnv* env, jclass clazz) {
270 SurfaceComposerClient::openGlobalTransaction();
271}
272
Robert Carre9953b12016-05-23 20:52:04 -0700273
274static void nativeCloseTransaction(JNIEnv* env, jclass clazz, jboolean sync) {
275 SurfaceComposerClient::closeGlobalTransaction(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800276}
277
278static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz) {
279 SurfaceComposerClient::setAnimationTransaction();
280}
281
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000282static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong nativeObject, jint zorder) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800283 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
284 status_t err = ctrl->setLayer(zorder);
285 if (err < 0 && err != NO_INIT) {
286 doThrowIAE(env);
287 }
288}
289
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000290static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat x, jfloat y) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800291 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
292 status_t err = ctrl->setPosition(x, y);
293 if (err < 0 && err != NO_INIT) {
294 doThrowIAE(env);
295 }
296}
297
Robert Carr6da3cc02016-06-16 15:17:07 -0700298static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carra9408d42016-06-03 13:28:48 -0700299 jlong nativeObject) {
300 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr6da3cc02016-06-16 15:17:07 -0700301 status_t err = ctrl->setGeometryAppliesWithResize();
Robert Carra9408d42016-06-03 13:28:48 -0700302 if (err < 0 && err != NO_INIT) {
303 doThrowIAE(env);
304 }
305}
306
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000307static void nativeSetSize(JNIEnv* env, jclass clazz, jlong nativeObject, jint w, jint h) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800308 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
309 status_t err = ctrl->setSize(w, h);
310 if (err < 0 && err != NO_INIT) {
311 doThrowIAE(env);
312 }
313}
314
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000315static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong nativeObject, jint flags, jint mask) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800316 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
317 status_t err = ctrl->setFlags(flags, mask);
318 if (err < 0 && err != NO_INIT) {
319 doThrowIAE(env);
320 }
321}
322
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000323static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800324 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
325 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
326 if (!region) {
327 doThrowIAE(env);
328 return;
329 }
330
331 const SkIRect& b(region->getBounds());
332 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
333 if (region->isComplex()) {
334 SkRegion::Iterator it(*region);
335 while (!it.done()) {
336 const SkIRect& r(it.rect());
337 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
338 it.next();
339 }
340 }
341
342 status_t err = ctrl->setTransparentRegionHint(reg);
343 if (err < 0 && err != NO_INIT) {
344 doThrowIAE(env);
345 }
346}
347
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000348static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat alpha) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800349 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
350 status_t err = ctrl->setAlpha(alpha);
351 if (err < 0 && err != NO_INIT) {
352 doThrowIAE(env);
353 }
354}
355
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000356static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800357 jfloat dsdx, jfloat dtdx, jfloat dsdy, jfloat dtdy) {
358 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
359 status_t err = ctrl->setMatrix(dsdx, dtdx, dsdy, dtdy);
360 if (err < 0 && err != NO_INIT) {
361 doThrowIAE(env);
362 }
363}
364
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000365static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800366 jint l, jint t, jint r, jint b) {
367 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
368 Rect crop(l, t, r, b);
369 status_t err = ctrl->setCrop(crop);
370 if (err < 0 && err != NO_INIT) {
371 doThrowIAE(env);
372 }
373}
374
Pablo Ceballos27982e62016-03-09 10:50:45 -0800375static void nativeSetFinalCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
376 jint l, jint t, jint r, jint b) {
377 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
378 Rect crop(l, t, r, b);
379 status_t err = ctrl->setFinalCrop(crop);
380 if (err < 0 && err != NO_INIT) {
381 doThrowIAE(env);
382 }
383}
384
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000385static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong nativeObject, jint layerStack) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800386 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
387 status_t err = ctrl->setLayerStack(layerStack);
388 if (err < 0 && err != NO_INIT) {
389 doThrowIAE(env);
390 }
391}
392
393static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) {
394 sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id));
395 return javaObjectForIBinder(env, token);
396}
397
398static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
399 jboolean secure) {
400 ScopedUtfChars name(env, nameObj);
401 sp<IBinder> token(SurfaceComposerClient::createDisplay(
402 String8(name.c_str()), bool(secure)));
403 return javaObjectForIBinder(env, token);
404}
405
Jesse Hall6a6bc212013-08-08 12:15:03 -0700406static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
407 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
408 if (token == NULL) return;
409 SurfaceComposerClient::destroyDisplay(token);
410}
411
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800412static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000413 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800414 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
415 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800416 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800417 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800418 if (sur != NULL) {
419 bufferProducer = sur->getIGraphicBufferProducer();
420 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700421 status_t err = SurfaceComposerClient::setDisplaySurface(token,
422 bufferProducer);
423 if (err != NO_ERROR) {
424 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
425 " Surface created with singleBufferMode?");
426 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800427}
428
429static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
430 jobject tokenObj, jint layerStack) {
431 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
432 if (token == NULL) return;
433
434 SurfaceComposerClient::setDisplayLayerStack(token, layerStack);
435}
436
437static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
438 jobject tokenObj, jint orientation,
439 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
440 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
441 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
442 if (token == NULL) return;
443 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
444 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
445 SurfaceComposerClient::setDisplayProjection(token, orientation, layerStackRect, displayRect);
446}
447
Michael Wright01e840f2014-06-26 16:03:25 -0700448static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
449 jobject tokenObj, jint width, jint height) {
450 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
451 if (token == NULL) return;
452 SurfaceComposerClient::setDisplaySize(token, width, height);
453}
454
Dan Stoza00101052014-05-02 15:23:40 -0700455static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
456 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800457 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700458 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800459
Dan Stoza00101052014-05-02 15:23:40 -0700460 Vector<DisplayInfo> configs;
461 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
462 configs.size() == 0) {
463 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800464 }
465
Dan Stoza00101052014-05-02 15:23:40 -0700466 jobjectArray configArray = env->NewObjectArray(configs.size(),
467 gPhysicalDisplayInfoClassInfo.clazz, NULL);
468
469 for (size_t c = 0; c < configs.size(); ++c) {
470 const DisplayInfo& info = configs[c];
471 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
472 gPhysicalDisplayInfoClassInfo.ctor);
473 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
474 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
475 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
476 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
477 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
478 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
479 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700480 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
481 info.appVsyncOffset);
482 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
483 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700484 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
485 env->DeleteLocalRef(infoObj);
486 }
487
488 return configArray;
489}
490
491static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
492 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
493 if (token == NULL) return -1;
494 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
495}
496
497static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
498 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
499 if (token == NULL) return JNI_FALSE;
500 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
501 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800502}
503
Michael Wright1c9977b2016-07-12 13:30:10 -0700504static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
505 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
506 if (token == NULL) return NULL;
507 Vector<android_color_mode_t> colorModes;
508 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
509 colorModes.isEmpty()) {
510 return NULL;
511 }
512
513 jintArray colorModesArray = env->NewIntArray(colorModes.size());
514 if (colorModesArray == NULL) {
515 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
516 return NULL;
517 }
518 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
519 for (size_t i = 0; i < colorModes.size(); i++) {
520 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
521 }
522 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
523 return colorModesArray;
524}
525
526static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
527 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
528 if (token == NULL) return -1;
529 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
530}
531
532static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
533 jobject tokenObj, jint colorMode) {
534 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
535 if (token == NULL) return JNI_FALSE;
536 status_t err = SurfaceComposerClient::setActiveColorMode(token,
537 static_cast<android_color_mode_t>(colorMode));
538 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
539}
540
Prashant Malanic55929a2014-05-25 01:59:21 -0700541static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800542 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
543 if (token == NULL) return;
544
Prashant Malanic55929a2014-05-25 01:59:21 -0700545 ALOGD_IF_SLOW(100, "Excessive delay in setPowerMode()");
546 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800547}
548
Svetoslav1376d602014-03-13 11:17:26 -0700549static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
550 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
551 status_t err = ctrl->clearLayerFrameStats();
552
553 if (err < 0 && err != NO_INIT) {
554 doThrowIAE(env);
555 }
556
557 // The other end is not ready, just report we failed.
558 if (err == NO_INIT) {
559 return JNI_FALSE;
560 }
561
562 return JNI_TRUE;
563}
564
565static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
566 jobject outStats) {
567 FrameStats stats;
568
569 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
570 status_t err = ctrl->getLayerFrameStats(&stats);
571 if (err < 0 && err != NO_INIT) {
572 doThrowIAE(env);
573 }
574
575 // The other end is not ready, fine just return empty stats.
576 if (err == NO_INIT) {
577 return JNI_FALSE;
578 }
579
580 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
581 size_t frameCount = stats.desiredPresentTimesNano.size();
582
583 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
584 if (postedTimesNanoDst == NULL) {
585 return JNI_FALSE;
586 }
587
588 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
589 if (presentedTimesNanoDst == NULL) {
590 return JNI_FALSE;
591 }
592
593 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
594 if (readyTimesNanoDst == NULL) {
595 return JNI_FALSE;
596 }
597
598 nsecs_t postedTimesNanoSrc[frameCount];
599 nsecs_t presentedTimesNanoSrc[frameCount];
600 nsecs_t readyTimesNanoSrc[frameCount];
601
602 for (size_t i = 0; i < frameCount; i++) {
603 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
604 if (postedTimeNano == INT64_MAX) {
605 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
606 }
607 postedTimesNanoSrc[i] = postedTimeNano;
608
609 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
610 if (presentedTimeNano == INT64_MAX) {
611 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
612 }
613 presentedTimesNanoSrc[i] = presentedTimeNano;
614
615 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
616 if (readyTimeNano == INT64_MAX) {
617 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
618 }
619 readyTimesNanoSrc[i] = readyTimeNano;
620 }
621
622 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
623 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
624 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
625
626 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
627 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
628
629 if (env->ExceptionCheck()) {
630 return JNI_FALSE;
631 }
632
633 return JNI_TRUE;
634}
635
636static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
637 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
638
639 if (err < 0 && err != NO_INIT) {
640 doThrowIAE(env);
641 }
642
643 // The other end is not ready, just report we failed.
644 if (err == NO_INIT) {
645 return JNI_FALSE;
646 }
647
648 return JNI_TRUE;
649}
650
651static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
652 FrameStats stats;
653
654 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
655 if (err < 0 && err != NO_INIT) {
656 doThrowIAE(env);
657 }
658
659 // The other end is not ready, fine just return empty stats.
660 if (err == NO_INIT) {
661 return JNI_FALSE;
662 }
663
664 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
665 size_t frameCount = stats.desiredPresentTimesNano.size();
666
667 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
668 if (presentedTimesNanoDst == NULL) {
669 return JNI_FALSE;
670 }
671
672 nsecs_t presentedTimesNanoSrc[frameCount];
673
674 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700675 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700676 if (presentedTimeNano == INT64_MAX) {
677 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
678 }
679 presentedTimesNanoSrc[i] = presentedTimeNano;
680 }
681
682 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
683
684 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
685 presentedTimesNanoDst);
686
687 if (env->ExceptionCheck()) {
688 return JNI_FALSE;
689 }
690
691 return JNI_TRUE;
692}
693
Rob Carr64e516f2015-10-29 00:20:45 +0000694
695static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong nativeObject,
696 jobject handleObject, jlong frameNumber) {
697 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
698 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
699
700 ctrl->deferTransactionUntil(handle, frameNumber);
701}
702
Robert Carr1ca6a332016-04-11 18:00:43 -0700703static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong nativeObject,
704 jint scalingMode) {
705 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
706
707 ctrl->setOverrideScalingMode(scalingMode);
708}
709
Rob Carr64e516f2015-10-29 00:20:45 +0000710static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
711 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
712
713 return javaObjectForIBinder(env, ctrl->getHandle());
714}
715
Robert Carr6da3cc02016-06-16 15:17:07 -0700716static jboolean nativeGetTransformToDisplayInverse(JNIEnv* env, jclass clazz, jlong nativeObject) {
717 bool out = false;
718 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
719 status_t status = ctrl->getTransformToDisplayInverse(&out);
720 if (status != NO_ERROR) {
721 return false;
722 }
723 return out;
724}
725
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700726static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
727 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
728 if (token == NULL) return NULL;
729
730 HdrCapabilities capabilities;
731 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
732
733 const auto& types = capabilities.getSupportedHdrTypes();
734 auto typesArray = env->NewIntArray(types.size());
735 env->SetIntArrayRegion(typesArray, 0, types.size(), types.data());
736
Michael Wright9ff94c02016-03-30 18:05:40 -0700737 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700738 typesArray, capabilities.getDesiredMaxLuminance(),
739 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
740}
741
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800742// ----------------------------------------------------------------------------
743
Daniel Micay76f6a862015-09-19 17:31:01 -0400744static const JNINativeMethod sSurfaceControlMethods[] = {
Robert Carr838120c2016-11-01 18:31:12 -0700745 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJ)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800746 (void*)nativeCreate },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000747 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800748 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000749 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800750 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -0800751 {"nativeDisconnect", "(J)V",
752 (void*)nativeDisconnect },
Riley Andrews1d134062014-08-21 15:47:07 -0700753 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;",
Mathias Agopian0449a402013-03-01 23:01:51 -0800754 (void*)nativeScreenshotBitmap },
Dan Stoza9890e3412014-05-22 16:12:54 -0700755 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800756 (void*)nativeScreenshot },
757 {"nativeOpenTransaction", "()V",
758 (void*)nativeOpenTransaction },
Robert Carre9953b12016-05-23 20:52:04 -0700759 {"nativeCloseTransaction", "(Z)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800760 (void*)nativeCloseTransaction },
761 {"nativeSetAnimationTransaction", "()V",
762 (void*)nativeSetAnimationTransaction },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000763 {"nativeSetLayer", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800764 (void*)nativeSetLayer },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000765 {"nativeSetPosition", "(JFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800766 (void*)nativeSetPosition },
Robert Carr6da3cc02016-06-16 15:17:07 -0700767 {"nativeSetGeometryAppliesWithResize", "(J)V",
768 (void*)nativeSetGeometryAppliesWithResize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000769 {"nativeSetSize", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800770 (void*)nativeSetSize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000771 {"nativeSetTransparentRegionHint", "(JLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800772 (void*)nativeSetTransparentRegionHint },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000773 {"nativeSetAlpha", "(JF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800774 (void*)nativeSetAlpha },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000775 {"nativeSetMatrix", "(JFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800776 (void*)nativeSetMatrix },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000777 {"nativeSetFlags", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800778 (void*)nativeSetFlags },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000779 {"nativeSetWindowCrop", "(JIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800780 (void*)nativeSetWindowCrop },
Pablo Ceballos27982e62016-03-09 10:50:45 -0800781 {"nativeSetFinalCrop", "(JIIII)V",
782 (void*)nativeSetFinalCrop },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000783 {"nativeSetLayerStack", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800784 (void*)nativeSetLayerStack },
785 {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
786 (void*)nativeGetBuiltInDisplay },
787 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
788 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -0700789 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
790 (void*)nativeDestroyDisplay },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000791 {"nativeSetDisplaySurface", "(Landroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800792 (void*)nativeSetDisplaySurface },
793 {"nativeSetDisplayLayerStack", "(Landroid/os/IBinder;I)V",
794 (void*)nativeSetDisplayLayerStack },
795 {"nativeSetDisplayProjection", "(Landroid/os/IBinder;IIIIIIIII)V",
796 (void*)nativeSetDisplayProjection },
Michael Wright01e840f2014-06-26 16:03:25 -0700797 {"nativeSetDisplaySize", "(Landroid/os/IBinder;II)V",
798 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -0700799 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
800 (void*)nativeGetDisplayConfigs },
801 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
802 (void*)nativeGetActiveConfig },
803 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
804 (void*)nativeSetActiveConfig },
Michael Wright1c9977b2016-07-12 13:30:10 -0700805 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
806 (void*)nativeGetDisplayColorModes},
807 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
808 (void*)nativeGetActiveColorMode},
809 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
810 (void*)nativeSetActiveColorMode},
Michael Wright9ff94c02016-03-30 18:05:40 -0700811 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
812 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -0700813 {"nativeClearContentFrameStats", "(J)Z",
814 (void*)nativeClearContentFrameStats },
815 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
816 (void*)nativeGetContentFrameStats },
817 {"nativeClearAnimationFrameStats", "()Z",
818 (void*)nativeClearAnimationFrameStats },
819 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
820 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -0700821 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
822 (void*)nativeSetDisplayPowerMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000823 {"nativeDeferTransactionUntil", "(JLandroid/os/IBinder;J)V",
824 (void*)nativeDeferTransactionUntil },
Robert Carr1ca6a332016-04-11 18:00:43 -0700825 {"nativeSetOverrideScalingMode", "(JI)V",
826 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000827 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -0700828 (void*)nativeGetHandle },
829 {"nativeGetTransformToDisplayInverse", "(J)Z",
Robert Carr6486d312017-01-09 19:48:29 -0800830 (void*)nativeGetTransformToDisplayInverse },
831 {"nativeScreenshotToBuffer",
832 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/GraphicBuffer;",
833 (void*)nativeScreenshotToBuffer },
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800834};
835
836int register_android_view_SurfaceControl(JNIEnv* env)
837{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800838 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800839 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
840
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800841 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
842 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
843 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
844 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
845 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
846 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
847 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
848 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
849 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
850 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
851 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
852 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
853 clazz, "appVsyncOffsetNanos", "J");
854 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
855 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700856
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800857 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
858 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
859 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
860 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
861 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -0700862
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800863 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
864 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
865 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700866 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
867
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800868 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
869 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
870 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700871 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
872
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800873 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
874 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
875 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700876 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
877
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700878 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
879 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
880 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
881 "([IFFF)V");
882
Robert Carr6486d312017-01-09 19:48:29 -0800883 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
884 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
885 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
886 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
887
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800888 return err;
889}
890
891};