blob: 59deae76b108b624ac098015eae76563260bc2f1 [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,
Evan Rosky485df202018-12-06 14:11:12 -0800127 jobject metadataParcel) {
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;
Evan Rosky485df202018-12-06 14:11:12 -0800137 LayerMetadata metadata;
138 Parcel* parcel = parcelForJavaObject(env, metadataParcel);
139 if (parcel && !parcel->objectsCount()) {
140 status_t err = metadata.readFromParcel(parcel);
141 if (err != NO_ERROR) {
142 jniThrowException(env, "java/lang/IllegalArgumentException",
143 "Metadata parcel has wrong format");
144 }
145 }
146
Robert Carrb0f39362018-03-14 13:52:25 -0700147 status_t err = client->createSurfaceChecked(
Evan Rosky485df202018-12-06 14:11:12 -0800148 String8(name.c_str()), w, h, format, &surface, flags, parent, std::move(metadata));
Robert Carrb0f39362018-03-14 13:52:25 -0700149 if (err == NAME_NOT_FOUND) {
150 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
151 return 0;
152 } else if (err != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800153 jniThrowException(env, OutOfResourcesException, NULL);
154 return 0;
155 }
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500156
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800157 surface->incStrong((void *)nativeCreate);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000158 return reinterpret_cast<jlong>(surface.get());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800159}
160
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000161static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800162 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800163 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800164}
165
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000166static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800167 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
168 ctrl->clear();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800169 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800170}
171
Chong Zhang47e36a32016-02-29 16:44:33 -0800172static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
173 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
174 if (ctrl != NULL) {
175 ctrl->disconnect();
176 }
177}
178
Robert Carr6486d312017-01-09 19:48:29 -0800179static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
180 int left = env->GetIntField(rectObj, gRectClassInfo.left);
181 int top = env->GetIntField(rectObj, gRectClassInfo.top);
182 int right = env->GetIntField(rectObj, gRectClassInfo.right);
183 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
184 return Rect(left, top, right, bottom);
185}
186
chaviw08520a02018-09-10 16:44:56 -0700187static jobject nativeScreenshot(JNIEnv* env, jclass clazz,
Robert Carr6486d312017-01-09 19:48:29 -0800188 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
chaviw08520a02018-09-10 16:44:56 -0700189 bool useIdentityTransform, int rotation) {
Robert Carr6486d312017-01-09 19:48:29 -0800190 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
191 if (displayToken == NULL) {
192 return NULL;
193 }
194 Rect sourceCrop = rectFromObj(env, sourceCropObj);
Robert Carr6486d312017-01-09 19:48:29 -0800195 sp<GraphicBuffer> buffer;
Peiyong Lin10a34d12018-09-19 13:56:12 -0700196 status_t res = ScreenshotClient::capture(displayToken, ui::Dataspace::V0_SRGB,
197 ui::PixelFormat::RGBA_8888,
198 sourceCrop, width, height,
199 useIdentityTransform, rotation, &buffer);
Robert Carr6486d312017-01-09 19:48:29 -0800200 if (res != NO_ERROR) {
201 return NULL;
202 }
203
204 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
205 gGraphicBufferClassInfo.builder,
206 buffer->getWidth(),
207 buffer->getHeight(),
208 buffer->getPixelFormat(),
Mathias Agopian113fd302017-05-25 18:31:04 -0700209 (jint)buffer->getUsage(),
Patrik Torstensson511a8082017-03-27 15:04:11 +0100210 (jlong)buffer.get());
Robert Carr6486d312017-01-09 19:48:29 -0800211}
212
Chavi Weingartend7ec64c2017-11-30 01:52:01 +0000213static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject layerHandleToken,
chaviwfbe47df2017-11-10 16:14:49 -0800214 jobject sourceCropObj, jfloat frameScale) {
215
216 sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken);
217 if (layerHandle == NULL) {
218 return NULL;
219 }
220
221 Rect sourceCrop;
222 if (sourceCropObj != NULL) {
223 sourceCrop = rectFromObj(env, sourceCropObj);
224 }
225
226 sp<GraphicBuffer> buffer;
Peiyong Lin10a34d12018-09-19 13:56:12 -0700227 status_t res = ScreenshotClient::captureChildLayers(layerHandle, ui::Dataspace::V0_SRGB,
228 ui::PixelFormat::RGBA_8888, sourceCrop,
229 frameScale, &buffer);
chaviwfbe47df2017-11-10 16:14:49 -0800230 if (res != NO_ERROR) {
231 return NULL;
232 }
233
234 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
235 gGraphicBufferClassInfo.builder,
236 buffer->getWidth(),
237 buffer->getHeight(),
238 buffer->getPixelFormat(),
239 (jint)buffer->getUsage(),
240 (jlong)buffer.get());
chaviw1cda84c2017-10-23 16:47:10 -0700241}
242
Robert Carre13b58e2017-08-31 14:50:44 -0700243static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) {
244 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
245 transaction->apply(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800246}
247
Robert Carrb1579c82017-09-05 14:54:47 -0700248static void nativeMergeTransaction(JNIEnv* env, jclass clazz,
249 jlong transactionObj, jlong otherTransactionObj) {
250 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
251 auto otherTransaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(
252 otherTransactionObj);
253 transaction->merge(std::move(*otherTransaction));
254}
255
Robert Carre13b58e2017-08-31 14:50:44 -0700256static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) {
257 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
258 transaction->setAnimationTransaction();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800259}
260
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100261static void nativeSetEarlyWakeup(JNIEnv* env, jclass clazz, jlong transactionObj) {
262 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
263 transaction->setEarlyWakeup();
264}
265
Robert Carre13b58e2017-08-31 14:50:44 -0700266static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
267 jlong nativeObject, jint zorder) {
268 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800269
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800270 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700271 transaction->setLayer(ctrl, zorder);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800272}
273
Robert Carre13b58e2017-08-31 14:50:44 -0700274static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
275 jlong nativeObject,
Robert Carraf422a82017-04-10 18:34:33 -0700276 jobject relativeTo, jint zorder) {
Robert Carre13b58e2017-08-31 14:50:44 -0700277
Robert Carraf422a82017-04-10 18:34:33 -0700278 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
279 sp<IBinder> handle = ibinderForJavaObject(env, relativeTo);
280
Robert Carre13b58e2017-08-31 14:50:44 -0700281 {
282 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
283 transaction->setRelativeLayer(ctrl, handle, zorder);
284 }
Robert Carraf422a82017-04-10 18:34:33 -0700285}
286
Robert Carre13b58e2017-08-31 14:50:44 -0700287static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj,
288 jlong nativeObject, jfloat x, jfloat y) {
289 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
290
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800291 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700292 transaction->setPosition(ctrl, x, y);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800293}
294
Robert Carr76907ee2019-01-11 13:38:19 -0800295static void nativeSetGeometry(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject,
296 jobject sourceObj, jobject dstObj, jlong orientation) {
297 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
298 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
299
300 Rect source, dst;
301 if (sourceObj != NULL) {
302 source = rectFromObj(env, sourceObj);
303 }
304 if (dstObj != NULL) {
305 dst = rectFromObj(env, dstObj);
306 }
307 transaction->setGeometry(ctrl, source, dst, orientation);
308}
309
Robert Carr6da3cc02016-06-16 15:17:07 -0700310static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700311jlong transactionObj,
Robert Carra9408d42016-06-03 13:28:48 -0700312 jlong nativeObject) {
Robert Carre13b58e2017-08-31 14:50:44 -0700313 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
314
Robert Carra9408d42016-06-03 13:28:48 -0700315 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700316 transaction->setGeometryAppliesWithResize(ctrl);
Robert Carra9408d42016-06-03 13:28:48 -0700317}
318
Robert Carre13b58e2017-08-31 14:50:44 -0700319static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj,
320 jlong nativeObject, jint w, jint h) {
321 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
322
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800323 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700324 transaction->setSize(ctrl, w, h);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800325}
326
Robert Carre13b58e2017-08-31 14:50:44 -0700327static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong transactionObj,
328 jlong nativeObject, jint flags, jint mask) {
329 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
330
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800331 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700332 transaction->setFlags(ctrl, flags, mask);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800333}
334
Robert Carre13b58e2017-08-31 14:50:44 -0700335static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong transactionObj,
336 jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800337 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
338 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
339 if (!region) {
340 doThrowIAE(env);
341 return;
342 }
343
344 const SkIRect& b(region->getBounds());
345 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
346 if (region->isComplex()) {
347 SkRegion::Iterator it(*region);
348 while (!it.done()) {
349 const SkIRect& r(it.rect());
350 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
351 it.next();
352 }
353 }
354
Robert Carre13b58e2017-08-31 14:50:44 -0700355 {
356 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
357 transaction->setTransparentRegionHint(ctrl, reg);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800358 }
359}
360
Robert Carre13b58e2017-08-31 14:50:44 -0700361static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj,
362 jlong nativeObject, jfloat alpha) {
363 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
364
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800365 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700366 transaction->setAlpha(ctrl, alpha);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800367}
368
Robert Carr788f5742018-07-30 17:46:45 -0700369static void nativeSetInputWindowInfo(JNIEnv* env, jclass clazz, jlong transactionObj,
370 jlong nativeObject, jobject inputWindow) {
371 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
372
373 sp<NativeInputWindowHandle> handle = android_server_InputWindowHandle_getHandle(
374 env, inputWindow);
375 handle->updateInfo();
376
377 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
378 transaction->setInputWindowInfo(ctrl, *handle->getInfo());
379}
380
chaviw59f532e2018-12-26 15:34:59 -0800381static void nativeTransferTouchFocus(JNIEnv* env, jclass clazz, jlong transactionObj,
382 jobject fromTokenObj, jobject toTokenObj) {
383 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
384
385 sp<IBinder> fromToken(ibinderForJavaObject(env, fromTokenObj));
386 sp<IBinder> toToken(ibinderForJavaObject(env, toTokenObj));
387 transaction->transferTouchFocus(fromToken, toToken);
388}
389
Evan Rosky485df202018-12-06 14:11:12 -0800390static void nativeSetMetadata(JNIEnv* env, jclass clazz, jlong transactionObj,
391 jlong nativeObject, jint id, jobject parcelObj) {
392 Parcel* parcel = parcelForJavaObject(env, parcelObj);
393 if (!parcel) {
394 jniThrowNullPointerException(env, "attribute data");
395 return;
396 }
397 if (parcel->objectsCount()) {
398 jniThrowException(env, "java/lang/RuntimeException",
399 "Tried to marshall a Parcel that contained Binder objects.");
400 return;
401 }
402
403 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
404
405 std::vector<uint8_t> byteData(parcel->dataSize());
406 memcpy(byteData.data(), parcel->data(), parcel->dataSize());
407
408 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);
409 transaction->setMetadata(ctrl, id, std::move(byteData));
410}
411
Robert Carre13b58e2017-08-31 14:50:44 -0700412static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj,
413 jlong nativeObject, jfloatArray fColor) {
414 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
chaviw0dd03f52017-08-25 12:15:26 -0700415 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700416
chaviw0dd03f52017-08-25 12:15:26 -0700417 float* floatColors = env->GetFloatArrayElements(fColor, 0);
418 half3 color(floatColors[0], floatColors[1], floatColors[2]);
Robert Carre13b58e2017-08-31 14:50:44 -0700419 transaction->setColor(ctrl, color);
chaviw0dd03f52017-08-25 12:15:26 -0700420}
421
Robert Carre13b58e2017-08-31 14:50:44 -0700422static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj,
423 jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800424 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Robert Carre13b58e2017-08-31 14:50:44 -0700425 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
426
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800427 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700428 transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800429}
430
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700431static void nativeSetColorTransform(JNIEnv* env, jclass clazz, jlong transactionObj,
432 jlong nativeObject, jfloatArray fMatrix, jfloatArray fTranslation) {
433 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
434 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
435 float* floatMatrix = env->GetFloatArrayElements(fMatrix, 0);
436 mat3 matrix(static_cast<float const*>(floatMatrix));
437 float* floatTranslation = env->GetFloatArrayElements(fTranslation, 0);
438 vec3 translation(floatTranslation[0], floatTranslation[1], floatTranslation[2]);
439 transaction->setColorTransform(surfaceControl, matrix, translation);
440}
441
Robert Carre13b58e2017-08-31 14:50:44 -0700442static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
443 jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800444 jint l, jint t, jint r, jint b) {
Robert Carre13b58e2017-08-31 14:50:44 -0700445 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
446
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800447 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
448 Rect crop(l, t, r, b);
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700449 transaction->setCrop_legacy(ctrl, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800450}
451
Lucas Dupinff9d6ab2018-10-16 18:05:50 -0700452static void nativeSetCornerRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
453 jlong nativeObject, jfloat cornerRadius) {
454 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
455
456 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
457 transaction->setCornerRadius(ctrl, cornerRadius);
458}
459
Robert Carre13b58e2017-08-31 14:50:44 -0700460static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj,
461 jlong nativeObject, jint layerStack) {
462 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
463
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800464 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700465 transaction->setLayerStack(ctrl, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800466}
467
468static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) {
469 sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id));
470 return javaObjectForIBinder(env, token);
471}
472
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700473static jobject nativeGetDisplayedContentSamplingAttributes(JNIEnv* env, jclass clazz,
474 jobject tokenObj) {
475 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
476
477 ui::PixelFormat format;
478 ui::Dataspace dataspace;
479 uint8_t componentMask;
480 status_t err = SurfaceComposerClient::getDisplayedContentSamplingAttributes(
481 token, &format, &dataspace, &componentMask);
482 if (err != OK) {
483 return nullptr;
484 }
485 return env->NewObject(gDisplayedContentSamplingAttributesClassInfo.clazz,
486 gDisplayedContentSamplingAttributesClassInfo.ctor,
487 format, dataspace, componentMask);
488}
489
490static jboolean nativeSetDisplayedContentSamplingEnabled(JNIEnv* env, jclass clazz,
491 jobject tokenObj, jboolean enable, jint componentMask, jint maxFrames) {
492 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Kevin DuBois205a6802019-01-07 17:04:46 -0800493 status_t rc = SurfaceComposerClient::setDisplayContentSamplingEnabled(
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700494 token, enable, componentMask, maxFrames);
Kevin DuBois205a6802019-01-07 17:04:46 -0800495 return rc == OK;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700496}
497
498static jobject nativeGetDisplayedContentSample(JNIEnv* env, jclass clazz, jobject tokenObj,
499 jlong maxFrames, jlong timestamp) {
500 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
501
502 DisplayedFrameStats stats;
503 status_t err = SurfaceComposerClient::getDisplayedContentSample(
504 token, maxFrames, timestamp, &stats);
505 if (err != OK) {
506 return nullptr;
507 }
508
509 jlongArray histogramComponent0 = env->NewLongArray(stats.component_0_sample.size());
510 jlongArray histogramComponent1 = env->NewLongArray(stats.component_1_sample.size());
511 jlongArray histogramComponent2 = env->NewLongArray(stats.component_2_sample.size());
512 jlongArray histogramComponent3 = env->NewLongArray(stats.component_3_sample.size());
513 if ((histogramComponent0 == nullptr) ||
514 (histogramComponent1 == nullptr) ||
515 (histogramComponent2 == nullptr) ||
516 (histogramComponent3 == nullptr)) {
517 return JNI_FALSE;
518 }
519
520 env->SetLongArrayRegion(histogramComponent0, 0,
521 stats.component_0_sample.size(),
522 reinterpret_cast<jlong*>(stats.component_0_sample.data()));
523 env->SetLongArrayRegion(histogramComponent1, 0,
524 stats.component_1_sample.size(),
525 reinterpret_cast<jlong*>(stats.component_1_sample.data()));
526 env->SetLongArrayRegion(histogramComponent2, 0,
527 stats.component_2_sample.size(),
528 reinterpret_cast<jlong*>(stats.component_2_sample.data()));
529 env->SetLongArrayRegion(histogramComponent3, 0,
530 stats.component_3_sample.size(),
531 reinterpret_cast<jlong*>(stats.component_3_sample.data()));
532 return env->NewObject(gDisplayedContentSampleClassInfo.clazz,
533 gDisplayedContentSampleClassInfo.ctor,
534 stats.numFrames,
535 histogramComponent0,
536 histogramComponent1,
537 histogramComponent2,
538 histogramComponent3);
539}
540
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800541static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
542 jboolean secure) {
543 ScopedUtfChars name(env, nameObj);
544 sp<IBinder> token(SurfaceComposerClient::createDisplay(
545 String8(name.c_str()), bool(secure)));
546 return javaObjectForIBinder(env, token);
547}
548
Jesse Hall6a6bc212013-08-08 12:15:03 -0700549static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
550 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
551 if (token == NULL) return;
552 SurfaceComposerClient::destroyDisplay(token);
553}
554
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800555static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700556 jlong transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000557 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800558 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
559 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800560 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800561 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800562 if (sur != NULL) {
563 bufferProducer = sur->getIGraphicBufferProducer();
564 }
Robert Carre13b58e2017-08-31 14:50:44 -0700565
566
567 status_t err = NO_ERROR;
568 {
569 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
570 err = transaction->setDisplaySurface(token,
571 bufferProducer);
572 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700573 if (err != NO_ERROR) {
574 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
575 " Surface created with singleBufferMode?");
576 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800577}
578
579static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700580 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800581 jobject tokenObj, jint layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -0700582
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800583 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
584 if (token == NULL) return;
585
Robert Carre13b58e2017-08-31 14:50:44 -0700586 {
587 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
588 transaction->setDisplayLayerStack(token, layerStack);
589 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800590}
591
592static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700593 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800594 jobject tokenObj, jint orientation,
595 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
596 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
597 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
598 if (token == NULL) return;
599 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
600 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
Robert Carre13b58e2017-08-31 14:50:44 -0700601
602 {
603 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
604 transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect);
605 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800606}
607
Michael Wright01e840f2014-06-26 16:03:25 -0700608static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700609 jlong transactionObj,
Michael Wright01e840f2014-06-26 16:03:25 -0700610 jobject tokenObj, jint width, jint height) {
611 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
612 if (token == NULL) return;
Robert Carre13b58e2017-08-31 14:50:44 -0700613
614 {
615 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
616 transaction->setDisplaySize(token, width, height);
617 }
Michael Wright01e840f2014-06-26 16:03:25 -0700618}
619
Dan Stoza00101052014-05-02 15:23:40 -0700620static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
621 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800622 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700623 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800624
Dan Stoza00101052014-05-02 15:23:40 -0700625 Vector<DisplayInfo> configs;
626 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
627 configs.size() == 0) {
628 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800629 }
630
Dan Stoza00101052014-05-02 15:23:40 -0700631 jobjectArray configArray = env->NewObjectArray(configs.size(),
632 gPhysicalDisplayInfoClassInfo.clazz, NULL);
633
634 for (size_t c = 0; c < configs.size(); ++c) {
635 const DisplayInfo& info = configs[c];
636 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
637 gPhysicalDisplayInfoClassInfo.ctor);
638 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
639 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
640 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
641 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
642 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
643 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
644 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700645 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
646 info.appVsyncOffset);
647 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
648 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700649 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
650 env->DeleteLocalRef(infoObj);
651 }
652
653 return configArray;
654}
655
656static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
657 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
658 if (token == NULL) return -1;
659 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
660}
661
662static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
663 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
664 if (token == NULL) return JNI_FALSE;
665 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
666 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800667}
668
Michael Wright1c9977b2016-07-12 13:30:10 -0700669static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
670 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
671 if (token == NULL) return NULL;
Peiyong Linb88549e2018-03-28 12:03:45 -0700672 Vector<ui::ColorMode> colorModes;
Michael Wright1c9977b2016-07-12 13:30:10 -0700673 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
674 colorModes.isEmpty()) {
675 return NULL;
676 }
677
678 jintArray colorModesArray = env->NewIntArray(colorModes.size());
679 if (colorModesArray == NULL) {
680 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
681 return NULL;
682 }
683 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
684 for (size_t i = 0; i < colorModes.size(); i++) {
685 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
686 }
687 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
688 return colorModesArray;
689}
690
691static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
692 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
693 if (token == NULL) return -1;
694 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
695}
696
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800697static jintArray nativeGetCompositionDataspaces(JNIEnv* env, jclass) {
698 ui::Dataspace defaultDataspace, wcgDataspace;
699 ui::PixelFormat defaultPixelFormat, wcgPixelFormat;
700 if (SurfaceComposerClient::getCompositionPreference(&defaultDataspace,
701 &defaultPixelFormat,
702 &wcgDataspace,
703 &wcgPixelFormat) != NO_ERROR) {
704 return nullptr;
705 }
706 jintArray array = env->NewIntArray(2);
707 if (array == nullptr) {
708 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
709 return nullptr;
710 }
711 jint* arrayValues = env->GetIntArrayElements(array, 0);
712 arrayValues[0] = static_cast<jint>(defaultDataspace);
713 arrayValues[1] = static_cast<jint>(wcgDataspace);
714 env->ReleaseIntArrayElements(array, arrayValues, 0);
715 return array;
716}
717
Michael Wright1c9977b2016-07-12 13:30:10 -0700718static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
719 jobject tokenObj, jint colorMode) {
720 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
721 if (token == NULL) return JNI_FALSE;
722 status_t err = SurfaceComposerClient::setActiveColorMode(token,
Peiyong Linb88549e2018-03-28 12:03:45 -0700723 static_cast<ui::ColorMode>(colorMode));
Michael Wright1c9977b2016-07-12 13:30:10 -0700724 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
725}
726
Prashant Malanic55929a2014-05-25 01:59:21 -0700727static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800728 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
729 if (token == NULL) return;
730
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700731 android::base::Timer t;
Prashant Malanic55929a2014-05-25 01:59:21 -0700732 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700733 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800734}
735
Peiyong Lin0ddb7d42019-01-16 13:25:09 -0800736static jboolean nativeGetProtectedContentSupport(JNIEnv* env, jclass) {
737 return static_cast<jboolean>(SurfaceComposerClient::getProtectedContentSupport());
738}
739
Svetoslav1376d602014-03-13 11:17:26 -0700740static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
741 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
742 status_t err = ctrl->clearLayerFrameStats();
743
744 if (err < 0 && err != NO_INIT) {
745 doThrowIAE(env);
746 }
747
748 // The other end is not ready, just report we failed.
749 if (err == NO_INIT) {
750 return JNI_FALSE;
751 }
752
753 return JNI_TRUE;
754}
755
756static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
757 jobject outStats) {
758 FrameStats stats;
759
760 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
761 status_t err = ctrl->getLayerFrameStats(&stats);
762 if (err < 0 && err != NO_INIT) {
763 doThrowIAE(env);
764 }
765
766 // The other end is not ready, fine just return empty stats.
767 if (err == NO_INIT) {
768 return JNI_FALSE;
769 }
770
771 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
772 size_t frameCount = stats.desiredPresentTimesNano.size();
773
774 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
775 if (postedTimesNanoDst == NULL) {
776 return JNI_FALSE;
777 }
778
779 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
780 if (presentedTimesNanoDst == NULL) {
781 return JNI_FALSE;
782 }
783
784 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
785 if (readyTimesNanoDst == NULL) {
786 return JNI_FALSE;
787 }
788
789 nsecs_t postedTimesNanoSrc[frameCount];
790 nsecs_t presentedTimesNanoSrc[frameCount];
791 nsecs_t readyTimesNanoSrc[frameCount];
792
793 for (size_t i = 0; i < frameCount; i++) {
794 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
795 if (postedTimeNano == INT64_MAX) {
796 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
797 }
798 postedTimesNanoSrc[i] = postedTimeNano;
799
800 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
801 if (presentedTimeNano == INT64_MAX) {
802 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
803 }
804 presentedTimesNanoSrc[i] = presentedTimeNano;
805
806 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
807 if (readyTimeNano == INT64_MAX) {
808 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
809 }
810 readyTimesNanoSrc[i] = readyTimeNano;
811 }
812
813 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
814 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
815 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
816
817 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
818 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
819
820 if (env->ExceptionCheck()) {
821 return JNI_FALSE;
822 }
823
824 return JNI_TRUE;
825}
826
827static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
828 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
829
830 if (err < 0 && err != NO_INIT) {
831 doThrowIAE(env);
832 }
833
834 // The other end is not ready, just report we failed.
835 if (err == NO_INIT) {
836 return JNI_FALSE;
837 }
838
839 return JNI_TRUE;
840}
841
842static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
843 FrameStats stats;
844
845 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
846 if (err < 0 && err != NO_INIT) {
847 doThrowIAE(env);
848 }
849
850 // The other end is not ready, fine just return empty stats.
851 if (err == NO_INIT) {
852 return JNI_FALSE;
853 }
854
855 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
856 size_t frameCount = stats.desiredPresentTimesNano.size();
857
858 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
859 if (presentedTimesNanoDst == NULL) {
860 return JNI_FALSE;
861 }
862
863 nsecs_t presentedTimesNanoSrc[frameCount];
864
865 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700866 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700867 if (presentedTimeNano == INT64_MAX) {
868 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
869 }
870 presentedTimesNanoSrc[i] = presentedTimeNano;
871 }
872
873 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
874
875 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
876 presentedTimesNanoDst);
877
878 if (env->ExceptionCheck()) {
879 return JNI_FALSE;
880 }
881
882 return JNI_TRUE;
883}
884
Robert Carre13b58e2017-08-31 14:50:44 -0700885static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj,
886 jlong nativeObject,
Rob Carr64e516f2015-10-29 00:20:45 +0000887 jobject handleObject, jlong frameNumber) {
888 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
889 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
890
Robert Carre13b58e2017-08-31 14:50:44 -0700891 {
892 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700893 transaction->deferTransactionUntil_legacy(ctrl, handle, frameNumber);
Robert Carre13b58e2017-08-31 14:50:44 -0700894 }
Rob Carr64e516f2015-10-29 00:20:45 +0000895}
896
Robert Carre13b58e2017-08-31 14:50:44 -0700897static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
898 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -0800899 jlong surfaceObject, jlong frameNumber) {
Robert Carre13b58e2017-08-31 14:50:44 -0700900 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
901
Robert Carrd5c7dd62017-03-08 10:39:30 -0800902 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
903 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
904
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700905 transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber);
Robert Carrd5c7dd62017-03-08 10:39:30 -0800906}
907
Robert Carre13b58e2017-08-31 14:50:44 -0700908static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
909 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -0800910 jobject newParentObject) {
Robert Carre13b58e2017-08-31 14:50:44 -0700911
Robert Carrd5c7dd62017-03-08 10:39:30 -0800912 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
913 sp<IBinder> handle = ibinderForJavaObject(env, newParentObject);
914
Robert Carre13b58e2017-08-31 14:50:44 -0700915 {
916 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
917 transaction->reparentChildren(ctrl, handle);
918 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800919}
920
Robert Carre13b58e2017-08-31 14:50:44 -0700921static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
922 jlong nativeObject,
Robert Carr10584fa2019-01-14 15:55:19 -0800923 jlong newParentObject) {
chaviw63542382017-08-17 17:39:29 -0700924 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr10584fa2019-01-14 15:55:19 -0800925 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700926
927 {
928 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr10584fa2019-01-14 15:55:19 -0800929 transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL);
Robert Carre13b58e2017-08-31 14:50:44 -0700930 }
chaviw63542382017-08-17 17:39:29 -0700931}
932
Robert Carre13b58e2017-08-31 14:50:44 -0700933static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
934 jlong nativeObject) {
935 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
936
Robert Carrd5c7dd62017-03-08 10:39:30 -0800937 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700938 transaction->detachChildren(ctrl);
Robert Carrd5c7dd62017-03-08 10:39:30 -0800939}
940
Robert Carre13b58e2017-08-31 14:50:44 -0700941static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj,
942 jlong nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -0700943 jint scalingMode) {
Robert Carre13b58e2017-08-31 14:50:44 -0700944 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr1ca6a332016-04-11 18:00:43 -0700945
Robert Carre13b58e2017-08-31 14:50:44 -0700946 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
947 transaction->setOverrideScalingMode(ctrl, scalingMode);
Robert Carr1ca6a332016-04-11 18:00:43 -0700948}
949
Rob Carr64e516f2015-10-29 00:20:45 +0000950static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
951 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Rob Carr64e516f2015-10-29 00:20:45 +0000952 return javaObjectForIBinder(env, ctrl->getHandle());
953}
954
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700955static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
956 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
957 if (token == NULL) return NULL;
958
959 HdrCapabilities capabilities;
960 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
961
962 const auto& types = capabilities.getSupportedHdrTypes();
Peiyong Lin3a0c6e12018-04-16 11:05:29 -0700963 std::vector<int32_t> intTypes;
964 for (auto type : types) {
965 intTypes.push_back(static_cast<int32_t>(type));
966 }
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700967 auto typesArray = env->NewIntArray(types.size());
Peiyong Lin3a0c6e12018-04-16 11:05:29 -0700968 env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data());
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700969
Michael Wright9ff94c02016-03-30 18:05:40 -0700970 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700971 typesArray, capabilities.getDesiredMaxLuminance(),
972 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
973}
974
Jorim Jaggi06975df2017-12-01 14:52:13 +0100975static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
976 Parcel* parcel = parcelForJavaObject(env, parcelObj);
977 if (parcel == NULL) {
978 doThrowNPE(env);
979 return 0;
980 }
981 sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel);
982 if (surface == nullptr) {
983 return 0;
984 }
985 surface->incStrong((void *)nativeCreate);
986 return reinterpret_cast<jlong>(surface.get());
987}
988
chaviwbeb7a0c2018-12-05 13:49:54 -0800989static jlong nativeCopyFromSurfaceControl(JNIEnv* env, jclass clazz, jlong surfaceControlNativeObj) {
990 sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj));
991 if (surface == nullptr) {
992 return 0;
993 }
Robert Carr5fea55b2018-12-10 13:05:52 -0800994
995 sp<SurfaceControl> newSurface = new SurfaceControl(surface);
996 newSurface->incStrong((void *)nativeCreate);
997 return reinterpret_cast<jlong>(newSurface.get());
chaviwbeb7a0c2018-12-05 13:49:54 -0800998}
999
Jorim Jaggi06975df2017-12-01 14:52:13 +01001000static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
1001 jlong nativeObject, jobject parcelObj) {
1002 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1003 if (parcel == NULL) {
1004 doThrowNPE(env);
1005 return;
1006 }
1007 SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject);
chaviwbeb7a0c2018-12-05 13:49:54 -08001008 if (self != nullptr) {
1009 self->writeToParcel(parcel);
1010 }
Jorim Jaggi06975df2017-12-01 14:52:13 +01001011}
1012
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001013// ----------------------------------------------------------------------------
1014
Daniel Micay76f6a862015-09-19 17:31:01 -04001015static const JNINativeMethod sSurfaceControlMethods[] = {
Evan Rosky485df202018-12-06 14:11:12 -08001016 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJLandroid/os/Parcel;)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001017 (void*)nativeCreate },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001018 {"nativeReadFromParcel", "(Landroid/os/Parcel;)J",
1019 (void*)nativeReadFromParcel },
chaviwbeb7a0c2018-12-05 13:49:54 -08001020 {"nativeCopyFromSurfaceControl", "(J)J" ,
1021 (void*)nativeCopyFromSurfaceControl },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001022 {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
1023 (void*)nativeWriteToParcel },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001024 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001025 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001026 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001027 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -08001028 {"nativeDisconnect", "(J)V",
1029 (void*)nativeDisconnect },
Robert Carre13b58e2017-08-31 14:50:44 -07001030 {"nativeCreateTransaction", "()J",
1031 (void*)nativeCreateTransaction },
1032 {"nativeApplyTransaction", "(JZ)V",
1033 (void*)nativeApplyTransaction },
1034 {"nativeGetNativeTransactionFinalizer", "()J",
1035 (void*)nativeGetNativeTransactionFinalizer },
Robert Carrb1579c82017-09-05 14:54:47 -07001036 {"nativeMergeTransaction", "(JJ)V",
1037 (void*)nativeMergeTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -07001038 {"nativeSetAnimationTransaction", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001039 (void*)nativeSetAnimationTransaction },
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001040 {"nativeSetEarlyWakeup", "(J)V",
1041 (void*)nativeSetEarlyWakeup },
Robert Carre13b58e2017-08-31 14:50:44 -07001042 {"nativeSetLayer", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001043 (void*)nativeSetLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001044 {"nativeSetRelativeLayer", "(JJLandroid/os/IBinder;I)V",
Robert Carraf422a82017-04-10 18:34:33 -07001045 (void*)nativeSetRelativeLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001046 {"nativeSetPosition", "(JJFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001047 (void*)nativeSetPosition },
Robert Carre13b58e2017-08-31 14:50:44 -07001048 {"nativeSetGeometryAppliesWithResize", "(JJ)V",
Robert Carr6da3cc02016-06-16 15:17:07 -07001049 (void*)nativeSetGeometryAppliesWithResize },
Robert Carre13b58e2017-08-31 14:50:44 -07001050 {"nativeSetSize", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001051 (void*)nativeSetSize },
Robert Carre13b58e2017-08-31 14:50:44 -07001052 {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001053 (void*)nativeSetTransparentRegionHint },
Robert Carre13b58e2017-08-31 14:50:44 -07001054 {"nativeSetAlpha", "(JJF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001055 (void*)nativeSetAlpha },
Robert Carre13b58e2017-08-31 14:50:44 -07001056 {"nativeSetColor", "(JJ[F)V",
chaviw0dd03f52017-08-25 12:15:26 -07001057 (void*)nativeSetColor },
Robert Carre13b58e2017-08-31 14:50:44 -07001058 {"nativeSetMatrix", "(JJFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001059 (void*)nativeSetMatrix },
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001060 {"nativeSetColorTransform", "(JJ[F[F)V",
1061 (void*)nativeSetColorTransform },
Robert Carre13b58e2017-08-31 14:50:44 -07001062 {"nativeSetFlags", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001063 (void*)nativeSetFlags },
Robert Carre13b58e2017-08-31 14:50:44 -07001064 {"nativeSetWindowCrop", "(JJIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001065 (void*)nativeSetWindowCrop },
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001066 {"nativeSetCornerRadius", "(JJF)V",
1067 (void*)nativeSetCornerRadius },
Robert Carre13b58e2017-08-31 14:50:44 -07001068 {"nativeSetLayerStack", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001069 (void*)nativeSetLayerStack },
1070 {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
1071 (void*)nativeGetBuiltInDisplay },
1072 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
1073 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -07001074 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
1075 (void*)nativeDestroyDisplay },
Robert Carre13b58e2017-08-31 14:50:44 -07001076 {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001077 (void*)nativeSetDisplaySurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001078 {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001079 (void*)nativeSetDisplayLayerStack },
Robert Carre13b58e2017-08-31 14:50:44 -07001080 {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001081 (void*)nativeSetDisplayProjection },
Robert Carre13b58e2017-08-31 14:50:44 -07001082 {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
Michael Wright01e840f2014-06-26 16:03:25 -07001083 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -07001084 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
1085 (void*)nativeGetDisplayConfigs },
1086 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
1087 (void*)nativeGetActiveConfig },
1088 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
1089 (void*)nativeSetActiveConfig },
Michael Wright1c9977b2016-07-12 13:30:10 -07001090 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
1091 (void*)nativeGetDisplayColorModes},
1092 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
1093 (void*)nativeGetActiveColorMode},
1094 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
1095 (void*)nativeSetActiveColorMode},
Peiyong Lin5f4a5682019-01-17 11:37:07 -08001096 {"nativeGetCompositionDataspaces", "()[I",
1097 (void*)nativeGetCompositionDataspaces},
Michael Wright9ff94c02016-03-30 18:05:40 -07001098 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
1099 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -07001100 {"nativeClearContentFrameStats", "(J)Z",
1101 (void*)nativeClearContentFrameStats },
1102 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
1103 (void*)nativeGetContentFrameStats },
1104 {"nativeClearAnimationFrameStats", "()Z",
1105 (void*)nativeClearAnimationFrameStats },
1106 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
1107 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -07001108 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
1109 (void*)nativeSetDisplayPowerMode },
Peiyong Lin0ddb7d42019-01-16 13:25:09 -08001110 {"nativeGetProtectedContentSupport", "()Z",
1111 (void*)nativeGetProtectedContentSupport },
Robert Carre13b58e2017-08-31 14:50:44 -07001112 {"nativeDeferTransactionUntil", "(JJLandroid/os/IBinder;J)V",
Rob Carr64e516f2015-10-29 00:20:45 +00001113 (void*)nativeDeferTransactionUntil },
Robert Carre13b58e2017-08-31 14:50:44 -07001114 {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001115 (void*)nativeDeferTransactionUntilSurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001116 {"nativeReparentChildren", "(JJLandroid/os/IBinder;)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001117 (void*)nativeReparentChildren } ,
Robert Carr10584fa2019-01-14 15:55:19 -08001118 {"nativeReparent", "(JJJ)V",
chaviw76431402017-09-18 16:50:05 -07001119 (void*)nativeReparent },
Robert Carre13b58e2017-08-31 14:50:44 -07001120 {"nativeSeverChildren", "(JJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001121 (void*)nativeSeverChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001122 {"nativeSetOverrideScalingMode", "(JJI)V",
Robert Carr1ca6a332016-04-11 18:00:43 -07001123 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +00001124 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -07001125 (void*)nativeGetHandle },
chaviw08520a02018-09-10 16:44:56 -07001126 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZI)Landroid/graphics/GraphicBuffer;",
1127 (void*)nativeScreenshot },
Chavi Weingartenea2eb5a2017-11-29 21:26:24 +00001128 {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/graphics/Rect;F)Landroid/graphics/GraphicBuffer;",
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001129 (void*)nativeCaptureLayers },
Robert Carr788f5742018-07-30 17:46:45 -07001130 {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
chaviw59f532e2018-12-26 15:34:59 -08001131 (void*)nativeSetInputWindowInfo },
1132 {"nativeTransferTouchFocus", "(JLandroid/os/IBinder;Landroid/os/IBinder;)V",
1133 (void*)nativeTransferTouchFocus },
Evan Rosky485df202018-12-06 14:11:12 -08001134 {"nativeSetMetadata", "(JILandroid/os/Parcel;)V",
1135 (void*)nativeSetMetadata },
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001136 {"nativeGetDisplayedContentSamplingAttributes",
1137 "(Landroid/os/IBinder;)Landroid/hardware/display/DisplayedContentSamplingAttributes;",
1138 (void*)nativeGetDisplayedContentSamplingAttributes },
1139 {"nativeSetDisplayedContentSamplingEnabled", "(Landroid/os/IBinder;ZII)Z",
1140 (void*)nativeSetDisplayedContentSamplingEnabled },
1141 {"nativeGetDisplayedContentSample",
1142 "(Landroid/os/IBinder;JJ)Landroid/hardware/display/DisplayedContentSample;",
1143 (void*)nativeGetDisplayedContentSample },
Robert Carr76907ee2019-01-11 13:38:19 -08001144 {"nativeSetGeometry", "(JJLandroid/graphics/Rect;Landroid/graphics/Rect;J)V",
1145 (void*)nativeSetGeometry }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001146};
1147
1148int register_android_view_SurfaceControl(JNIEnv* env)
1149{
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001150 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001151 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
1152
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001153 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
1154 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
1155 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
1156 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
1157 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
1158 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
1159 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
1160 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
1161 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
1162 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
1163 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
1164 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
1165 clazz, "appVsyncOffsetNanos", "J");
1166 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
1167 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001168
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001169 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
1170 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
1171 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
1172 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
1173 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -07001174
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001175 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
1176 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
1177 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001178 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
1179
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001180 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
1181 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1182 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001183 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1184
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001185 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
1186 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1187 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001188 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1189
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001190 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
1191 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
1192 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
1193 "([IFFF)V");
1194
Robert Carr6486d312017-01-09 19:48:29 -08001195 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
1196 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
1197 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
1198 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
1199
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001200 jclass displayedContentSampleClazz = FindClassOrDie(env,
1201 "android/hardware/display/DisplayedContentSample");
1202 gDisplayedContentSampleClassInfo.clazz = MakeGlobalRefOrDie(env, displayedContentSampleClazz);
1203 gDisplayedContentSampleClassInfo.ctor = GetMethodIDOrDie(env,
1204 displayedContentSampleClazz, "<init>", "(J[J[J[J[J)V");
1205
1206 jclass displayedContentSamplingAttributesClazz = FindClassOrDie(env,
1207 "android/hardware/display/DisplayedContentSamplingAttributes");
1208 gDisplayedContentSamplingAttributesClassInfo.clazz = MakeGlobalRefOrDie(env,
1209 displayedContentSamplingAttributesClazz);
1210 gDisplayedContentSamplingAttributesClassInfo.ctor = GetMethodIDOrDie(env,
1211 displayedContentSamplingAttributesClazz, "<init>", "(III)V");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001212 return err;
1213}
1214
1215};