blob: 0453195e6a1d2a40b97c42df04ba47de55d5d841 [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);
Robert Carr76907ee2019-01-11 13:38:19 -0800129 sp<SurfaceComposerClient> client;
130 if (sessionObj != NULL) {
131 client = android_view_SurfaceSession_getClient(env, sessionObj);
132 } else {
133 client = SurfaceComposerClient::getDefault();
134 }
Robert Carr838120c2016-11-01 18:31:12 -0700135 SurfaceControl *parent = reinterpret_cast<SurfaceControl*>(parentObject);
Robert Carrb0f39362018-03-14 13:52:25 -0700136 sp<SurfaceControl> surface;
137 status_t err = client->createSurfaceChecked(
138 String8(name.c_str()), w, h, format, &surface, flags, parent, windowType, ownerUid);
139 if (err == NAME_NOT_FOUND) {
140 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
141 return 0;
142 } else if (err != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800143 jniThrowException(env, OutOfResourcesException, NULL);
144 return 0;
145 }
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500146
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800147 surface->incStrong((void *)nativeCreate);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000148 return reinterpret_cast<jlong>(surface.get());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800149}
150
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000151static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800152 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800153 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800154}
155
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000156static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800157 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
158 ctrl->clear();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800159 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800160}
161
Chong Zhang47e36a32016-02-29 16:44:33 -0800162static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
163 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
164 if (ctrl != NULL) {
165 ctrl->disconnect();
166 }
167}
168
Robert Carr6486d312017-01-09 19:48:29 -0800169static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
170 int left = env->GetIntField(rectObj, gRectClassInfo.left);
171 int top = env->GetIntField(rectObj, gRectClassInfo.top);
172 int right = env->GetIntField(rectObj, gRectClassInfo.right);
173 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
174 return Rect(left, top, right, bottom);
175}
176
chaviw08520a02018-09-10 16:44:56 -0700177static jobject nativeScreenshot(JNIEnv* env, jclass clazz,
Robert Carr6486d312017-01-09 19:48:29 -0800178 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
chaviw08520a02018-09-10 16:44:56 -0700179 bool useIdentityTransform, int rotation) {
Robert Carr6486d312017-01-09 19:48:29 -0800180 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
181 if (displayToken == NULL) {
182 return NULL;
183 }
184 Rect sourceCrop = rectFromObj(env, sourceCropObj);
Robert Carr6486d312017-01-09 19:48:29 -0800185 sp<GraphicBuffer> buffer;
Peiyong Lin10a34d12018-09-19 13:56:12 -0700186 status_t res = ScreenshotClient::capture(displayToken, ui::Dataspace::V0_SRGB,
187 ui::PixelFormat::RGBA_8888,
188 sourceCrop, width, height,
189 useIdentityTransform, rotation, &buffer);
Robert Carr6486d312017-01-09 19:48:29 -0800190 if (res != NO_ERROR) {
191 return NULL;
192 }
193
194 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
195 gGraphicBufferClassInfo.builder,
196 buffer->getWidth(),
197 buffer->getHeight(),
198 buffer->getPixelFormat(),
Mathias Agopian113fd302017-05-25 18:31:04 -0700199 (jint)buffer->getUsage(),
Patrik Torstensson511a8082017-03-27 15:04:11 +0100200 (jlong)buffer.get());
Robert Carr6486d312017-01-09 19:48:29 -0800201}
202
Chavi Weingartend7ec64c2017-11-30 01:52:01 +0000203static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject layerHandleToken,
chaviwfbe47df2017-11-10 16:14:49 -0800204 jobject sourceCropObj, jfloat frameScale) {
205
206 sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken);
207 if (layerHandle == NULL) {
208 return NULL;
209 }
210
211 Rect sourceCrop;
212 if (sourceCropObj != NULL) {
213 sourceCrop = rectFromObj(env, sourceCropObj);
214 }
215
216 sp<GraphicBuffer> buffer;
Peiyong Lin10a34d12018-09-19 13:56:12 -0700217 status_t res = ScreenshotClient::captureChildLayers(layerHandle, ui::Dataspace::V0_SRGB,
218 ui::PixelFormat::RGBA_8888, sourceCrop,
219 frameScale, &buffer);
chaviwfbe47df2017-11-10 16:14:49 -0800220 if (res != NO_ERROR) {
221 return NULL;
222 }
223
224 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
225 gGraphicBufferClassInfo.builder,
226 buffer->getWidth(),
227 buffer->getHeight(),
228 buffer->getPixelFormat(),
229 (jint)buffer->getUsage(),
230 (jlong)buffer.get());
chaviw1cda84c2017-10-23 16:47:10 -0700231}
232
Robert Carre13b58e2017-08-31 14:50:44 -0700233static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) {
234 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
235 transaction->apply(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800236}
237
Robert Carrb1579c82017-09-05 14:54:47 -0700238static void nativeMergeTransaction(JNIEnv* env, jclass clazz,
239 jlong transactionObj, jlong otherTransactionObj) {
240 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
241 auto otherTransaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(
242 otherTransactionObj);
243 transaction->merge(std::move(*otherTransaction));
244}
245
Robert Carre13b58e2017-08-31 14:50:44 -0700246static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) {
247 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
248 transaction->setAnimationTransaction();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800249}
250
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100251static void nativeSetEarlyWakeup(JNIEnv* env, jclass clazz, jlong transactionObj) {
252 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
253 transaction->setEarlyWakeup();
254}
255
Robert Carre13b58e2017-08-31 14:50:44 -0700256static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
257 jlong nativeObject, jint zorder) {
258 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800259
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800260 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700261 transaction->setLayer(ctrl, zorder);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800262}
263
Robert Carre13b58e2017-08-31 14:50:44 -0700264static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
265 jlong nativeObject,
Robert Carraf422a82017-04-10 18:34:33 -0700266 jobject relativeTo, jint zorder) {
Robert Carre13b58e2017-08-31 14:50:44 -0700267
Robert Carraf422a82017-04-10 18:34:33 -0700268 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
269 sp<IBinder> handle = ibinderForJavaObject(env, relativeTo);
270
Robert Carre13b58e2017-08-31 14:50:44 -0700271 {
272 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
273 transaction->setRelativeLayer(ctrl, handle, zorder);
274 }
Robert Carraf422a82017-04-10 18:34:33 -0700275}
276
Robert Carre13b58e2017-08-31 14:50:44 -0700277static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj,
278 jlong nativeObject, jfloat x, jfloat y) {
279 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
280
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800281 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700282 transaction->setPosition(ctrl, x, y);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800283}
284
Robert Carr76907ee2019-01-11 13:38:19 -0800285static void nativeSetGeometry(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject,
286 jobject sourceObj, jobject dstObj, jlong orientation) {
287 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
288 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
289
290 Rect source, dst;
291 if (sourceObj != NULL) {
292 source = rectFromObj(env, sourceObj);
293 }
294 if (dstObj != NULL) {
295 dst = rectFromObj(env, dstObj);
296 }
297 transaction->setGeometry(ctrl, source, dst, orientation);
298}
299
Robert Carr6da3cc02016-06-16 15:17:07 -0700300static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700301jlong transactionObj,
Robert Carra9408d42016-06-03 13:28:48 -0700302 jlong nativeObject) {
Robert Carre13b58e2017-08-31 14:50:44 -0700303 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
304
Robert Carra9408d42016-06-03 13:28:48 -0700305 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700306 transaction->setGeometryAppliesWithResize(ctrl);
Robert Carra9408d42016-06-03 13:28:48 -0700307}
308
Robert Carre13b58e2017-08-31 14:50:44 -0700309static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj,
310 jlong nativeObject, jint w, jint h) {
311 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
312
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800313 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700314 transaction->setSize(ctrl, w, h);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800315}
316
Robert Carre13b58e2017-08-31 14:50:44 -0700317static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong transactionObj,
318 jlong nativeObject, jint flags, jint mask) {
319 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
320
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800321 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700322 transaction->setFlags(ctrl, flags, mask);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800323}
324
Robert Carre13b58e2017-08-31 14:50:44 -0700325static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong transactionObj,
326 jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800327 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
328 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
329 if (!region) {
330 doThrowIAE(env);
331 return;
332 }
333
334 const SkIRect& b(region->getBounds());
335 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
336 if (region->isComplex()) {
337 SkRegion::Iterator it(*region);
338 while (!it.done()) {
339 const SkIRect& r(it.rect());
340 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
341 it.next();
342 }
343 }
344
Robert Carre13b58e2017-08-31 14:50:44 -0700345 {
346 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
347 transaction->setTransparentRegionHint(ctrl, reg);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800348 }
349}
350
Robert Carre13b58e2017-08-31 14:50:44 -0700351static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj,
352 jlong nativeObject, jfloat alpha) {
353 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
354
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800355 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700356 transaction->setAlpha(ctrl, alpha);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800357}
358
Robert Carr788f5742018-07-30 17:46:45 -0700359static void nativeSetInputWindowInfo(JNIEnv* env, jclass clazz, jlong transactionObj,
360 jlong nativeObject, jobject inputWindow) {
361 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
362
363 sp<NativeInputWindowHandle> handle = android_server_InputWindowHandle_getHandle(
364 env, inputWindow);
365 handle->updateInfo();
366
367 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
368 transaction->setInputWindowInfo(ctrl, *handle->getInfo());
369}
370
chaviw59f532e2018-12-26 15:34:59 -0800371static void nativeTransferTouchFocus(JNIEnv* env, jclass clazz, jlong transactionObj,
372 jobject fromTokenObj, jobject toTokenObj) {
373 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
374
375 sp<IBinder> fromToken(ibinderForJavaObject(env, fromTokenObj));
376 sp<IBinder> toToken(ibinderForJavaObject(env, toTokenObj));
377 transaction->transferTouchFocus(fromToken, toToken);
378}
379
Robert Carre13b58e2017-08-31 14:50:44 -0700380static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj,
381 jlong nativeObject, jfloatArray fColor) {
382 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
chaviw0dd03f52017-08-25 12:15:26 -0700383 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700384
chaviw0dd03f52017-08-25 12:15:26 -0700385 float* floatColors = env->GetFloatArrayElements(fColor, 0);
386 half3 color(floatColors[0], floatColors[1], floatColors[2]);
Robert Carre13b58e2017-08-31 14:50:44 -0700387 transaction->setColor(ctrl, color);
chaviw0dd03f52017-08-25 12:15:26 -0700388}
389
Robert Carre13b58e2017-08-31 14:50:44 -0700390static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj,
391 jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800392 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
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);
Robert Carre13b58e2017-08-31 14:50:44 -0700396 transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800397}
398
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700399static void nativeSetColorTransform(JNIEnv* env, jclass clazz, jlong transactionObj,
400 jlong nativeObject, jfloatArray fMatrix, jfloatArray fTranslation) {
401 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
402 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
403 float* floatMatrix = env->GetFloatArrayElements(fMatrix, 0);
404 mat3 matrix(static_cast<float const*>(floatMatrix));
405 float* floatTranslation = env->GetFloatArrayElements(fTranslation, 0);
406 vec3 translation(floatTranslation[0], floatTranslation[1], floatTranslation[2]);
407 transaction->setColorTransform(surfaceControl, matrix, translation);
408}
409
Robert Carre13b58e2017-08-31 14:50:44 -0700410static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
411 jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800412 jint l, jint t, jint r, jint b) {
Robert Carre13b58e2017-08-31 14:50:44 -0700413 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
414
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800415 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
416 Rect crop(l, t, r, b);
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700417 transaction->setCrop_legacy(ctrl, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800418}
419
Lucas Dupinff9d6ab2018-10-16 18:05:50 -0700420static void nativeSetCornerRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
421 jlong nativeObject, jfloat cornerRadius) {
422 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
423
424 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
425 transaction->setCornerRadius(ctrl, cornerRadius);
426}
427
Robert Carre13b58e2017-08-31 14:50:44 -0700428static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj,
429 jlong nativeObject, jint layerStack) {
430 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
431
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800432 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700433 transaction->setLayerStack(ctrl, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800434}
435
436static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) {
437 sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id));
438 return javaObjectForIBinder(env, token);
439}
440
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700441static jobject nativeGetDisplayedContentSamplingAttributes(JNIEnv* env, jclass clazz,
442 jobject tokenObj) {
443 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
444
445 ui::PixelFormat format;
446 ui::Dataspace dataspace;
447 uint8_t componentMask;
448 status_t err = SurfaceComposerClient::getDisplayedContentSamplingAttributes(
449 token, &format, &dataspace, &componentMask);
450 if (err != OK) {
451 return nullptr;
452 }
453 return env->NewObject(gDisplayedContentSamplingAttributesClassInfo.clazz,
454 gDisplayedContentSamplingAttributesClassInfo.ctor,
455 format, dataspace, componentMask);
456}
457
458static jboolean nativeSetDisplayedContentSamplingEnabled(JNIEnv* env, jclass clazz,
459 jobject tokenObj, jboolean enable, jint componentMask, jint maxFrames) {
460 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Kevin DuBois205a6802019-01-07 17:04:46 -0800461 status_t rc = SurfaceComposerClient::setDisplayContentSamplingEnabled(
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700462 token, enable, componentMask, maxFrames);
Kevin DuBois205a6802019-01-07 17:04:46 -0800463 return rc == OK;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700464}
465
466static jobject nativeGetDisplayedContentSample(JNIEnv* env, jclass clazz, jobject tokenObj,
467 jlong maxFrames, jlong timestamp) {
468 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
469
470 DisplayedFrameStats stats;
471 status_t err = SurfaceComposerClient::getDisplayedContentSample(
472 token, maxFrames, timestamp, &stats);
473 if (err != OK) {
474 return nullptr;
475 }
476
477 jlongArray histogramComponent0 = env->NewLongArray(stats.component_0_sample.size());
478 jlongArray histogramComponent1 = env->NewLongArray(stats.component_1_sample.size());
479 jlongArray histogramComponent2 = env->NewLongArray(stats.component_2_sample.size());
480 jlongArray histogramComponent3 = env->NewLongArray(stats.component_3_sample.size());
481 if ((histogramComponent0 == nullptr) ||
482 (histogramComponent1 == nullptr) ||
483 (histogramComponent2 == nullptr) ||
484 (histogramComponent3 == nullptr)) {
485 return JNI_FALSE;
486 }
487
488 env->SetLongArrayRegion(histogramComponent0, 0,
489 stats.component_0_sample.size(),
490 reinterpret_cast<jlong*>(stats.component_0_sample.data()));
491 env->SetLongArrayRegion(histogramComponent1, 0,
492 stats.component_1_sample.size(),
493 reinterpret_cast<jlong*>(stats.component_1_sample.data()));
494 env->SetLongArrayRegion(histogramComponent2, 0,
495 stats.component_2_sample.size(),
496 reinterpret_cast<jlong*>(stats.component_2_sample.data()));
497 env->SetLongArrayRegion(histogramComponent3, 0,
498 stats.component_3_sample.size(),
499 reinterpret_cast<jlong*>(stats.component_3_sample.data()));
500 return env->NewObject(gDisplayedContentSampleClassInfo.clazz,
501 gDisplayedContentSampleClassInfo.ctor,
502 stats.numFrames,
503 histogramComponent0,
504 histogramComponent1,
505 histogramComponent2,
506 histogramComponent3);
507}
508
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800509static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
510 jboolean secure) {
511 ScopedUtfChars name(env, nameObj);
512 sp<IBinder> token(SurfaceComposerClient::createDisplay(
513 String8(name.c_str()), bool(secure)));
514 return javaObjectForIBinder(env, token);
515}
516
Jesse Hall6a6bc212013-08-08 12:15:03 -0700517static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
518 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
519 if (token == NULL) return;
520 SurfaceComposerClient::destroyDisplay(token);
521}
522
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800523static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700524 jlong transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000525 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800526 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
527 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800528 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800529 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800530 if (sur != NULL) {
531 bufferProducer = sur->getIGraphicBufferProducer();
532 }
Robert Carre13b58e2017-08-31 14:50:44 -0700533
534
535 status_t err = NO_ERROR;
536 {
537 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
538 err = transaction->setDisplaySurface(token,
539 bufferProducer);
540 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700541 if (err != NO_ERROR) {
542 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
543 " Surface created with singleBufferMode?");
544 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800545}
546
547static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700548 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800549 jobject tokenObj, jint layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -0700550
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800551 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
552 if (token == NULL) return;
553
Robert Carre13b58e2017-08-31 14:50:44 -0700554 {
555 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
556 transaction->setDisplayLayerStack(token, layerStack);
557 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800558}
559
560static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700561 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800562 jobject tokenObj, jint orientation,
563 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
564 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
565 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
566 if (token == NULL) return;
567 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
568 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
Robert Carre13b58e2017-08-31 14:50:44 -0700569
570 {
571 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
572 transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect);
573 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800574}
575
Michael Wright01e840f2014-06-26 16:03:25 -0700576static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700577 jlong transactionObj,
Michael Wright01e840f2014-06-26 16:03:25 -0700578 jobject tokenObj, jint width, jint height) {
579 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
580 if (token == NULL) return;
Robert Carre13b58e2017-08-31 14:50:44 -0700581
582 {
583 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
584 transaction->setDisplaySize(token, width, height);
585 }
Michael Wright01e840f2014-06-26 16:03:25 -0700586}
587
Dan Stoza00101052014-05-02 15:23:40 -0700588static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
589 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800590 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700591 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800592
Dan Stoza00101052014-05-02 15:23:40 -0700593 Vector<DisplayInfo> configs;
594 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
595 configs.size() == 0) {
596 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800597 }
598
Dan Stoza00101052014-05-02 15:23:40 -0700599 jobjectArray configArray = env->NewObjectArray(configs.size(),
600 gPhysicalDisplayInfoClassInfo.clazz, NULL);
601
602 for (size_t c = 0; c < configs.size(); ++c) {
603 const DisplayInfo& info = configs[c];
604 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
605 gPhysicalDisplayInfoClassInfo.ctor);
606 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
607 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
608 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
609 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
610 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
611 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
612 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700613 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
614 info.appVsyncOffset);
615 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
616 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700617 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
618 env->DeleteLocalRef(infoObj);
619 }
620
621 return configArray;
622}
623
624static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
625 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
626 if (token == NULL) return -1;
627 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
628}
629
630static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
631 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
632 if (token == NULL) return JNI_FALSE;
633 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
634 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800635}
636
Michael Wright1c9977b2016-07-12 13:30:10 -0700637static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
638 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
639 if (token == NULL) return NULL;
Peiyong Linb88549e2018-03-28 12:03:45 -0700640 Vector<ui::ColorMode> colorModes;
Michael Wright1c9977b2016-07-12 13:30:10 -0700641 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
642 colorModes.isEmpty()) {
643 return NULL;
644 }
645
646 jintArray colorModesArray = env->NewIntArray(colorModes.size());
647 if (colorModesArray == NULL) {
648 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
649 return NULL;
650 }
651 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
652 for (size_t i = 0; i < colorModes.size(); i++) {
653 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
654 }
655 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
656 return colorModesArray;
657}
658
659static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
660 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
661 if (token == NULL) return -1;
662 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
663}
664
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800665static jintArray nativeGetCompositionDataspaces(JNIEnv* env, jclass) {
666 ui::Dataspace defaultDataspace, wcgDataspace;
667 ui::PixelFormat defaultPixelFormat, wcgPixelFormat;
668 if (SurfaceComposerClient::getCompositionPreference(&defaultDataspace,
669 &defaultPixelFormat,
670 &wcgDataspace,
671 &wcgPixelFormat) != NO_ERROR) {
672 return nullptr;
673 }
674 jintArray array = env->NewIntArray(2);
675 if (array == nullptr) {
676 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
677 return nullptr;
678 }
679 jint* arrayValues = env->GetIntArrayElements(array, 0);
680 arrayValues[0] = static_cast<jint>(defaultDataspace);
681 arrayValues[1] = static_cast<jint>(wcgDataspace);
682 env->ReleaseIntArrayElements(array, arrayValues, 0);
683 return array;
684}
685
Michael Wright1c9977b2016-07-12 13:30:10 -0700686static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
687 jobject tokenObj, jint colorMode) {
688 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
689 if (token == NULL) return JNI_FALSE;
690 status_t err = SurfaceComposerClient::setActiveColorMode(token,
Peiyong Linb88549e2018-03-28 12:03:45 -0700691 static_cast<ui::ColorMode>(colorMode));
Michael Wright1c9977b2016-07-12 13:30:10 -0700692 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
693}
694
Prashant Malanic55929a2014-05-25 01:59:21 -0700695static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800696 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
697 if (token == NULL) return;
698
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700699 android::base::Timer t;
Prashant Malanic55929a2014-05-25 01:59:21 -0700700 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700701 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800702}
703
Peiyong Lin0ddb7d42019-01-16 13:25:09 -0800704static jboolean nativeGetProtectedContentSupport(JNIEnv* env, jclass) {
705 return static_cast<jboolean>(SurfaceComposerClient::getProtectedContentSupport());
706}
707
Svetoslav1376d602014-03-13 11:17:26 -0700708static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
709 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
710 status_t err = ctrl->clearLayerFrameStats();
711
712 if (err < 0 && err != NO_INIT) {
713 doThrowIAE(env);
714 }
715
716 // The other end is not ready, just report we failed.
717 if (err == NO_INIT) {
718 return JNI_FALSE;
719 }
720
721 return JNI_TRUE;
722}
723
724static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
725 jobject outStats) {
726 FrameStats stats;
727
728 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
729 status_t err = ctrl->getLayerFrameStats(&stats);
730 if (err < 0 && err != NO_INIT) {
731 doThrowIAE(env);
732 }
733
734 // The other end is not ready, fine just return empty stats.
735 if (err == NO_INIT) {
736 return JNI_FALSE;
737 }
738
739 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
740 size_t frameCount = stats.desiredPresentTimesNano.size();
741
742 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
743 if (postedTimesNanoDst == NULL) {
744 return JNI_FALSE;
745 }
746
747 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
748 if (presentedTimesNanoDst == NULL) {
749 return JNI_FALSE;
750 }
751
752 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
753 if (readyTimesNanoDst == NULL) {
754 return JNI_FALSE;
755 }
756
757 nsecs_t postedTimesNanoSrc[frameCount];
758 nsecs_t presentedTimesNanoSrc[frameCount];
759 nsecs_t readyTimesNanoSrc[frameCount];
760
761 for (size_t i = 0; i < frameCount; i++) {
762 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
763 if (postedTimeNano == INT64_MAX) {
764 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
765 }
766 postedTimesNanoSrc[i] = postedTimeNano;
767
768 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
769 if (presentedTimeNano == INT64_MAX) {
770 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
771 }
772 presentedTimesNanoSrc[i] = presentedTimeNano;
773
774 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
775 if (readyTimeNano == INT64_MAX) {
776 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
777 }
778 readyTimesNanoSrc[i] = readyTimeNano;
779 }
780
781 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
782 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
783 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
784
785 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
786 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
787
788 if (env->ExceptionCheck()) {
789 return JNI_FALSE;
790 }
791
792 return JNI_TRUE;
793}
794
795static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
796 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
797
798 if (err < 0 && err != NO_INIT) {
799 doThrowIAE(env);
800 }
801
802 // The other end is not ready, just report we failed.
803 if (err == NO_INIT) {
804 return JNI_FALSE;
805 }
806
807 return JNI_TRUE;
808}
809
810static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
811 FrameStats stats;
812
813 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
814 if (err < 0 && err != NO_INIT) {
815 doThrowIAE(env);
816 }
817
818 // The other end is not ready, fine just return empty stats.
819 if (err == NO_INIT) {
820 return JNI_FALSE;
821 }
822
823 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
824 size_t frameCount = stats.desiredPresentTimesNano.size();
825
826 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
827 if (presentedTimesNanoDst == NULL) {
828 return JNI_FALSE;
829 }
830
831 nsecs_t presentedTimesNanoSrc[frameCount];
832
833 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700834 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700835 if (presentedTimeNano == INT64_MAX) {
836 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
837 }
838 presentedTimesNanoSrc[i] = presentedTimeNano;
839 }
840
841 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
842
843 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
844 presentedTimesNanoDst);
845
846 if (env->ExceptionCheck()) {
847 return JNI_FALSE;
848 }
849
850 return JNI_TRUE;
851}
852
Robert Carre13b58e2017-08-31 14:50:44 -0700853static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj,
854 jlong nativeObject,
Rob Carr64e516f2015-10-29 00:20:45 +0000855 jobject handleObject, jlong frameNumber) {
856 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
857 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
858
Robert Carre13b58e2017-08-31 14:50:44 -0700859 {
860 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700861 transaction->deferTransactionUntil_legacy(ctrl, handle, frameNumber);
Robert Carre13b58e2017-08-31 14:50:44 -0700862 }
Rob Carr64e516f2015-10-29 00:20:45 +0000863}
864
Robert Carre13b58e2017-08-31 14:50:44 -0700865static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
866 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -0800867 jlong surfaceObject, jlong frameNumber) {
Robert Carre13b58e2017-08-31 14:50:44 -0700868 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
869
Robert Carrd5c7dd62017-03-08 10:39:30 -0800870 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
871 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
872
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700873 transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber);
Robert Carrd5c7dd62017-03-08 10:39:30 -0800874}
875
Robert Carre13b58e2017-08-31 14:50:44 -0700876static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
877 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -0800878 jobject newParentObject) {
Robert Carre13b58e2017-08-31 14:50:44 -0700879
Robert Carrd5c7dd62017-03-08 10:39:30 -0800880 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
881 sp<IBinder> handle = ibinderForJavaObject(env, newParentObject);
882
Robert Carre13b58e2017-08-31 14:50:44 -0700883 {
884 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
885 transaction->reparentChildren(ctrl, handle);
886 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800887}
888
Robert Carre13b58e2017-08-31 14:50:44 -0700889static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
890 jlong nativeObject,
Robert Carr10584fa2019-01-14 15:55:19 -0800891 jlong newParentObject) {
chaviw63542382017-08-17 17:39:29 -0700892 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr10584fa2019-01-14 15:55:19 -0800893 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700894
895 {
896 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr10584fa2019-01-14 15:55:19 -0800897 transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL);
Robert Carre13b58e2017-08-31 14:50:44 -0700898 }
chaviw63542382017-08-17 17:39:29 -0700899}
900
Robert Carre13b58e2017-08-31 14:50:44 -0700901static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
902 jlong nativeObject) {
903 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
904
Robert Carrd5c7dd62017-03-08 10:39:30 -0800905 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700906 transaction->detachChildren(ctrl);
Robert Carrd5c7dd62017-03-08 10:39:30 -0800907}
908
Robert Carre13b58e2017-08-31 14:50:44 -0700909static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj,
910 jlong nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -0700911 jint scalingMode) {
Robert Carre13b58e2017-08-31 14:50:44 -0700912 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr1ca6a332016-04-11 18:00:43 -0700913
Robert Carre13b58e2017-08-31 14:50:44 -0700914 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
915 transaction->setOverrideScalingMode(ctrl, scalingMode);
Robert Carr1ca6a332016-04-11 18:00:43 -0700916}
917
Rob Carr64e516f2015-10-29 00:20:45 +0000918static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
919 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Rob Carr64e516f2015-10-29 00:20:45 +0000920 return javaObjectForIBinder(env, ctrl->getHandle());
921}
922
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700923static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
924 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
925 if (token == NULL) return NULL;
926
927 HdrCapabilities capabilities;
928 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
929
930 const auto& types = capabilities.getSupportedHdrTypes();
Peiyong Lin3a0c6e12018-04-16 11:05:29 -0700931 std::vector<int32_t> intTypes;
932 for (auto type : types) {
933 intTypes.push_back(static_cast<int32_t>(type));
934 }
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700935 auto typesArray = env->NewIntArray(types.size());
Peiyong Lin3a0c6e12018-04-16 11:05:29 -0700936 env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data());
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700937
Michael Wright9ff94c02016-03-30 18:05:40 -0700938 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700939 typesArray, capabilities.getDesiredMaxLuminance(),
940 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
941}
942
Jorim Jaggi06975df2017-12-01 14:52:13 +0100943static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
944 Parcel* parcel = parcelForJavaObject(env, parcelObj);
945 if (parcel == NULL) {
946 doThrowNPE(env);
947 return 0;
948 }
949 sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel);
950 if (surface == nullptr) {
951 return 0;
952 }
953 surface->incStrong((void *)nativeCreate);
954 return reinterpret_cast<jlong>(surface.get());
955}
956
chaviwbeb7a0c2018-12-05 13:49:54 -0800957static jlong nativeCopyFromSurfaceControl(JNIEnv* env, jclass clazz, jlong surfaceControlNativeObj) {
958 sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj));
959 if (surface == nullptr) {
960 return 0;
961 }
Robert Carr5fea55b2018-12-10 13:05:52 -0800962
963 sp<SurfaceControl> newSurface = new SurfaceControl(surface);
964 newSurface->incStrong((void *)nativeCreate);
965 return reinterpret_cast<jlong>(newSurface.get());
chaviwbeb7a0c2018-12-05 13:49:54 -0800966}
967
Jorim Jaggi06975df2017-12-01 14:52:13 +0100968static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
969 jlong nativeObject, jobject parcelObj) {
970 Parcel* parcel = parcelForJavaObject(env, parcelObj);
971 if (parcel == NULL) {
972 doThrowNPE(env);
973 return;
974 }
975 SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject);
chaviwbeb7a0c2018-12-05 13:49:54 -0800976 if (self != nullptr) {
977 self->writeToParcel(parcel);
978 }
Jorim Jaggi06975df2017-12-01 14:52:13 +0100979}
980
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800981// ----------------------------------------------------------------------------
982
Daniel Micay76f6a862015-09-19 17:31:01 -0400983static const JNINativeMethod sSurfaceControlMethods[] = {
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500984 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJII)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800985 (void*)nativeCreate },
Jorim Jaggi06975df2017-12-01 14:52:13 +0100986 {"nativeReadFromParcel", "(Landroid/os/Parcel;)J",
987 (void*)nativeReadFromParcel },
chaviwbeb7a0c2018-12-05 13:49:54 -0800988 {"nativeCopyFromSurfaceControl", "(J)J" ,
989 (void*)nativeCopyFromSurfaceControl },
Jorim Jaggi06975df2017-12-01 14:52:13 +0100990 {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
991 (void*)nativeWriteToParcel },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000992 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800993 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000994 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800995 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -0800996 {"nativeDisconnect", "(J)V",
997 (void*)nativeDisconnect },
Robert Carre13b58e2017-08-31 14:50:44 -0700998 {"nativeCreateTransaction", "()J",
999 (void*)nativeCreateTransaction },
1000 {"nativeApplyTransaction", "(JZ)V",
1001 (void*)nativeApplyTransaction },
1002 {"nativeGetNativeTransactionFinalizer", "()J",
1003 (void*)nativeGetNativeTransactionFinalizer },
Robert Carrb1579c82017-09-05 14:54:47 -07001004 {"nativeMergeTransaction", "(JJ)V",
1005 (void*)nativeMergeTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -07001006 {"nativeSetAnimationTransaction", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001007 (void*)nativeSetAnimationTransaction },
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001008 {"nativeSetEarlyWakeup", "(J)V",
1009 (void*)nativeSetEarlyWakeup },
Robert Carre13b58e2017-08-31 14:50:44 -07001010 {"nativeSetLayer", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001011 (void*)nativeSetLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001012 {"nativeSetRelativeLayer", "(JJLandroid/os/IBinder;I)V",
Robert Carraf422a82017-04-10 18:34:33 -07001013 (void*)nativeSetRelativeLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001014 {"nativeSetPosition", "(JJFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001015 (void*)nativeSetPosition },
Robert Carre13b58e2017-08-31 14:50:44 -07001016 {"nativeSetGeometryAppliesWithResize", "(JJ)V",
Robert Carr6da3cc02016-06-16 15:17:07 -07001017 (void*)nativeSetGeometryAppliesWithResize },
Robert Carre13b58e2017-08-31 14:50:44 -07001018 {"nativeSetSize", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001019 (void*)nativeSetSize },
Robert Carre13b58e2017-08-31 14:50:44 -07001020 {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001021 (void*)nativeSetTransparentRegionHint },
Robert Carre13b58e2017-08-31 14:50:44 -07001022 {"nativeSetAlpha", "(JJF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001023 (void*)nativeSetAlpha },
Robert Carre13b58e2017-08-31 14:50:44 -07001024 {"nativeSetColor", "(JJ[F)V",
chaviw0dd03f52017-08-25 12:15:26 -07001025 (void*)nativeSetColor },
Robert Carre13b58e2017-08-31 14:50:44 -07001026 {"nativeSetMatrix", "(JJFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001027 (void*)nativeSetMatrix },
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001028 {"nativeSetColorTransform", "(JJ[F[F)V",
1029 (void*)nativeSetColorTransform },
Robert Carre13b58e2017-08-31 14:50:44 -07001030 {"nativeSetFlags", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001031 (void*)nativeSetFlags },
Robert Carre13b58e2017-08-31 14:50:44 -07001032 {"nativeSetWindowCrop", "(JJIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001033 (void*)nativeSetWindowCrop },
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001034 {"nativeSetCornerRadius", "(JJF)V",
1035 (void*)nativeSetCornerRadius },
Robert Carre13b58e2017-08-31 14:50:44 -07001036 {"nativeSetLayerStack", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001037 (void*)nativeSetLayerStack },
1038 {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
1039 (void*)nativeGetBuiltInDisplay },
1040 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
1041 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -07001042 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
1043 (void*)nativeDestroyDisplay },
Robert Carre13b58e2017-08-31 14:50:44 -07001044 {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001045 (void*)nativeSetDisplaySurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001046 {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001047 (void*)nativeSetDisplayLayerStack },
Robert Carre13b58e2017-08-31 14:50:44 -07001048 {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001049 (void*)nativeSetDisplayProjection },
Robert Carre13b58e2017-08-31 14:50:44 -07001050 {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
Michael Wright01e840f2014-06-26 16:03:25 -07001051 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -07001052 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
1053 (void*)nativeGetDisplayConfigs },
1054 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
1055 (void*)nativeGetActiveConfig },
1056 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
1057 (void*)nativeSetActiveConfig },
Michael Wright1c9977b2016-07-12 13:30:10 -07001058 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
1059 (void*)nativeGetDisplayColorModes},
1060 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
1061 (void*)nativeGetActiveColorMode},
1062 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
1063 (void*)nativeSetActiveColorMode},
Peiyong Lin5f4a5682019-01-17 11:37:07 -08001064 {"nativeGetCompositionDataspaces", "()[I",
1065 (void*)nativeGetCompositionDataspaces},
Michael Wright9ff94c02016-03-30 18:05:40 -07001066 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
1067 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -07001068 {"nativeClearContentFrameStats", "(J)Z",
1069 (void*)nativeClearContentFrameStats },
1070 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
1071 (void*)nativeGetContentFrameStats },
1072 {"nativeClearAnimationFrameStats", "()Z",
1073 (void*)nativeClearAnimationFrameStats },
1074 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
1075 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -07001076 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
1077 (void*)nativeSetDisplayPowerMode },
Peiyong Lin0ddb7d42019-01-16 13:25:09 -08001078 {"nativeGetProtectedContentSupport", "()Z",
1079 (void*)nativeGetProtectedContentSupport },
Robert Carre13b58e2017-08-31 14:50:44 -07001080 {"nativeDeferTransactionUntil", "(JJLandroid/os/IBinder;J)V",
Rob Carr64e516f2015-10-29 00:20:45 +00001081 (void*)nativeDeferTransactionUntil },
Robert Carre13b58e2017-08-31 14:50:44 -07001082 {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001083 (void*)nativeDeferTransactionUntilSurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001084 {"nativeReparentChildren", "(JJLandroid/os/IBinder;)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001085 (void*)nativeReparentChildren } ,
Robert Carr10584fa2019-01-14 15:55:19 -08001086 {"nativeReparent", "(JJJ)V",
chaviw76431402017-09-18 16:50:05 -07001087 (void*)nativeReparent },
Robert Carre13b58e2017-08-31 14:50:44 -07001088 {"nativeSeverChildren", "(JJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001089 (void*)nativeSeverChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001090 {"nativeSetOverrideScalingMode", "(JJI)V",
Robert Carr1ca6a332016-04-11 18:00:43 -07001091 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +00001092 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -07001093 (void*)nativeGetHandle },
chaviw08520a02018-09-10 16:44:56 -07001094 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZI)Landroid/graphics/GraphicBuffer;",
1095 (void*)nativeScreenshot },
Chavi Weingartenea2eb5a2017-11-29 21:26:24 +00001096 {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/graphics/Rect;F)Landroid/graphics/GraphicBuffer;",
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001097 (void*)nativeCaptureLayers },
Robert Carr788f5742018-07-30 17:46:45 -07001098 {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
chaviw59f532e2018-12-26 15:34:59 -08001099 (void*)nativeSetInputWindowInfo },
1100 {"nativeTransferTouchFocus", "(JLandroid/os/IBinder;Landroid/os/IBinder;)V",
1101 (void*)nativeTransferTouchFocus },
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001102 {"nativeGetDisplayedContentSamplingAttributes",
1103 "(Landroid/os/IBinder;)Landroid/hardware/display/DisplayedContentSamplingAttributes;",
1104 (void*)nativeGetDisplayedContentSamplingAttributes },
1105 {"nativeSetDisplayedContentSamplingEnabled", "(Landroid/os/IBinder;ZII)Z",
1106 (void*)nativeSetDisplayedContentSamplingEnabled },
1107 {"nativeGetDisplayedContentSample",
1108 "(Landroid/os/IBinder;JJ)Landroid/hardware/display/DisplayedContentSample;",
1109 (void*)nativeGetDisplayedContentSample },
Robert Carr76907ee2019-01-11 13:38:19 -08001110 {"nativeSetGeometry", "(JJLandroid/graphics/Rect;Landroid/graphics/Rect;J)V",
1111 (void*)nativeSetGeometry }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001112};
1113
1114int register_android_view_SurfaceControl(JNIEnv* env)
1115{
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001116 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001117 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
1118
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001119 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
1120 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
1121 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
1122 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
1123 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
1124 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
1125 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
1126 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
1127 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
1128 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
1129 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
1130 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
1131 clazz, "appVsyncOffsetNanos", "J");
1132 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
1133 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001134
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001135 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
1136 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
1137 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
1138 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
1139 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -07001140
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001141 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
1142 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
1143 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001144 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
1145
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001146 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
1147 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1148 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001149 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1150
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001151 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
1152 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1153 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001154 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1155
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001156 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
1157 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
1158 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
1159 "([IFFF)V");
1160
Robert Carr6486d312017-01-09 19:48:29 -08001161 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
1162 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
1163 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
1164 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
1165
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001166 jclass displayedContentSampleClazz = FindClassOrDie(env,
1167 "android/hardware/display/DisplayedContentSample");
1168 gDisplayedContentSampleClassInfo.clazz = MakeGlobalRefOrDie(env, displayedContentSampleClazz);
1169 gDisplayedContentSampleClassInfo.ctor = GetMethodIDOrDie(env,
1170 displayedContentSampleClazz, "<init>", "(J[J[J[J[J)V");
1171
1172 jclass displayedContentSamplingAttributesClazz = FindClassOrDie(env,
1173 "android/hardware/display/DisplayedContentSamplingAttributes");
1174 gDisplayedContentSamplingAttributesClassInfo.clazz = MakeGlobalRefOrDie(env,
1175 displayedContentSamplingAttributesClazz);
1176 gDisplayedContentSamplingAttributesClassInfo.ctor = GetMethodIDOrDie(env,
1177 displayedContentSamplingAttributesClazz, "<init>", "(III)V");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001178 return err;
1179}
1180
1181};