blob: 7e0f497ad50155ef958a0ac8dee6ac0f6191378b [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"
Robert Carr788f5742018-07-30 17:46:45 -070022#include "android_hardware_input_InputWindowHandle.h"
John Reckf29ed282015-04-07 07:32:03 -070023#include "android/graphics/Bitmap.h"
Mathias Agopian3866f0d2013-02-11 22:08:48 -080024#include "android/graphics/GraphicsJNI.h"
25#include "android/graphics/Region.h"
Andreas Gampeed6b9df2014-11-20 22:02:20 -080026#include "core_jni_helpers.h"
Ben Wagner60126ef2015-08-07 12:13:48 -040027
Tom Cherry8ed74bb2017-07-10 14:31:18 -070028#include <android-base/chrono_utils.h>
Steven Moreland2279b252017-07-19 09:50:45 -070029#include <nativehelper/JNIHelp.h>
30#include <nativehelper/ScopedUtfChars.h>
Mathias Agopian0449a402013-03-01 23:01:51 -080031#include <android_runtime/android_view_Surface.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080032#include <android_runtime/android_view_SurfaceSession.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080033#include <gui/Surface.h>
34#include <gui/SurfaceComposerClient.h>
Ben Wagner60126ef2015-08-07 12:13:48 -040035#include <jni.h>
36#include <memory>
37#include <stdio.h>
Michael Wright1c9977b2016-07-12 13:30:10 -070038#include <system/graphics.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080039#include <ui/DisplayInfo.h>
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -070040#include <ui/DisplayedFrameStats.h>
Svetoslav1376d602014-03-13 11:17:26 -070041#include <ui/FrameStats.h>
Peiyong Linb88549e2018-03-28 12:03:45 -070042#include <ui/GraphicTypes.h>
Peiyong Lin371b98f2018-03-14 17:29:10 -070043#include <ui/HdrCapabilities.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080044#include <ui/Rect.h>
45#include <ui/Region.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080046#include <utils/Log.h>
47
Mathias Agopian3866f0d2013-02-11 22:08:48 -080048// ----------------------------------------------------------------------------
49
50namespace android {
51
52static const char* const OutOfResourcesException =
53 "android/view/Surface$OutOfResourcesException";
54
55static struct {
Dan Stoza00101052014-05-02 15:23:40 -070056 jclass clazz;
57 jmethodID ctor;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080058 jfieldID width;
59 jfieldID height;
60 jfieldID refreshRate;
61 jfieldID density;
62 jfieldID xDpi;
63 jfieldID yDpi;
64 jfieldID secure;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -070065 jfieldID appVsyncOffsetNanos;
66 jfieldID presentationDeadlineNanos;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080067} gPhysicalDisplayInfoClassInfo;
68
Dan Stoza9890e3412014-05-22 16:12:54 -070069static struct {
70 jfieldID bottom;
71 jfieldID left;
72 jfieldID right;
73 jfieldID top;
74} gRectClassInfo;
75
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050076// Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref.
77void DeleteScreenshot(void* addr, void* context) {
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050078 delete ((ScreenshotClient*) context);
79}
Mathias Agopian3866f0d2013-02-11 22:08:48 -080080
Svetoslav1376d602014-03-13 11:17:26 -070081static struct {
82 nsecs_t UNDEFINED_TIME_NANO;
83 jmethodID init;
84} gWindowContentFrameStatsClassInfo;
85
86static struct {
87 nsecs_t UNDEFINED_TIME_NANO;
88 jmethodID init;
89} gWindowAnimationFrameStatsClassInfo;
90
Hangyu Kuang54ac2192016-04-25 13:22:02 -070091static struct {
92 jclass clazz;
93 jmethodID ctor;
94} gHdrCapabilitiesClassInfo;
95
Robert Carr6486d312017-01-09 19:48:29 -080096static struct {
97 jclass clazz;
98 jmethodID builder;
99} gGraphicBufferClassInfo;
100
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700101static struct {
102 jclass clazz;
103 jmethodID ctor;
104} gDisplayedContentSampleClassInfo;
105
106static struct {
107 jclass clazz;
108 jmethodID ctor;
109} gDisplayedContentSamplingAttributesClassInfo;
110
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800111// ----------------------------------------------------------------------------
112
Robert Carre13b58e2017-08-31 14:50:44 -0700113static jlong nativeCreateTransaction(JNIEnv* env, jclass clazz) {
114 return reinterpret_cast<jlong>(new SurfaceComposerClient::Transaction);
115}
116
117static void releaseTransaction(SurfaceComposerClient::Transaction* t) {
118 delete t;
119}
120
121static jlong nativeGetNativeTransactionFinalizer(JNIEnv* env, jclass clazz) {
122 return static_cast<jlong>(reinterpret_cast<uintptr_t>(&releaseTransaction));
123}
124
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000125static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500126 jstring nameStr, jint w, jint h, jint format, jint flags, jlong parentObject,
127 jint windowType, jint ownerUid) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800128 ScopedUtfChars name(env, nameStr);
129 sp<SurfaceComposerClient> client(android_view_SurfaceSession_getClient(env, sessionObj));
Robert Carr838120c2016-11-01 18:31:12 -0700130 SurfaceControl *parent = reinterpret_cast<SurfaceControl*>(parentObject);
Robert Carrb0f39362018-03-14 13:52:25 -0700131 sp<SurfaceControl> surface;
132 status_t err = client->createSurfaceChecked(
133 String8(name.c_str()), w, h, format, &surface, flags, parent, windowType, ownerUid);
134 if (err == NAME_NOT_FOUND) {
135 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
136 return 0;
137 } else if (err != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800138 jniThrowException(env, OutOfResourcesException, NULL);
139 return 0;
140 }
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500141
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800142 surface->incStrong((void *)nativeCreate);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000143 return reinterpret_cast<jlong>(surface.get());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800144}
145
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000146static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800147 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800148 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800149}
150
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000151static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800152 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
153 ctrl->clear();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800154 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800155}
156
Chong Zhang47e36a32016-02-29 16:44:33 -0800157static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
158 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
159 if (ctrl != NULL) {
160 ctrl->disconnect();
161 }
162}
163
Robert Carr6486d312017-01-09 19:48:29 -0800164static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
165 int left = env->GetIntField(rectObj, gRectClassInfo.left);
166 int top = env->GetIntField(rectObj, gRectClassInfo.top);
167 int right = env->GetIntField(rectObj, gRectClassInfo.right);
168 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
169 return Rect(left, top, right, bottom);
170}
171
chaviw08520a02018-09-10 16:44:56 -0700172static jobject nativeScreenshot(JNIEnv* env, jclass clazz,
Robert Carr6486d312017-01-09 19:48:29 -0800173 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
chaviw08520a02018-09-10 16:44:56 -0700174 bool useIdentityTransform, int rotation) {
Robert Carr6486d312017-01-09 19:48:29 -0800175 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
176 if (displayToken == NULL) {
177 return NULL;
178 }
179 Rect sourceCrop = rectFromObj(env, sourceCropObj);
Robert Carr6486d312017-01-09 19:48:29 -0800180 sp<GraphicBuffer> buffer;
Peiyong Lin10a34d12018-09-19 13:56:12 -0700181 status_t res = ScreenshotClient::capture(displayToken, ui::Dataspace::V0_SRGB,
182 ui::PixelFormat::RGBA_8888,
183 sourceCrop, width, height,
184 useIdentityTransform, rotation, &buffer);
Robert Carr6486d312017-01-09 19:48:29 -0800185 if (res != NO_ERROR) {
186 return NULL;
187 }
188
189 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
190 gGraphicBufferClassInfo.builder,
191 buffer->getWidth(),
192 buffer->getHeight(),
193 buffer->getPixelFormat(),
Mathias Agopian113fd302017-05-25 18:31:04 -0700194 (jint)buffer->getUsage(),
Patrik Torstensson511a8082017-03-27 15:04:11 +0100195 (jlong)buffer.get());
Robert Carr6486d312017-01-09 19:48:29 -0800196}
197
Chavi Weingartend7ec64c2017-11-30 01:52:01 +0000198static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject layerHandleToken,
chaviwfbe47df2017-11-10 16:14:49 -0800199 jobject sourceCropObj, jfloat frameScale) {
200
201 sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken);
202 if (layerHandle == NULL) {
203 return NULL;
204 }
205
206 Rect sourceCrop;
207 if (sourceCropObj != NULL) {
208 sourceCrop = rectFromObj(env, sourceCropObj);
209 }
210
211 sp<GraphicBuffer> buffer;
Peiyong Lin10a34d12018-09-19 13:56:12 -0700212 status_t res = ScreenshotClient::captureChildLayers(layerHandle, ui::Dataspace::V0_SRGB,
213 ui::PixelFormat::RGBA_8888, sourceCrop,
214 frameScale, &buffer);
chaviwfbe47df2017-11-10 16:14:49 -0800215 if (res != NO_ERROR) {
216 return NULL;
217 }
218
219 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
220 gGraphicBufferClassInfo.builder,
221 buffer->getWidth(),
222 buffer->getHeight(),
223 buffer->getPixelFormat(),
224 (jint)buffer->getUsage(),
225 (jlong)buffer.get());
chaviw1cda84c2017-10-23 16:47:10 -0700226}
227
Robert Carre13b58e2017-08-31 14:50:44 -0700228static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) {
229 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
230 transaction->apply(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800231}
232
Robert Carrb1579c82017-09-05 14:54:47 -0700233static void nativeMergeTransaction(JNIEnv* env, jclass clazz,
234 jlong transactionObj, jlong otherTransactionObj) {
235 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
236 auto otherTransaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(
237 otherTransactionObj);
238 transaction->merge(std::move(*otherTransaction));
239}
240
Robert Carre13b58e2017-08-31 14:50:44 -0700241static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) {
242 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
243 transaction->setAnimationTransaction();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800244}
245
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100246static void nativeSetEarlyWakeup(JNIEnv* env, jclass clazz, jlong transactionObj) {
247 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
248 transaction->setEarlyWakeup();
249}
250
Robert Carre13b58e2017-08-31 14:50:44 -0700251static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
252 jlong nativeObject, jint zorder) {
253 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800254
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800255 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700256 transaction->setLayer(ctrl, zorder);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800257}
258
Robert Carre13b58e2017-08-31 14:50:44 -0700259static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
260 jlong nativeObject,
Robert Carraf422a82017-04-10 18:34:33 -0700261 jobject relativeTo, jint zorder) {
Robert Carre13b58e2017-08-31 14:50:44 -0700262
Robert Carraf422a82017-04-10 18:34:33 -0700263 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
264 sp<IBinder> handle = ibinderForJavaObject(env, relativeTo);
265
Robert Carre13b58e2017-08-31 14:50:44 -0700266 {
267 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
268 transaction->setRelativeLayer(ctrl, handle, zorder);
269 }
Robert Carraf422a82017-04-10 18:34:33 -0700270}
271
Robert Carre13b58e2017-08-31 14:50:44 -0700272static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj,
273 jlong nativeObject, jfloat x, jfloat y) {
274 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
275
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800276 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700277 transaction->setPosition(ctrl, x, y);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800278}
279
Robert Carr6da3cc02016-06-16 15:17:07 -0700280static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700281jlong transactionObj,
Robert Carra9408d42016-06-03 13:28:48 -0700282 jlong nativeObject) {
Robert Carre13b58e2017-08-31 14:50:44 -0700283 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
284
Robert Carra9408d42016-06-03 13:28:48 -0700285 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700286 transaction->setGeometryAppliesWithResize(ctrl);
Robert Carra9408d42016-06-03 13:28:48 -0700287}
288
Robert Carre13b58e2017-08-31 14:50:44 -0700289static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj,
290 jlong nativeObject, jint w, jint h) {
291 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
292
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800293 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700294 transaction->setSize(ctrl, w, h);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800295}
296
Robert Carre13b58e2017-08-31 14:50:44 -0700297static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong transactionObj,
298 jlong nativeObject, jint flags, jint mask) {
299 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
300
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800301 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700302 transaction->setFlags(ctrl, flags, mask);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800303}
304
Robert Carre13b58e2017-08-31 14:50:44 -0700305static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong transactionObj,
306 jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800307 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
308 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
309 if (!region) {
310 doThrowIAE(env);
311 return;
312 }
313
314 const SkIRect& b(region->getBounds());
315 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
316 if (region->isComplex()) {
317 SkRegion::Iterator it(*region);
318 while (!it.done()) {
319 const SkIRect& r(it.rect());
320 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
321 it.next();
322 }
323 }
324
Robert Carre13b58e2017-08-31 14:50:44 -0700325 {
326 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
327 transaction->setTransparentRegionHint(ctrl, reg);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800328 }
329}
330
Robert Carre13b58e2017-08-31 14:50:44 -0700331static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj,
332 jlong nativeObject, jfloat alpha) {
333 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
334
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800335 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700336 transaction->setAlpha(ctrl, alpha);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800337}
338
Robert Carr788f5742018-07-30 17:46:45 -0700339static void nativeSetInputWindowInfo(JNIEnv* env, jclass clazz, jlong transactionObj,
340 jlong nativeObject, jobject inputWindow) {
341 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
342
343 sp<NativeInputWindowHandle> handle = android_server_InputWindowHandle_getHandle(
344 env, inputWindow);
345 handle->updateInfo();
346
347 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
348 transaction->setInputWindowInfo(ctrl, *handle->getInfo());
349}
350
chaviw59f532e2018-12-26 15:34:59 -0800351static void nativeTransferTouchFocus(JNIEnv* env, jclass clazz, jlong transactionObj,
352 jobject fromTokenObj, jobject toTokenObj) {
353 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
354
355 sp<IBinder> fromToken(ibinderForJavaObject(env, fromTokenObj));
356 sp<IBinder> toToken(ibinderForJavaObject(env, toTokenObj));
357 transaction->transferTouchFocus(fromToken, toToken);
358}
359
Robert Carre13b58e2017-08-31 14:50:44 -0700360static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj,
361 jlong nativeObject, jfloatArray fColor) {
362 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
chaviw0dd03f52017-08-25 12:15:26 -0700363 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700364
chaviw0dd03f52017-08-25 12:15:26 -0700365 float* floatColors = env->GetFloatArrayElements(fColor, 0);
366 half3 color(floatColors[0], floatColors[1], floatColors[2]);
Robert Carre13b58e2017-08-31 14:50:44 -0700367 transaction->setColor(ctrl, color);
chaviw0dd03f52017-08-25 12:15:26 -0700368}
369
Robert Carre13b58e2017-08-31 14:50:44 -0700370static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj,
371 jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800372 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Robert Carre13b58e2017-08-31 14:50:44 -0700373 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
374
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800375 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700376 transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800377}
378
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700379static void nativeSetColorTransform(JNIEnv* env, jclass clazz, jlong transactionObj,
380 jlong nativeObject, jfloatArray fMatrix, jfloatArray fTranslation) {
381 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
382 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
383 float* floatMatrix = env->GetFloatArrayElements(fMatrix, 0);
384 mat3 matrix(static_cast<float const*>(floatMatrix));
385 float* floatTranslation = env->GetFloatArrayElements(fTranslation, 0);
386 vec3 translation(floatTranslation[0], floatTranslation[1], floatTranslation[2]);
387 transaction->setColorTransform(surfaceControl, matrix, translation);
388}
389
Robert Carre13b58e2017-08-31 14:50:44 -0700390static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
391 jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800392 jint l, jint t, jint r, jint b) {
Robert Carre13b58e2017-08-31 14:50:44 -0700393 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
394
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800395 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
396 Rect crop(l, t, r, b);
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700397 transaction->setCrop_legacy(ctrl, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800398}
399
Lucas Dupinff9d6ab2018-10-16 18:05:50 -0700400static void nativeSetCornerRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
401 jlong nativeObject, jfloat cornerRadius) {
402 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
403
404 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
405 transaction->setCornerRadius(ctrl, cornerRadius);
406}
407
Robert Carre13b58e2017-08-31 14:50:44 -0700408static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj,
409 jlong nativeObject, jint layerStack) {
410 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
411
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800412 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700413 transaction->setLayerStack(ctrl, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800414}
415
416static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) {
417 sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id));
418 return javaObjectForIBinder(env, token);
419}
420
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700421static jobject nativeGetDisplayedContentSamplingAttributes(JNIEnv* env, jclass clazz,
422 jobject tokenObj) {
423 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
424
425 ui::PixelFormat format;
426 ui::Dataspace dataspace;
427 uint8_t componentMask;
428 status_t err = SurfaceComposerClient::getDisplayedContentSamplingAttributes(
429 token, &format, &dataspace, &componentMask);
430 if (err != OK) {
431 return nullptr;
432 }
433 return env->NewObject(gDisplayedContentSamplingAttributesClassInfo.clazz,
434 gDisplayedContentSamplingAttributesClassInfo.ctor,
435 format, dataspace, componentMask);
436}
437
438static jboolean nativeSetDisplayedContentSamplingEnabled(JNIEnv* env, jclass clazz,
439 jobject tokenObj, jboolean enable, jint componentMask, jint maxFrames) {
440 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Kevin DuBois205a6802019-01-07 17:04:46 -0800441 status_t rc = SurfaceComposerClient::setDisplayContentSamplingEnabled(
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700442 token, enable, componentMask, maxFrames);
Kevin DuBois205a6802019-01-07 17:04:46 -0800443 return rc == OK;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700444}
445
446static jobject nativeGetDisplayedContentSample(JNIEnv* env, jclass clazz, jobject tokenObj,
447 jlong maxFrames, jlong timestamp) {
448 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
449
450 DisplayedFrameStats stats;
451 status_t err = SurfaceComposerClient::getDisplayedContentSample(
452 token, maxFrames, timestamp, &stats);
453 if (err != OK) {
454 return nullptr;
455 }
456
457 jlongArray histogramComponent0 = env->NewLongArray(stats.component_0_sample.size());
458 jlongArray histogramComponent1 = env->NewLongArray(stats.component_1_sample.size());
459 jlongArray histogramComponent2 = env->NewLongArray(stats.component_2_sample.size());
460 jlongArray histogramComponent3 = env->NewLongArray(stats.component_3_sample.size());
461 if ((histogramComponent0 == nullptr) ||
462 (histogramComponent1 == nullptr) ||
463 (histogramComponent2 == nullptr) ||
464 (histogramComponent3 == nullptr)) {
465 return JNI_FALSE;
466 }
467
468 env->SetLongArrayRegion(histogramComponent0, 0,
469 stats.component_0_sample.size(),
470 reinterpret_cast<jlong*>(stats.component_0_sample.data()));
471 env->SetLongArrayRegion(histogramComponent1, 0,
472 stats.component_1_sample.size(),
473 reinterpret_cast<jlong*>(stats.component_1_sample.data()));
474 env->SetLongArrayRegion(histogramComponent2, 0,
475 stats.component_2_sample.size(),
476 reinterpret_cast<jlong*>(stats.component_2_sample.data()));
477 env->SetLongArrayRegion(histogramComponent3, 0,
478 stats.component_3_sample.size(),
479 reinterpret_cast<jlong*>(stats.component_3_sample.data()));
480 return env->NewObject(gDisplayedContentSampleClassInfo.clazz,
481 gDisplayedContentSampleClassInfo.ctor,
482 stats.numFrames,
483 histogramComponent0,
484 histogramComponent1,
485 histogramComponent2,
486 histogramComponent3);
487}
488
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800489static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
490 jboolean secure) {
491 ScopedUtfChars name(env, nameObj);
492 sp<IBinder> token(SurfaceComposerClient::createDisplay(
493 String8(name.c_str()), bool(secure)));
494 return javaObjectForIBinder(env, token);
495}
496
Jesse Hall6a6bc212013-08-08 12:15:03 -0700497static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
498 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
499 if (token == NULL) return;
500 SurfaceComposerClient::destroyDisplay(token);
501}
502
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800503static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700504 jlong transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000505 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800506 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
507 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800508 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800509 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800510 if (sur != NULL) {
511 bufferProducer = sur->getIGraphicBufferProducer();
512 }
Robert Carre13b58e2017-08-31 14:50:44 -0700513
514
515 status_t err = NO_ERROR;
516 {
517 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
518 err = transaction->setDisplaySurface(token,
519 bufferProducer);
520 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700521 if (err != NO_ERROR) {
522 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
523 " Surface created with singleBufferMode?");
524 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800525}
526
527static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700528 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800529 jobject tokenObj, jint layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -0700530
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800531 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
532 if (token == NULL) return;
533
Robert Carre13b58e2017-08-31 14:50:44 -0700534 {
535 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
536 transaction->setDisplayLayerStack(token, layerStack);
537 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800538}
539
540static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700541 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800542 jobject tokenObj, jint orientation,
543 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
544 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
545 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
546 if (token == NULL) return;
547 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
548 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
Robert Carre13b58e2017-08-31 14:50:44 -0700549
550 {
551 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
552 transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect);
553 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800554}
555
Michael Wright01e840f2014-06-26 16:03:25 -0700556static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700557 jlong transactionObj,
Michael Wright01e840f2014-06-26 16:03:25 -0700558 jobject tokenObj, jint width, jint height) {
559 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
560 if (token == NULL) return;
Robert Carre13b58e2017-08-31 14:50:44 -0700561
562 {
563 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
564 transaction->setDisplaySize(token, width, height);
565 }
Michael Wright01e840f2014-06-26 16:03:25 -0700566}
567
Dan Stoza00101052014-05-02 15:23:40 -0700568static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
569 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800570 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700571 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800572
Dan Stoza00101052014-05-02 15:23:40 -0700573 Vector<DisplayInfo> configs;
574 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
575 configs.size() == 0) {
576 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800577 }
578
Dan Stoza00101052014-05-02 15:23:40 -0700579 jobjectArray configArray = env->NewObjectArray(configs.size(),
580 gPhysicalDisplayInfoClassInfo.clazz, NULL);
581
582 for (size_t c = 0; c < configs.size(); ++c) {
583 const DisplayInfo& info = configs[c];
584 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
585 gPhysicalDisplayInfoClassInfo.ctor);
586 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
587 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
588 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
589 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
590 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
591 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
592 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700593 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
594 info.appVsyncOffset);
595 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
596 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700597 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
598 env->DeleteLocalRef(infoObj);
599 }
600
601 return configArray;
602}
603
604static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
605 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
606 if (token == NULL) return -1;
607 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
608}
609
610static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
611 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
612 if (token == NULL) return JNI_FALSE;
613 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
614 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800615}
616
Michael Wright1c9977b2016-07-12 13:30:10 -0700617static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
618 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
619 if (token == NULL) return NULL;
Peiyong Linb88549e2018-03-28 12:03:45 -0700620 Vector<ui::ColorMode> colorModes;
Michael Wright1c9977b2016-07-12 13:30:10 -0700621 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
622 colorModes.isEmpty()) {
623 return NULL;
624 }
625
626 jintArray colorModesArray = env->NewIntArray(colorModes.size());
627 if (colorModesArray == NULL) {
628 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
629 return NULL;
630 }
631 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
632 for (size_t i = 0; i < colorModes.size(); i++) {
633 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
634 }
635 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
636 return colorModesArray;
637}
638
639static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
640 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
641 if (token == NULL) return -1;
642 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
643}
644
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800645static jintArray nativeGetCompositionDataspaces(JNIEnv* env, jclass) {
646 ui::Dataspace defaultDataspace, wcgDataspace;
647 ui::PixelFormat defaultPixelFormat, wcgPixelFormat;
648 if (SurfaceComposerClient::getCompositionPreference(&defaultDataspace,
649 &defaultPixelFormat,
650 &wcgDataspace,
651 &wcgPixelFormat) != NO_ERROR) {
652 return nullptr;
653 }
654 jintArray array = env->NewIntArray(2);
655 if (array == nullptr) {
656 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
657 return nullptr;
658 }
659 jint* arrayValues = env->GetIntArrayElements(array, 0);
660 arrayValues[0] = static_cast<jint>(defaultDataspace);
661 arrayValues[1] = static_cast<jint>(wcgDataspace);
662 env->ReleaseIntArrayElements(array, arrayValues, 0);
663 return array;
664}
665
Michael Wright1c9977b2016-07-12 13:30:10 -0700666static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
667 jobject tokenObj, jint colorMode) {
668 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
669 if (token == NULL) return JNI_FALSE;
670 status_t err = SurfaceComposerClient::setActiveColorMode(token,
Peiyong Linb88549e2018-03-28 12:03:45 -0700671 static_cast<ui::ColorMode>(colorMode));
Michael Wright1c9977b2016-07-12 13:30:10 -0700672 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
673}
674
Prashant Malanic55929a2014-05-25 01:59:21 -0700675static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800676 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
677 if (token == NULL) return;
678
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700679 android::base::Timer t;
Prashant Malanic55929a2014-05-25 01:59:21 -0700680 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700681 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800682}
683
Peiyong Lin0ddb7d42019-01-16 13:25:09 -0800684static jboolean nativeGetProtectedContentSupport(JNIEnv* env, jclass) {
685 return static_cast<jboolean>(SurfaceComposerClient::getProtectedContentSupport());
686}
687
Svetoslav1376d602014-03-13 11:17:26 -0700688static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
689 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
690 status_t err = ctrl->clearLayerFrameStats();
691
692 if (err < 0 && err != NO_INIT) {
693 doThrowIAE(env);
694 }
695
696 // The other end is not ready, just report we failed.
697 if (err == NO_INIT) {
698 return JNI_FALSE;
699 }
700
701 return JNI_TRUE;
702}
703
704static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
705 jobject outStats) {
706 FrameStats stats;
707
708 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
709 status_t err = ctrl->getLayerFrameStats(&stats);
710 if (err < 0 && err != NO_INIT) {
711 doThrowIAE(env);
712 }
713
714 // The other end is not ready, fine just return empty stats.
715 if (err == NO_INIT) {
716 return JNI_FALSE;
717 }
718
719 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
720 size_t frameCount = stats.desiredPresentTimesNano.size();
721
722 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
723 if (postedTimesNanoDst == NULL) {
724 return JNI_FALSE;
725 }
726
727 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
728 if (presentedTimesNanoDst == NULL) {
729 return JNI_FALSE;
730 }
731
732 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
733 if (readyTimesNanoDst == NULL) {
734 return JNI_FALSE;
735 }
736
737 nsecs_t postedTimesNanoSrc[frameCount];
738 nsecs_t presentedTimesNanoSrc[frameCount];
739 nsecs_t readyTimesNanoSrc[frameCount];
740
741 for (size_t i = 0; i < frameCount; i++) {
742 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
743 if (postedTimeNano == INT64_MAX) {
744 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
745 }
746 postedTimesNanoSrc[i] = postedTimeNano;
747
748 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
749 if (presentedTimeNano == INT64_MAX) {
750 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
751 }
752 presentedTimesNanoSrc[i] = presentedTimeNano;
753
754 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
755 if (readyTimeNano == INT64_MAX) {
756 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
757 }
758 readyTimesNanoSrc[i] = readyTimeNano;
759 }
760
761 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
762 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
763 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
764
765 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
766 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
767
768 if (env->ExceptionCheck()) {
769 return JNI_FALSE;
770 }
771
772 return JNI_TRUE;
773}
774
775static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
776 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
777
778 if (err < 0 && err != NO_INIT) {
779 doThrowIAE(env);
780 }
781
782 // The other end is not ready, just report we failed.
783 if (err == NO_INIT) {
784 return JNI_FALSE;
785 }
786
787 return JNI_TRUE;
788}
789
790static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
791 FrameStats stats;
792
793 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
794 if (err < 0 && err != NO_INIT) {
795 doThrowIAE(env);
796 }
797
798 // The other end is not ready, fine just return empty stats.
799 if (err == NO_INIT) {
800 return JNI_FALSE;
801 }
802
803 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
804 size_t frameCount = stats.desiredPresentTimesNano.size();
805
806 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
807 if (presentedTimesNanoDst == NULL) {
808 return JNI_FALSE;
809 }
810
811 nsecs_t presentedTimesNanoSrc[frameCount];
812
813 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700814 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700815 if (presentedTimeNano == INT64_MAX) {
816 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
817 }
818 presentedTimesNanoSrc[i] = presentedTimeNano;
819 }
820
821 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
822
823 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
824 presentedTimesNanoDst);
825
826 if (env->ExceptionCheck()) {
827 return JNI_FALSE;
828 }
829
830 return JNI_TRUE;
831}
832
Robert Carre13b58e2017-08-31 14:50:44 -0700833static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj,
834 jlong nativeObject,
Rob Carr64e516f2015-10-29 00:20:45 +0000835 jobject handleObject, jlong frameNumber) {
836 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
837 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
838
Robert Carre13b58e2017-08-31 14:50:44 -0700839 {
840 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700841 transaction->deferTransactionUntil_legacy(ctrl, handle, frameNumber);
Robert Carre13b58e2017-08-31 14:50:44 -0700842 }
Rob Carr64e516f2015-10-29 00:20:45 +0000843}
844
Robert Carre13b58e2017-08-31 14:50:44 -0700845static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
846 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -0800847 jlong surfaceObject, jlong frameNumber) {
Robert Carre13b58e2017-08-31 14:50:44 -0700848 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
849
Robert Carrd5c7dd62017-03-08 10:39:30 -0800850 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
851 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
852
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700853 transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber);
Robert Carrd5c7dd62017-03-08 10:39:30 -0800854}
855
Robert Carre13b58e2017-08-31 14:50:44 -0700856static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
857 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -0800858 jobject newParentObject) {
Robert Carre13b58e2017-08-31 14:50:44 -0700859
Robert Carrd5c7dd62017-03-08 10:39:30 -0800860 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
861 sp<IBinder> handle = ibinderForJavaObject(env, newParentObject);
862
Robert Carre13b58e2017-08-31 14:50:44 -0700863 {
864 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
865 transaction->reparentChildren(ctrl, handle);
866 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800867}
868
Robert Carre13b58e2017-08-31 14:50:44 -0700869static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
870 jlong nativeObject,
Robert Carr10584fa2019-01-14 15:55:19 -0800871 jlong newParentObject) {
chaviw63542382017-08-17 17:39:29 -0700872 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr10584fa2019-01-14 15:55:19 -0800873 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700874
875 {
876 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr10584fa2019-01-14 15:55:19 -0800877 transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL);
Robert Carre13b58e2017-08-31 14:50:44 -0700878 }
chaviw63542382017-08-17 17:39:29 -0700879}
880
Robert Carre13b58e2017-08-31 14:50:44 -0700881static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
882 jlong nativeObject) {
883 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
884
Robert Carrd5c7dd62017-03-08 10:39:30 -0800885 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700886 transaction->detachChildren(ctrl);
Robert Carrd5c7dd62017-03-08 10:39:30 -0800887}
888
Robert Carre13b58e2017-08-31 14:50:44 -0700889static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj,
890 jlong nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -0700891 jint scalingMode) {
Robert Carre13b58e2017-08-31 14:50:44 -0700892 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr1ca6a332016-04-11 18:00:43 -0700893
Robert Carre13b58e2017-08-31 14:50:44 -0700894 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
895 transaction->setOverrideScalingMode(ctrl, scalingMode);
Robert Carr1ca6a332016-04-11 18:00:43 -0700896}
897
Rob Carr64e516f2015-10-29 00:20:45 +0000898static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
899 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Rob Carr64e516f2015-10-29 00:20:45 +0000900 return javaObjectForIBinder(env, ctrl->getHandle());
901}
902
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700903static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
904 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
905 if (token == NULL) return NULL;
906
907 HdrCapabilities capabilities;
908 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
909
910 const auto& types = capabilities.getSupportedHdrTypes();
Peiyong Lin3a0c6e12018-04-16 11:05:29 -0700911 std::vector<int32_t> intTypes;
912 for (auto type : types) {
913 intTypes.push_back(static_cast<int32_t>(type));
914 }
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700915 auto typesArray = env->NewIntArray(types.size());
Peiyong Lin3a0c6e12018-04-16 11:05:29 -0700916 env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data());
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700917
Michael Wright9ff94c02016-03-30 18:05:40 -0700918 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700919 typesArray, capabilities.getDesiredMaxLuminance(),
920 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
921}
922
Jorim Jaggi06975df2017-12-01 14:52:13 +0100923static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
924 Parcel* parcel = parcelForJavaObject(env, parcelObj);
925 if (parcel == NULL) {
926 doThrowNPE(env);
927 return 0;
928 }
929 sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel);
930 if (surface == nullptr) {
931 return 0;
932 }
933 surface->incStrong((void *)nativeCreate);
934 return reinterpret_cast<jlong>(surface.get());
935}
936
chaviwbeb7a0c2018-12-05 13:49:54 -0800937static jlong nativeCopyFromSurfaceControl(JNIEnv* env, jclass clazz, jlong surfaceControlNativeObj) {
938 sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj));
939 if (surface == nullptr) {
940 return 0;
941 }
Robert Carr5fea55b2018-12-10 13:05:52 -0800942
943 sp<SurfaceControl> newSurface = new SurfaceControl(surface);
944 newSurface->incStrong((void *)nativeCreate);
945 return reinterpret_cast<jlong>(newSurface.get());
chaviwbeb7a0c2018-12-05 13:49:54 -0800946}
947
Jorim Jaggi06975df2017-12-01 14:52:13 +0100948static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
949 jlong nativeObject, jobject parcelObj) {
950 Parcel* parcel = parcelForJavaObject(env, parcelObj);
951 if (parcel == NULL) {
952 doThrowNPE(env);
953 return;
954 }
955 SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject);
chaviwbeb7a0c2018-12-05 13:49:54 -0800956 if (self != nullptr) {
957 self->writeToParcel(parcel);
958 }
Jorim Jaggi06975df2017-12-01 14:52:13 +0100959}
960
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800961// ----------------------------------------------------------------------------
962
Daniel Micay76f6a862015-09-19 17:31:01 -0400963static const JNINativeMethod sSurfaceControlMethods[] = {
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500964 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJII)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800965 (void*)nativeCreate },
Jorim Jaggi06975df2017-12-01 14:52:13 +0100966 {"nativeReadFromParcel", "(Landroid/os/Parcel;)J",
967 (void*)nativeReadFromParcel },
chaviwbeb7a0c2018-12-05 13:49:54 -0800968 {"nativeCopyFromSurfaceControl", "(J)J" ,
969 (void*)nativeCopyFromSurfaceControl },
Jorim Jaggi06975df2017-12-01 14:52:13 +0100970 {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
971 (void*)nativeWriteToParcel },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000972 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800973 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000974 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800975 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -0800976 {"nativeDisconnect", "(J)V",
977 (void*)nativeDisconnect },
Robert Carre13b58e2017-08-31 14:50:44 -0700978 {"nativeCreateTransaction", "()J",
979 (void*)nativeCreateTransaction },
980 {"nativeApplyTransaction", "(JZ)V",
981 (void*)nativeApplyTransaction },
982 {"nativeGetNativeTransactionFinalizer", "()J",
983 (void*)nativeGetNativeTransactionFinalizer },
Robert Carrb1579c82017-09-05 14:54:47 -0700984 {"nativeMergeTransaction", "(JJ)V",
985 (void*)nativeMergeTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -0700986 {"nativeSetAnimationTransaction", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800987 (void*)nativeSetAnimationTransaction },
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100988 {"nativeSetEarlyWakeup", "(J)V",
989 (void*)nativeSetEarlyWakeup },
Robert Carre13b58e2017-08-31 14:50:44 -0700990 {"nativeSetLayer", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800991 (void*)nativeSetLayer },
Robert Carre13b58e2017-08-31 14:50:44 -0700992 {"nativeSetRelativeLayer", "(JJLandroid/os/IBinder;I)V",
Robert Carraf422a82017-04-10 18:34:33 -0700993 (void*)nativeSetRelativeLayer },
Robert Carre13b58e2017-08-31 14:50:44 -0700994 {"nativeSetPosition", "(JJFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800995 (void*)nativeSetPosition },
Robert Carre13b58e2017-08-31 14:50:44 -0700996 {"nativeSetGeometryAppliesWithResize", "(JJ)V",
Robert Carr6da3cc02016-06-16 15:17:07 -0700997 (void*)nativeSetGeometryAppliesWithResize },
Robert Carre13b58e2017-08-31 14:50:44 -0700998 {"nativeSetSize", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800999 (void*)nativeSetSize },
Robert Carre13b58e2017-08-31 14:50:44 -07001000 {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001001 (void*)nativeSetTransparentRegionHint },
Robert Carre13b58e2017-08-31 14:50:44 -07001002 {"nativeSetAlpha", "(JJF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001003 (void*)nativeSetAlpha },
Robert Carre13b58e2017-08-31 14:50:44 -07001004 {"nativeSetColor", "(JJ[F)V",
chaviw0dd03f52017-08-25 12:15:26 -07001005 (void*)nativeSetColor },
Robert Carre13b58e2017-08-31 14:50:44 -07001006 {"nativeSetMatrix", "(JJFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001007 (void*)nativeSetMatrix },
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001008 {"nativeSetColorTransform", "(JJ[F[F)V",
1009 (void*)nativeSetColorTransform },
Robert Carre13b58e2017-08-31 14:50:44 -07001010 {"nativeSetFlags", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001011 (void*)nativeSetFlags },
Robert Carre13b58e2017-08-31 14:50:44 -07001012 {"nativeSetWindowCrop", "(JJIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001013 (void*)nativeSetWindowCrop },
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001014 {"nativeSetCornerRadius", "(JJF)V",
1015 (void*)nativeSetCornerRadius },
Robert Carre13b58e2017-08-31 14:50:44 -07001016 {"nativeSetLayerStack", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001017 (void*)nativeSetLayerStack },
1018 {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
1019 (void*)nativeGetBuiltInDisplay },
1020 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
1021 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -07001022 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
1023 (void*)nativeDestroyDisplay },
Robert Carre13b58e2017-08-31 14:50:44 -07001024 {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001025 (void*)nativeSetDisplaySurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001026 {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001027 (void*)nativeSetDisplayLayerStack },
Robert Carre13b58e2017-08-31 14:50:44 -07001028 {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001029 (void*)nativeSetDisplayProjection },
Robert Carre13b58e2017-08-31 14:50:44 -07001030 {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
Michael Wright01e840f2014-06-26 16:03:25 -07001031 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -07001032 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
1033 (void*)nativeGetDisplayConfigs },
1034 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
1035 (void*)nativeGetActiveConfig },
1036 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
1037 (void*)nativeSetActiveConfig },
Michael Wright1c9977b2016-07-12 13:30:10 -07001038 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
1039 (void*)nativeGetDisplayColorModes},
1040 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
1041 (void*)nativeGetActiveColorMode},
1042 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
1043 (void*)nativeSetActiveColorMode},
Peiyong Lin5f4a5682019-01-17 11:37:07 -08001044 {"nativeGetCompositionDataspaces", "()[I",
1045 (void*)nativeGetCompositionDataspaces},
Michael Wright9ff94c02016-03-30 18:05:40 -07001046 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
1047 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -07001048 {"nativeClearContentFrameStats", "(J)Z",
1049 (void*)nativeClearContentFrameStats },
1050 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
1051 (void*)nativeGetContentFrameStats },
1052 {"nativeClearAnimationFrameStats", "()Z",
1053 (void*)nativeClearAnimationFrameStats },
1054 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
1055 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -07001056 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
1057 (void*)nativeSetDisplayPowerMode },
Peiyong Lin0ddb7d42019-01-16 13:25:09 -08001058 {"nativeGetProtectedContentSupport", "()Z",
1059 (void*)nativeGetProtectedContentSupport },
Robert Carre13b58e2017-08-31 14:50:44 -07001060 {"nativeDeferTransactionUntil", "(JJLandroid/os/IBinder;J)V",
Rob Carr64e516f2015-10-29 00:20:45 +00001061 (void*)nativeDeferTransactionUntil },
Robert Carre13b58e2017-08-31 14:50:44 -07001062 {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001063 (void*)nativeDeferTransactionUntilSurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001064 {"nativeReparentChildren", "(JJLandroid/os/IBinder;)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001065 (void*)nativeReparentChildren } ,
Robert Carr10584fa2019-01-14 15:55:19 -08001066 {"nativeReparent", "(JJJ)V",
chaviw76431402017-09-18 16:50:05 -07001067 (void*)nativeReparent },
Robert Carre13b58e2017-08-31 14:50:44 -07001068 {"nativeSeverChildren", "(JJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001069 (void*)nativeSeverChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001070 {"nativeSetOverrideScalingMode", "(JJI)V",
Robert Carr1ca6a332016-04-11 18:00:43 -07001071 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +00001072 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -07001073 (void*)nativeGetHandle },
chaviw08520a02018-09-10 16:44:56 -07001074 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZI)Landroid/graphics/GraphicBuffer;",
1075 (void*)nativeScreenshot },
Chavi Weingartenea2eb5a2017-11-29 21:26:24 +00001076 {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/graphics/Rect;F)Landroid/graphics/GraphicBuffer;",
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001077 (void*)nativeCaptureLayers },
Robert Carr788f5742018-07-30 17:46:45 -07001078 {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
chaviw59f532e2018-12-26 15:34:59 -08001079 (void*)nativeSetInputWindowInfo },
1080 {"nativeTransferTouchFocus", "(JLandroid/os/IBinder;Landroid/os/IBinder;)V",
1081 (void*)nativeTransferTouchFocus },
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001082 {"nativeGetDisplayedContentSamplingAttributes",
1083 "(Landroid/os/IBinder;)Landroid/hardware/display/DisplayedContentSamplingAttributes;",
1084 (void*)nativeGetDisplayedContentSamplingAttributes },
1085 {"nativeSetDisplayedContentSamplingEnabled", "(Landroid/os/IBinder;ZII)Z",
1086 (void*)nativeSetDisplayedContentSamplingEnabled },
1087 {"nativeGetDisplayedContentSample",
1088 "(Landroid/os/IBinder;JJ)Landroid/hardware/display/DisplayedContentSample;",
1089 (void*)nativeGetDisplayedContentSample },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001090};
1091
1092int register_android_view_SurfaceControl(JNIEnv* env)
1093{
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001094 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001095 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
1096
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001097 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
1098 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
1099 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
1100 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
1101 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
1102 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
1103 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
1104 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
1105 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
1106 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
1107 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
1108 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
1109 clazz, "appVsyncOffsetNanos", "J");
1110 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
1111 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001112
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001113 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
1114 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
1115 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
1116 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
1117 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -07001118
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001119 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
1120 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
1121 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001122 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
1123
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001124 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
1125 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1126 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001127 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1128
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001129 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
1130 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1131 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001132 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1133
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001134 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
1135 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
1136 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
1137 "([IFFF)V");
1138
Robert Carr6486d312017-01-09 19:48:29 -08001139 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
1140 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
1141 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
1142 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
1143
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001144 jclass displayedContentSampleClazz = FindClassOrDie(env,
1145 "android/hardware/display/DisplayedContentSample");
1146 gDisplayedContentSampleClassInfo.clazz = MakeGlobalRefOrDie(env, displayedContentSampleClazz);
1147 gDisplayedContentSampleClassInfo.ctor = GetMethodIDOrDie(env,
1148 displayedContentSampleClazz, "<init>", "(J[J[J[J[J)V");
1149
1150 jclass displayedContentSamplingAttributesClazz = FindClassOrDie(env,
1151 "android/hardware/display/DisplayedContentSamplingAttributes");
1152 gDisplayedContentSamplingAttributesClassInfo.clazz = MakeGlobalRefOrDie(env,
1153 displayedContentSamplingAttributesClazz);
1154 gDisplayedContentSamplingAttributesClassInfo.ctor = GetMethodIDOrDie(env,
1155 displayedContentSamplingAttributesClazz, "<init>", "(III)V");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001156 return err;
1157}
1158
1159};